home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / type_array.e < prev    next >
Text File  |  1999-06-05  |  11KB  |  495 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_ARRAY
  17.    --
  18.    -- For ARRAY declaration :    ARRAY[INTEGER];
  19.    --                            ARRAY[POINT];
  20.    --                            ARRAY[G];
  21.    --                            ARRAY[ARRAY[ANY]];
  22.    --
  23.    -- Note : can be implicit when used for the type of manifest
  24.    --        arrays.
  25.    --
  26.  
  27. inherit TYPE;
  28.  
  29. creation make, with, final
  30.  
  31. feature
  32.  
  33.    base_class_name: CLASS_NAME;
  34.          -- Is always "ARRAY" but with the good `start_position'.
  35.  
  36.    generic_list: ARRAY[TYPE];
  37.          -- With exactely one element.
  38.  
  39.    written_mark: STRING;
  40.  
  41. feature {NONE}
  42.  
  43.    run_type_memory: like Current;
  44.  
  45. feature {NONE}
  46.  
  47.    make(sp: like start_position; of_what: TYPE) is
  48.       require
  49.          sp /= Void;
  50.          of_what /= Void
  51.       do
  52.          !!base_class_name.make(as_array,sp);
  53.          generic_list := <<of_what>>;
  54.          tmp_written_mark.copy(as_array);
  55.          tmp_written_mark.extend('[');
  56.          tmp_written_mark.append(of_what.written_mark);
  57.          tmp_written_mark.extend(']');
  58.          written_mark := string_aliaser.item(tmp_written_mark);
  59.       ensure
  60.          start_position = sp;
  61.          base_class_name.to_string = as_array;
  62.          array_of = of_what
  63.       end;
  64.  
  65.    with(bcn: like base_class_name; wm: STRING; of_what: TYPE) is
  66.       require
  67.          bcn.to_string = as_array;
  68.          wm /= Void;
  69.          of_what.is_run_type
  70.       do
  71.          base_class_name := bcn;
  72.          generic_list := <<of_what>>;
  73.          written_mark := wm;
  74.          !!run_type_memory.final(bcn,of_what.run_type);
  75.       ensure
  76.          is_run_type;
  77.          written_mark = wm
  78.       end;
  79.  
  80.    final(bcn: like base_class_name; of_what: TYPE) is
  81.       require
  82.          bcn.to_string = as_array;
  83.          of_what.run_type = of_what
  84.       do
  85.          base_class_name := bcn;
  86.          generic_list := <<of_what>>;
  87.          tmp_written_mark.copy(as_array);
  88.          tmp_written_mark.extend('[');
  89.          tmp_written_mark.append(of_what.written_mark);
  90.          tmp_written_mark.extend(']');
  91.          written_mark := string_aliaser.item(tmp_written_mark);
  92.          run_type_memory := Current;
  93.       ensure
  94.          run_type = Current;
  95.          written_mark = run_time_mark
  96.       end;
  97.  
  98. feature
  99.  
  100.    is_generic: BOOLEAN is true;
  101.  
  102.    is_array: BOOLEAN is true;
  103.  
  104.    is_none: BOOLEAN is false;
  105.  
  106.    is_any: BOOLEAN is false;
  107.  
  108.    is_expanded: BOOLEAN is false;
  109.  
  110.    is_basic_eiffel_expanded: BOOLEAN is false;
  111.  
  112.    is_reference: BOOLEAN is true;
  113.  
  114.    is_dummy_expanded: BOOLEAN is false;
  115.  
  116.    is_user_expanded: BOOLEAN is false;
  117.  
  118.    is_like_current: BOOLEAN is false;
  119.  
  120.    is_like_argument: BOOLEAN is false;
  121.  
  122.    is_like_feature: BOOLEAN is false;
  123.  
  124.    jvm_method_flags: INTEGER is 17;
  125.  
  126.    need_c_struct: BOOLEAN is true;
  127.  
  128. feature
  129.  
  130.    static_base_class_name: CLASS_NAME is
  131.       do
  132.          Result := base_class_name;
  133.       end;
  134.  
  135.    is_run_type: BOOLEAN is
  136.       local
  137.          et: TYPE;
  138.       do
  139.          if run_type_memory /= Void then
  140.             Result := true;
  141.          else
  142.             et := array_of;
  143.             if et.is_run_type and then et.run_type = et then
  144.                run_type_memory := Current;
  145.                Result := true;
  146.             end;
  147.          end;
  148.       end;
  149.  
  150.    run_type: TYPE is
  151.       do
  152.          if is_run_type then
  153.             Result := run_type_memory;
  154.          end;
  155.       end;
  156.  
  157.    space_for_variable: INTEGER is
  158.       do
  159.          Result := space_for_pointer;
  160.       end;
  161.  
  162.    space_for_object: INTEGER is
  163.       do
  164.          Result := standard_space_for_object;
  165.       end;
  166.  
  167.    run_class: RUN_CLASS is
  168.       do
  169.          if is_run_type then
  170.             Result := small_eiffel.run_class(run_type);
  171.          end;
  172.       end;
  173.  
  174.    c_header_pass1 is
  175.       do
  176.          standard_c_typedef;
  177.       end;
  178.  
  179.    c_header_pass2 is
  180.       do
  181.       end;
  182.  
  183.    c_header_pass3 is
  184.       do
  185.       end;
  186.  
  187.    c_header_pass4 is
  188.       do
  189.          standard_c_struct;
  190.          standard_c_object_model;
  191.          standard_c_print_function;
  192.       end;
  193.  
  194.    c_initialize is
  195.       do
  196.          cpp.put_string(fz_null);
  197.       end;
  198.  
  199.    c_initialize_in(str: STRING) is
  200.       do
  201.          str.append(fz_null);
  202.       end;
  203.  
  204.    array_of: TYPE is
  205.       do
  206.          Result := generic_list.first;
  207.       end;
  208.  
  209.    expanded_initializer: RUN_FEATURE_3 is
  210.       do
  211.       end;
  212.  
  213.    c_type_for_argument_in(str: STRING) is
  214.       do
  215.          str.append(fz_t0_star);
  216.       end;
  217.  
  218.    c_type_for_target_in(str: STRING) is
  219.       do
  220.          str.extend('T');
  221.          id.append_in(str);
  222.          str.extend('*');
  223.       end;
  224.  
  225.    c_type_for_result_in(str: STRING) is
  226.       do
  227.          str.append(fz_t0_star);
  228.       end;
  229.  
  230.    has_creation(fn: FEATURE_NAME): BOOLEAN is
  231.       do
  232.          if Current = run_type then
  233.             Result := base_class.has_creation(fn);
  234.          else
  235.             Result := run_type.has_creation(fn);
  236.          end;
  237.       end;
  238.  
  239.    used_as_reference is
  240.       do
  241.       end;
  242.  
  243.    to_reference is
  244.       do
  245.       end;
  246.  
  247.    jvm_descriptor_in(str: STRING) is
  248.       do
  249.          str.append(jvm_root_descriptor);
  250.       end;
  251.  
  252.    jvm_target_descriptor_in(str: STRING) is
  253.       do
  254.       end;
  255.  
  256.    jvm_return_code is
  257.       do
  258.          code_attribute.opcode_areturn;
  259.       end;
  260.  
  261.    jvm_check_class_invariant is
  262.       do
  263.          standard_jvm_check_class_invariant;
  264.       end;
  265.  
  266.    jvm_push_local(offset: INTEGER) is
  267.       do
  268.          code_attribute.opcode_aload(offset);
  269.       end;
  270.  
  271.    jvm_push_default: INTEGER is
  272.       do
  273.          code_attribute.opcode_aconst_null;
  274.          Result := 1;
  275.       end;
  276.  
  277.    jvm_write_local(offset: INTEGER) is
  278.       do
  279.          code_attribute.opcode_astore(offset);
  280.       end;
  281.  
  282.    jvm_xnewarray is
  283.       local
  284.          idx: INTEGER;
  285.       do
  286.          idx := constant_pool.idx_jvm_root_class;
  287.          code_attribute.opcode_anewarray(idx);
  288.       end;
  289.  
  290.    jvm_xastore is
  291.       do
  292.          code_attribute.opcode_aastore;
  293.       end;
  294.  
  295.    jvm_xaload is
  296.       do
  297.          code_attribute.opcode_aaload;
  298.       end;
  299.  
  300.    jvm_if_x_eq: INTEGER is
  301.       do
  302.          Result := code_attribute.opcode_if_acmpeq;
  303.       end;
  304.  
  305.    jvm_if_x_ne: INTEGER is
  306.       do
  307.          Result := code_attribute.opcode_if_acmpne;
  308.       end;
  309.  
  310.    jvm_to_reference is
  311.       do
  312.       end;
  313.  
  314.    jvm_expanded_from_reference(other: TYPE): INTEGER is
  315.       do
  316.          check
  317.             false
  318.          end;
  319.       end;
  320.  
  321.    jvm_convert_to(destination: TYPE): INTEGER is
  322.       do
  323.          Result := 1;
  324.       end;
  325.  
  326.    jvm_standard_is_equal is
  327.       local
  328.          rc: RUN_CLASS;
  329.          wa: ARRAY[RUN_FEATURE_2];
  330.       do
  331.          rc := run_class;
  332.          wa := rc.writable_attributes;
  333.          jvm.std_is_equal(rc,wa);
  334.       end;
  335.  
  336.    start_position: POSITION is
  337.       do
  338.          Result := base_class_name.start_position;
  339.       end;
  340.  
  341.    run_time_mark: STRING is
  342.       do
  343.          if is_run_type then
  344.             Result := run_type.written_mark;
  345.          end;
  346.       end;
  347.  
  348.    smallest_ancestor(other: TYPE): TYPE is
  349.       local
  350.          rto, array_of1, array_of2, array_of3: TYPE;
  351.       do
  352.          rto := other.run_type;
  353.          if rto.is_array then
  354.             array_of1 := array_of.run_type;
  355.             array_of2 := rto.generic_list.first;
  356.             array_of3 := array_of1.smallest_ancestor(array_of2);
  357.             if array_of3 = array_of1 then
  358.                Result := Current;
  359.             elseif array_of3 = array_of2 then
  360.                Result := other;
  361.             else
  362.                !TYPE_ARRAY!Result.make(Void,array_of3);
  363.             end;
  364.          else
  365.             Result := rto.smallest_ancestor(Current);
  366.          end;
  367.       end;
  368.  
  369.    is_a(other: TYPE): BOOLEAN is
  370.       do
  371.          if run_class = other.run_class then
  372.             Result := true;
  373.          elseif other.is_array then
  374.             Result := array_of.is_a(other.generic_list.first);
  375.             if not Result then
  376.                eh.extend(' ');
  377.             end;
  378.          elseif base_class.is_subclass_of(other.base_class) then
  379.             if other.is_generic then
  380.                Result := base_class.is_a_vncg(Current,other);
  381.             else
  382.                Result := true;
  383.             end;
  384.          end;
  385.          if not Result then
  386.             eh.add_type(Current,fz_inako);
  387.             eh.add_type(other,fz_dot);
  388.          end;
  389.       end;
  390.  
  391.    to_runnable(ct: TYPE): like Current is
  392.       local
  393.          et1, et2: TYPE;
  394.       do
  395.          et1 := array_of;
  396.          et2 := et1.to_runnable(ct);
  397.          if et2 = Void then
  398.             if et2 /= Void then
  399.                eh.add_position(et2.start_position);
  400.             end;
  401.             eh.add_position(et1.start_position);
  402.             fatal_error(fz_bga);
  403.          end;
  404.          if run_type_memory = Void then
  405.             Result := Current;
  406.             if et2.run_type = et1 then
  407.                run_type_memory := Current;
  408.             else
  409.                !!run_type_memory.final(base_class_name,et2.run_type);
  410.             end;
  411.          elseif et2 = et1 then
  412.             Result := Current;
  413.          else
  414.             !!Result.with(base_class_name,written_mark,et2);
  415.          end;
  416.       end;
  417.  
  418.    id: INTEGER is
  419.       do
  420.          Result := run_class.id;
  421.       end;
  422.  
  423. feature {RUN_CLASS,TYPE}
  424.  
  425.    need_gc_mark_function: BOOLEAN is true;
  426.  
  427.    just_before_gc_mark_in(str: STRING) is
  428.       do
  429.          standard_just_before_gc_mark_in(str);
  430.       end;
  431.  
  432.    gc_info_in(str: STRING) is
  433.       do
  434.          standard_gc_info_in(str);
  435.       end;
  436.  
  437.    gc_define1 is
  438.       do
  439.          standard_gc_define1;
  440.       end;
  441.  
  442.    gc_define2 is
  443.       do
  444.          standard_gc_define2;
  445.       end;
  446.  
  447. feature {MANIFEST_ARRAY,E_STRIP}
  448.  
  449.    load_basic_features is
  450.          -- Force some basic feature to be loaded.
  451.       require
  452.          run_type = Current
  453.       local
  454.          et: TYPE;
  455.          rf: RUN_FEATURE;
  456.          rc: RUN_CLASS;
  457.       do
  458.          et := array_of;
  459.          if et.is_expanded then
  460.             et.run_class.set_at_run_time;
  461.          end;
  462.          rc := run_class;
  463.          rf := rc.get_feature_with(as_capacity);
  464.          rf := rc.get_feature_with(as_lower);
  465.          rf := rc.get_feature_with(as_upper);
  466.          rf := rc.get_feature_with(as_storage);
  467.       end;
  468.  
  469. feature {NONE}
  470.  
  471.    tmp_written_mark: STRING is
  472.       once
  473.          !!Result.make(128);
  474.       end;
  475.  
  476. feature {TYPE}
  477.  
  478.    frozen short_hook is
  479.       do
  480.          short_print.a_class_name(base_class_name);
  481.          short_print.hook_or("open_sb","[");
  482.          generic_list.first.short_hook;
  483.          short_print.hook_or("close_sb","]");
  484.       end;
  485.  
  486. invariant
  487.  
  488.    generic_list.count = 1;
  489.  
  490.    generic_list.lower = 1;
  491.  
  492. end -- TYPE_ARRAY
  493.  
  494.  
  495.