From d75c35ba30221f694a6e3dadce11461c2efffee2 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sun, 13 Feb 2011 17:07:14 +0900 Subject: [PATCH] Allow qc style function params. Due to ambiguities in the grammar, qc-style function params and c-style function params had to be completely separated. This means that qc-style functions can not use pointers and must use qc-style function declarations for parameters, and c-style functions must use c-style param declarations. While this rule is tedious for converting the Ruamoko library, it does actually make for a more consistent language. --- tools/qfcc/source/qc-parse.y | 38 ++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/tools/qfcc/source/qc-parse.y b/tools/qfcc/source/qc-parse.y index 845391f0b..e9b6ac6ee 100644 --- a/tools/qfcc/source/qc-parse.y +++ b/tools/qfcc/source/qc-parse.y @@ -157,6 +157,7 @@ int yylex (void); %type type %type function_params var_list param_declaration +%type qc_func_params qc_var_list qc_param_decl %type var_decl function_decl %type abstract_decl abs_decl @@ -307,7 +308,7 @@ external_def_list external_def : optional_specifiers external_decl_list ';' { } | optional_specifiers ';' { } - | optional_specifiers function_params + | optional_specifiers qc_func_params { $$ = $1; // copy spec bits and storage $$.type = parse_params ($1.type, $2), st_global, 0; @@ -569,7 +570,6 @@ var_decl | var_decl function_params { $$->type = append_type ($$->type, parse_params (0, $2)); - print_type ($$->type); } | var_decl array_decl { @@ -615,6 +615,11 @@ function_params | '(' ps var_list ')' { $$ = check_params ($3); } ; +qc_func_params + : '(' ')' { $$ = 0; } + | '(' ps qc_var_list ')' { $$ = check_params ($3); } + ; + ps : ; var_list @@ -630,6 +635,19 @@ var_list } ; +qc_var_list + : qc_param_decl + | qc_var_list ',' qc_param_decl + { + param_t *p; + + for (p = $1; p->next; p = p->next) + ; + p->next = $3; + $$ = $1; + } + ; + param_declaration : type var_decl { @@ -648,6 +666,22 @@ abstract_decl } ; +qc_param_decl + : type NAME + { + $2->type = find_type ($1.type); + $$ = new_param (0, $2->type, $2->name); + } + | type qc_func_params NAME + { + $3->type = parse_params ($1.type, $2); + $3->type = find_type ($3->type); + $3->params = $2; + $$ = new_param (0, $3->type, $3->name); + } + | ELLIPSIS { $$ = new_param (0, 0, 0); } + ; + //FIXME type construction is inside-out abs_decl : /* empty */ { $$ = new_symbol (""); }