home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / sos3-2.lha / src / mta / mta.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-23  |  32.7 KB  |  1,198 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 mta                       03/06/89                 Juergen Uhl (ju)
  13. //
  14. // **************************************************************************
  15. // implements methods of all classes declared in schema "mta" 
  16. // **************************************************************************
  17.  
  18. #include "sys.h"
  19. #include "smg.h"
  20. #include "mta_err.h"
  21. #include "trc_mta.h"
  22.  
  23. #include "dir_use.h"
  24. #include "cci_use.h"
  25.  
  26. #include "mta_sos.h"
  27.  
  28. static sos_Schema_type get_object_type();
  29. static sos_Schema_type get_scalar_object_type();
  30.  
  31. // *************************************************************************
  32. sos_Schema_type sos_Imports::lookup_type (sos_String name,
  33.                       sos_Bool   look_for_alias)
  34. // *************************************************************************
  35.  
  36. {  
  37.    T_PROC ("sos_Imports::lookup_type");
  38.    TT (mta_H, T_ENTER);
  39.  
  40.    sos_Schema_type result = sos_Schema_type::make (NO_OBJECT);
  41.    sos_Imports     imp    = self;
  42.    agg_iterate (imp, sos_Schema_module sm)
  43.    {  result = sm.get_type_table()[name];
  44.       if (result != NO_OBJECT)
  45.      if (NOT look_for_alias AND
  46.          NOT result.get_name().equal(name))
  47.         result = sos_Schema_type::make (NO_OBJECT);
  48.      else
  49.         break;
  50.    }
  51.    agg_iterate_end (imp, sm);
  52.  
  53.    TT (mta_H, T_LEAVE);
  54.  
  55.    return result;
  56. }
  57.  
  58. // *************************************************************************
  59. sos_Schema_module_Directory sos_Schema_module::schema_dir ()
  60. // *************************************************************************
  61. {
  62.    T_PROC ("sos_Schema_module::schema_dir");
  63.    TT (mta_H, T_ENTER);
  64.  
  65.    sos_String name;
  66.    sos_Schema_module_Directory dir;
  67.    sos_Directory root_dir;
  68.  
  69.    name = smg_String ("sos_schemas").make_String (TEMP_CONTAINER);
  70.    ROOT_CONTAINER.open (READING, WAITING);
  71.    root_dir = sos_Object_Directory::root();
  72.    dir = sos_Schema_module_Directory::make (root_dir [name]);
  73.    ROOT_CONTAINER.close ();
  74.    if (dir == NO_OBJECT)
  75.    {  dir = sos_Schema_module_Directory::create (sos_Container::create(), name);
  76.       ROOT_CONTAINER.open (WRITING, WAITING);
  77.       root_dir.insert (name, dir);
  78.       ROOT_CONTAINER.close ();
  79.    }
  80.    name.destroy();
  81.  
  82.    TT (mta_H, T_LEAVE);
  83.  
  84.    return dir;
  85. }
  86.  
  87. // *************************************************************************
  88. sos_Schema_module sos_Schema_module::lookup (sos_String name)
  89. // *************************************************************************
  90. {  T_PROC ("sos_Schema_module::lookup")
  91.    TT (mta_H, T_ENTER);
  92.  
  93.    sos_Schema_module sm;
  94.    sos_Schema_module_Directory sd = sos_Schema_module::schema_dir ();
  95.  
  96.    sd.container().open (READING, WAITING);
  97.    if (sd.is_key (name))
  98.       sm = sos_Schema_module::make (sd [name]);
  99.    else
  100.       sm = sos_Schema_module::make (NO_OBJECT);
  101.    sd.container().close ();
  102.  
  103.    TT (mta_H, T_LEAVE);
  104.  
  105.    return sm;
  106. }
  107.  
  108. // *************************************************************************
  109. sos_Schema_module sos_Schema_module::retrieve (sos_Container ct)
  110. // *************************************************************************
  111. {  T_PROC ("sos_Schema_module::retrieve")
  112.    TT (mta_H, T_ENTER);
  113.  
  114.    sos_Schema_module sm = sos_Schema_module::make (ct.root_object());
  115.  
  116.    TT (mta_H, T_LEAVE);
  117.    return sm;
  118. }
  119.  
  120. // *************************************************************************
  121. sos_Schema_type sos_Schema_module::lookup_type
  122.                      (sos_String name, sos_Bool look_for_alias)
  123. // *************************************************************************
  124.  
  125. // search for a type declaration with 'name' in the type table
  126. // of the schema module. If no declaration is found search for 'name'
  127. // in the type tables of the imported modules. If the search fails
  128. // return NO_OBJECT.
  129.  
  130. {  T_PROC ("sos_Schema_module::lookup_type")
  131.    TT (mta_H, T_ENTER);
  132.  
  133.    sos_Schema_type result;
  134.    sos_Type_table  tt = self.get_type_table();
  135.  
  136.    result = tt[name];
  137.    if (result == NO_OBJECT)
  138.       result = self.get_imports().lookup_type (name, look_for_alias);
  139.    else if (NOT look_for_alias AND
  140.         NOT result.get_name().equal(name))
  141.       result = sos_Schema_type::make (NO_OBJECT);
  142.  
  143.    TT (mta_H, T_LEAVE);
  144.  
  145.    return result;
  146. }
  147.  
  148. // *************************************************************************
  149. void sos_Schema_module::open_imports ()
  150. // *************************************************************************
  151. {
  152.    T_PROC ("sos_Schema_module::open_imports");
  153.    TT (mta_H, T_ENTER);
  154.  
  155.    sos_Imports imp = self.get_imports();
  156.    agg_iterate (imp, sos_Schema_module sm)
  157.    {  sm.container().open(READING, WAITING);
  158.    }
  159.    agg_iterate_end (imp, sm);
  160.  
  161.    TT (mta_H, T_LEAVE);
  162. }
  163.  
  164. // *************************************************************************
  165. void sos_Schema_module::close_imports ()
  166. // *************************************************************************
  167. {
  168.    T_PROC ("sos_Schema_module::close_imports");
  169.    TT (mta_H, T_ENTER);
  170.  
  171.    sos_Imports imp = self.get_imports();
  172.    agg_iterate (imp, sos_Schema_module sm)
  173.    {  sm.container().close();
  174.    }
  175.    agg_iterate_end (imp, sm);
  176.  
  177.    TT (mta_H, T_LEAVE);
  178. }
  179.  
  180. // *************************************************************************
  181. void sos_Schema_module::install ()
  182. // *************************************************************************
  183. {
  184.    T_PROC ("sos_Schema_module::install");
  185.    TT (mta_H, T_ENTER);
  186.  
  187.    sos_String str;
  188.    sos_Container ct;
  189.    sos_Schema_module_Directory sd = sos_Schema_module::schema_dir ();
  190.  
  191.    sd.container().open (WRITING, WAITING);
  192.    str = self.get_name ();
  193.    if (sd.is_key (str))
  194.    {  // not yet implemented:
  195.       // info that schemas must be recompiled
  196.       ct = sd[str].container();
  197.       sd.remove (str);
  198.       ct.open (WRITING, WAITING);
  199.       ct.destroy();
  200.       ct.close();
  201.    }
  202.  
  203.    sd.insert (str, self);
  204.    sd.container().close ();
  205.  
  206.    TT (mta_H, T_LEAVE);
  207. }
  208.  
  209. // *************************************************************************
  210. sos_Schema_type sos_Type_name::make_base_type ()
  211. // *************************************************************************
  212. {  
  213.    T_PROC ("sos_Type_name::make_base_type");
  214.    TT (mta_H, T_ENTER);
  215.  
  216.    sos_Schema_type result = self.make_type();
  217.  
  218.    TT (mta_H, T_LEAVE);
  219.  
  220.    return result;
  221. }
  222.  
  223. // *************************************************************************
  224. sos_Expr_List sos_Type_name::create_params ()
  225. // *************************************************************************
  226. {  
  227.    T_PROC ("sos_Type_name::create_params");
  228.    TT (mta_H, T_ENTER);
  229.  
  230.    sos_Expr_List result = sos_Expr_List::make (NO_OBJECT);
  231.  
  232.    TT (mta_H, T_LEAVE);
  233.  
  234.    return result;
  235. }
  236.  
  237. // *************************************************************************
  238. sos_Schema_type sos_Type_name::make_root_type ()
  239. // *************************************************************************
  240. {  
  241.    T_PROC ("sos_Type_name::make_root_type");
  242.    TT (mta_H, T_ENTER);
  243.  
  244.    sos_Schema_type result = self.make_base_type();
  245.    if (NOT self.identical (result))
  246.       result = result.make_root_type();
  247.  
  248.    TT (mta_H, T_LEAVE);
  249.  
  250.    return result;
  251. }
  252.  
  253. // *************************************************************************
  254. sos_Schema_type sos_Schema_type::make_type ()
  255. // *************************************************************************
  256. {  
  257.    T_PROC ("sos_Schema_type::make_type");
  258.    TT (mta_H, T_ENTER);
  259.  
  260.    sos_Schema_type result = self;
  261.  
  262.    TT (mta_H, T_LEAVE);
  263.  
  264.    return result;
  265. }
  266.  
  267. // *************************************************************************
  268. sos_String sos_Schema_type::make_type_name ()
  269. // *************************************************************************
  270. {  
  271.    T_PROC ("sos_Schema_type::make_type_name");
  272.    TT (mta_H, T_ENTER);
  273.  
  274.    sos_String result = self.get_name();
  275.  
  276.    TT (mta_H, T_LEAVE);
  277.  
  278.    return result;
  279. }
  280.  
  281. // *************************************************************************
  282. sos_Bool sos_Schema_type::is_derived_from (sos_Type tp)
  283. // *************************************************************************
  284. {
  285.    T_PROC ("sos_Schema_type::is_derived_from");
  286.    TT (mta_H, T_ENTER);
  287.  
  288.    sos_Bool result;
  289.  
  290.    sos_Type b1 = self.base ();
  291.    sos_Type b2 = tp.base ();
  292.  
  293. #ifdef ATT
  294.    if (b1.operator== (b2))
  295. #else
  296.    if (b1 == b2)
  297. #endif
  298.       result = TRUE;
  299.    else
  300.    {
  301. #ifdef ATT
  302.       if (self.operator!= (b1)  OR  tp.operator!= (b2))
  303. #else
  304.       if (self != b1 OR tp != b2)
  305. #endif
  306.      result = b1.is_derived_from (b2);
  307.       else if (b1.has_type (sos_Extern_type_type) OR
  308.            b1.has_type (sos_Enum_type_type))
  309.      result = get_scalar_object_type().is_derived_from (b2);
  310.         // this handles the cases:
  311.         //  - b2 is no scalar type
  312.         //  - b2 is a scalar type different from b1
  313.         // 'b2 is a scalar type identical with b1' is handled above
  314.       else
  315.      result = (sos_Bool)(b1.equal (b2) OR
  316.                  b2.equal (get_object_type()));
  317.    }
  318.  
  319.    TT (mta_H, T_LEAVE; TB (result));
  320.  
  321.    return result;
  322. }
  323.  
  324. // *************************************************************************
  325. sos_Bool sos_Schema_type::is_derived_from_some (sos_Type tp)
  326. // *************************************************************************
  327. {
  328.    T_PROC ("sos_Schema_type::is_derived_from_some");
  329.    TT (mta_H, T_ENTER);
  330.  
  331.    sos_Bool result;
  332.  
  333.    sos_Type b1 = self.base ();
  334.    sos_Type b2 = tp.base ();
  335.  
  336. #ifdef ATT
  337.    if (b1.operator== (b2))
  338. #else
  339.    if (b1 == b2)
  340. #endif
  341.       result = TRUE;
  342.    else
  343.    {
  344. #ifdef ATT
  345.       if (self.operator!= (b1)  OR  tp.operator!= (b2))
  346. #else
  347.       if (self != b1 OR tp != b2)
  348. #endif
  349.      result = b1.is_derived_from_some (b2);
  350.       else if (b1.has_type (sos_Extern_type_type) OR
  351.            b1.has_type (sos_Enum_type_type))
  352.      result = get_scalar_object_type().is_derived_from_some (b2);
  353.         // this handles the cases:
  354.         //  - b2 is no scalar type
  355.         //  - b2 is a scalar type different from b1
  356.         // 'b2 is a scalar type identical with b1' is handled above
  357.       else
  358.      result = (sos_Bool)(b1.equal (b2) OR
  359.                  b2.equal (get_object_type()));
  360.    }
  361.  
  362.    TT (mta_H, T_LEAVE; TB (result));
  363.  
  364.    return result;
  365. }
  366.  
  367. // *************************************************************************
  368. sos_Type sos_Schema_type::base ()
  369. // *************************************************************************
  370. {  
  371.    T_PROC ("sos_Schema_type::base");
  372.    TT (mta_H, T_ENTER);
  373.  
  374.    sos_Type t = self.make_base_type();
  375.  
  376.    TT (mta_H, T_LEAVE);
  377.  
  378.    return t;
  379. }
  380.  
  381. // *************************************************************************
  382. sos_Bool sos_Schema_type::is_scalar ()
  383. // *************************************************************************
  384. {  T_PROC ("sos_Schema_type::is_scalar")
  385.    TT (mta_H, T_ENTER);
  386.  
  387.    sos_Type bt = self.base ();
  388.    sos_Bool result = (sos_Bool) (bt.has_type (sos_Extern_type_type) OR
  389.                  bt.has_type (sos_Enum_type_type));
  390.  
  391.    TT (mta_H, T_LEAVE; TB (result));
  392.    return result;
  393. }
  394.  
  395. // *************************************************************************
  396. sos_Bool sos_Schema_type::total_equal (sos_Schema_type x,
  397.                        sos_Object      o,
  398.                        sos_Eq_kind       )
  399. // *************************************************************************
  400. {
  401.    T_PROC ("sos_Schema_type::total_equal");
  402.    TT (mta_H, T_ENTER);
  403.  
  404.    sos_Bool result;
  405.  
  406.    sos_Type y = sos_Type::make (o);
  407.    sos_Type b1 = x.base ();
  408.    sos_Type b2 = y.base ();
  409.  
  410. #ifdef ATT
  411.    if (x.operator!= (b1)  OR  y.operator!= (b2))
  412.       result = b1.equal (b2);
  413.    else
  414.       result = b1.operator==(b2);
  415. #else
  416.    if (x != b1 OR y != b2)
  417.       result = b1.equal (b2);
  418.    else
  419.       result = b1 == b2;
  420. #endif
  421.  
  422.    TT (mta_H, T_LEAVE; TB (result));
  423.  
  424.    return result;
  425. }
  426.  
  427. // *************************************************************************
  428. sos_Int sos_Schema_type::total_hash_value (sos_Schema_type)
  429. // *************************************************************************
  430. {
  431.    T_PROC ("sos_Schema_type::total_hash_value");
  432.    TT (mta_H, T_ENTER);
  433.  
  434.    sos_Int result = 0;
  435.  
  436.    TT (mta_H, T_LEAVE; TB (result));
  437.  
  438.    return result;
  439. }
  440.  
  441. // *************************************************************************
  442. sos_Schema_type sos_Unidentified_type::make_type ()
  443. // *************************************************************************
  444. {  
  445.    T_PROC ("sos_Unidentified_type::make_type");
  446.    TT (mta_H, T_ENTER);
  447.  
  448.    sos_Schema_type result = sos_Schema_type::make (NO_OBJECT);
  449.  
  450.    TT (mta_H, T_LEAVE);
  451.  
  452.    return result;
  453. }
  454.  
  455. // *************************************************************************
  456. sos_String sos_Unidentified_type::make_type_name ()
  457. // *************************************************************************
  458. {  
  459.    T_PROC ("sos_Unidentified_type::make_type_name");
  460.    TT (mta_H, T_ENTER);
  461.  
  462.    sos_String result = self.get_name();
  463.  
  464.    TT (mta_H, T_LEAVE);
  465.  
  466.    return result;
  467. }
  468.  
  469. // *************************************************************************
  470. sos_Expr_List sos_Type_with_params::create_params ()
  471. // *************************************************************************
  472. {  
  473.    T_PROC ("sos_Type_with_params::create_params");
  474.    TT (mta_H, T_ENTER);
  475.  
  476.    sos_Expr_List result = self.get_params();
  477.  
  478.    TT (mta_H, T_LEAVE);
  479.  
  480.    return result;
  481. }
  482.  
  483. // *************************************************************************
  484. sos_Schema_type sos_Type_with_params::make_type ()
  485. // *************************************************************************
  486. {  
  487.    T_PROC ("sos_Type_with_params::make_type");
  488.    TT (mta_H, T_ENTER);
  489.  
  490.    sos_Schema_type result = self.get_type_name().make_type();
  491.  
  492.    TT (mta_H, T_LEAVE);
  493.  
  494.    return result;
  495. }
  496.  
  497. // *************************************************************************
  498. sos_String sos_Type_with_params::make_type_name ()
  499. // *************************************************************************
  500. {  
  501.    T_PROC ("sos_Type_with_params::make_type_name");
  502.    TT (mta_H, T_ENTER);
  503.  
  504.    sos_String result = self.get_type_name().make_type_name();
  505.  
  506.    TT (mta_H, T_LEAVE);
  507.  
  508.    return result;
  509. }
  510.  
  511. // *************************************************************************
  512. sos_Schema_type sos_Generic_instantiation::make_type ()
  513. // *************************************************************************
  514. {  
  515.    T_PROC ("sos_Generic_instantiation::make_type");
  516.    TT (mta_H, T_ENTER);
  517.  
  518.    sos_Schema_type result = self.get_instantiation();
  519.  
  520.    TT (mta_H, T_LEAVE);
  521.  
  522.    return result;
  523. }
  524.  
  525. // *************************************************************************
  526. sos_String sos_Generic_instantiation::make_type_name ()
  527. // *************************************************************************
  528. {  
  529.    T_PROC ("sos_Generic_instantiation::make_type_name");
  530.    TT (mta_H, T_ENTER);
  531.  
  532.    sos_String result = self.get_instantiation().make_type_name();
  533.  
  534.    TT (mta_H, T_LEAVE);
  535.  
  536.    return result;
  537. }
  538.  
  539. // *************************************************************************
  540. sos_Bool sos_Generic_instantiation::is_universal ()
  541. // *************************************************************************
  542. {  
  543.    T_PROC ("sos_Generic_instantiation::is_universal");
  544.    TT (mta_H, T_ENTER);
  545.  
  546.    sos_Class_type gen_t = self.get_gen();
  547.  
  548.    sos_Type_name_List tnl = self.get_gen_params();
  549.    sos_Gen_param_List gpl = sos_Class_type::make (gen_t).get_gen_params();
  550.  
  551.    sos_Bool is_universal = TRUE;
  552.    sos_Cursor c1 = tnl.open_cursor ();
  553.    sos_Cursor c2 = gpl.open_cursor ();
  554.    for (sos_Bool valid1 = tnl.is_valid (c1),
  555.          valid2 = gpl.is_valid (c2);
  556.         valid1 AND valid2 AND is_universal;
  557.         valid1 = tnl.to_succ (c1), valid2 = gpl.to_succ (c2))
  558.    {  is_universal =
  559.       tnl.get(c1).make_base_type ().equal (gpl.get(c2).make_base_type());
  560.    }
  561.    tnl.close_cursor (c1);
  562.    gpl.close_cursor (c2);
  563.  
  564.  
  565.    TT (mta_H, T_LEAVE);
  566.  
  567.    return is_universal;
  568. }
  569.  
  570. // *************************************************************************
  571. sos_Schema_type sos_Gen_param::make_type ()
  572. // *************************************************************************
  573. {  
  574.    T_PROC ("sos_Gen_param::make_type");
  575.    TT (mta_H, T_ENTER);
  576.  
  577.    sos_Type_name sc = self.get_super_class();
  578.    sos_Schema_type result;
  579.    if (sc == NO_OBJECT)
  580.       result = (get_object_type());
  581.    else
  582.       result = sc.make_type ();
  583.  
  584.    TT (mta_H, T_LEAVE);
  585.  
  586.    return result;
  587. }
  588.  
  589. // *************************************************************************
  590. sos_String sos_Gen_param::make_type_name ()
  591. // *************************************************************************
  592. {  
  593.    T_PROC ("sos_Gen_param::make_type_name");
  594.    TT (mta_H, T_ENTER);
  595.  
  596.    sos_Type_name sc = self.get_super_class();
  597.    sos_String result;
  598.    if (sc == NO_OBJECT)
  599.       result = (get_object_type().make_type_name());
  600.    else
  601.       result = sc.make_type_name();
  602.  
  603.    TT (mta_H, T_LEAVE);
  604.  
  605.    return result;
  606. }
  607.  
  608. // *************************************************************************
  609. sos_Bool sos_Method::overloads (sos_Method m)
  610. // *************************************************************************
  611. // precondition: self.name == m.name
  612. {  
  613.    T_PROC ("sos_Method::overloads");
  614.    TT (mta_H, T_ENTER);
  615.  
  616.    sos_Bool result = (sos_Bool)
  617.             (self.get_is_static() == m.get_is_static() AND
  618.              self.get_params().card() != m.get_params().card());
  619.  
  620.    TT (mta_H, T_LEAVE; TB(result));
  621.    return result;
  622. }
  623.  
  624. // *************************************************************************
  625. sos_Bool sos_Method::redefines (sos_Method m)
  626. // *************************************************************************
  627. {  
  628. // precondition: self.get_name() == m.get_name()
  629.  
  630.    T_PROC ("sos_Method::redefines");
  631.    TT (mta_H, T_ENTER);
  632.  
  633.    sos_Bool result;
  634.  
  635.    if (self.get_is_static() != m.get_is_static())
  636.       result = FALSE;
  637.    else
  638.    {  sos_Type ts = self.get_result_type().make_base_type();
  639.       sos_Type tm =    m.get_result_type().make_base_type();
  640.       
  641.       if (ts.equal (tm))
  642.       {  result             = TRUE;
  643.          sos_Param_List pls = self.get_params();
  644.          sos_Param_List plm =    m.get_params();
  645.  
  646.          sos_Int comp = 0;
  647.          agg_iterate_double (pls, sos_Param ps, plm, sos_Param pm, comp)
  648.          {  ts = ps.get_type_name().make_base_type();
  649.         tm = pm.get_type_name().make_base_type();
  650.         result = ts.equal (tm);
  651.         if (NOT result) break;
  652.          }
  653.          agg_iterate_double_end (pls, ps, plm, pm, comp);
  654.          result = (sos_Bool)(result AND comp == 0);
  655.       }
  656.       else
  657.          result = FALSE;
  658.    }
  659.  
  660.    TT (mta_H, T_LEAVE; TB(result));
  661.    return result;
  662. }
  663.  
  664. // *************************************************************************
  665. sos_Object sos_Method::execute (sos_Object o, sos_Object_Array p)
  666. // *************************************************************************
  667. {  
  668.    T_PROC ("sos_Method::is_execute");
  669.    TT (mta_H, T_ENTER);
  670.  
  671.    sos_Object result;
  672.    sos_Method_impl_List impls = self.get_impls();
  673.    sos_Bool found = FALSE;
  674.    if (impls != NO_OBJECT)
  675.    {  agg_iterate (impls, sos_Method_impl impl)
  676.       {  if (impl.isa (cci_Method_impl_type))
  677.      {  result = cci_Method_impl::make (impl).execute (o, p);
  678.         found = TRUE;
  679.         break;
  680.      }
  681.       }
  682.       agg_iterate_end (impls, impl);
  683.    }
  684.    if (NOT found)
  685.       err_raise (err_SYS, err_MTA_METHOD_NOT_EXECUTABLE,
  686.               self.get_name().make_Cstring());
  687.  
  688.    TT (mta_H, T_LEAVE);
  689.    return result;
  690. }
  691.  
  692. // *************************************************************************
  693. sos_Method sos_Method_table::lookup (sos_Method m)
  694. // *************************************************************************
  695. {
  696.    T_PROC ("sos_Method_table::lookup");
  697.    TT (mta_H, T_ENTER);
  698.  
  699.    sos_Method result = sos_Method::make (NO_OBJECT);
  700.    sos_String m_name = m.get_name();
  701.  
  702.    if (self.is_key (m_name))
  703.    {  sos_Method_List ml = self[m_name];
  704.  
  705.       agg_iterate (ml, sos_Method m1)
  706.       {  if (NOT m.overloads (m1))
  707.      {  result = m1;
  708.         break;
  709.      }
  710.       }
  711.       agg_iterate_end (ml, m1);
  712.    }
  713.  
  714.    TT (mta_H, T_LEAVE);
  715.    return result;
  716. }
  717.  
  718. // *************************************************************************
  719. sos_Method sos_Method_table::lookup_or_add (sos_Method m)
  720. // *************************************************************************
  721. {
  722.    T_PROC ("sos_Method_table::lookup_or_add");
  723.    TT (mta_H, T_ENTER);
  724.  
  725.    sos_Method result;
  726.    sos_String m_name = m.get_name();
  727.    sos_Method_List ml;
  728.    sos_Bool found = FALSE;
  729.  
  730.    if (self.is_key (m_name))
  731.    {  ml = self[m_name];
  732.  
  733.       agg_iterate (ml, sos_Method m1)
  734.          if (NOT m.overloads (m1))
  735.      {  found = TRUE;
  736.         result = m1;
  737.         break;
  738.      }
  739.       agg_iterate_end (ml, m1);
  740.    }
  741.    else
  742.    {  ml = sos_Method_List::create (self.container(), FALSE);
  743.       self.insert (m_name, ml);
  744.    }
  745.  
  746.    if (NOT found)
  747.    {  ml.append (m);
  748.       result = m;
  749.    }
  750.  
  751.    TT (mta_H, T_LEAVE;TB(found));
  752.    return result;
  753. }
  754.  
  755. // *************************************************************************
  756. sos_Method sos_Method_table::replace_or_add (sos_Method m)
  757. // *************************************************************************
  758. {
  759.    T_PROC ("sos_Method_table::replace_or_add");
  760.    TT (mta_H, T_ENTER);
  761.  
  762.    sos_Method      result;
  763.    sos_String      m_name = m.get_name();
  764.    sos_Method_List ml;
  765.    sos_Bool        found = FALSE;
  766.  
  767.    if (self.is_key (m_name))
  768.    {  ml = self[m_name];
  769.  
  770.       sos_Cursor c = ml.open_cursor();
  771.       for (sos_Bool valid = ml.is_valid (c); valid; valid = ml.to_succ (c))
  772.       {  sos_Method m1 = ml.get(c);
  773.          if (NOT m.overloads (m1))
  774.      {  ml.set (c, m);
  775.         found = TRUE;
  776.         result = m1;
  777.         break;
  778.      }
  779.       }
  780.       ml.close_cursor (c);
  781.    }
  782.    else
  783.    {  ml = sos_Method_List::create (self.container(), FALSE);
  784.       self.insert (m_name, ml);
  785.    }
  786.  
  787.    if (NOT found)
  788.    {  ml.append (m);
  789.       result = m;
  790.    }
  791.  
  792.    TT (mta_H, T_LEAVE);
  793.    return result;
  794. }
  795.  
  796. // *************************************************************************
  797. sos_Comp_method sos_Method_table::lookup_comp (sos_String name,
  798.                            sos_Bool   is_set)
  799. // *************************************************************************
  800. {
  801.    T_PROC ("sos_Method_table::lookup_comp");
  802.    TT (mta_H, T_ENTER);
  803.  
  804.    sos_String mn = sos_String::create(TEMP_CONTAINER);
  805.    if (is_set)
  806.       mn.assign_Cstring ("set_");
  807.    else
  808.       mn.assign_Cstring ("get_");
  809.    mn += name;
  810.  
  811.    sos_Comp_method result = sos_Comp_method::make (NO_OBJECT);
  812.  
  813.    if (self.is_key (mn))
  814.    {  sos_Method_List ml = self[mn];
  815.  
  816.       agg_iterate (ml, sos_Method m)
  817.          if (m.has_type (sos_Comp_method_type))
  818.      {  result = sos_Comp_method::make (m);
  819.         break;
  820.      }
  821.       agg_iterate_end (ml, m);
  822.    }
  823.  
  824.    mn.destroy();
  825.  
  826.    TT (mta_H, T_LEAVE);
  827.    return result;
  828. }
  829.  
  830. // *************************************************************************
  831. sos_Bool sos_Union_type::local_equal (sos_Union_type,sos_Object,sos_Eq_kind)
  832. // *************************************************************************
  833. {  
  834.    T_PROC ("sos_Union_type::local_equal");
  835.    TT (mta_H, T_ENTER);
  836.  
  837.    sos_Bool result = TRUE;
  838.  
  839.    TT (mta_H, T_LEAVE);
  840.    return result;
  841. }
  842.  
  843. // *************************************************************************
  844. sos_Int sos_Union_type::local_hash_value (sos_Union_type)
  845. // *************************************************************************
  846. {  
  847.    T_PROC ("sos_Union_type::local_hash_value");
  848.    TT (mta_H, T_ENTER);
  849.  
  850.    sos_Int result = 0;
  851.  
  852.    TT (mta_H, T_LEAVE);
  853.    return result;
  854. }
  855.  
  856. // *************************************************************************
  857. sos_Schema_type sos_Typedef_type::make_base_type ()
  858. // *************************************************************************
  859. {  
  860.    T_PROC ("sos_Typedef_type::make_base_type");
  861.    TT (mta_H, T_ENTER);
  862.  
  863.    sos_Schema_type t = self.get_type_name().make_base_type();
  864.  
  865.    TT (mta_H, T_LEAVE);
  866.    return t;
  867. }
  868.  
  869. // *************************************************************************
  870. sos_Bool sos_Typedef_type::local_equal (sos_Typedef_type,sos_Object,sos_Eq_kind)
  871. // *************************************************************************
  872. {  
  873.    T_PROC ("sos_Typedef_type::local_equal");
  874.    TT (mta_H, T_ENTER);
  875.  
  876.    sos_Bool result = TRUE;
  877.  
  878.    TT (mta_H, T_LEAVE);
  879.    return result;
  880. }
  881.  
  882. // *************************************************************************
  883. sos_Int sos_Typedef_type::local_hash_value (sos_Typedef_type)
  884. // *************************************************************************
  885. {  
  886.    T_PROC ("sos_Typedef_type::local_hash_value");
  887.    TT (mta_H, T_ENTER);
  888.  
  889.    sos_Int result = 0;
  890.  
  891.    TT (mta_H, T_LEAVE);
  892.    return result;
  893. }
  894.  
  895. // *************************************************************************
  896. sos_Scalar_object sos_Enum_type::make_object (sos_String literal)
  897. // *************************************************************************
  898. {  T_PROC ("sos_Enum_type::make_object");
  899.    TT (mta_H, T_ENTER);
  900.  
  901.    sos_String_List sl    = self.get_literals();
  902.    sos_Int         idx   = 0;
  903.    sos_Bool        found = FALSE;
  904.  
  905.    agg_iterate (sl, sos_String lit)
  906.       if (lit.equal (literal))
  907.       {  found = TRUE;
  908.          break;
  909.       }
  910.       ++ idx;
  911.    agg_iterate_end (sl, lit);
  912.  
  913.    sos_Scalar_object result = found ? sos_enum_from_sos_Int (idx, self)
  914.                     : sos_Scalar_object::make (NO_OBJECT);
  915.    TT (mta_H, T_LEAVE);
  916.    return result;
  917. }
  918.  
  919. // *************************************************************************
  920. sos_String sos_Enum_type::make_string (sos_Scalar_object enum_obj)
  921. // *************************************************************************
  922. {  T_PROC ("sos_Enum_type::make_string");
  923.    TT (mta_H, T_ENTER);
  924.  
  925.    sos_Int    lidx          = sos_Int_from_enum (enum_obj, self) + 1;
  926.    sos_String_List literals = self.get_literals();
  927.  
  928.    err_assert (1 <= lidx  AND  lidx <= literals.card(),
  929.                "sos_Enum_type::make_string : enum out of range");
  930.  
  931.    sos_String result = sos_String::clone (literals.get_nth (lidx),
  932.                                           TEMP_CONTAINER);
  933.    TT (mta_H, T_LEAVE);
  934.    return result;
  935. }
  936.  
  937. // *************************************************************************
  938. sos_Bool sos_Enum_type::local_equal (sos_Enum_type,sos_Object,sos_Eq_kind)
  939. // *************************************************************************
  940. {  T_PROC ("sos_Enum_type::local_equal");
  941.    TT (mta_H, T_ENTER);
  942.  
  943.    sos_Bool result = TRUE;
  944.  
  945.    TT (mta_H, T_LEAVE);
  946.    return result;
  947. }
  948.  
  949. // *************************************************************************
  950. sos_Int sos_Enum_type::local_hash_value (sos_Enum_type)
  951. // *************************************************************************
  952. {  
  953.    T_PROC ("sos_Enum_type::local_hash_value");
  954.    TT (mta_H, T_ENTER);
  955.  
  956.    sos_Int result = 0;
  957.  
  958.    TT (mta_H, T_LEAVE);
  959.    return result;
  960. }
  961.  
  962. // *************************************************************************
  963. sos_Schema_type sos_Forward_class_type::make_base_type ()
  964. // *************************************************************************
  965. {  
  966.    T_PROC ("sos_Forward_class_type::make_base_type");
  967.    TT (mta_H, T_ENTER);
  968.  
  969.    sos_Schema_type t = self.get_complete();
  970.    if (t == NO_OBJECT) t = self;
  971.  
  972.    TT (mta_H, T_LEAVE);
  973.    return t;
  974. }
  975.  
  976. // *************************************************************************
  977. sos_Bool sos_Forward_class_type::local_equal (sos_Forward_class_type,sos_Object,sos_Eq_kind)
  978. // *************************************************************************
  979. {  
  980.    T_PROC ("sos_Forward_class_type::local_equal");
  981.    TT (mta_H, T_ENTER);
  982.  
  983.    sos_Bool result = TRUE;
  984.  
  985.    TT (mta_H, T_LEAVE);
  986.    return result;
  987. }
  988.  
  989. // *************************************************************************
  990. sos_Int sos_Forward_class_type::local_hash_value (sos_Forward_class_type)
  991. // *************************************************************************
  992. {  
  993.    T_PROC ("sos_Forward_class_type::local_hash_value");
  994.    TT (mta_H, T_ENTER);
  995.  
  996.    sos_Int result = 0;
  997.  
  998.    TT (mta_H, T_LEAVE);
  999.    return result;
  1000. }
  1001.  
  1002. // *************************************************************************
  1003. sos_Class_type sos_Class_type::root_class ()
  1004. // *************************************************************************
  1005. {
  1006.    T_PROC ("sos_Class_type::root_class");
  1007.    TT (mta_H, T_ENTER);
  1008.  
  1009.    sos_Class_type ct;
  1010.  
  1011.    sos_Generic_instantiation gi = self.get_generated_from();
  1012.    if (gi != NO_OBJECT)
  1013.       ct = gi.get_gen();
  1014.    else
  1015.       ct = self;
  1016.  
  1017.    TT (mta_H, T_LEAVE);
  1018.    return ct;
  1019. }
  1020.  
  1021. // *************************************************************************
  1022. sos_Bool sos_Class_type::is_derived_from (sos_Type tp)
  1023. // *************************************************************************
  1024. {
  1025.    T_PROC ("sos_Class_type::is_derived_from");
  1026.    TT (mta_H, T_ENTER);
  1027.  
  1028.    sos_Bool result = FALSE;
  1029.  
  1030.    if (self.equal (tp) OR tp.equal (get_object_type()))
  1031.       result = TRUE;
  1032.    else
  1033.    {  sos_Super_class_List scl = self.get_super_closure();
  1034.  
  1035.       agg_iterate (scl, sos_Super_class sc)
  1036.          if (sc.get_super_class().equal (tp))
  1037.      {  result = TRUE;
  1038.         break;
  1039.      }
  1040.       agg_iterate_end (scl, sc);
  1041.    }
  1042.  
  1043.    TT (mta_H, T_LEAVE; TB (result));
  1044.    return result;
  1045. }
  1046.  
  1047. // *************************************************************************
  1048. sos_Bool sos_Class_type::is_derived_from_some (sos_Type tp)
  1049. // *************************************************************************
  1050. {
  1051.    T_PROC ("sos_Class_type::is_derived_from_some");
  1052.    TT (mta_H, T_ENTER);
  1053.  
  1054.    sos_Bool result = FALSE;
  1055.  
  1056.    if (self.equal (tp) OR tp.equal (get_object_type()))
  1057.       result = TRUE;
  1058.    else
  1059.    {  sos_Super_class_List scl = self.get_super_closure();
  1060.  
  1061.       agg_iterate (scl, sos_Super_class sc)
  1062.          if (sc.get_super_class().root_class().equal (tp))
  1063.      {  result = TRUE;
  1064.         break;
  1065.      }
  1066.       agg_iterate_end (scl, sc);
  1067.    }
  1068.  
  1069.    TT (mta_H, T_LEAVE; TB (result));
  1070.    return result;
  1071. }
  1072.  
  1073. // *************************************************************************
  1074. sos_Type sos_Class_type::root ()
  1075. // *************************************************************************
  1076. {
  1077.    T_PROC ("sos_Class_type::root");
  1078.    TT (mta_M, T_ENTER);
  1079.  
  1080.    sos_Type t = self.root_class();
  1081.  
  1082.    TT (mta_M, T_LEAVE);
  1083.    return t;
  1084. }
  1085.  
  1086. // *************************************************************************
  1087. sos_Schema_type sos_Class_type::make_root_type ()
  1088. // *************************************************************************
  1089. {
  1090.    T_PROC ("sos_Class_type::make_root_type");
  1091.    TT (mta_H, T_ENTER);
  1092.  
  1093.    sos_Schema_type t = self.root_class();
  1094.  
  1095.    TT (mta_H, T_LEAVE);
  1096.    return t;
  1097. }
  1098.  
  1099. // *************************************************************************
  1100. sos_String sos_Class_type::make_type_name ()
  1101. // *************************************************************************
  1102. {  
  1103.    T_PROC ("sos_Class_type::make_type_name");
  1104.    TT (mta_H, T_ENTER);
  1105.  
  1106.    sos_String result = self.get_root_name();
  1107.  
  1108.    if (result == NO_OBJECT)
  1109.       result = self.get_name();
  1110.  
  1111.    TT (mta_H, T_LEAVE);
  1112.    return result;
  1113. }
  1114.  
  1115. static sos_Schema_type *the_object_type;
  1116.  
  1117. // *************************************************************************
  1118. static sos_Schema_type get_object_type()
  1119. // *************************************************************************
  1120. {
  1121.    T_PROC ("get_object_type");
  1122.    TT (mta_H, T_ENTER);
  1123.  
  1124.    sos_Schema_type result;
  1125.    if (the_object_type)
  1126.       result = *the_object_type;
  1127.    else
  1128.    {
  1129. #ifdef BOOT
  1130.       sos_Schema_module knl =
  1131.      sos_Schema_module::lookup (smg_String ("knl").make_String (TEMP_CONTAINER));
  1132.       result = knl.lookup_type (smg_String ("sos_Object").make_String (TEMP_CONTAINER));
  1133. #else
  1134.       result = sos_Schema_type::make (sos_Object_type);
  1135. #endif
  1136.       the_object_type  = new sos_Schema_type;
  1137.       *the_object_type = result;
  1138.    }
  1139.  
  1140.    TT (mta_H, T_LEAVE);
  1141.    return result;
  1142. }
  1143.  
  1144. static sos_Schema_type *the_scalar_object_type;
  1145.  
  1146. // *************************************************************************
  1147. static sos_Schema_type get_scalar_object_type()
  1148. // *************************************************************************
  1149. {
  1150.    T_PROC ("get_scalar_object_type");
  1151.    TT (mta_H, T_ENTER);
  1152.  
  1153.    sos_Schema_type result;
  1154.    if (the_scalar_object_type)
  1155.       result = *the_scalar_object_type;
  1156.    else
  1157.    {
  1158. #ifdef BOOT
  1159.       sos_Schema_module knl =
  1160.      sos_Schema_module::lookup (smg_String ("knl").make_String (TEMP_CONTAINER));
  1161.       result = knl.lookup_type (smg_String ("sos_Scalar_object").make_String (TEMP_CONTAINER));
  1162. #else
  1163.       result = sos_Schema_type::make (sos_Scalar_object_type);
  1164. #endif
  1165.       the_scalar_object_type  = new sos_Schema_type;
  1166.       *the_scalar_object_type = result;
  1167.    }
  1168.  
  1169.    TT (mta_H, T_LEAVE);
  1170.    return result;
  1171. }
  1172.  
  1173. // *************************************************************************
  1174. sos_Bool sos_Class_type::local_equal (sos_Class_type,sos_Object,sos_Eq_kind)
  1175. // *************************************************************************
  1176. {  
  1177.    T_PROC ("sos_Class_type::local_equal");
  1178.    TT (mta_M, T_ENTER);
  1179.  
  1180.    sos_Bool result = TRUE;
  1181.  
  1182.    TT (mta_M, T_LEAVE);
  1183.    return result;
  1184. }
  1185.  
  1186. // *************************************************************************
  1187. sos_Int sos_Class_type::local_hash_value (sos_Class_type)
  1188. // *************************************************************************
  1189. {  
  1190.    T_PROC ("sos_Class_type::local_hash_value");
  1191.    TT (mta_M, T_ENTER);
  1192.  
  1193.    sos_Int result = 0;
  1194.  
  1195.    TT (mta_M, T_LEAVE);
  1196.    return result;
  1197. }
  1198.