/* YACC parser for C++ names, for GDB.
- Copyright (C) 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
+ Copyright (C) 2003, 2004, 2005, 2007, 2008, 2009
+ Free Software Foundation, Inc.
Parts of the lexer are based on c-exp.y from GDB.
-This file is part of GDB.
+ This file is part of GDB.
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 51 Franklin Street, Fifth Floor,
-Boston, MA 02110-1301, USA. */
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Note that malloc's and realloc's in this file are transformed to
xmalloc and xrealloc respectively by the same sed command in the
%{
+#include "defs.h"
+
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "safe-ctype.h"
#include "libiberty.h"
#include "demangle.h"
+#include "cp-support.h"
/* Bison does not make it easy to create a parser without global
state, unfortunately. Here are all the global variables used
| OPERATOR ARROW
{ $$ = make_operator ("->", 2); }
| OPERATOR '(' ')'
- { $$ = make_operator ("()", 0); }
+ { $$ = make_operator ("()", 2); }
| OPERATOR '[' ']'
{ $$ = make_operator ("[]", 2); }
;
in parentheses. */
exp1 : '&' start
{ $$ = fill_comp (DEMANGLE_COMPONENT_UNARY, make_operator ("&", 1), $2); }
+ | '&' '(' start ')'
+ { $$ = fill_comp (DEMANGLE_COMPONENT_UNARY, make_operator ("&", 1), $3); }
;
/* Expressions, not including the comma operator. */
}
;
-/* Another form of C++-style cast. "type ( exp1 )" is not allowed (it's too
- ambiguous), but "name ( exp1 )" is. Because we don't need to support
- function types, we can handle this unambiguously (the use of typespec_2
- prevents a silly, harmless conflict with qualifiers_opt). This does not
- appear in demangler output so it's not a great loss if we need to
- disable it. */
-exp : typespec_2 '(' exp1 ')' %prec UNARY
- { $$ = fill_comp (DEMANGLE_COMPONENT_UNARY,
- fill_comp (DEMANGLE_COMPONENT_CAST, $1, NULL),
- $3);
- }
- ;
+/* Another form of C++-style cast is "type ( exp1 )". This creates too many
+ conflicts to support. For a while we supported the simpler
+ "typespec_2 ( exp1 )", but that conflicts with "& ( start )" as a
+ reference, deep within the wilderness of abstract declarators:
+ Qux<int(&(*))> vs Qux<int(&(var))>, a shift-reduce conflict at the
+ innermost left parenthesis. So we do not support function-like casts.
+ Fortunately they never appear in demangler output. */
/* TO INVESTIGATE: ._0 style anonymous names; anonymous namespaces */
after the zeros. A value of 0 does not mean end of string. */
static int
-parse_escape (const char **string_ptr)
+cp_parse_escape (const char **string_ptr)
{
int target_char;
int c = *(*string_ptr)++;
if (c == '?')
return 0177;
else if (c == '\\')
- target_char = parse_escape (string_ptr);
+ target_char = cp_parse_escape (string_ptr);
else
target_char = c;
lexptr++;
c = *lexptr++;
if (c == '\\')
- c = parse_escape (&lexptr);
+ c = cp_parse_escape (&lexptr);
else if (c == '\'')
{
yyerror ("empty character constant");
return c;
}
+/* When this file is built as a standalone program, xmalloc comes from
+ libiberty --- in which case we have to provide xfree ourselves. */
+
+void
+xfree (void *ptr)
+{
+ if (ptr != NULL)
+ free (ptr);
+}
+
int
main (int argc, char **argv)
{