author | ca |
Wed, 07 Feb 2007 11:53:20 +0100 | |
changeset 1980 | 8298d33fd68b |
parent 1945 | 5c08a14f6269 |
child 1982 | 2098c5e965ce |
permissions | -rw-r--r-- |
0 | 1 |
" |
4 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
62 | 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 |
393 | 15 |
instanceVariableNames:'myHome blockHome' |
261 | 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 |
|
62 | 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 |
1980 | 128 |
false ifTrue:[ |
1945
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
129 |
aCompiler parserFlags allowPossibleSTCCompilationProblems ifFalse:[ |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
130 |
aCompiler |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
131 |
parseError:'stc will not compile return within a return' |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
132 |
line:lineNr. |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
133 |
] ifTrue:[ |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
134 |
aCompiler parserFlags warnAboutPossibleSTCCompilationProblems ifTrue:[ |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
135 |
aCompiler |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
136 |
warning:'stc will not compile return within a return' |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
137 |
line:lineNr. |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
138 |
]. |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
139 |
]. |
1980 | 140 |
]. |
1945
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
141 |
self basicCodeOn:aStream inBlock:b for:aCompiler |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
142 |
|
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
143 |
"Modified: / 16-11-2006 / 14:34:15 / cg" |
0 | 144 |
! ! |
145 |
||
1035 | 146 |
!ReturnNode methodsFor:'enumerating'! |
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
147 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
148 |
nodeDo:anEnumerator |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
149 |
"helper for parse tree walking" |
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 |
^ anEnumerator doReturn:self value:expression |
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 |
"Modified: 19.6.1997 / 16:42:40 / cg" |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
154 |
! ! |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
155 |
|
1035 | 156 |
!ReturnNode methodsFor:'evaluation'! |
140 | 157 |
|
1383 | 158 |
evaluateExpressionIn:anEnvironment |
140 | 159 |
|val| |
160 |
||
1594 | 161 |
expression notNil ifTrue:[ |
162 |
val := expression evaluateIn:anEnvironment. |
|
163 |
]. |
|
140 | 164 |
myHome exitWith:val. |
165 |
"when we arrive here, the parser context is already gone |
|
166 |
- try block-return" |
|
167 |
blockHome notNil ifTrue:[blockHome exitWith:val]. |
|
168 |
"well - what else can be done" |
|
169 |
^ val |
|
170 |
! ! |
|
171 |
||
1080 | 172 |
!ReturnNode methodsFor:'printing & storing'! |
0 | 173 |
|
174 |
printOn:aStream indent:i |
|
175 |
aStream nextPutAll:'^ '. |
|
176 |
expression printOn:aStream |
|
177 |
! ! |
|
140 | 178 |
|
179 |
!ReturnNode methodsFor:'queries'! |
|
180 |
||
181 |
isConstant |
|
182 |
^ false |
|
183 |
! |
|
184 |
||
185 |
isReturnNode |
|
186 |
^ true |
|
187 |
! ! |
|
188 |
||
148 | 189 |
!ReturnNode class methodsFor:'documentation'! |
190 |
||
191 |
version |
|
1980 | 192 |
^ '$Header: /cvs/stx/stx/libcomp/ReturnNode.st,v 1.36 2007-02-07 10:53:20 ca Exp $' |
148 | 193 |
! ! |