/
RBLiteralArrayNode.class.st
164 lines (143 loc) · 4.31 KB
/
RBLiteralArrayNode.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
"
A RBLiteralArrayNode is an AST node that represents literal arrays and literal byte arrays.
Instance Variables
contents: <Array of: RBLiteralNode> literal nodes of the array
isByteArray: <Boolean> if the receiver is a literal byte array
"
Class {
#name : #RBLiteralArrayNode,
#superclass : #RBLiteralNode,
#instVars : [
'isByteArray',
'contents'
],
#category : #'AST-Core-Nodes'
}
{ #category : #'instance creation' }
RBLiteralArrayNode class >> startPosition: startInteger contents: anArray stopPosition: stopInteger isByteArray: aBoolean [
^(self new)
startPosition: startInteger
contents: anArray
stopPosition: stopInteger
isByteArray: aBoolean;
yourself
]
{ #category : #'instance creation' }
RBLiteralArrayNode class >> value: aValue [
^(self new)
startPosition: 0
contents: (aValue asArray collect: [:each | RBLiteralNode value: each])
stopPosition: -1
isByteArray: aValue class ~~ Array;
yourself
]
{ #category : #comparing }
RBLiteralArrayNode >> = anObject [
super = anObject ifFalse: [^false].
self isForByteArray = anObject isForByteArray ifFalse: [^false].
self contents size = anObject contents size ifFalse: [^false].
self contents
with: anObject contents
do: [:first :second | first = second ifFalse: [^false]].
^true
]
{ #category : #visiting }
RBLiteralArrayNode >> acceptVisitor: aProgramNodeVisitor [
^aProgramNodeVisitor visitLiteralArrayNode: self
]
{ #category : #accessing }
RBLiteralArrayNode >> children [
^contents
]
{ #category : #accessing }
RBLiteralArrayNode >> contents [
^contents
]
{ #category : #initialization }
RBLiteralArrayNode >> contents: aRBLiteralNodeCollection [
contents := aRBLiteralNodeCollection.
contents do: [:each | each parent: self]
]
{ #category : #matching }
RBLiteralArrayNode >> copyInContext: aDictionary [
^ self class
startPosition: 0
contents: (self copyList: self contents inContext: aDictionary)
stopPosition: -1
isByteArray: isByteArray
]
{ #category : #generation }
RBLiteralArrayNode >> dumpOn: aStream [
aStream
nextPutAll: self class name;
nextPutAll: ' value: #('.
(self contents collect: [ :each | each value ]) printOn: aStream delimiter: ' '.
aStream nextPutAll: ')'
]
{ #category : #comparing }
RBLiteralArrayNode >> equalTo: anObject withMapping: aDictionary [
self class = anObject class ifFalse: [^false].
self isForByteArray = anObject isForByteArray ifFalse: [^false].
self contents size = anObject contents size ifFalse: [^false].
self contents
with: anObject contents
do: [:first :second | (first equalTo: second withMapping: aDictionary) ifFalse: [^false]].
^true
]
{ #category : #testing }
RBLiteralArrayNode >> isFaulty [
^self contents anySatisfy: #isFaulty
]
{ #category : #testing }
RBLiteralArrayNode >> isForByteArray [
^isByteArray
]
{ #category : #testing }
RBLiteralArrayNode >> isLiteralArray [
^true
]
{ #category : #matching }
RBLiteralArrayNode >> match: aNode inContext: aDictionary [
aNode class = self class ifFalse: [^false].
self isForByteArray = aNode isForByteArray ifFalse: [^false].
^self
matchList: contents
against: aNode contents
inContext: aDictionary
]
{ #category : #copying }
RBLiteralArrayNode >> postCopy [
super postCopy.
self contents: (self contents collect: [ :each | each copy ])
]
{ #category : #replacing }
RBLiteralArrayNode >> replaceNode: aNode withNode: anotherNode [
self contents: (contents
collect: [:each | each == aNode ifTrue: [anotherNode] ifFalse: [each]])
]
{ #category : #'private-replacing' }
RBLiteralArrayNode >> replaceSourceWith: aNode [
(self class = aNode class and:
[self isForByteArray = aNode isForByteArray
and: [self contents size = aNode contents size]])
ifFalse: [^super replaceSourceWith: aNode].
self contents
with: aNode contents
do: [:first :second | first = second ifFalse: [ first replaceSourceWith: second]]
]
{ #category : #initialization }
RBLiteralArrayNode >> startPosition: startInteger contents: anArray stopPosition: stopInteger isByteArray: aBoolean [
start := startInteger.
self contents: anArray.
stop := stopInteger.
isByteArray := aBoolean
]
{ #category : #accessing }
RBLiteralArrayNode >> value [
| array |
array := (isByteArray ifTrue: [ByteArray] ifFalse: [Array])
new: contents size.
1 to: contents size
do: [:each | array at: each put: (contents at: each) value].
^array
]