commit d3f766992c8196bd3fdd8f34577598ecaedaa0d7
parent 298745960166f4881f8203e9353b36a9f5603ef1
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Tue, 2 Jul 2013 21:22:28 +0200
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.
Diffstat:
3 files changed, 6 insertions(+), 8 deletions(-)
diff --git a/decl.c b/decl.c
@@ -9,7 +9,7 @@
#include "symbol.h"
char parser_out_home;
-
+struct ctype *curfun;
static void declarator(void);
@@ -140,15 +140,13 @@ static void
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');
diff --git a/flow.c b/flow.c
@@ -178,12 +178,11 @@ static struct node *
_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);
}
diff --git a/symbol.h b/symbol.h
@@ -48,6 +48,7 @@ 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;