From c5aecf2d5a8b29c8b960380255d3a74982ad1f67 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sat, 4 Feb 2023 18:15:15 -0800 Subject: More compliance with C11. --- gfx/src/scene/scene_graph.h | 78 ++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/gfx/src/scene/scene_graph.h b/gfx/src/scene/scene_graph.h index 93d2e38..a26f828 100644 --- a/gfx/src/scene/scene_graph.h +++ b/gfx/src/scene/scene_graph.h @@ -44,50 +44,50 @@ /// - The node's parent cannot be the node's child or sibling, unless it's 0. /// - If the node has a parent and the node is the leftmost sibling, then the /// parent's child is the node. -#define ASSERT_TREE_NODE_INVARIANT(ITEM) \ - { \ - const gfx_idx item_idx = MEM_GET_INDEX(ITEM).val; \ - assert((ITEM)->prev.val != item_idx); \ - assert((ITEM)->next.val != item_idx); \ - if ((ITEM)->prev.val) { \ - assert((ITEM)->prev.val != (ITEM)->next.val); \ - } \ - if ((ITEM)->child.val) { \ - assert((ITEM)->child.val != (ITEM)->prev.val); \ - assert((ITEM)->child.val != (ITEM)->next.val); \ - } \ - assert((ITEM)->parent.val != item_idx); \ - if ((ITEM)->parent.val && !(ITEM)->prev.val) { \ - assert((ITEM)->parent.val != (ITEM)->prev.val); \ - assert((ITEM)->parent.val != (ITEM)->next.val); \ - const typeof(ITEM) item_parent = MEM_GET((ITEM)->parent); \ - assert(item_parent->child.val == item_idx); \ - } \ +#define ASSERT_TREE_NODE_INVARIANT(ITEM) \ + { \ + const gfx_idx item_idx = MEM_GET_INDEX(ITEM).val; \ + assert((ITEM)->prev.val != item_idx); \ + assert((ITEM)->next.val != item_idx); \ + if ((ITEM)->prev.val) { \ + assert((ITEM)->prev.val != (ITEM)->next.val); \ + } \ + if ((ITEM)->child.val) { \ + assert((ITEM)->child.val != (ITEM)->prev.val); \ + assert((ITEM)->child.val != (ITEM)->next.val); \ + } \ + assert((ITEM)->parent.val != item_idx); \ + if ((ITEM)->parent.val && !(ITEM)->prev.val) { \ + assert((ITEM)->parent.val != (ITEM)->prev.val); \ + assert((ITEM)->parent.val != (ITEM)->next.val); \ + const __typeof__(ITEM) item_parent = MEM_GET((ITEM)->parent); \ + assert(item_parent->child.val == item_idx); \ + } \ } /// Prepend an item to a list. /// Modify HEAD_INDEX to equal the index of the new head. -#define LIST_PREPEND(HEAD_INDEX, ITEM) \ - (ITEM)->next = HEAD_INDEX; \ - if (HEAD_INDEX.val) { \ - typeof(ITEM) old_head = MEM_GET(HEAD_INDEX); \ - old_head->prev = MEM_GET_INDEX(ITEM); \ - } \ - HEAD_INDEX = MEM_GET_INDEX(ITEM); \ +#define LIST_PREPEND(HEAD_INDEX, ITEM) \ + (ITEM)->next = HEAD_INDEX; \ + if (HEAD_INDEX.val) { \ + __typeof__(ITEM) old_head = MEM_GET(HEAD_INDEX); \ + old_head->prev = MEM_GET_INDEX(ITEM); \ + } \ + HEAD_INDEX = MEM_GET_INDEX(ITEM); \ ASSERT_LIST_NODE_INVARIANT(ITEM); /// Disconnect an item from its siblings. -#define LIST_REMOVE(ITEM) \ - if ((ITEM)->prev.val) { \ - typeof(ITEM) prev_sibling = MEM_GET((ITEM)->prev); \ - prev_sibling->next = (ITEM)->next; \ - } \ - if ((ITEM)->next.val) { \ - typeof(ITEM) next_sibling = MEM_GET((ITEM)->next); \ - next_sibling->prev = (ITEM)->prev; \ - } \ - (ITEM)->prev.val = 0; \ - (ITEM)->next.val = 0; \ +#define LIST_REMOVE(ITEM) \ + if ((ITEM)->prev.val) { \ + __typeof__(ITEM) prev_sibling = MEM_GET((ITEM)->prev); \ + prev_sibling->next = (ITEM)->next; \ + } \ + if ((ITEM)->next.val) { \ + __typeof__(ITEM) next_sibling = MEM_GET((ITEM)->next); \ + next_sibling->prev = (ITEM)->prev; \ + } \ + (ITEM)->prev.val = 0; \ + (ITEM)->next.val = 0; \ ASSERT_LIST_NODE_INVARIANT(ITEM); /// Set the child's parent. @@ -126,8 +126,8 @@ /* The parent points only to its first/leftmost child. If this item is */ \ /* the leftmost sibling, then we need to rewire the parent to point to */ \ /* the next sibling to keep the parent connected to its children. */ \ - typeof(ITEM) parent = MEM_GET((ITEM)->parent); \ - const typeof(ITEM) parent_child = MEM_GET(parent->child); \ + __typeof__(ITEM) parent = MEM_GET((ITEM)->parent); \ + const __typeof__(ITEM) parent_child = MEM_GET(parent->child); \ if (parent_child == ITEM) { \ assert((ITEM)->prev.val == 0); \ parent->child = (ITEM)->next; \ -- cgit v1.2.3