Skip to content

Commit 78afa46

Browse files
committed
rework trace
1 parent df4e0a5 commit 78afa46

File tree

5 files changed

+104
-40
lines changed

5 files changed

+104
-40
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
= xref:macros.adoc[Macro] BOOST_OPENMETHOD_ENABLE_RUNTIME_CHECKS
2+
3+
Enable runtime checks in method calls.
4+
5+
== Synopsis
6+
7+
May be defined by a program before including
8+
`<boost/openmethod/default_registry.hpp>`.
9+
10+
== Description
11+
12+
`BOOST_OPENMETHOD_ENABLE_RUNTIME_CHECKS` enables runtime checks in method calls,
13+
for the methods in the
14+
link:reference/boost/openmethod/default_registry.html[`default_registry`]. These
15+
checks can find missing registrations for classes that are used in method calls,
16+
but not in method or overrider virtual parameters.
17+
18+
Use with caution, as inconsistent use of this macro can cause ODR violations. If
19+
defined, it must be in all the translation units in the program that use
20+
`default_registry`, including those pulled from libraries.

doc/modules/ROOT/pages/macros.adoc

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,29 @@
55
[cols=2]
66
|===
77
| Name
8-
| Description
8+
| Description.
99
| xref:BOOST_OPENMETHOD.adoc[BOOST_OPENMETHOD]
10-
| Declare a method
10+
| Declare a method.
1111
| xref:BOOST_OPENMETHOD_CLASSES.adoc[BOOST_OPENMETHOD_CLASSES]
12-
| registers classes
12+
| registers classes.
1313
| xref:BOOST_OPENMETHOD_DECLARE_OVERRIDER.adoc[BOOST_OPENMETHOD_DECLARE_OVERRIDER]
14-
| Declare a method overrider
15-
| xref:BOOST_OPENMETHOD_DEFAULT_REGISTRY.adoc[BOOST_OPENMETHOD_DEFAULT_REGISTRY]
16-
| Default registry
14+
| Declare a method overrider.
1715
| xref:BOOST_OPENMETHOD_DEFINE_OVERRIDER.adoc[BOOST_OPENMETHOD_DEFINE_OVERRIDER]
18-
| Define the body of a method overrider
16+
| Define the body of a method overrider.
1917
| xref:BOOST_OPENMETHOD_ID.adoc[BOOST_OPENMETHOD_ID]
20-
| Generate a method id
18+
| Generate a method id.
2119
| xref:BOOST_OPENMETHOD_INLINE_OVERRIDE.adoc[BOOST_OPENMETHOD_INLINE_OVERRIDE]
22-
| Add an overrider to a method as an inline function
20+
| Add an overrider to a method as an inline function.
2321
| xref:BOOST_OPENMETHOD_OVERRIDE.adoc[BOOST_OPENMETHOD_OVERRIDE]
24-
| Add an overrider to a method
22+
| Add an overrider to a method.
2523
| xref:BOOST_OPENMETHOD_OVERRIDER.adoc[BOOST_OPENMETHOD_OVERRIDER]
26-
| Return the class template specialization containing an overrider
24+
| Return the class template specialization containing an overrider.
2725
| xref:BOOST_OPENMETHOD_OVERRIDERS.adoc[BOOST_OPENMETHOD_OVERRIDERS]
28-
| Return the class template containing the overriders for all the methods with a given name
26+
| Return the class template containing the overriders for all the methods with a given name.
2927
| xref:BOOST_OPENMETHOD_REGISTER.adoc[BOOST_OPENMETHOD_REGISTER]
30-
| Create a registrar object
28+
| Create a registrar object.
29+
| xref:BOOST_OPENMETHOD_DEFAULT_REGISTRY.adoc[BOOST_OPENMETHOD_DEFAULT_REGISTRY]
30+
| Default registry.
31+
| xref:BOOST_OPENMETHOD_ENABLE_RUNTIME_CHECKS.adoc[BOOST_OPENMETHOD_ENABLE_RUNTIME_CHECKS]
32+
| Enable runtime checks in method calls.
3133
|===

include/boost/openmethod/initialize.hpp

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,21 +1547,61 @@ struct initialize_aux<
15471547
//!
15481548
//! If the first template argument is a registry, initialize it. Otherwise,
15491549
//! initialize the default registry. Additional template arguments, if any, must
1550-
//! be option types (@ref n2216 or @ref has_trace).
1550+
//! be option types (@ref n2216 or @ref trace).
1551+
//!
1552+
//! The function returns an object of an unspecified type that contains a
1553+
//! `report` member, itself an object of an unspecified type, that
1554+
//! provides information about the initialization process. Its members are:
1555+
//! @li `std::size_t cells`: The number of cells in all multi-method dispatch
1556+
//! tables.
1557+
//! @li `std::size_t not_implemented`: The number of multi-method dispatch tables that
1558+
//! contain at least one not implemented entry.
1559+
//! @li `std::size_t ambiguous`: The number of multi-method dispatch tables that contain at
1560+
//! least one ambiguous entry.
15511561
//!
15521562
//! @note
15531563
//! A translation unit that contains a call to `initialize` must include the
15541564
//! `<boost/openmethod/initialize.hpp>` header.
15551565
//!
1566+
//! @tparam Class... An optional @registry type followed by zero or more option
1567+
//! types.
1568+
//!
1569+
//! @return An object of an unspecified type.
1570+
//!
15561571
//! @par Errors
15571572
//!
1558-
//! @li @ref missing_class: A class used in a virtual parameter was
1559-
//! not registered.
1573+
//! @li @ref missing_class: A class used in a virtual parameter was not
1574+
//! registered.
1575+
//! @li The registry's policies may report additional errors.
1576+
//!
1577+
//! @par Example
1578+
//!
1579+
//! Initialize the default registry with tracing enabled, and exit
1580+
//! with an error message if there were any possibility of a @reg bad_call
1581+
//! error. User may run the program again with `BOOST_OPENMETHOD_TRACE=1` to
1582+
//! troubleshoot.
1583+
//!
1584+
//! @code
1585+
//! #include <iostream>
1586+
//!
1587+
//! #include <boost/openmethod.hpp>
1588+
//! #include <boost/openmethod/initialize.hpp>
1589+
//!
1590+
//! int main() {
1591+
//! namespace bom = boost::openmethod;
1592+
//! auto report = bom::initialize<bom::trace>().report;
1593+
//!
1594+
//! if (report.not_implemented != 0 || report.ambiguous != 0) {
1595+
//! std::cerr << "missing overriders or ambiguous methods\n";
1596+
//! return 1;
1597+
//! }
15601598
//!
1561-
//! @li Errors reported by the policies.
1562-
template<class... T>
1599+
//! // ...
1600+
//! }
1601+
//! @endcode
1602+
template<class... Class>
15631603
inline auto initialize() {
1564-
return detail::initialize_aux<void, T...>::fn();
1604+
return detail::initialize_aux<void, Class...>::fn();
15651605
}
15661606

15671607
namespace detail {

include/boost/openmethod/options.hpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,21 @@ struct n2216 : detail::option_base {};
2727

2828
//! Enable `initialize` tracing.
2929
//!
30-
//! If `trace` is present, trace instructions are added to various parts of the
31-
//! initialization process (dispatch table construction, hash factors search,
32-
//! etc). These instructions are executed only if `trace::fn<Registry>::on` is
33-
//! set to `true`. The default value of `on` is `true` if environment variable
34-
//! `BOOST_OPENMETHOD_TRACE` is set to the string "1". At the moment, any other
35-
//! value disables tracing.
30+
//! If `trace` is present in @ref initialize\'s `Options`, tracing code is added
31+
//! to various parts of the initialization process (dispatch table construction,
32+
//! hash factors search, etc). The tracing code is executed only if
33+
//! @ref trace::on is set to `true`. The default value of `on` is `true` if
34+
//! environment variable `BOOST_OPENMETHOD_TRACE` is set to the string "1", and
35+
//! false otherwise.
3636
//!
37-
//! `trace` requires an `output` policy to be present. Trace is written to its
38-
//! output stream.
37+
//! `trace` requires the registry being initialized to have an @ref output
38+
//! policy.
3939
//!
40-
//! The exact format of the trace output is not specified, and may change at any
41-
//! time. The only guarantee is that it is detailed and comprehensive, and makes
42-
//! it possible to troubleshoot problems like missing class registrations,
43-
//! missing or ambiguous overriders, etc.
40+
//! The content of the trace is neither specified, nor stable across versions.
41+
//! It is comprehensive, and useful for troubleshooting missing class
42+
//! registrations, missing or ambiguous overriders, etc.
4443
struct trace : detail::option_base {
44+
//! Enable trace.
4545
static bool on;
4646
};
4747

include/boost/openmethod/registry.hpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,9 @@ struct LightweightOutputStream {
371371

372372
#endif
373373

374-
//! Namespace containing the policy framework.
374+
//! Namespace for the policies.
375+
//!
376+
//! @see @ref registry for an explanation of policies.
375377

376378
namespace policies {
377379

@@ -754,18 +756,17 @@ struct initialize_aux;
754756

755757
} // namespace detail
756758

757-
//! A collection of methods, classes and policies.
759+
//! Methods, classes and policies.
758760
//!
759761
//! Methods exist in the context of a registry. Any class used as a method or
760762
//! overrider parameter, or in as a method call argument, must be registered
761763
//! with the same registry.
762764
//!
763-
//! Before calling a method, the @ref registry::initialize function must be
764-
//! called for its registry to set up the dispatch tables. This is typically
765-
//! done at the beginning of `main`.
765+
//! Before calling a method, its registry must be initialized with the @ref
766+
//! initialize function. This is typically done at the beginning of `main`.
766767
//!
767768
//! Multiple registries can co-exist in the same program. They must be
768-
//! initialized independently. Classes referenced by methods in different
769+
//! initialized individually. Classes referenced by methods in different
769770
//! registries must be registered with each registry.
770771
//!
771772
//! A registry also contains a set of @ref policies that control how certain
@@ -774,9 +775,10 @@ struct initialize_aux;
774775
//! interface with custom RTII systems (like LLVM's).
775776
//!
776777
//! Policies are implemented as Boost.MP11 quoted meta-functions. A policy class
777-
//! must contain a `fn<Registry>` template that provides a set of _static_
778-
//! members, specific to each policy category. Registries instantiate policies
779-
//! by passing themselves to the nested `fn` class templates.
778+
//! must contain a `fn<Registry>` template that provides a set of static
779+
//! members, specific to the responsibility of the policy. Registries
780+
//! instantiate policies by passing themselves to the nested `fn` class
781+
//! templates.
780782
//!
781783
//! There are two reason for this design.
782784
//!

0 commit comments

Comments
 (0)