home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #4 / amigaacscoverdisc1998-041998.iso / utilities / shareware / dev / ppcsmalleiffel / lib_se / call_infix.e < prev    next >
Encoding:
Text File  |  1998-01-16  |  4.6 KB  |  188 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://www.loria.fr/SmallEiffel
  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_INFIX
  17. --   
  18. -- For all sort of infix operators.
  19. -- Root of all CALL_INFIX_*.
  20. --
  21.  
  22. inherit
  23.    CALL_1
  24.       rename make as make_call_1
  25.       undefine precedence
  26.       redefine feature_name, precedence, print_as_target
  27.       end;
  28.    
  29. feature 
  30.    
  31.    feature_name: INFIX_NAME;
  32.    
  33.    precedence: INTEGER is
  34.       deferred
  35.       end;
  36.    
  37.    operator: STRING is
  38.       deferred
  39.       ensure     
  40.      Result.count >= 1
  41.       end;
  42.    
  43. feature {NONE}   
  44.    
  45.    frozen make(lp: like target; operator_position: POSITION; rp: like arg1) is
  46.       require
  47.      operator_position /= Void;
  48.       local
  49.      eal: EFFECTIVE_ARG_LIST;
  50.       do
  51.      if lp = Void or else rp = Void then
  52.         eh.add_position(operator_position);
  53.         fatal_error("Syntax Error.");
  54.      end;
  55.      !!feature_name.make(operator,operator_position);
  56.      !!eal.make(<<rp>>);
  57.      make_call_1(lp,feature_name,eal);
  58.       ensure
  59.      target /= Void;
  60.       end;
  61.    
  62. feature 
  63.  
  64.    frozen short is
  65.       do
  66.      if target.precedence = atomic_precedence then
  67.         target.short;
  68.         short_print_feature_name;
  69.         if arg1.precedence = atomic_precedence then
  70.            arg1.short;
  71.         elseif precedence >= arg1.precedence then
  72.            arg1.bracketed_short;
  73.         else
  74.            arg1.short;
  75.         end;
  76.      elseif target.precedence < precedence then
  77.         target.bracketed_short;
  78.         short_print_feature_name;
  79.         arg1.short;
  80.      else
  81.         target.short;
  82.         short_print_feature_name;
  83.         arg1.short;
  84.      end;        
  85.       end;
  86.    
  87.    frozen short_target is
  88.       do
  89.      bracketed_short;
  90.      short_print.a_dot;
  91.       end;
  92.  
  93.    frozen print_as_target is
  94.       do
  95.      fmt.put_character('(');
  96.      pretty_print;
  97.      fmt.put_character(')');
  98.      fmt.put_character('.');
  99.       end;
  100.  
  101.    frozen bracketed_pretty_print is
  102.       do
  103.      fmt.put_character('(');
  104.      pretty_print;
  105.      fmt.put_character(')');
  106.       end;
  107.    
  108.    pretty_print is
  109.      -- *** Should be frozen ***
  110.      -- *** Because the bug with priority of infix "^", this 
  111.      -- *** feature is NOT frozen.
  112.      -- *** The only one redefinition is in CALL_INFIX_POWER.
  113.       do
  114.      if target.precedence = atomic_precedence then
  115.         target.pretty_print;
  116.         print_op;
  117.         if arg1.precedence = atomic_precedence then
  118.            arg1.pretty_print;
  119.         elseif precedence >= arg1.precedence then
  120.            arg1.bracketed_pretty_print;
  121.         else
  122.            arg1.pretty_print;
  123.         end;
  124.      elseif arg1.precedence = atomic_precedence then
  125.         if target.precedence >= precedence then
  126.            target.bracketed_pretty_print;
  127.         else
  128.            target.pretty_print;
  129.         end;
  130.         print_op;
  131.         arg1.pretty_print;
  132.      elseif precedence <= target.precedence then
  133.         target.bracketed_pretty_print;
  134.         print_op;
  135.         if precedence <= arg1.precedence then
  136.            arg1.bracketed_pretty_print;
  137.         else
  138.            arg1.pretty_print;
  139.         end;
  140.      else
  141.         target.pretty_print;
  142.         print_op;          
  143.         arg1.pretty_print;
  144.      end;        
  145.       end;
  146.       
  147. feature {NONE}
  148.    
  149.    print_op is
  150.       do
  151.      fmt.put_character(' ');
  152.      feature_name.pretty_print;
  153.      fmt.put_character(' ');
  154.       end;
  155.  
  156. feature {NONE}
  157.  
  158.    frozen short_print_feature_name is
  159.       do
  160.      short_print.a_infix_name("Binfix"," ","Ainfix"," ",feature_name);
  161.       end;
  162.    
  163.    frozen c2c_cast_op(cast, op: STRING) is
  164.       do
  165.      cpp.put_character('(');
  166.      cpp.put_character('(');
  167.      cpp.put_character('(');
  168.      cpp.put_string(cast);
  169.      cpp.put_character(')');
  170.      cpp.put_character('(');
  171.      target.compile_to_c;
  172.      cpp.put_character(')');
  173.      cpp.put_character(')');
  174.      cpp.put_string(op);
  175.      cpp.put_character('(');
  176.      cpp.put_character('(');
  177.      cpp.put_string(cast);
  178.      cpp.put_character(')');
  179.      cpp.put_character('(');
  180.      arg1.compile_to_c;
  181.      cpp.put_character(')');
  182.      cpp.put_character(')');
  183.      cpp.put_character(')');
  184.       end;
  185.  
  186. end -- CALL_INFIX
  187.  
  188.