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 <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
Krzysztof Chruscinski 2019-01-23 13:29:43 +01:00 committed by Anas Nashif
commit 8cdca11620
3 changed files with 20 additions and 54 deletions

View file

@ -285,8 +285,8 @@ char *log_strdup(const char *str);
#else #else
#define _LOG_LEVEL_RESOLVE(...) \ #define _LOG_LEVEL_RESOLVE(...) \
_LOG_EVAL(LOG_LEVEL, \ _LOG_EVAL(LOG_LEVEL, \
(__LOG_ARG_2(__VA_ARGS__, LOG_LEVEL)), \ (GET_ARG2(__VA_ARGS__, LOG_LEVEL)), \
(__LOG_ARG_2(__VA_ARGS__, CONFIG_LOG_DEFAULT_LEVEL))) (GET_ARG2(__VA_ARGS__, CONFIG_LOG_DEFAULT_LEVEL)))
#endif #endif
/* Return first argument */ /* Return first argument */
@ -355,7 +355,7 @@ char *log_strdup(const char *str);
#define LOG_MODULE_REGISTER(...) \ #define LOG_MODULE_REGISTER(...) \
_LOG_EVAL( \ _LOG_EVAL( \
_LOG_LEVEL_RESOLVE(__VA_ARGS__), \ _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__))),\ _LOG_LEVEL_RESOLVE(__VA_ARGS__))),\
()/*Empty*/ \ ()/*Empty*/ \
) \ ) \
@ -389,20 +389,20 @@ char *log_strdup(const char *str);
*/ */
#define LOG_MODULE_DECLARE(...) \ #define LOG_MODULE_DECLARE(...) \
extern const struct log_source_const_data \ 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 \ 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 * \ static const struct log_source_const_data * \
__log_current_const_data __attribute__((unused)) = \ __log_current_const_data __attribute__((unused)) = \
_LOG_LEVEL_RESOLVE(__VA_ARGS__) ? \ _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 * \ static struct log_source_dynamic_data * \
__log_current_dynamic_data __attribute__((unused)) = \ __log_current_dynamic_data __attribute__((unused)) = \
(_LOG_LEVEL_RESOLVE(__VA_ARGS__) && \ (_LOG_LEVEL_RESOLVE(__VA_ARGS__) && \
IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING)) ? \ 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)) = \ static const u32_t __log_level __attribute__((unused)) = \
_LOG_LEVEL_RESOLVE(__VA_ARGS__) _LOG_LEVEL_RESOLVE(__VA_ARGS__)

View file

@ -39,7 +39,7 @@ extern "C" {
_LOG_RESOLVED_LEVEL1(_level, _default) _LOG_RESOLVED_LEVEL1(_level, _default)
#define _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_XXXX0 _LOG_YYYY,
#define _LOG_XXXX1 _LOG_YYYY, #define _LOG_XXXX1 _LOG_YYYY,
@ -47,17 +47,6 @@ extern "C" {
#define _LOG_XXXX3 _LOG_YYYY, #define _LOG_XXXX3 _LOG_YYYY,
#define _LOG_XXXX4 _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. * @brief Macro for conditional code generation if provided log level allows.
* *
@ -76,36 +65,13 @@ extern "C" {
_LOG_EVAL1(_eval_level, _iftrue, _iffalse) _LOG_EVAL1(_eval_level, _iftrue, _iffalse)
#define _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_ZZZZ1 _LOG_YYYY,
#define _LOG_ZZZZ2 _LOG_YYYY, #define _LOG_ZZZZ2 _LOG_YYYY,
#define _LOG_ZZZZ3 _LOG_YYYY, #define _LOG_ZZZZ3 _LOG_YYYY,
#define _LOG_ZZZZ4 _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. /** @brief Macro for getting log level for given module.
* *
* It is evaluated to LOG_LEVEL if defined. Otherwise CONFIG_LOG_DEFAULT_LEVEL * 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 * @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. * case.
* *
* The purpose of this macro is to prefix string literal with format * The purpose of this macro is to prefix string literal with format
@ -165,10 +131,10 @@ extern "C" {
* used. * used.
*/ */
#define _LOG_STR(...) "%s: " __LOG_ARG_1(__VA_ARGS__), __func__\ #define _LOG_STR(...) "%s: " GET_ARG1(__VA_ARGS__), __func__\
_LOG_Z_EVAL(NUM_VA_ARGS_LESS_1(__VA_ARGS__),\ COND_CODE_0(NUM_VA_ARGS_LESS_1(__VA_ARGS__),\
(),\ (),\
(, __LOG_ARGS_LESS1(__VA_ARGS__))\ (, GET_ARGS_LESS_1(__VA_ARGS__))\
) )

View file

@ -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 * 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 * 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. * Brackets are stripped away during macro processing.
* *
* Usage example: * 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: * It can be considered as alternative to:
* *
* #if defined(CONFIG_FLAG) && (CONFIG_FLAG == 1) * \#if defined(CONFIG_FLAG) && (CONFIG_FLAG == 1)
* #define MACRO(x) u32_t x; * \#define MACRO(x) u32_t x;
* #else * \#else
* #define MACRO(x) * \#define MACRO(x)
* #endif * \#endif
* *
* However, the advantage of that approach is that code is resolved in place * 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 * where it is used while \#if method resolves given macro when header is