Change M_BY_NARGS semantics:
simplify suffix by __ # NARGS instead of __NARGS_ # NARGS Driver: reduce macro name length.
This commit is contained in:
1 parent
268192138a
commit
796f2619e5
3 files changed
+21
-19
No files matched your search
@@ -4438,22 +4438,23 @@ m_core_parse2_enum (const char str[], const char **endptr)
|
||||
M_BY_NARGS( M_IF(M_GET_PROPERTY(oplist, NOCLEAR))(M_CHAIN_OBJ_A, M_CHAIN_OBJ_B), __VA_ARGS__) \
|
||||
(name, oplist, __VA_ARGS__)
|
||||
// Need to define an exception handler. Use of M_CHAIN_INIT
|
||||
#define M_CHAIN_OBJ_B__NARGS_1(name, oplist, var) \
|
||||
#define M_CHAIN_OBJ_B__1(name, oplist, var) \
|
||||
M_CHAIN_INIT( name, M_CALL_INIT(oplist, var), M_CALL_CLEAR(oplist, var) )
|
||||
#define M_CHAIN_OBJ_B__NARGS_2(name, oplist, var, value) \
|
||||
M_IF(M_PARENTHESIS_P(value))(M_CHAIN_OBJ_B__NARGS_2_WITH, M_CHAIN_OBJ_B__NARGS_2_SET) \
|
||||
#define M_CHAIN_OBJ_B__2(name, oplist, var, value) \
|
||||
M_IF(M_PARENTHESIS_P(value))(M_CHAIN_OBJ_B__2_WITH, M_CHAIN_OBJ_B__2_SET) \
|
||||
(name, oplist, var, value)
|
||||
#define M_CHAIN_OBJ_B__NARGS_2_WITH(name, oplist, var, value) \
|
||||
#define M_CHAIN_OBJ_B__2_WITH(name, oplist, var, value) \
|
||||
M_CHAIN_INIT( name, M_CALL_INIT_WITH(oplist, var, value), M_CALL_CLEAR(oplist, var) )
|
||||
#define M_CHAIN_OBJ_B__NARGS_2_SET(name, oplist, var, value) \
|
||||
#define M_CHAIN_OBJ_B__2_SET(name, oplist, var, value) \
|
||||
M_CHAIN_INIT( name, M_CALL_INIT_SET(oplist, var, value), M_CALL_CLEAR(oplist, var) )
|
||||
// No need to define an exception handler. Just call the INIT function.
|
||||
#define M_CHAIN_OBJ_A__NARGS_1(name, oplist, var) \
|
||||
#define M_CHAIN_OBJ_A__1(name, oplist, var) \
|
||||
M_CHAIN_FOR(name, M_CALL_INIT(oplist, var) )
|
||||
#define M_CHAIN_OBJ_A__NARGS_2(name, oplist, var, value) \
|
||||
#define M_CHAIN_OBJ_A__2(name, oplist, var, value) \
|
||||
M_CHAIN_FOR(name, \
|
||||
M_IF(M_PARENTHESIS_P(value))(M_CALL_INIT_WITH, M_CALL_INIT_SET) \
|
||||
(oplist, var, value) )
|
||||
|
||||
// Execute the 'init' function in a for loop construct
|
||||
#define M_CHAIN_FOR(name, init ) \
|
||||
M_CHAIN_FOR_B(M_C(m_var_, name), init)
|
||||
@@ -4513,17 +4514,18 @@ m_core_parse2_enum (const char str[], const char **endptr)
|
||||
/******************* INIT_WITH Enhancing ********************/
|
||||
/************************************************************/
|
||||
|
||||
/* Add as suffix for the given function the number of arguments of the calls.
|
||||
/* Add as suffix for the given function the number of arguments of the calls
|
||||
equal to __ # NARGS(...)
|
||||
Can be used to call different function in function of the number of arguments.
|
||||
It doesn't call the function with the argument in order to be able to chain the
|
||||
macro */
|
||||
#define M_BY_NARGS(function, ...) M_C3(function, __NARGS_, M_NARGS(__VA_ARGS__))
|
||||
#define M_BY_NARGS(function, ...) M_C3(function, __, M_NARGS(__VA_ARGS__))
|
||||
|
||||
/* Call different INIT_WITH method in function of the number of arguments of the call,
|
||||
* to be used in an OPLIST.
|
||||
/* Call different methods in function of the number of arguments of the call,
|
||||
* to be used in an OPLIST for the INIT_WITH operator.
|
||||
* Shall be used with API_1 call (example INIT_WITH(API_1(M_INIT_WITH_NVAR)) )
|
||||
* Shall define a NAME base method
|
||||
* All INIT_WITH methods shall be named as name ## _init_with_ ## NARGS
|
||||
* All INIT_WITH methods shall be named as name ## _init_with__ ## NARGS
|
||||
*/
|
||||
#define M_INIT_WITH_NVAR(oplist, ...) \
|
||||
M_BY_NARGS(M_C(M_GET_NAME oplist, _init_with), __VA_ARGS__)(__VA_ARGS__)
|
||||
|
||||
+5
-5
@@ -188,11 +188,11 @@ typedef struct m_worker_sync_s {
|
||||
input is (fieldname, type) or (fieldname, type, oplist)
|
||||
Output shall be : M_OPEXTEND(M_GLOBAL_OPLIST_OR_DEF(type_or_oplist)(), TYPE(type)) / M_OPEXTEND(oplist, TYPE(type))
|
||||
*/
|
||||
#define M_WORK3R_SPAWN_EXTEND_P0(...) M_BY_NARGS(M_WORK3R_SPAWN_EXTEND_P0, M_ID __VA_ARGS__) __VA_ARGS__
|
||||
#define M_WORK3R_SPAWN_EXTEND_P0__NARGS_2(field, type) M_OPEXTEND(M_GLOBAL_OPLIST_OR_DEF(type)(), TYPE(type))
|
||||
#define M_WORK3R_SPAWN_EXTEND_P0__NARGS_3(field, type, oplist) M_IF_OPLIST(oplist)(M_WORK3R_SPAWN_EXTEND_P0__NARGS_3_OK, M_WORK3R_SPAWN_EXTEND_P0__NARGS_3_KO)(field, type, oplist)
|
||||
#define M_WORK3R_SPAWN_EXTEND_P0__NARGS_3_OK(field, type, oplist) M_OPEXTEND(oplist, TYPE(type))
|
||||
#define M_WORK3R_SPAWN_EXTEND_P0__NARGS_3_KO(field, type, oplist) \
|
||||
#define M_WORK3R_SPAWN_EXTEND_P0(...) M_BY_NARGS(M_WORK3R_SPAWN_EXTEND_P0, M_ID __VA_ARGS__) __VA_ARGS__
|
||||
#define M_WORK3R_SPAWN_EXTEND_P0__2(field, type) M_OPEXTEND(M_GLOBAL_OPLIST_OR_DEF(type)(), TYPE(type))
|
||||
#define M_WORK3R_SPAWN_EXTEND_P0__3(field, type, oplist) M_IF_OPLIST(oplist)(M_WORK3R_SPAWN_EXTEND_P0__3_OK, M_WORK3R_SPAWN_EXTEND_P0__3_KO)(field, type, oplist)
|
||||
#define M_WORK3R_SPAWN_EXTEND_P0__3_OK(field, type, oplist) M_OPEXTEND(oplist, TYPE(type))
|
||||
#define M_WORK3R_SPAWN_EXTEND_P0__3_KO(field, type, oplist) \
|
||||
M_STATIC_FAILURE(M_LIB_NOT_AN_OPLIST, "(M_WORKER_SPAWN_EXTEND): the argument is not a valid oplist: " M_MAP(M_AS_STR, oplist))
|
||||
|
||||
/* Deferred evaluation for the definition,
|
||||
|
||||
+2
-2
@@ -570,8 +570,8 @@ static void test_oplist(void)
|
||||
assert (M_ID (M_GET_NAME A5));
|
||||
|
||||
#define A6 (NAME(A6), INIT_WITH(API_1(M_INIT_WITH_NVAR)))
|
||||
#define A6_init_with__NARGS_1(x) 1
|
||||
#define A6_init_with__NARGS_2(x, y) 0
|
||||
#define A6_init_with__1(x) 1
|
||||
#define A6_init_with__2(x, y) 0
|
||||
assert (M_ID(M_CALL_INIT_WITH (A6, 0)));
|
||||
assert (M_ID(!M_CALL_INIT_WITH (A6, 0, 0)));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user