mirror of
https://github.com/boostorg/contract.git
synced 2026-02-27 17:02:15 +00:00
added trailing EMPTY to aux_/type.hpp PARSE macros
This commit is contained in:
@@ -114,7 +114,7 @@ def code():
|
||||
#define BOOST_CONTRACT_EXT_PP_ASSERTION_TRAITS_BOOL_PARSE_{0}_(d, l, decl) \\
|
||||
BOOST_CONTRACT_EXT_PP_BOOL_ASSERTION_TRAITS_PARSE(decl)
|
||||
|
||||
// This more complex because it has to eventually use IS_RETURN_BACK which does
|
||||
// This is needed because it has to eventually use IS_RETURN_BACK which does
|
||||
// not allow decl to end with parenthesis `... (...)` (so type is first parsed
|
||||
// to make sure this is a valid return assertion with a type (possibly auto),
|
||||
// a not-nil assignment, etc.). Only after that, IS_RETURN_BACK is safely used.
|
||||
@@ -133,8 +133,8 @@ def code():
|
||||
BOOST_PP_TUPLE_ELEM(2, 1, decl_type)), \\
|
||||
0 \\
|
||||
, \\
|
||||
BOOST_PP_EXPAND(BOOST_CONTRACT_EXT_PP_IS_EMPTY \\
|
||||
BOOST_PP_TUPLE_ELEM(2, 1, decl_type)) \\
|
||||
BOOST_CONTRACT_EXT_PP_IS_EMPTY( \\
|
||||
BOOST_PP_TUPLE_ELEM(2, 1, decl_type)()) \\
|
||||
) \\
|
||||
) , \\
|
||||
BOOST_CONTRACT_EXT_PP_ASSERTION_TRAITS_BOOL_PARSE_{0}_ \\
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -9,10 +9,12 @@
|
||||
|
||||
/* PUBLIC */
|
||||
|
||||
// Expand to `auto | (type,,,)`.
|
||||
// Expand to `auto | (type,,,)` (this should never be empty).
|
||||
#define BOOST_CONTRACT_EXT_PP_OLDOF_ASSERTION_TRAITS_TYPE(traits) \
|
||||
BOOST_CONTRACT_EXT_PP_TRAITS_AUX_ELEM( \
|
||||
BOOST_CONTRACT_EXT_PP_TRAITS_AUX_INDEX_OLDOF_ASSERTION_TYPE, traits)
|
||||
BOOST_CONTRACT_EXT_PP_TRAITS_AUX_INDEX_OLDOF_ASSERTION_TYPE, \
|
||||
traits \
|
||||
)()
|
||||
|
||||
// Precondition: decl = `{auto | wrapped-type} ...`.
|
||||
#define BOOST_CONTRACT_EXT_PP_OLDOF_ASSERTION_TRAITS_TYPE_PARSE_D(d, \
|
||||
|
||||
@@ -9,12 +9,12 @@
|
||||
|
||||
/* PUBLIC */
|
||||
|
||||
// Expand to `auto | (type,,,)`.
|
||||
// Expand to `auto | (type,,,)` (this should never be empty).
|
||||
#define BOOST_CONTRACT_EXT_PP_RETURN_ASSERTION_TRAITS_TYPE(traits) \
|
||||
BOOST_CONTRACT_EXT_PP_TRAITS_AUX_ELEM( \
|
||||
BOOST_CONTRACT_EXT_PP_TRAITS_AUX_INDEX_RETURN_ASSERTION_TYPE, \
|
||||
traits \
|
||||
)
|
||||
)()
|
||||
|
||||
// Precondition: decl = `{auto | wrapped-type} ...`.
|
||||
#define BOOST_CONTRACT_EXT_PP_RETURN_ASSERTION_TRAITS_TYPE_PARSE_D(d, \
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
BOOST_CONTRACT_EXT_PP_TRAITS_AUX_TYPE_PARSE_D(d, \
|
||||
BOOST_CONTRACT_EXT_PP_KEYWORD_TYPEDEF_REMOVE_FRONT( \
|
||||
BOOST_PP_TUPLE_ELEM(2, 0, decl_traits)) \
|
||||
), \
|
||||
)(), \
|
||||
BOOST_PP_TUPLE_ELEM(2, 1, decl_traits) \
|
||||
)
|
||||
|
||||
|
||||
@@ -33,16 +33,24 @@
|
||||
/* PUBLIC */
|
||||
|
||||
// Expand decl = `[type | (type)] ...` (type can also be `void`) to
|
||||
// `(..., (type) | ())`.
|
||||
// For example, `int const ...` to `(..., (int const))`.
|
||||
// `(..., [(type)] EMPTY)`.
|
||||
// For example, expand:
|
||||
// decl = `int const ...` to `(..., (int const) EMPTY)`.
|
||||
// decl = `(map<T, U>) ...` to `(..., (map<T, U>) EMPTY)`.
|
||||
// decl = `auto ...` to `(..., (auto) EMPTY)`.
|
||||
// decl = `f ...` to `(f ..., EMPTY)`.
|
||||
// Precondition: `...` in decl cannot be EMPTY() (so expanded 2-tuple is valid).
|
||||
#define BOOST_CONTRACT_EXT_PP_TRAITS_AUX_TYPE_PARSE_D(d, decl) \
|
||||
BOOST_CONTRACT_EXT_PP_TRAITS_AUX_TYPE_D_(d, decl, \
|
||||
BOOST_CONTRACT_EXT_PP_TRAITS_AUX_TYPE_SPACED_PUSH_BACK_)
|
||||
|
||||
// Expand decl = `[auto | type | (type)] ...` (type can also be `void`) to
|
||||
// `(..., auto | (type) | ())` (note that auto is not wrapped in parenthesis).
|
||||
// For example, `auto ...` to `(..., auto)`.
|
||||
// `(..., [auto | (type)] EMPTY)` (note that auto not wrapped in parenthesis).
|
||||
// For example, expand:
|
||||
// decl = `int const ...` to `(..., (int const) EMPTY)`.
|
||||
// decl = `(map<T, U>) ...` to `(..., (map<T, U>) EMPTY)`.
|
||||
// decl = `auto ...` to `(..., auto EMPTY)`.
|
||||
// decl = `f ...` to `(f ..., EMPTY)`.
|
||||
// Precondition: `...` in decl cannot be EMPTY() (so expanded 2-tuple is valid).
|
||||
// NOTE: So far, there is no need of a SEQ version of this macro.
|
||||
#define BOOST_CONTRACT_EXT_PP_TRAITS_AUX_AUTO_TYPE_PARSE_D(d, decl) \
|
||||
@@ -54,9 +62,13 @@
|
||||
)(d, decl)
|
||||
|
||||
// Expand decl = `[type | (type)] ...` (type can also be `void`) to
|
||||
// `(..., ((keyword1))...((keyword-n)) | (()))`.
|
||||
// For example, `int const ...` to `(..., ((int)) ((const)))` (useful to access
|
||||
// `(..., [((keyword1))...((keyword-n))] EMTPY)` (this is useful to access
|
||||
// single type keywords `int`, `const`, etc.).
|
||||
// For example, expand:
|
||||
// decl = `int const ...` to `(..., ((int)) ((const)) EMPTY)`.
|
||||
// decl = `(map<T, U>) ...` to `(..., ((map<T, U>)) EMPTY)`.
|
||||
// decl = `auto ...` to `(..., ((auto)) EMPTY)`.
|
||||
// decl = `f ...` to `(f ..., EMPTY)`.
|
||||
// Precondition: `...` in decl cannot be EMPTY() (so expanded 2-tuple is valid).
|
||||
#define BOOST_CONTRACT_EXT_PP_TRAITS_AUX_TYPE_SEQ_PARSE_D(d, decl) \
|
||||
BOOST_CONTRACT_EXT_PP_TRAITS_AUX_TYPE_SEQ_RETURN_( \
|
||||
@@ -75,7 +87,7 @@
|
||||
|
||||
// Precondition: decl = `auto ...`.
|
||||
#define BOOST_CONTRACT_EXT_PP_TRAITS_AUX_AUTO_TYPE_(unused, decl) \
|
||||
(BOOST_CONTRACT_EXT_PP_KEYWORD_AUTO_REMOVE_FRONT(decl), auto)
|
||||
(BOOST_CONTRACT_EXT_PP_KEYWORD_AUTO_REMOVE_FRONT(decl), auto BOOST_PP_EMPTY)
|
||||
|
||||
// Extra level of indirection needed for proper macro expansion (on MSVC).
|
||||
#define BOOST_CONTRACT_EXT_PP_TRAITS_AUX_TYPE_SEQ_RETURN_(decl_type) \
|
||||
@@ -84,15 +96,14 @@
|
||||
|
||||
// Remove an extra set of parenthesis around sequence (originally added to
|
||||
// handle commas by algorithms in common with spaced type traits).
|
||||
// Implementation: Always return `(())` (double paren seq with 1 empty elem) in
|
||||
// case no type was parsed.
|
||||
#define BOOST_CONTRACT_EXT_PP_TRAITS_AUX_TYPE_SEQ_RETURN_ARGS_(decl, type) \
|
||||
( \
|
||||
decl, \
|
||||
BOOST_PP_EXPR_IIF(BOOST_CONTRACT_EXT_PP_IS_EMPTY type, \
|
||||
(()) \
|
||||
BOOST_PP_EXPR_IIF(BOOST_PP_COMPL(BOOST_CONTRACT_EXT_PP_IS_EMPTY( \
|
||||
type())), \
|
||||
BOOST_PP_TUPLE_REM(1) \
|
||||
) \
|
||||
BOOST_PP_TUPLE_REM_CTOR(1, type) \
|
||||
type \
|
||||
)
|
||||
|
||||
#define BOOST_CONTRACT_EXT_PP_TRAITS_AUX_TYPE_D_(d, decl, push_back_macro) \
|
||||
@@ -109,6 +120,7 @@
|
||||
BOOST_PP_TUPLE_EAT(0) decl, \
|
||||
push_back_macro(BOOST_PP_EMPTY(), \
|
||||
BOOST_CONTRACT_EXT_PP_PAREN_FRONT(decl)) \
|
||||
BOOST_PP_EMPTY \
|
||||
)
|
||||
|
||||
// Precondition: decl does not start with paren (it's formed by keywords).
|
||||
@@ -127,8 +139,16 @@
|
||||
continue_decl_type_push) \
|
||||
( \
|
||||
BOOST_PP_TUPLE_ELEM(4, 1, continue_decl_type_push), \
|
||||
( BOOST_CONTRACT_EXT_PP_NIL_REMOVE_FRONT( \
|
||||
BOOST_PP_TUPLE_ELEM(4, 2, continue_decl_type_push)) ) \
|
||||
BOOST_CONTRACT_EXT_PP_TRAITS_AUX_TYPE_KEYWORD_PARENTHESIZE_( \
|
||||
BOOST_CONTRACT_EXT_PP_NIL_REMOVE_FRONT( \
|
||||
BOOST_PP_TUPLE_ELEM(4, 2, continue_decl_type_push)) \
|
||||
) \
|
||||
BOOST_PP_EMPTY \
|
||||
)
|
||||
|
||||
#define BOOST_CONTRACT_EXT_PP_TRAITS_AUX_TYPE_KEYWORD_PARENTHESIZE_(tokens) \
|
||||
BOOST_PP_EXPR_IIF(BOOST_PP_COMPL(BOOST_CONTRACT_EXT_PP_IS_EMPTY(tokens)), \
|
||||
(tokens) \
|
||||
)
|
||||
|
||||
#define BOOST_CONTRACT_EXT_PP_TRAITS_AUX_TYPE_KEYWORD_PRED_( \
|
||||
@@ -238,7 +258,5 @@
|
||||
push_back_macro \
|
||||
)
|
||||
|
||||
// TODO: Consider returning EMPTY in case no type is parsed...
|
||||
|
||||
#endif // #include guard
|
||||
|
||||
|
||||
@@ -18,36 +18,13 @@
|
||||
|
||||
|
||||
// Precondition: decl = `[wrapped-type] ...`.
|
||||
// Implementation: Trailing EMPTY already added by AUX_TYPE_PARSE.
|
||||
#define BOOST_CONTRACT_EXT_PP_CAPTURE_TRAITS_TYPE_PARSE_D(d, decl_traits) \
|
||||
BOOST_CONTRACT_EXT_PP_CAPTURE_TRAITS_TYPE_( \
|
||||
BOOST_CONTRACT_EXT_PP_DECL_TRAITS_AUX_PUSH_BACK( \
|
||||
BOOST_CONTRACT_EXT_PP_TRAITS_AUX_TYPE_PARSE_D(d, \
|
||||
BOOST_PP_TUPLE_ELEM(2, 0, decl_traits)), \
|
||||
BOOST_PP_TUPLE_ELEM(2, 1, decl_traits) \
|
||||
)
|
||||
|
||||
/* PRIVATE */
|
||||
|
||||
// EXPAND needed for proper macro expansion (on MSVC).
|
||||
#define BOOST_CONTRACT_EXT_PP_CAPTURE_TRAITS_TYPE_(decl_type, traits) \
|
||||
BOOST_PP_IIF(BOOST_PP_EXPAND(BOOST_CONTRACT_EXT_PP_IS_EMPTY \
|
||||
BOOST_PP_TUPLE_ELEM(2, 1, decl_type)), \
|
||||
BOOST_CONTRACT_EXT_PP_CAPTURE_TRAITS_TYPE_NO_ \
|
||||
, \
|
||||
BOOST_CONTRACT_EXT_PP_CAPTURE_TRAITS_TYPE_YES_ \
|
||||
)(decl_type, traits)
|
||||
|
||||
#define BOOST_CONTRACT_EXT_PP_CAPTURE_TRAITS_TYPE_YES_(decl_type, traits) \
|
||||
( \
|
||||
BOOST_PP_TUPLE_ELEM(2, 0, decl_type), \
|
||||
BOOST_CONTRACT_EXT_PP_TRAITS_AUX_PUSH_BACK(traits, \
|
||||
BOOST_PP_TUPLE_ELEM(2, 1, decl_type) BOOST_PP_EMPTY) \
|
||||
)
|
||||
|
||||
#define BOOST_CONTRACT_EXT_PP_CAPTURE_TRAITS_TYPE_NO_(decl_type, traits) \
|
||||
( \
|
||||
BOOST_PP_TUPLE_ELEM(2, 0, decl_type), \
|
||||
BOOST_CONTRACT_EXT_PP_TRAITS_AUX_PUSH_BACK(traits, BOOST_PP_EMPTY) \
|
||||
)
|
||||
|
||||
#endif // #include guard
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@
|
||||
BOOST_PP_SEQ_FOR_EACH( \
|
||||
BOOST_CONTRACT_EXT_PP_FUNC_TRAITS_NAME_OPERATOR_TYPE_REM_,\
|
||||
1, \
|
||||
BOOST_PP_TUPLE_ELEM(2, 1, decl_type) \
|
||||
BOOST_PP_TUPLE_ELEM(2, 1, decl_type)() \
|
||||
) \
|
||||
) \
|
||||
( \
|
||||
@@ -88,7 +88,7 @@
|
||||
BOOST_PP_SEQ_FOR_EACH( \
|
||||
BOOST_CONTRACT_EXT_PP_FUNC_TRAITS_NAME_OPERATOR_TYPE_REM_, \
|
||||
0, \
|
||||
BOOST_PP_TUPLE_ELEM(2, 1, decl_type) \
|
||||
BOOST_PP_TUPLE_ELEM(2, 1, decl_type)() \
|
||||
) \
|
||||
) \
|
||||
) \
|
||||
|
||||
@@ -51,11 +51,11 @@
|
||||
)(d, decl, traits)
|
||||
|
||||
// Precondition: decl = `return ...`.
|
||||
// Implementation: Trailing EMPTY already added by AUX_TYPE_PARSE.
|
||||
#define BOST_CONTRACT_EXT_PP_FUNC_TRAITS_TRAILING_RETURN_YES_(d, decl, traits) \
|
||||
BOOST_CONTRACT_EXT_PP_FUNC_TRAITS_RETURN_( \
|
||||
BOOST_CONTRACT_EXT_PP_DECL_TRAITS_AUX_PUSH_BACK( \
|
||||
BOOST_CONTRACT_EXT_PP_TRAITS_AUX_TYPE_PARSE_D(d, \
|
||||
BOOST_CONTRACT_EXT_PP_KEYWORD_RETURN_REMOVE_FRONT(decl) \
|
||||
), \
|
||||
BOOST_CONTRACT_EXT_PP_KEYWORD_RETURN_REMOVE_FRONT(decl)), \
|
||||
traits \
|
||||
)
|
||||
|
||||
@@ -67,24 +67,13 @@
|
||||
BOOST_CONTRACT_EXT_PP_FUNC_TRAITS_RETURN_NO_ \
|
||||
)(d, decl, traits)
|
||||
|
||||
// Implementation: Trailing EMPTY already added by AUX_AUTO_TYPE_PARSE.
|
||||
#define BOOST_CONTRACT_EXT_PP_FUNC_TRAITS_RETURN_YES_(d, decl, traits) \
|
||||
BOOST_CONTRACT_EXT_PP_FUNC_TRAITS_RETURN_( \
|
||||
BOOST_CONTRACT_EXT_PP_DECL_TRAITS_AUX_PUSH_BACK( \
|
||||
BOOST_CONTRACT_EXT_PP_TRAITS_AUX_AUTO_TYPE_PARSE_D(d, decl), traits)
|
||||
|
||||
#define BOOST_CONTRACT_EXT_PP_FUNC_TRAITS_RETURN_(decl_return, traits) \
|
||||
BOOST_CONTRACT_EXT_PP_DECL_TRAITS_AUX_PUSH_BACK( \
|
||||
( \
|
||||
BOOST_PP_TUPLE_ELEM(2, 0, decl_return), \
|
||||
BOOST_PP_TUPLE_ELEM(2, 1, decl_return) BOOST_PP_EMPTY \
|
||||
), \
|
||||
traits \
|
||||
)
|
||||
|
||||
#define BOOST_CONTRACT_EXT_PP_FUNC_TRAITS_RETURN_NO_(d, decl, traits) \
|
||||
( \
|
||||
decl, \
|
||||
BOOST_CONTRACT_EXT_PP_TRAITS_AUX_PUSH_BACK(traits, BOOST_PP_EMPTY) \
|
||||
)
|
||||
(decl, BOOST_CONTRACT_EXT_PP_TRAITS_AUX_PUSH_BACK(traits, BOOST_PP_EMPTY))
|
||||
|
||||
// Constructors, destructors, type conversion operators, etc. do no have a
|
||||
// return type so this checks first if this declaration is supposed to have
|
||||
|
||||
@@ -76,18 +76,18 @@
|
||||
BOOST_CONTRACT_EXT_PP_TRAITS_AUX_TYPE_PARSE_D(d, decl), traits)
|
||||
|
||||
#define BOOST_CONTRACT_EXT_PP_PARAM_TRAITS_TYPE_(decl_type, traits) \
|
||||
BOOST_PP_IIF(BOOST_PP_EXPAND(BOOST_CONTRACT_EXT_PP_IS_EMPTY \
|
||||
BOOST_PP_TUPLE_ELEM(2, 1, decl_type)), \
|
||||
BOOST_CONTRACT_EXT_PP_PARAM_TRAITS_TYPE_NOT_PARSED_ \
|
||||
BOOST_PP_IIF(BOOST_CONTRACT_EXT_PP_IS_EMPTY( \
|
||||
BOOST_PP_TUPLE_ELEM(2, 1, decl_type)()), \
|
||||
BOOST_CONTRACT_EXT_PP_PARAM_TRAITS_TYPE_NO_ \
|
||||
, \
|
||||
BOOST_CONTRACT_EXT_PP_DECL_TRAITS_AUX_PUSH_BACK \
|
||||
BOOST_CONTRACT_EXT_PP_PARAM_TRAITS_TYPE_YES_ \
|
||||
)(decl_type, traits)
|
||||
|
||||
// Precondition: Unable to parse type so assume decl = `type NIL` (i.e., the
|
||||
// non-keyword type was specified unwrapped). That is allowed only when no
|
||||
// parameter name is given so all tokens in decl are for the type and remaining
|
||||
// decl is set to NIL here (which will be parsed as no parameter name).
|
||||
#define BOOST_CONTRACT_EXT_PP_PARAM_TRAITS_TYPE_NOT_PARSED_(decl_type, traits) \
|
||||
#define BOOST_CONTRACT_EXT_PP_PARAM_TRAITS_TYPE_NO_(decl_type, traits) \
|
||||
( \
|
||||
BOOST_PP_NIL, \
|
||||
BOOST_CONTRACT_EXT_PP_TRAITS_AUX_PUSH_BACK( \
|
||||
@@ -97,6 +97,13 @@
|
||||
) \
|
||||
)
|
||||
|
||||
#define BOOST_CONTRACT_EXT_PP_PARAM_TRAITS_TYPE_YES_(decl_type, traits) \
|
||||
( \
|
||||
BOOST_PP_TUPLE_ELEM(2, 0, decl_type), \
|
||||
BOOST_CONTRACT_EXT_PP_TRAITS_AUX_PUSH_BACK(traits, \
|
||||
BOOST_PP_TUPLE_ELEM(2, 1, decl_type)()) \
|
||||
)
|
||||
|
||||
// Precondition: decl = `typename ...`.
|
||||
#define BOOST_CONTRACT_EXT_PP_TEMPLATE_PARAM_TRAITS_TYPE_TYPENAME_( \
|
||||
d, decl, traits) \
|
||||
|
||||
Reference in New Issue
Block a user