home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #4 / amigaacscoverdisc1998-041998.iso / utilities / shareware / dev / ppcsmalleiffel / lib_se / class_invariant.e < prev    next >
Encoding:
Text File  |  1998-01-16  |  4.6 KB  |  176 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 CLASS_INVARIANT
  17.    --
  18.    -- To store a `class invariant'.
  19.    --
  20.    
  21. inherit ASSERTION_LIST redefine pretty_print end;
  22.          
  23. creation {ANY}
  24.    make, from_runnable
  25.  
  26. feature {ANY}
  27.    
  28.    name: STRING is
  29.       do
  30.      Result := fz_invariant;
  31.       end;
  32.    
  33.    pretty_print is
  34.       local
  35.      i: INTEGER;
  36.       do
  37.      fmt.set_indent_level(0);
  38.      if not fmt.zen_mode then
  39.         fmt.skip(1);
  40.      end;
  41.      fmt.keyword(name);
  42.      if header_comment /= Void then
  43.         header_comment.pretty_print;
  44.      end;
  45.      if list /= Void then
  46.         from  
  47.            i := 1;
  48.         until
  49.            i > list.upper          
  50.         loop
  51.            fmt.set_indent_level(1);
  52.            fmt.indent;
  53.            if not fmt.zen_mode then
  54.           fmt.skip(1);
  55.            end;
  56.            fmt.set_semi_colon_flag(true);
  57.            list.item(i).pretty_print;
  58.            i := i + 1;
  59.         end;
  60.      end;
  61.       end;
  62.  
  63.    short(bc: BASE_CLASS) is
  64.       local
  65.      i: INTEGER;
  66.       do
  67.      bc.header_comment_for(Current);
  68.      short_print.hook_or("hook811","invariant%N");
  69.      if header_comment = Void then
  70.         short_print.hook_or("hook812","");
  71.      else
  72.         short_print.hook_or("hook813","");
  73.         header_comment.short("hook814","   -- ","hook815","%N");
  74.         short_print.hook_or("hook816","");
  75.      end;
  76.      if list = Void then
  77.         short_print.hook_or("hook817","");
  78.      else
  79.         short_print.hook_or("hook818","");
  80.         from  
  81.            i := 1;
  82.         until
  83.            i = list.upper          
  84.         loop
  85.            list.item(i).short("hook819","   ", -- before each assertion
  86.                   "hook820","", -- no tag
  87.                   "hook821","", -- before tag
  88.                   "hook822",": ", -- after tag
  89.                   "hook823","", -- no expression
  90.                   "hook824","", -- before expression
  91.                   "hook825",";", -- after expression except last
  92.                   "hook826","%N", -- no comment
  93.                   "hook827","", -- before comment
  94.                   "hook828"," -- ", -- comment begin line
  95.                   "hook829","%N", -- comment end of line
  96.                   "hook830","", -- after comment
  97.                   "hook831",""); -- end of each assertion
  98.  
  99.            i := i + 1;
  100.         end;
  101.         list.item(i).short("hook819","   ", -- before each assertion
  102.                    "hook820","", -- no tag
  103.                    "hook821","", -- before tag
  104.                    "hook822",": ", -- after tag
  105.                    "hook823","", -- no expression
  106.                    "hook824","", -- before expression
  107.                    "hook832",";", -- after last expression
  108.                    "hook826","%N", -- no comment
  109.                    "hook827","", -- before comment
  110.                    "hook828"," -- ", -- comment begin line
  111.                    "hook829","%N", -- comment end of line
  112.                    "hook830","", -- after comment
  113.                    "hook831","");
  114.         short_print.hook_or("hook833","");
  115.      end;
  116.      short_print.hook_or("hook834","");
  117.       ensure
  118.      fmt.indent_level = old fmt.indent_level;
  119.       end;
  120.  
  121. feature {NONE}
  122.    
  123.    check_assertion_mode: STRING is
  124.       do
  125.      Result := "inv";
  126.       end;
  127.       
  128. feature {RUN_CLASS}
  129.    
  130.    c_define is
  131.      -- Define C function to check invariant.
  132.       require
  133.      run_control.invariant_check;
  134.      current_type /= Void;
  135.      run_class.at_run_time;
  136.      small_eiffel.is_ready;
  137.      cpp.on_c
  138.       local
  139.      id: INTEGER;
  140.       do
  141.      id := current_type.id;
  142.      cdm.clear;
  143.      cdm.extend('T');
  144.      id.append_in(cdm);
  145.      cdm.extend('*');
  146.      cdm.extend('i');
  147.      id.append_in(cdm);
  148.      cdm.extend('(');
  149.      cdm.extend('T');
  150.      id.append_in(cdm);
  151.      cdm.extend('*');
  152.      cdm.extend('C');
  153.      cdm.extend(')');
  154.      cpp.put_c_heading(cdm);
  155.      cpp.swap_on_c;
  156.      cdm.copy("*((int*)rs++)=INVid;*((char**)rs++)=p[");
  157.      id.append_in(cdm);
  158.      cdm.extend(']');
  159.      cdm.append(fz_00);
  160.      cpp.put_string(cdm);
  161.      compile_to_c;
  162.      cpp.put_string("rs-=2;return C;}%N");
  163.       ensure     
  164.      cpp.on_c
  165.       end;
  166.    
  167. feature {NONE}   
  168.  
  169.    cdm: STRING is
  170.       once
  171.      !!Result.make(128);
  172.       end;
  173.  
  174. end -- CLASS_INVARIANT
  175.  
  176.