home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #4 / amigaacscoverdisc1998-041998.iso / utilities / shareware / dev / ppcsmalleiffel / lib_se / feature_name_list.e < prev    next >
Encoding:
Text File  |  1998-01-16  |  4.3 KB  |  217 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 FEATURE_NAME_LIST
  17.    --
  18.    -- A list of FEATURE_NAME (FEATURE_NAME, INFIX_NAME and
  19.    -- PREFIX_NAME mixed).
  20.    --
  21.    
  22. inherit GLOBALS;
  23.    
  24. creation make
  25.    
  26. feature {NONE}
  27.    
  28.    list: ARRAY[FEATURE_NAME];
  29.    
  30. feature 
  31.    
  32.    make(l: like list) is
  33.      -- Note: also check for multiple occurrences.
  34.       require   
  35.      l.lower = 1;
  36.      not l.empty;
  37.       local
  38.      i, i2: INTEGER;
  39.       do
  40.      list := l;
  41.      from  
  42.         i := l.upper;
  43.      until
  44.         i = 0 
  45.      loop
  46.         i2 := index_of(l.item(i));
  47.         if i2 /= i then
  48.            eh.add_position(l.item(i2).start_position);
  49.            eh.add_position(l.item(i).start_position);
  50.            fatal_error("Same feature name appears twice.");
  51.         end;
  52.         i := i - 1;
  53.      end;
  54.       ensure
  55.      list = l;
  56.       end;
  57.    
  58. feature
  59.    
  60.    has(fn: FEATURE_NAME): BOOLEAN is
  61.       require
  62.      fn /= Void
  63.       do
  64.      Result := index_of(fn) > 0 ;
  65.       end;
  66.    
  67.    feature_name(fn_key: STRING): FEATURE_NAME is
  68.       require
  69.      fn_key = unique_string.item(fn_key)
  70.       local
  71.      i: INTEGER;
  72.       do
  73.      from  
  74.         i := 1;
  75.      until
  76.         fn_key = item(i).to_key or else i > count
  77.      loop
  78.         i := i + 1;
  79.      end;
  80.      if i <= count then
  81.         Result := item(i);
  82.      end;
  83.       end;
  84.    
  85.    pretty_print is
  86.       local
  87.      i, icount: INTEGER;
  88.       do
  89.      from  
  90.         i := 1;
  91.      until
  92.         i > count
  93.      loop
  94.         fmt.set_indent_level(3);
  95.         list.item(i).definition_pretty_print;
  96.         i := i + 1;
  97.         icount := icount + 1;
  98.         if i <= count then
  99.            fmt.put_string(", ");
  100.            if icount > 4 then
  101.           fmt.set_indent_level(3);
  102.           fmt.indent;
  103.           icount := 0;
  104.            end;
  105.         end;
  106.      end;
  107.       end;
  108.  
  109.    short is
  110.       local
  111.      i, icount: INTEGER;
  112.       do
  113.      from  
  114.         i := 1;
  115.      until
  116.         i > count
  117.      loop
  118.         list.item(i).short;
  119.         i := i + 1;
  120.         if i <= count then
  121.            short_print.hook_or("fnl_sep",", ");
  122.         end;
  123.      end;
  124.       end;
  125.    
  126.    item(i: INTEGER): FEATURE_NAME is
  127.       require
  128.      1 <= i;
  129.      i <= count;
  130.       do
  131.      Result := list.item(i);
  132.       end;
  133.    
  134.    count: INTEGER is
  135.       do 
  136.      Result := list.upper;
  137.       end;
  138.  
  139. feature {FEATURE_CLAUSE}
  140.  
  141.    for_short(fc: FEATURE_CLAUSE; heading_done: BOOLEAN; bcn: CLASS_NAME;
  142.          sort: BOOLEAN; rf_list: FIXED_ARRAY[RUN_FEATURE]; 
  143.          rc: RUN_CLASS): BOOLEAN is
  144.       local
  145.      i: INTEGER;
  146.      fn: FEATURE_NAME;
  147.      rf: RUN_FEATURE;
  148.       do
  149.      Result := heading_done;
  150.      from  
  151.         i := 1;
  152.      until
  153.         i > count
  154.      loop
  155.         fn := list.item(i);
  156.         rf := rc.get_rf_with(fn);
  157.         if not rf_list.fast_has(rf) then
  158.            rf_list.add_last(rf);
  159.            if not sort then
  160.           if not heading_done then
  161.              Result := true;
  162.              fc.do_heading_for_short(bcn);
  163.           end;
  164.           short_print.a_run_feature(rf);
  165.            end;
  166.         end;
  167.         i := i + 1;
  168.      end;
  169.       end;
  170.    
  171. feature {RUN_FEATURE_1}
  172.  
  173.    index_of(fn: FEATURE_NAME): INTEGER is
  174.       require
  175.      fn /= Void;
  176.       local
  177.      fn_key: STRING;
  178.       do
  179.      fn_key := fn.to_key;
  180.      from  
  181.         Result := list.upper;
  182.      until
  183.         Result = 0 or else fn_key = item(Result).to_key
  184.      loop
  185.         Result := Result - 1;
  186.      end;
  187.       ensure
  188.      0 <= Result;
  189.      Result <= count;
  190.      Result > 0 implies fn.to_key = item(Result).to_key
  191.       end;
  192.  
  193. feature {CREATION_CLAUSE}
  194.  
  195.    short_for_creation is
  196.       local
  197.      i: INTEGER;
  198.       do
  199.      from  
  200.         i := 1;
  201.      until
  202.         i > count
  203.      loop
  204.         short_print.a_feature(list.item(i));
  205.         i := i + 1;
  206.      end;
  207.       end;
  208.    
  209. invariant
  210.    
  211.    count >= 1;
  212.    
  213.    list.lower = 1;
  214.    
  215. end -- FEATURE_NAME_LIST
  216.  
  217.