commit 4e770c4791211178f97399cb864a99e319eccbdf
parent 529349a0c7457739a1d78497a0ccc7e7d7b20dd7
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Thu, 31 Oct 2013 08:20:41 +0100
Use a stack for symbol definition
We have nested declarations due to the functions and to the structs,
so cursym can change the value before of the end of the declaration,
and it can cause a lot of problems (we are assigning the type
to other symbol). The correct solution is using a stack.
Diffstat:
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/decl.c b/decl.c
@@ -9,7 +9,13 @@
#include "symbol.h"
char parser_out_home;
-
+/*
+ * Number of nested declarations:
+ * Number of nested struct declarations
+ * +1 for the function declaration
+ * +1 for the field declaration
+ */
+static struct symbol *symstack[NR_STRUCT_LEVEL + 1 + 1], **symstackp = symstack;
static struct symbol *cursym;
static unsigned char nr_tags = NS_TAG;
static unsigned char nested_tags;
@@ -23,7 +29,8 @@ directdcl(register struct ctype *tp, unsigned char ns)
declarator(tp, ns);
expect(')');
} else if (yytoken == IDEN) {
- cursym = lookup(yytext, ns);
+ /* we can't overflow due to the check in structdcl */
+ *symstackp++ = cursym = lookup(yytext, ns);
if (!cursym->ctype)
cursym->ctx = curctx;
else if (cursym->ctx == curctx)
@@ -308,6 +315,7 @@ listdcl(struct ctype *base, struct storage *store)
fun = tp->type == FTN && yytoken == '{';
aux = fun ? function(cursym) : initializer(tp);
addstmt(&c, node(ODEF, np, aux));
+ cursym = *--symstackp;
} while (!fun && accept(','));
if (!fun)