Skip to content

Commit adc423f

Browse files
authored
Merge pull request #744 from elbeno/fix-logging
⬆️ Update `stdx` for new formatting
2 parents b9c6e61 + be7d331 commit adc423f

File tree

9 files changed

+51
-93
lines changed

9 files changed

+51
-93
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#3023efe")
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: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,16 @@ struct graph_builder {
7575
for_each(
7676
[&]<typename Lhs, typename Rhs, typename Cond>(
7777
dsl::edge<Lhs, Rhs, Cond> const &) {
78-
auto lhs = get<name_for<Lhs>>(named_nodes);
79-
auto rhs = get<name_for<Rhs>>(named_nodes);
78+
auto const lhs = get<name_for<Lhs>>(named_nodes);
79+
auto const rhs = get<name_for<Rhs>>(named_nodes);
8080

8181
using lhs_t = std::remove_cvref_t<decltype(lhs)>;
8282
using rhs_t = std::remove_cvref_t<decltype(rhs)>;
8383
using lhs_cond_t = std::remove_cvref_t<decltype(lhs.condition)>;
8484
using rhs_cond_t = std::remove_cvref_t<decltype(rhs.condition)>;
8585

8686
using edge_ps_t = decltype(Cond::predicates);
87-
auto node_ps = stdx::to_unsorted_set(stdx::tuple_cat(
87+
constexpr auto node_ps = stdx::to_unsorted_set(stdx::tuple_cat(
8888
lhs_t::condition.predicates, rhs_t::condition.predicates));
8989

9090
stdx::for_each(
@@ -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

@@ -174,6 +172,7 @@ struct graph_builder {
174172
return x + ", "_ctst + y;
175173
});
176174

175+
// NOLINTNEXTLINE (readability-function-cognitive-complexity)
177176
constexpr static void check_for_missing_nodes(auto nodes,
178177
auto mentioned_nodes) {
179178
constexpr auto get_name = []<typename N>(N) ->
@@ -187,21 +186,24 @@ struct graph_builder {
187186
using missing_nodes_t =
188187
boost::mp11::mp_set_difference<mentioned_node_names_t,
189188
node_names_t>;
189+
constexpr auto missing_nodes = error_steps<missing_nodes_t>;
190190
STATIC_ASSERT(
191191
(std::is_same_v<node_names_t, mentioned_node_names_t>),
192192
"One or more steps are referenced in the flow ({}) but not "
193-
"explicitly added with the * operator. The missing steps are: {}.",
194-
CX_VALUE(Name), CX_VALUE(error_steps<missing_nodes_t>));
193+
"explicitly added with the * operator. The missing steps are: "
194+
"{}.",
195+
Name, missing_nodes);
195196

196197
constexpr auto duplicates = stdx::transform(
197198
[](auto e) { return stdx::get<0>(e); },
198199
stdx::filter<detail::is_duplicated>(stdx::gather(node_names)));
199200
using duplicate_nodes_t = decltype(duplicates);
201+
constexpr auto dup_nodes = error_steps<duplicate_nodes_t>;
200202
STATIC_ASSERT(
201203
stdx::tuple_size_v<duplicate_nodes_t> == 0,
202204
"One or more steps in the flow ({}) are explicitly added more than "
203205
"once using the * operator. The duplicate steps are: {}.",
204-
CX_VALUE(Name), CX_VALUE(error_steps<duplicate_nodes_t>));
206+
Name, dup_nodes);
205207
}
206208

207209
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.

include/msg/callback.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@ struct callback {
2828
}
2929

3030
template <stdx::ct_string Extra = "", typename... Args>
31+
// NOLINTNEXTLINE (readability-function-cognitive-complexity)
3132
[[nodiscard]] auto handle(auto const &data, Args &&...args) const -> bool {
3233
CIB_LOG_ENV(logging::get_level, logging::level::INFO);
3334
if (msg::call_with_message<Msg>(matcher, data)) {
3435
CIB_APPEND_LOG_ENV(typename Msg::env_t);
36+
auto const desc = matcher.describe();
3537
CIB_LOG("Incoming message matched [{}], because [{}]{}, executing "
3638
"callback",
37-
stdx::cts_t<Name>{}, matcher.describe(),
38-
stdx::cts_t<Extra>{});
39+
stdx::cts_t<Name>{}, desc, stdx::cts_t<Extra>{});
3940
msg::call_with_message<Msg>(callable, data,
4041
std::forward<Args>(args)...);
4142
return true;

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: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,16 @@ 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+
#if __clang_major__ == 14
384+
// workaround: clang-14 ICE with CIB_INFO here
385+
logging::log<stdx::extend_env_t<cib_log_env_t, logging::get_level,
386+
logging::level::INFO>>(
387+
__FILE__, __LINE__, stdx::ct_format<"{}">(desc));
388+
#else
389+
CIB_INFO("{}", desc);
390+
#endif
391+
383392
CAPTURE(log_buffer);
384393
CHECK(log_buffer.find("msg(f1: 0xba11, id: 0x80, f3: 0xd00d, f2: 0x42)") !=
385394
std::string::npos);

0 commit comments

Comments
 (0)