ref: d3a0477d93e577b3a2d9e243fc3d3545f180ba85
parent: 03f23451b61d962da0add262a741e9ac0d15d0bc
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Thu Jun 14 17:16:49 EDT 2012
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.
--- a/keyword.c
+++ b/keyword.c
@@ -55,6 +55,6 @@
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;
}
}
--- a/lex.c
+++ b/lex.c
@@ -37,7 +37,6 @@
ungetc(ch, yyin);
yyval.sym = sym = install(NULL, 0);
sym->val = atoi(yytext);
- sym->type = T_INT;
return CONSTANT;
}
@@ -57,7 +56,7 @@
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;
--- a/symbol.c
+++ b/symbol.c
@@ -58,6 +58,7 @@
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;
--- 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;