home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #4 / amigaacscoverdisc1998-041998.iso / utilities / shareware / dev / ppcsmalleiffel / lib_se / assertion_list.e < prev    next >
Encoding:
Text File  |  1998-01-16  |  6.4 KB  |  305 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. deferred class ASSERTION_LIST
  17.    --
  18.    -- To store a list of assertions (see ASSERTION).
  19.    --
  20.    -- See also : CLASS_INVARIANT, E_REQUIRE, E_ENSURE, 
  21.    --            LOOP_INVARIANT and CHECK_INVARIANT.
  22.    --
  23.    
  24. inherit GLOBALS;
  25.    
  26. feature 
  27.    
  28.    name: STRING is 
  29.       deferred
  30.       end;
  31.    
  32.    start_position: POSITION;
  33.      -- If any, the position of the first letter of `name'.
  34.    
  35.    header_comment: COMMENT;
  36.      
  37. feature {ASSERTION_LIST,E_CHECK,E_FEATURE}
  38.    
  39.    list: ARRAY[ASSERTION];
  40.      
  41. feature 
  42.  
  43.    current_type: TYPE;
  44.      -- Not Void when checked in.
  45.    
  46.    set_current_type(ct: like current_type) is
  47.       do
  48.      current_type := ct;
  49.       end;
  50.    
  51.    afd_check is
  52.       local
  53.      i: INTEGER;
  54.       do
  55.      if list /= Void then
  56.         from
  57.            i := list.upper;
  58.         until
  59.            i = 0
  60.         loop
  61.            list.item(i).afd_check;
  62.            i := i - 1;
  63.         end;
  64.      end;
  65.       end;
  66.    
  67.    compile_to_c is
  68.       local
  69.      i: INTEGER;
  70.       do
  71.      if list /= Void then
  72.         cpp.put_string("if(!se_af){se_af=1;%N");
  73.         from
  74.            i := 1;
  75.         until
  76.            i > list.upper
  77.         loop
  78.            cpp.set_check_assertion_mode(check_assertion_mode);
  79.            list.item(i).compile_to_c;
  80.            i := i + 1;
  81.         end;
  82.         cpp.put_string("se_af=0;}%N");
  83.      end;
  84.       end;
  85.    
  86.    frozen compile_to_jvm(last_chance: BOOLEAN) is
  87.      -- If `last_chance' is true, this assertion list 
  88.      -- must be true : an error message is printed at run 
  89.      -- time and the result is not pushed on the JVM stack.
  90.      -- When `last_chance' is false, the result is left on top
  91.      -- of the JVM stack and no error message is produced 
  92.      -- whatever the result is.
  93.       local
  94.      point_true, i: INTEGER;
  95.      ca: like code_attribute;
  96.       do
  97.      if list /= Void then
  98.         ca := code_attribute;
  99.         ca.check_opening;
  100.         if last_chance then
  101.            from
  102.           i := 1;
  103.            until
  104.           i > list.upper
  105.            loop
  106.           list.item(i).compile_to_jvm(true);
  107.           i := i + 1;
  108.            end;
  109.         else
  110.            from
  111.           points_false.clear;
  112.           i := 1;
  113.            until
  114.           i > list.upper
  115.            loop
  116.           list.item(i).compile_to_jvm(false);
  117.           points_false.add_last(ca.opcode_ifeq);
  118.           i := i + 1;
  119.            end;
  120.            ca.opcode_iconst_1;
  121.            point_true := ca.opcode_goto;
  122.            ca.resolve_with(points_false);
  123.            ca.opcode_iconst_0;
  124.            ca.resolve_u2_branch(point_true);
  125.         end;
  126.         ca.check_closing;
  127.      end;
  128.       end;
  129.    
  130.    is_pre_computable: BOOLEAN is 
  131.       local
  132.      i: INTEGER;
  133.       do
  134.      if list = Void then
  135.         Result := true;
  136.      else
  137.         from
  138.            i := list.upper;
  139.            Result := true;
  140.         until
  141.            not Result or else i = 0
  142.         loop
  143.            Result := list.item(i).is_pre_computable;
  144.            i := i - 1;
  145.         end;
  146.      end;
  147.       end;
  148.  
  149.    use_current: BOOLEAN is
  150.       local
  151.      i: INTEGER;
  152.       do
  153.      if list /= Void then
  154.         from  
  155.            i := list.upper;
  156.         until
  157.            Result or else i = 0
  158.         loop
  159.            Result := list.item(i).use_current;
  160.            i := i - 1;
  161.         end;
  162.      end;
  163.       end;
  164.    
  165. feature {NONE}
  166.  
  167.    make(sp: like start_position; hc: like header_comment; l: like list) is
  168.       require
  169.      l /= Void implies not l.empty;
  170.      hc /= Void or else l /= Void;
  171.       do
  172.      start_position := sp;
  173.      header_comment := hc;
  174.      list := l;
  175.       ensure
  176.      start_position = sp;
  177.      header_comment = hc;
  178.      list = l;
  179.       end;
  180.    
  181. feature {NONE}
  182.  
  183.    from_runnable(l: like list) is
  184.       require
  185.      l.lower = 1;
  186.      l.upper >= 1;
  187.       do
  188.      list := l;
  189.      current_type := list.item(1).current_type;
  190.       ensure
  191.      current_type /= Void;
  192.       end;
  193.    
  194. feature 
  195.    
  196.    empty: BOOLEAN is
  197.       do
  198.      Result := list = Void;
  199.       end;
  200.    
  201.    run_class: RUN_CLASS is
  202.       do
  203.      Result := current_type.run_class;
  204.       end;
  205.    
  206.    to_runnable(ct: TYPE): like Current is
  207.       require
  208.      ct.run_type = ct;
  209.       do
  210.      if current_type = Void then
  211.         current_type := ct;
  212.         if list /= Void then
  213.            list := runnable(list,ct,small_eiffel.top_rf); 
  214.         end;
  215.         if nb_errors = 0 then
  216.            Result := Current;
  217.         end;
  218.      else
  219.         Result := twin;
  220.         Result.set_current_type(Void);
  221.         Result := Result.to_runnable(ct);
  222.      end;
  223.       ensure
  224.      nb_errors = 0 implies Result /= Void
  225.       end;
  226.    
  227.    pretty_print is
  228.       local
  229.      i: INTEGER;
  230.       do
  231.      fmt.indent;
  232.      fmt.keyword(name);
  233.      fmt.level_incr;
  234.      if header_comment /= Void then
  235.         header_comment.pretty_print;
  236.      else
  237.         fmt.indent;
  238.      end;
  239.      if list /= Void then
  240.         from  
  241.            i := 1;
  242.         until
  243.            i > list.upper          
  244.         loop
  245.            if fmt.zen_mode and i = list.upper then
  246.           fmt.set_semi_colon_flag(false);
  247.            else
  248.           fmt.set_semi_colon_flag(true);
  249.            end;           
  250.            fmt.indent;           
  251.            list.item(i).pretty_print;
  252.            i := i + 1;
  253.         end;
  254.      end;
  255.      fmt.level_decr;
  256.      fmt.indent;
  257.       ensure
  258.      fmt.indent_level = old fmt.indent_level;
  259.       end;
  260.  
  261.    set_header_comment(hc: like header_comment) is
  262.       do
  263.      header_comment := hc;
  264.       end;
  265.  
  266. feature {E_FEATURE,RUN_CLASS}
  267.    
  268.    add_into(collector: ARRAY[ASSERTION]) is
  269.       local
  270.      i: INTEGER;
  271.      a: ASSERTION;
  272.       do
  273.      if list /= Void then
  274.         from  
  275.            i := 1;
  276.         until
  277.            i > list.upper
  278.         loop
  279.            a := list.item(i);
  280.            if not collector.fast_has(a) then
  281.           collector.add_last(a);
  282.            end;
  283.            i := i + 1;
  284.         end;
  285.      end;
  286.       end;
  287.       
  288. feature {NONE}
  289.  
  290.    points_false: FIXED_ARRAY[INTEGER] is
  291.       once
  292.      !!Result.with_capacity(12);
  293.       end;
  294.  
  295.    check_assertion_mode: STRING is
  296.       deferred
  297.       end;
  298.    
  299. invariant
  300.    
  301.    list /= Void implies (list.lower = 1 and not list.empty);
  302.    
  303. end -- ASSERTION_LIST
  304.  
  305.