home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / e_precursor.e < prev    next >
Text File  |  1999-06-05  |  5KB  |  172 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. deferred class E_PRECURSOR
  17.    --
  18.    -- Handling of the pseudo variable "Current".
  19.    --
  20.  
  21. inherit GLOBALS;
  22.  
  23. feature
  24.  
  25.    start_position: POSITION;
  26.  
  27.  
  28.    parent: CLASS_NAME;
  29.          -- {{<CLASS_NAME>}} to remove the ambiguity if any.
  30.  
  31. feature {E_PRECURSOR}
  32.  
  33.    current_type: TYPE;
  34.  
  35.    arguments: EFFECTIVE_ARG_LIST;
  36.  
  37.    run_feature: RUN_FEATURE;
  38.          -- Corresponding super feature.
  39. feature
  40.  
  41.    make(sp: like start_position; pc: like parent; pal: like arguments) is
  42.       require
  43.          sp /= Void
  44.       do
  45.          start_position := sp;
  46.          parent := pc;
  47.          arguments := pal;
  48.       ensure
  49.          start_position = sp;
  50.          parent = pc;
  51.          arguments = pal;
  52.       end;
  53.  
  54. feature
  55.  
  56.    is_current: BOOLEAN is false;
  57.  
  58.    is_manifest_string: BOOLEAN is false;
  59.  
  60.    is_result: BOOLEAN is false;
  61.  
  62.    is_void: BOOLEAN is false;
  63.  
  64.    use_current: BOOLEAN is true;
  65.  
  66. feature
  67.  
  68.    frozen afd_check is
  69.       do
  70.          if arguments /= Void then
  71.             arguments.afd_check;
  72.          end;
  73.       end;
  74.  
  75.    compile_to_c is
  76.       do
  77.          cpp.push_precursor(run_feature,arguments);
  78.          run_feature.mapping_c;
  79.          cpp.pop;
  80.       end;
  81.  
  82.    frozen pretty_print is
  83.       do
  84.          if parent /= Void then
  85.             fmt.put_string("{{ ");
  86.             parent.pretty_print;
  87.             fmt.put_string(" }} ");
  88.          end;
  89.          fmt.put_string(as_precursor);
  90.          if arguments /= Void then
  91.             fmt.level_incr;
  92.             arguments.pretty_print;
  93.             fmt.level_decr;
  94.          end;
  95.          put_semi_colon;
  96.       end;
  97.  
  98.    frozen compile_to_jvm is
  99.       do
  100.          jvm.push_precursor(run_feature,arguments);
  101.          run_feature.mapping_jvm;
  102.          jvm.pop;
  103.       end;
  104.  
  105. feature {NONE}
  106.  
  107.    put_semi_colon is
  108.       deferred
  109.       end;
  110.  
  111. feature {NONE}
  112.  
  113.    super_feature(wrf: RUN_FEATURE): EFFECTIVE_ROUTINE is
  114.          -- Gives the E_FEATURE to be called where `wrf' is the
  115.          -- written runable feature which contains Current.
  116.       require
  117.          wrf /= Void
  118.       local
  119.          e_feature: E_FEATURE;
  120.          wbc: BASE_CLASS;
  121.          pl: PARENT_LIST;
  122.       do
  123.          e_feature := wrf.base_feature;
  124.          wbc := e_feature.base_class;
  125.          pl := wbc.parent_list;
  126.          if pl = Void then
  127.             eh.add_position(start_position);
  128.             fatal_error("Precursor call is allowed only when the %
  129.                         %enclosing routine is redefined.");
  130.          else
  131.             Result := pl.precursor_for(Current,wrf);
  132.          end;
  133.       ensure
  134.          Result /= Void
  135.       end;
  136.  
  137.    prepare_arguments(ct: TYPE) is
  138.          -- Called after `super_feature' in order to prepare runnable `arguments'.
  139.       require
  140.          run_feature /= Void
  141.       local
  142.          a: like arguments;
  143.       do
  144.          if arguments /= Void then
  145.             a := arguments.to_runnable(ct);
  146.             if a = Void then
  147.                error(arguments.start_position,fz_bad_arguments);
  148.             else
  149.                arguments := a;
  150.             end;
  151.             if nb_errors = 0 then
  152.                arguments.match_with(run_feature,ct);
  153.             end;
  154.          elseif run_feature.arguments /= Void then
  155.             eh.add_position(run_feature.start_position);
  156.             eh.add_position(start_position);
  157.             fatal_error("Precursor must pass argument(s).");
  158.          end;
  159.       end;
  160.  
  161. feature {NONE}
  162.  
  163.    precursor_name(wfn: FEATURE_NAME; super: E_FEATURE): PRECURSOR_NAME is
  164.       require
  165.          wfn /= Void;
  166.          super /= Void
  167.       do
  168.          !!Result.refer_to(super.base_class.id,wfn);
  169.       end;
  170.  
  171. end -- E_PRECURSOR
  172.