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
2 changes: 1 addition & 1 deletion 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#7c5b26c")
add_versioned_package("gh:intel/cpp-std-extensions#37cc9c5")
add_versioned_package("gh:intel/cpp-std-extensions#ec95cd6")
add_versioned_package("gh:intel/cpp-baremetal-senders-and-receivers#73d95bc")

set(GEN_STR_CATALOG
Expand Down
2 changes: 1 addition & 1 deletion include/flow/log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace flow {
using default_log_env =
logging::make_env_t<logging::get_level, logging::level::TRACE>;
stdx::make_env_t<logging::get_level, logging::level::TRACE>;
template <stdx::ct_string, typename...>
constexpr auto log_env = default_log_env{};

Expand Down
4 changes: 2 additions & 2 deletions include/interrupt/dynamic_controller.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#pragma once

#include <conc/concurrency.hpp>

#include <stdx/compiler.hpp>
#include <stdx/tuple.hpp>
#include <stdx/tuple_algorithms.hpp>
#include <stdx/type_traits.hpp>

#include <conc/concurrency.hpp>

#include <boost/mp11/algorithm.hpp>
#include <boost/mp11/list.hpp>

Expand Down
4 changes: 1 addition & 3 deletions include/log/catalog/mipi_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,6 @@ struct default_builder {
return std::forward<T>(t).query(*this);
}

CONSTEVAL auto operator()(auto &&) const {
return stdx::ct<default_builder{}>();
}
CONSTEVAL auto operator()(auto &&) const { return default_builder{}; }
} get_builder;
} // namespace logging::mipi
10 changes: 5 additions & 5 deletions include/log/catalog/mipi_encoder.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include <conc/concurrency.hpp>
#include <log/catalog/catalog.hpp>
#include <log/catalog/mipi_builder.hpp>
#include <log/catalog/mipi_messages.hpp>
Expand All @@ -13,6 +12,8 @@
#include <stdx/tuple.hpp>
#include <stdx/utility.hpp>

#include <conc/concurrency.hpp>

#include <algorithm>
#include <concepts>
#include <cstdint>
Expand Down Expand Up @@ -49,11 +50,10 @@ template <typename TDestinations> struct log_handler {

template <typename Env, typename Msg> auto log_msg(Msg msg) -> void {
msg.apply([&]<typename S, typename... Args>(S, Args... args) {
constexpr auto L = stdx::to_underlying(get_level(Env{}).value);
constexpr auto L = stdx::to_underlying(get_level(Env{}));
using Message = decltype(detail::to_message<S, Args...>());
using Module =
decltype(detail::to_module<get_module(Env{}).value>());
auto builder = get_builder(Env{}).value;
using Module = decltype(detail::to_module<get_module(Env{})>());
auto builder = get_builder(Env{});
write(builder.template build<L>(catalog<Message>(),
module<Module>(), args...));
});
Expand Down
87 changes: 3 additions & 84 deletions include/log/env.hpp
Original file line number Diff line number Diff line change
@@ -1,90 +1,9 @@
#pragma once

#include <stdx/compiler.hpp>
#include <stdx/ct_string.hpp>
#include <stdx/utility.hpp>
#include <stdx/env.hpp>

#include <boost/mp11/algorithm.hpp>

namespace logging {
template <auto Query, auto Value> struct prop {
[[nodiscard]] CONSTEVAL static auto query(decltype(Query)) noexcept {
return Value;
}
};

namespace detail {
template <typename Q, typename Env>
concept valid_query_for = requires { Env::query(Q{}); };

template <typename Q, typename... Envs>
concept valid_query_over = (... or valid_query_for<Q, Envs>);

template <typename Q> struct has_query {
template <typename Env>
using fn = std::bool_constant<valid_query_for<Q, Env>>;
};
} // namespace detail

template <typename... Envs> struct env {
template <detail::valid_query_over<Envs...> Q>
CONSTEVAL static auto query(Q) noexcept {
using I = boost::mp11::mp_find_if_q<boost::mp11::mp_list<Envs...>,
detail::has_query<Q>>;
using E = boost::mp11::mp_at<boost::mp11::mp_list<Envs...>, I>;
return Q{}(E{});
}
};

namespace detail {
template <typename T> struct autowrap {
// NOLINTNEXTLINE(google-explicit-constructor)
CONSTEVAL autowrap(T t) : value(t) {}
T value;
};

// NOLINTNEXTLINE(modernize-avoid-c-arrays)
template <std::size_t N> using str_lit_t = char const (&)[N];

template <std::size_t N> struct autowrap<str_lit_t<N>> {
// NOLINTNEXTLINE(google-explicit-constructor)
CONSTEVAL autowrap(str_lit_t<N> str) : value(str) {}
stdx::ct_string<N> value;
};

template <typename T> autowrap(T) -> autowrap<T>;
template <std::size_t N> autowrap(str_lit_t<N>) -> autowrap<str_lit_t<N>>;

template <auto V> struct wrap {
constexpr static auto value = V;
};

template <typename> struct for_each_pair;
template <std::size_t... Is> struct for_each_pair<std::index_sequence<Is...>> {
template <auto... Args>
using type = env<
prop<boost::mp11::mp_at_c<boost::mp11::mp_list<wrap<Args>...>,
2 * Is>::value.value,
stdx::ct<boost::mp11::mp_at_c<boost::mp11::mp_list<wrap<Args>...>,
(2 * Is) + 1>::value.value>()>...>;
};
} // namespace detail

template <typename Env = env<>>
constexpr auto make_env = []<detail::autowrap... Args> {
using new_env_t = typename detail::for_each_pair<
std::make_index_sequence<sizeof...(Args) / 2>>::template type<Args...>;
return boost::mp11::mp_append<new_env_t, Env>{};
};

template <typename Env, detail::autowrap... Args>
using extend_env_t = decltype(make_env<Env>.template operator()<Args...>());

template <detail::autowrap... Args>
using make_env_t = extend_env_t<env<>, Args...>;
} // namespace logging

using cib_log_env_t = logging::env<>;
using cib_log_env_t = stdx::env<>;

// NOLINTBEGIN(cppcoreguidelines-macro-usage)

Expand All @@ -96,7 +15,7 @@ using cib_log_env_t = logging::env<>;

#define CIB_LOG_ENV_DECL(...) \
[[maybe_unused]] typedef decltype([] { \
return logging::extend_env_t<cib_log_env_t, __VA_ARGS__>{}; \
return stdx::extend_env_t<cib_log_env_t, __VA_ARGS__>{}; \
}()) cib_log_env_t

#define CIB_LOG_ENV(...) \
Expand Down
2 changes: 1 addition & 1 deletion include/log/flavor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct default_flavor_t;
}

CONSTEVAL auto operator()(auto &&) const {
return stdx::ct<stdx::type_identity<default_flavor_t>{}>();
return stdx::type_identity<default_flavor_t>{};
}
} get_flavor;
} // namespace logging
4 changes: 2 additions & 2 deletions include/log/fmt/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ template <typename TDestinations> struct log_handler {
stdx::for_each(
[&](auto &out) {
::fmt::format_to(out, "{:>8}us {} [{}]: ", currentTime,
level_wrapper<get_level(Env{}).value>{},
get_module(Env{}).value);
level_wrapper<get_level(Env{})>{},
get_module(Env{}));
msg.apply(
[&]<typename StringType>(StringType, auto const &...args) {
::fmt::format_to(out, StringType::value, args...);
Expand Down
6 changes: 3 additions & 3 deletions include/log/log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ template <typename...> inline auto config = null::config{};

template <typename Env, typename... Ts>
constexpr static auto get_config() -> auto & {
using flavor_t = typename decltype(get_flavor(Env{}).value)::type;
using flavor_t = typename decltype(get_flavor(Env{}))::type;
if constexpr (std::same_as<flavor_t, default_flavor_t>) {
return config<Ts...>;
} else {
Expand All @@ -63,7 +63,7 @@ static auto log(TArgs &&...args) -> void {

#define CIB_LOG_WITH_LEVEL(LEVEL, MSG, ...) \
logging::log< \
logging::extend_env_t<cib_log_env_t, logging::get_level, LEVEL>>( \
stdx::extend_env_t<cib_log_env_t, logging::get_level, LEVEL>>( \
__FILE__, __LINE__, sc::format(MSG##_sc __VA_OPT__(, ) __VA_ARGS__))

#define CIB_TRACE(...) \
Expand Down Expand Up @@ -109,7 +109,7 @@ template <typename Env, typename... Ts> static auto log_version() -> void {
} // namespace logging

#define CIB_LOG_V(FLAVOR) \
logging::log_version<logging::extend_env_t< \
logging::log_version<stdx::extend_env_t< \
cib_log_env_t, logging::get_flavor, stdx::type_identity<FLAVOR>{}>>()
#define CIB_LOG_VERSION() CIB_LOG_V(logging::default_flavor_t)

Expand Down
2 changes: 1 addition & 1 deletion include/log/module.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace logging {

CONSTEVAL auto operator()(auto &&) const {
using namespace stdx::literals;
return "default"_ctst;
return "default"_cts;
}
} get_module;
} // namespace logging
Expand Down
14 changes: 7 additions & 7 deletions test/flow/custom_log_levels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct log_config {
template <typename Env, typename FilenameStringType,
typename LineNumberType, typename MsgType>
auto log(FilenameStringType, LineNumberType, MsgType const &) -> void {
log_calls.push_back(logging::get_level(Env{}).value);
log_calls.push_back(logging::get_level(Env{}));
}
};
log_handler logger;
Expand All @@ -51,16 +51,16 @@ struct log_config {
template <> inline auto logging::config<> = log_config{};

using user1_log_env =
logging::extend_env_t<flow::default_log_env, logging::get_level,
logging::level::USER1>;
stdx::extend_env_t<flow::default_log_env, logging::get_level,
logging::level::USER1>;

using user2_log_env =
logging::extend_env_t<flow::default_log_env, logging::get_level,
logging::level::USER2>;
stdx::extend_env_t<flow::default_log_env, logging::get_level,
logging::level::USER2>;

using info_log_env =
logging::extend_env_t<flow::default_log_env, logging::get_level,
logging::level::INFO>;
stdx::extend_env_t<flow::default_log_env, logging::get_level,
logging::level::INFO>;

template <> constexpr auto flow::log_env<"default"> = info_log_env{};

Expand Down
2 changes: 1 addition & 1 deletion test/flow/log_levels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct log_config {
template <typename Env, typename FilenameStringType,
typename LineNumberType, typename MsgType>
auto log(FilenameStringType, LineNumberType, MsgType const &) -> void {
log_calls.push_back(logging::get_level(Env{}).value);
log_calls.push_back(logging::get_level(Env{}));
}
};
log_handler logger;
Expand Down
2 changes: 1 addition & 1 deletion test/interrupt/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct test_nexus {

template <auto> struct enable_field_t {
static inline bool value{};
constexpr friend auto operator==(enable_field_t, enable_field_t)
friend constexpr auto operator==(enable_field_t, enable_field_t)
-> bool = default;
};
template <auto> struct status_field_t {
Expand Down
5 changes: 3 additions & 2 deletions test/log/catalog1_lib.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include "catalog_concurrency.hpp"

#include <conc/concurrency.hpp>
#include <log/catalog/mipi_encoder.hpp>

#include <conc/concurrency.hpp>

#include <cstdint>

template <> inline auto conc::injected_policy<> = test_conc_policy{};
Expand All @@ -18,7 +19,7 @@ struct test_log_args_destination {
}
};

using log_env1 = logging::make_env_t<logging::get_level, logging::level::TRACE>;
using log_env1 = stdx::make_env_t<logging::get_level, logging::level::TRACE>;
} // namespace

auto log_zero_args() -> void;
Expand Down
6 changes: 3 additions & 3 deletions test/log/catalog2a_lib.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include "catalog_concurrency.hpp"
#include "catalog_enums.hpp"

#include <conc/concurrency.hpp>
#include <log/catalog/mipi_encoder.hpp>

#include <conc/concurrency.hpp>

#include <cstdint>

template <> inline auto conc::injected_policy<> = test_conc_policy{};
Expand All @@ -19,8 +20,7 @@ struct test_log_args_destination {
}
};

using log_env2a =
logging::make_env_t<logging::get_level, logging::level::TRACE>;
using log_env2a = stdx::make_env_t<logging::get_level, logging::level::TRACE>;
} // namespace

auto log_two_rt_args() -> void;
Expand Down
6 changes: 3 additions & 3 deletions test/log/catalog2b_lib.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include "catalog_concurrency.hpp"
#include "catalog_enums.hpp"

#include <conc/concurrency.hpp>
#include <log/catalog/mipi_encoder.hpp>

#include <conc/concurrency.hpp>

#include <cstdint>

template <> inline auto conc::injected_policy<> = test_conc_policy{};
Expand All @@ -15,8 +16,7 @@ struct test_log_args_destination {
auto log_by_args(std::uint32_t, auto...) -> void { ++log_calls; }
};

using log_env2b =
logging::make_env_t<logging::get_level, logging::level::TRACE>;
using log_env2b = stdx::make_env_t<logging::get_level, logging::level::TRACE>;
} // namespace

auto log_rt_enum_arg() -> void;
Expand Down
11 changes: 6 additions & 5 deletions test/log/env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <catch2/catch_test_macros.hpp>

#include <string>
#include <string_view>
#include <utility>
#include <vector>
Expand Down Expand Up @@ -43,7 +44,7 @@ TEST_CASE("supplement environment", "[log_env]") {
using namespace stdx::literals;
CIB_LOG_ENV(logging::get_module, "hello");
static_assert(custom(cib_log_env_t{}) == 1);
static_assert(logging::get_module(cib_log_env_t{}) == "hello"_ctst);
static_assert(logging::get_module(cib_log_env_t{}) == "hello"_cts);
}
}

Expand All @@ -52,19 +53,19 @@ TEST_CASE("multi-value environment", "[log_env]") {

using namespace stdx::literals;
static_assert(custom(cib_log_env_t{}) == 1);
static_assert(logging::get_module(cib_log_env_t{}) == "hello"_ctst);
static_assert(logging::get_module(cib_log_env_t{}) == "hello"_cts);
}

namespace {
auto logged_modules = std::vector<std::string_view>{};
auto logged_modules = std::vector<std::string>{};

struct log_handler {
template <typename Env, typename FilenameStringType,
typename LineNumberType, typename MsgType>
auto log(FilenameStringType, LineNumberType, MsgType const &) -> void {
using namespace stdx::literals;
logged_modules.push_back(
std::string_view{logging::get_module(Env{}).value});
logged_modules.emplace_back(
std::string_view{logging::get_module(Env{})});
}
};

Expand Down
2 changes: 1 addition & 1 deletion test/log/fmt_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ inline auto logging::config<secure_t> =
logging::fmt::config{std::back_inserter(secure_buffer)};

#define SECURE_TRACE(MSG, ...) \
logging::log<logging::extend_env_t< \
logging::log<stdx::extend_env_t< \
cib_log_env_t, logging::get_level, logging::level::TRACE, \
logging::get_flavor, stdx::type_identity<secure_t>{}>>( \
__FILE__, __LINE__, sc::format(MSG##_sc __VA_OPT__(, ) __VA_ARGS__))
Expand Down
Loading
Loading