scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit b41e00fe1e8913bd4e35ff3a913b67a9aaedb26f
parent 50be87310cc42377a409547fbb946f2750e5e925
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sun, 16 Nov 2014 12:44:33 -0500

Remove unneeded struct in symbol structure

This structure was not needed at all.

Diffstat:
Mcc1/cc1.h | 16+++++++---------
Mcc1/code.c | 14+++++++-------
Mcc1/decl.c | 26+++++++++++++-------------
Mcc1/expr.c | 2+-
Mcc1/stmt.c | 6+++---
Mcc1/symbol.c | 4++--
6 files changed, 33 insertions(+), 35 deletions(-)

diff --git a/cc1/cc1.h b/cc1/cc1.h @@ -58,15 +58,13 @@ struct symbol { uint8_t ctx; uint8_t ns; uint8_t token; - struct { - bool isglobal : 1; - bool isstatic : 1; - bool isauto : 1; - bool isregister : 1; - bool isdefined : 1; - bool isfield : 1; - bool isparameter : 1; - } s; + bool isglobal : 1; + bool isstatic : 1; + bool isauto : 1; + bool isregister : 1; + bool isdefined : 1; + bool isfield : 1; + bool isparameter : 1; union { int i; char *s; diff --git a/cc1/code.c b/cc1/code.c @@ -84,17 +84,17 @@ emitvar(Symbol *sym) { char c; - if (sym->s.isstatic && !sym->s.isglobal) + if (sym->isstatic && !sym->isglobal) c = 'T'; - else if (sym->s.isstatic && sym->s.isglobal) + else if (sym->isstatic && sym->isglobal) c = 'Y'; - else if (sym->s.isglobal) + else if (sym->isglobal) c = 'G'; - else if (sym->s.isregister) + else if (sym->isregister) c = 'R'; - else if (sym->s.isfield) + else if (sym->isfield) c = 'M'; - else if (sym->s.isparameter) + else if (sym->isparameter) c = 'P'; else c = 'A'; @@ -223,7 +223,7 @@ void emitfun(Symbol *sym) { printf("%c%d\tF\t%s\t{\n", - sym->s.isglobal ? 'G' : 'Y', sym->id, sym->name); + sym->isglobal ? 'G' : 'Y', sym->id, sym->name); } void diff --git a/cc1/decl.c b/cc1/decl.c @@ -238,7 +238,7 @@ invalid_type: static struct node * initializer(Symbol *sym) { - if (!sym->s.isdefined) + if (!sym->isdefined) error("'%s' initialized and declared extern", sym->name); if (accept('{')) { @@ -324,7 +324,7 @@ structdcl(void) do { sym = declarator(base, ID_EXPECTED, tagtype->ns); - sym->s.isfield = 1; + sym->isfield = 1; tp = sym->type; if (tp->op == FTN) error("invalid type in struct/union"); @@ -387,7 +387,7 @@ parameter(void) if ((tp = specifier(&sclass)) == voidtype) return tp; sym = declarator(tp, ID_ACCEPTED, NS_IDEN); - sym->s.isparameter = 1; + sym->isparameter = 1; tp = sym->type; if (tp->op == FTN) error("incorrect function type for a function parameter"); @@ -395,10 +395,10 @@ parameter(void) tp = mktype(tp->type, PTR, 0, NULL); switch (sclass) { case REGISTER: - sym->s.isregister = 1; + sym->isregister = 1; break; case 0: - sym->s.isauto = 1; + sym->isauto = 1; break; default: error("bad storage class in function parameter"); @@ -426,13 +426,13 @@ decl(void) sym->token = TYPEIDEN; continue; case STATIC: - sym->s.isstatic = 1; + sym->isstatic = 1; break; case EXTERN: - sym->s.isdefined = 0; + sym->isdefined = 0; break; case REGISTER: - sym->s.isregister = 1; + sym->isregister = 1; if (isfun) goto bad_function; break; @@ -441,7 +441,7 @@ decl(void) goto bad_function; /* passtrough */ default: - sym->s.isauto = 1; + sym->isauto = 1; break; } if (accept('=')) @@ -486,17 +486,17 @@ extdecl(void) do { sym = declarator(base, ID_EXPECTED, NS_IDEN); tp = sym->type; - sym->s.isstatic = 1; - sym->s.isglobal= 1; + sym->isstatic = 1; + sym->isglobal= 1; switch (sclass) { case REGISTER: case AUTO: error("incorrect storage class for file-scope declaration"); case STATIC: - sym->s.isglobal = 0; + sym->isglobal = 0; break; case EXTERN: - sym->s.isdefined = 0; + sym->isdefined = 0; break; case TYPEDEF: sym->token = TYPEIDEN; diff --git a/cc1/expr.c b/cc1/expr.c @@ -377,7 +377,7 @@ address(char op, Node *np) { if (!np->b.lvalue) error("lvalue required in unary expression"); - if (np->b.symbol && np->u.sym->s.isregister) + if (np->b.symbol && np->u.sym->isregister) error("address of register variable '%s' requested", yytext); return unarycode(op, mktype(np->type, PTR, 0, NULL), np); } diff --git a/cc1/stmt.c b/cc1/stmt.c @@ -31,15 +31,15 @@ label(char *s, char define) if ((sym = lookup(s, NS_LABEL)) != NULL) { if (define) { - if (sym->s.isdefined) + if (sym->isdefined) error("label '%s' already defined", s); - sym->s.isdefined = 1; + sym->isdefined = 1; } return sym; } sym = install(s, NS_LABEL); - sym->s.isdefined = define; + sym->isdefined = define; return sym; } diff --git a/cc1/symbol.c b/cc1/symbol.c @@ -38,7 +38,7 @@ freesyms(uint8_t ns) for (sym = tbl->head; sym; sym = next) { if (sym->ctx <= curctx) break; - if (ns == NS_LABEL && !sym->s.isdefined) + if (ns == NS_LABEL && !sym->isdefined) error("label '%s' is not defined", sym->name); if (ns == NS_TAG) sym->type->defined = 0; @@ -94,7 +94,7 @@ install(char *s, uint8_t ns) sym->ctx = curctx; sym->token = IDEN; sym->id = (curctx) ? ++localcnt : ++globalcnt; - sym->s.isdefined = 1; + sym->isdefined = 1; sym->ns = ns; tbl = &symtab[(ns > NS_STRUCTS) ? NS_STRUCTS : ns]; sym->next = tbl->head;