home *** CD-ROM | disk | FTP | other *** search
- /* --------------------------------------------------------------------------
- * Copyright 1992 by Forschungszentrum Informatik (FZI)
- *
- * You can use and distribute this software under the terms of the licence
- * you should have received along with this program.
- * If not or if you want additional information, write to
- * Forschungszentrum Informatik, "STONE", Haid-und-Neu-Strasse 10-14,
- * D-7500 Karlsruhe 1, Germany.
- * --------------------------------------------------------------------------
- */
- // **************************************************************************
- // Module genCC Juergen Uhl (ju)
- //
- // **************************************************************************
- // SOS interface generator for C++
- // **************************************************************************
-
- #include <stream.h>
- #include "sys.h"
- #include "smg.h"
- #include "genCC_err.h"
- #include "trc_genCC.h"
- #include "mta_use.h"
- #include "cci_use.h"
-
- #include "genCC.h"
-
- const sos_Cstring U_SUFFIX = "_use.h";
- const sos_Cstring I_SUFFIX = "_sos.h";
- const sos_Cstring X_SUFFIX = "_ext.h";
- const sos_Cstring C_SUFFIX = "_sos.c";
- const sos_Cstring _ID = "_";
- const sos_Cstring CCI = "cci_Schema_impl";
-
- const sos_Cstring INT1 = "sos_Char";
- const sos_Cstring INT2 = "sos_Short";
- const sos_Cstring INT4 = "sos_Int";
-
- sos_Bool gen_inline;
-
- static void imports_out (sos_Imports);
- static void typedef_type_out (sos_Typedef_type);
- static void enum_type_out (sos_Enum_type,sos_Bool);
- static void scalar_type_out (sos_Schema_type);
- static void union_type_out (sos_Union_type);
- static void class_type_out (sos_Class_type);
- static void type_type_out (sos_Schema_type);
- static void inits_out (sos_Schema_module);
-
- static void id_class_out (sos_Class_type, sos_Super_class_List);
- static void id_super_classes_out (sos_Type_name_List);
- static void id_cc_methods_out (sos_Class_type);
- static void id_predefined_methods_out (sos_Class_type);
- static sos_Method_kind id_method_kind;
- static void id_methods_out (sos_Class_type, sos_Method_List);
- static void id_method_out (sos_Class_type, sos_Method);
- static void id_comp_method_out (sos_Class_type, sos_Comp_method);
- enum Method_class {MC_REGULAR, MC_COMP, MC_STATIC};
- static void id_univ_methods_out (sos_Class_type ct,
- sos_Method_List ml,
- Method_class mc,
- sos_Bool only_predefined);
- static void id_univ_method_out (sos_Class_type ct,
- sos_Method m,
- sos_Bool is_static);
-
- static void class_out (sos_Class_type, sos_Super_class_List);
- static void init_out (sos_Class_type, sos_Super_class_List);
- static void friends_out (sos_Class_type);
- static void ccc_methods_out (sos_Class_type);
- static void cc_methods_out (sos_Class_type);
- static sos_Method_kind method_kind;
- static void inherited_methods_out (sos_Class_type);
- static void method_out (sos_Class_type, sos_Method);
- static void params_out (ostream&,
- sos_Param_List,
- sos_Bool no_param_names,
- sos_Bool impl,
- sos_Bool actual,
- sos_Bool first = TRUE,
- sos_Int start = 1);
- static void type_conversion_out (ostream&, sos_Type_name, sos_Type_name, sos_Bool);
- static void params_and_type_conversion_out
- (ostream&, sos_Param_List, sos_Param_List, sos_Bool);
- static void exprs_out (ostream&, sos_Expr_List, sos_Bool);
-
- static ostream& operator<< (ostream&, sos_String_List);
- static ostream& operator<< (ostream&, sos_Type_name);
- static ostream& operator<< (ostream&, sos_Param_List);
- static ostream& operator<< (ostream&, sos_Param);
- static ostream& operator<< (ostream&, sos_Expr);
- static ostream& operator<< (ostream&, sos_Expr_List);
- static ostream& operator<< (ostream&, sos_Typed_id);
- static ostream& operator<< (ostream&, sos_Method_kind);
-
- static sos_Bool is_root_type (sos_Type);
- static sos_Bool is_generic_parameter (sos_Type_name);
- static sos_Bool is_ccc_method (sos_Method);
- static sos_Schema_type get_void_type();
- static sos_Schema_type get_scalar_object_type();
- static sos_Schema_module generated_schema;
-
- filebuf fb_h;
- filebuf fb_i;
- filebuf fb_c;
- ostream out_h(&fb_h);
- ostream out_i(&fb_i);
- ostream out_c(&fb_c);
-
- #define out_I (gen_inline?out_h:out_i)
-
- void gen_module_out (sos_Schema_module mdl)
- {
- T_PROC ("gen_module_out");
- TT (genCC_H, T_ENTER);
-
- generated_schema = mdl;
-
- sos_Container ct = mdl.container();
- ct.open (WRITING, WAITING);
- cci_Schema_impl::make_impl (mdl);
-
- sos_Schema_type_List type_decls = mdl.get_types();
- smg_String m_name = mdl.get_name();
- smg_String u_name = m_name + U_SUFFIX;
- smg_String i_name = m_name + I_SUFFIX;
- smg_String c_name = m_name + C_SUFFIX;
-
- if (fb_h.open(u_name.make_Cstring (SMG_BORROW), output) == 0 ||
- fb_i.open(i_name.make_Cstring (SMG_BORROW), output) == 0 ||
- fb_c.open(c_name.make_Cstring (SMG_BORROW), output) == 0)
- { err_raise (err_USE, err_GEN_OUTPUT_ERROR, NULL, FALSE);
- return;
- }
-
- out_h << "#ifndef " << m_name << "_SOSH\n"
- << "#define " << m_name << "_SOSH 1\n\n";
-
- out_i << "#ifndef " << m_name << "_SOSI\n"
- << "#define " << m_name << "_SOSI 1\n\n"
- << "#include \"" << m_name << U_SUFFIX << "\"\n";
-
- out_c << "#include \"" << m_name << I_SUFFIX << "\"\n";
-
- out_c << "#include \"err.h\"\n"; // for 'err_raise_abstract_method'
-
- imports_out (mdl.get_imports());
-
- out_c << "#include \"cci" << U_SUFFIX << "\"\n";
-
- agg_iterate (type_decls, sos_Schema_type td)
- { if (td.has_type(sos_Enum_type_type))
- enum_type_out (sos_Enum_type::make(td),TRUE);
- else if (td.has_type(sos_Class_type_type))
- { if (is_root_type (td))
- out_I << "class " << _ID << td.make_type_name() << ";\n";
- out_h << "class " << td.make_type_name() << ";\n";
- }
- else if (td.has_type(sos_Typedef_type_type))
- typedef_type_out (sos_Typedef_type::make(td));
- }
- agg_iterate_end (type_decls, td);
-
- if (mdl.get_has_external_types() OR mdl.get_has_external_import())
- out_h << "#include \"" << m_name << X_SUFFIX << "\"\n";
-
- agg_iterate (type_decls, sos_Schema_type td)
- { if (td.has_type(sos_Enum_type_type))
- enum_type_out (sos_Enum_type::make(td),FALSE);
- else if (td.has_type(sos_Extern_type_type))
- {
- #ifdef ATT
- if (td.operator!=(get_void_type ()))
- #else
- if (td != get_void_type ())
- #endif
- scalar_type_out (td);
- }
- else if (td.has_type(sos_Union_type_type))
- union_type_out (sos_Union_type::make(td));
- else if (td.has_type(sos_Class_type_type))
- class_type_out (sos_Class_type::make(td));
- else if (NOT td.has_type(sos_Typedef_type_type))
- // predefined or forward type: do nothing
- continue;
-
- type_type_out (td);
- }
- agg_iterate_end (type_decls, td);
-
- inits_out (mdl);
-
- out_h << "#endif\n";
- out_i << "#endif\n";
-
- fb_h.close();
- fb_i.close();
- fb_c.close();
-
- ct.close ();
-
- TT (genCC_H, T_LEAVE);
- }
-
- static void imports_out (sos_Imports imports)
- {
- T_PROC ("imports_out");
- TT (genCC_H, T_ENTER);
-
- agg_iterate (imports, sos_Schema_module mdl)
- { out_h << "#include \"" << mdl.get_name() << U_SUFFIX << "\"\n";
- out_I << "#include \"" << mdl.get_name() << I_SUFFIX << "\"\n";
- }
- agg_iterate_end (imports, mdl);
-
- TT (genCC_H, T_LEAVE);
- }
-
- static void typedef_type_out (sos_Typedef_type tdt)
- {
- T_PROC ("typedef_type_out");
- TT (genCC_H, T_ENTER);
-
- sos_Type_name tn = tdt.get_type_name();
- sos_String n = tdt.get_name();
- out_h << "typedef ";
- if (tn.make_base_type().has_type (sos_Class_type_type))
- out_h << "class ";
-
- out_h << tn << " " << n << ";\n";
- if (tn.make_type().is_scalar ())
- { sos_String bn = tn.make_base_type().make_type_name ();
- out_h << "#define make_" << n << "_object make_" << bn << "_object\n";
- out_h << "#define make_" << n << " make_" << bn << "\n";
- }
-
- TT (genCC_H, T_LEAVE);
- }
-
- static void enum_type_out (sos_Enum_type et,sos_Bool declare_type)
- {
- T_PROC ("enum_type_out");
- TT (genCC_H, T_ENTER);
-
- sos_String n = et.get_name();
-
- if (declare_type)
- out_h << "enum " << n << " { " << et.get_literals() << " };\n";
- else
- {
- sos_Int size = et.get_object_size ();
- smg_String ht;
-
- if (size == 1)
- ht = INT1;
- else
- { err_assert (size == 2, "enum_type_out");
- ht = INT2;
- }
-
- out_h << "inline void bcopy_from_" << n << " (void *e,void *c)\n"
- << "{ *(" << ht << "*)c = (" << ht << ")*(" << n << "*)e; }\n"
- << "inline void bcopy_to_" << n << " (void *e,void *c)\n"
- << "{ *(" << n << "*)e = (" << n << ")*(" << ht << "*)c; }\n";
-
- scalar_type_out (et);
- }
-
- TT (genCC_H, T_LEAVE);
- }
-
- static void scalar_type_out (sos_Schema_type tp)
- {
- T_PROC ("scalar_type_out");
- TT (genCC_H, T_ENTER);
-
- sos_String n = tp.get_name();
-
- out_h << "sos_Object" << " make_" << n << "_object(" << n << ");\n";
- out_c << "sos_Object" << " make_" << n << "_object(" << n << " x)\n"
- << "{ return sos_object_from_extern (&x,bcopy_from_" << n << ","
- << _ID << n << "_type); }\n";
-
- out_h << n << " make_" << n << "(" << "sos_Object" << ");\n";
- out_c << n << " make_" << n << "(" << "sos_Object" << " o)\n"
- << "{ " << n << " x;\n"
- << " sos_extern_from_object (&x,o,bcopy_to_" << n << ","
- << _ID << n << "_type);\n"
- << " return x; }\n";
-
- TT (genCC_H, T_LEAVE);
- }
-
- static void union_type_out (sos_Union_type ut)
- {
- T_PROC ("union_type_out");
- TT (genCC_H, T_ENTER);
-
- sos_String n = ut.get_name();
- sos_Type_name_List uniteds = ut.get_uniteds();
-
- out_h << "class " << n << " : public " << "sos_Object" << "\n"
- << "{\n"
- << "public:\n " << n << "() {}\n";
-
- agg_iterate (uniteds, sos_Type_name tn)
- { out_h << " " << n << "(" << tn << ");\n";
- out_c << n << "::" << n << "(" << tn << " p) { *(sos_Object*)this=";
- if (tn.make_type().is_scalar ())
- out_c << "make_"
- << tn.make_base_type().make_type_name () << "_object (p)";
- else
- out_c << "p";
- out_c << "; }\n";
- }
- agg_iterate_end (uniteds, tn);
-
- out_h << " static " << n << " make(" << "sos_Object);\n";
- out_c << n << " " << n << "::make(" << "sos_Object" << " o)\n"
- << " { " << n << " x; *(sos_Object*)&x=o; return x; }\n";
-
- out_h << "};\n";
-
- TT (genCC_H, T_LEAVE);
- }
-
- static void class_type_out (sos_Class_type ct)
- {
- T_PROC ("class_type_out");
- TT (genCC_H, T_ENTER);
-
- sos_Super_class_List super_closure = ct.get_super_closure();
-
- if (is_root_type (ct))
- id_class_out (ct, super_closure);
- else
- id_univ_methods_out (ct, ct.get_static_methods(), MC_STATIC, TRUE);
- class_out (ct, super_closure);
-
- TT (genCC_H, T_LEAVE);
- }
-
- static void type_type_out (sos_Schema_type t)
- {
- T_PROC ("type_type_out");
- TT (genCC_H, T_ENTER);
-
- sos_String tn = t.make_type_name();
- sos_Typed_id tpid = t.base().typed_id();
- sos_Id id = tpid.get_id();
- sos_Id tp = tpid.get_tp();
-
- out_h << "#define " << _ID << tn
- << "_type sos_Id::make(sos_Container::make(" << sos_Int(id.container())
- << ")," << id.offset() << ")\n"
- << "#define " << tn << "_type sos_type_object("
- << _ID << tn << "_type,sos_Id::make(sos_Container::make("
- << sos_Int(tp.container()) << ")," << tp.offset() << "))\n";
-
- TT (genCC_H, T_LEAVE);
- }
-
- static void inits_out (sos_Schema_module mdl)
- {
- T_PROC ("inits_out");
- TT (genCC_H, T_ENTER);
-
- sos_Schema_type_List type_decls = mdl.get_types();
- sos_String schema_name = mdl.get_name();
-
- out_I << "extern void _" << schema_name << "_init_sos();\n";
-
- // Call module initialization using a constructor.
- // The destructor ensures that each object module added during
- // incremental loading contains at least one destructor.
- // (A missing destructor list '___DTOR_LIST__' caused a
- // bus error in gcc-ld.)
- out_c << "static struct _sos_init_dummy {\n"
- << " _sos_init_dummy() {_" << schema_name << "_init_sos();}"
- << " ~_sos_init_dummy(){}\n } _sos_dummy;\n";
-
- out_c << "static int _sos_initialized=0;\n"
- << "void _" << schema_name << "_init_sos(){\n"
- << " if (_sos_initialized) return;\n"
- << " _sos_initialized=1;\n";
-
- sos_Imports imports = mdl.get_imports();
-
- agg_iterate (imports, sos_Schema_module imported)
- { out_c << " _" << imported.get_name() << "_init_sos();\n";
- }
- agg_iterate_end (imports, imported);
-
- agg_iterate (type_decls, sos_Type tp)
- { if (tp.has_type (sos_Class_type_type))
- { sos_String tn = sos_Class_type::make(tp).make_type_name();
- sos_Typed_id tpid = tp.typed_id();
- if (is_root_type (tp))
- { out_c << " _" << _ID << tn << "_obj=new " << _ID << tn << ";\n"
- << " _init_meth_" << tpid << "();\n"
- << " _init_comp_" << tpid << "();\n";
- }
- out_c << " _init_stat_" << tpid << "();\n"
- << " _init_new_" << tpid << "();\n";
- }
- else if ((tp.has_type (sos_Extern_type_type) OR
- tp.has_type (sos_Enum_type_type)) AND
- #ifdef ATT
- tp.operator!=(get_void_type ())
- #else
- tp != get_void_type ()
- #endif
- )
- { sos_String tn = tp.get_name();
- sos_Super_class_List scl =
- sos_Class_type::make (get_scalar_object_type()).get_super_closure();
-
- agg_iterate (scl, sos_Super_class sc)
- { sos_Class_type tp = sc.get_super_class();
- out_c << " " << CCI << "::enter_make_obj("
- << _ID << tp.get_name() << "_type,"
- << _ID << tn << "_type,("
- << _ID << tp.get_name() << "*) new "
- << _ID << "sos_Scalar_object" << ");\n";
- }
- agg_iterate_end (scl, sc);
-
- if (tp.has_type (sos_Extern_type_type))
- out_c << " " << CCI << "::enter_string_io ("
- << _ID << tn << "_type,(cci_IO_fun)make_string_from_"
- << tn << "_object,(cci_IO_fun)make_"
- << tn << "_object_from_string);\n";
- }
- }
- agg_iterate_end (type_decls, tp);
-
- out_c << "}\n";
-
- TT (genCC_H, T_LEAVE);
- }
-
- static void id_class_out (sos_Class_type ct, sos_Super_class_List super_closure)
- {
- T_PROC ("id_class_out");
- TT (genCC_H, T_ENTER);
-
- sos_String cn = ct.make_type_name();
- sos_Type_name stn; // super class
-
- out_I << "class " << _ID << cn;
- id_super_classes_out (ct.get_super_classes());
- out_I << "\n{ friend class " << cn << ";\n";
-
- // sos_Offset-operations:
- agg_iterate (super_closure, sos_Super_class sc)
- { sos_Int os = sc.get_offset();
- stn = sc.get_super_class().make_root_type();
-
- out_I << " virtual sos_Offset _offset_" << stn
- << " () { return " << os << "; }\n";
- }
- agg_iterate_end (super_closure, sc);
-
- out_I << "public:\n";
-
- id_cc_methods_out (ct);
- id_predefined_methods_out (ct);
-
- id_method_kind = sos_PUBLIC;
- id_methods_out (ct, ct.get_methods());
- id_methods_out (ct, ct.get_comp_methods());
- id_methods_out (ct, ct.get_static_methods());
-
- out_I << "};\n";
-
- id_univ_methods_out (ct, ct.get_methods(), MC_REGULAR, FALSE);
- id_univ_methods_out (ct, ct.get_comp_methods(), MC_COMP, FALSE);
- id_univ_methods_out (ct, ct.get_static_methods(), MC_STATIC, FALSE);
-
- out_I << "extern " << _ID << cn << " *_" << _ID << cn << "_obj;\n";
- out_c << _ID << cn << " *_" << _ID << cn << "_obj;\n";
-
- TT (genCC_H, T_LEAVE);
-
- }
-
-
- static void id_super_classes_out (sos_Type_name_List super_classes)
- {
- T_PROC ("id_super_classes_out");
- TT (genCC_H, T_ENTER);
-
- sos_Bool first = TRUE;
- agg_iterate (super_classes, sos_Type_name sc)
- { if (first)
- { first = FALSE;
- out_I << ":";
- }
- else
- out_I << ",";
-
- out_I << "virtual public " << _ID << sc.make_root_type();
- }
- agg_iterate_end (super_classes, sc);
-
- TT (genCC_H, T_LEAVE);
- }
-
- static void id_cc_methods_out (sos_Class_type ct)
- {
- T_PROC ("id_cc_methods_out");
- TT (genCC_H, T_ENTER);
-
- sos_String cn = ct.make_type_name();
-
- // make
- out_I << " static " << _ID << cn << "* _make(sos_Typed_id&);\n";
- out_c << _ID << cn << "* " << _ID << cn
- << "::_make(sos_Typed_id &tpid)\n"
- << "{ return (" << _ID << cn << "*)" << CCI << "::get_make_obj("
- << _ID << cn << "_type,tpid.get_tp());\n}\n";
-
- // _size
- out_I << " virtual sos_Offset _size();\n";
- out_c << "sos_Offset " << _ID << cn << "::_size(){return "
- << ct.get_object_size() << ";}\n";
-
- TT (genCC_H, T_LEAVE);
- }
-
-
- sos_Super_class_List remove_redefined_locals (sos_Super_class_List scl,
- sos_String str,
- sos_Bool &removed)
- {
- T_PROC ("remove_redefined_locals");
- TT (genCC_H, T_ENTER);
-
- sos_Super_class_List result;
- sos_Super_class_List totals;
-
- removed = FALSE;
- result = sos_Super_class_List::create (TEMP_CONTAINER, FALSE);
- totals = sos_Super_class_List::create (TEMP_CONTAINER, FALSE);
-
- agg_iterate_reverse (scl, sos_Super_class sc)
- { sos_Bool remove = FALSE;
- sos_Class_type sct = sc.get_super_class();
- agg_iterate (totals, sos_Super_class sc1)
- { if (sc1.get_super_class().is_derived_from (sct))
- { remove = TRUE;
- break;
- }
- }
- agg_iterate_end (totals, sc1);
- if (remove)
- removed = TRUE;
- else
- result.insert (1, sc);
- if (sct.get_inherited_methods()[str] != NO_OBJECT)
- totals.append (sc);
- }
- agg_iterate_reverse_end (scl, sc);
- totals.destroy();
-
- TT (genCC_H, T_LEAVE);
-
- return result;
- }
-
- sos_Bool defines_method (sos_Class_type ct, sos_String str)
- {
- T_PROC ("defines_method");
- TT (genCC_H, T_ENTER);
-
- sos_Bool result;
- sos_Method_table mt = ct.get_inherited_methods();
- sos_Method_List ml = mt [str];
- result = (sos_Bool)(ml != NO_OBJECT AND NOT ml.get_nth(1).get_is_predefined());
-
- TT (genCC_H, T_LEAVE);
-
- return result;
- }
-
- static void id_predefined_methods_out (sos_Class_type ct)
- {
- T_PROC ("id_predefined_methods_out");
- TT (genCC_H, T_ENTER);
-
- sos_String cn = ct.make_type_name();
- sos_Param_List create_params = ct.get_create_params();
- sos_Super_class_List super_closure = ct.get_super_closure();
- sos_String str;
- sos_Super_class_List total_closure;
- sos_Bool removed;
-
- // _create
- out_I << " void _create(sos_Typed_id&";
- if (create_params != NO_OBJECT)
- params_out (out_I, create_params, /* no_param_names */ FALSE,
- /*impl*/ FALSE, /*actual*/ FALSE, /*is_first*/ FALSE);
- out_I << ");\n";
-
- out_c << "void " << _ID << cn << "::_create(sos_Typed_id&_tpid";
- if (create_params != NO_OBJECT)
- params_out (out_c, create_params, /* no_param_names */ FALSE,
- /*impl*/ TRUE, /*actual*/ FALSE, /*is_first*/ FALSE);
- out_c << "){\n"
- << " " << cn << " _x=" << cn << "::make(_tpid,this);\n";
-
- agg_iterate (super_closure, sos_Super_class sc)
- { sos_Class_type sct = sc.get_super_class();
- if (sct.get_has_init_comps())
- { sos_Expr_List cpl = sc.get_create_params();
-
- out_c << _ID << sct.make_root_type() << "::_create_comps(_x";
- if (cpl != NO_OBJECT)
- exprs_out (out_c, cpl, /*is_first*/ FALSE);
- out_c << ");\n";
- }
- }
- agg_iterate_end (super_closure, sc);
-
- str = smg_String ("local_initialize").make_String (TEMP_CONTAINER);
- agg_iterate (super_closure, sos_Super_class sc)
- { sos_Class_type sct = sc.get_super_class();
-
- if (sct.get_inherited_methods() [str] != NO_OBJECT)
- { out_c << _ID << sct.make_root_type()
- << "::local_initialize(_x);\n";
- }
- }
- agg_iterate_end (super_closure, sc);
- str.destroy();
-
- out_c << "}\n";
-
- // _create_comps
- if (ct.get_has_init_comps())
- { sos_Method_List ml = ct.get_comp_methods();
-
- out_I << "protected:\n"
- << " static void _create_comps(" << cn;
- if (create_params != NO_OBJECT)
- params_out (out_I, create_params, /* no_param_names */ FALSE,
- /*impl*/ FALSE, /*actual*/ FALSE, /*is_first*/ FALSE);
- out_I << ");\n"
- << "public:\n";
-
- out_c << "void " << _ID << cn << "::_create_comps(" << cn << " _x";
- if (create_params != NO_OBJECT)
- params_out (out_c, create_params, /* no_param_names */ FALSE,
- /*impl*/ TRUE, /*actual*/ FALSE, /*is_first*/ FALSE);
- out_c << "){\n ";
-
- agg_iterate (ml, sos_Method m)
- { sos_Comp_method cm = sos_Comp_method::make (m);
- if (cm.get_is_set())
- { sos_Expr e = cm.get_init_expr();
- if (e != NO_OBJECT)
- { out_c << " _x." << cm.get_name() << "(";
- if (e.has_type (sos_Identifier_type))
- if (smg_String (sos_Identifier::make (e).get_id()).
- equal ("NO_OBJECT"))
- out_c << cm.get_params().get_nth(1).get_type_name()
- << "::make(NO_OBJECT)";
-
- else
- out_c << e;
- else
- out_c << e;
- out_c << ");\n";
- }
- }
- }
- agg_iterate_end (ml, m);
- out_c << "}\n";
- }
-
- // _copy
- out_I << " void _copy(sos_Typed_id&," << cn << ");\n";
-
- out_c << "void " << _ID << cn << "::_copy(sos_Typed_id&_tpid,"
- << cn << " y){\n"
- << " " << cn << " x=" << cn << "::make(_tpid,this);\n";
-
- agg_iterate (super_closure, sos_Super_class sc)
- { sos_Class_type sct = sc.get_super_class();
- if (sct.get_has_init_comps())
- { sos_Expr_List cpl = sc.get_create_params();
-
- out_c << _ID << sct.make_root_type() << "::_copy_comps(x,y);\n";
- }
- }
- agg_iterate_end (super_closure, sc);
-
- str = smg_String ("local_initialize").make_String (TEMP_CONTAINER);
- agg_iterate (super_closure, sos_Super_class sc)
- { sos_Class_type sct = sc.get_super_class();
-
- if (sct.get_inherited_methods() [str] != NO_OBJECT)
- { out_c << _ID << sct.make_root_type()
- << "::local_initialize(x);\n";
- }
- }
- agg_iterate_end (super_closure, sc);
- str.destroy();
-
- out_c << "}\n";
-
- // _copy_comps
- if (ct.get_has_init_comps())
- { sos_Method_List ml = ct.get_comp_methods();
-
- out_I << "protected:\n"
- << " static void _copy_comps(" << cn << "," << cn << ");\n"
- << "public:\n";
-
- out_c << "void " << _ID << cn << "::_copy_comps("
- << cn << " x," << cn << " y){\n";
-
- agg_iterate (ml, sos_Method m)
- { sos_Comp_method cm = sos_Comp_method::make (m);
- if (cm.get_is_set())
- { sos_Expr e = cm.get_init_expr();
- if (e != NO_OBJECT)
- { sos_Cstring mn = cm.get_name().make_Cstring();
- out_c << " x." << mn << "(y.";
- mn[0] = 'g';
- out_c << mn << "());\n";
- delete mn;
- }
- }
- }
- agg_iterate_end (ml, m);
- out_c << "}\n";
- }
-
- // _clone
- out_I << " virtual sos_Object _clone(sos_Typed_id&,sos_Container);\n";
-
- out_c << "sos_Object " << _ID << cn
- << "::_clone(sos_Typed_id&_tpid,sos_Container cnt){\n"
- << " " << cn << " _x=" << cn << "::make(_tpid,this);\n"
- << " return " << cn << "::copy(_x,cnt);}\n";
-
- // destroy
- out_I << " virtual void destroy(sos_Typed_id&);\n";
-
- out_c << "void " << _ID << cn << "::destroy(sos_Typed_id&_tpid){\n";
-
- str = smg_String ("local_finalize").make_String (TEMP_CONTAINER);
- agg_iterate_reverse (super_closure, sos_Super_class sc)
- { sos_Class_type sct = sc.get_super_class();
-
- if (sct.get_inherited_methods() [str] != NO_OBJECT)
- { sos_Type_name stn = sct.make_root_type();
- out_c << " " << _ID << stn
- << "::local_finalize(" << stn << "::make(_tpid,this));\n";
- }
- }
- agg_iterate_reverse_end (super_closure, sc);
- str.destroy();
-
- out_c << " _tpid.container().deallocate(_tpid.offset(),"
- << ct.get_object_size() << ");}\n";
-
- // assign
- out_I << " virtual void assign(sos_Typed_id&,sos_Object);\n";
-
- out_c << "void " << _ID << cn
- << "::assign(sos_Typed_id&_tpid,sos_Object o){\n "
- << cn << " x=" << cn << "::make(_tpid,this);\n";
-
- str = smg_String ("total_assign").make_String (TEMP_CONTAINER);
- total_closure = remove_redefined_locals (super_closure, str, removed);
- agg_iterate (total_closure, sos_Super_class sc)
- { sos_Class_type sct = sc.get_super_class().root_class();
- out_c << " " << _ID << sct.make_type_name() << "::";
- if (removed AND sct.get_inherited_methods()[str] != NO_OBJECT)
- out_c << "total";
- else
- out_c << "local";
- out_c << "_assign(x,o);\n";
- }
- agg_iterate_end (total_closure, sc);
- out_c << "}\n";
- str.destroy();
- total_closure.destroy();
-
- str = smg_String ("local_assign").make_String (TEMP_CONTAINER);
- if (NOT defines_method (ct, str))
- { out_I << " static void local_assign(" << cn << ",sos_Object);\n";
-
- out_c << "void " << _ID << cn << "::local_assign(" << cn
- << " x,sos_Object o){\n";
- if (ct.get_local_size() > 0)
- { out_c << " " << cn << " y=" << cn << "::make(o);\n"
- << " y.container().copy(y.offset()+y._ref->_offset_" << cn
- << "()," << ct.get_local_size()
- << ",x.container(),x.offset()+x._ref->_offset_" << cn << "());";
- }
- out_c << "}\n";
- }
- str.destroy();
-
- // equal
- out_I << " virtual sos_Bool equal(sos_Typed_id&,sos_Object,sos_Eq_kind=EQ_STRONG);\n";
-
- out_c << "sos_Bool " << _ID << cn
- << "::equal(sos_Typed_id&_tpid,sos_Object o,sos_Eq_kind eq_kind){\n "
- << cn << " x=" << cn << "::make(_tpid,this);\n";
-
- str = smg_String ("total_equal").make_String (TEMP_CONTAINER);
- total_closure = remove_redefined_locals (super_closure, str, removed);
- agg_iterate (total_closure, sos_Super_class sc)
- { sos_Class_type sct = sc.get_super_class().root_class();
- out_c << " if (! " << _ID << sct.make_type_name() << "::";
- if (removed AND sct.get_inherited_methods()[str] != NO_OBJECT)
- out_c << "total";
- else
- out_c << "local";
- out_c << "_equal(x,o,eq_kind)) return FALSE;\n";
- }
- agg_iterate_end (total_closure, sc);
- out_c << " return TRUE;}\n";
- str.destroy();
- total_closure.destroy();
-
- str = smg_String ("local_equal").make_String (TEMP_CONTAINER);
- if (NOT defines_method (ct, str))
- { out_I << " static sos_Bool local_equal(" << cn << ",sos_Object,sos_Eq_kind);\n";
-
- out_c << "sos_Bool " << _ID << cn << "::local_equal(" << cn;
-
- if (ct.get_local_size() > 0)
- { sos_Bool is_generic_class = (sos_Bool)
- (ct.get_gen_params() != NO_OBJECT);
- out_c << " x,sos_Object o,sos_Eq_kind eq_kind){\n"
- << " if (eq_kind==EQ_STRONG) {if (!o.has_type(";
-
- if (is_generic_class)
- out_c << "x.type()";
- else
- out_c << cn << "_type";
-
- out_c << ")) return FALSE;}\n else if (!o.isa(";
-
- if (is_generic_class)
- out_c << "x.type()";
- else
- out_c << cn << "_type";
-
- out_c << ")) return FALSE;\n"
- << " " << cn << " y=" << cn << "::make(o);\n"
- << " return (sos_Bool)x.container().equal("
- << "x.offset()+x._ref->_offset_" << cn << "(),"
- << ct.get_local_size()
- << ",y.container(),y.offset()+y._ref->_offset_" << cn << "());";
- }
- else
- out_c << ",sos_Object,sos_Eq_kind) { return TRUE;";
- out_c << "}\n";
- }
- str.destroy();
-
- // hash_value
- out_I << " virtual sos_Int hash_value(sos_Typed_id&);\n";
-
- out_c << "sos_Int " << _ID << cn << "::hash_value(sos_Typed_id&_tpid){\n "
- << cn << " x=" << cn << "::make(_tpid,this);\n sos_Int result=0;\n";
-
- str = smg_String ("total_hash_value").make_String (TEMP_CONTAINER);
- total_closure = remove_redefined_locals (super_closure, str, removed);
- agg_iterate (total_closure, sos_Super_class sc)
- { sos_Class_type sct = sc.get_super_class().root_class();
- out_c << " result ^= " << _ID << sct.make_type_name() << "::";
- if (removed AND sct.get_inherited_methods()[str] != NO_OBJECT)
- out_c << "total";
- else
- out_c << "local";
- out_c << "_hash_value(x);\n";
- }
- agg_iterate_end (total_closure, sc);
- out_c << " return result;}\n";
- str.destroy();
- total_closure.destroy();
-
- str = smg_String ("local_hash_value").make_String (TEMP_CONTAINER);
- if (NOT defines_method (ct, str))
- { out_I << " static sos_Int local_hash_value(" << cn << ");\n";
-
- out_c << "sos_Int " << _ID << cn << "::local_hash_value(" << cn << " x){\n"
- << " return x.container().hash_value(x.offset()+x._ref->_offset_"
- << cn << "()," << ct.get_local_size() << ");}\n";
- }
- str.destroy();
-
- TT (genCC_H, T_LEAVE);
- }
-
- static void id_methods_out (sos_Class_type ct, sos_Method_List ml)
- {
- T_PROC ("id_methods_out");
- TT (genCC_H, T_ENTER);
-
- agg_iterate (ml, sos_Method m1)
- { sos_Method m = m1.get_generated_from();
- if (m == NO_OBJECT) m = m1;
-
- sos_Method_kind mk = m.get_kind();
- if (mk != id_method_kind)
- { id_method_kind = mk;
- out_I << id_method_kind << ":\n";
- }
-
- if (m.has_type (sos_Comp_method_type))
- id_comp_method_out (ct, sos_Comp_method::make (m));
- else
- id_method_out (ct, m);
- }
- agg_iterate_end (ml, m);
- TT (genCC_H, T_LEAVE);
- }
-
- static void id_method_out (sos_Class_type, sos_Method m)
- {
- T_PROC ("id_method_out");
- TT (genCC_H, T_ENTER);
-
- sos_String cn;
- sos_String mn = m.get_name();
- sos_Param_List params = m.get_params();
- sos_Type_name result_type = m.get_result_type();
- sos_Bool is_abstract = m.get_is_abstract();
- sos_Bool is_static = m.get_is_static();
- sos_Bool is_operator = m.get_is_operator();
-
- TT(genCC_L, TsS (mn));
-
- if (NOT m.get_is_predefined())
- { if (is_static)
- out_I << " static ";
- else
- out_I << " virtual ";
-
- if (is_operator)
- mn = cci_Method_impl::operator_string (mn);
-
- out_I << result_type << " " << mn << "(";
- if (is_abstract)
- {
- cn = m.get_defined_in().make_root_type().make_type_name();
- out_c << result_type << " "
- << _ID << cn << "::" << mn << "(";
- }
-
- sos_Bool is_first;
- if (is_static)
- is_first = TRUE;
- else
- { is_first = FALSE;
- out_I << "sos_Typed_id&";
- if (is_abstract)
- out_c << "sos_Typed_id&";
- }
-
- params_out (out_I, params, /* no_param_names */ FALSE,
- /*impl*/ FALSE, /*actual*/ FALSE, is_first);
- out_I << ");\n";
-
- if (is_abstract)
- {
- params_out (out_c, params, /* no_param_names */ TRUE,
- /*impl*/ FALSE, /*actual*/ FALSE, is_first);
- out_c << ") ";
-
- // now create function body
- out_c << "{\n err_raise_abstract_method (\"" << cn << "::" << mn
- << "\"); ";
- #ifdef ATT
- if (result_type.operator!= (get_void_type()))
- #else
- if (result_type != get_void_type())
- #endif
- {
- out_c << "\n return ";
- // Now check if result type is scalar type. If so, cast 0 into
- // the according type.
- if (result_type.make_base_type().has_type (sos_Extern_type_type) OR
- result_type.make_base_type().has_type (sos_Enum_type_type))
- out_c << "(" << result_type << ") 0; ";
- else
- out_c << result_type << "::make(NO_OBJECT); ";
- }
- out_c << "}\n";
- }
- if (is_operator)
- mn.destroy();
- }
-
- TT (genCC_H, T_LEAVE);
- }
-
- static void id_comp_method_out (sos_Class_type ct, sos_Comp_method cm)
- {
- T_PROC ("id_comp_method_out");
- TT (genCC_H, T_ENTER);
-
- sos_String cn = ct.make_type_name();
- sos_String n = cm.get_name();
- sos_Bool is_set = cm.get_is_set();
- sos_Type_name tn = (is_set) ? cm.get_params().get_nth(1).get_type_name()
- : cm.get_result_type();
- sos_Int size;
-
- sos_Schema_type bt = tn.make_base_type ();
- sos_Bool is_scalar = bt.is_scalar ();
- sos_Bool is_local = cm.get_is_local();
- smg_String ht;
-
- if (is_scalar)
- { size = bt.get_object_size();
- ht = bt.get_name();
- }
- else if (is_local)
- { size = SOS_OFFSET_SIZE;
- ht = "sos_Offset";
- }
- else
- { size = SOS_TYPED_ID_SIZE;
- ht = "sos_Typed_id";
- }
- // ???
- // Added the keywords 'virtual' to set_.../get_... declarations
- // 15/8/91, Dietmar
-
- if (is_set)
- { out_I << " virtual void " << n << "(sos_Typed_id&," << tn << ");\n";
- out_c << "void " << _ID << cn << "::" << n
- << "(sos_Typed_id&_tpid," << tn
- << " a){\n union {" << ht << " x; char c[" << size << "];} u;\n";
- if (is_scalar)
- out_c << " bcopy_from_" << ht << "(&a,&u);\n";
- else if (is_local)
- out_c << " " << ht << " x=sos_local_offset(a,_tpid.container());\n"
- << " bcopy_from_" << ht << "(&x,&u);\n";
- else
- out_c << " " << ht << " x=a.typed_id();\n"
- << " bcopy_from_" << ht << "(&x,&u);\n";
- out_c << " _tpid.container().write(_tpid.offset() + _offset_" << cn
- << "() + " << cm.get_offset() << "," << size << ",&u);\n}\n";
- }
- else
- { out_I << " virtual " << tn << " " << n << "(sos_Typed_id&);\n";
-
- out_c << tn << " " << _ID << cn << "::" << n
- << "(sos_Typed_id&_tpid)\n"
- << "{ union {" << ht << " x; char c[" << size << "];} u; "
- << ht << " a;\n"
- << " _tpid.container().read(_tpid.offset()+_offset_" << cn
- << "()+" << cm.get_offset() << "," << size << ",&u);\n"
- << " bcopy_to_" << ht << "(&a,&u);\n";
- if (is_scalar)
- out_c << " return a;";
- else if (is_local)
- out_c << " return " << bt.make_type_name()
- << "::make(sos_make_local_typed_id(a,_tpid.container()));";
- else
- out_c << " return " << bt.make_type_name() << "::make(a);";
- out_c << "}\n";
- }
-
- TT (genCC_H, T_LEAVE);
- }
-
- static void id_univ_method_out (sos_Class_type ct,
- sos_Method m,
- sos_Bool is_static)
- // modified: 13.08.91 (bs)
- // to avoid the effects of a GNU (1.37 & 1.39) compiler error
- {
- T_PROC ("id_univ_method_out");
- TT (genCC_H, T_ENTER);
-
- sos_String cn = ct.make_type_name();
- sos_String mn = m.get_name();
- sos_Param_List params = m.get_params();
- sos_Type_name result_type = m.get_result_type();
- sos_Bool is_operator = m.get_is_operator();
- sos_Int card = params.card();
-
- #ifdef ATT
- sos_Bool is_void_result = result_type.operator==(get_void_type());
- #else
- sos_Bool is_void_result = result_type == get_void_type();
- #endif
- // out Header
- out_c << "static sos_Object _univ_"
- << cci_Method_impl::make_impl (m).typed_id()
- << "(sos_Object";
-
- if (NOT is_static)
- out_c << " o";
-
- out_c << ",sos_Object_Array";
- if (params.card() > 0)
- out_c << " p";
-
- out_c << "){\n "; // out Implementation
-
- sos_Int ref_params = 0;
-
- if (card > 0)
- {
- out_c << "sos_Object ";
- for (sos_Int j=1; j <= card; j++)
- {
- if (params.get_nth(j).get_is_ref())
- ref_params++;
- out_c << "o" << j << "=p[" << j-1;
- // The storing of the value of 'p' would only
- // be necessary for parameters passed by reference.
- // It is done here for all parameters, to avoid a
- // GNU(1.39) compiler error. (bs)
- if (j < card)
- out_c << "], ";
- else
- out_c << "];\n ";
- }
- }
- TT (genCC_L, TXT ("No. of reference parameters"); TI(ref_params));
-
- if (NOT is_void_result)
- {
- if (ref_params NEQ 0) // (bs)
- out_c << "sos_Object r=";
- else
- out_c << "return ";
-
- if (result_type.make_type().is_scalar())
- out_c << "::make_" << result_type << "_object";
- else
- {
- #ifdef ATT
- if (result_type.make_type().operator!= (sos_Object_type))
- #else
- if (result_type.make_type() != sos_Object_type) // (bs)
- #endif
- out_c << "sos_Object::make";
- }
- out_c << "(";
- }
-
- if (is_static)
- out_c << cn << "::";
- else
- out_c << cn << "::make (o).";
- if (is_operator)
- out_c << "operator";
-
- out_c << mn << "(";
-
- sos_Bool first = TRUE;
-
- for (sos_Int i=1; i<=card; i++)
- { sos_Param p = params.get_nth(i);
- sos_Schema_type pt = p.get_type_name().make_base_type();
- sos_String ptn = pt.make_type_name();
-
- if (NOT first)
- out_c << ",";
- else
- first = FALSE;
-
- if (pt.is_scalar ())
- out_c << "::make_" << ptn;
- else
- out_c << ptn << "::make";
- out_c << "(o" << i << ")";
- // out_c << "(p[" << i-1 << "])"; replaced 13.08.91 (bs)
- }
- out_c << ")";
-
- if (NOT is_void_result)
- out_c << ")";
-
- if (ref_params NEQ 0)
- {
- out_c << ";\n ";
- sos_Int done_ref_params = 0;
- for (sos_Int k = 1; k <= card; k++) // write back reference params
- {
- if (params.get_nth(k).get_is_ref())
- {
- out_c << "p.set_nth(" << k-1 << ",o" << k << ")";
- done_ref_params++;
- if (done_ref_params NEQ ref_params)
- out_c << "; ";
- }
- }
- }
-
- if (is_void_result)
- out_c << ";\n return NO_OBJECT";
- else
- if (ref_params NEQ 0)
- out_c << ";\n return r";
-
- out_c << ";}\n";
-
- TT (genCC_H, T_LEAVE);
- }
-
-
- static void id_univ_methods_out (sos_Class_type ct,
- sos_Method_List ml,
- Method_class mc,
- sos_Bool only_predefined)
- {
- T_PROC ("id_univ_methods_out");
- TT (genCC_H, T_ENTER; TB (only_predefined));
-
- sos_String cn = ct.make_type_name();
-
- agg_iterate (ml, sos_Method m)
- { if (m.get_kind() == sos_PUBLIC AND
- (NOT only_predefined OR m.get_is_predefined()))
- id_univ_method_out (ct, m, (sos_Bool)(mc == MC_STATIC));
- }
- agg_iterate_end (ml, m);
- sos_Typed_id tpid = ct.typed_id();
-
- out_c << "static void _init_";
- switch (mc)
- { case MC_REGULAR: out_c << "meth_"; break;
- case MC_COMP: out_c << "comp_"; break;
- case MC_STATIC: out_c << "stat_"; break;
- }
- out_c << tpid << "(){\n";
-
- if (NOT only_predefined)
- { agg_iterate (ml, sos_Method m)
- { sos_Typed_id mtpid = cci_Method_impl::make_impl (m).typed_id();
- if (m.get_kind() == sos_PUBLIC AND
- (NOT only_predefined OR m.get_is_predefined()))
- out_c << " " << CCI
- << "::enter_fun(sos_Id::make(sos_Container::make("
- << sos_Int(mtpid.container()) << "),"
- << mtpid.offset() << "),(cci_Fun)_univ_" << mtpid << ");\n";
- }
- agg_iterate_end (ml, m);
- }
-
- out_c << "}\n";
-
- TT (genCC_H, T_LEAVE);
- }
-
- static void class_out (sos_Class_type ct, sos_Super_class_List super_closure)
- {
- T_PROC ("class_out");
- TT (genCC_H, T_ENTER);
-
- sos_String cn = ct.make_type_name();
- sos_Type_name rtn = ct.make_root_type();
-
- init_out (ct, super_closure);
-
- out_h << "class " << cn << ": public sos_Root_class \n"
- << "{ friend class " << _ID << rtn << ";\n"
- << " class " << _ID << rtn << "* " << "_ref;\n";
-
- // conversion to super classes
- out_h << "public:\n";
- agg_iterate (super_closure, sos_Super_class sc)
- { sos_Class_type sct = sc.get_super_class();
- #ifdef ATT
- if (ct.operator!=(sct))
- #else
- if (ct != sct)
- #endif
- { sos_String scn = sct.make_type_name();
- out_h << " operator " << scn << " ()";
- if (gen_inline)
- out_h << "{return(" << scn << "::make(_tpid,_ref));}";
- else
- out_c << cn << "::operator " << scn << "()"
- << "{return(" << scn << "::make(_tpid,_ref));}\n";
- out_h << ";\n";
- }
- if (NOT is_root_type (sct))
- { sos_Type_name scrtn = sct.make_root_type();
-
- out_h << " operator " << scrtn << " ()";
- if (gen_inline)
- out_h << "{return(" << scrtn << "::make(_tpid,_ref));}";
- else
- out_c << cn << "::operator " << scrtn << "()"
- << "{return(" << scrtn << "::make(_tpid,_ref));}\n";
- out_h << ";\n";
- }
- }
- agg_iterate_end (super_closure, sc);
-
- friends_out (ct);
-
- method_kind = sos_PUBLIC;
- cc_methods_out (ct);
- ccc_methods_out (ct);
- inherited_methods_out (ct);
- out_h << "};\n";
-
- TT (genCC_H, T_LEAVE);
- }
-
- static void init_out (sos_Class_type ct, sos_Super_class_List super_closure)
- {
- T_PROC ("init_out");
- TT (genCC_H, T_ENTER);
-
- sos_String cn = ct.make_type_name();
- sos_Type_name gtn = ct.make_root_type();
- sos_Typed_id tpid = ct.typed_id();
-
- out_c << "static void _init_new_" << tpid << "(){\n";
- agg_iterate (super_closure, sos_Super_class sc)
- { sos_Type_name sgtn = sc.get_super_class().make_root_type();
-
- out_c << " " << CCI << "::enter_make_obj("
- << _ID << sgtn << "_type,"
- << _ID << cn << "_type,("
- << _ID << sgtn << "*)_" << _ID << gtn << "_obj);\n";
- }
- agg_iterate_end (super_closure, sc)
- out_c << "}\n";
-
- TT (genCC_H, T_LEAVE);
- }
-
- static void friends_out (sos_Class_type ct)
- {
- T_PROC ("friends_out");
- TT (genCC_H, T_ENTER);
-
- sos_Type_name_List tnl = ct.get_friends();
- agg_iterate (tnl, sos_Type_name tn)
- { out_h << " friend class " << _ID << tn.make_type_name() << ";\n";
- }
- agg_iterate_end (tnl, tn);
-
- TT (genCC_H, T_LEAVE);
- }
-
- static void ccc_methods_out (sos_Class_type ct)
- {
- T_PROC ("ccc_method_out");
- TT (genCC_H, T_ENTER);
-
- sos_Param_List create_params = ct.get_create_params();
- sos_String cn = ct.make_type_name();
- sos_Type_name rtn = ct.make_root_type();
-
- // create
- out_h << " static " << cn << " create(sos_Container";
- if (create_params != NO_OBJECT)
- params_out (out_h, create_params, /* no_param_names */ FALSE,
- /*impl*/ FALSE, /*actual*/ FALSE, /*is_first*/ FALSE);
- out_h << ");\n";
-
- out_c << cn << " " << cn << "::create(sos_Container _cnt";
- if (create_params != NO_OBJECT)
- params_out (out_c, create_params, /* no_param_names */ FALSE,
- /*impl*/ TRUE, /*actual*/ FALSE, /*is_first*/ FALSE);
- out_c << "){\n"
- << " " << cn << " _x=" << cn
- << "::make(sos_Typed_id::allocate(" << cn << "_type,_cnt,"
- << ct.get_object_size() << "));\n"
- << " _x._ref->_create(_x._tpid";
- if (create_params != NO_OBJECT)
- params_out (out_c, create_params, /* no_param_names */ FALSE,
- /*impl*/ TRUE, /*actual*/ TRUE, /*is_first*/ FALSE);
- out_c << ");\n"
- << " return _x;\n}\n";
-
- // copy
- out_h << " static " << cn << " copy(" << cn << ",sos_Container);\n";
- out_c << cn << " " << cn << "::copy(" << cn << " y,sos_Container cnt){\n "
- << cn << " x=" << cn
- << "::make(sos_Typed_id::allocate(" << cn << "_type,cnt,"
- << ct.get_object_size() << "));\n"
- << " x._ref->_copy(x._tpid,y);\n x.assign(y);\n return x;\n}\n";
-
- // clone
- out_h << " static " << cn << " clone(" << cn << ",sos_Container);\n";
- out_c << cn << " " << cn << "::clone(" << cn << " o,sos_Container cnt){\n"
- << " return " << cn << "::make (o._ref->_clone(o._tpid,cnt));\n}\n";
-
- TT (genCC_H, T_LEAVE);
- }
-
- static void cc_methods_out (sos_Class_type ct)
- {
- T_PROC ("cc_methods_out");
- TT (genCC_H, T_ENTER);
-
- sos_String cn = ct.make_type_name();
- sos_Type_name rtn = ct.make_root_type();
-
-
- // composition
-
- out_h << " static " << cn << " make(sos_Typed_id&);\n";
- out_c << cn << " " << cn << "::make(sos_Typed_id&p){\n "
- << cn << " o; o._tpid=p;\n "
- << "o._ref=" << _ID << rtn << "::_make(p); return o;}\n";
-
- out_h << " static " << cn << " make(sos_Typed_id&p,"
- << _ID << rtn << "*r){\n "
- << cn << " o; o._tpid = p; o._ref=r; return o;}\n";
-
- // make
- out_h << " static " << cn << " make(sos_Root_class&);\n";
- out_c << cn << " " << cn << "::make(sos_Root_class& o)"
- << "{return " << cn << "::make(o.typed_id());}\n";
-
- // _size
- out_h << " sos_Offset _size();\n";
- out_c << " sos_Offset " << cn << "::_size(){return _ref->_size();}\n";
-
- TT (genCC_H, T_LEAVE);
- }
-
- static void inherited_methods_out (sos_Class_type ct)
- {
- T_PROC ("inherited_methods_out");
- TT (genCC_H, T_ENTER);
-
- sos_Method_table mt = ct.get_inherited_methods();
- sos_Bool is_root = is_root_type (ct);
-
- agg_iterate_association (mt, sos_String name, sos_Method_List ml)
- { agg_iterate (ml, sos_Method m)
- { sos_Method_kind mk = m.get_kind();
- if ((is_root OR mk == sos_PUBLIC) AND NOT is_ccc_method (m))
- { if (mk != method_kind)
- { method_kind = mk;
- out_h << method_kind << ":\n";
- }
- method_out (ct, m);
- }
- }
- agg_iterate_end (ml, m);
- }
- agg_iterate_association_end (mt, name, ml);
-
- TT (genCC_H, T_LEAVE);
- }
-
- void method_out (sos_Class_type ct, sos_Method m)
- {
- sos_String cn = ct.make_type_name();
- sos_String mn = m.get_name();
- sos_Type_name rtn = m.get_result_type();
- sos_Param_List params = m.get_params();
- sos_Bool is_static = m.get_is_static();
- sos_Bool is_operator = m.get_is_operator();
- sos_Type_name gtn = ct.make_root_type();
- sos_Method gm = m.get_generated_from();
- sos_Bool is_generated = gm != NO_OBJECT;
-
- if (is_static)
- out_h << " static ";
- else
- out_h << " ";
- out_h << rtn << " ";
- if (is_operator)
- out_h << "operator";
- out_h << mn << "(";
- params_out (out_h, params, /* no_param_names */ FALSE,
- /*impl*/ FALSE, /*actual*/ FALSE); out_h << ");\n";
-
- out_c << rtn << " " << cn << "::";
- if (is_operator)
- out_c << "operator";
- out_c << mn << "(";
- params_out (out_c, params, /* no_param_names */ FALSE,
- /*impl*/ TRUE, /*actual*/FALSE); out_c << ")";
-
- out_c << "{";
- #ifdef ATT
- if (rtn.operator!=(get_void_type()))
- #else
- if (rtn != get_void_type())
- #endif
- { out_c << "return ";
- if (is_generated)
- type_conversion_out (out_c, gm.get_result_type(), rtn, TRUE);
- }
- out_c << "(";
-
- if (is_static)
- out_c << _ID << gtn << "::";
- else
- out_c << "_ref->";
-
- if (is_operator)
- { sos_String on = cci_Method_impl::operator_string (mn);
- out_c << on;
- on.destroy();
- }
- else
- out_c << mn;
- out_c << "(";
-
- sos_Bool is_first;
- if (is_static)
- is_first = TRUE;
- else
- { is_first = FALSE;
- out_c << "_tpid";
- }
-
- if (is_generated)
- params_and_type_conversion_out
- (out_c, gm.get_params(), params, is_first);
- else
- params_out (out_c, params, /* no_param_names */ FALSE,
- /*impl*/ TRUE, /*actual*/ TRUE, is_first);
- out_c << "));}\n";
- }
-
- static void type_conversion_out (ostream& out_f,
- sos_Type_name generic_tn,
- sos_Type_name replaced_tn,
- sos_Bool from_gen)
- {
- T_PROC ("type_conversion_out");
- TT (genCC_H, T_ENTER);
-
- sos_Type gt = generic_tn.make_type();
- sos_Type rt = replaced_tn.make_type();
-
- if (NOT gt.equal (rt))
- { if (from_gen)
- { if (is_generic_parameter (generic_tn))
- if (rt.is_scalar ())
- out_f << "::make_" << replaced_tn;
- else
- out_f << replaced_tn << "::make";
- }
- else
- { if (is_generic_parameter (generic_tn))
- if (rt.is_scalar ())
- out_f << "::make_" << replaced_tn << "_object";
- else
- {
- #ifdef ATT
- if (rt.is_derived_from (gt) OR rt.root().operator==(gt))
- #else
- if (rt.is_derived_from (gt) OR rt.root() == gt)
- #endif
- out_f << generic_tn;
- else
- out_f << generic_tn << "::make";
- }
- }
- }
-
- TT (genCC_H, T_LEAVE);
- }
-
- static void params_and_type_conversion_out (ostream& out_f,
- sos_Param_List generic_pl,
- sos_Param_List replaced_pl,
- sos_Bool first)
- {
- T_PROC ("params_and_type_conversion_out");
- TT (genCC_H, T_ENTER);
-
- sos_Int i = 1;
- agg_iterate_double (generic_pl, sos_Param gen_p,
- replaced_pl, sos_Param repl_p, sos_Int comp)
- { sos_String pn = repl_p.get_name();
-
- if (NOT first)
- out_f << ",";
- else
- first = FALSE;
-
- type_conversion_out (out_c, gen_p.get_type_name(),
- repl_p.get_type_name(), FALSE);
-
- if (pn != NO_OBJECT)
- out_f << "(" << pn << ")";
- else
- out_f << "(_p" << i << ")";
- i++;
- }
- agg_iterate_double_end (generic_pl, gen_p, replaced_pl, repl_p, comp);
- TT (genCC_H, T_LEAVE);
- }
-
- static void params_out (ostream& out_f,
- sos_Param_List pl,
- sos_Bool no_param_names,
- sos_Bool impl,
- sos_Bool actual,
- sos_Bool first,
- sos_Int start)
- {
- T_PROC ("params_out");
- TT (genCC_H, T_ENTER);
-
- sos_Int i, c;
- c = pl.card();
-
- for (i=start; i<=c; i++)
- { sos_Param p = pl.get_nth(i);
- sos_String pn = p.get_name();
- sos_Type_name tn = p.get_type_name();
- sos_Expr e = p.get_default_expr();
-
- if (NOT first)
- out_f << ",";
- else
- first = FALSE;
-
- if (NOT actual)
- { out_f << tn;
- if (p.get_is_ref())
- out_f << "& ";
- else
- out_f << " ";
- }
-
- if (NOT no_param_names)
- {
- if (pn != NO_OBJECT)
- out_f << pn;
- else
- out_f << "_p" << i;
-
- if (NOT impl AND NOT actual AND e != NO_OBJECT)
- out_f << " = " << e;
- }
- }
-
- TT (genCC_H, T_LEAVE);
- }
-
- static void exprs_out (ostream& out_f, sos_Expr_List el, sos_Bool is_first)
- {
- T_PROC ("ostream& operator<<");
- TT (genCC_H, T_ENTER);
-
- agg_iterate (el, sos_Expr e)
- { if (is_first)
- is_first = FALSE;
- else
- out_f << ",";
- out_f << e;
- }
- agg_iterate_end (el, e);
-
- TT (genCC_H, T_LEAVE);
- }
-
- static ostream& operator<< (ostream& out_f, sos_String_List sl)
- {
- T_PROC ("ostream& operator<<");
- TT (genCC_H, T_ENTER);
-
- sos_Bool is_first = TRUE;
- agg_iterate (sl, sos_String s)
- { if (is_first)
- is_first = FALSE;
- else
- out_f << ",";
- out_f << s;
- }
- agg_iterate_end (sl, s);
-
- TT (genCC_H, T_LEAVE);
- return out_f;
- }
-
- static ostream& operator<< (ostream& out_f, sos_Type_name tn)
- {
- T_PROC ("ostream& operator<<");
- TT (genCC_H, T_ENTER);
-
- err_assert (NOT tn.has_type(sos_String_type), "operator<<");
-
- out_f << tn.make_type_name ();
-
- TT (genCC_H, T_LEAVE);
- return out_f;
- }
-
- static ostream& operator<< (ostream& out_f, sos_Param_List pl)
- {
- T_PROC ("ostream& operator<<");
- TT (genCC_H, T_ENTER);
-
- sos_Bool is_first = TRUE;
- agg_iterate (pl, sos_Param p)
- { if (is_first)
- is_first = FALSE;
- else
- out_f << ",";
- out_f << p;
- }
- agg_iterate_end (pl, p);
-
- TT (genCC_H, T_LEAVE);
- return (out_f);
- }
-
- static ostream& operator<< (ostream& out_f, sos_Param p)
- {
- T_PROC ("ostream& operator<<");
- TT (genCC_H, T_ENTER);
-
- sos_Expr expr = p.get_default_expr();
- sos_String name = p.get_name();
-
- out_f << p.get_type_name();
- if (name != NO_OBJECT)
- out_f << " " << name;
- if (expr != NO_OBJECT)
- out_f << " = " << expr;
-
- TT (genCC_H, T_LEAVE);
- return (out_f);
- }
-
- static ostream& operator<< (ostream& out_f, sos_Expr_List el)
- {
- T_PROC ("ostream& operator<<");
- TT (genCC_H, T_ENTER);
-
- exprs_out (out_f, el, TRUE);
-
- TT (genCC_H, T_LEAVE);
- return (out_f);
- }
-
- static ostream& operator<< (ostream& out_f, sos_Expr e)
- {
- T_PROC ("ostream& operator<<");
- TT (genCC_H, T_ENTER);
-
- if (e.has_type(sos_Identifier_type))
- out_f << sos_Identifier::make(e).get_id();
- else // e has_type sos_Int_expr_type
- { sos_Int_expr i;
- i = sos_Int_expr::make(e);
- out_f << i.get_value();
- }
-
- TT (genCC_H, T_LEAVE);
- return (out_f);
- }
-
- static ostream& operator<< (ostream& out_f, sos_Typed_id tpid)
- {
- T_PROC ("ostream& operator<<");
- TT (genCC_H, T_ENTER);
-
- out_f << sos_Int(tpid.container()) << "_" << tpid.offset();
-
- TT (genCC_H, T_LEAVE);
- return (out_f);
- }
-
- static ostream& operator<< (ostream& out_f, sos_Method_kind mk)
- {
- T_PROC ("ostream& operator<<");
- TT (genCC_H, T_ENTER);
-
- switch (mk)
- { case sos_PRIVATE: out_f << "private"; break;
- case sos_PROTECTED: out_f << "protected"; break;
- case sos_PUBLIC: out_f << "public"; break;
- }
-
- TT (genCC_H, T_LEAVE);
- return (out_f);
- }
-
- static sos_Bool is_root_type (sos_Type tp)
- {
- #ifdef ATT
- return tp.operator==(tp.root());
- #else
- return tp == tp.root();
- #endif
- }
-
- static sos_Bool is_generic_parameter (sos_Type_name tn)
- {
- if (tn.has_type(sos_Gen_param_type))
- return TRUE;
- else if (tn.has_type(sos_Generic_instantiation_type))
- { sos_Type_name_List gpl =
- sos_Generic_instantiation::make(tn).get_gen_params();
-
- sos_Bool is_gen_par = FALSE;
- agg_iterate (gpl, sos_Type_name gp)
- { is_gen_par = is_generic_parameter (gp);
- if (is_gen_par) break;
- }
- agg_iterate_end (gpl, gp);
-
- return (is_gen_par);
- }
- else return FALSE;
- }
-
- static sos_Bool is_ccc_method (sos_Method m)
- { smg_String mn = m.get_name().make_Cstring();
- return (sos_Bool) (m.get_is_predefined() AND
- (mn.equal ("create") OR mn.equal ("copy")
- OR mn.equal ("clone")));
- }
-
- static sos_Schema_type *the_void_type;
-
- // *************************************************************************
- sos_Schema_type get_void_type()
- // *************************************************************************
- {
- T_PROC ("get_void_type");
- TT (genCC_H, T_ENTER);
-
- sos_Schema_type result;
- if (the_void_type)
- result = *the_void_type;
- else
- {
- #ifdef BOOT
- result = generated_schema.lookup_type (
- smg_String ("void").make_String (TEMP_CONTAINER));
- #else
- result = sos_Schema_type::make (void_type);
- #endif
- the_void_type = new sos_Schema_type;
- *the_void_type = result;
- }
-
- TT (genCC_H, T_LEAVE);
-
- return (result);
- }
-
- static sos_Schema_type *the_scalar_object_type;
-
- // *************************************************************************
- static sos_Schema_type get_scalar_object_type()
- // *************************************************************************
- {
- T_PROC ("get_scalar_object_type");
- TT (genCC_H, T_ENTER);
-
- sos_Schema_type result;
- if (the_scalar_object_type)
- result = *the_scalar_object_type;
- else
- {
- #ifdef BOOT
- result = generated_schema.lookup_type (
- smg_String ("sos_Scalar_object").make_String (TEMP_CONTAINER));
- #else
- result = sos_Schema_type::make (sos_Scalar_object_type);
- #endif
- the_scalar_object_type = new sos_Schema_type;
- *the_scalar_object_type = result;
- }
-
- TT (genCC_H, T_LEAVE);
-
- return (result);
- }
-