author | Claus Gittinger <cg@exept.de> |
Thu, 19 Jun 1997 18:38:52 +0200 | |
changeset 542 | 728300bd8861 |
parent 539 | 69a1cd05c7d6 |
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:#AssignmentNode |
|
375 | 14 |
instanceVariableNames:'variable expression lineNr' |
219
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
15 |
classVariableNames:'' |
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
16 |
poolDictionaries:'' |
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
17 |
category:'System-Compiler-Support' |
0 | 18 |
! |
19 |
||
20 | 20 |
!AssignmentNode class methodsFor:'documentation'! |
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 |
" |
|
261 | 38 |
node for parse-trees, representing assignments. |
39 |
This is a helper class for the compiler. |
|
263 | 40 |
|
41 |
[author:] |
|
42 |
Claus Gittinger |
|
43 |
||
20 | 44 |
" |
45 |
! ! |
|
0 | 46 |
|
47 |
!AssignmentNode class methodsFor:'instance creation'! |
|
48 |
||
49 |
variable:v expression:e |
|
50 |
^ (self basicNew) variable:v expression:e |
|
51 |
! ! |
|
52 |
||
140 | 53 |
!AssignmentNode methodsFor:'accessing'! |
0 | 54 |
|
140 | 55 |
expression |
56 |
^ expression |
|
57 |
! |
|
0 | 58 |
|
375 | 59 |
lineNr |
60 |
"return lineNr" |
|
61 |
||
62 |
^ lineNr |
|
63 |
||
64 |
"Created: 21.10.1996 / 11:49:01 / cg" |
|
65 |
! |
|
66 |
||
67 |
lineNr:something |
|
68 |
"set lineNr" |
|
69 |
||
70 |
lineNr := something. |
|
71 |
||
72 |
"Created: 21.10.1996 / 11:49:01 / cg" |
|
73 |
! |
|
74 |
||
542 | 75 |
variable |
76 |
^ variable |
|
77 |
||
78 |
"Created: 19.6.1997 / 17:08:58 / cg" |
|
79 |
! |
|
80 |
||
0 | 81 |
variable:v expression:e |
82 |
variable := v. |
|
83 |
expression := e |
|
84 |
! ! |
|
85 |
||
86 |
!AssignmentNode methodsFor:'code generation'! |
|
87 |
||
117 | 88 |
checkIncDecOn:aStream |
219
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
89 |
"check if we can use incMvar / decMvar instruction. |
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
90 |
If so, code it and return true. |
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
91 |
Otherwise, return false." |
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
92 |
|
117 | 93 |
|sel erec arg code| |
0 | 94 |
|
95 |
(variable type == #MethodVariable) ifTrue:[ |
|
219
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
96 |
expression isBinaryMessage ifTrue:[ |
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
97 |
sel := expression selector. |
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
98 |
erec := expression receiver. |
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
99 |
|
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
100 |
((sel == #+) or:[sel == #-]) ifTrue:[ |
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
101 |
(erec type == #MethodVariable) ifTrue:[ |
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
102 |
(erec index == variable index) ifTrue:[ |
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
103 |
arg := expression arg1. |
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
104 |
arg isConstant ifTrue:[ |
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
105 |
(arg value == 1) ifTrue:[ |
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
106 |
(sel == #+) ifTrue:[ |
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
107 |
code := #incMethodVar |
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
108 |
] ifFalse:[ |
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
109 |
code := #decMethodVar |
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
110 |
]. |
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
111 |
aStream nextPut:code; nextPut:(expression lineNumber); nextPut:(variable index). |
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
112 |
^ true |
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
113 |
] |
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
114 |
] |
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
115 |
] |
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
116 |
] |
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
117 |
] |
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
118 |
] |
0 | 119 |
]. |
117 | 120 |
^ false |
219
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
121 |
|
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
122 |
"Modified: 1.3.1996 / 00:08:02 / cg" |
117 | 123 |
! |
124 |
||
125 |
codeForSideEffectOn:aStream inBlock:b for:aCompiler |
|
126 |
(self checkIncDecOn:aStream) ifTrue:[^ self]. |
|
219
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
127 |
|
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
128 |
self codeNormalOn:aStream valueNeeded:false inBlock:b for:aCompiler |
117 | 129 |
|
130 |
"Modified: 4.9.1995 / 14:38:10 / claus" |
|
219
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
131 |
"Modified: 1.3.1996 / 00:42:10 / cg" |
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
132 |
! |
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
133 |
|
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
134 |
codeNormalOn:aStream valueNeeded:forValue inBlock:b for:aCompiler |
386 | 135 |
|isSend| |
136 |
||
137 |
isSend := expression isMessage. |
|
138 |
(lineNr notNil |
|
139 |
and:[isSend not]) ifTrue:[ |
|
140 |
ParseNode codeLineNumber:lineNr on:aStream for:aCompiler |
|
141 |
]. |
|
142 |
||
219
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
143 |
expression codeOn:aStream inBlock:b for:aCompiler. |
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
144 |
expression isBlock ifTrue:[ |
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
145 |
variable isLocal ifTrue:[ |
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
146 |
aStream nextPut:#blockRef |
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
147 |
] |
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
148 |
]. |
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
149 |
|
386 | 150 |
(lineNr notNil |
151 |
and:[isSend]) ifTrue:[ |
|
381 | 152 |
ParseNode codeLineNumber:lineNr on:aStream for:aCompiler |
375 | 153 |
]. |
219
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
154 |
variable codeStoreOn:aStream inBlock:b valueNeeded:forValue for:aCompiler |
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
155 |
|
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
156 |
"Modified: 4.9.1995 / 14:38:10 / claus" |
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
157 |
"Created: 1.3.1996 / 00:41:43 / cg" |
386 | 158 |
"Modified: 21.10.1996 / 16:26:33 / cg" |
0 | 159 |
! |
160 |
||
104 | 161 |
codeOn:aStream inBlock:b for:aCompiler |
117 | 162 |
(self checkIncDecOn:aStream) ifTrue:[ |
219
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
163 |
expression receiver codeOn:aStream inBlock:b for:aCompiler. |
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
164 |
^ self |
117 | 165 |
]. |
219
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
166 |
|
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
167 |
self codeNormalOn:aStream valueNeeded:true inBlock:b for:aCompiler |
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
168 |
|
6b977f472cda
care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
169 |
"Modified: 1.3.1996 / 00:42:21 / cg" |
0 | 170 |
! ! |
171 |
||
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
479
diff
changeset
|
172 |
!AssignmentNode methodsFor:'enumeration'! |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
479
diff
changeset
|
173 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
479
diff
changeset
|
174 |
nodeDo:anEnumerator |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
479
diff
changeset
|
175 |
"helper for parse tree walking" |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
479
diff
changeset
|
176 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
479
diff
changeset
|
177 |
^ anEnumerator doAssignment:self variable:variable value:expression |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
479
diff
changeset
|
178 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
479
diff
changeset
|
179 |
"Modified: 19.6.1997 / 16:37:50 / cg" |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
479
diff
changeset
|
180 |
! ! |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
479
diff
changeset
|
181 |
|
140 | 182 |
!AssignmentNode methodsFor:'evaluating'! |
183 |
||
184 |
evaluate |
|
185 |
|value| |
|
186 |
value := expression evaluate. |
|
187 |
variable store:value. |
|
188 |
^ value |
|
189 |
! ! |
|
190 |
||
0 | 191 |
!AssignmentNode methodsFor:'printing'! |
192 |
||
193 |
printOn:aStream indent:i |
|
194 |
variable printOn:aStream. |
|
195 |
aStream nextPutAll:' := '. |
|
196 |
expression printOn:aStream |
|
197 |
! ! |
|
140 | 198 |
|
199 |
!AssignmentNode methodsFor:'queries'! |
|
200 |
||
479 | 201 |
collectBlocksInto:aCollection |
202 |
expression collectBlocksInto:aCollection. |
|
203 |
||
204 |
"Created: 11.1.1997 / 20:54:30 / cg" |
|
205 |
! |
|
206 |
||
140 | 207 |
isAssignment |
208 |
"return true, if this is a node for an assignment" |
|
209 |
||
210 |
^ true |
|
211 |
! ! |
|
212 |
||
148 | 213 |
!AssignmentNode class methodsFor:'documentation'! |
214 |
||
215 |
version |
|
542 | 216 |
^ '$Header: /cvs/stx/stx/libcomp/AssignmentNode.st,v 1.25 1997-06-19 16:38:36 cg Exp $' |
148 | 217 |
! ! |