Skip to content

Commit ad3b3ab

Browse files
committed
Extract header nodes from DeclGroups
This also involves changing Child.Refactoring to support a new kind of change: “extracted”, in which a group of adjacent children are moved into a new child node. Future commits will introduce clients that use the new *DeclHeaderSyntax nodes directly.
1 parent ba525b3 commit ad3b3ab

38 files changed

+4363
-1231
lines changed

CodeGeneration/Sources/SyntaxSupport/Child.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,10 +371,10 @@ extension Child {
371371
/// should be provided. The associated value is the *old*, now-deprecated name.
372372
case renamed(from: String)
373373

374-
// /// Several adjacent children were extracted into a separate node at some
375-
// /// point in the past, so deprecated aliases that flatten the other node's
376-
// /// children into this node should be provided.
377-
// case extracted
374+
/// Several adjacent children were extracted into a separate node at some
375+
/// point in the past, so deprecated aliases that flatten the other node's
376+
/// children into this node should be provided.
377+
case extracted
378378
}
379379
}
380380

CodeGeneration/Sources/SyntaxSupport/CompatibilityLayers.swift

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ public struct CompatibilityLayers /*: Sendable*/ {
3333
}
3434
}
3535

36+
private func extractedChildren(in layoutNode: LayoutNode) -> ArraySlice<Child> {
37+
var children = layoutNode.children[...]
38+
if children.first?.isUnexpectedNodes ?? false {
39+
children.removeFirst()
40+
}
41+
if children.last?.isUnexpectedNodes ?? false {
42+
children.removeLast()
43+
}
44+
return children
45+
}
46+
3647
/// Returns the child or children that would have existed in place of this
3748
/// child before this refactoring was applied.
3849
private mutating func replacementChildren(for newerChild: Child, by refactoring: Child.Refactoring) -> [Child] {
@@ -46,8 +57,16 @@ public struct CompatibilityLayers /*: Sendable*/ {
4657
)
4758
]
4859

49-
// case .extracted:
50-
// fatalError("unimplemented")
60+
case .extracted:
61+
let extractedNode = SYNTAX_NODE_MAP[newerChild.syntaxNodeKind]!
62+
realizeLayers(for: extractedNode)
63+
64+
// Drop the leading and trailing unexpected nodes--these will be newly introduced.
65+
let newerGrandchildren = extractedChildren(in: extractedNode.layoutNode!)
66+
67+
return newerGrandchildren.map { newerGrandchild in
68+
Child(newerChildPath: [newerChild, newerGrandchild])
69+
}
5170
}
5271
}
5372

0 commit comments

Comments
 (0)