Skip to content

Commit 698e17a

Browse files
committed
Update for MissingDeclSyntax Gaining Attributes
1 parent 554057f commit 698e17a

File tree

4 files changed

+197
-3
lines changed

4 files changed

+197
-3
lines changed

Sources/SwiftSyntax/gyb_generated/SyntaxFactory.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,26 @@ public enum SyntaxFactory {
8888
], length: .zero, presence: presence))
8989
return MissingSyntax(data)
9090
}
91+
public static func makeMissingDecl(_ garbageBeforeAttributes: GarbageNodesSyntax? = nil, attributes: AttributeListSyntax?, _ garbageBetweenAttributesAndModifiers: GarbageNodesSyntax? = nil, modifiers: ModifierListSyntax?) -> MissingDeclSyntax {
92+
let layout: [RawSyntax?] = [
93+
garbageBeforeAttributes?.raw,
94+
attributes?.raw,
95+
garbageBetweenAttributesAndModifiers?.raw,
96+
modifiers?.raw,
97+
]
98+
let raw = RawSyntax.createAndCalcLength(kind: SyntaxKind.missingDecl,
99+
layout: layout, presence: SourcePresence.present)
100+
let data = SyntaxData.forRoot(raw)
101+
return MissingDeclSyntax(data)
102+
}
91103

92104
public static func makeBlankMissingDecl(presence: SourcePresence = .missing) -> MissingDeclSyntax {
93105
let data = SyntaxData.forRoot(RawSyntax.create(kind: .missingDecl,
94106
layout: [
107+
nil,
108+
nil,
109+
nil,
110+
nil,
95111
], length: .zero, presence: presence))
96112
return MissingDeclSyntax(data)
97113
}

Sources/SwiftSyntax/gyb_generated/syntax_nodes/SyntaxDeclNodes.swift

Lines changed: 169 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ extension UnknownDeclSyntax: CustomReflectable {
5555
// MARK: - MissingDeclSyntax
5656

5757
public struct MissingDeclSyntax: DeclSyntaxProtocol, SyntaxHashable {
58+
enum Cursor: Int {
59+
case garbageBeforeAttributes
60+
case attributes
61+
case garbageBetweenAttributesAndModifiers
62+
case modifiers
63+
}
5864

5965
public let _syntaxNode: Syntax
6066

@@ -77,16 +83,178 @@ public struct MissingDeclSyntax: DeclSyntaxProtocol, SyntaxHashable {
7783
return Swift.type(of: self)
7884
}
7985

86+
public var garbageBeforeAttributes: GarbageNodesSyntax? {
87+
get {
88+
let childData = data.child(at: Cursor.garbageBeforeAttributes,
89+
parent: Syntax(self))
90+
if childData == nil { return nil }
91+
return GarbageNodesSyntax(childData!)
92+
}
93+
set(value) {
94+
self = withGarbageBeforeAttributes(value)
95+
}
96+
}
97+
98+
/// Returns a copy of the receiver with its `garbageBeforeAttributes` replaced.
99+
/// - param newChild: The new `garbageBeforeAttributes` to replace the node's
100+
/// current `garbageBeforeAttributes`, if present.
101+
public func withGarbageBeforeAttributes(
102+
_ newChild: GarbageNodesSyntax?) -> MissingDeclSyntax {
103+
let raw = newChild?.raw
104+
let newData = data.replacingChild(raw, at: Cursor.garbageBeforeAttributes)
105+
return MissingDeclSyntax(newData)
106+
}
107+
108+
public var attributes: AttributeListSyntax? {
109+
get {
110+
let childData = data.child(at: Cursor.attributes,
111+
parent: Syntax(self))
112+
if childData == nil { return nil }
113+
return AttributeListSyntax(childData!)
114+
}
115+
set(value) {
116+
self = withAttributes(value)
117+
}
118+
}
119+
120+
/// Adds the provided `Attribute` to the node's `attributes`
121+
/// collection.
122+
/// - param element: The new `Attribute` to add to the node's
123+
/// `attributes` collection.
124+
/// - returns: A copy of the receiver with the provided `Attribute`
125+
/// appended to its `attributes` collection.
126+
public func addAttribute(_ element: Syntax) -> MissingDeclSyntax {
127+
var collection: RawSyntax
128+
if let col = raw[Cursor.attributes] {
129+
collection = col.appending(element.raw)
130+
} else {
131+
collection = RawSyntax.create(kind: SyntaxKind.attributeList,
132+
layout: [element.raw], length: element.raw.totalLength, presence: .present)
133+
}
134+
let newData = data.replacingChild(collection,
135+
at: Cursor.attributes)
136+
return MissingDeclSyntax(newData)
137+
}
138+
139+
/// Returns a copy of the receiver with its `attributes` replaced.
140+
/// - param newChild: The new `attributes` to replace the node's
141+
/// current `attributes`, if present.
142+
public func withAttributes(
143+
_ newChild: AttributeListSyntax?) -> MissingDeclSyntax {
144+
let raw = newChild?.raw
145+
let newData = data.replacingChild(raw, at: Cursor.attributes)
146+
return MissingDeclSyntax(newData)
147+
}
148+
149+
public var garbageBetweenAttributesAndModifiers: GarbageNodesSyntax? {
150+
get {
151+
let childData = data.child(at: Cursor.garbageBetweenAttributesAndModifiers,
152+
parent: Syntax(self))
153+
if childData == nil { return nil }
154+
return GarbageNodesSyntax(childData!)
155+
}
156+
set(value) {
157+
self = withGarbageBetweenAttributesAndModifiers(value)
158+
}
159+
}
160+
161+
/// Returns a copy of the receiver with its `garbageBetweenAttributesAndModifiers` replaced.
162+
/// - param newChild: The new `garbageBetweenAttributesAndModifiers` to replace the node's
163+
/// current `garbageBetweenAttributesAndModifiers`, if present.
164+
public func withGarbageBetweenAttributesAndModifiers(
165+
_ newChild: GarbageNodesSyntax?) -> MissingDeclSyntax {
166+
let raw = newChild?.raw
167+
let newData = data.replacingChild(raw, at: Cursor.garbageBetweenAttributesAndModifiers)
168+
return MissingDeclSyntax(newData)
169+
}
170+
171+
public var modifiers: ModifierListSyntax? {
172+
get {
173+
let childData = data.child(at: Cursor.modifiers,
174+
parent: Syntax(self))
175+
if childData == nil { return nil }
176+
return ModifierListSyntax(childData!)
177+
}
178+
set(value) {
179+
self = withModifiers(value)
180+
}
181+
}
182+
183+
/// Adds the provided `Modifier` to the node's `modifiers`
184+
/// collection.
185+
/// - param element: The new `Modifier` to add to the node's
186+
/// `modifiers` collection.
187+
/// - returns: A copy of the receiver with the provided `Modifier`
188+
/// appended to its `modifiers` collection.
189+
public func addModifier(_ element: DeclModifierSyntax) -> MissingDeclSyntax {
190+
var collection: RawSyntax
191+
if let col = raw[Cursor.modifiers] {
192+
collection = col.appending(element.raw)
193+
} else {
194+
collection = RawSyntax.create(kind: SyntaxKind.modifierList,
195+
layout: [element.raw], length: element.raw.totalLength, presence: .present)
196+
}
197+
let newData = data.replacingChild(collection,
198+
at: Cursor.modifiers)
199+
return MissingDeclSyntax(newData)
200+
}
201+
202+
/// Returns a copy of the receiver with its `modifiers` replaced.
203+
/// - param newChild: The new `modifiers` to replace the node's
204+
/// current `modifiers`, if present.
205+
public func withModifiers(
206+
_ newChild: ModifierListSyntax?) -> MissingDeclSyntax {
207+
let raw = newChild?.raw
208+
let newData = data.replacingChild(raw, at: Cursor.modifiers)
209+
return MissingDeclSyntax(newData)
210+
}
211+
80212

81213
public func _validateLayout() {
82214
let rawChildren = Array(RawSyntaxChildren(Syntax(self)))
83-
assert(rawChildren.count == 0)
215+
assert(rawChildren.count == 4)
216+
// Check child #0 child is GarbageNodesSyntax or missing
217+
if let raw = rawChildren[0].raw {
218+
let info = rawChildren[0].syntaxInfo
219+
let absoluteRaw = AbsoluteRawSyntax(raw: raw, info: info)
220+
let syntaxData = SyntaxData(absoluteRaw, parent: Syntax(self))
221+
let syntaxChild = Syntax(syntaxData)
222+
assert(syntaxChild.is(GarbageNodesSyntax.self))
223+
}
224+
// Check child #1 child is AttributeListSyntax or missing
225+
if let raw = rawChildren[1].raw {
226+
let info = rawChildren[1].syntaxInfo
227+
let absoluteRaw = AbsoluteRawSyntax(raw: raw, info: info)
228+
let syntaxData = SyntaxData(absoluteRaw, parent: Syntax(self))
229+
let syntaxChild = Syntax(syntaxData)
230+
assert(syntaxChild.is(AttributeListSyntax.self))
231+
}
232+
// Check child #2 child is GarbageNodesSyntax or missing
233+
if let raw = rawChildren[2].raw {
234+
let info = rawChildren[2].syntaxInfo
235+
let absoluteRaw = AbsoluteRawSyntax(raw: raw, info: info)
236+
let syntaxData = SyntaxData(absoluteRaw, parent: Syntax(self))
237+
let syntaxChild = Syntax(syntaxData)
238+
assert(syntaxChild.is(GarbageNodesSyntax.self))
239+
}
240+
// Check child #3 child is ModifierListSyntax or missing
241+
if let raw = rawChildren[3].raw {
242+
let info = rawChildren[3].syntaxInfo
243+
let absoluteRaw = AbsoluteRawSyntax(raw: raw, info: info)
244+
let syntaxData = SyntaxData(absoluteRaw, parent: Syntax(self))
245+
let syntaxChild = Syntax(syntaxData)
246+
assert(syntaxChild.is(ModifierListSyntax.self))
247+
}
84248
}
85249
}
86250

87251
extension MissingDeclSyntax: CustomReflectable {
88252
public var customMirror: Mirror {
89253
return Mirror(self, children: [
254+
"garbageBeforeAttributes": garbageBeforeAttributes.map(Syntax.init)?.asProtocol(SyntaxProtocol.self) as Any,
255+
"attributes": attributes.map(Syntax.init)?.asProtocol(SyntaxProtocol.self) as Any,
256+
"garbageBetweenAttributesAndModifiers": garbageBetweenAttributesAndModifiers.map(Syntax.init)?.asProtocol(SyntaxProtocol.self) as Any,
257+
"modifiers": modifiers.map(Syntax.init)?.asProtocol(SyntaxProtocol.self) as Any,
90258
])
91259
}
92260
}

Sources/SwiftSyntaxBuilderGeneration/gyb_generated/CommonNodes.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,17 @@ let COMMON_NODES: [Node] = [
4747
kind: "Syntax"),
4848

4949
Node(name: "MissingDecl",
50-
kind: "Decl"),
50+
kind: "Decl",
51+
children: [
52+
Child(name: "Attributes",
53+
kind: "AttributeList",
54+
isOptional: true,
55+
collectionElementName: "Attribute"),
56+
Child(name: "Modifiers",
57+
kind: "ModifierList",
58+
isOptional: true,
59+
collectionElementName: "Modifier")
60+
]),
5161

5262
Node(name: "MissingExpr",
5363
kind: "Expr"),

Sources/SwiftSyntaxParser/gyb_generated/NodeDeclarationHash.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
extension SyntaxParser {
1818
static func verifyNodeDeclarationHash() -> Bool {
1919
return String(cString: swiftparse_syntax_structure_versioning_identifier()!) ==
20-
"d88a6458605388d56b70604413c05f40ff4ffb0c"
20+
"cae571f89efe64c25c27e8c2c299f2e19b8593dd"
2121
}
2222
}

0 commit comments

Comments
 (0)