home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / expression.e < prev    next >
Text File  |  1999-06-05  |  12KB  |  439 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 EXPRESSION
  17.    --
  18.    -- Any kind of Eiffel expression.
  19.    --
  20.  
  21. inherit GLOBALS;
  22.  
  23. feature
  24.  
  25.    start_position: POSITION is
  26.          -- Of the expression if any.
  27.       deferred
  28.       end;
  29.  
  30.    is_current: BOOLEAN is
  31.          -- Is it a `Current' like expression (really written 
  32.          -- `Current' or some implicit non-written `Current') ?
  33.       deferred
  34.       end;
  35.  
  36.    is_manifest_string: BOOLEAN is
  37.          -- Is it a manifest string ?
  38.       deferred
  39.       end;
  40.  
  41.    is_void: BOOLEAN is
  42.          -- Is it the built-in Void ?
  43.       deferred
  44.       end;
  45.  
  46.    is_result: BOOLEAN is
  47.          -- Is it the pseudo local variable `Result' ?
  48.       deferred
  49.       end;
  50.  
  51.    is_writable: BOOLEAN is
  52.          -- Is is something that one can find on the left-hand-side 
  53.          -- of the := operator ?
  54.       deferred
  55.       end;
  56.  
  57.    static_result_base_class: BASE_CLASS is
  58.          -- The static BASE_CLASS of the `result_type' (according to the
  59.          -- `start_position').
  60.          -- Void when it is too difficult to compute, when some error 
  61.          -- occurs or when this is the class NONE.
  62.       deferred
  63.       end;
  64.  
  65.    result_type: TYPE is
  66.          -- The `result_type' is available only when the expression 
  67.          -- has been checked (see `to_runnable').
  68.       deferred
  69.       ensure
  70.          Result /= Void
  71.       end;
  72.  
  73.    use_current: BOOLEAN is
  74.          -- True if `Current' is used.
  75.          -- As for `result_type', available only for checked expression.
  76.       require
  77.          small_eiffel.is_ready
  78.       deferred
  79.       end;
  80.  
  81.    to_runnable(ct: TYPE): like Current is
  82.          -- Gives the corresponding expression checked in `ct'.
  83.       require
  84.          ct.run_type = ct;
  85.          ct.run_class /= Void
  86.       deferred
  87.       ensure
  88.          nb_errors = 0 implies Result.result_type.is_run_type
  89.       end;
  90.  
  91. feature
  92.  
  93.    isa_dca_inline_argument: INTEGER is
  94.          -- Interpretation of the Result :
  95.          --    -1 : yes and no ARGUMENT_NAME used
  96.          --     0 : not inlinable
  97.          --   > 0 : inlinable and ARGUMENT_NAME rank is used.
  98.       require
  99.          run_control.boost and small_eiffel.is_ready
  100.       deferred
  101.       ensure
  102.          Result >= -1
  103.       end;
  104.  
  105.    dca_inline_argument(formal_arg_type: TYPE) is
  106.       require
  107.          formal_arg_type /= Void;
  108.          isa_dca_inline_argument /= 0
  109.       deferred
  110.       end;
  111.  
  112.    assertion_check(tag: CHARACTER) is
  113.          -- Assume the current code in inside some assertion (a
  114.          -- require clause or some class invariant for example)..
  115.          -- The `tag' mangling is :
  116.          --   'R' when we are inside some require clause.
  117.          --   'E' when we are inside some ensure clause.
  118.          --   '_' for all other assertions.
  119.          -- This flag is used to check VAPE and VEEN as well.
  120.       require
  121.          run_control.no_check;
  122.          ("RE_").has(tag)
  123.       deferred
  124.       end;
  125.  
  126. feature  -- Handling of precedence (priority of expressions) :
  127.  
  128.    precedence: INTEGER is
  129.       deferred
  130.       ensure
  131.          1 <= Result and Result <= atomic_precedence
  132.       end;
  133.  
  134. feature
  135.  
  136.    frozen add_comment(c: COMMENT): EXPRESSION is
  137.          -- Attach `c' to the receiver.
  138.       do
  139.          if c = Void or else c.count = 0 then
  140.             Result := Current;
  141.          else
  142.             !EXPRESSION_WITH_COMMENT!Result.make(Current,c);
  143.          end;
  144.       end;
  145.  
  146.    frozen base_class_written: BASE_CLASS is
  147.       do
  148.          Result := written_in.base_class;
  149.       end;
  150.  
  151.    frozen written_in: CLASS_NAME is
  152.          -- The name of the base class where the expression is
  153.          -- written if any.
  154.       local
  155.          sp: like start_position;
  156.       do
  157.          sp := start_position;
  158.          if sp /= Void then
  159.             Result := sp.base_class_name;
  160.          end;
  161.       end;
  162.  
  163.    afd_check is
  164.          -- After Falling Down Check.
  165.       deferred
  166.       end;
  167.  
  168. feature -- To produce C code :
  169.  
  170.    collect_c_tmp is
  171.          -- Traverse the expression to collect needed C tmp variables
  172.          -- just before `compile_to_c'.
  173.       require
  174.          small_eiffel.is_ready
  175.       deferred
  176.       end;
  177.  
  178.    compile_to_c is
  179.          -- Produce C code to access the value of the Current
  180.          -- expression : user's expanded are no longuer pointer.
  181.       require
  182.          small_eiffel.is_ready;
  183.          cpp.on_c
  184.       deferred
  185.       ensure
  186.          cpp.on_c
  187.       end;
  188.  
  189.    mapping_c_target(formal_type: TYPE) is
  190.          -- Produce C code in order to pass Current expression as
  191.          -- the target of a feature call.
  192.          -- When it is needed, C code to check invariant is
  193.          -- automatically added as well as a C cast according to
  194.          -- the destination `formal_type'.
  195.       require
  196.          small_eiffel.is_ready;
  197.          formal_type.at_run_time
  198.       deferred
  199.       end;
  200.  
  201.    mapping_c_arg(formal_arg_type: TYPE) is
  202.          -- Produce C code in order to pass Current expression as an
  203.          -- argument of the feature called.
  204.          -- Thus, it is the same jobs as `mapping_c_target' without
  205.          -- the invariant call.
  206.       require
  207.          small_eiffel.is_ready
  208.       deferred
  209.       end;
  210.  
  211.    c_declare_for_old is
  212.          -- Produce C code to declare `old' expression variables.
  213.       require
  214.          small_eiffel.is_ready;
  215.          cpp.on_c
  216.       deferred
  217.       ensure
  218.          cpp.on_c
  219.       end;
  220.  
  221.    compile_to_c_old is
  222.          -- Produce C code to memorize `old' expression values.
  223.       require
  224.          small_eiffel.is_ready;
  225.          cpp.on_c
  226.       deferred
  227.       ensure
  228.          cpp.on_c
  229.       end;
  230.  
  231. feature  -- To produce C code :
  232.  
  233.    c_simple: BOOLEAN is
  234.          -- True when the C code of `compile_c' has no side effect at
  235.          -- and `compile_to_c' on the corresponding simple expression
  236.          -- can be called more than once without any problem.
  237.       deferred
  238.       end;
  239.  
  240.    can_be_dropped: BOOLEAN is
  241.          -- True if evaluation of current expression has NO possible
  242.          -- side effects. Thus, in such a case, an unused expression
  243.          -- can be dropped (for example target of real procedure or
  244.          -- real function).
  245.       require
  246.          small_eiffel.is_ready
  247.       deferred
  248.       end;
  249.  
  250. feature  -- Finding `int' Constant C expression :
  251.  
  252.    is_static: BOOLEAN is
  253.          -- True if expression has always the same static
  254.          -- value: INTEGER or BOOLEAN value is always the same
  255.          -- or when reference is always the same (Void or the
  256.          -- same manifest string for example).
  257.       require
  258.          small_eiffel.is_ready
  259.       deferred
  260.       end;
  261.  
  262.    static_value: INTEGER is
  263.          -- Note: the result could be an EXPRESSION ... it seems
  264.          -- to be a good idea.
  265.       require
  266.          is_static
  267.       deferred
  268.       end;
  269.  
  270.    is_pre_computable: BOOLEAN is
  271.          -- Can the current expression be pre-computed in main
  272.          -- function to speed up a once function ?
  273.       require
  274.          small_eiffel.is_ready
  275.       deferred
  276.       end;
  277.  
  278. feature -- For `compile_to_jvm' :
  279.  
  280.    compile_to_jvm is
  281.          -- Produce Java byte code in order to push expression value
  282.          -- on the jvm stack.
  283.       require
  284.          small_eiffel.is_ready
  285.       deferred
  286.       end;
  287.  
  288.    compile_target_to_jvm is
  289.          -- Same as `compile_to_jvm', but add class invariant check
  290.          -- when needed.
  291.       require
  292.          small_eiffel.is_ready
  293.       deferred
  294.       end;
  295.  
  296.    compile_to_jvm_old is
  297.          -- Produce Java byte code to memorize `old' expression values.
  298.       require
  299.          small_eiffel.is_ready
  300.       deferred
  301.       end;
  302.  
  303.    compile_to_jvm_into(dest: TYPE): INTEGER is
  304.          -- Assume `result_type' conforms to `dest'.
  305.          -- Produce Java byte code in order to convert the expression
  306.          -- into `dest' (comparisons = and /=, argument passing and
  307.          -- assignment).
  308.          -- Result gives the space in the JVM stack.
  309.       require
  310.          conversion_check(dest,result_type)
  311.       deferred
  312.       ensure
  313.          Result >= 1
  314.       end;
  315.  
  316. feature {NONE}
  317.  
  318.    frozen standard_compile_target_to_jvm is
  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. feature
  335.  
  336.    conversion_check(dest, rt: TYPE): BOOLEAN is
  337.       do
  338.          Result := true;
  339.          if rt.is_a(dest) then
  340.          else
  341.             eh.cancel;
  342.             if dest.is_a(rt) then
  343.             else
  344.                warning(start_position,
  345.                 ". Impossible conversion (EXPRESSION).");
  346.             end;
  347.          end;
  348.       end;
  349.  
  350.    jvm_branch_if_false: INTEGER is
  351.          -- Gives the `program_counter' to be resolved.
  352.       require
  353.          result_type.is_boolean
  354.       deferred
  355.       end;
  356.  
  357.    jvm_branch_if_true: INTEGER is
  358.          -- Gives the `program_counter' to be resolved.
  359.       require
  360.          result_type.is_boolean
  361.       deferred
  362.       end;
  363.  
  364.    jvm_assign is
  365.          -- Basic assignment using value on top of stack.
  366.       require
  367.          is_writable
  368.       deferred
  369.       end;
  370.  
  371. feature {NONE}
  372.  
  373.    frozen jvm_standard_branch_if_false: INTEGER is
  374.          -- Gives the `program_counter' to be resolved.
  375.       require
  376.          result_type.is_boolean
  377.       do
  378.          compile_to_jvm;
  379.          Result := code_attribute.opcode_ifeq;
  380.       end;
  381.  
  382.    frozen jvm_standard_branch_if_true: INTEGER is
  383.          -- Gives the `program_counter' to be resolved.
  384.       require
  385.          result_type.is_boolean
  386.       do
  387.          compile_to_jvm;
  388.          Result := code_attribute.opcode_ifne
  389.       end;
  390.  
  391. feature
  392.  
  393.    to_integer: INTEGER is
  394.       do
  395.          error(start_position,fz_iinaiv);
  396.       end;
  397.  
  398. feature -- Pretty printing :
  399.  
  400.    pretty_print is
  401.          -- Start the `pretty_print' process.
  402.       require
  403.          fmt.indent_level >= 1;
  404.       deferred
  405.       ensure
  406.          fmt.indent_level = old fmt.indent_level;
  407.       end;
  408.  
  409.    print_as_target is
  410.          -- Print the expression viewed as a target plus the
  411.          -- corresponding dot when it is necessary.
  412.       deferred
  413.       end;
  414.  
  415.    bracketed_pretty_print is
  416.          -- Add bracket only when it is necessary.
  417.       deferred
  418.       end;
  419.  
  420. feature -- For `short' :
  421.  
  422.    short is
  423.       deferred
  424.       end;
  425.  
  426.    short_target is
  427.          -- A target with the following dot if needed.
  428.       deferred
  429.       end;
  430.  
  431.    frozen bracketed_short is
  432.       do
  433.          short_print.hook_or("open_b","(");
  434.          short;
  435.          short_print.hook_or("close_b",")");
  436.       end;
  437.  
  438. end -- EXPRESSION
  439.