home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #4 / amigaacscoverdisc1998-041998.iso / utilities / shareware / dev / ppcsmalleiffel / lib_se / class_name_list.e < prev    next >
Encoding:
Text File  |  1998-01-16  |  3.4 KB  |  165 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_NAME_LIST
  17.    
  18. inherit GLOBALS;
  19.    
  20. creation {CLIENT_LIST} merge, make
  21.    
  22. feature {CLASS_NAME_LIST}
  23.    
  24.    list: ARRAY[CLASS_NAME];
  25.    
  26. feature {NONE}
  27.    
  28.    make(l: like list) is
  29.      -- Note: also check for multiple occurrences of the 
  30.      -- same name.
  31.       require   
  32.      l /= Void;
  33.      not l.empty;
  34.       local
  35.      i, i2: INTEGER;
  36.       do
  37.      list := l;
  38.      from  
  39.         i := list.upper;
  40.      until
  41.         i = 0
  42.      loop
  43.         i2 := index_of(list.item(i));
  44.         check
  45.            list.item(i2) /= Void 
  46.         end;
  47.         if i2 /= i then
  48.            eh.add_position(list.item(i2).start_position)
  49.            warning(list.item(i).start_position,
  50.              "Same Class Name appears twice.");
  51.         end;
  52.         i := i - 1;
  53.      end;
  54.       ensure
  55.      list = l;
  56.       end;
  57.  
  58.    merge(l1, l2: like Current) is
  59.       require
  60.      l1 /= Void;
  61.      l2 /= Void
  62.       local
  63.      i: INTEGER;
  64.      cn: CLASS_NAME;
  65.      a: ARRAY[CLASS_NAME];
  66.       do
  67.      list := l1.list.twin;
  68.      from
  69.         a := l2.list;
  70.         i := a.upper;
  71.      until
  72.         i = 0
  73.      loop
  74.         cn := a.item(i);
  75.         if not gives_permission_to(cn) then
  76.            list.add_last(cn);
  77.         end;
  78.         i := i - 1;
  79.      end;
  80.       end;
  81.  
  82. feature {CLIENT_LIST}
  83.  
  84.    pretty_print is
  85.       local
  86.      i: INTEGER;
  87.       do
  88.      from  
  89.         i := 1;
  90.      until
  91.         i > list.upper
  92.      loop
  93.         list.item(i).pretty_print;
  94.         i := i + 1;
  95.         if i <= list.upper then
  96.            fmt.put_string(", ");
  97.         end;
  98.      end;
  99.       end;
  100.    
  101.    gives_permission_to(cn: CLASS_NAME): BOOLEAN is
  102.       local
  103.      i: INTEGER;
  104.       do
  105.      if index_of(cn) > 0 then
  106.         Result := true;
  107.      else
  108.         from  
  109.            i := list.upper;
  110.         until
  111.            Result or else i = 0
  112.         loop
  113.            Result := cn.is_subclass_of(list.item(i));
  114.            i := i - 1;           
  115.         end;
  116.      end;
  117.       end;
  118.  
  119.    gives_permission_to_any: BOOLEAN is
  120.       local
  121.      i: INTEGER;
  122.       do
  123.      from  
  124.         i := list.upper;
  125.      until
  126.         Result or else i = 0
  127.      loop
  128.         Result := list.item(i).to_string = us_any;
  129.         i := i - 1;           
  130.      end;
  131.       end;
  132.  
  133. feature {NONE}
  134.  
  135.    index_of(n: CLASS_NAME): INTEGER is
  136.       -- Use `to_string' for comparison.
  137.       -- Gives 0 when `n' is not in the `list'.
  138.       require
  139.      n /= Void;
  140.       local
  141.      to_string: STRING;
  142.       do
  143.      from  
  144.         to_string := n.to_string;
  145.         Result := list.upper;
  146.      until
  147.         (Result = 0) or else 
  148.         (to_string = list.item(Result).to_string)
  149.      loop
  150.         Result := Result - 1;
  151.      end;
  152.       ensure
  153.      0 <= Result;
  154.      Result <= list.upper;
  155.       end;
  156.    
  157. invariant
  158.    
  159.    list.lower = 1;
  160.    
  161.    not list.empty;
  162.    
  163. end -- CLASS_NAME_LIST
  164.  
  165.