devicetree: re-work DT_INST_FOREACH()

Due to the use of UTIL_EVAL*() macros, the UTIL_LISTIFY() macro used
by DT_INST_FOREACH(foo) can cause long build errors when there is a
build error in the expansion for "foo". More than a thousand lines of
build error output have been observed for an error in a single line of
faulty C.

To improve the situation, re-work the implementation details so the
errors are a bit shorter and easier to read. The use of COND_CODE_1
still makes the error messages quite long, due to GCC generating notes
for various intermediate expansions (__DEBRACKET,
__GET_ARG_2_DEBRACKET, __COND_CODE, Z_COND_CODE_1, COND_CODE1), but
it's better than the long list of UTIL_EVAL notes.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This commit is contained in:
Martí Bolívar 2020-04-06 15:13:53 -07:00 committed by Kumar Gala
commit 63d5529a0d
4 changed files with 43 additions and 5 deletions

View file

@ -1389,7 +1389,8 @@
* Has to accept instance_number as only parameter.
*/
#define DT_INST_FOREACH(inst_expr) \
UTIL_LISTIFY(DT_NUM_INST(DT_DRV_COMPAT), DT_CALL_WITH_ARG, inst_expr)
COND_CODE_1(DT_HAS_COMPAT(DT_DRV_COMPAT), \
(UTIL_CAT(DT_FOREACH_INST_, DT_DRV_COMPAT)(inst_expr)), ())
/**
* @brief Does a DT_DRV_COMPAT instance have a property?
@ -1489,7 +1490,5 @@
#define DT_DASH(...) MACRO_MAP_CAT(DT_DASH_PREFIX, __VA_ARGS__)
/** @internal helper for DT_DASH(): prepends _ to a name */
#define DT_DASH_PREFIX(name) _##name
/** @internal DT_INST_FOREACH helper */
#define DT_CALL_WITH_ARG(arg, expr) expr(arg);
#endif /* DEVICETREE_H */