@@ -144,10 +144,14 @@ public struct Syntax: SyntaxProtocol, SyntaxHashable {
144
144
/// - Parameters:
145
145
/// - newRaw: The node that should replace `self`
146
146
/// - rawNodeArena: The arena in which `newRaw` resides
147
- /// - allocationArena : The arena in which new nodes should be allocated
147
+ /// - rawAllocationArena : The arena in which new nodes should be allocated
148
148
/// - Returns: A syntax tree with all parents where this node has been
149
149
/// replaced by `newRaw`
150
- func replacingSelf( _ newRaw: RawSyntax , rawNodeArena: RetainedRawSyntaxArena , allocationArena: RawSyntaxArena ) -> Syntax {
150
+ func replacingSelf(
151
+ _ newRaw: RawSyntax ,
152
+ rawNodeArena: RetainedRawSyntaxArena ,
153
+ rawAllocationArena: RawSyntaxArena
154
+ ) -> Syntax {
151
155
precondition ( newRaw. arenaReference == rawNodeArena)
152
156
// If we have a parent already, then ask our current parent to copy itself
153
157
// recursively up to the root.
@@ -156,7 +160,7 @@ public struct Syntax: SyntaxProtocol, SyntaxHashable {
156
160
at: layoutIndexInParent,
157
161
with: newRaw,
158
162
rawNodeArena: rawNodeArena,
159
- allocationArena : allocationArena
163
+ rawAllocationArena : rawAllocationArena
160
164
)
161
165
return newParent. child ( at: layoutIndexInParent) !
162
166
} else {
@@ -172,75 +176,91 @@ public struct Syntax: SyntaxProtocol, SyntaxHashable {
172
176
/// - index: The index pointing to where in the raw layout to place this
173
177
/// child.
174
178
/// - newChild: The raw syntax for the new child to replace.
175
- /// - newChildArena : The arena in which `newChild` resides.
176
- /// - arena : The arena in which the new node will be allocated.
179
+ /// - rawNodeArena : The arena in which `newChild` resides.
180
+ /// - rawAllocationArena : The arena in which the new node will be allocated.
177
181
/// - Returns: The new root node created by this operation, and the new child
178
182
/// syntax data.
179
183
/// - SeeAlso: replacingSelf(_:)
180
184
func replacingChild(
181
185
at index: Int ,
182
186
with newChild: RawSyntax ? ,
183
187
rawNodeArena: RetainedRawSyntaxArena ? ,
184
- allocationArena : RawSyntaxArena
188
+ rawAllocationArena : RawSyntaxArena
185
189
) -> Syntax {
186
190
precondition ( newChild == nil || ( rawNodeArena != nil && newChild!. arenaReference == rawNodeArena!) )
187
191
// After newRaw has been allocated in `allocationArena`, `rawNodeArena` will
188
192
// be a child arena of `allocationArena` and thus, `allocationArena` will
189
193
// keep `newChild` alive.
190
194
let newRaw = withExtendedLifetime ( rawNodeArena) {
191
- raw. layoutView!. replacingChild ( at: index, with: newChild, arena: allocationArena )
195
+ raw. layoutView!. replacingChild ( at: index, with: newChild, arena: rawAllocationArena )
192
196
}
193
- return replacingSelf ( newRaw, rawNodeArena: RetainedRawSyntaxArena ( allocationArena) , allocationArena: allocationArena)
197
+ return replacingSelf (
198
+ newRaw,
199
+ rawNodeArena: RetainedRawSyntaxArena ( rawAllocationArena) ,
200
+ rawAllocationArena: rawAllocationArena
201
+ )
194
202
}
195
203
196
- /// Same as `replacingChild(at:with:rawNodeArena:allocationArena :)` but takes a `__RawSyntaxArena` instead of a `RetainedRawSyntaxArena`.
204
+ /// Same as `replacingChild(at:with:rawNodeArena:rawAllocationArena :)` but takes a `__RawSyntaxArena` instead of a `RetainedRawSyntaxArena`.
197
205
func replacingChild(
198
206
at index: Int ,
199
207
with newChild: RawSyntax ? ,
200
208
rawNodeArena: RawSyntaxArena ? ,
201
- allocationArena : RawSyntaxArena
209
+ rawAllocationArena : RawSyntaxArena
202
210
) -> Syntax {
203
211
return self . replacingChild (
204
212
at: index,
205
213
with: newChild,
206
214
rawNodeArena: rawNodeArena. map ( RetainedRawSyntaxArena . init) ,
207
- allocationArena : allocationArena
215
+ rawAllocationArena : rawAllocationArena
208
216
)
209
217
}
210
218
211
- /// Identical to `replacingChild(at: Int, with: RawSyntax?, arena : RawSyntaxArena)`
219
+ /// Identical to `replacingChild(at: Int, with: RawSyntax?, rawAllocationArena : RawSyntaxArena)`
212
220
/// that ensures that the arena of`newChild` doesn’t get de-allocated before
213
221
/// `newChild` has been addded to the result.
214
- func replacingChild( at index: Int , with newChild: Syntax ? , arena : RawSyntaxArena ) -> Syntax {
222
+ func replacingChild( at index: Int , with newChild: Syntax ? , rawAllocationArena : RawSyntaxArena ) -> Syntax {
215
223
return withExtendedLifetime ( newChild) {
216
224
return replacingChild (
217
225
at: index,
218
226
with: newChild? . raw,
219
227
rawNodeArena: newChild? . raw. arenaReference. retained,
220
- allocationArena : arena
228
+ rawAllocationArena : rawAllocationArena
221
229
)
222
230
}
223
231
}
224
232
225
- func withLeadingTrivia( _ leadingTrivia: Trivia , arena: RawSyntaxArena ) -> Syntax {
226
- if let raw = raw. withLeadingTrivia ( leadingTrivia, arena: arena) {
227
- return replacingSelf ( raw, rawNodeArena: RetainedRawSyntaxArena ( arena) , allocationArena: arena)
233
+ func withLeadingTrivia( _ leadingTrivia: Trivia , rawAllocationArena: RawSyntaxArena ) -> Syntax {
234
+ if let raw = raw. withLeadingTrivia ( leadingTrivia, arena: rawAllocationArena) {
235
+ return replacingSelf (
236
+ raw,
237
+ rawNodeArena: RetainedRawSyntaxArena ( rawAllocationArena) ,
238
+ rawAllocationArena: rawAllocationArena
239
+ )
228
240
} else {
229
241
return self
230
242
}
231
243
}
232
244
233
- func withTrailingTrivia( _ trailingTrivia: Trivia , arena: RawSyntaxArena ) -> Syntax {
234
- if let raw = raw. withTrailingTrivia ( trailingTrivia, arena: arena) {
235
- return replacingSelf ( raw, rawNodeArena: RetainedRawSyntaxArena ( arena) , allocationArena: arena)
245
+ func withTrailingTrivia( _ trailingTrivia: Trivia , rawAllocationArena: RawSyntaxArena ) -> Syntax {
246
+ if let raw = raw. withTrailingTrivia ( trailingTrivia, arena: rawAllocationArena) {
247
+ return replacingSelf (
248
+ raw,
249
+ rawNodeArena: RetainedRawSyntaxArena ( rawAllocationArena) ,
250
+ rawAllocationArena: rawAllocationArena
251
+ )
236
252
} else {
237
253
return self
238
254
}
239
255
}
240
256
241
- func withPresence( _ presence: SourcePresence , arena: RawSyntaxArena ) -> Syntax {
242
- if let raw = raw. tokenView? . withPresence ( presence, arena: arena) {
243
- return replacingSelf ( raw, rawNodeArena: RetainedRawSyntaxArena ( arena) , allocationArena: arena)
257
+ func withPresence( _ presence: SourcePresence , rawAllocationArena: RawSyntaxArena ) -> Syntax {
258
+ if let raw = raw. tokenView? . withPresence ( presence, arena: rawAllocationArena) {
259
+ return replacingSelf (
260
+ raw,
261
+ rawNodeArena: RetainedRawSyntaxArena ( rawAllocationArena) ,
262
+ rawAllocationArena: rawAllocationArena
263
+ )
244
264
} else {
245
265
return self
246
266
}
0 commit comments