home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / class_name_list.e < prev    next >
Text File  |  1999-06-05  |  5KB  |  202 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://SmallEiffel.loria.fr
  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 make_1, merge
  21.  
  22. feature {NONE}
  23.  
  24.    first: CLASS_NAME;
  25.  
  26.    remainder: FIXED_ARRAY[CLASS_NAME];
  27.  
  28. feature {NONE}
  29.  
  30.    make_1(cn: CLASS_NAME) is
  31.       require
  32.          cn /= Void
  33.       do
  34.          first := cn;
  35.       ensure
  36.          count = 1;
  37.          item(1) = cn
  38.       end;
  39.  
  40.    merge(l1, l2: like Current) is
  41.       require
  42.          l1 /= Void;
  43.          l2 /= Void
  44.       local
  45.          i: INTEGER;
  46.          cn: CLASS_NAME;
  47.       do
  48.          first := l1.item(1);
  49.          !!remainder.with_capacity(l1.count + l2.count - 1);
  50.          from
  51.             i := l1.count;
  52.          until
  53.             i = 1
  54.          loop
  55.             remainder.add_last(l1.item(i));
  56.             i := i - 1;
  57.          end;
  58.          from
  59.             i := l2.count;
  60.          until
  61.             i = 0
  62.          loop
  63.             cn := l2.item(i);
  64.             if index_of(cn) = 0 then
  65.                remainder.add_last(cn);
  66.             end;
  67.             i := i - 1;
  68.          end;
  69.       end;
  70.  
  71. feature
  72.  
  73.    count: INTEGER is
  74.       do
  75.          if remainder = Void then
  76.             Result := 1;
  77.          else
  78.             Result := 2 + remainder.upper;
  79.          end;
  80.       end;
  81.  
  82.    item(i: INTEGER): CLASS_NAME is
  83.       require
  84.          i.in_range(1,count)
  85.       do
  86.          if i = 1 then
  87.             Result := first;
  88.          else
  89.             Result := remainder.item(i - 2);
  90.          end;
  91.       ensure
  92.          Result /= Void
  93.       end;
  94.  
  95. feature {EIFFEL_PARSER}
  96.  
  97.    add_last(cn: CLASS_NAME) is
  98.       require
  99.          cn /= Void
  100.       local
  101.          i: INTEGER;
  102.       do
  103.          i := index_of(cn);
  104.          if i > 0 then
  105.             eh.add_position(item(i).start_position);
  106.             warning(cn.start_position,"Same Class Name appears twice.");
  107.          end;
  108.          if remainder = Void then
  109.             !!remainder.with_capacity(4);
  110.          end;
  111.          remainder.add_last(cn);
  112.       ensure
  113.          count = 1 + old count;
  114.          item(count) = cn
  115.       end;
  116.  
  117. feature {CLIENT_LIST}
  118.  
  119.    pretty_print is
  120.       local
  121.          i: INTEGER;
  122.       do
  123.          from
  124.             i := 1;
  125.          until
  126.             i > count
  127.          loop
  128.             item(i).pretty_print;
  129.             if i < count then
  130.                fmt.put_string(", ");
  131.             end;
  132.             i := i + 1;
  133.          end;
  134.       end;
  135.  
  136.    gives_permission_to(cn: CLASS_NAME): BOOLEAN is
  137.       local
  138.          i: INTEGER;
  139.       do
  140.          if index_of(cn) > 0 then
  141.             Result := true;
  142.          else
  143.             from
  144.                i := count;
  145.             until
  146.                Result or else i = 0
  147.             loop
  148.                Result := cn.is_subclass_of(item(i));
  149.                i := i - 1;
  150.             end;
  151.  
  152.          end;
  153.       end;
  154.  
  155.    gives_permission_to_any: BOOLEAN is
  156.       local
  157.          i: INTEGER;
  158.          cn: CLASS_NAME;
  159.       do
  160.          from
  161.             i := count;
  162.          until
  163.             Result or else i = 0
  164.          loop
  165.             cn := item(i);
  166.             Result := cn.to_string = as_any;
  167.             i := i - 1;
  168.          end;
  169.       end;
  170.  
  171. feature {}
  172.  
  173.    index_of(n: CLASS_NAME): INTEGER is
  174.       -- Use `to_string' for comparison.
  175.       -- Gives 0 when `n' is not in the `list'.
  176.       require
  177.          n /= Void;
  178.       local
  179.          to_string: STRING;
  180.       do
  181.          from
  182.             to_string := n.to_string;
  183.             Result := count;
  184.          until
  185.             Result = 0 or else to_string = item(Result).to_string
  186.          loop
  187.             Result := Result - 1;
  188.          end;
  189.       ensure
  190.          Result.in_range(0,count);
  191.          Result > 0 implies n.to_string = item(Result).to_string
  192.       end;
  193.  
  194. invariant
  195.  
  196.    first /= Void;
  197.  
  198.    remainder /= Void implies count = 1 + remainder.count;
  199.  
  200. end -- CLASS_NAME_LIST
  201.  
  202.