Java Reference
In-Depth Information
AST
JVM Instructions
StaticReferencing
;
Instruction saved for later use:
putstatic
Ljava/io/PrintStream; java/lang/System/out
System.out
n
The box shows the instruction saved by Marker
59
for an assignment to the
static field out of the java.lang.System class.
/
Visitor code for Marker
56
/
procedure
visit
(FieldReferencing
n
)
call
n
.
getInstance()
.
accept(
valueVisitor
)
60
(
new
FieldStore(
n
.
getType(),
n
.
getName()))
call
set
S
tore
61
end
For a field reference, the instance containing the field must be evaluated first.
Marker
60
causes the relevant code to be generated by having the AST sub-
tree that represents the object instance accept the MethodBodyVisitor that was
captured at Marker
53
. The instruction for storing the field is then saved for
later use at Marker
61
.
AST
JVM Instructions
FieldReferencing
;
AST and code for storing the
name
;
field name from class MyClass:
;
;
n
o.name
;
;
Code generated for the instance
aload 4
LocalReferencing
o
;
Instruction saved for later use:
putfield Ljava/lang/String; MyClass/name
/
Visitor code for Marker
57
/
procedure
visit
(ArrayReferencing
n
)
call
n
.
getArray()
.
accept(
valueVisitor
)
62
call
n
.
getIndex()
.
accept(
valueVisitor
)
63
(
new
ArrayStore(
n
.
getArray()
.
getType( )))
call
set
S
tore
64
end