+/* Convenience macros for iteration.
+
+ These macros automatically use ABT_DATA to obtain the data elements that
+ encapsulate abt nodes, which often saves typing and can make code easier to
+ read. Refer to the large comment near the top of this file for an example.
+
+ These macros evaluate their arguments many times. */
+#define ABT_FIRST(STRUCT, MEMBER, ABT) \
+ ABT_NULLABLE_DATA (abt_first (ABT), STRUCT, MEMBER)
+#define ABT_NEXT(DATA, STRUCT, MEMBER, ABT) \
+ ABT_NULLABLE_DATA (abt_next (ABT, &(DATA)->MEMBER), STRUCT, MEMBER)
+#define ABT_FOR_EACH(DATA, STRUCT, MEMBER, ABT) \
+ for ((DATA) = ABT_FIRST (STRUCT, MEMBER, ABT); \
+ (DATA) != NULL; \
+ (DATA) = ABT_NEXT (DATA, STRUCT, MEMBER, ABT))
+#define ABT_FOR_EACH_SAFE(DATA, NEXT, STRUCT, MEMBER, ABT) \
+ for ((DATA) = ABT_FIRST (STRUCT, MEMBER, ABT); \
+ ((DATA) != NULL \
+ ? ((NEXT) = ABT_NEXT (DATA, STRUCT, MEMBER, ABT), 1) \
+ : 0); \
+ (DATA) = (NEXT))
+
+/* Returns true if ABT contains no nodes, false if ABT contains at least one
+ node. */
+static inline bool
+abt_is_empty (const struct abt *abt)
+{
+ return abt->root == NULL;
+}
+
+/* Helper for ABT_NULLABLE_DATA (to avoid evaluating its NODE argument more
+ than once). */
+static inline void *
+abt_nullable_data__ (struct abt_node *node, size_t member_offset)
+{
+ return node != NULL ? (char *) node - member_offset : NULL;
+}
+