Skip to content

Commit e2b8d98

Browse files
committed
[Basic] Abstract BridgedOStream
Define using the wrapper macro.
1 parent 5d99fe6 commit e2b8d98

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

include/swift/AST/ASTBridging.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,12 @@ namespace swift {
8181
} // end namespace swift
8282

8383
// Define the bridging wrappers for each AST node.
84-
#define AST_BRIDGING_WRAPPER(Name) BRIDGING_WRAPPER_NONNULL(Name)
84+
#define AST_BRIDGING_WRAPPER(Name) BRIDGING_WRAPPER_NONNULL(swift::Name, Name)
8585
#include "swift/AST/ASTBridgingWrappers.def"
8686

8787
// For nullable nodes, also define a nullable variant.
88-
#define AST_BRIDGING_WRAPPER_NULLABLE(Name) BRIDGING_WRAPPER_NULLABLE(Name)
88+
#define AST_BRIDGING_WRAPPER_NULLABLE(Name) \
89+
BRIDGING_WRAPPER_NULLABLE(swift::Name, Name)
8990
#define AST_BRIDGING_WRAPPER_NONNULL(Name)
9091
#include "swift/AST/ASTBridgingWrappers.def"
9192

include/swift/Basic/BasicBridging.h

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@
5757
#define BRIDGED_INLINE inline
5858
#endif
5959

60+
namespace llvm {
61+
class raw_ostream;
62+
} // end namespace llvm
63+
6064
SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
6165

6266
typedef intptr_t SwiftInt;
@@ -72,14 +76,14 @@ 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 unbridged() const { return Ptr; } \
86+
Node * Nullability unbridged() const { return Ptr; } \
8387
}; \
8488
\
8589
SWIFT_NAME("getter:Bridged" #Name ".raw(self:)") \
@@ -89,15 +93,15 @@ typedef uintptr_t SwiftUInt;
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
@@ -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

lib/Basic/BasicBridging.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ using namespace swift;
2727
//===----------------------------------------------------------------------===//
2828

2929
void BridgedStringRef::write(BridgedOStream os) const {
30-
static_cast<raw_ostream *>(os.streamAddr)->write(Data, Length);
30+
os.unbridged()->write(Data, Length);
3131
}
3232

3333
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)