From ed331517b3f317f91aa635bf4cf05cfac1d5c073 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 14 Nov 2001 22:31:57 +0000 Subject: [PATCH] more grammar re-work preparing for arrays and structs --- tools/qfcc/source/qc-parse.y | 106 ++++++++++++++++++++++------------- 1 file changed, 67 insertions(+), 39 deletions(-) diff --git a/tools/qfcc/source/qc-parse.y b/tools/qfcc/source/qc-parse.y index 29b42b413..504bd181c 100644 --- a/tools/qfcc/source/qc-parse.y +++ b/tools/qfcc/source/qc-parse.y @@ -59,6 +59,7 @@ void build_function (function_t *f); void finish_function (function_t *f); void emit_function (function_t *f, expr_t *e); void build_scope (function_t *f, def_t *func); +type_t *build_type (int is_field, type_t *type); hashtab_t *save_local_inits (def_t *scope); hashtab_t *merge_local_inits (hashtab_t *dl_1, hashtab_t *dl_2); @@ -112,9 +113,11 @@ typedef struct { %token SWITCH CASE DEFAULT %token TYPE -%type type maybe_func +%type type opt_func func_parms %type opt_field -%type param param_list def_item def_list def_name +%type param param_list def_name +%type var_def_item var_def_list +%type func_def_item func_def_list %type const opt_expr expr arg_list %type statement statements statement_block %type break_label continue_label @@ -148,32 +151,10 @@ defs ; def - : type - { - current_type = $1; - } - def_list - { - } - ; - -type : opt_field TYPE - { - current_type = $2; - } - maybe_func - { - if ($1) { - type_t new; - memset (&new, 0, sizeof (new)); - new.type = ev_field; - new.aux_type = $4 ? $4 : $2; - $$ = PR_FindType (&new); - } else { - $$ = $4 ? $4 : $2; - } - } + { current_type = build_type ($1, $2); } var_def_list + | opt_field TYPE { current_type = $2; } func_parms + { current_type = build_type ($1, $4); } func_def_list ; opt_field @@ -181,12 +162,19 @@ opt_field | '.' { $$ = 1; } ; -maybe_func +opt_func : /* empty */ { $$ = 0; } - | '(' + | func_parms + { + $$ = $1; + } + ; + +func_parms + : '(' { $$.scope = pr_scope; $$.type = current_type; @@ -216,15 +204,28 @@ maybe_func $$ = parse_params ((def_t*)1); } ; - -def_list - : def_list ',' def_item - | def_item +var_def_list + : var_def_list ',' var_def_item + | var_def_item ; -def_item - : def_name opt_initializer +var_def_item + : def_name opt_var_initializer + { + $$ = $1; + if (!$$->scope && $$->type->type != ev_func) + PR_DefInitialized ($$); + } + ; + +func_def_list + : func_def_list ',' func_def_item + | func_def_item + ; + +func_def_item + : def_name opt_func_initializer { $$ = $1; if (!$$->scope && $$->type->type != ev_func) @@ -235,7 +236,11 @@ def_item def_name : NAME { - $$ = PR_GetDef (current_type, $1, pr_scope, pr_scope ? pr_scope->alloc : &numpr_globals); + int *alloc = &numpr_globals; + + if (pr_scope) + alloc = pr_scope->alloc; + $$ = PR_GetDef (current_type, $1, pr_scope, alloc); current_def = $$; } ; @@ -255,14 +260,19 @@ param_list ; param - : type {current_type = $1;} def_item + : type {current_type = $1;} def_name { $3->type = $1; $$ = $3; } ; -opt_initializer +type + : opt_field TYPE { current_type = $2; } opt_func + { $$ = build_type ($1, $4 ? $4 : $2); } + ; + +opt_var_initializer : /*empty*/ | '=' expr { @@ -280,6 +290,10 @@ opt_initializer } } } + ; + +opt_func_initializer + : /*empty*/ | '=' '#' const { if (current_type->type != ev_func) { @@ -498,7 +512,7 @@ statement current_type = $2; local_expr = new_block_expr (); } - def_list ';' + var_def_list ';' { $$ = local_expr; local_expr = 0; @@ -770,6 +784,20 @@ build_scope (function_t *f, def_t *func) } } +type_t * +build_type (int is_field, type_t *type) +{ + if (is_field) { + type_t new; + memset (&new, 0, sizeof (new)); + new.type = ev_field; + new.aux_type = type; + return PR_FindType (&new); + } else { + return type; + } +} + function_t * new_function (void) {