Skip to content

Commit ba379ef

Browse files
committed
⬆️ Update stdx for new formatting
Problem: - `stdx` provides a formatting macro that auto-preserves the `constexpr` nature of arguments; CIB log macros do not yet do the same. Solution: - Update `stdx` and log macros.
1 parent b9c6e61 commit ba379ef

File tree

8 files changed

+32
-87
lines changed

8 files changed

+32
-87
lines changed

CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ include(cmake/string_catalog.cmake)
2525
add_versioned_package("gh:boostorg/mp11#boost-1.83.0")
2626
fmt_recipe(11.1.3)
2727
add_versioned_package("gh:intel/cpp-baremetal-concurrency#0ddce52")
28-
add_versioned_package("gh:intel/cpp-std-extensions#effadd4")
28+
add_versioned_package("gh:intel/cpp-std-extensions#dace94f")
2929
add_versioned_package("gh:intel/cpp-baremetal-senders-and-receivers#22c8006")
3030

3131
set(GEN_STR_CATALOG
@@ -120,8 +120,7 @@ target_sources(
120120
include/log/flavor.hpp
121121
include/log/level.hpp
122122
include/log/log.hpp
123-
include/log/module.hpp
124-
include/log/pp_map.hpp)
123+
include/log/module.hpp)
125124

126125
add_library(cib_msg INTERFACE)
127126
target_compile_features(cib_msg INTERFACE cxx_std_20)

include/cib/detail/runtime_conditional.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,8 @@ operator and(runtime_condition<LhsName, LhsPs...> const &lhs,
8282
return lhs;
8383

8484
} else {
85-
constexpr auto name =
86-
stdx::ct_format<"{} and {}">(CX_VALUE(LhsName), CX_VALUE(RhsName));
87-
88-
return runtime_condition<name.str.value, LhsPs..., RhsPs...>{};
85+
constexpr auto name = STDX_CT_FORMAT("{} and {}", LhsName, RhsName);
86+
return runtime_condition<name, LhsPs..., RhsPs...>{};
8987
}
9088
}
9189

include/flow/graph_builder.hpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,9 @@ struct graph_builder {
9595
"weaker than those on {}[{}] or {}[{}]. "
9696
"Specifically, the sequence is missing the "
9797
"predicate: {}",
98-
CX_VALUE(lhs_t::ct_name), CX_VALUE(rhs_t::ct_name),
99-
CX_VALUE(Cond::ct_name), CX_VALUE(lhs_t::ct_name),
100-
CX_VALUE(lhs_cond_t::ct_name),
101-
CX_VALUE(rhs_t::ct_name),
102-
CX_VALUE(rhs_cond_t::ct_name), CX_VALUE(P));
98+
lhs_t::ct_name, rhs_t::ct_name, Cond::ct_name,
99+
lhs_t::ct_name, lhs_cond_t::ct_name, rhs_t::ct_name,
100+
rhs_cond_t::ct_name, P);
103101
},
104102
node_ps);
105103

@@ -191,7 +189,7 @@ struct graph_builder {
191189
(std::is_same_v<node_names_t, mentioned_node_names_t>),
192190
"One or more steps are referenced in the flow ({}) but not "
193191
"explicitly added with the * operator. The missing steps are: {}.",
194-
CX_VALUE(Name), CX_VALUE(error_steps<missing_nodes_t>));
192+
Name, error_steps<missing_nodes_t>);
195193

196194
constexpr auto duplicates = stdx::transform(
197195
[](auto e) { return stdx::get<0>(e); },
@@ -201,7 +199,7 @@ struct graph_builder {
201199
stdx::tuple_size_v<duplicate_nodes_t> == 0,
202200
"One or more steps in the flow ({}) are explicitly added more than "
203201
"once using the * operator. The duplicate steps are: {}.",
204-
CX_VALUE(Name), CX_VALUE(error_steps<duplicate_nodes_t>));
202+
Name, error_steps<duplicate_nodes_t>);
205203
}
206204

207205
template <typename Graph>

include/log/log.hpp

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
#include <log/flavor.hpp>
55
#include <log/level.hpp>
66
#include <log/module.hpp>
7-
#include <log/pp_map.hpp>
87

98
#include <stdx/compiler.hpp>
109
#include <stdx/ct_format.hpp>
1110
#include <stdx/ct_string.hpp>
1211
#include <stdx/panic.hpp>
12+
#include <stdx/pp_map.hpp>
1313
#if __cpp_pack_indexing < 202311L
1414
#include <stdx/tuple.hpp>
1515
#endif
@@ -74,32 +74,13 @@ template <stdx::ct_string Msg> constexpr auto cx_log_wrap(int, auto &&...args) {
7474

7575
// NOLINTBEGIN(cppcoreguidelines-macro-usage)
7676

77-
#define CIB_CX_WRAP1(X) \
78-
[&](auto f) { \
79-
if constexpr (::logging::detail::is_already_ct<decltype(f())>) { \
80-
return f(); \
81-
} else if constexpr (requires { \
82-
stdx::ct<[&]() constexpr { return X; }()>; \
83-
}) { \
84-
return stdx::ct<f()>(); \
85-
} else { \
86-
return f(); \
87-
} \
88-
}([&] { return X; })
89-
90-
#define CIB_CX_WRAP(...) __VA_OPT__(, CIB_CX_WRAP1(__VA_ARGS__))
91-
92-
#define CIB_LOG(MSG, ...) \
93-
logging::log<cib_log_env_t>(__FILE__, __LINE__, \
94-
logging::detail::cx_log_wrap<MSG>( \
95-
0 CIB_MAP(CIB_CX_WRAP, __VA_ARGS__)))
96-
97-
#define CIB_LOG_WITH_LEVEL(LEVEL, MSG, ...) \
77+
#define CIB_LOG(...) \
78+
logging::log<cib_log_env_t>(__FILE__, __LINE__, STDX_CT_FORMAT(__VA_ARGS__))
79+
80+
#define CIB_LOG_WITH_LEVEL(LEVEL, ...) \
9881
logging::log< \
9982
stdx::extend_env_t<cib_log_env_t, logging::get_level, LEVEL>>( \
100-
__FILE__, __LINE__, \
101-
logging::detail::cx_log_wrap<MSG>( \
102-
0 CIB_MAP(CIB_CX_WRAP, __VA_ARGS__)))
83+
__FILE__, __LINE__, STDX_CT_FORMAT(__VA_ARGS__))
10384

10485
#define CIB_TRACE(...) \
10586
CIB_LOG_WITH_LEVEL(logging::level::TRACE __VA_OPT__(, ) __VA_ARGS__)
@@ -160,7 +141,7 @@ template <stdx::ct_string Fmt, typename Env, typename F, typename L>
160141

161142
#define CIB_FATAL(MSG, ...) \
162143
logging::detail::panic<MSG, cib_log_env_t>( \
163-
__FILE__, __LINE__ CIB_MAP(CIB_CX_WRAP, __VA_ARGS__))
144+
__FILE__, __LINE__ __VA_OPT__(, STDX_MAP(CX_WRAP, __VA_ARGS__)))
164145

165146
#define CIB_ASSERT(expr, ...) \
166147
((expr) \

include/log/pp_map.hpp

Lines changed: 0 additions & 35 deletions
This file was deleted.

test/log/encoder.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,10 @@ TEST_CASE("injection - log implicit compile-time arg (int)", "[mipi]") {
355355
}
356356

357357
TEST_CASE("injection - log implicit compile-time arg (string)", "[mipi]") {
358+
using namespace stdx::literals;
358359
test_critical_section::count = 0;
359360
expected_args.clear();
360-
CIB_TRACE("Hello {}", stdx::ct_string{"world"});
361+
CIB_TRACE("Hello {}", "world"_cts);
361362
CHECK(test_critical_section::count == 2);
362363
}
363364

test/log/log.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ TEST_CASE("CIB_FATAL pre-formats arguments passed to panic", "[log]") {
8181
reset_test_state();
8282
expected_why = "Hello 42";
8383

84-
CIB_FATAL("{} {}", "Hello"_ctst, stdx::ct<42>());
84+
CIB_FATAL("{} {}", "Hello", 42);
8585
CAPTURE(buffer);
8686
CHECK(buffer.find("Hello 42") != std::string::npos);
8787
CHECK(panicked);
@@ -115,27 +115,28 @@ TEST_CASE("CIB_FATAL can format stack arguments (2)", "[log]") {
115115
TEST_CASE("CIB_FATAL formats compile-time arguments where possible", "[log]") {
116116
using namespace stdx::literals;
117117
reset_test_state();
118-
expected_why = "Hello 42";
118+
expected_why = "Hello 17";
119119
expected_args = std::make_tuple(stdx::make_tuple());
120120

121121
[]<stdx::ct_string S>() {
122-
CIB_FATAL("{} {}", S, 42);
122+
CIB_FATAL("{} {}", S, 17);
123123
}.template operator()<"Hello">();
124124

125125
CAPTURE(buffer);
126-
CHECK(buffer.find("Hello 42") != std::string::npos);
126+
CHECK(buffer.find("Hello 17") != std::string::npos);
127127
CHECK(panicked);
128128
}
129129

130130
TEST_CASE("CIB_FATAL passes extra arguments to panic", "[log]") {
131131
reset_test_state();
132132
expected_why = "Hello {}";
133-
expected_args = std::make_tuple(stdx::make_tuple(42), stdx::ct<17>());
133+
expected_args = std::make_tuple(stdx::make_tuple(17), 18);
134134

135-
auto x = 42;
136-
CIB_FATAL("Hello {}", x, 17);
135+
auto x = 17;
136+
auto y = 18;
137+
CIB_FATAL("Hello {}", x, y);
137138
CAPTURE(buffer);
138-
CHECK(buffer.find("Hello 42") != std::string::npos);
139+
CHECK(buffer.find("Hello 17") != std::string::npos);
139140
CHECK(panicked);
140141
}
141142

@@ -152,9 +153,10 @@ TEST_CASE("CIB_ASSERT is equivalent to CIB_FATAL on failure", "[log]") {
152153
TEST_CASE("CIB_ASSERT passes arguments to panic", "[log]") {
153154
reset_test_state();
154155
expected_why = "Assertion failure: true == false";
155-
expected_args = std::make_tuple(stdx::make_tuple(), stdx::ct<42>());
156+
expected_args = std::make_tuple(stdx::make_tuple(), 17);
156157

157-
CIB_ASSERT(true == false, 42);
158+
auto x = 17;
159+
CIB_ASSERT(true == false, x);
158160
CAPTURE(buffer);
159161
CHECK(buffer.find(expected_why) != std::string::npos);
160162
CHECK(panicked);

test/msg/message.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,8 @@ TEST_CASE("less_than_or_equal_to matcher", "[message]") {
379379

380380
TEST_CASE("describe a message", "[message]") {
381381
test_msg m{"f1"_field = 0xba11, "f2"_field = 0x42, "f3"_field = 0xd00d};
382-
CIB_INFO("{}", m.describe());
382+
auto const desc = m.describe();
383+
CIB_INFO("{}", desc);
383384
CAPTURE(log_buffer);
384385
CHECK(log_buffer.find("msg(f1: 0xba11, id: 0x80, f3: 0xd00d, f2: 0x42)") !=
385386
std::string::npos);

0 commit comments

Comments
 (0)