Use ui_file_as_string in gdb/compile/
[deliverable/binutils-gdb.git] / gdb / rust-exp.y
index c1a863c465f9820da6e1648cc1fc991d326d9c99..dffccd0605bb5ef6e2e9d25d8eabd248461a01d7 100644 (file)
@@ -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
@@ -428,10 +429,14 @@ struct_expr_tail:
                }
 ;
 
-/* S{} is documented as valid but seems to be an unstable feature, so
-   it is left out here.  */
 struct_expr_list:
-       struct_expr_tail
+       /* %empty */
+               {
+                 VEC (set_field) **result
+                   = OBSTACK_ZALLOC (&work_obstack, VEC (set_field) *);
+                 $$ = result;
+               }
+|      struct_expr_tail
                {
                  VEC (set_field) **result
                    = OBSTACK_ZALLOC (&work_obstack, VEC (set_field) *);
@@ -573,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:
@@ -868,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.  */
@@ -968,17 +975,15 @@ super_name (const struct rust_op *ident, unsigned int n_supers)
       int i;
       int len;
       VEC (int) *offsets = NULL;
-      unsigned int current_len, previous_len;
+      unsigned int current_len;
       struct cleanup *cleanup;
 
       cleanup = make_cleanup (VEC_cleanup (int), &offsets);
       current_len = cp_find_first_component (scope);
-      previous_len = 0;
       while (scope[current_len] != '\0')
        {
          VEC_safe_push (int, offsets, current_len);
          gdb_assert (scope[current_len] == ':');
-         previous_len = current_len;
          /* The "::".  */
          current_len += 2;
          current_len += cp_find_first_component (scope
@@ -1418,6 +1423,7 @@ lex_number (void)
   int match;
   int is_integer = 0;
   int could_be_decimal = 1;
+  int implicit_i32 = 0;
   char *type_name = NULL;
   struct type *type;
   int end_index;
@@ -1436,7 +1442,10 @@ lex_number (void)
       is_integer = 1;
       end_index = subexps[INT_TEXT].rm_eo;
       if (subexps[INT_TYPE].rm_so == -1)
-       type_name = "i32";
+       {
+         type_name = "i32";
+         implicit_i32 = 1;
+       }
       else
        {
          type_index = INT_TYPE;
@@ -1478,6 +1487,7 @@ lex_number (void)
          end_index = subexps[0].rm_eo;
          type_name = "i32";
          could_be_decimal = 1;
+         implicit_i32 = 1;
        }
     }
 
@@ -1512,6 +1522,7 @@ lex_number (void)
   /* Parse the number.  */
   if (is_integer)
     {
+      uint64_t value;
       int radix = 10;
       if (number[0] == '0')
        {
@@ -1527,7 +1538,12 @@ lex_number (void)
              could_be_decimal = 0;
            }
        }
-      rustyylval.typed_val_int.val = strtoul (number, NULL, radix);
+
+      value = strtoul (number, NULL, radix);
+      if (implicit_i32 && value >= ((uint64_t) 1) << 31)
+       type = rust_type ("i64");
+
+      rustyylval.typed_val_int.val = value;
       rustyylval.typed_val_int.type = type;
     }
   else
@@ -2181,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;
This page took 0.026836 seconds and 4 git commands to generate.