]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
Relocate AST stuff
authorDale Weiler <killfieldengine@gmail.com>
Sun, 1 Dec 2013 15:12:27 +0000 (10:12 -0500)
committerDale Weiler <killfieldengine@gmail.com>
Sun, 1 Dec 2013 15:12:27 +0000 (10:12 -0500)
ast.c
ast.h
parser.c

diff --git a/ast.c b/ast.c
index f7a4fb3c59dd8276213bfdc7127eba39940f10d8..3cd92b80d452873d9c3fe90da2e73be595d3cfd8 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -3447,7 +3447,36 @@ error:
     return false;
 }
 
-/* iterator functions */
+/* AST iterator + iterator functions */
+void ast_iterator_begin(ast_iterator *iter, ast_node *start) {
+    iter->head = start;
+    iter->at = &iter->head;
+    iter->path = NULL;
+    vec_push(iter->path, iter->at);
+}
+
+void ast_iterator_delete(ast_iterator *iter) {
+    if (iter->path)
+        vec_free(iter->path);
+}
+
+ast_node *ast_iterator_next(ast_iterator *iter) {
+    size_t depth = vec_size(iter->path);
+    while (depth) {
+        ast_node **last = vec_last(iter->path);
+        ast_node **next = ast_next_child(*last, iter->at);
+        if (next) {
+            vec_push(iter->path, next);
+            iter->at = next;
+            return *next;
+        }
+        iter->at = last;
+        vec_pop(iter->path);
+        --depth;
+    }
+    return NULL;
+}
+
 static ast_node** ast_member_next_child(ast_member *self, ast_node **cur) {
     (void)self; (void)cur;
     return NULL;
diff --git a/ast.h b/ast.h
index e99b378b00c2bdd8dc3bdc2e6548b723ddbdd73c..0f8105fd3fe911073a166fbbd7b46d9bd4340636 100644 (file)
--- a/ast.h
+++ b/ast.h
@@ -708,4 +708,15 @@ bool ast_generate_accessors(ast_value *asvalue, ir_builder *ir);
  * all the flags.
  */
 typedef int static_assert_is_ast_flag_safe [((AST_FLAG_LAST) <= (ast_flag_t)(-1)) ? 1 : -1];
+
+/* AST iterator */
+typedef struct {
+    ast_node ***path;
+    ast_node **at;
+    ast_node *head;
+} ast_iterator;
+
+void      ast_iterator_begin(ast_iterator *iter, ast_node *start);
+void      ast_iterator_delete(ast_iterator *iter);
+ast_node *ast_iterator_next(ast_iterator *iter);
 #endif
index f6f02fe119f5c73f3d9596fbd127c3d0876350c2..004d8a39ff1b10f6bfc5ac6ab6396a4e264097ad 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -6155,73 +6155,6 @@ void parser_cleanup(parser_t *parser)
     mem_d(parser);
 }
 
-typedef struct {
-    ast_node ***path;
-    ast_node **at;
-    ast_node *head;
-} ast_iterator;
-
-static void ast_iterator_begin(ast_iterator *iter, ast_node *start)
-{
-    iter->head = start;
-    iter->at = &iter->head;
-    iter->path = NULL;
-    vec_push(iter->path, iter->at);
-}
-
-static void ast_iterator_delete(ast_iterator *iter)
-{
-    if (iter->path) {
-        vec_free(iter->path);
-    }
-}
-
-static ast_node* ast_iterator_next(ast_iterator *iter)
-{
-    size_t depth = vec_size(iter->path);
-    while (depth) {
-        ast_node **last = vec_last(iter->path);
-        ast_node **next = ast_next_child(*last, iter->at);
-        if (next) {
-            vec_push(iter->path, next);
-            iter->at = next;
-            return *next;
-        }
-        /* back up */
-        iter->at = last;
-        vec_pop(iter->path);
-        --depth;
-    }
-    return NULL;
-}
-
-static void traverse_that_thing(ast_function *fun)
-{
-#if 1
-    ast_node    *at;
-    size_t       depth;
-    ast_iterator iter;
-    ast_iterator_begin(&iter, (ast_node*)fun);
-
-    for (at = (ast_node*)fun;
-         at;
-         at = ast_iterator_next(&iter))
-    {
-        for (depth = vec_size(iter.path); depth; --depth)
-            con_out("> ");
-        con_out("ast_%s (%p)\n", ast_node_type_name[at->nodetype], at);
-    }
-
-    ast_iterator_delete(&iter);
-#else
-    ast_iterator iter = { NULL, (ast_node*)fun };
-    ast_iterator_begin(&iter, (ast_node*)fun);
-    if (!fun)
-        ast_iterator_next(&iter);
-    ast_iterator_delete(&iter);
-#endif
-}
-
 bool parser_finish(parser_t *parser, const char *output)
 {
     size_t i;
@@ -6368,7 +6301,6 @@ bool parser_finish(parser_t *parser, const char *output)
             ir_builder_delete(ir);
             return false;
         }
-        traverse_that_thing(parser->functions[i]);
     }
 
     parser_remove_ast(parser);