From 068d0239172386e5e95c91384d9802ff62f6d1e1 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Sat, 28 Mar 2020 11:36:51 +0100 Subject: [PATCH] Factorize in m-core.h the pattern recognication. --- m-algo.h | 15 +++------------ m-core.h | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/m-algo.h b/m-algo.h index 97622e50..4497b95a 100644 --- a/m-algo.h +++ b/m-algo.h @@ -866,15 +866,6 @@ } while (0) -/* The different special patterns which will interpret as special */ -#define ALGOI_PATTERN_and_and , -#define ALGOI_PATTERN_or_or , -#define ALGOI_PATTERN_sum_sum , -#define ALGOI_PATTERN_sum_add , -/* Test function for theses patterns */ -#define ALGOI_REDUCE_IS_FUNC(refFunc, reduceFunc) \ - M_COMMA_P(M_C4(ALGOI_PATTERN_, refFunc, _, reduceFunc)) - /* The special function handler */ #define ALGOI_REDUCE_AND(a,b) ((a) &= (b)) #define ALGOI_REDUCE_OR(a,b) ((a) |= (b)) @@ -884,11 +875,11 @@ It returns the special function handler if function is and, or, sum or add. Otherwise it returns the original function */ #define ALGOI_REDUCE_FUNC(reduceFunc) \ - M_IF(ALGOI_REDUCE_IS_FUNC(and, reduceFunc)) \ + M_IF(M_KEYWORD_P(and, reduceFunc)) \ (ALGOI_REDUCE_AND, \ - M_IF(ALGOI_REDUCE_IS_FUNC(or, reduceFunc)) \ + M_IF(M_KEYWORD_P(or, reduceFunc)) \ (ALGOI_REDUCE_OR, \ - M_IF(ALGOI_REDUCE_IS_FUNC(sum, reduceFunc)) \ + M_IF(M_KEYWORD_P(sum, reduceFunc)) \ (ALGOI_REDUCE_SUM, reduceFunc) \ ) \ ) diff --git a/m-core.h b/m-core.h index 1887bdce..e3a4e3ad 100644 --- a/m-core.h +++ b/m-core.h @@ -802,6 +802,24 @@ extern void m_no_default_function(void) __attribute__((error("The requested op #define M_PARENTHESISI_DETECT(...) 0, 1, #define M_PARENTHESIS_P(...) M_AND(M_COMMA_P(M_PARENTHESISI_DETECT __VA_ARGS__), M_INV(M_COMMA_P(__VA_ARGS__))) + +/* Return 1 if argument type or variable or function is the keyword. + - refFunc is the reference keyword. + It shall be either 'and', 'or', 'sum' (equivalent to 'add'), 'bool' + - testedFunc is the tested keyword. + It cannot start with a special character */ +#define M_KEYWORD_P(refFunc, testedFunc) \ + M_COMMA_P(M_C4(M_PATTERN_, refFunc, _, testedFunc)) +/* The different special recognized patterns: */ +#define M_PATTERN_and_and , +#define M_PATTERN_or_or , +#define M_PATTERN_sum_sum , +#define M_PATTERN_sum_add , +#define M_PATTERN_add_add , +#define M_PATTERN_add_sum , +#define M_PATTERN_bool_bool , + + /* Necessary macros to handle recursivity, delaying the evaluation by one (or more) level of macro expansion. The argument is a macro-function which has to be deferred */