forked from pharo-project/pharo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Variable.class.st
334 lines (268 loc) · 6.92 KB
/
Variable.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
"
I am an abstract class. Subclasses of me model meta objects for any kind of variables:
- slots (instance variables)
- literal variables (Class, Global, Pool) and
- local variables of methods (temps and args).
Being a superclass for LiteralVariable I have a restriction on my layout: I can only have a single instance variable representing the variable #name
DO NOT ADD ANY NEW STATE TO ME.
This restriction is required because LiteralVariable encodes global references in the method literals and therefore there is an expectation from the VM on particular shape of these objects.
At this step I only pulled a duplicated protocol of properties from my subclasses. But more cleanup is comming:
- breakpoints
- metalinks
- queries
- refactoring commands
Internal Representation and Key Implementation Points.
Instance Variables
name: <Symbol>
"
Class {
#name : #Variable,
#superclass : #Object,
#instVars : [
'name'
],
#classVars : [
'Properties'
],
#category : #'Kernel-Variables'
}
{ #category : #validating }
Variable class >> checkValidName: aString [
]
{ #category : #'class initialization' }
Variable class >> initialize [
Properties := Properties
ifNil: [ WeakIdentityKeyDictionary new. ]
ifNotNil: [ (WeakIdentityKeyDictionary newFrom: Properties) rehash]
]
{ #category : #testing }
Variable class >> isAbstract [
^self = Variable
]
{ #category : #'instance creation' }
Variable class >> named: aSymbol [
self checkValidName: aSymbol.
^ self new
name: aSymbol;
yourself
]
{ #category : #comparing }
Variable >> = other [
"Every subclass that adds state must redefine this method"
self == other
ifTrue: [ ^ true ].
^ (self species == other species)
and: [ name = other name ]
]
{ #category : #visiting }
Variable >> acceptVisitor: aProgramNodeVisitor node: aNode [
^ aProgramNodeVisitor visitVariableNode: aNode
]
{ #category : #converting }
Variable >> asDoItVariableFrom: aContext [
^ DoItVariable fromContext: aContext variable: self
]
{ #category : #queries }
Variable >> definingNode [
^ nil
]
{ #category : #'code generation' }
Variable >> emitStore: methodBuilder [
self subclassResponsibility
]
{ #category : #'code generation' }
Variable >> emitValue: methodBuilder [
self subclassResponsibility
]
{ #category : #properties }
Variable >> ensureProperties [
^ Properties at: self ifAbsentPut: WeakKeyDictionary new
]
{ #category : #properties }
Variable >> hasProperty: aKey [
"Test if the property aKey is present."
^self properties
ifNil: [false]
ifNotNil: [:prop | prop includesKey: aKey]
]
{ #category : #comparing }
Variable >> hash [
"Every subclass that adds state must redefine this method"
^ self species hash bitXor: self name hash
]
{ #category : #testing }
Variable >> isAccessedIn: aMethod [
^self usingMethods includes: aMethod
]
{ #category : #testing }
Variable >> isArgumentVariable [
^false
]
{ #category : #testing }
Variable >> isClassVariable [
^ false
]
{ #category : #testing }
Variable >> isDefinedByBlock [
"true if a variable node is defined by a block"
^false
]
{ #category : #testing }
Variable >> isGlobalVariable [
^ false
]
{ #category : #testing }
Variable >> isInstanceVariable [
"check if the var is an instance variable (a Slot)"
^false
]
{ #category : #testing }
Variable >> isLiteralVariable [
"returns true for Global Variables, Class Variables and some others
(e.g. Workspace bindings and Undeclared variables, see subclasses)"
^false
]
{ #category : #testing }
Variable >> isLocalVariable [
"temporary variables and arguments are local variables"
^false
]
{ #category : #testing }
Variable >> isReadIn: aCompiledCode [
^aCompiledCode ast readNodes
anySatisfy: [ :node | node binding == self ]
]
{ #category : #testing }
Variable >> isReferenced [
^ self usingMethods isNotEmpty
]
{ #category : #testing }
Variable >> isReservedVariable [
"thisContext, super, self are reserved variables (true, false and nil are literals)"
^false
]
{ #category : #testing }
Variable >> isSelfOrSuperVariable [
^ self isSelfVariable or: [ self isSuperVariable ]
]
{ #category : #testing }
Variable >> isSelfVariable [
^false
]
{ #category : #testing }
Variable >> isSuperVariable [
^false
]
{ #category : #testing }
Variable >> isTempVariable [
^false
]
{ #category : #testing }
Variable >> isThisContextVariable [
^false
]
{ #category : #testing }
Variable >> isUndeclaredVariable [
^ false
]
{ #category : #testing }
Variable >> isUninitialized [
^ false
]
{ #category : #testing }
Variable >> isUsed [
^ self isReferenced
]
{ #category : #testing }
Variable >> isWorkspaceVariable [
^ false
]
{ #category : #testing }
Variable >> isWritable [
^ true
]
{ #category : #testing }
Variable >> isWrittenIn: aCompiledCode [
^aCompiledCode ast variableWriteNodes
anySatisfy: [ :node | node binding == self ]
]
{ #category : #accessing }
Variable >> name [
^ name
]
{ #category : #accessing }
Variable >> name: aSymbol [
name := aSymbol
]
{ #category : #testing }
Variable >> needsFullDefinition [
"all but InstanceVariableSlot and ClassVariable need to print the full definition"
^true
]
{ #category : #properties }
Variable >> properties [
^ Properties at: self ifAbsent: nil
]
{ #category : #properties }
Variable >> propertyAt: propName [
^ self
propertyAt: propName
ifAbsent: [ nil ]
]
{ #category : #properties }
Variable >> propertyAt: propName ifAbsent: aBlock [
self properties ifNil: [^aBlock value].
^ self properties
at: propName
ifAbsent: aBlock
]
{ #category : #properties }
Variable >> propertyAt: aKey ifAbsentPut: aBlock [
"Answer the property associated with aKey or, if aKey isn't found store the result of evaluating aBlock as new value."
^ self propertyAt: aKey ifAbsent: [ self propertyAt: aKey put: aBlock value ]
]
{ #category : #properties }
Variable >> propertyAt: propName put: propValue [
^ self ensureProperties
at: propName
put: propValue
]
{ #category : #debugging }
Variable >> readInContext: aContext [
self subclassResponsibility
]
{ #category : #properties }
Variable >> removePropertiesIfEmpty [
^ Properties at: self ifPresent: [ :dict |
dict ifEmpty: [ Properties removeKey: self ] ]
]
{ #category : #properties }
Variable >> removeProperty: propName [
^ self
removeProperty: propName
ifAbsent: [ nil ]
]
{ #category : #properties }
Variable >> removeProperty: propName ifAbsent: aBlock [
| property |
self properties ifNil: [^aBlock value].
property := self properties
removeKey: propName
ifAbsent: aBlock.
self removePropertiesIfEmpty.
^ property
]
{ #category : #accessing }
Variable >> scope [
^self subclassResponsibility
]
{ #category : #queries }
Variable >> usingMethods [
self subclassResponsibility
]
{ #category : #debugging }
Variable >> write: aValue inContext: aContext [
"write the value in aContext. All #write:inContext: methods need to return the assigned value,
as this is the reflective version of assignment which has the assigned value as a value"
^self subclassResponsibility
]