home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #4 / amigaacscoverdisc1998-041998.iso / utilities / shareware / dev / ppcsmalleiffel / lib_se / expression.e < prev    next >
Encoding:
Text File  |  1998-01-16  |  11.0 KB  |  480 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 EXPRESSION
  17. --
  18. -- An Eiffel expression.
  19. --
  20.    
  21. inherit 
  22.    GLOBALS 
  23.       redefine fill_tagged_out_memory 
  24.       end; 
  25.    
  26. feature {EXPRESSION}
  27.    
  28.    static_value_mem: INTEGER;
  29.    
  30. feature 
  31.    
  32.    fill_tagged_out_memory is
  33.       local
  34.      p: POSITION;
  35.      ct, rt: TYPE;
  36.      rtm: STRING;
  37.       do
  38.      p := start_position;
  39.      if p /= Void then
  40.         p.fill_tagged_out_memory;
  41.      end;
  42.      if is_checked then
  43.         ct := current_type;
  44.         if ct /= Void then
  45.            rtm := ct.run_time_mark;
  46.            if rtm /= Void then
  47.           tagged_out_memory.append(" ct=");
  48.           tagged_out_memory.append(rtm);
  49.            end;
  50.         end;
  51.         rt := result_type;
  52.         if rt /= Void then
  53.            rtm := rt.run_time_mark;
  54.            if rtm /= Void then
  55.           tagged_out_memory.append(" rt=");
  56.           tagged_out_memory.append(rtm);
  57.            end;
  58.         end;
  59.      end;
  60.       end;
  61.  
  62.    current_type: TYPE; 
  63.      -- Not Void when checked in.
  64.    
  65.    frozen is_checked: BOOLEAN is
  66.      -- True when expression is checked.
  67.       do
  68.      Result := current_type /= Void;
  69.      if not Result then
  70.         warning(start_position,"EXPRESSION: Is not checked.");
  71.      end;
  72.       end;
  73.    
  74.    result_type: TYPE is
  75.      -- When checked, the type of the expression;
  76.       require
  77.      is_checked;
  78.       deferred
  79.       ensure
  80.      Result.is_run_type
  81.       end;
  82.    
  83.    use_current: BOOLEAN is
  84.       require
  85.      is_checked;
  86.      small_eiffel.is_ready;
  87.       deferred
  88.       end;
  89.    
  90.    to_runnable(ct: TYPE): like Current is
  91.       -- Gives the corresponding expression checked for `ct'.
  92.       require
  93.      ct.run_type = ct;
  94.      ct.run_class /= Void;
  95.      nb_errors = 0 implies empty_eh_check    
  96.       deferred
  97.       ensure
  98.      nb_errors = 0 implies Result /= Void;
  99.      Result = Void implies nb_errors > 0;
  100.      Result /= Void implies Result.current_type = ct; 
  101.      nb_errors = 0 implies empty_eh_check    
  102.       end;
  103.  
  104. feature 
  105.  
  106.    isa_dca_inline_argument: INTEGER is
  107.     ---*** GENERALISABLE POUR LES DCALLS (CHARACTER.is_digit par exemple).
  108.      -- Interpretation of Result :
  109.      -- -1 : yes and no ARGUMENT_NAME used
  110.      --  0 : not inlinable
  111.          -- >0 : inlinable and ARGUMENT_NAME rank is used.
  112.       require
  113.      run_control.boost and small_eiffel.is_ready
  114.       deferred
  115.       end;
  116.  
  117.    dca_inline_argument(formal_arg_type: TYPE) is
  118.       require
  119.      formal_arg_type /= Void;
  120.      isa_dca_inline_argument /= 0
  121.       deferred
  122.       end;
  123.  
  124. feature  -- Handling of precedence (priority of expressions) :
  125.    
  126.    precedence: INTEGER is
  127.      -- of the receiver.
  128.       deferred
  129.       ensure
  130.      1 <= Result and Result <= atomic_precedence
  131.       end;
  132.       
  133. feature  
  134.    
  135.    add_comment(c: COMMENT): EXPRESSION is
  136.      -- Attach `c' to the receiver.
  137.       do
  138.      if c = Void or else c.count = 0 then
  139.         Result := Current;
  140.      else
  141.         !EXPRESSION_WITH_COMMENT!Result.make(Current,c);
  142.      end;
  143.       end;
  144.    
  145.    start_position: POSITION is
  146.       -- Of the expression if any.
  147.       deferred
  148.       end;
  149.    
  150.    base_class_written: BASE_CLASS is
  151.       do
  152.      Result := written_in.base_class;
  153.       end;
  154.    
  155.    written_in: CLASS_NAME is
  156.      -- The name of the base class where the expression is 
  157.      -- written if any.
  158.       local
  159.      sp: like start_position;
  160.       do
  161.      sp := start_position;
  162.      if sp /= Void then
  163.         Result := sp.base_class_name;
  164.      end;
  165.       end;
  166.    
  167.    run_class: RUN_CLASS is
  168.       do
  169.      if current_type /= Void then
  170.         Result := current_type.run_class;
  171.      end;
  172.       end;
  173.  
  174.    is_current, is_void, is_result, is_writable,
  175.    is_manifest_string: BOOLEAN is 
  176.       do 
  177.       end;
  178.       
  179.    is_a(other: EXPRESSION): BOOLEAN is
  180.       require
  181.      result_type.is_run_type;
  182.      other.result_type.is_run_type
  183.       do
  184.      Result := result_type.run_type.is_a(other.result_type.run_type);
  185.      if not Result then
  186.         eh.add_position(start_position);
  187.         error(other.start_position," Type mismatch.");
  188.      end;
  189.       end;
  190.  
  191.    afd_check is
  192.      -- After Falling Down Check.
  193.       require
  194.      is_checked;
  195.       deferred
  196.       end;
  197.  
  198. feature -- To produce C code :
  199.  
  200.    compile_to_c is
  201.      -- Produce C code to access the value of the Current 
  202.      -- expression : user's expanded are no longuer pointer.
  203.       require
  204.      is_checked;
  205.      cpp.on_c;
  206.       deferred
  207.       ensure     
  208.      cpp.on_c
  209.       end;
  210.  
  211.    mapping_c_target(formal_type: TYPE) is
  212.      -- Produce C code in order to pass Current expression as 
  213.      -- the target of a feature call.
  214.      -- When it is needed, C code to check invariant is 
  215.      -- automatically added as well as a C cast according to 
  216.      -- the destination `formal_type'.
  217.       require
  218.      small_eiffel.is_ready;
  219.      formal_type.at_run_time
  220.       deferred
  221.       end;
  222.  
  223.    mapping_c_arg(formal_arg_type: TYPE) is
  224.      -- Produce C code in order to pass Current expression as an 
  225.      -- argument of the feature called.
  226.      -- Thus, it is the same jobs as `mapping_c_target' without
  227.      -- the invariant call.
  228.       require
  229.      small_eiffel.is_ready
  230.       deferred
  231.       end;
  232.    
  233.    compile_to_c_old is
  234.      -- Produce C code to memorize `old' expression values.
  235.       require
  236.      is_checked;
  237.      cpp.on_c;
  238.       deferred
  239.       ensure     
  240.      cpp.on_c
  241.       end;
  242.  
  243. feature  -- To produce C code :
  244.    
  245.    c_simple: BOOLEAN is
  246.      -- True when the C code of `compile_c' has no side effect at 
  247.      -- and `compile_to_c' on the corresponding simple expression 
  248.      -- can be called more than once without any problem. 
  249.       require
  250.      is_checked;
  251.       deferred
  252.       end;
  253.    
  254.    can_be_dropped: BOOLEAN is
  255.      -- True if evaluation of current expression has NO possible 
  256.      -- side effects. Thus, in such a case, an unused expression 
  257.      -- can be dropped (for example target of real procedure or 
  258.      -- real function).
  259.       require
  260.      is_checked;
  261.      small_eiffel.is_ready;
  262.       deferred
  263.       end;
  264.    
  265.    is_pre_computable: BOOLEAN is
  266.      -- Can the current expression be pre-computed in main 
  267.      -- function to speed up a once function ?
  268.      -- When `is_static' may be true it must be called in order
  269.      -- to prepare `static_value_mem'.
  270.       require
  271.      is_checked;
  272.      small_eiffel.is_ready
  273.       deferred
  274.       end;
  275.  
  276. feature -- For `compile_to_jvm' :
  277.    
  278.    compile_to_jvm is
  279.      -- Produce Java byte code in order to push expression value 
  280.      -- on the jvm stack.
  281.       require
  282.      is_checked
  283.       deferred
  284.       end;
  285.  
  286.    compile_target_to_jvm is
  287.      -- Same as `compile_to_jvm', but add class invariant check
  288.      -- when needed.
  289.       require
  290.      is_checked
  291.       deferred
  292.       end;
  293.  
  294.    compile_to_jvm_old is
  295.      -- Produce Java byte code to memorize `old' expression values.
  296.       require
  297.      is_checked;
  298.       deferred
  299.       end;
  300.    
  301.    compile_to_jvm_into(dest: TYPE): INTEGER is
  302.      -- Assume `result_type' conforms to `dest'.
  303.      -- Produce Java byte code in order to convert the expression 
  304.      -- into `dest' (comparisons = and /=, argument passing and 
  305.      -- assignment).
  306.      -- Result gives the space in the JVM stack.
  307.       require
  308.      conversion_check(dest,result_type)
  309.       deferred
  310.       ensure
  311.      Result >= 1
  312.       end;
  313.  
  314. feature {NONE}
  315.  
  316.    frozen standard_compile_target_to_jvm is
  317.       local
  318.      rt: TYPE;
  319.       do
  320.      compile_to_jvm;
  321.      result_type.jvm_check_class_invariant;
  322.       end;
  323.  
  324.    frozen standard_compile_to_jvm_into(dest: TYPE): INTEGER is
  325.       require
  326.      conversion_check(dest,result_type)
  327.       do
  328.      compile_to_jvm;
  329.      Result := result_type.run_type.jvm_convert_to(dest);
  330.       ensure
  331.      Result >= 1
  332.       end;
  333.  
  334.    conversion_check(dest, rt: TYPE): BOOLEAN is
  335.       do
  336.      Result := true;
  337.      if rt.is_a(dest) then
  338.      else
  339.         eh.cancel;
  340.         if dest.is_a(rt) then
  341.         else
  342.            warning(start_position,
  343.                ". Impossible conversion (EXPRESSION).");
  344.         end;
  345.      end;
  346.       end;
  347.  
  348. feature
  349.  
  350.    compile_to_jvm_assignment(a: ASSIGNMENT) is
  351.      -- Current is the writable which is the left-hand-side
  352.      -- of `a'.
  353.       require
  354.      Current = a.left_side
  355.       deferred
  356.       end;
  357.    
  358.    jvm_branch_if_false: INTEGER is
  359.      -- Gives the `program_counter' to be resolved.
  360.       require
  361.      result_type.is_boolean
  362.       deferred
  363.       end;
  364.  
  365.    jvm_branch_if_true: INTEGER is
  366.      -- Gives the `program_counter' to be resolved.
  367.       require
  368.      result_type.is_boolean
  369.       deferred
  370.       end;
  371.    
  372.    jvm_assign is
  373.      -- Very basic assignment.
  374.      -- Assume that a JVM reference is on top of the stack and
  375.      -- that Current is the writable to assign with.
  376.       require
  377.      result_type.is_reference
  378.       deferred
  379.       end;
  380.  
  381. feature {NONE}
  382.  
  383.    frozen jvm_standard_branch_if_false: INTEGER is
  384.      -- Gives the `program_counter' to be resolved.
  385.       require
  386.      result_type.is_boolean
  387.       do
  388.      compile_to_jvm;
  389.      Result := code_attribute.opcode_ifeq;
  390.       end;
  391.    
  392.    frozen jvm_standard_branch_if_true: INTEGER is
  393.      -- Gives the `program_counter' to be resolved.
  394.       require
  395.      result_type.is_boolean
  396.       do
  397.      compile_to_jvm;
  398.      Result := code_attribute.opcode_ifne
  399.       end;
  400.    
  401. feature  -- Finding `int' Constant C expression :
  402.    
  403.    is_static: BOOLEAN is
  404.      -- True if expression has always the same static
  405.      -- value: INTEGER or BOOLEAN value is always the same 
  406.      -- or when reference is always the same (Void or the 
  407.      -- same manifest string for example).
  408.       require
  409.      is_checked;
  410.      small_eiffel.is_ready
  411.       deferred   
  412.       end;
  413.    
  414.    static_value: INTEGER is
  415.       require
  416.      is_static;
  417.      small_eiffel.is_ready
  418.       do
  419.      Result := static_value_mem;
  420.       end;
  421.    
  422.    to_integer: INTEGER is
  423.       require
  424.      is_checked;
  425.       do
  426.      error(start_position,fz_iinaiv);
  427.       end;
  428.  
  429. feature -- Pretty printing :
  430.    
  431.    pretty_print is
  432.      -- Start the `pretty_print' process.
  433.       require
  434.      fmt.indent_level >= 1;
  435.       deferred
  436.       ensure
  437.      fmt.indent_level = old fmt.indent_level;
  438.       end;
  439.    
  440.    print_as_target is
  441.      -- Print the expression viewed as a target plus the 
  442.      -- corresponding dot when it is necessary.
  443.       deferred
  444.       end;
  445.    
  446.    bracketed_pretty_print is
  447.      -- Add bracket only when it is necessary.
  448.       deferred
  449.       end;
  450.       
  451. feature -- For `short' :
  452.    
  453.    short is
  454.       deferred
  455.       end;
  456.  
  457.    short_target is
  458.      -- A target with the following dot if needed.
  459.       deferred
  460.       end;
  461.  
  462.    frozen bracketed_short is
  463.       do
  464.      short_print.hook_or("open_b","(");
  465.      short;
  466.      short_print.hook_or("close_b",")");
  467.       end;
  468.    
  469. feature {EXPRESSION,DECLARATION_LIST}
  470.    
  471.    set_current_type(ct: TYPE) is
  472.       do
  473.      current_type := ct;
  474.       ensure 
  475.      current_type = ct;
  476.       end;
  477.    
  478. end -- EXPRESSION
  479.  
  480.