home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / call_infix2.e < prev    next >
Text File  |  1999-06-05  |  13KB  |  450 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. deferred class CALL_INFIX2
  17.    --
  18.    -- Root for CALL_INFIX_EQ and CALL_INFIX_NEQ.
  19.    --
  20.  
  21. inherit 
  22.    CALL_INFIX 
  23.       redefine static_result_base_class, afd_check, use_current 
  24.       end;
  25.  
  26. feature
  27.  
  28.    precedence: INTEGER is 6;
  29.  
  30.    left_brackets: BOOLEAN is false;
  31.  
  32. feature {NONE}
  33.  
  34.    frozen make(lp: like target; operator_position: POSITION; rp: like arg1) is
  35.       require
  36.          lp /= Void;
  37.          operator_position /= Void;
  38.          rp /= Void
  39.       do
  40.          target := lp;
  41.          !!feature_name.make(operator,operator_position);
  42.          !!arguments.make_1(rp);
  43.       ensure
  44.          target = lp;
  45.          start_position = operator_position;
  46.          arguments.first = rp
  47.       end;
  48.  
  49.    frozen with(t: like target; fn: like feature_name; a: like arguments) is
  50.       require
  51.          t /= Void;
  52.          fn /= Void;
  53.          a.count = 1
  54.       do
  55.          target := t;
  56.          feature_name := fn;
  57.          arguments := a;
  58.       ensure
  59.          target = t;
  60.          feature_name = fn;
  61.          arguments = a
  62.       end;
  63.  
  64. feature
  65.  
  66.    static_result_base_class: BASE_CLASS is
  67.       do
  68.          Result := small_eiffel.get_class(as_boolean);
  69.       end;
  70.  
  71.    frozen run_feature: RUN_FEATURE is
  72.       do
  73.       end;
  74.  
  75.    frozen result_type: TYPE is
  76.       do
  77.          Result := type_boolean;
  78.       end;
  79.  
  80.    frozen to_runnable(ct: TYPE): like Current is
  81.       require
  82.          ct /= Void
  83.       local
  84.          t: like target;
  85.          a: like arguments;
  86.       do
  87.          t := runnable_expression(target,ct);
  88.          a := runnable_args(arguments,ct);
  89.          if t = target and then a = arguments then
  90.             Result := Current;
  91.          else
  92.             !!Result.with(t,feature_name,a);
  93.          end;
  94.          Result.check_comparison(ct);
  95.       end;
  96.  
  97.    frozen assertion_check(tag: CHARACTER) is
  98.       do
  99.          target.assertion_check(tag);
  100.          arg1.assertion_check(tag);
  101.       end;
  102.  
  103.    frozen use_current: BOOLEAN is
  104.       do
  105.          Result := target.use_current or else arg1.use_current;
  106.       end;
  107.  
  108.    frozen afd_check is
  109.       do
  110.          target.afd_check;
  111.          arg1.afd_check;
  112.       end;
  113.  
  114.    frozen isa_dca_inline_argument: INTEGER is
  115.       do
  116.       end;
  117.  
  118.    frozen dca_inline_argument(formal_arg_type: TYPE) is
  119.       do
  120.       end;
  121.  
  122. feature {RUN_FEATURE_4}
  123.  
  124.    frozen dca_inline(formal_arg_type: TYPE) is
  125.       do
  126.          cpp.put_character('(');
  127.          cpp.put_target_as_value;
  128.          cpp.put_character(')');
  129.          if operator.first = '=' then
  130.             cpp.put_string(fz_c_eq);
  131.          else
  132.             cpp.put_string(fz_c_neq);
  133.          end;
  134.          cpp.put_character('(');
  135.          arg1.dca_inline_argument(formal_arg_type);
  136.          cpp.put_character(')');
  137.       end;
  138.  
  139. feature {RUN_FEATURE_3,RUN_FEATURE_4}
  140.  
  141.    finalize is
  142.       do
  143.       end;
  144.  
  145. feature {CALL_INFIX2}
  146.  
  147.    frozen check_comparison(ct: TYPE) is
  148.       local
  149.          tt, at: TYPE;
  150.       do
  151.          if nb_errors = 0 then
  152.             tt := target.result_type.run_type;
  153.             at := arg1.result_type.run_type;
  154.             if tt.is_none then
  155.                if at.is_expanded then
  156.                   at.used_as_reference;
  157.                end;
  158.             elseif at.is_none then
  159.                if tt.is_expanded then
  160.                   tt.used_as_reference;
  161.                end;
  162.             elseif tt.is_reference then
  163.                if at.is_reference then
  164.                   if tt.is_a(at) then
  165.                   else
  166.                      eh.cancel;
  167.                      if at.is_a(tt) then
  168.                      else
  169.                         error_comparison("Reference/Reference",ct);
  170.                      end;
  171.                   end;
  172.                elseif not at.is_a(tt) then
  173.                   error_comparison("Reference/Expanded",ct);
  174.                else
  175.                   at.used_as_reference;
  176.                end;
  177.             else
  178.                if at.is_expanded then
  179.                   if at.is_basic_eiffel_expanded then
  180.                      if tt.is_a(at) then
  181.                      else
  182.                         eh.cancel;
  183.                         if at.is_a(tt) then
  184.                         else
  185.                            error_comparison("Expanded/Expanded",ct);
  186.                         end;
  187.                      end;
  188.                   elseif tt.is_bit then
  189.                      bit_limitation(tt,at);
  190.                   elseif not at.is_a(tt) then
  191.                      error_comparison("Expanded/Expanded",ct);
  192.                   end;
  193.                elseif not tt.is_a(at) then
  194.                   error_comparison("Expanded/Reference",ct);
  195.                else
  196.                   tt.used_as_reference;
  197.                end;
  198.             end;
  199.          end;
  200.       end;
  201.  
  202. feature {NONE}
  203.  
  204.    error_comparison(str: STRING; ct: TYPE) is
  205.       do
  206.          eh.add_position(feature_name.start_position);
  207.          eh.append(" Comparison ");
  208.          eh.append(str);
  209.          eh.append(" Not Valid. Context of Types interpretation is ");
  210.          eh.add_type(ct,fz_dot);
  211.          eh.print_as_fatal_error;
  212.       end;
  213.  
  214.    bit_limitation(t1, t2: TYPE) is
  215.       require
  216.          t1.is_bit;
  217.          t2.is_bit
  218.       local
  219.          b1, b2: TYPE_BIT;
  220.       do
  221.          b1 ?= t1;
  222.          b2 ?= t2;
  223.          if b1.nb /= b2.nb then
  224.             eh.add_position(feature_name.start_position);
  225.             eh.append("Comparison between ");
  226.             eh.add_type(b1," and ");
  227.             eh.add_type(b2,
  228.             " is not yet implemented (you can work arround doing an %
  229.             %assignment in a local variable).");
  230.             eh.print_as_fatal_error;
  231.          end;
  232.       end;
  233.  
  234. feature {NONE}
  235.  
  236.    is_manifest_array(e: EXPRESSION): BOOLEAN is
  237.       local
  238.          ma: MANIFEST_ARRAY;
  239.       do
  240.          ma ?= e;
  241.          Result := ma /= Void;
  242.       end;
  243.  
  244. feature {NONE} -- Low level comparison tools :
  245.  
  246.    cmp_bit(equal_test: BOOLEAN; t: TYPE) is
  247.       require
  248.          t.is_bit
  249.       local
  250.          tb: TYPE_BIT;
  251.       do
  252.          tb ?= t;
  253.          if tb.is_c_unsigned_ptr then
  254.             if equal_test then
  255.                cpp.put_character('!');
  256.             end;
  257.             cpp.put_string("memcmp((");
  258.             target.mapping_c_arg(t);
  259.             cpp.put_string(fz_20);
  260.             arg1.mapping_c_arg(t);
  261.             cpp.put_string("),");
  262.             cpp.put_integer(tb.space_for_variable);
  263.             cpp.put_string(")");
  264.          else
  265.             cpp.put_character('(');
  266.             target.compile_to_c;
  267.             cpp.put_character(')');
  268.             if equal_test then
  269.                cpp.put_string(fz_c_eq);
  270.             else
  271.                cpp.put_string(fz_c_neq);
  272.             end;
  273.             cpp.put_character('(');
  274.             arg1.compile_to_c;
  275.             cpp.put_character(')');
  276.          end;
  277.       end;
  278.  
  279.    cmp_user_expanded(equal_test: BOOLEAN; t: TYPE) is
  280.       require
  281.          t.is_user_expanded
  282.       local
  283.          mem_id: INTEGER;
  284.       do
  285.          if t.is_dummy_expanded then
  286.             cpp.put_character('(');
  287.             target.compile_to_c;
  288.             cpp.put_character(',');
  289.             arg1.compile_to_c;
  290.             cpp.put_character(',');
  291.             if equal_test then
  292.                cpp.put_character('1');
  293.             else
  294.                cpp.put_character('0');
  295.             end;
  296.             cpp.put_character(')');
  297.          else
  298.             mem_id := t.id;
  299.             if equal_test then
  300.                cpp.put_character('!');
  301.             end;
  302.             cpp.put_string(fz_se_cmpt);
  303.             cpp.put_integer(mem_id);
  304.             cpp.put_string(fz_17);
  305.             target.compile_to_c;
  306.             cpp.put_string(fz_20);
  307.             arg1.compile_to_c;
  308.             cpp.put_string(fz_13);
  309.          end;
  310.       end;
  311.  
  312.    cmp_basic_eiffel_expanded(equal_test: BOOLEAN; t1, t2: TYPE) is
  313.       require
  314.          t1.is_basic_eiffel_expanded;
  315.          t2.is_basic_eiffel_expanded
  316.       local
  317.          flag: BOOLEAN;
  318.       do
  319.          flag := t1.is_real or else t2.is_real;
  320.          if flag then
  321.             cpp.put_string(fz_cast_float);
  322.          end;
  323.          cpp.put_character('(');
  324.          target.compile_to_c;
  325.          if flag then
  326.             cpp.put_string(fz_13);
  327.          end;
  328.          cpp.put_character(')');
  329.          if equal_test then
  330.             cpp.put_string(fz_c_eq);
  331.          else
  332.             cpp.put_string(fz_c_neq);
  333.          end;
  334.          cpp.put_character('(');
  335.          if flag then
  336.             cpp.put_string(fz_cast_float);
  337.          end;
  338.          arg1.compile_to_c;
  339.          cpp.put_character(')');
  340.          if flag then
  341.             cpp.put_string(fz_13);
  342.          end;
  343.       end;
  344.  
  345.    cmp_basic_ref(equal_test: BOOLEAN) is
  346.          -- *** ORIGINAL ***
  347.       do
  348.          cpp.put_character('(');
  349.          target.compile_to_c;
  350.          cpp.put_character(')');
  351.          if equal_test then
  352.             cpp.put_string(fz_c_eq);
  353.          else
  354.             cpp.put_string(fz_c_neq);
  355.          end;
  356.          cpp.put_character('(');
  357.          cpp.put_string(fz_cast_void_star);
  358.          cpp.put_character('(');
  359.          arg1.compile_to_c;
  360.          cpp.put_character(')');
  361.          cpp.put_character(')');
  362.       end;
  363.  
  364.    ecoop99_1_cmp_basic_ref(equal_test: BOOLEAN) is
  365.          -- *** `cmp_basic_ref' for ECOOP'99 benchmark ***
  366.          -- *** With aliasing ***
  367.       local
  368.          string_cmp: BOOLEAN;
  369.       do
  370.          if target.result_type.run_type.is_string then
  371.             if arg1.result_type.run_type.is_string then
  372.                string_cmp := false;
  373.             end;
  374.          end;
  375.          if string_cmp then
  376.             if not equal_test then
  377.                cpp.put_string("(!(");
  378.             end;
  379.             cpp.put_string("/*ECOOP*/r7is_equal(((T7*)(");
  380.             target.compile_to_c;
  381.             cpp.put_string(")),((T0*)(");
  382.             arg1.compile_to_c;
  383.             cpp.put_string(")))");
  384.             if not equal_test then
  385.                cpp.put_string("))");
  386.             end;
  387.          else
  388.             cpp.put_character('(');
  389.             target.compile_to_c;
  390.             cpp.put_character(')');
  391.             if equal_test then
  392.                cpp.put_string(fz_c_eq);
  393.             else
  394.                cpp.put_string(fz_c_neq);
  395.             end;
  396.             cpp.put_character('(');
  397.             cpp.put_string(fz_cast_void_star);
  398.             cpp.put_character('(');
  399.             arg1.compile_to_c;
  400.             cpp.put_character(')');
  401.             cpp.put_character(')');
  402.          end;
  403.       end;
  404.  
  405.    ecoop99_2_cmp_basic_ref(equal_test: BOOLEAN) is
  406.          -- *** `cmp_basic_ref' for ECOOP'99 benchmark ***
  407.          -- *** Without aliasing ***
  408.       local
  409.          string_cmp: BOOLEAN;
  410.       do
  411.          if target.result_type.run_type.is_string then
  412.             if arg1.result_type.run_type.is_string then
  413.                string_cmp := true;
  414.             end;
  415.          end;
  416.          if string_cmp then
  417.             if not equal_test then
  418.                cpp.put_string("(!(");
  419.             end;
  420.             cpp.put_string("/*ECOOP*/r7is_equal(((T7*)(");
  421.             target.compile_to_c;
  422.             cpp.put_string(")),((T0*)(");
  423.             arg1.compile_to_c;
  424.             cpp.put_string(")))");
  425.             if not equal_test then
  426.                cpp.put_string("))");
  427.             end;
  428.          else
  429.             cpp.put_character('(');
  430.             target.compile_to_c;
  431.             cpp.put_character(')');
  432.             if equal_test then
  433.                cpp.put_string(fz_c_eq);
  434.             else
  435.                cpp.put_string(fz_c_neq);
  436.             end;
  437.             cpp.put_character('(');
  438.             cpp.put_string(fz_cast_void_star);
  439.             cpp.put_character('(');
  440.             arg1.compile_to_c;
  441.             cpp.put_character(')');
  442.             cpp.put_character(')');
  443.          end;
  444.       end;
  445.  
  446.    fz_cast_float: STRING is "((float)(";
  447.  
  448. end -- CALL_INFIX2
  449.  
  450.