home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #4 / amigaacscoverdisc1998-041998.iso / utilities / shareware / dev / ppcsmalleiffel / lib_se / ifthenlist.e < prev    next >
Encoding:
Text File  |  1998-01-16  |  4.9 KB  |  245 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://www.loria.fr/SmallEiffel
  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 IFTHENLIST
  17.  
  18. inherit IF_GLOBALS;
  19.  
  20. creation make
  21.    
  22. feature {NONE}
  23.  
  24.    list: ARRAY[IFTHEN];
  25.    
  26.    run_compound: COMPOUND;
  27.      -- When not Void, Current is checked and belongs to
  28.      -- this compound
  29.  
  30. feature 
  31.    
  32.    make(l: like list) is
  33.       require
  34.      not l.empty;
  35.      l.lower = 1;
  36.       do
  37.      list := l;
  38.       ensure
  39.      list = l;
  40.       end;
  41.    
  42.    pretty_print is
  43.       local
  44.      i: INTEGER;
  45.       do
  46.      from  
  47.         i := 1;
  48.      until
  49.         i > list.upper
  50.      loop
  51.         list.item(i).pretty_print;
  52.         i := i + 1;
  53.         if i <= list.upper then
  54.            fmt.indent;
  55.            fmt.keyword("elseif");
  56.         end;
  57.      end;
  58.       end;
  59.  
  60.    afd_check is
  61.       local 
  62.      i: INTEGER;
  63.       do
  64.      from
  65.         i := list.upper;
  66.      until
  67.         i = 0
  68.      loop
  69.         list.item(i).afd_check;
  70.         i := i - 1;
  71.      end;
  72.       end;
  73.  
  74.    compile_to_c: INTEGER is
  75.      -- state 0: no printing done.
  76.      -- state 1: already print `non_static'.
  77.      -- state 2: end of list or previous `static_true'.
  78.       local
  79.      state, previous, i: INTEGER;
  80.       do
  81.      from
  82.         i := 1;
  83.      until
  84.         state = 2
  85.      loop
  86.         inspect 
  87.            state
  88.         when 0 then
  89.            if i > list.upper then
  90.           state := 2;
  91.           Result := previous; 
  92.            else
  93.           previous := list.item(i).compile_to_c(false);
  94.           inspect 
  95.              previous
  96.           when non_static then
  97.              state := 1;
  98.           when static_false then
  99.           when static_true then
  100.              Result := static_true;
  101.              state := 2;
  102.           end;
  103.            end;
  104.         else -- 1
  105.            if i > list.upper then
  106.           state := 2;
  107.           inspect 
  108.              previous
  109.           when static_true then
  110.              Result := static_true;
  111.           else
  112.              Result := non_static;
  113.           end;
  114.            else
  115.           previous := list.item(i).compile_to_c(true);
  116.           inspect 
  117.              previous
  118.           when non_static then
  119.           when static_false then
  120.           when static_true then
  121.              state := 2;
  122.              Result := static_true;
  123.           end;
  124.            end;
  125.         end;
  126.         i := i + 1;
  127.      end;
  128.       ensure
  129.      (<<static_true,static_false,non_static>>).fast_has(Result)
  130.       end;
  131.    
  132.    compile_to_jvm: INTEGER is
  133.       local
  134.      i: INTEGER;
  135.       do
  136.      from
  137.         Result := list.item(1).compile_to_jvm;
  138.         i := 2;
  139.      until
  140.         Result = static_true or else i > list.upper
  141.      loop
  142.         inspect
  143.            list.item(i).compile_to_jvm
  144.         when static_true then
  145.            Result := static_true
  146.         when static_false then
  147.            if Result = static_false then
  148.            else
  149.           Result := non_static;
  150.            end;
  151.         else -- non_static :
  152.            Result := non_static;
  153.         end;
  154.         i := i + 1;
  155.      end;
  156.       ensure
  157.      (<<static_true,static_false,non_static>>).fast_has(Result)
  158.       end;
  159.  
  160.    use_current: BOOLEAN is   
  161.       local      
  162.      i: INTEGER;
  163.       do
  164.      from  
  165.         i := 1;
  166.      until
  167.         i > list.upper or else Result
  168.      loop
  169.         Result := list.item(i).use_current;
  170.         i := i + 1;
  171.      end;
  172.       end;
  173.    
  174.    count: INTEGER is
  175.       do
  176.      Result := list.upper;
  177.       end;
  178.    
  179.    to_runnable(rc: COMPOUND): like Current is
  180.       require
  181.      rc.current_type.is_run_type
  182.       local 
  183.      i: INTEGER;
  184.       do
  185.      if run_compound /= Void then
  186.         !!Result.make(list.twin);
  187.         Result := Result.to_runnable(rc);
  188.      else
  189.         run_compound := rc;
  190.         from  
  191.            i := 1;
  192.         until
  193.            i > list.upper or else nb_errors > 0
  194.         loop
  195.            list.put(list.item(i).to_runnable(rc),i);
  196.            debug
  197.           if nb_errors = 0 then
  198.              check
  199.             list.item(i) /= Void;
  200.              end;
  201.           end;
  202.            end;
  203.            i := i + 1;
  204.         end;
  205.         Result := Current;
  206.      end;
  207.       end;
  208.    
  209. feature {IFTHENELSE}
  210.    
  211.    add_last(it: IFTHEN) is
  212.       require
  213.      it /= Void
  214.       do
  215.      list.add_last(it);
  216.       ensure
  217.      count = old count + 1
  218.       end;
  219.  
  220. feature {IFTHENELSE}
  221.  
  222.    compile_to_jvm_resolve_branch is
  223.       local
  224.      i, static: INTEGER;
  225.       do
  226.      from
  227.         i := 1;
  228.         static := non_static;
  229.      until
  230.         static = static_true or else i > list.upper
  231.      loop
  232.         static := list.item(i).compile_to_jvm_resolve_branch;
  233.         i := i + 1;
  234.      end;
  235.       end;
  236.    
  237. invariant
  238.  
  239.    list.lower = 1;
  240.    
  241.    count >= 1;
  242.    
  243. end -- IFTHENLIST
  244.  
  245.