author | Claus Gittinger <cg@exept.de> |
Mon, 19 Aug 1996 14:43:17 +0200 | |
changeset 332 | 7ffd2016cf73 |
parent 263 | 3b21d0991eff |
child 392 | cce48e2f0778 |
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 |
|
261 | 14 |
instanceVariableNames:'expression nextStatement' |
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'System-Compiler-Support' |
|
0 | 18 |
! |
19 |
||
332
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
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 |
|
332
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
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 |
||
77 |
nextStatement |
|
78 |
^ nextStatement |
|
79 |
! |
|
80 |
||
140 | 81 |
nextStatement:s |
82 |
nextStatement := s |
|
83 |
! ! |
|
84 |
||
85 |
!StatementNode methodsFor:'code generation'! |
|
86 |
||
87 |
codeForSideEffectOn:aStream inBlock:b for:aCompiler |
|
88 |
"generate code for this statement - value not needed" |
|
89 |
||
90 |
expression codeForSideEffectOn:aStream inBlock:b for:aCompiler |
|
0 | 91 |
! |
92 |
||
140 | 93 |
codeOn:aStream inBlock:b for:aCompiler |
94 |
"generate code for this statement" |
|
95 |
||
96 |
expression codeOn:aStream inBlock:b for:aCompiler |
|
0 | 97 |
! ! |
98 |
||
140 | 99 |
!StatementNode methodsFor:'evaluating'! |
100 |
||
101 |
evaluate |
|
102 |
|lastValue thisStatement| |
|
52 | 103 |
|
140 | 104 |
"this could be done more elegant - but with lots of recursion" |
105 |
thisStatement := self. |
|
106 |
[thisStatement notNil] whileTrue:[ |
|
107 |
lastValue := thisStatement evaluateExpression. |
|
108 |
thisStatement := thisStatement nextStatement |
|
109 |
]. |
|
110 |
^ lastValue |
|
111 |
! |
|
112 |
||
113 |
evaluateExpression |
|
114 |
^ expression evaluate |
|
52 | 115 |
! ! |
116 |
||
0 | 117 |
!StatementNode methodsFor:'printing'! |
118 |
||
119 |
printAllOn:aStream |
|
120 |
self printAllOn:aStream indent:4 |
|
121 |
! |
|
122 |
||
123 |
printAllOn:aStream indent:i |
|
124 |
|thisStatement| |
|
125 |
||
126 |
thisStatement := self. |
|
127 |
[thisStatement notNil] whileTrue:[ |
|
98 | 128 |
aStream spaces:i. |
52 | 129 |
thisStatement printOn:aStream indent:i. |
130 |
thisStatement nextStatement notNil ifTrue:[ |
|
131 |
aStream nextPut:$.. |
|
132 |
aStream cr. |
|
133 |
]. |
|
134 |
thisStatement := thisStatement nextStatement |
|
0 | 135 |
] |
140 | 136 |
! |
137 |
||
138 |
printOn:aStream indent:i |
|
139 |
expression printOn:aStream indent:i. |
|
0 | 140 |
! ! |
140 | 141 |
|
142 |
!StatementNode methodsFor:'queries'! |
|
143 |
||
144 |
isConstant |
|
145 |
nextStatement notNil ifTrue:[^ false]. |
|
146 |
^ expression isConstant |
|
332
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
147 |
! |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
148 |
|
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
149 |
listEndsWithReturn |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
150 |
|thisStatement lastStatement| |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
151 |
|
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
152 |
thisStatement := self. |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
153 |
[thisStatement notNil] whileTrue:[ |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
154 |
lastStatement := thisStatement. |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
155 |
thisStatement := thisStatement nextStatement |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
156 |
]. |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
157 |
|
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
158 |
^ lastStatement isReturnNode |
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
159 |
|
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
160 |
"Created: 19.8.1996 / 14:32:47 / cg" |
140 | 161 |
! ! |
162 |
||
332
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
163 |
!StatementNode class methodsFor:'documentation'! |
148 | 164 |
|
165 |
version |
|
332
7ffd2016cf73
added query if statementList ends in a return
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
166 |
^ '$Header: /cvs/stx/stx/libcomp/StatementNode.st,v 1.16 1996-08-19 12:43:17 cg Exp $' |
148 | 167 |
! ! |