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;
* 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
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;
ir_builder_delete(ir);
return false;
}
- traverse_that_thing(parser->functions[i]);
}
parser_remove_ast(parser);