forked from pharo-project/pharo
/
Variable.class.st
276 lines (220 loc) · 5.42 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
"
I am abstract. Subclasses of me model meta objects for any kind of variables: slots (instance variables), global variables (Class, Global, Pool) and potentialy local variables of methods (temps and args).
Currently I only unify Slots, LiteralVariables and TemporaryVariable (recently introduced).
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 requried 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 : #'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 : #'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 : #OCVARIABLE }
Variable >> isArg [
^false
]
{ #category : #OCVARIABLE }
Variable >> isClassVariable [
^ false
]
{ #category : #OCVARIABLE }
Variable >> isGlobal [
^false
]
{ #category : #OCVARIABLE }
Variable >> isGlobalVariable [
^ false
]
{ #category : #OCVARIABLE }
Variable >> isInstance [
^ false
]
{ #category : #OCVARIABLE }
Variable >> isLiteralVariable [
^false
]
{ #category : #testing }
Variable >> isReferenced [
^ self subclassResponsibility
]
{ #category : #OCVARIABLE }
Variable >> isRemote [
^false
]
{ #category : #OCVARIABLE }
Variable >> isSelf [
^false
]
{ #category : #OCVARIABLE }
Variable >> isSelfOrSuper [
^ false
]
{ #category : #OCVARIABLE }
Variable >> isSpecialVariable [
^false
]
{ #category : #OCVARIABLE }
Variable >> isSuper [
^false
]
{ #category : #OCVARIABLE }
Variable >> isTemp [
^ false
]
{ #category : #OCVARIABLE }
Variable >> isThisContext [
^false
]
{ #category : #OCVARIABLE }
Variable >> isUndeclared [
^ false
]
{ #category : #OCVARIABLE }
Variable >> isUninitialized [
^ false
]
{ #category : #OCVARIABLE }
Variable >> isWritable [
^ true
]
{ #category : #accessing }
Variable >> name [
^ name
]
{ #category : #accessing }
Variable >> name: aSymbol [
name := aSymbol
]
{ #category : #OCVARIABLE }
Variable >> originalVar [
^ self
]
{ #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 >> readFromContext: 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 : #OCVARIABLE }
Variable >> semanticNodeClass [
^self class semanticNodeClass
]
{ #category : #queries }
Variable >> usingMethods [
self subclassResponsibility
]
{ #category : #OCVARIABLE }
Variable >> variable [
"I return the first class variable that I model in the case of globals and ivars"
^self
]