home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / type_ref_to_exp.e < prev    next >
Text File  |  1999-06-05  |  10KB  |  418 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_REF_TO_EXP
  17.  
  18. inherit TYPE;
  19.  
  20. creation {RUN_CLASS} make
  21.  
  22. feature
  23.  
  24.    run_class: RUN_CLASS;
  25.  
  26.    written_mark: STRING;
  27.  
  28. feature {NONE}
  29.  
  30.    expanded_type: TYPE;
  31.          -- The corresponding one.
  32.  
  33.    make(model: TYPE) is
  34.       require
  35.          model.is_expanded;
  36.          model.run_type = model
  37.       do
  38.          expanded_type := model;
  39.          tmp_string.copy("_ref_");
  40.          tmp_string.append(model.run_time_mark);
  41.          written_mark := string_aliaser.item(tmp_string);
  42.          run_class := small_eiffel.run_class(Current)
  43.          run_class.set_at_run_time;
  44.       ensure
  45.          run_class.at_run_time
  46.       end;
  47.  
  48. feature
  49.  
  50.    is_run_type: BOOLEAN is true;
  51.  
  52.    is_expanded: BOOLEAN is false;
  53.  
  54.    is_reference: BOOLEAN is true;
  55.  
  56.    is_none: BOOLEAN is false;
  57.  
  58.    is_any: BOOLEAN is false;
  59.  
  60.    is_basic_eiffel_expanded: BOOLEAN is false;
  61.  
  62.    is_user_expanded: BOOLEAN is false;
  63.  
  64.    is_dummy_expanded: BOOLEAN is false;
  65.  
  66.    need_gc_mark_function: BOOLEAN is true;
  67.  
  68.    need_c_struct: BOOLEAN is true;
  69.  
  70.    is_array: BOOLEAN is false;
  71.  
  72.    is_like_current: BOOLEAN is false;
  73.  
  74.    is_like_argument: BOOLEAN is false;
  75.  
  76.    is_like_feature: BOOLEAN is false;
  77.  
  78.    jvm_method_flags: INTEGER is 17;
  79.  
  80.    static_base_class_name: CLASS_NAME is
  81.       do
  82.          Result := expanded_type.static_base_class_name;
  83.       end;
  84.  
  85.    id: INTEGER is
  86.       do
  87.          Result := run_class.id;
  88.       end;
  89.  
  90.    used_as_reference is
  91.       do
  92.       end;
  93.  
  94.    to_reference is
  95.       do
  96.       end;
  97.  
  98.    start_position: POSITION is
  99.       do
  100.       end;
  101.  
  102.    is_generic: BOOLEAN is
  103.       do
  104.          Result := expanded_type.is_generic;
  105.       end;
  106.  
  107.    run_type: TYPE is
  108.       do
  109.          Result := Current;
  110.       end;
  111.  
  112.    generic_list: ARRAY[TYPE] is
  113.       do
  114.          Result := expanded_type.generic_list;
  115.       end;
  116.  
  117.    run_time_mark: STRING is
  118.       do
  119.          Result := written_mark;
  120.       end;
  121.  
  122.    base_class_name: CLASS_NAME is
  123.       do
  124.          Result := expanded_type.base_class_name;
  125.       end;
  126.  
  127.    to_runnable(ct: TYPE): like Current is
  128.       do
  129.          Result := Current;
  130.       end;
  131.  
  132.    is_a(other: TYPE): BOOLEAN is
  133.       do
  134.          if other.run_time_mark /= expanded_type.run_time_mark then
  135.             Result := expanded_type.is_a(other);
  136.          else
  137.             eh.add_type(Current,fz_inako);
  138.             eh.add_type(other,fz_dot);
  139.          end;
  140.       end;
  141.  
  142.    has_creation(fn: FEATURE_NAME): BOOLEAN is
  143.       do
  144.       end;
  145.  
  146.    smallest_ancestor(other: TYPE): TYPE is
  147.       do
  148.          fatal_error("TYPE_REF_TO_EXP Not Yet Implemented #1");
  149.       end;
  150.  
  151.    just_before_gc_mark_in(str: STRING) is
  152.       do
  153.          standard_just_before_gc_mark_in(str);
  154.       end;
  155.  
  156.    gc_info_in(str: STRING) is
  157.       do
  158.          standard_gc_info_in(str);
  159.       end;
  160.  
  161.    gc_define1 is
  162.       do
  163.          standard_gc_define1;
  164.       end;
  165.  
  166.    gc_define2 is
  167.       do
  168.          standard_gc_define2;
  169.       end;
  170.  
  171.    space_for_variable: INTEGER is
  172.       do
  173.          Result := space_for_pointer;
  174.       end;
  175.  
  176.    expanded_initializer: RUN_FEATURE_3 is
  177.       do
  178.       end;
  179.  
  180.    c_type_for_argument_in(str: STRING) is
  181.       do
  182.          str.append(fz_t0_star);
  183.       end;
  184.  
  185.    c_type_for_target_in(str: STRING) is
  186.       do
  187.          str.extend('T');
  188.          id.append_in(str);
  189.          str.extend('*');
  190.       end;
  191.  
  192.    c_type_for_result_in(str: STRING) is
  193.       do
  194.          str.append(fz_t0_star);
  195.       end;
  196.  
  197.    c_header_pass1 is
  198.       do
  199.          standard_c_typedef;
  200.       end;
  201.  
  202.    c_header_pass2 is
  203.       do
  204.       end;
  205.  
  206.    c_header_pass3 is
  207.       do
  208.       end;
  209.  
  210.    c_header_pass4 is
  211.       local
  212.          rc: RUN_CLASS;
  213.          mem_id: INTEGER;
  214.       do
  215.          expanded_type.run_class.c_header_pass4;
  216.          rc := run_class;
  217.          mem_id := rc.id;
  218.          -- C struct :
  219.          tmp_string.copy(fz_struct);
  220.          tmp_string.extend('S');
  221.          mem_id.append_in(tmp_string);
  222.          tmp_string.append("{int id;T");
  223.          expanded_type.id.append_in(tmp_string);
  224.          tmp_string.append(" _item;};%N");
  225.          cpp.put_string(tmp_string);
  226.          -- Model :
  227.          tmp_string.clear;
  228.          tmp_string.extend('T');
  229.          mem_id.append_in(tmp_string);
  230.          tmp_string.extend(' ');
  231.          tmp_string.extend('M');
  232.          mem_id.append_in(tmp_string);
  233.          cpp.put_extern7(tmp_string);
  234.          cpp.swap_on_c;
  235.          tmp_string.clear;
  236.          tmp_string.extend('{');
  237.          mem_id.append_in(tmp_string);
  238.          tmp_string.extend(',');
  239.          expanded_type.run_class.c_object_model_in(tmp_string);
  240.          tmp_string.extend('}');
  241.          tmp_string.append(fz_00);
  242.          cpp.put_string(tmp_string);
  243.          cpp.swap_on_h;
  244.          -- Print function :
  245.          if run_control.no_check then
  246.             header.copy("void se_prinT");
  247.             mem_id.append_in(header);
  248.             header.append("(T");
  249.             mem_id.append_in(header);
  250.             header.append("**o)");
  251.             body.copy("if(*o==NULL){%N%
  252.                       %printf(%"Void%");%Nreturn;%N}%N%
  253.                       %printf(%"");
  254.             body.append(written_mark);
  255.             body.append("%");%N%
  256.                         %printf(%"#%%p%",*o);%N%
  257.                         %printf(%"[%");%N%
  258.                         %printf(%"\n\t%");%N%
  259.                         %printf(%"item = %");%N%
  260.                         %se_prinT");
  261.             expanded_type.id.append_in(body);
  262.             body.append("((void*)(&((*o)->_item)));%N%
  263.                         %printf(%"\n\t]%");");
  264.             cpp.put_c_function(header,body);
  265.          end;
  266.       end;
  267.  
  268.    c_initialize is
  269.       do
  270.          cpp.put_string(fz_null);
  271.       end;
  272.  
  273.    c_initialize_in(str: STRING) is
  274.       do
  275.          str.append(fz_null);
  276.       end;
  277.  
  278. feature
  279.  
  280.    jvm_descriptor_in(str: STRING) is
  281.       do
  282.          str.append(jvm_root_descriptor);
  283.       end;
  284.  
  285.    jvm_target_descriptor_in(str: STRING) is
  286.       do
  287.       end;
  288.  
  289.    jvm_return_code is
  290.       do
  291.          code_attribute.opcode_areturn;
  292.       end;
  293.  
  294.    jvm_check_class_invariant is
  295.       do
  296.          standard_jvm_check_class_invariant;
  297.       end;
  298.  
  299.    jvm_push_local(offset: INTEGER) is
  300.       do
  301.          code_attribute.opcode_aload(offset);
  302.       end;
  303.  
  304.    jvm_push_default: INTEGER is
  305.       do
  306.          Result := 1;
  307.          code_attribute.opcode_aconst_null;
  308.       end;
  309.  
  310.    jvm_write_local(offset: INTEGER) is
  311.       do
  312.          code_attribute.opcode_astore(offset);
  313.       end;
  314.  
  315.    jvm_xnewarray is
  316.       local
  317.          idx: INTEGER;
  318.       do
  319.          idx := constant_pool.idx_jvm_root_class;
  320.          code_attribute.opcode_anewarray(idx);
  321.       end;
  322.  
  323.    jvm_xastore is
  324.       do
  325.          code_attribute.opcode_aastore;
  326.       end;
  327.  
  328.    jvm_xaload is
  329.       do
  330.          code_attribute.opcode_aaload;
  331.       end;
  332.  
  333.    jvm_if_x_eq: INTEGER is
  334.       do
  335.          Result := code_attribute.opcode_if_acmpeq;
  336.       end;
  337.  
  338.    jvm_if_x_ne: INTEGER is
  339.       do
  340.          Result := code_attribute.opcode_if_acmpne;
  341.       end;
  342.  
  343.    jvm_to_reference is
  344.       do
  345.       end;
  346.  
  347.    jvm_expanded_from_reference(other: TYPE): INTEGER is
  348.       do
  349.          check
  350.             false
  351.          end;
  352.       end;
  353.  
  354.    jvm_convert_to(destination: TYPE): INTEGER is
  355.       do
  356.          check
  357.             destination.is_reference;
  358.          end;
  359.          Result := 1;
  360.       end;
  361.  
  362.    jvm_standard_is_equal is
  363.       local
  364.          ca: like code_attribute;
  365.          cp: like constant_pool;
  366.          idx: INTEGER;
  367.       do
  368.          ca := code_attribute;
  369.          cp := constant_pool;
  370.          idx := jvm_item_field_idx;
  371.          run_class.opcode_checkcast;
  372.          ca.opcode_getfield(idx,0);
  373.          ca.opcode_swap;
  374.          run_class.opcode_checkcast;
  375.          ca.opcode_getfield(idx,0);
  376.          expanded_type.jvm_standard_is_equal;
  377.       end;
  378.  
  379. feature {NONE}
  380.  
  381.    jvm_item_field_idx: INTEGER is
  382.       local
  383.          c, n, t: INTEGER;
  384.          cp: like constant_pool;
  385.       do
  386.          cp := constant_pool;
  387.          c := run_class.jvm_constant_pool_index;
  388.          n := cp.idx_utf8(as_item);
  389.          tmp_string.clear;
  390.          expanded_type.jvm_descriptor_in(tmp_string);
  391.          t := cp.idx_utf8(tmp_string);
  392.          Result := cp.idx_fieldref5(c,n,t);
  393.       end;
  394.  
  395. feature
  396.  
  397.    short_hook is
  398.       do
  399.          expanded_type.short_hook;
  400.       end;
  401.  
  402. feature {RUN_CLASS}
  403.  
  404.    jvm_prepare_item_field is
  405.       local
  406.          name_idx, descriptor: INTEGER;
  407.          cp: like constant_pool;
  408.       do
  409.          cp := constant_pool;
  410.          name_idx := cp.idx_utf8(as_item);
  411.          tmp_string.clear;
  412.          expanded_type.jvm_descriptor_in(tmp_string);
  413.          descriptor := cp.idx_utf8(tmp_string);
  414.          field_info.add(1,name_idx,descriptor);
  415.       end;
  416.  
  417. end -- TYPE_REF_TO_EXP
  418.