Java Reference
In-Depth Information
class NodeVisitor
procedure
( n )
foreach c n . getChildren() do call c . accept( this )
visit
C
hildren
end
end
class SemanticsVisitor extends NodeVisitor
/
This extends the class definition of Figure 9.26
/
procedure
visit
(Calling cn )
40
call
visit
C
hildren
( cn )
cn . calledMethod
null
methodSet ← get
M
ethods
( cn )
actualArgsType ← get
A
rg
T
ypes
( cn . args )
foreach de f methodSet do
if not
applicable
(
get
A
rgs
( de f . signature )
, actualArgsType )
then methodSet methodSet −{ de f }
if
size
( methodSet )
=
0
then call error
(” No method matches this call ”)
return
else
if
1
then methodSet ← filter
size
( methodSet )
>
D
efs
( methodSet )
if
size
( methodSet )
>
1
then call
error
(” More than one method matches this call ”)
else
Let m be the singleton member of methodSet
cn . calledMethod m
if cn . quali f ier
null and cn . quali f ier superNode and m . accessMode static
then call
error
(” Method called must be static ”)
else
if in
E
xpression
C
ontext
( cn ) and m . returnType = void
then call
error
(” Call must return a value ”)
end
end
Figure 9.34: Semantic Analysis Visitors (Part 4)
 
Search WWH ::




Custom Search