ref: 5d4796cb4d72a844fd0e6a002e0056e83b34b468
parent: 8962686ad60fd7d5665ff343360a7b85194bb820
author: Roberto E. Vargas Caballero <[email protected]>
date: Sun Jul 1 14:34:58 EDT 2012
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.
--- a/symbol.h
+++ b/symbol.h
@@ -41,12 +41,6 @@
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 */
--- a/types.c
+++ b/types.c
@@ -25,34 +25,11 @@
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;