home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / type_any.e < prev    next >
Text File  |  1999-06-05  |  7KB  |  354 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_ANY
  17.    --
  18.    -- Handling of the type ANY.
  19.    --
  20.  
  21. inherit TYPE;
  22.  
  23. creation make
  24.  
  25. feature
  26.  
  27.    base_class_name: CLASS_NAME;
  28.  
  29.    is_any: BOOLEAN is true;
  30.  
  31.    is_none: BOOLEAN is false;
  32.  
  33.    is_expanded: BOOLEAN is false;
  34.  
  35.    is_basic_eiffel_expanded: BOOLEAN is false;
  36.  
  37.    is_reference: BOOLEAN is true;
  38.  
  39.    is_dummy_expanded: BOOLEAN is false;
  40.  
  41.    is_user_expanded: BOOLEAN is false;
  42.  
  43.    is_run_type: BOOLEAN is true;
  44.  
  45.    is_generic: BOOLEAN is false;
  46.  
  47.    is_array: BOOLEAN is false;
  48.  
  49.    is_like_current: BOOLEAN is false;
  50.  
  51.    is_like_argument: BOOLEAN is false;
  52.  
  53.    is_like_feature: BOOLEAN is false;
  54.  
  55.    jvm_method_flags: INTEGER is 17;
  56.  
  57.    static_base_class_name: CLASS_NAME is
  58.       do
  59.          Result := base_class_name;
  60.       end;
  61.  
  62.    space_for_variable: INTEGER is
  63.       do
  64.          Result := space_for_pointer;
  65.       end;
  66.  
  67.    space_for_object: INTEGER is
  68.       do
  69.          Result := standard_space_for_object;
  70.       end;
  71.  
  72.    run_class: RUN_CLASS is
  73.       do
  74.          Result := small_eiffel.run_class(Current);
  75.       end;
  76.  
  77.    id: INTEGER is
  78.       do
  79.          Result := base_class.id;
  80.       end;
  81.  
  82.    run_type: TYPE is
  83.       do
  84.          Result := Current;
  85.       end;
  86.  
  87.    generic_list: ARRAY[TYPE] is
  88.       do
  89.          fatal_error_generic_list;
  90.       end;
  91.  
  92.    expanded_initializer: RUN_FEATURE_3 is
  93.       do
  94.       end;
  95.  
  96.    c_header_pass1 is
  97.       do
  98.          standard_c_typedef;
  99.       end;
  100.  
  101.    c_header_pass2 is
  102.       do
  103.       end;
  104.  
  105.    c_header_pass3 is
  106.       do
  107.       end;
  108.  
  109.    c_header_pass4 is
  110.       do
  111.          if need_c_struct then
  112.             standard_c_struct;
  113.          end;
  114.          standard_c_object_model;
  115.          standard_c_print_function;
  116.       end;
  117.  
  118.    c_type_for_argument_in(str: STRING) is
  119.       do
  120.          str.append(fz_t0_star);
  121.       end;
  122.  
  123.    c_type_for_target_in(str: STRING) is
  124.       do
  125.          str.extend('T');
  126.          id.append_in(str);
  127.          str.extend('*');
  128.       end;
  129.  
  130.    c_type_for_result_in(str: STRING) is
  131.       do
  132.          str.append(fz_t0_star);
  133.       end;
  134.  
  135.    need_c_struct: BOOLEAN is
  136.       do
  137.          if run_class.is_tagged then
  138.             Result := true;
  139.          else
  140.             Result := run_class.writable_attributes /= Void;
  141.          end;
  142.       end;
  143.  
  144.    c_initialize is
  145.       do
  146.          cpp.put_string(fz_null);
  147.       end;
  148.  
  149.    c_initialize_in(str: STRING) is
  150.       do
  151.          str.append(fz_null);
  152.       end;
  153.  
  154.    has_creation(fn: FEATURE_NAME): BOOLEAN is
  155.       do
  156.          eh.add_position(fn.start_position);
  157.          error(start_position,"No creation for ANY.");
  158.       end;
  159.  
  160.    start_position: POSITION is
  161.       do
  162.          Result := base_class_name.start_position;
  163.       end;
  164.  
  165.    to_runnable(ct: TYPE): like Current is
  166.       do
  167.          Result := Current;
  168.          check_type;
  169.       end;
  170.  
  171.    run_time_mark, written_mark: STRING is
  172.       do
  173.          Result := as_any;
  174.       end;
  175.  
  176.    smallest_ancestor(other: TYPE): TYPE is
  177.       do
  178.          Result := Current;
  179.       end;
  180.  
  181.    used_as_reference is
  182.       do
  183.       end;
  184.  
  185.    to_reference is
  186.       do
  187.       end;
  188.  
  189.    jvm_descriptor_in(str: STRING) is
  190.       do
  191.          str.append(jvm_root_descriptor);
  192.       end;
  193.  
  194.    jvm_target_descriptor_in(str: STRING) is
  195.       do
  196.       end;
  197.  
  198.    jvm_return_code is
  199.       do
  200.          code_attribute.opcode_areturn;
  201.       end;
  202.  
  203.    jvm_push_local(offset: INTEGER) is
  204.       do
  205.          code_attribute.opcode_aload(offset);
  206.       end;
  207.  
  208.    jvm_check_class_invariant is
  209.       do
  210.       end;
  211.  
  212.    jvm_push_default: INTEGER is
  213.       do
  214.          code_attribute.opcode_aconst_null;
  215.          Result := 1;
  216.       end;
  217.  
  218.    jvm_write_local(offset: INTEGER) is
  219.       do
  220.          code_attribute.opcode_astore(offset);
  221.       end;
  222.  
  223.    jvm_xnewarray is
  224.       local
  225.          idx: INTEGER;
  226.       do
  227.          idx := constant_pool.idx_jvm_root_class;
  228.          code_attribute.opcode_anewarray(idx);
  229.       end;
  230.  
  231.    jvm_xastore is
  232.       do
  233.          code_attribute.opcode_aastore;
  234.       end;
  235.  
  236.    jvm_xaload is
  237.       do
  238.          code_attribute.opcode_aaload;
  239.       end;
  240.  
  241.    jvm_if_x_eq: INTEGER is
  242.       do
  243.          Result := code_attribute.opcode_if_acmpeq;
  244.       end;
  245.  
  246.    jvm_if_x_ne: INTEGER is
  247.       do
  248.          Result := code_attribute.opcode_if_acmpne;
  249.       end;
  250.  
  251.    jvm_to_reference is
  252.       do
  253.       end;
  254.  
  255.    jvm_expanded_from_reference(other: TYPE): INTEGER is
  256.       do
  257.          check
  258.             false
  259.          end;
  260.       end;
  261.  
  262.    jvm_convert_to(destination: TYPE): INTEGER is
  263.       do
  264.          if destination.is_reference then
  265.             Result := 1;
  266.          else
  267.             Result := destination.jvm_expanded_from_reference(Current)
  268.          end;
  269.       end;
  270.  
  271.    jvm_standard_is_equal is
  272.       local
  273.          rc: RUN_CLASS;
  274.          wa: ARRAY[RUN_FEATURE_2];
  275.       do
  276.          rc := run_class;
  277.          wa := rc.writable_attributes;
  278.          jvm.std_is_equal(rc,wa);
  279.       end;
  280.  
  281.    is_a(other: TYPE): BOOLEAN is
  282.       do
  283.          if other.is_any then
  284.             Result := true;
  285.          elseif other.is_none then
  286.          else
  287.             Result := base_class.is_subclass_of(other.base_class);
  288.          end;
  289.          if not Result then
  290.             eh.add_type(Current,fz_inako);
  291.             eh.add_type(other,fz_dot);
  292.          end;
  293.       end;
  294.  
  295. feature {RUN_CLASS,TYPE}
  296.  
  297.    need_gc_mark_function: BOOLEAN is true;
  298.  
  299.    just_before_gc_mark_in(str: STRING) is
  300.       do
  301.          standard_just_before_gc_mark_in(str);
  302.       end;
  303.  
  304.    gc_info_in(str: STRING) is
  305.       do
  306.          standard_gc_info_in(str);
  307.       end;
  308.  
  309.    gc_define1 is
  310.       do
  311.          standard_gc_define1;
  312.       end;
  313.  
  314.    gc_define2 is
  315.       do
  316.          standard_gc_define2;
  317.       end;
  318.  
  319. feature {TYPE}
  320.  
  321.    frozen short_hook is
  322.       do
  323.          short_print.a_class_name(base_class_name);
  324.       end;
  325.  
  326. feature {NONE}
  327.  
  328.    check_type is
  329.       -- Do some checking for type ANY to be runnable.
  330.       local
  331.          bc: BASE_CLASS;
  332.          rc: RUN_CLASS;
  333.       once
  334.          bc := base_class;
  335.          if nb_errors = 0 then
  336.             rc := run_class;
  337.          end;
  338.          if nb_errors = 0 then
  339.             if bc.is_expanded then
  340.                error(start_position,"ANY must not be expanded.");
  341.             end;
  342.          end;
  343.       end;
  344.  
  345.    make(sp: like start_position) is
  346.       do
  347.          !!base_class_name.make(as_any,sp);
  348.       ensure
  349.          start_position = sp
  350.       end;
  351.  
  352. end -- TYPE_ANY
  353.  
  354.