@@ -103,20 +103,66 @@ typedef uintptr_t SwiftUInt;
103103// MARK: ArrayRef
104104// ===----------------------------------------------------------------------===//
105105
106- struct BridgedArrayRef {
107- const void *_Nullable data;
108- size_t numElements;
106+ class BridgedArrayRef {
107+ public:
108+ SWIFT_UNAVAILABLE (" Use '.data' instead" )
109+ const void *_Nullable Data;
110+
111+ SWIFT_UNAVAILABLE (" Use '.count' instead" )
112+ size_t Length;
113+
114+ BridgedArrayRef () : Data (nullptr ), Length (0 ) {}
115+
116+ SWIFT_NAME (" init(data:count:)" )
117+ BridgedArrayRef (const void *_Nullable data, size_t length)
118+ : Data (data), Length (length) {}
119+
120+ #ifdef USED_IN_CPP_SOURCE
121+ template <typename T>
122+ BridgedArrayRef (llvm::ArrayRef<T> arr)
123+ : Data (arr.data ()), Length (arr.size ()) {}
124+
125+ template <typename T>
126+ llvm::ArrayRef<T> get () const {
127+ return {static_cast <const T *>(Data), Length};
128+ }
129+ #endif
109130};
110131
132+ SWIFT_NAME (" getter:BridgedArrayRef.data(self:)" )
133+ BRIDGED_INLINE
134+ const void *_Nullable BridgedArrayRef_data(BridgedArrayRef arr);
135+
136+ SWIFT_NAME (" getter:BridgedArrayRef.count(self:)" )
137+ BRIDGED_INLINE SwiftInt BridgedArrayRef_count(BridgedArrayRef arr);
138+
111139// ===----------------------------------------------------------------------===//
112140// MARK: Data
113141// ===----------------------------------------------------------------------===//
114142
115- struct BridgedData {
116- const char *_Nullable baseAddress;
117- size_t size;
143+ class BridgedData {
144+ public:
145+ SWIFT_UNAVAILABLE (" Use '.baseAddress' instead" )
146+ const char *_Nullable BaseAddress;
147+
148+ SWIFT_UNAVAILABLE (" Use '.count' instead" )
149+ size_t Length;
150+
151+ BridgedData () : BaseAddress(nullptr ), Length(0 ) {}
152+
153+ SWIFT_NAME (" init(baseAddress:count:)" )
154+ BridgedData (const char *_Nullable baseAddress, size_t length)
155+ : BaseAddress(baseAddress), Length(length) {}
118156};
119157
158+ SWIFT_NAME (" getter:BridgedData.baseAddress(self:)" )
159+ BRIDGED_INLINE
160+ const char *_Nullable BridgedData_baseAddress(BridgedData data);
161+
162+ SWIFT_NAME (" getter:BridgedData.count(self:)" )
163+ BRIDGED_INLINE SwiftInt BridgedData_count(BridgedData data);
164+
165+ SWIFT_NAME (" BridgedData.free(self:)" )
120166void BridgedData_free(BridgedData data);
121167
122168// ===----------------------------------------------------------------------===//
@@ -153,6 +199,8 @@ class BridgedStringRef {
153199 llvm::StringRef get () const { return llvm::StringRef (Data, Length); }
154200#endif
155201
202+ BridgedStringRef () : Data(nullptr ), Length(0 ) {}
203+
156204 SWIFT_NAME (" init(data:count:)" )
157205 BridgedStringRef (const char *_Nullable data, size_t length)
158206 : Data(data), Length(length) {}
0 commit comments