shithub: scc

Download patch

ref: 6a98886da0c2c8b15616e2da8033c938a528c715
parent: ee2dcc9ef027dedf4a2b030464ea7c8c66a359e5
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed Jul 3 12:45:43 EDT 2013

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()).

--- 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 @@
 {
 	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;
 		}
--- a/flow.c
+++ b/flow.c
@@ -12,6 +12,7 @@
 
 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 @@
 }
 
 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');
--- a/symbol.h
+++ b/symbol.h
@@ -50,7 +50,6 @@
 	struct symbol *hash;
 };
 
-extern struct ctype *curfun;
 extern struct type tchar, tshort, tint, tulong, tllong, tvoid, tkeyword;
 extern struct type tfloat, tdouble, tldouble, tlong;
 
--