Java Reference
In-Depth Information
11.3.5 Assignment
/
Visitor code for Marker 8
/
procedure
visit
(Assigning n )
lhsVisitor new LHSVisitor( this )
31
call n . getLHS( ) . accept( lhsVisitor )
32
call n . getRHS( ) . accept( this )
33
call lhsVisitor . emitStore( n . getRHS( ) . getResultLocal())
34
end
For most languages, evaluation of an assignment statement begins with its
left-hand side, which could involve function calls, field references, and array
index computations. In left-to-right evaluation order, those expressions must
be evaluated before the statement's right-hand side can be evaluated. A special
left-hand side (LHS) visitor is needed, because the name that is assigned by
the AST node refers to that name's location and not its value. That visitor
is constructed at Marker 31 , and the details of that visitor are discussed in
Section 11.4. The left-hand side visitor processes the subtree corresponding to
the assignment's left-hand side at Marker 32 .
Many VMs are assignment safe , in the sense that programs cannot modify
storage arbitrarily. To limit the impact of an assignment statement, some VMs
restrict the form of an assignment's left-hand side so that safety checks can
be performed at compile-time. For safety issues that cannot be checked at
compile-time, code is generated to perform the check at runtime. This distinc-
tion in meaning is best addressed by a specialized visitor. After Marker 32
finishes, all code for processing the left-hand side is generated, except the final
store instruction.
Next, the right-hand side of an assignment statement is an expression
whose code can be generated as usual by the code-generation visitor. Names
appearing on an assignment statement's right-hand side denote their value.
The code generated on behalf of a LocalReferencing, FieldReferencing or
ArrayReferencingAST node causes such values to be loaded into the appro-
priate resource (register or stack cell).
After both sides of the assignment have been processed, the appropriate
instruction is generated at Marker 34 to cause the value to be written to the
appropriate location.
 
 
Search WWH ::




Custom Search