scc

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

commit 9a911ac4ee93084336a8f55d6815615b09b6b722
parent a8b9e699e5f953f3521cbe2e3e9ad431f307823c
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 25 Mar 2014 15:52:26 +0100

Add type macros

These macros allow us to known what kind of symbol we are handle.

Diffstat:
Msymbol.h | 11++++++++---
Mtokens.h | 53+++++++++++++++++++++++++++++++----------------------
2 files changed, 39 insertions(+), 25 deletions(-)

diff --git a/symbol.h b/symbol.h @@ -97,9 +97,14 @@ extern struct ctype *voidtype, *doubletype, *cdoubletype, *idoubletype, *ldoubletype, *cldoubletype,*ildoubletype; -#define ISQUAL(t) ((t)->op & TQUALIFIER) -#define UNQUAL(t) (ISQUAL(t) ? (t)->type : (t)) -#define ISFUN(t) (UNQUAL(t)->op == FTN) +#define UNQUAL(t) (ISQUAL(t) ? (t)->type : (t)) +#define BTYPE(t) (UNQUAL(t)->op) +#define ISFUN(t) ((t)->op == FTN) +#define ISPTR(t) ((t)->op == PTR) +#define ISARITH(t) ((t)->op & ARITH) +#define ISADDR(t) ((t)->op & POINTER) +#define ISRECORD(t) ((t)->op & RECORD) +#define ISQUAL(t) ((t)->op & TQUALIFIER) #endif diff --git a/tokens.h b/tokens.h @@ -5,28 +5,37 @@ # include <stdbool.h> #endif -#define FLOAT 1 -#define INT 2 -#define BOOL 3 -#define PTR 4 -#define ARY 5 -#define FTN 6 - -#define VOID 7 -#define STRUCT 8 -#define UNION 9 -#define ENUM 10 -#define TYPENAME 11 - -#define CHAR 12 -#define DOUBLE 13 -#define SHORT 14 -#define LONG 15 - -#define COMPLEX 16 -#define IMAGINARY 17 -#define UNSIGNED 18 -#define SIGNED 19 +#define ARITH 8 +#define RECORD 16 +#define POINTER 32 +#define ATYPE(x) (ARITH | (x)) +#define RTYPE(x) (RECORD | (x)) +#define PTYPE(x) (POINTER| (x)) + +#define FTN 1 +#define ENUM 2 +#define TYPENAME 3 +#define VOID 4 + +#define FLOAT ATYPE(1) +#define INT ATYPE(2) +#define BOOL ATYPE(3) + +#define STRUCT RTYPE(1) +#define UNION RTYPE(2) + +#define PTR PTYPE(1) +#define ARY PTYPE(2) + +#define CHAR (ARY+1) +#define DOUBLE (ARY+2) +#define SHORT (ARY+3) +#define LONG (ARY+4) + +#define COMPLEX (ARY+5) +#define IMAGINARY (ARY+6) +#define UNSIGNED (ARY+7) +#define SIGNED (ARY+8) #define CONST (1<<0) #define VOLATILE (1<<1)