From 896c14f33a1afe2297ab056546e5679bd8d6020a Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Thu, 5 Mar 2020 01:46:56 +0900 Subject: [PATCH] [qfcc] Support anonymous structs in ivars Missed this earlier. --- tools/qfcc/source/qc-parse.y | 18 ++++++++++++++++++ tools/qfcc/source/symtab.c | 3 ++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/tools/qfcc/source/qc-parse.y b/tools/qfcc/source/qc-parse.y index 46cf09e7e..a6c5d99e4 100644 --- a/tools/qfcc/source/qc-parse.y +++ b/tools/qfcc/source/qc-parse.y @@ -1873,6 +1873,24 @@ ivar_decls ivar_decl : type ivars + | type + { + if (is_anonymous_struct ($1)) { + // anonymous struct/union + // type->name always begins with "tag " + $1.sym = new_symbol (va (".anonymous.%s", $1.type->name + 4)); + $1.sym->type = $1.type; + $1.sym->sy_type = sy_var; + $1.sym->visibility = vis_anonymous; + symtab_addsymbol (current_symtab, $1.sym); + if (!$1.sym->table) { + error (0, "duplicate field `%s'", $1.sym->name); + } + } else { + // bare type + warning (0, "declaration does not declare anything"); + } + } ; ivars diff --git a/tools/qfcc/source/symtab.c b/tools/qfcc/source/symtab.c index 377671e8a..f94e8d71a 100644 --- a/tools/qfcc/source/symtab.c +++ b/tools/qfcc/source/symtab.c @@ -182,7 +182,8 @@ symtab_flat_copy (symtab_t *symtab, symtab_t *parent) newtab = new_symtab (parent, stab_local); do { for (symbol = symtab->symbols; symbol; symbol = symbol->next) { - if (Hash_Find (newtab->tab, symbol->name)) + if (symbol->visibility == vis_anonymous + || Hash_Find (newtab->tab, symbol->name)) continue; newsym = copy_symbol (symbol); symtab_addsymbol (newtab, newsym);