author | Claus Gittinger <cg@exept.de> |
Sat, 12 Feb 2000 16:34:02 +0100 | |
changeset 1035 | 8848672cb893 |
parent 882 | 0bc2a6ecdfad |
child 1080 | bd3f19f6009a |
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 |
" |
|
12 |
||
13 |
StatementNode subclass:#ReturnNode |
|
393 | 14 |
instanceVariableNames:'myHome blockHome' |
261 | 15 |
classVariableNames:'' |
16 |
poolDictionaries:'' |
|
17 |
category:'System-Compiler-Support' |
|
0 | 18 |
! |
19 |
||
20 | 20 |
!ReturnNode class methodsFor:'documentation'! |
21 |
||
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
62 | 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 return expressions |
|
261 | 39 |
This is a helper class for the compiler. |
263 | 40 |
|
41 |
[author:] |
|
42 |
Claus Gittinger |
|
20 | 43 |
" |
44 |
! ! |
|
0 | 45 |
|
380 | 46 |
!ReturnNode class methodsFor:'code generation helper'! |
47 |
||
48 |
codeSimpleReturnFor:expression inBlock:b on:aStream inLine:lineNrOrNil for:aCompiler |
|
843
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
49 |
"/ let expression decide how to do it efficiently. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
50 |
expression |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
51 |
codeForSimpleReturnOn:aStream |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
52 |
inBlock:b |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
53 |
lineNumber:lineNrOrNil |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
54 |
for:aCompiler |
380 | 55 |
|
56 |
"Created: 21.10.1996 / 14:37:35 / cg" |
|
57 |
"Modified: 21.10.1996 / 14:43:11 / cg" |
|
58 |
! ! |
|
59 |
||
0 | 60 |
!ReturnNode methodsFor:'accessing'! |
61 |
||
882
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
62 |
expression:e |
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
63 |
super expression:e. |
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
64 |
|
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
65 |
"/ 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
|
66 |
e isBlockNode ifTrue:[ |
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
67 |
e possiblyInlined:false |
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
68 |
] |
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
69 |
|
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
70 |
! |
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
71 |
|
0 | 72 |
home:someOne blockHome:aBlockNode |
73 |
myHome := someOne. |
|
74 |
blockHome := aBlockNode |
|
75 |
! ! |
|
76 |
||
77 |
!ReturnNode methodsFor:'code generation'! |
|
78 |
||
104 | 79 |
codeForSideEffectOn:aStream inBlock:b for:aCompiler |
0 | 80 |
"redefined - drop not needed since notreached" |
81 |
||
104 | 82 |
^ self codeOn:aStream inBlock:b for:aCompiler |
0 | 83 |
! |
84 |
||
104 | 85 |
codeOn:aStream inBlock:b for:aCompiler |
380 | 86 |
b isNil ifTrue:[ |
87 |
^ self class |
|
88 |
codeSimpleReturnFor:expression |
|
89 |
inBlock:nil |
|
90 |
on:aStream |
|
91 |
inLine:lineNr |
|
92 |
for:aCompiler |
|
29 | 93 |
]. |
94 |
||
380 | 95 |
expression codeOn:aStream inBlock:b for:aCompiler. |
96 |
||
374 | 97 |
lineNr notNil ifTrue:[ |
817 | 98 |
self codeLineNumber:lineNr on:aStream for:aCompiler |
0 | 99 |
]. |
374 | 100 |
|
380 | 101 |
aStream nextPut:#homeRetTop. |
374 | 102 |
|
380 | 103 |
"Modified: 21.10.1996 / 14:54:36 / cg" |
0 | 104 |
! ! |
105 |
||
1035 | 106 |
!ReturnNode methodsFor:'enumerating'! |
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
107 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
108 |
nodeDo:anEnumerator |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
109 |
"helper for parse tree walking" |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
110 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
111 |
^ anEnumerator doReturn:self value:expression |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
112 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
113 |
"Modified: 19.6.1997 / 16:42:40 / cg" |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
114 |
! ! |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
115 |
|
1035 | 116 |
!ReturnNode methodsFor:'evaluation'! |
140 | 117 |
|
118 |
evaluateExpression |
|
119 |
|val| |
|
120 |
||
121 |
val := expression evaluate. |
|
122 |
myHome exitWith:val. |
|
123 |
"when we arrive here, the parser context is already gone |
|
124 |
- try block-return" |
|
125 |
blockHome notNil ifTrue:[blockHome exitWith:val]. |
|
126 |
"well - what else can be done" |
|
127 |
^ val |
|
128 |
! ! |
|
129 |
||
0 | 130 |
!ReturnNode methodsFor:'printing'! |
131 |
||
132 |
printOn:aStream indent:i |
|
133 |
aStream nextPutAll:'^ '. |
|
134 |
expression printOn:aStream |
|
135 |
! ! |
|
140 | 136 |
|
137 |
!ReturnNode methodsFor:'queries'! |
|
138 |
||
139 |
isConstant |
|
140 |
^ false |
|
141 |
! |
|
142 |
||
143 |
isReturnNode |
|
144 |
^ true |
|
145 |
! ! |
|
146 |
||
148 | 147 |
!ReturnNode class methodsFor:'documentation'! |
148 |
||
149 |
version |
|
1035 | 150 |
^ '$Header: /cvs/stx/stx/libcomp/ReturnNode.st,v 1.24 2000-02-12 15:32:34 cg Exp $' |
148 | 151 |
! ! |