shithub: scc

Download patch

ref: d3f766992c8196bd3fdd8f34577598ecaedaa0d7
parent: 298745960166f4881f8203e9353b36a9f5603ef1
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Jul 2 17:22:28 EDT 2013

Catch a pointer to the current function

We need know where we are in the code, and having a pointer to the current
function allow us can check for example the returning value in a easy way.

--- a/decl.c
+++ b/decl.c
@@ -9,8 +9,8 @@
 #include "symbol.h"
 
 char parser_out_home;
+struct ctype *curfun;
 
-
 static void declarator(void);
 
 static void
@@ -140,15 +140,13 @@
 listdcl(register struct ctype *tp)
 {
 	do {
-		register  struct ctype *new;
-
 		declarator();
-		new = decl_type(tp);
-		if (!new->type) {
+		curfun = decl_type(tp);
+		if (!curfun->type) {
 			warning_error(options.implicit,
 				      "type defaults to 'int' in declaration of '%s'",
 				      yytext);
-		} else if (new->type == FTN && yytoken == '{') {
+		} else if (curfun->type == FTN && yytoken == '{') {
 			struct node *np = compound();
 			prtree(np);
 			putchar('\n');
--- a/flow.c
+++ b/flow.c
@@ -178,12 +178,11 @@
 _return(void)
 {
 	register struct node *np;
-	extern struct ctype *curfun;
 
 	expect(RETURN);
-	/* TODO: Check the type of the function, can be void */
 	np = expr();
 	expect(';');
+
 	return node1(ORETURN, np);
 }
 
--- a/symbol.h
+++ b/symbol.h
@@ -48,6 +48,7 @@
 	struct symbol *hash;
 };
 
+extern struct ctype *curfun;
 extern struct type tchar, tshort, tint, tulong, tllong, tvoid, tkeyword;
 extern struct type tfloat, tdouble, tldouble, tlong;