aboutsummaryrefslogtreecommitdiff
path: root/gdb/rust-exp.y
diff options
context:
space:
mode:
authorManish Goregaokar <manish@mozilla.com>2016-10-29 05:55:58 -0700
committerManish Goregaokar <manish@mozilla.com>2016-11-03 15:45:14 -0700
commitcdf5a07c75b47481da1e99ee91ee860c2a6bb5f6 (patch)
tree057640bee6175b7afea74966d85f931736b1522b /gdb/rust-exp.y
parentb96645f1a1e6084ed6a20ddf615bdc4d2487a9c9 (diff)
downloadgdb-cdf5a07c75b47481da1e99ee91ee860c2a6bb5f6.zip
gdb-cdf5a07c75b47481da1e99ee91ee860c2a6bb5f6.tar.gz
gdb-cdf5a07c75b47481da1e99ee91ee860c2a6bb5f6.tar.bz2
Add support for the sizeof function in Rust
2016-10-29 Manish Goregaokar <manish@mozilla.com> gdb/ChangeLog: * rust-exp.y: Parse `sizeof(exp)` as `UNOP_SIZEOF` gdb/testsuite/ChangeLog: * gdb.rust/simple.exp: Add tests for `sizeof(expr)`
Diffstat (limited to 'gdb/rust-exp.y')
-rw-r--r--gdb/rust-exp.y8
1 files changed, 6 insertions, 2 deletions
diff --git a/gdb/rust-exp.y b/gdb/rust-exp.y
index 6dc4704..dffccd0 100644
--- a/gdb/rust-exp.y
+++ b/gdb/rust-exp.y
@@ -276,6 +276,7 @@ struct rust_op
%token <voidval> KW_EXTERN
%token <voidval> KW_CONST
%token <voidval> KW_FN
+%token <voidval> KW_SIZEOF
/* Operator tokens. */
%token <voidval> DOTDOT
@@ -371,7 +372,7 @@ expr:
| array_expr
| idx_expr
| range_expr
-| unop_expr
+| unop_expr /* Must precede call_expr because of ambiguity with sizeof. */
| binop_expr
| paren_expr
| call_expr
@@ -577,7 +578,8 @@ unop_expr:
| '&' KW_MUT expr %prec UNARY
{ $$ = ast_unary (UNOP_ADDR, $3); }
-
+| KW_SIZEOF '(' expr ')' %prec UNARY
+ { $$ = ast_unary (UNOP_SIZEOF, $3); }
;
binop_expr:
@@ -872,6 +874,7 @@ static const struct token_info identifier_tokens[] =
{ "true", KW_TRUE, OP_NULL },
{ "extern", KW_EXTERN, OP_NULL },
{ "fn", KW_FN, OP_NULL },
+ { "sizeof", KW_SIZEOF, OP_NULL },
};
/* Operator tokens, sorted longest first. */
@@ -2194,6 +2197,7 @@ convert_ast_to_expression (struct parser_state *state,
case UNOP_COMPLEMENT:
case UNOP_IND:
case UNOP_ADDR:
+ case UNOP_SIZEOF:
convert_ast_to_expression (state, operation->left.op, top);
write_exp_elt_opcode (state, operation->opcode);
break;