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
7 changes: 3 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ target_sources(

add_library(cib_match INTERFACE)
target_compile_features(cib_match INTERFACE cxx_std_20)
target_link_libraries_system(cib_match INTERFACE cib_sc stdx)
target_link_libraries_system(cib_match INTERFACE stdx)

target_sources(
cib_match
Expand All @@ -79,7 +79,7 @@ target_sources(

add_library(cib_interrupt INTERFACE)
target_compile_features(cib_interrupt INTERFACE cxx_std_20)
target_link_libraries_system(cib_interrupt INTERFACE cib_sc concurrency stdx)
target_link_libraries_system(cib_interrupt INTERFACE concurrency stdx)

target_sources(
cib_interrupt
Expand Down Expand Up @@ -123,7 +123,7 @@ target_sources(

add_library(cib_log INTERFACE)
target_compile_features(cib_log INTERFACE cxx_std_20)
target_link_libraries_system(cib_log INTERFACE cib_sc stdx)
target_link_libraries_system(cib_log INTERFACE stdx)

target_sources(
cib_log
Expand All @@ -149,7 +149,6 @@ target_link_libraries_system(
cib_log
cib_lookup
cib_match
cib_sc
stdx)

target_sources(
Expand Down
13 changes: 6 additions & 7 deletions docs/intro.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,23 @@ library that contains all the functionality.
[mermaid, format="svg"]
----
flowchart BT
sc(cib_sc)
nexus(cib_nexus)
sc(cib_sc)
log(cib_log)
match(cib_match)
lookup(cib_lookup)

flow(cib_flow) --> nexus
flow --> sc
flow --> log

interrupt(cib_interrupt) --> sc
match(cib_match) --> sc
log(cib_log) --> sc


log_fmt(cib_log_fmt) --> log
msg(cib_msg) --> log & match
msg --> lookup

log_binary(cib_log_binary) --> msg
seq(cib_seq) --> flow

cib --> interrupt & seq & log_fmt & log_binary
interrupt(cib_interrupt)
cib --> seq & log_fmt & log_binary & interrupt
----
14 changes: 7 additions & 7 deletions include/flow/impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <flow/log.hpp>
#include <log/log.hpp>

#include <stdx/ct_format.hpp>
#include <stdx/ct_string.hpp>
#include <stdx/span.hpp>
#include <stdx/type_traits.hpp>
Expand All @@ -22,8 +23,8 @@ constexpr auto run_func() -> void {
logging::log<
decltype(get_log_env<CTNode, log_env_id_t<FlowName>>())>(
__FILE__, __LINE__,
sc::format("flow.{}({})"_sc, typename CTNode::type_t{},
typename CTNode::name_t{}));
stdx::ct_format<"flow.{}({})">(stdx::cts_t<CTNode::ct_type>{},
stdx::cts_t<CTNode::ct_name>{}));
}
typename CTNode::func_t{}();
}
Expand Down Expand Up @@ -56,19 +57,18 @@ template <stdx::ct_string Name, auto... FuncPtrs> struct inlined_func_list {
__attribute__((flatten, always_inline)) auto operator()() const -> void {
constexpr static bool loggingEnabled = not Name.empty();

constexpr auto name =
stdx::ct_string_to_type<Name, sc::string_constant>();

if constexpr (loggingEnabled) {
logging::log<decltype(get_log_env<inlined_func_list>())>(
__FILE__, __LINE__, sc::format("flow.start({})"_sc, name));
__FILE__, __LINE__,
stdx::ct_format<"flow.start({})">(stdx::cts_t<Name>{}));
}

(FuncPtrs(), ...);

if constexpr (loggingEnabled) {
logging::log<decltype(get_log_env<inlined_func_list>())>(
__FILE__, __LINE__, sc::format("flow.end({})"_sc, name));
__FILE__, __LINE__,
stdx::ct_format<"flow.end({})">(stdx::cts_t<Name>{}));
}
}
};
Expand Down
1 change: 1 addition & 0 deletions include/flow/step.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ struct ct_node {
decltype(stdx::ct_string_to_type<Name, sc::string_constant>());
using func_t = F;

constexpr static auto ct_type = Type;
constexpr static auto ct_name = Name;
constexpr static auto identity = Identity;
constexpr static auto condition = Cond{};
Expand Down
18 changes: 10 additions & 8 deletions include/log/catalog/encoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
namespace logging::binary {
namespace detail {
template <typename S, typename... Args> constexpr static auto to_message() {
constexpr auto s = S::value;
constexpr auto s = std::string_view{S::value};
using char_t = typename std::remove_cv_t<decltype(s)>::value_type;
return [&]<std::size_t... Is>(std::integer_sequence<std::size_t, Is...>) {
return sc::message<
Expand Down Expand Up @@ -74,20 +74,22 @@ template <typename T> log_writer(T) -> log_writer<T>;

template <typename Writer> struct log_handler {
template <typename Env, typename FilenameStringType,
typename LineNumberType, typename MsgType>
auto log(FilenameStringType, LineNumberType, MsgType const &msg) -> void {
log_msg<Env>(msg);
typename LineNumberType, typename FmtResult>
auto log(FilenameStringType, LineNumberType, FmtResult const &fr) -> void {
log_msg<Env>(fr);
}

template <typename Env, typename Msg> auto log_msg(Msg msg) -> void {
msg.apply([&]<typename S, typename... Args>(S, Args... args) {
template <typename Env, typename FmtResult>
auto log_msg(FmtResult const &fr) -> void {
fr.args.apply([&]<typename... Args>(Args &&...args) {
auto builder = get_builder(Env{});
constexpr auto L = stdx::to_underlying(get_level(Env{}));
using Message = typename decltype(builder)::template convert_args<
detail::to_message_t<S>::template fn, Args...>;
detail::to_message_t<decltype(fr.str)>::template fn,
std::remove_cvref_t<Args>...>;
using Module = decltype(detail::to_module<get_module(Env{})>());
w(builder.template build<L>(catalog<Message>(), module<Module>(),
args...));
std::forward<Args>(args)...));
});
}

Expand Down
13 changes: 7 additions & 6 deletions include/log/fmt/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ template <typename TDestinations> struct log_handler {
constexpr explicit log_handler(TDestinations &&ds) : dests{std::move(ds)} {}

template <typename Env, typename FilenameStringType,
typename LineNumberType, typename MsgType>
auto log(FilenameStringType, LineNumberType, MsgType const &msg) -> void {
typename LineNumberType, typename FmtResult>
auto log(FilenameStringType, LineNumberType, FmtResult const &fr) -> void {
auto const currentTime =
std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::steady_clock::now() - start_time)
Expand All @@ -52,10 +52,11 @@ template <typename TDestinations> struct log_handler {
::fmt::format_to(out, "{:>8}us {} [{}]: ", currentTime,
level_wrapper<get_level(Env{})>{},
get_module(Env{}));
msg.apply(
[&]<typename StringType>(StringType, auto const &...args) {
::fmt::format_to(out, StringType::value, args...);
});
constexpr auto fmtstr =
std::string_view{decltype(fr.str)::value};
fr.args.apply([&](auto const &...args) {
::fmt::format_to(out, fmtstr, args...);
});
*out = '\n';
},
dests);
Expand Down
25 changes: 11 additions & 14 deletions include/log/log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
#include <log/flavor.hpp>
#include <log/level.hpp>
#include <log/module.hpp>
#include <sc/format.hpp>
#include <sc/fwd.hpp>

#include <stdx/compiler.hpp>
#include <stdx/ct_format.hpp>
#include <stdx/ct_string.hpp>
#include <stdx/panic.hpp>
#include <stdx/type_traits.hpp>
Expand Down Expand Up @@ -58,13 +57,13 @@ static auto log(TArgs &&...args) -> void {
// NOLINTBEGIN(cppcoreguidelines-macro-usage)

#define CIB_LOG(MSG, ...) \
logging::log<cib_log_env_t>( \
__FILE__, __LINE__, sc::format(MSG##_sc __VA_OPT__(, ) __VA_ARGS__))
logging::log<cib_log_env_t>(__FILE__, __LINE__, \
stdx::ct_format<MSG>(__VA_ARGS__))

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

#define CIB_TRACE(...) \
CIB_LOG_WITH_LEVEL(logging::level::TRACE __VA_OPT__(, ) __VA_ARGS__)
Expand All @@ -76,14 +75,13 @@ static auto log(TArgs &&...args) -> void {
CIB_LOG_WITH_LEVEL(logging::level::ERROR __VA_OPT__(, ) __VA_ARGS__)

#define CIB_FATAL(MSG, ...) \
[](auto &&str) { \
[](auto &&s) { \
CIB_LOG_ENV(logging::get_level, logging::level::FATAL); \
logging::log<cib_log_env_t>(__FILE__, __LINE__, str); \
FWD(str).apply([]<typename S, typename... Args>(S s, Args... args) { \
constexpr auto cts = stdx::ct_string_from_type(s); \
stdx::panic<cts>(args...); \
logging::log<cib_log_env_t>(__FILE__, __LINE__, s); \
FWD(s).args.apply([](auto &&...args) { \
stdx::panic<decltype(s.str)::value>(FWD(args)...); \
}); \
}(sc::format(MSG##_sc __VA_OPT__(, ) __VA_ARGS__))
}(stdx::ct_format<MSG>(__VA_ARGS__))

#define CIB_ASSERT(expr) \
((expr) ? void(0) : CIB_FATAL("Assertion failure: " #expr))
Expand All @@ -102,9 +100,8 @@ template <typename Env, typename... Ts> static auto log_version() -> void {
CIB_LOG_ENV(logging::get_level, logging::level::MAX);
l_cfg.logger.template log<cib_log_env_t>(
"", 0,
sc::format("Version: {} ({})"_sc, sc::uint_<v_cfg.build_id>,
stdx::ct_string_to_type<v_cfg.version_string,
sc::string_constant>()));
stdx::ct_format<"Version: {} ({})">(
CX_VALUE(v_cfg.build_id), CX_VALUE(v_cfg.version_string)));
}
}
} // namespace logging
Expand Down
3 changes: 1 addition & 2 deletions include/match/and.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <match/implies.hpp>
#include <match/simplify.hpp>
#include <match/sum_of_products.hpp>
#include <sc/string_constant.hpp>

#include <cstddef>
#include <type_traits>
Expand All @@ -15,7 +14,7 @@
namespace match {
template <matcher, matcher> struct or_t;

template <matcher L, matcher R> struct and_t : bin_op_t<and_t, " and ", L, R> {
template <matcher L, matcher R> struct and_t : bin_op_t<and_t, "and", L, R> {
[[nodiscard]] constexpr auto operator()(auto const &event) const -> bool {
return this->lhs(event) and this->rhs(event);
}
Expand Down
10 changes: 5 additions & 5 deletions include/match/bin_op.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <match/cost.hpp>
#include <match/negate.hpp>
#include <match/simplify.hpp>
#include <sc/string_constant.hpp>

#include <stdx/ct_format.hpp>
#include <stdx/ct_string.hpp>
#include <stdx/type_traits.hpp>

Expand All @@ -32,16 +32,16 @@ struct bin_op_t {

private:
[[nodiscard]] constexpr auto form_description(auto const &f) const {
using namespace stdx::literals;
auto const desc = [&]<matcher M>(M const &m) {
if constexpr (stdx::is_specialization_of_v<M, Term>) {
return f(m);
} else {
return "("_sc + f(m) + ")"_sc;
return "("_ctst + f(m) + ")"_ctst;
}
};
return desc(lhs) +
stdx::ct_string_to_type<OpName, sc::string_constant>() +
desc(rhs);
return stdx::ct_format<"{} {} {}">(desc(lhs), stdx::cts_t<OpName>{},
desc(rhs));
}
};

Expand Down
6 changes: 2 additions & 4 deletions include/match/concepts.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#pragma once

#include <sc/fwd.hpp>

#include <concepts>
#include <type_traits>

Expand All @@ -12,7 +10,7 @@ concept matcher = requires { typename std::remove_cvref_t<T>::is_matcher; };
template <typename T, typename Event>
concept matcher_for = matcher<T> and requires(T const &t, Event const &e) {
{ t(e) } -> std::convertible_to<bool>;
{ t.describe() } -> sc::sc_like;
{ t.describe_match(e) } -> sc::sc_like;
t.describe();
t.describe_match(e);
};
} // namespace match
13 changes: 10 additions & 3 deletions include/match/constant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
#include <match/concepts.hpp>
#include <match/implies.hpp>
#include <match/negate.hpp>
#include <sc/string_constant.hpp>

#include <stdx/ct_string.hpp>

// NOTE: the implication overloads in this file are crafted to be high priority,
// to avoid ambiguity. Hence always_t and never_t define friend overloads that
Expand All @@ -17,7 +18,10 @@ struct always_t {
[[nodiscard]] constexpr auto operator()(auto const &) const -> bool {
return true;
}
[[nodiscard]] constexpr static auto describe() { return "true"_sc; }
[[nodiscard]] constexpr static auto describe() {
using namespace stdx::literals;
return "true"_ctst;
}
[[nodiscard]] constexpr static auto describe_match(auto const &) {
return describe();
}
Expand All @@ -35,7 +39,10 @@ struct never_t {
[[nodiscard]] constexpr auto operator()(auto const &) const -> bool {
return false;
}
[[nodiscard]] constexpr static auto describe() { return "false"_sc; }
[[nodiscard]] constexpr static auto describe() {
using namespace stdx::literals;
return "false"_ctst;
}
[[nodiscard]] constexpr static auto describe_match(auto const &) {
return describe();
}
Expand Down
7 changes: 3 additions & 4 deletions include/match/not.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
#include <match/negate.hpp>
#include <match/simplify.hpp>
#include <match/sum_of_products.hpp>
#include <sc/format.hpp>
#include <sc/string_constant.hpp>

#include <stdx/ct_format.hpp>
#include <stdx/type_traits.hpp>

#include <type_traits>
Expand All @@ -26,11 +25,11 @@ template <matcher M> struct not_t {
}

[[nodiscard]] constexpr auto describe() const {
return format("not ({})"_sc, m.describe());
return stdx::ct_format<"not ({})">(m.describe());
}

[[nodiscard]] constexpr auto describe_match(auto const &event) const {
return format("not ({})"_sc, m.describe_match(event));
return stdx::ct_format<"not ({})">(m.describe_match(event));
}

private:
Expand Down
3 changes: 1 addition & 2 deletions include/match/or.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <match/constant.hpp>
#include <match/simplify.hpp>
#include <match/sum_of_products.hpp>
#include <sc/string_constant.hpp>

#include <cstddef>
#include <type_traits>
Expand All @@ -14,7 +13,7 @@
namespace match {
template <matcher, matcher> struct and_t;

template <matcher L, matcher R> struct or_t : bin_op_t<or_t, " or ", L, R> {
template <matcher L, matcher R> struct or_t : bin_op_t<or_t, "or", L, R> {
[[nodiscard]] constexpr auto operator()(auto const &event) const -> bool {
return this->lhs(event) or this->rhs(event);
}
Expand Down
Loading
Loading