home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / call_infix_neq.e < prev    next >
Text File  |  1999-06-05  |  8KB  |  279 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_NEQ
  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_neq;
  30.       end;
  31.  
  32.    is_static: BOOLEAN is
  33.       do
  34.          if target.is_void then
  35.             Result := is_static_neq_void(arg1);
  36.          elseif arg1.is_void then
  37.             Result := is_static_neq_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_neq_void(arg1);
  47.          elseif arg1.is_void then
  48.             Result := static_neq_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(false,tt);
  66.                elseif tt.is_basic_eiffel_expanded then
  67.                   cmp_basic_eiffel_expanded(false,at,tt);
  68.                elseif tt.is_bit then
  69.                   cmp_bit(false,tt);
  70.                else -- NATIVE_ARRAY
  71.                   cmp_basic_ref(false);
  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(false);
  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.             r.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("),1)");
  97.       end;
  98.  
  99. feature {NONE}
  100.  
  101.    is_static_neq_void(e: EXPRESSION): BOOLEAN is
  102.       local
  103.          rt: TYPE;
  104.       do
  105.          if e.is_current or else
  106.             e.is_manifest_string or else
  107.             is_manifest_array(e)
  108.           then
  109.             Result := true;
  110.          else
  111.             rt := e.result_type.run_type;
  112.             if rt.is_expanded then
  113.                Result := true;
  114.             elseif e.is_static then
  115.                Result := true;
  116.             end;
  117.          end;
  118.       end;
  119.  
  120.    static_neq_void(e: EXPRESSION): INTEGER is
  121.       local
  122.          rt: TYPE;
  123.       do
  124.          if e.is_current or else
  125.            e.is_manifest_string or else
  126.            is_manifest_array(e)
  127.           then
  128.             Result := 1;
  129.          else
  130.             rt := e.result_type.run_type;
  131.             if rt.is_expanded then
  132.                Result := 1;
  133.             elseif e.is_static then
  134.                if e.static_value /= 0 then
  135.                   Result := 1;
  136.                end;
  137.             end;
  138.          end;
  139.       end;
  140.  
  141. feature
  142.  
  143.    compile_to_jvm is
  144.       local
  145.          space, point1, point2: INTEGER;
  146.          rt: TYPE;
  147.          rc: RUN_CLASS;
  148.          ca: like code_attribute;
  149.       do
  150.          if target.is_void then
  151.             jvm_void_cmp(arg1);
  152.          elseif arg1.is_void then
  153.             jvm_void_cmp(target);
  154.          else
  155.             ca := code_attribute;
  156.             rt := target.result_type.smallest_ancestor(arg1.result_type);
  157.             space := target.compile_to_jvm_into(rt);
  158.             space := arg1.compile_to_jvm_into(rt);
  159.             if rt.is_user_expanded then
  160.                rc := rt.run_class;
  161.                jvm_standard_is_neq_aux(rc,rc.writable_attributes);
  162.             else
  163.                point1 := rt.jvm_if_x_eq;
  164.                ca.opcode_iconst_1;
  165.                point2 := ca.opcode_goto;
  166.                ca.resolve_u2_branch(point1);
  167.                ca.opcode_iconst_0;
  168.                ca.resolve_u2_branch(point2);
  169.             end;
  170.          end;
  171.       end;
  172.  
  173.    jvm_branch_if_false: INTEGER is
  174.       do
  175.          Result := jvm_standard_branch_if_false;
  176.       end;
  177.  
  178.    jvm_branch_if_true: INTEGER is
  179.       do
  180.          Result := jvm_standard_branch_if_true;
  181.       end;
  182.  
  183. feature {NONE}
  184.  
  185.    jvm_void_cmp(e: EXPRESSION) is
  186.       local
  187.          rt: TYPE;
  188.          point1, point2: INTEGER;
  189.          space: INTEGER;
  190.          ca: like code_attribute;
  191.       do
  192.          ca := code_attribute;
  193.          rt := e.result_type.run_type;
  194.          if rt.is_expanded then
  195.             e.compile_to_jvm;
  196.             from
  197.                space := rt.jvm_stack_space;
  198.             until
  199.                space = 0
  200.             loop
  201.                ca.opcode_pop;
  202.                space := space - 1;
  203.             end;
  204.             ca.opcode_iconst_1;
  205.          else
  206.             e.compile_to_jvm;
  207.             point1 := ca.opcode_ifnonnull;
  208.             ca.opcode_iconst_0;
  209.             point2 := ca.opcode_goto;
  210.             ca.resolve_u2_branch(point1);
  211.             ca.opcode_iconst_1;
  212.             ca.resolve_u2_branch(point2);
  213.          end;
  214.       end;
  215.  
  216. feature {NONE}
  217.  
  218.    jvm_standard_is_neq_aux(rc: RUN_CLASS; wa: ARRAY[RUN_FEATURE_2]) is
  219.       require
  220.          rc.current_type.is_user_expanded
  221.       local
  222.          ca: like code_attribute;
  223.          rf2: RUN_FEATURE_2;
  224.          point1, point2, idx, space, i: INTEGER;
  225.       do
  226.          ca := code_attribute;
  227.          if wa = Void then
  228.             ca.opcode_pop;
  229.             ca.opcode_pop;
  230.             ca.opcode_iconst_0;
  231.          else
  232.             ca.branches.clear;
  233.             ca.opcode_dup;
  234.             rc.opcode_instanceof;
  235.             ca.branches.add_last(ca.opcode_ifeq);
  236.             from
  237.                i := wa.upper;
  238.             until
  239.                i = 0
  240.             loop
  241.                rf2 := wa.item(i);
  242.                idx := constant_pool.idx_fieldref(rf2);
  243.                space := rf2.result_type.jvm_stack_space - 1;
  244.                if i > 1 then
  245.                   ca.opcode_dup2;
  246.                end;
  247.                ca.opcode_getfield(idx,space);
  248.                if space = 0 then
  249.                   ca.opcode_swap;
  250.                else
  251.                   ca.opcode_dup2_x1;
  252.                   ca.opcode_pop2;
  253.                end;
  254.                ca.opcode_getfield(idx,space);
  255.                if i > 1 then
  256.                   ca.branches.add_last(rf2.result_type.jvm_if_x_ne);
  257.                else
  258.                   point1 := rf2.result_type.jvm_if_x_ne;
  259.                end;
  260.                i := i - 1;
  261.             end;
  262.             ca.opcode_iconst_0;
  263.             point2 := ca.opcode_goto;
  264.             ca.resolve_branches;
  265.             ca.opcode_pop;
  266.             ca.opcode_pop;
  267.             ca.resolve_u2_branch(point1);
  268.             ca.opcode_iconst_1;
  269.             ca.resolve_u2_branch(point2);
  270.          end;
  271.       end;
  272.  
  273. invariant
  274.  
  275.    run_feature = Void;
  276.  
  277. end -- CALL_INFIX_NEQ
  278.  
  279.