author | Claus Gittinger <cg@exept.de> |
Sun, 02 Feb 2003 16:52:47 +0100 | |
changeset 1366 | f91f6a0a56d5 |
parent 1313 | 9ecf8d3ea043 |
child 1379 | 7cbcca310b75 |
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 |
||
105 |
codeForSideEffectOn:aStream inBlock:b for:aCompiler |
|
106 |
"generate code for this statement - value not needed" |
|
107 |
||
985 | 108 |
expression notNil ifTrue:[ |
109 |
expression codeForSideEffectOn:aStream inBlock:b for:aCompiler |
|
110 |
] |
|
0 | 111 |
! |
112 |
||
140 | 113 |
codeOn:aStream inBlock:b for:aCompiler |
114 |
"generate code for this statement" |
|
115 |
||
1313 | 116 |
expression notNil ifTrue:[ |
117 |
expression codeOn:aStream inBlock:b for:aCompiler |
|
118 |
] |
|
0 | 119 |
! ! |
120 |
||
1209 | 121 |
!StatementNode methodsFor:'converting'! |
122 |
||
123 |
asCollectionOfStatements |
|
124 |
"returns a orderedCollection of statements, |
|
125 |
representing the list of which the receiver is the head" |
|
126 |
||
127 |
|coll stat| |
|
128 |
||
129 |
coll := OrderedCollection new. |
|
130 |
stat := self. |
|
131 |
[stat notNil] whileTrue:[ |
|
132 |
coll add:stat. |
|
133 |
stat := stat nextStatement. |
|
134 |
]. |
|
135 |
^ coll |
|
136 |
! ! |
|
137 |
||
1035 | 138 |
!StatementNode methodsFor:'enumerating'! |
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
139 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
140 |
nodeDo:anEnumerator |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
141 |
"helper for parse tree walking" |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
142 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
143 |
|stats this| |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
144 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
145 |
"/ 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
|
146 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
147 |
stats := OrderedCollection new. |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
148 |
this := self. |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
149 |
[this notNil] whileTrue:[ |
542 | 150 |
stats add:this expression. |
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
151 |
this := this nextStatement |
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 |
^ anEnumerator doSequence:self temporaries:#() statements:stats |
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 |
"Created: 19.6.1997 / 16:45:34 / cg" |
542 | 156 |
"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
|
157 |
! ! |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
158 |
|
1035 | 159 |
!StatementNode methodsFor:'evaluation'! |
140 | 160 |
|
161 |
evaluate |
|
162 |
|lastValue thisStatement| |
|
52 | 163 |
|
140 | 164 |
"this could be done more elegant - but with lots of recursion" |
165 |
thisStatement := self. |
|
166 |
[thisStatement notNil] whileTrue:[ |
|
167 |
lastValue := thisStatement evaluateExpression. |
|
168 |
thisStatement := thisStatement nextStatement |
|
169 |
]. |
|
170 |
^ lastValue |
|
171 |
! |
|
172 |
||
173 |
evaluateExpression |
|
174 |
^ expression evaluate |
|
52 | 175 |
! ! |
176 |
||
1080 | 177 |
!StatementNode methodsFor:'printing & storing'! |
0 | 178 |
|
179 |
printAllOn:aStream |
|
180 |
self printAllOn:aStream indent:4 |
|
181 |
! |
|
182 |
||
183 |
printAllOn:aStream indent:i |
|
184 |
|thisStatement| |
|
185 |
||
186 |
thisStatement := self. |
|
187 |
[thisStatement notNil] whileTrue:[ |
|
98 | 188 |
aStream spaces:i. |
52 | 189 |
thisStatement printOn:aStream indent:i. |
190 |
thisStatement nextStatement notNil ifTrue:[ |
|
191 |
aStream nextPut:$.. |
|
192 |
aStream cr. |
|
193 |
]. |
|
194 |
thisStatement := thisStatement nextStatement |
|
0 | 195 |
] |
140 | 196 |
! |
197 |
||
198 |
printOn:aStream indent:i |
|
199 |
expression printOn:aStream indent:i. |
|
0 | 200 |
! ! |
140 | 201 |
|
202 |
!StatementNode methodsFor:'queries'! |
|
203 |
||
392
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
204 |
collectBlocksInto:aCollection |
511
c144804051db
handle corrupt expression (nil) in statement
Claus Gittinger <cg@exept.de>
parents:
392
diff
changeset
|
205 |
|this ex| |
392
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
206 |
|
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
207 |
this := self. |
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
208 |
[this notNil] whileTrue:[ |
511
c144804051db
handle corrupt expression (nil) in statement
Claus Gittinger <cg@exept.de>
parents:
392
diff
changeset
|
209 |
ex := this expression. |
c144804051db
handle corrupt expression (nil) in statement
Claus Gittinger <cg@exept.de>
parents:
392
diff
changeset
|
210 |
ex notNil ifTrue:[ |
c144804051db
handle corrupt expression (nil) in statement
Claus Gittinger <cg@exept.de>
parents:
392
diff
changeset
|
211 |
ex collectBlocksInto:aCollection. |
c144804051db
handle corrupt expression (nil) in statement
Claus Gittinger <cg@exept.de>
parents:
392
diff
changeset
|
212 |
]. |
392
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
213 |
this := this nextStatement |
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
214 |
]. |
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
215 |
|
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
216 |
"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
|
217 |
"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
|
218 |
! |
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
219 |
|
140 | 220 |
isConstant |
221 |
nextStatement notNil ifTrue:[^ false]. |
|
222 |
^ expression isConstant |
|
332
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
223 |
! |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
224 |
|
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
225 |
listEndsWithReturn |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
226 |
|thisStatement lastStatement| |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
227 |
|
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
228 |
thisStatement := self. |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
229 |
[thisStatement notNil] whileTrue:[ |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
230 |
lastStatement := thisStatement. |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
231 |
thisStatement := thisStatement nextStatement |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
232 |
]. |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
233 |
|
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
234 |
^ lastStatement isReturnNode |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
235 |
|
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
236 |
"Created: 19.8.1996 / 14:32:47 / cg" |
140 | 237 |
! ! |
238 |
||
392
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
239 |
!StatementNode class methodsFor:'documentation'! |
148 | 240 |
|
241 |
version |
|
1313 | 242 |
^ '$Header: /cvs/stx/stx/libcomp/StatementNode.st,v 1.26 2002-08-23 08:48:38 cg Exp $' |
148 | 243 |
! ! |