scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 6a98886da0c2c8b15616e2da8033c938a528c715
parent ee2dcc9ef027dedf4a2b030464ea7c8c66a359e5
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed,  3 Jul 2013 16:45:43 +0200

Move curfun to flow.c

curfun is a useful variable which allow us to can access to the
current function and could check the return type of the function. This
information is only needed in flow.c, and it is the best place for
knowing when we are defining a new function (due to function()).

Diffstat:
Mdecl.c | 7+++----
Mflow.c | 4+++-
Msymbol.h | 1-
3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/decl.c b/decl.c @@ -9,7 +9,6 @@ #include "symbol.h" char parser_out_home; -struct ctype *curfun; static struct symbol *cursym; static void declarator(void); @@ -140,12 +139,12 @@ listdcl(register struct ctype *tp) { do { declarator(); - curfun = decl_type(tp); - if (!curfun->type) { + tp = decl_type(tp); + if (!tp->type) { warning_error(options.implicit, "type defaults to 'int' in declaration of '%s'", yytext); - } else if (curfun->type == FTN && yytoken == '{') { + } else if (tp->type == FTN && yytoken == '{') { function(cursym); return; } diff --git a/flow.c b/flow.c @@ -12,6 +12,7 @@ static struct node *stmt(void); static unsigned char blocks[NR_BLOCK]; static unsigned char *blockp = blocks; +static struct symbol *curfun; static void push(register unsigned char b) @@ -271,10 +272,11 @@ stmt(void) } void -function(struct symbol *sym) +function(register struct symbol *sym) { register struct node *np; + curfun = sym; np = node2(OFTN, nodesym(sym), compound()); prtree(np); putchar('\n'); diff --git a/symbol.h b/symbol.h @@ -50,7 +50,6 @@ struct symbol { struct symbol *hash; }; -extern struct ctype *curfun; extern struct type tchar, tshort, tint, tulong, tllong, tvoid, tkeyword; extern struct type tfloat, tdouble, tldouble, tlong;