ref: 0eef6fc79e97b9097d8bc5a1f0e93aa4248649b9
parent: 9c45c2b5f383585dedcede18b0d0cac97b27ab1c
author: Roberto E. Vargas Caballero <[email protected]>
date: Wed Sep 10 16:31:45 EDT 2014
Pass a storage class parameter to declaration This parameter simplifies all the logic of the code later.
--- a/cc2/parser.c
+++ b/cc2/parser.c
@@ -381,7 +381,7 @@
}
static Symbol *
-declaration(uint8_t t, char *token)
+declaration(uint8_t t, char class, char *token)
{
static Symbol *(*tbl[3])(char *)= {
[LOCAL] = local,
@@ -397,7 +397,7 @@
free(sym->name);
memset(sym, 0, sizeof(*sym));
sym->type = VAR;
- sym->u.v.sclass = token[0];
+ sym->u.v.sclass = class;
if ((s = strtok(NULL, "\t")) == NULL)
error(ESYNTAX);
@@ -411,7 +411,7 @@
static void
globdcl(char *token)
{
- Symbol *sym = declaration(GLOBAL, token);
+ Symbol *sym = declaration(GLOBAL, MEM, token);
switch (token[0]) {
case 'X':
@@ -439,7 +439,7 @@
static void
paramdcl(char *token)
{
- Symbol *sym = declaration(PARAMETER, token);
+ Symbol *sym = declaration(PARAMETER, AUTO, token);
sym->next = curfun->u.f.pars;
curfun->u.f.pars = sym;
}
@@ -447,7 +447,7 @@
static void
localdcl(char *token)
{
- Symbol *sym = declaration(LOCAL, token);
+ Symbol *sym = declaration(LOCAL, token[0], token);
sym->next = curfun->u.f.vars;
curfun->u.f.vars = sym;
}