mirror of
https://github.com/boostorg/contract.git
synced 2026-02-27 17:02:15 +00:00
parsing template parameters
This commit is contained in:
55
include/boost/contract/ext_/preprocessor/traits/adt.hpp
Normal file
55
include/boost/contract/ext_/preprocessor/traits/adt.hpp
Normal file
@@ -0,0 +1,55 @@
|
||||
|
||||
#ifndef BOOST_CONTRACT_EXT_PP_TRAITS_ADT_HPP_
|
||||
#define BOOST_CONTRACT_EXT_PP_TRAITS_ADT_HPP_
|
||||
|
||||
#include <boost/contract/ext_/preprocessor/utility/nil.hpp>
|
||||
#include <boost/preprocessor/seq/elem.hpp>
|
||||
#include <boost/preprocessor/seq/replace.hpp>
|
||||
|
||||
// These macros Abstract the Data Type (ADT) used to implement the traits
|
||||
// (pp-sequence, pp-array, pp-list, etc.) and signature (pp-tuple, etc.).
|
||||
// NOTE: These macros are typically not used by users. They are provided here
|
||||
// in case users want to implement their own signature parsers using the
|
||||
// ..._PARSE macros directly (instead of using the already provided macros).
|
||||
|
||||
/* PRIVATE */
|
||||
|
||||
#define BOOST_CONTRACT_EXT_PP_SIGN_TRAITS_FIRST_(sign, traits) sign
|
||||
|
||||
#define BOOST_CONTRACT_EXT_PP_SIGN_TRAITS_SECOND_(sign, traits) traits
|
||||
|
||||
/* PUBLIC */
|
||||
|
||||
// Traits (sequence).
|
||||
|
||||
// Usage: ..._ELEM(index, traits)
|
||||
#define BOOST_CONTRACT_EXT_PP_TRAITS_ELEM BOOST_PP_SEQ_ELEM
|
||||
|
||||
#define BOOST_CONTRACT_EXT_PP_TRAITS_PUSH_BACK(traits, trait) traits (trait)
|
||||
|
||||
// Usage: ..._REPLACE(traits, index, trait)
|
||||
#define BOOST_CONTRACT_EXT_PP_TRAITS_REPLACE BOOST_PP_SEQ_REPLACE
|
||||
|
||||
// Signature-Traits (2-tuple).
|
||||
|
||||
// Create a `sign_traits` data structure to start parsing specified signature.
|
||||
// Implementation: Leading NIL is used to handle empty macro params (on MSVC).
|
||||
#define BOOST_CONTRACT_EXT_PP_SIGN_TRAITS_INIT(sign) \
|
||||
( sign, BOOST_PP_NIL )
|
||||
|
||||
// Expand to final traits after they have been parsed from signature.
|
||||
// Implementation: Also removes leading NIL.
|
||||
#define BOOST_CONTRACT_EXT_PP_SIGN_TRAITS_DONE(sign_traits) \
|
||||
BOOST_CONTRACT_EXT_PP_NIL_REMOVE_FRONT( \
|
||||
BOOST_CONTRACT_EXT_PP_SIGN_TRAITS_SECOND(sign_traits))
|
||||
|
||||
// NOTE: Using `BOOST_PP_TUPLE_ELEM(2, 0, sign_traits)` confuses MSVC here.
|
||||
#define BOOST_CONTRACT_EXT_PP_SIGN_TRAITS_FIRST(sign_traits) \
|
||||
BOOST_CONTRACT_EXT_PP_SIGN_TRAITS_FIRST_ sign_traits
|
||||
|
||||
// NOTE: Using `BOOST_PP_TUPLE_ELEM(2, 1, sign_traits)` confuses MSVC here.
|
||||
#define BOOST_CONTRACT_EXT_PP_SIGN_TRAITS_SECOND(sign_traits) \
|
||||
BOOST_CONTRACT_EXT_PP_SIGN_TRAITS_SECOND_ sign_traits
|
||||
|
||||
#endif // #include guard
|
||||
|
||||
@@ -13,9 +13,9 @@
|
||||
#include <boost/contract/ext_/preprocessor/traits/func/verbatim.hpp>
|
||||
#include <boost/contract/ext_/preprocessor/traits/func/access.hpp>
|
||||
#include <boost/contract/ext_/preprocessor/traits/func/aux_/index.hpp>
|
||||
#include <boost/contract/ext_/preprocessor/traits/parse.hpp>
|
||||
#include <boost/contract/ext_/preprocessor/traits/adt.hpp>
|
||||
|
||||
// PRIVATE //
|
||||
/* PRIVATE */
|
||||
|
||||
// You can set this internal macro to stop and debug at a func-trait index.
|
||||
// define BOOST_CONTRACT_EXT_PP_FUNC_TRAITS_AUX_INDEX_TEST
|
||||
@@ -67,10 +67,10 @@
|
||||
sign_traits
|
||||
#else
|
||||
# define BOOST_CONTRACT_EXT_PP_FUNC_TRAITS_DONE_ \
|
||||
BOOST_CONTRACT_EXT_PP_TRAITS_PARSE_DONE
|
||||
BOOST_CONTRACT_EXT_PP_SIGN_TRAITS_DONE
|
||||
#endif
|
||||
|
||||
// PUBLIC //
|
||||
/* PUBLIC */
|
||||
|
||||
// Expand specified function signature into its traits. Function traits are
|
||||
// are inspected using the FUNC_TRAITS macros.
|
||||
@@ -81,7 +81,7 @@
|
||||
BOOST_CONTRACT_EXT_PP_FUNC_TRAITS_EXPORT_( \
|
||||
BOOST_CONTRACT_EXT_PP_FUNC_TRAITS_VERBATIM_( \
|
||||
BOOST_CONTRACT_EXT_PP_FUNC_TRAITS_ACCESS_( \
|
||||
BOOST_CONTRACT_EXT_PP_TRAITS_PARSE_INIT( \
|
||||
BOOST_CONTRACT_EXT_PP_SIGN_TRAITS_INIT( \
|
||||
sign \
|
||||
)))))) \
|
||||
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
|
||||
#ifndef BOOST_CONTRACT_EXPT_PP_TRAITS_PARSE_HPP_
|
||||
#define BOOST_CONTRACT_EXPT_PP_TRAITS_PARSE_HPP_
|
||||
|
||||
#include <boost/preprocessor/facilities/empty.hpp>
|
||||
#include <boost/preprocessor/tuple/elem.hpp>
|
||||
|
||||
// This API is typically not used by users. It is provided here in case users
|
||||
// want to implement their own signature parsing using the ..._PARSE macros
|
||||
// directly, instead of using the already provided function and class parsing.
|
||||
|
||||
// PUBLIC //
|
||||
|
||||
// Initialize a parsing data structure `sign_traits` from specified signature.
|
||||
#define BOOST_CONTRACT_EXT_PP_TRAITS_PARSE_INIT(sign) \
|
||||
( sign, BOOST_PP_EMPTY() )
|
||||
|
||||
// Expand to signature tokens remaining to be parsed.
|
||||
#define BOOST_CONTRACT_EXT_PP_TRAITS_PARSE_REST(sign_traits) \
|
||||
BOOST_PP_TUPLE_ELEM(2, 0, sign_traits)
|
||||
|
||||
// Expand to traits parsed so far from signature.
|
||||
#define BOOST_CONTRACT_EXT_PP_TRAITS_PARSE_DONE(sign_traits) \
|
||||
BOOST_PP_TUPLE_ELEM(2, 1, sign_traits)
|
||||
|
||||
#endif // #include guard
|
||||
|
||||
Reference in New Issue
Block a user