scc

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

commit d00c0a144ba4565dfc73b8429457aba03faf2264
parent 2f555ae12510f6214164f4e85f49ea2127d3c935
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 15 Sep 2015 12:25:16 +0200

Make type qualifier flags

A declaration can have more of one type qualifier (for example const and
volatile), so, it is very useful if the representation of these tokens
are flags. It is also added idempotent for all the type qualifiers
(restrict to).

Diffstat:
Mcc1/cc1.h | 11+++++------
Mcc1/decl.c | 4+---
2 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/cc1/cc1.h b/cc1/cc1.h @@ -159,10 +159,9 @@ enum { ISEMITTED = 1024, ISDEFINED = 2048, ISSTRING = 4096, - ISTYPEDEF = 8192 + ISTYPEDEF = 8192 }; - /* lexer mode, compiler or preprocessor directive */ enum { CCMODE, @@ -171,7 +170,10 @@ enum { /* input tokens */ enum tokens { - TQUALIFIER = 128, + CONST = 1, /* type qualifier tokens are used as flags */ + RESTRICT = 2, + VOLATILE = 4, + TQUALIFIER = 128, TYPE, IDEN, SCLASS, @@ -220,9 +222,6 @@ enum tokens { LONG, LLONG, COMPLEX, - CONST, - VOLATILE, - RESTRICT, TYPEDEF, EXTERN, STATIC, diff --git a/cc1/decl.c b/cc1/decl.c @@ -262,7 +262,7 @@ static Type * specifier(int *sclass) { Type *tp = NULL; - unsigned spec, qlf, sign, type, cls, size; + int spec, qlf, sign, type, cls, size, mask; spec = qlf = sign = type = cls = size = 0; @@ -275,8 +275,6 @@ specifier(int *sclass) p = &cls; break; case TQUALIFIER: - if (qlf && qlf != RESTRICT) - errorp("invalid type specification"); qlf |= yylval.token; next(); continue;