From 1452da676d007df297658722277d984e649df8a8 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 2 Feb 2011 15:07:44 +0900 Subject: [PATCH] Allow types to be built from the outside in. This is required for C style decl processing. --- tools/qfcc/include/type.h | 12 ++++++++++++ tools/qfcc/source/type.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/tools/qfcc/include/type.h b/tools/qfcc/include/type.h index 69065856c..29c3cbfaa 100644 --- a/tools/qfcc/include/type.h +++ b/tools/qfcc/include/type.h @@ -128,6 +128,18 @@ extern struct symtab_s *quaternion_struct; struct dstring_s; type_t *new_type (void); + +/** Append a type to the end of a type chain. + + The type chain must be made up of only field, pointer, function and array + types, as other types do not have auxiliary type fields. + + \param type The type chain to which the type will be appended. + \param new The type to be appended. May be any type. + \return The type chain with the type appended at the deepest + level. +*/ +type_t *append_type (type_t *type, type_t *new); type_t *find_type (type_t *new); void new_typedef (const char *name, type_t *type); type_t *field_type (type_t *aux); diff --git a/tools/qfcc/source/type.c b/tools/qfcc/source/type.c index 2f48c74e1..5722d7123 100644 --- a/tools/qfcc/source/type.c +++ b/tools/qfcc/source/type.c @@ -120,6 +120,42 @@ new_type (void) return type; } +type_t * +append_type (type_t *type, type_t *new) +{ + type_t **t = &type; + + while (*t) { + switch ((*t)->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: + internal_error (0, "append to basic type"); + case ev_field: + case ev_pointer: + t = &(*t)->t.fldptr.type; + break; + case ev_func: + t = &(*t)->t.func.type; + break; + case ev_invalid: + if ((*t)->ty == ty_array) + t = &(*t)->t.array.type; + else + internal_error (0, "append to object type"); + break; + } + } + *t = new; + return type; +} + static int types_same (type_t *a, type_t *b) {