Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ include(cmake/string_catalog.cmake)
add_versioned_package("gh:boostorg/mp11#boost-1.83.0")
fmt_recipe(11.1.3)
add_versioned_package("gh:intel/cpp-baremetal-concurrency#0ddce52")
add_versioned_package("gh:intel/cpp-std-extensions#effadd4")
add_versioned_package("gh:intel/cpp-std-extensions#3023efe")
add_versioned_package("gh:intel/cpp-baremetal-senders-and-receivers#22c8006")

set(GEN_STR_CATALOG
Expand Down Expand Up @@ -120,8 +120,7 @@ target_sources(
include/log/flavor.hpp
include/log/level.hpp
include/log/log.hpp
include/log/module.hpp
include/log/pp_map.hpp)
include/log/module.hpp)

add_library(cib_msg INTERFACE)
target_compile_features(cib_msg INTERFACE cxx_std_20)
Expand Down
6 changes: 2 additions & 4 deletions include/cib/detail/runtime_conditional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,8 @@ operator and(runtime_condition<LhsName, LhsPs...> const &lhs,
return lhs;

} else {
constexpr auto name =
stdx::ct_format<"{} and {}">(CX_VALUE(LhsName), CX_VALUE(RhsName));

return runtime_condition<name.str.value, LhsPs..., RhsPs...>{};
constexpr auto name = STDX_CT_FORMAT("{} and {}", LhsName, RhsName);
return runtime_condition<name, LhsPs..., RhsPs...>{};
}
}

Expand Down
24 changes: 13 additions & 11 deletions include/flow/graph_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,16 @@ struct graph_builder {
for_each(
[&]<typename Lhs, typename Rhs, typename Cond>(
dsl::edge<Lhs, Rhs, Cond> const &) {
auto lhs = get<name_for<Lhs>>(named_nodes);
auto rhs = get<name_for<Rhs>>(named_nodes);
auto const lhs = get<name_for<Lhs>>(named_nodes);
auto const rhs = get<name_for<Rhs>>(named_nodes);

using lhs_t = std::remove_cvref_t<decltype(lhs)>;
using rhs_t = std::remove_cvref_t<decltype(rhs)>;
using lhs_cond_t = std::remove_cvref_t<decltype(lhs.condition)>;
using rhs_cond_t = std::remove_cvref_t<decltype(rhs.condition)>;

using edge_ps_t = decltype(Cond::predicates);
auto node_ps = stdx::to_unsorted_set(stdx::tuple_cat(
constexpr auto node_ps = stdx::to_unsorted_set(stdx::tuple_cat(
lhs_t::condition.predicates, rhs_t::condition.predicates));

stdx::for_each(
Expand All @@ -95,11 +95,9 @@ struct graph_builder {
"weaker than those on {}[{}] or {}[{}]. "
"Specifically, the sequence is missing the "
"predicate: {}",
CX_VALUE(lhs_t::ct_name), CX_VALUE(rhs_t::ct_name),
CX_VALUE(Cond::ct_name), CX_VALUE(lhs_t::ct_name),
CX_VALUE(lhs_cond_t::ct_name),
CX_VALUE(rhs_t::ct_name),
CX_VALUE(rhs_cond_t::ct_name), CX_VALUE(P));
lhs_t::ct_name, rhs_t::ct_name, Cond::ct_name,
lhs_t::ct_name, lhs_cond_t::ct_name, rhs_t::ct_name,
rhs_cond_t::ct_name, P);
},
node_ps);

Expand Down Expand Up @@ -174,6 +172,7 @@ struct graph_builder {
return x + ", "_ctst + y;
});

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

constexpr auto duplicates = stdx::transform(
[](auto e) { return stdx::get<0>(e); },
stdx::filter<detail::is_duplicated>(stdx::gather(node_names)));
using duplicate_nodes_t = decltype(duplicates);
constexpr auto dup_nodes = error_steps<duplicate_nodes_t>;
STATIC_ASSERT(
stdx::tuple_size_v<duplicate_nodes_t> == 0,
"One or more steps in the flow ({}) are explicitly added more than "
"once using the * operator. The duplicate steps are: {}.",
CX_VALUE(Name), CX_VALUE(error_steps<duplicate_nodes_t>));
Name, dup_nodes);
}

template <typename Graph>
Expand Down
33 changes: 7 additions & 26 deletions include/log/log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
#include <log/flavor.hpp>
#include <log/level.hpp>
#include <log/module.hpp>
#include <log/pp_map.hpp>

#include <stdx/compiler.hpp>
#include <stdx/ct_format.hpp>
#include <stdx/ct_string.hpp>
#include <stdx/panic.hpp>
#include <stdx/pp_map.hpp>
#if __cpp_pack_indexing < 202311L
#include <stdx/tuple.hpp>
#endif
Expand Down Expand Up @@ -74,32 +74,13 @@ template <stdx::ct_string Msg> constexpr auto cx_log_wrap(int, auto &&...args) {

// NOLINTBEGIN(cppcoreguidelines-macro-usage)

#define CIB_CX_WRAP1(X) \
[&](auto f) { \
if constexpr (::logging::detail::is_already_ct<decltype(f())>) { \
return f(); \
} else if constexpr (requires { \
stdx::ct<[&]() constexpr { return X; }()>; \
}) { \
return stdx::ct<f()>(); \
} else { \
return f(); \
} \
}([&] { return X; })

#define CIB_CX_WRAP(...) __VA_OPT__(, CIB_CX_WRAP1(__VA_ARGS__))

#define CIB_LOG(MSG, ...) \
logging::log<cib_log_env_t>(__FILE__, __LINE__, \
logging::detail::cx_log_wrap<MSG>( \
0 CIB_MAP(CIB_CX_WRAP, __VA_ARGS__)))

#define CIB_LOG_WITH_LEVEL(LEVEL, MSG, ...) \
#define CIB_LOG(...) \
logging::log<cib_log_env_t>(__FILE__, __LINE__, STDX_CT_FORMAT(__VA_ARGS__))

#define CIB_LOG_WITH_LEVEL(LEVEL, ...) \
logging::log< \
stdx::extend_env_t<cib_log_env_t, logging::get_level, LEVEL>>( \
__FILE__, __LINE__, \
logging::detail::cx_log_wrap<MSG>( \
0 CIB_MAP(CIB_CX_WRAP, __VA_ARGS__)))
__FILE__, __LINE__, STDX_CT_FORMAT(__VA_ARGS__))

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

#define CIB_FATAL(MSG, ...) \
logging::detail::panic<MSG, cib_log_env_t>( \
__FILE__, __LINE__ CIB_MAP(CIB_CX_WRAP, __VA_ARGS__))
__FILE__, __LINE__ __VA_OPT__(, STDX_MAP(CX_WRAP, __VA_ARGS__)))

#define CIB_ASSERT(expr, ...) \
((expr) \
Expand Down
35 changes: 0 additions & 35 deletions include/log/pp_map.hpp

This file was deleted.

5 changes: 3 additions & 2 deletions include/msg/callback.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ struct callback {
}

template <stdx::ct_string Extra = "", typename... Args>
// NOLINTNEXTLINE (readability-function-cognitive-complexity)
[[nodiscard]] auto handle(auto const &data, Args &&...args) const -> bool {
CIB_LOG_ENV(logging::get_level, logging::level::INFO);
if (msg::call_with_message<Msg>(matcher, data)) {
CIB_APPEND_LOG_ENV(typename Msg::env_t);
auto const desc = matcher.describe();
CIB_LOG("Incoming message matched [{}], because [{}]{}, executing "
"callback",
stdx::cts_t<Name>{}, matcher.describe(),
stdx::cts_t<Extra>{});
stdx::cts_t<Name>{}, desc, stdx::cts_t<Extra>{});
msg::call_with_message<Msg>(callable, data,
std::forward<Args>(args)...);
return true;
Expand Down
3 changes: 2 additions & 1 deletion test/log/encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,10 @@ TEST_CASE("injection - log implicit compile-time arg (int)", "[mipi]") {
}

TEST_CASE("injection - log implicit compile-time arg (string)", "[mipi]") {
using namespace stdx::literals;
test_critical_section::count = 0;
expected_args.clear();
CIB_TRACE("Hello {}", stdx::ct_string{"world"});
CIB_TRACE("Hello {}", "world"_cts);
CHECK(test_critical_section::count == 2);
}

Expand Down
22 changes: 12 additions & 10 deletions test/log/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ TEST_CASE("CIB_FATAL pre-formats arguments passed to panic", "[log]") {
reset_test_state();
expected_why = "Hello 42";

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

[]<stdx::ct_string S>() {
CIB_FATAL("{} {}", S, 42);
CIB_FATAL("{} {}", S, 17);
}.template operator()<"Hello">();

CAPTURE(buffer);
CHECK(buffer.find("Hello 42") != std::string::npos);
CHECK(buffer.find("Hello 17") != std::string::npos);
CHECK(panicked);
}

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

auto x = 42;
CIB_FATAL("Hello {}", x, 17);
auto x = 17;
auto y = 18;
CIB_FATAL("Hello {}", x, y);
CAPTURE(buffer);
CHECK(buffer.find("Hello 42") != std::string::npos);
CHECK(buffer.find("Hello 17") != std::string::npos);
CHECK(panicked);
}

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

CIB_ASSERT(true == false, 42);
auto x = 17;
CIB_ASSERT(true == false, x);
CAPTURE(buffer);
CHECK(buffer.find(expected_why) != std::string::npos);
CHECK(panicked);
Expand Down
11 changes: 10 additions & 1 deletion test/msg/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,16 @@ TEST_CASE("less_than_or_equal_to matcher", "[message]") {

TEST_CASE("describe a message", "[message]") {
test_msg m{"f1"_field = 0xba11, "f2"_field = 0x42, "f3"_field = 0xd00d};
CIB_INFO("{}", m.describe());
auto const desc = m.describe();
#if __clang_major__ == 14
// workaround: clang-14 ICE with CIB_INFO here
logging::log<stdx::extend_env_t<cib_log_env_t, logging::get_level,
logging::level::INFO>>(
__FILE__, __LINE__, stdx::ct_format<"{}">(desc));
#else
CIB_INFO("{}", desc);
#endif

CAPTURE(log_buffer);
CHECK(log_buffer.find("msg(f1: 0xba11, id: 0x80, f3: 0xd00d, f2: 0x42)") !=
std::string::npos);
Expand Down
Loading