4470
|
1 |
"{ Encoding: utf8 }"
|
|
2 |
|
2584
|
3 |
"{ Package: 'stx:libcomp' }"
|
|
4 |
|
3781
|
5 |
"{ NameSpace: Smalltalk }"
|
|
6 |
|
2584
|
7 |
Object subclass:#ParseNodeVisitor
|
|
8 |
instanceVariableNames:''
|
|
9 |
classVariableNames:''
|
|
10 |
poolDictionaries:''
|
|
11 |
category:'System-Compiler-Support'
|
|
12 |
!
|
|
13 |
|
4470
|
14 |
ParseNodeVisitor subclass:#ParseNodeChildCollector
|
|
15 |
instanceVariableNames:'topNode children'
|
|
16 |
classVariableNames:''
|
|
17 |
poolDictionaries:''
|
|
18 |
privateIn:ParseNodeVisitor
|
|
19 |
!
|
|
20 |
|
3781
|
21 |
!ParseNodeVisitor class methodsFor:'documentation'!
|
|
22 |
|
|
23 |
documentation
|
|
24 |
"
|
|
25 |
a whitebox expandable abstract parsenode visitor.
|
|
26 |
Subclasses should redefine those acceptXXX methods, in which they are interested.
|
|
27 |
"
|
|
28 |
! !
|
2584
|
29 |
|
4470
|
30 |
!ParseNodeVisitor class methodsFor:'utilities'!
|
|
31 |
|
|
32 |
collectChildrenOf:aNode
|
|
33 |
|collector|
|
|
34 |
|
|
35 |
collector := ParseNodeChildCollector new topNode:aNode.
|
|
36 |
aNode acceptVisitor:collector.
|
|
37 |
^ collector children
|
|
38 |
! !
|
|
39 |
|
2584
|
40 |
!ParseNodeVisitor methodsFor:'visiting'!
|
|
41 |
|
|
42 |
visit:anObject
|
4470
|
43 |
| stmt lastResult |
|
2584
|
44 |
|
4470
|
45 |
anObject isStatementNode ifTrue:[
|
|
46 |
stmt := anObject.
|
|
47 |
[ stmt isNil ] whileFalse:[
|
|
48 |
lastResult := stmt acceptVisitor:self.
|
|
49 |
stmt := stmt nextStatement.
|
|
50 |
].
|
|
51 |
^ lastResult
|
|
52 |
] ifFalse:[
|
|
53 |
^ anObject acceptVisitor: self.
|
|
54 |
]
|
2584
|
55 |
|
|
56 |
"Modified: / 25-07-2011 / 22:33:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
57 |
!
|
|
58 |
|
|
59 |
visitAssignmentNode:anObject
|
|
60 |
|
|
61 |
self visit: anObject variable.
|
|
62 |
self visit: anObject expression.
|
|
63 |
|
|
64 |
"Modified: / 25-07-2011 / 22:30:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
65 |
!
|
|
66 |
|
|
67 |
visitBinaryNode:anObject
|
|
68 |
|
|
69 |
^self visitMessageNode: anObject
|
|
70 |
|
|
71 |
"Modified: / 25-07-2011 / 22:30:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
72 |
!
|
|
73 |
|
|
74 |
visitBlockNode:anObject
|
|
75 |
|
|
76 |
anObject statements ifNotNil:[
|
|
77 |
self visit: anObject statements
|
|
78 |
].
|
|
79 |
|
|
80 |
"Modified: / 25-07-2011 / 22:45:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
81 |
!
|
|
82 |
|
|
83 |
visitCascadeNode:anObject
|
|
84 |
|
|
85 |
self visitMessageNode: anObject.
|
|
86 |
|
|
87 |
"Modified: / 25-07-2011 / 22:37:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
88 |
!
|
|
89 |
|
|
90 |
visitConstantNode:anObject
|
|
91 |
|
|
92 |
"Modified: / 25-07-2011 / 22:41:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
93 |
!
|
|
94 |
|
|
95 |
visitECompletionConstantNode:anObject
|
|
96 |
"dispatched back from the visited eCompletionConstantNode-object (visitor pattern)"
|
|
97 |
|
|
98 |
"fall back to general object-case - please change as required"
|
|
99 |
|
|
100 |
^ self visitObject:anObject
|
|
101 |
!
|
|
102 |
|
|
103 |
visitMessageNode:anObject
|
|
104 |
|
|
105 |
self visit: anObject receiver.
|
|
106 |
anObject arguments do:[:arg|
|
|
107 |
self visit: arg.
|
|
108 |
]
|
|
109 |
|
|
110 |
"Modified: / 25-07-2011 / 22:37:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
111 |
!
|
|
112 |
|
|
113 |
visitObject:anObject
|
|
114 |
"dispatched back from the visited objects (visitor pattern)"
|
|
115 |
|
|
116 |
"general fallBack - please change as required"
|
|
117 |
|
|
118 |
self halt:'not yet implemented'
|
|
119 |
!
|
|
120 |
|
|
121 |
visitParseErrorNode:anObject
|
|
122 |
|
|
123 |
"Modified: / 25-07-2011 / 22:38:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
124 |
!
|
|
125 |
|
|
126 |
visitPrimitiveNode:anObject
|
|
127 |
|
|
128 |
"Modified: / 25-07-2011 / 22:38:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
129 |
!
|
|
130 |
|
|
131 |
visitReturnNode:anObject
|
3807
|
132 |
self visit: anObject expression.
|
2584
|
133 |
!
|
|
134 |
|
3807
|
135 |
visitSelfNode:anObject
|
|
136 |
"/ to be redefined in subclasses
|
2584
|
137 |
!
|
|
138 |
|
|
139 |
visitStatementNode:anObject
|
3964
|
140 |
|expr|
|
|
141 |
|
|
142 |
(expr := anObject expression) notNil ifTrue:[
|
|
143 |
self visit: expr.
|
|
144 |
]
|
2584
|
145 |
!
|
|
146 |
|
3807
|
147 |
visitSuperNode:anObject
|
|
148 |
"/ to be redefined in subclasses
|
2584
|
149 |
!
|
|
150 |
|
|
151 |
visitUnaryNode:anObject
|
3807
|
152 |
^self visitMessageNode: anObject
|
2584
|
153 |
!
|
|
154 |
|
3807
|
155 |
visitVariableNode:anObject
|
|
156 |
"/ to be redefined in subclasses
|
2584
|
157 |
! !
|
|
158 |
|
4470
|
159 |
!ParseNodeVisitor methodsFor:'visiting - javaScript'!
|
|
160 |
|
|
161 |
visitFunctionCallNode:anObject
|
|
162 |
self visitMessageNode:anObject
|
|
163 |
!
|
|
164 |
|
|
165 |
visitImplicitFunctionCallNode:aNode
|
|
166 |
self visitFunctionCallNode:aNode
|
|
167 |
!
|
|
168 |
|
|
169 |
visitJavaScriptFunctionNode:aNode
|
|
170 |
|stmt|
|
|
171 |
|
|
172 |
stmt := aNode statements.
|
|
173 |
[ stmt notNil ] whileTrue:[
|
|
174 |
self visit:stmt.
|
|
175 |
stmt := stmt nextStatement.
|
|
176 |
].
|
|
177 |
!
|
|
178 |
|
|
179 |
visitJavaScriptStatementNode:aNode
|
|
180 |
self visitStatementNode:aNode
|
|
181 |
!
|
|
182 |
|
|
183 |
visitJavaScriptVariableNode:aNode
|
|
184 |
self visitVariableNode:aNode
|
|
185 |
!
|
|
186 |
|
|
187 |
visitThisNode:aNode
|
|
188 |
self visitSelfNode:aNode
|
|
189 |
! !
|
|
190 |
|
|
191 |
!ParseNodeVisitor::ParseNodeChildCollector class methodsFor:'documentation'!
|
|
192 |
|
|
193 |
documentation
|
|
194 |
"
|
|
195 |
documentation to be added.
|
|
196 |
|
|
197 |
class:
|
|
198 |
<a short class summary here, describing what instances represent>
|
|
199 |
|
|
200 |
responsibilities:
|
|
201 |
<describing what my main role is>
|
|
202 |
|
|
203 |
collaborators:
|
|
204 |
<describing with whom and how I talk to>
|
|
205 |
|
|
206 |
API:
|
|
207 |
<public api and main messages>
|
|
208 |
|
|
209 |
example:
|
|
210 |
<a one-line examples on how to use - can also be in a separate example method>
|
|
211 |
|
|
212 |
implementation:
|
|
213 |
<implementation points>
|
|
214 |
|
|
215 |
[author:]
|
|
216 |
exept MBP
|
|
217 |
|
|
218 |
[instance variables:]
|
|
219 |
|
|
220 |
[class variables:]
|
|
221 |
|
|
222 |
[see also:]
|
|
223 |
|
|
224 |
"
|
|
225 |
! !
|
|
226 |
|
|
227 |
!ParseNodeVisitor::ParseNodeChildCollector class methodsFor:'instance creation'!
|
|
228 |
|
|
229 |
new
|
|
230 |
"return an initialized instance"
|
|
231 |
|
|
232 |
^ self basicNew initialize.
|
|
233 |
! !
|
|
234 |
|
|
235 |
!ParseNodeVisitor::ParseNodeChildCollector methodsFor:'accessing'!
|
|
236 |
|
|
237 |
children
|
|
238 |
^ children
|
|
239 |
!
|
|
240 |
|
|
241 |
topNode:something
|
|
242 |
topNode := something.
|
|
243 |
! !
|
|
244 |
|
|
245 |
!ParseNodeVisitor::ParseNodeChildCollector methodsFor:'initialization'!
|
|
246 |
|
|
247 |
initialize
|
|
248 |
children := IdentitySet new.
|
|
249 |
! !
|
|
250 |
|
|
251 |
!ParseNodeVisitor::ParseNodeChildCollector methodsFor:'visiting'!
|
|
252 |
|
|
253 |
visit:anObject
|
|
254 |
anObject parent == topNode ifTrue:[
|
|
255 |
children add:anObject.
|
|
256 |
"/ do not go deeper
|
|
257 |
] ifFalse:[
|
|
258 |
super visit:anObject
|
|
259 |
].
|
|
260 |
! !
|
|
261 |
|
2584
|
262 |
!ParseNodeVisitor class methodsFor:'documentation'!
|
|
263 |
|
|
264 |
version
|
3781
|
265 |
^ '$Header$'
|
2584
|
266 |
!
|
|
267 |
|
|
268 |
version_CVS
|
3781
|
269 |
^ '$Header$'
|
2584
|
270 |
! !
|
3781
|
271 |
|