home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #4 / amigaacscoverdisc1998-041998.iso / utilities / shareware / dev / ppcsmalleiffel / lib_se / simple_feature_name.e < prev    next >
Encoding:
Text File  |  1998-01-16  |  5.8 KB  |  267 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://www.loria.fr/SmallEiffel
  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 SIMPLE_FEATURE_NAME
  17. --   
  18. -- Is used for simple (not infix or prefix) names of feature in the
  19. -- declaration part of a feature but is also used when writing an
  20. --  attribute as a left hand side of an assignment.
  21. --
  22.  
  23. inherit 
  24.    FEATURE_NAME;
  25.    EXPRESSION
  26.       redefine is_writable
  27.       end;
  28.  
  29.  
  30. creation make
  31.  
  32. feature {NONE}
  33.  
  34.    run_feature_2: RUN_FEATURE_2;
  35.      -- Corresponding one when runnable.
  36.  
  37. feature
  38.  
  39.    is_writable: BOOLEAN is true;
  40.  
  41.    use_current: BOOLEAN is true;
  42.  
  43.    is_static: BOOLEAN is false;
  44.       
  45.    is_pre_computable: BOOLEAN is false;
  46.  
  47.    isa_dca_inline_argument: INTEGER is 0;
  48.  
  49. feature {BASE_CLASS}
  50.    
  51.    make(n: STRING; sp: like start_position) is
  52.       require
  53.      n.count >= 1;
  54.       do
  55.      to_string := unique_string.item(n);
  56.      start_position := sp;
  57.       end;
  58.  
  59. feature
  60.  
  61.    to_key: STRING is
  62.       do
  63.      Result := to_string;
  64.       end;
  65.  
  66.    result_type: TYPE is
  67.       do
  68.      Result := run_feature_2.result_type;
  69.       end;
  70.  
  71.    can_be_dropped: BOOLEAN is
  72.       do
  73.      eh.add_position(start_position);
  74.      fatal_error("FEATURE_NAME/Should never be called.");
  75.       end;
  76.  
  77.    to_runnable(ct: TYPE): like Current is
  78.       local
  79.      wbc: BASE_CLASS;
  80.      rf: RUN_FEATURE;
  81.      new_name:  FEATURE_NAME;
  82.       do
  83.      if current_type = Void then
  84.         current_type := ct;
  85.         wbc := start_position.base_class;
  86.         new_name := ct.base_class.new_name_of(wbc,Current);
  87.         rf := current_type.run_class.get_feature(new_name);
  88.         if rf = Void then
  89.            error(start_position,"Feature not found.");
  90.         else
  91.            run_feature_2 ?= rf;
  92.            if run_feature_2 = Void then
  93.           eh.add_position(rf.start_position);
  94.           error(start_position,
  95.             "Feature found is not writable.");
  96.            end;
  97.         end;
  98.         if nb_errors = 0 then
  99.            Result := Current;
  100.         else
  101.            error(start_position,"Bad feature name.");
  102.         end;
  103.      elseif ct = current_type then
  104.         Result := Current;
  105.      else
  106.         !!Result.make(to_string,start_position);
  107.         Result := Result.to_runnable(ct);
  108.      end;
  109.       end;
  110.    
  111.    precedence: INTEGER is
  112.       do
  113.      Result := atomic_precedence;
  114.       end;
  115.       
  116.    run_feature(t: TYPE): RUN_FEATURE is
  117.       -- **** VIRER ??? ***
  118.      -- Look for the corresponding runnable feature in `t';
  119.       require
  120.      t.is_run_type
  121.       do
  122.      Result := t.run_class.get_feature(Current);
  123.      -- *****************************
  124.      --                    get_rf_with ???
  125.       end;
  126.  
  127.    dca_inline_argument(formal_arg_type: TYPE) is
  128.       do
  129.       end;
  130.  
  131.    mapping_c_target(target_type: TYPE) is
  132.       local
  133.      flag: BOOLEAN;
  134.       do
  135.      flag := cpp.call_invariant_start(target_type);
  136.      compile_to_c;
  137.      if flag then
  138.         cpp.call_invariant_end;
  139.      end;
  140.       end;
  141.  
  142.    mapping_c_arg(formal_arg_type: TYPE) is
  143.       do
  144.      compile_to_c;
  145.       end;
  146.  
  147.    compile_to_c is
  148.       do
  149.      cpp.put_string("C->_");
  150.      cpp.put_string(run_feature_2.name.to_string);
  151.       end;
  152.  
  153.    compile_to_c_old is
  154.       do 
  155.       end;
  156.       
  157.    compile_to_jvm_old is
  158.       do 
  159.       end;
  160.    
  161. feature -- For pretty :
  162.  
  163.    print_as_target is
  164.       do
  165.      fmt.put_string(to_string);
  166.      fmt.put_character('.');
  167.       end;
  168.    
  169.    definition_pretty_print is
  170.       do
  171.      fmt.put_string(to_string);
  172.       end;
  173.  
  174. feature
  175.  
  176.    short is
  177.       local
  178.      i: INTEGER;
  179.      c: CHARACTER;
  180.       do
  181.      short_print.hook("Bsfn");
  182.      from
  183.         i := 1;
  184.      until
  185.         i > to_string.count
  186.      loop
  187.         c := to_string.item(i);
  188.         if c = '_' then
  189.            short_print.hook_or("Usfn","_");
  190.         else
  191.            short_print.a_character(c);
  192.         end;
  193.         i := i + 1;
  194.      end;
  195.      short_print.hook("Asfn");
  196.       end;
  197.  
  198.    short_target is
  199.       do
  200.      short;
  201.      short_print.a_dot;
  202.       end;
  203.  
  204. feature
  205.  
  206.    cpp_put_infix_or_prefix is
  207.       do
  208.       end;
  209.  
  210. feature
  211.  
  212.    compile_target_to_jvm, compile_to_jvm is
  213.       do
  214.      eh.add_position(start_position);
  215.      fatal_error(fz_jvm_error);
  216.       end;
  217.    
  218.    compile_to_jvm_assignment(a: ASSIGNMENT) is
  219.       local
  220.      space, idx: INTEGER;
  221.      rf: RUN_FEATURE;
  222.      rt: TYPE;
  223.       do
  224.      rf := run_feature_2;
  225.      rt := rf.result_type.run_type;
  226.      code_attribute.opcode_aload_0;
  227.      space := a.right_side.compile_to_jvm_into(rt);
  228.      idx := constant_pool.idx_fieldref(rf);
  229.      space := -(space + 1);
  230.      code_attribute.opcode_putfield(idx,space);
  231.       end;
  232.    
  233.    jvm_branch_if_false: INTEGER is
  234.       do
  235.      compile_to_jvm;
  236.      Result := code_attribute.opcode_ifeq;
  237.       end;
  238.  
  239.    jvm_branch_if_true: INTEGER is
  240.       do
  241.      compile_to_jvm;
  242.      Result := code_attribute.opcode_ifne;
  243.       end;
  244.  
  245.    compile_to_jvm_into(dest: TYPE): INTEGER is
  246.       do
  247.      Result := standard_compile_to_jvm_into(dest);
  248.       end;
  249.  
  250. feature {CREATION_CALL,EXPRESSION_WITH_COMMENT}
  251.       
  252.    jvm_assign is
  253.       local
  254.      space, idx: INTEGER;
  255.      rf: RUN_FEATURE;
  256.       do
  257.      code_attribute.opcode_aload_0;
  258.      code_attribute.opcode_swap;
  259.      rf := run_feature_2;
  260.      idx := constant_pool.idx_fieldref(rf);
  261.      space := -(rf.result_type.jvm_stack_space + 1);
  262.      code_attribute.opcode_putfield(idx,space);
  263.       end;
  264.  
  265. end -- SIMPLE_FEATURE_NAME
  266.  
  267.