diff options
author | Pedro Alves <palves@redhat.com> | 2017-03-27 13:56:49 +0100 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2017-03-27 15:28:17 +0100 |
commit | a7e80b9e21eb907ac5c90de7452588c059db0cec (patch) | |
tree | 4ba0712f3199454aabac1e814419e54bc2aafb44 /gdb/cp-name-parser.y | |
parent | b1a42fdfa31937d7e05df34afee970ac0ad239e1 (diff) | |
download | gdb-a7e80b9e21eb907ac5c90de7452588c059db0cec.zip gdb-a7e80b9e21eb907ac5c90de7452588c059db0cec.tar.gz gdb-a7e80b9e21eb907ac5c90de7452588c059db0cec.tar.bz2 |
gdb/cp-name-parser.y: Eliminate make_empty, use cplus_demangle_fill_component
The demangler exports the cplus_demangle_fill_component function that
clients should use to initialize demangle_component components that
use the "s_binary" union member. cp-name-parser.y uses it in some
places, via the fill_comp wrapper, but not all. Several places
instead use a GDB-specific "make_empty" function. Because this
function does not call any of the demangler "fill" functions, we had
to patch it recently to clear the allocated demangle_component's
"d_printing" field, which is supposedly a "private" demangler field.
To avoid such problems in the future, this commit switches those
places to use "fill_comp" instead, and eliminates the "make_empty"
function.
gdb/ChangeLog:
2017-03-27 Pedro Alves <palves@redhat.com>
* cp-name-parser.y (make_empty): Delete.
(demangler_special, nested_name, ptr_operator, array_indicator)
(direct_declarator, declarator_1): Use fill_comp instead of
make_empty.
Diffstat (limited to 'gdb/cp-name-parser.y')
-rw-r--r-- | gdb/cp-name-parser.y | 60 |
1 files changed, 14 insertions, 46 deletions
diff --git a/gdb/cp-name-parser.y b/gdb/cp-name-parser.y index b51c5e2..73a4d90 100644 --- a/gdb/cp-name-parser.y +++ b/gdb/cp-name-parser.y @@ -197,15 +197,6 @@ fill_comp (enum demangle_component_type d_type, struct demangle_component *lhs, } static struct demangle_component * -make_empty (enum demangle_component_type d_type) -{ - struct demangle_component *ret = d_grab (); - ret->type = d_type; - ret->d_printing = 0; - return ret; -} - -static struct demangle_component * make_operator (const char *name, int args) { struct demangle_component *ret = d_grab (); @@ -433,9 +424,7 @@ function demangler_special : DEMANGLER_SPECIAL start - { $$ = make_empty ((enum demangle_component_type) $1); - d_left ($$) = $2; - d_right ($$) = NULL; } + { $$ = fill_comp ((enum demangle_component_type) $1, $2, NULL); } | CONSTRUCTION_VTABLE start CONSTRUCTION_IN start { $$ = fill_comp (DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE, $2, $4); } ; @@ -600,30 +589,22 @@ ext_only_name : nested_name unqualified_name ; nested_name : NAME COLONCOLON - { $$.comp = make_empty (DEMANGLE_COMPONENT_QUAL_NAME); - d_left ($$.comp) = $1; - d_right ($$.comp) = NULL; + { $$.comp = fill_comp (DEMANGLE_COMPONENT_QUAL_NAME, $1, NULL); $$.last = $$.comp; } | nested_name NAME COLONCOLON { $$.comp = $1.comp; - d_right ($1.last) = make_empty (DEMANGLE_COMPONENT_QUAL_NAME); + d_right ($1.last) = fill_comp (DEMANGLE_COMPONENT_QUAL_NAME, $2, NULL); $$.last = d_right ($1.last); - d_left ($$.last) = $2; - d_right ($$.last) = NULL; } | templ COLONCOLON - { $$.comp = make_empty (DEMANGLE_COMPONENT_QUAL_NAME); - d_left ($$.comp) = $1; - d_right ($$.comp) = NULL; + { $$.comp = fill_comp (DEMANGLE_COMPONENT_QUAL_NAME, $1, NULL); $$.last = $$.comp; } | nested_name templ COLONCOLON { $$.comp = $1.comp; - d_right ($1.last) = make_empty (DEMANGLE_COMPONENT_QUAL_NAME); + d_right ($1.last) = fill_comp (DEMANGLE_COMPONENT_QUAL_NAME, $2, NULL); $$.last = d_right ($1.last); - d_left ($$.last) = $2; - d_right ($$.last) = NULL; } ; @@ -761,45 +742,34 @@ builtin_type : int_seq ; ptr_operator : '*' qualifiers_opt - { $$.comp = make_empty (DEMANGLE_COMPONENT_POINTER); - $$.comp->u.s_binary.left = $$.comp->u.s_binary.right = NULL; + { $$.comp = fill_comp (DEMANGLE_COMPONENT_POINTER, NULL, NULL); $$.last = &d_left ($$.comp); $$.comp = d_qualify ($$.comp, $2, 0); } /* g++ seems to allow qualifiers after the reference? */ | '&' - { $$.comp = make_empty (DEMANGLE_COMPONENT_REFERENCE); - $$.comp->u.s_binary.left = $$.comp->u.s_binary.right = NULL; + { $$.comp = fill_comp (DEMANGLE_COMPONENT_REFERENCE, NULL, NULL); $$.last = &d_left ($$.comp); } | ANDAND - { $$.comp = make_empty (DEMANGLE_COMPONENT_RVALUE_REFERENCE); - $$.comp->u.s_binary.left = $$.comp->u.s_binary.right = NULL; + { $$.comp = fill_comp (DEMANGLE_COMPONENT_RVALUE_REFERENCE, NULL, NULL); $$.last = &d_left ($$.comp); } | nested_name '*' qualifiers_opt - { $$.comp = make_empty (DEMANGLE_COMPONENT_PTRMEM_TYPE); - $$.comp->u.s_binary.left = $1.comp; + { $$.comp = fill_comp (DEMANGLE_COMPONENT_PTRMEM_TYPE, $1.comp, NULL); /* Convert the innermost DEMANGLE_COMPONENT_QUAL_NAME to a DEMANGLE_COMPONENT_NAME. */ *$1.last = *d_left ($1.last); - $$.comp->u.s_binary.right = NULL; $$.last = &d_right ($$.comp); $$.comp = d_qualify ($$.comp, $3, 0); } | COLONCOLON nested_name '*' qualifiers_opt - { $$.comp = make_empty (DEMANGLE_COMPONENT_PTRMEM_TYPE); - $$.comp->u.s_binary.left = $2.comp; + { $$.comp = fill_comp (DEMANGLE_COMPONENT_PTRMEM_TYPE, $2.comp, NULL); /* Convert the innermost DEMANGLE_COMPONENT_QUAL_NAME to a DEMANGLE_COMPONENT_NAME. */ *$2.last = *d_left ($2.last); - $$.comp->u.s_binary.right = NULL; $$.last = &d_right ($$.comp); $$.comp = d_qualify ($$.comp, $4, 0); } ; array_indicator : '[' ']' - { $$ = make_empty (DEMANGLE_COMPONENT_ARRAY_TYPE); - d_left ($$) = NULL; - } + { $$ = fill_comp (DEMANGLE_COMPONENT_ARRAY_TYPE, NULL, NULL); } | '[' INT ']' - { $$ = make_empty (DEMANGLE_COMPONENT_ARRAY_TYPE); - d_left ($$) = $2; - } + { $$ = fill_comp (DEMANGLE_COMPONENT_ARRAY_TYPE, $2, NULL); } ; /* Details of this approach inspired by the G++ < 3.4 parser. */ @@ -952,8 +922,7 @@ direct_declarator $$.last = &d_right ($2); } | colon_ext_name - { $$.comp = make_empty (DEMANGLE_COMPONENT_TYPED_NAME); - d_left ($$.comp) = $1; + { $$.comp = fill_comp (DEMANGLE_COMPONENT_TYPED_NAME, $1, NULL); $$.last = &d_right ($$.comp); } ; @@ -969,8 +938,7 @@ declarator_1 : ptr_operator declarator_1 $$.last = $1.last; *$2.last = $1.comp; } | colon_ext_name - { $$.comp = make_empty (DEMANGLE_COMPONENT_TYPED_NAME); - d_left ($$.comp) = $1; + { $$.comp = fill_comp (DEMANGLE_COMPONENT_TYPED_NAME, $1, NULL); $$.last = &d_right ($$.comp); } | direct_declarator_1 |