home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / type_like_feature.e < prev    next >
Text File  |  1999-06-05  |  4KB  |  157 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 TYPE_LIKE_FEATURE
  17.    --
  18.    -- For an anchored declaration type mark using a feature name.
  19.    --
  20.    -- See also TYPE_LIKE_ARG and TYPE_LIKE_CURRENT.
  21.    --
  22.  
  23. inherit TYPE_ANCHORED redefine is_like_feature, like_feature end;
  24.  
  25. creation make, with
  26.  
  27. feature
  28.  
  29.    like_what: FEATURE_NAME;
  30.  
  31.    written_mark: STRING;
  32.  
  33.    run_type: TYPE;
  34.          -- When runnable.
  35.  
  36. feature {NONE}
  37.  
  38.    make(sp: like start_position; lw: like like_what) is
  39.       require
  40.          sp /= Void;
  41.          lw /= Void
  42.       do
  43.          start_position := sp;
  44.          like_what := lw;
  45.          tmp_written_mark.copy(fz_like);
  46.          tmp_written_mark.extend(' ');
  47.          like_what.declaration_in(tmp_written_mark);
  48.          written_mark := string_aliaser.item(tmp_written_mark);
  49.       ensure
  50.          start_position = sp
  51.       end;
  52.  
  53.    with(model: like Current; rt: like run_type) is
  54.       require
  55.          model /= Void;
  56.          rt /= Void
  57.       do
  58.          start_position := model.start_position;
  59.          like_what := model.like_what;
  60.          written_mark := model.written_mark;
  61.          run_type := rt;
  62.       ensure
  63.          start_position = model.start_position;
  64.          like_what = model.like_what;
  65.          written_mark = model.written_mark;
  66.          run_type = rt;
  67.       end;
  68.  
  69. feature
  70.  
  71.    is_like_feature: BOOLEAN is true;
  72.  
  73.    is_like_current: BOOLEAN is false;
  74.  
  75.    is_like_argument: BOOLEAN is false;
  76.  
  77.    static_base_class_name: CLASS_NAME is
  78.       local
  79.          bc: BASE_CLASS;
  80.          e_feature: E_FEATURE;
  81.          rt: TYPE;
  82.       do
  83.          bc := start_position.base_class;
  84.          e_feature := bc.e_feature(like_feature);
  85.          if e_feature /= Void then
  86.             rt := e_feature.result_type;
  87.             if rt /= Void then
  88.                Result := rt.static_base_class_name;
  89.             end;
  90.          else
  91.             eh.append(fz_bad_anchor);
  92.             eh.add_position(start_position);
  93.             eh.print_as_fatal_error;
  94.          end;
  95.       end;
  96.  
  97.    like_feature: FEATURE_NAME is
  98.       do
  99.          Result := like_what;
  100.       end;
  101.  
  102.    is_run_type: BOOLEAN is
  103.       do
  104.          Result := run_type /= Void;
  105.       end;
  106.  
  107.    to_runnable(ct: TYPE): like Current is
  108.       local
  109.          rc: RUN_CLASS;
  110.          rt: TYPE;
  111.       do
  112.          anchor_cycle_start;
  113.          rc := ct.run_class;
  114.          rt := rc.get_result_type(like_what);
  115.          if run_type = Void then
  116.             run_type := rt;
  117.             Result := Current;
  118.          elseif run_type = rt then
  119.             Result := Current;
  120.          else
  121.             !!Result.with(Current,rt);
  122.          end;
  123.          anchor_cycle_end;
  124.       end;
  125.  
  126.    is_a(other: TYPE): BOOLEAN is
  127.       local
  128.          tlf: like Current;
  129.       do
  130.          if other.is_like_feature then
  131.             tlf ?= other;
  132.             if like_what.to_string = tlf.like_what.to_string then
  133.                Result := true;
  134.                --eh.add_position(other.start_position);
  135.                --warning(start_position,"YOO");
  136.             else
  137.                Result := run_type.is_a(other);
  138.             end;
  139.          else
  140.             Result := run_type.is_a(other);
  141.          end;
  142.          if not Result then
  143.             eh.add_position(start_position);
  144.          end;
  145.       end;
  146.  
  147. feature {TYPE}
  148.  
  149.    short_hook is
  150.       do
  151.          short_print.hook_or("like","like ");
  152.          like_what.short;
  153.       end;
  154.  
  155. end -- TYPE_LIKE_FEATURE
  156.  
  157.