PR exp/9514:
[deliverable/binutils-gdb.git] / gdb / c-exp.y
index 94d0737073864d268a0acbcee176bbf21b9a9a6b..7afce770e20861f8c85b8253305df6ce6ae21ebc 100644 (file)
@@ -1,7 +1,6 @@
 /* YACC parser for C expressions, for GDB.
-   Copyright (C) 1986, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
-   1998, 1999, 2000, 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011
-   Free Software Foundation, Inc.
+   Copyright (C) 1986, 1989-2000, 2003-2004, 2006-2012 Free Software
+   Foundation, Inc.
 
    This file is part of GDB.
 
 #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 */
@@ -167,9 +172,10 @@ static struct stoken operator_stoken (const char *);
 /* %type <bval> block */
 
 /* Fancy type parsing.  */
-%type <voidval> func_mod direct_abs_decl abs_decl
+%type <voidval> func_mod direct_abs_decl abs_decl ptr_operator
 %type <tval> ptype
 %type <lval> array_mod
+%type <tval> conversion_type_id
 
 %token <typed_val_int> INT
 %token <typed_val_float> FLOAT
@@ -208,6 +214,7 @@ static struct stoken operator_stoken (const char *);
 %token NEW DELETE
 %type <sval> operator
 %token REINTERPRET_CAST DYNAMIC_CAST STATIC_CAST CONST_CAST
+%token ENTRY
 
 /* Special type cases, put in to allow the parser to distinguish different
    legal basetypes.  */
@@ -756,6 +763,21 @@ block      :       block COLONCOLON name
                          $$ = SYMBOL_BLOCK_VALUE (tem); }
        ;
 
+variable:      name_not_typename ENTRY
+                       { struct symbol *sym = $1.sym;
+
+                         if (sym == NULL || !SYMBOL_IS_ARGUMENT (sym)
+                             || !symbol_read_needs_frame (sym))
+                           error (_("@entry can be used only for function "
+                                    "parameters, not for \"%s\""),
+                                  copy_name ($1.stoken));
+
+                         write_exp_elt_opcode (OP_VAR_ENTRY_VALUE);
+                         write_exp_elt_sym (sym);
+                         write_exp_elt_opcode (OP_VAR_ENTRY_VALUE);
+                       }
+       ;
+
 variable:      block COLONCOLON name
                        { struct symbol *sym;
                          sym = lookup_symbol (copy_name ($3), $1,
@@ -763,6 +785,13 @@ variable:  block COLONCOLON name
                          if (sym == 0)
                            error (_("No symbol \"%s\" in specified context."),
                                   copy_name ($3));
+                         if (symbol_read_needs_frame (sym))
+                           {
+                             if (innermost_block == 0
+                                 || contained_in (block_found,
+                                                  innermost_block))
+                               innermost_block = block_found;
+                           }
 
                          write_exp_elt_opcode (OP_VAR_VALUE);
                          /* block_found is set by lookup_symbol.  */
@@ -903,9 +932,7 @@ variable:   name_not_typename
        ;
 
 space_identifier : '@' NAME
-               { push_type_address_space (copy_name ($2.stoken));
-                 push_type (tp_space_identifier);
-               }
+               { insert_type_address_space (copy_name ($2.stoken)); }
        ;
 
 const_or_volatile: const_or_volatile_noopt
@@ -924,14 +951,23 @@ const_or_volatile_or_space_identifier:
        |
        ;
 
-abs_decl:      '*'
-                       { push_type (tp_pointer); $$ = 0; }
-       |       '*' abs_decl
-                       { push_type (tp_pointer); $$ = $2; }
+ptr_operator:
+               ptr_operator '*'
+                       { insert_type (tp_pointer); }
+               const_or_volatile_or_space_identifier
+                       { $$ = 0; }
+       |       '*' 
+                       { insert_type (tp_pointer); }
+               const_or_volatile_or_space_identifier
+                       { $$ = 0; }
        |       '&'
-                       { push_type (tp_reference); $$ = 0; }
-       |       '&' abs_decl
-                       { push_type (tp_reference); $$ = $2; }
+                       { insert_type (tp_reference); $$ = 0; }
+       |       '&' ptr_operator
+                       { insert_type (tp_reference); $$ = 0; }
+       ;
+
+abs_decl:      ptr_operator direct_abs_decl
+       |       ptr_operator
        |       direct_abs_decl
        ;
 
@@ -1175,22 +1211,30 @@ nonempty_typelist
        ;
 
 ptype  :       typebase
-       |       ptype const_or_volatile_or_space_identifier abs_decl const_or_volatile_or_space_identifier
+       |       ptype abs_decl
                { $$ = follow_types ($1); }
        ;
 
+conversion_type_id: typebase conversion_declarator
+               { $$ = follow_types ($1); }
+       ;
+
+conversion_declarator:  /* Nothing.  */
+       | ptr_operator conversion_declarator
+       ;
+
 const_and_volatile:    CONST_KEYWORD VOLATILE_KEYWORD
        |               VOLATILE_KEYWORD CONST_KEYWORD
        ;
 
 const_or_volatile_noopt:       const_and_volatile 
-                       { push_type (tp_const);
-                         push_type (tp_volatile); 
+                       { insert_type (tp_const);
+                         insert_type (tp_volatile); 
                        }
        |               CONST_KEYWORD
-                       { push_type (tp_const); }
+                       { insert_type (tp_const); }
        |               VOLATILE_KEYWORD
-                       { push_type (tp_volatile); }
+                       { insert_type (tp_volatile); }
        ;
 
 operator:      OPERATOR NEW
@@ -1297,7 +1341,7 @@ operator: OPERATOR NEW
                        { $$ = operator_stoken ("()"); }
        |       OPERATOR '[' ']'
                        { $$ = operator_stoken ("[]"); }
-       |       OPERATOR ptype
+       |       OPERATOR conversion_type_id
                        { char *name;
                          long length;
                          struct ui_file *buf = mem_fileopen ();
@@ -1391,9 +1435,6 @@ parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere)
 
   if (parsed_float)
     {
-      const char *suffix;
-      int suffix_len;
-
       /* If it ends at "df", "dd" or "dl", take it as type of decimal floating
          point.  Return DECFLOAT.  */
 
@@ -2224,6 +2265,21 @@ lex_one_token (void)
        return toktype;
       }
 
+    case '@':
+      {
+       char *p = &tokstart[1];
+       size_t len = strlen ("entry");
+
+       while (isspace (*p))
+         p++;
+       if (strncmp (p, "entry", len) == 0 && !isalnum (p[len])
+           && p[len] != '_')
+         {
+           lexptr = &p[len];
+           return ENTRY;
+         }
+      }
+      /* FALLTHRU */
     case '+':
     case '-':
     case '*':
@@ -2234,7 +2290,6 @@ lex_one_token (void)
     case '^':
     case '~':
     case '!':
-    case '@':
     case '<':
     case '>':
     case '?':
@@ -2466,9 +2521,8 @@ classify_name (struct block *block)
 
 /* Like classify_name, but used by the inner loop of the lexer, when a
    name might have already been seen.  FIRST_NAME is true if the token
-   in `yylval' is the first component of a name, false otherwise.  If
-   this function returns NAME, it might not have updated `yylval'.
-   This is ok because the caller only cares about TYPENAME.  */
+   in `yylval' is the first component of a name, false otherwise.  */
+
 static int
 classify_inner_name (struct block *block, int first_name)
 {
@@ -2482,18 +2536,28 @@ classify_inner_name (struct block *block, int first_name)
   if (TYPE_CODE (type) != TYPE_CODE_STRUCT
       && TYPE_CODE (type) != TYPE_CODE_UNION
       && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
-    /* We know the caller won't expect us to update yylval.  */
-    return NAME;
+    return ERROR;
 
   copy = copy_name (yylval.tsym.stoken);
-  new_type = cp_lookup_nested_type (yylval.tsym.type, copy, block);
+  yylval.ssym.sym = cp_lookup_nested_symbol (yylval.tsym.type, copy, block);
+  if (yylval.ssym.sym == NULL)
+    return ERROR;
 
-  if (new_type == NULL)
-    /* We know the caller won't expect us to update yylval.  */
-    return NAME;
+  switch (SYMBOL_CLASS (yylval.ssym.sym))
+    {
+    case LOC_BLOCK:
+    case LOC_LABEL:
+      return ERROR;
 
-  yylval.tsym.type = new_type;
-  return TYPENAME;
+    case LOC_TYPEDEF:
+      yylval.tsym.type = SYMBOL_TYPE (yylval.ssym.sym);;
+      return TYPENAME;
+
+    default:
+      yylval.ssym.is_a_field_of_this = 0;
+      return NAME;
+    }
+  internal_error (__FILE__, __LINE__, _("not reached"));
 }
 
 /* The outer level of a two-level lexer.  This calls the inner lexer
@@ -2553,7 +2617,7 @@ yylex (void)
                                                first_iter);
          /* We keep going until we either run out of names, or until
             we have a qualified name which is not a type.  */
-         if (classification != TYPENAME)
+         if (classification != TYPENAME && classification != NAME)
            {
              /* Push the final component and leave the loop.  */
              VEC_safe_push (token_and_value, token_fifo, &next);
This page took 0.026969 seconds and 4 git commands to generate.