author | Claus Gittinger <cg@exept.de> |
Mon, 17 Jul 2006 13:34:14 +0200 | |
changeset 1777 | 242e89fa2170 |
parent 1725 | 728ba29d1872 |
child 1804 | 7c22dbaa8d10 |
permissions | -rw-r--r-- |
0 | 1 |
" |
4 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
53 | 3 |
All Rights Reserved |
0 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
1044 | 13 |
"{ Package: 'stx:libcomp' }" |
14 |
||
0 | 15 |
Object subclass:#ParseNode |
244
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
16 |
instanceVariableNames:'type comments parenthized' |
1046 | 17 |
classVariableNames:'' |
244
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
18 |
poolDictionaries:'' |
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
19 |
category:'System-Compiler-Support' |
0 | 20 |
! |
21 |
||
20 | 22 |
!ParseNode class methodsFor:'documentation'! |
23 |
||
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
53 | 27 |
All Rights Reserved |
20 | 28 |
|
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
38 |
documentation |
|
39 |
" |
|
40 |
node for parse-trees; abstract class |
|
261 | 41 |
This is a helper class for the compiler. |
263 | 42 |
|
43 |
[author:] |
|
44 |
Claus Gittinger |
|
20 | 45 |
" |
46 |
! ! |
|
0 | 47 |
|
48 |
!ParseNode class methodsFor:'instance creation'! |
|
49 |
||
50 |
type:t |
|
51 |
^ (self basicNew) type:t |
|
52 |
! ! |
|
53 |
||
1114 | 54 |
!ParseNode class methodsFor:'code generation helpers'! |
383 | 55 |
|
56 |
codeLineNumber:nr on:aStream for:aCompiler |
|
57 |
"generate lineNumber information" |
|
58 |
||
1720 | 59 |
"/ caveat: (currently) there is no separate lineNumber or symbol table; |
60 |
"/ the line numbers are coded right into the instruction stream. |
|
61 |
"/ This might change in the future. |
|
62 |
"/ (It is not a problem speed wise: the Jitter just skips them.) |
|
63 |
||
383 | 64 |
nr > 0 ifTrue:[ |
65 |
nr <= 255 ifTrue:[ |
|
66 |
aStream nextPut:#lineno. |
|
67 |
aStream nextPut:nr |
|
68 |
] ifFalse:[ |
|
69 |
nr <= 16rFFFF ifTrue:[ |
|
70 |
aStream nextPut:#lineno16. |
|
71 |
aStream nextPut:((nr bitShift:-8) bitAnd:16rFF). |
|
72 |
aStream nextPut:(nr bitAnd:16rFF). |
|
73 |
] |
|
74 |
] |
|
75 |
] |
|
76 |
||
77 |
"Created: 21.10.1996 / 14:42:27 / cg" |
|
78 |
! ! |
|
79 |
||
140 | 80 |
!ParseNode methodsFor:'accessing'! |
81 |
||
82 |
lineNumber:dummy |
|
83 |
"set linenumber - ignored here" |
|
84 |
||
85 |
^ self |
|
86 |
! |
|
87 |
||
88 |
parenthized |
|
1338 | 89 |
^ parenthized ? false |
140 | 90 |
! |
91 |
||
92 |
parenthized:aBoolean |
|
93 |
parenthized := aBoolean |
|
94 |
! |
|
95 |
||
598 | 96 |
selectorPosition:aCharacterPosition |
97 |
"ignored here" |
|
98 |
||
99 |
"Created: 5.8.1997 / 16:32:17 / cg" |
|
100 |
! |
|
101 |
||
140 | 102 |
type |
103 |
"return the nodes type" |
|
104 |
||
105 |
^ type |
|
106 |
! ! |
|
107 |
||
108 |
!ParseNode methodsFor:'checks'! |
|
109 |
||
110 |
plausibilityCheck |
|
111 |
^ nil |
|
112 |
! ! |
|
113 |
||
114 |
!ParseNode methodsFor:'code generation'! |
|
115 |
||
116 |
codeForSideEffectOn:aStream inBlock:b for:aCompiler |
|
117 |
"generate code for this statement - value not needed" |
|
118 |
||
119 |
self codeOn:aStream inBlock:b for:aCompiler. |
|
120 |
aStream nextPut:#drop |
|
373 | 121 |
! |
122 |
||
843
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
123 |
codeForSimpleReturnOn:aStream inBlock:b lineNumber:lineNrOrNil for:aCompiler |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
124 |
"generate code to return myself as a simple method return" |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
125 |
|
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
126 |
self codeOn:aStream inBlock:b for:aCompiler. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
127 |
lineNrOrNil notNil ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
128 |
self codeLineNumber:lineNrOrNil on:aStream for:aCompiler |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
129 |
]. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
130 |
aStream nextPut:#retTop. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
131 |
|
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
132 |
|
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
133 |
! |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
134 |
|
1056 | 135 |
codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
136 |
"generate code for this statement - value is needed" |
|
137 |
||
138 |
self codeOn:aStream inBlock:b for:aCompiler. |
|
139 |
! |
|
140 |
||
373 | 141 |
codeLineNumber:nr on:aStream for:aCompiler |
142 |
"generate lineNumber information" |
|
143 |
||
816 | 144 |
self class codeLineNumber:nr on:aStream for:aCompiler |
140 | 145 |
! ! |
146 |
||
1503 | 147 |
!ParseNode methodsFor:'enumeration'! |
148 |
||
149 |
messagesDo:aBlock |
|
150 |
^ self |
|
151 |
! ! |
|
152 |
||
140 | 153 |
!ParseNode methodsFor:'evaluation'! |
154 |
||
1383 | 155 |
evaluate |
156 |
^ self evaluateIn:nil |
|
157 |
! |
|
158 |
||
140 | 159 |
evaluateForCascade |
1383 | 160 |
^ self evaluateForCascadeIn:nil |
161 |
! |
|
162 |
||
163 |
evaluateForCascadeIn:anEnvironment |
|
164 |
^ self evaluateIn:anEnvironment |
|
165 |
! |
|
166 |
||
167 |
evaluateIn:anEnvironment |
|
168 |
self subclassResponsibility |
|
140 | 169 |
! ! |
170 |
||
1080 | 171 |
!ParseNode methodsFor:'printing & storing'! |
140 | 172 |
|
173 |
printOn:aStream |
|
914 | 174 |
"append a user printed representation of the receiver to aStream. |
175 |
The format is suitable for a human - not meant to be read back." |
|
176 |
||
140 | 177 |
self printOn:aStream indent:0 |
178 |
! |
|
179 |
||
1588 | 180 |
printOn:aStream indent:indent |
181 |
"append a user printed representation of the receiver to aStream. |
|
182 |
The format is suitable for a human - not meant to be read back." |
|
183 |
||
184 |
self subclassResponsibility |
|
185 |
||
186 |
"Created: / 20-04-2005 / 14:21:46 / cg" |
|
187 |
! |
|
188 |
||
189 |
printOn:aStream indent:indent parenthized:parenthized |
|
190 |
parenthized ifTrue:[ |
|
191 |
aStream nextPutAll:'(' |
|
192 |
]. |
|
193 |
self printOn:aStream indent:indent. |
|
194 |
parenthized ifTrue:[ |
|
195 |
aStream nextPutAll:')' |
|
196 |
]. |
|
197 |
||
198 |
"Created: / 20-04-2005 / 14:21:28 / cg" |
|
199 |
! |
|
200 |
||
140 | 201 |
printString |
202 |
|stream| |
|
203 |
||
204 |
stream := WriteStream on:String new. |
|
205 |
self printOn:stream indent:0. |
|
206 |
^ stream contents |
|
207 |
! ! |
|
208 |
||
209 |
!ParseNode methodsFor:'private'! |
|
210 |
||
211 |
type:t |
|
212 |
"set the nodes type" |
|
213 |
||
214 |
type := t |
|
215 |
! ! |
|
216 |
||
0 | 217 |
!ParseNode methodsFor:'queries'! |
218 |
||
244
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
219 |
canReuseAsArg:anotherNode |
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
220 |
^ false |
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
221 |
|
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
222 |
"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
|
223 |
! |
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
224 |
|
395 | 225 |
collectBlocksInto:aCollection |
226 |
^ self |
|
227 |
||
228 |
"Created: 23.10.1996 / 15:45:00 / cg" |
|
229 |
! |
|
230 |
||
140 | 231 |
isAssignment |
232 |
"return true, if this is a node for an assignment" |
|
233 |
||
234 |
^ false |
|
235 |
! |
|
236 |
||
237 |
isBinaryMessage |
|
238 |
"return true, if this is a node for a binary send" |
|
239 |
||
240 |
^ false |
|
241 |
! |
|
242 |
||
243 |
isBlockNode |
|
244 |
"return true, if this is a node for a block" |
|
245 |
||
246 |
^ false |
|
247 |
! |
|
248 |
||
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
598
diff
changeset
|
249 |
isCascade |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
598
diff
changeset
|
250 |
^ false |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
598
diff
changeset
|
251 |
|
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
598
diff
changeset
|
252 |
"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
|
253 |
! |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
598
diff
changeset
|
254 |
|
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
598
diff
changeset
|
255 |
isCascadeToSuper |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
598
diff
changeset
|
256 |
^ false |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
598
diff
changeset
|
257 |
|
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
598
diff
changeset
|
258 |
"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
|
259 |
! |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
598
diff
changeset
|
260 |
|
0 | 261 |
isConstant |
13 | 262 |
"return true, if this is a node for a constant" |
263 |
||
264 |
^ false |
|
265 |
! |
|
266 |
||
1533 | 267 |
isErrorNode |
268 |
^ false |
|
269 |
! |
|
270 |
||
53 | 271 |
isGlobal |
272 |
"return true, if this is a node for a global variable" |
|
273 |
||
274 |
^ false |
|
275 |
! |
|
276 |
||
1310
feb30ab0c221
better variabletype queries.
Claus Gittinger <cg@exept.de>
parents:
1114
diff
changeset
|
277 |
isGlobalVariable |
feb30ab0c221
better variabletype queries.
Claus Gittinger <cg@exept.de>
parents:
1114
diff
changeset
|
278 |
^ false |
feb30ab0c221
better variabletype queries.
Claus Gittinger <cg@exept.de>
parents:
1114
diff
changeset
|
279 |
! |
feb30ab0c221
better variabletype queries.
Claus Gittinger <cg@exept.de>
parents:
1114
diff
changeset
|
280 |
|
1528 | 281 |
isImmutable |
282 |
"not used with ST/X - |
|
283 |
for JavaScript nodes return true here." |
|
284 |
||
285 |
^ true |
|
286 |
! |
|
287 |
||
1725 | 288 |
isInnerJavaScriptBlock |
289 |
^ false |
|
290 |
! |
|
291 |
||
140 | 292 |
isMessage |
293 |
"return true, if this is a node for a message expression" |
|
19 | 294 |
|
295 |
^ false |
|
296 |
! |
|
297 |
||
1310
feb30ab0c221
better variabletype queries.
Claus Gittinger <cg@exept.de>
parents:
1114
diff
changeset
|
298 |
isMethodVariable |
feb30ab0c221
better variabletype queries.
Claus Gittinger <cg@exept.de>
parents:
1114
diff
changeset
|
299 |
^ false |
feb30ab0c221
better variabletype queries.
Claus Gittinger <cg@exept.de>
parents:
1114
diff
changeset
|
300 |
! |
feb30ab0c221
better variabletype queries.
Claus Gittinger <cg@exept.de>
parents:
1114
diff
changeset
|
301 |
|
140 | 302 |
isPrimary |
303 |
"return true, if this is a node for a primary (i.e. non-send)" |
|
13 | 304 |
|
305 |
^ false |
|
306 |
! |
|
307 |
||
308 |
isReturnNode |
|
309 |
"return true, if this is a node for a return expression" |
|
310 |
||
0 | 311 |
^ false |
312 |
! |
|
313 |
||
862 | 314 |
isSelf |
315 |
"return true, if this is a self-node" |
|
316 |
||
317 |
^ false |
|
318 |
! |
|
319 |
||
140 | 320 |
isSuper |
321 |
"return true, if this is a super-node" |
|
13 | 322 |
|
0 | 323 |
^ false |
324 |
! |
|
325 |
||
326 |
isUnaryMessage |
|
13 | 327 |
"return true, if this is a node for a unary send" |
328 |
||
0 | 329 |
^ false |
244
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
330 |
! |
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
331 |
|
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
332 |
isVariable |
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
333 |
"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
|
334 |
|
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
335 |
^ false |
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
336 |
|
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
337 |
"Created: 14.4.1996 / 00:46:44 / cg" |
1588 | 338 |
! |
339 |
||
340 |
precedence |
|
341 |
^ 9999 |
|
0 | 342 |
! ! |
343 |
||
148 | 344 |
!ParseNode class methodsFor:'documentation'! |
345 |
||
346 |
version |
|
1725 | 347 |
^ '$Header: /cvs/stx/stx/libcomp/ParseNode.st,v 1.41 2006-03-16 14:24:57 cg Exp $' |
148 | 348 |
! ! |