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.21
/
29
procedure
visit
( Trying
tn
)
call
visit
C
hildren
(
tn
)
end
procedure
visit
(Catching
cn
)
30
if not
assignable
(
Throwable
,
cn
.
catchIdDecl
.
type
)
then
call
(”
Illegal type f or catch identi f ier
”)
cn
.
catchIdDecl
.
type
←
errorType
error
else
if
subsumes
L
ater
C
atches
(
cn
.
catchIdDecl
.
type
,
cn
.
more
)
then call
error
(”
This catch hides later catches
”)
call
()
attr
.
kind
←
variableAttributes
attr
.
variableType
←
cn
.
catchIdDecl
.
type
.
getTypeDescriptor()
call
currentSymbolTable
.
enterSymbol(
cn
.
catchIdDecl
.
ident
.
name
,
attr
)
call
cn
.
catchBody
.
accept(
this
)
call
open
S
cope
()
call
cn
.
more
.
accept(
this
)
close
S
cope
end
procedure
visit
(Throwing
tn
)
31
call
(
tn
)
if
tn
.
thrownVal
.
type
errorType
and not
visit
C
hildren
assignable
(
Throwable
,
tn
.
thrownVal
.
type
)
then call
error
(”
Illegal type f or throw
”)
end
end
Figure 9.26: Semantic Analysis Visitors (Part 3)