home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / type_formal_generic.e < prev    next >
Text File  |  1999-06-05  |  11KB  |  520 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_FORMAL_GENERIC
  17.  
  18. inherit
  19.    TYPE
  20.       redefine is_formal_generic, is_boolean,
  21.          is_character, is_integer, is_real, is_double, is_string,
  22.          is_array, is_bit, is_pointer,
  23.          to_reference, to_expanded
  24.       end;
  25.  
  26. creation make
  27.  
  28. feature
  29.  
  30.    formal_name: CLASS_NAME;
  31.          -- Formal argument name.
  32.  
  33.    rank: INTEGER;
  34.          -- Rank in the corresponding generic list.
  35.  
  36.    run_type: TYPE;
  37.          -- Not Void when real type is known.
  38.  
  39. feature {NONE}
  40.  
  41.    make(fn: like formal_name; r: INTEGER) is
  42.       require
  43.          fn /= Void;
  44.          r > 0
  45.       do
  46.          rank := r;
  47.          formal_name := fn;
  48.       ensure
  49.          formal_name = fn;
  50.          rank = r
  51.       end;
  52.  
  53. feature
  54.  
  55.    is_formal_generic: BOOLEAN is true;
  56.  
  57.    is_like_current: BOOLEAN is false;
  58.  
  59.    is_like_argument: BOOLEAN is false;
  60.  
  61.    is_like_feature: BOOLEAN is false;
  62.  
  63.    static_base_class_name: CLASS_NAME is
  64.       local
  65.          t: TYPE;
  66.       do
  67.          t := constraint;
  68.          if t /= Void then
  69.             Result := t.static_base_class_name;
  70.          else
  71.             -- *** eh.append("TYPE_FORMAL_GENERIC.static_base_class_name NYI");
  72.             -- *** eh.print_as_warning;
  73.          end;
  74.       end;
  75.  
  76.    run_class: RUN_CLASS is
  77.       do
  78.          Result := small_eiffel.run_class(run_type);
  79.       end;
  80.  
  81.    space_for_variable: INTEGER is
  82.       do
  83.          Result := run_type.space_for_variable;
  84.       end;
  85.  
  86.    space_for_object: INTEGER is
  87.       do
  88.          Result := run_type.space_for_object;
  89.       end;
  90.  
  91.    is_boolean: BOOLEAN is
  92.       do
  93.          Result := run_type.is_boolean;
  94.       end;
  95.  
  96.    is_character: BOOLEAN is
  97.       do
  98.          Result := run_type.is_character;
  99.       end;
  100.  
  101.    is_integer: BOOLEAN is
  102.       do
  103.          Result := run_type.is_integer;
  104.       end;
  105.  
  106.    is_real: BOOLEAN is
  107.       do
  108.          Result := run_type.is_real;
  109.       end;
  110.  
  111.    is_double: BOOLEAN is
  112.       do
  113.          Result := run_type.is_double;
  114.       end;
  115.  
  116.    is_string: BOOLEAN is
  117.       do
  118.          Result := run_type.is_string;
  119.       end;
  120.  
  121.    is_array: BOOLEAN is
  122.       do
  123.          Result := run_type.is_array;
  124.       end;
  125.  
  126.    is_bit: BOOLEAN is
  127.       do
  128.          Result := run_type.is_bit;
  129.       end;
  130.  
  131.    is_any: BOOLEAN is
  132.       do
  133.          Result := run_type.is_any;
  134.       end;
  135.  
  136.    is_none: BOOLEAN is
  137.       do
  138.          Result := run_type.is_none;
  139.       end;
  140.  
  141.    is_pointer: BOOLEAN is
  142.       do
  143.          Result := run_type.is_pointer;
  144.       end;
  145.  
  146.    is_reference: BOOLEAN is
  147.       do
  148.          Result := run_type.is_reference;
  149.       end;
  150.  
  151.    is_expanded: BOOLEAN is
  152.       do
  153.          Result := run_type.is_expanded;
  154.       end;
  155.  
  156.    is_basic_eiffel_expanded: BOOLEAN is
  157.       do
  158.          Result := run_type.is_basic_eiffel_expanded;
  159.       end;
  160.  
  161.    is_dummy_expanded: BOOLEAN is
  162.       do
  163.          Result := run_type.is_dummy_expanded;
  164.       end;
  165.  
  166.    is_user_expanded: BOOLEAN is
  167.       do
  168.          Result := run_type.is_user_expanded;
  169.       end;
  170.  
  171.    is_generic: BOOLEAN is
  172.       do
  173.          Result := run_type.is_generic;
  174.       end;
  175.  
  176.    generic_list: ARRAY[TYPE] is
  177.       do
  178.          if is_generic then
  179.             Result := run_type.generic_list;
  180.          else
  181.             fatal_error_generic_list;
  182.          end;
  183.       end;
  184.  
  185.    to_reference is
  186.       do
  187.          run_type.to_reference;
  188.       end;
  189.  
  190.    to_expanded is
  191.       do
  192.          run_type.to_expanded;
  193.       end;
  194.  
  195.    c_header_pass1 is
  196.       do
  197.          run_type.c_header_pass1;
  198.       end;
  199.  
  200.    c_header_pass2 is
  201.       do
  202.          run_type.c_header_pass2;
  203.       end;
  204.  
  205.    c_header_pass3 is
  206.       do
  207.          run_type.c_header_pass3;
  208.       end;
  209.  
  210.    c_header_pass4 is
  211.       do
  212.          run_type.c_header_pass4;
  213.       end;
  214.  
  215.    c_initialize is
  216.       do
  217.          run_type.c_initialize;
  218.       end;
  219.  
  220.    c_initialize_in(str: STRING) is
  221.       do
  222.          run_type.c_initialize_in(str);
  223.       end;
  224.  
  225.    expanded_initializer: RUN_FEATURE_3 is
  226.       do
  227.          Result := run_type.expanded_initializer;
  228.       end;
  229.  
  230.    id: INTEGER is
  231.       do
  232.          Result := run_class.id;
  233.       end;
  234.  
  235.    has_creation(fn: FEATURE_NAME): BOOLEAN is
  236.       do
  237.          if Current = run_type then
  238.             Result := base_class.has_creation(fn);
  239.          else
  240.             Result := run_type.has_creation(fn);
  241.          end;
  242.       end;
  243.  
  244.    base_class_name: CLASS_NAME is
  245.       do
  246.          Result := run_type.base_class_name;
  247.       end;
  248.  
  249.    start_position: POSITION is
  250.       do
  251.          Result := formal_name.start_position;
  252.       end;
  253.  
  254.    c_type_for_argument_in(str: STRING) is
  255.       do
  256.          run_type.c_type_for_argument_in(str);
  257.       end;
  258.  
  259.    c_type_for_target_in(str: STRING) is
  260.       do
  261.          run_type.c_type_for_target_in(str);
  262.       end;
  263.  
  264.    c_type_for_result_in(str: STRING) is
  265.       do
  266.          run_type.c_type_for_result_in(str);
  267.       end;
  268.  
  269.    need_c_struct: BOOLEAN is
  270.       do
  271.          Result := run_type.need_c_struct;
  272.       end;
  273.  
  274.    formal_generic_list: FORMAL_GENERIC_LIST is
  275.          -- Formal generic list it belongs to.
  276.       do
  277.          Result := start_position.base_class.formal_generic_list;
  278.       end;
  279.  
  280.    formal_arg: FORMAL_GENERIC_ARG is
  281.       do
  282.          Result := formal_generic_list.item(rank);
  283.       end;
  284.  
  285.    constraint: TYPE is
  286.       do
  287.          Result := formal_arg.constraint;
  288.       end;
  289.  
  290.    smallest_ancestor(other: TYPE): TYPE is
  291.       do
  292.          Result := run_type.smallest_ancestor(other);
  293.       end;
  294.  
  295.    is_a(other: TYPE): BOOLEAN is
  296.       do
  297.          Result := run_type.is_a(other);
  298.       end;
  299.  
  300.    is_run_type: BOOLEAN is
  301.       do
  302.          Result := run_type /= Void;
  303.       end;
  304.  
  305.    written_mark: STRING is
  306.       do
  307.          Result := formal_name.to_string;
  308.       end;
  309.  
  310.    run_time_mark: STRING is
  311.       do
  312.          Result := run_type.run_time_mark;
  313.       end;
  314.  
  315.    used_as_reference is
  316.       do
  317.          if is_expanded then
  318.             run_class.used_as_reference;
  319.          end;
  320.       end;
  321.  
  322.    jvm_method_flags: INTEGER is
  323.       do
  324.          Result := run_type.jvm_method_flags;
  325.       end;
  326.  
  327.    jvm_descriptor_in(str: STRING) is
  328.       do
  329.          run_type.jvm_descriptor_in(str);
  330.       end;
  331.  
  332.    jvm_target_descriptor_in(str: STRING) is
  333.       do
  334.          run_type.jvm_target_descriptor_in(str);
  335.       end;
  336.  
  337.    jvm_return_code is
  338.       do
  339.          run_type.jvm_return_code;
  340.       end;
  341.  
  342.    jvm_push_local(offset: INTEGER) is
  343.       do
  344.          run_type.jvm_push_local(offset);
  345.       end;
  346.  
  347.    jvm_check_class_invariant is
  348.       do
  349.          run_type.jvm_check_class_invariant;
  350.       end;
  351.  
  352.    jvm_push_default: INTEGER is
  353.       do
  354.          Result := run_type.jvm_push_default;
  355.       end;
  356.  
  357.    jvm_write_local(offset: INTEGER) is
  358.       do
  359.          run_type.jvm_write_local(offset);
  360.       end;
  361.  
  362.    jvm_xnewarray is
  363.       do
  364.          run_type.jvm_xnewarray;
  365.       end;
  366.  
  367.    jvm_xastore is
  368.       do
  369.          run_type.jvm_xastore;
  370.       end;
  371.  
  372.    jvm_xaload is
  373.       do
  374.          run_type.jvm_xaload;
  375.       end;
  376.  
  377.    jvm_if_x_eq: INTEGER is
  378.       do
  379.          Result := run_type.jvm_if_x_eq;
  380.       end;
  381.  
  382.    jvm_if_x_ne: INTEGER is
  383.       do
  384.          Result := run_type.jvm_if_x_ne;
  385.       end;
  386.  
  387.    jvm_to_reference is
  388.       do
  389.          run_type.jvm_to_reference;
  390.       end;
  391.  
  392.    jvm_expanded_from_reference(other: TYPE): INTEGER is
  393.       do
  394.          Result := run_type.jvm_expanded_from_reference(other);
  395.       end;
  396.  
  397.    jvm_convert_to(destination: TYPE): INTEGER is
  398.       do
  399.          Result := run_type.jvm_convert_to(destination);
  400.       end;
  401.  
  402.    jvm_standard_is_equal is
  403.       do
  404.          run_type.jvm_standard_is_equal;
  405.       end;
  406.  
  407.    to_runnable(ct: TYPE): like Current is
  408.       local
  409.          bc_written, bc_ct: BASE_CLASS;
  410.          p: PARENT;
  411.          t: TYPE;
  412.          gl: ARRAY[TYPE];
  413.       do
  414.          bc_written := start_position.base_class;
  415.          bc_ct := ct.base_class;
  416.          if bc_written = bc_ct then
  417.             gl := ct.generic_list;
  418.             if gl = Void or else rank > gl.upper then
  419.                eh.add_position(ct.start_position);
  420.                eh.add_position(start_position);
  421.                fatal_error(fz_bnga);
  422.             else
  423.                Result := make_runnable(gl.item(rank));
  424.             end;
  425.          else
  426.             check
  427.                bc_ct.is_subclass_of(bc_written)
  428.             end;
  429.             from
  430.                p := bc_ct.first_parent_for(bc_written);
  431.             until
  432.                p = Void
  433.             loop
  434.                t := p.type;
  435.                t := t.to_runnable(ct).run_type;
  436.                if Result = Void then
  437.                   Result := to_runnable(t);
  438.                   p := Void;
  439.                else
  440.                   p := bc_ct.next_parent_for(bc_written,p);
  441.                end;
  442.             end;
  443.             if Result = Void then
  444.                eh.add_type(ct," is the context.");
  445.                warning(start_position,"Unable to compute this type.");
  446.             end;
  447.          end;
  448.       end;
  449.  
  450. feature {RUN_CLASS,TYPE}
  451.  
  452.    need_gc_mark_function: BOOLEAN is
  453.       do
  454.          Result := run_type.need_gc_mark_function;
  455.       end;
  456.  
  457.    just_before_gc_mark_in(str: STRING) is
  458.       do
  459.          run_type.just_before_gc_mark_in(str);
  460.       end;
  461.  
  462.    gc_info_in(str: STRING) is
  463.       do
  464.          run_type.gc_info_in(str);
  465.       end;
  466.  
  467.    gc_define1 is
  468.       do
  469.          run_type.gc_define1;
  470.       end;
  471.  
  472.    gc_define2 is
  473.       do
  474.          run_type.gc_define2;
  475.       end;
  476.  
  477. feature {TYPE_FORMAL_GENERIC}
  478.  
  479.    make_runnable(rt: like run_type): like Current is
  480.       local
  481.          rt2: TYPE;
  482.       do
  483.          rt2 := rt.run_type;
  484.          if rt2 = Void then
  485.             if rt /= Void then
  486.                eh.add_position(rt.start_position);
  487.             end;
  488.             error(start_position,fz_bga);
  489.          elseif run_type = Void then
  490.             run_type := rt2;
  491.             Result := Current;
  492.          else
  493.             Result := twin;
  494.             Result.set_run_type(rt2);
  495.          end;
  496.       end;
  497.  
  498.    set_run_type(rt: TYPE) is
  499.       require
  500.          rt /= Void
  501.       do
  502.          run_type := rt;
  503.       ensure
  504.          run_type = rt
  505.       end;
  506.  
  507. feature {TYPE}
  508.  
  509.    frozen short_hook is
  510.       do
  511.          short_print.a_class_name(formal_name);
  512.       end;
  513.  
  514. invariant
  515.  
  516.    start_position /= Void;
  517.  
  518. end -- TYPE_FORMAL_GENERIC
  519.  
  520.