home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #4 / amigaacscoverdisc1998-041998.iso / utilities / shareware / dev / ppcsmalleiffel / lib_se / when_list.e < prev    next >
Encoding:
Text File  |  1998-01-16  |  5.9 KB  |  300 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 WHEN_LIST
  17.    
  18. inherit GLOBALS; 
  19.          
  20. creation {E_INSPECT}
  21.    make
  22.    
  23. creation {E_INSPECT,WHEN_LIST}
  24.    from_when_list
  25.    
  26. feature 
  27.    
  28.    e_inspect: E_INSPECT;
  29.      -- Corresponding one when checked.
  30.    
  31. feature {WHEN_LIST}   
  32.    
  33.    list: ARRAY[E_WHEN]; 
  34.    
  35. feature {NONE}   
  36.    
  37.    make(l: like list) is
  38.       require
  39.      l.lower = 1;
  40.      not l.empty;
  41.       do
  42.      list := l;
  43.       ensure
  44.      list = l;
  45.       end;
  46.    
  47. feature {E_INSPECT,WHEN_LIST}   
  48.    
  49.    from_when_list(wl: like Current) is
  50.       local
  51.      i: INTEGER;
  52.      e_when: E_WHEN;
  53.       do
  54.      from  
  55.         list := wl.list.twin;
  56.         i := 1;
  57.      until
  58.         i > list.upper
  59.      loop
  60.         !!e_when.from_e_when(list.item(i));
  61.         list.put(e_when,i);
  62.         i := i + 1;
  63.      end;
  64.       end;
  65.    
  66. feature
  67.    
  68.    pretty_print is
  69.       local
  70.      i, fmt_mode: INTEGER;
  71.       do
  72.      fmt_mode := fmt.mode;
  73.      fmt.set_zen;
  74.      from  
  75.         i := 1;
  76.      until
  77.         i > list.upper
  78.      loop
  79.         list.item(i).pretty_print;
  80.         i := i + 1;
  81.         if i <= list.upper then
  82.            fmt.put_character('%N');
  83.            fmt.indent;
  84.         end;
  85.      end;
  86.      fmt.set_mode(fmt_mode);
  87.       end;
  88.    
  89.    start_position: POSITION is
  90.      -- When not empty, the position of the first 
  91.      -- keyword "when".
  92.       do
  93.      Result := list.item(1).start_position;
  94.       end;
  95.    
  96.    current_type: TYPE is
  97.       require
  98.      e_inspect /= Void
  99.       do
  100.      Result := e_inspect.current_type;
  101.       end;
  102.    
  103. feature {E_INSPECT}
  104.  
  105.    afd_check is
  106.       local
  107.      i: INTEGER;
  108.       do
  109.      from  
  110.         i := list.upper;
  111.      until
  112.         i = 0
  113.      loop
  114.         list.item(i).afd_check;
  115.         i := i - 1;
  116.      end;
  117.       end;
  118.  
  119. feature {E_INSPECT,WHEN_LIST}
  120.    
  121.    includes_integer(v: INTEGER): BOOLEAN is
  122.       local
  123.      i: INTEGER;
  124.       do
  125.      from  
  126.         i := 1;
  127.      until
  128.         Result or else i > list.upper
  129.      loop
  130.         Result := list.item(i).includes_integer(v);
  131.         i := i + 1;
  132.      end;
  133.       end;
  134.    
  135.    to_runnable_integer(ei: E_INSPECT): like Current is
  136.       require
  137.      ei /= Void;
  138.       local
  139.      i: INTEGER;
  140.      e_when: E_WHEN;
  141.       do
  142.      if e_inspect = Void then
  143.         e_inspect := ei;
  144.         from  
  145.            i := 1;
  146.         until
  147.            i > list.upper or else nb_errors > 0
  148.         loop
  149.            e_when := list.item(i).to_runnable_integer(Current);
  150.            if e_when = Void then
  151.           error(start_position,em1);
  152.            else
  153.           list.put(e_when,i);
  154.            end;
  155.            i := i + 1;
  156.         end;
  157.         Result := Current;
  158.      else
  159.         !!Result.from_when_list(Current);
  160.         Result := Result.to_runnable_integer(ei);
  161.      end;
  162.       ensure
  163.      Result.e_inspect = ei
  164.       end;
  165.    
  166.    to_runnable_character(ei: E_INSPECT): like Current is
  167.       require
  168.      ei /= Void;
  169.       local
  170.      i: INTEGER;
  171.      e_when: E_WHEN;
  172.       do
  173.      if e_inspect = Void then
  174.         e_inspect := ei;
  175.         from  
  176.            i := 1;
  177.         until
  178.            i > list.upper or else nb_errors > 0
  179.         loop
  180.            e_when := list.item(i).to_runnable_character(Current);
  181.            if e_when = Void then
  182.           error(start_position,em1);
  183.            else
  184.           list.put(e_when,i);
  185.            end;
  186.            i := i + 1;
  187.         end;
  188.         Result := Current;
  189.      else
  190.         !!Result.from_when_list(Current);
  191.         Result := Result.to_runnable_character(ei);
  192.      end;
  193.       ensure
  194.      Result.e_inspect = ei
  195.       end;
  196.    
  197.    compile_to_c(else_position: POSITION) is
  198.       local
  199.      i: INTEGER;
  200.      last_compound: COMPOUND;
  201.       do
  202.      if list /= Void then
  203.         from  
  204.            i := 1;
  205.         until
  206.            i = list.upper
  207.         loop
  208.            list.item(i).compile_to_c;
  209.            i := i + 1;
  210.            if i < list.upper then
  211.           cpp.put_character(' ');
  212.           cpp.put_string(fz_else);
  213.           cpp.put_character(' ');
  214.            end;
  215.         end;
  216.         if i > 1 then
  217.            cpp.put_character(' ');
  218.            cpp.put_string(fz_else);
  219.            cpp.put_character(' ');
  220.         end;
  221.         if else_position = Void and then run_control.boost then
  222.            cpp.put_character('{');
  223.            last_compound := list.item(i).compound;
  224.            if last_compound /= Void then
  225.           last_compound.compile_to_c;
  226.            end;
  227.            cpp.put_character('}');
  228.         else
  229.            list.item(i).compile_to_c;
  230.         end;
  231.      end;
  232.       end;
  233.  
  234.    compile_to_jvm(else_position: POSITION) is
  235.       local
  236.      r, i: INTEGER;
  237.       do
  238.      if list /= Void then
  239.         from  
  240.            r := list.upper;
  241.            i := 1;
  242.         until
  243.            r = 0
  244.         loop
  245.            r := r - 1;
  246.            list.item(i).compile_to_jvm(else_position,r);
  247.            i := i + 1;
  248.         end;
  249.      end;
  250.       end;
  251.  
  252.    compile_to_jvm_resolve_branch is
  253.       local
  254.      i: INTEGER;
  255.       do
  256.      if list /= Void then
  257.         from  
  258.            i := list.upper;
  259.         until
  260.            i = 0
  261.         loop
  262.            list.item(i).compile_to_jvm_resolve_branch;
  263.            i := i - 1;
  264.         end;
  265.      end;
  266.       end;
  267.  
  268.  
  269.    use_current: BOOLEAN is
  270.       local
  271.      i: INTEGER;
  272.       do
  273.      if list /= Void then
  274.         from  
  275.            i := 1;
  276.         until
  277.            i > list.upper or else Result
  278.         loop
  279.            Result := list.item(i).use_current;
  280.            i := i + 1;
  281.         end;
  282.      end;
  283.       end;
  284.    
  285. feature {E_INSPECT}   
  286.    
  287.    add_last(ew: E_WHEN) is
  288.       require
  289.      ew /= Void;
  290.       do
  291.      list.add_last(ew);
  292.       end;
  293.    
  294. feature {NONE}
  295.    
  296.    em1: STRING is "Bad when list.";
  297.    
  298. end -- WHEN_LIST
  299.  
  300.