Skip to content

Commit 65a1f58

Browse files
committed
[NFC] [ASTGen] Refactor attribute attachment
Use `Decl::attachParsedAttrs()` instead of `Decl::setAttrs()` to attach attributes to a declaration in ASTGen. This causes the common attribute-setup logic there to be run. NFC in this commit because none of the attributes that have special setup logic are currently implemented in ASTGen. Prepares to add support for `@abi` in a future commit.
1 parent 8d428c4 commit 65a1f58

File tree

3 files changed

+23
-22
lines changed

3 files changed

+23
-22
lines changed

include/swift/AST/ASTBridging.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -907,8 +907,8 @@ BridgedUnavailableFromAsyncAttr BridgedUnavailableFromAsyncAttr_createParsed(
907907
// MARK: Decls
908908
//===----------------------------------------------------------------------===//
909909

910-
SWIFT_NAME("BridgedDecl.setAttrs(self:_:)")
911-
void BridgedDecl_setAttrs(BridgedDecl decl, BridgedDeclAttributes attrs);
910+
SWIFT_NAME("BridgedDecl.attachParsedAttrs(self:_:)")
911+
void BridgedDecl_attachParsedAttrs(BridgedDecl decl, BridgedDeclAttributes attrs);
912912

913913
enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedStaticSpelling {
914914
BridgedStaticSpellingNone,

lib/AST/Bridging/DeclBridging.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,9 @@ static AccessorKind unbridged(BridgedAccessorKind kind) {
115115
return static_cast<AccessorKind>(kind);
116116
}
117117

118-
void BridgedDecl_setAttrs(BridgedDecl decl, BridgedDeclAttributes attrs) {
119-
decl.unbridged()->getAttrs() = attrs.unbridged();
118+
void BridgedDecl_attachParsedAttrs(BridgedDecl decl,
119+
BridgedDeclAttributes attrs) {
120+
decl.unbridged()->attachParsedAttrs(attrs.unbridged());
120121
}
121122

122123
BridgedAccessorDecl BridgedAccessorDecl_createParsed(

lib/ASTGen/Sources/ASTGen/Decls.swift

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ extension ASTGenVisitor {
105105
underlyingType: self.generate(type: node.initializer.value),
106106
genericWhereClause: self.generate(genericWhereClause: node.genericWhereClause)
107107
)
108-
decl.asDecl.setAttrs(attrs.attributes)
108+
decl.asDecl.attachParsedAttrs(attrs.attributes)
109109
return decl
110110
}
111111

@@ -129,7 +129,7 @@ extension ASTGenVisitor {
129129
end: node.memberBlock.rightBrace
130130
)
131131
)
132-
decl.asDecl.setAttrs(attrs.attributes)
132+
decl.asDecl.attachParsedAttrs(attrs.attributes)
133133

134134
self.withDeclContext(decl.asDeclContext) {
135135
decl.setParsedMembers(self.generate(memberBlockItemList: node.memberBlock.members).lazy.bridgedArray(in: self))
@@ -158,7 +158,7 @@ extension ASTGenVisitor {
158158
end: node.memberBlock.rightBrace
159159
)
160160
)
161-
decl.asDecl.setAttrs(attrs.attributes)
161+
decl.asDecl.attachParsedAttrs(attrs.attributes)
162162

163163
self.withDeclContext(decl.asDeclContext) {
164164
decl.setParsedMembers(self.generate(memberBlockItemList: node.memberBlock.members).lazy.bridgedArray(in: self))
@@ -188,7 +188,7 @@ extension ASTGenVisitor {
188188
),
189189
isActor: false
190190
)
191-
decl.asDecl.setAttrs(attrs.attributes)
191+
decl.asDecl.attachParsedAttrs(attrs.attributes)
192192

193193
self.withDeclContext(decl.asDeclContext) {
194194
decl.setParsedMembers(self.generate(memberBlockItemList: node.memberBlock.members).lazy.bridgedArray(in: self))
@@ -218,7 +218,7 @@ extension ASTGenVisitor {
218218
),
219219
isActor: true
220220
)
221-
decl.asDecl.setAttrs(attrs.attributes)
221+
decl.asDecl.attachParsedAttrs(attrs.attributes)
222222

223223
self.withDeclContext(decl.asDeclContext) {
224224
decl.setParsedMembers(self.generate(memberBlockItemList: node.memberBlock.members).lazy.bridgedArray(in: self))
@@ -250,7 +250,7 @@ extension ASTGenVisitor {
250250
end: node.memberBlock.rightBrace
251251
)
252252
)
253-
decl.asDecl.setAttrs(attrs.attributes)
253+
decl.asDecl.attachParsedAttrs(attrs.attributes)
254254

255255
self.withDeclContext(decl.asDeclContext) {
256256
decl.setParsedMembers(self.generate(memberBlockItemList: node.memberBlock.members).lazy.bridgedArray(in: self))
@@ -275,7 +275,7 @@ extension ASTGenVisitor {
275275
defaultType: self.generate(type: node.initializer?.value),
276276
genericWhereClause: self.generate(genericWhereClause: node.genericWhereClause)
277277
)
278-
decl.asDecl.setAttrs(attrs.attributes)
278+
decl.asDecl.attachParsedAttrs(attrs.attributes)
279279
return decl
280280
}
281281
}
@@ -297,7 +297,7 @@ extension ASTGenVisitor {
297297
end: node.memberBlock.rightBrace
298298
)
299299
)
300-
decl.asDecl.setAttrs(attrs.attributes)
300+
decl.asDecl.attachParsedAttrs(attrs.attributes)
301301

302302
self.withDeclContext(decl.asDeclContext) {
303303
decl.setParsedMembers(self.generate(memberBlockItemList: node.memberBlock.members).lazy.bridgedArray(in: self))
@@ -334,7 +334,7 @@ extension ASTGenVisitor {
334334
guard let elemDecl = self.generate(enumCaseElement: elem) else {
335335
return nil
336336
}
337-
elemDecl.asDecl.setAttrs(attrs.attributes)
337+
elemDecl.asDecl.attachParsedAttrs(attrs.attributes)
338338
return elemDecl
339339
})
340340
return .createParsed(
@@ -419,7 +419,7 @@ extension ASTGenVisitor {
419419
throwsSpecifierLoc: self.generateSourceLoc(node.effectSpecifiers?.throwsClause),
420420
thrownType: self.generate(type: node.effectSpecifiers?.thrownError)
421421
)
422-
accessor.asDecl.setAttrs(attrs)
422+
accessor.asDecl.attachParsedAttrs(attrs)
423423
if let body = node.body {
424424
self.withDeclContext(accessor.asDeclContext) {
425425
accessor.setParsedBody(self.generate(codeBlock: body))
@@ -580,7 +580,7 @@ extension ASTGenVisitor {
580580
arrowLoc: self.generateSourceLoc(node.returnClause.arrow),
581581
returnType: self.generate(type: node.returnClause.type)
582582
)
583-
subscriptDecl.asDecl.setAttrs(attrs.attributes)
583+
subscriptDecl.asDecl.attachParsedAttrs(attrs.attributes)
584584

585585
if let accessors = node.accessorBlock {
586586
let storage = subscriptDecl.asAbstractStorageDecl
@@ -615,7 +615,7 @@ extension ASTGenVisitor {
615615
returnType: self.generate(type: node.signature.returnClause?.type),
616616
genericWhereClause: self.generate(genericWhereClause: node.genericWhereClause)
617617
)
618-
decl.asDecl.setAttrs(attrs.attributes)
618+
decl.asDecl.attachParsedAttrs(attrs.attributes)
619619

620620
if let body = node.body {
621621
self.withDeclContext(decl.asDeclContext) {
@@ -642,7 +642,7 @@ extension ASTGenVisitor {
642642
thrownType: self.generate(type: node.signature.effectSpecifiers?.thrownError),
643643
genericWhereClause: self.generate(genericWhereClause: node.genericWhereClause)
644644
)
645-
decl.asDecl.setAttrs(attrs.attributes)
645+
decl.asDecl.attachParsedAttrs(attrs.attributes)
646646

647647
if let body = node.body {
648648
self.withDeclContext(decl.asDeclContext) {
@@ -661,7 +661,7 @@ extension ASTGenVisitor {
661661
declContext: self.declContext,
662662
deinitKeywordLoc: self.generateSourceLoc(node.deinitKeyword)
663663
)
664-
decl.asDecl.setAttrs(attrs.attributes)
664+
decl.asDecl.attachParsedAttrs(attrs.attributes)
665665

666666
if let body = node.body {
667667
self.withDeclContext(decl.asDeclContext) {
@@ -691,7 +691,7 @@ extension ASTGenVisitor {
691691
resultType: self.generate(type: node.signature.returnClause?.type),
692692
definition: self.generate(expr: node.definition?.value)
693693
)
694-
decl.asDecl.setAttrs(attrs.attributes);
694+
decl.asDecl.attachParsedAttrs(attrs.attributes)
695695
return decl;
696696
}
697697
}
@@ -713,7 +713,7 @@ extension ASTGenVisitor {
713713
rightAngleLoc: info.rightAngleLoc,
714714
args: info.arguments
715715
)
716-
decl.asDecl.setAttrs(attrs.attributes)
716+
decl.asDecl.attachParsedAttrs(attrs.attributes)
717717

718718
return decl
719719
}
@@ -870,7 +870,7 @@ extension ASTGenVisitor {
870870
lowerThanNames: self.generate(precedenceGroupNameList: body.lowerThanRelation?.precedenceGroups),
871871
rightBraceLoc: self.generateSourceLoc(node.rightBrace)
872872
)
873-
decl.asDecl.setAttrs(attrs.attributes)
873+
decl.asDecl.attachParsedAttrs(attrs.attributes)
874874
return decl
875875
}
876876
}
@@ -917,7 +917,7 @@ extension ASTGenVisitor {
917917
self.generateLocatedIdentifier($0.name)
918918
}.bridgedArray(in: self)
919919
)
920-
decl.asDecl.setAttrs(attrs.attributes)
920+
decl.asDecl.attachParsedAttrs(attrs.attributes)
921921
return decl
922922
}
923923
}

0 commit comments

Comments
 (0)