home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #4 / amigaacscoverdisc1998-041998.iso / utilities / shareware / dev / ppcsmalleiffel / lib_se / rename_list.e < prev    next >
Encoding:
Text File  |  1998-01-16  |  4.2 KB  |  194 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 RENAME_LIST
  17.    
  18. inherit GLOBALS;
  19.    
  20. creation {ANY}
  21.    make
  22.    
  23. feature {NONE}
  24.    
  25.    list: ARRAY[RENAME_PAIR];
  26.    
  27. feature {ANY}
  28.    
  29.    make(l: like list) is
  30.       require
  31.      l.lower = 1;
  32.      not l.empty;
  33.       do
  34.      list := l;
  35.       ensure     
  36.      list = l
  37.       end;
  38.    
  39.    affect(fn: FEATURE_NAME): BOOLEAN is
  40.      -- Does Current affect `fn' (new or old as well) ?
  41.       require
  42.      fn /= Void
  43.       local
  44.      i: INTEGER;
  45.      rp: RENAME_PAIR;
  46.      fn_to_key: STRING;
  47.       do
  48.      from  
  49.         i := list.upper;
  50.      until
  51.         Result or else i = 0 
  52.      loop
  53.         rp := list.item(i);
  54.         fn_to_key := fn.to_key;
  55.         if rp.new_name.to_key = fn_to_key or else 
  56.            rp.old_name.to_key = fn_to_key 
  57.          then
  58.            Result := true;
  59.         else
  60.            i := i - 1;
  61.         end;
  62.      end;
  63.       end;
  64.    
  65.    pretty_print is
  66.       local
  67.      icount, i: INTEGER;
  68.       do
  69.      fmt.set_indent_level(2);
  70.      fmt.indent;
  71.      fmt.keyword("rename");
  72.      from  
  73.         i := 1;
  74.      until
  75.         i > list.upper
  76.      loop
  77.         list.item(i).pretty_print;
  78.         i := i + 1;
  79.         icount := icount + 1;
  80.         if i <= list.upper then
  81.            fmt.put_string(", ");
  82.            if icount > 3 then
  83.           icount := 0;
  84.           fmt.set_indent_level(3);
  85.           fmt.indent;
  86.            end;
  87.         end;
  88.      end;
  89.       end;
  90.    
  91.    to_old_name(fn: FEATURE_NAME): like fn is
  92.      -- Going up. Gives back `fn' or the old name if any. 
  93.       require
  94.      fn /= Void;
  95.       local
  96.      i: INTEGER;
  97.      fn_to_key: STRING;
  98.       do
  99.      from  
  100.         i := 1;
  101.         fn_to_key := fn.to_key;
  102.      until
  103.         Result /= Void or else i > list.upper
  104.      loop
  105.         if list.item(i).new_name.to_key = fn_to_key then
  106.            Result := list.item(i).old_name;
  107.         end;
  108.         i := i + 1;
  109.      end;
  110.      if Result = Void then
  111.         Result := fn;
  112.      end;
  113.       ensure 
  114.      Result /= Void
  115.       end;
  116.       
  117.    to_new_name(fn: FEATURE_NAME): like fn is
  118.      -- Going down. Gives back `fn' or the new name if any.
  119.       require
  120.      fn /= Void;
  121.       local
  122.      i: INTEGER;
  123.      fn_to_key: STRING;
  124.       do
  125.      from  
  126.         i := 1;
  127.         fn_to_key := fn.to_key;
  128.      until
  129.         Result /= Void or else i > list.upper
  130.      loop
  131.         if list.item(i).old_name.to_key = fn_to_key then
  132.            Result := list.item(i).new_name;
  133.         end;
  134.         i := i + 1;
  135.      end;
  136.      if Result = Void then
  137.         Result := fn;
  138.      end;
  139.       ensure 
  140.      Result /= Void
  141.       end;
  142.    
  143. feature {PARENT}
  144.    
  145.    add_last(rp: RENAME_PAIR) is
  146.       require
  147.      rp /= Void
  148.       do
  149.      list.add_last(rp);
  150.       end;
  151.    
  152.    get_started(pbc: BASE_CLASS) is
  153.       require
  154.      run_control.all_check
  155.       local
  156.      i, j: INTEGER;
  157.      rp1, rp2: RENAME_PAIR;
  158.       do
  159.      from
  160.         i := list.upper;
  161.      until
  162.         i = 0
  163.      loop
  164.         rp1 := list.item(i);
  165.         if not pbc.has(rp1.old_name) then
  166.            eh.add_position(rp1.old_name.start_position);
  167.            fatal_error("Cannot rename inexistant feature (VHRC.1).");
  168.         end;
  169.         i := i - 1;
  170.         from
  171.            j := i;
  172.         until
  173.            j = 0
  174.         loop
  175.            rp2 := list.item(j);
  176.            if rp2.old_name.to_key = rp1.old_name.to_key then
  177.           eh.add_position(rp1.old_name.start_position);
  178.           eh.add_position(rp2.old_name.start_position);
  179.           fatal_error("Multiple rename for the same feature (VHRC.2).");
  180.            end;
  181.            j := j - 1;
  182.         end;
  183.      end;
  184.       end;
  185.    
  186. invariant
  187.    
  188.    list.lower = 1;
  189.    
  190.    not list.empty;
  191.    
  192. end -- RENAME_LIST
  193.  
  194.