home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / class_name.e < prev    next >
Text File  |  1999-06-05  |  5KB  |  184 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
  17.    --
  18.    -- To store the base class name of a class.
  19.    --
  20.  
  21. inherit NAME;
  22.  
  23. creation make
  24.  
  25. creation {BASE_CLASS}
  26.    make_unknown
  27.  
  28. feature
  29.  
  30.    to_string: STRING;
  31.  
  32.    start_position: POSITION;
  33.  
  34. feature {NONE}
  35.  
  36.    make_unknown is
  37.       do
  38.          !!start_position.with(1,1,Current);
  39.          to_string := unknown_name;
  40.       end;
  41.  
  42. feature
  43.  
  44.    make(n: STRING; sp: like start_position) is
  45.       require
  46.          n = string_aliaser.item(n)
  47.       do
  48.          start_position := sp;
  49.          to_string := n;
  50.       ensure
  51.          start_position = sp;
  52.          to_string = n
  53.       end;
  54.  
  55. feature
  56.  
  57.    to_key: STRING is
  58.       do
  59.          Result := to_string;
  60.       end;
  61.  
  62.    is_unknown: BOOLEAN is
  63.       do
  64.          Result := to_string = unknown_name;
  65.       end;
  66.  
  67.    is_subclass_of(other: CLASS_NAME): BOOLEAN is
  68.       require
  69.          to_string /= other.to_string
  70.       do
  71.          if as_none = to_string then
  72.             Result := true;
  73.          elseif as_any = other.to_string then
  74.             Result := true;
  75.          elseif as_none = other.to_string then
  76.          else
  77.             Result := base_class.is_subclass_of(other.base_class);
  78.          end;
  79.       end;
  80.  
  81. feature
  82.  
  83.    predefined: BOOLEAN is
  84.          -- All following classes are handled in a special way
  85.          -- by the TYPE_* corresponding class.
  86.       do
  87.          Result := (as_any = to_string or else
  88.                     as_array = to_string or else
  89.                     as_boolean = to_string or else
  90.                     as_character = to_string or else
  91.                     as_double = to_string or else
  92.                     as_integer = to_string or else
  93.                     as_none = to_string or else
  94.                     as_pointer = to_string or else
  95.                     as_real = to_string or else
  96.                     as_string = to_string);
  97.       end;
  98.  
  99.    to_runnable: TYPE is
  100.          -- Return the corresponding simple (not generic) run type.
  101.       do
  102.          if as_any = to_string then
  103.             !TYPE_ANY!Result.make(start_position);
  104.          elseif as_boolean = to_string then
  105.             !TYPE_BOOLEAN!Result.make(start_position);
  106.          elseif as_character = to_string then
  107.             !TYPE_CHARACTER!Result.make(start_position);
  108.          elseif as_double = to_string then
  109.             !TYPE_DOUBLE!Result.make(start_position);
  110.          elseif as_integer = to_string then
  111.             !TYPE_INTEGER!Result.make(start_position);
  112.          elseif as_none = to_string then
  113.             !TYPE_NONE!Result.make(start_position);
  114.          elseif as_pointer = to_string then
  115.             !TYPE_POINTER!Result.make(start_position);
  116.          elseif as_real = to_string then
  117.             !TYPE_REAL!Result.make(start_position);
  118.          elseif as_string = to_string then
  119.             !TYPE_STRING!Result.make(start_position);
  120.          else
  121.             !TYPE_CLASS!Result.make(Current);
  122.          end;
  123.       end;
  124.  
  125.    base_class: BASE_CLASS is
  126.       do
  127.          Result := small_eiffel.base_class(Current);
  128.       end;
  129.  
  130.    is_a(other: like Current): BOOLEAN is
  131.       require
  132.          other /= Void;
  133.          eh.empty;
  134.       local
  135.          to_string2: STRING;
  136.          bc1, bc2: like base_class;
  137.       do
  138.          to_string2 := other.to_string;
  139.          if as_any = to_string2 then
  140.             Result := true;
  141.          elseif to_string = to_string2 then
  142.             Result := true;
  143.          elseif as_none = to_string2 then
  144.          else
  145.             bc1 := base_class;
  146.             bc2 := other.base_class;
  147.             if bc1 = Void then
  148.                eh.append("Unable to load ");
  149.                eh.append(to_string);
  150.                error(start_position,fz_dot);
  151.             elseif bc2 = Void then
  152.                eh.append("Unable to load ");
  153.                eh.append(to_string2);
  154.                error(start_position,fz_dot);
  155.             else
  156.                Result := bc1.is_subclass_of(bc2);
  157.             end;
  158.          end;
  159.       end;
  160.  
  161.    pretty_print is
  162.       do
  163.          fmt.put_string(to_string);
  164.       end;
  165.  
  166. feature {EIFFEL_PARSER}
  167.  
  168.    identify(s: STRING) is
  169.       require
  170.          is_unknown;
  171.          s = string_aliaser.item(s)
  172.       do
  173.          to_string := s;
  174.       ensure
  175.          to_string = s
  176.       end;
  177.  
  178. feature {NONE}
  179.  
  180.    unknown_name: STRING is "FOO";
  181.  
  182. end -- CLASS_NAME
  183.  
  184.