-
Notifications
You must be signed in to change notification settings - Fork 65
/
TVariableNode.class.st
149 lines (113 loc) · 3.07 KB
/
TVariableNode.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
Class {
#name : #TVariableNode,
#superclass : #TParseNode,
#instVars : [
'name'
],
#category : #'Slang-AST'
}
{ #category : #'instance creation' }
TVariableNode class >> named: aName [
^ self new
setName: aName;
yourself
]
{ #category : #'instance creation' }
TVariableNode class >> selfNode [
^ self named: 'self'
]
{ #category : #visiting }
TVariableNode >> accept: aVisitor [
^ aVisitor visitVariableNode: self
]
{ #category : #tranforming }
TVariableNode >> asCASTIn: aBuilder [
^ name = 'nil'
ifTrue: [ CIdentifierNode name: aBuilder nilTranslation ]
ifFalse: [ CIdentifierNode name: (aBuilder returnPrefixFromVariable: name) ]
]
{ #category : #transformations }
TVariableNode >> bindVariableUsesIn: aDictionary [
^ (aDictionary at: name ifAbsent: [^ self]) copy
]
{ #category : #transformations }
TVariableNode >> bindVariableUsesIn: aDictionary andConstantFoldIf: constantFold in: codeGen [
"Answer either the receiver, if it is not a reference to one of the given variables, or the replacement if it is."
^(aDictionary at: name ifAbsent: [^self]) copy
]
{ #category : #transformations }
TVariableNode >> bindVariablesIn: aDictionary [
^ (aDictionary at: name ifAbsent: [^ self]) copy
]
{ #category : #transformations }
TVariableNode >> bindVariablesIn: aDictionary unless: cautionaryBlock [
(cautionaryBlock value: self) ifTrue: [^self].
^ (aDictionary at: name ifAbsent: [^ self]) copy
]
{ #category : #accessing }
TVariableNode >> children [
^ #()
]
{ #category : #displaying }
TVariableNode >> displayString [
^ name asString
]
{ #category : #testing }
TVariableNode >> hasSideEffect [
"Answer if the parse tree rooted at this node has a side-effect or not."
^false
]
{ #category : #testing }
TVariableNode >> isLeaf [
^true
]
{ #category : #comparing }
TVariableNode >> isSameAs: aTParseNode [
^aTParseNode isVariable
and: [name = aTParseNode name]
]
{ #category : #testing }
TVariableNode >> isVariable [
^true
]
{ #category : #accessing }
TVariableNode >> name [
^name asString
]
{ #category : #accessing }
TVariableNode >> nameOrValue [
^name
]
{ #category : #enumerating }
TVariableNode >> nodesDo: aBlock parent: parent [
"Apply aBlock to all nodes in the receiver with each node's parent.
N.B. This is assumed to be bottom-up, leaves first."
aBlock value: self value: parent
]
{ #category : #printing }
TVariableNode >> printOn: aStream level: level [
super printOn: aStream level: level.
aStream
nextPutAll: '(';
nextPutAll: name;
nextPutAll: ')'
]
{ #category : #accessing }
TVariableNode >> setName: aString [
name := aString.
]
{ #category : #testing }
TVariableNode >> structTargetKindIn: aCodeGen [
"Answer if the recever evaluates to a struct or struct pointer
and hence can be dereferenced using . or ->. Answer any of
#struct #pointer or nil"
^aCodeGen structTargetKindForVariableName: name
]
{ #category : #'type inference' }
TVariableNode >> typeOrNilFrom: aCodeGenerator in: aTMethod [
^aTMethod typeFor: self name in: aCodeGenerator
]
{ #category : #accessing }
TVariableNode >> variableNameOrNil [
^name
]