home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #4 / amigaacscoverdisc1998-041998.iso / utilities / shareware / dev / ppcsmalleiffel / lib_se / compound.e < prev    next >
Encoding:
Text File  |  1998-01-16  |  5.2 KB  |  258 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 COMPOUND 
  17.    --
  18.    -- A list of Eiffel instructions.
  19.    --
  20.  
  21. inherit GLOBALS;
  22.  
  23. creation {EIFFEL_PARSER,COMPOUND}
  24.    make
  25.    
  26. feature  
  27.    
  28.    header_comment: COMMENT;
  29.    
  30.    current_type: TYPE;
  31.      -- Not Void when checked.
  32.    
  33. feature {NONE} 
  34.    
  35.    list: ARRAY[INSTRUCTION];
  36.    
  37. feature {EIFFEL_PARSER,COMPOUND}
  38.    
  39.    make(hc: like header_comment; l: like list) is
  40.       require
  41.      hc /= Void or else l /= Void;
  42.      l /= Void implies l.lower = 1 and not l.empty;
  43.       do
  44.      header_comment := hc;
  45.      list := l;
  46.       ensure 
  47.      header_comment = hc;
  48.      list = l;
  49.       end;
  50.    
  51. feature 
  52.    
  53.    count: INTEGER is
  54.       do
  55.      if list /= Void then
  56.         Result := list.upper;
  57.      end;
  58.       end;
  59.       
  60.    first: INSTRUCTION is
  61.       do
  62.      if list /= Void then
  63.         Result := list.first;
  64.      end;
  65.       end;
  66.    
  67.    start_position: POSITION is
  68.       do
  69.      if list /= Void then
  70.         Result := list.first.start_position;
  71.      end;
  72.       end;
  73.    
  74.    run_class: RUN_CLASS is
  75.       do
  76.      Result := current_type.run_class;
  77.       end;
  78.  
  79.    afd_check is
  80.       local
  81.      i: INTEGER;
  82.       do
  83.      if list /= Void then
  84.         from  
  85.            i := list.upper;
  86.         until
  87.            i = 0
  88.         loop
  89.            list.item(i).afd_check;
  90.            i := i - 1;
  91.         end;
  92.      end;
  93.       end;
  94.  
  95.    compile_to_c is
  96.       local
  97.      i: INTEGER;
  98.       do
  99.      if list /= Void then
  100.         from  
  101.            i := 1;
  102.         until
  103.            i > list.upper
  104.         loop
  105.            list.item(i).compile_to_c;
  106.            i := i + 1;
  107.         end;
  108.      end;
  109.       end;
  110.    
  111.    c2jvm: BOOLEAN is
  112.      -- Result is false when no byte code is produced.
  113.       local
  114.      pc: INTEGER;
  115.       do
  116.      pc := code_attribute.program_counter;
  117.      compile_to_jvm;
  118.      Result := pc /= code_attribute.program_counter;
  119.       end;
  120.    
  121.    compile_to_jvm is
  122.       local
  123.      i: INTEGER;
  124.       do
  125.      if list /= Void then
  126.         from  
  127.            i := 1;
  128.         until
  129.            i > list.upper
  130.         loop
  131.            list.item(i).compile_to_jvm;
  132.            i := i + 1;
  133.         end;
  134.      end;
  135.       end;
  136.    
  137.    use_current: BOOLEAN is
  138.       local
  139.      i: INTEGER;
  140.       do
  141.      if list /= Void then
  142.         from  
  143.            i := list.upper;
  144.         until
  145.            Result or else i = 0 
  146.         loop
  147.            Result := list.item(i).use_current;
  148.            i := i - 1;
  149.         end;
  150.      end;
  151.       end;
  152.    
  153.    is_pre_computable: BOOLEAN is 
  154.       local
  155.      i: INTEGER;
  156.       do
  157.      if list = Void then
  158.         Result := true; 
  159.      else
  160.         from  
  161.            i := list.upper;
  162.            Result := true;
  163.         until
  164.            not Result or else i = 0
  165.         loop
  166.            Result := list.item(i).is_pre_computable;
  167.            i := i - 1;
  168.         end;
  169.      end;
  170.       end;
  171.    
  172.    to_runnable(ct: TYPE): like Current is
  173.       require
  174.      ct.run_type = ct;
  175.      nb_errors = 0;
  176.       local
  177.      i: INTEGER;
  178.      i1, i2: INSTRUCTION;
  179.       do
  180.      if current_type = Void then
  181.         current_type := ct;
  182.         if list /= Void then
  183.            from
  184.           i := list.upper;
  185.            until
  186.           i = 0
  187.            loop
  188.           i1 := list.item(i);
  189.           i2 := i1.to_runnable(Current);
  190.           if nb_errors > 0 then
  191.              eh.append("Bad instruction (when interpreted in ");
  192.              eh.append(current_type.written_mark);
  193.              eh.add_position(i1.start_position);
  194.              fatal_error(").");
  195.           else
  196.              check
  197.             i2.run_compound = Current;
  198.              end;
  199.              list.put(i2,i);
  200.           end;
  201.           i := i - 1;
  202.            end;
  203.         end;
  204.         Result := Current;
  205.      else
  206.         if list = Void then
  207.            !!Result.make(header_comment,Void);
  208.         else
  209.            !!Result.make(header_comment,list.twin);
  210.         end;
  211.         Result := Result.to_runnable(ct);
  212.      end;
  213.       ensure 
  214.      Result /= Void implies Result.current_type = ct
  215.       end;
  216.    
  217.    pretty_print is
  218.       require
  219.      fmt.indent_level >= 2;
  220.       local
  221.      i: INTEGER;
  222.       do
  223.      fmt.level_incr;
  224.      fmt.indent;
  225.      if header_comment /= Void then
  226.         header_comment.pretty_print;
  227.      end;
  228.      if list /= Void then
  229.         from  
  230.            i := 1;
  231.         until
  232.            i > list.upper
  233.         loop
  234.            fmt.set_semi_colon_flag(true);
  235.            fmt.indent;
  236.            list.item(i).pretty_print;
  237.            i := i + 1;
  238.         end;
  239.      end;
  240.      fmt.level_decr;
  241.       ensure
  242.      fmt.indent_level = old fmt.indent_level;
  243.       end;
  244.  
  245.    empty_or_null_body: BOOLEAN is
  246.       do
  247.      Result := list = Void;
  248.       end;
  249.  
  250. invariant
  251.    
  252.    header_comment /= Void or else list /= Void;
  253.    
  254.    list /= Void implies list.lower = 1 and not list.empty;
  255.    
  256. end -- COMPOUND 
  257.  
  258.