Skip to content

Commit b137209

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 f566959 commit b137209

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
@@ -915,8 +915,8 @@ BridgedUnavailableFromAsyncAttr BridgedUnavailableFromAsyncAttr_createParsed(
915915
// MARK: Decls
916916
//===----------------------------------------------------------------------===//
917917

918-
SWIFT_NAME("BridgedDecl.setAttrs(self:_:)")
919-
void BridgedDecl_setAttrs(BridgedDecl decl, BridgedDeclAttributes attrs);
918+
SWIFT_NAME("BridgedDecl.attachParsedAttrs(self:_:)")
919+
void BridgedDecl_attachParsedAttrs(BridgedDecl decl, BridgedDeclAttributes attrs);
920920

921921
enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedStaticSpelling {
922922
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(
@@ -409,7 +409,7 @@ extension ASTGenVisitor {
409409
throwsSpecifierLoc: self.generateSourceLoc(node.effectSpecifiers?.throwsClause),
410410
thrownType: self.generate(type: node.effectSpecifiers?.thrownError)
411411
)
412-
accessor.asDecl.setAttrs(attrs)
412+
accessor.asDecl.attachParsedAttrs(attrs)
413413
if let body = node.body {
414414
self.withDeclContext(accessor.asDeclContext) {
415415
accessor.setParsedBody(self.generate(codeBlock: body))
@@ -570,7 +570,7 @@ extension ASTGenVisitor {
570570
arrowLoc: self.generateSourceLoc(node.returnClause.arrow),
571571
returnType: self.generate(type: node.returnClause.type)
572572
)
573-
subscriptDecl.asDecl.setAttrs(attrs.attributes)
573+
subscriptDecl.asDecl.attachParsedAttrs(attrs.attributes)
574574

575575
if let accessors = node.accessorBlock {
576576
let storage = subscriptDecl.asAbstractStorageDecl
@@ -605,7 +605,7 @@ extension ASTGenVisitor {
605605
returnType: self.generate(type: node.signature.returnClause?.type),
606606
genericWhereClause: self.generate(genericWhereClause: node.genericWhereClause)
607607
)
608-
decl.asDecl.setAttrs(attrs.attributes)
608+
decl.asDecl.attachParsedAttrs(attrs.attributes)
609609

610610
if let body = node.body {
611611
self.withDeclContext(decl.asDeclContext) {
@@ -632,7 +632,7 @@ extension ASTGenVisitor {
632632
thrownType: self.generate(type: node.signature.effectSpecifiers?.thrownError),
633633
genericWhereClause: self.generate(genericWhereClause: node.genericWhereClause)
634634
)
635-
decl.asDecl.setAttrs(attrs.attributes)
635+
decl.asDecl.attachParsedAttrs(attrs.attributes)
636636

637637
if let body = node.body {
638638
self.withDeclContext(decl.asDeclContext) {
@@ -651,7 +651,7 @@ extension ASTGenVisitor {
651651
declContext: self.declContext,
652652
deinitKeywordLoc: self.generateSourceLoc(node.deinitKeyword)
653653
)
654-
decl.asDecl.setAttrs(attrs.attributes)
654+
decl.asDecl.attachParsedAttrs(attrs.attributes)
655655

656656
if let body = node.body {
657657
self.withDeclContext(decl.asDeclContext) {
@@ -681,7 +681,7 @@ extension ASTGenVisitor {
681681
resultType: self.generate(type: node.signature.returnClause?.type),
682682
definition: self.generate(expr: node.definition?.value)
683683
)
684-
decl.asDecl.setAttrs(attrs.attributes);
684+
decl.asDecl.attachParsedAttrs(attrs.attributes)
685685
return decl;
686686
}
687687
}
@@ -703,7 +703,7 @@ extension ASTGenVisitor {
703703
rightAngleLoc: info.rightAngleLoc,
704704
args: info.arguments
705705
)
706-
decl.asDecl.setAttrs(attrs.attributes)
706+
decl.asDecl.attachParsedAttrs(attrs.attributes)
707707

708708
return decl
709709
}
@@ -860,7 +860,7 @@ extension ASTGenVisitor {
860860
lowerThanNames: self.generate(precedenceGroupNameList: body.lowerThanRelation?.precedenceGroups),
861861
rightBraceLoc: self.generateSourceLoc(node.rightBrace)
862862
)
863-
decl.asDecl.setAttrs(attrs.attributes)
863+
decl.asDecl.attachParsedAttrs(attrs.attributes)
864864
return decl
865865
}
866866
}
@@ -907,7 +907,7 @@ extension ASTGenVisitor {
907907
self.generateLocatedIdentifier($0.name)
908908
}.bridgedArray(in: self)
909909
)
910-
decl.asDecl.setAttrs(attrs.attributes)
910+
decl.asDecl.attachParsedAttrs(attrs.attributes)
911911
return decl
912912
}
913913
}

0 commit comments

Comments
 (0)