home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / simple_feature_name.e < prev    next >
Text File  |  1999-06-05  |  8KB  |  323 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 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, with
  31.  
  32. feature
  33.  
  34.    to_string: STRING;
  35.  
  36.    start_position: POSITION;
  37.  
  38.    run_feature_2: RUN_FEATURE_2;
  39.          -- Corresponding one when runnable.
  40.  
  41. feature
  42.  
  43.    is_frozen: BOOLEAN is false;
  44.  
  45.    is_current: BOOLEAN is false;
  46.  
  47.    is_writable: BOOLEAN is true;
  48.  
  49.    use_current: BOOLEAN is true;
  50.  
  51.    is_pre_computable: BOOLEAN is false;
  52.  
  53.    isa_dca_inline_argument: INTEGER is 0;
  54.  
  55.    is_static: BOOLEAN is false;
  56.  
  57. feature {BASE_CLASS}
  58.  
  59.    make(n: STRING; sp: like start_position) is
  60.       require
  61.          n.count >= 1;
  62.          n = string_aliaser.item(n)
  63.       do
  64.          to_string := n;
  65.          start_position := sp;
  66.       ensure
  67.          to_string = n;
  68.          start_position = sp
  69.       end;
  70.  
  71. feature {NONE}
  72.  
  73.    with(model: like Current; rf2: RUN_FEATURE_2) is
  74.       require
  75.          model /= Void;
  76.          rf2 /= Void
  77.       do
  78.          to_string := model.to_string;
  79.          start_position := model.start_position;
  80.          run_feature_2 := rf2;
  81.       ensure
  82.          to_string = model.to_string;
  83.          start_position = model.start_position;
  84.          run_feature_2 = rf2
  85.       end;
  86.  
  87. feature
  88.  
  89.    static_result_base_class: BASE_CLASS is    
  90.       local
  91.          bc: BASE_CLASS;
  92.          e_feature: E_FEATURE;
  93.          rt: TYPE;
  94.          cn: CLASS_NAME;
  95.       do
  96.          bc := start_position.base_class;
  97.          if bc /= Void then
  98.             e_feature := bc.e_feature(Current);
  99.             if e_feature /= Void then
  100.                rt := e_feature.result_type;
  101.                if rt /= Void then
  102.                   cn := rt.static_base_class_name;
  103.                   if cn /= Void then
  104.                      Result := cn.base_class;
  105.                   end;
  106.                end;
  107.             end;
  108.          end;
  109.       end;
  110.  
  111.    static_value: INTEGER is
  112.       do
  113.       end;
  114.  
  115.    to_key: STRING is
  116.       do
  117.          Result := to_string;
  118.       end;
  119.  
  120.    result_type: TYPE is
  121.       do
  122.          Result := run_feature_2.result_type;
  123.       end;
  124.  
  125.    can_be_dropped: BOOLEAN is
  126.       do
  127.          eh.add_position(start_position);
  128.          fatal_error("FEATURE_NAME/Should never be called.");
  129.       end;
  130.  
  131.    to_runnable(ct: TYPE): like Current is
  132.       local
  133.          wbc: BASE_CLASS;
  134.          rf: RUN_FEATURE;
  135.          new_name:  FEATURE_NAME;
  136.          rf2: RUN_FEATURE_2;
  137.       do
  138.          wbc := start_position.base_class;
  139.          new_name := ct.base_class.new_name_of(wbc,Current);
  140.          rf := ct.run_class.get_feature(new_name);
  141.          if rf = Void then
  142.             eh.add_feature_name(new_name);
  143.             fatal_error(fz_feature_not_found);
  144.          else
  145.             rf2 ?= rf;
  146.             if rf2 = Void then
  147.                eh.add_position(rf.start_position);
  148.                error(start_position,
  149.                      "Feature found is not writable.");
  150.             end;
  151.          end;
  152.          if run_feature_2 = Void then
  153.             run_feature_2 := rf2;
  154.             Result := Current;
  155.          elseif run_feature_2 = rf then
  156.             Result := Current;
  157.          else
  158.             !!Result.with(Current,rf2);
  159.          end;
  160.       end;
  161.  
  162.    precedence: INTEGER is
  163.       do
  164.          Result := atomic_precedence;
  165.       end;
  166.  
  167.    assertion_check(tag: CHARACTER) is
  168.       do
  169.       end;
  170.  
  171.    dca_inline_argument(formal_arg_type: TYPE) is
  172.       do
  173.       end;
  174.  
  175.    mapping_c_target(target_type: TYPE) is
  176.       local
  177.          flag: BOOLEAN;
  178.       do
  179.          flag := cpp.call_invariant_start(target_type);
  180.          compile_to_c;
  181.          if flag then
  182.             cpp.call_invariant_end;
  183.          end;
  184.       end;
  185.  
  186.    mapping_c_arg(formal_arg_type: TYPE) is
  187.       do
  188.          compile_to_c;
  189.       end;
  190.  
  191.    collect_c_tmp is
  192.       do
  193.       end;
  194.  
  195.    compile_to_c is
  196.       do
  197.          cpp.put_string("C->_");
  198.          cpp.put_string(run_feature_2.name.to_string);
  199.       end;
  200.  
  201.    c_declare_for_old is
  202.       do
  203.       end;
  204.  
  205.    compile_to_c_old is
  206.       do
  207.       end;
  208.  
  209.    compile_to_jvm_old is
  210.       do
  211.       end;
  212.  
  213.    print_as_target is
  214.       do
  215.          fmt.put_string(to_string);
  216.          fmt.put_character('.');
  217.       end;
  218.  
  219.    mapping_c_in(str: STRING) is
  220.       do
  221.          str.append(to_string);
  222.       end;
  223.  
  224.    declaration_in(str: STRING) is
  225.       do
  226.          str.append(to_string);
  227.       end;
  228.  
  229.    pretty_print, declaration_pretty_print is
  230.       do
  231.          fmt.put_string(to_string);
  232.       end;
  233.  
  234.    short is
  235.       local
  236.          i: INTEGER;
  237.          c: CHARACTER;
  238.       do
  239.          short_print.hook("Bsfn");
  240.          from
  241.             i := 1;
  242.          until
  243.             i > to_string.count
  244.          loop
  245.             c := to_string.item(i);
  246.             if c = '_' then
  247.                short_print.hook_or("Usfn","_");
  248.             else
  249.                short_print.a_character(c);
  250.             end;
  251.             i := i + 1;
  252.          end;
  253.          short_print.hook("Asfn");
  254.       end;
  255.  
  256.    short_target is
  257.       do
  258.          short;
  259.          short_print.a_dot;
  260.       end;
  261.  
  262.    compile_target_to_jvm, compile_to_jvm is
  263.       do
  264.          eh.add_position(start_position);
  265.          fatal_error(fz_jvm_error);
  266.       end;
  267.  
  268.    jvm_branch_if_false: INTEGER is
  269.       do
  270.          compile_to_jvm;
  271.          Result := code_attribute.opcode_ifeq;
  272.       end;
  273.  
  274.    jvm_branch_if_true: INTEGER is
  275.       do
  276.          compile_to_jvm;
  277.          Result := code_attribute.opcode_ifne;
  278.       end;
  279.  
  280.    compile_to_jvm_into(dest: TYPE): INTEGER is
  281.       do
  282.          Result := standard_compile_to_jvm_into(dest);
  283.       end;
  284.  
  285.    jvm_assign is
  286.       local
  287.          space, idx: INTEGER;
  288.          rf2: like run_feature_2;
  289.          ca: like code_attribute;
  290.       do
  291.          rf2 := run_feature_2;
  292.          ca := code_attribute;
  293.          space := rf2.result_type.jvm_stack_space;
  294.          ca.opcode_aload_0;
  295.          if space = 1 then
  296.             ca.opcode_swap;
  297.          else
  298.             ca.opcode_dup_x2;
  299.             ca.opcode_pop;
  300.          end;
  301.          idx := constant_pool.idx_fieldref(rf2);
  302.          ca.opcode_putfield(idx,-(space + 1));
  303.       end;
  304.  
  305. feature {TYPE_BIT_2}
  306.  
  307.    run_feature(t: TYPE): RUN_FEATURE is
  308.          -- Look for the corresponding runnable feature in `t';
  309.       require
  310.          t.is_run_type
  311.       do
  312.          Result := t.run_class.get_rf_with(Current);
  313.       end;
  314.  
  315. feature {RUN_FEATURE,FEATURE_NAME}
  316.  
  317.    put_cpp_tag is
  318.       do
  319.       end;
  320.  
  321. end -- SIMPLE_FEATURE_NAME
  322.  
  323.