Skip to content

Commit dadb863

Browse files
committed
[Swift bridging] Use Swift(U)Int consistently for bridging
1 parent 3aa046a commit dadb863

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

include/swift/AST/CASTBridging.h

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,14 @@
2525
SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
2626
SWIFT_BEGIN_ASSUME_NONNULL
2727

28-
typedef long SwiftInt;
29-
typedef unsigned long SwiftUInt;
30-
3128
typedef struct {
3229
const unsigned char *_Nullable data;
33-
long length;
30+
SwiftInt length;
3431
} BridgedString;
3532

3633
typedef struct {
3734
const void *_Nullable data;
38-
long numElements;
35+
SwiftInt numElements;
3936
} BridgedArrayRef;
4037

4138
typedef struct BridgedASTContext {
@@ -70,7 +67,7 @@ typedef struct {
7067
BridgedSourceLoc TrailingCommaLoc;
7168
} BridgedTupleTypeElement;
7269

73-
typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedRequirementReprKind : long {
70+
typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedRequirementReprKind : SwiftInt {
7471
/// A type bound T : P, where T is a type that depends on a generic
7572
/// parameter and P is some type that should bound T, either as a concrete
7673
/// supertype or a protocol to which T must conform.
@@ -97,7 +94,7 @@ typedef struct {
9794
} BridgedRequirementRepr;
9895

9996
/// Diagnostic severity when reporting diagnostics.
100-
typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedDiagnosticSeverity : long {
97+
typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedDiagnosticSeverity : SwiftInt {
10198
BridgedFatalError,
10299
BridgedError,
103100
BridgedWarning,
@@ -113,7 +110,7 @@ typedef struct BridgedDiagnosticEngine {
113110
void *raw;
114111
} BridgedDiagnosticEngine;
115112

116-
typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedMacroDefinitionKind : long {
113+
typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedMacroDefinitionKind : SwiftInt {
117114
/// An expanded macro.
118115
BridgedExpandedMacro = 0,
119116
/// An external macro, spelled with either the old spelling (Module.Type)
@@ -124,7 +121,7 @@ typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedMacroDefinitionKind : long {
124121
} BridgedMacroDefinitionKind;
125122

126123
/// Bridged parameter specifiers
127-
typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedAttributedTypeSpecifier : long {
124+
typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedAttributedTypeSpecifier : SwiftInt {
128125
BridgedAttributedTypeSpecifierInOut,
129126
BridgedAttributedTypeSpecifierBorrowing,
130127
BridgedAttributedTypeSpecifierConsuming,
@@ -135,7 +132,7 @@ typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedAttributedTypeSpecifier : long
135132
} BridgedAttributedTypeSpecifier;
136133

137134
// Bridged type attribute kinds, which mirror TypeAttrKind exactly.
138-
typedef enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedTypeAttrKind : long {
135+
typedef enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedTypeAttrKind : SwiftInt {
139136
BridgedTypeAttrKind_autoclosure,
140137
BridgedTypeAttrKind_convention,
141138
BridgedTypeAttrKind_noescape,
@@ -187,7 +184,7 @@ typedef enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedTypeAttrKind : long {
187184
BridgedTypeAttrKind_Count
188185
} BridgedTypeAttrKind;
189186

190-
typedef enum ENUM_EXTENSIBILITY_ATTR(open) ASTNodeKind : long {
187+
typedef enum ENUM_EXTENSIBILITY_ATTR(open) ASTNodeKind : SwiftInt {
191188
ASTNodeKindExpr,
192189
ASTNodeKindStmt,
193190
ASTNodeKindDecl
@@ -307,7 +304,7 @@ void *IfStmt_create(BridgedASTContext cContext, BridgedSourceLoc cIfLoc,
307304
void *BraceStmt_create(BridgedASTContext cContext, BridgedSourceLoc cLBLoc,
308305
BridgedArrayRef elements, BridgedSourceLoc cRBLoc);
309306

310-
BridgedSourceLoc SourceLoc_advanced(BridgedSourceLoc cLoc, long len);
307+
BridgedSourceLoc SourceLoc_advanced(BridgedSourceLoc cLoc, SwiftInt len);
311308

312309
void *ParamDecl_create(BridgedASTContext cContext, BridgedSourceLoc cLoc,
313310
BridgedSourceLoc cArgLoc, BridgedIdentifier argName,
@@ -357,7 +354,7 @@ void *GenericTypeParamDecl_create(BridgedASTContext cContext,
357354
BridgedDeclContext cDeclContext,
358355
BridgedIdentifier name,
359356
BridgedSourceLoc cNameLoc,
360-
BridgedSourceLoc cEachLoc, long index,
357+
BridgedSourceLoc cEachLoc, SwiftInt index,
361358
_Bool isParameterPack);
362359
void GenericTypeParamDecl_setInheritedType(BridgedASTContext cContext,
363360
void *Param, void *ty);

include/swift/Basic/CBasicBridging.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@ FeatureName,
3838

3939
SWIFT_BEGIN_ASSUME_NONNULL
4040

41+
typedef long SwiftInt;
42+
typedef unsigned long SwiftUInt;
43+
4144
typedef struct BridgedData {
4245
const char *_Nullable baseAddress;
43-
unsigned long size;
46+
SwiftUInt size;
4447
} BridgedData;
4548

4649
void BridgedData_free(BridgedData data);

lib/AST/CASTBridging.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ void *ImportDecl_create(BridgedASTContext cContext,
204204
std::move(importPath).get());
205205
}
206206

207-
BridgedSourceLoc SourceLoc_advanced(BridgedSourceLoc cLoc, long len) {
207+
BridgedSourceLoc SourceLoc_advanced(BridgedSourceLoc cLoc, SwiftInt len) {
208208
SourceLoc loc = convertSourceLoc(cLoc).getAdvancedLoc(len);
209209
return {loc.getOpaquePointerValue()};
210210
}
@@ -764,7 +764,7 @@ void *GenericTypeParamDecl_create(BridgedASTContext cContext,
764764
BridgedDeclContext cDeclContext,
765765
BridgedIdentifier name,
766766
BridgedSourceLoc cNameLoc,
767-
BridgedSourceLoc cEachLoc, long index,
767+
BridgedSourceLoc cEachLoc, SwiftInt index,
768768
bool isParameterPack) {
769769
return GenericTypeParamDecl::createParsed(
770770
convertDeclContext(cDeclContext), convertIdentifier(name),
@@ -881,6 +881,6 @@ bool Plugin_waitForNextMessage(PluginHandle handle, BridgedData *out) {
881881
auto size = message.size();
882882
auto outPtr = malloc(size);
883883
memcpy(outPtr, message.data(), size);
884-
*out = BridgedData{(const char *)outPtr, (unsigned long)size};
884+
*out = BridgedData{(const char *)outPtr, (SwiftUInt)size};
885885
return false;
886886
}

0 commit comments

Comments
 (0)