scc

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

commit d3a0477d93e577b3a2d9e243fc3d3545f180ba85
parent 03f23451b61d962da0add262a741e9ac0d15d0bc
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 14 Jun 2012 21:16:49 +0200

Added ctype struct

This struct is used for store all the information of the symbol type. This
is the first step in order to remove the qualifiers and storage information
from the type struct, because this is information of the symbol, not of the
type.

Diffstat:
Mkeyword.c | 2+-
Mlex.c | 3+--
Msymbol.c | 1+
Msymbol.h | 27++++++++++++++++++++++++++-
4 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/keyword.c b/keyword.c @@ -55,6 +55,6 @@ void init_keywords(void) for (bp = keywords; bp->str; bp++) { sym = install(bp->str, hashfun(bp->str)); sym->tok = bp->tok; - sym->type = T_KWD; + sym->ns = NS_KEYWORD; } } diff --git a/lex.c b/lex.c @@ -37,7 +37,6 @@ static char number(void) ungetc(ch, yyin); yyval.sym = sym = install(NULL, 0); sym->val = atoi(yytext); - sym->type = T_INT; return CONSTANT; } @@ -57,7 +56,7 @@ static unsigned char iden(void) error("identifier too long %s", yytext); *bp = '\0'; ungetc(ch, yyin); - if ((sym = lookup(yytext, yyhash)) && sym->type == T_KWD) + if ((sym = lookup(yytext, yyhash)) && sym->ns == NS_KEYWORD) return sym->tok; yyval.sym = sym; return IDEN; diff --git a/symbol.c b/symbol.c @@ -58,6 +58,7 @@ struct symbol *install(const char *s, unsigned char key) if (s) { sym->str = xstrdup(s); + sym->ns = NS_IDEN; head = &iden_hash.buf[key & NR_SYM_HASH-1]; next = head->h_next; sym->h_next = next; diff --git a/symbol.h b/symbol.h @@ -3,10 +3,35 @@ #ifndef SYMBOL_H #define SYMBOL_H +#if ! __bool_true_false_are_defined +# include <stdbool.h> +#endif + +enum namespace { + NS_IDEN, + NS_KEYWORD, + NS_STRUCT, + NS_LABEL, + NS_TYPEDEF +}; + struct type; +struct symbol; + +struct ctype { + bool c_typedef : 1; + bool c_extern : 1; + bool c_static : 1; + bool c_auto : 1; + bool c_register : 1; + bool c_const : 1; + bool c_volatile : 1; + struct type *base; +}; struct symbol { - struct type *type; + struct ctype ctype; + unsigned char ns; union { struct { char *str;