Fix PR cli/18053
[deliverable/binutils-gdb.git] / gdb / c-exp.y
index 84f3a338bf88483bb031942a694a4e6a2c1c0af1..29f672f54c8a6027e60f9dff6e597c20c8b36a56 100644 (file)
@@ -1,5 +1,5 @@
 /* YACC parser for C expressions, for GDB.
-   Copyright (C) 1986-2015 Free Software Foundation, Inc.
+   Copyright (C) 1986-2016 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
 
 #define parse_type(ps) builtin_type (parse_gdbarch (ps))
 
-/* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
-   as well as gratuitiously global symbol names, so we can have multiple
-   yacc generated parsers in gdb.  Note that these are only the variables
-   produced by yacc.  If other parser generators (bison, byacc, etc) produce
-   additional global names that conflict at link time, then those parser
-   generators need to be fixed instead of adding those names to this list. */
-
-#define        yymaxdepth c_maxdepth
-#define        yyparse c_parse_internal
-#define        yylex   c_lex
-#define        yyerror c_error
-#define        yylval  c_lval
-#define        yychar  c_char
-#define        yydebug c_debug
-#define        yypact  c_pact  
-#define        yyr1    c_r1                    
-#define        yyr2    c_r2                    
-#define        yydef   c_def           
-#define        yychk   c_chk           
-#define        yypgo   c_pgo           
-#define        yyact   c_act           
-#define        yyexca  c_exca
-#define yyerrflag c_errflag
-#define yynerrs        c_nerrs
-#define        yyps    c_ps
-#define        yypv    c_pv
-#define        yys     c_s
-#define        yy_yys  c_yys
-#define        yystate c_state
-#define        yytmp   c_tmp
-#define        yyv     c_v
-#define        yy_yyv  c_yyv
-#define        yyval   c_val
-#define        yylloc  c_lloc
-#define yyreds c_reds          /* With YYDEBUG defined */
-#define yytoks c_toks          /* With YYDEBUG defined */
-#define yyname c_name          /* With YYDEBUG defined */
-#define yyrule c_rule          /* With YYDEBUG defined */
-#define yylhs  c_yylhs
-#define yylen  c_yylen
-#define yydefred c_yydefred
-#define yydgoto        c_yydgoto
-#define yysindex c_yysindex
-#define yyrindex c_yyrindex
-#define yygindex c_yygindex
-#define yytable         c_yytable
-#define yycheck         c_yycheck
-#define yyss   c_yyss
-#define yysslim        c_yysslim
-#define yyssp  c_yyssp
-#define yystacksize c_yystacksize
-#define yyvs   c_yyvs
-#define yyvsp  c_yyvsp
-
-#ifndef YYDEBUG
-#define        YYDEBUG 1               /* Default to yydebug support */
-#endif
-
-#define YYFPRINTF parser_fprintf
+/* Remap normal yacc parser interface names (yyparse, yylex, yyerror,
+   etc).  */
+#define GDB_YY_REMAP_PREFIX c_
+#include "yy-remap.h"
 
 /* The state of the parser, used internally when we are parsing the
    expression.  */
@@ -793,7 +738,7 @@ exp :       SIZEOF '(' type ')'     %prec UNARY
                                              (parse_language (pstate),
                                               parse_gdbarch (pstate),
                                               "int"));
-                         CHECK_TYPEDEF (type);
+                         type = check_typedef (type);
 
                            /* $5.3.3/2 of the C++ Standard (n3290 draft)
                               says of sizeof:  "When applied to a reference
@@ -839,7 +784,7 @@ string_exp:
 
                          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);
                        }
 
@@ -849,10 +794,10 @@ string_exp:
                             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;
@@ -864,7 +809,7 @@ string_exp:
 exp    :       string_exp
                        {
                          int i;
-                         enum c_string_type type = C_STRING;
+                         c_string_type type = C_STRING;
 
                          for (i = 0; i < $1.len; ++i)
                            {
@@ -878,7 +823,7 @@ exp :       string_exp
                                  if (type != C_STRING
                                      && type != $1.tokens[i].type)
                                    error (_("Undefined string concatenation."));
-                                 type = $1.tokens[i].type;
+                                 type = (enum c_string_type_values) $1.tokens[i].type;
                                  break;
                                default:
                                  /* internal error */
@@ -923,8 +868,8 @@ exp     :       FALSEKEYWORD
 
 block  :       BLOCKNAME
                        {
-                         if ($1.sym)
-                           $$ = SYMBOL_BLOCK_VALUE ($1.sym);
+                         if ($1.sym.symbol)
+                           $$ = SYMBOL_BLOCK_VALUE ($1.sym.symbol);
                          else
                            error (_("No file or function \"%s\"."),
                                   copy_name ($1.stoken));
@@ -938,7 +883,8 @@ block       :       BLOCKNAME
 block  :       block COLONCOLON name
                        { struct symbol *tem
                            = lookup_symbol (copy_name ($3), $1,
-                                            VAR_DOMAIN, NULL);
+                                            VAR_DOMAIN, NULL).symbol;
+
                          if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
                            error (_("No function \"%s\" in specified context."),
                                   copy_name ($3));
@@ -946,7 +892,7 @@ block       :       block COLONCOLON name
        ;
 
 variable:      name_not_typename ENTRY
-                       { struct symbol *sym = $1.sym;
+                       { struct symbol *sym = $1.sym.symbol;
 
                          if (sym == NULL || !SYMBOL_IS_ARGUMENT (sym)
                              || !symbol_read_needs_frame (sym))
@@ -961,31 +907,31 @@ variable: name_not_typename ENTRY
        ;
 
 variable:      block COLONCOLON name
-                       { struct symbol *sym;
-                         sym = lookup_symbol (copy_name ($3), $1,
-                                              VAR_DOMAIN, NULL);
-                         if (sym == 0)
+                       { struct block_symbol sym
+                           = lookup_symbol (copy_name ($3), $1,
+                                            VAR_DOMAIN, NULL);
+
+                         if (sym.symbol == 0)
                            error (_("No symbol \"%s\" in specified context."),
                                   copy_name ($3));
-                         if (symbol_read_needs_frame (sym))
+                         if (symbol_read_needs_frame (sym.symbol))
                            {
                              if (innermost_block == 0
-                                 || contained_in (block_found,
+                                 || contained_in (sym.block,
                                                   innermost_block))
-                               innermost_block = block_found;
+                               innermost_block = sym.block;
                            }
 
                          write_exp_elt_opcode (pstate, OP_VAR_VALUE);
-                         /* block_found is set by lookup_symbol.  */
-                         write_exp_elt_block (pstate, block_found);
-                         write_exp_elt_sym (pstate, sym);
+                         write_exp_elt_block (pstate, sym.block);
+                         write_exp_elt_sym (pstate, sym.symbol);
                          write_exp_elt_opcode (pstate, OP_VAR_VALUE); }
        ;
 
 qualified_name:        TYPENAME COLONCOLON name
                        {
                          struct type *type = $1.type;
-                         CHECK_TYPEDEF (type);
+                         type = check_typedef (type);
                          if (!type_aggregate_p (type))
                            error (_("`%s' is not defined as an aggregate type."),
                                   TYPE_SAFE_NAME (type));
@@ -1001,11 +947,11 @@ qualified_name:  TYPENAME COLONCOLON name
                          struct stoken tmp_token;
                          char *buf;
 
-                         CHECK_TYPEDEF (type);
+                         type = check_typedef (type);
                          if (!type_aggregate_p (type))
                            error (_("`%s' is not defined as an aggregate type."),
                                   TYPE_SAFE_NAME (type));
-                         buf = alloca ($4.length + 2);
+                         buf = (char *) alloca ($4.length + 2);
                          tmp_token.ptr = buf;
                          tmp_token.length = $4.length + 1;
                          buf[0] = '~';
@@ -1035,9 +981,9 @@ variable:  qualified_name
                          struct symbol *sym;
                          struct bound_minimal_symbol msymbol;
 
-                         sym =
-                           lookup_symbol (name, (const struct block *) NULL,
-                                          VAR_DOMAIN, NULL);
+                         sym
+                           lookup_symbol (name, (const struct block *) NULL,
+                                            VAR_DOMAIN, NULL).symbol;
                          if (sym)
                            {
                              write_exp_elt_opcode (pstate, OP_VAR_VALUE);
@@ -1058,24 +1004,21 @@ variable:       qualified_name
        ;
 
 variable:      name_not_typename
-                       { struct symbol *sym = $1.sym;
+                       { struct block_symbol sym = $1.sym;
 
-                         if (sym)
+                         if (sym.symbol)
                            {
-                             if (symbol_read_needs_frame (sym))
+                             if (symbol_read_needs_frame (sym.symbol))
                                {
                                  if (innermost_block == 0
-                                     || contained_in (block_found,
+                                     || contained_in (sym.block,
                                                       innermost_block))
-                                   innermost_block = block_found;
+                                   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_sym (pstate, sym);
+                             write_exp_elt_block (pstate, sym.block);
+                             write_exp_elt_sym (pstate, sym.symbol);
                              write_exp_elt_opcode (pstate, OP_VAR_VALUE);
                            }
                          else if ($1.is_a_field_of_this)
@@ -1084,9 +1027,9 @@ variable: name_not_typename
                                 not inadvertently convert from a method call
                                 to data ref.  */
                              if (innermost_block == 0
-                                 || contained_in (block_found,
+                                 || contained_in (sym.block,
                                                   innermost_block))
-                               innermost_block = block_found;
+                               innermost_block = sym.block;
                              write_exp_elt_opcode (pstate, OP_THIS);
                              write_exp_elt_opcode (pstate, OP_THIS);
                              write_exp_elt_opcode (pstate, STRUCTOP_PTR);
@@ -1666,7 +1609,7 @@ name_not_typename :       NAME
 static void
 write_destructor_name (struct parser_state *par_state, struct stoken token)
 {
-  char *copy = alloca (token.length + 1);
+  char *copy = (char *) alloca (token.length + 1);
 
   copy[0] = '~';
   memcpy (&copy[1], token.ptr, token.length);
@@ -1688,7 +1631,7 @@ operator_stoken (const char *op)
   char *buf;
 
   st.length = strlen (operator_string) + strlen (op);
-  buf = malloc (st.length + 1);
+  buf = (char *) malloc (st.length + 1);
   strcpy (buf, operator_string);
   strcat (buf, op);
   st.ptr = buf;
@@ -1773,7 +1716,7 @@ parse_number (struct parser_state *par_state,
   struct type *unsigned_type;
   char *p;
 
-  p = alloca (len);
+  p = (char *) alloca (len);
   memcpy (p, buf, len);
 
   if (parsed_float)
@@ -2166,7 +2109,7 @@ parse_string_or_char (const char *tokptr, const char **outptr,
                      struct typed_stoken *value, int *host_chars)
 {
   int quote;
-  enum c_string_type type;
+  c_string_type type;
   int is_objc = 0;
 
   /* Build the gdb internal form of the input string in tempbuf.  Note
@@ -2249,7 +2192,7 @@ parse_string_or_char (const char *tokptr, const char **outptr,
   ++tokptr;
 
   value->type = type;
-  value->ptr = obstack_base (&tempbuf);
+  value->ptr = (char *) obstack_base (&tempbuf);
   value->length = obstack_object_size (&tempbuf);
 
   *outptr = tokptr;
@@ -2259,7 +2202,7 @@ parse_string_or_char (const char *tokptr, const char **outptr,
 
 /* This is used to associate some attributes with a token.  */
 
-enum token_flags
+enum token_flag
 {
   /* If this bit is set, the token is C++-only.  */
 
@@ -2271,13 +2214,14 @@ enum token_flags
 
   FLAG_SHADOW = 2
 };
+DEF_ENUM_FLAGS_TYPE (enum token_flag, token_flags);
 
 struct token
 {
   char *oper;
   int token;
   enum exp_opcode opcode;
-  enum token_flags flags;
+  token_flags flags;
 };
 
 static const struct token tokentab3[] =
@@ -2401,7 +2345,8 @@ scan_macro_expansion (char *expansion)
 
   /* Copy to the obstack, and then free the intermediate
      expansion.  */
-  copy = obstack_copy0 (&expansion_obstack, expansion, strlen (expansion));
+  copy = (char *) obstack_copy0 (&expansion_obstack, expansion,
+                                strlen (expansion));
   xfree (expansion);
 
   /* Save the old lexptr value, so we can return to it when we're done
@@ -2817,7 +2762,7 @@ lex_one_token (struct parser_state *par_state, int *is_quoted_name)
                               VAR_DOMAIN,
                               (parse_language (par_state)->la_language
                                == language_cplus ? &is_a_field_of_this
-                               : NULL))
+                               : NULL)).symbol
                != NULL)
              {
                /* The keyword is shadowed.  */
@@ -2838,7 +2783,8 @@ lex_one_token (struct parser_state *par_state, int *is_quoted_name)
     saw_name_at_eof = 1;
 
   yylval.ssym.stoken = yylval.sval;
-  yylval.ssym.sym = NULL;
+  yylval.ssym.sym.symbol = NULL;
+  yylval.ssym.sym.block = NULL;
   yylval.ssym.is_a_field_of_this = 0;
   return NAME;
 }
@@ -2873,7 +2819,7 @@ static int
 classify_name (struct parser_state *par_state, const struct block *block,
               int is_quoted_name)
 {
-  struct symbol *sym;
+  struct block_symbol bsym;
   char *copy;
   struct field_of_this_result is_a_field_of_this;
 
@@ -2883,17 +2829,17 @@ classify_name (struct parser_state *par_state, const struct block *block,
      we can refer to it unconditionally below.  */
   memset (&is_a_field_of_this, 0, sizeof (is_a_field_of_this));
 
-  sym = lookup_symbol (copy, block, VAR_DOMAIN,
-                      parse_language (par_state)->la_name_of_this
-                      ? &is_a_field_of_this : NULL);
+  bsym = lookup_symbol (copy, block, VAR_DOMAIN,
+                       parse_language (par_state)->la_name_of_this
+                       ? &is_a_field_of_this : NULL);
 
-  if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
+  if (bsym.symbol && SYMBOL_CLASS (bsym.symbol) == LOC_BLOCK)
     {
-      yylval.ssym.sym = sym;
+      yylval.ssym.sym = bsym;
       yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
       return BLOCKNAME;
     }
-  else if (!sym)
+  else if (!bsym.symbol)
     {
       /* If we found a field of 'this', we might have erroneously
         found a constructor where we wanted a type name.  Handle this
@@ -2906,11 +2852,11 @@ classify_name (struct parser_state *par_state, const struct block *block,
        {
          struct field_of_this_result inner_is_a_field_of_this;
 
-         sym = lookup_symbol (copy, block, STRUCT_DOMAIN,
-                              &inner_is_a_field_of_this);
-         if (sym != NULL)
+         bsym = lookup_symbol (copy, block, STRUCT_DOMAIN,
+                               &inner_is_a_field_of_this);
+         if (bsym.symbol != NULL)
            {
-             yylval.tsym.type = SYMBOL_TYPE (sym);
+             yylval.tsym.type = SYMBOL_TYPE (bsym.symbol);
              return TYPENAME;
            }
        }
@@ -2934,18 +2880,20 @@ classify_name (struct parser_state *par_state, const struct block *block,
        }
     }
 
-  if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
+  if (bsym.symbol && SYMBOL_CLASS (bsym.symbol) == LOC_TYPEDEF)
     {
-      yylval.tsym.type = SYMBOL_TYPE (sym);
+      yylval.tsym.type = SYMBOL_TYPE (bsym.symbol);
       return TYPENAME;
     }
 
   /* See if it's an ObjC classname.  */
-  if (parse_language (par_state)->la_language == language_objc && !sym)
+  if (parse_language (par_state)->la_language == language_objc && !bsym.symbol)
     {
       CORE_ADDR Class = lookup_objc_class (parse_gdbarch (par_state), copy);
       if (Class)
        {
+         struct symbol *sym;
+
          yylval.theclass.theclass = Class;
          sym = lookup_struct_typedef (copy, expression_context_block, 1);
          if (sym)
@@ -2957,26 +2905,27 @@ classify_name (struct parser_state *par_state, const struct block *block,
   /* Input names that aren't symbols but ARE valid hex numbers, when
      the input radix permits them, can be names or numbers depending
      on the parse.  Note we support radixes > 16 here.  */
-  if (!sym
+  if (!bsym.symbol
       && ((copy[0] >= 'a' && copy[0] < 'a' + input_radix - 10)
          || (copy[0] >= 'A' && copy[0] < 'A' + input_radix - 10)))
     {
       YYSTYPE newlval; /* Its value is ignored.  */
       int hextype = parse_number (par_state, copy, yylval.sval.length,
                                  0, &newlval);
+
       if (hextype == INT)
        {
-         yylval.ssym.sym = sym;
+         yylval.ssym.sym = bsym;
          yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
          return NAME_OR_INT;
        }
     }
 
   /* Any other kind of symbol */
-  yylval.ssym.sym = sym;
+  yylval.ssym.sym = bsym;
   yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
 
-  if (sym == NULL
+  if (bsym.symbol == NULL
       && parse_language (par_state)->la_language == language_cplus
       && is_a_field_of_this.type == NULL
       && lookup_minimal_symbol (copy, NULL, NULL).minsym == NULL)
@@ -3004,12 +2953,13 @@ classify_inner_name (struct parser_state *par_state,
     return ERROR;
 
   copy = copy_name (yylval.ssym.stoken);
-  yylval.ssym.sym = cp_lookup_nested_symbol (type, copy, block);
+  /* N.B. We assume the symbol can only be in VAR_DOMAIN.  */
+  yylval.ssym.sym = cp_lookup_nested_symbol (type, copy, block, VAR_DOMAIN);
 
   /* If no symbol was found, search for a matching base class named
      COPY.  This will allow users to enter qualified names of class members
      relative to the `this' pointer.  */
-  if (yylval.ssym.sym == NULL)
+  if (yylval.ssym.sym.symbol == NULL)
     {
       struct type *base_type = cp_find_type_baseclass_by_name (type, copy);
 
@@ -3022,7 +2972,7 @@ classify_inner_name (struct parser_state *par_state,
       return ERROR;
     }
 
-  switch (SYMBOL_CLASS (yylval.ssym.sym))
+  switch (SYMBOL_CLASS (yylval.ssym.sym.symbol))
     {
     case LOC_BLOCK:
     case LOC_LABEL:
@@ -3041,7 +2991,7 @@ classify_inner_name (struct parser_state *par_state,
       return ERROR;
 
     case LOC_TYPEDEF:
-      yylval.tsym.type = SYMBOL_TYPE (yylval.ssym.sym);
+      yylval.tsym.type = SYMBOL_TYPE (yylval.ssym.sym.symbol);
       return TYPENAME;
 
     default:
@@ -3168,7 +3118,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 = (const char *) obstack_base (&name_obstack);
          yylval.sval.length = obstack_object_size (&name_obstack);
          current.value = yylval;
          current.token = classification;
@@ -3193,9 +3143,10 @@ yylex (void)
      the FIFO, and delete the other constituent tokens.  */
   if (checkpoint > 0)
     {
-      current.value.sval.ptr = obstack_copy0 (&expansion_obstack,
-                                             current.value.sval.ptr,
-                                             current.value.sval.length);
+      current.value.sval.ptr
+       = (const char *) obstack_copy0 (&expansion_obstack,
+                                       current.value.sval.ptr,
+                                       current.value.sval.length);
 
       VEC_replace (token_and_value, token_fifo, 0, &current);
       if (checkpoint > 1)
@@ -3275,7 +3226,7 @@ c_print_token (FILE *file, int type, YYSTYPE value)
     case CHAR:
     case STRING:
       {
-       char *copy = alloca (value.tsval.length + 1);
+       char *copy = (char *) alloca (value.tsval.length + 1);
 
        memcpy (copy, value.tsval.ptr, value.tsval.length);
        copy[value.tsval.length] = '\0';
@@ -3301,8 +3252,8 @@ c_print_token (FILE *file, int type, YYSTYPE value)
     case BLOCKNAME:
       fprintf (file, "ssym<name=%s, sym=%s, field_of_this=%d>",
               copy_name (value.ssym.stoken),
-              (value.ssym.sym == NULL
-               ? "(null)" : SYMBOL_PRINT_NAME (value.ssym.sym)),
+              (value.ssym.sym.symbol == NULL
+               ? "(null)" : SYMBOL_PRINT_NAME (value.ssym.sym.symbol)),
               value.ssym.is_a_field_of_this);
       break;
 
This page took 0.032479 seconds and 4 git commands to generate.