Skip to content

Commit 7fd97c9

Browse files
committed
[ASTGen] Factor out attribute list handling logic
1 parent 55f61d0 commit 7fd97c9

File tree

3 files changed

+18
-33
lines changed

3 files changed

+18
-33
lines changed

lib/ASTGen/Sources/ASTGen/DeclAttrs.swift

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,7 @@ extension ASTGenVisitor {
5454
}
5555

5656
// '@' attributes.
57-
// FIXME: Factor out this and share it with 'generate(accessorDecl:)'.
58-
visitIfConfigElements(node.attributes, of: AttributeSyntax.self) { element in
59-
switch element {
60-
case .ifConfigDecl(let ifConfigDecl):
61-
return .ifConfigDecl(ifConfigDecl)
62-
case .attribute(let attribute):
63-
return .underlying(attribute)
64-
}
65-
} body: { attribute in
66-
self.generateDeclAttribute(attribute: attribute, handler: addAttribute(_:))
67-
}
57+
self.generateDeclAttributes(attributeList: node.attributes, handler: addAttribute(_:))
6858

6959
func genStatic(node: DeclModifierSyntax, spelling: BridgedStaticSpelling) {
7060
// TODO: Diagnose duplicated attrs.
@@ -93,6 +83,19 @@ extension ASTGenVisitor {
9383
staticLoc: staticLoc
9484
)
9585
}
86+
87+
func generateDeclAttributes(attributeList node: AttributeListSyntax, handler: (BridgedDeclAttribute) -> Void) {
88+
visitIfConfigElements(node, of: AttributeSyntax.self) { element in
89+
switch element {
90+
case .ifConfigDecl(let ifConfigDecl):
91+
return .ifConfigDecl(ifConfigDecl)
92+
case .attribute(let attribute):
93+
return .underlying(attribute)
94+
}
95+
} body: { attribute in
96+
self.generateDeclAttribute(attribute: attribute, handler: handler)
97+
}
98+
}
9699
}
97100

98101
// MARK: - Decl attributes

lib/ASTGen/Sources/ASTGen/Decls.swift

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -381,17 +381,8 @@ extension ASTGenVisitor {
381381
var attrs = BridgedDeclAttributes()
382382

383383
// '@' attributes.
384-
visitIfConfigElements(node.attributes, of: AttributeSyntax.self) { element in
385-
switch element {
386-
case .ifConfigDecl(let ifConfigDecl):
387-
return .ifConfigDecl(ifConfigDecl)
388-
case .attribute(let attribute):
389-
return .underlying(attribute)
390-
}
391-
} body: { node in
392-
self.generateDeclAttribute(attribute: node) { attr in
393-
attrs.add(attr)
394-
}
384+
self.generateDeclAttributes(attributeList: node.attributes) { attr in
385+
attrs.add(attr)
395386
}
396387

397388
// The modifier

lib/ASTGen/Sources/ASTGen/Exprs.swift

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -224,17 +224,8 @@ extension ASTGenVisitor {
224224
var result = GeneratedClosureSignature()
225225

226226
// Attributes.
227-
visitIfConfigElements(node.attributes, of: AttributeSyntax.self) { element in
228-
switch element {
229-
case .ifConfigDecl(let ifConfigDecl):
230-
return .ifConfigDecl(ifConfigDecl)
231-
case .attribute(let attribute):
232-
return .underlying(attribute)
233-
}
234-
} body: { node in
235-
self.generateDeclAttribute(attribute: node) { attr in
236-
result.attributes.add(attr)
237-
}
227+
self.generateDeclAttributes(attributeList: node.attributes) { attr in
228+
result.attributes.add(attr)
238229
}
239230

240231
if let node = node.capture {

0 commit comments

Comments
 (0)