Java Reference
In-Depth Information
/
Visitor code for Marker
14
on page 302
/
procedure
visit
(ClassDeclaring
cd
)
typeRe f
←
new
TypeDescriptor(
ClassType
)
typeRe f
.
names
←
51
new
SymbolTable()
attr
←
new
Attributes(
ClassAttributes
)
attr
.
classType
←
typeRe f
call
currentSymbolTable
.
enterSymbol(
name
.
name
,
attr
)
call
set
C
urrent
C
lass
(
attr
)
if
null
then
cd
.
parentclass
← get
cd
.
parentclass
=
52
R
ef
T
o
O
bject
()
else
new
TypeVisitor()
call
cd
.
parentclass
.
accept(
typeVisitor
)
if
cd
.
parentclass
.
type
=
errorType
then
attr
.
classtype
←
errorType
else
typeVisitor
←
if
cd
.
parentclass
.
type
.
kind
classType
then
attr
.
classtype
←
errorType
call
error
(
parentClass
.
name
,
”
does not name a class
”)
else
typeRe f
.
parent
←
cd
.
parentClass
.
attributeRe f
typeRe f
.
isFinal
← member
53
O
f
(
cd
.
modi f iers
,
final )
typeRe f
.
isAbstractl
← member
O
f
(
cd
.
modi f iers
,
abstract )
call
typeRe f
.
names
.
incorporate(
cd
.
parentclass
.
type
.
names
)
call
54
open
S
cope
(
typeRe f
.
names
)
call
cd
.
fields
.
accept(
this
)
call
cd
.
constructors
.
accept(
this
)
call
cd
.
methods
.
accept(
this
)
call
close
55
S
cope
()
call
set
C
urrent
C
lass
(
null
)
end
Figure 8.29:
visit
method in TopDeclVisitor forClassDeclaring