author | Claus Gittinger <cg@exept.de> |
Tue, 06 May 2003 16:03:55 +0200 | |
changeset 1409 | e965cfbd9a78 |
parent 1384 | 0db9682870d9 |
child 1504 | eb26e6d08d71 |
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 |
|
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
82 |
^ lineNr |
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
83 |
|
711 | 84 |
"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
|
85 |
! |
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
86 |
|
711 | 87 |
lineNumber:something |
392
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
88 |
"set lineNr" |
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
89 |
|
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
90 |
lineNr := something. |
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:11 / 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 |
|
0 | 95 |
nextStatement |
96 |
^ nextStatement |
|
97 |
! |
|
98 |
||
140 | 99 |
nextStatement:s |
100 |
nextStatement := s |
|
101 |
! ! |
|
102 |
||
103 |
!StatementNode methodsFor:'code generation'! |
|
104 |
||
1379 | 105 |
codeAllForSideEffectOn:aStream inBlock:b for:aCompiler |
106 |
|thisStatement| |
|
107 |
||
108 |
thisStatement := self. |
|
109 |
[thisStatement notNil] whileTrue:[ |
|
110 |
thisStatement codeForSideEffectOn:aStream inBlock:b for:aCompiler. |
|
111 |
thisStatement := thisStatement nextStatement |
|
112 |
]. |
|
113 |
! |
|
114 |
||
140 | 115 |
codeForSideEffectOn:aStream inBlock:b for:aCompiler |
116 |
"generate code for this statement - value not needed" |
|
117 |
||
985 | 118 |
expression notNil ifTrue:[ |
119 |
expression codeForSideEffectOn:aStream inBlock:b for:aCompiler |
|
120 |
] |
|
0 | 121 |
! |
122 |
||
140 | 123 |
codeOn:aStream inBlock:b for:aCompiler |
124 |
"generate code for this statement" |
|
125 |
||
1313 | 126 |
expression notNil ifTrue:[ |
127 |
expression codeOn:aStream inBlock:b for:aCompiler |
|
128 |
] |
|
0 | 129 |
! ! |
130 |
||
1209 | 131 |
!StatementNode methodsFor:'converting'! |
132 |
||
133 |
asCollectionOfStatements |
|
134 |
"returns a orderedCollection of statements, |
|
135 |
representing the list of which the receiver is the head" |
|
136 |
||
137 |
|coll stat| |
|
138 |
||
139 |
coll := OrderedCollection new. |
|
140 |
stat := self. |
|
141 |
[stat notNil] whileTrue:[ |
|
142 |
coll add:stat. |
|
143 |
stat := stat nextStatement. |
|
144 |
]. |
|
145 |
^ coll |
|
146 |
! ! |
|
147 |
||
1035 | 148 |
!StatementNode methodsFor:'enumerating'! |
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
149 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
150 |
nodeDo:anEnumerator |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
151 |
"helper for parse tree walking" |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
152 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
153 |
|stats this| |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
154 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
155 |
"/ 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
|
156 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
157 |
stats := OrderedCollection new. |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
158 |
this := self. |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
159 |
[this notNil] whileTrue:[ |
542 | 160 |
stats add:this expression. |
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
161 |
this := this nextStatement |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
162 |
]. |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
163 |
^ anEnumerator doSequence:self temporaries:#() statements:stats |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
164 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
165 |
"Created: 19.6.1997 / 16:45:34 / cg" |
542 | 166 |
"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
|
167 |
! ! |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
168 |
|
1035 | 169 |
!StatementNode methodsFor:'evaluation'! |
140 | 170 |
|
1384 | 171 |
evaluateAllIn:anEnvironment |
140 | 172 |
|lastValue thisStatement| |
52 | 173 |
|
140 | 174 |
"this could be done more elegant - but with lots of recursion" |
175 |
thisStatement := self. |
|
176 |
[thisStatement notNil] whileTrue:[ |
|
1384 | 177 |
lastValue := thisStatement evaluateExpressionIn:anEnvironment. |
178 |
thisStatement := thisStatement nextStatement |
|
140 | 179 |
]. |
180 |
^ lastValue |
|
181 |
! |
|
182 |
||
1384 | 183 |
evaluateExpressionIn:anEnvironment |
184 |
^ expression evaluateIn:anEnvironment |
|
185 |
! |
|
186 |
||
187 |
evaluateIn:anEnvironment |
|
188 |
^ self evaluateAllIn:anEnvironment. |
|
52 | 189 |
! ! |
190 |
||
1080 | 191 |
!StatementNode methodsFor:'printing & storing'! |
0 | 192 |
|
193 |
printAllOn:aStream |
|
194 |
self printAllOn:aStream indent:4 |
|
195 |
! |
|
196 |
||
197 |
printAllOn:aStream indent:i |
|
198 |
|thisStatement| |
|
199 |
||
200 |
thisStatement := self. |
|
201 |
[thisStatement notNil] whileTrue:[ |
|
1379 | 202 |
aStream spaces:i. |
203 |
thisStatement printOn:aStream indent:i. |
|
204 |
thisStatement nextStatement notNil ifTrue:[ |
|
205 |
aStream cr. |
|
206 |
]. |
|
207 |
thisStatement := thisStatement nextStatement |
|
0 | 208 |
] |
140 | 209 |
! |
210 |
||
211 |
printOn:aStream indent:i |
|
212 |
expression printOn:aStream indent:i. |
|
0 | 213 |
! ! |
140 | 214 |
|
215 |
!StatementNode methodsFor:'queries'! |
|
216 |
||
392
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
217 |
collectBlocksInto:aCollection |
511
c144804051db
handle corrupt expression (nil) in statement
Claus Gittinger <cg@exept.de>
parents:
392
diff
changeset
|
218 |
|this ex| |
392
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
219 |
|
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
220 |
this := self. |
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
221 |
[this notNil] whileTrue:[ |
511
c144804051db
handle corrupt expression (nil) in statement
Claus Gittinger <cg@exept.de>
parents:
392
diff
changeset
|
222 |
ex := this expression. |
c144804051db
handle corrupt expression (nil) in statement
Claus Gittinger <cg@exept.de>
parents:
392
diff
changeset
|
223 |
ex notNil ifTrue:[ |
c144804051db
handle corrupt expression (nil) in statement
Claus Gittinger <cg@exept.de>
parents:
392
diff
changeset
|
224 |
ex collectBlocksInto:aCollection. |
c144804051db
handle corrupt expression (nil) in statement
Claus Gittinger <cg@exept.de>
parents:
392
diff
changeset
|
225 |
]. |
392
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
226 |
this := this nextStatement |
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
227 |
]. |
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
228 |
|
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
229 |
"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
|
230 |
"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
|
231 |
! |
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
232 |
|
140 | 233 |
isConstant |
234 |
nextStatement notNil ifTrue:[^ false]. |
|
235 |
^ expression isConstant |
|
332
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
236 |
! |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
237 |
|
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
238 |
listEndsWithReturn |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
239 |
|thisStatement lastStatement| |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
240 |
|
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
241 |
thisStatement := self. |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
242 |
[thisStatement notNil] whileTrue:[ |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
243 |
lastStatement := thisStatement. |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
244 |
thisStatement := thisStatement nextStatement |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
245 |
]. |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
246 |
|
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
247 |
^ lastStatement isReturnNode |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
248 |
|
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
249 |
"Created: 19.8.1996 / 14:32:47 / cg" |
140 | 250 |
! ! |
251 |
||
392
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
252 |
!StatementNode class methodsFor:'documentation'! |
148 | 253 |
|
254 |
version |
|
1384 | 255 |
^ '$Header: /cvs/stx/stx/libcomp/StatementNode.st,v 1.28 2003-03-28 14:41:25 cg Exp $' |
148 | 256 |
! ! |