57
57
#define BRIDGED_INLINE inline
58
58
#endif
59
59
60
+ namespace llvm {
61
+ class raw_ostream ;
62
+ } // end namespace llvm
63
+
60
64
SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
61
65
62
66
typedef intptr_t SwiftInt;
@@ -72,32 +76,32 @@ typedef uintptr_t SwiftUInt;
72
76
// PURE_BRIDGING_MODE.
73
77
#define BRIDGING_WRAPPER_IMPL (Node, Name, Nullability ) \
74
78
class Bridged ##Name { \
75
- swift:: Node * Nullability Ptr; \
79
+ Node * Nullability Ptr; \
76
80
\
77
81
public: \
78
82
SWIFT_UNAVAILABLE (" Use init(raw:) instead" ) \
79
- Bridged##Name(swift:: Node * Nullability ptr) : Ptr(ptr) {} \
83
+ Bridged##Name(Node * Nullability ptr) : Ptr(ptr) {} \
80
84
\
81
85
SWIFT_UNAVAILABLE (" Use '.raw' instead" ) \
82
- swift:: Node * Nullability get () const { return Ptr; } \
86
+ Node * Nullability unbridged () const { return Ptr; } \
83
87
}; \
84
88
\
85
89
SWIFT_NAME (" getter:Bridged" #Name " .raw(self:)" ) \
86
90
inline void * Nullability Bridged##Name##_getRaw(Bridged##Name bridged) { \
87
- return bridged.get (); \
91
+ return bridged.unbridged (); \
88
92
} \
89
93
\
90
94
SWIFT_NAME (" Bridged" #Name " .init(raw:)" ) \
91
95
inline Bridged##Name Bridged##Name##_fromRaw(void * Nullability ptr) { \
92
- return static_cast <swift:: Node *>(ptr); \
96
+ return static_cast <Node *>(ptr); \
93
97
}
94
98
95
99
// Bridging wrapper macros for convenience.
96
- #define BRIDGING_WRAPPER_NONNULL (Name ) \
97
- BRIDGING_WRAPPER_IMPL (Name , Name, _Nonnull)
100
+ #define BRIDGING_WRAPPER_NONNULL (Node, Name ) \
101
+ BRIDGING_WRAPPER_IMPL (Node , Name, _Nonnull)
98
102
99
- #define BRIDGING_WRAPPER_NULLABLE (Name ) \
100
- BRIDGING_WRAPPER_IMPL (Name , Nullable##Name, _Nullable)
103
+ #define BRIDGING_WRAPPER_NULLABLE (Node, Name ) \
104
+ BRIDGING_WRAPPER_IMPL (Node , Nullable##Name, _Nullable)
101
105
102
106
// ===----------------------------------------------------------------------===//
103
107
// MARK: ArrayRef
@@ -123,7 +127,7 @@ class BridgedArrayRef {
123
127
: Data (arr.data ()), Length (arr.size ()) {}
124
128
125
129
template <typename T>
126
- llvm::ArrayRef<T> get () const {
130
+ llvm::ArrayRef<T> unbridged () const {
127
131
return {static_cast <const T *>(Data), Length};
128
132
}
129
133
#endif
@@ -179,9 +183,7 @@ enum ENUM_EXTENSIBILITY_ATTR(open) BridgedFeature {
179
183
// MARK: OStream
180
184
// ===----------------------------------------------------------------------===//
181
185
182
- struct BridgedOStream {
183
- void * _Nonnull streamAddr;
184
- };
186
+ BRIDGING_WRAPPER_NONNULL (llvm::raw_ostream, OStream)
185
187
186
188
// ===----------------------------------------------------------------------===//
187
189
// MARK: StringRef
@@ -196,7 +198,7 @@ class BridgedStringRef {
196
198
BridgedStringRef (llvm::StringRef sref)
197
199
: Data (sref.data ()), Length (sref.size ()) {}
198
200
199
- llvm::StringRef get () const { return llvm::StringRef (Data, Length); }
201
+ llvm::StringRef unbridged () const { return llvm::StringRef (Data, Length); }
200
202
#endif
201
203
202
204
BridgedStringRef () : Data (nullptr ), Length (0 ) {}
@@ -226,7 +228,7 @@ class BridgedOwnedString {
226
228
#ifdef USED_IN_CPP_SOURCE
227
229
BridgedOwnedString (const std::string &stringToCopy);
228
230
229
- llvm::StringRef getRef () const { return llvm::StringRef (Data, Length); }
231
+ llvm::StringRef unbridgedRef () const { return llvm::StringRef (Data, Length); }
230
232
#endif
231
233
232
234
void destroy () const ;
@@ -258,7 +260,7 @@ class BridgedSourceLoc {
258
260
#ifdef USED_IN_CPP_SOURCE
259
261
BridgedSourceLoc (swift::SourceLoc loc) : Raw(loc.getOpaquePointerValue()) {}
260
262
261
- swift::SourceLoc get () const {
263
+ swift::SourceLoc unbridged () const {
262
264
return swift::SourceLoc (
263
265
llvm::SMLoc::getFromPointer (static_cast <const char *>(Raw)));
264
266
}
@@ -279,16 +281,62 @@ BRIDGED_INLINE bool BridgedSourceLoc_isValid(BridgedSourceLoc loc);
279
281
// MARK: SourceRange
280
282
// ===----------------------------------------------------------------------===//
281
283
282
- struct BridgedSourceRange {
283
- BridgedSourceLoc startLoc;
284
- BridgedSourceLoc endLoc;
284
+ class BridgedSourceRange {
285
+ public:
286
+ SWIFT_NAME (" start" )
287
+ BridgedSourceLoc Start;
288
+
289
+ SWIFT_NAME (" end" )
290
+ BridgedSourceLoc End;
291
+
292
+ SWIFT_NAME (" init(start:end:)" )
293
+ BridgedSourceRange (BridgedSourceLoc start, BridgedSourceLoc end)
294
+ : Start(start), End(end) {}
295
+
296
+ #ifdef USED_IN_CPP_SOURCE
297
+ BridgedSourceRange (swift::SourceRange range)
298
+ : Start(range.Start), End(range.End) {}
299
+
300
+ swift::SourceRange unbridged () const {
301
+ return swift::SourceRange (Start.unbridged (), End.unbridged ());
302
+ }
303
+ #endif
285
304
};
286
305
287
- struct BridgedCharSourceRange {
288
- void *_Nonnull start;
289
- size_t byteLength;
306
+ class BridgedCharSourceRange {
307
+ public:
308
+ SWIFT_UNAVAILABLE (" Use '.start' instead" )
309
+ BridgedSourceLoc Start;
310
+
311
+ SWIFT_UNAVAILABLE (" Use '.byteLength' instead" )
312
+ unsigned ByteLength;
313
+
314
+ SWIFT_NAME (" init(start:byteLength:)" )
315
+ BridgedCharSourceRange (BridgedSourceLoc start, unsigned byteLength)
316
+ : Start(start), ByteLength(byteLength) {}
317
+
318
+ #ifdef USED_IN_CPP_SOURCE
319
+ BridgedCharSourceRange (swift::CharSourceRange range)
320
+ : Start(range.getStart()), ByteLength(range.getByteLength()) {}
321
+
322
+ swift::CharSourceRange unbridged () const {
323
+ return swift::CharSourceRange (Start.unbridged (), ByteLength);
324
+ }
325
+ #endif
290
326
};
291
327
328
+ SWIFT_NAME (" getter:BridgedCharSourceRange.start(self:)" )
329
+ inline BridgedSourceLoc
330
+ BridgedCharSourceRange_start(BridgedCharSourceRange range) {
331
+ return range.Start ;
332
+ }
333
+
334
+ SWIFT_NAME (" getter:BridgedCharSourceRange.byteLength(self:)" )
335
+ inline SwiftInt
336
+ BridgedCharSourceRange_byteLength(BridgedCharSourceRange range) {
337
+ return static_cast <SwiftInt>(range.ByteLength );
338
+ }
339
+
292
340
// ===----------------------------------------------------------------------===//
293
341
// MARK: Plugins
294
342
// ===----------------------------------------------------------------------===//
0 commit comments