To apply the simplify algorithm we need to define the relevant sub-expressions of, and ``direct accesses'' in, the various kinds of expression node in the language. The non-trivial cases--the cases that have non-empty sets of direct accesses--are:
++, etc)
+=, etc)
Table A.1 gives suitable definitions for the ``direct accesses'' in these nodes. In these tables LHS stands for the left-hand-side operand of an assignment; RHS stands for the right-hand-side operand.
|
|
No other kinds of expression involve direct accesses, and most other
kinds of expression have reasonably obvious sub-expression lists.
For example, a binary
expression node has two subexpressions and no direct accesses;
a triplet subscript ![]()
: ![]()
:
contributes
three subexpressions to a section expression;
an (ordinary Java) array initializer term is treated as a kind of expression
with a variable number of subexpressions (and no direct accesses); etc, etc.
In the case of anonymous class instance creation, the algorithm only
treats constructor arguments as subexpressions; it does not treat the
class body as a subexpression. Instead the ``direct accesses'' conservatively
include all variables that could be used or modified in any anonymous
class body. Note that unlike a method invocation, the body of an
anonymous class can use local variables of the enclosing environment
(at least if the local variables have the final modifier).
There are a handful of expression types for which the generic
form of simplify in Figure A.1 is not
straightforwardly applicable. The first set of odd cases is the update
operations: simple assignments, increment and decrement operations,
and compound assignments. These are singled out because they must handle
variable expressions in a careful way. The second set is of odd cases is the
expressions with ``conditional evaluation''. These are: conditional expression
(
), conditional ``and'' (
),
and conditional ``or'' (
). These are special because
evaluation of some subexpressions is conditional on the results of
others. Computation of initialization expressions lifted from a
conditionally evaluated subexpression must be controlled by the same
condition that controls evaluation of the original subexpression.