scc

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

commit 67dd2d72eacab11d263530d495d0019168ea9d6e
parent da40be16dc3adcabf313f467b6ac91bca512038b
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 24 Sep 2013 22:22:45 +0200

Add bit fields

Bit fields are small integers with a varible size of bits. C99
defines that bit fields can be of type int or type bool.

Diffstat:
Mdecl.c | 12++++++++++++
Mtokens.h | 2+-
Mtypes.c | 2+-
3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/decl.c b/decl.c @@ -122,6 +122,18 @@ struct_dcl(unsigned char ns) do { declarator(base, ns); tp = decl_type(base); + if (accept(':')) { + expect(CONSTANT); + switch (tp->type) { + case INT: case BOOL: + tp = btype(NULL, BITFLD); + tp->len = yyval.sym->val; + break; + default: + error("bit-field '%s' has invalid type", + cursym->name); + } + } (cursym->ctype = tp)->refcnt++; } while (accept(',')); diff --git a/tokens.h b/tokens.h @@ -11,7 +11,7 @@ enum tokens { /* types */ INT = 1, CHAR, FLOAT, LONG, LLONG, SHORT, VOID, DOUBLE, LDOUBLE, STRUCT, UNION, ENUM, BOOL, ARY, PTR, FTN, - COMPLEX, IMAGINARY, + COMPLEX, IMAGINARY, BITFLD, /* storage specifier */ TYPEDEF, EXTERN, STATIC, AUTO, REGISTER, /* type qualifier */ diff --git a/types.c b/types.c @@ -93,7 +93,7 @@ btype(struct ctype *tp, unsigned char tok) type = tp->type; switch (tok) { - case VOID: case BOOL: case STRUCT: case UNION: case ENUM: + case VOID: case BOOL: case STRUCT: case UNION: case ENUM: case BITFLD: if (type) goto two_or_more;; type = tok;