Skip to content

Commit e1dfed3

Browse files
committed
[ASTGen] Bridge TypeAttribute subclasses
1 parent e066bb2 commit e1dfed3

File tree

4 files changed

+51
-22
lines changed

4 files changed

+51
-22
lines changed

include/swift/AST/ASTBridging.h

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,15 @@ struct BridgedASTNode {
444444
Bridged##CLASS##Attr attr);
445445
#include "swift/AST/DeclAttr.def"
446446

447+
// Declare `.asTypeAttr` on each BridgedXXXTypeAttr type, which upcasts a
448+
// wrapper for a TypeAttr subclass to a BridgedTypeAttr.
449+
#define SIMPLE_TYPE_ATTR(...)
450+
#define TYPE_ATTR(SPELLING, CLASS) \
451+
SWIFT_NAME("getter:Bridged" #CLASS "TypeAttr.asTypeAttribute(self:)") \
452+
BridgedTypeAttribute Bridged##CLASS##TypeAttr_asTypeAttribute( \
453+
Bridged##CLASS##TypeAttr attr);
454+
#include "swift/AST/TypeAttr.def"
455+
447456
struct BridgedPatternBindingEntry {
448457
BridgedPattern pattern;
449458
BridgedSourceLoc equalLoc;
@@ -2200,23 +2209,25 @@ enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedIsolatedTypeAttrIsolationKind {
22002209
BridgedIsolatedTypeAttrIsolationKind_DynamicIsolation,
22012210
};
22022211

2203-
SWIFT_NAME("BridgedTypeAttribute.createIsolated(_:atLoc:nameLoc:lpLoc:isolationKindLoc:isolationKind:rpLoc:)")
2204-
BridgedTypeAttribute BridgedTypeAttribute_createIsolated(
2205-
BridgedASTContext cContext,
2206-
BridgedSourceLoc cAtLoc, BridgedSourceLoc cNameLoc,
2207-
BridgedSourceLoc cLPLoc, BridgedSourceLoc cIsolationLoc,
2212+
SWIFT_NAME("BridgedIsolatedTypeAttr.createParsed(_:atLoc:nameLoc:lpLoc:"
2213+
"isolationKindLoc:isolationKind:rpLoc:)")
2214+
BridgedIsolatedTypeAttr BridgedIsolatedTypeAttr_createParsed(
2215+
BridgedASTContext cContext, BridgedSourceLoc cAtLoc,
2216+
BridgedSourceLoc cNameLoc, BridgedSourceLoc cLPLoc,
2217+
BridgedSourceLoc cIsolationLoc,
22082218
BridgedIsolatedTypeAttrIsolationKind cIsolation, BridgedSourceLoc cRPLoc);
22092219

22102220
enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedExecutionTypeAttrExecutionKind {
22112221
BridgedExecutionTypeAttrExecutionKind_Concurrent,
22122222
BridgedExecutionTypeAttrExecutionKind_Caller
22132223
};
22142224

2215-
SWIFT_NAME("BridgedTypeAttribute.createExecution(_:atLoc:nameLoc:lpLoc:behaviorLoc:behavior:rpLoc:)")
2216-
BridgedTypeAttribute BridgedTypeAttribute_createExecution(
2217-
BridgedASTContext cContext,
2218-
BridgedSourceLoc cAtLoc, BridgedSourceLoc cNameLoc,
2219-
BridgedSourceLoc cLPLoc, BridgedSourceLoc cBehaviorLoc,
2225+
SWIFT_NAME("BridgedExecutionTypeAttr.createParsed(_:atLoc:nameLoc:lpLoc:"
2226+
"behaviorLoc:behavior:rpLoc:)")
2227+
BridgedExecutionTypeAttr BridgedExecutionTypeAttr_createParsed(
2228+
BridgedASTContext cContext, BridgedSourceLoc cAtLoc,
2229+
BridgedSourceLoc cNameLoc, BridgedSourceLoc cLPLoc,
2230+
BridgedSourceLoc cBehaviorLoc,
22202231
BridgedExecutionTypeAttrExecutionKind behavior, BridgedSourceLoc cRPLoc);
22212232

22222233
//===----------------------------------------------------------------------===//

include/swift/AST/ASTBridgingWrappers.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@
8585
#endif
8686
#include "swift/AST/DeclAttr.def"
8787

88+
#ifndef TYPE_ATTR
89+
#define SIMPLE_TYPE_ATTR(...)
90+
#define TYPE_ATTR(SPELLING, CLASS) AST_BRIDGING_WRAPPER_NONNULL(CLASS##TypeAttr)
91+
#endif
92+
#include "swift/AST/TypeAttr.def"
93+
8894
// Some of the base classes need to be nullable to allow them to be used as
8995
// optional parameters.
9096
AST_BRIDGING_WRAPPER_NULLABLE(Decl)

lib/AST/Bridging/TypeAttributeBridging.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ using namespace swift;
2323
// MARK: TypeAttributes
2424
//===----------------------------------------------------------------------===//
2525

26+
// Define `.asTypeAttr` on each BridgedXXXTypeAttr type.
27+
#define SIMPLE_TYPE_ATTR(...)
28+
#define TYPE_ATTR(SPELLING, CLASS) \
29+
SWIFT_NAME("getter:Bridged" #CLASS "TypeAttr.asTypeAttribute(self:)") \
30+
BridgedTypeAttribute Bridged##CLASS##TypeAttr_asTypeAttribute( \
31+
Bridged##CLASS##TypeAttr attr) { \
32+
return attr.unbridged(); \
33+
}
34+
#include "swift/AST/TypeAttr.def"
35+
2636
BridgedTypeAttrKind BridgedTypeAttrKind_fromString(BridgedStringRef cStr) {
2737
auto optKind = TypeAttribute::getAttrKindFromString(cStr.unbridged());
2838
if (!optKind)
@@ -74,7 +84,7 @@ BridgedTypeAttribute BridgedTypeAttribute_createSimple(
7484
cAtLoc.unbridged(), cNameLoc.unbridged());
7585
}
7686

77-
BridgedTypeAttribute BridgedTypeAttribute_createIsolated(
87+
BridgedIsolatedTypeAttr BridgedIsolatedTypeAttr_createParsed(
7888
BridgedASTContext cContext, BridgedSourceLoc cAtLoc,
7989
BridgedSourceLoc cNameLoc, BridgedSourceLoc cLPLoc,
8090
BridgedSourceLoc cIsolationLoc,
@@ -92,7 +102,7 @@ BridgedTypeAttribute BridgedTypeAttribute_createIsolated(
92102
{isolationKind, cIsolationLoc.unbridged()});
93103
}
94104

95-
BridgedTypeAttribute BridgedTypeAttribute_createExecution(
105+
BridgedExecutionTypeAttr BridgedExecutionTypeAttr_createParsed(
96106
BridgedASTContext cContext, BridgedSourceLoc cAtLoc,
97107
BridgedSourceLoc cNameLoc, BridgedSourceLoc cLPLoc,
98108
BridgedSourceLoc cBehaviorLoc,
@@ -110,4 +120,4 @@ BridgedTypeAttribute BridgedTypeAttribute_createExecution(
110120
ExecutionTypeAttr(cAtLoc.unbridged(), cNameLoc.unbridged(),
111121
{cLPLoc.unbridged(), cRPLoc.unbridged()},
112122
{behaviorKind, cBehaviorLoc.unbridged()});
113-
}
123+
}

lib/ASTGen/Sources/ASTGen/TypeAttrs.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ extension ASTGenVisitor {
8989
fatalError("unimplemented")
9090

9191
case .isolated:
92-
return self.generateIsolatedTypeAttr(attribute: node)
92+
return self.generateIsolatedTypeAttr(attribute: node)?.asTypeAttribute
9393

9494
case .execution:
95-
return self.generateExecutionTypeAttr(attribute: node)
95+
return self.generateExecutionTypeAttr(attribute: node)?.asTypeAttribute
9696

9797
// SIL type attributes are not supported.
9898
case .autoreleased,
@@ -145,8 +145,8 @@ extension ASTGenVisitor {
145145
nameLoc: self.generateSourceLoc(node.attributeName)
146146
)
147147
}
148-
149-
func generateIsolatedTypeAttr(attribute node: AttributeSyntax) -> BridgedTypeAttribute? {
148+
149+
func generateIsolatedTypeAttr(attribute node: AttributeSyntax) -> BridgedIsolatedTypeAttr? {
150150
guard case .argumentList(let isolatedArgs) = node.arguments,
151151
isolatedArgs.count == 1,
152152
let labelArg = isolatedArgs.first,
@@ -167,17 +167,18 @@ extension ASTGenVisitor {
167167
return nil
168168
}
169169

170-
return BridgedTypeAttribute.createIsolated(
170+
return BridgedIsolatedTypeAttr.createParsed(
171171
self.ctx,
172172
atLoc: self.generateSourceLoc(node.atSign),
173173
nameLoc: self.generateSourceLoc(node.attributeName),
174174
lpLoc: self.generateSourceLoc(node.leftParen!),
175175
isolationKindLoc: self.generateSourceLoc(isolationKindExpr.baseName),
176176
isolationKind: isolationKind,
177-
rpLoc: self.generateSourceLoc(node.rightParen!))
177+
rpLoc: self.generateSourceLoc(node.rightParen!)
178+
)
178179
}
179180

180-
func generateExecutionTypeAttr(attribute node: AttributeSyntax) -> BridgedTypeAttribute? {
181+
func generateExecutionTypeAttr(attribute node: AttributeSyntax) -> BridgedExecutionTypeAttr? {
181182
guard case .argumentList(let executionArgs) = node.arguments,
182183
executionArgs.count == 1,
183184
let labelArg = executionArgs.first,
@@ -198,13 +199,14 @@ extension ASTGenVisitor {
198199
return nil
199200
}
200201

201-
return BridgedTypeAttribute.createExecution(
202+
return BridgedExecutionTypeAttr.createParsed(
202203
self.ctx,
203204
atLoc: self.generateSourceLoc(node.atSign),
204205
nameLoc: self.generateSourceLoc(node.attributeName),
205206
lpLoc: self.generateSourceLoc(node.leftParen!),
206207
behaviorLoc: self.generateSourceLoc(behaviorExpr.baseName),
207208
behavior: behavior,
208-
rpLoc: self.generateSourceLoc(node.rightParen!))
209+
rpLoc: self.generateSourceLoc(node.rightParen!)
210+
)
209211
}
210212
}

0 commit comments

Comments
 (0)