fix pretty printing and make commandline interface
[ccc.git] / ast.c
diff --git a/ast.c b/ast.c
index 597dfa6..372234e 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -4,7 +4,7 @@
 
 #include "util.h"
 #include "ast.h"
-#include "y.tab.h"
+#include "parse.h"
 
 static const char *binop_str[] = {
        [binor] = "||", [binand] = "&&", [eq] = "==", [neq] = "!=",
@@ -37,7 +37,7 @@ struct vardecl *vardecl(struct type *type, char *ident, struct expr *expr)
 }
 
 struct decl *decl_fun(char *ident, struct list *args, struct list *atypes,
-       struct type *rtype, struct list *vars, struct list *body)
+       struct type *rtype, struct list *body)
 {
        struct decl *res = safe_malloc(sizeof(struct decl));
        res->type = dfundecl;
@@ -47,8 +47,6 @@ struct decl *decl_fun(char *ident, struct list *args, struct list *atypes,
        res->data.dfun.atypes = (struct type **)
                list_to_array(atypes, &res->data.dfun.natypes, true);
        res->data.dfun.rtype = rtype;
-       res->data.dfun.vars = (struct vardecl **)
-               list_to_array(vars, &res->data.dfun.nvar, true);
        res->data.dfun.body = (struct stmt **)
                list_to_array(body, &res->data.dfun.nbody, true);
        return res;
@@ -330,8 +328,6 @@ void decl_print(struct decl *decl, int indent, FILE *out)
                        type_print(decl->data.dfun.rtype, out);
                }
                safe_fprintf(out, " {\n");
-               for (int i = 0; i<decl->data.dfun.nvar; i++)
-                       vardecl_print(decl->data.dfun.vars[i], indent+1, out);
                for (int i = 0; i<decl->data.dfun.nbody; i++)
                        stmt_print(decl->data.dfun.body[i], indent+1, out);
                pindent(indent, out);
@@ -531,9 +527,6 @@ void decl_free(struct decl *decl)
                        type_free(decl->data.dfun.atypes[i]);
                free(decl->data.dfun.atypes);
                type_free(decl->data.dfun.rtype);
-               for (int i = 0; i<decl->data.dfun.nvar; i++)
-                       vardecl_free(decl->data.dfun.vars[i]);
-               free(decl->data.dfun.vars);
                for (int i = 0; i<decl->data.dfun.nbody; i++)
                        stmt_free(decl->data.dfun.body[i]);
                free(decl->data.dfun.body);