mirror of
https://github.com/Ed94/metadesk.git
synced 2026-07-03 08:31:49 -07:00
mdesk: at tree introspection
This commit is contained in:
+46
-116
@@ -79,24 +79,23 @@ string_list_from_token_flags(Arena* arena, TokenFlags flags)
|
||||
return strs;
|
||||
}
|
||||
|
||||
internal void
|
||||
void
|
||||
token_chunk_list_push(Arena* arena, TokenChunkList* list, U64 cap, Token token)
|
||||
{
|
||||
TokenChunkNode *node = list->last;
|
||||
if(node == 0 || node->count >= node->cap)
|
||||
{
|
||||
node = push_array(arena, TokenChunkNode, 1);
|
||||
node->cap = cap;
|
||||
node->v = push_array_no_zero(arena, Token, cap);
|
||||
sll_queue_push(list->first, list->last, node);
|
||||
list->chunk_count += 1;
|
||||
}
|
||||
memory_copy_struct(&node->v[node->count], &token);
|
||||
node->count += 1;
|
||||
list->total_token_count += 1;
|
||||
TokenChunkNode* node = list->last;
|
||||
if (node == 0 || node->count >= node->cap) {
|
||||
node = push_array(arena, TokenChunkNode, 1);
|
||||
node->cap = cap;
|
||||
node->v = push_array_no_zero(arena, Token, cap);
|
||||
sll_queue_push(list->first, list->last, node);
|
||||
list->chunk_count += 1;
|
||||
}
|
||||
memory_copy_struct(&node->v[node->count], &token);
|
||||
node->count += 1;
|
||||
list->total_token_count += 1;
|
||||
}
|
||||
|
||||
internal TokenArray
|
||||
TokenArray
|
||||
token_array_from_chunk_list(Arena* arena, TokenChunkList* chunks)
|
||||
{
|
||||
TokenArray result = {0};
|
||||
@@ -114,115 +113,46 @@ token_array_from_chunk_list(Arena* arena, TokenChunkList* chunks)
|
||||
////////////////////////////////
|
||||
//~ rjf: Node Type Functions
|
||||
|
||||
//- rjf: flag conversions
|
||||
|
||||
internal NodeFlags
|
||||
node_flags_from_token_flags(TokenFlags flags)
|
||||
{
|
||||
NodeFlags result = 0;
|
||||
result |= NodeFlag_Identifier*!!(flags&TokenFlag_Identifier);
|
||||
result |= NodeFlag_Numeric*!!(flags&TokenFlag_Numeric);
|
||||
result |= NodeFlag_StringLiteral*!!(flags&TokenFlag_StringLiteral);
|
||||
result |= NodeFlag_Symbol*!!(flags&TokenFlag_Symbol);
|
||||
result |= NodeFlag_StringSingleQuote *!!(flags&TokenFlag_StringSingleQuote);
|
||||
result |= NodeFlag_StringDoubleQuote *!!(flags&TokenFlag_StringDoubleQuote);
|
||||
result |= NodeFlag_StringTick*!!(flags&TokenFlag_StringTick);
|
||||
result |= NodeFlag_StringTriplet*!!(flags&TokenFlag_StringTriplet);
|
||||
return result;
|
||||
}
|
||||
|
||||
//- rjf: nil
|
||||
|
||||
internal B32
|
||||
node_is_nil(Node *node)
|
||||
{
|
||||
return (node == 0 || node == nil_node() || node->kind == NodeKind_Nil);
|
||||
}
|
||||
|
||||
//- rjf: iteration
|
||||
|
||||
internal NodeRec
|
||||
node_rec_depth_first(Node *node, Node *subtree_root, U64 child_off, U64 sib_off)
|
||||
NodeRec
|
||||
node_rec_depth_first(Node* node, Node* subtree_root, U64 child_off, U64 sib_off)
|
||||
{
|
||||
NodeRec rec = {0};
|
||||
rec.next = nil_node();
|
||||
if(!node_is_nil(*member_from_offset(Node **, node, child_off)))
|
||||
{
|
||||
rec.next = *member_from_offset(Node **, node, child_off);
|
||||
rec.push_count = 1;
|
||||
}
|
||||
else for(Node *p = node; !node_is_nil(p) && p != subtree_root; p = p->parent, rec.pop_count += 1)
|
||||
{
|
||||
if(!node_is_nil(*member_from_offset(Node **, p, sib_off)))
|
||||
{
|
||||
rec.next = *member_from_offset(Node **, p, sib_off);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return rec;
|
||||
NodeRec
|
||||
rec = {0};
|
||||
rec.next = nil_node();
|
||||
if (!node_is_nil(*member_from_offset(Node**, node, child_off))) {
|
||||
rec.next = *member_from_offset(Node**, node, child_off);
|
||||
rec.push_count = 1;
|
||||
}
|
||||
else for (Node* p = node; !node_is_nil(p) && p != subtree_root; p = p->parent, rec.pop_count += 1)
|
||||
{
|
||||
if (!node_is_nil(*member_from_offset(Node**, p, sib_off))) {
|
||||
rec.next = *member_from_offset(Node**, p, sib_off);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return rec;
|
||||
}
|
||||
|
||||
//- rjf: tree building
|
||||
|
||||
internal Node *
|
||||
push_node(Arena *arena, NodeKind kind, NodeFlags flags, String8 string, String8 raw_string, U64 src_offset)
|
||||
void
|
||||
unhook(Node* node)
|
||||
{
|
||||
Node *node = push_array(arena, Node, 1);
|
||||
node->first = node->last = node->parent = node->next = node->prev = node->first_tag = node->last_tag = nil_node();
|
||||
node->kind = kind;
|
||||
node->flags = flags;
|
||||
node->string = string;
|
||||
node->raw_string = raw_string;
|
||||
node->src_offset = src_offset;
|
||||
return node;
|
||||
}
|
||||
|
||||
internal void
|
||||
node_insert_child(Node *parent, Node *prev_child, Node *node)
|
||||
{
|
||||
node->parent = parent;
|
||||
dll_insert_npz(nil_node(), parent->first, parent->last, prev_child, node, next, prev);
|
||||
}
|
||||
|
||||
internal void
|
||||
node_insert_tag(Node *parent, Node *prev_child, Node *node)
|
||||
{
|
||||
node->kind = NodeKind_Tag;
|
||||
node->parent = parent;
|
||||
dll_insert_npz(nil_node(), parent->first_tag, parent->last_tag, prev_child, node, next, prev);
|
||||
}
|
||||
|
||||
internal void
|
||||
node_push_child(Node *parent, Node *node)
|
||||
{
|
||||
node->parent = parent;
|
||||
dll_push_back_npz(nil_node(), parent->first, parent->last, node, next, prev);
|
||||
}
|
||||
|
||||
internal void
|
||||
node_push_tag(Node *parent, Node *node)
|
||||
{
|
||||
node->kind = NodeKind_Tag;
|
||||
node->parent = parent;
|
||||
dll_push_back_npz(nil_node(), parent->first_tag, parent->last_tag, node, next, prev);
|
||||
}
|
||||
|
||||
internal void
|
||||
unhook(Node *node)
|
||||
{
|
||||
Node *parent = node->parent;
|
||||
if(!node_is_nil(parent))
|
||||
{
|
||||
if(node->kind == NodeKind_Tag)
|
||||
{
|
||||
dll_remove_npz(nil_node(), parent->first_tag, parent->last_tag, node, next, prev);
|
||||
}
|
||||
else
|
||||
{
|
||||
dll_remove_npz(nil_node(), parent->first, parent->last, node, next, prev);
|
||||
}
|
||||
node->parent = nil_node();
|
||||
}
|
||||
Node* parent = node->parent;
|
||||
if (!node_is_nil(parent))
|
||||
{
|
||||
if(node->kind == NodeKind_Tag)
|
||||
{
|
||||
dll_remove_npz(nil_node(), parent->first_tag, parent->last_tag, node, next, prev);
|
||||
}
|
||||
else
|
||||
{
|
||||
dll_remove_npz(nil_node(), parent->first, parent->last, node, next, prev);
|
||||
}
|
||||
node->parent = nil_node();
|
||||
}
|
||||
}
|
||||
|
||||
//- rjf: tree introspection
|
||||
@@ -373,7 +303,7 @@ string_from_children(Arena *arena, Node *root)
|
||||
{
|
||||
TempArena scratch = scratch_begin(&arena, 1);
|
||||
String8List strs = {0};
|
||||
for MD_EachNode(child, root->first)
|
||||
for each_node(child, root->first)
|
||||
{
|
||||
if(child->flags == child->prev->flags)
|
||||
{
|
||||
|
||||
+62
-11
@@ -285,31 +285,82 @@ token_match(Token a, Token b) {
|
||||
|
||||
//- rjf: flag conversions
|
||||
|
||||
internal NodeFlags node_flags_from_token_flags(TokenFlags flags);
|
||||
inline NodeFlags
|
||||
node_flags_from_token_flags(TokenFlags flags)
|
||||
{
|
||||
NodeFlags result = 0;
|
||||
result |= NodeFlag_Identifier *!!(flags & TokenFlag_Identifier );
|
||||
result |= NodeFlag_Numeric *!!(flags & TokenFlag_Numeric );
|
||||
result |= NodeFlag_StringLiteral *!!(flags & TokenFlag_StringLiteral );
|
||||
result |= NodeFlag_Symbol *!!(flags & TokenFlag_Symbol );
|
||||
result |= NodeFlag_StringSingleQuote *!!(flags & TokenFlag_StringSingleQuote);
|
||||
result |= NodeFlag_StringDoubleQuote *!!(flags & TokenFlag_StringDoubleQuote);
|
||||
result |= NodeFlag_StringTick *!!(flags & TokenFlag_StringTick );
|
||||
result |= NodeFlag_StringTriplet *!!(flags & TokenFlag_StringTriplet );
|
||||
return result;
|
||||
}
|
||||
|
||||
//- rjf: nil
|
||||
|
||||
internal B32 node_is_nil(Node *node);
|
||||
B32 node_is_nil(Node* node) { return (node == 0 || node == nil_node() || node->kind == NodeKind_Nil); }
|
||||
|
||||
//- rjf: iteration
|
||||
|
||||
#define MD_EachNode(it, first) (Node *it = first; !node_is_nil(it); it = it->next)
|
||||
#define each_node(it, first) (Node *it = first; !node_is_nil(it); it = it->next)
|
||||
|
||||
internal NodeRec node_rec_depth_first(Node *node, Node *subtree_root, U64 child_off, U64 sib_off);
|
||||
MD_API NodeRec node_rec_depth_first(Node *node, Node *subtree_root, U64 child_off, U64 sib_off);
|
||||
|
||||
#define node_rec_depth_first_pre(node, subtree_root) node_rec_depth_first((node), (subtree_root), offset_of(Node, first), offset_of(Node, next))
|
||||
#define node_rec_depth_first_pre_rev(node, subtree_root) node_rec_depth_first((node), (subtree_root), offset_of(Node, last), offset_of(Node, prev))
|
||||
|
||||
//- rjf: tree building
|
||||
|
||||
internal Node* push_node (Arena *arena, NodeKind kind, NodeFlags flags, String8 string, String8 raw_string, U64 src_offset);
|
||||
internal void node_insert_tag (Node *parent, Node *prev_child, Node *node);
|
||||
internal void node_insert_child(Node *parent, Node *prev_child, Node *node);
|
||||
internal void node_push_child (Node *parent, Node *node);
|
||||
internal void node_push_tag (Node *parent, Node *node);
|
||||
internal void unhook (Node *node);
|
||||
Node* push_node (Arena *arena, NodeKind kind, NodeFlags flags, String8 string, String8 raw_string, U64 src_offset);
|
||||
void node_insert_tag (Node *parent, Node *prev_child, Node *node);
|
||||
void node_insert_child(Node *parent, Node *prev_child, Node *node);
|
||||
void node_push_child (Node *parent, Node *node);
|
||||
void node_push_tag (Node *parent, Node *node);
|
||||
void unhook (Node *node);
|
||||
|
||||
//- rjf: tree introspection
|
||||
inline Node*
|
||||
push_node(Arena* arena, NodeKind kind, NodeFlags flags, String8 string, String8 raw_string, U64 src_offset) {
|
||||
Node* node = push_array(arena, Node, 1);
|
||||
node->first = node->last = node->parent = node->next = node->prev = node->first_tag = node->last_tag = nil_node();
|
||||
node->kind = kind;
|
||||
node->flags = flags;
|
||||
node->string = string;
|
||||
node->raw_string = raw_string;
|
||||
node->src_offset = src_offset;
|
||||
return node;
|
||||
}
|
||||
|
||||
inline void
|
||||
node_insert_child(Node* parent, Node* prev_child, Node* node) {
|
||||
node->parent = parent;
|
||||
dll_insert_npz(nil_node(), parent->first, parent->last, prev_child, node, next, prev);
|
||||
}
|
||||
|
||||
inline void
|
||||
node_insert_tag(Node* parent, Node* prev_child, Node* node) {
|
||||
node->kind = NodeKind_Tag;
|
||||
node->parent = parent;
|
||||
dll_insert_npz(nil_node(), parent->first_tag, parent->last_tag, prev_child, node, next, prev);
|
||||
}
|
||||
|
||||
inline void
|
||||
node_push_child(Node* parent, Node* node) {
|
||||
node->parent = parent;
|
||||
dll_push_back_npz(nil_node(), parent->first, parent->last, node, next, prev);
|
||||
}
|
||||
|
||||
inline void
|
||||
node_push_tag(Node* parent, Node* node) {
|
||||
node->kind = NodeKind_Tag;
|
||||
node->parent = parent;
|
||||
dll_push_back_npz(nil_node(), parent->first_tag, parent->last_tag, node, next, prev);
|
||||
}
|
||||
|
||||
//- rjf: tree introspectionhttps://github.com/Ed94/metadesk
|
||||
|
||||
internal Node* node_from_chain_string(Node *first, Node *opl, String8 string, StringMatchFlags flags);
|
||||
internal Node* node_from_chain_index (Node *first, Node *opl, U64 index);
|
||||
|
||||
@@ -517,7 +517,7 @@ mg_child_array_from_node(Arena *arena, Node *node)
|
||||
{
|
||||
MG_NodeArray children = mg_node_array_make(arena, child_count_from_node(node));
|
||||
U64 idx = 0;
|
||||
for MD_EachNode(child, node->first)
|
||||
for each_node(child, node->first)
|
||||
{
|
||||
children.v[idx] = child;
|
||||
idx += 1;
|
||||
@@ -533,7 +533,7 @@ mg_node_grid_make_from_node(Arena *arena, Node *root)
|
||||
// rjf: determine dimensions
|
||||
U64 row_count = child_count_from_node(root);
|
||||
U64 column_count = 0;
|
||||
for MD_EachNode(row, root->first)
|
||||
for each_node(row, root->first)
|
||||
{
|
||||
U64 cell_count_this_row = child_count_from_node(row);
|
||||
column_count = Max(column_count, cell_count_this_row);
|
||||
@@ -548,11 +548,11 @@ mg_node_grid_make_from_node(Arena *arena, Node *root)
|
||||
// rjf: fill nodes
|
||||
{
|
||||
U64 y = 0;
|
||||
for MD_EachNode(row, root->first)
|
||||
for each_node(row, root->first)
|
||||
{
|
||||
U64 x = 0;
|
||||
grid.row_parents.v[y] = row;
|
||||
for MD_EachNode(cell, row->first)
|
||||
for each_node(cell, row->first)
|
||||
{
|
||||
grid.cells.v[x*grid.x_stride + y*grid.y_stride] = cell;
|
||||
x += 1;
|
||||
@@ -622,7 +622,7 @@ mg_column_desc_array_from_tag(Arena *arena, Node *tag)
|
||||
result.count = child_count_from_node(tag);
|
||||
result.v = push_array(arena, MG_ColumnDesc, result.count);
|
||||
U64 idx = 0;
|
||||
for MD_EachNode(hdr, tag->first)
|
||||
for each_node(hdr, tag->first)
|
||||
{
|
||||
result.v[idx].name = push_str8_copy(arena, hdr->string);
|
||||
result.v[idx].kind = MG_ColumnKind_DirectCell;
|
||||
@@ -1031,12 +1031,12 @@ mg_string_list_from_table_gen(Arena *arena, MG_Map grid_name_map, MG_Map grid_co
|
||||
str8_list_push(arena, &result, gen->string);
|
||||
str8_list_push(arena, &result, str8_lit("\n"));
|
||||
}
|
||||
else for MD_EachNode(strexpr_node, gen->first)
|
||||
else for each_node(strexpr_node, gen->first)
|
||||
{
|
||||
// rjf: build task list
|
||||
MG_TableExpandTask *first_task = 0;
|
||||
MG_TableExpandTask *last_task = 0;
|
||||
for MD_EachNode(tag, strexpr_node->first_tag)
|
||||
for each_node(tag, strexpr_node->first_tag)
|
||||
{
|
||||
if(str8_match(tag->string, str8_lit("expand"), 0))
|
||||
{
|
||||
|
||||
+10
-10
@@ -129,7 +129,7 @@ entry_point(CmdLine *cmdline)
|
||||
for(MG_FileParseNode *n = parses.first; n != 0; n = n->next)
|
||||
{
|
||||
Node *file = n->v.root;
|
||||
for MD_EachNode(node, file->first)
|
||||
for each_node(node, file->first)
|
||||
{
|
||||
Node *table_tag = tag_from_string(node, str8_lit("table"), 0);
|
||||
if(!node_is_nil(table_tag))
|
||||
@@ -154,7 +154,7 @@ entry_point(CmdLine *cmdline)
|
||||
Node *file = n->v.root;
|
||||
String8 layer_key = mg_layer_key_from_path(file->string);
|
||||
MG_Layer *layer = mg_layer_from_key(layer_key);
|
||||
for MD_EachNode(node, file->first)
|
||||
for each_node(node, file->first)
|
||||
{
|
||||
if(node_has_tag(node, str8_lit("option"), 0))
|
||||
{
|
||||
@@ -220,7 +220,7 @@ entry_point(CmdLine *cmdline)
|
||||
for(MG_FileParseNode *n = parses.first; n != 0; n = n->next)
|
||||
{
|
||||
Node *file = n->v.root;
|
||||
for MD_EachNode(node, file->first)
|
||||
for each_node(node, file->first)
|
||||
{
|
||||
Node *tag = tag_from_string(node, str8_lit("enum"), 0);
|
||||
if(!node_is_nil(tag))
|
||||
@@ -267,7 +267,7 @@ entry_point(CmdLine *cmdline)
|
||||
for(MG_FileParseNode *n = parses.first; n != 0; n = n->next)
|
||||
{
|
||||
Node *file = n->v.root;
|
||||
for MD_EachNode(node, file->first)
|
||||
for each_node(node, file->first)
|
||||
{
|
||||
Node *tag = tag_from_string(node, str8_lit("xlist"), 0);
|
||||
if(!node_is_nil(tag))
|
||||
@@ -292,7 +292,7 @@ entry_point(CmdLine *cmdline)
|
||||
for(MG_FileParseNode *n = parses.first; n != 0; n = n->next)
|
||||
{
|
||||
Node *file = n->v.root;
|
||||
for MD_EachNode(node, file->first)
|
||||
for each_node(node, file->first)
|
||||
{
|
||||
if(node_has_tag(node, str8_lit("struct"), 0))
|
||||
{
|
||||
@@ -317,7 +317,7 @@ entry_point(CmdLine *cmdline)
|
||||
for(MG_FileParseNode *n = parses.first; n != 0; n = n->next)
|
||||
{
|
||||
Node *file = n->v.root;
|
||||
for MD_EachNode(node, file->first)
|
||||
for each_node(node, file->first)
|
||||
{
|
||||
Node *tag = tag_from_string(node, str8_lit("data"), 0);
|
||||
if(!node_is_nil(tag))
|
||||
@@ -347,7 +347,7 @@ entry_point(CmdLine *cmdline)
|
||||
for(MG_FileParseNode *n = parses.first; n != 0; n = n->next)
|
||||
{
|
||||
Node *file = n->v.root;
|
||||
for MD_EachNode(node, file->first)
|
||||
for each_node(node, file->first)
|
||||
{
|
||||
Node *tag = tag_from_string(node, str8_lit("enum2string_switch"), 0);
|
||||
if(!node_is_nil(tag))
|
||||
@@ -380,7 +380,7 @@ entry_point(CmdLine *cmdline)
|
||||
for(MG_FileParseNode *n = parses.first; n != 0; n = n->next)
|
||||
{
|
||||
Node *file = n->v.root;
|
||||
for MD_EachNode(node, file->first)
|
||||
for each_node(node, file->first)
|
||||
{
|
||||
Node *tag = tag_from_string(node, str8_lit("gen"), 0);
|
||||
if(!node_is_nil(tag))
|
||||
@@ -412,7 +412,7 @@ entry_point(CmdLine *cmdline)
|
||||
for(MG_FileParseNode *n = parses.first; n != 0; n = n->next)
|
||||
{
|
||||
Node *file = n->v.root;
|
||||
for MD_EachNode(node, file->first)
|
||||
for each_node(node, file->first)
|
||||
{
|
||||
if(node_has_tag(node, str8_lit("embed_string"), 0))
|
||||
{
|
||||
@@ -446,7 +446,7 @@ entry_point(CmdLine *cmdline)
|
||||
for(MG_FileParseNode *n = parses.first; n != 0; n = n->next)
|
||||
{
|
||||
Node *file = n->v.root;
|
||||
for MD_EachNode(node, file->first)
|
||||
for each_node(node, file->first)
|
||||
{
|
||||
//- rjf: generate markdown page
|
||||
if(node_has_tag(node, str8_lit("markdown"), 0))
|
||||
|
||||
@@ -231,10 +231,10 @@ MD_ExprOprPush(arena, &list, MD_ExprOprKind_##k, p, MD_S8Lit(t), Op##e, 0);
|
||||
}
|
||||
|
||||
// print the verbose parse results
|
||||
for (MD_EachNode(root_it, list->first_child))
|
||||
for (each_node(root_it, list->first_child))
|
||||
{
|
||||
Node *root = MD_ResolveNodeFromReference(root_it);
|
||||
for (MD_EachNode(node, root->first_child))
|
||||
for (each_node(node, root->first_child))
|
||||
{
|
||||
MD_ExprParseResult parse = MD_ExprParse(arena, &table, node->first_child, MD_NilNode());
|
||||
|
||||
|
||||
@@ -210,13 +210,13 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
// apply expression parsing to each top level node
|
||||
for (MD_EachNode(root_it, list->first_child))
|
||||
for (each_node(root_it, list->first_child))
|
||||
{
|
||||
// init eval map
|
||||
eval_map = MD_MapMake(arena);
|
||||
|
||||
Node *root = MD_ResolveNodeFromReference(root_it);
|
||||
for (MD_EachNode(node, root->first_child))
|
||||
for (each_node(node, root->first_child))
|
||||
{
|
||||
// @notes An expression parse is an extra stage of analysis on top
|
||||
// of the initial Metadesk parse. It takes in a range of Metadesk
|
||||
|
||||
@@ -184,7 +184,7 @@ main(int argc, char **argv)
|
||||
fprintf(stdout, "on thread %d:\n", i);
|
||||
|
||||
// print the name of each root
|
||||
for (MD_EachNode(root_it, threads[i].list->first_child))
|
||||
for (each_node(root_it, threads[i].list->first_child))
|
||||
{
|
||||
Node *root = MD_ResolveNodeFromReference(root_it);
|
||||
fprintf(stdout, "%.*s\n", MD_S8VArg(root->string));
|
||||
|
||||
@@ -71,10 +71,10 @@ int main(int argument_count, char **arguments)
|
||||
if (!failed_parse)
|
||||
{
|
||||
Initialize();
|
||||
for(MD_EachNode(ref, list->first_child))
|
||||
for(each_node(ref, list->first_child))
|
||||
{
|
||||
Node *root = MD_ResolveNodeFromReference(ref);
|
||||
for(MD_EachNode(node, root->first_child))
|
||||
for(each_node(node, root->first_child))
|
||||
{
|
||||
TopLevel(node);
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ int main(int argc, char **argv)
|
||||
// list. The second parameter is a pointer to the first node of the list.
|
||||
// Generally we past the `first_child` of a list or parent Node, but we
|
||||
// don't always have to.
|
||||
for (MD_EachNode(root_it, list->first_child))
|
||||
for (each_node(root_it, list->first_child))
|
||||
{
|
||||
|
||||
// @notes The `list` we have been building does not contain a normal
|
||||
@@ -81,7 +81,7 @@ int main(int argc, char **argv)
|
||||
// get the root of the parse tree.
|
||||
Node *root = MD_ResolveNodeFromReference(root_it);
|
||||
|
||||
for (MD_EachNode(node, root->first_child))
|
||||
for (each_node(node, root->first_child))
|
||||
{
|
||||
// @notes The Metadesk library likes to use MD_String8List for
|
||||
// functions that build and return big strings. This simplifies
|
||||
|
||||
@@ -208,10 +208,10 @@ gen_check_and_do_duplicate_symbol_error(Node *new_node)
|
||||
void
|
||||
gen_gather_types_and_maps(Node *list)
|
||||
{
|
||||
for(MD_EachNode(ref, list->first_child))
|
||||
for(each_node(ref, list->first_child))
|
||||
{
|
||||
Node *root = MD_ResolveNodeFromReference(ref);
|
||||
for(MD_EachNode(node, root->first_child))
|
||||
for(each_node(node, root->first_child))
|
||||
{
|
||||
// gather type
|
||||
Node *type_tag = MD_TagFromString(node, MD_S8Lit("type"), 0);
|
||||
@@ -275,10 +275,10 @@ gen_check_duplicate_member_names(void)
|
||||
type = type->next)
|
||||
{
|
||||
Node *type_root_node = type->node;
|
||||
for (MD_EachNode(member_node, type_root_node->first_child))
|
||||
for (each_node(member_node, type_root_node->first_child))
|
||||
{
|
||||
MD_String8 name = member_node->string;
|
||||
for (MD_EachNode(check_node, type_root_node->first_child))
|
||||
for (each_node(check_node, type_root_node->first_child))
|
||||
{
|
||||
if (member_node == check_node)
|
||||
{
|
||||
@@ -362,7 +362,7 @@ gen_equip_struct_members(void)
|
||||
int member_count = 0;
|
||||
|
||||
Node *type_root_node = type->node;
|
||||
for (MD_EachNode(member_node, type_root_node->first_child))
|
||||
for (each_node(member_node, type_root_node->first_child))
|
||||
{
|
||||
Node *type_name_node = member_node->first_child;
|
||||
|
||||
@@ -523,7 +523,7 @@ gen_equip_enum_members(void)
|
||||
int next_implicit_value = 0;
|
||||
|
||||
Node *type_root_node = type->node;
|
||||
for (MD_EachNode(enumerant_node, type_root_node->first_child))
|
||||
for (each_node(enumerant_node, type_root_node->first_child))
|
||||
{
|
||||
Node *value_node = enumerant_node->first_child;
|
||||
int value = 0;
|
||||
|
||||
@@ -58,7 +58,7 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
// check for custom errors
|
||||
for(MD_EachNode(ref, list->first_child))
|
||||
for(each_node(ref, list->first_child))
|
||||
{
|
||||
Node *root = MD_ResolveNodeFromReference(ref);
|
||||
|
||||
@@ -66,7 +66,7 @@ int main(int argc, char **argv)
|
||||
// so we can check for them by visiting each node from the root.
|
||||
// The example "type metadata" includes more advanced custom errors
|
||||
// that are only discovered after more analysis.
|
||||
for(MD_EachNode(node, root->first_child))
|
||||
for(each_node(node, root->first_child))
|
||||
{
|
||||
|
||||
// top level node should have one or zero tags.
|
||||
|
||||
+9
-9
@@ -3245,7 +3245,7 @@ MD_FUNCTION MD_i64
|
||||
MD_ChildCountFromNode(Node *node)
|
||||
{
|
||||
MD_i64 result = 0;
|
||||
for(MD_EachNode(child, node->first_child))
|
||||
for(each_node(child, node->first_child))
|
||||
{
|
||||
result += 1;
|
||||
}
|
||||
@@ -3256,7 +3256,7 @@ MD_FUNCTION MD_i64
|
||||
MD_TagCountFromNode(Node *node)
|
||||
{
|
||||
MD_i64 result = 0;
|
||||
for(MD_EachNode(tag, node->first_tag))
|
||||
for(each_node(tag, node->first_tag))
|
||||
{
|
||||
result += 1;
|
||||
}
|
||||
@@ -3867,7 +3867,7 @@ MD_S8ListPush(arena, out, indent_string);\
|
||||
//- rjf: tags of node
|
||||
if(flags & MD_GenerateFlag_Tags)
|
||||
{
|
||||
for(MD_EachNode(tag, node->first_tag))
|
||||
for(each_node(tag, node->first_tag))
|
||||
{
|
||||
MD_PrintIndent(indent);
|
||||
MD_S8ListPush(arena, out, MD_S8Lit("@"));
|
||||
@@ -3876,7 +3876,7 @@ MD_S8ListPush(arena, out, indent_string);\
|
||||
{
|
||||
int tag_arg_indent = (int)(indent + 1 + tag->string.size + 1);
|
||||
MD_S8ListPush(arena, out, MD_S8Lit("("));
|
||||
for(MD_EachNode(child, tag->first_child))
|
||||
for(each_node(child, tag->first_child))
|
||||
{
|
||||
int child_indent = tag_arg_indent;
|
||||
if(MD_NodeIsNil(child->prev))
|
||||
@@ -3955,7 +3955,7 @@ MD_S8ListPush(arena, out, indent_string);\
|
||||
}
|
||||
MD_PrintIndent(indent);
|
||||
MD_S8ListPush(arena, out, MD_S8Lit("{\n"));
|
||||
for(MD_EachNode(child, node->first_child))
|
||||
for(each_node(child, node->first_child))
|
||||
{
|
||||
MD_DebugDumpFromNode(arena, out, child, indent+1, indent_string, flags);
|
||||
MD_S8ListPush(arena, out, MD_S8Lit(",\n"));
|
||||
@@ -4023,7 +4023,7 @@ MD_S8ListPush(arena, out, indent_string);\
|
||||
MD_u32 tag_first_line = MD_CodeLocFromNode(node->first_tag).line;
|
||||
MD_u32 tag_last_line = tag_first_line;
|
||||
{
|
||||
for(MD_EachNode(tag, node->first_tag))
|
||||
for(each_node(tag, node->first_tag))
|
||||
{
|
||||
MD_u32 tag_line = MD_CodeLocFromNode(tag).line;
|
||||
if(tag_line != tag_last_line)
|
||||
@@ -4044,7 +4044,7 @@ MD_S8ListPush(arena, out, indent_string);\
|
||||
int tag_arg_indent = (int)(indent + 1 + tag->string.size + 1);
|
||||
MD_S8ListPush(arena, out, MD_S8Lit("("));
|
||||
MD_u32 last_line = MD_CodeLocFromNode(tag).line;
|
||||
for(MD_EachNode(child, tag->first_child))
|
||||
for(each_node(child, tag->first_child))
|
||||
{
|
||||
MD_CodeLoc child_loc = MD_CodeLocFromNode(child);
|
||||
if(child_loc.line != last_line)
|
||||
@@ -4113,7 +4113,7 @@ MD_S8ListPush(arena, out, indent_string);\
|
||||
else if(node->flags & NodeFlag_HasBraceRight) { closer_char = '}'; }
|
||||
|
||||
MD_b32 multiline = 0;
|
||||
for(MD_EachNode(child, node->first_child))
|
||||
for(each_node(child, node->first_child))
|
||||
{
|
||||
MD_CodeLoc child_loc = MD_CodeLocFromNode(child);
|
||||
if(child_loc.line != code_loc.line)
|
||||
@@ -4142,7 +4142,7 @@ MD_S8ListPush(arena, out, indent_string);\
|
||||
}
|
||||
}
|
||||
MD_u32 last_line = MD_CodeLocFromNode(node->first_child).line;
|
||||
for(MD_EachNode(child, node->first_child))
|
||||
for(each_node(child, node->first_child))
|
||||
{
|
||||
int child_indent = 0;
|
||||
MD_CodeLoc child_loc = MD_CodeLocFromNode(child);
|
||||
|
||||
+1
-1
@@ -1149,7 +1149,7 @@ MD_FUNCTION MD_String8 MD_PrevCommentFromNode(Node *node);
|
||||
MD_FUNCTION MD_String8 MD_NextCommentFromNode(Node *node);
|
||||
|
||||
// NOTE(rjf): For-Loop Helpers
|
||||
#define MD_EachNode(it, first) Node *it = (first); !MD_NodeIsNil(it); it = it->next
|
||||
#define each_node(it, first) Node *it = (first); !MD_NodeIsNil(it); it = it->next
|
||||
|
||||
//~ Error/Warning Helpers
|
||||
|
||||
|
||||
Reference in New Issue
Block a user