ref: bb37ffe1e43c9fa3c8475807c801f9e228f9100a
parent: 4ed32812fd0a83d1bd86fb41f5c4531a6c477148
author: Roberto E. Vargas Caballero <[email protected]>
date: Wed Jul 3 12:14:39 EDT 2013
Add function operator This operator marks when a function body is generated.
--- a/decl.c
+++ b/decl.c
@@ -146,10 +146,7 @@
"type defaults to 'int' in declaration of '%s'",
yytext);
} else if (curfun->type == FTN && yytoken == '{') {
- struct node *np = compound();
- prtree(np);
- putchar('\n');
- freesyms();
+ function(cursym);
return;
}
} while (accept(','));
--- a/flow.c
+++ b/flow.c
@@ -230,6 +230,22 @@
}
static struct node *
+compound(void)
+{
+ register struct node *np = nodecomp();
+
+ expect('{');
+ new_ctx();
+ while (decl())
+ /* nothing */;
+ while (!accept('}'))
+ addstmt(np, stmt());
+ del_ctx();
+
+ return np;
+}
+
+static struct node *
stmt(void)
{
register struct node *np;
@@ -254,18 +270,13 @@
return np;
}
-struct node *
-compound(void)
+void
+function(struct symbol *sym)
{
- register struct node *np = nodecomp();
+ register struct node *np;
- expect('{');
- new_ctx();
- while (decl())
- /* nothing */;
- while (!accept('}'))
- addstmt(np, stmt());
- del_ctx();
-
- return np;
+ np = node2(OFTN, nodesym(sym), compound());
+ prtree(np);
+ putchar('\n');
+ freesyms();
}
--- a/syntax.h
+++ b/syntax.h
@@ -12,16 +12,16 @@
OA_MOD, OA_ADD, OA_SUB, OA_SHL, OA_SHR, OA_AND,
OA_XOR, OA_OR, OSYM, OCOMP, OSWITCH, OIF, OFOR,
OFEXP, ODO, OWHILE, OLABEL, OGOTO, OBREAK, OCONT,
- ORETURN, OCASE, ODEFAULT
+ ORETURN, OCASE, ODEFAULT, OFTN
};
struct node;
struct symbol;
-extern struct node *compound(void);
extern struct node *expr(void);
extern unsigned char decl(void);
extern void type_name(void);
+extern void function(struct symbol *sym);
extern struct node *node3(unsigned char op,
struct node *l, struct node *i, struct node *r);
--- a/tree.c
+++ b/tree.c
@@ -189,7 +189,8 @@
[OCONT] = {1, "cont"},
[ORETURN] = {1, "return"},
[OCASE] = {1, "case"},
- [ODEFAULT] = {1, "default"}
+ [ODEFAULT] = {1, "default"},
+ [OFTN] = {2, "function"}
};
if (!np) {
fputs(" nil", stdout);
--- a/types.c
+++ b/types.c
@@ -74,7 +74,6 @@
{
while (stackp != stack)
tp = mktype(tp, *--stackp);
- ptype(tp);
return tp;
}