Skip to content

Commit

Permalink
more policy splitting
Browse files Browse the repository at this point in the history
  • Loading branch information
jll63 committed Sep 2, 2024
1 parent 3acc2de commit d0a1024
Show file tree
Hide file tree
Showing 17 changed files with 757 additions and 516 deletions.
7 changes: 2 additions & 5 deletions include/yorel/yomm2/detail.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#ifndef YOREL_YOMM2_DETAIL_HPP
#define YOREL_YOMM2_DETAIL_HPP

#include <boost/assert.hpp>
#include <boost/dynamic_bitset.hpp>
#include <boost/mp11/algorithm.hpp>
#include <boost/mp11/bind.hpp>

#include <yorel/yomm2/detail/static_list.hpp>

#include <boost/assert.hpp>

namespace yorel {
namespace yomm2 {
namespace detail {
Expand Down
20 changes: 13 additions & 7 deletions include/yorel/yomm2/detail/compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <boost/assert.hpp>
#include <boost/dynamic_bitset.hpp>


namespace yorel {
namespace yomm2 {
namespace detail {
Expand All @@ -37,20 +36,26 @@ struct aggregate_reports;

template<class... Reports, class Facet, class... MoreFacets>
struct aggregate_reports<
types<Reports...>, types<Facet, MoreFacets...>,
types<Reports...>,
types<Facet, MoreFacets...>,
std::void_t<typename Facet::report>> {
using type = typename aggregate_reports<
types<Reports..., typename Facet::report>, types<MoreFacets...>>::type;
types<Reports..., typename Facet::report>,
types<MoreFacets...>>::type;
};

template<class... Reports, class Facet, class... MoreFacets, typename Void>
struct aggregate_reports<types<Reports...>, types<Facet, MoreFacets...>, Void> {
struct aggregate_reports<
types<Reports...>,
types<Facet, MoreFacets...>, Void> {
using type = typename aggregate_reports<
types<Reports...>, types<MoreFacets...>>::type;
types<Reports...>,
types<MoreFacets...>>::type;
};

template<class... Reports, typename Void>
struct aggregate_reports<types<Reports...>, types<>, Void> {
struct aggregate_reports<
types<Reports...>, types<>, Void> {
struct type : Reports... {};
};

Expand Down Expand Up @@ -224,7 +229,8 @@ struct compiler : generic_compiler {
using type_index_type = decltype(Policy::type_index(0));

typename aggregate_reports<
types<update_report>, typename Policy::facets>::type report;
types<update_report>, typename Policy::facets>::type
report;

std::unordered_map<type_index_type, class_*> class_map;

Expand Down
2 changes: 2 additions & 0 deletions include/yorel/yomm2/detail/trace.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef YOREL_YOMM2_DETAIL_TRACE_HPP
#define YOREL_YOMM2_DETAIL_TRACE_HPP

#include <boost/dynamic_bitset.hpp>

namespace yorel {
namespace yomm2 {
namespace detail {
Expand Down
40 changes: 40 additions & 0 deletions include/yorel/yomm2/detail/types.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#ifndef YOREL_YOMM2_DETAIL_TYPES_HPP
#define YOREL_YOMM2_DETAIL_TYPES_HPP

#include <cstdint>
#include <limits>

#if defined(YOMM2_SHARED)
#if defined(_MSC_VER)
#if !defined(yOMM2_API_msc)
#define yOMM2_API_msc __declspec(dllimport)
#endif
#endif
#endif

#if !defined(yOMM2_API_gcc)
#define yOMM2_API_gcc
#endif

#if !defined(yOMM2_API_msc)
#define yOMM2_API_msc
#endif

#define yOMM2_API yOMM2_API_gcc yOMM2_API_msc

namespace yorel {
namespace yomm2 {

using type_id = std::uintptr_t;
constexpr type_id invalid_type = (std::numeric_limits<type_id>::max)();

namespace detail {

template<typename... Types>
struct types;

}
} // namespace yomm2
} // namespace yorel

#endif
28 changes: 28 additions & 0 deletions include/yorel/yomm2/policies/basic_error_output.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

// Copyright (c) 2018-2024 Jean-Louis Leroy
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)

#ifndef YOREL_YOMM2_POLICY_BASIC_ERROR_OUTPUT_HPP
#define YOREL_YOMM2_POLICY_BASIC_ERROR_OUTPUT_HPP

#include <yorel/yomm2/policies/core.hpp>

namespace yorel {
namespace yomm2 {
namespace policy {

template<class Policy, typename Stream = detail::ostderr>
struct yOMM2_API_gcc basic_error_output : virtual error_output {
static Stream error_stream;
};

template<class Policy, typename Stream>
Stream basic_error_output<Policy, Stream>::error_stream;

}
}
}

#endif
29 changes: 29 additions & 0 deletions include/yorel/yomm2/policies/basic_indirect_vptr.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

// Copyright (c) 2018-2024 Jean-Louis Leroy
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)

#ifndef YOREL_YOMM2_POLICY_BASIC_INDIRECT_VPTR_HPP
#define YOREL_YOMM2_POLICY_BASIC_INDIRECT_VPTR_HPP

#include <yorel/yomm2/policies/core.hpp>

namespace yorel {
namespace yomm2 {
namespace policy {

template<class Policy>
struct yOMM2_API_gcc basic_indirect_vptr : virtual indirect_vptr {
static std::vector<std::uintptr_t const* const*> indirect_vptrs;
};

template<class Policy>
std::vector<std::uintptr_t const* const*>
basic_indirect_vptr<Policy>::indirect_vptrs;

}
}
}

#endif
35 changes: 35 additions & 0 deletions include/yorel/yomm2/policies/basic_trace_output.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

// Copyright (c) 2018-2024 Jean-Louis Leroy
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)

#ifndef YOREL_YOMM2_POLICY_BASIC_TRACE_OUTPUT_HPP
#define YOREL_YOMM2_POLICY_BASIC_TRACE_OUTPUT_HPP

#include <yorel/yomm2/policies/core.hpp>

namespace yorel {
namespace yomm2 {
namespace policy {

template<class Policy, typename Stream = detail::ostderr>
struct yOMM2_API_gcc basic_trace_output : virtual trace_output {
static Stream trace_stream;
static bool trace_enabled;
};

template<class Policy, typename Stream>
Stream basic_trace_output<Policy, Stream>::trace_stream;

template<class Policy, typename Stream>
bool basic_trace_output<Policy, Stream>::trace_enabled([]() {
auto env = getenv("YOMM2_TRACE");
return env && *env++ == '1' && *env++ == 0;
}());

}
}
}

#endif
104 changes: 77 additions & 27 deletions include/yorel/yomm2/policies/core.hpp
Original file line number Diff line number Diff line change
@@ -1,38 +1,19 @@
// Copyright (c) 2018-2024 Jean-Louis Leroy
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)

#ifndef YOREL_YOMM2_POLICIES_CORE_HPP
#define YOREL_YOMM2_POLICIES_CORE_HPP

#include <yorel/yomm2/detail/types.hpp>
#include <yorel/yomm2/detail/static_list.hpp>

#if defined(YOMM2_SHARED)
#if defined(_MSC_VER)
#if !defined(yOMM2_API_msc)
#define yOMM2_API_msc __declspec(dllimport)
#endif
#endif
#endif

#if !defined(yOMM2_API_gcc)
#define yOMM2_API_gcc
#endif

#if !defined(yOMM2_API_msc)
#define yOMM2_API_msc
#endif

#define yOMM2_API yOMM2_API_gcc yOMM2_API_msc

// -----------------------------------------------------------------------------
// Forward declarations needed by "detail.hpp"
#include <boost/mp11/algorithm.hpp>
#include <boost/mp11/bind.hpp>

namespace yorel {
namespace yomm2 {

struct context;
struct catalog;

using type_id = std::uintptr_t;
constexpr type_id invalid_type = (std::numeric_limits<type_id>::max)();

namespace detail {

// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -193,6 +174,75 @@ detail::method_catalog basic_domain<Key>::methods;
template<class Key>
std::vector<std::uintptr_t> basic_domain<Key>::dispatch_data;

template<typename Policy, class Facet>
struct rebind_facet {
using type = Facet;
};

template<
typename NewPolicy, typename OldPolicy,
template<typename...> class GenericFacet, typename... Args>
struct rebind_facet<NewPolicy, GenericFacet<OldPolicy, Args...>> {
using type = GenericFacet<NewPolicy, Args...>;
};

template<class Policy, class... Facets>
struct basic_policy : virtual abstract_policy,
virtual basic_domain<Policy>,
virtual Facets... {
using facets = detail::types<Facets...>;

template<class Facet>
static constexpr bool has_facet = std::is_base_of_v<Facet, Policy>;

template<class Facet>
using use_facet = boost::mp11::mp_first<boost::mp11::mp_filter_q<
boost::mp11::mp_bind_front_q<
boost::mp11::mp_quote_trait<std::is_base_of>, Facet>,
facets>>;

template<class NewPolicy>
using rebind = basic_policy<
NewPolicy, typename rebind_facet<NewPolicy, Facets>::type...>;

template<class Base, class Facet>
using replace = boost::mp11::mp_apply<
basic_policy,
boost::mp11::mp_push_front<
boost::mp11::mp_replace_if_q<
facets,
boost::mp11::mp_bind_front_q<
boost::mp11::mp_quote_trait<std::is_base_of>, Base>,
Facet>,
Policy>>;

template<class Base>
using remove = boost::mp11::mp_apply<
basic_policy,
boost::mp11::mp_push_front<
boost::mp11::mp_remove_if_q<
facets,
boost::mp11::mp_bind_front_q<
boost::mp11::mp_quote_trait<std::is_base_of>, Base>>,
Policy>>;
};

template<class Policy, class Facet>
constexpr bool has_facet = Policy::template has_facet<Facet>;

struct rtti {
static type_id type_index(type_id type) {
return type;
}

template<typename Stream>
static void type_name(type_id type, Stream& stream) {
stream << "type_id(" << type << ")";
}
};

struct deferred_static_rtti : virtual rtti {};

} // namespace policy

} // namespace yomm2
Expand Down
Loading

0 comments on commit d0a1024

Please sign in to comment.