2012-06-04 Pedro Alves <palves@redhat.com>
[deliverable/binutils-gdb.git] / gdb / ada-exp.y
index 4b8bb93a0635cee75aedd6fb89d1e926337bd5ca..1a80b0b1fe49d6934c60d4b0ded832e3427cfabb 100644 (file)
@@ -1,23 +1,21 @@
 /* YACC parser for Ada expressions, for GDB.
-   Copyright (C) 1986, 1989, 1990, 1991, 1993, 1994, 1997, 2000, 2003, 2004,
-   2007, 2008 Free Software Foundation, Inc.
+   Copyright (C) 1986, 1989-1991, 1993-1994, 1997, 2000, 2003-2004,
+   2007-2012 Free Software Foundation, Inc.
 
-This file is part of GDB.
+   This file is part of GDB.
 
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
 
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
 
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 51 Franklin Street, Fifth Floor,
-Boston, MA 02110-1301, USA.  */
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 /* Parse an Ada expression from text in a string,
    and return the result as a  struct expression  pointer.
@@ -96,6 +94,12 @@ Boston, MA 02110-1301, USA.  */
 #define yytoks ada_toks                /* With YYDEBUG defined */
 #define yyname ada_name                /* With YYDEBUG defined */
 #define yyrule ada_rule                /* With YYDEBUG defined */
+#define yyss   ada_yyss
+#define yysslim        ada_yysslim
+#define yyssp  ada_yyssp
+#define yystacksize ada_yystacksize
+#define yyvs   ada_yyvs
+#define yyvsp  ada_yyvsp
 
 #ifndef YYDEBUG
 #define        YYDEBUG 1               /* Default to yydebug support */
@@ -869,8 +873,7 @@ write_object_renaming (struct block *orig_left_context,
 {
   char *name;
   enum { SIMPLE_INDEX, LOWER_BOUND, UPPER_BOUND } slice_state;
-  struct symbol *sym;
-  struct block *block;
+  struct ada_symbol_info sym_info;
 
   if (max_depth <= 0)
     error (_("Could not find renamed symbol"));
@@ -879,29 +882,28 @@ write_object_renaming (struct block *orig_left_context,
     orig_left_context = get_selected_block (NULL);
 
   name = obsavestring (renamed_entity, renamed_entity_len, &temp_parse_space);
-  sym = ada_lookup_encoded_symbol (name, orig_left_context, VAR_DOMAIN, 
-                                  &block);
-  if (sym == NULL)
+  ada_lookup_encoded_symbol (name, orig_left_context, VAR_DOMAIN, &sym_info);
+  if (sym_info.sym == NULL)
     error (_("Could not find renamed variable: %s"), ada_decode (name));
-  else if (SYMBOL_CLASS (sym) == LOC_TYPEDEF)
+  else if (SYMBOL_CLASS (sym_info.sym) == LOC_TYPEDEF)
     /* We have a renaming of an old-style renaming symbol.  Don't
        trust the block information.  */
-    block = orig_left_context;
+    sym_info.block = orig_left_context;
 
   {
     const char *inner_renamed_entity;
     int inner_renamed_entity_len;
     const char *inner_renaming_expr;
 
-    switch (ada_parse_renaming (sym, &inner_renamed_entity, 
+    switch (ada_parse_renaming (sym_info.sym, &inner_renamed_entity,
                                &inner_renamed_entity_len,
                                &inner_renaming_expr))
       {
       case ADA_NOT_RENAMING:
-       write_var_from_sym (orig_left_context, block, sym);
+       write_var_from_sym (orig_left_context, sym_info.block, sym_info.sym);
        break;
       case ADA_OBJECT_RENAMING:
-       write_object_renaming (block,
+       write_object_renaming (sym_info.block,
                               inner_renamed_entity, inner_renamed_entity_len,
                               inner_renaming_expr, max_depth - 1);
        break;
@@ -922,6 +924,7 @@ write_object_renaming (struct block *orig_left_context,
         break;
       case 'L':
        slice_state = LOWER_BOUND;
+       /* FALLTHROUGH */
       case 'S':
        renaming_expr += 1;
        if (isdigit (*renaming_expr))
@@ -940,7 +943,7 @@ write_object_renaming (struct block *orig_left_context,
          {
            const char *end;
            char *index_name;
-           struct symbol *index_sym;
+           struct ada_symbol_info index_sym_info;
 
            end = strchr (renaming_expr, 'X');
            if (end == NULL)
@@ -951,14 +954,15 @@ write_object_renaming (struct block *orig_left_context,
                            &temp_parse_space);
            renaming_expr = end;
 
-           index_sym = ada_lookup_encoded_symbol (index_name, NULL,
-                                                  VAR_DOMAIN, &block);
-           if (index_sym == NULL)
+           ada_lookup_encoded_symbol (index_name, NULL, VAR_DOMAIN,
+                                      &index_sym_info);
+           if (index_sym_info.sym == NULL)
              error (_("Could not find %s"), index_name);
-           else if (SYMBOL_CLASS (index_sym) == LOC_TYPEDEF)
+           else if (SYMBOL_CLASS (index_sym_info.sym) == LOC_TYPEDEF)
              /* Index is an old-style renaming symbol.  */
-             block = orig_left_context;
-           write_var_from_sym (NULL, block, index_sym);
+             index_sym_info.block = orig_left_context;
+           write_var_from_sym (NULL, index_sym_info.block,
+                               index_sym_info.sym);
          }
        if (slice_state == SIMPLE_INDEX)
          {
@@ -1022,9 +1026,9 @@ block_lookup (struct block *context, char *raw_name)
   else
     name = ada_encode (raw_name);
 
-  nsyms = ada_lookup_symbol_list (name, context, VAR_DOMAIN, &syms);
-  if (context == NULL &&
-      (nsyms == 0 || SYMBOL_CLASS (syms[0].sym) != LOC_BLOCK))
+  nsyms = ada_lookup_symbol_list (name, context, VAR_DOMAIN, &syms, 1);
+  if (context == NULL
+      && (nsyms == 0 || SYMBOL_CLASS (syms[0].sym) != LOC_BLOCK))
     symtab = lookup_symtab (name);
   else
     symtab = NULL;
@@ -1093,7 +1097,6 @@ find_primitive_type (char *name)
     {
       /* Check to see if we have a regular definition of this
         type that just didn't happen to have been read yet.  */
-      int ntypes;
       struct symbol *sym;
       char *expanded_name = 
        (char *) alloca (strlen (name) + sizeof ("standard__"));
@@ -1209,6 +1212,7 @@ get_symbol_field_type (struct symbol *sym, char *encoded_field_name)
 
   if (type == NULL || field_name == NULL)
     return NULL;
+  type = check_typedef (type);
 
   while (field_name[0] != '\0')
     {
@@ -1279,7 +1283,7 @@ write_var_or_type (struct block *block, struct stoken name0)
 
          encoded_name[tail_index] = '\0';
          nsyms = ada_lookup_symbol_list (encoded_name, block,
-                                         VAR_DOMAIN, &syms);
+                                         VAR_DOMAIN, &syms, 1);
          encoded_name[tail_index] = terminator;
 
          /* A single symbol may rename a package or object. */
@@ -1288,12 +1292,11 @@ write_var_or_type (struct block *block, struct stoken name0)
             FIXME pnh 7/20/2007. */
          if (nsyms == 1)
            {
-             struct symbol *renaming =
-               ada_find_renaming_symbol (SYMBOL_LINKAGE_NAME (syms[0].sym), 
-                                         syms[0].block);
+             struct symbol *ren_sym =
+               ada_find_renaming_symbol (syms[0].sym, syms[0].block);
 
-             if (renaming != NULL)
-               syms[0].sym = renaming;
+             if (ren_sym != NULL)
+               syms[0].sym = ren_sym;
            }
 
          type_sym = select_possible_type_sym (syms, nsyms);
@@ -1367,7 +1370,6 @@ write_var_or_type (struct block *block, struct stoken name0)
            }
          else if (nsyms == 0) 
            {
-             int i;
              struct minimal_symbol *msym 
                = ada_lookup_simple_minsym (encoded_name);
              if (msym != NULL)
@@ -1429,7 +1431,7 @@ write_name_assoc (struct stoken name)
     {
       struct ada_symbol_info *syms;
       int nsyms = ada_lookup_symbol_list (name.ptr, expression_context_block,
-                                         VAR_DOMAIN, &syms);
+                                         VAR_DOMAIN, &syms, 1);
       if (nsyms != 1 || SYMBOL_CLASS (syms[0].sym) == LOC_TYPEDEF)
        write_exp_op_with_string (OP_NAME, name);
       else
@@ -1451,13 +1453,17 @@ convert_char_literal (struct type *type, LONGEST val)
   char name[7];
   int f;
 
-  if (type == NULL || TYPE_CODE (type) != TYPE_CODE_ENUM)
+  if (type == NULL)
+    return val;
+  type = check_typedef (type);
+  if (TYPE_CODE (type) != TYPE_CODE_ENUM)
     return val;
-  sprintf (name, "QU%02x", (int) val);
+
+  xsnprintf (name, sizeof (name), "QU%02x", (int) val);
   for (f = 0; f < TYPE_NFIELDS (type); f += 1)
     {
       if (strcmp (name, TYPE_FIELD_NAME (type, f)) == 0)
-       return TYPE_FIELD_BITPOS (type, f);
+       return TYPE_FIELD_ENUMVAL (type, f);
     }
   return val;
 }
@@ -1520,6 +1526,9 @@ type_system_address (void)
   return  type != NULL ? type : parse_type->builtin_data_ptr;
 }
 
+/* Provide a prototype to silence -Wmissing-prototypes.  */
+extern initialize_file_ftype _initialize_ada_exp;
+
 void
 _initialize_ada_exp (void)
 {
This page took 0.03133 seconds and 4 git commands to generate.