From 246518f4873a5def626dbf7501d75621863c4582 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 7 Feb 2022 10:40:26 +0900 Subject: [PATCH] [qfcc] Get reused type names working for local variables This allows the likes of "id id;" or typedef int foo; ... { double foo; } So long as the redeclaration is in a sub-scope. --- tools/qfcc/source/qc-parse.y | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/tools/qfcc/source/qc-parse.y b/tools/qfcc/source/qc-parse.y index 2874965a2..29029e543 100644 --- a/tools/qfcc/source/qc-parse.y +++ b/tools/qfcc/source/qc-parse.y @@ -265,11 +265,16 @@ static specifier_t spec_merge (specifier_t spec, specifier_t new) { if (new.type) { - if (spec.type && !spec.multi_type) { + // deal with "type " + if (!spec.type || new.sym) { + spec.sym = new.sym; + if (!spec.type) { + spec.type = new.type; + } + } else if (!spec.multi_type) { error (0, "two or more data types in declaration specifiers"); spec.multi_type = 1; } - spec.type = new.type; } if (new.is_typedef || new.storage) { if ((spec.is_typedef || spec.storage) && !spec.multi_store) { @@ -677,15 +682,7 @@ type : type_specifier | type type_specifier { - // deal with eg "int id" - $1.sym = $2.sym; - - if (!$1.sym && !$1.type) { - $1 = spec_merge ($1, $2); - } else if (!$1.sym) { - error (0, "two or more data types in declaration specifiers"); - } - $$ = $1; + $$ = spec_merge ($1, $2); } ; @@ -1410,7 +1407,7 @@ local_def local_expr = 0; (void) ($2); } - | specifiers ';' + | specifiers opt_initializer ';' { check_specifiers ($1); $$ = 0;