home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / formal_generic_arg.e < prev    next >
Text File  |  1999-06-05  |  3KB  |  115 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 FORMAL_GENERIC_ARG
  17.    --
  18.    -- To store one formal generic argument.
  19.    --
  20.  
  21. inherit GLOBALS;
  22.  
  23. creation make
  24.  
  25. feature
  26.  
  27.    name: CLASS_NAME;
  28.          -- Name of the formal generic argument.
  29.  
  30.    constraint: TYPE;
  31.  
  32. feature {NONE}
  33.  
  34.    make(n: like name; c: like constraint) is
  35.       require
  36.          n /= Void
  37.       do
  38.          name := n;
  39.          constraint := c;
  40.       ensure
  41.          name = n;
  42.          constraint = c
  43.       end;
  44.  
  45. feature
  46.  
  47.    base_class: BASE_CLASS is
  48.       do
  49.          Result := name.start_position.base_class;
  50.       ensure
  51.          Result.is_generic
  52.       end;
  53.  
  54.    rank: INTEGER is
  55.          -- In the corresponding declation list.
  56.       do
  57.          check
  58.             base_class /= Void;
  59.             base_class.is_generic;
  60.             base_class.formal_generic_list.count >= 1;
  61.          end;
  62.          Result := base_class.formal_generic_list.index_of(Current.name);
  63.       ensure
  64.          Result >= 1
  65.       end;
  66.  
  67.    constrained: BOOLEAN is
  68.       do
  69.          Result := (constraint /= void);
  70.       end;
  71.  
  72.    start_position: POSITION is
  73.       do
  74.          Result := name.start_position;
  75.       end;
  76.  
  77.    pretty_print is
  78.       do
  79.          name.pretty_print;
  80.          if constrained then
  81.             fmt.level_incr;
  82.             fmt.put_string("->");
  83.             constraint.pretty_print;
  84.             fmt.level_decr;
  85.          end;
  86.       end;
  87.  
  88.    short is
  89.       do
  90.          short_print.a_class_name(name);
  91.          if constrained then
  92.             short_print.hook_or("arrow","->");
  93.             constraint.short;
  94.          end;
  95.       end;
  96.  
  97. feature {FORMAL_GENERIC_LIST}
  98.  
  99.    check_generic_formal_arguments is
  100.       do
  101.          if small_eiffel.is_used(name.to_string) then
  102.             eh.add_position(name.start_position);
  103.             fatal_error("A formal generic argument must not be the %
  104.                         %name of an existing class (VCFG.1).");
  105.  
  106.          end;
  107.       end;
  108.  
  109. invariant
  110.  
  111.    name /= Void;
  112.  
  113. end -- FORMAL_GENERIC_ARG
  114.  
  115.