diff --git a/tools/qfcc/include/type.h b/tools/qfcc/include/type.h index 29c3cbfaa..961a839ce 100644 --- a/tools/qfcc/include/type.h +++ b/tools/qfcc/include/type.h @@ -74,6 +74,7 @@ typedef struct type_s { struct class_s *class; } t; struct type_s *next; + int freeable; } type_t; typedef struct { @@ -128,6 +129,7 @@ extern struct symtab_s *quaternion_struct; struct dstring_s; type_t *new_type (void); +void free_type (type_t *type); /** Append a type to the end of a type chain. diff --git a/tools/qfcc/source/type.c b/tools/qfcc/source/type.c index 5722d7123..41a2ecbd3 100644 --- a/tools/qfcc/source/type.c +++ b/tools/qfcc/source/type.c @@ -117,9 +117,43 @@ new_type (void) { type_t *type; ALLOC (1024, type_t, types, type); + type->freeable = 1; return type; } +void +free_type (type_t *type) +{ + if (!type || !type->freeable) + return; + switch (type->type) { + case ev_void: + case ev_string: + case ev_float: + case ev_vector: + case ev_entity: + case ev_type_count: + case ev_quat: + case ev_integer: + case ev_short: + break; + case ev_field: + case ev_pointer: + free_type (type->t.fldptr.type); + break; + case ev_func: + free_type (type->t.func.type); + break; + case ev_invalid: + if (type->ty == ty_array) + free_type (type->t.array.type); + break; + } + memset (type, 0, sizeof (type)); + type->next = free_types; + free_types = type; +} + type_t * append_type (type_t *type, type_t *new) { @@ -226,6 +260,7 @@ find_type (type_t *type) // allocate a new one check = new_type (); *check = *type; + check->freeable = 0; chain_type (check);