aboutsummaryrefslogtreecommitdiff
path: root/gdb/c-exp.y
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2010-01-18 20:54:35 +0000
committerTom Tromey <tromey@redhat.com>2010-01-18 20:54:35 +0000
commit4e8f195d9dd0be6a5caf9349883db5a531aabd5f (patch)
tree4135b82af0d720a7a7e9786de58cf7cfc9486885 /gdb/c-exp.y
parentd9c57d9ff1bf3533ddb272717afe2b18f61dd017 (diff)
downloadgdb-4e8f195d9dd0be6a5caf9349883db5a531aabd5f.zip
gdb-4e8f195d9dd0be6a5caf9349883db5a531aabd5f.tar.gz
gdb-4e8f195d9dd0be6a5caf9349883db5a531aabd5f.tar.bz2
gdb
PR c++/9680: * c-exp.y (REINTERPRET_CAST, DYNAMIC_CAST, STATIC_CAST) (CONST_CAST): New tokens. (exp): Add new productions. (ident_tokens): Add const_cast, dynamic_cast, static_cast, and reinterpret_cast. (is_cast_operator): New function. (yylex): Handle cast operators specially. * eval.c (evaluate_subexp_standard) <UNOP_DYNAMIC_CAST, UNOP_REINTERPRET_CAST>: New cases. * expprint.c (print_subexp_standard): Likewise. (op_name_standard): Likewise. (dump_subexp_body_standard): Likewise. * parse.c (operator_length_standard): Likewise. * expression.h (enum exp_opcode): New constants UNOP_DYNAMIC_CAST, UNOP_REINTERPRET_CAST. * gdbtypes.c (class_types_same_p): New function. (is_ancestor): Use it. (is_public_ancestor): New function. (is_unique_ancestor_worker): Likewise. (is_unique_ancestor): Likewise. * gdbtypes.h (class_types_same_p, is_public_ancestor) (is_unique_ancestor): Declare. * valops.c (value_reinterpret_cast): New function. (dynamic_cast_check_1): Likewise. (dynamic_cast_check_2): Likewise. (value_dynamic_cast): Likewise. * value.h (value_reinterpret_cast, value_dynamic_cast): Declare. gdb/testsuite PR c++/9680: * gdb.cp/casts.cc: Add new classes and variables. * gdb.cp/casts.exp: Test new operators.
Diffstat (limited to 'gdb/c-exp.y')
-rw-r--r--gdb/c-exp.y65
1 files changed, 55 insertions, 10 deletions
diff --git a/gdb/c-exp.y b/gdb/c-exp.y
index 2ea5c6f..8e00979 100644
--- a/gdb/c-exp.y
+++ b/gdb/c-exp.y
@@ -206,6 +206,7 @@ static struct stoken operator_stoken (const char *);
%token ERROR
%token NEW DELETE
%type <sval> operator
+%token REINTERPRET_CAST DYNAMIC_CAST STATIC_CAST CONST_CAST
/* Special type cases, put in to allow the parser to distinguish different
legal basetypes. */
@@ -591,6 +592,32 @@ exp : SIZEOF '(' type ')' %prec UNARY
write_exp_elt_opcode (OP_LONG); }
;
+exp : REINTERPRET_CAST '<' type '>' '(' exp ')' %prec UNARY
+ { write_exp_elt_opcode (UNOP_REINTERPRET_CAST);
+ write_exp_elt_type ($3);
+ write_exp_elt_opcode (UNOP_REINTERPRET_CAST); }
+ ;
+
+exp : STATIC_CAST '<' type '>' '(' exp ')' %prec UNARY
+ { write_exp_elt_opcode (UNOP_CAST);
+ write_exp_elt_type ($3);
+ write_exp_elt_opcode (UNOP_CAST); }
+ ;
+
+exp : DYNAMIC_CAST '<' type '>' '(' exp ')' %prec UNARY
+ { write_exp_elt_opcode (UNOP_DYNAMIC_CAST);
+ write_exp_elt_type ($3);
+ write_exp_elt_opcode (UNOP_DYNAMIC_CAST); }
+ ;
+
+exp : CONST_CAST '<' type '>' '(' exp ')' %prec UNARY
+ { /* We could do more error checking here, but
+ it doesn't seem worthwhile. */
+ write_exp_elt_opcode (UNOP_CAST);
+ write_exp_elt_type ($3);
+ write_exp_elt_opcode (UNOP_CAST); }
+ ;
+
string_exp:
STRING
{
@@ -1894,7 +1921,12 @@ static const struct token ident_tokens[] =
{"or", OROR, BINOP_END, 1},
{"or_eq", ASSIGN_MODIFY, BINOP_BITWISE_IOR, 1},
{"xor", '^', OP_NULL, 1},
- {"xor_eq", ASSIGN_MODIFY, BINOP_BITWISE_XOR, 1}
+ {"xor_eq", ASSIGN_MODIFY, BINOP_BITWISE_XOR, 1},
+
+ {"const_cast", CONST_CAST, OP_NULL, 1 },
+ {"dynamic_cast", DYNAMIC_CAST, OP_NULL, 1 },
+ {"static_cast", STATIC_CAST, OP_NULL, 1 },
+ {"reinterpret_cast", REINTERPRET_CAST, OP_NULL, 1 }
};
/* When we find that lexptr (the global var defined in parse.c) is
@@ -1972,6 +2004,16 @@ scan_macro_cleanup (void *dummy)
obstack_free (&expansion_obstack, NULL);
}
+/* Return true iff the token represents a C++ cast operator. */
+
+static int
+is_cast_operator (const char *token, int len)
+{
+ return (! strncmp (token, "dynamic_cast", len)
+ || ! strncmp (token, "static_cast", len)
+ || ! strncmp (token, "reinterpret_cast", len)
+ || ! strncmp (token, "const_cast", len));
+}
/* The scope used for macro expansion. */
static struct macro_scope *expression_macro_scope;
@@ -2235,16 +2277,19 @@ yylex (void)
FIXME: This mishandles `print $a<4&&$a>3'. */
if (c == '<')
- {
- /* Scan ahead to get rest of the template specification. Note
- that we look ahead only when the '<' adjoins non-whitespace
- characters; for comparison expressions, e.g. "a < b > c",
- there must be spaces before the '<', etc. */
+ {
+ if (! is_cast_operator (tokstart, namelen))
+ {
+ /* Scan ahead to get rest of the template specification. Note
+ that we look ahead only when the '<' adjoins non-whitespace
+ characters; for comparison expressions, e.g. "a < b > c",
+ there must be spaces before the '<', etc. */
- char * p = find_template_name_end (tokstart + namelen);
- if (p)
- namelen = p - tokstart;
- break;
+ char * p = find_template_name_end (tokstart + namelen);
+ if (p)
+ namelen = p - tokstart;
+ }
+ break;
}
c = tokstart[++namelen];
}