home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #4 / amigaacscoverdisc1998-041998.iso / utilities / shareware / dev / ppcsmalleiffel / lib_se / when_item_2.e < prev    next >
Encoding:
Text File  |  1998-01-16  |  3.4 KB  |  131 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_ITEM_2
  17. --
  18. -- To store a slice value of a when clause in an inspect instruction.
  19. --
  20. -- Exemple :
  21. --          inspect ...
  22. --              when foo .. bar, then ...
  23. -- 
  24.  
  25. inherit WHEN_ITEM; 
  26.          
  27. creation {E_WHEN,WHEN_ITEM_2}
  28.    make
  29.    
  30. feature {ANY}
  31.    
  32.    lower, upper: EXPRESSION;
  33.    
  34.    lower_value, upper_value: INTEGER;
  35.    
  36. feature {NONE}
  37.    
  38.    make(l, u: EXPRESSION) is
  39.       require
  40.      l /= Void;
  41.      u /= Void
  42.       do
  43.      lower := l;
  44.      upper := u;
  45.       ensure
  46.      lower = l;
  47.      upper = u
  48.       end;
  49.    
  50. feature {ANY}
  51.    
  52.    start_position: POSITION is
  53.       do
  54.      Result := lower.start_position;
  55.       end;
  56.    
  57. feature {E_WHEN,WHEN_ITEM_2}
  58.    
  59.    to_runnable_integer(ew: like e_when): like Current is
  60.       local
  61.      v: like lower;
  62.       do
  63.      if e_when = Void then
  64.         e_when := ew;
  65.         v := lower.to_runnable(current_type);
  66.         if v /= Void and then v.result_type.is_integer then
  67.            lower := v; 
  68.            lower_value := lower.to_integer;
  69.         else        
  70.            error(lower.start_position,fz_biv);
  71.         end;
  72.         v := upper.to_runnable(current_type);
  73.         if v /= Void and then v.result_type.is_integer then
  74.            upper := v; 
  75.            upper_value := upper.to_integer;
  76.         else        
  77.            error(upper.start_position,fz_biv);
  78.         end;
  79.         e_when.add_when_item_2(Current);
  80.         Result := Current;
  81.      else
  82.         !!Result.make(lower,upper);
  83.         Result := Result.to_runnable_integer(ew);
  84.      end;
  85.       end;
  86.    
  87.    to_runnable_character(ew: like e_when): like Current is
  88.       local
  89.      v: like lower;
  90.       do
  91.      if e_when = Void then
  92.         e_when := ew;
  93.         v := lower.to_runnable(current_type);
  94.         if v /= Void and then v.result_type.is_character then
  95.            lower := v; 
  96.            lower_value := lower.to_integer;
  97.         else        
  98.            error(lower.start_position,fz_bcv);
  99.         end;
  100.         v := upper.to_runnable(current_type);
  101.         if v /= Void and then v.result_type.is_character then
  102.            upper := v; 
  103.            upper_value := upper.to_integer;
  104.         else        
  105.            error(upper.start_position,fz_bcv);
  106.         end;
  107.         e_when.add_when_item_2(Current);
  108.         Result := Current;
  109.      else
  110.         !!Result.make(lower,upper);
  111.         Result := Result.to_runnable_character(ew);
  112.      end;
  113.       end;
  114.    
  115.    pretty_print is
  116.       do
  117.      lower.pretty_print;
  118.      fmt.put_string("..");
  119.      upper.pretty_print;
  120.       end;
  121.  
  122. feature {E_WHEN}
  123.  
  124.    eval(exp: INTEGER): BOOLEAN is
  125.       do
  126.      Result := (lower_value <= exp) and (exp <= upper_value);
  127.       end;
  128.  
  129. end -- WHEN_ITEM_2
  130.  
  131.