Skip to content

Commit 39d7acb

Browse files
New formatting scripts
1 parent 4d11e78 commit 39d7acb

File tree

9 files changed

+335
-119
lines changed

9 files changed

+335
-119
lines changed

.clang-format

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,23 +62,41 @@ SpaceBeforeAssignmentOperators: true
6262
ContinuationIndentWidth: 4
6363
CommentPragmas: "^ IWYU pragma:"
6464
SpaceBeforeParens: ControlStatements
65+
SortIncludes: CaseSensitive
6566
DisableFormat: false
6667
IncludeBlocks: Regroup
6768
IncludeCategories:
6869
- Regex: '"\.' # Relative headers
6970
Priority: 10
7071
- Regex: '<amongoc/|"amongoc/' # amongoc headers first
7172
Priority: 20
72-
- Regex: '<bson/|"bson/' # bson headers next
73+
- Regex: "<bson/" # bson headers next
7374
Priority: 25
74-
- Regex: '<mlib/|"mlib/' # mlib headers next
75+
- Regex: "<mlib/" # mlib headers next
7576
Priority: 30
7677
- Regex: '<.*/.*\.h>|<.*/.*\.hpp>' # Other non-standard headres
7778
Priority: 40
7879
- Regex: '<.*\.h>|<.*\.hpp>' # Other non-standard headres
7980
Priority: 50
8081
- Regex: '<[[:alnum:]_.]+>|<std.*\.h>' # Standard headres
8182
Priority: 60
83+
# Unix platform headers
84+
- Regex: '<(unistd|netdb|pthread|netinet/.*|sys/.*|netdb|fcntl|arpa/.*|resolv|sched|poll)\.h>'
85+
Priority: 90
86+
# Darwin platform headers
87+
- Regex: '<(Availability|AvailabilityMacros|TargetConditionals|CommonCrypto/.*|Security/.*|CoreFoundation/.*)\.h>'
88+
CaseSensitive: false
89+
Priority: 90
90+
# Windows platform headers
91+
- Regex: '<(win(dows|sock2|error|trnl|error|crypt|ver|dns)|sspi|ws2tcpip|ntstatus|mstcpip|process)\.h>'
92+
CaseSensitive: false
93+
Priority: 90
94+
# Standard library headers are near last
95+
- Regex: "<(assert|string|ctype|limits|time|math|errno|inttypes|signal).h>|<std|<[^.]+>"
96+
Priority: 100
97+
# Other -I headers get sorted before platform headers
98+
- Regex: "<"
99+
Priority: 80
82100
InsertNewlineAtEOF: true
83101
IfMacros:
84102
- mlib_math_catch

include/amongoc/collection.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ mlib_extern_c_begin();
3232
*/
3333
#define amongoc_collection_new(Client, DbName, CollName) \
3434
amongoc_collection_new(Client, mlib_str_view_from(DbName), mlib_str_view_from(CollName))
35-
amongoc_collection*(amongoc_collection_new)(amongoc_client* cl,
36-
mlib_str_view db_name,
37-
mlib_str_view coll_name)mlib_noexcept;
35+
amongoc_collection*(amongoc_collection_new)(amongoc_client * cl,
36+
mlib_str_view db_name,
37+
mlib_str_view coll_name) mlib_noexcept;
3838

3939
/**
4040
* @brief Delete a collection handle. Is a no-op for null handles.

include/bson/view.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ typedef struct bson_view {
5858
* The `static_cast` in the return type will SFINAE-away invalid operands
5959
*/
6060
template <typename T>
61-
[[nodiscard]] constexpr static auto from(T&& o) noexcept -> decltype(static_cast<bson_view>(o)) {
61+
[[nodiscard]] constexpr static auto from(T&& o) noexcept
62+
-> decltype(static_cast<bson_view>(o)) {
6263
return static_cast<bson_view>(o);
6364
}
6465

include/mlib/config.h

Lines changed: 53 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@
2525

2626
#define MLIB_PASTE(A, ...) _mlibPaste1(A, __VA_ARGS__)
2727
#define MLIB_PASTE_3(A, B, ...) MLIB_PASTE(A, MLIB_PASTE(B, __VA_ARGS__))
28-
#define MLIB_PASTE_4(A, B, C, ...) \
29-
MLIB_PASTE(A, MLIB_PASTE_3(B, C, __VA_ARGS__))
30-
#define MLIB_PASTE_5(A, B, C, D, ...) \
31-
MLIB_PASTE(A, MLIB_PASTE_4(B, C, D, __VA_ARGS__))
28+
#define MLIB_PASTE_4(A, B, C, ...) MLIB_PASTE(A, MLIB_PASTE_3(B, C, __VA_ARGS__))
29+
#define MLIB_PASTE_5(A, B, C, D, ...) MLIB_PASTE(A, MLIB_PASTE_4(B, C, D, __VA_ARGS__))
3230
#define _mlibPaste1(A, ...) A##__VA_ARGS__
3331

3432
#define MLIB_STR(...) _mlibStr(__VA_ARGS__)
@@ -51,9 +49,8 @@
5149
#define MLIB_EVAL_2(...) MLIB_EVAL_1(MLIB_EVAL_1(__VA_ARGS__))
5250
#define MLIB_EVAL_1(...) __VA_ARGS__
5351

54-
#if defined(__cpp_concepts) && __cpp_concepts >= 201907L && \
55-
defined(__cpp_impl_three_way_comparison) && \
56-
__cpp_impl_three_way_comparison >= 201907L
52+
#if defined(__cpp_concepts) && __cpp_concepts >= 201907L \
53+
&& defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
5754
#define mlib_have_cxx20() 1
5855
#else
5956
#define mlib_have_cxx20() 0
@@ -69,12 +66,26 @@
6966
* @brief Expands to an integer literal corresponding to the number of macro
7067
* arguments. Supports up to fifteen arguments.
7168
*/
72-
#define MLIB_ARG_COUNT(...) \
73-
_mlibPickSixteenth(__VA_ARGS__ __VA_OPT__(, ) 15, 14, 13, 12, 11, 10, 9, 8, \
74-
7, 6, 5, 4, 3, 2, 1, 0)
75-
#define _mlibPickSixteenth(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, \
76-
_13, _14, _15, _16, ...) \
77-
_16
69+
#define MLIB_ARG_COUNT(...) \
70+
_mlibPickSixteenth(__VA_ARGS__ __VA_OPT__(, ) 15, \
71+
14, \
72+
13, \
73+
12, \
74+
11, \
75+
10, \
76+
9, \
77+
8, \
78+
7, \
79+
6, \
80+
5, \
81+
4, \
82+
3, \
83+
2, \
84+
1, \
85+
0)
86+
#define _mlibPickSixteenth( \
87+
_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, ...) \
88+
_16
7889

7990
/**
8091
* @brief If the argument expands to `0`, `false`, or nothing, expands to `0`.
@@ -93,8 +104,7 @@
93104
* list. Otherwise, expands to the third argument list. The unused argument list
94105
* is not expanded and is discarded.
95106
*/
96-
#define MLIB_IF_ELSE(...) \
97-
MLIB_PASTE(_mlibIfElseBranch_, MLIB_BOOLEAN(__VA_ARGS__))
107+
#define MLIB_IF_ELSE(...) MLIB_PASTE(_mlibIfElseBranch_, MLIB_BOOLEAN(__VA_ARGS__))
98108
#define _mlibIfElseBranch_1(...) __VA_ARGS__ _mlibNoExpandNothing
99109
#define _mlibIfElseBranch_0(...) MLIB_NOTHING(#__VA_ARGS__) MLIB_JUST
100110
#define _mlibNoExpandNothing(...) MLIB_NOTHING(#__VA_ARGS__)
@@ -152,8 +162,8 @@
152162
#define mlib_static_assert MLIB_LANG_PICK(_Static_assert)(static_assert)
153163

154164
#define mlib_extern_c_begin() MLIB_IF_CXX(extern "C" {) mlib_static_assert(1, "")
155-
#define mlib_extern_c_end() MLIB_IF_CXX( \
156-
}) mlib_static_assert(1, "")
165+
#define mlib_extern_c_end() MLIB_IF_CXX( \
166+
}) mlib_static_assert(1, "")
157167

158168
/**
159169
* @brief Use as the prefix of a braced initializer within C headers, allowing
@@ -168,21 +178,21 @@
168178
* @brief (C++ only) Expands to a `static_cast` expression that perfect-forwards
169179
* the argument.
170180
*/
171-
#define mlib_fwd(...) (static_cast<decltype(__VA_ARGS__) &&>(__VA_ARGS__))
181+
#define mlib_fwd(...) (static_cast<decltype(__VA_ARGS__)&&>(__VA_ARGS__))
172182

173183
#ifdef __has_include
174184
#if __has_include(<mlib.tweaks.h>)
175185
#include <mlib.tweaks.h>
176-
#endif // __has_include()
177-
#endif // __has_include
186+
#endif // __has_include()
187+
#endif // __has_include
178188

179189
#ifndef mlib_audit_allocator_passing
180190
/**
181191
* @brief Macro that should be used to toggle convenience APIs that will
182192
* pass default allocators.
183193
*/
184194
#define mlib_audit_allocator_passing() 1
185-
#endif // mlib_audit_allocator_passing
195+
#endif // mlib_audit_allocator_passing
186196

187197
#ifdef __GNUC__
188198
#define mlib_is_gnu_like() 1
@@ -292,13 +302,13 @@
292302
#elif __STDC__ == 1 && __STDC_VERSION >= 201112L
293303
// Declares C11 support
294304
#define mlib_has_generic_selection() 1
295-
#elif mlib_is_gcc_at_least(4, 9, 0) || mlib_is_clang_at_least(3, 0, 0) || \
296-
mlib_is_msvc_at_least(19, 28, 0)
305+
#elif mlib_is_gcc_at_least(4, 9, 0) || mlib_is_clang_at_least(3, 0, 0) \
306+
|| mlib_is_msvc_at_least(19, 28, 0)
297307
// Other compilers that support _Generic() without full C11
298308
#define mlib_has_generic_selection() 1
299309
#else
300310
#define mlib_has_generic_selection() 0
301-
#endif // Check for _Generic() support
311+
#endif // Check for _Generic() support
302312

303313
/**
304314
* @brief Create a generic selection expression with fallback compatibility for
@@ -310,11 +320,10 @@
310320
* @param SelectorExpression The Selector expression for _Generic()
311321
* @param __VA_ARGS__ All remaining arguments are the selectors for _Generic()
312322
*/
313-
#define mlib_generic(CxxExpression, DefaultExpression, SelectorExpression, \
314-
...) \
315-
MLIB_LANG_PICK(MLIB_IF_ELSE(mlib_has_generic_selection())( \
316-
_Generic((SelectorExpression), __VA_ARGS__))(DefaultExpression)) \
317-
(CxxExpression)
323+
#define mlib_generic(CxxExpression, DefaultExpression, SelectorExpression, ...) \
324+
MLIB_LANG_PICK(MLIB_IF_ELSE(mlib_has_generic_selection())( \
325+
_Generic((SelectorExpression), __VA_ARGS__))(DefaultExpression)) \
326+
(CxxExpression)
318327

319328
/**
320329
* @brief For empty struct/union types, this must be the sole non-static
@@ -348,30 +357,30 @@ namespace mlib {
348357
*/
349358
mlib_constexpr bool is_constant_evaluated() noexcept {
350359
#ifdef __cpp_if_consteval
351-
if consteval {
352-
return true;
353-
} else {
354-
return false;
355-
}
360+
if consteval {
361+
return true;
362+
} else {
363+
return false;
364+
}
356365
#endif
357366
#if mlib_is_gnu_like() || mlib_is_msvc()
358-
// GNU and MSVC share the builtin
359-
return __builtin_is_constant_evaluated();
367+
// GNU and MSVC share the builtin
368+
return __builtin_is_constant_evaluated();
360369
#endif
361-
// Otherwise we cannot check
362-
return false;
370+
// Otherwise we cannot check
371+
return false;
363372
}
364373

365374
/**
366375
* @brief An invocable object that simply returns its argument unchanged
367376
*/
368377
struct identity {
369-
template <typename T>
370-
mlib_always_inline constexpr T &&operator()(T &&arg) const noexcept {
371-
return static_cast<T &&>(arg);
372-
}
378+
template <typename T>
379+
mlib_always_inline constexpr T&& operator()(T&& arg) const noexcept {
380+
return static_cast<T&&>(arg);
381+
}
373382
};
374383

375-
} // namespace mlib
384+
} // namespace mlib
376385

377-
#endif // C++
386+
#endif // C++

src/amongoc/collection.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ _parse_cursor(::amongoc_collection& coll, int batch_size, bson_view resp) {
6767
return mlib::unique(std::move(curs));
6868
}
6969

70-
::amongoc_collection*(amongoc_collection_new)(amongoc_client* cl,
71-
mlib_str_view db_name,
72-
mlib_str_view coll_name) noexcept try {
70+
::amongoc_collection*(amongoc_collection_new)(amongoc_client * cl,
71+
mlib_str_view db_name,
72+
mlib_str_view coll_name) noexcept try {
7373
auto ptr = cl->get_allocator().rebind<amongoc_collection>().new_(*cl,
7474
string(db_name,
7575
cl->get_allocator()),

src/amongoc/coroutine.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ class nanosender_awaiter {
255255
* @param s The nanosender being awaited
256256
*/
257257
template <nanosender S>
258-
nanosender_awaiter<S> operator co_await(S && s) {
258+
nanosender_awaiter<S> operator co_await(S&& s) {
259259
return nanosender_awaiter<S>{mlib_fwd(s)};
260260
}
261261

src/testing-main.test.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
#include <stdlib.h>
55
#include <test_params.test.hpp>
66

7-
#include "catch2/catch_test_macros.hpp"
8-
97
int main(int argc, char** argv) {
108
Catch::Session session;
119
std::string uri;

0 commit comments

Comments
 (0)