author | Claus Gittinger <cg@exept.de> |
Fri, 25 Jul 2008 14:45:39 +0200 | |
changeset 2101 | 3ce4958aab99 |
parent 1982 | 2098c5e965ce |
child 2397 | 6aea7415db4f |
permissions | -rw-r--r-- |
0 | 1 |
" |
4 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
1982
2098c5e965ce
changed #codeOn:inBlock:for:
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
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 |
" |
|
1080 | 12 |
"{ Package: 'stx:libcomp' }" |
13 |
||
0 | 14 |
StatementNode subclass:#ReturnNode |
2101 | 15 |
instanceVariableNames:'myHome blockHome' |
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'System-Compiler-Support' |
|
0 | 19 |
! |
20 |
||
20 | 21 |
!ReturnNode class methodsFor:'documentation'! |
22 |
||
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
1982
2098c5e965ce
changed #codeOn:inBlock:for:
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
26 |
All Rights Reserved |
20 | 27 |
|
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
36 |
||
37 |
documentation |
|
38 |
" |
|
39 |
node for parse-trees, representing return expressions |
|
261 | 40 |
This is a helper class for the compiler. |
263 | 41 |
|
42 |
[author:] |
|
43 |
Claus Gittinger |
|
20 | 44 |
" |
45 |
! ! |
|
0 | 46 |
|
47 |
!ReturnNode methodsFor:'accessing'! |
|
48 |
||
882
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
49 |
expression:e |
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
50 |
super expression:e. |
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
51 |
|
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
52 |
"/ any block, which is returned cannot be inlined. |
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
53 |
e isBlockNode ifTrue:[ |
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
54 |
e possiblyInlined:false |
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
55 |
] |
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
56 |
|
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
57 |
! |
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
58 |
|
0 | 59 |
home:someOne blockHome:aBlockNode |
60 |
myHome := someOne. |
|
61 |
blockHome := aBlockNode |
|
1945
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
62 |
! |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
63 |
|
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
64 |
lineNumber:something |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
65 |
"set lineNr" |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
66 |
|
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
67 |
lineNr := something. |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
68 |
|
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
69 |
"Created: / 16-11-2006 / 14:38:51 / cg" |
0 | 70 |
! ! |
71 |
||
72 |
!ReturnNode methodsFor:'code generation'! |
|
73 |
||
1945
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
74 |
basicCodeOn:aStream inBlock:b for:aCompiler |
1593 | 75 |
b isNil ifTrue:[ |
76 |
self codeLocalReturnOn:aStream inBlock:b for:aCompiler. |
|
77 |
^ self. |
|
29 | 78 |
]. |
79 |
||
1593 | 80 |
"return from homeContext in a block" |
81 |
expression isNil ifTrue:[ |
|
82 |
"/ nil-expression is not possible in smalltalk; |
|
83 |
"/ however, it might be in a subclass (i.e. JavaScript) |
|
84 |
aStream nextPut:#pushNil. |
|
85 |
] ifFalse:[ |
|
86 |
expression codeOn:aStream inBlock:b for:aCompiler. |
|
87 |
]. |
|
374 | 88 |
lineNr notNil ifTrue:[ |
817 | 89 |
self codeLineNumber:lineNr on:aStream for:aCompiler |
0 | 90 |
]. |
380 | 91 |
aStream nextPut:#homeRetTop. |
374 | 92 |
|
1945
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
93 |
"Created: / 16-11-2006 / 14:05:27 / cg" |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
94 |
! |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
95 |
|
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
96 |
codeForSideEffectOn:aStream inBlock:b for:aCompiler |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
97 |
"redefined - drop not needed since notreached" |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
98 |
|
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
99 |
^ self basicCodeOn:aStream inBlock:b for:aCompiler |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
100 |
|
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
101 |
"Modified: / 16-11-2006 / 14:05:32 / cg" |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
102 |
! |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
103 |
|
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
104 |
codeForSimpleReturnOn:aStream inBlock:b lineNumber:lineNrOrNil for:aCompiler |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
105 |
"generate code to return myself as a simple method return" |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
106 |
|
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
107 |
self basicCodeOn:aStream inBlock:b for:aCompiler. |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
108 |
|
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
109 |
"as a ReturnNode, I did return, so retTop is not needed" |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
110 |
"/ aStream nextPut:#retTop. |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
111 |
|
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
112 |
"Modified: / 16-11-2006 / 14:05:35 / cg" |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
113 |
! |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
114 |
|
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
115 |
codeLocalReturnOn:aStream inBlock:b for:aCompiler |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
116 |
expression isNil ifTrue:[ |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
117 |
aStream nextPut:#retNil. |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
118 |
^ self. |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
119 |
]. |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
120 |
expression |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
121 |
codeForSimpleReturnOn:aStream |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
122 |
inBlock:b |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
123 |
lineNumber:lineNr |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
124 |
for:aCompiler. |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
125 |
! |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
126 |
|
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
127 |
codeOn:aStream inBlock:b for:aCompiler |
1982
2098c5e965ce
changed #codeOn:inBlock:for:
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
128 |
"/ aCompiler parserFlags allowPossibleSTCCompilationProblems ifFalse:[ |
2098c5e965ce
changed #codeOn:inBlock:for:
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
129 |
"/ aCompiler |
2098c5e965ce
changed #codeOn:inBlock:for:
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
130 |
"/ parseError:'stc will not compile return within a return' |
2098c5e965ce
changed #codeOn:inBlock:for:
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
131 |
"/ line:lineNr. |
2098c5e965ce
changed #codeOn:inBlock:for:
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
132 |
"/ ] ifTrue:[ |
2098c5e965ce
changed #codeOn:inBlock:for:
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
133 |
"/ aCompiler parserFlags warnAboutPossibleSTCCompilationProblems ifTrue:[ |
2098c5e965ce
changed #codeOn:inBlock:for:
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
134 |
"/ aCompiler |
2098c5e965ce
changed #codeOn:inBlock:for:
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
135 |
"/ warning:'stc will not compile return within a return' |
2098c5e965ce
changed #codeOn:inBlock:for:
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
136 |
"/ line:lineNr. |
2098c5e965ce
changed #codeOn:inBlock:for:
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
137 |
"/ ]. |
2098c5e965ce
changed #codeOn:inBlock:for:
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
138 |
"/ ]. |
1945
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
139 |
self basicCodeOn:aStream inBlock:b for:aCompiler |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
140 |
|
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
141 |
"Modified: / 16-11-2006 / 14:34:15 / cg" |
0 | 142 |
! ! |
143 |
||
1035 | 144 |
!ReturnNode methodsFor:'enumerating'! |
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
145 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
146 |
nodeDo:anEnumerator |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
147 |
"helper for parse tree walking" |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
148 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
149 |
^ anEnumerator doReturn:self value:expression |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
150 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
151 |
"Modified: 19.6.1997 / 16:42:40 / cg" |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
152 |
! ! |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
153 |
|
1035 | 154 |
!ReturnNode methodsFor:'evaluation'! |
140 | 155 |
|
1383 | 156 |
evaluateExpressionIn:anEnvironment |
140 | 157 |
|val| |
158 |
||
1594 | 159 |
expression notNil ifTrue:[ |
160 |
val := expression evaluateIn:anEnvironment. |
|
161 |
]. |
|
140 | 162 |
myHome exitWith:val. |
163 |
"when we arrive here, the parser context is already gone |
|
164 |
- try block-return" |
|
165 |
blockHome notNil ifTrue:[blockHome exitWith:val]. |
|
166 |
"well - what else can be done" |
|
167 |
^ val |
|
168 |
! ! |
|
169 |
||
1080 | 170 |
!ReturnNode methodsFor:'printing & storing'! |
0 | 171 |
|
172 |
printOn:aStream indent:i |
|
173 |
aStream nextPutAll:'^ '. |
|
174 |
expression printOn:aStream |
|
175 |
! ! |
|
140 | 176 |
|
177 |
!ReturnNode methodsFor:'queries'! |
|
178 |
||
179 |
isConstant |
|
180 |
^ false |
|
181 |
! |
|
182 |
||
183 |
isReturnNode |
|
184 |
^ true |
|
2101 | 185 |
! |
186 |
||
187 |
isSimpleConstant |
|
188 |
^ false |
|
189 |
! |
|
190 |
||
191 |
isSimpleExpression |
|
192 |
^ false |
|
193 |
! |
|
194 |
||
195 |
isSimpleVariable |
|
196 |
^ false |
|
140 | 197 |
! ! |
198 |
||
148 | 199 |
!ReturnNode class methodsFor:'documentation'! |
200 |
||
201 |
version |
|
2101 | 202 |
^ '$Header: /cvs/stx/stx/libcomp/ReturnNode.st,v 1.38 2008-07-25 12:45:39 cg Exp $' |
148 | 203 |
! ! |