home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / call_infix.e < prev    next >
Text File  |  1999-06-05  |  4KB  |  160 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_INFIX
  17.    --
  18.    -- For all sort of infix operators (root of all CALL_INFIX_*).
  19.    --
  20.  
  21. inherit CALL_1 redefine feature_name, print_as_target end;
  22.  
  23. feature
  24.  
  25.    feature_name: INFIX_NAME;
  26.  
  27. feature
  28.  
  29.    left_brackets: BOOLEAN is
  30.       deferred
  31.       end;
  32.  
  33.    right_brackets: BOOLEAN is
  34.       do
  35.          Result := not left_brackets;
  36.       end;
  37.  
  38.    operator: STRING is
  39.       deferred
  40.       ensure
  41.          Result.count >= 1
  42.       end;
  43.  
  44. feature
  45.  
  46.    frozen short is
  47.       do
  48.          if target.precedence = atomic_precedence then
  49.             target.short;
  50.             short_print_feature_name;
  51.             if arg1.precedence = atomic_precedence then
  52.                arg1.short;
  53.             elseif precedence >= arg1.precedence then
  54.                arg1.bracketed_short;
  55.             else
  56.                arg1.short;
  57.             end;
  58.          elseif target.precedence < precedence then
  59.             target.bracketed_short;
  60.             short_print_feature_name;
  61.             arg1.short;
  62.          else
  63.             target.short;
  64.             short_print_feature_name;
  65.             arg1.short;
  66.          end;
  67.       end;
  68.  
  69.    frozen short_target is
  70.       do
  71.          bracketed_short;
  72.          short_print.a_dot;
  73.       end;
  74.  
  75.    frozen print_as_target is
  76.       do
  77.          fmt.put_character('(');
  78.          pretty_print;
  79.          fmt.put_character(')');
  80.          fmt.put_character('.');
  81.       end;
  82.  
  83.    frozen bracketed_pretty_print is
  84.       do
  85.          fmt.put_character('(');
  86.          pretty_print;
  87.          fmt.put_character(')');
  88.       end;
  89.  
  90. feature
  91.  
  92.    frozen pretty_print is
  93.       do
  94.          if target.precedence = atomic_precedence then
  95.             target.pretty_print;
  96.          elseif precedence > target.precedence then
  97.             target.bracketed_pretty_print;
  98.          elseif precedence < target.precedence then
  99.             target.pretty_print;
  100.          elseif left_brackets then
  101.             target.bracketed_pretty_print;
  102.          else
  103.             target.pretty_print;
  104.          end;
  105.          print_op;
  106.          if arg1.precedence = atomic_precedence then
  107.             arg1.pretty_print;
  108.          elseif precedence > arg1.precedence then
  109.             arg1.bracketed_pretty_print;
  110.          elseif precedence < arg1.precedence then
  111.             arg1.pretty_print;
  112.          elseif right_brackets then
  113.             arg1.bracketed_pretty_print;
  114.          else
  115.             arg1.pretty_print;
  116.          end;
  117.       end;
  118.  
  119. feature {NONE}
  120.  
  121.    frozen print_op is
  122.       do
  123.          fmt.put_character(' ');
  124.          feature_name.pretty_print;
  125.          fmt.put_character(' ');
  126.       end;
  127.  
  128. feature {NONE}
  129.  
  130.    frozen short_print_feature_name is
  131.       do
  132.          short_print.a_infix_name("Binfix"," ","Ainfix"," ",feature_name);
  133.       end;
  134.  
  135.    frozen c2c_cast_op(cast, op: STRING) is
  136.       do
  137.          cpp.put_character('(');
  138.          cpp.put_character('(');
  139.          cpp.put_character('(');
  140.          cpp.put_string(cast);
  141.          cpp.put_character(')');
  142.          cpp.put_character('(');
  143.          target.compile_to_c;
  144.          cpp.put_character(')');
  145.          cpp.put_character(')');
  146.          cpp.put_string(op);
  147.          cpp.put_character('(');
  148.          cpp.put_character('(');
  149.          cpp.put_string(cast);
  150.          cpp.put_character(')');
  151.          cpp.put_character('(');
  152.          arg1.compile_to_c;
  153.          cpp.put_character(')');
  154.          cpp.put_character(')');
  155.          cpp.put_character(')');
  156.       end;
  157.  
  158. end -- CALL_INFIX
  159.  
  160.