+2016-10-29 Manish Goregaokar <manish@mozilla.com>
+
+ * rust-exp.y: Parse `sizeof(exp)` as `UNOP_SIZEOF`
+
2016-10-28 Manish Goregaokar <manish@mozilla.com>
* rust-lang.c (rust_union_is_untagged): Add function to
%token <voidval> KW_EXTERN
%token <voidval> KW_CONST
%token <voidval> KW_FN
+%token <voidval> KW_SIZEOF
/* Operator tokens. */
%token <voidval> DOTDOT
| 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
| '&' KW_MUT expr %prec UNARY
{ $$ = ast_unary (UNOP_ADDR, $3); }
-
+| KW_SIZEOF '(' expr ')' %prec UNARY
+ { $$ = ast_unary (UNOP_SIZEOF, $3); }
;
binop_expr:
{ "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. */
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;
+2016-10-29 Manish Goregaokar <manish@mozilla.com>
+
+ * gdb.rust/simple.exp: Add tests for `sizeof(expr)`
+
2016-10-27 Manish Goregaokar <manish@mozilla.com>
* gdb.rust/simple.rs: Add test for univariant enums without discriminants
gdb_test "print a" " = \\(\\)"
gdb_test "ptype a" " = \\(\\)"
+gdb_test "print sizeof(a)" " = 0"
gdb_test "print b" " = \\\[\\\]"
gdb_test "ptype b" " = \\\[i32; 0\\\]"
gdb_test "print c" " = 99"
gdb_test "ptype c" " = i32"
+gdb_test "print sizeof(c)" " = 4"
gdb_test "print c = 87" " = \\(\\)"
gdb_test "print c" " = 87"
gdb_test "print e" " = simple::MoreComplicated::Two\\(73\\)"
gdb_test "print e2" \
" = simple::MoreComplicated::Four\\{this: true, is: 8, a: 109 'm', struct_: 100, variant: 10\\}"
-
+gdb_test "print sizeof(e)" " = 24"
gdb_test_sequence "ptype e" "" {
" = enum simple::MoreComplicated \\{"
" One,"