#include "util.h"
#include "ast.h"
-#include "y.tab.h"
+#include "parse.h"
static const char *binop_str[] = {
[binor] = "||", [binand] = "&&", [eq] = "==", [neq] = "!=",
}
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;
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;
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);
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);