author | Stefan Vogel <sv@exept.de> |
Fri, 06 Mar 1998 16:38:37 +0100 | |
changeset 657 | 0ecf1ff6f6bf |
parent 542 | 728300bd8861 |
child 711 | 25b9a501b97d |
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 |
||
13 |
ParseNode subclass:#StatementNode |
|
392
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
14 |
instanceVariableNames:'expression nextStatement lineNr' |
261 | 15 |
classVariableNames:'' |
16 |
poolDictionaries:'' |
|
17 |
category:'System-Compiler-Support' |
|
0 | 18 |
! |
19 |
||
392
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
20 |
!StatementNode class methodsFor:'documentation'! |
20 | 21 |
|
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
52 | 25 |
All Rights Reserved |
20 | 26 |
|
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
36 |
documentation |
|
37 |
" |
|
38 |
node for parse-trees, representing statements |
|
261 | 39 |
This is a helper class for the compiler. |
263 | 40 |
|
41 |
[author:] |
|
42 |
Claus Gittinger |
|
20 | 43 |
" |
44 |
! ! |
|
0 | 45 |
|
392
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
46 |
!StatementNode class methodsFor:'instance creation'! |
0 | 47 |
|
48 |
expression:e |
|
49 |
^ (self basicNew) expression:e |
|
50 |
! ! |
|
51 |
||
140 | 52 |
!StatementNode methodsFor:'accessing'! |
0 | 53 |
|
140 | 54 |
expression |
55 |
^ expression |
|
0 | 56 |
! |
57 |
||
140 | 58 |
expression:e |
59 |
expression := e |
|
0 | 60 |
! |
61 |
||
62 |
last |
|
63 |
"return the last statement in a list" |
|
64 |
||
65 |
|last this| |
|
66 |
||
67 |
"this could be done more elegant - but with lots of recursion" |
|
68 |
last := self. |
|
69 |
this := self. |
|
70 |
[this notNil] whileTrue:[ |
|
52 | 71 |
last := this. |
72 |
this := this nextStatement |
|
0 | 73 |
]. |
74 |
^ last |
|
75 |
! |
|
76 |
||
392
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
77 |
lineNr |
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
78 |
"return lineNr" |
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
79 |
|
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
80 |
^ 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 |
"Created: 23.10.1996 / 14:51:54 / cg" |
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
83 |
! |
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
84 |
|
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
85 |
lineNr:something |
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
86 |
"set lineNr" |
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 |
lineNr := something. |
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 |
"Created: 23.10.1996 / 14:51:58 / cg" |
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 |
|
0 | 93 |
nextStatement |
94 |
^ nextStatement |
|
95 |
! |
|
96 |
||
140 | 97 |
nextStatement:s |
98 |
nextStatement := s |
|
99 |
! ! |
|
100 |
||
101 |
!StatementNode methodsFor:'code generation'! |
|
102 |
||
103 |
codeForSideEffectOn:aStream inBlock:b for:aCompiler |
|
104 |
"generate code for this statement - value not needed" |
|
105 |
||
106 |
expression codeForSideEffectOn:aStream inBlock:b for:aCompiler |
|
0 | 107 |
! |
108 |
||
140 | 109 |
codeOn:aStream inBlock:b for:aCompiler |
110 |
"generate code for this statement" |
|
111 |
||
112 |
expression codeOn:aStream inBlock:b for:aCompiler |
|
0 | 113 |
! ! |
114 |
||
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
115 |
!StatementNode methodsFor:'enumeration'! |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
116 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
117 |
nodeDo:anEnumerator |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
118 |
"helper for parse tree walking" |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
119 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
120 |
|stats this| |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
121 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
122 |
"/ 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
|
123 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
124 |
stats := OrderedCollection new. |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
125 |
this := self. |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
126 |
[this notNil] whileTrue:[ |
542 | 127 |
stats add:this expression. |
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
128 |
this := this nextStatement |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
129 |
]. |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
130 |
^ anEnumerator doSequence:self temporaries:#() statements:stats |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
131 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
132 |
"Created: 19.6.1997 / 16:45:34 / cg" |
542 | 133 |
"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
|
134 |
! ! |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
135 |
|
140 | 136 |
!StatementNode methodsFor:'evaluating'! |
137 |
||
138 |
evaluate |
|
139 |
|lastValue thisStatement| |
|
52 | 140 |
|
140 | 141 |
"this could be done more elegant - but with lots of recursion" |
142 |
thisStatement := self. |
|
143 |
[thisStatement notNil] whileTrue:[ |
|
144 |
lastValue := thisStatement evaluateExpression. |
|
145 |
thisStatement := thisStatement nextStatement |
|
146 |
]. |
|
147 |
^ lastValue |
|
148 |
! |
|
149 |
||
150 |
evaluateExpression |
|
151 |
^ expression evaluate |
|
52 | 152 |
! ! |
153 |
||
0 | 154 |
!StatementNode methodsFor:'printing'! |
155 |
||
156 |
printAllOn:aStream |
|
157 |
self printAllOn:aStream indent:4 |
|
158 |
! |
|
159 |
||
160 |
printAllOn:aStream indent:i |
|
161 |
|thisStatement| |
|
162 |
||
163 |
thisStatement := self. |
|
164 |
[thisStatement notNil] whileTrue:[ |
|
98 | 165 |
aStream spaces:i. |
52 | 166 |
thisStatement printOn:aStream indent:i. |
167 |
thisStatement nextStatement notNil ifTrue:[ |
|
168 |
aStream nextPut:$.. |
|
169 |
aStream cr. |
|
170 |
]. |
|
171 |
thisStatement := thisStatement nextStatement |
|
0 | 172 |
] |
140 | 173 |
! |
174 |
||
175 |
printOn:aStream indent:i |
|
176 |
expression printOn:aStream indent:i. |
|
0 | 177 |
! ! |
140 | 178 |
|
179 |
!StatementNode methodsFor:'queries'! |
|
180 |
||
392
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
181 |
collectBlocksInto:aCollection |
511
c144804051db
handle corrupt expression (nil) in statement
Claus Gittinger <cg@exept.de>
parents:
392
diff
changeset
|
182 |
|this ex| |
392
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
183 |
|
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
184 |
this := self. |
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
185 |
[this notNil] whileTrue:[ |
511
c144804051db
handle corrupt expression (nil) in statement
Claus Gittinger <cg@exept.de>
parents:
392
diff
changeset
|
186 |
ex := this expression. |
c144804051db
handle corrupt expression (nil) in statement
Claus Gittinger <cg@exept.de>
parents:
392
diff
changeset
|
187 |
ex notNil ifTrue:[ |
c144804051db
handle corrupt expression (nil) in statement
Claus Gittinger <cg@exept.de>
parents:
392
diff
changeset
|
188 |
ex collectBlocksInto:aCollection. |
c144804051db
handle corrupt expression (nil) in statement
Claus Gittinger <cg@exept.de>
parents:
392
diff
changeset
|
189 |
]. |
392
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
190 |
this := this nextStatement |
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
191 |
]. |
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
192 |
|
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
193 |
"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
|
194 |
"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
|
195 |
! |
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
196 |
|
140 | 197 |
isConstant |
198 |
nextStatement notNil ifTrue:[^ false]. |
|
199 |
^ expression isConstant |
|
332
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
200 |
! |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
201 |
|
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
202 |
listEndsWithReturn |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
203 |
|thisStatement lastStatement| |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
204 |
|
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
205 |
thisStatement := self. |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
206 |
[thisStatement notNil] whileTrue:[ |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
207 |
lastStatement := thisStatement. |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
208 |
thisStatement := thisStatement nextStatement |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
209 |
]. |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
210 |
|
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
211 |
^ lastStatement isReturnNode |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
212 |
|
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
213 |
"Created: 19.8.1996 / 14:32:47 / cg" |
140 | 214 |
! ! |
215 |
||
392
cce48e2f0778
moved lineNr instVar up to here
Claus Gittinger <cg@exept.de>
parents:
332
diff
changeset
|
216 |
!StatementNode class methodsFor:'documentation'! |
148 | 217 |
|
218 |
version |
|
542 | 219 |
^ '$Header: /cvs/stx/stx/libcomp/Attic/StatNode.st,v 1.20 1997-06-19 16:38:28 cg Exp $' |
148 | 220 |
! ! |