author | Claus Gittinger <cg@exept.de> |
Mon, 16 Feb 2009 14:10:39 +0100 | |
changeset 2165 | 4dde25bad190 |
parent 2103 | 7eab888fb15a |
child 2168 | be3e52955e96 |
permissions | -rw-r--r-- |
0 | 1 |
" |
4 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
52 | 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 |
" |
|
1080 | 12 |
"{ Package: 'stx:libcomp' }" |
13 |
||
0 | 14 |
ParseNode subclass:#StatementNode |
392
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
15 |
instanceVariableNames:'expression nextStatement lineNr' |
261 | 16 |
classVariableNames:'' |
17 |
poolDictionaries:'' |
|
18 |
category:'System-Compiler-Support' |
|
0 | 19 |
! |
20 |
||
392
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
21 |
!StatementNode class methodsFor:'documentation'! |
20 | 22 |
|
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
52 | 26 |
All Rights Reserved |
20 | 27 |
|
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
36 |
||
37 |
documentation |
|
38 |
" |
|
39 |
node for parse-trees, representing statements |
|
261 | 40 |
This is a helper class for the compiler. |
263 | 41 |
|
42 |
[author:] |
|
43 |
Claus Gittinger |
|
20 | 44 |
" |
45 |
! ! |
|
0 | 46 |
|
392
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
47 |
!StatementNode class methodsFor:'instance creation'! |
0 | 48 |
|
49 |
expression:e |
|
50 |
^ (self basicNew) expression:e |
|
51 |
! ! |
|
52 |
||
140 | 53 |
!StatementNode methodsFor:'accessing'! |
0 | 54 |
|
140 | 55 |
expression |
56 |
^ expression |
|
0 | 57 |
! |
58 |
||
140 | 59 |
expression:e |
60 |
expression := e |
|
0 | 61 |
! |
62 |
||
63 |
last |
|
64 |
"return the last statement in a list" |
|
65 |
||
66 |
|last this| |
|
67 |
||
68 |
"this could be done more elegant - but with lots of recursion" |
|
69 |
last := self. |
|
70 |
this := self. |
|
71 |
[this notNil] whileTrue:[ |
|
52 | 72 |
last := this. |
73 |
this := this nextStatement |
|
0 | 74 |
]. |
75 |
^ last |
|
76 |
! |
|
77 |
||
711 | 78 |
lineNumber |
392
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
79 |
"return lineNr" |
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
80 |
|
1504 | 81 |
lineNr notNil ifTrue:[^ lineNr]. |
82 |
expression notNil ifTrue:[ ^ expression lineNumber ]. |
|
83 |
nextStatement notNil ifTrue:[^ nextStatement lineNumber]. |
|
84 |
^ nil |
|
392
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
85 |
|
711 | 86 |
"Created: / 14.5.1998 / 19:31:06 / cg" |
392
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
87 |
! |
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
88 |
|
711 | 89 |
lineNumber:something |
392
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
90 |
"set lineNr" |
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
91 |
|
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
92 |
lineNr := something. |
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
93 |
|
711 | 94 |
"Created: / 14.5.1998 / 19:31:11 / cg" |
392
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
95 |
! |
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
96 |
|
1504 | 97 |
lineNumberOfFirstMessage |
98 |
|lno| |
|
99 |
||
100 |
lno := self lineNumber. |
|
101 |
self messagesDo:[:m | lno := lno min:(m lineNumber)]. |
|
102 |
^ lno |
|
103 |
! |
|
104 |
||
0 | 105 |
nextStatement |
106 |
^ nextStatement |
|
107 |
! |
|
108 |
||
140 | 109 |
nextStatement:s |
110 |
nextStatement := s |
|
111 |
! ! |
|
112 |
||
113 |
!StatementNode methodsFor:'code generation'! |
|
114 |
||
1379 | 115 |
codeAllForSideEffectOn:aStream inBlock:b for:aCompiler |
116 |
|thisStatement| |
|
117 |
||
118 |
thisStatement := self. |
|
119 |
[thisStatement notNil] whileTrue:[ |
|
120 |
thisStatement codeForSideEffectOn:aStream inBlock:b for:aCompiler. |
|
121 |
thisStatement := thisStatement nextStatement |
|
122 |
]. |
|
123 |
! |
|
124 |
||
140 | 125 |
codeForSideEffectOn:aStream inBlock:b for:aCompiler |
126 |
"generate code for this statement - value not needed" |
|
127 |
||
985 | 128 |
expression notNil ifTrue:[ |
129 |
expression codeForSideEffectOn:aStream inBlock:b for:aCompiler |
|
130 |
] |
|
0 | 131 |
! |
132 |
||
140 | 133 |
codeOn:aStream inBlock:b for:aCompiler |
134 |
"generate code for this statement" |
|
135 |
||
1313 | 136 |
expression notNil ifTrue:[ |
137 |
expression codeOn:aStream inBlock:b for:aCompiler |
|
138 |
] |
|
0 | 139 |
! ! |
140 |
||
1209 | 141 |
!StatementNode methodsFor:'converting'! |
142 |
||
143 |
asCollectionOfStatements |
|
144 |
"returns a orderedCollection of statements, |
|
145 |
representing the list of which the receiver is the head" |
|
146 |
||
147 |
|coll stat| |
|
148 |
||
149 |
coll := OrderedCollection new. |
|
150 |
stat := self. |
|
151 |
[stat notNil] whileTrue:[ |
|
152 |
coll add:stat. |
|
153 |
stat := stat nextStatement. |
|
154 |
]. |
|
155 |
^ coll |
|
156 |
! ! |
|
157 |
||
1035 | 158 |
!StatementNode methodsFor:'enumerating'! |
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
159 |
|
1504 | 160 |
messagesDo:aBlock |
161 |
|s e| |
|
162 |
||
163 |
s := self. |
|
164 |
[s notNil] whileTrue:[ |
|
165 |
e := s expression. |
|
166 |
e notNil ifTrue:[e messagesDo:aBlock]. |
|
167 |
s := s nextStatement |
|
168 |
]. |
|
169 |
! |
|
170 |
||
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
171 |
nodeDo:anEnumerator |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
172 |
"helper for parse tree walking" |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
173 |
|
1585 | 174 |
|stats this expr| |
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
175 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
176 |
"/ too stupid: ST/X statements are linked as a list ... |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
177 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
178 |
stats := OrderedCollection new. |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
179 |
this := self. |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
180 |
[this notNil] whileTrue:[ |
1592 | 181 |
this isReturnNode ifTrue:[ |
182 |
stats add:this |
|
183 |
] ifFalse:[ |
|
184 |
expr := this expression. |
|
185 |
stats add:(expr ? this). |
|
186 |
]. |
|
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
187 |
this := this nextStatement |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
188 |
]. |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
189 |
^ anEnumerator doSequence:self temporaries:#() statements:stats |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
190 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
191 |
"Created: 19.6.1997 / 16:45:34 / cg" |
542 | 192 |
"Modified: 19.6.1997 / 17:06:47 / cg" |
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
193 |
! ! |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
194 |
|
1035 | 195 |
!StatementNode methodsFor:'evaluation'! |
140 | 196 |
|
1384 | 197 |
evaluateAllIn:anEnvironment |
140 | 198 |
|lastValue thisStatement| |
52 | 199 |
|
140 | 200 |
"this could be done more elegant - but with lots of recursion" |
201 |
thisStatement := self. |
|
202 |
[thisStatement notNil] whileTrue:[ |
|
1384 | 203 |
lastValue := thisStatement evaluateExpressionIn:anEnvironment. |
204 |
thisStatement := thisStatement nextStatement |
|
140 | 205 |
]. |
206 |
^ lastValue |
|
207 |
! |
|
208 |
||
1384 | 209 |
evaluateExpressionIn:anEnvironment |
210 |
^ expression evaluateIn:anEnvironment |
|
211 |
! |
|
212 |
||
213 |
evaluateIn:anEnvironment |
|
214 |
^ self evaluateAllIn:anEnvironment. |
|
52 | 215 |
! ! |
216 |
||
1080 | 217 |
!StatementNode methodsFor:'printing & storing'! |
0 | 218 |
|
219 |
printAllOn:aStream |
|
220 |
self printAllOn:aStream indent:4 |
|
221 |
! |
|
222 |
||
223 |
printAllOn:aStream indent:i |
|
224 |
|thisStatement| |
|
225 |
||
226 |
thisStatement := self. |
|
227 |
[thisStatement notNil] whileTrue:[ |
|
1379 | 228 |
aStream spaces:i. |
229 |
thisStatement printOn:aStream indent:i. |
|
230 |
thisStatement nextStatement notNil ifTrue:[ |
|
1633 | 231 |
aStream nextPut:$.. |
1379 | 232 |
aStream cr. |
233 |
]. |
|
234 |
thisStatement := thisStatement nextStatement |
|
0 | 235 |
] |
140 | 236 |
! |
237 |
||
238 |
printOn:aStream indent:i |
|
239 |
expression printOn:aStream indent:i. |
|
0 | 240 |
! ! |
140 | 241 |
|
242 |
!StatementNode methodsFor:'queries'! |
|
243 |
||
392
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
244 |
collectBlocksInto:aCollection |
511
c144804051db
handle corrupt expression (nil) in statement
Claus Gittinger <cg@exept.de>
parents:
392
diff
changeset
|
245 |
|this ex| |
392
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
246 |
|
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
247 |
this := self. |
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
248 |
[this notNil] whileTrue:[ |
511
c144804051db
handle corrupt expression (nil) in statement
Claus Gittinger <cg@exept.de>
parents:
392
diff
changeset
|
249 |
ex := this expression. |
c144804051db
handle corrupt expression (nil) in statement
Claus Gittinger <cg@exept.de>
parents:
392
diff
changeset
|
250 |
ex notNil ifTrue:[ |
c144804051db
handle corrupt expression (nil) in statement
Claus Gittinger <cg@exept.de>
parents:
392
diff
changeset
|
251 |
ex collectBlocksInto:aCollection. |
c144804051db
handle corrupt expression (nil) in statement
Claus Gittinger <cg@exept.de>
parents:
392
diff
changeset
|
252 |
]. |
392
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
253 |
this := this nextStatement |
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
254 |
]. |
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
255 |
|
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
256 |
"Created: 23.10.1996 / 15:44:13 / cg" |
511
c144804051db
handle corrupt expression (nil) in statement
Claus Gittinger <cg@exept.de>
parents:
392
diff
changeset
|
257 |
"Modified: 20.4.1997 / 12:10:18 / cg" |
392
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
258 |
! |
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
259 |
|
2065 | 260 |
isSimpleConstant |
140 | 261 |
nextStatement notNil ifTrue:[^ false]. |
262 |
^ expression isConstant |
|
332
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
263 |
! |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
264 |
|
2103 | 265 |
isSimpleExpression |
266 |
nextStatement notNil ifTrue:[^ false]. |
|
267 |
^ expression notNil |
|
268 |
! |
|
269 |
||
2065 | 270 |
isSimpleVariable |
271 |
nextStatement notNil ifTrue:[^ false]. |
|
272 |
^ expression isVariable |
|
273 |
! |
|
274 |
||
332
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
275 |
listEndsWithReturn |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
276 |
|thisStatement lastStatement| |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
277 |
|
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
278 |
thisStatement := self. |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
279 |
[thisStatement notNil] whileTrue:[ |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
280 |
lastStatement := thisStatement. |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
281 |
thisStatement := thisStatement nextStatement |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
282 |
]. |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
283 |
|
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
284 |
^ lastStatement isReturnNode |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
285 |
|
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
286 |
"Created: 19.8.1996 / 14:32:47 / cg" |
140 | 287 |
! ! |
288 |
||
392
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
289 |
!StatementNode class methodsFor:'documentation'! |
148 | 290 |
|
291 |
version |
|
2103 | 292 |
^ '$Header: /cvs/stx/stx/libcomp/StatementNode.st,v 1.35 2008-07-25 12:45:46 cg Exp $' |
148 | 293 |
! ! |