home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / call_infix_eq.e < prev    next >
Text File  |  1999-06-05  |  7KB  |  223 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 CALL_INFIX_EQ
  17.    --
  18.    --   Infix operator : "=".
  19.    --
  20.  
  21. inherit CALL_INFIX2;
  22.  
  23. creation make, with
  24.  
  25. feature
  26.  
  27.    operator: STRING is
  28.       do
  29.          Result := as_eq;
  30.       end;
  31.  
  32.    is_static: BOOLEAN is
  33.       do
  34.          if target.is_void then
  35.             Result := is_static_eq_void(arg1);
  36.          elseif arg1.is_void then
  37.             Result := is_static_eq_void(target);
  38.          elseif target.is_static and then arg1.is_static then
  39.             Result := true;
  40.          end;
  41.       end;
  42.  
  43.    static_value: INTEGER is
  44.       do
  45.          if target.is_void then
  46.             Result := static_eq_void(arg1);
  47.          elseif arg1.is_void then
  48.             Result := static_eq_void(target);
  49.          elseif target.is_static and then arg1.is_static then
  50.             if target.static_value = arg1.static_value then
  51.                Result := 1;
  52.             end;
  53.          end;
  54.       end;
  55.  
  56.    compile_to_c is
  57.       local
  58.          tt, at: TYPE;
  59.       do
  60.          tt := target.result_type.run_type;
  61.          at := arg1.result_type.run_type;
  62.          if tt.is_expanded then
  63.             if at.is_expanded then -- ------------- Expanded/Expanded :
  64.                if tt.is_user_expanded then
  65.                   cmp_user_expanded(true,tt);
  66.                elseif tt.is_basic_eiffel_expanded then
  67.                   cmp_basic_eiffel_expanded(true,at,tt);
  68.                elseif tt.is_bit then
  69.                   cmp_bit(true,tt);
  70.                else -- NATIVE_ARRAY
  71.                   cmp_basic_ref(true);
  72.                end;
  73.             else -- ------------------------------- Expanded/Reference :
  74.                c2c_exp_ref(target,tt,arg1,at);
  75.             end;
  76.          elseif at.is_expanded then -- ----------- Reference/Expanded :
  77.             c2c_exp_ref(arg1,at,target,tt);
  78.          else -- ---------------------------- Reference/Reference :
  79.             cmp_basic_ref(true);
  80.          end;
  81.       end;
  82.  
  83. feature {NONE}
  84.  
  85.    c2c_exp_ref(e: EXPRESSION; et: TYPE; r: EXPRESSION; rt: TYPE) is
  86.       do
  87.          if r.is_void then
  88.             cpp.put_string(fz_17);
  89.             e.compile_to_c;
  90.          else
  91.             cpp.put_string(fz_17);
  92.             e.compile_to_c;
  93.             cpp.put_string(fz_20);
  94.             r.compile_to_c;
  95.          end;
  96.          cpp.put_string("),0)");
  97.       end;
  98.  
  99. feature {NONE}
  100.  
  101.    is_static_eq_void(e: EXPRESSION): BOOLEAN is
  102.       local
  103.          rt: TYPE;
  104.       do
  105.          if e.is_current then
  106.             Result := true;
  107.          elseif e.is_manifest_string then
  108.             Result := true;
  109.          elseif is_manifest_array(e) then
  110.             Result := true;
  111.          else
  112.             rt := e.result_type.run_type;
  113.             if rt.is_expanded then
  114.                if e.can_be_dropped then
  115.                   Result := true;
  116.                end;
  117.             elseif e.is_static then
  118.                if e.static_value = 0 then
  119.                   Result := true;
  120.                end;
  121.             end;
  122.          end;
  123.       end;
  124.  
  125.    static_eq_void(e: EXPRESSION): INTEGER is
  126.       local
  127.          rt: TYPE;
  128.       do
  129.          if e.is_current then
  130.          elseif e.is_manifest_string then
  131.          elseif is_manifest_array(e) then
  132.          else
  133.             rt := e.result_type.run_type;
  134.             if rt.is_expanded then
  135.                if e.can_be_dropped then
  136.                   Result := 0;
  137.                end;
  138.             elseif e.is_static then
  139.                if e.static_value = 0 then
  140.                   Result := 1;
  141.                end;
  142.             end;
  143.          end;
  144.       end;
  145.  
  146. feature
  147.  
  148.    compile_to_jvm is
  149.       local
  150.          space, point1, point2: INTEGER;
  151.          rt: TYPE;
  152.          rc: RUN_CLASS;
  153.       do
  154.          if target.is_void then
  155.             jvm_void_cmp(arg1);
  156.          elseif arg1.is_void then
  157.             jvm_void_cmp(target);
  158.          else
  159.             rt := target.result_type.smallest_ancestor(arg1.result_type);
  160.             space := target.compile_to_jvm_into(rt);
  161.             space := arg1.compile_to_jvm_into(rt);
  162.             if rt.is_user_expanded then
  163.                rc := rt.run_class;
  164.                jvm.std_is_equal(rc,rc.writable_attributes);
  165.             else
  166.                point1 := rt.jvm_if_x_eq;
  167.                code_attribute.opcode_iconst_0;
  168.                point2 := code_attribute.opcode_goto;
  169.                code_attribute.resolve_u2_branch(point1);
  170.                code_attribute.opcode_iconst_1;
  171.                code_attribute.resolve_u2_branch(point2);
  172.             end;
  173.          end;
  174.       end;
  175.  
  176.    jvm_branch_if_false: INTEGER is
  177.       do
  178.          Result := jvm_standard_branch_if_false;
  179.       end;
  180.  
  181.    jvm_branch_if_true: INTEGER is
  182.       do
  183.          Result := jvm_standard_branch_if_true;
  184.       end;
  185.  
  186. feature {NONE}
  187.  
  188.    jvm_void_cmp(e: EXPRESSION) is
  189.       local
  190.          rt: TYPE;
  191.          point1, point2: INTEGER;
  192.          space: INTEGER;
  193.       do
  194.          rt := e.result_type.run_type;
  195.          if rt.is_expanded then
  196.             e.compile_to_jvm;
  197.             from
  198.                space := rt.jvm_stack_space;
  199.             until
  200.                space = 0
  201.             loop
  202.                code_attribute.opcode_pop;
  203.                space := space - 1;
  204.             end;
  205.             code_attribute.opcode_iconst_0;
  206.          else
  207.             e.compile_to_jvm;
  208.             point1 := code_attribute.opcode_ifnull;
  209.             code_attribute.opcode_iconst_0;
  210.             point2 := code_attribute.opcode_goto;
  211.             code_attribute.resolve_u2_branch(point1);
  212.             code_attribute.opcode_iconst_1;
  213.             code_attribute.resolve_u2_branch(point2);
  214.          end;
  215.       end;
  216.  
  217. invariant
  218.  
  219.    run_feature = Void;
  220.  
  221. end -- CALL_INFIX_EQ
  222.  
  223.