scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit 97c2741373af5f85c0538a671c51d22bb3ef1d97
parent 2d9f4dcdec7a6a85817ec1a58b7f106aa9f43b0d
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri,  8 Aug 2014 16:08:57 +0200

Fix parsing of 'T' elements

'T' is used for static variables that are not global, and they
can appear in outer contex or in the context of a function. If
they appear in the context of function they have to be stored
in the local pool, and if they appear in the outer then they
must be stored in the global spool.

Diffstat:
cc2/cc2.h | 1+
cc2/parser.c | 6++++--
2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/cc2/cc2.h b/cc2/cc2.h @@ -1,5 +1,6 @@ typedef struct { + char public; union { struct { char type; diff --git a/cc2/parser.c b/cc2/parser.c @@ -89,7 +89,7 @@ static void variable(char *token) { Symbol *sym; - char op; + char op, public = 0; Node *np = newnode(); switch (token[0]) { @@ -102,15 +102,17 @@ variable(char *token) op = REGISTER; break; case 'T': - sym = local(token); + sym = (funbody) ? local(token) : global(token); op = STATIC; break; case 'G': sym = global(token); op = STATIC; + public = 1; break; } + sym->public = public; np->u.sym = sym; np->op = op; np->type = sym->u.v.type;