5757#define BRIDGED_INLINE inline
5858#endif
5959
60+ namespace llvm {
61+ class raw_ostream ;
62+ } // end namespace llvm
63+
6064SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
6165
6266typedef intptr_t SwiftInt;
@@ -72,32 +76,32 @@ typedef uintptr_t SwiftUInt;
7276// PURE_BRIDGING_MODE.
7377#define BRIDGING_WRAPPER_IMPL (Node, Name, Nullability ) \
7478 class Bridged ##Name { \
75- swift:: Node * Nullability Ptr; \
79+ Node * Nullability Ptr; \
7680 \
7781 public: \
7882 SWIFT_UNAVAILABLE (" Use init(raw:) instead" ) \
79- Bridged##Name(swift:: Node * Nullability ptr) : Ptr(ptr) {} \
83+ Bridged##Name(Node * Nullability ptr) : Ptr(ptr) {} \
8084 \
8185 SWIFT_UNAVAILABLE (" Use '.raw' instead" ) \
82- swift:: Node * Nullability get () const { return Ptr; } \
86+ Node * Nullability unbridged () const { return Ptr; } \
8387 }; \
8488 \
8589 SWIFT_NAME (" getter:Bridged" #Name " .raw(self:)" ) \
8690 inline void * Nullability Bridged##Name##_getRaw(Bridged##Name bridged) { \
87- return bridged.get (); \
91+ return bridged.unbridged (); \
8892 } \
8993 \
9094 SWIFT_NAME (" Bridged" #Name " .init(raw:)" ) \
9195 inline Bridged##Name Bridged##Name##_fromRaw(void * Nullability ptr) { \
92- return static_cast <swift:: Node *>(ptr); \
96+ return static_cast <Node *>(ptr); \
9397 }
9498
9599// 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)
98102
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)
101105
102106// ===----------------------------------------------------------------------===//
103107// MARK: ArrayRef
@@ -123,7 +127,7 @@ class BridgedArrayRef {
123127 : Data (arr.data ()), Length (arr.size ()) {}
124128
125129 template <typename T>
126- llvm::ArrayRef<T> get () const {
130+ llvm::ArrayRef<T> unbridged () const {
127131 return {static_cast <const T *>(Data), Length};
128132 }
129133#endif
@@ -179,9 +183,7 @@ enum ENUM_EXTENSIBILITY_ATTR(open) BridgedFeature {
179183// MARK: OStream
180184// ===----------------------------------------------------------------------===//
181185
182- struct BridgedOStream {
183- void * _Nonnull streamAddr;
184- };
186+ BRIDGING_WRAPPER_NONNULL (llvm::raw_ostream, OStream)
185187
186188// ===----------------------------------------------------------------------===//
187189// MARK: StringRef
@@ -196,7 +198,7 @@ class BridgedStringRef {
196198 BridgedStringRef (llvm::StringRef sref)
197199 : Data (sref.data ()), Length (sref.size ()) {}
198200
199- llvm::StringRef get () const { return llvm::StringRef (Data, Length); }
201+ llvm::StringRef unbridged () const { return llvm::StringRef (Data, Length); }
200202#endif
201203
202204 BridgedStringRef () : Data (nullptr ), Length (0 ) {}
@@ -226,7 +228,7 @@ class BridgedOwnedString {
226228#ifdef USED_IN_CPP_SOURCE
227229 BridgedOwnedString (const std::string &stringToCopy);
228230
229- llvm::StringRef getRef () const { return llvm::StringRef (Data, Length); }
231+ llvm::StringRef unbridgedRef () const { return llvm::StringRef (Data, Length); }
230232#endif
231233
232234 void destroy () const ;
@@ -258,7 +260,7 @@ class BridgedSourceLoc {
258260#ifdef USED_IN_CPP_SOURCE
259261 BridgedSourceLoc (swift::SourceLoc loc) : Raw(loc.getOpaquePointerValue()) {}
260262
261- swift::SourceLoc get () const {
263+ swift::SourceLoc unbridged () const {
262264 return swift::SourceLoc (
263265 llvm::SMLoc::getFromPointer (static_cast <const char *>(Raw)));
264266 }
@@ -279,16 +281,62 @@ BRIDGED_INLINE bool BridgedSourceLoc_isValid(BridgedSourceLoc loc);
279281// MARK: SourceRange
280282// ===----------------------------------------------------------------------===//
281283
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
285304};
286305
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
290326};
291327
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+
292340// ===----------------------------------------------------------------------===//
293341// MARK: Plugins
294342// ===----------------------------------------------------------------------===//
0 commit comments