next up previous contents index
Next: Updates Up: Expression simplification Previous: Data structures   Contents   Index

Expression nodes

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:

The ``variable'' expressions defined here will be treated differently, according to whether they appear as the variable operand of an update, or anywhere else. A ``named expression'' is any expression with the syntax of one or more identifiers separated by periods.

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.


Table A.1: Direct accesses of various expression nodes, for simplify algorithm.

Expression node Direct uses Direct defs
Simple assignment with named expression on LHS   Variable descriptor (local or field) associated with LHS.
Simple assignment with field reference as LHS   Field descriptor associated with LHS.
Simple assignment with array element on LHS   ``All array elements''.
Compound assignment with named expression as LHS Variable descriptor (local or field) associated with LHS. Variable descriptor (local or field) associated with LHS.
Compound assignment with field reference as LHS Field descriptor associated with LHS. Field descriptor associated with LHS.
Compound assignment with array element on LHS ``All array elements''. ``All array elements''.
Autoincrement/decrement with named expression as operand Variable descriptor (local or field) associated with operand. Variable descriptor (local or field) associated with operand.
Autoincrement/decrement with field reference as operand Field descriptor associated with operand. Field descriptor associated with operand.
Autoincrement/decrement with array element as operand ``All array elements''. ``All array elements''.
Named expression, not the variable of an update. Variable descriptor (local or field) associated with named expression.  
Field reference, not the variable of an update. Field descriptor associated with field reference.  
Array element reference, not the variable of an update. ``All array elements''.  
Any method invocation ``All fields''; ``All array elements''. ``All fields''; ``All array elements''.
Class instance creation (named class) ``All fields''; ``All array elements''. ``All fields''; ``All array elements''.
Anonymous class instance creation ``All variables''. ``All fields''; ``All array elements''.


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 $l$ : $u$ : $s$ 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 ( $b\verb; ? ;x\verb; : ;y$), conditional ``and'' ($b\verb; && ;c$), and conditional ``or'' ($b\verb; \vert\vert ;c$). 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.


next up previous contents index
Next: Updates Up: Expression simplification Previous: Data structures   Contents   Index
Bryan Carpenter 2003-04-15