From 8cdca116200fc8ef58541c13a6496cf9fc5d907e Mon Sep 17 00:00:00 2001 From: Krzysztof Chruscinski Date: Wed, 23 Jan 2019 13:29:43 +0100 Subject: [PATCH] logging: Replace custom macros with generic ones from util.h Some of macros initially created in the logger has been moved to util.h. This commit replaces custom macros with the one from util.h Signed-off-by: Krzysztof Chruscinski --- include/logging/log.h | 14 ++++++------ include/logging/log_core.h | 46 +++++--------------------------------- include/misc/util.h | 14 ++++++------ 3 files changed, 20 insertions(+), 54 deletions(-) diff --git a/include/logging/log.h b/include/logging/log.h index 657da82f284..1ffd9ac4c3c 100644 --- a/include/logging/log.h +++ b/include/logging/log.h @@ -285,8 +285,8 @@ char *log_strdup(const char *str); #else #define _LOG_LEVEL_RESOLVE(...) \ _LOG_EVAL(LOG_LEVEL, \ - (__LOG_ARG_2(__VA_ARGS__, LOG_LEVEL)), \ - (__LOG_ARG_2(__VA_ARGS__, CONFIG_LOG_DEFAULT_LEVEL))) + (GET_ARG2(__VA_ARGS__, LOG_LEVEL)), \ + (GET_ARG2(__VA_ARGS__, CONFIG_LOG_DEFAULT_LEVEL))) #endif /* Return first argument */ @@ -355,7 +355,7 @@ char *log_strdup(const char *str); #define LOG_MODULE_REGISTER(...) \ _LOG_EVAL( \ _LOG_LEVEL_RESOLVE(__VA_ARGS__), \ - (_LOG_MODULE_DATA_CREATE(_LOG_ARG1(__VA_ARGS__), \ + (_LOG_MODULE_DATA_CREATE(GET_ARG1(__VA_ARGS__), \ _LOG_LEVEL_RESOLVE(__VA_ARGS__))),\ ()/*Empty*/ \ ) \ @@ -389,20 +389,20 @@ char *log_strdup(const char *str); */ #define LOG_MODULE_DECLARE(...) \ extern const struct log_source_const_data \ - LOG_ITEM_CONST_DATA(_LOG_ARG1(__VA_ARGS__)); \ + LOG_ITEM_CONST_DATA(GET_ARG1(__VA_ARGS__)); \ extern struct log_source_dynamic_data \ - LOG_ITEM_DYNAMIC_DATA(_LOG_ARG1(__VA_ARGS__)); \ + LOG_ITEM_DYNAMIC_DATA(GET_ARG1(__VA_ARGS__)); \ \ static const struct log_source_const_data * \ __log_current_const_data __attribute__((unused)) = \ _LOG_LEVEL_RESOLVE(__VA_ARGS__) ? \ - &LOG_ITEM_CONST_DATA(_LOG_ARG1(__VA_ARGS__)) : NULL; \ + &LOG_ITEM_CONST_DATA(GET_ARG1(__VA_ARGS__)) : NULL; \ \ static struct log_source_dynamic_data * \ __log_current_dynamic_data __attribute__((unused)) = \ (_LOG_LEVEL_RESOLVE(__VA_ARGS__) && \ IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING)) ? \ - &LOG_ITEM_DYNAMIC_DATA(_LOG_ARG1(__VA_ARGS__)) : NULL;\ + &LOG_ITEM_DYNAMIC_DATA(GET_ARG1(__VA_ARGS__)) : NULL; \ \ static const u32_t __log_level __attribute__((unused)) = \ _LOG_LEVEL_RESOLVE(__VA_ARGS__) diff --git a/include/logging/log_core.h b/include/logging/log_core.h index d78b91f0206..2252781e732 100644 --- a/include/logging/log_core.h +++ b/include/logging/log_core.h @@ -39,7 +39,7 @@ extern "C" { _LOG_RESOLVED_LEVEL1(_level, _default) #define _LOG_RESOLVED_LEVEL1(_level, _default) \ - __LOG_RESOLVED_LEVEL2(_LOG_XXXX##_level, _level, _default) + __COND_CODE(_LOG_XXXX##_level, (_level), (_default)) #define _LOG_XXXX0 _LOG_YYYY, #define _LOG_XXXX1 _LOG_YYYY, @@ -47,17 +47,6 @@ extern "C" { #define _LOG_XXXX3 _LOG_YYYY, #define _LOG_XXXX4 _LOG_YYYY, -#define __LOG_RESOLVED_LEVEL2(one_or_two_args, _level, _default) \ - __LOG_ARG_2(one_or_two_args _level, _default) - -#define LOG_DEBRACKET(...) __VA_ARGS__ - -#define __LOG_ARG_1(val, ...) val -#define __LOG_ARG_2(ignore_this, val, ...) val -#define __LOG_ARGS_LESS1(val, ...) __VA_ARGS__ - -#define __LOG_ARG_2_DEBRACKET(ignore_this, val, ...) LOG_DEBRACKET val - /** * @brief Macro for conditional code generation if provided log level allows. * @@ -76,36 +65,13 @@ extern "C" { _LOG_EVAL1(_eval_level, _iftrue, _iffalse) #define _LOG_EVAL1(_eval_level, _iftrue, _iffalse) \ - _LOG_EVAL2(_LOG_ZZZZ##_eval_level, _iftrue, _iffalse) + __COND_CODE(_LOG_ZZZZ##_eval_level, _iftrue, _iffalse) #define _LOG_ZZZZ1 _LOG_YYYY, #define _LOG_ZZZZ2 _LOG_YYYY, #define _LOG_ZZZZ3 _LOG_YYYY, #define _LOG_ZZZZ4 _LOG_YYYY, -#define _LOG_EVAL2(one_or_two_args, _iftrue, _iffalse) \ - __LOG_ARG_2_DEBRACKET(one_or_two_args _iftrue, _iffalse) - -/** - * @brief Macro for condition code generation. - * - * @param _eval Parameter evaluated against 0 - * @param _ifzero Code included if _eval is 0. Must be wrapped in brackets. - * @param _ifnzero Code included if _eval is not 0. - * Must be wrapped in brackets. - */ - -#define _LOG_Z_EVAL(_eval, _ifzero, _ifnzero) \ - _LOG_Z_EVAL1(_eval, _ifzero, _ifnzero) - -#define _LOG_Z_EVAL1(_eval, _ifzero, _ifnzero) \ - _LOG_Z_EVAL2(_LOG_Z_ZZZZ##_eval, _ifzero, _ifnzero) - -#define _LOG_Z_ZZZZ0 _LOG_Z_YYYY, - -#define _LOG_Z_EVAL2(one_or_two_args, _ifzero, _ifnzero) \ - __LOG_ARG_2_DEBRACKET(one_or_two_args _ifzero, _ifnzero) - /** @brief Macro for getting log level for given module. * * It is evaluated to LOG_LEVEL if defined. Otherwise CONFIG_LOG_DEFAULT_LEVEL @@ -156,7 +122,7 @@ extern "C" { /** * @brief Macro for optional injection of function name as first argument of - * formatted string. _LOG_Z_EVAL() macro is used to handle no arguments + * formatted string. COND_CODE_0() macro is used to handle no arguments * case. * * The purpose of this macro is to prefix string literal with format @@ -165,10 +131,10 @@ extern "C" { * used. */ -#define _LOG_STR(...) "%s: " __LOG_ARG_1(__VA_ARGS__), __func__\ - _LOG_Z_EVAL(NUM_VA_ARGS_LESS_1(__VA_ARGS__),\ +#define _LOG_STR(...) "%s: " GET_ARG1(__VA_ARGS__), __func__\ + COND_CODE_0(NUM_VA_ARGS_LESS_1(__VA_ARGS__),\ (),\ - (, __LOG_ARGS_LESS1(__VA_ARGS__))\ + (, GET_ARGS_LESS_1(__VA_ARGS__))\ ) diff --git a/include/misc/util.h b/include/misc/util.h index 4236a8f4400..405e09bb76e 100644 --- a/include/misc/util.h +++ b/include/misc/util.h @@ -205,20 +205,20 @@ static inline s64_t arithmetic_shift_right(s64_t value, u8_t shift) * * This is based on same idea as @ref IS_ENABLED macro but as the result of * flag evaluation provided code is injected. Because preprocessor interprets - * each comma as argument boundary, code must be provided in the brackets. + * each comma as an argument boundary, code must be provided in the brackets. * Brackets are stripped away during macro processing. * * Usage example: * - * #define MACRO(x) COND_CODE_1(CONFIG_FLAG, (u32_t x;), ()) + * \#define MACRO(x) COND_CODE_1(CONFIG_FLAG, (u32_t x;), ()) * * It can be considered as alternative to: * - * #if defined(CONFIG_FLAG) && (CONFIG_FLAG == 1) - * #define MACRO(x) u32_t x; - * #else - * #define MACRO(x) - * #endif + * \#if defined(CONFIG_FLAG) && (CONFIG_FLAG == 1) + * \#define MACRO(x) u32_t x; + * \#else + * \#define MACRO(x) + * \#endif * * However, the advantage of that approach is that code is resolved in place * where it is used while \#if method resolves given macro when header is