scc

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

commit 5d4796cb4d72a844fd0e6a002e0056e83b34b468
parent 8962686ad60fd7d5665ff343360a7b85194bb820
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sun,  1 Jul 2012 18:34:58 +0200

Removed pointers from types.

Original idea was having an unique tree where all the types were built. But
this idea is not possible due to the pointer modifiers. The modifiers can
appears in any order, so a "int *cont volatile" is the same that a
"int *volatile const", but using the actual tree system, they will be
represented using different pointers, so the system is broken. After this
patch the system is a continuos memory leak, but this is not important in
this moment.

Diffstat:
Msymbol.h | 6------
Mtypes.c | 25+------------------------
2 files changed, 1 insertion(+), 30 deletions(-)

diff --git a/symbol.h b/symbol.h @@ -41,12 +41,6 @@ struct ctype { struct type { unsigned char op; struct type *base; - struct type *ary; /* array */ - struct type *ptr; /* pointer */ - struct type *ftn; /* function */ - struct type *cnst; /* const */ - struct type *vltl; /* volatile */ - struct type *rstr; /* restricted */ union { size_t nelem; /* size of array */ diff --git a/types.c b/types.c @@ -25,34 +25,11 @@ static unsigned char *stackp = stack; static struct type * mktype(register struct type *base, unsigned char op) { - register struct type **ptr, *nt; + register struct type *nt; assert(op == PTR || op == ARY || op == FTN || op == VOLATILE || op == RESTRICT || op == CONST); - switch (op) { - case PTR: - ptr = &base->ptr; - break; - case ARY: - ptr = &base->ary; - break; - case FTN: - ptr = &base->ftn; - break; - case VOLATILE: - ptr = &base->vltl; - break; - case RESTRICT: - ptr = &base->rstr; - break; - case CONST: - ptr = &base->cnst; - break; - } - if (*ptr) return *ptr; - nt = xcalloc(sizeof(*base), 1); - *ptr = nt; nt->op = op; nt->base = base; return nt;