Fix enum flag with Python 3
[deliverable/binutils-gdb.git] / gdb / d-exp.y
index bcf62bad75293fac4faaa4145f51742cf8a0da5f..54c01c5b4bc4d4cf8b708976b0845bfacdcfb8a2 100644 (file)
@@ -1,6 +1,6 @@
 /* YACC parser for D expressions, for GDB.
 
-   Copyright (C) 2014-2015 Free Software Foundation, Inc.
+   Copyright (C) 2014-2016 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -126,6 +126,8 @@ static int yylex (void);
 
 void yyerror (char *);
 
+static int type_aggregate_p (struct type *);
+
 %}
 
 /* Although the yacc "value" of an expression is not used,
@@ -366,6 +368,8 @@ UnaryExpression:
                { write_exp_elt_opcode (pstate, UNOP_LOGICAL_NOT); }
 |      '~' UnaryExpression
                { write_exp_elt_opcode (pstate, UNOP_COMPLEMENT); }
+|      TypeExp '.' SIZEOF_KEYWORD
+               { write_exp_elt_opcode (pstate, UNOP_SIZEOF); }
 |      CastExpression
 |      PowExpression
 ;
@@ -408,6 +412,8 @@ PostfixExpression:
                  write_exp_elt_opcode (pstate, STRUCTOP_STRUCT);
                  write_exp_string (pstate, $3);
                  write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); }
+|      PostfixExpression '.' SIZEOF_KEYWORD
+               { write_exp_elt_opcode (pstate, UNOP_SIZEOF); }
 |      PostfixExpression INCREMENT
                { write_exp_elt_opcode (pstate, UNOP_POSTINCREMENT); }
 |      PostfixExpression DECREMENT
@@ -475,15 +481,13 @@ PrimaryExpression:
                    {
                      if (symbol_read_needs_frame (sym.symbol))
                        {
-                         if (innermost_block == 0 ||
-                             contained_in (sym.block, innermost_block))
+                         if (innermost_block == 0
+                             || contained_in (sym.block, innermost_block))
                            innermost_block = sym.block;
                        }
 
                      write_exp_elt_opcode (pstate, OP_VAR_VALUE);
-                     /* We want to use the selected frame, not another more inner frame
-                        which happens to be in the same block.  */
-                     write_exp_elt_block (pstate, NULL);
+                     write_exp_elt_block (pstate, sym.block);
                      write_exp_elt_sym (pstate, sym.symbol);
                      write_exp_elt_opcode (pstate, OP_VAR_VALUE);
                    }
@@ -491,8 +495,8 @@ PrimaryExpression:
                     {
                      /* It hangs off of `this'.  Must not inadvertently convert from a
                         method call to data ref.  */
-                     if (innermost_block == 0 ||
-                         contained_in (sym.block, innermost_block))
+                     if (innermost_block == 0
+                         || contained_in (sym.block, innermost_block))
                        innermost_block = sym.block;
                      write_exp_elt_opcode (pstate, OP_THIS);
                      write_exp_elt_opcode (pstate, OP_THIS);
@@ -522,13 +526,14 @@ PrimaryExpression:
                            {
                              struct bound_minimal_symbol msymbol;
                              struct block_symbol sym;
-                             const char *typename = TYPE_SAFE_NAME (type);
-                             int typename_len = strlen (typename);
-                             char *name = malloc (typename_len + $3.length + 1);
+                             const char *type_name = TYPE_SAFE_NAME (type);
+                             int type_name_len = strlen (type_name);
+                             char *name;
 
-                             make_cleanup (free, name);
-                             sprintf (name, "%.*s.%.*s",
-                                      typename_len, typename, $3.length, $3.ptr);
+                             name = xstrprintf ("%.*s.%.*s",
+                                                type_name_len, type_name,
+                                                $3.length, $3.ptr);
+                             make_cleanup (xfree, name);
 
                              sym =
                                lookup_symbol (name, (const struct block *) NULL,
@@ -553,9 +558,7 @@ PrimaryExpression:
 
                          /* Check if the qualified name resolves as a member
                             of an aggregate or an enum type.  */
-                         if (!(TYPE_CODE (type) == TYPE_CODE_STRUCT
-                               || TYPE_CODE (type) == TYPE_CODE_UNION
-                               || TYPE_CODE (type) == TYPE_CODE_ENUM))
+                         if (!type_aggregate_p (type))
                            error (_("`%s' is not defined as an aggregate type."),
                                   TYPE_SAFE_NAME (type));
 
@@ -615,6 +618,8 @@ PrimaryExpression:
                  write_exp_elt_longcst (pstate, (LONGEST) 0);
                  write_exp_elt_longcst (pstate, (LONGEST) $1 - 1);
                  write_exp_elt_opcode (pstate, OP_ARRAY); }
+|      TYPEOF_KEYWORD '(' Expression ')'
+               { write_exp_elt_opcode (pstate, OP_TYPEOF); }
 ;
 
 ArrayLiteral:
@@ -639,7 +644,7 @@ StringExp:
 
                  vec->type = $1.type;
                  vec->length = $1.length;
-                 vec->ptr = malloc ($1.length + 1);
+                 vec->ptr = (char *) malloc ($1.length + 1);
                  memcpy (vec->ptr, $1.ptr, $1.length + 1);
                }
 |      StringExp STRING_LITERAL
@@ -647,10 +652,10 @@ StringExp:
                     for convenience.  */
                  char *p;
                  ++$$.len;
-                 $$.tokens = realloc ($$.tokens,
-                                      $$.len * sizeof (struct typed_stoken));
+                 $$.tokens
+                   = XRESIZEVEC (struct typed_stoken, $$.tokens, $$.len);
 
-                 p = malloc ($2.length + 1);
+                 p = (char *) malloc ($2.length + 1);
                  memcpy (p, $2.ptr, $2.length + 1);
 
                  $$.tokens[$$.len - 1].type = $2.type;
@@ -694,6 +699,17 @@ BasicType:
 
 %%
 
+/* Return true if the type is aggregate-like.  */
+
+static int
+type_aggregate_p (struct type *type)
+{
+  return (TYPE_CODE (type) == TYPE_CODE_STRUCT
+         || TYPE_CODE (type) == TYPE_CODE_UNION
+         || (TYPE_CODE (type) == TYPE_CODE_ENUM
+             && TYPE_DECLARED_CLASS (type)));
+}
+
 /* Take care of parsing a number (anything that starts with a digit).
    Set yylval and return the token type; update lexptr.
    LEN is the number of characters in it.  */
@@ -989,7 +1005,7 @@ parse_string_or_char (const char *tokptr, const char **outptr,
   else
     value->type = C_STRING;
 
-  value->ptr = obstack_base (&tempbuf);
+  value->ptr = (char *) obstack_base (&tempbuf);
   value->length = obstack_object_size (&tempbuf);
 
   *outptr = tokptr;
@@ -1207,8 +1223,8 @@ lex_one_token (struct parser_state *par_state)
            /* We will take any letters or digits, ignoring any embedded '_'.
               parse_number will complain if past the radix, or if L or U are
               not final.  */
-           else if ((*p < '0' || *p > '9') && (*p != '_') &&
-                    ((*p < 'a' || *p > 'z') && (*p < 'A' || *p > 'Z')))
+           else if ((*p < '0' || *p > '9') && (*p != '_')
+                    && ((*p < 'a' || *p > 'z') && (*p < 'A' || *p > 'Z')))
              break;
          }
 
@@ -1439,6 +1455,8 @@ classify_inner_name (struct parser_state *par_state,
     return classify_name (par_state, block);
 
   type = check_typedef (context);
+  if (!type_aggregate_p (type))
+    return ERROR;
 
   copy = copy_name (yylval.ssym.stoken);
   yylval.ssym.sym = d_lookup_nested_symbol (type, copy, block);
@@ -1540,7 +1558,7 @@ yylex (void)
              obstack_grow (&name_obstack, next->value.sval.ptr,
                            next->value.sval.length);
 
-             yylval.sval.ptr = obstack_base (&name_obstack);
+             yylval.sval.ptr = (char *) obstack_base (&name_obstack);
              yylval.sval.length = obstack_object_size (&name_obstack);
 
              current.token = classify_name (pstate, expression_context_block);
@@ -1620,7 +1638,7 @@ yylex (void)
          obstack_grow (&name_obstack, next->value.sval.ptr,
                        next->value.sval.length);
 
-         yylval.sval.ptr = obstack_base (&name_obstack);
+         yylval.sval.ptr = (char *) obstack_base (&name_obstack);
          yylval.sval.length = obstack_object_size (&name_obstack);
          current.value = yylval;
          current.token = classification;
This page took 0.02853 seconds and 4 git commands to generate.