123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- /*
- * Copyright (c) 2011-2014, Wind River Systems, Inc.
- * Copyright (c) 2020, Nordic Semiconductor ASA
- *
- * SPDX-License-Identifier: Apache-2.0
- */
- /**
- * @file
- * @brief Misc utilities
- *
- * Repetitive or obscure helper macros needed by sys/util.h.
- */
- /* IS_ENABLED() helpers */
- /* This is called from IS_ENABLED(), and sticks on a "_XXXX" prefix,
- * it will now be "_XXXX1" if config_macro is "1", or just "_XXXX" if it's
- * undefined.
- * ENABLED: Z_IS_ENABLED2(_XXXX1)
- * DISABLED Z_IS_ENABLED2(_XXXX)
- */
- /* Here's the core trick, we map "_XXXX1" to "_YYYY," (i.e. a string
- * with a trailing comma), so it has the effect of making this a
- * two-argument tuple to the preprocessor only in the case where the
- * value is defined to "1"
- * ENABLED: _YYYY, <
- * DISABLED: _XXXX
- */
- /* Then we append an extra argument to fool the gcc preprocessor into
- * accepting it as a varargs macro.
- * arg1 arg2 arg3
- * ENABLED: Z_IS_ENABLED3(_YYYY, 1, 0)
- * DISABLED Z_IS_ENABLED3(_XXXX 1, 0)
- */
- /* And our second argument is thus now cooked to be 1 in the case
- * where the value is defined to 1, and 0 if not:
- */
- /* Used internally by COND_CODE_1 and COND_CODE_0. */
- __COND_CODE(_XXXX
- __COND_CODE(_ZZZZ
- __GET_ARG2_DEBRACKET(one_or_two_args _if_code, _else_code)
- /* Gets second argument and removes brackets around that argument. It
- * is expected that the parameter is provided in brackets/parentheses.
- */
- /* Used to remove brackets from around a single argument. */
- /* Used by IS_EMPTY() */
- /* Used by LIST_DROP_EMPTY() */
- /* Adding ',' after each element would add empty element at the end of
- * list, which is hard to remove, so instead precede each element with ',',
- * this way first element is empty, and this one is easy to drop.
- */
- COND_CODE_1(IS_EMPTY(e), (), (Z_LIST_ADD_ELEM(e)))
- /* Implementation details for NUM_VA_ARGS_LESS_1 */
- _ignored, \
- _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, \
- _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, \
- _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, \
- _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, \
- _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, \
- _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, \
- _61, _62, N, ...) N
- /* Used by MACRO_MAP_CAT */
- /* To make sure it works also for 2 arguments in total */ \
- MACRO_MAP_CAT_N(NUM_VA_ARGS_LESS_1(__VA_ARGS__), __VA_ARGS__)
|