home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / function.e < prev    next >
Text File  |  1999-06-05  |  7KB  |  219 lines

  1. --          This file is part of SmallEiffel The GNU Eiffel Compiler.
  2. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  3. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr
  4. --                       http://SmallEiffel.loria.fr
  5. -- SmallEiffel is  free  software;  you can  redistribute it and/or modify it
  6. -- under the terms of the GNU General Public License as published by the Free
  7. -- Software  Foundation;  either  version  2, or (at your option)  any  later
  8. -- version. SmallEiffel is distributed in the hope that it will be useful,but
  9. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. -- or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU General Public License
  11. -- for  more  details.  You  should  have  received a copy of the GNU General
  12. -- Public  License  along  with  SmallEiffel;  see the file COPYING.  If not,
  13. -- write to the  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. -- Boston, MA 02111-1307, USA.
  15. --
  16. class FUNCTION
  17.  
  18. inherit EFFECTIVE_ROUTINE;
  19.  
  20. creation make
  21.  
  22. feature
  23.  
  24.    result_type: TYPE;
  25.  
  26. feature
  27.  
  28.    make(n: like names;
  29.         fa: like arguments; t: like result_type;
  30.         om: like obsolete_mark;
  31.         hc: like header_comment;
  32.         ra: like require_assertion; lv: like local_vars;
  33.         rb: like routine_body) is
  34.       require
  35.          t /= void
  36.       do
  37.          make_effective_routine(n,fa,om,hc,ra,lv,rb);
  38.          result_type := t;
  39.       end;
  40.  
  41.    to_run_feature(t: TYPE; fn: FEATURE_NAME): RUN_FEATURE_4 is
  42.       do
  43.          !!Result.make(t,fn,Current);
  44.       end;
  45.  
  46. feature {C_PRETTY_PRINTER}
  47.  
  48.    stupid_switch(up_rf: RUN_FEATURE; r: ARRAY[RUN_CLASS]): BOOLEAN is
  49.       local
  50.          rf8a, rf8b: RUN_FEATURE_8;
  51.          rf4a, rf4b: RUN_FEATURE_4;
  52.          rf2a, rf2b: RUN_FEATURE_2;
  53.          rfa, rfb: RUN_FEATURE;
  54.          offseta, offsetb: INTEGER;
  55.          calla, callb: CALL;
  56.          call0a, call0b: CALL;
  57.          rta, rtb: TYPE;
  58.          i: INTEGER;
  59.          rc: RUN_CLASS;
  60.       do
  61.          rf4a ?= r.first.dynamic(up_rf);
  62.          if rf4a.is_empty_or_null_body then
  63.             Result := not up_rf.result_type.is_anchored;
  64.             if Result then
  65.                cpp.put_comment("SSF1");
  66.             end;
  67.          end;
  68.          if not Result then
  69.             from
  70.                Result := true;
  71.                i := r.upper;
  72.             until
  73.                not Result or else i = 0
  74.             loop
  75.                rc := r.item(i);
  76.                rf4b ?= rc.dynamic(up_rf);
  77.                rf2b := rf4b.is_attribute_reader;
  78.                if rf2a = Void then
  79.                   rf2a := rf2b;
  80.                   if rf2a /= Void then
  81.                      offseta := rc.offset_of(rf2a);
  82.                   end;
  83.                end;
  84.                if rf2b = Void then
  85.                   Result := false;
  86.                elseif rf2a.name.to_string = rf2b.name.to_string then
  87.                   offsetb := rc.offset_of(rf2b);
  88.                   Result := offseta = offsetb;
  89.                else
  90.                   Result := false;
  91.                end;
  92.                i := i - 1;
  93.             end;
  94.             if Result then
  95.                cpp.put_comment("SSF2");
  96.             end;
  97.          end;
  98.          if not Result then
  99.             from
  100.                Result := true;
  101.                i := r.upper;
  102.             until
  103.                not Result or else i = 0
  104.             loop
  105.                rc := r.item(i);
  106.                rf4b ?= rc.dynamic(up_rf);
  107.                callb := rf4b.is_direct_call_on_attribute;
  108.                if callb /= Void then
  109.                   rfb := callb.run_feature;
  110.                   call0b ?= callb.target;
  111.                   rf2b ?= call0b.run_feature;
  112.                   offsetb := rc.offset_of(rf2b);
  113.                   rf8b ?= rfb;
  114.                end;
  115.                if calla = Void then
  116.                   calla := callb;
  117.                   rfa := rfb;
  118.                   call0a := call0b;
  119.                   rf2a := rf2b;
  120.                   offseta := offsetb;
  121.                   rf8a := rf8b;
  122.                end;
  123.                if callb = Void then
  124.                   Result := false;
  125.                elseif offseta /= offsetb then
  126.                   Result := false;
  127.                elseif rfa = rfb then
  128.                elseif rf8a /= Void and then rf8b /= Void then
  129.                   if rf8a.name.to_string = as_item then
  130.                      rta := rf8a.result_type;
  131.                      rtb := rf8b.result_type;
  132.                      if rta.is_reference then
  133.                         Result := rtb.is_reference;
  134.                      else
  135.                         Result := rta.run_time_mark = rtb.run_time_mark;
  136.                      end;
  137.                   end;
  138.                else
  139.                   Result := false;
  140.                end;
  141.                i := i - 1;
  142.             end;
  143.             if Result then
  144.                cpp.put_comment("SSF3");
  145.             end;
  146.          end;
  147.          if not Result then
  148.             Result := stupid_switch_for_collection(up_rf,r);
  149.             if Result then
  150.                cpp.put_comment("SSF4");
  151.             end;
  152.          end;
  153.       end;
  154.  
  155. feature {NONE}
  156.  
  157.    stupid_switch_for_collection(up_rf: RUN_FEATURE; r: ARRAY[RUN_CLASS]): BOOLEAN is
  158.          -- I think it is a little bit dirty to handle these features
  159.          -- specifically.
  160.       local
  161.          bcn: STRING;
  162.          fns: STRING;
  163.          i: INTEGER;
  164.          rf: RUN_FEATURE;
  165.       do
  166.          bcn := up_rf.current_type.base_class.name.to_string;
  167.          if as_array = bcn or else as_fixed_array = bcn then
  168.             fns := up_rf.name.to_string;
  169.             if collection_names.fast_has(fns) then
  170.                from
  171.                   i := r.upper;
  172.                   Result := true;
  173.                until
  174.                   not Result or else i = 0
  175.                loop
  176.                   rf := r.item(i).dynamic(up_rf);
  177.                   if rf.result_type.is_expanded then
  178.                      Result := false;
  179.                   end;
  180.                   i := i - 1;
  181.                end;
  182.             end
  183.             if not Result then
  184.                if fns = as_lower then
  185.                   Result := true;
  186.                elseif fns = as_upper then
  187.                   Result := true;
  188.                elseif fns = as_count then
  189.                   Result := true;
  190.                elseif fns.is_equal("empty") then
  191.                   Result := true;
  192.                end;
  193.             end;
  194.          end;
  195.       end;
  196.  
  197.    collection_names: ARRAY[STRING] is
  198.       once
  199.          Result := <<as_item, as_at, as_first, as_last>>;
  200.       end;
  201.  
  202.    try_to_undefine_aux(fn: FEATURE_NAME;
  203.                        bc: BASE_CLASS): DEFERRED_ROUTINE is
  204.       do
  205.          !DEFERRED_FUNCTION!Result.from_effective(fn,arguments,
  206.                                                   result_type,
  207.                                                   require_assertion,
  208.                                                   ensure_assertion,
  209.                                                   bc);
  210.       end;
  211.  
  212.    pretty_print_once_or_do is
  213.       do
  214.          fmt.keyword(fz_do);
  215.       end;
  216.  
  217. end -- FUNCTION
  218.  
  219.