diff --git a/tools/qfcc/source/pr_lex.c b/tools/qfcc/source/pr_lex.c index 18c3f5a02..d0a60e980 100644 --- a/tools/qfcc/source/pr_lex.c +++ b/tools/qfcc/source/pr_lex.c @@ -720,6 +720,56 @@ PR_ParseName (void) return ident; } +void +PR_PrintType (type_t *type) +{ + int i; + if (!type) { + printf("(null)"); + return; + } + switch (type->type) { + case ev_void: + printf ("void"); + break; + case ev_string: + printf ("string"); + break; + case ev_float: + printf ("float"); + break; + case ev_vector: + printf ("vector"); + break; + case ev_entity: + printf ("entity"); + break; + case ev_field: + printf ("."); + PR_PrintType (type->aux_type); + break; + case ev_func: + PR_PrintType (type->aux_type); + printf ("("); + for (i = 0; i < type->num_parms; i++) { + PR_PrintType (type->parm_types[i]); + if (i < type->num_parms - 1) + printf (","); + } + if (type->num_parms == -1) + printf ("..."); + printf (")"); + break; + case ev_pointer: + printf ("pointer to "); + PR_PrintType (type->aux_type); + break; + default: + printf ("unknown type %d", type->type); + break; + } +} + /* PR_FindType @@ -732,13 +782,27 @@ PR_FindType (type_t *type) def_t *def; type_t *check; int i; - +extern int lineno; + printf("%-5d ", lineno); + PR_PrintType (type); + puts(""); + for (check = pr.types; check; check = check->next) { + PR_PrintType (check); + puts(""); + } + puts(""); for (check = pr.types; check; check = check->next) { if (check->type != type->type || check->aux_type != type->aux_type || check->num_parms != type->num_parms) continue; + if (check->type != ev_func) + return check; + + if (check->num_parms == -1) + return check; + for (i = 0; i < type->num_parms; i++) if (check->parm_types[i] != type->parm_types[i]) break; diff --git a/tools/qfcc/source/qc-parse.y b/tools/qfcc/source/qc-parse.y index ab6c3a557..667fae76a 100644 --- a/tools/qfcc/source/qc-parse.y +++ b/tools/qfcc/source/qc-parse.y @@ -27,7 +27,7 @@ typedef struct { %} %union { - scope_t *scope; + scope_t scope; def_t *def; type_t *type; expr_t *expr; @@ -108,17 +108,18 @@ def_item : def_name opt_initializer | '(' { - $$->scope = pr_scope; - $$->type = current_type; - $$->pscope = param_scope.scope_next; + $$.scope = pr_scope; + $$.type = current_type; + $$.pscope = param_scope.scope_next; + param_scope.scope_next = 0; pr_scope = ¶m_scope; } param_list { $$ = param_scope.scope_next; - current_type = $2->type; - param_scope.scope_next = $2->pscope; - pr_scope = $2->scope; + current_type = $2.type; + param_scope.scope_next = $2.pscope; + pr_scope = $2.scope; } ')' { current_type = parse_params ($4); } def_name opt_definition { @@ -312,8 +313,8 @@ parse_params (def_t *parms) i = 1; do { //puts (parms->name); - strcpy (pr_parm_names[new.num_parms - 1], parms->name); - new.parm_types[new.num_parms - 1] = parms->type; + strcpy (pr_parm_names[new.num_parms - i], parms->name); + new.parm_types[new.num_parms - i] = parms->type; i++; parms = parms->next; } while (parms);