home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / sos3-2.lha / src / genCC / genCC.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-23  |  52.5 KB  |  1,886 lines

  1. /* --------------------------------------------------------------------------
  2.  * Copyright 1992 by Forschungszentrum Informatik (FZI)
  3.  *
  4.  * You can use and distribute this software under the terms of the licence
  5.  * you should have received along with this program.
  6.  * If not or if you want additional information, write to
  7.  * Forschungszentrum Informatik, "STONE", Haid-und-Neu-Strasse 10-14,
  8.  * D-7500 Karlsruhe 1, Germany.
  9.  * --------------------------------------------------------------------------
  10.  */
  11. // **************************************************************************
  12. // Module genCC                                              Juergen Uhl (ju)
  13. //
  14. // **************************************************************************
  15. // SOS interface generator for C++ 
  16. // **************************************************************************
  17.  
  18. #include <stream.h>
  19. #include "sys.h"
  20. #include "smg.h"
  21. #include "genCC_err.h"
  22. #include "trc_genCC.h"
  23. #include "mta_use.h"
  24. #include "cci_use.h"
  25.  
  26. #include "genCC.h"
  27.  
  28. const sos_Cstring U_SUFFIX    = "_use.h";
  29. const sos_Cstring I_SUFFIX    = "_sos.h";
  30. const sos_Cstring X_SUFFIX    = "_ext.h";
  31. const sos_Cstring C_SUFFIX    = "_sos.c";
  32. const sos_Cstring _ID        = "_";
  33. const sos_Cstring CCI        = "cci_Schema_impl";
  34.  
  35. const sos_Cstring INT1        = "sos_Char";
  36. const sos_Cstring INT2        = "sos_Short";
  37. const sos_Cstring INT4        = "sos_Int";
  38.  
  39. sos_Bool gen_inline;
  40.  
  41. static void imports_out (sos_Imports);
  42. static void typedef_type_out (sos_Typedef_type);
  43. static void enum_type_out (sos_Enum_type,sos_Bool);
  44. static void scalar_type_out (sos_Schema_type);
  45. static void union_type_out (sos_Union_type);
  46. static void class_type_out (sos_Class_type);
  47. static void type_type_out (sos_Schema_type);
  48. static void inits_out (sos_Schema_module);
  49.  
  50. static void id_class_out (sos_Class_type, sos_Super_class_List);
  51. static void id_super_classes_out (sos_Type_name_List);
  52. static void id_cc_methods_out (sos_Class_type);
  53. static void id_predefined_methods_out (sos_Class_type);
  54. static sos_Method_kind id_method_kind;
  55. static void id_methods_out (sos_Class_type, sos_Method_List);
  56. static void id_method_out (sos_Class_type, sos_Method);
  57. static void id_comp_method_out (sos_Class_type, sos_Comp_method);
  58. enum Method_class {MC_REGULAR, MC_COMP, MC_STATIC};
  59. static void id_univ_methods_out (sos_Class_type  ct,
  60.                  sos_Method_List ml,
  61.                  Method_class    mc,
  62.                  sos_Bool        only_predefined);
  63. static void id_univ_method_out (sos_Class_type ct,
  64.                 sos_Method     m,
  65.                 sos_Bool       is_static);
  66.  
  67. static void class_out (sos_Class_type, sos_Super_class_List);
  68. static void init_out (sos_Class_type, sos_Super_class_List);
  69. static void friends_out (sos_Class_type);
  70. static void ccc_methods_out (sos_Class_type);
  71. static void cc_methods_out (sos_Class_type);
  72. static sos_Method_kind method_kind;
  73. static void inherited_methods_out (sos_Class_type);
  74. static void method_out (sos_Class_type, sos_Method);
  75. static void params_out (ostream&,
  76.             sos_Param_List,
  77.             sos_Bool no_param_names,
  78.             sos_Bool impl,
  79.             sos_Bool actual,
  80.             sos_Bool first = TRUE,
  81.             sos_Int start = 1);
  82. static void type_conversion_out (ostream&, sos_Type_name, sos_Type_name, sos_Bool);
  83. static void params_and_type_conversion_out
  84.            (ostream&, sos_Param_List, sos_Param_List, sos_Bool);
  85. static void exprs_out (ostream&, sos_Expr_List, sos_Bool);
  86.  
  87. static ostream& operator<< (ostream&, sos_String_List);
  88. static ostream& operator<< (ostream&, sos_Type_name);
  89. static ostream& operator<< (ostream&, sos_Param_List);
  90. static ostream& operator<< (ostream&, sos_Param);
  91. static ostream& operator<< (ostream&, sos_Expr);
  92. static ostream& operator<< (ostream&, sos_Expr_List);
  93. static ostream& operator<< (ostream&, sos_Typed_id);
  94. static ostream& operator<< (ostream&, sos_Method_kind);
  95.  
  96. static sos_Bool is_root_type (sos_Type);
  97. static sos_Bool is_generic_parameter (sos_Type_name);
  98. static sos_Bool is_ccc_method (sos_Method);
  99. static sos_Schema_type get_void_type();
  100. static sos_Schema_type get_scalar_object_type();
  101. static sos_Schema_module generated_schema;
  102.  
  103. filebuf fb_h;
  104. filebuf fb_i;
  105. filebuf fb_c;
  106. ostream out_h(&fb_h);
  107. ostream out_i(&fb_i);
  108. ostream out_c(&fb_c);
  109.  
  110. #define out_I (gen_inline?out_h:out_i)
  111.  
  112. void gen_module_out (sos_Schema_module mdl)
  113. {
  114.    T_PROC ("gen_module_out");
  115.    TT (genCC_H, T_ENTER);
  116.  
  117.    generated_schema = mdl;
  118.  
  119.    sos_Container ct = mdl.container();
  120.    ct.open (WRITING, WAITING);
  121.    cci_Schema_impl::make_impl (mdl);
  122.  
  123.    sos_Schema_type_List type_decls = mdl.get_types();
  124.    smg_String m_name = mdl.get_name();
  125.    smg_String u_name = m_name + U_SUFFIX;
  126.    smg_String i_name = m_name + I_SUFFIX;
  127.    smg_String c_name = m_name + C_SUFFIX;
  128.  
  129.    if (fb_h.open(u_name.make_Cstring (SMG_BORROW), output) == 0 || 
  130.        fb_i.open(i_name.make_Cstring (SMG_BORROW), output) == 0 ||
  131.        fb_c.open(c_name.make_Cstring (SMG_BORROW), output) == 0)
  132.    {  err_raise (err_USE, err_GEN_OUTPUT_ERROR, NULL, FALSE);
  133.       return;
  134.    }
  135.  
  136.    out_h << "#ifndef " << m_name << "_SOSH\n"
  137.          << "#define " << m_name << "_SOSH 1\n\n";
  138.  
  139.    out_i << "#ifndef " << m_name << "_SOSI\n"
  140.          << "#define " << m_name << "_SOSI 1\n\n"
  141.      << "#include \"" << m_name << U_SUFFIX << "\"\n";
  142.  
  143.    out_c << "#include \"" << m_name << I_SUFFIX << "\"\n";
  144.  
  145.    out_c << "#include \"err.h\"\n";    // for 'err_raise_abstract_method'
  146.  
  147.    imports_out (mdl.get_imports());
  148.  
  149.    out_c << "#include \"cci" << U_SUFFIX << "\"\n";
  150.  
  151.    agg_iterate (type_decls, sos_Schema_type td)
  152.    {  if (td.has_type(sos_Enum_type_type))
  153.          enum_type_out (sos_Enum_type::make(td),TRUE);
  154.       else if (td.has_type(sos_Class_type_type))
  155.       {  if (is_root_type (td))
  156.         out_I << "class " << _ID << td.make_type_name() << ";\n";
  157.          out_h << "class " << td.make_type_name() << ";\n";
  158.       }
  159.       else if (td.has_type(sos_Typedef_type_type))
  160.          typedef_type_out (sos_Typedef_type::make(td)); 
  161.    }
  162.    agg_iterate_end (type_decls, td);
  163.  
  164.    if (mdl.get_has_external_types() OR mdl.get_has_external_import())
  165.       out_h << "#include \"" << m_name << X_SUFFIX << "\"\n";
  166.  
  167.    agg_iterate (type_decls, sos_Schema_type td)
  168.    {  if (td.has_type(sos_Enum_type_type))
  169.          enum_type_out (sos_Enum_type::make(td),FALSE);
  170.       else if (td.has_type(sos_Extern_type_type))
  171.       {
  172. #ifdef ATT
  173.      if (td.operator!=(get_void_type ()))
  174. #else
  175.      if (td != get_void_type ())
  176. #endif
  177.         scalar_type_out (td);
  178.       }
  179.       else if (td.has_type(sos_Union_type_type))
  180.          union_type_out (sos_Union_type::make(td));
  181.       else if (td.has_type(sos_Class_type_type))
  182.          class_type_out (sos_Class_type::make(td));
  183.       else if (NOT td.has_type(sos_Typedef_type_type))
  184.       // predefined or forward type: do nothing
  185.          continue;
  186.       
  187.       type_type_out (td);
  188.    }
  189.    agg_iterate_end (type_decls, td);
  190.  
  191.    inits_out (mdl);
  192.  
  193.    out_h << "#endif\n";
  194.    out_i << "#endif\n";
  195.  
  196.    fb_h.close();
  197.    fb_i.close();
  198.    fb_c.close();
  199.  
  200.    ct.close ();
  201.  
  202.    TT (genCC_H, T_LEAVE);
  203. }
  204.  
  205. static void imports_out (sos_Imports imports)
  206. {
  207.    T_PROC ("imports_out");
  208.    TT (genCC_H, T_ENTER);
  209.  
  210.    agg_iterate (imports, sos_Schema_module mdl)
  211.    {  out_h << "#include \"" << mdl.get_name() << U_SUFFIX << "\"\n";
  212.       out_I << "#include \"" << mdl.get_name() << I_SUFFIX << "\"\n";
  213.    }
  214.    agg_iterate_end (imports, mdl);
  215.  
  216.    TT (genCC_H, T_LEAVE);
  217. }
  218.  
  219. static void typedef_type_out (sos_Typedef_type tdt)
  220. {
  221.    T_PROC ("typedef_type_out");
  222.    TT (genCC_H, T_ENTER);
  223.  
  224.    sos_Type_name tn = tdt.get_type_name();
  225.    sos_String n = tdt.get_name();
  226.    out_h << "typedef ";
  227.    if (tn.make_base_type().has_type (sos_Class_type_type))
  228.       out_h << "class ";
  229.  
  230.    out_h << tn << " " << n << ";\n";
  231.    if (tn.make_type().is_scalar ())
  232.    {  sos_String bn = tn.make_base_type().make_type_name ();
  233.       out_h << "#define make_" << n << "_object make_" << bn << "_object\n";
  234.       out_h << "#define make_" << n << " make_" << bn << "\n";
  235.    }
  236.  
  237.    TT (genCC_H, T_LEAVE);
  238. }
  239.  
  240. static void enum_type_out (sos_Enum_type et,sos_Bool declare_type)
  241. {
  242.    T_PROC ("enum_type_out");
  243.    TT (genCC_H, T_ENTER);
  244.  
  245.    sos_String n = et.get_name();
  246.    
  247.    if (declare_type)
  248.       out_h << "enum " << n << " { " << et.get_literals() << " };\n";
  249.    else
  250.    {
  251.       sos_Int    size = et.get_object_size ();
  252.       smg_String ht;
  253.       
  254.       if (size == 1)
  255.          ht = INT1;
  256.       else
  257.       {  err_assert (size == 2, "enum_type_out");
  258.          ht = INT2;
  259.       }
  260.    
  261.       out_h << "inline void bcopy_from_" << n << " (void *e,void *c)\n"
  262.         << "{  *(" << ht << "*)c = (" << ht << ")*(" << n << "*)e; }\n"
  263.         << "inline void bcopy_to_"   << n << " (void *e,void *c)\n"
  264.         << "{  *(" << n  << "*)e = (" << n  << ")*(" << ht << "*)c; }\n";
  265.       
  266.       scalar_type_out (et);
  267.    }
  268.  
  269.    TT (genCC_H, T_LEAVE);
  270. }
  271.  
  272. static void scalar_type_out (sos_Schema_type tp)
  273. {
  274.    T_PROC ("scalar_type_out");
  275.    TT (genCC_H, T_ENTER);
  276.  
  277.    sos_String n = tp.get_name();
  278.  
  279.    out_h << "sos_Object" << " make_" << n << "_object(" << n << ");\n";
  280.    out_c << "sos_Object" << " make_" << n << "_object(" << n << " x)\n"
  281.      << "{  return sos_object_from_extern (&x,bcopy_from_" << n << ","
  282.      << _ID << n << "_type); }\n";
  283.  
  284.    out_h << n << " make_" << n << "(" << "sos_Object" << ");\n";
  285.    out_c << n << " make_" << n << "(" << "sos_Object" << " o)\n"
  286.      << "{  " << n << " x;\n"
  287.      << "   sos_extern_from_object (&x,o,bcopy_to_" << n << ","
  288.      << _ID << n << "_type);\n"
  289.      << "   return x; }\n";
  290.  
  291.    TT (genCC_H, T_LEAVE);
  292. }
  293.  
  294. static void union_type_out (sos_Union_type ut)
  295. {
  296.    T_PROC ("union_type_out");
  297.    TT (genCC_H, T_ENTER);
  298.  
  299.    sos_String n = ut.get_name();
  300.    sos_Type_name_List uniteds = ut.get_uniteds();
  301.  
  302.    out_h << "class " << n << " : public " << "sos_Object" << "\n"
  303.          << "{\n"
  304.          << "public:\n   " << n << "() {}\n";
  305.  
  306.    agg_iterate (uniteds, sos_Type_name tn)
  307.    {  out_h << "   " << n << "(" << tn << ");\n";
  308.       out_c << n << "::" << n << "(" << tn << " p) { *(sos_Object*)this=";
  309.       if (tn.make_type().is_scalar ())
  310.          out_c << "make_"
  311.            << tn.make_base_type().make_type_name () << "_object (p)";
  312.       else
  313.          out_c << "p";
  314.       out_c << "; }\n";
  315.    }
  316.    agg_iterate_end (uniteds, tn);
  317.  
  318.    out_h << "   static " << n << " make(" << "sos_Object);\n";
  319.    out_c << n << " " << n << "::make(" << "sos_Object" << " o)\n"
  320.          << "   { " << n << " x; *(sos_Object*)&x=o; return x; }\n";
  321.  
  322.    out_h << "};\n";
  323.  
  324.    TT (genCC_H, T_LEAVE);
  325. }
  326.  
  327. static void class_type_out (sos_Class_type ct)
  328. {
  329.    T_PROC ("class_type_out");
  330.    TT (genCC_H, T_ENTER);
  331.  
  332.    sos_Super_class_List super_closure = ct.get_super_closure();
  333.  
  334.    if (is_root_type (ct))
  335.       id_class_out (ct, super_closure);
  336.    else
  337.       id_univ_methods_out (ct, ct.get_static_methods(), MC_STATIC, TRUE);
  338.    class_out (ct, super_closure);
  339.  
  340.    TT (genCC_H, T_LEAVE);
  341. }
  342.  
  343. static void type_type_out (sos_Schema_type t)
  344. {
  345.    T_PROC ("type_type_out");
  346.    TT (genCC_H, T_ENTER);
  347.  
  348.    sos_String tn = t.make_type_name();
  349.    sos_Typed_id tpid = t.base().typed_id();
  350.    sos_Id id = tpid.get_id();
  351.    sos_Id tp = tpid.get_tp();
  352.  
  353.    out_h << "#define " << _ID << tn
  354.          << "_type sos_Id::make(sos_Container::make(" << sos_Int(id.container())
  355.      << ")," << id.offset() << ")\n"
  356.      << "#define " << tn << "_type sos_type_object("
  357.      << _ID << tn << "_type,sos_Id::make(sos_Container::make("
  358.      << sos_Int(tp.container()) << ")," << tp.offset() << "))\n";
  359.  
  360.    TT (genCC_H, T_LEAVE);
  361. }
  362.  
  363. static void inits_out (sos_Schema_module mdl)
  364. {
  365.    T_PROC ("inits_out");
  366.    TT (genCC_H, T_ENTER);
  367.  
  368.    sos_Schema_type_List type_decls = mdl.get_types();
  369.    sos_String schema_name = mdl.get_name();
  370.  
  371.    out_I << "extern void _" << schema_name << "_init_sos();\n";
  372.  
  373.         // Call module initialization using a constructor.
  374.         // The destructor ensures that each object module added during
  375.         // incremental loading contains at least one destructor.
  376.         // (A missing destructor list '___DTOR_LIST__' caused a
  377.         //  bus error in gcc-ld.)
  378.    out_c << "static struct _sos_init_dummy {\n"
  379.      << "   _sos_init_dummy() {_" << schema_name << "_init_sos();}"
  380.      << "   ~_sos_init_dummy(){}\n   } _sos_dummy;\n";
  381.  
  382.    out_c << "static int _sos_initialized=0;\n"
  383.      << "void _" << schema_name << "_init_sos(){\n"
  384.      << "   if (_sos_initialized) return;\n"
  385.      << "   _sos_initialized=1;\n";
  386.  
  387.    sos_Imports imports = mdl.get_imports();
  388.  
  389.    agg_iterate (imports, sos_Schema_module imported)
  390.    {  out_c << "   _" << imported.get_name() << "_init_sos();\n";
  391.    }
  392.    agg_iterate_end (imports, imported);
  393.   
  394.    agg_iterate (type_decls, sos_Type tp)
  395.    {  if (tp.has_type (sos_Class_type_type))
  396.       {  sos_String tn = sos_Class_type::make(tp).make_type_name();
  397.      sos_Typed_id tpid = tp.typed_id();
  398.      if (is_root_type (tp))
  399.      {  out_c << "   _" << _ID << tn << "_obj=new " << _ID << tn << ";\n"
  400.           << "   _init_meth_" << tpid << "();\n"
  401.           << "   _init_comp_" << tpid << "();\n";
  402.      }
  403.      out_c << "   _init_stat_" << tpid << "();\n"
  404.            << "   _init_new_" << tpid << "();\n";
  405.       }
  406.       else if ((tp.has_type (sos_Extern_type_type) OR
  407.            tp.has_type (sos_Enum_type_type)) AND
  408. #ifdef ATT
  409.            tp.operator!=(get_void_type ())
  410. #else
  411.            tp != get_void_type ()
  412. #endif
  413.           )
  414.       {  sos_String tn = tp.get_name();
  415.      sos_Super_class_List scl = 
  416.         sos_Class_type::make (get_scalar_object_type()).get_super_closure();
  417.  
  418.      agg_iterate (scl, sos_Super_class sc)
  419.      {  sos_Class_type tp = sc.get_super_class();
  420.         out_c << "   " << CCI << "::enter_make_obj("
  421.           << _ID << tp.get_name() << "_type,"
  422.           << _ID << tn << "_type,("
  423.           << _ID << tp.get_name() << "*) new "
  424.           << _ID << "sos_Scalar_object" << ");\n";
  425.      }
  426.      agg_iterate_end (scl, sc);
  427.  
  428.      if (tp.has_type (sos_Extern_type_type))
  429.         out_c << "   " << CCI << "::enter_string_io ("
  430.               << _ID << tn << "_type,(cci_IO_fun)make_string_from_"
  431.                      << tn << "_object,(cci_IO_fun)make_"
  432.                << tn << "_object_from_string);\n";
  433.       }
  434.    }
  435.    agg_iterate_end (type_decls, tp);
  436.  
  437.    out_c << "}\n";
  438.  
  439.    TT (genCC_H, T_LEAVE);
  440. }
  441.  
  442. static void id_class_out (sos_Class_type ct, sos_Super_class_List super_closure)
  443. {
  444.    T_PROC ("id_class_out");
  445.    TT (genCC_H, T_ENTER);
  446.  
  447.    sos_String cn = ct.make_type_name();
  448.    sos_Type_name stn;        // super class
  449.  
  450.    out_I << "class " << _ID << cn;
  451.    id_super_classes_out (ct.get_super_classes());
  452.    out_I << "\n{  friend class " << cn << ";\n";
  453.  
  454.    // sos_Offset-operations:
  455.    agg_iterate (super_closure, sos_Super_class sc)
  456.    {  sos_Int os = sc.get_offset();
  457.       stn = sc.get_super_class().make_root_type();
  458.  
  459.       out_I << "   virtual sos_Offset _offset_" << stn
  460.         << " () { return " << os << "; }\n";
  461.    }
  462.    agg_iterate_end (super_closure, sc);
  463.  
  464.    out_I << "public:\n";
  465.  
  466.    id_cc_methods_out (ct);
  467.    id_predefined_methods_out (ct);
  468.  
  469.    id_method_kind = sos_PUBLIC;
  470.    id_methods_out (ct, ct.get_methods());
  471.    id_methods_out (ct, ct.get_comp_methods());
  472.    id_methods_out (ct, ct.get_static_methods());
  473.  
  474.    out_I << "};\n";
  475.  
  476.    id_univ_methods_out (ct, ct.get_methods(), MC_REGULAR, FALSE);
  477.    id_univ_methods_out (ct, ct.get_comp_methods(), MC_COMP, FALSE);
  478.    id_univ_methods_out (ct, ct.get_static_methods(), MC_STATIC, FALSE);
  479.  
  480.    out_I << "extern " << _ID << cn << " *_" << _ID << cn << "_obj;\n";
  481.    out_c << _ID << cn << " *_" << _ID << cn << "_obj;\n";
  482.  
  483.    TT (genCC_H, T_LEAVE);
  484.  
  485.  
  486.  
  487. static void id_super_classes_out (sos_Type_name_List super_classes)
  488. {
  489.    T_PROC ("id_super_classes_out");
  490.    TT (genCC_H, T_ENTER);
  491.  
  492.    sos_Bool first = TRUE;
  493.    agg_iterate (super_classes, sos_Type_name sc)
  494.    {  if (first)
  495.       {  first = FALSE;
  496.          out_I << ":";
  497.       }
  498.       else
  499.          out_I << ",";
  500.  
  501.       out_I << "virtual public " << _ID << sc.make_root_type();
  502.    }
  503.    agg_iterate_end (super_classes, sc);
  504.  
  505.    TT (genCC_H, T_LEAVE);
  506.  
  507. static void id_cc_methods_out (sos_Class_type ct)
  508. {
  509.    T_PROC ("id_cc_methods_out");
  510.    TT (genCC_H, T_ENTER);
  511.  
  512.    sos_String cn = ct.make_type_name();
  513.  
  514.    // make
  515.    out_I << "   static " << _ID << cn << "* _make(sos_Typed_id&);\n";
  516.    out_c << _ID << cn << "* " << _ID << cn
  517.      << "::_make(sos_Typed_id &tpid)\n"
  518.      << "{  return (" << _ID << cn << "*)" << CCI << "::get_make_obj("
  519.      << _ID << cn << "_type,tpid.get_tp());\n}\n";
  520.  
  521.    // _size
  522.    out_I << "   virtual sos_Offset _size();\n";
  523.    out_c << "sos_Offset " << _ID << cn << "::_size(){return "
  524.      << ct.get_object_size() << ";}\n";
  525.  
  526.    TT (genCC_H, T_LEAVE);
  527. }
  528.  
  529.  
  530. sos_Super_class_List remove_redefined_locals (sos_Super_class_List scl,
  531.                           sos_String  str,
  532.                           sos_Bool    &removed)
  533. {
  534.    T_PROC ("remove_redefined_locals");
  535.    TT (genCC_H, T_ENTER);
  536.  
  537.    sos_Super_class_List result;
  538.    sos_Super_class_List totals;
  539.  
  540.    removed = FALSE;
  541.    result = sos_Super_class_List::create (TEMP_CONTAINER, FALSE);
  542.    totals = sos_Super_class_List::create (TEMP_CONTAINER, FALSE);
  543.  
  544.    agg_iterate_reverse (scl, sos_Super_class sc)
  545.    {  sos_Bool remove = FALSE;
  546.       sos_Class_type sct = sc.get_super_class();
  547.       agg_iterate (totals, sos_Super_class sc1)
  548.       {  if (sc1.get_super_class().is_derived_from (sct))
  549.      {  remove = TRUE;
  550.         break;
  551.      }
  552.       }
  553.       agg_iterate_end (totals, sc1);
  554.       if (remove)
  555.      removed = TRUE;
  556.       else
  557.      result.insert (1, sc);
  558.       if (sct.get_inherited_methods()[str] != NO_OBJECT)
  559.      totals.append (sc);
  560.    }
  561.    agg_iterate_reverse_end (scl, sc);
  562.    totals.destroy();
  563.  
  564.    TT (genCC_H, T_LEAVE);
  565.  
  566.    return result;
  567. }
  568.  
  569. sos_Bool defines_method (sos_Class_type ct, sos_String str)
  570. {
  571.    T_PROC ("defines_method");
  572.    TT (genCC_H, T_ENTER);
  573.  
  574.    sos_Bool result;
  575.    sos_Method_table mt = ct.get_inherited_methods();
  576.    sos_Method_List ml = mt [str];
  577.    result = (sos_Bool)(ml != NO_OBJECT AND NOT ml.get_nth(1).get_is_predefined());
  578.  
  579.    TT (genCC_H, T_LEAVE);
  580.  
  581.    return result;
  582. }
  583.  
  584. static void id_predefined_methods_out (sos_Class_type ct)
  585. {
  586.    T_PROC ("id_predefined_methods_out");
  587.    TT (genCC_H, T_ENTER);
  588.  
  589.    sos_String cn = ct.make_type_name();
  590.    sos_Param_List create_params = ct.get_create_params();
  591.    sos_Super_class_List super_closure = ct.get_super_closure();
  592.    sos_String str;
  593.    sos_Super_class_List total_closure;
  594.    sos_Bool removed;
  595.  
  596.    // _create
  597.    out_I << "   void _create(sos_Typed_id&";
  598.    if (create_params != NO_OBJECT)
  599.       params_out (out_I, create_params, /* no_param_names */ FALSE, 
  600.           /*impl*/ FALSE, /*actual*/ FALSE, /*is_first*/ FALSE);
  601.    out_I << ");\n";
  602.  
  603.    out_c << "void " << _ID << cn << "::_create(sos_Typed_id&_tpid";
  604.    if (create_params != NO_OBJECT)
  605.       params_out (out_c, create_params, /* no_param_names */ FALSE, 
  606.           /*impl*/ TRUE, /*actual*/ FALSE, /*is_first*/ FALSE);
  607.    out_c << "){\n"
  608.      << "   " << cn << " _x=" << cn << "::make(_tpid,this);\n";
  609.  
  610.    agg_iterate (super_closure, sos_Super_class sc)
  611.    {  sos_Class_type sct = sc.get_super_class();
  612.       if (sct.get_has_init_comps())
  613.       {  sos_Expr_List cpl = sc.get_create_params();
  614.  
  615.      out_c << _ID << sct.make_root_type() << "::_create_comps(_x";
  616.      if (cpl != NO_OBJECT)
  617.         exprs_out (out_c, cpl, /*is_first*/ FALSE);
  618.      out_c << ");\n";
  619.       }
  620.    }
  621.    agg_iterate_end (super_closure, sc);
  622.  
  623.    str = smg_String ("local_initialize").make_String (TEMP_CONTAINER);
  624.    agg_iterate (super_closure, sos_Super_class sc)
  625.    {  sos_Class_type sct = sc.get_super_class();
  626.  
  627.       if (sct.get_inherited_methods() [str] != NO_OBJECT)
  628.       {  out_c << _ID << sct.make_root_type()
  629.            << "::local_initialize(_x);\n";
  630.       }
  631.    }
  632.    agg_iterate_end (super_closure, sc);
  633.    str.destroy();
  634.  
  635.    out_c << "}\n";
  636.  
  637.    // _create_comps
  638.    if (ct.get_has_init_comps())
  639.    {  sos_Method_List ml = ct.get_comp_methods();
  640.  
  641.       out_I << "protected:\n"
  642.         << "   static void _create_comps(" << cn;
  643.       if (create_params != NO_OBJECT)
  644.      params_out (out_I, create_params, /* no_param_names */ FALSE,
  645.              /*impl*/ FALSE, /*actual*/ FALSE, /*is_first*/ FALSE);
  646.       out_I << ");\n"
  647.         << "public:\n";
  648.  
  649.       out_c << "void " << _ID << cn << "::_create_comps(" << cn << " _x";
  650.       if (create_params != NO_OBJECT)
  651.      params_out (out_c, create_params, /* no_param_names */ FALSE,
  652.              /*impl*/ TRUE, /*actual*/ FALSE, /*is_first*/ FALSE);
  653.       out_c << "){\n   ";
  654.  
  655.       agg_iterate (ml, sos_Method m)
  656.       {  sos_Comp_method cm = sos_Comp_method::make (m);
  657.      if (cm.get_is_set())
  658.      {  sos_Expr e = cm.get_init_expr();
  659.         if (e != NO_OBJECT)
  660.         {  out_c << "   _x." << cm.get_name() << "(";
  661.            if (e.has_type (sos_Identifier_type))
  662.               if (smg_String (sos_Identifier::make (e).get_id()).
  663.               equal ("NO_OBJECT"))
  664.              out_c << cm.get_params().get_nth(1).get_type_name()
  665.                << "::make(NO_OBJECT)";
  666.      
  667.               else
  668.              out_c << e;
  669.            else
  670.           out_c << e;
  671.            out_c << ");\n";
  672.         }
  673.      }
  674.       }
  675.       agg_iterate_end (ml, m);
  676.       out_c << "}\n";
  677.    }
  678.  
  679.    // _copy
  680.    out_I << "   void _copy(sos_Typed_id&," << cn << ");\n";
  681.  
  682.    out_c << "void " << _ID << cn << "::_copy(sos_Typed_id&_tpid,"
  683.      << cn << " y){\n"
  684.      << "   " << cn << " x=" << cn << "::make(_tpid,this);\n";
  685.  
  686.    agg_iterate (super_closure, sos_Super_class sc)
  687.    {  sos_Class_type sct = sc.get_super_class();
  688.       if (sct.get_has_init_comps())
  689.       {  sos_Expr_List cpl = sc.get_create_params();
  690.  
  691.      out_c << _ID << sct.make_root_type() << "::_copy_comps(x,y);\n";
  692.       }
  693.    }
  694.    agg_iterate_end (super_closure, sc);
  695.  
  696.    str = smg_String ("local_initialize").make_String (TEMP_CONTAINER);
  697.    agg_iterate (super_closure, sos_Super_class sc)
  698.    {  sos_Class_type sct = sc.get_super_class();
  699.  
  700.       if (sct.get_inherited_methods() [str] != NO_OBJECT)
  701.       {  out_c << _ID << sct.make_root_type()
  702.            << "::local_initialize(x);\n";
  703.       }
  704.    }
  705.    agg_iterate_end (super_closure, sc);
  706.    str.destroy();
  707.  
  708.    out_c << "}\n";
  709.  
  710.    // _copy_comps
  711.    if (ct.get_has_init_comps())
  712.    {  sos_Method_List ml = ct.get_comp_methods();
  713.  
  714.       out_I << "protected:\n"
  715.         << "   static void _copy_comps(" << cn << "," << cn << ");\n"
  716.         << "public:\n";
  717.  
  718.       out_c << "void " << _ID << cn << "::_copy_comps("
  719.         << cn << " x," << cn << " y){\n";
  720.  
  721.       agg_iterate (ml, sos_Method m)
  722.       {  sos_Comp_method cm = sos_Comp_method::make (m);
  723.      if (cm.get_is_set())
  724.      {  sos_Expr e = cm.get_init_expr();
  725.         if (e != NO_OBJECT)
  726.         {  sos_Cstring mn = cm.get_name().make_Cstring();
  727.            out_c << "   x." << mn << "(y.";
  728.            mn[0] = 'g';
  729.            out_c << mn << "());\n";
  730.            delete mn;
  731.         }
  732.      }
  733.       }
  734.       agg_iterate_end (ml, m);
  735.       out_c << "}\n";
  736.    }
  737.  
  738.    // _clone
  739.    out_I << "   virtual sos_Object _clone(sos_Typed_id&,sos_Container);\n";
  740.  
  741.    out_c << "sos_Object " << _ID << cn
  742.         << "::_clone(sos_Typed_id&_tpid,sos_Container cnt){\n"
  743.      << "   " << cn << " _x=" << cn << "::make(_tpid,this);\n"
  744.      << "   return " << cn << "::copy(_x,cnt);}\n";
  745.  
  746.    // destroy
  747.    out_I << "   virtual void destroy(sos_Typed_id&);\n";
  748.  
  749.    out_c << "void " << _ID << cn << "::destroy(sos_Typed_id&_tpid){\n";
  750.  
  751.    str = smg_String ("local_finalize").make_String (TEMP_CONTAINER);
  752.    agg_iterate_reverse (super_closure, sos_Super_class sc)
  753.    {  sos_Class_type sct = sc.get_super_class();
  754.  
  755.       if (sct.get_inherited_methods() [str] != NO_OBJECT)
  756.       {  sos_Type_name stn = sct.make_root_type();
  757.      out_c << "   " << _ID << stn
  758.            << "::local_finalize(" << stn << "::make(_tpid,this));\n";
  759.       }
  760.    }
  761.    agg_iterate_reverse_end (super_closure, sc);
  762.    str.destroy();
  763.  
  764.    out_c << "   _tpid.container().deallocate(_tpid.offset(),"
  765.      << ct.get_object_size() << ");}\n";
  766.  
  767.    // assign
  768.    out_I << "   virtual void assign(sos_Typed_id&,sos_Object);\n";
  769.  
  770.    out_c << "void " << _ID << cn
  771.          << "::assign(sos_Typed_id&_tpid,sos_Object o){\n   "
  772.      << cn << " x=" << cn << "::make(_tpid,this);\n";
  773.  
  774.    str = smg_String ("total_assign").make_String (TEMP_CONTAINER);
  775.    total_closure = remove_redefined_locals (super_closure, str, removed);
  776.    agg_iterate (total_closure, sos_Super_class sc)
  777.    {  sos_Class_type sct = sc.get_super_class().root_class();
  778.       out_c << "   " << _ID << sct.make_type_name() << "::";
  779.       if (removed AND sct.get_inherited_methods()[str] != NO_OBJECT)
  780.      out_c << "total";
  781.       else
  782.      out_c << "local";
  783.       out_c << "_assign(x,o);\n";
  784.    }
  785.    agg_iterate_end (total_closure, sc);
  786.    out_c << "}\n";
  787.    str.destroy();
  788.    total_closure.destroy();
  789.  
  790.    str = smg_String ("local_assign").make_String (TEMP_CONTAINER);
  791.    if (NOT defines_method (ct, str))
  792.    {  out_I << "   static void local_assign(" << cn << ",sos_Object);\n";
  793.  
  794.       out_c << "void " << _ID << cn << "::local_assign(" << cn
  795.         << " x,sos_Object o){\n";
  796.       if (ct.get_local_size() > 0)
  797.       {  out_c << "   " << cn << " y=" << cn << "::make(o);\n"
  798.            << "   y.container().copy(y.offset()+y._ref->_offset_" << cn
  799.            << "()," << ct.get_local_size()
  800.            << ",x.container(),x.offset()+x._ref->_offset_" << cn << "());";
  801.       }
  802.       out_c << "}\n";
  803.    }
  804.    str.destroy();
  805.  
  806.    // equal
  807.    out_I << "   virtual sos_Bool equal(sos_Typed_id&,sos_Object,sos_Eq_kind=EQ_STRONG);\n";
  808.  
  809.    out_c << "sos_Bool " << _ID << cn
  810.         << "::equal(sos_Typed_id&_tpid,sos_Object o,sos_Eq_kind eq_kind){\n   "
  811.      << cn << " x=" << cn << "::make(_tpid,this);\n";
  812.  
  813.    str = smg_String ("total_equal").make_String (TEMP_CONTAINER);
  814.    total_closure = remove_redefined_locals (super_closure, str, removed);
  815.    agg_iterate (total_closure, sos_Super_class sc)
  816.    {  sos_Class_type sct = sc.get_super_class().root_class();
  817.       out_c << "   if (! " << _ID << sct.make_type_name() << "::";
  818.       if (removed AND sct.get_inherited_methods()[str] != NO_OBJECT)
  819.      out_c << "total";
  820.       else
  821.      out_c << "local";
  822.       out_c << "_equal(x,o,eq_kind)) return FALSE;\n";
  823.    }
  824.    agg_iterate_end (total_closure, sc);
  825.    out_c << "   return TRUE;}\n";
  826.    str.destroy();
  827.    total_closure.destroy();
  828.  
  829.    str = smg_String ("local_equal").make_String (TEMP_CONTAINER);
  830.    if (NOT defines_method (ct, str))
  831.    {  out_I << "   static sos_Bool local_equal(" << cn << ",sos_Object,sos_Eq_kind);\n";
  832.  
  833.       out_c << "sos_Bool " << _ID << cn << "::local_equal(" << cn;
  834.  
  835.       if (ct.get_local_size() > 0)
  836.       {  sos_Bool is_generic_class = (sos_Bool)
  837.                            (ct.get_gen_params() != NO_OBJECT);
  838.          out_c << " x,sos_Object o,sos_Eq_kind eq_kind){\n"
  839.            << "   if (eq_kind==EQ_STRONG) {if (!o.has_type(";
  840.      
  841.      if (is_generic_class)
  842.         out_c << "x.type()";
  843.      else
  844.         out_c << cn << "_type";
  845.  
  846.      out_c << ")) return FALSE;}\n   else if (!o.isa(";
  847.  
  848.      if (is_generic_class)
  849.         out_c << "x.type()";
  850.      else
  851.         out_c << cn << "_type";
  852.  
  853.      out_c << ")) return FALSE;\n"
  854.            << "   " << cn << " y=" << cn << "::make(o);\n"
  855.            << "   return (sos_Bool)x.container().equal("
  856.            << "x.offset()+x._ref->_offset_" << cn << "()," 
  857.            << ct.get_local_size()
  858.            << ",y.container(),y.offset()+y._ref->_offset_" << cn << "());";
  859.       }
  860.       else
  861.      out_c << ",sos_Object,sos_Eq_kind) { return TRUE;";
  862.       out_c << "}\n";
  863.    }
  864.    str.destroy();
  865.  
  866.    // hash_value
  867.    out_I << "   virtual sos_Int hash_value(sos_Typed_id&);\n";
  868.  
  869.    out_c << "sos_Int " << _ID << cn << "::hash_value(sos_Typed_id&_tpid){\n   "
  870.      << cn << " x=" << cn << "::make(_tpid,this);\n   sos_Int result=0;\n";
  871.  
  872.    str = smg_String ("total_hash_value").make_String (TEMP_CONTAINER);
  873.    total_closure = remove_redefined_locals (super_closure, str, removed);
  874.    agg_iterate (total_closure, sos_Super_class sc)
  875.    {  sos_Class_type sct = sc.get_super_class().root_class();
  876.       out_c << "   result ^= " << _ID << sct.make_type_name() << "::";
  877.       if (removed AND sct.get_inherited_methods()[str] != NO_OBJECT)
  878.      out_c << "total";
  879.       else
  880.      out_c << "local";
  881.       out_c << "_hash_value(x);\n";
  882.    }
  883.    agg_iterate_end (total_closure, sc);
  884.    out_c << "   return result;}\n";
  885.    str.destroy();
  886.    total_closure.destroy();
  887.  
  888.    str = smg_String ("local_hash_value").make_String (TEMP_CONTAINER);
  889.    if (NOT defines_method (ct, str))
  890.    {  out_I << "   static sos_Int local_hash_value(" << cn << ");\n";
  891.  
  892.       out_c << "sos_Int " << _ID << cn << "::local_hash_value(" << cn << " x){\n"
  893.         << "   return x.container().hash_value(x.offset()+x._ref->_offset_"
  894.         << cn << "()," << ct.get_local_size() << ");}\n";
  895.    }
  896.    str.destroy();
  897.  
  898.    TT (genCC_H, T_LEAVE);
  899. }
  900.  
  901. static void id_methods_out (sos_Class_type ct, sos_Method_List ml)
  902. {
  903.    T_PROC ("id_methods_out");
  904.    TT (genCC_H, T_ENTER);
  905.  
  906.    agg_iterate (ml, sos_Method m1)
  907.    {  sos_Method m = m1.get_generated_from();
  908.       if (m == NO_OBJECT) m = m1;
  909.  
  910.       sos_Method_kind mk = m.get_kind();
  911.       if (mk != id_method_kind)
  912.       {  id_method_kind = mk;
  913.      out_I << id_method_kind << ":\n";
  914.       }
  915.  
  916.       if (m.has_type (sos_Comp_method_type))
  917.      id_comp_method_out (ct, sos_Comp_method::make (m));
  918.       else
  919.      id_method_out (ct, m);
  920.    }
  921.    agg_iterate_end (ml, m);
  922.    TT (genCC_H, T_LEAVE);
  923. }
  924.  
  925. static void id_method_out (sos_Class_type, sos_Method m)
  926.    T_PROC ("id_method_out");
  927.    TT (genCC_H, T_ENTER);
  928.  
  929.    sos_String     cn;
  930.    sos_String      mn          = m.get_name();
  931.    sos_Param_List params      = m.get_params();
  932.    sos_Type_name  result_type = m.get_result_type();
  933.    sos_Bool      is_abstract = m.get_is_abstract();
  934.    sos_Bool      is_static   = m.get_is_static();
  935.    sos_Bool      is_operator = m.get_is_operator();
  936.  
  937.    TT(genCC_L, TsS (mn));
  938.  
  939.    if (NOT m.get_is_predefined())
  940.    {  if (is_static)
  941.      out_I << "   static ";
  942.       else
  943.      out_I << "   virtual ";
  944.  
  945.       if (is_operator)
  946.          mn = cci_Method_impl::operator_string (mn);
  947.  
  948.       out_I << result_type << " " << mn << "(";
  949.       if (is_abstract)
  950.       {  
  951.      cn = m.get_defined_in().make_root_type().make_type_name();
  952.      out_c << result_type << " "
  953.            << _ID << cn << "::" << mn << "(";
  954.       }
  955.  
  956.       sos_Bool is_first;
  957.       if (is_static)
  958.      is_first = TRUE;
  959.       else
  960.       {  is_first = FALSE;
  961.      out_I << "sos_Typed_id&";
  962.      if (is_abstract)
  963.         out_c << "sos_Typed_id&";
  964.       }
  965.  
  966.       params_out (out_I, params, /* no_param_names */ FALSE, 
  967.           /*impl*/ FALSE, /*actual*/ FALSE, is_first); 
  968.       out_I << ");\n";
  969.  
  970.       if (is_abstract)
  971.       {
  972.      params_out (out_c, params, /* no_param_names */ TRUE,
  973.              /*impl*/ FALSE, /*actual*/ FALSE, is_first);
  974.      out_c << ") ";
  975.  
  976.      // now create function body
  977.      out_c << "{\n   err_raise_abstract_method (\"" << cn << "::" << mn
  978.            << "\"); ";
  979. #ifdef ATT
  980.      if (result_type.operator!= (get_void_type()))
  981. #else
  982.      if (result_type != get_void_type())
  983. #endif
  984.      {
  985.         out_c << "\n   return ";
  986.         // Now check if result type is scalar type. If so, cast 0 into
  987.         // the according type.
  988.         if (result_type.make_base_type().has_type (sos_Extern_type_type) OR
  989.              result_type.make_base_type().has_type (sos_Enum_type_type))
  990.            out_c << "(" << result_type << ") 0; ";
  991.         else
  992.            out_c << result_type << "::make(NO_OBJECT); ";
  993.      }
  994.      out_c << "}\n";
  995.       }
  996.       if (is_operator)
  997.      mn.destroy();
  998.    }
  999.  
  1000.    TT (genCC_H, T_LEAVE);
  1001. }
  1002.  
  1003. static void id_comp_method_out (sos_Class_type ct, sos_Comp_method cm)
  1004. {  
  1005.    T_PROC ("id_comp_method_out");
  1006.    TT (genCC_H, T_ENTER);
  1007.  
  1008.    sos_String     cn    = ct.make_type_name();
  1009.    sos_String     n    = cm.get_name();
  1010.    sos_Bool     is_set = cm.get_is_set();
  1011.    sos_Type_name tn     = (is_set) ? cm.get_params().get_nth(1).get_type_name()
  1012.                    : cm.get_result_type();
  1013.    sos_Int     size;
  1014.  
  1015.    sos_Schema_type bt = tn.make_base_type ();
  1016.    sos_Bool is_scalar = bt.is_scalar ();
  1017.    sos_Bool is_local  = cm.get_is_local();
  1018.    smg_String ht;
  1019.  
  1020.    if (is_scalar)
  1021.    {  size = bt.get_object_size();
  1022.       ht   = bt.get_name();
  1023.    }
  1024.    else if (is_local)
  1025.    {  size = SOS_OFFSET_SIZE;
  1026.       ht   = "sos_Offset";
  1027.    }
  1028.    else
  1029.    {  size = SOS_TYPED_ID_SIZE;
  1030.       ht   = "sos_Typed_id";
  1031.    }
  1032.    // ???
  1033.    // Added the keywords 'virtual' to set_.../get_... declarations
  1034.    // 15/8/91, Dietmar
  1035.  
  1036.    if (is_set)
  1037.    {  out_I << "   virtual void " << n << "(sos_Typed_id&," << tn << ");\n";
  1038.       out_c << "void " << _ID << cn << "::" << n
  1039.         << "(sos_Typed_id&_tpid," << tn
  1040.         << " a){\n   union {" << ht << " x; char c[" << size << "];} u;\n";
  1041.       if (is_scalar)
  1042.      out_c << "   bcopy_from_" << ht << "(&a,&u);\n";
  1043.       else if (is_local)
  1044.      out_c << "   " << ht << " x=sos_local_offset(a,_tpid.container());\n"
  1045.            << "   bcopy_from_" << ht << "(&x,&u);\n";
  1046.       else
  1047.      out_c << "   " << ht << " x=a.typed_id();\n"
  1048.            << "   bcopy_from_" << ht << "(&x,&u);\n";
  1049.       out_c << "   _tpid.container().write(_tpid.offset() + _offset_" << cn
  1050.         << "() + " << cm.get_offset() << "," << size << ",&u);\n}\n";
  1051.    }
  1052.    else
  1053.    {  out_I << "   virtual " << tn << " " << n << "(sos_Typed_id&);\n";
  1054.  
  1055.       out_c << tn << " " << _ID << cn << "::" << n
  1056.         << "(sos_Typed_id&_tpid)\n"
  1057.         << "{  union {" << ht << " x; char c[" << size << "];} u; "
  1058.         << ht << " a;\n"
  1059.         << "   _tpid.container().read(_tpid.offset()+_offset_" << cn
  1060.         << "()+" << cm.get_offset() << "," << size << ",&u);\n"
  1061.         << "   bcopy_to_" << ht << "(&a,&u);\n";
  1062.       if (is_scalar)
  1063.      out_c << "   return a;"; 
  1064.       else if (is_local)
  1065.      out_c << "   return " << bt.make_type_name()
  1066.            << "::make(sos_make_local_typed_id(a,_tpid.container()));";
  1067.       else
  1068.      out_c << "   return " << bt.make_type_name() << "::make(a);";
  1069.       out_c << "}\n"; 
  1070.    }
  1071.  
  1072.    TT (genCC_H, T_LEAVE);
  1073. }
  1074.  
  1075. static void id_univ_method_out (sos_Class_type ct,
  1076.                 sos_Method     m,
  1077.                 sos_Bool       is_static)
  1078. // modified: 13.08.91 (bs)
  1079. // to avoid the effects of a GNU (1.37 & 1.39) compiler error
  1080. {
  1081.    T_PROC ("id_univ_method_out");
  1082.    TT (genCC_H, T_ENTER);
  1083.  
  1084.    sos_String     cn          = ct.make_type_name();
  1085.    sos_String     mn          = m.get_name();
  1086.    sos_Param_List params      = m.get_params();
  1087.    sos_Type_name  result_type = m.get_result_type();
  1088.    sos_Bool       is_operator = m.get_is_operator();
  1089.    sos_Int        card        = params.card();
  1090.  
  1091. #ifdef ATT
  1092.    sos_Bool is_void_result = result_type.operator==(get_void_type());
  1093. #else
  1094.    sos_Bool is_void_result = result_type == get_void_type();
  1095. #endif
  1096.                                               // out Header
  1097.    out_c << "static sos_Object _univ_"
  1098.         << cci_Method_impl::make_impl (m).typed_id()
  1099.         << "(sos_Object";
  1100.    
  1101.    if (NOT is_static)
  1102.       out_c << " o";
  1103.   
  1104.    out_c << ",sos_Object_Array";
  1105.    if (params.card() > 0)
  1106.       out_c << " p";
  1107.  
  1108.    out_c << "){\n   ";                        // out Implementation
  1109.  
  1110.    sos_Int ref_params = 0;
  1111.  
  1112.    if (card > 0)
  1113.    {
  1114.       out_c << "sos_Object ";
  1115.       for (sos_Int j=1; j <= card; j++)
  1116.       { 
  1117.         if (params.get_nth(j).get_is_ref())
  1118.        ref_params++;
  1119.         out_c << "o" << j << "=p[" << j-1;
  1120.            // The storing of the value of 'p' would only
  1121.            // be necessary for parameters passed by reference.
  1122.            // It is done here for all parameters, to avoid a 
  1123.            // GNU(1.39) compiler error. (bs)
  1124.          if (j < card)
  1125.             out_c << "], ";
  1126.          else
  1127.             out_c << "];\n   ";
  1128.       }
  1129.    }
  1130.    TT (genCC_L, TXT ("No. of reference parameters"); TI(ref_params));
  1131.  
  1132.    if (NOT is_void_result)
  1133.    {  
  1134.       if (ref_params NEQ 0) // (bs)
  1135.      out_c << "sos_Object r=";
  1136.       else
  1137.          out_c << "return ";
  1138.       
  1139.       if (result_type.make_type().is_scalar())
  1140.          out_c << "::make_" << result_type << "_object";
  1141.       else
  1142.       {
  1143. #ifdef ATT
  1144.          if (result_type.make_type().operator!= (sos_Object_type))
  1145. #else
  1146.          if (result_type.make_type() != sos_Object_type) // (bs)
  1147. #endif
  1148.             out_c << "sos_Object::make";
  1149.       }
  1150.       out_c << "(";
  1151.    }  
  1152.  
  1153.    if (is_static)
  1154.       out_c << cn << "::";
  1155.    else
  1156.       out_c << cn << "::make (o).";
  1157.    if (is_operator)
  1158.       out_c << "operator";
  1159.  
  1160.    out_c << mn << "(";
  1161.  
  1162.    sos_Bool first = TRUE;
  1163.  
  1164.    for (sos_Int i=1; i<=card; i++)
  1165.    {  sos_Param       p   = params.get_nth(i);
  1166.       sos_Schema_type pt  = p.get_type_name().make_base_type();
  1167.       sos_String      ptn = pt.make_type_name();
  1168.  
  1169.       if (NOT first)
  1170.      out_c << ",";
  1171.       else
  1172.      first = FALSE;
  1173.  
  1174.       if (pt.is_scalar ())
  1175.      out_c << "::make_" << ptn;
  1176.       else
  1177.      out_c << ptn << "::make";
  1178.          out_c << "(o" << i << ")"; 
  1179.       // out_c << "(p[" << i-1 << "])"; replaced 13.08.91 (bs)
  1180.    }
  1181.    out_c << ")";
  1182.  
  1183.    if (NOT is_void_result)
  1184.       out_c << ")";
  1185.  
  1186.    if (ref_params NEQ 0)
  1187.    {
  1188.       out_c << ";\n   ";
  1189.       sos_Int done_ref_params = 0;
  1190.       for (sos_Int k = 1; k <= card; k++)  // write back reference params
  1191.       { 
  1192.         if (params.get_nth(k).get_is_ref())
  1193.         {
  1194.            out_c << "p.set_nth(" << k-1 << ",o" << k << ")";
  1195.        done_ref_params++;
  1196.            if (done_ref_params NEQ ref_params)
  1197.           out_c << "; ";
  1198.         }
  1199.       }
  1200.    }
  1201.  
  1202.    if (is_void_result)
  1203.       out_c << ";\n   return NO_OBJECT";
  1204.    else
  1205.       if (ref_params NEQ 0)
  1206.          out_c << ";\n   return r";
  1207.  
  1208.    out_c << ";}\n";
  1209.  
  1210.    TT (genCC_H, T_LEAVE);
  1211. }
  1212.  
  1213.  
  1214. static void id_univ_methods_out (sos_Class_type   ct,
  1215.                  sos_Method_List  ml,
  1216.                  Method_class     mc,
  1217.                  sos_Bool         only_predefined)
  1218. {
  1219.    T_PROC ("id_univ_methods_out");
  1220.    TT (genCC_H, T_ENTER; TB (only_predefined));
  1221.  
  1222.    sos_String cn = ct.make_type_name();
  1223.  
  1224.    agg_iterate (ml, sos_Method m)
  1225.    {  if (m.get_kind() == sos_PUBLIC AND
  1226.       (NOT only_predefined OR m.get_is_predefined()))
  1227.      id_univ_method_out (ct, m, (sos_Bool)(mc == MC_STATIC));
  1228.    }
  1229.    agg_iterate_end (ml, m);
  1230.    sos_Typed_id tpid = ct.typed_id();
  1231.  
  1232.    out_c << "static void _init_";
  1233.    switch (mc)
  1234.    {  case MC_REGULAR: out_c << "meth_";  break;
  1235.       case MC_COMP:    out_c << "comp_";  break;
  1236.       case MC_STATIC:  out_c << "stat_";  break;
  1237.    }
  1238.    out_c << tpid << "(){\n";
  1239.  
  1240.    if (NOT only_predefined)
  1241.    {  agg_iterate (ml, sos_Method m)
  1242.       {  sos_Typed_id mtpid = cci_Method_impl::make_impl (m).typed_id();
  1243.      if (m.get_kind() == sos_PUBLIC AND
  1244.          (NOT only_predefined OR m.get_is_predefined()))
  1245.         out_c << "   " << CCI
  1246.               << "::enter_fun(sos_Id::make(sos_Container::make("
  1247.               << sos_Int(mtpid.container()) << "),"
  1248.               << mtpid.offset() << "),(cci_Fun)_univ_" << mtpid << ");\n";
  1249.       }
  1250.       agg_iterate_end (ml, m);
  1251.    }
  1252.  
  1253.    out_c << "}\n";
  1254.  
  1255.    TT (genCC_H, T_LEAVE);
  1256. }
  1257.  
  1258. static void class_out (sos_Class_type ct, sos_Super_class_List super_closure) 
  1259. {
  1260.    T_PROC ("class_out");
  1261.    TT (genCC_H, T_ENTER);
  1262.  
  1263.    sos_String cn = ct.make_type_name();
  1264.    sos_Type_name rtn = ct.make_root_type();
  1265.  
  1266.    init_out (ct, super_closure);
  1267.  
  1268.    out_h << "class " << cn << ": public sos_Root_class \n"
  1269.      << "{  friend class " << _ID << rtn << ";\n"
  1270.      << "   class " << _ID << rtn << "* " << "_ref;\n";
  1271.  
  1272.    // conversion to super classes
  1273.    out_h << "public:\n";
  1274.    agg_iterate (super_closure, sos_Super_class sc)
  1275.    {  sos_Class_type sct = sc.get_super_class();
  1276. #ifdef ATT
  1277.       if (ct.operator!=(sct))
  1278. #else
  1279.       if (ct != sct)
  1280. #endif
  1281.       {  sos_String scn = sct.make_type_name();
  1282.      out_h << "   operator " << scn << " ()";
  1283.      if (gen_inline)
  1284.         out_h << "{return(" << scn << "::make(_tpid,_ref));}";
  1285.      else
  1286.         out_c << cn << "::operator " << scn << "()"
  1287.           << "{return(" << scn << "::make(_tpid,_ref));}\n";
  1288.      out_h << ";\n";
  1289.       }
  1290.       if (NOT is_root_type (sct))
  1291.       {  sos_Type_name scrtn = sct.make_root_type();
  1292.  
  1293.      out_h << "   operator " << scrtn << " ()";
  1294.      if (gen_inline)
  1295.         out_h << "{return(" << scrtn << "::make(_tpid,_ref));}";
  1296.      else
  1297.         out_c << cn << "::operator " << scrtn << "()"
  1298.           << "{return(" << scrtn << "::make(_tpid,_ref));}\n";
  1299.      out_h << ";\n";
  1300.       }
  1301.    }
  1302.    agg_iterate_end (super_closure, sc);
  1303.  
  1304.    friends_out (ct);
  1305.  
  1306.    method_kind = sos_PUBLIC;
  1307.    cc_methods_out (ct);
  1308.    ccc_methods_out (ct);
  1309.    inherited_methods_out (ct);
  1310.    out_h << "};\n";
  1311.  
  1312.    TT (genCC_H, T_LEAVE);
  1313. }
  1314.  
  1315. static void init_out (sos_Class_type ct, sos_Super_class_List super_closure) 
  1316. {
  1317.    T_PROC ("init_out");
  1318.    TT (genCC_H, T_ENTER);
  1319.  
  1320.    sos_String cn = ct.make_type_name();
  1321.    sos_Type_name gtn = ct.make_root_type();
  1322.    sos_Typed_id tpid = ct.typed_id();
  1323.  
  1324.    out_c << "static void _init_new_" << tpid << "(){\n";
  1325.    agg_iterate (super_closure, sos_Super_class sc)
  1326.    {  sos_Type_name sgtn = sc.get_super_class().make_root_type();
  1327.  
  1328.       out_c << "   " << CCI << "::enter_make_obj("
  1329.             << _ID << sgtn << "_type,"
  1330.             << _ID << cn << "_type,("
  1331.         << _ID << sgtn << "*)_" << _ID << gtn << "_obj);\n";
  1332.    }
  1333.    agg_iterate_end (super_closure, sc)
  1334.    out_c << "}\n";
  1335.  
  1336.    TT (genCC_H, T_LEAVE);
  1337. }
  1338.  
  1339. static void friends_out (sos_Class_type ct)
  1340. {
  1341.    T_PROC ("friends_out");
  1342.    TT (genCC_H, T_ENTER);
  1343.  
  1344.    sos_Type_name_List tnl = ct.get_friends();
  1345.    agg_iterate (tnl, sos_Type_name tn)
  1346.    {  out_h << "   friend class " << _ID << tn.make_type_name()  << ";\n";
  1347.    }
  1348.    agg_iterate_end (tnl, tn);
  1349.  
  1350.    TT (genCC_H, T_LEAVE);
  1351. }
  1352.  
  1353. static void ccc_methods_out (sos_Class_type ct)
  1354. {
  1355.    T_PROC ("ccc_method_out");
  1356.    TT (genCC_H, T_ENTER);
  1357.  
  1358.    sos_Param_List create_params = ct.get_create_params();
  1359.    sos_String cn = ct.make_type_name();
  1360.    sos_Type_name rtn = ct.make_root_type();
  1361.  
  1362.    // create
  1363.    out_h << "   static " << cn << " create(sos_Container";
  1364.    if (create_params != NO_OBJECT)
  1365.       params_out (out_h, create_params, /* no_param_names */ FALSE, 
  1366.               /*impl*/ FALSE, /*actual*/ FALSE, /*is_first*/ FALSE);
  1367.    out_h << ");\n";
  1368.  
  1369.    out_c << cn << " " << cn << "::create(sos_Container _cnt";
  1370.    if (create_params != NO_OBJECT)
  1371.       params_out (out_c, create_params, /* no_param_names */ FALSE, 
  1372.               /*impl*/ TRUE, /*actual*/ FALSE, /*is_first*/ FALSE);
  1373.    out_c << "){\n"
  1374.      << "   " << cn << " _x=" << cn
  1375.      << "::make(sos_Typed_id::allocate(" << cn << "_type,_cnt,"
  1376.      << ct.get_object_size() << "));\n"
  1377.      << "   _x._ref->_create(_x._tpid";
  1378.    if (create_params != NO_OBJECT)
  1379.       params_out (out_c, create_params, /* no_param_names */ FALSE, 
  1380.               /*impl*/ TRUE, /*actual*/ TRUE, /*is_first*/ FALSE);
  1381.    out_c << ");\n"
  1382.      << "   return _x;\n}\n";
  1383.  
  1384.    // copy
  1385.    out_h << "   static " << cn << " copy(" << cn << ",sos_Container);\n";
  1386.    out_c << cn << " " << cn << "::copy(" << cn << " y,sos_Container cnt){\n   "
  1387.      << cn << " x=" << cn
  1388.      << "::make(sos_Typed_id::allocate(" << cn << "_type,cnt,"
  1389.      << ct.get_object_size() << "));\n"
  1390.      << "   x._ref->_copy(x._tpid,y);\n   x.assign(y);\n   return x;\n}\n";
  1391.  
  1392.    // clone
  1393.    out_h << "   static " << cn << " clone(" << cn << ",sos_Container);\n";
  1394.    out_c << cn << " " << cn << "::clone(" << cn << " o,sos_Container cnt){\n"
  1395.      << "   return " << cn << "::make (o._ref->_clone(o._tpid,cnt));\n}\n";
  1396.  
  1397.    TT (genCC_H, T_LEAVE);
  1398. }
  1399.  
  1400. static void cc_methods_out (sos_Class_type ct)
  1401. {
  1402.    T_PROC ("cc_methods_out");
  1403.    TT (genCC_H, T_ENTER);
  1404.  
  1405.    sos_String cn = ct.make_type_name();
  1406.    sos_Type_name rtn = ct.make_root_type();
  1407.  
  1408.  
  1409.    // composition
  1410.  
  1411.    out_h << "   static " << cn << " make(sos_Typed_id&);\n";
  1412.    out_c << cn << " " << cn << "::make(sos_Typed_id&p){\n   "
  1413.      << cn << " o; o._tpid=p;\n   "
  1414.      << "o._ref=" << _ID << rtn << "::_make(p); return o;}\n";
  1415.  
  1416.    out_h << "   static " << cn << " make(sos_Typed_id&p,"
  1417.         << _ID << rtn << "*r){\n   "
  1418.      << cn << " o; o._tpid = p; o._ref=r; return o;}\n";
  1419.  
  1420.    // make
  1421.    out_h << "   static " << cn << " make(sos_Root_class&);\n";
  1422.    out_c << cn << " " << cn << "::make(sos_Root_class& o)" 
  1423.          << "{return " << cn << "::make(o.typed_id());}\n";
  1424.  
  1425.    // _size
  1426.    out_h << "   sos_Offset _size();\n";
  1427.    out_c << "   sos_Offset " << cn << "::_size(){return _ref->_size();}\n";
  1428.  
  1429.    TT (genCC_H, T_LEAVE);
  1430. }
  1431.  
  1432. static void inherited_methods_out (sos_Class_type ct)
  1433. {
  1434.    T_PROC ("inherited_methods_out");
  1435.    TT (genCC_H, T_ENTER);
  1436.  
  1437.    sos_Method_table mt = ct.get_inherited_methods();
  1438.    sos_Bool is_root = is_root_type (ct);
  1439.  
  1440.    agg_iterate_association (mt, sos_String name, sos_Method_List ml)
  1441.    {  agg_iterate (ml, sos_Method m)
  1442.       {  sos_Method_kind mk = m.get_kind();
  1443.      if ((is_root OR mk == sos_PUBLIC) AND NOT is_ccc_method (m))
  1444.      {  if (mk != method_kind)
  1445.         {  method_kind = mk;
  1446.            out_h << method_kind << ":\n";
  1447.         }
  1448.         method_out (ct, m);
  1449.      }
  1450.       }
  1451.       agg_iterate_end (ml, m);
  1452.    }
  1453.    agg_iterate_association_end (mt, name, ml);
  1454.  
  1455.    TT (genCC_H, T_LEAVE);
  1456. }
  1457.  
  1458. void method_out (sos_Class_type ct, sos_Method m)
  1459. {
  1460.    sos_String cn = ct.make_type_name();
  1461.    sos_String mn = m.get_name();
  1462.    sos_Type_name rtn = m.get_result_type();
  1463.    sos_Param_List params = m.get_params();
  1464.    sos_Bool is_static = m.get_is_static();
  1465.    sos_Bool is_operator = m.get_is_operator();
  1466.    sos_Type_name gtn = ct.make_root_type();
  1467.    sos_Method gm = m.get_generated_from();
  1468.    sos_Bool is_generated = gm != NO_OBJECT;
  1469.  
  1470.    if (is_static)
  1471.       out_h << "   static ";
  1472.    else
  1473.       out_h << "   ";
  1474.    out_h << rtn << " ";
  1475.    if (is_operator)
  1476.       out_h << "operator";
  1477.    out_h << mn << "(";
  1478.    params_out (out_h, params, /* no_param_names */ FALSE, 
  1479.            /*impl*/ FALSE, /*actual*/ FALSE); out_h << ");\n";
  1480.  
  1481.    out_c << rtn << " " << cn << "::";
  1482.    if (is_operator)
  1483.       out_c << "operator";
  1484.    out_c << mn << "(";
  1485.    params_out (out_c, params, /* no_param_names */ FALSE, 
  1486.            /*impl*/ TRUE, /*actual*/FALSE); out_c << ")";
  1487.  
  1488.    out_c << "{";
  1489. #ifdef ATT
  1490.    if (rtn.operator!=(get_void_type()))
  1491. #else
  1492.    if (rtn != get_void_type())
  1493. #endif
  1494.    {  out_c << "return ";
  1495.       if (is_generated)
  1496.      type_conversion_out (out_c, gm.get_result_type(), rtn, TRUE);
  1497.    }
  1498.    out_c << "(";
  1499.  
  1500.    if (is_static)
  1501.       out_c << _ID << gtn << "::";
  1502.    else
  1503.       out_c << "_ref->";
  1504.  
  1505.    if (is_operator)
  1506.    {  sos_String on = cci_Method_impl::operator_string (mn);
  1507.       out_c << on;
  1508.       on.destroy();
  1509.    }
  1510.    else
  1511.       out_c << mn;
  1512.    out_c << "(";
  1513.  
  1514.    sos_Bool is_first;
  1515.    if (is_static)
  1516.       is_first = TRUE;
  1517.    else
  1518.    {  is_first = FALSE;
  1519.       out_c << "_tpid";
  1520.    }
  1521.  
  1522.    if (is_generated)
  1523.       params_and_type_conversion_out
  1524.      (out_c, gm.get_params(), params, is_first);
  1525.    else
  1526.       params_out (out_c, params, /* no_param_names */ FALSE,
  1527.           /*impl*/ TRUE, /*actual*/ TRUE, is_first);
  1528.    out_c << "));}\n";
  1529. }
  1530.  
  1531. static void type_conversion_out (ostream& out_f,
  1532.                  sos_Type_name generic_tn,
  1533.                  sos_Type_name replaced_tn,
  1534.                  sos_Bool from_gen)
  1535. {
  1536.    T_PROC ("type_conversion_out");
  1537.    TT (genCC_H, T_ENTER);
  1538.  
  1539.    sos_Type gt = generic_tn.make_type();
  1540.    sos_Type rt = replaced_tn.make_type();
  1541.  
  1542.    if (NOT gt.equal (rt))
  1543.    {  if (from_gen)
  1544.       {  if (is_generic_parameter (generic_tn))
  1545.         if (rt.is_scalar ())
  1546.            out_f << "::make_" << replaced_tn;
  1547.         else
  1548.            out_f << replaced_tn << "::make";
  1549.       }
  1550.       else
  1551.       {  if (is_generic_parameter (generic_tn))
  1552.         if (rt.is_scalar ())
  1553.            out_f << "::make_" << replaced_tn << "_object";
  1554.         else
  1555.         {  
  1556. #ifdef ATT
  1557.            if (rt.is_derived_from (gt) OR rt.root().operator==(gt))
  1558. #else
  1559.            if (rt.is_derived_from (gt) OR rt.root() == gt)
  1560. #endif
  1561.           out_f << generic_tn;
  1562.            else
  1563.           out_f << generic_tn << "::make";
  1564.         }
  1565.       }
  1566.    }
  1567.  
  1568.    TT (genCC_H, T_LEAVE);
  1569. }
  1570.  
  1571. static void params_and_type_conversion_out (ostream& out_f,
  1572.                                             sos_Param_List generic_pl,
  1573.                                             sos_Param_List replaced_pl, 
  1574.                                             sos_Bool first) 
  1575. {
  1576.    T_PROC ("params_and_type_conversion_out");
  1577.    TT (genCC_H, T_ENTER);
  1578.  
  1579.    sos_Int i = 1;
  1580.    agg_iterate_double (generic_pl, sos_Param gen_p,
  1581.                replaced_pl, sos_Param repl_p, sos_Int comp)
  1582.    {  sos_String pn = repl_p.get_name();
  1583.  
  1584.       if (NOT first)
  1585.          out_f << ",";
  1586.       else
  1587.          first = FALSE;
  1588.  
  1589.       type_conversion_out (out_c, gen_p.get_type_name(),
  1590.                            repl_p.get_type_name(), FALSE);
  1591.  
  1592.       if (pn != NO_OBJECT)
  1593.          out_f << "(" << pn << ")";
  1594.       else
  1595.          out_f << "(_p" << i << ")";
  1596.       i++;
  1597.    }
  1598.    agg_iterate_double_end (generic_pl, gen_p, replaced_pl, repl_p, comp);
  1599.    TT (genCC_H, T_LEAVE);
  1600. }
  1601.  
  1602. static void params_out (ostream& out_f,
  1603.             sos_Param_List pl,
  1604.             sos_Bool no_param_names,
  1605.             sos_Bool impl,
  1606.             sos_Bool actual,
  1607.             sos_Bool first,
  1608.             sos_Int start)
  1609. {
  1610.    T_PROC ("params_out");
  1611.    TT (genCC_H, T_ENTER);
  1612.  
  1613.    sos_Int i, c;
  1614.    c = pl.card();
  1615.  
  1616.    for (i=start; i<=c; i++)
  1617.    {  sos_Param p = pl.get_nth(i);
  1618.       sos_String    pn = p.get_name();
  1619.       sos_Type_name tn = p.get_type_name();
  1620.       sos_Expr e = p.get_default_expr();
  1621.  
  1622.       if (NOT first)
  1623.          out_f << ",";
  1624.       else
  1625.          first = FALSE;
  1626.  
  1627.       if (NOT actual)
  1628.       {  out_f << tn;
  1629.          if (p.get_is_ref())
  1630.             out_f << "& ";
  1631.          else
  1632.             out_f << " ";
  1633.       }
  1634.  
  1635.       if (NOT no_param_names)
  1636.       {
  1637.      if (pn != NO_OBJECT)
  1638.         out_f << pn;
  1639.      else
  1640.         out_f << "_p" << i;
  1641.  
  1642.      if (NOT impl AND NOT actual AND e != NO_OBJECT)
  1643.         out_f << " = " << e;
  1644.       }
  1645.    }
  1646.  
  1647.    TT (genCC_H, T_LEAVE);
  1648. }
  1649.  
  1650. static void exprs_out (ostream& out_f, sos_Expr_List el, sos_Bool is_first)
  1651. {
  1652.    T_PROC ("ostream& operator<<");
  1653.    TT (genCC_H, T_ENTER);
  1654.  
  1655.    agg_iterate (el, sos_Expr e)
  1656.    {  if (is_first)
  1657.      is_first = FALSE;
  1658.       else
  1659.          out_f << ",";
  1660.       out_f << e;
  1661.    }
  1662.    agg_iterate_end (el, e);
  1663.  
  1664.    TT (genCC_H, T_LEAVE);
  1665. }
  1666.  
  1667. static ostream& operator<< (ostream& out_f, sos_String_List sl)
  1668. {
  1669.    T_PROC ("ostream& operator<<");
  1670.    TT (genCC_H, T_ENTER);
  1671.  
  1672.    sos_Bool is_first = TRUE;
  1673.    agg_iterate (sl, sos_String s)
  1674.    {  if (is_first)
  1675.      is_first = FALSE;
  1676.       else
  1677.          out_f << ",";
  1678.       out_f << s;
  1679.    }
  1680.    agg_iterate_end (sl, s);
  1681.  
  1682.    TT (genCC_H, T_LEAVE);
  1683.    return out_f;
  1684. }
  1685.  
  1686. static ostream& operator<< (ostream& out_f, sos_Type_name tn)
  1687. {
  1688.    T_PROC ("ostream& operator<<");
  1689.    TT (genCC_H, T_ENTER);
  1690.  
  1691.    err_assert (NOT tn.has_type(sos_String_type), "operator<<");
  1692.  
  1693.    out_f << tn.make_type_name ();
  1694.  
  1695.    TT (genCC_H, T_LEAVE);
  1696.    return out_f;
  1697. }
  1698.  
  1699. static ostream& operator<< (ostream& out_f, sos_Param_List pl)
  1700. {
  1701.    T_PROC ("ostream& operator<<");
  1702.    TT (genCC_H, T_ENTER);
  1703.  
  1704.    sos_Bool is_first = TRUE;
  1705.    agg_iterate (pl, sos_Param p)
  1706.    {  if (is_first)
  1707.      is_first = FALSE;
  1708.       else
  1709.          out_f << ",";
  1710.       out_f << p;
  1711.    }
  1712.    agg_iterate_end (pl, p);
  1713.  
  1714.    TT (genCC_H, T_LEAVE);
  1715.    return (out_f);
  1716. }
  1717.  
  1718. static ostream& operator<< (ostream& out_f, sos_Param p)
  1719. {
  1720.    T_PROC ("ostream& operator<<");
  1721.    TT (genCC_H, T_ENTER);
  1722.  
  1723.    sos_Expr expr = p.get_default_expr();
  1724.    sos_String name = p.get_name();
  1725.  
  1726.    out_f << p.get_type_name();
  1727.    if (name != NO_OBJECT)
  1728.       out_f << " " << name;
  1729.    if (expr != NO_OBJECT)
  1730.       out_f << " = " << expr;
  1731.  
  1732.    TT (genCC_H, T_LEAVE);
  1733.    return (out_f);
  1734. }
  1735.  
  1736. static ostream& operator<< (ostream& out_f, sos_Expr_List el)
  1737. {
  1738.    T_PROC ("ostream& operator<<");
  1739.    TT (genCC_H, T_ENTER);
  1740.  
  1741.    exprs_out (out_f, el, TRUE);
  1742.  
  1743.    TT (genCC_H, T_LEAVE);
  1744.    return (out_f);
  1745. }
  1746.  
  1747. static ostream& operator<< (ostream& out_f, sos_Expr e)
  1748. {
  1749.    T_PROC ("ostream& operator<<");
  1750.    TT (genCC_H, T_ENTER);
  1751.  
  1752.    if (e.has_type(sos_Identifier_type))
  1753.       out_f << sos_Identifier::make(e).get_id();
  1754.    else // e has_type sos_Int_expr_type
  1755.    {  sos_Int_expr i;
  1756.       i = sos_Int_expr::make(e);
  1757.       out_f << i.get_value();
  1758.    }
  1759.  
  1760.    TT (genCC_H, T_LEAVE);
  1761.    return (out_f);
  1762. }
  1763.  
  1764. static ostream& operator<< (ostream& out_f, sos_Typed_id tpid)
  1765. {
  1766.    T_PROC ("ostream& operator<<");
  1767.    TT (genCC_H, T_ENTER);
  1768.  
  1769.    out_f << sos_Int(tpid.container()) << "_" << tpid.offset();
  1770.  
  1771.    TT (genCC_H, T_LEAVE);
  1772.    return (out_f);
  1773. }
  1774.  
  1775. static ostream& operator<< (ostream& out_f, sos_Method_kind mk)
  1776. {
  1777.    T_PROC ("ostream& operator<<");
  1778.    TT (genCC_H, T_ENTER);
  1779.  
  1780.    switch (mk)
  1781.    {  case sos_PRIVATE:        out_f << "private"; break;
  1782.       case sos_PROTECTED:    out_f << "protected"; break;
  1783.       case sos_PUBLIC:        out_f << "public"; break;
  1784.    }
  1785.  
  1786.    TT (genCC_H, T_LEAVE);
  1787.    return (out_f);
  1788. }
  1789.  
  1790. static sos_Bool is_root_type (sos_Type tp)
  1791. {
  1792. #ifdef ATT
  1793.    return tp.operator==(tp.root());
  1794. #else
  1795.    return tp == tp.root();
  1796. #endif
  1797. }
  1798.  
  1799. static sos_Bool is_generic_parameter (sos_Type_name tn)
  1800. {
  1801.    if (tn.has_type(sos_Gen_param_type))
  1802.       return TRUE;
  1803.    else if (tn.has_type(sos_Generic_instantiation_type))
  1804.    {  sos_Type_name_List gpl =
  1805.      sos_Generic_instantiation::make(tn).get_gen_params();
  1806.  
  1807.       sos_Bool is_gen_par = FALSE;
  1808.       agg_iterate (gpl, sos_Type_name gp)
  1809.       {  is_gen_par = is_generic_parameter (gp);
  1810.      if (is_gen_par) break;
  1811.       }       
  1812.       agg_iterate_end (gpl, gp);
  1813.  
  1814.       return (is_gen_par);
  1815.    }
  1816.    else return FALSE;
  1817. }
  1818.  
  1819. static sos_Bool is_ccc_method (sos_Method m)
  1820. {  smg_String mn = m.get_name().make_Cstring();
  1821.    return (sos_Bool) (m.get_is_predefined() AND
  1822.               (mn.equal ("create") OR mn.equal ("copy") 
  1823.                        OR mn.equal ("clone")));
  1824. }
  1825.  
  1826. static sos_Schema_type *the_void_type;
  1827.  
  1828. // *************************************************************************
  1829. sos_Schema_type get_void_type()
  1830. // *************************************************************************
  1831. {
  1832.    T_PROC ("get_void_type");
  1833.    TT (genCC_H, T_ENTER);
  1834.  
  1835.    sos_Schema_type result;
  1836.    if (the_void_type)
  1837.       result = *the_void_type;
  1838.    else
  1839.    {
  1840. #ifdef BOOT
  1841.       result = generated_schema.lookup_type (
  1842.          smg_String ("void").make_String (TEMP_CONTAINER));
  1843. #else
  1844.       result = sos_Schema_type::make (void_type);
  1845. #endif
  1846.       the_void_type  = new sos_Schema_type;
  1847.       *the_void_type = result;
  1848.    }
  1849.  
  1850.    TT (genCC_H, T_LEAVE);
  1851.  
  1852.    return (result);
  1853. }
  1854.  
  1855. static sos_Schema_type *the_scalar_object_type;
  1856.  
  1857. // *************************************************************************
  1858. static sos_Schema_type get_scalar_object_type()
  1859. // *************************************************************************
  1860. {
  1861.    T_PROC ("get_scalar_object_type");
  1862.    TT (genCC_H, T_ENTER);
  1863.  
  1864.    sos_Schema_type result;
  1865.    if (the_scalar_object_type)
  1866.       result = *the_scalar_object_type;
  1867.    else
  1868.    {
  1869. #ifdef BOOT
  1870.       result = generated_schema.lookup_type (
  1871.          smg_String ("sos_Scalar_object").make_String (TEMP_CONTAINER));
  1872. #else
  1873.       result = sos_Schema_type::make (sos_Scalar_object_type);
  1874. #endif
  1875.       the_scalar_object_type  = new sos_Schema_type;
  1876.       *the_scalar_object_type = result;
  1877.    }
  1878.  
  1879.    TT (genCC_H, T_LEAVE);
  1880.  
  1881.    return (result);
  1882. }
  1883.