X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gdb%2Fcp-name-parser.y;h=c6a5c341bfc521065284735b9910b9a0ebd34bfd;hb=35fd2deb6916e972248d52b1bc1d584fa9059f8f;hp=b0262f2307d0c28d01a1f98d27a024a5135ef304;hpb=dd274a34d22249bd4ae2e868fdd02678f69dd36c;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/cp-name-parser.y b/gdb/cp-name-parser.y index b0262f2307..c6a5c341bf 100644 --- a/gdb/cp-name-parser.y +++ b/gdb/cp-name-parser.y @@ -1,7 +1,6 @@ /* YACC parser for C++ names, for GDB. - Copyright (C) 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011 - Free Software Foundation, Inc. + Copyright (C) 2003-2016 Free Software Foundation, Inc. Parts of the lexer are based on c-exp.y from GDB. @@ -32,16 +31,10 @@ #include "defs.h" -#include -#include #include -#include - #include "safe-ctype.h" -#include "libiberty.h" #include "demangle.h" #include "cp-support.h" -#include "gdb_assert.h" /* Bison does not make it easy to create a parser without global state, unfortunately. Here are all the global variables used @@ -76,7 +69,7 @@ d_grab (void) { if (demangle_info->next == NULL) { - more = malloc (sizeof (struct demangle_info)); + more = XNEW (struct demangle_info); more->next = NULL; demangle_info->next = more; } @@ -171,6 +164,12 @@ static struct demangle_component *d_binary (const char *, #define yygindex cpname_yygindex #define yytable cpname_yytable #define yycheck cpname_yycheck +#define yyss cpname_yyss +#define yysslim cpname_yysslim +#define yyssp cpname_yyssp +#define yystacksize cpname_yystacksize +#define yyvs cpname_yyvs +#define yyvsp cpname_yyvsp int yyparse (void); static int yylex (void); @@ -189,7 +188,11 @@ fill_comp (enum demangle_component_type d_type, struct demangle_component *lhs, struct demangle_component *rhs) { struct demangle_component *ret = d_grab (); - cplus_demangle_fill_component (ret, d_type, lhs, rhs); + int i; + + i = cplus_demangle_fill_component (ret, d_type, lhs, rhs); + gdb_assert (i); + return ret; } @@ -205,7 +208,11 @@ static struct demangle_component * make_operator (const char *name, int args) { struct demangle_component *ret = d_grab (); - cplus_demangle_fill_operator (ret, name, args); + int i; + + i = cplus_demangle_fill_operator (ret, name, args); + gdb_assert (i); + return ret; } @@ -213,7 +220,11 @@ static struct demangle_component * make_dtor (enum gnu_v3_dtor_kinds kind, struct demangle_component *name) { struct demangle_component *ret = d_grab (); - cplus_demangle_fill_dtor (ret, kind, name); + int i; + + i = cplus_demangle_fill_dtor (ret, kind, name); + gdb_assert (i); + return ret; } @@ -221,7 +232,11 @@ static struct demangle_component * make_builtin_type (const char *name) { struct demangle_component *ret = d_grab (); - cplus_demangle_fill_builtin_type (ret, name); + int i; + + i = cplus_demangle_fill_builtin_type (ret, name); + gdb_assert (i); + return ret; } @@ -229,7 +244,11 @@ static struct demangle_component * make_name (const char *name, int len) { struct demangle_component *ret = d_grab (); - cplus_demangle_fill_name (ret, name, len); + int i; + + i = cplus_demangle_fill_name (ret, name, len); + gdb_assert (i); + return ret; } @@ -258,9 +277,9 @@ make_name (const char *name, int len) const char *opname; } -%type exp exp1 type start start_opt operator colon_name +%type exp exp1 type start start_opt oper colon_name %type unqualified_name colon_ext_name -%type template template_arg +%type templ template_arg %type builtin_type %type typespec_2 array_indicator %type colon_ext_only ext_only_name @@ -413,21 +432,37 @@ function demangler_special : DEMANGLER_SPECIAL start - { $$ = make_empty ($1); + { $$ = make_empty ((enum demangle_component_type) $1); d_left ($$) = $2; d_right ($$) = NULL; } | CONSTRUCTION_VTABLE start CONSTRUCTION_IN start { $$ = fill_comp (DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE, $2, $4); } ; -operator : OPERATOR NEW - { $$ = make_operator ("new", 1); } +oper : OPERATOR NEW + { + /* Match the whitespacing of cplus_demangle_operators. + It would abort on unrecognized string otherwise. */ + $$ = make_operator ("new", 3); + } | OPERATOR DELETE - { $$ = make_operator ("delete", 1); } + { + /* Match the whitespacing of cplus_demangle_operators. + It would abort on unrecognized string otherwise. */ + $$ = make_operator ("delete ", 1); + } | OPERATOR NEW '[' ']' - { $$ = make_operator ("new[]", 1); } + { + /* Match the whitespacing of cplus_demangle_operators. + It would abort on unrecognized string otherwise. */ + $$ = make_operator ("new[]", 3); + } | OPERATOR DELETE '[' ']' - { $$ = make_operator ("delete[]", 1); } + { + /* Match the whitespacing of cplus_demangle_operators. + It would abort on unrecognized string otherwise. */ + $$ = make_operator ("delete[] ", 1); + } | OPERATOR '+' { $$ = make_operator ("+", 2); } | OPERATOR '-' @@ -493,7 +528,7 @@ operator : OPERATOR NEW since it's not clear that it's parseable. */ conversion_op : OPERATOR typespec_2 - { $$ = fill_comp (DEMANGLE_COMPONENT_CAST, $2, NULL); } + { $$ = fill_comp (DEMANGLE_COMPONENT_CONVERSION, $2, NULL); } ; conversion_op_name @@ -519,8 +554,8 @@ conversion_op_name /* DEMANGLE_COMPONENT_NAME */ /* This accepts certain invalid placements of '~'. */ -unqualified_name: operator - | operator '<' template_params '>' +unqualified_name: oper + | oper '<' template_params '>' { $$ = fill_comp (DEMANGLE_COMPONENT_TEMPLATE, $1, $3.comp); } | '~' NAME { $$ = make_dtor (gnu_v3_complete_object_dtor, $2); } @@ -544,9 +579,9 @@ colon_name : name name : nested_name NAME %prec NAME { $$ = $1.comp; d_right ($1.last) = $2; } | NAME %prec NAME - | nested_name template %prec NAME + | nested_name templ %prec NAME { $$ = $1.comp; d_right ($1.last) = $2; } - | template %prec NAME + | templ %prec NAME ; colon_ext_name : colon_name @@ -576,13 +611,13 @@ nested_name : NAME COLONCOLON d_left ($$.last) = $2; d_right ($$.last) = NULL; } - | template COLONCOLON + | templ COLONCOLON { $$.comp = make_empty (DEMANGLE_COMPONENT_QUAL_NAME); d_left ($$.comp) = $1; d_right ($$.comp) = NULL; $$.last = $$.comp; } - | nested_name template COLONCOLON + | nested_name templ COLONCOLON { $$.comp = $1.comp; d_right ($1.last) = make_empty (DEMANGLE_COMPONENT_QUAL_NAME); $$.last = d_right ($1.last); @@ -593,7 +628,7 @@ nested_name : NAME COLONCOLON /* DEMANGLE_COMPONENT_TEMPLATE */ /* DEMANGLE_COMPONENT_TEMPLATE_ARGLIST */ -template : NAME '<' template_params '>' +templ : NAME '<' template_params '>' { $$ = fill_comp (DEMANGLE_COMPONENT_TEMPLATE, $1, $3.comp); } ; @@ -1158,7 +1193,11 @@ exp : FLOAT ; exp : SIZEOF '(' type ')' %prec UNARY - { $$ = d_unary ("sizeof", $3); } + { + /* Match the whitespacing of cplus_demangle_operators. + It would abort on unrecognized string otherwise. */ + $$ = d_unary ("sizeof ", $3); + } ; /* C++. */ @@ -1938,7 +1977,7 @@ yyerror (char *msg) static struct demangle_info * allocate_info (void) { - struct demangle_info *info = malloc (sizeof (struct demangle_info)); + struct demangle_info *info = XNEW (struct demangle_info); info->next = NULL; info->used = 0; @@ -1968,7 +2007,7 @@ cp_new_demangle_parse_info (void) { struct demangle_parse_info *info; - info = malloc (sizeof (struct demangle_parse_info)); + info = XNEW (struct demangle_parse_info); info->info = NULL; info->tree = NULL; obstack_init (&info->obstack);