Remove DEF_VECs from symtab.h
[deliverable/binutils-gdb.git] / gdb / d-exp.y
index 426f9b33551235c6d3a4669b4ddf8a39b342f674..c09fe7a3f36aa706a8de5aafdb232ff3887d6800 100644 (file)
@@ -1,6 +1,6 @@
 /* YACC parser for D expressions, for GDB.
 
-   Copyright (C) 2014-2016 Free Software Foundation, Inc.
+   Copyright (C) 2014-2018 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -69,7 +69,7 @@ int yyparse (void);
 
 static int yylex (void);
 
-void yyerror (char *);
+static void yyerror (const char *);
 
 static int type_aggregate_p (struct type *);
 
@@ -86,7 +86,7 @@ static int type_aggregate_p (struct type *);
       struct type *type;
     } typed_val_int;
     struct {
-      DOUBLEST dval;
+      gdb_byte val[16];
       struct type *type;
     } typed_val_float;
     struct symbol *sym;
@@ -321,15 +321,12 @@ UnaryExpression:
 
 CastExpression:
        CAST_KEYWORD '(' TypeExp ')' UnaryExpression
-               { write_exp_elt_opcode (pstate, UNOP_CAST);
-                 write_exp_elt_type (pstate, $3);
-                 write_exp_elt_opcode (pstate, UNOP_CAST); }
+               { write_exp_elt_opcode (pstate, UNOP_CAST_TYPE); }
        /* C style cast is illegal D, but is still recognised in
           the grammar, so we keep this around for convenience.  */
 |      '(' TypeExp ')' UnaryExpression
-               { write_exp_elt_opcode (pstate, UNOP_CAST);
-                 write_exp_elt_type (pstate, $2);
-                 write_exp_elt_opcode (pstate, UNOP_CAST); }
+               { write_exp_elt_opcode (pstate, UNOP_CAST_TYPE); }
+
 ;
 
 PowExpression:
@@ -425,12 +422,7 @@ PrimaryExpression:
                  if (sym.symbol && SYMBOL_CLASS (sym.symbol) != LOC_TYPEDEF)
                    {
                      if (symbol_read_needs_frame (sym.symbol))
-                       {
-                         if (innermost_block == 0
-                             || contained_in (sym.block, innermost_block))
-                           innermost_block = sym.block;
-                       }
-
+                       innermost_block.update (sym);
                      write_exp_elt_opcode (pstate, OP_VAR_VALUE);
                      write_exp_elt_block (pstate, sym.block);
                      write_exp_elt_sym (pstate, sym.symbol);
@@ -440,9 +432,7 @@ 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))
-                       innermost_block = sym.block;
+                     innermost_block.update (sym);
                      write_exp_elt_opcode (pstate, OP_THIS);
                      write_exp_elt_opcode (pstate, OP_THIS);
                      write_exp_elt_opcode (pstate, STRUCTOP_PTR);
@@ -473,15 +463,14 @@ PrimaryExpression:
                              struct block_symbol sym;
                              const char *type_name = TYPE_SAFE_NAME (type);
                              int type_name_len = strlen (type_name);
-                             char *name;
-
-                             name = xstrprintf ("%.*s.%.*s",
+                             std::string name
+                               = string_printf ("%.*s.%.*s",
                                                 type_name_len, type_name,
                                                 $3.length, $3.ptr);
-                             make_cleanup (xfree, name);
 
                              sym =
-                               lookup_symbol (name, (const struct block *) NULL,
+                               lookup_symbol (name.c_str (),
+                                              (const struct block *) NULL,
                                               VAR_DOMAIN, NULL);
                              if (sym.symbol)
                                {
@@ -492,13 +481,14 @@ PrimaryExpression:
                                  break;
                                }
 
-                             msymbol = lookup_bound_minimal_symbol (name);
+                             msymbol = lookup_bound_minimal_symbol (name.c_str ());
                              if (msymbol.minsym != NULL)
                                write_exp_msymbol (pstate, msymbol);
                              else if (!have_full_symbols () && !have_partial_symbols ())
                                error (_("No symbol table is loaded.  Use the \"file\" command."));
                              else
-                               error (_("No symbol \"%s\" in current context."), name);
+                               error (_("No symbol \"%s\" in current context."),
+                                      name.c_str ());
                            }
 
                          /* Check if the qualified name resolves as a member
@@ -543,10 +533,10 @@ PrimaryExpression:
                  write_exp_elt_longcst (pstate, (LONGEST)($1.val));
                  write_exp_elt_opcode (pstate, OP_LONG); }
 |      FLOAT_LITERAL
-               { write_exp_elt_opcode (pstate, OP_DOUBLE);
+               { write_exp_elt_opcode (pstate, OP_FLOAT);
                  write_exp_elt_type (pstate, $1.type);
-                 write_exp_elt_dblcst (pstate, $1.dval);
-                 write_exp_elt_opcode (pstate, OP_DOUBLE); }
+                 write_exp_elt_floatcst (pstate, $1.val);
+                 write_exp_elt_opcode (pstate, OP_FLOAT); }
 |      CHARACTER_LITERAL
                { struct stoken_vector vec;
                  vec.len = 1;
@@ -651,6 +641,7 @@ type_aggregate_p (struct type *type)
 {
   return (TYPE_CODE (type) == TYPE_CODE_STRUCT
          || TYPE_CODE (type) == TYPE_CODE_UNION
+         || TYPE_CODE (type) == TYPE_CODE_MODULE
          || (TYPE_CODE (type) == TYPE_CODE_ENUM
              && TYPE_DECLARED_CLASS (type)));
 }
@@ -684,8 +675,6 @@ parse_number (struct parser_state *ps, const char *p,
 
   if (parsed_float)
     {
-      const char *suffix;
-      int suffix_len;
       char *s, *sp;
 
       /* Strip out all embedded '_' before passing to parse_float.  */
@@ -700,54 +689,51 @@ parse_number (struct parser_state *ps, const char *p,
       *sp = '\0';
       len = strlen (s);
 
-      if (! parse_float (s, len, &putithere->typed_val_float.dval, &suffix))
-       return ERROR;
-
-      suffix_len = s + len - suffix;
-
-      if (suffix_len == 0)
+      /* Check suffix for `i' , `fi' or `li' (idouble, ifloat or ireal).  */
+      if (len >= 1 && tolower (s[len - 1]) == 'i')
        {
-         putithere->typed_val_float.type
-           = parse_d_type (ps)->builtin_double;
-       }
-      else if (suffix_len == 1)
-       {
-         /* Check suffix for `f', `l', or `i' (float, real, or idouble).  */
-         if (tolower (*suffix) == 'f')
+         if (len >= 2 && tolower (s[len - 2]) == 'f')
            {
              putithere->typed_val_float.type
-               = parse_d_type (ps)->builtin_float;
+               = parse_d_type (ps)->builtin_ifloat;
+             len -= 2;
            }
-         else if (tolower (*suffix) == 'l')
+         else if (len >= 2 && tolower (s[len - 2]) == 'l')
            {
              putithere->typed_val_float.type
-               = parse_d_type (ps)->builtin_real;
+               = parse_d_type (ps)->builtin_ireal;
+             len -= 2;
            }
-         else if (tolower (*suffix) == 'i')
+         else
            {
              putithere->typed_val_float.type
                = parse_d_type (ps)->builtin_idouble;
+             len -= 1;
            }
-         else
-           return ERROR;
        }
-      else if (suffix_len == 2)
+      /* Check suffix for `f' or `l'' (float or real).  */
+      else if (len >= 1 && tolower (s[len - 1]) == 'f')
        {
-         /* Check suffix for `fi' or `li' (ifloat or ireal).  */
-         if (tolower (suffix[0]) == 'f' && tolower (suffix[1] == 'i'))
-           {
-             putithere->typed_val_float.type
-               = parse_d_type (ps)->builtin_ifloat;
-           }
-         else if (tolower (suffix[0]) == 'l' && tolower (suffix[1] == 'i'))
-           {
-             putithere->typed_val_float.type
-               = parse_d_type (ps)->builtin_ireal;
-           }
-         else
-           return ERROR;
+         putithere->typed_val_float.type
+           = parse_d_type (ps)->builtin_float;
+         len -= 1;
        }
+      else if (len >= 1 && tolower (s[len - 1]) == 'l')
+       {
+         putithere->typed_val_float.type
+           = parse_d_type (ps)->builtin_real;
+         len -= 1;
+       }
+      /* Default type if no suffix.  */
       else
+       {
+         putithere->typed_val_float.type
+           = parse_d_type (ps)->builtin_double;
+       }
+
+      if (!parse_float (s, len,
+                       putithere->typed_val_float.type,
+                       putithere->typed_val_float.val))
        return ERROR;
 
       return FLOAT_LITERAL;
@@ -959,7 +945,7 @@ parse_string_or_char (const char *tokptr, const char **outptr,
 
 struct token
 {
-  char *oper;
+  const char *oper;
   int token;
   enum exp_opcode opcode;
 };
@@ -1123,7 +1109,7 @@ lex_one_token (struct parser_state *par_state)
            last_was_structop = 1;
          goto symbol;          /* Nope, must be a symbol.  */
        }
-      /* FALL THRU into number case.  */
+      /* FALL THRU.  */
 
     case '0':
     case '1':
@@ -1327,24 +1313,23 @@ lex_one_token (struct parser_state *par_state)
 }
 
 /* An object of this type is pushed on a FIFO by the "outer" lexer.  */
-typedef struct
+struct token_and_value
 {
   int token;
   YYSTYPE value;
-} token_and_value;
+};
 
-DEF_VEC_O (token_and_value);
 
 /* A FIFO of tokens that have been read but not yet returned to the
    parser.  */
-static VEC (token_and_value) *token_fifo;
+static std::vector<token_and_value> token_fifo;
 
 /* Non-zero if the lexer should return tokens from the FIFO.  */
 static int popping;
 
 /* Temporary storage for yylex; this holds symbol names as they are
    built up.  */
-static struct obstack name_obstack;
+static auto_obstack name_obstack;
 
 /* Classify an IDENTIFIER token.  The contents of the token are in `yylval'.
    Updates yylval and returns the new token type.  BLOCK is the block
@@ -1433,7 +1418,7 @@ yylex (void)
   int last_to_examine, next_to_examine, checkpoint;
   const struct block *search_block;
 
-  if (popping && !VEC_empty (token_and_value, token_fifo))
+  if (popping && !token_fifo.empty ())
     goto do_pop;
   popping = 0;
 
@@ -1445,14 +1430,14 @@ yylex (void)
   /* Read any sequence of alternating "." and identifier tokens into
      the token FIFO.  */
   current.value = yylval;
-  VEC_safe_push (token_and_value, token_fifo, &current);
+  token_fifo.push_back (current);
   last_was_dot = current.token == '.';
 
   while (1)
     {
       current.token = lex_one_token (pstate);
       current.value = yylval;
-      VEC_safe_push (token_and_value, token_fifo, &current);
+      token_fifo.push_back (current);
 
       if ((last_was_dot && current.token != IDENTIFIER)
          || (!last_was_dot && current.token != '.'))
@@ -1464,10 +1449,10 @@ yylex (void)
 
   /* We always read one extra token, so compute the number of tokens
      to examine accordingly.  */
-  last_to_examine = VEC_length (token_and_value, token_fifo) - 2;
+  last_to_examine = token_fifo.size () - 2;
   next_to_examine = 0;
 
-  current = *VEC_index (token_and_value, token_fifo, next_to_examine);
+  current = token_fifo[next_to_examine];
   ++next_to_examine;
 
   /* If we are not dealing with a typename, now is the time to find out.  */
@@ -1482,7 +1467,7 @@ yylex (void)
      first try building up a name until we find the qualified module.  */
   if (current.token == UNKNOWN_NAME)
     {
-      obstack_free (&name_obstack, obstack_base (&name_obstack));
+      name_obstack.clear ();
       obstack_grow (&name_obstack, current.value.sval.ptr,
                    current.value.sval.length);
 
@@ -1490,17 +1475,17 @@ yylex (void)
 
       while (next_to_examine <= last_to_examine)
        {
-         token_and_value *next;
+         token_and_value next;
 
-         next = VEC_index (token_and_value, token_fifo, next_to_examine);
+         next = token_fifo[next_to_examine];
          ++next_to_examine;
 
-         if (next->token == IDENTIFIER && last_was_dot)
+         if (next.token == IDENTIFIER && last_was_dot)
            {
              /* Update the partial name we are constructing.  */
               obstack_grow_str (&name_obstack, ".");
-             obstack_grow (&name_obstack, next->value.sval.ptr,
-                           next->value.sval.length);
+             obstack_grow (&name_obstack, next.value.sval.ptr,
+                           next.value.sval.length);
 
              yylval.sval.ptr = (char *) obstack_base (&name_obstack);
              yylval.sval.length = obstack_object_size (&name_obstack);
@@ -1512,13 +1497,13 @@ yylex (void)
              if (current.token == TYPENAME)
                {
                  /* Install it as the first token in the FIFO.  */
-                 VEC_replace (token_and_value, token_fifo, 0, &current);
-                 VEC_block_remove (token_and_value, token_fifo, 1,
-                                   next_to_examine - 1);
+                 token_fifo[0] = current;
+                 token_fifo.erase (token_fifo.begin () + 1,
+                                   token_fifo.begin () + next_to_examine);
                  break;
                }
            }
-         else if (next->token == '.' && !last_was_dot)
+         else if (next.token == '.' && !last_was_dot)
            last_was_dot = 1;
          else
            {
@@ -1529,13 +1514,13 @@ yylex (void)
 
       /* Reset our current token back to the start, if we found nothing
         this means that we will just jump to do pop.  */
-      current = *VEC_index (token_and_value, token_fifo, 0);
+      current = token_fifo[0];
       next_to_examine = 1;
     }
   if (current.token != TYPENAME && current.token != '.')
     goto do_pop;
 
-  obstack_free (&name_obstack, obstack_base (&name_obstack));
+  name_obstack.clear ();
   checkpoint = 0;
   if (current.token == '.')
     search_block = NULL;
@@ -1553,16 +1538,16 @@ yylex (void)
 
   while (next_to_examine <= last_to_examine)
     {
-      token_and_value *next;
+      token_and_value next;
 
-      next = VEC_index (token_and_value, token_fifo, next_to_examine);
+      next = token_fifo[next_to_examine];
       ++next_to_examine;
 
-      if (next->token == IDENTIFIER && last_was_dot)
+      if (next.token == IDENTIFIER && last_was_dot)
        {
          int classification;
 
-         yylval = next->value;
+         yylval = next.value;
          classification = classify_inner_name (pstate, search_block,
                                                context_type);
          /* We keep going until we either run out of names, or until
@@ -1579,8 +1564,8 @@ yylex (void)
              /* We don't want to put a leading "." into the name.  */
               obstack_grow_str (&name_obstack, ".");
            }
-         obstack_grow (&name_obstack, next->value.sval.ptr,
-                       next->value.sval.length);
+         obstack_grow (&name_obstack, next.value.sval.ptr,
+                       next.value.sval.length);
 
          yylval.sval.ptr = (char *) obstack_base (&name_obstack);
          yylval.sval.length = obstack_object_size (&name_obstack);
@@ -1594,7 +1579,7 @@ yylex (void)
 
          context_type = yylval.tsym.type;
        }
-      else if (next->token == '.' && !last_was_dot)
+      else if (next.token == '.' && !last_was_dot)
        last_was_dot = 1;
       else
        {
@@ -1607,14 +1592,15 @@ yylex (void)
      the FIFO, and delete the other constituent tokens.  */
   if (checkpoint > 0)
     {
-      VEC_replace (token_and_value, token_fifo, 0, &current);
+      token_fifo[0] = current;
       if (checkpoint > 1)
-       VEC_block_remove (token_and_value, token_fifo, 1, checkpoint - 1);
+       token_fifo.erase (token_fifo.begin () + 1,
+                         token_fifo.begin () + checkpoint);
     }
 
  do_pop:
-  current = *VEC_index (token_and_value, token_fifo, 0);
-  VEC_ordered_remove (token_and_value, token_fifo, 0);
+  current = token_fifo[0];
+  token_fifo.erase (token_fifo.begin ());
   yylval = current.value;
   return current.token;
 }
@@ -1622,39 +1608,31 @@ yylex (void)
 int
 d_parse (struct parser_state *par_state)
 {
-  int result;
-  struct cleanup *back_to;
-
   /* Setting up the parser state.  */
+  scoped_restore pstate_restore = make_scoped_restore (&pstate);
   gdb_assert (par_state != NULL);
   pstate = par_state;
 
-  back_to = make_cleanup (null_cleanup, NULL);
-
-  make_cleanup_restore_integer (&yydebug);
-  make_cleanup_clear_parser_state (&pstate);
-  yydebug = parser_debug;
+  scoped_restore restore_yydebug = make_scoped_restore (&yydebug,
+                                                       parser_debug);
 
   /* Initialize some state used by the lexer.  */
   last_was_structop = 0;
   saw_name_at_eof = 0;
 
-  VEC_free (token_and_value, token_fifo);
+  token_fifo.clear ();
   popping = 0;
-  obstack_init (&name_obstack);
-  make_cleanup_obstack_free (&name_obstack);
+  name_obstack.clear ();
 
-  result = yyparse ();
-  do_cleanups (back_to);
-  return result;
+  return yyparse ();
 }
 
-void
-yyerror (char *msg)
+static void
+yyerror (const char *msg)
 {
   if (prev_lexptr)
     lexptr = prev_lexptr;
 
-  error (_("A %s in expression, near `%s'."), (msg ? msg : "error"), lexptr);
+  error (_("A %s in expression, near `%s'."), msg, lexptr);
 }
 
This page took 0.037242 seconds and 4 git commands to generate.