author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Tue, 28 Jun 2011 22:06:14 +0200 | |
changeset 2503 | 791583d321c8 |
parent 2387 | 6614ed53a9d1 |
child 2598 | 2f08bc888c24 |
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 |
2503 | 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 |
||
2503 | 63 |
isStatement |
64 |
^true. |
|
65 |
||
66 |
"Created: / 22-02-2011 / 15:04:36 / Jakub <zelenja7@fel.cvut.cz>" |
|
67 |
! |
|
68 |
||
0 | 69 |
last |
70 |
"return the last statement in a list" |
|
71 |
||
72 |
|last this| |
|
73 |
||
74 |
"this could be done more elegant - but with lots of recursion" |
|
75 |
last := self. |
|
76 |
this := self. |
|
77 |
[this notNil] whileTrue:[ |
|
52 | 78 |
last := this. |
79 |
this := this nextStatement |
|
0 | 80 |
]. |
81 |
^ last |
|
82 |
! |
|
83 |
||
711 | 84 |
lineNumber |
392
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
85 |
"return lineNr" |
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
86 |
|
1504 | 87 |
lineNr notNil ifTrue:[^ lineNr]. |
88 |
expression notNil ifTrue:[ ^ expression lineNumber ]. |
|
89 |
nextStatement notNil ifTrue:[^ nextStatement lineNumber]. |
|
90 |
^ nil |
|
392
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
91 |
|
711 | 92 |
"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
|
93 |
! |
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
94 |
|
711 | 95 |
lineNumber:something |
392
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
96 |
"set lineNr" |
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
97 |
|
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
98 |
lineNr := something. |
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
99 |
|
711 | 100 |
"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
|
101 |
! |
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
102 |
|
1504 | 103 |
lineNumberOfFirstMessage |
104 |
|lno| |
|
105 |
||
106 |
lno := self lineNumber. |
|
107 |
self messagesDo:[:m | lno := lno min:(m lineNumber)]. |
|
108 |
^ lno |
|
109 |
! |
|
110 |
||
0 | 111 |
nextStatement |
112 |
^ nextStatement |
|
113 |
! |
|
114 |
||
140 | 115 |
nextStatement:s |
116 |
nextStatement := s |
|
117 |
! ! |
|
118 |
||
119 |
!StatementNode methodsFor:'code generation'! |
|
120 |
||
1379 | 121 |
codeAllForSideEffectOn:aStream inBlock:b for:aCompiler |
122 |
|thisStatement| |
|
123 |
||
124 |
thisStatement := self. |
|
125 |
[thisStatement notNil] whileTrue:[ |
|
126 |
thisStatement codeForSideEffectOn:aStream inBlock:b for:aCompiler. |
|
127 |
thisStatement := thisStatement nextStatement |
|
128 |
]. |
|
129 |
! |
|
130 |
||
140 | 131 |
codeForSideEffectOn:aStream inBlock:b for:aCompiler |
132 |
"generate code for this statement - value not needed" |
|
133 |
||
985 | 134 |
expression notNil ifTrue:[ |
135 |
expression codeForSideEffectOn:aStream inBlock:b for:aCompiler |
|
136 |
] |
|
0 | 137 |
! |
138 |
||
140 | 139 |
codeOn:aStream inBlock:b for:aCompiler |
140 |
"generate code for this statement" |
|
141 |
||
1313 | 142 |
expression notNil ifTrue:[ |
143 |
expression codeOn:aStream inBlock:b for:aCompiler |
|
144 |
] |
|
0 | 145 |
! ! |
146 |
||
1209 | 147 |
!StatementNode methodsFor:'converting'! |
148 |
||
149 |
asCollectionOfStatements |
|
150 |
"returns a orderedCollection of statements, |
|
151 |
representing the list of which the receiver is the head" |
|
152 |
||
153 |
|coll stat| |
|
154 |
||
155 |
coll := OrderedCollection new. |
|
156 |
stat := self. |
|
157 |
[stat notNil] whileTrue:[ |
|
158 |
coll add:stat. |
|
159 |
stat := stat nextStatement. |
|
160 |
]. |
|
161 |
^ coll |
|
162 |
! ! |
|
163 |
||
1035 | 164 |
!StatementNode methodsFor:'enumerating'! |
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
165 |
|
1504 | 166 |
messagesDo:aBlock |
167 |
|s e| |
|
168 |
||
169 |
s := self. |
|
170 |
[s notNil] whileTrue:[ |
|
171 |
e := s expression. |
|
172 |
e notNil ifTrue:[e messagesDo:aBlock]. |
|
173 |
s := s nextStatement |
|
174 |
]. |
|
175 |
! |
|
176 |
||
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
177 |
nodeDo:anEnumerator |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
178 |
"helper for parse tree walking" |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
179 |
|
1585 | 180 |
|stats this expr| |
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
181 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
182 |
"/ 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
|
183 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
184 |
stats := OrderedCollection new. |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
185 |
this := self. |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
186 |
[this notNil] whileTrue:[ |
1592 | 187 |
this isReturnNode ifTrue:[ |
188 |
stats add:this |
|
189 |
] ifFalse:[ |
|
190 |
expr := this expression. |
|
191 |
stats add:(expr ? this). |
|
192 |
]. |
|
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
193 |
this := this nextStatement |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
194 |
]. |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
195 |
^ anEnumerator doSequence:self temporaries:#() statements:stats |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
196 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
197 |
"Created: 19.6.1997 / 16:45:34 / cg" |
542 | 198 |
"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
|
199 |
! ! |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
200 |
|
1035 | 201 |
!StatementNode methodsFor:'evaluation'! |
140 | 202 |
|
1384 | 203 |
evaluateAllIn:anEnvironment |
140 | 204 |
|lastValue thisStatement| |
52 | 205 |
|
140 | 206 |
"this could be done more elegant - but with lots of recursion" |
207 |
thisStatement := self. |
|
208 |
[thisStatement notNil] whileTrue:[ |
|
1384 | 209 |
lastValue := thisStatement evaluateExpressionIn:anEnvironment. |
210 |
thisStatement := thisStatement nextStatement |
|
140 | 211 |
]. |
212 |
^ lastValue |
|
213 |
! |
|
214 |
||
1384 | 215 |
evaluateExpressionIn:anEnvironment |
216 |
^ expression evaluateIn:anEnvironment |
|
217 |
! |
|
218 |
||
219 |
evaluateIn:anEnvironment |
|
220 |
^ self evaluateAllIn:anEnvironment. |
|
52 | 221 |
! ! |
222 |
||
1080 | 223 |
!StatementNode methodsFor:'printing & storing'! |
0 | 224 |
|
225 |
printAllOn:aStream |
|
226 |
self printAllOn:aStream indent:4 |
|
227 |
! |
|
228 |
||
229 |
printAllOn:aStream indent:i |
|
230 |
|thisStatement| |
|
231 |
||
232 |
thisStatement := self. |
|
233 |
[thisStatement notNil] whileTrue:[ |
|
1379 | 234 |
aStream spaces:i. |
235 |
thisStatement printOn:aStream indent:i. |
|
236 |
thisStatement nextStatement notNil ifTrue:[ |
|
1633 | 237 |
aStream nextPut:$.. |
1379 | 238 |
aStream cr. |
239 |
]. |
|
240 |
thisStatement := thisStatement nextStatement |
|
0 | 241 |
] |
140 | 242 |
! |
243 |
||
244 |
printOn:aStream indent:i |
|
2168
be3e52955e96
care for nil expression when printing
Claus Gittinger <cg@exept.de>
parents:
2103
diff
changeset
|
245 |
expression notNil ifTrue:[ expression printOn:aStream indent:i ]. |
0 | 246 |
! ! |
140 | 247 |
|
248 |
!StatementNode methodsFor:'queries'! |
|
249 |
||
392
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
250 |
collectBlocksInto:aCollection |
511
c144804051db
handle corrupt expression (nil) in statement
Claus Gittinger <cg@exept.de>
parents:
392
diff
changeset
|
251 |
|this ex| |
392
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
252 |
|
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
253 |
this := self. |
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
254 |
[this notNil] whileTrue:[ |
511
c144804051db
handle corrupt expression (nil) in statement
Claus Gittinger <cg@exept.de>
parents:
392
diff
changeset
|
255 |
ex := this expression. |
c144804051db
handle corrupt expression (nil) in statement
Claus Gittinger <cg@exept.de>
parents:
392
diff
changeset
|
256 |
ex notNil ifTrue:[ |
c144804051db
handle corrupt expression (nil) in statement
Claus Gittinger <cg@exept.de>
parents:
392
diff
changeset
|
257 |
ex collectBlocksInto:aCollection. |
c144804051db
handle corrupt expression (nil) in statement
Claus Gittinger <cg@exept.de>
parents:
392
diff
changeset
|
258 |
]. |
392
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
259 |
this := this nextStatement |
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
260 |
]. |
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
261 |
|
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
262 |
"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
|
263 |
"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
|
264 |
! |
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
265 |
|
2385 | 266 |
containsReturn |
267 |
^ self expression containsReturn |
|
268 |
! |
|
269 |
||
270 |
containsReturnInAnyStatement |
|
271 |
|s| |
|
272 |
||
273 |
s := self. |
|
274 |
[s notNil] whileTrue:[ |
|
2387 | 275 |
s isReturnNode ifTrue:[^ true]. |
2385 | 276 |
s containsReturn ifTrue:[^ true]. |
277 |
s := s nextStatement. |
|
278 |
]. |
|
279 |
^ false |
|
280 |
! |
|
281 |
||
2065 | 282 |
isSimpleConstant |
140 | 283 |
nextStatement notNil ifTrue:[^ false]. |
284 |
^ expression isConstant |
|
332
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 |
|
2103 | 287 |
isSimpleExpression |
288 |
nextStatement notNil ifTrue:[^ false]. |
|
289 |
^ expression notNil |
|
290 |
! |
|
291 |
||
2065 | 292 |
isSimpleVariable |
293 |
nextStatement notNil ifTrue:[^ false]. |
|
294 |
^ expression isVariable |
|
295 |
! |
|
296 |
||
332
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
297 |
listEndsWithReturn |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
298 |
|thisStatement lastStatement| |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
299 |
|
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
300 |
thisStatement := self. |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
301 |
[thisStatement notNil] whileTrue:[ |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
302 |
lastStatement := thisStatement. |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
303 |
thisStatement := thisStatement nextStatement |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
304 |
]. |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
305 |
|
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
306 |
^ lastStatement isReturnNode |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
307 |
|
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
308 |
"Created: 19.8.1996 / 14:32:47 / cg" |
140 | 309 |
! ! |
310 |
||
2503 | 311 |
!StatementNode methodsFor:'testing'! |
312 |
||
313 |
isStatementNode |
|
314 |
||
315 |
^ true |
|
316 |
||
317 |
"Created: / 13-06-2011 / 11:26:30 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
318 |
"Modified: / 13-06-2011 / 14:05:12 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
319 |
! ! |
|
320 |
||
392
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
321 |
!StatementNode class methodsFor:'documentation'! |
148 | 322 |
|
2503 | 323 |
version_CVS |
324 |
^ '$Header: /cvs/stx/stx/libcomp/StatementNode.st,v 1.39 2011-06-28 20:06:14 vrany Exp $' |
|
2385 | 325 |
! |
326 |
||
2503 | 327 |
version_SVN |
328 |
^ ' Id ' |
|
148 | 329 |
! ! |