Skip to content

Commit 41d6765

Browse files
Reorganize macro definitions
1 parent fb1ac46 commit 41d6765

File tree

7 files changed

+213
-140
lines changed

7 files changed

+213
-140
lines changed

.clang-format

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ NamespaceIndentation: None
2121
SpaceBeforeAssignmentOperators: true
2222
Standard: Cpp11
2323
UseTab: Never
24+
WhitespaceSensitiveMacros:
25+
- bsoncxx_pragma

src/bsoncxx/include/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ set_dist_list(src_bsoncxx_include_DIST
4545
bsoncxx/v_noabi/bsoncxx/config/compiler.hpp
4646
bsoncxx/v_noabi/bsoncxx/config/postlude.hpp
4747
bsoncxx/v_noabi/bsoncxx/config/prelude.hpp
48+
bsoncxx/v_noabi/bsoncxx/config/util.hpp
4849
bsoncxx/v_noabi/bsoncxx/decimal128.hpp
4950
bsoncxx/v_noabi/bsoncxx/document/element.hpp
5051
bsoncxx/v_noabi/bsoncxx/document/value.hpp

src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/config/compiler.hpp

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,35 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#if defined(_MSC_VER)
15+
// clang-format off
16+
17+
#define bsoncxx_if_msvc(...)
18+
#define bsoncxx_if_gcc(...)
19+
#define bsoncxx_if_clang(...)
20+
#define bsoncxx_if_gnu_like(...) \
21+
bsoncxx_if_gcc(__VA_ARGS__) \
22+
bsoncxx_if_clang(__VA_ARGS__)
23+
24+
#ifdef __GNUC__
25+
#ifdef __clang__
26+
#undef bsoncxx_if_clang
27+
#define bsoncxx_if_clang(...) __VA_ARGS__
28+
#else
29+
#undef bsoncxx_if_gcc
30+
#define bsoncxx_if_gcc(...) __VA_ARGS__
31+
#endif
32+
#elif defined(_MSC_VER)
33+
#undef bsoncxx_if_msvc
34+
#undef bsoncxx_if_msvc(...) __VA_ARGS__
35+
#endif
36+
37+
// clang-format on
1638

1739
// Disable MSVC warnings that cause a lot of noise related to DLL visibility
1840
// for types that we don't control (like std::unique_ptr).
19-
#pragma warning(push)
20-
#pragma warning(disable : 4251 4275)
41+
bsoncxx_push_warnings();
42+
bsoncxx_disable_warning(MSVC(4251));
43+
bsoncxx_disable_warning(MSVC(5275));
2144

2245
#define BSONCXX_INLINE inline BSONCXX_PRIVATE
23-
24-
#define BSONCXX_CALL __cdecl
25-
26-
#else
27-
28-
#define BSONCXX_INLINE inline BSONCXX_PRIVATE
29-
30-
#define BSONCXX_CALL
31-
32-
#endif
46+
#define BSONCXX_CALL bsoncxx_if_msvc(__cdecl)

src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/config/postlude.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
// compiler.hpp
1616
#undef BSONCXX_INLINE
1717
#pragma pop_macro("BSONCXX_INLINE")
18-
#if defined(_MSC_VER)
19-
#pragma warning(pop)
20-
#endif
18+
bsoncxx_pop_warnings();
2119
#undef BSONCXX_CALL
2220
#pragma pop_macro("BSONCXX_CALL")
2321

@@ -67,7 +65,7 @@
6765
#undef BSONCXX_UNREACHABLE
6866
#pragma pop_macro("BSONCXX_UNREACHABLE")
6967

70-
#pragma pop_macro("mongo_cxx14_constexpr")
68+
#pragma pop_macro("bsoncxx_cxx14_constexpr")
7169
#pragma pop_macro("bsoncxx_returns")
7270

7371
// CXX-2769: out-of-place, but remains for backward compatibility.
@@ -76,19 +74,21 @@ static_assert(false, "BSONCXX_ENUM must be undef'ed");
7674
#endif
7775
#pragma pop_macro("BSONCXX_ENUM")
7876

77+
// util.hpp
7978
#pragma pop_macro("bsoncxx_push_warnings")
8079
#pragma pop_macro("bsoncxx_pop_warnings")
8180
#pragma pop_macro("bsoncxx_disable_warning")
8281

83-
#pragma pop_macro("BSONCXX_DISABLE_WARNING_IMPL_MSVC")
84-
#pragma pop_macro("BSONCXX_DISABLE_WARNING_IMPL_GCC")
85-
#pragma pop_macro("BSONCXX_DISABLE_WARNING_IMPL_GNU")
86-
#pragma pop_macro("BSONCXX_DISABLE_WARNING_IMPL_Clang")
82+
#pragma pop_macro("_bsoncxxDisableWarningImpl_for_MSVC")
83+
#pragma pop_macro("_bsoncxxDisableWarningImpl_for_GCC")
84+
#pragma pop_macro("_bsoncxxDisableWarningImpl_for_GNU")
85+
#pragma pop_macro("_bsoncxxDisableWarningImpl_for_Clang")
8786

8887
#pragma pop_macro("bsoncxx_concat")
8988
#pragma pop_macro("bsoncxx_concat_impl")
9089

9190
#pragma pop_macro("bsoncxx_pragma")
91+
#pragma pop_macro("_bsoncxxPragma")
9292
#pragma pop_macro("bsoncxx_stringify_impl")
9393
#pragma pop_macro("bsoncxx_stringify")
9494
#pragma pop_macro("bsoncxx_force_semicolon")

src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/config/prelude.hpp

Lines changed: 44 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,53 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
// util.hpp
16+
#pragma push_macro("bsoncxx_concat")
17+
#undef bsoncxx_concat
18+
#pragma push_macro("bsoncxx_concat_impl")
19+
#undef bsoncxx_concat_impl
20+
#pragma push_macro("bsoncxx_stringify")
21+
#undef bsoncxx_stringify
22+
#pragma push_macro("bsoncxx_stringify_impl")
23+
#undef bsoncxx_stringify_impl
24+
#pragma push_macro("bsoncxx_pragma")
25+
#undef bsoncxx_pragma
26+
#pragma push_macro("_bsoncxxPragma")
27+
#undef _bsoncxxPragma
28+
#pragma push_macro("bsoncxx_force_semicolon")
29+
#undef bsoncxx_force_semicolon
30+
#pragma push_macro("bsoncxx_returns")
31+
#undef bsoncxx_returns
32+
#pragma push_macro("bsoncxx_cxx14_constexpr")
33+
#undef bsoncxx_cxx14_constexpr
34+
#pragma push_macro("bsoncxx_disable_warning")
35+
#undef bsoncxx_disable_warning
36+
#pragma push_macro("bsoncxx_push_warnings")
37+
#undef bsoncxx_push_warnings
38+
#pragma push_macro("bsoncxx_pop_warnings")
39+
#undef bsoncxx_pop_warnings
40+
#pragma push_macro("_bsoncxxDisableWarningImpl_for_GCC")
41+
#undef _bsoncxxDisableWarningImpl_for_GCC
42+
#pragma push_macro("_bsoncxxDisableWarningImpl_for_Clang")
43+
#undef _bsoncxxDisableWarningImpl_for_Clang
44+
#pragma push_macro("_bsoncxxDisableWarningImpl_for_MSVC")
45+
#undef _bsoncxxDisableWarningImpl_for_MSVC
46+
#pragma push_macro("_bsoncxxDisableWarningImpl_for_GNU")
47+
#undef _bsoncxxDisableWarningImpl_for_GNU
48+
1549
// compiler.hpp
1650
#pragma push_macro("BSONCXX_INLINE")
1751
#undef BSONCXX_INLINE
1852
#pragma push_macro("BSONCXX_CALL")
1953
#undef BSONCXX_CALL
54+
#pragma push_macro("bsoncxx_if_msvc")
55+
#undef bsoncxx_if_msvc
56+
#pragma push_macro("bsoncxx_if_gcc")
57+
#undef bsoncxx_if_gcc
58+
#pragma push_macro("bsoncxx_if_clang")
59+
#undef bsoncxx_if_clang
60+
#pragma push_macro("bsoncxx_if_gnu_like")
61+
#undef bsoncxx_if_gnu_like
2062

2163
// config.hpp (generated by CMake)
2264
#pragma push_macro("BSONCXX_INLINE_NAMESPACE_BEGIN")
@@ -60,6 +102,8 @@
60102
#pragma push_macro("BSONCXX_NO_DEPRECATED")
61103
#undef BSONCXX_NO_DEPRECATED
62104

105+
#include <bsoncxx/config/util.hpp>
106+
//
63107
#include <bsoncxx/config/compiler.hpp>
64108
#include <bsoncxx/config/config.hpp>
65109
#include <bsoncxx/config/export.hpp>
@@ -90,118 +134,3 @@
90134
/// @namespace bsoncxx::v_noabi::stdx
91135
/// Declares polyfills for C++17 forward compatibility.
92136
///
93-
94-
#pragma push_macro("mongo_cxx14_constexpr")
95-
#if __cplusplus >= 201402L
96-
#define mongo_cxx14_constexpr constexpr
97-
#else
98-
#define mongo_cxx14_constexpr inline
99-
#endif
100-
101-
#pragma push_macro("bsoncxx_returns")
102-
/**
103-
* @brief Add a trailing noexcept, decltype-return, and return-body to a function definition.
104-
*/
105-
#define bsoncxx_returns(...) \
106-
noexcept(noexcept(__VA_ARGS__))->decltype(__VA_ARGS__) { \
107-
return __VA_ARGS__; \
108-
} \
109-
bsoncxx_force_semicolon
110-
111-
// clang-format off
112-
113-
#pragma push_macro("bsoncxx_if_msvc")
114-
#define bsoncxx_if_msvc(...)
115-
#pragma push_macro("bsoncxx_if_gcc")
116-
#define bsoncxx_if_gcc(...)
117-
#pragma push_macro("bsoncxx_if_clang")
118-
#define bsoncxx_if_clang(...)
119-
#pragma push_macro("bsoncxx_if_gnu_like")
120-
#define bsoncxx_if_gnu_like(...) \
121-
bsoncxx_if_gcc(__VA_ARGS__) \
122-
bsoncxx_if_clang(__VA_ARGS__)
123-
124-
#ifdef __GNUC__
125-
#ifdef __clang__
126-
#undef bsoncxx_if_clang
127-
#define bsoncxx_if_clang(...) __VA_ARGS__
128-
#else
129-
#undef bsoncxx_if_gcc
130-
#define bsoncxx_if_gcc(...) __VA_ARGS__
131-
#endif
132-
#elif defined(_MSC_VER)
133-
#undef bsoncxx_if_msvc
134-
#undef bsoncxx_if_msvc(...) __VA_ARGS__
135-
#endif
136-
137-
#pragma push_macro("bsoncxx_stringify")
138-
#pragma push_macro("bsoncxx_stringify_impl")
139-
#define bsoncxx_stringify(...) bsoncxx_stringify_impl(__VA_ARGS__)
140-
#define bsoncxx_stringify_impl(...) #__VA_ARGS__
141-
142-
#pragma push_macro("bsoncxx_pragma")
143-
#define bsoncxx_pragma(...) _Pragma(bsoncxx_stringify(__VA_ARGS__))
144-
145-
#pragma push_macro("bsoncxx_force_semicolon")
146-
/**
147-
* @brief Use in a declaration position to force the appearence of a semicolon as the next token
148-
*/
149-
#define bsoncxx_force_semicolon static_assert(true, "")
150-
151-
#pragma push_macro("bsoncxx_concat")
152-
#pragma push_macro("bsoncxx_concat_impl")
153-
#define bsoncxx_concat(A, ...) bsoncxx_concat_impl(A, __VA_ARGS__)
154-
#define bsoncxx_concat_impl(A, ...) A##__VA_ARGS__
155-
156-
#pragma push_macro("bsoncxx_disable_warning")
157-
/**
158-
* @brief Disable a warning for a particular compiler.
159-
*
160-
* The argument should be of the form:
161-
*
162-
* - Clang(<flag-string>)
163-
* - GCC(<flag-string>)
164-
* - GNU(<flag-string>)
165-
* - MSVC(<id-integer>)
166-
*/
167-
#define bsoncxx_disable_warning(Spec) bsoncxx_concat(BSONCXX_DISABLE_WARNING_IMPL_, Spec)
168-
169-
#pragma push_macro("bsoncxx_push_warnings")
170-
/**
171-
* @brief Push the current compiler diagnostics settings state
172-
*/
173-
#define bsoncxx_push_warnings() \
174-
bsoncxx_if_gnu_like(bsoncxx_pragma(GCC diagnostic push);) \
175-
bsoncxx_if_msvc(bsoncxx_pragma(warning(push));) \
176-
bsoncxx_force_semicolon
177-
178-
#pragma push_macro("bsoncxx_pop_warnings")
179-
/**
180-
* @brief Restore prior compiler diagnostics settings from before the most
181-
* recent bsoncxx_push_warnings()
182-
*/
183-
#define bsoncxx_pop_warnings() \
184-
bsoncxx_if_gnu_like(bsoncxx_pragma(GCC diagnostic pop);) \
185-
bsoncxx_if_msvc(bsoncxx_pragma(warning(pop));) \
186-
bsoncxx_force_semicolon
187-
188-
#pragma push_macro("BSONCXX_DISABLE_WARNING_IMPL_GCC")
189-
#define BSONCXX_DISABLE_WARNING_IMPL_GCC(...) \
190-
bsoncxx_if_gcc(bsoncxx_pragma(GCC diagnostic ignored __VA_ARGS__);) \
191-
bsoncxx_force_semicolon
192-
193-
#pragma push_macro("BSONCXX_DISABLE_WARNING_IMPL_Clang")
194-
#define BSONCXX_DISABLE_WARNING_IMPL_Clang(...) \
195-
bsoncxx_if_clang(bsoncxx_pragma(GCC diagnostic ignored __VA_ARGS__);) \
196-
bsoncxx_force_semicolon
197-
198-
#pragma push_macro("BSONCXX_DISABLE_WARNING_IMPL_GNU")
199-
#define BSONCXX_DISABLE_WARNING_IMPL_GNU(...) \
200-
BSONCXX_DISABLE_WARNING_IMPL_GCC(__VA_ARGS__); \
201-
BSONCXX_DISABLE_WARNING_IMPL_Clang(__VA_ARGS__)
202-
203-
#pragma push_macro("BSONCXX_DISABLE_WARNING_IMPL_MSVC")
204-
#define BSONCXX_DISABLE_WARNING_IMPL_MSVC(...) \
205-
bsoncxx_if_msvc(warning(disable : __VA_ARGS__))
206-
207-
// clang-format on

0 commit comments

Comments
 (0)