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