Skip to content

Commit 91c0677

Browse files
committed
ASTBridging: Bridge swift::GenericTypeParamKind directly
1 parent 8bf770c commit 91c0677

File tree

4 files changed

+24
-40
lines changed

4 files changed

+24
-40
lines changed

include/swift/AST/ASTBridging.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "swift/AST/AttrKind.h"
2525
#include "swift/AST/DiagnosticKind.h"
2626
#include "swift/AST/DiagnosticList.h"
27+
#include "swift/AST/GenericTypeParamKind.h"
2728
#include "swift/AST/LayoutConstraintKind.h"
2829
#include "swift/Basic/BasicBridging.h"
2930

@@ -2923,15 +2924,6 @@ BridgedRequirementRepr BridgedRequirementRepr_createLayoutConstraint(
29232924
BridgedLayoutConstraint cLayout, BridgedSourceLoc cLayoutLoc,
29242925
bool isExpansionPattern);
29252926

2926-
enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedGenericTypeParamKind : size_t {
2927-
/// A regular generic type parameter: 'T'
2928-
BridgedGenericTypeParamKindType = 0,
2929-
/// A generic parameter pack: 'each T'
2930-
BridgedGenericTypeParamKindPack,
2931-
/// A generic value parameter: 'let T'
2932-
BridgedGenericTypeParamKindValue,
2933-
};
2934-
29352927
SWIFT_NAME("BridgedGenericParamList.createParsed(_:leftAngleLoc:parameters:"
29362928
"genericWhereClause:rightAngleLoc:)")
29372929
BridgedGenericParamList BridgedGenericParamList_createParsed(
@@ -2947,7 +2939,7 @@ BridgedGenericTypeParamDecl BridgedGenericTypeParamDecl_createParsed(
29472939
BridgedASTContext cContext, BridgedDeclContext cDeclContext,
29482940
BridgedSourceLoc cSpecifierLoc, BridgedIdentifier cName,
29492941
BridgedSourceLoc cNameLoc, BridgedNullableTypeRepr opaqueInheritedType,
2950-
size_t index, BridgedGenericTypeParamKind paramKind);
2942+
size_t index, swift::GenericTypeParamKind paramKind);
29512943

29522944
SWIFT_NAME(
29532945
"BridgedTrailingWhereClause.createParsed(_:whereKeywordLoc:requirements:)")

include/swift/AST/GenericTypeParamKind.h

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,36 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2024 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2024 - 2025 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
99
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010
//
1111
//===----------------------------------------------------------------------===//
12-
//
13-
// This file defines the GenericTypeParamKind enum.
14-
//
12+
///
13+
/// This file defines the `GenericTypeParamKind` enum.
14+
///
1515
//===----------------------------------------------------------------------===//
1616

1717
#ifndef SWIFT_AST_GENERICTYPEPARAMKIND_H
1818
#define SWIFT_AST_GENERICTYPEPARAMKIND_H
1919

20+
/// This header is included in a bridging header. Be *very* careful with what
21+
/// you include here! See include caveats in `ASTBridging.h`.
22+
#include "swift/Basic/SwiftBridging.h"
23+
#include <stdint.h>
24+
2025
namespace swift {
2126
/// Describes the kind of a generic type parameter that occurs within generic
2227
/// parameter lists.
23-
enum class GenericTypeParamKind: uint8_t {
28+
enum class ENUM_EXTENSIBILITY_ATTR(closed) GenericTypeParamKind : uint8_t {
2429
/// A regular generic type parameter: 'T'
25-
Type,
30+
Type SWIFT_NAME("type"),
2631
/// A generic parameter pack: 'each T'
27-
Pack,
32+
Pack SWIFT_NAME("pack"),
2833
/// A generic value parameter: 'let T'
29-
Value
34+
Value SWIFT_NAME("value")
3035
};
3136

3237
} // namespace swift

lib/AST/Bridging/GenericsBridging.cpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,9 @@ BridgedGenericTypeParamDecl BridgedGenericTypeParamDecl_createParsed(
4646
BridgedASTContext cContext, BridgedDeclContext cDeclContext,
4747
BridgedSourceLoc cSpecifierLoc, BridgedIdentifier cName,
4848
BridgedSourceLoc cNameLoc, BridgedNullableTypeRepr bridgedInheritedType,
49-
size_t index, BridgedGenericTypeParamKind cParamKind) {
49+
size_t index, swift::GenericTypeParamKind paramKind) {
5050
auto specifierLoc = cSpecifierLoc.unbridged();
5151

52-
GenericTypeParamKind paramKind;
53-
54-
switch (cParamKind) {
55-
case BridgedGenericTypeParamKindType:
56-
paramKind = GenericTypeParamKind::Type;
57-
break;
58-
case BridgedGenericTypeParamKindPack:
59-
paramKind = GenericTypeParamKind::Pack;
60-
break;
61-
case BridgedGenericTypeParamKindValue:
62-
paramKind = GenericTypeParamKind::Value;
63-
break;
64-
}
65-
6652
auto *decl = GenericTypeParamDecl::createParsed(
6753
cDeclContext.unbridged(), cName.unbridged(), cNameLoc.unbridged(),
6854
specifierLoc, index, paramKind);

lib/ASTGen/Sources/ASTGen/Generics.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,14 @@ extension ASTGenVisitor {
4141
preconditionFailure("Node not part of the parent?")
4242
}
4343

44-
var paramKind: BridgedGenericTypeParamKind = .type
45-
46-
if node.specifier?.tokenKind == .keyword(.each) {
47-
paramKind = .pack
48-
} else if node.specifier?.tokenKind == .keyword(.let) {
49-
paramKind = .value
50-
}
44+
let paramKind: swift.GenericTypeParamKind =
45+
if node.specifier?.tokenKind == .keyword(.each) {
46+
.pack
47+
} else if node.specifier?.tokenKind == .keyword(.let) {
48+
.value
49+
} else {
50+
.type
51+
}
5152

5253
return .createParsed(
5354
self.ctx,

0 commit comments

Comments
 (0)