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 |
|
4505
|
35 |
collector := self parseNodeChildCollectorClass new topNode:aNode.
|
4470
|
36 |
aNode acceptVisitor:collector.
|
|
37 |
^ collector children
|
4505
|
38 |
!
|
|
39 |
|
|
40 |
parseNodeChildCollectorClass
|
|
41 |
^ ParseNodeChildCollector
|
4470
|
42 |
! !
|
|
43 |
|
2584
|
44 |
!ParseNodeVisitor methodsFor:'visiting'!
|
|
45 |
|
|
46 |
visit:anObject
|
4470
|
47 |
| stmt lastResult |
|
2584
|
48 |
|
4470
|
49 |
anObject isStatementNode ifTrue:[
|
|
50 |
stmt := anObject.
|
|
51 |
[ stmt isNil ] whileFalse:[
|
|
52 |
lastResult := stmt acceptVisitor:self.
|
|
53 |
stmt := stmt nextStatement.
|
|
54 |
].
|
|
55 |
^ lastResult
|
|
56 |
] ifFalse:[
|
|
57 |
^ anObject acceptVisitor: self.
|
|
58 |
]
|
2584
|
59 |
|
|
60 |
"Modified: / 25-07-2011 / 22:33:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
61 |
!
|
|
62 |
|
|
63 |
visitAssignmentNode:anObject
|
|
64 |
|
|
65 |
self visit: anObject variable.
|
|
66 |
self visit: anObject expression.
|
|
67 |
|
|
68 |
"Modified: / 25-07-2011 / 22:30:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
69 |
!
|
|
70 |
|
|
71 |
visitBinaryNode:anObject
|
|
72 |
|
|
73 |
^self visitMessageNode: anObject
|
|
74 |
|
|
75 |
"Modified: / 25-07-2011 / 22:30:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
76 |
!
|
|
77 |
|
|
78 |
visitBlockNode:anObject
|
|
79 |
|
|
80 |
anObject statements ifNotNil:[
|
|
81 |
self visit: anObject statements
|
|
82 |
].
|
|
83 |
|
|
84 |
"Modified: / 25-07-2011 / 22:45:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
85 |
!
|
|
86 |
|
|
87 |
visitCascadeNode:anObject
|
|
88 |
|
|
89 |
self visitMessageNode: anObject.
|
|
90 |
|
|
91 |
"Modified: / 25-07-2011 / 22:37:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
92 |
!
|
|
93 |
|
|
94 |
visitConstantNode:anObject
|
|
95 |
|
|
96 |
"Modified: / 25-07-2011 / 22:41:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
97 |
!
|
|
98 |
|
|
99 |
visitECompletionConstantNode:anObject
|
|
100 |
"dispatched back from the visited eCompletionConstantNode-object (visitor pattern)"
|
|
101 |
|
|
102 |
"fall back to general object-case - please change as required"
|
|
103 |
|
|
104 |
^ self visitObject:anObject
|
|
105 |
!
|
|
106 |
|
|
107 |
visitMessageNode:anObject
|
|
108 |
|
|
109 |
self visit: anObject receiver.
|
|
110 |
anObject arguments do:[:arg|
|
|
111 |
self visit: arg.
|
|
112 |
]
|
|
113 |
|
|
114 |
"Modified: / 25-07-2011 / 22:37:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
115 |
!
|
|
116 |
|
|
117 |
visitObject:anObject
|
|
118 |
"dispatched back from the visited objects (visitor pattern)"
|
|
119 |
|
|
120 |
"general fallBack - please change as required"
|
|
121 |
|
|
122 |
self halt:'not yet implemented'
|
|
123 |
!
|
|
124 |
|
|
125 |
visitParseErrorNode:anObject
|
|
126 |
|
|
127 |
"Modified: / 25-07-2011 / 22:38:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
128 |
!
|
|
129 |
|
|
130 |
visitPrimitiveNode:anObject
|
|
131 |
|
|
132 |
"Modified: / 25-07-2011 / 22:38:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
133 |
!
|
|
134 |
|
|
135 |
visitReturnNode:anObject
|
3807
|
136 |
self visit: anObject expression.
|
2584
|
137 |
!
|
|
138 |
|
3807
|
139 |
visitSelfNode:anObject
|
|
140 |
"/ to be redefined in subclasses
|
2584
|
141 |
!
|
|
142 |
|
|
143 |
visitStatementNode:anObject
|
3964
|
144 |
|expr|
|
|
145 |
|
|
146 |
(expr := anObject expression) notNil ifTrue:[
|
|
147 |
self visit: expr.
|
|
148 |
]
|
2584
|
149 |
!
|
|
150 |
|
3807
|
151 |
visitSuperNode:anObject
|
|
152 |
"/ to be redefined in subclasses
|
2584
|
153 |
!
|
|
154 |
|
|
155 |
visitUnaryNode:anObject
|
3807
|
156 |
^self visitMessageNode: anObject
|
2584
|
157 |
!
|
|
158 |
|
3807
|
159 |
visitVariableNode:anObject
|
|
160 |
"/ to be redefined in subclasses
|
2584
|
161 |
! !
|
|
162 |
|
4470
|
163 |
!ParseNodeVisitor methodsFor:'visiting - javaScript'!
|
|
164 |
|
4497
|
165 |
doesNotUnderstand:aMessage
|
|
166 |
"catch to prevent stupid error reports from Explainer in end-user app (expecco)"
|
|
167 |
|
|
168 |
Smalltalk isStandAloneApp ifTrue:[^ self].
|
|
169 |
"/ ((aMessage selector startsWith:'visit')
|
|
170 |
"/ and:[ aMessage selector endsWith:'Node:' ]) ifTrue:[
|
|
171 |
"/ ^ self.
|
|
172 |
"/ ].
|
|
173 |
^ super doesNotUnderstand:aMessage.
|
4470
|
174 |
! !
|
|
175 |
|
|
176 |
!ParseNodeVisitor::ParseNodeChildCollector class methodsFor:'documentation'!
|
|
177 |
|
|
178 |
documentation
|
|
179 |
"
|
|
180 |
documentation to be added.
|
|
181 |
|
|
182 |
class:
|
|
183 |
<a short class summary here, describing what instances represent>
|
|
184 |
|
|
185 |
responsibilities:
|
|
186 |
<describing what my main role is>
|
|
187 |
|
|
188 |
collaborators:
|
|
189 |
<describing with whom and how I talk to>
|
|
190 |
|
|
191 |
API:
|
|
192 |
<public api and main messages>
|
|
193 |
|
|
194 |
example:
|
|
195 |
<a one-line examples on how to use - can also be in a separate example method>
|
|
196 |
|
|
197 |
implementation:
|
|
198 |
<implementation points>
|
|
199 |
|
|
200 |
[author:]
|
|
201 |
exept MBP
|
|
202 |
|
|
203 |
[instance variables:]
|
|
204 |
|
|
205 |
[class variables:]
|
|
206 |
|
|
207 |
[see also:]
|
|
208 |
|
|
209 |
"
|
|
210 |
! !
|
|
211 |
|
|
212 |
!ParseNodeVisitor::ParseNodeChildCollector class methodsFor:'instance creation'!
|
|
213 |
|
|
214 |
new
|
|
215 |
"return an initialized instance"
|
|
216 |
|
|
217 |
^ self basicNew initialize.
|
|
218 |
! !
|
|
219 |
|
|
220 |
!ParseNodeVisitor::ParseNodeChildCollector methodsFor:'accessing'!
|
|
221 |
|
|
222 |
children
|
|
223 |
^ children
|
|
224 |
!
|
|
225 |
|
|
226 |
topNode:something
|
|
227 |
topNode := something.
|
|
228 |
! !
|
|
229 |
|
|
230 |
!ParseNodeVisitor::ParseNodeChildCollector methodsFor:'initialization'!
|
|
231 |
|
|
232 |
initialize
|
|
233 |
children := IdentitySet new.
|
|
234 |
! !
|
|
235 |
|
|
236 |
!ParseNodeVisitor::ParseNodeChildCollector methodsFor:'visiting'!
|
|
237 |
|
|
238 |
visit:anObject
|
|
239 |
anObject parent == topNode ifTrue:[
|
|
240 |
children add:anObject.
|
|
241 |
"/ do not go deeper
|
|
242 |
] ifFalse:[
|
|
243 |
super visit:anObject
|
|
244 |
].
|
|
245 |
! !
|
|
246 |
|
2584
|
247 |
!ParseNodeVisitor class methodsFor:'documentation'!
|
|
248 |
|
|
249 |
version
|
3781
|
250 |
^ '$Header$'
|
2584
|
251 |
!
|
|
252 |
|
|
253 |
version_CVS
|
3781
|
254 |
^ '$Header$'
|
2584
|
255 |
! !
|
3781
|
256 |
|