author | Claus Gittinger <cg@exept.de> |
Sun, 13 Oct 2019 23:31:57 +0200 | |
changeset 4582 | 120e83524d09 |
parent 4576 | 930ac289e158 |
child 4590 | 6b1123552ce1 |
permissions | -rw-r--r-- |
4541 | 1 |
"{ Encoding: utf8 }" |
2 |
||
0 | 3 |
" |
4 | 4 |
COPYRIGHT (c) 1989 by Claus Gittinger |
53 | 5 |
All Rights Reserved |
0 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
1044 | 14 |
"{ Package: 'stx:libcomp' }" |
15 |
||
3553 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
0 | 18 |
Object subclass:#ParseNode |
2550 | 19 |
instanceVariableNames:'parent type comments parenthized startPosition endPosition |
20 |
attributes' |
|
1046 | 21 |
classVariableNames:'' |
244
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
22 |
poolDictionaries:'' |
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
23 |
category:'System-Compiler-Support' |
0 | 24 |
! |
25 |
||
20 | 26 |
!ParseNode class methodsFor:'documentation'! |
27 |
||
28 |
copyright |
|
29 |
" |
|
30 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
53 | 31 |
All Rights Reserved |
20 | 32 |
|
33 |
This software is furnished under a license and may be used |
|
34 |
only in accordance with the terms of that license and with the |
|
35 |
inclusion of the above copyright notice. This software may not |
|
36 |
be provided or otherwise made available to, or used by, any |
|
37 |
other person. No title to or ownership of the software is |
|
38 |
hereby transferred. |
|
39 |
" |
|
40 |
! |
|
41 |
||
42 |
documentation |
|
43 |
" |
|
44 |
node for parse-trees; abstract class |
|
261 | 45 |
This is a helper class for the compiler. |
263 | 46 |
|
47 |
[author:] |
|
48 |
Claus Gittinger |
|
20 | 49 |
" |
50 |
! ! |
|
0 | 51 |
|
52 |
!ParseNode class methodsFor:'instance creation'! |
|
53 |
||
54 |
type:t |
|
55 |
^ (self basicNew) type:t |
|
56 |
! ! |
|
57 |
||
4471 | 58 |
!ParseNode methodsFor:'RBParser compatibility'! |
59 |
||
4534 | 60 |
bestNodeFor: anInterval |
61 |
(self intersectsInterval: anInterval) ifFalse: [^nil]. |
|
62 |
(self containedBy: anInterval) ifTrue: [^self]. |
|
63 |
||
64 |
self childrenDo:[:each | |
|
65 |
| node | |
|
66 |
node := each bestNodeFor: anInterval. |
|
67 |
node notNil ifTrue: [^node] |
|
68 |
]. |
|
69 |
^ nil |
|
70 |
! |
|
71 |
||
4471 | 72 |
children |
4506 | 73 |
|children| |
74 |
||
75 |
children := OrderedCollection new. |
|
76 |
self childrenDo:[:each | |
|
77 |
self assert:(each notNil). |
|
78 |
children add:each |
|
79 |
]. |
|
80 |
^ children. |
|
81 |
! |
|
82 |
||
83 |
childrenDo:aBlock |
|
84 |
^ self |
|
4471 | 85 |
! |
86 |
||
4522 | 87 |
containedBy:anInterval |
88 |
"true if the interval contains me completely" |
|
89 |
||
4471 | 90 |
startPosition isNil ifTrue:[^ false]. |
91 |
endPosition isNil ifTrue:[^ false]. |
|
92 |
^ anInterval first <= startPosition and:[anInterval last >= endPosition] |
|
93 |
! |
|
94 |
||
95 |
intersectsInterval: anInterval |
|
96 |
|myStart myStop ivStart ivStop| |
|
97 |
||
98 |
myStart := startPosition. |
|
99 |
myStop := endPosition. |
|
100 |
ivStart := anInterval first. |
|
101 |
ivStop := anInterval last. |
|
102 |
(myStart notNil and:[ivStop < myStart]) ifTrue:[^ false]. |
|
103 |
(myStop notNil and:[ivStart > myStop]) ifTrue:[^ false]. |
|
104 |
^ true |
|
105 |
! |
|
106 |
||
107 |
nodesDo:aBlock |
|
108 |
aBlock value: self. |
|
109 |
self children do: [:each | each nodesDo: aBlock] |
|
110 |
! |
|
111 |
||
112 |
start |
|
113 |
"for RBToken compat." |
|
114 |
||
115 |
^ self startPosition |
|
116 |
! |
|
117 |
||
118 |
whichNodeIntersects: anInterval |
|
119 |
| selectedChildren nChildren | |
|
120 |
||
121 |
(self intersectsInterval: anInterval) ifFalse: [^nil]. |
|
122 |
||
123 |
selectedChildren := self children select:[:each | |
|
124 |
each intersectsInterval: anInterval |
|
125 |
]. |
|
126 |
||
127 |
nChildren := selectedChildren size. |
|
128 |
nChildren == 0 ifTrue:[ |
|
129 |
^ self "/ I intersect |
|
130 |
]. |
|
131 |
nChildren == 1 ifTrue:[ |
|
132 |
^ selectedChildren first whichNodeIntersects: anInterval |
|
133 |
]. |
|
134 |
"/ self halt:'should this happen ?'. |
|
135 |
^ self "/ I intersect |
|
136 |
! |
|
137 |
||
4522 | 138 |
whichNodeIsContainedBy:anInterval |
139 |
|firstChildInInterval| |
|
4471 | 140 |
|
141 |
(self intersectsInterval: anInterval) ifFalse: [^nil]. |
|
142 |
(self containedBy: anInterval) ifTrue: [^self]. |
|
143 |
||
4522 | 144 |
self childrenDo:[:each | |
145 |
(each intersectsInterval:anInterval) ifTrue:[ |
|
146 |
firstChildInInterval notNil ifTrue:[ |
|
147 |
"/ ouch: multiple children in interval |
|
148 |
^ self |
|
149 |
]. |
|
150 |
firstChildInInterval := each |
|
151 |
]. |
|
152 |
]. |
|
153 |
||
154 |
firstChildInInterval isNil ifTrue:[ |
|
155 |
"/ no children in interval; so it must be me |
|
4506 | 156 |
^ self |
157 |
]. |
|
4522 | 158 |
"/ look deeper |
159 |
^ firstChildInInterval whichNodeIsContainedBy:anInterval. |
|
4471 | 160 |
! ! |
161 |
||
2819 | 162 |
!ParseNode methodsFor:'accessing'! |
2694 | 163 |
|
2819 | 164 |
enclosingBlock |
165 |
"Return closest enclosing block node or nil" |
|
166 |
||
167 |
| block | |
|
168 |
block := parent. |
|
3485 | 169 |
[ block notNil and:[block realNode isBlockNode not] ] whileTrue:[ |
170 |
block := block realNode parent. |
|
2819 | 171 |
]. |
172 |
^block. |
|
173 |
||
174 |
"Created: / 16-02-2012 / 22:46:12 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
175 |
! |
|
140 | 176 |
|
2505 | 177 |
endPosition |
3542 | 178 |
"the node's last character position in the original source" |
179 |
||
2505 | 180 |
^ endPosition |
181 |
! |
|
182 |
||
2265 | 183 |
endPosition:aCharacterPosition |
4506 | 184 |
self assert:aCharacterPosition >= 1. |
2505 | 185 |
|
186 |
endPosition := aCharacterPosition |
|
187 |
||
2618
256319b44ac8
More fixes for start/end position
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2564
diff
changeset
|
188 |
"Modified: / 28-07-2011 / 10:03:53 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2265 | 189 |
! |
190 |
||
2548 | 191 |
line |
192 |
||
193 |
"Compatibility" |
|
194 |
||
195 |
^self lineNumber |
|
196 |
||
197 |
"Created: / 09-07-2011 / 22:30:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
198 |
! |
|
199 |
||
200 |
lineNumber |
|
201 |
||
202 |
^nil |
|
203 |
||
204 |
"Created: / 09-07-2011 / 22:30:57 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
205 |
! |
|
206 |
||
140 | 207 |
lineNumber:dummy |
208 |
"set linenumber - ignored here" |
|
209 |
||
210 |
^ self |
|
211 |
! |
|
212 |
||
2550 | 213 |
parent |
214 |
||
215 |
^parent |
|
216 |
||
217 |
"Created: / 11-07-2011 / 17:36:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
218 |
! |
|
219 |
||
220 |
parent: aParseNode |
|
221 |
||
222 |
parent := aParseNode |
|
223 |
||
224 |
"Created: / 11-07-2011 / 17:36:33 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
225 |
! |
|
226 |
||
1990
ede012b2bd5b
oops - parenthesized was written with typo
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
227 |
parenthesized |
ede012b2bd5b
oops - parenthesized was written with typo
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
228 |
^ parenthized ? false |
ede012b2bd5b
oops - parenthesized was written with typo
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
229 |
! |
ede012b2bd5b
oops - parenthesized was written with typo
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
230 |
|
ede012b2bd5b
oops - parenthesized was written with typo
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
231 |
parenthesized:aBoolean |
ede012b2bd5b
oops - parenthesized was written with typo
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
232 |
parenthized := aBoolean |
ede012b2bd5b
oops - parenthesized was written with typo
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
233 |
! |
ede012b2bd5b
oops - parenthesized was written with typo
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
234 |
|
140 | 235 |
parenthized |
1990
ede012b2bd5b
oops - parenthesized was written with typo
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
236 |
"obsolete - typo in message name - use parenthesized" |
ede012b2bd5b
oops - parenthesized was written with typo
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
237 |
|
1338 | 238 |
^ parenthized ? false |
140 | 239 |
! |
240 |
||
241 |
parenthized:aBoolean |
|
1990
ede012b2bd5b
oops - parenthesized was written with typo
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
242 |
"obsolete - typo in message name - use parenthesized:" |
ede012b2bd5b
oops - parenthesized was written with typo
Claus Gittinger <cg@exept.de>
parents:
1804
diff
changeset
|
243 |
|
140 | 244 |
parenthized := aBoolean |
245 |
! |
|
246 |
||
3483 | 247 |
realNode |
248 |
^ self |
|
249 |
! |
|
250 |
||
3300 | 251 |
selectorPartPositions:selectorPartPositions |
252 |
"/ ignored here, but implemented because sent without checking |
|
253 |
"/ when parsing keyword messages to an optimized messageNode |
|
254 |
"/ (which become optimized to a constantNode by the folder) |
|
255 |
||
256 |
"Created: / 28-08-2013 / 21:17:22 / cg" |
|
257 |
! |
|
258 |
||
598 | 259 |
selectorPosition:aCharacterPosition |
260 |
"ignored here" |
|
261 |
||
262 |
"Created: 5.8.1997 / 16:32:17 / cg" |
|
263 |
! |
|
264 |
||
2505 | 265 |
startPosition |
3542 | 266 |
"the node's character position in the original source" |
267 |
||
2505 | 268 |
^ startPosition |
269 |
! |
|
270 |
||
2550 | 271 |
startPosition:start |
4506 | 272 |
self assert:start > 0. |
2550 | 273 |
startPosition := start |
2505 | 274 |
|
275 |
"Modified: / 08-04-2011 / 22:03:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2265 | 276 |
! |
277 |
||
4506 | 278 |
startPosition:start endPosition:end |
279 |
(start == -1 and:[end == -1]) ifTrue:[ |
|
280 |
"/ a synthetic node |
|
281 |
"/ self halt. |
|
282 |
] ifFalse:[ |
|
4522 | 283 |
"/ nil end means: up-to-end (but only for error nodes) |
4524 | 284 |
self assert:(start notNil and:[start > 0]). |
4522 | 285 |
end isNil ifTrue:[ |
286 |
self assert:(self isErrorNode) |
|
287 |
] ifFalse:[ |
|
288 |
self assert:(end >= start). |
|
289 |
]. |
|
4506 | 290 |
]. |
2550 | 291 |
startPosition := start. |
2564
43f35a40884d
- parse tree nodes are no longer shared
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2550
diff
changeset
|
292 |
endPosition := end. |
2550 | 293 |
|
294 |
"Created: / 11-07-2011 / 17:44:11 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
4352 | 295 |
"Modified: / 15-02-2019 / 14:39:10 / Claus Gittinger" |
2550 | 296 |
! |
297 |
||
140 | 298 |
type |
299 |
"return the nodes type" |
|
300 |
||
301 |
^ type |
|
302 |
! ! |
|
303 |
||
4471 | 304 |
|
2546
5ae96e911e36
ParseNode: added attributes instvar for other tools to store
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2533
diff
changeset
|
305 |
!ParseNode methodsFor:'attributes access'! |
5ae96e911e36
ParseNode: added attributes instvar for other tools to store
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2533
diff
changeset
|
306 |
|
5ae96e911e36
ParseNode: added attributes instvar for other tools to store
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2533
diff
changeset
|
307 |
objectAttributes |
5ae96e911e36
ParseNode: added attributes instvar for other tools to store
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2533
diff
changeset
|
308 |
|
5ae96e911e36
ParseNode: added attributes instvar for other tools to store
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2533
diff
changeset
|
309 |
^attributes |
5ae96e911e36
ParseNode: added attributes instvar for other tools to store
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2533
diff
changeset
|
310 |
|
5ae96e911e36
ParseNode: added attributes instvar for other tools to store
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2533
diff
changeset
|
311 |
"Created: / 09-07-2011 / 12:17:55 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
5ae96e911e36
ParseNode: added attributes instvar for other tools to store
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2533
diff
changeset
|
312 |
! |
5ae96e911e36
ParseNode: added attributes instvar for other tools to store
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2533
diff
changeset
|
313 |
|
5ae96e911e36
ParseNode: added attributes instvar for other tools to store
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2533
diff
changeset
|
314 |
objectAttributes: anObject |
5ae96e911e36
ParseNode: added attributes instvar for other tools to store
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2533
diff
changeset
|
315 |
|
5ae96e911e36
ParseNode: added attributes instvar for other tools to store
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2533
diff
changeset
|
316 |
attributes := anObject |
5ae96e911e36
ParseNode: added attributes instvar for other tools to store
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2533
diff
changeset
|
317 |
|
5ae96e911e36
ParseNode: added attributes instvar for other tools to store
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2533
diff
changeset
|
318 |
"Created: / 09-07-2011 / 12:18:08 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
5ae96e911e36
ParseNode: added attributes instvar for other tools to store
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2533
diff
changeset
|
319 |
! ! |
5ae96e911e36
ParseNode: added attributes instvar for other tools to store
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2533
diff
changeset
|
320 |
|
140 | 321 |
!ParseNode methodsFor:'checks'! |
322 |
||
2095 | 323 |
plausibilityCheckIn:aParser |
140 | 324 |
^ nil |
325 |
! ! |
|
326 |
||
327 |
!ParseNode methodsFor:'code generation'! |
|
328 |
||
329 |
codeForSideEffectOn:aStream inBlock:b for:aCompiler |
|
330 |
"generate code for this statement - value not needed" |
|
331 |
||
4548 | 332 |
self codeThenDropOn:aStream inBlock:b for:aCompiler |
373 | 333 |
! |
334 |
||
843
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
335 |
codeForSimpleReturnOn:aStream inBlock:b lineNumber:lineNrOrNil for:aCompiler |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
336 |
"generate code to return myself as a simple method return" |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
337 |
|
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
338 |
self codeOn:aStream inBlock:b for:aCompiler. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
339 |
lineNrOrNil notNil ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
340 |
self codeLineNumber:lineNrOrNil on:aStream for:aCompiler |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
341 |
]. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
342 |
aStream nextPut:#retTop. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
343 |
|
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
344 |
|
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
345 |
! |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
346 |
|
1056 | 347 |
codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
348 |
"generate code for this statement - value is needed" |
|
349 |
||
350 |
self codeOn:aStream inBlock:b for:aCompiler. |
|
351 |
! |
|
352 |
||
3165
7894a735faac
Emit #lineno16 byte codes only, if line number really changes
Stefan Vogel <sv@exept.de>
parents:
3110
diff
changeset
|
353 |
codeLineNumber:nr on:codeStream for:aCompiler |
373 | 354 |
"generate lineNumber information" |
355 |
||
3165
7894a735faac
Emit #lineno16 byte codes only, if line number really changes
Stefan Vogel <sv@exept.de>
parents:
3110
diff
changeset
|
356 |
aCompiler codeLineNumber:nr on:codeStream |
2029 | 357 |
! |
358 |
||
359 |
codeOn:aStream inBlock:codeBlock for:aCompiler |
|
360 |
^ self subclassResponsibility |
|
4548 | 361 |
! |
362 |
||
363 |
codeThenDropOn:aStream inBlock:b for:aCompiler |
|
364 |
"generate code for this statement - value not needed" |
|
365 |
||
366 |
self codeOn:aStream inBlock:b for:aCompiler. |
|
367 |
aStream nextPut:#drop |
|
140 | 368 |
! ! |
369 |
||
1804
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
370 |
!ParseNode methodsFor:'code generation helpers'! |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
371 |
|
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
372 |
emitPushGlobalWithLiteralIndex:litIndex on:aTokenCodeStream for:aCompiler |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
373 |
litIndex <= 255 ifTrue:[ |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
374 |
aTokenCodeStream nextPut:#pushGlobalS; nextPut:litIndex |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
375 |
] ifFalse:[ |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
376 |
litIndex <= 16rFFFF ifTrue:[ |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
377 |
aTokenCodeStream nextPut:#pushGlobalL; nextPut:litIndex; nextPut:0 |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
378 |
] ifFalse:[ |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
379 |
aTokenCodeStream nextPut:#pushGlobalVL; nextPut:0; nextPut:litIndex; nextPut:0; nextPut:0; nextPut:0 |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
380 |
]. |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
381 |
]. |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
382 |
! |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
383 |
|
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
384 |
emitPushLiteral:value on:aTokenCodeStream for:aCompiler |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
385 |
|index| |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
386 |
|
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
387 |
index := aCompiler addLiteral:value. |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
388 |
self emitPushLiteralIndex:index on:aTokenCodeStream for:aCompiler |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
389 |
! |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
390 |
|
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
391 |
emitPushLiteralIndex:index on:aTokenCodeStream for:aCompiler |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
392 |
index <= 8 ifTrue:[ |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
393 |
aTokenCodeStream |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
394 |
nextPut:(#(pushLit1 pushLit2 pushLit3 pushLit4 |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
395 |
pushLit5 pushLit6 pushLit7 pushLit8) at:index). |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
396 |
] ifFalse:[ |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
397 |
index <= 255 ifTrue:[ |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
398 |
aTokenCodeStream nextPut:#pushLitS; nextPut:index |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
399 |
] ifFalse:[ |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
400 |
index <= 16rFFFF ifTrue:[ |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
401 |
aTokenCodeStream nextPut:#pushLitL; nextPut:index; nextPut:0 |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
402 |
] ifFalse:[ |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
403 |
aTokenCodeStream nextPut:#pushLitVL; nextPut:0; nextPut:index; nextPut:0; nextPut:0; nextPut:0 |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
404 |
] |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
405 |
]. |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
406 |
]. |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
407 |
! |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
408 |
|
3165
7894a735faac
Emit #lineno16 byte codes only, if line number really changes
Stefan Vogel <sv@exept.de>
parents:
3110
diff
changeset
|
409 |
emitSendLiteralIndex:litIndex numArgs:nargs line:lineNr on:aStream for:aCompiler |
3110
f517641d3673
Emit LINE16 bytecode insn just before a SEND bytecode is emmited when
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2862
diff
changeset
|
410 |
lineNr >= 255 ifTrue:[ |
3165
7894a735faac
Emit #lineno16 byte codes only, if line number really changes
Stefan Vogel <sv@exept.de>
parents:
3110
diff
changeset
|
411 |
self codeLineNumber: lineNr on: aStream for:aCompiler. |
3110
f517641d3673
Emit LINE16 bytecode insn just before a SEND bytecode is emmited when
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2862
diff
changeset
|
412 |
]. |
1804
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
413 |
(litIndex <= 255) ifTrue:[ |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
414 |
nargs <= 3 ifTrue:[ |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
415 |
aStream |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
416 |
nextPut:(#(send0 send1 send2 send3) at:(nargs+1)); nextPut:lineNr; |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
417 |
nextPut:litIndex. |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
418 |
^ self. |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
419 |
]. |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
420 |
aStream |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
421 |
nextPut:#send; nextPut:lineNr; |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
422 |
nextPut:litIndex; |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
423 |
nextPut:nargs. |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
424 |
^ self. |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
425 |
]. |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
426 |
|
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
427 |
(litIndex <= 16rFFFF) ifTrue:[ |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
428 |
aStream |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
429 |
nextPut:#sendL; nextPut:lineNr; |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
430 |
nextPut:litIndex; nextPut:0; |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
431 |
nextPut:nargs. |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
432 |
^ self. |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
433 |
]. |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
434 |
|
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
435 |
aStream |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
436 |
nextPut:#sendVL; nextPut:0; nextPut:lineNr; |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
437 |
nextPut:litIndex; nextPut:0; nextPut:0; nextPut:0; |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
438 |
nextPut:nargs. |
3110
f517641d3673
Emit LINE16 bytecode insn just before a SEND bytecode is emmited when
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2862
diff
changeset
|
439 |
|
f517641d3673
Emit LINE16 bytecode insn just before a SEND bytecode is emmited when
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2862
diff
changeset
|
440 |
"Modified: / 13-04-2013 / 11:02:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1804
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
441 |
! |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
442 |
|
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
443 |
emitStoreGlobalWithLiteralIndex:litIndex on:aTokenCodeStream for:aCompiler |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
444 |
litIndex <= 255 ifTrue:[ |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
445 |
aTokenCodeStream nextPut:#storeGlobalS; nextPut:litIndex |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
446 |
] ifFalse:[ |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
447 |
litIndex <= 16rFFFF ifTrue:[ |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
448 |
aTokenCodeStream nextPut:#storeGlobalL; nextPut:litIndex; nextPut:0 |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
449 |
] ifFalse:[ |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
450 |
aTokenCodeStream nextPut:#storeGlobalVL; nextPut:0; nextPut:litIndex; nextPut:0; nextPut:0; nextPut:0; nextPut:0 |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
451 |
]. |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
452 |
]. |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
453 |
! |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
454 |
|
3165
7894a735faac
Emit #lineno16 byte codes only, if line number really changes
Stefan Vogel <sv@exept.de>
parents:
3110
diff
changeset
|
455 |
emitSuperSendLiteralIndex:litIndex classLiteralIndex:clsLitIndex numArgs:nargs line:lineNr on:aStream for:aCompiler |
3110
f517641d3673
Emit LINE16 bytecode insn just before a SEND bytecode is emmited when
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2862
diff
changeset
|
456 |
lineNr >= 255 ifTrue:[ |
3165
7894a735faac
Emit #lineno16 byte codes only, if line number really changes
Stefan Vogel <sv@exept.de>
parents:
3110
diff
changeset
|
457 |
self codeLineNumber: lineNr on: aStream for:aCompiler. |
3110
f517641d3673
Emit LINE16 bytecode insn just before a SEND bytecode is emmited when
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2862
diff
changeset
|
458 |
]. |
1804
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
459 |
(litIndex <= 255 and:[clsLitIndex <= 255]) ifTrue:[ |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
460 |
aStream |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
461 |
nextPut:#superSend; nextPut:lineNr; |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
462 |
nextPut:litIndex; |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
463 |
nextPut:nargs; |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
464 |
nextPut:clsLitIndex. |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
465 |
] ifFalse:[ |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
466 |
(litIndex <= 16rFFFF and:[clsLitIndex <= 16rFFFF]) ifTrue:[ |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
467 |
aStream |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
468 |
nextPut:#superSendL; nextPut:lineNr; |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
469 |
nextPut:litIndex; nextPut:0; |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
470 |
nextPut:nargs; |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
471 |
nextPut:clsLitIndex; nextPut:0. |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
472 |
] ifFalse:[ |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
473 |
aStream |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
474 |
nextPut:#superSendVL; nextPut:0; nextPut:lineNr; |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
475 |
nextPut:litIndex; nextPut:0; nextPut:0; nextPut:0; |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
476 |
nextPut:nargs; |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
477 |
nextPut:clsLitIndex; nextPut:0; nextPut:0; nextPut:0. |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
478 |
]. |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
479 |
]. |
3110
f517641d3673
Emit LINE16 bytecode insn just before a SEND bytecode is emmited when
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2862
diff
changeset
|
480 |
|
f517641d3673
Emit LINE16 bytecode insn just before a SEND bytecode is emmited when
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2862
diff
changeset
|
481 |
"Modified: / 13-04-2013 / 11:01:51 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1804
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
482 |
! ! |
7c22dbaa8d10
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1725
diff
changeset
|
483 |
|
1503 | 484 |
!ParseNode methodsFor:'enumeration'! |
485 |
||
4576 | 486 |
allMessageSelectorsDo:aBlock |
487 |
"evaluate aBlock for each message-node here and in subnodes" |
|
488 |
||
489 |
^ self messageSelectorsDo:aBlock |
|
490 |
! |
|
491 |
||
492 |
allMessagesDo:aBlock |
|
493 |
"evaluate aBlock for each message-node here and in subnodes" |
|
494 |
||
495 |
^ self messagesDo:aBlock |
|
496 |
! |
|
497 |
||
3337 | 498 |
allNodesDo:aBlock |
499 |
"evaluate aBlock for each variable-node here and in subnodes" |
|
500 |
||
4232 | 501 |
aBlock value:self. |
502 |
self allSubNodesDo:aBlock. |
|
503 |
! |
|
504 |
||
505 |
allSubNodesDo:aBlock |
|
4234 | 506 |
"/ self subclassResponsibility. |
3337 | 507 |
! |
508 |
||
3275
921a8afad859
renamed messagesDo: to messageNodes: do
Claus Gittinger <cg@exept.de>
parents:
3184
diff
changeset
|
509 |
messageNodesDo:aBlock |
921a8afad859
renamed messagesDo: to messageNodes: do
Claus Gittinger <cg@exept.de>
parents:
3184
diff
changeset
|
510 |
"evaluate aBlock for each message-node here and in subnodes" |
921a8afad859
renamed messagesDo: to messageNodes: do
Claus Gittinger <cg@exept.de>
parents:
3184
diff
changeset
|
511 |
|
3315 | 512 |
self messagesDo:aBlock |
3275
921a8afad859
renamed messagesDo: to messageNodes: do
Claus Gittinger <cg@exept.de>
parents:
3184
diff
changeset
|
513 |
! |
921a8afad859
renamed messagesDo: to messageNodes: do
Claus Gittinger <cg@exept.de>
parents:
3184
diff
changeset
|
514 |
|
3276 | 515 |
messageSelectors |
3337 | 516 |
"return a collection of message selectors" |
3276 | 517 |
|
518 |
|setOfSymbols| |
|
519 |
||
520 |
setOfSymbols := Set new. |
|
3279 | 521 |
self messageSelectorsDo:[:each | setOfSymbols add:each ]. |
3276 | 522 |
^ setOfSymbols |
523 |
! |
|
524 |
||
3279 | 525 |
messageSelectorsDo:aBlock |
526 |
"evaluate aBlock for each message-selector here and in subnodes" |
|
527 |
||
528 |
^ self |
|
529 |
! |
|
530 |
||
3275
921a8afad859
renamed messagesDo: to messageNodes: do
Claus Gittinger <cg@exept.de>
parents:
3184
diff
changeset
|
531 |
messages |
3276 | 532 |
"return a collection of messageNodes" |
533 |
||
3275
921a8afad859
renamed messagesDo: to messageNodes: do
Claus Gittinger <cg@exept.de>
parents:
3184
diff
changeset
|
534 |
|setOfMessages| |
921a8afad859
renamed messagesDo: to messageNodes: do
Claus Gittinger <cg@exept.de>
parents:
3184
diff
changeset
|
535 |
|
921a8afad859
renamed messagesDo: to messageNodes: do
Claus Gittinger <cg@exept.de>
parents:
3184
diff
changeset
|
536 |
setOfMessages := Set new. |
3279 | 537 |
self messagesDo:[:each | setOfMessages add:each ]. |
3275
921a8afad859
renamed messagesDo: to messageNodes: do
Claus Gittinger <cg@exept.de>
parents:
3184
diff
changeset
|
538 |
^ setOfMessages |
921a8afad859
renamed messagesDo: to messageNodes: do
Claus Gittinger <cg@exept.de>
parents:
3184
diff
changeset
|
539 |
! |
921a8afad859
renamed messagesDo: to messageNodes: do
Claus Gittinger <cg@exept.de>
parents:
3184
diff
changeset
|
540 |
|
1503 | 541 |
messagesDo:aBlock |
3275
921a8afad859
renamed messagesDo: to messageNodes: do
Claus Gittinger <cg@exept.de>
parents:
3184
diff
changeset
|
542 |
"evaluate aBlock for each message-node here and in subnodes" |
921a8afad859
renamed messagesDo: to messageNodes: do
Claus Gittinger <cg@exept.de>
parents:
3184
diff
changeset
|
543 |
|
1503 | 544 |
^ self |
3315 | 545 |
! |
546 |
||
4506 | 547 |
statements:statements do:aBlock |
548 |
|s| |
|
549 |
||
550 |
statements isNil ifTrue:[^ self]. |
|
551 |
||
552 |
"/ temporary hack |
|
553 |
statements isCollection ifTrue:[ |
|
554 |
statements do:aBlock. |
|
555 |
] ifFalse:[ |
|
556 |
"/ bad hack |
|
557 |
(statements isKindOf:StatementNode) ifTrue:[ |
|
558 |
s := statements. |
|
559 |
[ s notNil ] whileTrue:[ |
|
560 |
aBlock value:s. |
|
561 |
s := s nextStatement |
|
562 |
]. |
|
563 |
] ifFalse:[ |
|
564 |
"/ an innerblock node |
|
565 |
aBlock value:statements. |
|
566 |
]. |
|
567 |
]. |
|
568 |
||
569 |
"Modified: / 10-07-2019 / 02:32:21 / Claus Gittinger" |
|
570 |
! |
|
571 |
||
3315 | 572 |
variableNodesDo:aBlock |
573 |
"evaluate aBlock for each variable-node here and in subnodes" |
|
574 |
||
575 |
^ self |
|
1503 | 576 |
! ! |
577 |
||
140 | 578 |
!ParseNode methodsFor:'evaluation'! |
579 |
||
1383 | 580 |
evaluate |
581 |
^ self evaluateIn:nil |
|
582 |
! |
|
583 |
||
140 | 584 |
evaluateForCascade |
1383 | 585 |
^ self evaluateForCascadeIn:nil |
586 |
! |
|
587 |
||
588 |
evaluateForCascadeIn:anEnvironment |
|
589 |
^ self evaluateIn:anEnvironment |
|
590 |
! |
|
591 |
||
592 |
evaluateIn:anEnvironment |
|
593 |
self subclassResponsibility |
|
2505 | 594 |
! |
595 |
||
596 |
isStatement |
|
597 |
^false. |
|
598 |
||
599 |
"Created: / 22-02-2011 / 16:29:50 / Jakub <zelenja7@fel.cvut.cz>" |
|
140 | 600 |
! ! |
601 |
||
4471 | 602 |
|
603 |
||
1080 | 604 |
!ParseNode methodsFor:'printing & storing'! |
140 | 605 |
|
606 |
printOn:aStream |
|
914 | 607 |
"append a user printed representation of the receiver to aStream. |
608 |
The format is suitable for a human - not meant to be read back." |
|
609 |
||
140 | 610 |
self printOn:aStream indent:0 |
611 |
! |
|
612 |
||
1588 | 613 |
printOn:aStream indent:indent |
614 |
"append a user printed representation of the receiver to aStream. |
|
615 |
The format is suitable for a human - not meant to be read back." |
|
616 |
||
617 |
self subclassResponsibility |
|
618 |
||
619 |
"Created: / 20-04-2005 / 14:21:46 / cg" |
|
620 |
! |
|
621 |
||
622 |
printOn:aStream indent:indent parenthized:parenthized |
|
623 |
parenthized ifTrue:[ |
|
624 |
aStream nextPutAll:'(' |
|
625 |
]. |
|
626 |
self printOn:aStream indent:indent. |
|
627 |
parenthized ifTrue:[ |
|
628 |
aStream nextPutAll:')' |
|
629 |
]. |
|
630 |
||
631 |
"Created: / 20-04-2005 / 14:21:28 / cg" |
|
4501 | 632 |
! |
633 |
||
634 |
printStatementListOn:aStream indent:i |
|
635 |
self printOn:aStream indent:i |
|
140 | 636 |
! ! |
637 |
||
638 |
!ParseNode methodsFor:'private'! |
|
639 |
||
640 |
type:t |
|
641 |
"set the nodes type" |
|
642 |
||
643 |
type := t |
|
644 |
! ! |
|
645 |
||
0 | 646 |
!ParseNode methodsFor:'queries'! |
647 |
||
244
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
648 |
canReuseAsArg:anotherNode |
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
649 |
^ false |
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
650 |
|
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
651 |
"Created: 14.4.1996 / 00:43:08 / cg" |
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
652 |
! |
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
653 |
|
395 | 654 |
collectBlocksInto:aCollection |
655 |
^ self |
|
656 |
||
657 |
"Created: 23.10.1996 / 15:45:00 / cg" |
|
658 |
! |
|
659 |
||
2382 | 660 |
containsReturn |
661 |
^ false |
|
662 |
! |
|
663 |
||
4506 | 664 |
parseNodeVisitorClass |
665 |
^ ParseNodeVisitor |
|
666 |
! |
|
667 |
||
3296 | 668 |
positionToInsertPeriodForStatementSeparation |
669 |
^ self endPosition + (parenthized == true ifTrue:1 ifFalse:0) |
|
670 |
||
671 |
"Created: 14.4.1996 / 00:43:08 / cg" |
|
672 |
! |
|
673 |
||
2327 | 674 |
precedence |
675 |
^ 9999 |
|
676 |
! |
|
677 |
||
4582 | 678 |
whoDefines:aName |
679 |
"return the node (blockNode) in which this variable is defined. |
|
680 |
(nil if instvar, classvar or global)" |
|
681 |
||
682 |
|p| |
|
683 |
||
684 |
"/ TODO |
|
685 |
"/ block notNil ifTrue:[ |
|
686 |
"/ self halt |
|
687 |
"/ ]. |
|
688 |
p := parent. |
|
689 |
[p notNil and:[p isFunctionNode not and:[p isBlockNode not]]] whileTrue:[ p := p parent]. |
|
690 |
p notNil ifTrue:[ |
|
691 |
((p arguments ? #()) contains:[:var | var name = aName]) ifTrue:[^ p]. |
|
692 |
((p localVariables ? #()) contains:[:var | var name = aName]) ifTrue:[^ p]. |
|
693 |
]. |
|
694 |
^ nil |
|
695 |
! |
|
696 |
||
2327 | 697 |
withConstantValueDo:aBlock |
698 |
"return true, if this evaluates to a constant value |
|
699 |
and evaluate aBlock with it" |
|
700 |
||
701 |
^ false |
|
702 |
! ! |
|
703 |
||
704 |
!ParseNode methodsFor:'testing'! |
|
705 |
||
140 | 706 |
isAssignment |
707 |
"return true, if this is a node for an assignment" |
|
708 |
||
709 |
^ false |
|
710 |
! |
|
711 |
||
712 |
isBinaryMessage |
|
713 |
"return true, if this is a node for a binary send" |
|
714 |
||
715 |
^ false |
|
716 |
! |
|
717 |
||
718 |
isBlockNode |
|
719 |
"return true, if this is a node for a block" |
|
720 |
||
721 |
^ false |
|
722 |
! |
|
723 |
||
2533 | 724 |
isBreakPointNode |
725 |
^ false |
|
726 |
||
727 |
"Created: / 05-07-2011 / 21:14:01 / cg" |
|
728 |
! |
|
729 |
||
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
598
diff
changeset
|
730 |
isCascade |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
598
diff
changeset
|
731 |
^ false |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
598
diff
changeset
|
732 |
|
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
598
diff
changeset
|
733 |
"Created: / 16.7.1998 / 20:11:33 / cg" |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
598
diff
changeset
|
734 |
! |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
598
diff
changeset
|
735 |
|
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
598
diff
changeset
|
736 |
isCascadeToSuper |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
598
diff
changeset
|
737 |
^ false |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
598
diff
changeset
|
738 |
|
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
598
diff
changeset
|
739 |
"Created: / 16.7.1998 / 19:51:07 / cg" |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
598
diff
changeset
|
740 |
! |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
598
diff
changeset
|
741 |
|
0 | 742 |
isConstant |
13 | 743 |
"return true, if this is a node for a constant" |
744 |
||
745 |
^ false |
|
746 |
! |
|
747 |
||
4277 | 748 |
isConstantNumber |
749 |
"return true, if this is a node for a constant number" |
|
750 |
||
751 |
^ false |
|
752 |
||
753 |
"Created: / 16-06-2018 / 08:47:03 / Claus Gittinger" |
|
754 |
! |
|
755 |
||
1533 | 756 |
isErrorNode |
757 |
^ false |
|
758 |
! |
|
759 |
||
4322 | 760 |
isFunctionCallNode |
761 |
^ false |
|
762 |
||
763 |
"Created: / 13-12-2018 / 22:35:28 / Claus Gittinger" |
|
764 |
! |
|
765 |
||
4330 | 766 |
isFunctionNode |
767 |
^ false |
|
768 |
||
769 |
"Created: / 08-02-2019 / 10:53:58 / Claus Gittinger" |
|
770 |
! |
|
771 |
||
53 | 772 |
isGlobal |
773 |
"return true, if this is a node for a global variable" |
|
774 |
||
775 |
^ false |
|
776 |
! |
|
777 |
||
2000 | 778 |
isGlobalNamed:globalName |
779 |
"return true, if this is a node for a particular global variable" |
|
780 |
||
781 |
^ false |
|
782 |
||
783 |
"Created: / 05-03-2007 / 15:13:23 / cg" |
|
784 |
! |
|
785 |
||
1310
feb30ab0c221
better variabletype queries.
Claus Gittinger <cg@exept.de>
parents:
1114
diff
changeset
|
786 |
isGlobalVariable |
feb30ab0c221
better variabletype queries.
Claus Gittinger <cg@exept.de>
parents:
1114
diff
changeset
|
787 |
^ false |
feb30ab0c221
better variabletype queries.
Claus Gittinger <cg@exept.de>
parents:
1114
diff
changeset
|
788 |
! |
feb30ab0c221
better variabletype queries.
Claus Gittinger <cg@exept.de>
parents:
1114
diff
changeset
|
789 |
|
1528 | 790 |
isImmutable |
791 |
"not used with ST/X - |
|
792 |
for JavaScript nodes return true here." |
|
793 |
||
794 |
^ true |
|
795 |
! |
|
796 |
||
2403
79c95fae81e8
added: #isImplicitJavaScriptMessage
Claus Gittinger <cg@exept.de>
parents:
2402
diff
changeset
|
797 |
isImplicitJavaScriptMessage |
79c95fae81e8
added: #isImplicitJavaScriptMessage
Claus Gittinger <cg@exept.de>
parents:
2402
diff
changeset
|
798 |
"return true, if this is a node for an implicit getter/setter send" |
79c95fae81e8
added: #isImplicitJavaScriptMessage
Claus Gittinger <cg@exept.de>
parents:
2402
diff
changeset
|
799 |
|
79c95fae81e8
added: #isImplicitJavaScriptMessage
Claus Gittinger <cg@exept.de>
parents:
2402
diff
changeset
|
800 |
^ false |
79c95fae81e8
added: #isImplicitJavaScriptMessage
Claus Gittinger <cg@exept.de>
parents:
2402
diff
changeset
|
801 |
|
79c95fae81e8
added: #isImplicitJavaScriptMessage
Claus Gittinger <cg@exept.de>
parents:
2402
diff
changeset
|
802 |
"Created: / 05-07-2010 / 14:11:41 / cg" |
79c95fae81e8
added: #isImplicitJavaScriptMessage
Claus Gittinger <cg@exept.de>
parents:
2402
diff
changeset
|
803 |
! |
79c95fae81e8
added: #isImplicitJavaScriptMessage
Claus Gittinger <cg@exept.de>
parents:
2402
diff
changeset
|
804 |
|
4237 | 805 |
isInnerFunction |
806 |
^ false |
|
807 |
! |
|
808 |
||
1725 | 809 |
isInnerJavaScriptBlock |
810 |
^ false |
|
811 |
! |
|
812 |
||
2862 | 813 |
isJAVA |
814 |
"Return true, if receiver is global variable node JAVA. |
|
815 |
Used to highlight Java class references." |
|
816 |
||
817 |
^false |
|
818 |
||
819 |
"Created: / 19-04-2012 / 09:36:31 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
820 |
! |
|
821 |
||
822 |
isJavaPackageReference |
|
823 |
"Return true, given node is JAVA package reference in form: |
|
824 |
JAVA package1 package2 |
|
825 |
" |
|
826 |
||
827 |
^false |
|
828 |
||
829 |
"Created: / 19-04-2012 / 09:53:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
830 |
! |
|
831 |
||
3184 | 832 |
isJavaScriptAndExpression |
833 |
^ false |
|
834 |
! |
|
835 |
||
2402
da3d16a4193d
changed: #testplanItem:groupPattern:executor:testPlanExecutor:
Claus Gittinger <cg@exept.de>
parents:
2401
diff
changeset
|
836 |
isJavaScriptArrayAccess |
da3d16a4193d
changed: #testplanItem:groupPattern:executor:testPlanExecutor:
Claus Gittinger <cg@exept.de>
parents:
2401
diff
changeset
|
837 |
"return true, if this is a node for a javascript array reference i.e. expr[]" |
da3d16a4193d
changed: #testplanItem:groupPattern:executor:testPlanExecutor:
Claus Gittinger <cg@exept.de>
parents:
2401
diff
changeset
|
838 |
|
da3d16a4193d
changed: #testplanItem:groupPattern:executor:testPlanExecutor:
Claus Gittinger <cg@exept.de>
parents:
2401
diff
changeset
|
839 |
^ false |
da3d16a4193d
changed: #testplanItem:groupPattern:executor:testPlanExecutor:
Claus Gittinger <cg@exept.de>
parents:
2401
diff
changeset
|
840 |
|
da3d16a4193d
changed: #testplanItem:groupPattern:executor:testPlanExecutor:
Claus Gittinger <cg@exept.de>
parents:
2401
diff
changeset
|
841 |
"Created: / 05-07-2010 / 14:04:27 / cg" |
da3d16a4193d
changed: #testplanItem:groupPattern:executor:testPlanExecutor:
Claus Gittinger <cg@exept.de>
parents:
2401
diff
changeset
|
842 |
! |
da3d16a4193d
changed: #testplanItem:groupPattern:executor:testPlanExecutor:
Claus Gittinger <cg@exept.de>
parents:
2401
diff
changeset
|
843 |
|
2400 | 844 |
isJavaScriptBlock |
845 |
"return true, if this is a node for a javascript block" |
|
846 |
||
847 |
^ false |
|
848 |
||
849 |
"Created: / 09-06-2010 / 01:53:19 / cg" |
|
850 |
! |
|
851 |
||
3438 | 852 |
isJavaScriptClassNode |
853 |
^ false |
|
854 |
! |
|
855 |
||
2401
3bfe65bdcc64
added: #isJavaScriptConditionalExpression
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
856 |
isJavaScriptConditionalExpression |
3bfe65bdcc64
added: #isJavaScriptConditionalExpression
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
857 |
"return true, if this is a node for a ?: expression" |
3bfe65bdcc64
added: #isJavaScriptConditionalExpression
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
858 |
|
3bfe65bdcc64
added: #isJavaScriptConditionalExpression
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
859 |
^ false |
3bfe65bdcc64
added: #isJavaScriptConditionalExpression
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
860 |
|
3bfe65bdcc64
added: #isJavaScriptConditionalExpression
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
861 |
"Created: / 09-06-2010 / 01:55:15 / cg" |
3bfe65bdcc64
added: #isJavaScriptConditionalExpression
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
862 |
! |
3bfe65bdcc64
added: #isJavaScriptConditionalExpression
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
863 |
|
3184 | 864 |
isJavaScriptOrExpression |
865 |
^ false |
|
866 |
! |
|
867 |
||
3812 | 868 |
isLiteral |
869 |
"for compatibility with RB-AST" |
|
870 |
||
871 |
^ self isConstant |
|
872 |
! |
|
873 |
||
4471 | 874 |
isLiteralArray |
875 |
"for compatibility with RB-AST" |
|
876 |
||
877 |
^ false |
|
878 |
! |
|
879 |
||
880 |
isLiteralCString |
|
881 |
"for compatibility with RB-AST" |
|
882 |
||
883 |
^ false |
|
884 |
! |
|
885 |
||
3474 | 886 |
isLocalVariable |
887 |
^ false |
|
888 |
! |
|
889 |
||
140 | 890 |
isMessage |
891 |
"return true, if this is a node for a message expression" |
|
19 | 892 |
|
893 |
^ false |
|
894 |
! |
|
895 |
||
3414 | 896 |
isMethodNode |
897 |
^ false |
|
898 |
! |
|
899 |
||
1310
feb30ab0c221
better variabletype queries.
Claus Gittinger <cg@exept.de>
parents:
1114
diff
changeset
|
900 |
isMethodVariable |
feb30ab0c221
better variabletype queries.
Claus Gittinger <cg@exept.de>
parents:
1114
diff
changeset
|
901 |
^ false |
feb30ab0c221
better variabletype queries.
Claus Gittinger <cg@exept.de>
parents:
1114
diff
changeset
|
902 |
! |
feb30ab0c221
better variabletype queries.
Claus Gittinger <cg@exept.de>
parents:
1114
diff
changeset
|
903 |
|
2327 | 904 |
isNew |
905 |
"return true, if this is a new XXXX node" |
|
906 |
||
907 |
^ false |
|
908 |
! |
|
909 |
||
2088 | 910 |
isPostIncDec |
911 |
"for JavaScript" |
|
912 |
||
913 |
^ false |
|
914 |
! |
|
915 |
||
916 |
isPreIncDec |
|
917 |
"for JavaScript" |
|
918 |
||
919 |
^ false |
|
920 |
! |
|
921 |
||
140 | 922 |
isPrimary |
923 |
"return true, if this is a node for a primary (i.e. non-send)" |
|
13 | 924 |
|
925 |
^ false |
|
926 |
! |
|
927 |
||
928 |
isReturnNode |
|
929 |
"return true, if this is a node for a return expression" |
|
930 |
||
0 | 931 |
^ false |
932 |
! |
|
933 |
||
862 | 934 |
isSelf |
935 |
"return true, if this is a self-node" |
|
936 |
||
937 |
^ false |
|
938 |
! |
|
939 |
||
4541 | 940 |
isSequence |
941 |
"return true, if this is a sequence node (JS)" |
|
942 |
||
943 |
^ false |
|
944 |
! |
|
945 |
||
2505 | 946 |
isStatementNode |
947 |
"return true, if this is a statement node" |
|
948 |
||
949 |
^ false |
|
950 |
||
951 |
"Created: / 13-06-2011 / 11:26:10 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
952 |
! |
|
953 |
||
140 | 954 |
isSuper |
955 |
"return true, if this is a super-node" |
|
13 | 956 |
|
0 | 957 |
^ false |
958 |
! |
|
959 |
||
2089 | 960 |
isThis |
961 |
"for JavaScript" |
|
962 |
||
963 |
^ false |
|
964 |
! |
|
965 |
||
0 | 966 |
isUnaryMessage |
13 | 967 |
"return true, if this is a node for a unary send" |
968 |
||
0 | 969 |
^ false |
244
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
970 |
! |
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
971 |
|
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
972 |
isVariable |
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
973 |
"return true, if this is a node for a variable" |
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
974 |
|
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
975 |
^ false |
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
976 |
|
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
977 |
"Created: 14.4.1996 / 00:46:44 / cg" |
2694 | 978 |
! |
979 |
||
980 |
isVariableNode |
|
981 |
"return true, if this is a node for a variable" |
|
982 |
||
983 |
^ self isVariable |
|
984 |
||
985 |
"Created: / 12-09-2011 / 09:32:17 / cg" |
|
0 | 986 |
! ! |
987 |
||
148 | 988 |
!ParseNode class methodsFor:'documentation'! |
989 |
||
3276 | 990 |
version |
3812 | 991 |
^ '$Header$' |
3276 | 992 |
! |
993 |
||
2505 | 994 |
version_CVS |
3812 | 995 |
^ '$Header$' |
148 | 996 |
! ! |
3110
f517641d3673
Emit LINE16 bytecode insn just before a SEND bytecode is emmited when
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2862
diff
changeset
|
997 |