home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #4 / amigaacscoverdisc1998-041998.iso / utilities / shareware / dev / ppcsmalleiffel / lib_se / e_inspect.e < prev    next >
Encoding:
Text File  |  1998-01-16  |  6.4 KB  |  271 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 E_INSPECT
  17.    --
  18.    -- The Eiffel inspect instruction.
  19.    --
  20.    
  21. inherit INSTRUCTION;
  22.    
  23. creation make
  24.    
  25. feature 
  26.    
  27.    start_position: POSITION;
  28.      -- Of keyword `inspect'.
  29.    
  30.    expression: EXPRESSION;
  31.      -- Heading expression after keyword `inspect'.
  32.    
  33.    when_list: WHEN_LIST;
  34.      -- List of when clauses.
  35.    
  36.    else_position: POSITION;
  37.      -- Of the keyword `else' if any.
  38.    
  39.    else_compound: COMPOUND; 
  40.      -- Else compound if any. 
  41.    
  42. feature {NONE}
  43.    
  44.    make(sp: like start_position; exp: like expression) is
  45.       require
  46.      sp /= Void;
  47.      exp /= Void;
  48.       do
  49.      start_position := sp;
  50.      expression := exp;
  51.       ensure
  52.      start_position = sp;
  53.      expression = exp;
  54.       end;
  55.    
  56. feature 
  57.  
  58.    is_pre_computable: BOOLEAN is false;
  59.  
  60.    end_mark_comment: BOOLEAN is true;
  61.    
  62. feature
  63.  
  64.    afd_check is 
  65.       do 
  66.      expression.afd_check;
  67.      if when_list /= Void then
  68.         when_list.afd_check;
  69.      end;
  70.      if else_compound /= Void then
  71.         else_compound.afd_check;
  72.      end;
  73.       end;
  74.  
  75.    includes(v: INTEGER): BOOLEAN is
  76.       -- True if a when clause includes `v'.
  77.       do
  78.      Result := when_list.includes_integer(v);
  79.       end;
  80.    
  81.    compile_to_c is
  82.       do
  83.      cpp.inspect_incr;
  84.      cpp.put_string("{int ");
  85.      cpp.put_inspect;
  86.      cpp.put_character('=');
  87.      expression.compile_to_c;
  88.      cpp.put_string(fz_00);
  89.      if when_list = Void then
  90.         if else_position = Void then
  91.            if run_control.no_check then
  92.           cpp.put_error1(em2,start_position);
  93.            end;
  94.         elseif else_compound /= Void then
  95.            else_compound.compile_to_c;
  96.         end;
  97.      else
  98.         when_list.compile_to_c(else_position);
  99.         if else_position = Void then
  100.            if run_control.no_check then
  101.           cpp.put_character(' ');
  102.           cpp.put_string(fz_else);
  103.           cpp.put_character('{');
  104.           cpp.put_error1(em2,start_position);
  105.           cpp.put_character('}');
  106.            end;
  107.         elseif else_compound /= Void then
  108.            cpp.put_character(' ');
  109.            cpp.put_string(fz_else);
  110.            cpp.put_character('{');
  111.            else_compound.compile_to_c;
  112.            cpp.put_character('}');
  113.         end;
  114.      end;
  115.      cpp.put_string(fz_12);
  116.      cpp.inspect_decr;
  117.       end;
  118.    
  119.    compile_to_jvm is
  120.       do
  121.      expression.compile_to_jvm;
  122.      if when_list /= Void then
  123.         when_list.compile_to_jvm(else_position);
  124.      end;
  125.      if else_compound /= Void then
  126.         if run_control.no_check then
  127.            -- *** Code pour crash ***
  128.         end;
  129.         else_compound.compile_to_jvm;
  130.      end;
  131.      if when_list /= Void then
  132.         when_list.compile_to_jvm_resolve_branch;
  133.      end;
  134.      code_attribute.opcode_pop;
  135.       end;
  136.  
  137.    use_current: BOOLEAN is
  138.       do
  139.      Result := Result or else expression.use_current;
  140.      if when_list /= Void then
  141.         Result := Result or else when_list.use_current;
  142.      end;
  143.      if else_compound /= Void then
  144.         Result := Result or else else_compound.use_current;
  145.      end;     
  146.       end;
  147.    
  148.    add_when(e_when: E_WHEN) is
  149.       require
  150.      e_when /= Void
  151.       do
  152.      if when_list = Void then
  153.         !!when_list.make(<<e_when>>);
  154.      else
  155.         when_list.add_last(e_when);
  156.      end;
  157.       end;
  158.    
  159.    set_else_compound(sp: like else_position; ec: like else_compound) is
  160.       do
  161.      else_position := sp;
  162.      else_compound := ec;
  163.       end;
  164.    
  165.    to_runnable(rc: like run_compound): like Current is
  166.       local
  167.      e: like expression;
  168.      te: TYPE;
  169.      wl: WHEN_LIST;
  170.       do
  171.      if run_compound = Void then
  172.         run_compound := rc;
  173.         e := expression.to_runnable(current_type);
  174.         if nb_errors = 0 then
  175.            expression := e;
  176.            te := e.result_type.run_type;
  177.            --                  ********
  178.            --                  VIRABLE
  179.         end;
  180.         if nb_errors = 0 then
  181.            if te.is_character then
  182.           if when_list /= Void then
  183.              when_list := when_list.to_runnable_character(Current);
  184.              if when_list = Void then
  185.             error(start_position,em1);
  186.              end;
  187.           end;          
  188.            elseif te.is_integer then
  189.           if when_list /= Void then
  190.              when_list := when_list.to_runnable_integer(Current);
  191.              if when_list = Void then
  192.             error(start_position,em1);
  193.              end;
  194.           end;          
  195.            else
  196.           eh.append("Expression must be INTEGER or CHARACTER.");
  197.           eh.add_type(te," is not allowed.");
  198.           eh.add_position(start_position);
  199.           eh.print_as_error;
  200.            end; 
  201.         end;
  202.         if else_compound /= Void then
  203.            else_compound := else_compound.to_runnable(current_type);
  204.         end;
  205.         Result := Current
  206.      else
  207.         Result := twin;
  208.         !!wl.from_when_list(when_list);
  209.         Result.set_when_list(wl);
  210.         Result.set_run_compound(Void);
  211.         Result := Result.to_runnable(rc);
  212.      end;
  213.       end;
  214.    
  215. feature    
  216.    
  217.    pretty_print is
  218.       do
  219.      fmt.keyword(fz_inspect);
  220.      fmt.level_incr;
  221.      if not fmt.zen_mode then
  222.         fmt.indent;
  223.      end;
  224.      fmt.set_semi_colon_flag(false);
  225.      expression.pretty_print;
  226.      fmt.level_decr;
  227.      fmt.indent;
  228.      if when_list /= Void then
  229.         when_list.pretty_print;
  230.      end;
  231.      if else_compound = Void then
  232.         if else_position /= Void then
  233.            fmt.indent;
  234.            fmt.keyword(fz_else);
  235.         end;
  236.      else
  237.         fmt.indent;
  238.         fmt.keyword(fz_else);
  239.         fmt.level_incr;
  240.         else_compound.pretty_print;
  241.         fmt.level_decr;
  242.      end;
  243.      fmt.indent;
  244.      fmt.keyword("end;");
  245.      if fmt.print_end_inspect then
  246.         fmt.put_end(fz_inspect);
  247.      end;
  248.       end;
  249.    
  250. feature {E_INSPECT}
  251.    
  252.    set_when_list(wl: like when_list) is
  253.       do
  254.      when_list := wl;
  255.       ensure
  256.      when_list = wl;
  257.       end;
  258.    
  259. feature {NONE}
  260.    
  261.    em1: STRING is "Bad inspect.";
  262.    
  263.    em2: STRING is "Invalid inspect (nothing selected).";
  264.    
  265. invariant
  266.    
  267.    expression /= Void;
  268.    
  269. end -- E_INSPECT
  270.  
  271.