Skip to content

Commit 5fce8c8

Browse files
committed
ASTBridging: Bridge swift::ExternKind directly
1 parent c37dfd0 commit 5fce8c8

File tree

4 files changed

+9
-24
lines changed

4 files changed

+9
-24
lines changed

include/swift/AST/ASTBridging.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,17 +1012,12 @@ BridgedExposeAttr BridgedExposeAttr_createParsed(BridgedASTContext cContext,
10121012
BridgedStringRef cName,
10131013
swift::ExposureKind kind);
10141014

1015-
enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedExternKind {
1016-
BridgedExternKindC,
1017-
BridgedExternKindWasm,
1018-
};
1019-
10201015
SWIFT_NAME("BridgedExternAttr.createParsed(_:atLoc:range:lParenLoc:rParenLoc:"
10211016
"kind:moduleName:name:)")
10221017
BridgedExternAttr BridgedExternAttr_createParsed(
10231018
BridgedASTContext cContext, BridgedSourceLoc cAtLoc,
10241019
BridgedSourceRange cRange, BridgedSourceLoc cLParenLoc,
1025-
BridgedSourceLoc cRParenLoc, BridgedExternKind cKind,
1020+
BridgedSourceLoc cRParenLoc, swift::ExternKind kind,
10261021
BridgedStringRef cModuleName, BridgedStringRef cName);
10271022

10281023
SWIFT_NAME("BridgedImplementsAttr.createParsed(_:atLoc:range:protocolType:"

include/swift/AST/AttrKind.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,17 @@ enum class ENUM_EXTENSIBILITY_ATTR(closed) ExposureKind : uint8_t {
102102
};
103103

104104
/// This enum represents the possible values of the @_extern attribute.
105-
enum class ExternKind: uint8_t {
105+
enum class ENUM_EXTENSIBILITY_ATTR(closed) ExternKind : uint8_t {
106106
/// Reference an externally defined C function.
107107
/// The imported function has C function pointer representation,
108108
/// and is called using the C calling convention.
109-
C,
109+
C SWIFT_NAME("c"),
110110
/// Reference an externally defined function through WebAssembly's
111111
/// import mechanism.
112112
/// This does not specify the calling convention and can be used
113113
/// with other extern kinds together.
114114
/// Effectively, this is no-op on non-WebAssembly targets.
115-
Wasm,
115+
Wasm SWIFT_NAME("wasm"),
116116
Last_ExternKind = Wasm
117117
};
118118

lib/AST/Bridging/DeclAttributeBridging.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -338,20 +338,10 @@ BridgedExposeAttr BridgedExposeAttr_createParsed(BridgedASTContext cContext,
338338
kind, /*Implicit=*/false);
339339
}
340340

341-
static ExternKind unbridged(BridgedExternKind kind) {
342-
switch (kind) {
343-
case BridgedExternKindC:
344-
return ExternKind::C;
345-
case BridgedExternKindWasm:
346-
return ExternKind::Wasm;
347-
}
348-
llvm_unreachable("unhandled enum value");
349-
}
350-
351341
BridgedExternAttr BridgedExternAttr_createParsed(
352342
BridgedASTContext cContext, BridgedSourceLoc cAtLoc,
353343
BridgedSourceRange cRange, BridgedSourceLoc cLParenLoc,
354-
BridgedSourceLoc cRParenLoc, BridgedExternKind cKind,
344+
BridgedSourceLoc cRParenLoc, swift::ExternKind kind,
355345
BridgedStringRef cModuleName, BridgedStringRef cName) {
356346
std::optional<StringRef> moduleName = cModuleName.unbridged();
357347
if (moduleName->empty())
@@ -363,7 +353,7 @@ BridgedExternAttr BridgedExternAttr_createParsed(
363353

364354
return new (cContext.unbridged())
365355
ExternAttr(moduleName, name, cAtLoc.unbridged(), cLParenLoc.unbridged(),
366-
cRParenLoc.unbridged(), cRange.unbridged(), unbridged(cKind),
356+
cRParenLoc.unbridged(), cRange.unbridged(), kind,
367357
/*Implicit=*/false);
368358
}
369359

lib/ASTGen/Sources/ASTGen/DeclAttrs.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -950,10 +950,10 @@ extension ASTGenVisitor {
950950
/// ```
951951
func generateExternAttr(attribute node: AttributeSyntax) -> BridgedExternAttr? {
952952
return self.generateWithLabeledExprListArguments(attribute: node) { args in
953-
let kind: BridgedExternKind? = self.generateConsumingPlainIdentifierAttrOption(args: &args) {
953+
let kind: swift.ExternKind? = self.generateConsumingPlainIdentifierAttrOption(args: &args) {
954954
switch $0.rawText {
955955
case "c":
956-
return .C
956+
return .c
957957
case "wasm":
958958
return .wasm
959959
default:
@@ -968,7 +968,7 @@ extension ASTGenVisitor {
968968
let moduleName: BridgedStringRef?
969969
let symbolName: BridgedStringRef?
970970
switch kind {
971-
case .C:
971+
case .c:
972972
moduleName = nil
973973
symbolName = args.isEmpty ? nil : self.generateConsumingSimpleStringLiteralAttrOption(args: &args)
974974
case .wasm:

0 commit comments

Comments
 (0)