4542
|
1 |
"{ Encoding: utf8 }"
|
|
2 |
|
2584
|
3 |
"{ Package: 'stx:libcomp' }"
|
|
4 |
|
3781
|
5 |
"{ NameSpace: Smalltalk }"
|
|
6 |
|
2584
|
7 |
Object subclass:#ParseNodeVisitor
|
4542
|
8 |
instanceVariableNames:'pluggableActionsPerNodeType'
|
2584
|
9 |
classVariableNames:''
|
|
10 |
poolDictionaries:''
|
|
11 |
category:'System-Compiler-Support'
|
|
12 |
!
|
|
13 |
|
3781
|
14 |
!ParseNodeVisitor class methodsFor:'documentation'!
|
|
15 |
|
|
16 |
documentation
|
|
17 |
"
|
|
18 |
a whitebox expandable abstract parsenode visitor.
|
|
19 |
Subclasses should redefine those acceptXXX methods, in which they are interested.
|
|
20 |
"
|
|
21 |
! !
|
2584
|
22 |
|
4542
|
23 |
!ParseNodeVisitor methodsFor:'pluggable setup'!
|
|
24 |
|
|
25 |
actionForNodeClass:aNodeClass put:aBlock
|
|
26 |
"setup so that for nodes of type aNodeClass, aBlock is invoked.
|
|
27 |
If the block returns true, subnodes (eg. right side of assignments, etc.)
|
|
28 |
will be enumerated as well.
|
|
29 |
Otherwise, no subnodes are visited."
|
|
30 |
|
|
31 |
pluggableActionsPerNodeType isNil ifTrue:[
|
|
32 |
pluggableActionsPerNodeType := Dictionary new.
|
|
33 |
].
|
|
34 |
pluggableActionsPerNodeType at:aNodeClass put:aBlock
|
|
35 |
! !
|
|
36 |
|
2584
|
37 |
!ParseNodeVisitor methodsFor:'visiting'!
|
|
38 |
|
|
39 |
visit:anObject
|
4542
|
40 |
|action stmt lastResult|
|
|
41 |
|
|
42 |
action := pluggableActionsPerNodeType at:(anObject class) ifAbsent:[nil].
|
|
43 |
action notNil ifTrue:[
|
|
44 |
(action value:anObject) ifFalse:[^ self].
|
|
45 |
].
|
2584
|
46 |
|
4470
|
47 |
anObject isStatementNode ifTrue:[
|
|
48 |
stmt := anObject.
|
|
49 |
[ stmt isNil ] whileFalse:[
|
|
50 |
lastResult := stmt acceptVisitor:self.
|
|
51 |
stmt := stmt nextStatement.
|
|
52 |
].
|
|
53 |
^ lastResult
|
|
54 |
] ifFalse:[
|
|
55 |
^ anObject acceptVisitor: self.
|
|
56 |
]
|
2584
|
57 |
|
|
58 |
"Modified: / 25-07-2011 / 22:33:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
59 |
!
|
|
60 |
|
|
61 |
visitAssignmentNode:anObject
|
|
62 |
|
|
63 |
self visit: anObject variable.
|
|
64 |
self visit: anObject expression.
|
|
65 |
|
|
66 |
"Modified: / 25-07-2011 / 22:30:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
67 |
!
|
|
68 |
|
|
69 |
visitBinaryNode:anObject
|
|
70 |
|
|
71 |
^self visitMessageNode: anObject
|
|
72 |
|
|
73 |
"Modified: / 25-07-2011 / 22:30:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
74 |
!
|
|
75 |
|
|
76 |
visitBlockNode:anObject
|
|
77 |
|
|
78 |
anObject statements ifNotNil:[
|
|
79 |
self visit: anObject statements
|
|
80 |
].
|
|
81 |
|
|
82 |
"Modified: / 25-07-2011 / 22:45:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
83 |
!
|
|
84 |
|
|
85 |
visitCascadeNode:anObject
|
|
86 |
|
|
87 |
self visitMessageNode: anObject.
|
|
88 |
|
|
89 |
"Modified: / 25-07-2011 / 22:37:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
90 |
!
|
|
91 |
|
|
92 |
visitConstantNode:anObject
|
|
93 |
|
|
94 |
"Modified: / 25-07-2011 / 22:41:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
95 |
!
|
|
96 |
|
|
97 |
visitECompletionConstantNode:anObject
|
|
98 |
"dispatched back from the visited eCompletionConstantNode-object (visitor pattern)"
|
|
99 |
|
|
100 |
"fall back to general object-case - please change as required"
|
|
101 |
|
|
102 |
^ self visitObject:anObject
|
|
103 |
!
|
|
104 |
|
|
105 |
visitMessageNode:anObject
|
|
106 |
|
|
107 |
self visit: anObject receiver.
|
|
108 |
anObject arguments do:[:arg|
|
|
109 |
self visit: arg.
|
|
110 |
]
|
|
111 |
|
|
112 |
"Modified: / 25-07-2011 / 22:37:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
113 |
!
|
|
114 |
|
|
115 |
visitObject:anObject
|
|
116 |
"dispatched back from the visited objects (visitor pattern)"
|
|
117 |
|
|
118 |
"general fallBack - please change as required"
|
|
119 |
|
|
120 |
self halt:'not yet implemented'
|
|
121 |
!
|
|
122 |
|
|
123 |
visitParseErrorNode:anObject
|
|
124 |
|
|
125 |
"Modified: / 25-07-2011 / 22:38:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
126 |
!
|
|
127 |
|
|
128 |
visitPrimitiveNode:anObject
|
|
129 |
|
|
130 |
"Modified: / 25-07-2011 / 22:38:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
131 |
!
|
|
132 |
|
|
133 |
visitReturnNode:anObject
|
3807
|
134 |
self visit: anObject expression.
|
2584
|
135 |
!
|
|
136 |
|
3807
|
137 |
visitSelfNode:anObject
|
|
138 |
"/ to be redefined in subclasses
|
2584
|
139 |
!
|
|
140 |
|
|
141 |
visitStatementNode:anObject
|
3964
|
142 |
|expr|
|
|
143 |
|
|
144 |
(expr := anObject expression) notNil ifTrue:[
|
|
145 |
self visit: expr.
|
|
146 |
]
|
2584
|
147 |
!
|
|
148 |
|
3807
|
149 |
visitSuperNode:anObject
|
|
150 |
"/ to be redefined in subclasses
|
2584
|
151 |
!
|
|
152 |
|
|
153 |
visitUnaryNode:anObject
|
3807
|
154 |
^self visitMessageNode: anObject
|
2584
|
155 |
!
|
|
156 |
|
3807
|
157 |
visitVariableNode:anObject
|
|
158 |
"/ to be redefined in subclasses
|
2584
|
159 |
! !
|
|
160 |
|
4470
|
161 |
!ParseNodeVisitor methodsFor:'visiting - javaScript'!
|
|
162 |
|
4497
|
163 |
doesNotUnderstand:aMessage
|
|
164 |
"catch to prevent stupid error reports from Explainer in end-user app (expecco)"
|
|
165 |
|
|
166 |
Smalltalk isStandAloneApp ifTrue:[^ self].
|
|
167 |
"/ ((aMessage selector startsWith:'visit')
|
|
168 |
"/ and:[ aMessage selector endsWith:'Node:' ]) ifTrue:[
|
|
169 |
"/ ^ self.
|
|
170 |
"/ ].
|
|
171 |
^ super doesNotUnderstand:aMessage.
|
4470
|
172 |
! !
|
|
173 |
|
2584
|
174 |
!ParseNodeVisitor class methodsFor:'documentation'!
|
|
175 |
|
|
176 |
version
|
3781
|
177 |
^ '$Header$'
|
2584
|
178 |
!
|
|
179 |
|
|
180 |
version_CVS
|
3781
|
181 |
^ '$Header$'
|
2584
|
182 |
! !
|
3781
|
183 |
|