author | Claus Gittinger <cg@exept.de> |
Fri, 28 Mar 2003 15:41:56 +0100 | |
changeset 1384 | 0db9682870d9 |
parent 1383 | 3d485eefbb36 |
child 1503 | 5feba91aa28a |
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 |
||
59 |
nr > 0 ifTrue:[ |
|
60 |
nr <= 255 ifTrue:[ |
|
61 |
aStream nextPut:#lineno. |
|
62 |
aStream nextPut:nr |
|
63 |
] ifFalse:[ |
|
64 |
nr <= 16rFFFF ifTrue:[ |
|
65 |
aStream nextPut:#lineno16. |
|
66 |
aStream nextPut:((nr bitShift:-8) bitAnd:16rFF). |
|
67 |
aStream nextPut:(nr bitAnd:16rFF). |
|
68 |
] |
|
69 |
] |
|
70 |
] |
|
71 |
||
72 |
"Created: 21.10.1996 / 14:42:27 / cg" |
|
73 |
! ! |
|
74 |
||
140 | 75 |
!ParseNode methodsFor:'accessing'! |
76 |
||
77 |
lineNumber:dummy |
|
78 |
"set linenumber - ignored here" |
|
79 |
||
80 |
^ self |
|
81 |
! |
|
82 |
||
83 |
parenthized |
|
1338 | 84 |
^ parenthized ? false |
140 | 85 |
! |
86 |
||
87 |
parenthized:aBoolean |
|
88 |
parenthized := aBoolean |
|
89 |
! |
|
90 |
||
598 | 91 |
selectorPosition:aCharacterPosition |
92 |
"ignored here" |
|
93 |
||
94 |
"Created: 5.8.1997 / 16:32:17 / cg" |
|
95 |
! |
|
96 |
||
140 | 97 |
type |
98 |
"return the nodes type" |
|
99 |
||
100 |
^ type |
|
101 |
! ! |
|
102 |
||
103 |
!ParseNode methodsFor:'checks'! |
|
104 |
||
105 |
plausibilityCheck |
|
106 |
^ nil |
|
107 |
! ! |
|
108 |
||
109 |
!ParseNode methodsFor:'code generation'! |
|
110 |
||
111 |
codeForSideEffectOn:aStream inBlock:b for:aCompiler |
|
112 |
"generate code for this statement - value not needed" |
|
113 |
||
114 |
self codeOn:aStream inBlock:b for:aCompiler. |
|
115 |
aStream nextPut:#drop |
|
373 | 116 |
! |
117 |
||
843
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
118 |
codeForSimpleReturnOn:aStream inBlock:b lineNumber:lineNrOrNil for:aCompiler |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
119 |
"generate code to return myself as a simple method return" |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
120 |
|
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
121 |
self codeOn:aStream inBlock:b for:aCompiler. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
122 |
lineNrOrNil notNil ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
123 |
self codeLineNumber:lineNrOrNil on:aStream for:aCompiler |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
124 |
]. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
125 |
aStream nextPut:#retTop. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
126 |
|
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
127 |
|
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
128 |
! |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
129 |
|
1056 | 130 |
codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
131 |
"generate code for this statement - value is needed" |
|
132 |
||
133 |
self codeOn:aStream inBlock:b for:aCompiler. |
|
134 |
! |
|
135 |
||
373 | 136 |
codeLineNumber:nr on:aStream for:aCompiler |
137 |
"generate lineNumber information" |
|
138 |
||
816 | 139 |
self class codeLineNumber:nr on:aStream for:aCompiler |
140 | 140 |
! ! |
141 |
||
142 |
!ParseNode methodsFor:'evaluation'! |
|
143 |
||
1383 | 144 |
evaluate |
145 |
^ self evaluateIn:nil |
|
146 |
! |
|
147 |
||
140 | 148 |
evaluateForCascade |
1383 | 149 |
^ self evaluateForCascadeIn:nil |
150 |
! |
|
151 |
||
152 |
evaluateForCascadeIn:anEnvironment |
|
153 |
^ self evaluateIn:anEnvironment |
|
154 |
! |
|
155 |
||
156 |
evaluateIn:anEnvironment |
|
157 |
self subclassResponsibility |
|
140 | 158 |
! ! |
159 |
||
1080 | 160 |
!ParseNode methodsFor:'printing & storing'! |
140 | 161 |
|
162 |
printOn:aStream |
|
914 | 163 |
"append a user printed representation of the receiver to aStream. |
164 |
The format is suitable for a human - not meant to be read back." |
|
165 |
||
140 | 166 |
self printOn:aStream indent:0 |
167 |
! |
|
168 |
||
169 |
printString |
|
170 |
|stream| |
|
171 |
||
172 |
stream := WriteStream on:String new. |
|
173 |
self printOn:stream indent:0. |
|
174 |
^ stream contents |
|
175 |
! ! |
|
176 |
||
177 |
!ParseNode methodsFor:'private'! |
|
178 |
||
179 |
type:t |
|
180 |
"set the nodes type" |
|
181 |
||
182 |
type := t |
|
183 |
! ! |
|
184 |
||
0 | 185 |
!ParseNode methodsFor:'queries'! |
186 |
||
244
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
187 |
canReuseAsArg:anotherNode |
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
188 |
^ false |
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
189 |
|
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
190 |
"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
|
191 |
! |
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
192 |
|
395 | 193 |
collectBlocksInto:aCollection |
194 |
^ self |
|
195 |
||
196 |
"Created: 23.10.1996 / 15:45:00 / cg" |
|
197 |
! |
|
198 |
||
140 | 199 |
isAssignment |
200 |
"return true, if this is a node for an assignment" |
|
201 |
||
202 |
^ false |
|
203 |
! |
|
204 |
||
205 |
isBinaryMessage |
|
206 |
"return true, if this is a node for a binary send" |
|
207 |
||
208 |
^ false |
|
209 |
! |
|
210 |
||
211 |
isBlockNode |
|
212 |
"return true, if this is a node for a block" |
|
213 |
||
214 |
^ false |
|
215 |
! |
|
216 |
||
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
598
diff
changeset
|
217 |
isCascade |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
598
diff
changeset
|
218 |
^ false |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
598
diff
changeset
|
219 |
|
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
598
diff
changeset
|
220 |
"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
|
221 |
! |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
598
diff
changeset
|
222 |
|
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
598
diff
changeset
|
223 |
isCascadeToSuper |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
598
diff
changeset
|
224 |
^ false |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
598
diff
changeset
|
225 |
|
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
598
diff
changeset
|
226 |
"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
|
227 |
! |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
598
diff
changeset
|
228 |
|
0 | 229 |
isConstant |
13 | 230 |
"return true, if this is a node for a constant" |
231 |
||
232 |
^ false |
|
233 |
! |
|
234 |
||
53 | 235 |
isGlobal |
236 |
"return true, if this is a node for a global variable" |
|
237 |
||
238 |
^ false |
|
239 |
! |
|
240 |
||
1310
feb30ab0c221
better variabletype queries.
Claus Gittinger <cg@exept.de>
parents:
1114
diff
changeset
|
241 |
isGlobalVariable |
feb30ab0c221
better variabletype queries.
Claus Gittinger <cg@exept.de>
parents:
1114
diff
changeset
|
242 |
^ false |
feb30ab0c221
better variabletype queries.
Claus Gittinger <cg@exept.de>
parents:
1114
diff
changeset
|
243 |
! |
feb30ab0c221
better variabletype queries.
Claus Gittinger <cg@exept.de>
parents:
1114
diff
changeset
|
244 |
|
140 | 245 |
isMessage |
246 |
"return true, if this is a node for a message expression" |
|
19 | 247 |
|
248 |
^ false |
|
249 |
! |
|
250 |
||
1310
feb30ab0c221
better variabletype queries.
Claus Gittinger <cg@exept.de>
parents:
1114
diff
changeset
|
251 |
isMethodVariable |
feb30ab0c221
better variabletype queries.
Claus Gittinger <cg@exept.de>
parents:
1114
diff
changeset
|
252 |
^ false |
feb30ab0c221
better variabletype queries.
Claus Gittinger <cg@exept.de>
parents:
1114
diff
changeset
|
253 |
! |
feb30ab0c221
better variabletype queries.
Claus Gittinger <cg@exept.de>
parents:
1114
diff
changeset
|
254 |
|
140 | 255 |
isPrimary |
256 |
"return true, if this is a node for a primary (i.e. non-send)" |
|
13 | 257 |
|
258 |
^ false |
|
259 |
! |
|
260 |
||
261 |
isReturnNode |
|
262 |
"return true, if this is a node for a return expression" |
|
263 |
||
0 | 264 |
^ false |
265 |
! |
|
266 |
||
862 | 267 |
isSelf |
268 |
"return true, if this is a self-node" |
|
269 |
||
270 |
^ false |
|
271 |
! |
|
272 |
||
140 | 273 |
isSuper |
274 |
"return true, if this is a super-node" |
|
13 | 275 |
|
0 | 276 |
^ false |
277 |
! |
|
278 |
||
279 |
isUnaryMessage |
|
13 | 280 |
"return true, if this is a node for a unary send" |
281 |
||
0 | 282 |
^ false |
244
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
283 |
! |
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
284 |
|
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
285 |
isVariable |
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
286 |
"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
|
287 |
|
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
288 |
^ false |
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
289 |
|
2ce60e837d52
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
290 |
"Created: 14.4.1996 / 00:46:44 / cg" |
0 | 291 |
! ! |
292 |
||
148 | 293 |
!ParseNode class methodsFor:'documentation'! |
294 |
||
295 |
version |
|
1383 | 296 |
^ '$Header: /cvs/stx/stx/libcomp/ParseNode.st,v 1.35 2003-03-28 14:39:08 cg Exp $' |
148 | 297 |
! ! |