Fix latent bug in target_pass_ctrlc
[deliverable/binutils-gdb.git] / gdb / ada-lang.c
index 332363b1ecc9a827a9496b99b8ba96cbe553708a..cbcceba838de6b4d07f9343179c187be0a126158 100644 (file)
@@ -1,6 +1,6 @@
 /* Ada language support routines for GDB, the GNU debugger.
 
-   Copyright (C) 1992-2019 Free Software Foundation, Inc.
+   Copyright (C) 1992-2020 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -20,7 +20,6 @@
 
 #include "defs.h"
 #include <ctype.h>
-#include "demangle.h"
 #include "gdb_regex.h"
 #include "frame.h"
 #include "symtab.h"
@@ -30,7 +29,6 @@
 #include "parser-defs.h"
 #include "language.h"
 #include "varobj.h"
-#include "c-lang.h"
 #include "inferior.h"
 #include "symfile.h"
 #include "objfiles.h"
 #include "gdb_obstack.h"
 #include "ada-lang.h"
 #include "completer.h"
-#include <sys/stat.h>
 #include "ui-out.h"
 #include "block.h"
 #include "infcall.h"
-#include "dictionary.h"
 #include "annotate.h"
 #include "valprint.h"
 #include "source.h"
 #include "observable.h"
-#include "common/vec.h"
 #include "stack.h"
-#include "common/gdb_vecs.h"
 #include "typeprint.h"
 #include "namespace.h"
+#include "cli/cli-style.h"
 
-#include "psymtab.h"
 #include "value.h"
 #include "mi/mi-common.h"
 #include "arch-utils.h"
 #include "cli/cli-utils.h"
-#include "common/function-view.h"
-#include "common/byte-vector.h"
+#include "gdbsupport/function-view.h"
+#include "gdbsupport/byte-vector.h"
 #include <algorithm>
-#include <map>
 
 /* Define whether or not the C operator '/' truncates towards zero for
    differently signed operands (truncation direction is undefined in C).
@@ -203,6 +196,8 @@ static LONGEST pos_atr (struct value *);
 
 static struct value *value_pos_atr (struct type *, struct value *);
 
+static struct value *val_atr (struct type *, LONGEST);
+
 static struct value *value_val_atr (struct type *, struct value *);
 
 static struct symbol *standard_lookup (const char *, const struct block *,
@@ -211,9 +206,6 @@ static struct symbol *standard_lookup (const char *, const struct block *,
 static struct value *ada_search_struct_field (const char *, struct value *, int,
                                               struct type *);
 
-static struct value *ada_value_primitive_field (struct value *, int, int,
-                                                struct type *);
-
 static int find_struct_field (const char *, struct type *, int,
                               struct type **, int *, int *, int *, int *);
 
@@ -223,9 +215,6 @@ static int ada_resolve_function (struct block_symbol *, int,
 
 static int ada_is_direct_array_type (struct type *);
 
-static void ada_language_arch_info (struct gdbarch *,
-                                   struct language_arch_info *);
-
 static struct value *ada_index_struct_field (int, struct value *, int,
                                             struct type *);
 
@@ -339,26 +328,9 @@ static const char *known_auxiliary_function_name_patterns[] = {
 static struct cmd_list_element *maint_set_ada_cmdlist;
 static struct cmd_list_element *maint_show_ada_cmdlist;
 
-/* Implement the "maintenance set ada" (prefix) command.  */
-
-static void
-maint_set_ada_cmd (const char *args, int from_tty)
-{
-  help_list (maint_set_ada_cmdlist, "maintenance set ada ", all_commands,
-            gdb_stdout);
-}
-
-/* Implement the "maintenance show ada" (prefix) command.  */
-
-static void
-maint_show_ada_cmd (const char *args, int from_tty)
-{
-  cmd_show_list (maint_show_ada_cmdlist, from_tty, "");
-}
-
 /* The "maintenance ada set/show ignore-descriptive-type" value.  */
 
-static int ada_ignore_descriptive_types_p = 0;
+static bool ada_ignore_descriptive_types_p = false;
 
                        /* Inferior-specific data.  */
 
@@ -478,7 +450,7 @@ get_ada_pspace_data (struct program_space *pspace)
 static struct type *
 ada_typedef_target_type (struct type *type)
 {
-  while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
+  while (type->code () == TYPE_CODE_TYPEDEF)
     type = TYPE_TARGET_TYPE (type);
   return type;
 }
@@ -516,38 +488,17 @@ add_angle_brackets (const char *str)
   return string_printf ("<%s>", str);
 }
 
-static const char *
-ada_get_gdb_completer_word_break_characters (void)
-{
-  return ada_completer_word_break_characters;
-}
-
-/* Print an array element index using the Ada syntax.  */
-
-static void
-ada_print_array_index (struct value *index_value, struct ui_file *stream,
-                       const struct value_print_options *options)
-{
-  LA_VALUE_PRINT (index_value, stream, options);
-  fprintf_filtered (stream, " => ");
-}
-
-/* la_watch_location_expression for Ada.  */
+/* Assuming V points to an array of S objects,  make sure that it contains at
+   least M objects, updating V and S as necessary.  */
 
-gdb::unique_xmalloc_ptr<char>
-ada_watch_location_expression (struct type *type, CORE_ADDR addr)
-{
-  type = check_typedef (TYPE_TARGET_TYPE (check_typedef (type)));
-  std::string name = type_to_string (type);
-  return gdb::unique_xmalloc_ptr<char>
-    (xstrprintf ("{%s} %s", name.c_str (), core_addr_to_string (addr)));
-}
+#define GROW_VECT(v, s, m)                                    \
+   if ((s) < (m)) (v) = (char *) grow_vect (v, &(s), m, sizeof *(v));
 
 /* Assuming VECT points to an array of *SIZE objects of size
    ELEMENT_SIZE, grow it to contain at least MIN_SIZE objects,
    updating *SIZE as necessary and returning the (new) array.  */
 
-void *
+static void *
 grow_vect (void *vect, size_t *size, size_t min_size, int element_size)
 {
   if (*size < min_size)
@@ -592,13 +543,13 @@ ada_get_field_index (const struct type *type, const char *field_name,
   int fieldno;
   struct type *struct_type = check_typedef ((struct type *) type);
 
-  for (fieldno = 0; fieldno < TYPE_NFIELDS (struct_type); fieldno++)
+  for (fieldno = 0; fieldno < struct_type->num_fields (); fieldno++)
     if (field_name_match (TYPE_FIELD_NAME (struct_type, fieldno), field_name))
       return fieldno;
 
   if (!maybe_missing)
     error (_("Unable to find field %s in struct %s.  Aborting"),
-           field_name, TYPE_NAME (struct_type));
+           field_name, struct_type->name ());
 
   return -1;
 }
@@ -770,13 +721,13 @@ min_of_type (struct type *t)
 LONGEST
 ada_discrete_type_high_bound (struct type *type)
 {
-  type = resolve_dynamic_type (type, NULL, 0);
-  switch (TYPE_CODE (type))
+  type = resolve_dynamic_type (type, {}, 0);
+  switch (type->code ())
     {
     case TYPE_CODE_RANGE:
       return TYPE_HIGH_BOUND (type);
     case TYPE_CODE_ENUM:
-      return TYPE_FIELD_ENUMVAL (type, TYPE_NFIELDS (type) - 1);
+      return TYPE_FIELD_ENUMVAL (type, type->num_fields () - 1);
     case TYPE_CODE_BOOL:
       return 1;
     case TYPE_CODE_CHAR:
@@ -791,8 +742,8 @@ ada_discrete_type_high_bound (struct type *type)
 LONGEST
 ada_discrete_type_low_bound (struct type *type)
 {
-  type = resolve_dynamic_type (type, NULL, 0);
-  switch (TYPE_CODE (type))
+  type = resolve_dynamic_type (type, {}, 0);
+  switch (type->code ())
     {
     case TYPE_CODE_RANGE:
       return TYPE_LOW_BOUND (type);
@@ -814,7 +765,7 @@ ada_discrete_type_low_bound (struct type *type)
 static struct type *
 get_base_type (struct type *type)
 {
-  while (type != NULL && TYPE_CODE (type) == TYPE_CODE_RANGE)
+  while (type != NULL && type->code () == TYPE_CODE_RANGE)
     {
       if (type == TYPE_TARGET_TYPE (type) || TYPE_TARGET_TYPE (type) == NULL)
         return type;
@@ -825,7 +776,7 @@ get_base_type (struct type *type)
 
 /* Return a decoded version of the given VALUE.  This means returning
    a value whose type is obtained by applying all the GNAT-specific
-   encondings, making the resulting type a static but standard description
+   encodings, making the resulting type a static but standard description
    of the initial type.  */
 
 struct value *
@@ -835,9 +786,9 @@ ada_get_decoded_value (struct value *value)
 
   if (ada_is_array_descriptor_type (type)
       || (ada_is_constrained_packed_array_type (type)
-          && TYPE_CODE (type) != TYPE_CODE_PTR))
+          && type->code () != TYPE_CODE_PTR))
     {
-      if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)  /* array access type.  */
+      if (type->code () == TYPE_CODE_TYPEDEF)  /* array access type.  */
         value = ada_coerce_to_simple_array_ptr (value);
       else
         value = ada_coerce_to_simple_array (value);
@@ -869,7 +820,7 @@ ada_get_decoded_type (struct type *type)
 /* If the main program is in Ada, return language_ada, otherwise return LANG
    (the main program is in Ada iif the adainit symbol is found).  */
 
-enum language
+static enum language
 ada_update_initial_language (enum language lang)
 {
   if (lookup_minimal_symbol ("adainit", NULL, NULL).minsym != NULL)
@@ -897,18 +848,11 @@ ada_main_name (void)
 
   if (msym.minsym != NULL)
     {
-      CORE_ADDR main_program_name_addr;
-      int err_code;
-
-      main_program_name_addr = BMSYMBOL_VALUE_ADDRESS (msym);
+      CORE_ADDR main_program_name_addr = BMSYMBOL_VALUE_ADDRESS (msym);
       if (main_program_name_addr == 0)
         error (_("Invalid address for Ada main program name."));
 
-      target_read_string (main_program_name_addr, &main_program_name,
-                          1024, &err_code);
-
-      if (err_code != 0)
-        return NULL;
+      main_program_name = target_read_string (main_program_name_addr, 1024);
       return main_program_name.get ();
     }
 
@@ -1016,18 +960,18 @@ ada_encode (const char *decoded)
    quotes, unfolded, but with the quotes stripped away.  Result good
    to next call.  */
 
-char *
-ada_fold_name (const char *name)
+static char *
+ada_fold_name (gdb::string_view name)
 {
   static char *fold_buffer = NULL;
   static size_t fold_buffer_size = 0;
 
-  int len = strlen (name);
+  int len = name.size ();
   GROW_VECT (fold_buffer, fold_buffer_size, len + 1);
 
   if (name[0] == '\'')
     {
-      strncpy (fold_buffer, name + 1, len - 2);
+      strncpy (fold_buffer, name.data () + 1, len - 2);
       fold_buffer[len - 2] = '\000';
     }
   else
@@ -1105,22 +1049,16 @@ ada_remove_po_subprogram_suffix (const char *encoded, int *len)
 
 /* If ENCODED follows the GNAT entity encoding conventions, then return
    the decoded form of ENCODED.  Otherwise, return "<%s>" where "%s" is
-   replaced by ENCODED.
-
-   The resulting string is valid until the next call of ada_decode.
-   If the string is unchanged by decoding, the original string pointer
-   is returned.  */
+   replaced by ENCODED.  */
 
-const char *
+std::string
 ada_decode (const char *encoded)
 {
   int i, j;
   int len0;
   const char *p;
-  char *decoded;
   int at_start_name;
-  static char *decoding_buffer = NULL;
-  static size_t decoding_buffer_size = 0;
+  std::string decoded;
 
   /* With function descriptors on PPC64, the value of a symbol named
      ".FN", if it exists, is the entry point of the function "FN".  */
@@ -1179,8 +1117,7 @@ ada_decode (const char *encoded)
 
   /* Make decoded big enough for possible expansion by operator name.  */
 
-  GROW_VECT (decoding_buffer, decoding_buffer_size, 2 * len0 + 1);
-  decoded = decoding_buffer;
+  decoded.resize (2 * len0 + 1, 'X');
 
   /* Remove trailing __{digit}+ or trailing ${digit}+.  */
 
@@ -1217,7 +1154,7 @@ ada_decode (const char *encoded)
                             op_len - 1) == 0)
                   && !isalnum (encoded[i + op_len]))
                 {
-                  strcpy (decoded + j, ada_opname_table[k].decoded);
+                  strcpy (&decoded.front() + j, ada_opname_table[k].decoded);
                   at_start_name = 0;
                   i += op_len;
                   j += strlen (ada_opname_table[k].decoded);
@@ -1338,27 +1275,22 @@ ada_decode (const char *encoded)
           j += 1;
         }
     }
-  decoded[j] = '\000';
+  decoded.resize (j);
 
   /* Decoded names should never contain any uppercase character.
      Double-check this, and abort the decoding if we find one.  */
 
-  for (i = 0; decoded[i] != '\0'; i += 1)
+  for (i = 0; i < decoded.length(); ++i)
     if (isupper (decoded[i]) || decoded[i] == ' ')
       goto Suppress;
 
-  if (strcmp (decoded, encoded) == 0)
-    return encoded;
-  else
-    return decoded;
+  return decoded;
 
 Suppress:
-  GROW_VECT (decoding_buffer, decoding_buffer_size, strlen (encoded) + 3);
-  decoded = decoding_buffer;
   if (encoded[0] == '<')
-    strcpy (decoded, encoded);
+    decoded = encoded;
   else
-    xsnprintf (decoded, decoding_buffer_size, "<%s>", encoded);
+    decoded = '<' + std::string(encoded) + '>';
   return decoded;
 
 }
@@ -1389,14 +1321,13 @@ ada_decode_symbol (const struct general_symbol_info *arg)
 
   if (!gsymbol->ada_mangled)
     {
-      const char *decoded = ada_decode (gsymbol->name);
+      std::string decoded = ada_decode (gsymbol->linkage_name ());
       struct obstack *obstack = gsymbol->language_specific.obstack;
 
       gsymbol->ada_mangled = 1;
 
       if (obstack != NULL)
-       *resultp
-         = (const char *) obstack_copy0 (obstack, decoded, strlen (decoded));
+       *resultp = obstack_strdup (obstack, decoded.c_str ());
       else
         {
          /* Sometimes, we can't find a corresponding objfile, in
@@ -1405,10 +1336,10 @@ ada_decode_symbol (const struct general_symbol_info *arg)
             significant memory leak (FIXME).  */
 
           char **slot = (char **) htab_find_slot (decoded_names_store,
-                                                  decoded, INSERT);
+                                                  decoded.c_str (), INSERT);
 
           if (*slot == NULL)
-            *slot = xstrdup (decoded);
+            *slot = xstrdup (decoded.c_str ());
           *resultp = *slot;
         }
     }
@@ -1419,46 +1350,7 @@ ada_decode_symbol (const struct general_symbol_info *arg)
 static char *
 ada_la_decode (const char *encoded, int options)
 {
-  return xstrdup (ada_decode (encoded));
-}
-
-/* Implement la_sniff_from_mangled_name for Ada.  */
-
-static int
-ada_sniff_from_mangled_name (const char *mangled, char **out)
-{
-  const char *demangled = ada_decode (mangled);
-
-  *out = NULL;
-
-  if (demangled != mangled && demangled != NULL && demangled[0] != '<')
-    {
-      /* Set the gsymbol language to Ada, but still return 0.
-        Two reasons for that:
-
-        1. For Ada, we prefer computing the symbol's decoded name
-        on the fly rather than pre-compute it, in order to save
-        memory (Ada projects are typically very large).
-
-        2. There are some areas in the definition of the GNAT
-        encoding where, with a bit of bad luck, we might be able
-        to decode a non-Ada symbol, generating an incorrect
-        demangled name (Eg: names ending with "TB" for instance
-        are identified as task bodies and so stripped from
-        the decoded name returned).
-
-        Returning 1, here, but not setting *DEMANGLED, helps us get a
-        little bit of the best of both worlds.  Because we're last,
-        we should not affect any of the other languages that were
-        able to demangle the symbol before us; we get to correctly
-        tag Ada symbols as such; and even if we incorrectly tagged a
-        non-Ada symbol, which should be rare, any routing through the
-        Ada language should be transparent (Ada tries to behave much
-        like C/C++ with non-Ada symbols).  */
-      return 1;
-    }
-
-  return 0;
+  return xstrdup (ada_decode (encoded).c_str ());
 }
 
 \f
@@ -1472,7 +1364,7 @@ ada_sniff_from_mangled_name (const char *mangled, char **out)
    Otherwise, do nothing.  This function also does nothing if
    INDEX_DESC_TYPE is NULL.
 
-   The GNAT encoding used to describle the array index type evolved a bit.
+   The GNAT encoding used to describe the array index type evolved a bit.
    Initially, the information would be provided through the name of each
    field of the structure type only, while the type of these fields was
    described as unspecified and irrelevant.  The debugger was then expected
@@ -1495,7 +1387,7 @@ ada_fixup_array_indexes_type (struct type *index_desc_type)
 
   if (index_desc_type == NULL)
     return;
-  gdb_assert (TYPE_NFIELDS (index_desc_type) > 0);
+  gdb_assert (index_desc_type->num_fields () > 0);
 
   /* Check if INDEX_DESC_TYPE follows the older encoding (it is sufficient
      to check one field only, no need to check them all).  If not, return
@@ -1504,34 +1396,22 @@ ada_fixup_array_indexes_type (struct type *index_desc_type)
      If our INDEX_DESC_TYPE was generated using the older encoding,
      the field type should be a meaningless integer type whose name
      is not equal to the field name.  */
-  if (TYPE_NAME (TYPE_FIELD_TYPE (index_desc_type, 0)) != NULL
-      && strcmp (TYPE_NAME (TYPE_FIELD_TYPE (index_desc_type, 0)),
+  if (index_desc_type->field (0).type ()->name () != NULL
+      && strcmp (index_desc_type->field (0).type ()->name (),
                  TYPE_FIELD_NAME (index_desc_type, 0)) == 0)
     return;
 
   /* Fixup each field of INDEX_DESC_TYPE.  */
-  for (i = 0; i < TYPE_NFIELDS (index_desc_type); i++)
+  for (i = 0; i < index_desc_type->num_fields (); i++)
    {
      const char *name = TYPE_FIELD_NAME (index_desc_type, i);
      struct type *raw_type = ada_check_typedef (ada_find_any_type (name));
 
      if (raw_type)
-       TYPE_FIELD_TYPE (index_desc_type, i) = raw_type;
+       index_desc_type->field (i).set_type (raw_type);
    }
 }
 
-/* Names of MAX_ADA_DIMENS bounds in P_BOUNDS fields of array descriptors.  */
-
-static const char *bound_name[] = {
-  "LB0", "UB0", "LB1", "UB1", "LB2", "UB2", "LB3", "UB3",
-  "LB4", "UB4", "LB5", "UB5", "LB6", "UB6", "LB7", "UB7"
-};
-
-/* Maximum number of array dimensions we are prepared to handle.  */
-
-#define MAX_ADA_DIMENS (sizeof(bound_name) / (2*sizeof(char *)))
-
-
 /* The desc_* routines return primitive portions of array descriptors
    (fat pointers).  */
 
@@ -1544,12 +1424,12 @@ desc_base_type (struct type *type)
   if (type == NULL)
     return NULL;
   type = ada_check_typedef (type);
-  if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
+  if (type->code () == TYPE_CODE_TYPEDEF)
     type = ada_typedef_target_type (type);
 
   if (type != NULL
-      && (TYPE_CODE (type) == TYPE_CODE_PTR
-          || TYPE_CODE (type) == TYPE_CODE_REF))
+      && (type->code () == TYPE_CODE_PTR
+          || type->code () == TYPE_CODE_REF))
     return ada_check_typedef (TYPE_TARGET_TYPE (type));
   else
     return type;
@@ -1597,7 +1477,7 @@ thin_data_pntr (struct value *val)
 
   data_type = lookup_pointer_type (data_type);
 
-  if (TYPE_CODE (type) == TYPE_CODE_PTR)
+  if (type->code () == TYPE_CODE_PTR)
     return value_cast (data_type, value_copy (val));
   else
     return value_from_longest (data_type, value_address (val));
@@ -1609,7 +1489,7 @@ static int
 is_thick_pntr (struct type *type)
 {
   type = desc_base_type (type);
-  return (type != NULL && TYPE_CODE (type) == TYPE_CODE_STRUCT
+  return (type != NULL && type->code () == TYPE_CODE_STRUCT
           && lookup_struct_elt_type (type, "P_BOUNDS", 1) != NULL);
 }
 
@@ -1634,7 +1514,7 @@ desc_bounds_type (struct type *type)
       if (r != NULL)
         return ada_check_typedef (r);
     }
-  else if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
+  else if (type->code () == TYPE_CODE_STRUCT)
     {
       r = lookup_struct_elt_type (type, "P_BOUNDS", 1);
       if (r != NULL)
@@ -1663,7 +1543,7 @@ desc_bounds (struct value *arr)
       /* NOTE: The following calculation is not really kosher, but
          since desc_type is an XVE-encoded type (and shouldn't be),
          the correct calculation is a real pain.  FIXME (and fix GCC).  */
-      if (TYPE_CODE (type) == TYPE_CODE_PTR)
+      if (type->code () == TYPE_CODE_PTR)
         addr = value_as_long (arr);
       else
         addr = value_address (arr);
@@ -1680,7 +1560,7 @@ desc_bounds (struct value *arr)
       struct type *p_bounds_type = value_type (p_bounds);
 
       if (p_bounds_type
-         && TYPE_CODE (p_bounds_type) == TYPE_CODE_PTR)
+         && p_bounds_type->code () == TYPE_CODE_PTR)
        {
          struct type *target_type = TYPE_TARGET_TYPE (p_bounds_type);
 
@@ -1718,7 +1598,7 @@ fat_pntr_bounds_bitsize (struct type *type)
   if (TYPE_FIELD_BITSIZE (type, 1) > 0)
     return TYPE_FIELD_BITSIZE (type, 1);
   else
-    return 8 * TYPE_LENGTH (ada_check_typedef (TYPE_FIELD_TYPE (type, 1)));
+    return 8 * TYPE_LENGTH (ada_check_typedef (type->field (1).type ()));
 }
 
 /* If TYPE is the type of an array descriptor (fat or thin pointer) or a
@@ -1733,13 +1613,13 @@ desc_data_target_type (struct type *type)
 
   /* NOTE: The following is bogus; see comment in desc_bounds.  */
   if (is_thin_pntr (type))
-    return desc_base_type (TYPE_FIELD_TYPE (thin_descriptor_type (type), 1));
+    return desc_base_type (thin_descriptor_type (type)->field (1).type ());
   else if (is_thick_pntr (type))
     {
       struct type *data_type = lookup_struct_elt_type (type, "P_ARRAY", 1);
 
       if (data_type
-         && TYPE_CODE (ada_check_typedef (data_type)) == TYPE_CODE_PTR)
+         && ada_check_typedef (data_type)->code () == TYPE_CODE_PTR)
        return ada_check_typedef (TYPE_TARGET_TYPE (data_type));
     }
 
@@ -1784,7 +1664,7 @@ fat_pntr_data_bitsize (struct type *type)
   if (TYPE_FIELD_BITSIZE (type, 0) > 0)
     return TYPE_FIELD_BITSIZE (type, 0);
   else
-    return TARGET_CHAR_BIT * TYPE_LENGTH (TYPE_FIELD_TYPE (type, 0));
+    return TARGET_CHAR_BIT * TYPE_LENGTH (type->field (0).type ());
 }
 
 /* If BOUNDS is an array-bounds structure (or pointer to one), return
@@ -1794,7 +1674,10 @@ fat_pntr_data_bitsize (struct type *type)
 static struct value *
 desc_one_bound (struct value *bounds, int i, int which)
 {
-  return value_struct_elt (&bounds, NULL, bound_name[2 * i + which - 2], NULL,
+  char bound_name[20];
+  xsnprintf (bound_name, sizeof (bound_name), "%cB%d",
+            which ? 'U' : 'L', i - 1);
+  return value_struct_elt (&bounds, NULL, bound_name, NULL,
                            _("Bad GNAT array descriptor bounds"));
 }
 
@@ -1820,7 +1703,7 @@ desc_bound_bitsize (struct type *type, int i, int which)
   if (TYPE_FIELD_BITSIZE (type, 2 * i + which - 2) > 0)
     return TYPE_FIELD_BITSIZE (type, 2 * i + which - 2);
   else
-    return 8 * TYPE_LENGTH (TYPE_FIELD_TYPE (type, 2 * i + which - 2));
+    return 8 * TYPE_LENGTH (type->field (2 * i + which - 2).type ());
 }
 
 /* If TYPE is the type of an array-bounds structure, the type of its
@@ -1831,8 +1714,12 @@ desc_index_type (struct type *type, int i)
 {
   type = desc_base_type (type);
 
-  if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
-    return lookup_struct_elt_type (type, bound_name[2 * i - 2], 1);
+  if (type->code () == TYPE_CODE_STRUCT)
+    {
+      char bound_name[20];
+      xsnprintf (bound_name, sizeof (bound_name), "LB%d", i - 1);
+      return lookup_struct_elt_type (type, bound_name, 1);
+    }
   else
     return NULL;
 }
@@ -1846,7 +1733,7 @@ desc_arity (struct type *type)
   type = desc_base_type (type);
 
   if (type != NULL)
-    return TYPE_NFIELDS (type) / 2;
+    return type->num_fields () / 2;
   return 0;
 }
 
@@ -1860,7 +1747,7 @@ ada_is_direct_array_type (struct type *type)
   if (type == NULL)
     return 0;
   type = ada_check_typedef (type);
-  return (TYPE_CODE (type) == TYPE_CODE_ARRAY
+  return (type->code () == TYPE_CODE_ARRAY
           || ada_is_array_descriptor_type (type));
 }
 
@@ -1870,9 +1757,9 @@ ada_is_direct_array_type (struct type *type)
 static int
 ada_is_array_type (struct type *type)
 {
-  while (type != NULL 
-        && (TYPE_CODE (type) == TYPE_CODE_PTR 
-            || TYPE_CODE (type) == TYPE_CODE_REF))
+  while (type != NULL
+        && (type->code () == TYPE_CODE_PTR
+            || type->code () == TYPE_CODE_REF))
     type = TYPE_TARGET_TYPE (type);
   return ada_is_direct_array_type (type);
 }
@@ -1885,10 +1772,10 @@ ada_is_simple_array_type (struct type *type)
   if (type == NULL)
     return 0;
   type = ada_check_typedef (type);
-  return (TYPE_CODE (type) == TYPE_CODE_ARRAY
-          || (TYPE_CODE (type) == TYPE_CODE_PTR
-              && TYPE_CODE (ada_check_typedef (TYPE_TARGET_TYPE (type)))
-                 == TYPE_CODE_ARRAY));
+  return (type->code () == TYPE_CODE_ARRAY
+         || (type->code () == TYPE_CODE_PTR
+             && (ada_check_typedef (TYPE_TARGET_TYPE (type))->code ()
+                 == TYPE_CODE_ARRAY)));
 }
 
 /* Non-zero iff TYPE belongs to a GNAT array descriptor.  */
@@ -1902,7 +1789,7 @@ ada_is_array_descriptor_type (struct type *type)
     return 0;
   type = ada_check_typedef (type);
   return (data_type != NULL
-         && TYPE_CODE (data_type) == TYPE_CODE_ARRAY
+         && data_type->code () == TYPE_CODE_ARRAY
          && desc_arity (desc_bounds_type (type)) > 0);
 }
 
@@ -1916,7 +1803,7 @@ ada_is_bogus_array_descriptor (struct type *type)
 {
   return
     type != NULL
-    && TYPE_CODE (type) == TYPE_CODE_STRUCT
+    && type->code () == TYPE_CODE_STRUCT
     && (lookup_struct_elt_type (type, "P_BOUNDS", 1) != NULL
         || lookup_struct_elt_type (type, "P_ARRAY", 1) != NULL)
     && !ada_is_array_descriptor_type (type);
@@ -1930,7 +1817,8 @@ ada_is_bogus_array_descriptor (struct type *type)
    the ARR denotes a null array descriptor and BOUNDS is non-zero,
    returns NULL.  The result is simply the type of ARR if ARR is not
    a descriptor.  */
-struct type *
+
+static struct type *
 ada_type_of_array (struct value *arr, int bounds)
 {
   if (ada_is_constrained_packed_array_type (value_type (arr)))
@@ -2111,7 +1999,7 @@ decode_packed_array_bitsize (struct type *type)
   /* Access to arrays implemented as fat pointers are encoded as a typedef
      of the fat pointer type.  We need the name of the fat pointer type
      to do the decoding, so strip the typedef layer.  */
-  if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
+  if (type->code () == TYPE_CODE_TYPEDEF)
     type = ada_typedef_target_type (type);
 
   raw_name = ada_type_name (ada_check_typedef (type));
@@ -2161,15 +2049,15 @@ constrained_packed_array_type (struct type *type, long *elt_bits)
   LONGEST low_bound, high_bound;
 
   type = ada_check_typedef (type);
-  if (TYPE_CODE (type) != TYPE_CODE_ARRAY)
+  if (type->code () != TYPE_CODE_ARRAY)
     return type;
 
   index_type_desc = ada_find_parallel_type (type, "___XA");
   if (index_type_desc)
-    index_type = to_fixed_range_type (TYPE_FIELD_TYPE (index_type_desc, 0),
+    index_type = to_fixed_range_type (index_type_desc->field (0).type (),
                                      NULL);
   else
-    index_type = TYPE_INDEX_TYPE (type);
+    index_type = type->index_type ();
 
   new_type = alloc_type_copy (type);
   new_elt_type =
@@ -2177,9 +2065,9 @@ constrained_packed_array_type (struct type *type, long *elt_bits)
                                   elt_bits);
   create_array_type (new_type, new_elt_type, index_type);
   TYPE_FIELD_BITSIZE (new_type, 0) = *elt_bits;
-  TYPE_NAME (new_type) = ada_type_name (type);
+  new_type->set_name (ada_type_name (type));
 
-  if ((TYPE_CODE (check_typedef (index_type)) == TYPE_CODE_RANGE
+  if ((check_typedef (index_type)->code () == TYPE_CODE_RANGE
        && is_dynamic_type (check_typedef (index_type)))
       || get_discrete_bounds (index_type, &low_bound, &high_bound) < 0)
     low_bound = high_bound = 0;
@@ -2230,7 +2118,7 @@ decode_constrained_packed_array_type (struct type *type)
     }
   shadow_type = check_typedef (shadow_type);
 
-  if (TYPE_CODE (shadow_type) != TYPE_CODE_ARRAY)
+  if (shadow_type->code () != TYPE_CODE_ARRAY)
     {
       lim_warning (_("could not understand bounds "
                     "information on packed array"));
@@ -2260,7 +2148,7 @@ decode_constrained_packed_array (struct value *arr)
      and "value_ind" routines to perform the dereferencing, as opposed
      to using "ada_coerce_ref" or "ada_value_ind".  */
   arr = coerce_ref (arr);
-  if (TYPE_CODE (ada_check_typedef (value_type (arr))) == TYPE_CODE_PTR)
+  if (ada_check_typedef (value_type (arr))->code () == TYPE_CODE_PTR)
     arr = value_ind (arr);
 
   type = decode_constrained_packed_array_type (value_type (arr));
@@ -2270,7 +2158,7 @@ decode_constrained_packed_array (struct value *arr)
       return NULL;
     }
 
-  if (gdbarch_bits_big_endian (get_type_arch (value_type (arr)))
+  if (type_byte_order (value_type (arr)) == BFD_ENDIAN_BIG
       && ada_is_modular_type (value_type (arr)))
     {
        /* This is a (right-justified) modular type representing a packed
@@ -2316,14 +2204,14 @@ value_subscript_packed (struct value *arr, int arity, struct value **ind)
   elt_type = ada_check_typedef (value_type (arr));
   for (i = 0; i < arity; i += 1)
     {
-      if (TYPE_CODE (elt_type) != TYPE_CODE_ARRAY
+      if (elt_type->code () != TYPE_CODE_ARRAY
           || TYPE_FIELD_BITSIZE (elt_type, 0) == 0)
         error
           (_("attempt to do packed indexing of "
             "something other than a packed array"));
       else
         {
-          struct type *range_type = TYPE_INDEX_TYPE (elt_type);
+          struct type *range_type = elt_type->index_type ();
           LONGEST lowerbound, upperbound;
           LONGEST idx;
 
@@ -2355,14 +2243,14 @@ value_subscript_packed (struct value *arr, int arity, struct value **ind)
 static int
 has_negatives (struct type *type)
 {
-  switch (TYPE_CODE (type))
+  switch (type->code ())
     {
     default:
       return 0;
     case TYPE_CODE_INT:
       return !TYPE_UNSIGNED (type);
     case TYPE_CODE_RANGE:
-      return TYPE_LOW_BOUND (type) < 0;
+      return TYPE_LOW_BOUND (type) - TYPE_RANGE_DATA (type)->bias < 0;
     }
 }
 
@@ -2512,7 +2400,7 @@ ada_value_primitive_packed_val (struct value *obj, const gdb_byte *valaddr,
   const gdb_byte *src;                /* First byte containing data to unpack */
   gdb_byte *unpacked;
   const int is_scalar = is_scalar_type (type);
-  const int is_big_endian = gdbarch_bits_big_endian (get_type_arch (type));
+  const int is_big_endian = type_byte_order (type) == BFD_ENDIAN_BIG;
   gdb::byte_vector staging;
 
   type = ada_check_typedef (type);
@@ -2538,7 +2426,7 @@ ada_value_primitive_packed_val (struct value *obj, const gdb_byte *valaddr,
                                staging.data (), staging.size (),
                                is_big_endian, has_negatives (type),
                                is_scalar);
-      type = resolve_dynamic_type (type, staging.data (), 0);
+      type = resolve_dynamic_type (type, staging, 0);
       if (TYPE_LENGTH (type) < (bit_size + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT)
        {
          /* This happens when the length of the object is dynamic,
@@ -2640,8 +2528,8 @@ ada_value_assign (struct value *toval, struct value *fromval)
 
   if (VALUE_LVAL (toval) == lval_memory
       && bits > 0
-      && (TYPE_CODE (type) == TYPE_CODE_FLT
-          || TYPE_CODE (type) == TYPE_CODE_STRUCT))
+      && (type->code () == TYPE_CODE_FLT
+          || type->code () == TYPE_CODE_STRUCT))
     {
       int len = (value_bitpos (toval)
                 + bits + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT;
@@ -2650,7 +2538,7 @@ ada_value_assign (struct value *toval, struct value *fromval)
       struct value *val;
       CORE_ADDR to_addr = value_address (toval);
 
-      if (TYPE_CODE (type) == TYPE_CODE_FLT)
+      if (type->code () == TYPE_CODE_FLT)
         fromval = value_cast (type, fromval);
 
       read_memory (to_addr, buffer, len);
@@ -2658,7 +2546,7 @@ ada_value_assign (struct value *toval, struct value *fromval)
       if (from_size == 0)
        from_size = TYPE_LENGTH (value_type (fromval)) * TARGET_CHAR_BIT;
 
-      const int is_big_endian = gdbarch_bits_big_endian (get_type_arch (type));
+      const int is_big_endian = type_byte_order (type) == BFD_ENDIAN_BIG;
       ULONGEST from_offset = 0;
       if (is_big_endian && is_scalar_type (value_type (fromval)))
        from_offset = from_size - bits;
@@ -2707,7 +2595,7 @@ value_assign_to_component (struct value *container, struct value *component,
   else
     bits = value_bitsize (component);
 
-  if (gdbarch_bits_big_endian (get_type_arch (value_type (container))))
+  if (type_byte_order (value_type (container)) == BFD_ENDIAN_BIG)
     {
       int src_offset;
 
@@ -2731,7 +2619,7 @@ value_assign_to_component (struct value *container, struct value *component,
 bool
 ada_is_access_to_unconstrained_array (struct type *type)
 {
-  return (TYPE_CODE (type) == TYPE_CODE_TYPEDEF
+  return (type->code () == TYPE_CODE_TYPEDEF
          && is_thick_pntr (ada_typedef_target_type (type)));
 }
 
@@ -2749,7 +2637,7 @@ ada_value_subscript (struct value *arr, int arity, struct value **ind)
   elt = ada_coerce_to_simple_array (arr);
 
   elt_type = ada_check_typedef (value_type (elt));
-  if (TYPE_CODE (elt_type) == TYPE_CODE_ARRAY
+  if (elt_type->code () == TYPE_CODE_ARRAY
       && TYPE_FIELD_BITSIZE (elt_type, 0) > 0)
     return value_subscript_packed (elt, arity, ind);
 
@@ -2757,13 +2645,13 @@ ada_value_subscript (struct value *arr, int arity, struct value **ind)
     {
       struct type *saved_elt_type = TYPE_TARGET_TYPE (elt_type);
 
-      if (TYPE_CODE (elt_type) != TYPE_CODE_ARRAY)
+      if (elt_type->code () != TYPE_CODE_ARRAY)
         error (_("too many subscripts (%d expected)"), k);
 
       elt = value_subscript (elt, pos_atr (ind[k]));
 
       if (ada_is_access_to_unconstrained_array (saved_elt_type)
-         && TYPE_CODE (value_type (elt)) != TYPE_CODE_TYPEDEF)
+         && value_type (elt)->code () != TYPE_CODE_TYPEDEF)
        {
          /* The element is a typedef to an unconstrained array,
             except that the value_subscript call stripped the
@@ -2806,22 +2694,20 @@ ada_value_ptr_subscript (struct value *arr, int arity, struct value **ind)
   struct type *type
     = check_typedef (value_enclosing_type (array_ind));
 
-  if (TYPE_CODE (type) == TYPE_CODE_ARRAY
+  if (type->code () == TYPE_CODE_ARRAY
       && TYPE_FIELD_BITSIZE (type, 0) > 0)
     return value_subscript_packed (array_ind, arity, ind);
 
   for (k = 0; k < arity; k += 1)
     {
       LONGEST lwb, upb;
-      struct value *lwb_value;
 
-      if (TYPE_CODE (type) != TYPE_CODE_ARRAY)
+      if (type->code () != TYPE_CODE_ARRAY)
         error (_("too many subscripts (%d expected)"), k);
       arr = value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
                         value_copy (arr));
-      get_discrete_bounds (TYPE_INDEX_TYPE (type), &lwb, &upb);
-      lwb_value = value_from_longest (value_type(ind[k]), lwb);
-      arr = value_ptradd (arr, pos_atr (ind[k]) - pos_atr (lwb_value));
+      get_discrete_bounds (type->index_type (), &lwb, &upb);
+      arr = value_ptradd (arr, pos_atr (ind[k]) - lwb);
       type = TYPE_TARGET_TYPE (type);
     }
 
@@ -2837,14 +2723,14 @@ ada_value_slice_from_ptr (struct value *array_ptr, struct type *type,
                           int low, int high)
 {
   struct type *type0 = ada_check_typedef (type);
-  struct type *base_index_type = TYPE_TARGET_TYPE (TYPE_INDEX_TYPE (type0));
+  struct type *base_index_type = TYPE_TARGET_TYPE (type0->index_type ());
   struct type *index_type
     = create_static_range_type (NULL, base_index_type, low, high);
   struct type *slice_type = create_array_type_with_stride
                              (NULL, TYPE_TARGET_TYPE (type0), index_type,
-                              get_dyn_prop (DYN_PROP_BYTE_STRIDE, type0),
+                              type0->dyn_prop (DYN_PROP_BYTE_STRIDE),
                               TYPE_FIELD_BITSIZE (type0, 0));
-  int base_low =  ada_discrete_type_low_bound (TYPE_INDEX_TYPE (type0));
+  int base_low =  ada_discrete_type_low_bound (type0->index_type ());
   LONGEST base_low_pos, low_pos;
   CORE_ADDR base;
 
@@ -2867,12 +2753,12 @@ static struct value *
 ada_value_slice (struct value *array, int low, int high)
 {
   struct type *type = ada_check_typedef (value_type (array));
-  struct type *base_index_type = TYPE_TARGET_TYPE (TYPE_INDEX_TYPE (type));
+  struct type *base_index_type = TYPE_TARGET_TYPE (type->index_type ());
   struct type *index_type
-    = create_static_range_type (NULL, TYPE_INDEX_TYPE (type), low, high);
+    = create_static_range_type (NULL, type->index_type (), low, high);
   struct type *slice_type = create_array_type_with_stride
                              (NULL, TYPE_TARGET_TYPE (type), index_type,
-                              get_dyn_prop (DYN_PROP_BYTE_STRIDE, type),
+                              type->dyn_prop (DYN_PROP_BYTE_STRIDE),
                               TYPE_FIELD_BITSIZE (type, 0));
   LONGEST low_pos, high_pos;
 
@@ -2904,10 +2790,10 @@ ada_array_arity (struct type *type)
   type = desc_base_type (type);
 
   arity = 0;
-  if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
+  if (type->code () == TYPE_CODE_STRUCT)
     return desc_arity (desc_bounds_type (type));
   else
-    while (TYPE_CODE (type) == TYPE_CODE_ARRAY)
+    while (type->code () == TYPE_CODE_ARRAY)
       {
         arity += 1;
         type = ada_check_typedef (TYPE_TARGET_TYPE (type));
@@ -2926,7 +2812,7 @@ ada_array_element_type (struct type *type, int nindices)
 {
   type = desc_base_type (type);
 
-  if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
+  if (type->code () == TYPE_CODE_STRUCT)
     {
       int k;
       struct type *p_array_type;
@@ -2947,9 +2833,9 @@ ada_array_element_type (struct type *type, int nindices)
         }
       return p_array_type;
     }
-  else if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
+  else if (type->code () == TYPE_CODE_ARRAY)
     {
-      while (nindices != 0 && TYPE_CODE (type) == TYPE_CODE_ARRAY)
+      while (nindices != 0 && type->code () == TYPE_CODE_ARRAY)
         {
           type = TYPE_TARGET_TYPE (type);
           nindices -= 1;
@@ -2982,11 +2868,11 @@ ada_index_type (struct type *type, int n, const char *name)
 
       for (i = 1; i < n; i += 1)
         type = TYPE_TARGET_TYPE (type);
-      result_type = TYPE_TARGET_TYPE (TYPE_INDEX_TYPE (type));
+      result_type = TYPE_TARGET_TYPE (type->index_type ());
       /* FIXME: The stabs type r(0,0);bound;bound in an array type
          has a target type of TYPE_CODE_UNDEF.  We compensate here, but
          perhaps stabsread.c would make more sense.  */
-      if (result_type && TYPE_CODE (result_type) == TYPE_CODE_UNDEF)
+      if (result_type && result_type->code () == TYPE_CODE_UNDEF)
         result_type = NULL;
     }
   else
@@ -3019,7 +2905,7 @@ ada_array_bound_from_type (struct type *arr_type, int n, int which)
   if (arr_type == NULL || !ada_is_simple_array_type (arr_type))
     return (LONGEST) - which;
 
-  if (TYPE_CODE (arr_type) == TYPE_CODE_PTR)
+  if (arr_type->code () == TYPE_CODE_PTR)
     type = TYPE_TARGET_TYPE (arr_type);
   else
     type = arr_type;
@@ -3038,7 +2924,7 @@ ada_array_bound_from_type (struct type *arr_type, int n, int which)
     }
 
   if (index_type_desc != NULL)
-    index_type = to_fixed_range_type (TYPE_FIELD_TYPE (index_type_desc, n - 1),
+    index_type = to_fixed_range_type (index_type_desc->field (n - 1).type (),
                                      NULL);
   else
     {
@@ -3047,7 +2933,7 @@ ada_array_bound_from_type (struct type *arr_type, int n, int which)
       for (i = 1; i < n; i++)
        elt_type = check_typedef (TYPE_TARGET_TYPE (elt_type));
 
-      index_type = TYPE_INDEX_TYPE (elt_type);
+      index_type = elt_type->index_type ();
     }
 
   return
@@ -3066,7 +2952,7 @@ ada_array_bound (struct value *arr, int n, int which)
 {
   struct type *arr_type;
 
-  if (TYPE_CODE (check_typedef (value_type (arr))) == TYPE_CODE_PTR)
+  if (check_typedef (value_type (arr))->code () == TYPE_CODE_PTR)
     arr = value_ind (arr);
   arr_type = value_enclosing_type (arr);
 
@@ -3090,7 +2976,7 @@ ada_array_length (struct value *arr, int n)
   struct type *arr_type, *index_type;
   int low, high;
 
-  if (TYPE_CODE (check_typedef (value_type (arr))) == TYPE_CODE_PTR)
+  if (check_typedef (value_type (arr))->code () == TYPE_CODE_PTR)
     arr = value_ind (arr);
   arr_type = value_enclosing_type (arr);
 
@@ -3113,7 +2999,7 @@ ada_array_length (struct value *arr, int n)
   if (index_type != NULL)
     {
       struct type *base_type;
-      if (TYPE_CODE (index_type) == TYPE_CODE_RANGE)
+      if (index_type->code () == TYPE_CODE_RANGE)
        base_type = TYPE_TARGET_TYPE (index_type);
       else
        base_type = index_type;
@@ -3134,7 +3020,7 @@ empty_array (struct type *arr_type, int low, int high)
   struct type *arr_type0 = ada_check_typedef (arr_type);
   struct type *index_type
     = create_static_range_type
-        (NULL, TYPE_TARGET_TYPE (TYPE_INDEX_TYPE (arr_type0)), low,
+        (NULL, TYPE_TARGET_TYPE (arr_type0->index_type ()), low,
         high < low ? low - 1 : high);
   struct type *elt_type = ada_array_element_type (arr_type0, 1);
 
@@ -3160,887 +3046,863 @@ ada_decoded_op_name (enum exp_opcode op)
   error (_("Could not find operator name for opcode"));
 }
 
+/* Returns true (non-zero) iff decoded name N0 should appear before N1
+   in a listing of choices during disambiguation (see sort_choices, below).
+   The idea is that overloadings of a subprogram name from the
+   same package should sort in their source order.  We settle for ordering
+   such symbols by their trailing number (__N  or $N).  */
 
-/* Same as evaluate_type (*EXP), but resolves ambiguous symbol
-   references (marked by OP_VAR_VALUE nodes in which the symbol has an
-   undefined namespace) and converts operators that are
-   user-defined into appropriate function calls.  If CONTEXT_TYPE is
-   non-null, it provides a preferred result type [at the moment, only
-   type void has any effect---causing procedures to be preferred over
-   functions in calls].  A null CONTEXT_TYPE indicates that a non-void
-   return type is preferred.  May change (expand) *EXP.  */
-
-static void
-resolve (expression_up *expp, int void_context_p, int parse_completion,
-        innermost_block_tracker *tracker)
+static int
+encoded_ordered_before (const char *N0, const char *N1)
 {
-  struct type *context_type = NULL;
-  int pc = 0;
+  if (N1 == NULL)
+    return 0;
+  else if (N0 == NULL)
+    return 1;
+  else
+    {
+      int k0, k1;
 
-  if (void_context_p)
-    context_type = builtin_type ((*expp)->gdbarch)->builtin_void;
+      for (k0 = strlen (N0) - 1; k0 > 0 && isdigit (N0[k0]); k0 -= 1)
+        ;
+      for (k1 = strlen (N1) - 1; k1 > 0 && isdigit (N1[k1]); k1 -= 1)
+        ;
+      if ((N0[k0] == '_' || N0[k0] == '$') && N0[k0 + 1] != '\000'
+          && (N1[k1] == '_' || N1[k1] == '$') && N1[k1 + 1] != '\000')
+        {
+          int n0, n1;
 
-  resolve_subexp (expp, &pc, 1, context_type, parse_completion, tracker);
+          n0 = k0;
+          while (N0[n0] == '_' && n0 > 0 && N0[n0 - 1] == '_')
+            n0 -= 1;
+          n1 = k1;
+          while (N1[n1] == '_' && n1 > 0 && N1[n1 - 1] == '_')
+            n1 -= 1;
+          if (n0 == n1 && strncmp (N0, N1, n0) == 0)
+            return (atoi (N0 + k0 + 1) < atoi (N1 + k1 + 1));
+        }
+      return (strcmp (N0, N1) < 0);
+    }
 }
 
-/* Resolve the operator of the subexpression beginning at
-   position *POS of *EXPP.  "Resolving" consists of replacing
-   the symbols that have undefined namespaces in OP_VAR_VALUE nodes
-   with their resolutions, replacing built-in operators with
-   function calls to user-defined operators, where appropriate, and,
-   when DEPROCEDURE_P is non-zero, converting function-valued variables
-   into parameterless calls.  May expand *EXPP.  The CONTEXT_TYPE functions
-   are as in ada_resolve, above.  */
+/* Sort SYMS[0..NSYMS-1] to put the choices in a canonical order by the
+   encoded names.  */
 
-static struct value *
-resolve_subexp (expression_up *expp, int *pos, int deprocedure_p,
-                struct type *context_type, int parse_completion,
-               innermost_block_tracker *tracker)
+static void
+sort_choices (struct block_symbol syms[], int nsyms)
 {
-  int pc = *pos;
   int i;
-  struct expression *exp;       /* Convenience: == *expp.  */
-  enum exp_opcode op = (*expp)->elts[pc].opcode;
-  struct value **argvec;        /* Vector of operand types (alloca'ed).  */
-  int nargs;                    /* Number of operands.  */
-  int oplen;
-
-  argvec = NULL;
-  nargs = 0;
-  exp = expp->get ();
 
-  /* Pass one: resolve operands, saving their types and updating *pos,
-     if needed.  */
-  switch (op)
+  for (i = 1; i < nsyms; i += 1)
     {
-    case OP_FUNCALL:
-      if (exp->elts[pc + 3].opcode == OP_VAR_VALUE
-          && SYMBOL_DOMAIN (exp->elts[pc + 5].symbol) == UNDEF_DOMAIN)
-        *pos += 7;
-      else
+      struct block_symbol sym = syms[i];
+      int j;
+
+      for (j = i - 1; j >= 0; j -= 1)
         {
-          *pos += 3;
-          resolve_subexp (expp, pos, 0, NULL, parse_completion, tracker);
+          if (encoded_ordered_before (syms[j].symbol->linkage_name (),
+                                      sym.symbol->linkage_name ()))
+            break;
+          syms[j + 1] = syms[j];
         }
-      nargs = longest_to_int (exp->elts[pc + 1].longconst);
-      break;
+      syms[j + 1] = sym;
+    }
+}
 
-    case UNOP_ADDR:
-      *pos += 1;
-      resolve_subexp (expp, pos, 0, NULL, parse_completion, tracker);
-      break;
+/* Whether GDB should display formals and return types for functions in the
+   overloads selection menu.  */
+static bool print_signatures = true;
 
-    case UNOP_QUAL:
-      *pos += 3;
-      resolve_subexp (expp, pos, 1, check_typedef (exp->elts[pc + 1].type),
-                     parse_completion, tracker);
-      break;
+/* Print the signature for SYM on STREAM according to the FLAGS options.  For
+   all but functions, the signature is just the name of the symbol.  For
+   functions, this is the name of the function, the list of types for formals
+   and the return type (if any).  */
 
-    case OP_ATR_MODULUS:
-    case OP_ATR_SIZE:
-    case OP_ATR_TAG:
-    case OP_ATR_FIRST:
-    case OP_ATR_LAST:
-    case OP_ATR_LENGTH:
-    case OP_ATR_POS:
-    case OP_ATR_VAL:
-    case OP_ATR_MIN:
-    case OP_ATR_MAX:
-    case TERNOP_IN_RANGE:
-    case BINOP_IN_BOUNDS:
-    case UNOP_IN_RANGE:
-    case OP_AGGREGATE:
-    case OP_OTHERS:
-    case OP_CHOICES:
-    case OP_POSITIONAL:
-    case OP_DISCRETE_RANGE:
-    case OP_NAME:
-      ada_forward_operator_length (exp, pc, &oplen, &nargs);
-      *pos += oplen;
-      break;
+static void
+ada_print_symbol_signature (struct ui_file *stream, struct symbol *sym,
+                           const struct type_print_options *flags)
+{
+  struct type *type = SYMBOL_TYPE (sym);
 
-    case BINOP_ASSIGN:
-      {
-        struct value *arg1;
+  fprintf_filtered (stream, "%s", sym->print_name ());
+  if (!print_signatures
+      || type == NULL
+      || type->code () != TYPE_CODE_FUNC)
+    return;
 
-        *pos += 1;
-        arg1 = resolve_subexp (expp, pos, 0, NULL, parse_completion, tracker);
-        if (arg1 == NULL)
-          resolve_subexp (expp, pos, 1, NULL, parse_completion, tracker);
-        else
-          resolve_subexp (expp, pos, 1, value_type (arg1), parse_completion,
-                         tracker);
-        break;
-      }
+  if (type->num_fields () > 0)
+    {
+      int i;
 
-    case UNOP_CAST:
-      *pos += 3;
-      nargs = 1;
-      break;
+      fprintf_filtered (stream, " (");
+      for (i = 0; i < type->num_fields (); ++i)
+       {
+         if (i > 0)
+           fprintf_filtered (stream, "; ");
+         ada_print_type (type->field (i).type (), NULL, stream, -1, 0,
+                         flags);
+       }
+      fprintf_filtered (stream, ")");
+    }
+  if (TYPE_TARGET_TYPE (type) != NULL
+      && TYPE_TARGET_TYPE (type)->code () != TYPE_CODE_VOID)
+    {
+      fprintf_filtered (stream, " return ");
+      ada_print_type (TYPE_TARGET_TYPE (type), NULL, stream, -1, 0, flags);
+    }
+}
 
-    case BINOP_ADD:
-    case BINOP_SUB:
-    case BINOP_MUL:
-    case BINOP_DIV:
-    case BINOP_REM:
-    case BINOP_MOD:
-    case BINOP_EXP:
-    case BINOP_CONCAT:
-    case BINOP_LOGICAL_AND:
-    case BINOP_LOGICAL_OR:
-    case BINOP_BITWISE_AND:
-    case BINOP_BITWISE_IOR:
-    case BINOP_BITWISE_XOR:
+/* Read and validate a set of numeric choices from the user in the
+   range 0 .. N_CHOICES-1.  Place the results in increasing
+   order in CHOICES[0 .. N-1], and return N.
 
-    case BINOP_EQUAL:
-    case BINOP_NOTEQUAL:
-    case BINOP_LESS:
-    case BINOP_GTR:
-    case BINOP_LEQ:
-    case BINOP_GEQ:
+   The user types choices as a sequence of numbers on one line
+   separated by blanks, encoding them as follows:
 
-    case BINOP_REPEAT:
-    case BINOP_SUBSCRIPT:
-    case BINOP_COMMA:
-      *pos += 1;
-      nargs = 2;
-      break;
+     + A choice of 0 means to cancel the selection, throwing an error.
+     + If IS_ALL_CHOICE, a choice of 1 selects the entire set 0 .. N_CHOICES-1.
+     + The user chooses k by typing k+IS_ALL_CHOICE+1.
 
-    case UNOP_NEG:
-    case UNOP_PLUS:
-    case UNOP_LOGICAL_NOT:
-    case UNOP_ABS:
-    case UNOP_IND:
-      *pos += 1;
-      nargs = 1;
-      break;
-
-    case OP_LONG:
-    case OP_FLOAT:
-    case OP_VAR_VALUE:
-    case OP_VAR_MSYM_VALUE:
-      *pos += 4;
-      break;
-
-    case OP_TYPE:
-    case OP_BOOL:
-    case OP_LAST:
-    case OP_INTERNALVAR:
-      *pos += 3;
-      break;
-
-    case UNOP_MEMVAL:
-      *pos += 3;
-      nargs = 1;
-      break;
+   The user is not allowed to choose more than MAX_RESULTS values.
 
-    case OP_REGISTER:
-      *pos += 4 + BYTES_TO_EXP_ELEM (exp->elts[pc + 1].longconst + 1);
-      break;
+   ANNOTATION_SUFFIX, if present, is used to annotate the input
+   prompts (for use with the -f switch).  */
 
-    case STRUCTOP_STRUCT:
-      *pos += 4 + BYTES_TO_EXP_ELEM (exp->elts[pc + 1].longconst + 1);
-      nargs = 1;
-      break;
+static int
+get_selections (int *choices, int n_choices, int max_results,
+                int is_all_choice, const char *annotation_suffix)
+{
+  const char *args;
+  const char *prompt;
+  int n_chosen;
+  int first_choice = is_all_choice ? 2 : 1;
 
-    case TERNOP_SLICE:
-      *pos += 1;
-      nargs = 3;
-      break;
+  prompt = getenv ("PS2");
+  if (prompt == NULL)
+    prompt = "> ";
 
-    case OP_STRING:
-      break;
+  args = command_line_input (prompt, annotation_suffix);
 
-    default:
-      error (_("Unexpected operator during name resolution"));
-    }
+  if (args == NULL)
+    error_no_arg (_("one or more choice numbers"));
 
-  argvec = XALLOCAVEC (struct value *, nargs + 1);
-  for (i = 0; i < nargs; i += 1)
-    argvec[i] = resolve_subexp (expp, pos, 1, NULL, parse_completion,
-                               tracker);
-  argvec[i] = NULL;
-  exp = expp->get ();
+  n_chosen = 0;
 
-  /* Pass two: perform any resolution on principal operator.  */
-  switch (op)
+  /* Set choices[0 .. n_chosen-1] to the users' choices in ascending
+     order, as given in args.  Choices are validated.  */
+  while (1)
     {
-    default:
-      break;
+      char *args2;
+      int choice, j;
 
-    case OP_VAR_VALUE:
-      if (SYMBOL_DOMAIN (exp->elts[pc + 2].symbol) == UNDEF_DOMAIN)
-        {
-          std::vector<struct block_symbol> candidates;
-          int n_candidates;
+      args = skip_spaces (args);
+      if (*args == '\0' && n_chosen == 0)
+        error_no_arg (_("one or more choice numbers"));
+      else if (*args == '\0')
+        break;
 
-          n_candidates =
-            ada_lookup_symbol_list (SYMBOL_LINKAGE_NAME
-                                    (exp->elts[pc + 2].symbol),
-                                    exp->elts[pc + 1].block, VAR_DOMAIN,
-                                    &candidates);
+      choice = strtol (args, &args2, 10);
+      if (args == args2 || choice < 0
+          || choice > n_choices + first_choice - 1)
+        error (_("Argument must be choice number"));
+      args = args2;
 
-          if (n_candidates > 1)
-            {
-              /* Types tend to get re-introduced locally, so if there
-                 are any local symbols that are not types, first filter
-                 out all types.  */
-              int j;
-              for (j = 0; j < n_candidates; j += 1)
-                switch (SYMBOL_CLASS (candidates[j].symbol))
-                  {
-                  case LOC_REGISTER:
-                  case LOC_ARG:
-                  case LOC_REF_ARG:
-                  case LOC_REGPARM_ADDR:
-                  case LOC_LOCAL:
-                  case LOC_COMPUTED:
-                    goto FoundNonType;
-                  default:
-                    break;
-                  }
-            FoundNonType:
-              if (j < n_candidates)
-                {
-                  j = 0;
-                  while (j < n_candidates)
-                    {
-                      if (SYMBOL_CLASS (candidates[j].symbol) == LOC_TYPEDEF)
-                        {
-                          candidates[j] = candidates[n_candidates - 1];
-                          n_candidates -= 1;
-                        }
-                      else
-                        j += 1;
-                    }
-                }
-            }
+      if (choice == 0)
+        error (_("cancelled"));
 
-          if (n_candidates == 0)
-            error (_("No definition found for %s"),
-                   SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol));
-          else if (n_candidates == 1)
-            i = 0;
-          else if (deprocedure_p
-                   && !is_nonfunction (candidates.data (), n_candidates))
-            {
-              i = ada_resolve_function
-                (candidates.data (), n_candidates, NULL, 0,
-                 SYMBOL_LINKAGE_NAME (exp->elts[pc + 2].symbol),
-                 context_type, parse_completion);
-              if (i < 0)
-                error (_("Could not find a match for %s"),
-                       SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol));
-            }
-          else
-            {
-              printf_filtered (_("Multiple matches for %s\n"),
-                               SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol));
-              user_select_syms (candidates.data (), n_candidates, 1);
-              i = 0;
-            }
+      if (choice < first_choice)
+        {
+          n_chosen = n_choices;
+          for (j = 0; j < n_choices; j += 1)
+            choices[j] = j;
+          break;
+        }
+      choice -= first_choice;
 
-          exp->elts[pc + 1].block = candidates[i].block;
-          exp->elts[pc + 2].symbol = candidates[i].symbol;
-         tracker->update (candidates[i]);
+      for (j = n_chosen - 1; j >= 0 && choice < choices[j]; j -= 1)
+        {
         }
 
-      if (deprocedure_p
-          && (TYPE_CODE (SYMBOL_TYPE (exp->elts[pc + 2].symbol))
-              == TYPE_CODE_FUNC))
+      if (j < 0 || choice != choices[j])
         {
-          replace_operator_with_call (expp, pc, 0, 4,
-                                      exp->elts[pc + 2].symbol,
-                                      exp->elts[pc + 1].block);
-          exp = expp->get ();
+          int k;
+
+          for (k = n_chosen - 1; k > j; k -= 1)
+            choices[k + 1] = choices[k];
+          choices[j + 1] = choice;
+          n_chosen += 1;
         }
-      break;
+    }
 
-    case OP_FUNCALL:
-      {
-        if (exp->elts[pc + 3].opcode == OP_VAR_VALUE
-            && SYMBOL_DOMAIN (exp->elts[pc + 5].symbol) == UNDEF_DOMAIN)
-          {
-           std::vector<struct block_symbol> candidates;
-            int n_candidates;
+  if (n_chosen > max_results)
+    error (_("Select no more than %d of the above"), max_results);
 
-            n_candidates =
-              ada_lookup_symbol_list (SYMBOL_LINKAGE_NAME
-                                      (exp->elts[pc + 5].symbol),
-                                      exp->elts[pc + 4].block, VAR_DOMAIN,
-                                      &candidates);
+  return n_chosen;
+}
 
-            if (n_candidates == 1)
-              i = 0;
-            else
-              {
-                i = ada_resolve_function
-                  (candidates.data (), n_candidates,
-                   argvec, nargs,
-                   SYMBOL_LINKAGE_NAME (exp->elts[pc + 5].symbol),
-                   context_type, parse_completion);
-                if (i < 0)
-                  error (_("Could not find a match for %s"),
-                         SYMBOL_PRINT_NAME (exp->elts[pc + 5].symbol));
-              }
+/* Given a list of NSYMS symbols in SYMS, select up to MAX_RESULTS>0
+   by asking the user (if necessary), returning the number selected,
+   and setting the first elements of SYMS items.  Error if no symbols
+   selected.  */
 
-            exp->elts[pc + 4].block = candidates[i].block;
-            exp->elts[pc + 5].symbol = candidates[i].symbol;
-           tracker->update (candidates[i]);
-          }
-      }
-      break;
-    case BINOP_ADD:
-    case BINOP_SUB:
-    case BINOP_MUL:
-    case BINOP_DIV:
-    case BINOP_REM:
-    case BINOP_MOD:
-    case BINOP_CONCAT:
-    case BINOP_BITWISE_AND:
-    case BINOP_BITWISE_IOR:
-    case BINOP_BITWISE_XOR:
-    case BINOP_EQUAL:
-    case BINOP_NOTEQUAL:
-    case BINOP_LESS:
-    case BINOP_GTR:
-    case BINOP_LEQ:
-    case BINOP_GEQ:
-    case BINOP_EXP:
-    case UNOP_NEG:
-    case UNOP_PLUS:
-    case UNOP_LOGICAL_NOT:
-    case UNOP_ABS:
-      if (possible_user_operator_p (op, argvec))
-        {
-         std::vector<struct block_symbol> candidates;
-          int n_candidates;
+/* NOTE: Adapted from decode_line_2 in symtab.c, with which it ought
+   to be re-integrated one of these days.  */
 
-          n_candidates =
-            ada_lookup_symbol_list (ada_decoded_op_name (op),
-                                   NULL, VAR_DOMAIN,
-                                    &candidates);
+static int
+user_select_syms (struct block_symbol *syms, int nsyms, int max_results)
+{
+  int i;
+  int *chosen = XALLOCAVEC (int , nsyms);
+  int n_chosen;
+  int first_choice = (max_results == 1) ? 1 : 2;
+  const char *select_mode = multiple_symbols_select_mode ();
 
-          i = ada_resolve_function (candidates.data (), n_candidates, argvec,
-                                   nargs, ada_decoded_op_name (op), NULL,
-                                   parse_completion);
-          if (i < 0)
-            break;
+  if (max_results < 1)
+    error (_("Request to select 0 symbols!"));
+  if (nsyms <= 1)
+    return nsyms;
 
-         replace_operator_with_call (expp, pc, nargs, 1,
-                                     candidates[i].symbol,
-                                     candidates[i].block);
-          exp = expp->get ();
-        }
-      break;
+  if (select_mode == multiple_symbols_cancel)
+    error (_("\
+canceled because the command is ambiguous\n\
+See set/show multiple-symbol."));
 
-    case OP_TYPE:
-    case OP_REGISTER:
-      return NULL;
-    }
+  /* If select_mode is "all", then return all possible symbols.
+     Only do that if more than one symbol can be selected, of course.
+     Otherwise, display the menu as usual.  */
+  if (select_mode == multiple_symbols_all && max_results > 1)
+    return nsyms;
 
-  *pos = pc;
-  if (exp->elts[pc].opcode == OP_VAR_MSYM_VALUE)
-    return evaluate_var_msym_value (EVAL_AVOID_SIDE_EFFECTS,
-                                   exp->elts[pc + 1].objfile,
-                                   exp->elts[pc + 2].msymbol);
-  else
-    return evaluate_subexp_type (exp, pos);
-}
+  printf_filtered (_("[0] cancel\n"));
+  if (max_results > 1)
+    printf_filtered (_("[1] all\n"));
 
-/* Return non-zero if formal type FTYPE matches actual type ATYPE.  If
-   MAY_DEREF is non-zero, the formal may be a pointer and the actual
-   a non-pointer.  */
-/* The term "match" here is rather loose.  The match is heuristic and
-   liberal.  */
+  sort_choices (syms, nsyms);
 
-static int
-ada_type_match (struct type *ftype, struct type *atype, int may_deref)
-{
-  ftype = ada_check_typedef (ftype);
-  atype = ada_check_typedef (atype);
+  for (i = 0; i < nsyms; i += 1)
+    {
+      if (syms[i].symbol == NULL)
+        continue;
 
-  if (TYPE_CODE (ftype) == TYPE_CODE_REF)
-    ftype = TYPE_TARGET_TYPE (ftype);
-  if (TYPE_CODE (atype) == TYPE_CODE_REF)
-    atype = TYPE_TARGET_TYPE (atype);
+      if (SYMBOL_CLASS (syms[i].symbol) == LOC_BLOCK)
+        {
+          struct symtab_and_line sal =
+            find_function_start_sal (syms[i].symbol, 1);
 
-  switch (TYPE_CODE (ftype))
-    {
-    default:
-      return TYPE_CODE (ftype) == TYPE_CODE (atype);
-    case TYPE_CODE_PTR:
-      if (TYPE_CODE (atype) == TYPE_CODE_PTR)
-        return ada_type_match (TYPE_TARGET_TYPE (ftype),
-                               TYPE_TARGET_TYPE (atype), 0);
+         printf_filtered ("[%d] ", i + first_choice);
+         ada_print_symbol_signature (gdb_stdout, syms[i].symbol,
+                                     &type_print_raw_options);
+         if (sal.symtab == NULL)
+           printf_filtered (_(" at %p[<no source file available>%p]:%d\n"),
+                            metadata_style.style ().ptr (), nullptr, sal.line);
+         else
+           printf_filtered
+             (_(" at %ps:%d\n"),
+              styled_string (file_name_style.style (),
+                             symtab_to_filename_for_display (sal.symtab)),
+              sal.line);
+          continue;
+        }
       else
-        return (may_deref
-                && ada_type_match (TYPE_TARGET_TYPE (ftype), atype, 0));
-    case TYPE_CODE_INT:
-    case TYPE_CODE_ENUM:
-    case TYPE_CODE_RANGE:
-      switch (TYPE_CODE (atype))
         {
-        case TYPE_CODE_INT:
-        case TYPE_CODE_ENUM:
-        case TYPE_CODE_RANGE:
-          return 1;
-        default:
-          return 0;
-        }
+          int is_enumeral =
+            (SYMBOL_CLASS (syms[i].symbol) == LOC_CONST
+             && SYMBOL_TYPE (syms[i].symbol) != NULL
+             && SYMBOL_TYPE (syms[i].symbol)->code () == TYPE_CODE_ENUM);
+         struct symtab *symtab = NULL;
 
-    case TYPE_CODE_ARRAY:
-      return (TYPE_CODE (atype) == TYPE_CODE_ARRAY
-              || ada_is_array_descriptor_type (atype));
+         if (SYMBOL_OBJFILE_OWNED (syms[i].symbol))
+           symtab = symbol_symtab (syms[i].symbol);
 
-    case TYPE_CODE_STRUCT:
-      if (ada_is_array_descriptor_type (ftype))
-        return (TYPE_CODE (atype) == TYPE_CODE_ARRAY
-                || ada_is_array_descriptor_type (atype));
-      else
-        return (TYPE_CODE (atype) == TYPE_CODE_STRUCT
-                && !ada_is_array_descriptor_type (atype));
+          if (SYMBOL_LINE (syms[i].symbol) != 0 && symtab != NULL)
+           {
+             printf_filtered ("[%d] ", i + first_choice);
+             ada_print_symbol_signature (gdb_stdout, syms[i].symbol,
+                                         &type_print_raw_options);
+             printf_filtered (_(" at %s:%d\n"),
+                              symtab_to_filename_for_display (symtab),
+                              SYMBOL_LINE (syms[i].symbol));
+           }
+          else if (is_enumeral
+                   && SYMBOL_TYPE (syms[i].symbol)->name () != NULL)
+            {
+              printf_filtered (("[%d] "), i + first_choice);
+              ada_print_type (SYMBOL_TYPE (syms[i].symbol), NULL,
+                              gdb_stdout, -1, 0, &type_print_raw_options);
+              printf_filtered (_("'(%s) (enumeral)\n"),
+                              syms[i].symbol->print_name ());
+            }
+         else
+           {
+             printf_filtered ("[%d] ", i + first_choice);
+             ada_print_symbol_signature (gdb_stdout, syms[i].symbol,
+                                         &type_print_raw_options);
 
-    case TYPE_CODE_UNION:
-    case TYPE_CODE_FLT:
-      return (TYPE_CODE (atype) == TYPE_CODE (ftype));
+             if (symtab != NULL)
+               printf_filtered (is_enumeral
+                                ? _(" in %s (enumeral)\n")
+                                : _(" at %s:?\n"),
+                                symtab_to_filename_for_display (symtab));
+             else
+               printf_filtered (is_enumeral
+                                ? _(" (enumeral)\n")
+                                : _(" at ?\n"));
+           }
+        }
     }
+
+  n_chosen = get_selections (chosen, nsyms, max_results, max_results > 1,
+                             "overload-choice");
+
+  for (i = 0; i < n_chosen; i += 1)
+    syms[i] = syms[chosen[i]];
+
+  return n_chosen;
 }
 
-/* Return non-zero if the formals of FUNC "sufficiently match" the
-   vector of actual argument types ACTUALS of size N_ACTUALS.  FUNC
-   may also be an enumeral, in which case it is treated as a 0-
-   argument function.  */
+/* Resolve the operator of the subexpression beginning at
+   position *POS of *EXPP.  "Resolving" consists of replacing
+   the symbols that have undefined namespaces in OP_VAR_VALUE nodes
+   with their resolutions, replacing built-in operators with
+   function calls to user-defined operators, where appropriate, and,
+   when DEPROCEDURE_P is non-zero, converting function-valued variables
+   into parameterless calls.  May expand *EXPP.  The CONTEXT_TYPE functions
+   are as in ada_resolve, above.  */
 
-static int
-ada_args_match (struct symbol *func, struct value **actuals, int n_actuals)
+static struct value *
+resolve_subexp (expression_up *expp, int *pos, int deprocedure_p,
+                struct type *context_type, int parse_completion,
+               innermost_block_tracker *tracker)
 {
+  int pc = *pos;
   int i;
-  struct type *func_type = SYMBOL_TYPE (func);
-
-  if (SYMBOL_CLASS (func) == LOC_CONST
-      && TYPE_CODE (func_type) == TYPE_CODE_ENUM)
-    return (n_actuals == 0);
-  else if (func_type == NULL || TYPE_CODE (func_type) != TYPE_CODE_FUNC)
-    return 0;
+  struct expression *exp;       /* Convenience: == *expp.  */
+  enum exp_opcode op = (*expp)->elts[pc].opcode;
+  struct value **argvec;        /* Vector of operand types (alloca'ed).  */
+  int nargs;                    /* Number of operands.  */
+  int oplen;
 
-  if (TYPE_NFIELDS (func_type) != n_actuals)
-    return 0;
+  argvec = NULL;
+  nargs = 0;
+  exp = expp->get ();
 
-  for (i = 0; i < n_actuals; i += 1)
+  /* Pass one: resolve operands, saving their types and updating *pos,
+     if needed.  */
+  switch (op)
     {
-      if (actuals[i] == NULL)
-        return 0;
+    case OP_FUNCALL:
+      if (exp->elts[pc + 3].opcode == OP_VAR_VALUE
+          && SYMBOL_DOMAIN (exp->elts[pc + 5].symbol) == UNDEF_DOMAIN)
+        *pos += 7;
       else
         {
-          struct type *ftype = ada_check_typedef (TYPE_FIELD_TYPE (func_type,
-                                                                  i));
-          struct type *atype = ada_check_typedef (value_type (actuals[i]));
-
-          if (!ada_type_match (ftype, atype, 1))
-            return 0;
+          *pos += 3;
+          resolve_subexp (expp, pos, 0, NULL, parse_completion, tracker);
         }
-    }
-  return 1;
-}
+      nargs = longest_to_int (exp->elts[pc + 1].longconst);
+      break;
 
-/* False iff function type FUNC_TYPE definitely does not produce a value
-   compatible with type CONTEXT_TYPE.  Conservatively returns 1 if
-   FUNC_TYPE is not a valid function type with a non-null return type
-   or an enumerated type.  A null CONTEXT_TYPE indicates any non-void type.  */
+    case UNOP_ADDR:
+      *pos += 1;
+      resolve_subexp (expp, pos, 0, NULL, parse_completion, tracker);
+      break;
 
-static int
-return_match (struct type *func_type, struct type *context_type)
-{
-  struct type *return_type;
+    case UNOP_QUAL:
+      *pos += 3;
+      resolve_subexp (expp, pos, 1, check_typedef (exp->elts[pc + 1].type),
+                     parse_completion, tracker);
+      break;
 
-  if (func_type == NULL)
-    return 1;
+    case OP_ATR_MODULUS:
+    case OP_ATR_SIZE:
+    case OP_ATR_TAG:
+    case OP_ATR_FIRST:
+    case OP_ATR_LAST:
+    case OP_ATR_LENGTH:
+    case OP_ATR_POS:
+    case OP_ATR_VAL:
+    case OP_ATR_MIN:
+    case OP_ATR_MAX:
+    case TERNOP_IN_RANGE:
+    case BINOP_IN_BOUNDS:
+    case UNOP_IN_RANGE:
+    case OP_AGGREGATE:
+    case OP_OTHERS:
+    case OP_CHOICES:
+    case OP_POSITIONAL:
+    case OP_DISCRETE_RANGE:
+    case OP_NAME:
+      ada_forward_operator_length (exp, pc, &oplen, &nargs);
+      *pos += oplen;
+      break;
 
-  if (TYPE_CODE (func_type) == TYPE_CODE_FUNC)
-    return_type = get_base_type (TYPE_TARGET_TYPE (func_type));
-  else
-    return_type = get_base_type (func_type);
-  if (return_type == NULL)
-    return 1;
+    case BINOP_ASSIGN:
+      {
+        struct value *arg1;
 
-  context_type = get_base_type (context_type);
+        *pos += 1;
+        arg1 = resolve_subexp (expp, pos, 0, NULL, parse_completion, tracker);
+        if (arg1 == NULL)
+          resolve_subexp (expp, pos, 1, NULL, parse_completion, tracker);
+        else
+          resolve_subexp (expp, pos, 1, value_type (arg1), parse_completion,
+                         tracker);
+        break;
+      }
 
-  if (TYPE_CODE (return_type) == TYPE_CODE_ENUM)
-    return context_type == NULL || return_type == context_type;
-  else if (context_type == NULL)
-    return TYPE_CODE (return_type) != TYPE_CODE_VOID;
-  else
-    return TYPE_CODE (return_type) == TYPE_CODE (context_type);
-}
+    case UNOP_CAST:
+      *pos += 3;
+      nargs = 1;
+      break;
 
+    case BINOP_ADD:
+    case BINOP_SUB:
+    case BINOP_MUL:
+    case BINOP_DIV:
+    case BINOP_REM:
+    case BINOP_MOD:
+    case BINOP_EXP:
+    case BINOP_CONCAT:
+    case BINOP_LOGICAL_AND:
+    case BINOP_LOGICAL_OR:
+    case BINOP_BITWISE_AND:
+    case BINOP_BITWISE_IOR:
+    case BINOP_BITWISE_XOR:
 
-/* Returns the index in SYMS[0..NSYMS-1] that contains  the symbol for the
-   function (if any) that matches the types of the NARGS arguments in
-   ARGS.  If CONTEXT_TYPE is non-null and there is at least one match
-   that returns that type, then eliminate matches that don't.  If
-   CONTEXT_TYPE is void and there is at least one match that does not
-   return void, eliminate all matches that do.
+    case BINOP_EQUAL:
+    case BINOP_NOTEQUAL:
+    case BINOP_LESS:
+    case BINOP_GTR:
+    case BINOP_LEQ:
+    case BINOP_GEQ:
 
-   Asks the user if there is more than one match remaining.  Returns -1
-   if there is no such symbol or none is selected.  NAME is used
-   solely for messages.  May re-arrange and modify SYMS in
-   the process; the index returned is for the modified vector.  */
+    case BINOP_REPEAT:
+    case BINOP_SUBSCRIPT:
+    case BINOP_COMMA:
+      *pos += 1;
+      nargs = 2;
+      break;
 
-static int
-ada_resolve_function (struct block_symbol syms[],
-                      int nsyms, struct value **args, int nargs,
-                      const char *name, struct type *context_type,
-                     int parse_completion)
-{
-  int fallback;
-  int k;
-  int m;                        /* Number of hits */
+    case UNOP_NEG:
+    case UNOP_PLUS:
+    case UNOP_LOGICAL_NOT:
+    case UNOP_ABS:
+    case UNOP_IND:
+      *pos += 1;
+      nargs = 1;
+      break;
 
-  m = 0;
-  /* In the first pass of the loop, we only accept functions matching
-     context_type.  If none are found, we add a second pass of the loop
-     where every function is accepted.  */
-  for (fallback = 0; m == 0 && fallback < 2; fallback++)
-    {
-      for (k = 0; k < nsyms; k += 1)
-        {
-          struct type *type = ada_check_typedef (SYMBOL_TYPE (syms[k].symbol));
+    case OP_LONG:
+    case OP_FLOAT:
+    case OP_VAR_VALUE:
+    case OP_VAR_MSYM_VALUE:
+      *pos += 4;
+      break;
 
-          if (ada_args_match (syms[k].symbol, args, nargs)
-              && (fallback || return_match (type, context_type)))
-            {
-              syms[m] = syms[k];
-              m += 1;
-            }
-        }
-    }
+    case OP_TYPE:
+    case OP_BOOL:
+    case OP_LAST:
+    case OP_INTERNALVAR:
+      *pos += 3;
+      break;
 
-  /* If we got multiple matches, ask the user which one to use.  Don't do this
-     interactive thing during completion, though, as the purpose of the
-     completion is providing a list of all possible matches.  Prompting the
-     user to filter it down would be completely unexpected in this case.  */
-  if (m == 0)
-    return -1;
-  else if (m > 1 && !parse_completion)
-    {
-      printf_filtered (_("Multiple matches for %s\n"), name);
-      user_select_syms (syms, m, 1);
-      return 0;
+    case UNOP_MEMVAL:
+      *pos += 3;
+      nargs = 1;
+      break;
+
+    case OP_REGISTER:
+      *pos += 4 + BYTES_TO_EXP_ELEM (exp->elts[pc + 1].longconst + 1);
+      break;
+
+    case STRUCTOP_STRUCT:
+      *pos += 4 + BYTES_TO_EXP_ELEM (exp->elts[pc + 1].longconst + 1);
+      nargs = 1;
+      break;
+
+    case TERNOP_SLICE:
+      *pos += 1;
+      nargs = 3;
+      break;
+
+    case OP_STRING:
+      break;
+
+    default:
+      error (_("Unexpected operator during name resolution"));
     }
-  return 0;
-}
 
-/* Returns true (non-zero) iff decoded name N0 should appear before N1
-   in a listing of choices during disambiguation (see sort_choices, below).
-   The idea is that overloadings of a subprogram name from the
-   same package should sort in their source order.  We settle for ordering
-   such symbols by their trailing number (__N  or $N).  */
+  argvec = XALLOCAVEC (struct value *, nargs + 1);
+  for (i = 0; i < nargs; i += 1)
+    argvec[i] = resolve_subexp (expp, pos, 1, NULL, parse_completion,
+                               tracker);
+  argvec[i] = NULL;
+  exp = expp->get ();
 
-static int
-encoded_ordered_before (const char *N0, const char *N1)
-{
-  if (N1 == NULL)
-    return 0;
-  else if (N0 == NULL)
-    return 1;
-  else
+  /* Pass two: perform any resolution on principal operator.  */
+  switch (op)
     {
-      int k0, k1;
+    default:
+      break;
 
-      for (k0 = strlen (N0) - 1; k0 > 0 && isdigit (N0[k0]); k0 -= 1)
-        ;
-      for (k1 = strlen (N1) - 1; k1 > 0 && isdigit (N1[k1]); k1 -= 1)
-        ;
-      if ((N0[k0] == '_' || N0[k0] == '$') && N0[k0 + 1] != '\000'
-          && (N1[k1] == '_' || N1[k1] == '$') && N1[k1 + 1] != '\000')
+    case OP_VAR_VALUE:
+      if (SYMBOL_DOMAIN (exp->elts[pc + 2].symbol) == UNDEF_DOMAIN)
         {
-          int n0, n1;
+          std::vector<struct block_symbol> candidates;
+          int n_candidates;
 
-          n0 = k0;
-          while (N0[n0] == '_' && n0 > 0 && N0[n0 - 1] == '_')
-            n0 -= 1;
-          n1 = k1;
-          while (N1[n1] == '_' && n1 > 0 && N1[n1 - 1] == '_')
-            n1 -= 1;
-          if (n0 == n1 && strncmp (N0, N1, n0) == 0)
-            return (atoi (N0 + k0 + 1) < atoi (N1 + k1 + 1));
+          n_candidates =
+            ada_lookup_symbol_list (exp->elts[pc + 2].symbol->linkage_name (),
+                                    exp->elts[pc + 1].block, VAR_DOMAIN,
+                                    &candidates);
+
+          if (n_candidates > 1)
+            {
+              /* Types tend to get re-introduced locally, so if there
+                 are any local symbols that are not types, first filter
+                 out all types.  */
+              int j;
+              for (j = 0; j < n_candidates; j += 1)
+                switch (SYMBOL_CLASS (candidates[j].symbol))
+                  {
+                  case LOC_REGISTER:
+                  case LOC_ARG:
+                  case LOC_REF_ARG:
+                  case LOC_REGPARM_ADDR:
+                  case LOC_LOCAL:
+                  case LOC_COMPUTED:
+                    goto FoundNonType;
+                  default:
+                    break;
+                  }
+            FoundNonType:
+              if (j < n_candidates)
+                {
+                  j = 0;
+                  while (j < n_candidates)
+                    {
+                      if (SYMBOL_CLASS (candidates[j].symbol) == LOC_TYPEDEF)
+                        {
+                          candidates[j] = candidates[n_candidates - 1];
+                          n_candidates -= 1;
+                        }
+                      else
+                        j += 1;
+                    }
+                }
+            }
+
+          if (n_candidates == 0)
+            error (_("No definition found for %s"),
+                   exp->elts[pc + 2].symbol->print_name ());
+          else if (n_candidates == 1)
+            i = 0;
+          else if (deprocedure_p
+                   && !is_nonfunction (candidates.data (), n_candidates))
+            {
+              i = ada_resolve_function
+                (candidates.data (), n_candidates, NULL, 0,
+                 exp->elts[pc + 2].symbol->linkage_name (),
+                 context_type, parse_completion);
+              if (i < 0)
+                error (_("Could not find a match for %s"),
+                       exp->elts[pc + 2].symbol->print_name ());
+            }
+          else
+            {
+              printf_filtered (_("Multiple matches for %s\n"),
+                               exp->elts[pc + 2].symbol->print_name ());
+              user_select_syms (candidates.data (), n_candidates, 1);
+              i = 0;
+            }
+
+          exp->elts[pc + 1].block = candidates[i].block;
+          exp->elts[pc + 2].symbol = candidates[i].symbol;
+         tracker->update (candidates[i]);
+        }
+
+      if (deprocedure_p
+          && (SYMBOL_TYPE (exp->elts[pc + 2].symbol)->code ()
+              == TYPE_CODE_FUNC))
+        {
+          replace_operator_with_call (expp, pc, 0, 4,
+                                      exp->elts[pc + 2].symbol,
+                                      exp->elts[pc + 1].block);
+          exp = expp->get ();
         }
-      return (strcmp (N0, N1) < 0);
-    }
-}
+      break;
 
-/* Sort SYMS[0..NSYMS-1] to put the choices in a canonical order by the
-   encoded names.  */
+    case OP_FUNCALL:
+      {
+        if (exp->elts[pc + 3].opcode == OP_VAR_VALUE
+            && SYMBOL_DOMAIN (exp->elts[pc + 5].symbol) == UNDEF_DOMAIN)
+          {
+           std::vector<struct block_symbol> candidates;
+            int n_candidates;
 
-static void
-sort_choices (struct block_symbol syms[], int nsyms)
-{
-  int i;
+            n_candidates =
+              ada_lookup_symbol_list (exp->elts[pc + 5].symbol->linkage_name (),
+                                      exp->elts[pc + 4].block, VAR_DOMAIN,
+                                      &candidates);
 
-  for (i = 1; i < nsyms; i += 1)
-    {
-      struct block_symbol sym = syms[i];
-      int j;
+            if (n_candidates == 1)
+              i = 0;
+            else
+              {
+                i = ada_resolve_function
+                  (candidates.data (), n_candidates,
+                   argvec, nargs,
+                   exp->elts[pc + 5].symbol->linkage_name (),
+                   context_type, parse_completion);
+                if (i < 0)
+                  error (_("Could not find a match for %s"),
+                         exp->elts[pc + 5].symbol->print_name ());
+              }
 
-      for (j = i - 1; j >= 0; j -= 1)
+            exp->elts[pc + 4].block = candidates[i].block;
+            exp->elts[pc + 5].symbol = candidates[i].symbol;
+           tracker->update (candidates[i]);
+          }
+      }
+      break;
+    case BINOP_ADD:
+    case BINOP_SUB:
+    case BINOP_MUL:
+    case BINOP_DIV:
+    case BINOP_REM:
+    case BINOP_MOD:
+    case BINOP_CONCAT:
+    case BINOP_BITWISE_AND:
+    case BINOP_BITWISE_IOR:
+    case BINOP_BITWISE_XOR:
+    case BINOP_EQUAL:
+    case BINOP_NOTEQUAL:
+    case BINOP_LESS:
+    case BINOP_GTR:
+    case BINOP_LEQ:
+    case BINOP_GEQ:
+    case BINOP_EXP:
+    case UNOP_NEG:
+    case UNOP_PLUS:
+    case UNOP_LOGICAL_NOT:
+    case UNOP_ABS:
+      if (possible_user_operator_p (op, argvec))
         {
-          if (encoded_ordered_before (SYMBOL_LINKAGE_NAME (syms[j].symbol),
-                                      SYMBOL_LINKAGE_NAME (sym.symbol)))
-            break;
-          syms[j + 1] = syms[j];
-        }
-      syms[j + 1] = sym;
-    }
-}
-
-/* Whether GDB should display formals and return types for functions in the
-   overloads selection menu.  */
-static int print_signatures = 1;
-
-/* Print the signature for SYM on STREAM according to the FLAGS options.  For
-   all but functions, the signature is just the name of the symbol.  For
-   functions, this is the name of the function, the list of types for formals
-   and the return type (if any).  */
+         std::vector<struct block_symbol> candidates;
+          int n_candidates;
 
-static void
-ada_print_symbol_signature (struct ui_file *stream, struct symbol *sym,
-                           const struct type_print_options *flags)
-{
-  struct type *type = SYMBOL_TYPE (sym);
+          n_candidates =
+            ada_lookup_symbol_list (ada_decoded_op_name (op),
+                                   NULL, VAR_DOMAIN,
+                                    &candidates);
 
-  fprintf_filtered (stream, "%s", SYMBOL_PRINT_NAME (sym));
-  if (!print_signatures
-      || type == NULL
-      || TYPE_CODE (type) != TYPE_CODE_FUNC)
-    return;
+          i = ada_resolve_function (candidates.data (), n_candidates, argvec,
+                                   nargs, ada_decoded_op_name (op), NULL,
+                                   parse_completion);
+          if (i < 0)
+            break;
 
-  if (TYPE_NFIELDS (type) > 0)
-    {
-      int i;
+         replace_operator_with_call (expp, pc, nargs, 1,
+                                     candidates[i].symbol,
+                                     candidates[i].block);
+          exp = expp->get ();
+        }
+      break;
 
-      fprintf_filtered (stream, " (");
-      for (i = 0; i < TYPE_NFIELDS (type); ++i)
-       {
-         if (i > 0)
-           fprintf_filtered (stream, "; ");
-         ada_print_type (TYPE_FIELD_TYPE (type, i), NULL, stream, -1, 0,
-                         flags);
-       }
-      fprintf_filtered (stream, ")");
-    }
-  if (TYPE_TARGET_TYPE (type) != NULL
-      && TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_VOID)
-    {
-      fprintf_filtered (stream, " return ");
-      ada_print_type (TYPE_TARGET_TYPE (type), NULL, stream, -1, 0, flags);
+    case OP_TYPE:
+    case OP_REGISTER:
+      return NULL;
     }
-}
 
-/* Given a list of NSYMS symbols in SYMS, select up to MAX_RESULTS>0 
-   by asking the user (if necessary), returning the number selected, 
-   and setting the first elements of SYMS items.  Error if no symbols
-   selected.  */
+  *pos = pc;
+  if (exp->elts[pc].opcode == OP_VAR_MSYM_VALUE)
+    return evaluate_var_msym_value (EVAL_AVOID_SIDE_EFFECTS,
+                                   exp->elts[pc + 1].objfile,
+                                   exp->elts[pc + 2].msymbol);
+  else
+    return evaluate_subexp_type (exp, pos);
+}
 
-/* NOTE: Adapted from decode_line_2 in symtab.c, with which it ought
-   to be re-integrated one of these days.  */
+/* Return non-zero if formal type FTYPE matches actual type ATYPE.  If
+   MAY_DEREF is non-zero, the formal may be a pointer and the actual
+   a non-pointer.  */
+/* The term "match" here is rather loose.  The match is heuristic and
+   liberal.  */
 
-int
-user_select_syms (struct block_symbol *syms, int nsyms, int max_results)
+static int
+ada_type_match (struct type *ftype, struct type *atype, int may_deref)
 {
-  int i;
-  int *chosen = XALLOCAVEC (int , nsyms);
-  int n_chosen;
-  int first_choice = (max_results == 1) ? 1 : 2;
-  const char *select_mode = multiple_symbols_select_mode ();
-
-  if (max_results < 1)
-    error (_("Request to select 0 symbols!"));
-  if (nsyms <= 1)
-    return nsyms;
-
-  if (select_mode == multiple_symbols_cancel)
-    error (_("\
-canceled because the command is ambiguous\n\
-See set/show multiple-symbol."));
-
-  /* If select_mode is "all", then return all possible symbols.
-     Only do that if more than one symbol can be selected, of course.
-     Otherwise, display the menu as usual.  */
-  if (select_mode == multiple_symbols_all && max_results > 1)
-    return nsyms;
-
-  printf_filtered (_("[0] cancel\n"));
-  if (max_results > 1)
-    printf_filtered (_("[1] all\n"));
+  ftype = ada_check_typedef (ftype);
+  atype = ada_check_typedef (atype);
 
-  sort_choices (syms, nsyms);
+  if (ftype->code () == TYPE_CODE_REF)
+    ftype = TYPE_TARGET_TYPE (ftype);
+  if (atype->code () == TYPE_CODE_REF)
+    atype = TYPE_TARGET_TYPE (atype);
 
-  for (i = 0; i < nsyms; i += 1)
+  switch (ftype->code ())
     {
-      if (syms[i].symbol == NULL)
-        continue;
-
-      if (SYMBOL_CLASS (syms[i].symbol) == LOC_BLOCK)
-        {
-          struct symtab_and_line sal =
-            find_function_start_sal (syms[i].symbol, 1);
-
-         printf_filtered ("[%d] ", i + first_choice);
-         ada_print_symbol_signature (gdb_stdout, syms[i].symbol,
-                                     &type_print_raw_options);
-         if (sal.symtab == NULL)
-           printf_filtered (_(" at <no source file available>:%d\n"),
-                            sal.line);
-         else
-           printf_filtered (_(" at %s:%d\n"),
-                            symtab_to_filename_for_display (sal.symtab),
-                            sal.line);
-          continue;
-        }
+    default:
+      return ftype->code () == atype->code ();
+    case TYPE_CODE_PTR:
+      if (atype->code () == TYPE_CODE_PTR)
+        return ada_type_match (TYPE_TARGET_TYPE (ftype),
+                               TYPE_TARGET_TYPE (atype), 0);
       else
+        return (may_deref
+                && ada_type_match (TYPE_TARGET_TYPE (ftype), atype, 0));
+    case TYPE_CODE_INT:
+    case TYPE_CODE_ENUM:
+    case TYPE_CODE_RANGE:
+      switch (atype->code ())
         {
-          int is_enumeral =
-            (SYMBOL_CLASS (syms[i].symbol) == LOC_CONST
-             && SYMBOL_TYPE (syms[i].symbol) != NULL
-             && TYPE_CODE (SYMBOL_TYPE (syms[i].symbol)) == TYPE_CODE_ENUM);
-         struct symtab *symtab = NULL;
-
-         if (SYMBOL_OBJFILE_OWNED (syms[i].symbol))
-           symtab = symbol_symtab (syms[i].symbol);
-
-          if (SYMBOL_LINE (syms[i].symbol) != 0 && symtab != NULL)
-           {
-             printf_filtered ("[%d] ", i + first_choice);
-             ada_print_symbol_signature (gdb_stdout, syms[i].symbol,
-                                         &type_print_raw_options);
-             printf_filtered (_(" at %s:%d\n"),
-                              symtab_to_filename_for_display (symtab),
-                              SYMBOL_LINE (syms[i].symbol));
-           }
-          else if (is_enumeral
-                   && TYPE_NAME (SYMBOL_TYPE (syms[i].symbol)) != NULL)
-            {
-              printf_filtered (("[%d] "), i + first_choice);
-              ada_print_type (SYMBOL_TYPE (syms[i].symbol), NULL,
-                              gdb_stdout, -1, 0, &type_print_raw_options);
-              printf_filtered (_("'(%s) (enumeral)\n"),
-                              SYMBOL_PRINT_NAME (syms[i].symbol));
-            }
-         else
-           {
-             printf_filtered ("[%d] ", i + first_choice);
-             ada_print_symbol_signature (gdb_stdout, syms[i].symbol,
-                                         &type_print_raw_options);
-
-             if (symtab != NULL)
-               printf_filtered (is_enumeral
-                                ? _(" in %s (enumeral)\n")
-                                : _(" at %s:?\n"),
-                                symtab_to_filename_for_display (symtab));
-             else
-               printf_filtered (is_enumeral
-                                ? _(" (enumeral)\n")
-                                : _(" at ?\n"));
-           }
+        case TYPE_CODE_INT:
+        case TYPE_CODE_ENUM:
+        case TYPE_CODE_RANGE:
+          return 1;
+        default:
+          return 0;
         }
-    }
 
-  n_chosen = get_selections (chosen, nsyms, max_results, max_results > 1,
-                             "overload-choice");
+    case TYPE_CODE_ARRAY:
+      return (atype->code () == TYPE_CODE_ARRAY
+              || ada_is_array_descriptor_type (atype));
 
-  for (i = 0; i < n_chosen; i += 1)
-    syms[i] = syms[chosen[i]];
+    case TYPE_CODE_STRUCT:
+      if (ada_is_array_descriptor_type (ftype))
+        return (atype->code () == TYPE_CODE_ARRAY
+                || ada_is_array_descriptor_type (atype));
+      else
+        return (atype->code () == TYPE_CODE_STRUCT
+                && !ada_is_array_descriptor_type (atype));
 
-  return n_chosen;
+    case TYPE_CODE_UNION:
+    case TYPE_CODE_FLT:
+      return (atype->code () == ftype->code ());
+    }
 }
 
-/* Read and validate a set of numeric choices from the user in the
-   range 0 .. N_CHOICES-1.  Place the results in increasing
-   order in CHOICES[0 .. N-1], and return N.
+/* Return non-zero if the formals of FUNC "sufficiently match" the
+   vector of actual argument types ACTUALS of size N_ACTUALS.  FUNC
+   may also be an enumeral, in which case it is treated as a 0-
+   argument function.  */
 
-   The user types choices as a sequence of numbers on one line
-   separated by blanks, encoding them as follows:
+static int
+ada_args_match (struct symbol *func, struct value **actuals, int n_actuals)
+{
+  int i;
+  struct type *func_type = SYMBOL_TYPE (func);
 
-     + A choice of 0 means to cancel the selection, throwing an error.
-     + If IS_ALL_CHOICE, a choice of 1 selects the entire set 0 .. N_CHOICES-1.
-     + The user chooses k by typing k+IS_ALL_CHOICE+1.
+  if (SYMBOL_CLASS (func) == LOC_CONST
+      && func_type->code () == TYPE_CODE_ENUM)
+    return (n_actuals == 0);
+  else if (func_type == NULL || func_type->code () != TYPE_CODE_FUNC)
+    return 0;
 
-   The user is not allowed to choose more than MAX_RESULTS values.
+  if (func_type->num_fields () != n_actuals)
+    return 0;
 
-   ANNOTATION_SUFFIX, if present, is used to annotate the input
-   prompts (for use with the -f switch).  */
+  for (i = 0; i < n_actuals; i += 1)
+    {
+      if (actuals[i] == NULL)
+        return 0;
+      else
+        {
+          struct type *ftype = ada_check_typedef (func_type->field (i).type ());
+          struct type *atype = ada_check_typedef (value_type (actuals[i]));
 
-int
-get_selections (int *choices, int n_choices, int max_results,
-                int is_all_choice, const char *annotation_suffix)
-{
-  char *args;
-  const char *prompt;
-  int n_chosen;
-  int first_choice = is_all_choice ? 2 : 1;
+          if (!ada_type_match (ftype, atype, 1))
+            return 0;
+        }
+    }
+  return 1;
+}
 
-  prompt = getenv ("PS2");
-  if (prompt == NULL)
-    prompt = "> ";
+/* False iff function type FUNC_TYPE definitely does not produce a value
+   compatible with type CONTEXT_TYPE.  Conservatively returns 1 if
+   FUNC_TYPE is not a valid function type with a non-null return type
+   or an enumerated type.  A null CONTEXT_TYPE indicates any non-void type.  */
 
-  args = command_line_input (prompt, annotation_suffix);
+static int
+return_match (struct type *func_type, struct type *context_type)
+{
+  struct type *return_type;
 
-  if (args == NULL)
-    error_no_arg (_("one or more choice numbers"));
+  if (func_type == NULL)
+    return 1;
 
-  n_chosen = 0;
+  if (func_type->code () == TYPE_CODE_FUNC)
+    return_type = get_base_type (TYPE_TARGET_TYPE (func_type));
+  else
+    return_type = get_base_type (func_type);
+  if (return_type == NULL)
+    return 1;
 
-  /* Set choices[0 .. n_chosen-1] to the users' choices in ascending
-     order, as given in args.  Choices are validated.  */
-  while (1)
-    {
-      char *args2;
-      int choice, j;
+  context_type = get_base_type (context_type);
 
-      args = skip_spaces (args);
-      if (*args == '\0' && n_chosen == 0)
-        error_no_arg (_("one or more choice numbers"));
-      else if (*args == '\0')
-        break;
+  if (return_type->code () == TYPE_CODE_ENUM)
+    return context_type == NULL || return_type == context_type;
+  else if (context_type == NULL)
+    return return_type->code () != TYPE_CODE_VOID;
+  else
+    return return_type->code () == context_type->code ();
+}
 
-      choice = strtol (args, &args2, 10);
-      if (args == args2 || choice < 0
-          || choice > n_choices + first_choice - 1)
-        error (_("Argument must be choice number"));
-      args = args2;
 
-      if (choice == 0)
-        error (_("cancelled"));
+/* Returns the index in SYMS[0..NSYMS-1] that contains  the symbol for the
+   function (if any) that matches the types of the NARGS arguments in
+   ARGS.  If CONTEXT_TYPE is non-null and there is at least one match
+   that returns that type, then eliminate matches that don't.  If
+   CONTEXT_TYPE is void and there is at least one match that does not
+   return void, eliminate all matches that do.
 
-      if (choice < first_choice)
-        {
-          n_chosen = n_choices;
-          for (j = 0; j < n_choices; j += 1)
-            choices[j] = j;
-          break;
-        }
-      choice -= first_choice;
+   Asks the user if there is more than one match remaining.  Returns -1
+   if there is no such symbol or none is selected.  NAME is used
+   solely for messages.  May re-arrange and modify SYMS in
+   the process; the index returned is for the modified vector.  */
 
-      for (j = n_chosen - 1; j >= 0 && choice < choices[j]; j -= 1)
-        {
-        }
+static int
+ada_resolve_function (struct block_symbol syms[],
+                      int nsyms, struct value **args, int nargs,
+                      const char *name, struct type *context_type,
+                     int parse_completion)
+{
+  int fallback;
+  int k;
+  int m;                        /* Number of hits */
 
-      if (j < 0 || choice != choices[j])
+  m = 0;
+  /* In the first pass of the loop, we only accept functions matching
+     context_type.  If none are found, we add a second pass of the loop
+     where every function is accepted.  */
+  for (fallback = 0; m == 0 && fallback < 2; fallback++)
+    {
+      for (k = 0; k < nsyms; k += 1)
         {
-          int k;
+          struct type *type = ada_check_typedef (SYMBOL_TYPE (syms[k].symbol));
 
-          for (k = n_chosen - 1; k > j; k -= 1)
-            choices[k + 1] = choices[k];
-          choices[j + 1] = choice;
-          n_chosen += 1;
+          if (ada_args_match (syms[k].symbol, args, nargs)
+              && (fallback || return_match (type, context_type)))
+            {
+              syms[m] = syms[k];
+              m += 1;
+            }
         }
     }
 
-  if (n_chosen > max_results)
-    error (_("Select no more than %d of the above"), max_results);
-
-  return n_chosen;
+  /* If we got multiple matches, ask the user which one to use.  Don't do this
+     interactive thing during completion, though, as the purpose of the
+     completion is providing a list of all possible matches.  Prompting the
+     user to filter it down would be completely unexpected in this case.  */
+  if (m == 0)
+    return -1;
+  else if (m > 1 && !parse_completion)
+    {
+      printf_filtered (_("Multiple matches for %s\n"), name);
+      user_select_syms (syms, m, 1);
+      return 0;
+    }
+  return 0;
 }
 
 /* Replace the operator of length OPLEN at position PC in *EXPP with a call
@@ -4088,7 +3950,7 @@ numeric_type_p (struct type *type)
     return 0;
   else
     {
-      switch (TYPE_CODE (type))
+      switch (type->code ())
         {
         case TYPE_CODE_INT:
         case TYPE_CODE_FLT:
@@ -4111,7 +3973,7 @@ integer_type_p (struct type *type)
     return 0;
   else
     {
-      switch (TYPE_CODE (type))
+      switch (type->code ())
         {
         case TYPE_CODE_INT:
           return 1;
@@ -4133,7 +3995,7 @@ scalar_type_p (struct type *type)
     return 0;
   else
     {
-      switch (TYPE_CODE (type))
+      switch (type->code ())
         {
         case TYPE_CODE_INT:
         case TYPE_CODE_RANGE:
@@ -4155,7 +4017,7 @@ discrete_type_p (struct type *type)
     return 0;
   else
     {
-      switch (TYPE_CODE (type))
+      switch (type->code ())
         {
         case TYPE_CODE_INT:
         case TYPE_CODE_RANGE:
@@ -4276,7 +4138,7 @@ ada_parse_renaming (struct symbol *sym,
     case LOC_STATIC:
     case LOC_COMPUTED:
     case LOC_OPTIMIZED_OUT:
-      info = strstr (SYMBOL_LINKAGE_NAME (sym), "___XR");
+      info = strstr (sym->linkage_name (), "___XR");
       if (info == NULL)
        return ADA_NOT_RENAMING;
       switch (info[5])
@@ -4325,7 +4187,7 @@ ada_read_renaming_var_value (struct symbol *renaming_sym,
 {
   const char *sym_name;
 
-  sym_name = SYMBOL_LINKAGE_NAME (renaming_sym);
+  sym_name = renaming_sym->linkage_name ();
   expression_up expr = parse_exp_1 (&sym_name, 0, block, 0);
   return evaluate_expression (expr.get ());
 }
@@ -4352,7 +4214,132 @@ ensure_lval (struct value *val)
       write_memory (addr, value_contents (val), len);
     }
 
-  return val;
+  return val;
+}
+
+/* Given ARG, a value of type (pointer or reference to a)*
+   structure/union, extract the component named NAME from the ultimate
+   target structure/union and return it as a value with its
+   appropriate type.
+
+   The routine searches for NAME among all members of the structure itself
+   and (recursively) among all members of any wrapper members
+   (e.g., '_parent').
+
+   If NO_ERR, then simply return NULL in case of error, rather than
+   calling error.  */
+
+static struct value *
+ada_value_struct_elt (struct value *arg, const char *name, int no_err)
+{
+  struct type *t, *t1;
+  struct value *v;
+  int check_tag;
+
+  v = NULL;
+  t1 = t = ada_check_typedef (value_type (arg));
+  if (t->code () == TYPE_CODE_REF)
+    {
+      t1 = TYPE_TARGET_TYPE (t);
+      if (t1 == NULL)
+       goto BadValue;
+      t1 = ada_check_typedef (t1);
+      if (t1->code () == TYPE_CODE_PTR)
+        {
+          arg = coerce_ref (arg);
+          t = t1;
+        }
+    }
+
+  while (t->code () == TYPE_CODE_PTR)
+    {
+      t1 = TYPE_TARGET_TYPE (t);
+      if (t1 == NULL)
+       goto BadValue;
+      t1 = ada_check_typedef (t1);
+      if (t1->code () == TYPE_CODE_PTR)
+        {
+          arg = value_ind (arg);
+          t = t1;
+        }
+      else
+        break;
+    }
+
+  if (t1->code () != TYPE_CODE_STRUCT && t1->code () != TYPE_CODE_UNION)
+    goto BadValue;
+
+  if (t1 == t)
+    v = ada_search_struct_field (name, arg, 0, t);
+  else
+    {
+      int bit_offset, bit_size, byte_offset;
+      struct type *field_type;
+      CORE_ADDR address;
+
+      if (t->code () == TYPE_CODE_PTR)
+       address = value_address (ada_value_ind (arg));
+      else
+       address = value_address (ada_coerce_ref (arg));
+
+      /* Check to see if this is a tagged type.  We also need to handle
+         the case where the type is a reference to a tagged type, but
+         we have to be careful to exclude pointers to tagged types.
+         The latter should be shown as usual (as a pointer), whereas
+         a reference should mostly be transparent to the user.  */
+
+      if (ada_is_tagged_type (t1, 0)
+          || (t1->code () == TYPE_CODE_REF
+              && ada_is_tagged_type (TYPE_TARGET_TYPE (t1), 0)))
+        {
+          /* We first try to find the searched field in the current type.
+            If not found then let's look in the fixed type.  */
+
+          if (!find_struct_field (name, t1, 0,
+                                  &field_type, &byte_offset, &bit_offset,
+                                  &bit_size, NULL))
+           check_tag = 1;
+         else
+           check_tag = 0;
+        }
+      else
+       check_tag = 0;
+
+      /* Convert to fixed type in all cases, so that we have proper
+        offsets to each field in unconstrained record types.  */
+      t1 = ada_to_fixed_type (ada_get_base_type (t1), NULL,
+                             address, NULL, check_tag);
+
+      if (find_struct_field (name, t1, 0,
+                             &field_type, &byte_offset, &bit_offset,
+                             &bit_size, NULL))
+        {
+          if (bit_size != 0)
+            {
+              if (t->code () == TYPE_CODE_REF)
+                arg = ada_coerce_ref (arg);
+              else
+                arg = ada_value_ind (arg);
+              v = ada_value_primitive_packed_val (arg, NULL, byte_offset,
+                                                  bit_offset, bit_size,
+                                                  field_type);
+            }
+          else
+            v = value_at_lazy (field_type, address + byte_offset);
+        }
+    }
+
+  if (v != NULL || no_err)
+    return v;
+  else
+    error (_("There is no member named %s."), name);
+
+ BadValue:
+  if (no_err)
+    return NULL;
+  else
+    error (_("Attempt to extract a component of "
+            "a value that is not a record."));
 }
 
 /* Return the value ACTUAL, converted to be an appropriate value for a
@@ -4366,24 +4353,24 @@ ada_convert_actual (struct value *actual, struct type *formal_type0)
   struct type *actual_type = ada_check_typedef (value_type (actual));
   struct type *formal_type = ada_check_typedef (formal_type0);
   struct type *formal_target =
-    TYPE_CODE (formal_type) == TYPE_CODE_PTR
+    formal_type->code () == TYPE_CODE_PTR
     ? ada_check_typedef (TYPE_TARGET_TYPE (formal_type)) : formal_type;
   struct type *actual_target =
-    TYPE_CODE (actual_type) == TYPE_CODE_PTR
+    actual_type->code () == TYPE_CODE_PTR
     ? ada_check_typedef (TYPE_TARGET_TYPE (actual_type)) : actual_type;
 
   if (ada_is_array_descriptor_type (formal_target)
-      && TYPE_CODE (actual_target) == TYPE_CODE_ARRAY)
+      && actual_target->code () == TYPE_CODE_ARRAY)
     return make_array_descriptor (formal_type, actual);
-  else if (TYPE_CODE (formal_type) == TYPE_CODE_PTR
-          || TYPE_CODE (formal_type) == TYPE_CODE_REF)
+  else if (formal_type->code () == TYPE_CODE_PTR
+          || formal_type->code () == TYPE_CODE_REF)
     {
       struct value *result;
 
-      if (TYPE_CODE (formal_target) == TYPE_CODE_ARRAY
+      if (formal_target->code () == TYPE_CODE_ARRAY
           && ada_is_array_descriptor_type (actual_target))
        result = desc_data (actual);
-      else if (TYPE_CODE (formal_type) != TYPE_CODE_PTR)
+      else if (formal_type->code () != TYPE_CODE_PTR)
         {
           if (VALUE_LVAL (actual) != lval_memory)
             {
@@ -4402,7 +4389,7 @@ ada_convert_actual (struct value *actual, struct type *formal_type0)
        return actual;
       return value_cast_pointers (formal_type, result, 0);
     }
-  else if (TYPE_CODE (actual_type) == TYPE_CODE_PTR)
+  else if (actual_type->code () == TYPE_CODE_PTR)
     return ada_value_ind (actual);
   else if (ada_is_aligner_type (formal_type))
     {
@@ -4433,7 +4420,7 @@ value_pointer (struct value *value, struct type *type)
 
   addr = value_address (value);
   gdbarch_address_to_pointer (gdbarch, type, buf, addr);
-  addr = extract_unsigned_integer (buf, len, gdbarch_byte_order (gdbarch));
+  addr = extract_unsigned_integer (buf, len, type_byte_order (type));
   return addr;
 }
 
@@ -4471,20 +4458,20 @@ make_array_descriptor (struct type *type, struct value *arr)
   modify_field (value_type (descriptor),
                value_contents_writeable (descriptor),
                value_pointer (ensure_lval (arr),
-                              TYPE_FIELD_TYPE (desc_type, 0)),
+                              desc_type->field (0).type ()),
                fat_pntr_data_bitpos (desc_type),
                fat_pntr_data_bitsize (desc_type));
 
   modify_field (value_type (descriptor),
                value_contents_writeable (descriptor),
                value_pointer (bounds,
-                              TYPE_FIELD_TYPE (desc_type, 1)),
+                              desc_type->field (1).type ()),
                fat_pntr_bounds_bitpos (desc_type),
                fat_pntr_bounds_bitsize (desc_type));
 
   descriptor = ensure_lval (descriptor);
 
-  if (TYPE_CODE (type) == TYPE_CODE_PTR)
+  if (type->code () == TYPE_CODE_PTR)
     return value_addr (descriptor);
   else
     return descriptor;
@@ -4599,7 +4586,6 @@ cache_symbol (const char *name, domain_enum domain, struct symbol *sym,
   struct ada_symbol_cache *sym_cache
     = ada_get_symbol_cache (current_program_space);
   int h;
-  char *copy;
   struct cache_entry *e;
 
   /* Symbols for builtin types don't have a block.
@@ -4622,9 +4608,7 @@ cache_symbol (const char *name, domain_enum domain, struct symbol *sym,
   e = XOBNEW (&sym_cache->cache_space, cache_entry);
   e->next = sym_cache->root[h];
   sym_cache->root[h] = e;
-  e->name = copy
-    = (char *) obstack_alloc (&sym_cache->cache_space, strlen (name) + 1);
-  strcpy (copy, name);
+  e->name = obstack_strdup (&sym_cache->cache_space, name);
   e->sym = sym;
   e->domain = domain;
   e->block = block;
@@ -4673,8 +4657,8 @@ is_nonfunction (struct block_symbol syms[], int n)
   int i;
 
   for (i = 0; i < n; i += 1)
-    if (TYPE_CODE (SYMBOL_TYPE (syms[i].symbol)) != TYPE_CODE_FUNC
-        && (TYPE_CODE (SYMBOL_TYPE (syms[i].symbol)) != TYPE_CODE_ENUM
+    if (SYMBOL_TYPE (syms[i].symbol)->code () != TYPE_CODE_FUNC
+        && (SYMBOL_TYPE (syms[i].symbol)->code () != TYPE_CODE_ENUM
             || SYMBOL_CLASS (syms[i].symbol) != LOC_CONST))
       return 1;
 
@@ -4690,10 +4674,10 @@ equiv_types (struct type *type0, struct type *type1)
   if (type0 == type1)
     return 1;
   if (type0 == NULL || type1 == NULL
-      || TYPE_CODE (type0) != TYPE_CODE (type1))
+      || type0->code () != type1->code ())
     return 0;
-  if ((TYPE_CODE (type0) == TYPE_CODE_STRUCT
-       || TYPE_CODE (type0) == TYPE_CODE_ENUM)
+  if ((type0->code () == TYPE_CODE_STRUCT
+       || type0->code () == TYPE_CODE_ENUM)
       && ada_type_name (type0) != NULL && ada_type_name (type1) != NULL
       && strcmp (ada_type_name (type0), ada_type_name (type1)) == 0)
     return 1;
@@ -4721,12 +4705,12 @@ lesseq_defined_than (struct symbol *sym0, struct symbol *sym1)
       {
         struct type *type0 = SYMBOL_TYPE (sym0);
         struct type *type1 = SYMBOL_TYPE (sym1);
-        const char *name0 = SYMBOL_LINKAGE_NAME (sym0);
-        const char *name1 = SYMBOL_LINKAGE_NAME (sym1);
+        const char *name0 = sym0->linkage_name ();
+        const char *name1 = sym1->linkage_name ();
         int len0 = strlen (name0);
 
         return
-          TYPE_CODE (type0) == TYPE_CODE (type1)
+          type0->code () == type1->code ()
           && (equiv_types (type0, type1)
               || (len0 < strlen (name1) && strncmp (name0, name1, len0) == 0
                   && startswith (name1 + len0, "___XV")));
@@ -4734,6 +4718,15 @@ lesseq_defined_than (struct symbol *sym0, struct symbol *sym1)
     case LOC_CONST:
       return SYMBOL_VALUE (sym0) == SYMBOL_VALUE (sym1)
         && equiv_types (SYMBOL_TYPE (sym0), SYMBOL_TYPE (sym1));
+
+    case LOC_STATIC:
+      {
+        const char *name0 = sym0->linkage_name ();
+        const char *name1 = sym1->linkage_name ();
+        return (strcmp (name0, name1) == 0
+                && SYMBOL_VALUE_ADDRESS (sym0) == SYMBOL_VALUE_ADDRESS (sym1));
+      }
+
     default:
       return 0;
     }
@@ -4824,7 +4817,7 @@ ada_lookup_simple_minsym (const char *name)
     {
       for (minimal_symbol *msymbol : objfile->msymbols ())
        {
-         if (match_name (MSYMBOL_LINKAGE_NAME (msymbol), lookup_name, NULL)
+         if (match_name (msymbol->linkage_name (), lookup_name, NULL)
              && MSYMBOL_TYPE (msymbol) != mst_solib_trampoline)
            {
              result.minsym = msymbol;
@@ -4837,36 +4830,6 @@ ada_lookup_simple_minsym (const char *name)
   return result;
 }
 
-/* Return all the bound minimal symbols matching NAME according to Ada
-   decoding rules.  Returns an empty vector if there is no such
-   minimal symbol.  Names prefixed with "standard__" are handled
-   specially: "standard__" is first stripped off, and only static and
-   global symbols are searched.  */
-
-static std::vector<struct bound_minimal_symbol>
-ada_lookup_simple_minsyms (const char *name)
-{
-  std::vector<struct bound_minimal_symbol> result;
-
-  symbol_name_match_type match_type = name_match_type_from_name (name);
-  lookup_name_info lookup_name (name, match_type);
-
-  symbol_name_matcher_ftype *match_name
-    = ada_get_symbol_name_matcher (lookup_name);
-
-  for (objfile *objfile : current_program_space->objfiles ())
-    {
-      for (minimal_symbol *msymbol : objfile->msymbols ())
-       {
-         if (match_name (MSYMBOL_LINKAGE_NAME (msymbol), lookup_name, NULL)
-             && MSYMBOL_TYPE (msymbol) != mst_solib_trampoline)
-           result.push_back ({msymbol, objfile});
-       }
-    }
-
-  return result;
-}
-
 /* For all subprograms that statically enclose the subprogram of the
    selected frame, add symbols matching identifier NAME in DOMAIN
    and their blocks to the list of data in OBSTACKP, as for
@@ -4896,7 +4859,7 @@ is_nondebugging_type (struct type *type)
 
    This function assumes that TYPE1 and TYPE2 are both TYPE_CODE_ENUM
    types and that their number of enumerals is identical (in other
-   words, TYPE_NFIELDS (type1) == TYPE_NFIELDS (type2)).  */
+   words, type1->num_fields () == type2->num_fields ()).  */
 
 static int
 ada_identical_enum_types_p (struct type *type1, struct type *type2)
@@ -4909,13 +4872,13 @@ ada_identical_enum_types_p (struct type *type1, struct type *type2)
      underlying value and name.  */
 
   /* All enums in the type should have an identical underlying value.  */
-  for (i = 0; i < TYPE_NFIELDS (type1); i++)
+  for (i = 0; i < type1->num_fields (); i++)
     if (TYPE_FIELD_ENUMVAL (type1, i) != TYPE_FIELD_ENUMVAL (type2, i))
       return 0;
 
   /* All enumerals should also have the same name (modulo any numerical
      suffix).  */
-  for (i = 0; i < TYPE_NFIELDS (type1); i++)
+  for (i = 0; i < type1->num_fields (); i++)
     {
       const char *name_1 = TYPE_FIELD_NAME (type1, i);
       const char *name_2 = TYPE_FIELD_NAME (type2, i);
@@ -4968,7 +4931,7 @@ symbols_are_identical_enums (const std::vector<struct block_symbol> &syms)
 
   /* Quick check: All symbols should have an enum type.  */
   for (i = 0; i < syms.size (); i++)
-    if (TYPE_CODE (SYMBOL_TYPE (syms[i].symbol)) != TYPE_CODE_ENUM)
+    if (SYMBOL_TYPE (syms[i].symbol)->code () != TYPE_CODE_ENUM)
       return 0;
 
   /* Quick check: They should all have the same value.  */
@@ -4978,8 +4941,8 @@ symbols_are_identical_enums (const std::vector<struct block_symbol> &syms)
 
   /* Quick check: They should all have the same number of enumerals.  */
   for (i = 1; i < syms.size (); i++)
-    if (TYPE_NFIELDS (SYMBOL_TYPE (syms[i].symbol))
-        != TYPE_NFIELDS (SYMBOL_TYPE (syms[0].symbol)))
+    if (SYMBOL_TYPE (syms[i].symbol)->num_fields ()
+        != SYMBOL_TYPE (syms[0].symbol)->num_fields ())
       return 0;
 
   /* All the sanity checks passed, so we might have a set of
@@ -5020,15 +4983,15 @@ remove_extra_symbols (std::vector<struct block_symbol> *syms)
          the get rid of the stub.  */
 
       if (TYPE_STUB (SYMBOL_TYPE ((*syms)[i].symbol))
-          && SYMBOL_LINKAGE_NAME ((*syms)[i].symbol) != NULL)
+          && (*syms)[i].symbol->linkage_name () != NULL)
         {
           for (j = 0; j < syms->size (); j++)
             {
               if (j != i
                   && !TYPE_STUB (SYMBOL_TYPE ((*syms)[j].symbol))
-                  && SYMBOL_LINKAGE_NAME ((*syms)[j].symbol) != NULL
-                  && strcmp (SYMBOL_LINKAGE_NAME ((*syms)[i].symbol),
-                             SYMBOL_LINKAGE_NAME ((*syms)[j].symbol)) == 0)
+                  && (*syms)[j].symbol->linkage_name () != NULL
+                  && strcmp ((*syms)[i].symbol->linkage_name (),
+                             (*syms)[j].symbol->linkage_name ()) == 0)
                 remove_p = 1;
             }
         }
@@ -5036,16 +4999,16 @@ remove_extra_symbols (std::vector<struct block_symbol> *syms)
       /* Two symbols with the same name, same class and same address
          should be identical.  */
 
-      else if (SYMBOL_LINKAGE_NAME ((*syms)[i].symbol) != NULL
+      else if ((*syms)[i].symbol->linkage_name () != NULL
           && SYMBOL_CLASS ((*syms)[i].symbol) == LOC_STATIC
           && is_nondebugging_type (SYMBOL_TYPE ((*syms)[i].symbol)))
         {
           for (j = 0; j < syms->size (); j += 1)
             {
               if (i != j
-                  && SYMBOL_LINKAGE_NAME ((*syms)[j].symbol) != NULL
-                  && strcmp (SYMBOL_LINKAGE_NAME ((*syms)[i].symbol),
-                             SYMBOL_LINKAGE_NAME ((*syms)[j].symbol)) == 0
+                  && (*syms)[j].symbol->linkage_name () != NULL
+                  && strcmp ((*syms)[i].symbol->linkage_name (),
+                             (*syms)[j].symbol->linkage_name ()) == 0
                   && SYMBOL_CLASS ((*syms)[i].symbol)
                       == SYMBOL_CLASS ((*syms)[j].symbol)
                   && SYMBOL_VALUE_ADDRESS ((*syms)[i].symbol)
@@ -5091,7 +5054,7 @@ xget_renaming_scope (struct type *renaming_type)
      So, to extract the scope, we search for the "___XR" extension,
      and then backtrack until we find the first "__".  */
 
-  const char *name = TYPE_NAME (renaming_type);
+  const char *name = renaming_type->name ();
   const char *suffix = strstr (name, "___XR");
   const char *last;
 
@@ -5222,7 +5185,7 @@ remove_irrelevant_renamings (std::vector<struct block_symbol> *syms,
 
       if (sym == NULL || SYMBOL_CLASS (sym) == LOC_TYPEDEF)
        continue;
-      name = SYMBOL_LINKAGE_NAME (sym);
+      name = sym->linkage_name ();
       suffix = strstr (name, "___XR");
 
       if (suffix != NULL)
@@ -5233,7 +5196,7 @@ remove_irrelevant_renamings (std::vector<struct block_symbol> *syms,
          is_new_style_renaming = 1;
          for (j = 0; j < syms->size (); j += 1)
            if (i != j && (*syms)[j].symbol != NULL
-               && strncmp (name, SYMBOL_LINKAGE_NAME ((*syms)[j].symbol),
+               && strncmp (name, (*syms)[j].symbol->linkage_name (),
                            name_len) == 0
                && block == (*syms)[j].block)
              (*syms)[j].symbol = NULL;
@@ -5262,7 +5225,7 @@ remove_irrelevant_renamings (std::vector<struct block_symbol> *syms,
   if (current_function == NULL)
     return syms->size ();
 
-  current_function_name = SYMBOL_LINKAGE_NAME (current_function);
+  current_function_name = current_function->linkage_name ();
   if (current_function_name == NULL)
     return syms->size ();
 
@@ -5332,8 +5295,8 @@ struct match_data
   int found_sym;
 };
 
-/* A callback for add_nonlocal_symbols that adds SYM, found in BLOCK,
-   to a list of symbols.  DATA0 is a pointer to a struct match_data *
+/* A callback for add_nonlocal_symbols that adds symbol, found in BSYM,
+   to a list of symbols.  DATA is a pointer to a struct match_data *
    containing the obstack that collects the symbol list, the file that SYM
    must come from, a flag indicating whether a non-argument symbol has
    been found in the current block, and the last argument symbol
@@ -5341,12 +5304,13 @@ struct match_data
    marking the end of a block, the argument symbol is added if no
    other has been found.  */
 
-static int
-aux_add_nonlocal_symbols (const struct block *block, struct symbol *sym,
-                         void *data0)
+static bool
+aux_add_nonlocal_symbols (struct block_symbol *bsym,
+                         struct match_data *data)
 {
-  struct match_data *data = (struct match_data *) data0;
-  
+  const struct block *block = bsym->block;
+  struct symbol *sym = bsym->symbol;
+
   if (sym == NULL)
     {
       if (!data->found_sym && data->arg_sym != NULL) 
@@ -5359,7 +5323,7 @@ aux_add_nonlocal_symbols (const struct block *block, struct symbol *sym,
   else 
     {
       if (SYMBOL_CLASS (sym) == LOC_UNRESOLVED)
-       return 0;
+       return true;
       else if (SYMBOL_IS_ARGUMENT (sym))
        data->arg_sym = sym;
       else
@@ -5370,7 +5334,7 @@ aux_add_nonlocal_symbols (const struct block *block, struct symbol *sym,
                           block);
        }
     }
-  return 0;
+  return true;
 }
 
 /* Helper for add_nonlocal_symbols.  Find symbols in DOMAIN which are
@@ -5541,22 +5505,19 @@ add_nonlocal_symbols (struct obstack *obstackp,
 
   bool is_wild_match = lookup_name.ada ().wild_match_p ();
 
+  auto callback = [&] (struct block_symbol *bsym)
+    {
+      return aux_add_nonlocal_symbols (bsym, &data);
+    };
+
   for (objfile *objfile : current_program_space->objfiles ())
     {
       data.objfile = objfile;
 
-      if (is_wild_match)
-       objfile->sf->qf->map_matching_symbols (objfile, lookup_name.name ().c_str (),
-                                              domain, global,
-                                              aux_add_nonlocal_symbols, &data,
-                                              symbol_name_match_type::WILD,
-                                              NULL);
-      else
-       objfile->sf->qf->map_matching_symbols (objfile, lookup_name.name ().c_str (),
-                                              domain, global,
-                                              aux_add_nonlocal_symbols, &data,
-                                              symbol_name_match_type::FULL,
-                                              compare_names);
+      objfile->sf->qf->map_matching_symbols (objfile, lookup_name,
+                                            domain, global, callback,
+                                            (is_wild_match
+                                             ? NULL : compare_names));
 
       for (compunit_symtab *cu : objfile->compunits ())
        {
@@ -5572,16 +5533,14 @@ add_nonlocal_symbols (struct obstack *obstackp,
   if (num_defns_collected (obstackp) == 0 && global && !is_wild_match)
     {
       const char *name = ada_lookup_name (lookup_name);
-      std::string name1 = std::string ("<_ada_") + name + '>';
+      std::string bracket_name = std::string ("<_ada_") + name + '>';
+      lookup_name_info name1 (bracket_name, symbol_name_match_type::FULL);
 
       for (objfile *objfile : current_program_space->objfiles ())
         {
          data.objfile = objfile;
-         objfile->sf->qf->map_matching_symbols (objfile, name1.c_str (),
-                                                domain, global,
-                                                aux_add_nonlocal_symbols,
-                                                &data,
-                                                symbol_name_match_type::FULL,
+         objfile->sf->qf->map_matching_symbols (objfile, name1,
+                                                domain, global, callback,
                                                 compare_names);
        }
     }          
@@ -5636,7 +5595,7 @@ ada_add_all_symbols (struct obstack *obstackp,
       else
        {
          /* In the !full_search case we're are being called by
-            ada_iterate_over_symbols, and we don't want to search
+            iterate_over_symbols, and we don't want to search
             superblocks.  */
          ada_add_block_symbols (obstackp, block, lookup_name, domain, NULL);
        }
@@ -5737,26 +5696,6 @@ ada_lookup_symbol_list (const char *name, const struct block *block,
   return ada_lookup_symbol_list_worker (lookup_name, block, domain, results, 1);
 }
 
-/* Implementation of the la_iterate_over_symbols method.  */
-
-static void
-ada_iterate_over_symbols
-  (const struct block *block, const lookup_name_info &name,
-   domain_enum domain,
-   gdb::function_view<symbol_found_callback_ftype> callback)
-{
-  int ndefs, i;
-  std::vector<struct block_symbol> results;
-
-  ndefs = ada_lookup_symbol_list_worker (name, block, domain, &results, 0);
-
-  for (i = 0; i < ndefs; ++i)
-    {
-      if (!callback (&results[i]))
-       break;
-    }
-}
-
 /* The result is as for ada_lookup_symbol_list with FULL_SEARCH set
    to 1, but choosing the first symbol found if there are multiple
    choices.
@@ -5803,46 +5742,6 @@ ada_lookup_symbol (const char *name, const struct block *block0,
   return info;
 }
 
-static struct block_symbol
-ada_lookup_symbol_nonlocal (const struct language_defn *langdef,
-                           const char *name,
-                            const struct block *block,
-                            const domain_enum domain)
-{
-  struct block_symbol sym;
-
-  sym = ada_lookup_symbol (name, block_static_block (block), domain);
-  if (sym.symbol != NULL)
-    return sym;
-
-  /* If we haven't found a match at this point, try the primitive
-     types.  In other languages, this search is performed before
-     searching for global symbols in order to short-circuit that
-     global-symbol search if it happens that the name corresponds
-     to a primitive type.  But we cannot do the same in Ada, because
-     it is perfectly legitimate for a program to declare a type which
-     has the same name as a standard type.  If looking up a type in
-     that situation, we have traditionally ignored the primitive type
-     in favor of user-defined types.  This is why, unlike most other
-     languages, we search the primitive types this late and only after
-     having searched the global symbols without success.  */
-
-  if (domain == VAR_DOMAIN)
-    {
-      struct gdbarch *gdbarch;
-
-      if (block == NULL)
-       gdbarch = target_gdbarch ();
-      else
-       gdbarch = block_gdbarch (block);
-      sym.symbol = language_lookup_primitive_type_as_symbol (langdef, gdbarch, name);
-      if (sym.symbol != NULL)
-       return sym;
-    }
-
-  return {};
-}
-
 
 /* True iff STR is a possible encoded suffix of a normal Ada name
    that is to be ignored for matching purposes.  Suffixes of parallel
@@ -5996,7 +5895,7 @@ is_name_suffix (const char *str)
 static int
 is_valid_name_for_wild_match (const char *name0)
 {
-  const char *decoded_name = ada_decode (name0);
+  std::string decoded_name = ada_decode (name0);
   int i;
 
   /* If the decoded name starts with an angle bracket, it means that
@@ -6132,8 +6031,7 @@ ada_add_block_symbols (struct obstack *obstackp,
        sym != NULL;
        sym = block_iter_match_next (lookup_name, &iter))
     {
-      if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
-                                SYMBOL_DOMAIN (sym), domain))
+      if (symbol_matches_domain (sym->language (), SYMBOL_DOMAIN (sym), domain))
        {
          if (SYMBOL_CLASS (sym) != LOC_UNRESOLVED)
            {
@@ -6172,22 +6070,22 @@ ada_add_block_symbols (struct obstack *obstackp,
 
       ALL_BLOCK_SYMBOLS (block, iter, sym)
       {
-        if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
+        if (symbol_matches_domain (sym->language (),
                                    SYMBOL_DOMAIN (sym), domain))
           {
             int cmp;
 
-            cmp = (int) '_' - (int) SYMBOL_LINKAGE_NAME (sym)[0];
+            cmp = (int) '_' - (int) sym->linkage_name ()[0];
             if (cmp == 0)
               {
-                cmp = !startswith (SYMBOL_LINKAGE_NAME (sym), "_ada_");
+                cmp = !startswith (sym->linkage_name (), "_ada_");
                 if (cmp == 0)
-                  cmp = strncmp (name, SYMBOL_LINKAGE_NAME (sym) + 5,
+                  cmp = strncmp (name, sym->linkage_name () + 5,
                                  name_len);
               }
 
             if (cmp == 0
-                && is_name_suffix (SYMBOL_LINKAGE_NAME (sym) + name_len + 5))
+                && is_name_suffix (sym->linkage_name () + name_len + 5))
               {
                if (SYMBOL_CLASS (sym) != LOC_UNRESOLVED)
                  {
@@ -6236,19 +6134,16 @@ ada_lookup_name_info::matches
   if (strncmp (sym_name, text, text_len) == 0)
     match = true;
 
+  std::string decoded_name = ada_decode (sym_name);
   if (match && !m_encoded_p)
     {
       /* One needed check before declaring a positive match is to verify
          that iff we are doing a verbatim match, the decoded version
          of the symbol name starts with '<'.  Otherwise, this symbol name
          is not a suitable completion.  */
-      const char *sym_name_copy = sym_name;
-      bool has_angle_bracket;
 
-      sym_name = ada_decode (sym_name);
-      has_angle_bracket = (sym_name[0] == '<');
+      bool has_angle_bracket = (decoded_name[0] == '<');
       match = (has_angle_bracket == m_verbatim_p);
-      sym_name = sym_name_copy;
     }
 
   if (match && !m_verbatim_p)
@@ -6272,7 +6167,7 @@ ada_lookup_name_info::matches
       /* Since we are doing wild matching, this means that TEXT
          may represent an unqualified symbol name.  We therefore must
          also compare TEXT against the unqualified name of the symbol.  */
-      sym_name = ada_unqualified_name (ada_decode (sym_name));
+      sym_name = ada_unqualified_name (decoded_name.c_str ());
 
       if (strncmp (sym_name, text, text_len) == 0)
        match = true;
@@ -6304,134 +6199,6 @@ ada_lookup_name_info::matches
   return true;
 }
 
-/* Add the list of possible symbol names completing TEXT to TRACKER.
-   WORD is the entire command on which completion is made.  */
-
-static void
-ada_collect_symbol_completion_matches (completion_tracker &tracker,
-                                      complete_symbol_mode mode,
-                                      symbol_name_match_type name_match_type,
-                                      const char *text, const char *word,
-                                      enum type_code code)
-{
-  struct symbol *sym;
-  const struct block *b, *surrounding_static_block = 0;
-  struct block_iterator iter;
-
-  gdb_assert (code == TYPE_CODE_UNDEF);
-
-  lookup_name_info lookup_name (text, name_match_type, true);
-
-  /* First, look at the partial symtab symbols.  */
-  expand_symtabs_matching (NULL,
-                          lookup_name,
-                          NULL,
-                          NULL,
-                          ALL_DOMAIN);
-
-  /* At this point scan through the misc symbol vectors and add each
-     symbol you find to the list.  Eventually we want to ignore
-     anything that isn't a text symbol (everything else will be
-     handled by the psymtab code above).  */
-
-  for (objfile *objfile : current_program_space->objfiles ())
-    {
-      for (minimal_symbol *msymbol : objfile->msymbols ())
-       {
-         QUIT;
-
-         if (completion_skip_symbol (mode, msymbol))
-           continue;
-
-         language symbol_language = MSYMBOL_LANGUAGE (msymbol);
-
-         /* Ada minimal symbols won't have their language set to Ada.  If
-            we let completion_list_add_name compare using the
-            default/C-like matcher, then when completing e.g., symbols in a
-            package named "pck", we'd match internal Ada symbols like
-            "pckS", which are invalid in an Ada expression, unless you wrap
-            them in '<' '>' to request a verbatim match.
-
-            Unfortunately, some Ada encoded names successfully demangle as
-            C++ symbols (using an old mangling scheme), such as "name__2Xn"
-            -> "Xn::name(void)" and thus some Ada minimal symbols end up
-            with the wrong language set.  Paper over that issue here.  */
-         if (symbol_language == language_auto
-             || symbol_language == language_cplus)
-           symbol_language = language_ada;
-
-         completion_list_add_name (tracker,
-                                   symbol_language,
-                                   MSYMBOL_LINKAGE_NAME (msymbol),
-                                   lookup_name, text, word);
-       }
-    }
-
-  /* Search upwards from currently selected frame (so that we can
-     complete on local vars.  */
-
-  for (b = get_selected_block (0); b != NULL; b = BLOCK_SUPERBLOCK (b))
-    {
-      if (!BLOCK_SUPERBLOCK (b))
-        surrounding_static_block = b;   /* For elmin of dups */
-
-      ALL_BLOCK_SYMBOLS (b, iter, sym)
-      {
-       if (completion_skip_symbol (mode, sym))
-         continue;
-
-       completion_list_add_name (tracker,
-                                 SYMBOL_LANGUAGE (sym),
-                                 SYMBOL_LINKAGE_NAME (sym),
-                                 lookup_name, text, word);
-      }
-    }
-
-  /* Go through the symtabs and check the externs and statics for
-     symbols which match.  */
-
-  for (objfile *objfile : current_program_space->objfiles ())
-    {
-      for (compunit_symtab *s : objfile->compunits ())
-       {
-         QUIT;
-         b = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (s), GLOBAL_BLOCK);
-         ALL_BLOCK_SYMBOLS (b, iter, sym)
-           {
-             if (completion_skip_symbol (mode, sym))
-               continue;
-
-             completion_list_add_name (tracker,
-                                       SYMBOL_LANGUAGE (sym),
-                                       SYMBOL_LINKAGE_NAME (sym),
-                                       lookup_name, text, word);
-           }
-       }
-    }
-
-  for (objfile *objfile : current_program_space->objfiles ())
-    {
-      for (compunit_symtab *s : objfile->compunits ())
-       {
-         QUIT;
-         b = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (s), STATIC_BLOCK);
-         /* Don't do this block twice.  */
-         if (b == surrounding_static_block)
-           continue;
-         ALL_BLOCK_SYMBOLS (b, iter, sym)
-           {
-             if (completion_skip_symbol (mode, sym))
-               continue;
-
-             completion_list_add_name (tracker,
-                                       SYMBOL_LANGUAGE (sym),
-                                       SYMBOL_LINKAGE_NAME (sym),
-                                       lookup_name, text, word);
-           }
-       }
-    }
-}
-
                                 /* Field Access */
 
 /* Return non-zero if TYPE is a pointer to the GNAT dispatch table used
@@ -6442,10 +6209,10 @@ ada_is_dispatch_table_ptr_type (struct type *type)
 {
   const char *name;
 
-  if (TYPE_CODE (type) != TYPE_CODE_PTR)
+  if (type->code () != TYPE_CODE_PTR)
     return 0;
 
-  name = TYPE_NAME (TYPE_TARGET_TYPE (type));
+  name = TYPE_TARGET_TYPE (type)->name ();
   if (name == NULL)
     return 0;
 
@@ -6457,7 +6224,7 @@ ada_is_dispatch_table_ptr_type (struct type *type)
 static int
 ada_is_interface_tag (struct type *type)
 {
-  const char *name = TYPE_NAME (type);
+  const char *name = type->name ();
 
   if (name == NULL)
     return 0;
@@ -6471,7 +6238,7 @@ ada_is_interface_tag (struct type *type)
 int
 ada_is_ignored_field (struct type *type, int field_num)
 {
-  if (field_num < 0 || field_num > TYPE_NFIELDS (type))
+  if (field_num < 0 || field_num > type->num_fields ())
     return 1;
 
   /* Check the name of that field.  */
@@ -6480,7 +6247,7 @@ ada_is_ignored_field (struct type *type, int field_num)
 
     /* Anonymous field names should not be printed.
        brobecker/2007-02-20: I don't think this can actually happen
-       but we don't want to print the value of annonymous fields anyway.  */
+       but we don't want to print the value of anonymous fields anyway.  */
     if (name == NULL)
       return 1;
 
@@ -6498,8 +6265,8 @@ ada_is_ignored_field (struct type *type, int field_num)
   /* If this is the dispatch table of a tagged type or an interface tag,
      then ignore.  */
   if (ada_is_tagged_type (type, 1)
-      && (ada_is_dispatch_table_ptr_type (TYPE_FIELD_TYPE (type, field_num))
-         || ada_is_interface_tag (TYPE_FIELD_TYPE (type, field_num))))
+      && (ada_is_dispatch_table_ptr_type (type->field (field_num).type ())
+         || ada_is_interface_tag (type->field (field_num).type ())))
     return 1;
 
   /* Not a special field, so it should not be ignored.  */
@@ -6522,7 +6289,7 @@ ada_is_tag_type (struct type *type)
 {
   type = ada_check_typedef (type);
 
-  if (type == NULL || TYPE_CODE (type) != TYPE_CODE_PTR)
+  if (type == NULL || type->code () != TYPE_CODE_PTR)
     return 0;
   else
     {
@@ -6535,7 +6302,7 @@ ada_is_tag_type (struct type *type)
 
 /* The type of the tag on VAL.  */
 
-struct type *
+static struct type *
 ada_tag_type (struct value *val)
 {
   return ada_lookup_struct_elt_type (value_type (val), "_tag", 1, 0);
@@ -6552,7 +6319,7 @@ is_ada95_tag (struct value *tag)
 
 /* The value of the tag on VAL.  */
 
-struct value *
+static struct value *
 ada_value_tag (struct value *val)
 {
   return ada_value_struct_elt (val, "_tag", 0);
@@ -6586,10 +6353,10 @@ value_tag_from_contents_and_address (struct type *type,
 static struct type *
 type_from_tag (struct value *tag)
 {
-  const char *type_name = ada_tag_name (tag);
+  gdb::unique_xmalloc_ptr<char> type_name = ada_tag_name (tag);
 
   if (type_name != NULL)
-    return ada_find_any_type (ada_encode (type_name));
+    return ada_find_any_type (ada_encode (type_name.get ()));
   return NULL;
 }
 
@@ -6612,8 +6379,7 @@ ada_tag_value_at_base_address (struct value *obj)
 
   /* It is the responsability of the caller to deref pointers.  */
 
-  if (TYPE_CODE (obj_type) == TYPE_CODE_PTR
-      || TYPE_CODE (obj_type) == TYPE_CODE_REF)
+  if (obj_type->code () == TYPE_CODE_PTR || obj_type->code () == TYPE_CODE_REF)
     return obj;
 
   tag = ada_value_tag (obj);
@@ -6738,37 +6504,41 @@ ada_get_tsd_from_tag (struct value *tag)
 /* Given the TSD of a tag (type-specific data), return a string
    containing the name of the associated type.
 
-   The returned value is good until the next call.  May return NULL
-   if we are unable to determine the tag name.  */
+   May return NULL if we are unable to determine the tag name.  */
 
-static char *
+static gdb::unique_xmalloc_ptr<char>
 ada_tag_name_from_tsd (struct value *tsd)
 {
-  static char name[1024];
   char *p;
   struct value *val;
 
   val = ada_value_struct_elt (tsd, "expanded_name", 1);
   if (val == NULL)
     return NULL;
-  read_memory_string (value_as_address (val), name, sizeof (name) - 1);
-  for (p = name; *p != '\0'; p += 1)
-    if (isalpha (*p))
-      *p = tolower (*p);
-  return name;
+  gdb::unique_xmalloc_ptr<char> buffer
+    = target_read_string (value_as_address (val), INT_MAX);
+  if (buffer == nullptr)
+    return nullptr;
+
+  for (p = buffer.get (); *p != '\0'; ++p)
+    {
+      if (isalpha (*p))
+       *p = tolower (*p);
+    }
+
+  return buffer;
 }
 
 /* The type name of the dynamic type denoted by the 'tag value TAG, as
    a C string.
 
    Return NULL if the TAG is not an Ada tag, or if we were unable to
-   determine the name of that tag.  The result is good until the next
-   call.  */
+   determine the name of that tag.  */
 
-const char *
+gdb::unique_xmalloc_ptr<char>
 ada_tag_name (struct value *tag)
 {
-  char *name = NULL;
+  gdb::unique_xmalloc_ptr<char> name;
 
   if (!ada_is_tag_type (value_type (tag)))
     return NULL;
@@ -6805,16 +6575,16 @@ ada_parent_type (struct type *type)
 
   type = ada_check_typedef (type);
 
-  if (type == NULL || TYPE_CODE (type) != TYPE_CODE_STRUCT)
+  if (type == NULL || type->code () != TYPE_CODE_STRUCT)
     return NULL;
 
-  for (i = 0; i < TYPE_NFIELDS (type); i += 1)
+  for (i = 0; i < type->num_fields (); i += 1)
     if (ada_is_parent_field (type, i))
       {
-        struct type *parent_type = TYPE_FIELD_TYPE (type, i);
+        struct type *parent_type = type->field (i).type ();
 
         /* If the _parent field is a pointer, then dereference it.  */
-        if (TYPE_CODE (parent_type) == TYPE_CODE_PTR)
+        if (parent_type->code () == TYPE_CODE_PTR)
           parent_type = TYPE_TARGET_TYPE (parent_type);
         /* If there is a parallel XVS type, get the actual base type.  */
         parent_type = ada_get_base_type (parent_type);
@@ -6879,11 +6649,11 @@ ada_is_variant_part (struct type *type, int field_num)
   if (!ADA_TYPE_P (type))
     return 0;
 
-  struct type *field_type = TYPE_FIELD_TYPE (type, field_num);
+  struct type *field_type = type->field (field_num).type ();
 
-  return (TYPE_CODE (field_type) == TYPE_CODE_UNION
-          || (is_dynamic_field (type, field_num)
-              && (TYPE_CODE (TYPE_TARGET_TYPE (field_type)) 
+  return (field_type->code () == TYPE_CODE_UNION
+         || (is_dynamic_field (type, field_num)
+             && (TYPE_TARGET_TYPE (field_type)->code ()
                  == TYPE_CODE_UNION)));
 }
 
@@ -6904,7 +6674,7 @@ ada_variant_discrim_type (struct type *var_type, struct type *outer_type)
    valid field number within it, returns 1 iff field FIELD_NUM of TYPE
    represents a 'when others' clause; otherwise 0.  */
 
-int
+static int
 ada_is_others_clause (struct type *type, int field_num)
 {
   const char *name = TYPE_FIELD_NAME (type, field_num);
@@ -6926,7 +6696,7 @@ ada_variant_discrim_name (struct type *type0)
   const char *discrim_end;
   const char *discrim_start;
 
-  if (TYPE_CODE (type0) == TYPE_CODE_PTR)
+  if (type0->code () == TYPE_CODE_PTR)
     type = TYPE_TARGET_TYPE (type0);
   else
     type = type0;
@@ -7012,7 +6782,7 @@ ada_scan_number (const char str[], int k, LONGEST * R, int *new_k)
    and FIELD_NUM is a valid field number within it, returns 1 iff VAL is
    in the range encoded by field FIELD_NUM of TYPE; otherwise 0.  */
 
-int
+static int
 ada_in_variant (LONGEST val, struct type *type, int field_num)
 {
   const char *name = TYPE_FIELD_NAME (type, field_num);
@@ -7061,14 +6831,14 @@ ada_in_variant (LONGEST val, struct type *type, int field_num)
    fields.  FIELDNO says which field.   Differs from value_primitive_field
    only in that it can handle packed values of arbitrary type.  */
 
-static struct value *
+struct value *
 ada_value_primitive_field (struct value *arg1, int offset, int fieldno,
                            struct type *arg_type)
 {
   struct type *type;
 
   arg_type = ada_check_typedef (arg_type);
-  type = TYPE_FIELD_TYPE (arg_type, fieldno);
+  type = arg_type->field (fieldno).type ();
 
   /* Handle packed fields.  It might be that the field is not packed
      relative to its containing structure, but the structure itself is
@@ -7171,7 +6941,7 @@ find_struct_field (const char *name, struct type *type, int offset,
   if (bit_size_p != NULL)
     *bit_size_p = 0;
 
-  for (i = 0; i < TYPE_NFIELDS (type); i += 1)
+  for (i = 0; i < type->num_fields (); i += 1)
     {
       int bit_pos = TYPE_FIELD_BITPOS (type, i);
       int fld_offset = offset + bit_pos / 8;
@@ -7199,7 +6969,7 @@ find_struct_field (const char *name, struct type *type, int offset,
           int bit_size = TYPE_FIELD_BITSIZE (type, i);
 
          if (field_type_p != NULL)
-           *field_type_p = TYPE_FIELD_TYPE (type, i);
+           *field_type_p = type->field (i).type ();
          if (byte_offset_p != NULL)
            *byte_offset_p = fld_offset;
          if (bit_offset_p != NULL)
@@ -7210,7 +6980,7 @@ find_struct_field (const char *name, struct type *type, int offset,
         }
       else if (ada_is_wrapper_field (type, i))
         {
-         if (find_struct_field (name, TYPE_FIELD_TYPE (type, i), fld_offset,
+         if (find_struct_field (name, type->field (i).type (), fld_offset,
                                 field_type_p, byte_offset_p, bit_offset_p,
                                 bit_size_p, index_p))
             return 1;
@@ -7221,11 +6991,11 @@ find_struct_field (const char *name, struct type *type, int offset,
             fixed type?? */
           int j;
           struct type *field_type
-           = ada_check_typedef (TYPE_FIELD_TYPE (type, i));
+           = ada_check_typedef (type->field (i).type ());
 
-          for (j = 0; j < TYPE_NFIELDS (field_type); j += 1)
+          for (j = 0; j < field_type->num_fields (); j += 1)
             {
-              if (find_struct_field (name, TYPE_FIELD_TYPE (field_type, j),
+              if (find_struct_field (name, field_type->field (j).type (),
                                      fld_offset
                                      + TYPE_FIELD_BITPOS (field_type, j) / 8,
                                      field_type_p, byte_offset_p,
@@ -7245,7 +7015,7 @@ find_struct_field (const char *name, struct type *type, int offset,
       int bit_pos = TYPE_FIELD_BITPOS (type, parent_offset);
       int fld_offset = offset + bit_pos / 8;
 
-      if (find_struct_field (name, TYPE_FIELD_TYPE (type, parent_offset),
+      if (find_struct_field (name, type->field (parent_offset).type (),
                              fld_offset, field_type_p, byte_offset_p,
                              bit_offset_p, bit_size_p, index_p))
         return 1;
@@ -7283,7 +7053,7 @@ ada_search_struct_field (const char *name, struct value *arg, int offset,
   int parent_offset = -1;
 
   type = ada_check_typedef (type);
-  for (i = 0; i < TYPE_NFIELDS (type); i += 1)
+  for (i = 0; i < type->num_fields (); i += 1)
     {
       const char *t_field_name = TYPE_FIELD_NAME (type, i);
 
@@ -7312,7 +7082,7 @@ ada_search_struct_field (const char *name, struct value *arg, int offset,
           struct value *v =     /* Do not let indent join lines here.  */
             ada_search_struct_field (name, arg,
                                      offset + TYPE_FIELD_BITPOS (type, i) / 8,
-                                     TYPE_FIELD_TYPE (type, i));
+                                     type->field (i).type ());
 
           if (v != NULL)
             return v;
@@ -7322,17 +7092,16 @@ ada_search_struct_field (const char *name, struct value *arg, int offset,
         {
          /* PNH: Do we ever get here?  See find_struct_field.  */
           int j;
-          struct type *field_type = ada_check_typedef (TYPE_FIELD_TYPE (type,
-                                                                       i));
+          struct type *field_type = ada_check_typedef (type->field (i).type ());
           int var_offset = offset + TYPE_FIELD_BITPOS (type, i) / 8;
 
-          for (j = 0; j < TYPE_NFIELDS (field_type); j += 1)
+          for (j = 0; j < field_type->num_fields (); j += 1)
             {
               struct value *v = ada_search_struct_field /* Force line
                                                           break.  */
                 (name, arg,
                  var_offset + TYPE_FIELD_BITPOS (field_type, j) / 8,
-                 TYPE_FIELD_TYPE (field_type, j));
+                 field_type->field (j).type ());
 
               if (v != NULL)
                 return v;
@@ -7347,7 +7116,7 @@ ada_search_struct_field (const char *name, struct value *arg, int offset,
     {
       struct value *v = ada_search_struct_field (
        name, arg, offset + TYPE_FIELD_BITPOS (type, parent_offset) / 8,
-       TYPE_FIELD_TYPE (type, parent_offset));
+       type->field (parent_offset).type ());
 
       if (v != NULL)
         return v;
@@ -7384,158 +7153,33 @@ ada_index_struct_field_1 (int *index_p, struct value *arg, int offset,
   int i;
   type = ada_check_typedef (type);
 
-  for (i = 0; i < TYPE_NFIELDS (type); i += 1)
+  for (i = 0; i < type->num_fields (); i += 1)
     {
       if (TYPE_FIELD_NAME (type, i) == NULL)
         continue;
       else if (ada_is_wrapper_field (type, i))
         {
           struct value *v =     /* Do not let indent join lines here.  */
-            ada_index_struct_field_1 (index_p, arg,
-                                     offset + TYPE_FIELD_BITPOS (type, i) / 8,
-                                     TYPE_FIELD_TYPE (type, i));
-
-          if (v != NULL)
-            return v;
-        }
-
-      else if (ada_is_variant_part (type, i))
-        {
-         /* PNH: Do we ever get here?  See ada_search_struct_field,
-            find_struct_field.  */
-         error (_("Cannot assign this kind of variant record"));
-        }
-      else if (*index_p == 0)
-        return ada_value_primitive_field (arg, offset, i, type);
-      else
-       *index_p -= 1;
-    }
-  return NULL;
-}
-
-/* Given ARG, a value of type (pointer or reference to a)*
-   structure/union, extract the component named NAME from the ultimate
-   target structure/union and return it as a value with its
-   appropriate type.
-
-   The routine searches for NAME among all members of the structure itself
-   and (recursively) among all members of any wrapper members
-   (e.g., '_parent').
-
-   If NO_ERR, then simply return NULL in case of error, rather than 
-   calling error.  */
-
-struct value *
-ada_value_struct_elt (struct value *arg, const char *name, int no_err)
-{
-  struct type *t, *t1;
-  struct value *v;
-  int check_tag;
-
-  v = NULL;
-  t1 = t = ada_check_typedef (value_type (arg));
-  if (TYPE_CODE (t) == TYPE_CODE_REF)
-    {
-      t1 = TYPE_TARGET_TYPE (t);
-      if (t1 == NULL)
-       goto BadValue;
-      t1 = ada_check_typedef (t1);
-      if (TYPE_CODE (t1) == TYPE_CODE_PTR)
-        {
-          arg = coerce_ref (arg);
-          t = t1;
-        }
-    }
-
-  while (TYPE_CODE (t) == TYPE_CODE_PTR)
-    {
-      t1 = TYPE_TARGET_TYPE (t);
-      if (t1 == NULL)
-       goto BadValue;
-      t1 = ada_check_typedef (t1);
-      if (TYPE_CODE (t1) == TYPE_CODE_PTR)
-        {
-          arg = value_ind (arg);
-          t = t1;
-        }
-      else
-        break;
-    }
-
-  if (TYPE_CODE (t1) != TYPE_CODE_STRUCT && TYPE_CODE (t1) != TYPE_CODE_UNION)
-    goto BadValue;
-
-  if (t1 == t)
-    v = ada_search_struct_field (name, arg, 0, t);
-  else
-    {
-      int bit_offset, bit_size, byte_offset;
-      struct type *field_type;
-      CORE_ADDR address;
-
-      if (TYPE_CODE (t) == TYPE_CODE_PTR)
-       address = value_address (ada_value_ind (arg));
-      else
-       address = value_address (ada_coerce_ref (arg));
-
-      /* Check to see if this is a tagged type.  We also need to handle
-         the case where the type is a reference to a tagged type, but
-         we have to be careful to exclude pointers to tagged types.
-         The latter should be shown as usual (as a pointer), whereas
-         a reference should mostly be transparent to the user.  */
-
-      if (ada_is_tagged_type (t1, 0)
-          || (TYPE_CODE (t1) == TYPE_CODE_REF
-              && ada_is_tagged_type (TYPE_TARGET_TYPE (t1), 0)))
-        {
-          /* We first try to find the searched field in the current type.
-            If not found then let's look in the fixed type.  */
-
-          if (!find_struct_field (name, t1, 0,
-                                  &field_type, &byte_offset, &bit_offset,
-                                  &bit_size, NULL))
-           check_tag = 1;
-         else
-           check_tag = 0;
-        }
-      else
-       check_tag = 0;
-
-      /* Convert to fixed type in all cases, so that we have proper
-        offsets to each field in unconstrained record types.  */
-      t1 = ada_to_fixed_type (ada_get_base_type (t1), NULL,
-                             address, NULL, check_tag);
+            ada_index_struct_field_1 (index_p, arg,
+                                     offset + TYPE_FIELD_BITPOS (type, i) / 8,
+                                     type->field (i).type ());
 
-      if (find_struct_field (name, t1, 0,
-                             &field_type, &byte_offset, &bit_offset,
-                             &bit_size, NULL))
+          if (v != NULL)
+            return v;
+        }
+
+      else if (ada_is_variant_part (type, i))
         {
-          if (bit_size != 0)
-            {
-              if (TYPE_CODE (t) == TYPE_CODE_REF)
-                arg = ada_coerce_ref (arg);
-              else
-                arg = ada_value_ind (arg);
-              v = ada_value_primitive_packed_val (arg, NULL, byte_offset,
-                                                  bit_offset, bit_size,
-                                                  field_type);
-            }
-          else
-            v = value_at_lazy (field_type, address + byte_offset);
+         /* PNH: Do we ever get here?  See ada_search_struct_field,
+            find_struct_field.  */
+         error (_("Cannot assign this kind of variant record"));
         }
+      else if (*index_p == 0)
+        return ada_value_primitive_field (arg, offset, i, type);
+      else
+       *index_p -= 1;
     }
-
-  if (v != NULL || no_err)
-    return v;
-  else
-    error (_("There is no member named %s."), name);
-
- BadValue:
-  if (no_err)
-    return NULL;
-  else
-    error (_("Attempt to extract a component of "
-            "a value that is not a record."));
+  return NULL;
 }
 
 /* Return a string representation of type TYPE.  */
@@ -7584,15 +7228,14 @@ ada_lookup_struct_elt_type (struct type *type, const char *name, int refok,
     while (1)
       {
         type = ada_check_typedef (type);
-        if (TYPE_CODE (type) != TYPE_CODE_PTR
-            && TYPE_CODE (type) != TYPE_CODE_REF)
+        if (type->code () != TYPE_CODE_PTR && type->code () != TYPE_CODE_REF)
           break;
         type = TYPE_TARGET_TYPE (type);
       }
 
   if (type == NULL
-      || (TYPE_CODE (type) != TYPE_CODE_STRUCT
-          && TYPE_CODE (type) != TYPE_CODE_UNION))
+      || (type->code () != TYPE_CODE_STRUCT
+         && type->code () != TYPE_CODE_UNION))
     {
       if (noerr)
         return NULL;
@@ -7603,7 +7246,7 @@ ada_lookup_struct_elt_type (struct type *type, const char *name, int refok,
 
   type = to_static_fixed_type (type);
 
-  for (i = 0; i < TYPE_NFIELDS (type); i += 1)
+  for (i = 0; i < type->num_fields (); i += 1)
     {
       const char *t_field_name = TYPE_FIELD_NAME (type, i);
       struct type *t;
@@ -7626,11 +7269,11 @@ ada_lookup_struct_elt_type (struct type *type, const char *name, int refok,
         }
 
       else if (field_name_match (t_field_name, name))
-       return TYPE_FIELD_TYPE (type, i);
+       return type->field (i).type ();
 
       else if (ada_is_wrapper_field (type, i))
         {
-          t = ada_lookup_struct_elt_type (TYPE_FIELD_TYPE (type, i), name,
+          t = ada_lookup_struct_elt_type (type->field (i).type (), name,
                                           0, 1);
           if (t != NULL)
            return t;
@@ -7639,10 +7282,9 @@ ada_lookup_struct_elt_type (struct type *type, const char *name, int refok,
       else if (ada_is_variant_part (type, i))
         {
           int j;
-          struct type *field_type = ada_check_typedef (TYPE_FIELD_TYPE (type,
-                                                                       i));
+          struct type *field_type = ada_check_typedef (type->field (i).type ());
 
-          for (j = TYPE_NFIELDS (field_type) - 1; j >= 0; j -= 1)
+          for (j = field_type->num_fields () - 1; j >= 0; j -= 1)
             {
              /* FIXME pnh 2008/01/26: We check for a field that is
                 NOT wrapped in a struct, since the compiler sometimes
@@ -7652,10 +7294,9 @@ ada_lookup_struct_elt_type (struct type *type, const char *name, int refok,
 
              if (v_field_name != NULL 
                  && field_name_match (v_field_name, name))
-               t = TYPE_FIELD_TYPE (field_type, j);
+               t = field_type->field (j).type ();
              else
-               t = ada_lookup_struct_elt_type (TYPE_FIELD_TYPE (field_type,
-                                                                j),
+               t = ada_lookup_struct_elt_type (field_type->field (j).type (),
                                                name, 0, 1);
 
               if (t != NULL)
@@ -7672,7 +7313,7 @@ ada_lookup_struct_elt_type (struct type *type, const char *name, int refok,
       {
         struct type *t;
 
-        t = ada_lookup_struct_elt_type (TYPE_FIELD_TYPE (type, parent_offset),
+        t = ada_lookup_struct_elt_type (type->field (parent_offset).type (),
                                         name, 0, 1);
         if (t != NULL)
          return t;
@@ -7705,33 +7346,28 @@ is_unchecked_variant (struct type *var_type, struct type *outer_type)
 
 
 /* Assuming that VAR_TYPE is the type of a variant part of a record (a union),
-   within a value of type OUTER_TYPE that is stored in GDB at
-   OUTER_VALADDR, determine which variant clause (field number in VAR_TYPE,
+   within OUTER, determine which variant clause (field number in VAR_TYPE,
    numbering from 0) is applicable.  Returns -1 if none are.  */
 
 int
-ada_which_variant_applies (struct type *var_type, struct type *outer_type,
-                           const gdb_byte *outer_valaddr)
+ada_which_variant_applies (struct type *var_type, struct value *outer)
 {
   int others_clause;
   int i;
   const char *discrim_name = ada_variant_discrim_name (var_type);
-  struct value *outer;
   struct value *discrim;
   LONGEST discrim_val;
 
   /* Using plain value_from_contents_and_address here causes problems
      because we will end up trying to resolve a type that is currently
      being constructed.  */
-  outer = value_from_contents_and_address_unresolved (outer_type,
-                                                     outer_valaddr, 0);
   discrim = ada_value_struct_elt (outer, discrim_name, 1);
   if (discrim == NULL)
     return -1;
   discrim_val = value_as_long (discrim);
 
   others_clause = -1;
-  for (i = 0; i < TYPE_NFIELDS (var_type); i += 1)
+  for (i = 0; i < var_type->num_fields (); i += 1)
     {
       if (ada_is_others_clause (var_type, i))
         others_clause = i;
@@ -7800,7 +7436,7 @@ ada_value_ind (struct value *val0)
 static struct value *
 ada_coerce_ref (struct value *val0)
 {
-  if (TYPE_CODE (value_type (val0)) == TYPE_CODE_REF)
+  if (value_type (val0)->code () == TYPE_CODE_REF)
     {
       struct value *val = val0;
 
@@ -7815,15 +7451,6 @@ ada_coerce_ref (struct value *val0)
     return val0;
 }
 
-/* Return OFF rounded upward if necessary to a multiple of
-   ALIGNMENT (a power of 2).  */
-
-static unsigned int
-align_value (unsigned int off, unsigned int alignment)
-{
-  return (off + alignment - 1) & ~(alignment - 1);
-}
-
 /* Return the bit alignment required for field #F of template type TYPE.  */
 
 static unsigned int
@@ -7894,7 +7521,7 @@ ada_find_any_type (const char *name)
 static bool
 ada_is_renaming_symbol (struct symbol *name_sym)
 {
-  const char *name = SYMBOL_LINKAGE_NAME (name_sym);
+  const char *name = name_sym->linkage_name ();
   return strstr (name, "___XR") != NULL;
 }
 
@@ -7910,11 +7537,11 @@ ada_prefer_type (struct type *type0, struct type *type1)
     return 1;
   else if (type0 == NULL)
     return 0;
-  else if (TYPE_CODE (type1) == TYPE_CODE_VOID)
+  else if (type1->code () == TYPE_CODE_VOID)
     return 1;
-  else if (TYPE_CODE (type0) == TYPE_CODE_VOID)
+  else if (type0->code () == TYPE_CODE_VOID)
     return 0;
-  else if (TYPE_NAME (type1) == NULL && TYPE_NAME (type0) != NULL)
+  else if (type1->name () == NULL && type0->name () != NULL)
     return 1;
   else if (ada_is_constrained_packed_array_type (type0))
     return 1;
@@ -7923,8 +7550,8 @@ ada_prefer_type (struct type *type0, struct type *type1)
     return 1;
   else
     {
-      const char *type0_name = TYPE_NAME (type0);
-      const char *type1_name = TYPE_NAME (type1);
+      const char *type0_name = type0->name ();
+      const char *type1_name = type1->name ();
 
       if (type0_name != NULL && strstr (type0_name, "___XR") != NULL
          && (type1_name == NULL || strstr (type1_name, "___XR") == NULL))
@@ -7941,7 +7568,7 @@ ada_type_name (struct type *type)
 {
   if (type == NULL)
     return NULL;
-  return TYPE_NAME (type);
+  return type->name ();
 }
 
 /* Search the list of "descriptive" types associated to TYPE for a type
@@ -8052,7 +7679,7 @@ dynamic_template_type (struct type *type)
 {
   type = ada_check_typedef (type);
 
-  if (type == NULL || TYPE_CODE (type) != TYPE_CODE_STRUCT
+  if (type == NULL || type->code () != TYPE_CODE_STRUCT
       || ada_type_name (type) == NULL)
     return NULL;
   else
@@ -8075,7 +7702,7 @@ is_dynamic_field (struct type *templ_type, int field_num)
   const char *name = TYPE_FIELD_NAME (templ_type, field_num);
 
   return name != NULL
-    && TYPE_CODE (TYPE_FIELD_TYPE (templ_type, field_num)) == TYPE_CODE_PTR
+    && templ_type->field (field_num).type ()->code () == TYPE_CODE_PTR
     && strstr (name, "___XVL") != NULL;
 }
 
@@ -8087,10 +7714,10 @@ variant_field_index (struct type *type)
 {
   int f;
 
-  if (type == NULL || TYPE_CODE (type) != TYPE_CODE_STRUCT)
+  if (type == NULL || type->code () != TYPE_CODE_STRUCT)
     return -1;
 
-  for (f = 0; f < TYPE_NFIELDS (type); f += 1)
+  for (f = 0; f < type->num_fields (); f += 1)
     {
       if (ada_is_variant_part (type, f))
         return f;
@@ -8105,11 +7732,9 @@ empty_record (struct type *templ)
 {
   struct type *type = alloc_type_copy (templ);
 
-  TYPE_CODE (type) = TYPE_CODE_STRUCT;
-  TYPE_NFIELDS (type) = 0;
-  TYPE_FIELDS (type) = NULL;
+  type->set_code (TYPE_CODE_STRUCT);
   INIT_NONE_SPECIFIC (type);
-  TYPE_NAME (type) = "<empty>";
+  type->set_name ("<empty>");
   TYPE_LENGTH (type) = 0;
   return type;
 }
@@ -8150,24 +7775,23 @@ ada_template_to_fixed_record_type_1 (struct type *type,
      to be processed: unless keep_dynamic_fields, this includes only
      fields whose position and length are static will be processed.  */
   if (keep_dynamic_fields)
-    nfields = TYPE_NFIELDS (type);
+    nfields = type->num_fields ();
   else
     {
       nfields = 0;
-      while (nfields < TYPE_NFIELDS (type)
+      while (nfields < type->num_fields ()
              && !ada_is_variant_part (type, nfields)
              && !is_dynamic_field (type, nfields))
         nfields++;
     }
 
   rtype = alloc_type_copy (type);
-  TYPE_CODE (rtype) = TYPE_CODE_STRUCT;
+  rtype->set_code (TYPE_CODE_STRUCT);
   INIT_NONE_SPECIFIC (rtype);
-  TYPE_NFIELDS (rtype) = nfields;
-  TYPE_FIELDS (rtype) = (struct field *)
-    TYPE_ALLOC (rtype, nfields * sizeof (struct field));
-  memset (TYPE_FIELDS (rtype), 0, sizeof (struct field) * nfields);
-  TYPE_NAME (rtype) = ada_type_name (type);
+  rtype->set_num_fields (nfields);
+  rtype->set_fields
+   ((struct field *) TYPE_ZALLOC (rtype, nfields * sizeof (struct field)));
+  rtype->set_name (ada_type_name (type));
   TYPE_FIXED_INSTANCE (rtype) = 1;
 
   off = 0;
@@ -8176,9 +7800,9 @@ ada_template_to_fixed_record_type_1 (struct type *type,
 
   for (f = 0; f < nfields; f += 1)
     {
-      off = align_value (off, field_alignment (type, f))
+      off = align_up (off, field_alignment (type, f))
        + TYPE_FIELD_BITPOS (type, f);
-      SET_FIELD_BITPOS (TYPE_FIELD (rtype, f), off);
+      SET_FIELD_BITPOS (rtype->field (f), off);
       TYPE_FIELD_BITSIZE (rtype, f) = 0;
 
       if (ada_is_variant_part (type, f))
@@ -8191,7 +7815,7 @@ ada_template_to_fixed_record_type_1 (struct type *type,
          const gdb_byte *field_valaddr = valaddr;
          CORE_ADDR field_address = address;
          struct type *field_type =
-           TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, f));
+           TYPE_TARGET_TYPE (type->field (f).type ());
 
           if (dval0 == NULL)
            {
@@ -8250,7 +7874,7 @@ ada_template_to_fixed_record_type_1 (struct type *type,
             record size.  */
          ada_ensure_varsize_limit (field_type);
 
-         TYPE_FIELD_TYPE (rtype, f) = field_type;
+         rtype->field (f).set_type (field_type);
           TYPE_FIELD_NAME (rtype, f) = TYPE_FIELD_NAME (type, f);
          /* The multiplication can potentially overflow.  But because
             the field length has been size-checked just above, and
@@ -8259,7 +7883,7 @@ ada_template_to_fixed_record_type_1 (struct type *type,
             adding overflow recovery code to this already complex code,
             we just assume that it's not going to happen.  */
           fld_bit_len =
-            TYPE_LENGTH (TYPE_FIELD_TYPE (rtype, f)) * TARGET_CHAR_BIT;
+            TYPE_LENGTH (rtype->field (f).type ()) * TARGET_CHAR_BIT;
         }
       else
         {
@@ -8273,20 +7897,20 @@ ada_template_to_fixed_record_type_1 (struct type *type,
             structure, the typedef is the only clue which allows us
             to distinguish between the two options.  Stripping it
             would prevent us from printing this field appropriately.  */
-          TYPE_FIELD_TYPE (rtype, f) = TYPE_FIELD_TYPE (type, f);
+          rtype->field (f).set_type (type->field (f).type ());
           TYPE_FIELD_NAME (rtype, f) = TYPE_FIELD_NAME (type, f);
           if (TYPE_FIELD_BITSIZE (type, f) > 0)
             fld_bit_len =
               TYPE_FIELD_BITSIZE (rtype, f) = TYPE_FIELD_BITSIZE (type, f);
           else
            {
-             struct type *field_type = TYPE_FIELD_TYPE (type, f);
+             struct type *field_type = type->field (f).type ();
 
              /* We need to be careful of typedefs when computing
                 the length of our field.  If this is a typedef,
                 get the length of the target type, not the length
                 of the typedef.  */
-             if (TYPE_CODE (field_type) == TYPE_CODE_TYPEDEF)
+             if (field_type->code () == TYPE_CODE_TYPEDEF)
                field_type = ada_typedef_target_type (field_type);
 
               fld_bit_len =
@@ -8297,7 +7921,7 @@ ada_template_to_fixed_record_type_1 (struct type *type,
         bit_len = off + fld_bit_len;
       off += fld_bit_len;
       TYPE_LENGTH (rtype) =
-        align_value (bit_len, TARGET_CHAR_BIT) / TARGET_CHAR_BIT;
+        align_up (bit_len, TARGET_CHAR_BIT) / TARGET_CHAR_BIT;
     }
 
   /* We handle the variant part, if any, at the end because of certain
@@ -8324,26 +7948,26 @@ ada_template_to_fixed_record_type_1 (struct type *type,
 
       branch_type =
         to_fixed_variant_branch_type
-        (TYPE_FIELD_TYPE (type, variant_field),
+        (type->field (variant_field).type (),
          cond_offset_host (valaddr, off / TARGET_CHAR_BIT),
          cond_offset_target (address, off / TARGET_CHAR_BIT), dval);
       if (branch_type == NULL)
         {
-          for (f = variant_field + 1; f < TYPE_NFIELDS (rtype); f += 1)
-            TYPE_FIELDS (rtype)[f - 1] = TYPE_FIELDS (rtype)[f];
-          TYPE_NFIELDS (rtype) -= 1;
+          for (f = variant_field + 1; f < rtype->num_fields (); f += 1)
+            rtype->field (f - 1) = rtype->field (f);
+         rtype->set_num_fields (rtype->num_fields () - 1);
         }
       else
         {
-          TYPE_FIELD_TYPE (rtype, variant_field) = branch_type;
+          rtype->field (variant_field).set_type (branch_type);
           TYPE_FIELD_NAME (rtype, variant_field) = "S";
           fld_bit_len =
-            TYPE_LENGTH (TYPE_FIELD_TYPE (rtype, variant_field)) *
+            TYPE_LENGTH (rtype->field (variant_field).type ()) *
             TARGET_CHAR_BIT;
           if (off + fld_bit_len > bit_len)
             bit_len = off + fld_bit_len;
           TYPE_LENGTH (rtype) =
-            align_value (bit_len, TARGET_CHAR_BIT) / TARGET_CHAR_BIT;
+            align_up (bit_len, TARGET_CHAR_BIT) / TARGET_CHAR_BIT;
         }
     }
 
@@ -8355,17 +7979,17 @@ ada_template_to_fixed_record_type_1 (struct type *type,
      the current RTYPE length might be good enough for our purposes.  */
   if (TYPE_LENGTH (type) <= 0)
     {
-      if (TYPE_NAME (rtype))
+      if (rtype->name ())
        warning (_("Invalid type size for `%s' detected: %s."),
-                TYPE_NAME (rtype), pulongest (TYPE_LENGTH (type)));
+                rtype->name (), pulongest (TYPE_LENGTH (type)));
       else
        warning (_("Invalid type size for <unnamed> detected: %s."),
                 pulongest (TYPE_LENGTH (type)));
     }
   else
     {
-      TYPE_LENGTH (rtype) = align_value (TYPE_LENGTH (rtype),
-                                         TYPE_LENGTH (type));
+      TYPE_LENGTH (rtype) = align_up (TYPE_LENGTH (rtype),
+                                     TYPE_LENGTH (type));
     }
 
   value_free_to_mark (mark);
@@ -8411,7 +8035,7 @@ template_to_static_fixed_type (struct type *type0)
 
   /* Don't clone TYPE0 until we are sure we are going to need a copy.  */
   type = type0;
-  nfields = TYPE_NFIELDS (type0);
+  nfields = type0->num_fields ();
 
   /* Whether or not we cloned TYPE0, cache the result so that we don't do
      recompute all over next time.  */
@@ -8419,7 +8043,7 @@ template_to_static_fixed_type (struct type *type0)
 
   for (f = 0; f < nfields; f += 1)
     {
-      struct type *field_type = TYPE_FIELD_TYPE (type0, f);
+      struct type *field_type = type0->field (f).type ();
       struct type *new_type;
 
       if (is_dynamic_field (type0, f))
@@ -8436,18 +8060,22 @@ template_to_static_fixed_type (struct type *type0)
          if (type == type0)
            {
              TYPE_TARGET_TYPE (type0) = type = alloc_type_copy (type0);
-             TYPE_CODE (type) = TYPE_CODE (type0);
+             type->set_code (type0->code ());
              INIT_NONE_SPECIFIC (type);
-             TYPE_NFIELDS (type) = nfields;
-             TYPE_FIELDS (type) = (struct field *)
-               TYPE_ALLOC (type, nfields * sizeof (struct field));
-             memcpy (TYPE_FIELDS (type), TYPE_FIELDS (type0),
+             type->set_num_fields (nfields);
+
+             field *fields =
+               ((struct field *)
+                TYPE_ALLOC (type, nfields * sizeof (struct field)));
+             memcpy (fields, type0->fields (),
                      sizeof (struct field) * nfields);
-             TYPE_NAME (type) = ada_type_name (type0);
+             type->set_fields (fields);
+
+             type->set_name (ada_type_name (type0));
              TYPE_FIXED_INSTANCE (type) = 1;
              TYPE_LENGTH (type) = 0;
            }
-         TYPE_FIELD_TYPE (type, f) = new_type;
+         type->field (f).set_type (new_type);
          TYPE_FIELD_NAME (type, f) = TYPE_FIELD_NAME (type0, f);
        }
     }
@@ -8470,7 +8098,7 @@ to_record_with_fixed_variant_part (struct type *type, const gdb_byte *valaddr,
   struct value *dval;
   struct type *rtype;
   struct type *branch_type;
-  int nfields = TYPE_NFIELDS (type);
+  int nfields = type->num_fields ();
   int variant_field = variant_field_index (type);
 
   if (variant_field == -1)
@@ -8485,19 +8113,21 @@ to_record_with_fixed_variant_part (struct type *type, const gdb_byte *valaddr,
     dval = dval0;
 
   rtype = alloc_type_copy (type);
-  TYPE_CODE (rtype) = TYPE_CODE_STRUCT;
+  rtype->set_code (TYPE_CODE_STRUCT);
   INIT_NONE_SPECIFIC (rtype);
-  TYPE_NFIELDS (rtype) = nfields;
-  TYPE_FIELDS (rtype) =
+  rtype->set_num_fields (nfields);
+
+  field *fields =
     (struct field *) TYPE_ALLOC (rtype, nfields * sizeof (struct field));
-  memcpy (TYPE_FIELDS (rtype), TYPE_FIELDS (type),
-          sizeof (struct field) * nfields);
-  TYPE_NAME (rtype) = ada_type_name (type);
+  memcpy (fields, type->fields (), sizeof (struct field) * nfields);
+  rtype->set_fields (fields);
+
+  rtype->set_name (ada_type_name (type));
   TYPE_FIXED_INSTANCE (rtype) = 1;
   TYPE_LENGTH (rtype) = TYPE_LENGTH (type);
 
   branch_type = to_fixed_variant_branch_type
-    (TYPE_FIELD_TYPE (type, variant_field),
+    (type->field (variant_field).type (),
      cond_offset_host (valaddr,
                        TYPE_FIELD_BITPOS (type, variant_field)
                        / TARGET_CHAR_BIT),
@@ -8509,17 +8139,17 @@ to_record_with_fixed_variant_part (struct type *type, const gdb_byte *valaddr,
       int f;
 
       for (f = variant_field + 1; f < nfields; f += 1)
-        TYPE_FIELDS (rtype)[f - 1] = TYPE_FIELDS (rtype)[f];
-      TYPE_NFIELDS (rtype) -= 1;
+        rtype->field (f - 1) = rtype->field (f);
+      rtype->set_num_fields (rtype->num_fields () - 1);
     }
   else
     {
-      TYPE_FIELD_TYPE (rtype, variant_field) = branch_type;
+      rtype->field (variant_field).set_type (branch_type);
       TYPE_FIELD_NAME (rtype, variant_field) = "S";
       TYPE_FIELD_BITSIZE (rtype, variant_field) = 0;
       TYPE_LENGTH (rtype) += TYPE_LENGTH (branch_type);
     }
-  TYPE_LENGTH (rtype) -= TYPE_LENGTH (TYPE_FIELD_TYPE (type, variant_field));
+  TYPE_LENGTH (rtype) -= TYPE_LENGTH (type->field (variant_field).type ());
 
   value_free_to_mark (mark);
   return rtype;
@@ -8587,7 +8217,7 @@ to_fixed_variant_branch_type (struct type *var_type0, const gdb_byte *valaddr,
   struct type *templ_type;
   struct type *var_type;
 
-  if (TYPE_CODE (var_type0) == TYPE_CODE_PTR)
+  if (var_type0->code () == TYPE_CODE_PTR)
     var_type = TYPE_TARGET_TYPE (var_type0);
   else
     var_type = var_type0;
@@ -8599,22 +8229,20 @@ to_fixed_variant_branch_type (struct type *var_type0, const gdb_byte *valaddr,
 
   if (is_unchecked_variant (var_type, value_type (dval)))
       return var_type0;
-  which =
-    ada_which_variant_applies (var_type,
-                               value_type (dval), value_contents (dval));
+  which = ada_which_variant_applies (var_type, dval);
 
   if (which < 0)
     return empty_record (var_type);
   else if (is_dynamic_field (var_type, which))
     return to_fixed_record_type
-      (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (var_type, which)),
+      (TYPE_TARGET_TYPE (var_type->field (which).type ()),
        valaddr, address, dval);
-  else if (variant_field_index (TYPE_FIELD_TYPE (var_type, which)) >= 0)
+  else if (variant_field_index (var_type->field (which).type ()) >= 0)
     return
       to_fixed_record_type
-      (TYPE_FIELD_TYPE (var_type, which), valaddr, address, dval);
+      (var_type->field (which).type (), valaddr, address, dval);
   else
-    return TYPE_FIELD_TYPE (var_type, which);
+    return var_type->field (which).type ();
 }
 
 /* Assuming RANGE_TYPE is a TYPE_CODE_RANGE, return nonzero if
@@ -8629,10 +8257,10 @@ ada_is_redundant_range_encoding (struct type *range_type,
   int n;
   LONGEST lo, hi;
 
-  gdb_assert (TYPE_CODE (range_type) == TYPE_CODE_RANGE);
+  gdb_assert (range_type->code () == TYPE_CODE_RANGE);
 
-  if (TYPE_CODE (get_base_type (range_type))
-      != TYPE_CODE (get_base_type (encoding_type)))
+  if (get_base_type (range_type)->code ()
+      != get_base_type (encoding_type)->code ())
     {
       /* The compiler probably used a simple base type to describe
         the range type instead of the range's actual base type,
@@ -8645,10 +8273,10 @@ ada_is_redundant_range_encoding (struct type *range_type,
   if (is_dynamic_type (range_type))
     return 0;
 
-  if (TYPE_NAME (encoding_type) == NULL)
+  if (encoding_type->name () == NULL)
     return 0;
 
-  bounds_str = strstr (TYPE_NAME (encoding_type), "___XDLU_");
+  bounds_str = strstr (encoding_type->name (), "___XDLU_");
   if (bounds_str == NULL)
     return 0;
 
@@ -8678,10 +8306,10 @@ ada_is_redundant_index_type_desc (struct type *array_type,
   struct type *this_layer = check_typedef (array_type);
   int i;
 
-  for (i = 0; i < TYPE_NFIELDS (desc_type); i++)
+  for (i = 0; i < desc_type->num_fields (); i++)
     {
-      if (!ada_is_redundant_range_encoding (TYPE_INDEX_TYPE (this_layer),
-                                           TYPE_FIELD_TYPE (desc_type, i)))
+      if (!ada_is_redundant_range_encoding (this_layer->index_type (),
+                                           desc_type->field (i).type ()))
        return 0;
       this_layer = check_typedef (TYPE_TARGET_TYPE (this_layer));
     }
@@ -8774,7 +8402,7 @@ to_fixed_array_type (struct type *type0, struct value *dval,
         result = type0;
       else
         result = create_array_type (alloc_type_copy (type0),
-                                    elt_type, TYPE_INDEX_TYPE (type0));
+                                    elt_type, type0->index_type ());
     }
   else
     {
@@ -8782,7 +8410,7 @@ to_fixed_array_type (struct type *type0, struct value *dval,
       struct type *elt_type0;
 
       elt_type0 = type0;
-      for (i = TYPE_NFIELDS (index_type_desc); i > 0; i -= 1)
+      for (i = index_type_desc->num_fields (); i > 0; i -= 1)
         elt_type0 = TYPE_TARGET_TYPE (elt_type0);
 
       /* NOTE: result---the fixed version of elt_type0---should never
@@ -8800,10 +8428,10 @@ to_fixed_array_type (struct type *type0, struct value *dval,
         ada_to_fixed_type (ada_check_typedef (elt_type0), 0, 0, dval, 1);
 
       elt_type0 = type0;
-      for (i = TYPE_NFIELDS (index_type_desc) - 1; i >= 0; i -= 1)
+      for (i = index_type_desc->num_fields () - 1; i >= 0; i -= 1)
         {
           struct type *range_type =
-            to_fixed_range_type (TYPE_FIELD_TYPE (index_type_desc, i), dval);
+            to_fixed_range_type (index_type_desc->field (i).type (), dval);
 
           result = create_array_type (alloc_type_copy (elt_type0),
                                       result, range_type);
@@ -8816,7 +8444,7 @@ to_fixed_array_type (struct type *type0, struct value *dval,
   /* We want to preserve the type name.  This can be useful when
      trying to get the type name of a value that has already been
      printed (for instance, if the user did "print VAR; whatis $".  */
-  TYPE_NAME (result) = TYPE_NAME (type0);
+  result->set_name (type0->name ());
 
   if (constrained_packed_array_p)
     {
@@ -8860,7 +8488,7 @@ ada_to_fixed_type_1 (struct type *type, const gdb_byte *valaddr,
   if (!HAVE_GNAT_AUX_INFO (type))
     return type;
 
-  switch (TYPE_CODE (type))
+  switch (type->code ())
     {
     default:
       return type;
@@ -9005,10 +8633,10 @@ ada_to_fixed_type (struct type *type, const gdb_byte *valaddr,
       brobecker/2010-11-19: It seems to me that the only case where it is
       useful to preserve the typedef layer is when dealing with fat pointers.
       Perhaps, we could add a check for that and preserve the typedef layer
-      only in that situation.  But this seems unecessary so far, probably
+      only in that situation.  But this seems unnecessary so far, probably
       because we call check_typedef/ada_check_typedef pretty much everywhere.
       */
-  if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF
+  if (type->code () == TYPE_CODE_TYPEDEF
       && (TYPE_MAIN_TYPE (ada_typedef_target_type (type))
          == TYPE_MAIN_TYPE (fixed_type)))
     return type;
@@ -9032,7 +8660,7 @@ to_static_fixed_type (struct type *type0)
 
   type0 = ada_check_typedef (type0);
 
-  switch (TYPE_CODE (type0))
+  switch (type0->code ())
     {
     default:
       return type0;
@@ -9058,9 +8686,9 @@ static_unwrap_type (struct type *type)
 {
   if (ada_is_aligner_type (type))
     {
-      struct type *type1 = TYPE_FIELD_TYPE (ada_check_typedef (type), 0);
+      struct type *type1 = ada_check_typedef (type)->field (0).type ();
       if (ada_type_name (type1) == NULL)
-        TYPE_NAME (type1) = ada_type_name (type);
+       type1->set_name (ada_type_name (type));
 
       return static_unwrap_type (type1);
     }
@@ -9105,13 +8733,13 @@ ada_check_typedef (struct type *type)
     return type;
 
   type = check_typedef (type);
-  if (type == NULL || TYPE_CODE (type) != TYPE_CODE_ENUM
+  if (type == NULL || type->code () != TYPE_CODE_ENUM
       || !TYPE_STUB (type)
-      || TYPE_NAME (type) == NULL)
+      || type->name () == NULL)
     return type;
   else
     {
-      const char *name = TYPE_NAME (type);
+      const char *name = type->name ();
       struct type *type1 = ada_find_any_type (name);
 
       if (type1 == NULL)
@@ -9121,7 +8749,7 @@ ada_check_typedef (struct type *type)
         stubs pointing to arrays, as we don't create symbols for array
         types, only for the typedef-to-array types).  If that's the case,
         strip the typedef layer.  */
-      if (TYPE_CODE (type1) == TYPE_CODE_TYPEDEF)
+      if (type1->code () == TYPE_CODE_TYPEDEF)
        type1 = ada_check_typedef (type1);
 
       return type1;
@@ -9189,7 +8817,7 @@ static const char *attribute_names[] = {
   0
 };
 
-const char *
+static const char *
 ada_attribute_name (enum exp_opcode n)
 {
   if (n >= OP_ATR_FIRST && n <= (int) OP_ATR_VAL)
@@ -9224,6 +8852,21 @@ value_pos_atr (struct type *type, struct value *arg)
 
 /* Evaluate the TYPE'VAL attribute applied to ARG.  */
 
+static struct value *
+val_atr (struct type *type, LONGEST val)
+{
+  gdb_assert (discrete_type_p (type));
+  if (type->code () == TYPE_CODE_RANGE)
+    type = TYPE_TARGET_TYPE (type);
+  if (type->code () == TYPE_CODE_ENUM)
+    {
+      if (val < 0 || val >= type->num_fields ())
+        error (_("argument to 'VAL out of range"));
+      val = TYPE_FIELD_ENUMVAL (type, val);
+    }
+  return value_from_longest (type, val);
+}
+
 static struct value *
 value_val_atr (struct type *type, struct value *arg)
 {
@@ -9232,16 +8875,7 @@ value_val_atr (struct type *type, struct value *arg)
   if (!integer_type_p (value_type (arg)))
     error (_("'VAL requires integral argument"));
 
-  if (TYPE_CODE (type) == TYPE_CODE_ENUM)
-    {
-      long pos = value_as_long (arg);
-
-      if (pos < 0 || pos >= TYPE_NFIELDS (type))
-        error (_("argument to 'VAL out of range"));
-      return value_from_longest (type, TYPE_FIELD_ENUMVAL (type, pos));
-    }
-  else
-    return value_from_longest (type, value_as_long (arg));
+  return val_atr (type, value_as_long (arg));
 }
 \f
 
@@ -9258,15 +8892,15 @@ ada_is_character_type (struct type *type)
 
   /* If the type code says it's a character, then assume it really is,
      and don't check any further.  */
-  if (TYPE_CODE (type) == TYPE_CODE_CHAR)
+  if (type->code () == TYPE_CODE_CHAR)
     return true;
   
   /* Otherwise, assume it's a character type iff it is a discrete type
      with a known character type name.  */
   name = ada_type_name (type);
   return (name != NULL
-          && (TYPE_CODE (type) == TYPE_CODE_INT
-              || TYPE_CODE (type) == TYPE_CODE_RANGE)
+          && (type->code () == TYPE_CODE_INT
+              || type->code () == TYPE_CODE_RANGE)
           && (strcmp (name, "character") == 0
               || strcmp (name, "wide_character") == 0
               || strcmp (name, "wide_wide_character") == 0
@@ -9280,7 +8914,7 @@ ada_is_string_type (struct type *type)
 {
   type = ada_check_typedef (type);
   if (type != NULL
-      && TYPE_CODE (type) != TYPE_CODE_PTR
+      && type->code () != TYPE_CODE_PTR
       && (ada_is_simple_array_type (type)
           || ada_is_array_descriptor_type (type))
       && ada_array_arity (type) == 1)
@@ -9302,7 +8936,7 @@ ada_is_string_type (struct type *type)
 
    Set to True if the debugger should trust the contents of PAD types.
    Otherwise, ignore the PAD type if there is a parallel XVS type.  */
-static int trust_pad_over_xvs = 1;
+static bool trust_pad_over_xvs = true;
 
 /* True if TYPE is a struct type introduced by the compiler to force the
    alignment of a value.  Such types have a single field with a
@@ -9316,8 +8950,8 @@ ada_is_aligner_type (struct type *type)
   if (!trust_pad_over_xvs && ada_find_parallel_type (type, "___XVS") != NULL)
     return 0;
 
-  return (TYPE_CODE (type) == TYPE_CODE_STRUCT
-          && TYPE_NFIELDS (type) == 1
+  return (type->code () == TYPE_CODE_STRUCT
+          && type->num_fields () == 1
           && strcmp (TYPE_FIELD_NAME (type, 0), "F") == 0);
 }
 
@@ -9330,7 +8964,7 @@ ada_get_base_type (struct type *raw_type)
   struct type *real_type_namer;
   struct type *raw_real_type;
 
-  if (raw_type == NULL || TYPE_CODE (raw_type) != TYPE_CODE_STRUCT)
+  if (raw_type == NULL || raw_type->code () != TYPE_CODE_STRUCT)
     return raw_type;
 
   if (ada_is_aligner_type (raw_type))
@@ -9350,14 +8984,14 @@ ada_get_base_type (struct type *raw_type)
 
   real_type_namer = ada_find_parallel_type (raw_type, "___XVS");
   if (real_type_namer == NULL
-      || TYPE_CODE (real_type_namer) != TYPE_CODE_STRUCT
-      || TYPE_NFIELDS (real_type_namer) != 1)
+      || real_type_namer->code () != TYPE_CODE_STRUCT
+      || real_type_namer->num_fields () != 1)
     return raw_type;
 
-  if (TYPE_CODE (TYPE_FIELD_TYPE (real_type_namer, 0)) != TYPE_CODE_REF)
+  if (real_type_namer->field (0).type ()->code () != TYPE_CODE_REF)
     {
       /* This is an older encoding form where the base type needs to be
-        looked up by name.  We prefer the newer enconding because it is
+        looked up by name.  We prefer the newer encoding because it is
         more efficient.  */
       raw_real_type = ada_find_any_type (TYPE_FIELD_NAME (real_type_namer, 0));
       if (raw_real_type == NULL)
@@ -9367,7 +9001,7 @@ ada_get_base_type (struct type *raw_type)
     }
 
   /* The field in our XVS type is a reference to the base type.  */
-  return TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (real_type_namer, 0));
+  return TYPE_TARGET_TYPE (real_type_namer->field (0).type ());
 }
 
 /* The type of value designated by TYPE, with all aligners removed.  */
@@ -9376,7 +9010,7 @@ struct type *
 ada_aligned_type (struct type *type)
 {
   if (ada_is_aligner_type (type))
-    return ada_aligned_type (TYPE_FIELD_TYPE (type, 0));
+    return ada_aligned_type (type->field (0).type ());
   else
     return ada_get_base_type (type);
 }
@@ -9389,7 +9023,7 @@ const gdb_byte *
 ada_aligned_value_addr (struct type *type, const gdb_byte *valaddr)
 {
   if (ada_is_aligner_type (type))
-    return ada_aligned_value_addr (TYPE_FIELD_TYPE (type, 0),
+    return ada_aligned_value_addr (type->field (0).type (),
                                    valaddr +
                                    TYPE_FIELD_BITPOS (type,
                                                       0) / TARGET_CHAR_BIT);
@@ -9440,6 +9074,14 @@ ada_enum_name (const char *name)
           if (sscanf (name + 2, "%x", &v) != 1)
             return name;
         }
+      else if (((name[1] >= '0' && name[1] <= '9')
+               || (name[1] >= 'a' && name[1] <= 'z'))
+              && name[2] == '\0')
+       {
+         GROW_VECT (result, result_len, 4);
+         xsnprintf (result, result_len, "'%c'", name[1]);
+         return result;
+       }
       else
         return name;
 
@@ -9494,7 +9136,7 @@ unwrap_value (struct value *val)
       struct type *val_type = ada_check_typedef (value_type (v));
 
       if (ada_type_name (val_type) == NULL)
-        TYPE_NAME (val_type) = ada_type_name (type);
+       val_type->set_name (ada_type_name (type));
 
       return unwrap_value (v);
     }
@@ -9534,7 +9176,7 @@ cast_to_fixed (struct type *type, struct value *arg)
     return arg;
 
   struct value *scale = ada_scaling_factor (type);
-  if (ada_is_fixed_point_type (value_type (arg)))
+  if (ada_is_gnat_encoded_fixed_point_type (value_type (arg)))
     arg = cast_from_fixed (value_type (scale), arg);
   else
     arg = value_cast (value_type (scale), arg);
@@ -9585,9 +9227,9 @@ ada_promote_array_of_integrals (struct type *type, struct value *val)
   /* Verify that both val and type are arrays of scalars, and
      that the size of val's elements is smaller than the size
      of type's element.  */
-  gdb_assert (TYPE_CODE (type) == TYPE_CODE_ARRAY);
+  gdb_assert (type->code () == TYPE_CODE_ARRAY);
   gdb_assert (is_integral_type (TYPE_TARGET_TYPE (type)));
-  gdb_assert (TYPE_CODE (value_type (val)) == TYPE_CODE_ARRAY);
+  gdb_assert (value_type (val)->code () == TYPE_CODE_ARRAY);
   gdb_assert (is_integral_type (TYPE_TARGET_TYPE (value_type (val))));
   gdb_assert (TYPE_LENGTH (TYPE_TARGET_TYPE (type))
              > TYPE_LENGTH (TYPE_TARGET_TYPE (value_type (val))));
@@ -9623,15 +9265,15 @@ coerce_for_assign (struct type *type, struct value *val)
   type2 = ada_check_typedef (type2);
   type = ada_check_typedef (type);
 
-  if (TYPE_CODE (type2) == TYPE_CODE_PTR
-      && TYPE_CODE (type) == TYPE_CODE_ARRAY)
+  if (type2->code () == TYPE_CODE_PTR
+      && type->code () == TYPE_CODE_ARRAY)
     {
       val = ada_value_ind (val);
       type2 = value_type (val);
     }
 
-  if (TYPE_CODE (type2) == TYPE_CODE_ARRAY
-      && TYPE_CODE (type) == TYPE_CODE_ARRAY)
+  if (type2->code () == TYPE_CODE_ARRAY
+      && type->code () == TYPE_CODE_ARRAY)
     {
       if (!ada_same_array_size_p (type, type2))
        error (_("cannot assign arrays of different length"));
@@ -9666,8 +9308,8 @@ ada_value_binop (struct value *arg1, struct value *arg2, enum exp_opcode op)
   type1 = get_base_type (ada_check_typedef (value_type (arg1)));
   type2 = get_base_type (ada_check_typedef (value_type (arg2)));
 
-  if (TYPE_CODE (type1) != TYPE_CODE_INT
-      || TYPE_CODE (type2) != TYPE_CODE_INT)
+  if (type1->code () != TYPE_CODE_INT
+      || type2->code () != TYPE_CODE_INT)
     return value_binop (arg1, arg2, op);
 
   switch (op)
@@ -9708,7 +9350,7 @@ ada_value_binop (struct value *arg1, struct value *arg2, enum exp_opcode op)
   val = allocate_value (type1);
   store_unsigned_integer (value_contents_raw (val),
                           TYPE_LENGTH (value_type (val)),
-                         gdbarch_byte_order (get_type_arch (type1)), v);
+                         type_byte_order (type1), v);
   return val;
 }
 
@@ -9731,8 +9373,8 @@ ada_value_equal (struct value *arg1, struct value *arg2)
       arg1_type = ada_check_typedef (value_type (arg1));
       arg2_type = ada_check_typedef (value_type (arg2));
 
-      if (TYPE_CODE (arg1_type) != TYPE_CODE_ARRAY
-          || TYPE_CODE (arg2_type) != TYPE_CODE_ARRAY)
+      if (arg1_type->code () != TYPE_CODE_ARRAY
+          || arg2_type->code () != TYPE_CODE_ARRAY)
         error (_("Attempt to compare array with non-array"));
       /* FIXME: The following works only for types whose
          representations use all bits (no padding or undefined bits)
@@ -9786,7 +9428,7 @@ assign_component (struct value *container, struct value *lhs, LONGEST index,
   struct value *elt;
   struct type *lhs_type = check_typedef (value_type (lhs));
 
-  if (TYPE_CODE (lhs_type) == TYPE_CODE_ARRAY)
+  if (lhs_type->code () == TYPE_CODE_ARRAY)
     {
       struct type *index_type = builtin_type (exp->gdbarch)->builtin_int;
       struct value *index_val = value_from_longest (index_type, index);
@@ -9853,7 +9495,7 @@ assign_aggregate (struct value *container,
       low_index = TYPE_ARRAY_LOWER_BOUND_VALUE (lhs_type);
       high_index = TYPE_ARRAY_UPPER_BOUND_VALUE (lhs_type);
     }
-  else if (TYPE_CODE (lhs_type) == TYPE_CODE_STRUCT)
+  else if (lhs_type->code () == TYPE_CODE_STRUCT)
     {
       low_index = 0;
       high_index = num_visible_fields (lhs_type) - 1;
@@ -9975,7 +9617,7 @@ aggregate_assign_from_choices (struct value *container,
              name = &exp->elts[choice_pos + 2].string;
              break;
            case OP_VAR_VALUE:
-             name = SYMBOL_NATURAL_NAME (exp->elts[choice_pos + 2].symbol);
+             name = exp->elts[choice_pos + 2].symbol->natural_name ();
              break;
            default:
              error (_("Invalid record component association."));
@@ -10082,10 +9724,10 @@ ada_value_cast (struct type *type, struct value *arg2)
   if (type == ada_check_typedef (value_type (arg2)))
     return arg2;
 
-  if (ada_is_fixed_point_type (type))
+  if (ada_is_gnat_encoded_fixed_point_type (type))
     return cast_to_fixed (type, arg2);
 
-  if (ada_is_fixed_point_type (value_type (arg2)))
+  if (ada_is_gnat_encoded_fixed_point_type (value_type (arg2)))
     return cast_from_fixed (type, arg2);
 
   return value_cast (type, arg2);
@@ -10146,7 +9788,7 @@ ada_value_cast (struct type *type, struct value *arg2)
     information nor the associated type structure in GDB are able to
     express such dynamic types.  So what the debugger does is to create
     "fixed" versions of the type that applies to the specific object.
-    We also informally refer to this opperation as "fixing" an object,
+    We also informally refer to this operation as "fixing" an object,
     which means creating its associated fixed type.
 
     Example: when printing the value of variable "Yes" above, its fixed
@@ -10447,8 +10089,8 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
         result = evaluate_subexp_standard (expect_type, exp, pos, noside);
         /* The result type will have code OP_STRING, bashed there from 
            OP_ARRAY.  Bash it back.  */
-        if (TYPE_CODE (value_type (result)) == TYPE_CODE_STRING)
-          TYPE_CODE (value_type (result)) = TYPE_CODE_ARRAY;
+        if (value_type (result)->code () == TYPE_CODE_STRING)
+          value_type (result)->set_code (TYPE_CODE_ARRAY);
         return result;
       }
 
@@ -10485,9 +10127,9 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
        {
          /* Nothing.  */
        }
-      else if (ada_is_fixed_point_type (value_type (arg1)))
+      else if (ada_is_gnat_encoded_fixed_point_type (value_type (arg1)))
         arg2 = cast_to_fixed (value_type (arg1), arg2);
-      else if (ada_is_fixed_point_type (value_type (arg2)))
+      else if (ada_is_gnat_encoded_fixed_point_type (value_type (arg2)))
         error
           (_("Fixed-point values must be assigned to fixed-point variables"));
       else
@@ -10499,23 +10141,23 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
       arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
       if (noside == EVAL_SKIP)
         goto nosideret;
-      if (TYPE_CODE (value_type (arg1)) == TYPE_CODE_PTR)
+      if (value_type (arg1)->code () == TYPE_CODE_PTR)
         return (value_from_longest
                  (value_type (arg1),
                   value_as_long (arg1) + value_as_long (arg2)));
-      if (TYPE_CODE (value_type (arg2)) == TYPE_CODE_PTR)
+      if (value_type (arg2)->code () == TYPE_CODE_PTR)
         return (value_from_longest
                  (value_type (arg2),
                   value_as_long (arg1) + value_as_long (arg2)));
-      if ((ada_is_fixed_point_type (value_type (arg1))
-           || ada_is_fixed_point_type (value_type (arg2)))
+      if ((ada_is_gnat_encoded_fixed_point_type (value_type (arg1))
+           || ada_is_gnat_encoded_fixed_point_type (value_type (arg2)))
           && value_type (arg1) != value_type (arg2))
         error (_("Operands of fixed-point addition must have the same type"));
       /* Do the addition, and cast the result to the type of the first
          argument.  We cannot cast the result to a reference type, so if
          ARG1 is a reference type, find its underlying type.  */
       type = value_type (arg1);
-      while (TYPE_CODE (type) == TYPE_CODE_REF)
+      while (type->code () == TYPE_CODE_REF)
         type = TYPE_TARGET_TYPE (type);
       binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
       return value_cast (type, value_binop (arg1, arg2, BINOP_ADD));
@@ -10525,16 +10167,16 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
       arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
       if (noside == EVAL_SKIP)
         goto nosideret;
-      if (TYPE_CODE (value_type (arg1)) == TYPE_CODE_PTR)
+      if (value_type (arg1)->code () == TYPE_CODE_PTR)
         return (value_from_longest
                  (value_type (arg1),
                   value_as_long (arg1) - value_as_long (arg2)));
-      if (TYPE_CODE (value_type (arg2)) == TYPE_CODE_PTR)
+      if (value_type (arg2)->code () == TYPE_CODE_PTR)
         return (value_from_longest
                  (value_type (arg2),
                   value_as_long (arg1) - value_as_long (arg2)));
-      if ((ada_is_fixed_point_type (value_type (arg1))
-           || ada_is_fixed_point_type (value_type (arg2)))
+      if ((ada_is_gnat_encoded_fixed_point_type (value_type (arg1))
+           || ada_is_gnat_encoded_fixed_point_type (value_type (arg2)))
           && value_type (arg1) != value_type (arg2))
         error (_("Operands of fixed-point subtraction "
                 "must have the same type"));
@@ -10542,7 +10184,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
          argument.  We cannot cast the result to a reference type, so if
          ARG1 is a reference type, find its underlying type.  */
       type = value_type (arg1);
-      while (TYPE_CODE (type) == TYPE_CODE_REF)
+      while (type->code () == TYPE_CODE_REF)
         type = TYPE_TARGET_TYPE (type);
       binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
       return value_cast (type, value_binop (arg1, arg2, BINOP_SUB));
@@ -10563,9 +10205,9 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
       else
         {
           type = builtin_type (exp->gdbarch)->builtin_double;
-          if (ada_is_fixed_point_type (value_type (arg1)))
+          if (ada_is_gnat_encoded_fixed_point_type (value_type (arg1)))
             arg1 = cast_from_fixed (type, arg1);
-          if (ada_is_fixed_point_type (value_type (arg2)))
+          if (ada_is_gnat_encoded_fixed_point_type (value_type (arg2)))
             arg2 = cast_from_fixed (type, arg2);
           binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
           return ada_value_binop (arg1, arg2, op);
@@ -10593,7 +10235,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
       if (noside == EVAL_SKIP)
         goto nosideret;
-      else if (ada_is_fixed_point_type (value_type (arg1)))
+      else if (ada_is_gnat_encoded_fixed_point_type (value_type (arg1)))
         return value_cast (value_type (arg1), value_neg (arg1));
       else
        {
@@ -10640,7 +10282,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
            context other than a function call, in which case, it is
            invalid.  */
         error (_("Unexpected unresolved symbol, %s, during evaluation"),
-               SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol));
+               exp->elts[pc + 2].symbol->print_name ());
 
       if (noside == EVAL_AVOID_SIDE_EFFECTS)
         {
@@ -10651,7 +10293,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
              The latter should be shown as usual (as a pointer), whereas
              a reference should mostly be transparent to the user.  */
           if (ada_is_tagged_type (type, 0)
-              || (TYPE_CODE (type) == TYPE_CODE_REF
+              || (type->code () == TYPE_CODE_REF
                   && ada_is_tagged_type (TYPE_TARGET_TYPE (type), 0)))
            {
              /* Tagged types are a little special in the fact that the real
@@ -10673,7 +10315,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
                 type in the type description.  */
              arg1 = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_NORMAL);
 
-             if (TYPE_CODE (type) != TYPE_CODE_REF)
+             if (type->code () != TYPE_CODE_REF)
                {
                  struct type *actual_type;
 
@@ -10706,9 +10348,9 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
             For instance, a case statement in a variant record would be
             replaced by the relevant components based on the actual
             value of the discriminants.  */
-         if ((TYPE_CODE (type) == TYPE_CODE_STRUCT
+         if ((type->code () == TYPE_CODE_STRUCT
               && dynamic_template_type (type) != NULL)
-             || (TYPE_CODE (type) == TYPE_CODE_UNION
+             || (type->code () == TYPE_CODE_UNION
                  && ada_find_parallel_type (type, "___XVU") != NULL))
            {
              *pos += 4;
@@ -10730,7 +10372,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
       if (exp->elts[*pos].opcode == OP_VAR_VALUE
           && SYMBOL_DOMAIN (exp->elts[pc + 5].symbol) == UNDEF_DOMAIN)
         error (_("Unexpected unresolved symbol, %s, during evaluation"),
-               SYMBOL_PRINT_NAME (exp->elts[pc + 5].symbol));
+               exp->elts[pc + 5].symbol->print_name ());
       else
         {
           for (tem = 0; tem <= nargs; tem += 1)
@@ -10744,13 +10386,13 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
       if (ada_is_constrained_packed_array_type
          (desc_base_type (value_type (argvec[0]))))
         argvec[0] = ada_coerce_to_simple_array (argvec[0]);
-      else if (TYPE_CODE (value_type (argvec[0])) == TYPE_CODE_ARRAY
+      else if (value_type (argvec[0])->code () == TYPE_CODE_ARRAY
                && TYPE_FIELD_BITSIZE (value_type (argvec[0]), 0) != 0)
         /* This is a packed array that has already been fixed, and
           therefore already coerced to a simple array.  Nothing further
           to do.  */
         ;
-      else if (TYPE_CODE (value_type (argvec[0])) == TYPE_CODE_REF)
+      else if (value_type (argvec[0])->code () == TYPE_CODE_REF)
        {
          /* Make sure we dereference references so that all the code below
             feels like it's really handling the referenced value.  Wrapping
@@ -10758,7 +10400,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
             well.  */
          argvec[0] = ada_to_fixed_value (coerce_ref (argvec[0]));
        }
-      else if (TYPE_CODE (value_type (argvec[0])) == TYPE_CODE_ARRAY
+      else if (value_type (argvec[0])->code () == TYPE_CODE_ARRAY
               && VALUE_LVAL (argvec[0]) == lval_memory)
        argvec[0] = value_addr (argvec[0]);
 
@@ -10767,12 +10409,12 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
       /* Ada allows us to implicitly dereference arrays when subscripting
         them.  So, if this is an array typedef (encoding use for array
         access types encoded as fat pointers), strip it now.  */
-      if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
+      if (type->code () == TYPE_CODE_TYPEDEF)
        type = ada_typedef_target_type (type);
 
-      if (TYPE_CODE (type) == TYPE_CODE_PTR)
+      if (type->code () == TYPE_CODE_PTR)
         {
-          switch (TYPE_CODE (ada_check_typedef (TYPE_TARGET_TYPE (type))))
+          switch (ada_check_typedef (TYPE_TARGET_TYPE (type))->code ())
             {
             case TYPE_CODE_FUNC:
               type = ada_check_typedef (TYPE_TARGET_TYPE (type));
@@ -10791,7 +10433,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
             }
         }
 
-      switch (TYPE_CODE (type))
+      switch (type->code ())
         {
         case TYPE_CODE_FUNC:
           if (noside == EVAL_AVOID_SIDE_EFFECTS)
@@ -10882,7 +10524,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
 
         /* If this is a reference to an aligner type, then remove all
            the aligners.  */
-        if (TYPE_CODE (value_type (array)) == TYPE_CODE_REF
+        if (value_type (array)->code () == TYPE_CODE_REF
             && ada_is_aligner_type (TYPE_TARGET_TYPE (value_type (array))))
           TYPE_TARGET_TYPE (value_type (array)) =
             ada_aligned_type (TYPE_TARGET_TYPE (value_type (array)));
@@ -10892,8 +10534,8 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
 
         /* If this is a reference to an array or an array lvalue,
            convert to a pointer.  */
-        if (TYPE_CODE (value_type (array)) == TYPE_CODE_REF
-            || (TYPE_CODE (value_type (array)) == TYPE_CODE_ARRAY
+        if (value_type (array)->code () == TYPE_CODE_REF
+            || (value_type (array)->code () == TYPE_CODE_ARRAY
                 && VALUE_LVAL (array) == lval_memory))
           array = value_addr (array);
 
@@ -10907,8 +10549,8 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
 
         /* If we have more than one level of pointer indirection,
            dereference the value until we get only one level.  */
-        while (TYPE_CODE (value_type (array)) == TYPE_CODE_PTR
-               && (TYPE_CODE (TYPE_TARGET_TYPE (value_type (array)))
+        while (value_type (array)->code () == TYPE_CODE_PTR
+               && (TYPE_TARGET_TYPE (value_type (array))->code ()
                      == TYPE_CODE_PTR))
           array = value_ind (array);
 
@@ -10919,7 +10561,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
         if (!ada_is_simple_array_type (value_type (array)))
           error (_("cannot take slice of non-array"));
 
-        if (TYPE_CODE (ada_check_typedef (value_type (array)))
+        if (ada_check_typedef (value_type (array))->code ()
             == TYPE_CODE_PTR)
           {
             struct type *type0 = ada_check_typedef (value_type (array));
@@ -10953,7 +10595,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
       if (noside == EVAL_SKIP)
         goto nosideret;
 
-      switch (TYPE_CODE (type))
+      switch (type->code ())
         {
         default:
           lim_warning (_("Membership test incompletely implemented; "
@@ -11116,7 +10758,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
             const char *name = ada_type_name (type_arg);
 
             range_type = NULL;
-            if (name != NULL && TYPE_CODE (type_arg) != TYPE_CODE_ENUM)
+            if (name != NULL && type_arg->code () != TYPE_CODE_ENUM)
               range_type = to_fixed_range_type (type_arg, NULL);
             if (range_type == NULL)
               range_type = type_arg;
@@ -11134,7 +10776,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
                 error (_("the 'length attribute applies only to array types"));
               }
           }
-        else if (TYPE_CODE (type_arg) == TYPE_CODE_FLT)
+        else if (type_arg->code () == TYPE_CODE_FLT)
           error (_("unimplemented type attribute"));
         else
           {
@@ -11230,7 +10872,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
       /* If the argument is a reference, then dereference its type, since
          the user is really asking for the size of the actual object,
          not the size of the pointer.  */
-      if (TYPE_CODE (type) == TYPE_CODE_REF)
+      if (type->code () == TYPE_CODE_REF)
         type = TYPE_TARGET_TYPE (type);
 
       if (noside == EVAL_SKIP)
@@ -11305,18 +10947,18 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
                 error (_("Attempt to dereference null array pointer."));
               return value_at_lazy (arrType, 0);
             }
-          else if (TYPE_CODE (type) == TYPE_CODE_PTR
-                   || TYPE_CODE (type) == TYPE_CODE_REF
+          else if (type->code () == TYPE_CODE_PTR
+                   || type->code () == TYPE_CODE_REF
                    /* In C you can dereference an array to get the 1st elt.  */
-                   || TYPE_CODE (type) == TYPE_CODE_ARRAY)
+                   || type->code () == TYPE_CODE_ARRAY)
             {
             /* As mentioned in the OP_VAR_VALUE case, tagged types can
                only be determined by inspecting the object's tag.
                This means that we need to evaluate completely the
                expression in order to get its type.  */
 
-             if ((TYPE_CODE (type) == TYPE_CODE_REF
-                  || TYPE_CODE (type) == TYPE_CODE_PTR)
+             if ((type->code () == TYPE_CODE_REF
+                  || type->code () == TYPE_CODE_PTR)
                  && ada_is_tagged_type (TYPE_TARGET_TYPE (type), 0))
                {
                  arg1 = evaluate_subexp (NULL_TYPE, exp, &preeval_pos,
@@ -11332,7 +10974,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
              ada_ensure_varsize_limit (type);
               return value_zero (type, lval_memory);
             }
-          else if (TYPE_CODE (type) == TYPE_CODE_INT)
+          else if (type->code () == TYPE_CODE_INT)
            {
              /* GDB allows dereferencing an int.  */
              if (expect_type == NULL)
@@ -11351,7 +10993,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
       arg1 = ada_coerce_ref (arg1);     /* FIXME: What is this for??  */
       type = ada_check_typedef (value_type (arg1));
 
-      if (TYPE_CODE (type) == TYPE_CODE_INT)
+      if (type->code () == TYPE_CODE_INT)
           /* GDB allows dereferencing an int.  If we were given
              the expect_type, then use that as the target type.
              Otherwise, assume that the target type is an int.  */
@@ -11465,10 +11107,10 @@ nosideret:
    Otherwise, return NULL.  */
 
 static const char *
-fixed_type_info (struct type *type)
+gnat_encoded_fixed_type_info (struct type *type)
 {
   const char *name = ada_type_name (type);
-  enum type_code code = (type == NULL) ? TYPE_CODE_UNDEF : TYPE_CODE (type);
+  enum type_code code = (type == NULL) ? TYPE_CODE_UNDEF : type->code ();
 
   if ((code == TYPE_CODE_INT || code == TYPE_CODE_RANGE) && name != NULL)
     {
@@ -11480,7 +11122,7 @@ fixed_type_info (struct type *type)
         return tail + 5;
     }
   else if (code == TYPE_CODE_RANGE && TYPE_TARGET_TYPE (type) != type)
-    return fixed_type_info (TYPE_TARGET_TYPE (type));
+    return gnat_encoded_fixed_type_info (TYPE_TARGET_TYPE (type));
   else
     return NULL;
 }
@@ -11488,9 +11130,9 @@ fixed_type_info (struct type *type)
 /* Returns non-zero iff TYPE represents an Ada fixed-point type.  */
 
 int
-ada_is_fixed_point_type (struct type *type)
+ada_is_gnat_encoded_fixed_point_type (struct type *type)
 {
-  return fixed_type_info (type) != NULL;
+  return gnat_encoded_fixed_type_info (type) != NULL;
 }
 
 /* Return non-zero iff TYPE represents a System.Address type.  */
@@ -11498,8 +11140,7 @@ ada_is_fixed_point_type (struct type *type)
 int
 ada_is_system_address_type (struct type *type)
 {
-  return (TYPE_NAME (type)
-          && strcmp (TYPE_NAME (type), "system__address") == 0);
+  return (type->name () && strcmp (type->name (), "system__address") == 0);
 }
 
 /* Assuming that TYPE is the representation of an Ada fixed-point
@@ -11517,9 +11158,9 @@ ada_scaling_type (struct type *type)
    delta cannot be determined.  */
 
 struct value *
-ada_delta (struct type *type)
+gnat_encoded_fixed_point_delta (struct type *type)
 {
-  const char *encoding = fixed_type_info (type);
+  const char *encoding = gnat_encoded_fixed_type_info (type);
   struct type *scale_type = ada_scaling_type (type);
 
   long long num, den;
@@ -11531,13 +11172,13 @@ ada_delta (struct type *type)
                        value_from_longest (scale_type, den), BINOP_DIV);
 }
 
-/* Assuming that ada_is_fixed_point_type (TYPE), return the scaling
-   factor ('SMALL value) associated with the type.  */
+/* Assuming that ada_is_gnat_encoded_fixed_point_type (TYPE), return
+   the scaling factor ('SMALL value) associated with the type.  */
 
 struct value *
 ada_scaling_factor (struct type *type)
 {
-  const char *encoding = fixed_type_info (type);
+  const char *encoding = gnat_encoded_fixed_type_info (type);
   struct type *scale_type = ada_scaling_type (type);
 
   long long num0, den0, num1, den1;
@@ -11667,14 +11308,14 @@ to_fixed_range_type (struct type *raw_type, struct value *dval)
   const char *subtype_info;
 
   gdb_assert (raw_type != NULL);
-  gdb_assert (TYPE_NAME (raw_type) != NULL);
+  gdb_assert (raw_type->name () != NULL);
 
-  if (TYPE_CODE (raw_type) == TYPE_CODE_RANGE)
+  if (raw_type->code () == TYPE_CODE_RANGE)
     base_type = TYPE_TARGET_TYPE (raw_type);
   else
     base_type = raw_type;
 
-  name = TYPE_NAME (raw_type);
+  name = raw_type->name ();
   subtype_info = strstr (name, "___XD");
   if (subtype_info == NULL)
     {
@@ -11748,7 +11389,7 @@ to_fixed_range_type (struct type *raw_type, struct value *dval)
          to match the size of the base_type, which is not what we want.
          Set it back to the original range type's length.  */
       TYPE_LENGTH (type) = TYPE_LENGTH (raw_type);
-      TYPE_NAME (type) = name;
+      type->set_name (name);
       return type;
     }
 }
@@ -11771,8 +11412,8 @@ ada_is_modular_type (struct type *type)
 {
   struct type *subranged_type = get_base_type (type);
 
-  return (subranged_type != NULL && TYPE_CODE (type) == TYPE_CODE_RANGE
-          && TYPE_CODE (subranged_type) == TYPE_CODE_INT
+  return (subranged_type != NULL && type->code () == TYPE_CODE_RANGE
+          && subranged_type->code () == TYPE_CODE_INT
           && TYPE_UNSIGNED (subranged_type));
 }
 
@@ -11867,9 +11508,22 @@ static CORE_ADDR ada_unhandled_exception_name_addr_from_raise (void);
 
 /* The following exception support info structure describes how to
    implement exception catchpoints with the latest version of the
-   Ada runtime (as of 2007-03-06).  */
+   Ada runtime (as of 2019-08-??).  */
 
 static const struct exception_support_info default_exception_support_info =
+{
+  "__gnat_debug_raise_exception", /* catch_exception_sym */
+  "__gnat_unhandled_exception", /* catch_exception_unhandled_sym */
+  "__gnat_debug_raise_assert_failure", /* catch_assert_sym */
+  "__gnat_begin_handler_v1", /* catch_handlers_sym */
+  ada_unhandled_exception_name_addr
+};
+
+/* The following exception support info structure describes how to
+   implement exception catchpoints with an earlier version of the
+   Ada runtime (as of 2007-03-06) using v0 of the EH ABI.  */
+
+static const struct exception_support_info exception_support_info_v0 =
 {
   "__gnat_debug_raise_exception", /* catch_exception_sym */
   "__gnat_unhandled_exception", /* catch_exception_unhandled_sym */
@@ -11938,8 +11592,34 @@ ada_has_this_exception_support (const struct exception_support_info *einfo)
   /* Make sure that the symbol we found corresponds to a function.  */
 
   if (SYMBOL_CLASS (sym) != LOC_BLOCK)
-    error (_("Symbol \"%s\" is not a function (class = %d)"),
-           SYMBOL_LINKAGE_NAME (sym), SYMBOL_CLASS (sym));
+    {
+      error (_("Symbol \"%s\" is not a function (class = %d)"),
+            sym->linkage_name (), SYMBOL_CLASS (sym));
+      return 0;
+    }
+
+  sym = standard_lookup (einfo->catch_handlers_sym, NULL, VAR_DOMAIN);
+  if (sym == NULL)
+    {
+      struct bound_minimal_symbol msym
+       = lookup_minimal_symbol (einfo->catch_handlers_sym, NULL, NULL);
+
+      if (msym.minsym && MSYMBOL_TYPE (msym.minsym) != mst_solib_trampoline)
+       error (_("Your Ada runtime appears to be missing some debugging "
+                "information.\nCannot insert Ada exception catchpoint "
+                "in this configuration."));
+
+      return 0;
+    }
+
+  /* Make sure that the symbol we found corresponds to a function.  */
+
+  if (SYMBOL_CLASS (sym) != LOC_BLOCK)
+    {
+      error (_("Symbol \"%s\" is not a function (class = %d)"),
+            sym->linkage_name (), SYMBOL_CLASS (sym));
+      return 0;
+    }
 
   return 1;
 }
@@ -11966,6 +11646,13 @@ ada_exception_support_info_sniffer (void)
       return;
     }
 
+  /* Try the v0 exception suport info.  */
+  if (ada_has_this_exception_support (&exception_support_info_v0))
+    {
+      data->exception_info = &exception_support_info_v0;
+      return;
+    }
+
   /* Try our fallback exception suport info.  */
   if (ada_has_this_exception_support (&exception_support_info_fallback))
     {
@@ -12029,7 +11716,7 @@ is_known_support_routine (struct frame_info *frame)
   if (access (fullname, R_OK) != 0)
     return 1;
 
-  /* Check the unit filename againt the Ada runtime file naming.
+  /* Check the unit filename against the Ada runtime file naming.
      We also check the name of the objfile against the name of some
      known system libraries that sometimes come with debugging info
      too.  */
@@ -12208,7 +11895,8 @@ ada_exception_message_1 (void)
     return NULL;
 
   gdb::unique_xmalloc_ptr<char> e_msg ((char *) xmalloc (e_msg_len + 1));
-  read_memory_string (value_address (e_msg_val), e_msg.get (), e_msg_len + 1);
+  read_memory (value_address (e_msg_val), (gdb_byte *) e_msg.get (),
+              e_msg_len);
   e_msg.get ()[e_msg_len] = '\0';
 
   return e_msg;
@@ -12283,7 +11971,7 @@ class ada_catchpoint_location : public bp_location
 {
 public:
   ada_catchpoint_location (breakpoint *owner)
-    : bp_location (owner)
+    : bp_location (owner, bp_loc_software_breakpoint)
   {}
 
   /* The condition that checks whether the exception that was raised
@@ -12296,8 +11984,16 @@ public:
 
 struct ada_catchpoint : public breakpoint
 {
+  explicit ada_catchpoint (enum ada_exception_catchpoint_kind kind)
+    : m_kind (kind)
+  {
+  }
+
   /* The name of the specific exception the user specified.  */
   std::string excep_string;
+
+  /* What kind of catchpoint this is.  */
+  enum ada_exception_catchpoint_kind m_kind;
 };
 
 /* Parse the exception condition string in the context of each of the
@@ -12307,6 +12003,8 @@ static void
 create_excep_cond_exprs (struct ada_catchpoint *c,
                          enum ada_exception_catchpoint_kind ex)
 {
+  struct bp_location *bl;
+
   /* Nothing to do if there's no specific exception to catch.  */
   if (c->excep_string.empty ())
     return;
@@ -12315,45 +12013,28 @@ create_excep_cond_exprs (struct ada_catchpoint *c,
   if (c->loc == NULL)
     return;
 
-  /* We have to compute the expression once for each program space,
-     because the expression may hold the addresses of multiple symbols
-     in some cases.  */
-  std::multimap<program_space *, struct bp_location *> loc_map;
-  for (bp_location *bl = c->loc; bl != NULL; bl = bl->next)
-    loc_map.emplace (bl->pspace, bl);
-
-  scoped_restore_current_program_space save_pspace;
+  /* Compute the condition expression in text form, from the specific
+     expection we want to catch.  */
+  std::string cond_string
+    = ada_exception_catchpoint_cond_string (c->excep_string.c_str (), ex);
 
-  std::string cond_string;
-  program_space *last_ps = nullptr;
-  for (auto iter : loc_map)
+  /* Iterate over all the catchpoint's locations, and parse an
+     expression for each.  */
+  for (bl = c->loc; bl != NULL; bl = bl->next)
     {
       struct ada_catchpoint_location *ada_loc
-       = (struct ada_catchpoint_location *) iter.second;
-
-      if (ada_loc->pspace != last_ps)
-       {
-         last_ps = ada_loc->pspace;
-         set_current_program_space (last_ps);
-
-         /* Compute the condition expression in text form, from the
-            specific expection we want to catch.  */
-         cond_string
-           = ada_exception_catchpoint_cond_string (c->excep_string.c_str (),
-                                                   ex);
-       }
-
+       = (struct ada_catchpoint_location *) bl;
       expression_up exp;
 
-      if (!ada_loc->shlib_disabled)
+      if (!bl->shlib_disabled)
        {
          const char *s;
 
          s = cond_string.c_str ();
          try
            {
-             exp = parse_exp_1 (&s, ada_loc->address,
-                                block_for_pc (ada_loc->address),
+             exp = parse_exp_1 (&s, bl->address,
+                                block_for_pc (bl->address),
                                 0);
            }
          catch (const gdb_exception_error &e)
@@ -12372,8 +12053,7 @@ create_excep_cond_exprs (struct ada_catchpoint *c,
    structure for all exception catchpoint kinds.  */
 
 static struct bp_location *
-allocate_location_exception (enum ada_exception_catchpoint_kind ex,
-                            struct breakpoint *self)
+allocate_location_exception (struct breakpoint *self)
 {
   return new ada_catchpoint_location (self);
 }
@@ -12382,7 +12062,7 @@ allocate_location_exception (enum ada_exception_catchpoint_kind ex,
    exception catchpoint kinds.  */
 
 static void
-re_set_exception (enum ada_exception_catchpoint_kind ex, struct breakpoint *b)
+re_set_exception (struct breakpoint *b)
 {
   struct ada_catchpoint *c = (struct ada_catchpoint *) b;
 
@@ -12392,7 +12072,7 @@ re_set_exception (enum ada_exception_catchpoint_kind ex, struct breakpoint *b)
 
   /* Reparse the exception conditional expressions.  One for each
      location.  */
-  create_excep_cond_exprs (c, ex);
+  create_excep_cond_exprs (c, c->m_kind);
 }
 
 /* Returns true if we should stop for this breakpoint hit.  If the
@@ -12407,6 +12087,30 @@ should_stop_exception (const struct bp_location *bl)
     = (const struct ada_catchpoint_location *) bl;
   int stop;
 
+  struct internalvar *var = lookup_internalvar ("_ada_exception");
+  if (c->m_kind == ada_catch_assert)
+    clear_internalvar (var);
+  else
+    {
+      try
+       {
+         const char *expr;
+
+         if (c->m_kind == ada_catch_handlers)
+           expr = ("GNAT_GCC_exception_Access(gcc_exception)"
+                   ".all.occurrence.id");
+         else
+           expr = "e";
+
+         struct value *exc = parse_and_eval (expr);
+         set_internalvar (var, exc);
+       }
+      catch (const gdb_exception_error &ex)
+       {
+         clear_internalvar (var);
+       }
+    }
+
   /* With no specific exception, should always stop.  */
   if (c->excep_string.empty ())
     return 1;
@@ -12440,7 +12144,7 @@ should_stop_exception (const struct bp_location *bl)
    for all exception catchpoint kinds.  */
 
 static void
-check_status_exception (enum ada_exception_catchpoint_kind ex, bpstat bs)
+check_status_exception (bpstat bs)
 {
   bs->stop = should_stop_exception (bs->bp_location_at);
 }
@@ -12449,7 +12153,7 @@ check_status_exception (enum ada_exception_catchpoint_kind ex, bpstat bs)
    for all exception catchpoint kinds.  */
 
 static enum print_stop_action
-print_it_exception (enum ada_exception_catchpoint_kind ex, bpstat bs)
+print_it_exception (bpstat bs)
 {
   struct ui_out *uiout = current_uiout;
   struct breakpoint *b = bs->breakpoint_at;
@@ -12465,7 +12169,7 @@ print_it_exception (enum ada_exception_catchpoint_kind ex, bpstat bs)
 
   uiout->text (b->disposition == disp_del
               ? "\nTemporary catchpoint " : "\nCatchpoint ");
-  uiout->field_int ("bkptno", b->number);
+  uiout->field_signed ("bkptno", b->number);
   uiout->text (", ");
 
   /* ada_exception_name_addr relies on the selected frame being the
@@ -12475,13 +12179,14 @@ print_it_exception (enum ada_exception_catchpoint_kind ex, bpstat bs)
      ada_find_printable_frame).  */
   select_frame (get_current_frame ());
 
-  switch (ex)
+  struct ada_catchpoint *c = (struct ada_catchpoint *) b;
+  switch (c->m_kind)
     {
       case ada_catch_exception:
       case ada_catch_exception_unhandled:
       case ada_catch_handlers:
        {
-         const CORE_ADDR addr = ada_exception_name_addr (ex, b);
+         const CORE_ADDR addr = ada_exception_name_addr (c->m_kind, b);
          char exception_name[256];
 
          if (addr != 0)
@@ -12505,7 +12210,7 @@ print_it_exception (enum ada_exception_catchpoint_kind ex, bpstat bs)
             it clearer to the user which kind of catchpoint just got
             hit.  We used ui_out_text to make sure that this extra
             info does not pollute the exception name in the MI case.  */
-         if (ex == ada_catch_exception_unhandled)
+         if (c->m_kind == ada_catch_exception_unhandled)
            uiout->text ("unhandled ");
          uiout->field_string ("exception-name", exception_name);
        }
@@ -12538,23 +12243,19 @@ print_it_exception (enum ada_exception_catchpoint_kind ex, bpstat bs)
    for all exception catchpoint kinds.  */
 
 static void
-print_one_exception (enum ada_exception_catchpoint_kind ex,
-                     struct breakpoint *b, struct bp_location **last_loc)
+print_one_exception (struct breakpoint *b, struct bp_location **last_loc)
 { 
   struct ui_out *uiout = current_uiout;
   struct ada_catchpoint *c = (struct ada_catchpoint *) b;
   struct value_print_options opts;
 
   get_user_print_options (&opts);
+
   if (opts.addressprint)
-    {
-      annotate_field (4);
-      uiout->field_core_addr ("addr", b->loc->gdbarch, b->loc->address);
-    }
+    uiout->field_skip ("addr");
 
   annotate_field (5);
-  *last_loc = b->loc;
-  switch (ex)
+  switch (c->m_kind)
     {
       case ada_catch_exception:
         if (!c->excep_string.empty ())
@@ -12598,18 +12299,17 @@ print_one_exception (enum ada_exception_catchpoint_kind ex,
    for all exception catchpoint kinds.  */
 
 static void
-print_mention_exception (enum ada_exception_catchpoint_kind ex,
-                         struct breakpoint *b)
+print_mention_exception (struct breakpoint *b)
 {
   struct ada_catchpoint *c = (struct ada_catchpoint *) b;
   struct ui_out *uiout = current_uiout;
 
   uiout->text (b->disposition == disp_del ? _("Temporary catchpoint ")
                                                  : _("Catchpoint "));
-  uiout->field_int ("bkptno", b->number);
+  uiout->field_signed ("bkptno", b->number);
   uiout->text (": ");
 
-  switch (ex)
+  switch (c->m_kind)
     {
       case ada_catch_exception:
         if (!c->excep_string.empty ())
@@ -12631,246 +12331,74 @@ print_mention_exception (enum ada_exception_catchpoint_kind ex,
          {
            std::string info
              = string_printf (_("`%s' Ada exception handlers"),
-                              c->excep_string.c_str ());
-           uiout->text (info.c_str ());
-         }
-        else
-          uiout->text (_("all Ada exceptions handlers"));
-        break;
-
-      case ada_catch_assert:
-        uiout->text (_("failed Ada assertions"));
-        break;
-
-      default:
-        internal_error (__FILE__, __LINE__, _("unexpected catchpoint type"));
-        break;
-    }
-}
-
-/* Implement the PRINT_RECREATE method in the breakpoint_ops structure
-   for all exception catchpoint kinds.  */
-
-static void
-print_recreate_exception (enum ada_exception_catchpoint_kind ex,
-                         struct breakpoint *b, struct ui_file *fp)
-{
-  struct ada_catchpoint *c = (struct ada_catchpoint *) b;
-
-  switch (ex)
-    {
-      case ada_catch_exception:
-       fprintf_filtered (fp, "catch exception");
-       if (!c->excep_string.empty ())
-         fprintf_filtered (fp, " %s", c->excep_string.c_str ());
-       break;
-
-      case ada_catch_exception_unhandled:
-       fprintf_filtered (fp, "catch exception unhandled");
-       break;
-
-      case ada_catch_handlers:
-       fprintf_filtered (fp, "catch handlers");
-       break;
-
-      case ada_catch_assert:
-       fprintf_filtered (fp, "catch assert");
-       break;
-
-      default:
-       internal_error (__FILE__, __LINE__, _("unexpected catchpoint type"));
-    }
-  print_recreate_thread (b, fp);
-}
-
-/* Virtual table for "catch exception" breakpoints.  */
-
-static struct bp_location *
-allocate_location_catch_exception (struct breakpoint *self)
-{
-  return allocate_location_exception (ada_catch_exception, self);
-}
-
-static void
-re_set_catch_exception (struct breakpoint *b)
-{
-  re_set_exception (ada_catch_exception, b);
-}
-
-static void
-check_status_catch_exception (bpstat bs)
-{
-  check_status_exception (ada_catch_exception, bs);
-}
-
-static enum print_stop_action
-print_it_catch_exception (bpstat bs)
-{
-  return print_it_exception (ada_catch_exception, bs);
-}
-
-static void
-print_one_catch_exception (struct breakpoint *b, struct bp_location **last_loc)
-{
-  print_one_exception (ada_catch_exception, b, last_loc);
-}
-
-static void
-print_mention_catch_exception (struct breakpoint *b)
-{
-  print_mention_exception (ada_catch_exception, b);
-}
-
-static void
-print_recreate_catch_exception (struct breakpoint *b, struct ui_file *fp)
-{
-  print_recreate_exception (ada_catch_exception, b, fp);
-}
-
-static struct breakpoint_ops catch_exception_breakpoint_ops;
-
-/* Virtual table for "catch exception unhandled" breakpoints.  */
-
-static struct bp_location *
-allocate_location_catch_exception_unhandled (struct breakpoint *self)
-{
-  return allocate_location_exception (ada_catch_exception_unhandled, self);
-}
-
-static void
-re_set_catch_exception_unhandled (struct breakpoint *b)
-{
-  re_set_exception (ada_catch_exception_unhandled, b);
-}
-
-static void
-check_status_catch_exception_unhandled (bpstat bs)
-{
-  check_status_exception (ada_catch_exception_unhandled, bs);
-}
-
-static enum print_stop_action
-print_it_catch_exception_unhandled (bpstat bs)
-{
-  return print_it_exception (ada_catch_exception_unhandled, bs);
-}
-
-static void
-print_one_catch_exception_unhandled (struct breakpoint *b,
-                                    struct bp_location **last_loc)
-{
-  print_one_exception (ada_catch_exception_unhandled, b, last_loc);
-}
-
-static void
-print_mention_catch_exception_unhandled (struct breakpoint *b)
-{
-  print_mention_exception (ada_catch_exception_unhandled, b);
-}
-
-static void
-print_recreate_catch_exception_unhandled (struct breakpoint *b,
-                                         struct ui_file *fp)
-{
-  print_recreate_exception (ada_catch_exception_unhandled, b, fp);
-}
-
-static struct breakpoint_ops catch_exception_unhandled_breakpoint_ops;
-
-/* Virtual table for "catch assert" breakpoints.  */
-
-static struct bp_location *
-allocate_location_catch_assert (struct breakpoint *self)
-{
-  return allocate_location_exception (ada_catch_assert, self);
-}
-
-static void
-re_set_catch_assert (struct breakpoint *b)
-{
-  re_set_exception (ada_catch_assert, b);
-}
-
-static void
-check_status_catch_assert (bpstat bs)
-{
-  check_status_exception (ada_catch_assert, bs);
-}
+                              c->excep_string.c_str ());
+           uiout->text (info.c_str ());
+         }
+        else
+          uiout->text (_("all Ada exceptions handlers"));
+        break;
 
-static enum print_stop_action
-print_it_catch_assert (bpstat bs)
-{
-  return print_it_exception (ada_catch_assert, bs);
-}
+      case ada_catch_assert:
+        uiout->text (_("failed Ada assertions"));
+        break;
 
-static void
-print_one_catch_assert (struct breakpoint *b, struct bp_location **last_loc)
-{
-  print_one_exception (ada_catch_assert, b, last_loc);
+      default:
+        internal_error (__FILE__, __LINE__, _("unexpected catchpoint type"));
+        break;
+    }
 }
 
-static void
-print_mention_catch_assert (struct breakpoint *b)
-{
-  print_mention_exception (ada_catch_assert, b);
-}
+/* Implement the PRINT_RECREATE method in the breakpoint_ops structure
+   for all exception catchpoint kinds.  */
 
 static void
-print_recreate_catch_assert (struct breakpoint *b, struct ui_file *fp)
+print_recreate_exception (struct breakpoint *b, struct ui_file *fp)
 {
-  print_recreate_exception (ada_catch_assert, b, fp);
-}
-
-static struct breakpoint_ops catch_assert_breakpoint_ops;
+  struct ada_catchpoint *c = (struct ada_catchpoint *) b;
 
-/* Virtual table for "catch handlers" breakpoints.  */
+  switch (c->m_kind)
+    {
+      case ada_catch_exception:
+       fprintf_filtered (fp, "catch exception");
+       if (!c->excep_string.empty ())
+         fprintf_filtered (fp, " %s", c->excep_string.c_str ());
+       break;
 
-static struct bp_location *
-allocate_location_catch_handlers (struct breakpoint *self)
-{
-  return allocate_location_exception (ada_catch_handlers, self);
-}
+      case ada_catch_exception_unhandled:
+       fprintf_filtered (fp, "catch exception unhandled");
+       break;
 
-static void
-re_set_catch_handlers (struct breakpoint *b)
-{
-  re_set_exception (ada_catch_handlers, b);
-}
+      case ada_catch_handlers:
+       fprintf_filtered (fp, "catch handlers");
+       break;
 
-static void
-check_status_catch_handlers (bpstat bs)
-{
-  check_status_exception (ada_catch_handlers, bs);
-}
+      case ada_catch_assert:
+       fprintf_filtered (fp, "catch assert");
+       break;
 
-static enum print_stop_action
-print_it_catch_handlers (bpstat bs)
-{
-  return print_it_exception (ada_catch_handlers, bs);
+      default:
+       internal_error (__FILE__, __LINE__, _("unexpected catchpoint type"));
+    }
+  print_recreate_thread (b, fp);
 }
 
-static void
-print_one_catch_handlers (struct breakpoint *b,
-                         struct bp_location **last_loc)
-{
-  print_one_exception (ada_catch_handlers, b, last_loc);
-}
+/* Virtual tables for various breakpoint types.  */
+static struct breakpoint_ops catch_exception_breakpoint_ops;
+static struct breakpoint_ops catch_exception_unhandled_breakpoint_ops;
+static struct breakpoint_ops catch_assert_breakpoint_ops;
+static struct breakpoint_ops catch_handlers_breakpoint_ops;
 
-static void
-print_mention_catch_handlers (struct breakpoint *b)
-{
-  print_mention_exception (ada_catch_handlers, b);
-}
+/* See ada-lang.h.  */
 
-static void
-print_recreate_catch_handlers (struct breakpoint *b,
-                              struct ui_file *fp)
+bool
+is_ada_exception_catchpoint (breakpoint *bp)
 {
-  print_recreate_exception (ada_catch_handlers, b, fp);
+  return (bp->ops == &catch_exception_breakpoint_ops
+         || bp->ops == &catch_exception_unhandled_breakpoint_ops
+         || bp->ops == &catch_assert_breakpoint_ops
+         || bp->ops == &catch_handlers_breakpoint_ops);
 }
 
-static struct breakpoint_ops catch_handlers_breakpoint_ops;
-
 /* Split the arguments specified in a "catch exception" command.  
    Set EX to the appropriate catchpoint type.
    Set EXCEP_STRING to the name of the specific exception if
@@ -13015,18 +12543,18 @@ ada_exception_catchpoint_cond_string (const char *excep_string,
                                       enum ada_exception_catchpoint_kind ex)
 {
   int i;
+  bool is_standard_exc = false;
   std::string result;
-  const char *name;
 
   if (ex == ada_catch_handlers)
     {
       /* For exception handlers catchpoints, the condition string does
          not use the same parameter as for the other exceptions.  */
-      name = ("long_integer (GNAT_GCC_exception_Access"
-             "(gcc_exception).all.occurrence.id)");
+      result = ("long_integer (GNAT_GCC_exception_Access"
+               "(gcc_exception).all.occurrence.id)");
     }
   else
-    name = "long_integer (e)";
+    result = "long_integer (e)";
 
   /* The standard exceptions are a special case.  They are defined in
      runtime units that have been compiled without debugging info; if
@@ -13042,38 +12570,26 @@ ada_exception_catchpoint_cond_string (const char *excep_string,
      exception constraint_error" is rewritten into "catch exception
      standard.constraint_error".
 
-     If an exception named contraint_error is defined in another package of
+     If an exception named constraint_error is defined in another package of
      the inferior program, then the only way to specify this exception as a
      breakpoint condition is to use its fully-qualified named:
-     e.g. my_package.constraint_error.
+     e.g. my_package.constraint_error.  */
 
-     Furthermore, in some situations a standard exception's symbol may
-     be present in more than one objfile, because the compiler may
-     choose to emit copy relocations for them.  So, we have to compare
-     against all the possible addresses.  */
-
-  /* Storage for a rewritten symbol name.  */
-  std::string std_name;
   for (i = 0; i < sizeof (standard_exc) / sizeof (char *); i++)
     {
       if (strcmp (standard_exc [i], excep_string) == 0)
        {
-         std_name = std::string ("standard.") + excep_string;
-         excep_string = std_name.c_str ();
+         is_standard_exc = true;
          break;
        }
     }
 
-  excep_string = ada_encode (excep_string);
-  std::vector<struct bound_minimal_symbol> symbols
-    = ada_lookup_simple_minsyms (excep_string);
-  for (const bound_minimal_symbol &msym : symbols)
-    {
-      if (!result.empty ())
-       result += " or ";
-      string_appendf (result, "%s = %s", name,
-                     pulongest (BMSYMBOL_VALUE_ADDRESS (msym)));
-    }
+  result += " = ";
+
+  if (is_standard_exc)
+    string_appendf (result, "long_integer (&standard.%s)", excep_string);
+  else
+    string_appendf (result, "long_integer (&%s)", excep_string);
 
   return result;
 }
@@ -13143,7 +12659,7 @@ create_ada_exception_catchpoint (struct gdbarch *gdbarch,
   const struct breakpoint_ops *ops = NULL;
   struct symtab_and_line sal = ada_exception_sal (ex_kind, &addr_string, &ops);
 
-  std::unique_ptr<ada_catchpoint> c (new ada_catchpoint ());
+  std::unique_ptr<ada_catchpoint> c (new ada_catchpoint (ex_kind));
   init_ada_exception_breakpoint (c.get (), gdbarch, sal, addr_string.c_str (),
                                 ops, tempflag, disabled, from_tty);
   c->excep_string = excep_string;
@@ -13275,7 +12791,7 @@ catch_assert_command (const char *arg_entry, int from_tty,
 static int
 ada_is_exception_sym (struct symbol *sym)
 {
-  const char *type_name = TYPE_NAME (SYMBOL_TYPE (sym));
+  const char *type_name = SYMBOL_TYPE (sym)->name ();
 
   return (SYMBOL_CLASS (sym) != LOC_TYPEDEF
           && SYMBOL_CLASS (sym) != LOC_BLOCK
@@ -13297,13 +12813,13 @@ ada_is_non_standard_exception_sym (struct symbol *sym)
     return 0;
 
   for (i = 0; i < ARRAY_SIZE (standard_exc); i++)
-    if (strcmp (SYMBOL_LINKAGE_NAME (sym), standard_exc[i]) == 0)
+    if (strcmp (sym->linkage_name (), standard_exc[i]) == 0)
       return 0;  /* A standard exception.  */
 
   /* Numeric_Error is also a standard exception, so exclude it.
      See the STANDARD_EXC description for more details as to why
      this exception is not listed in that array.  */
-  if (strcmp (SYMBOL_LINKAGE_NAME (sym), "numeric_error") == 0)
+  if (strcmp (sym->linkage_name (), "numeric_error") == 0)
     return 0;
 
   return 1;
@@ -13416,7 +12932,7 @@ ada_add_exceptions_from_frame (compiled_regex *preg,
            default:
              if (ada_is_exception_sym (sym))
                {
-                 struct ada_exc_info info = {SYMBOL_PRINT_NAME (sym),
+                 struct ada_exc_info info = {sym->print_name (),
                                              SYMBOL_VALUE_ADDRESS (sym)};
 
                  exceptions->push_back (info);
@@ -13435,7 +12951,7 @@ static bool
 name_matches_regex (const char *name, compiled_regex *preg)
 {
   return (preg == NULL
-         || preg->exec (ada_decode (name), 0, NULL, 0) == 0);
+         || preg->exec (ada_decode (name).c_str (), 0, NULL, 0) == 0);
 }
 
 /* Add all exceptions defined globally whose name name match
@@ -13468,8 +12984,8 @@ ada_add_global_exceptions (compiled_regex *preg,
                           lookup_name_info::match_any (),
                           [&] (const char *search_name)
                           {
-                            const char *decoded = ada_decode (search_name);
-                            return name_matches_regex (decoded, preg);
+                            std::string decoded = ada_decode (search_name);
+                            return name_matches_regex (decoded.c_str (), preg);
                           },
                           NULL,
                           VARIABLES_DOMAIN);
@@ -13489,10 +13005,10 @@ ada_add_global_exceptions (compiled_regex *preg,
 
              ALL_BLOCK_SYMBOLS (b, iter, sym)
                if (ada_is_non_standard_exception_sym (sym)
-                   && name_matches_regex (SYMBOL_NATURAL_NAME (sym), preg))
+                   && name_matches_regex (sym->natural_name (), preg))
                  {
                    struct ada_exc_info info
-                     = {SYMBOL_PRINT_NAME (sym), SYMBOL_VALUE_ADDRESS (sym)};
+                     = {sym->print_name (), SYMBOL_VALUE_ADDRESS (sym)};
 
                    exceptions->push_back (info);
                  }
@@ -13820,7 +13336,7 @@ ada_print_subexp (struct expression *exp, int *pos,
       return;
 
     case OP_VAR_VALUE:
-      fputs_filtered (SYMBOL_NATURAL_NAME (exp->elts[pc + 2].symbol), stream);
+      fputs_filtered (exp->elts[pc + 2].symbol->natural_name (), stream);
       return;
 
     case BINOP_IN_BOUNDS:
@@ -13860,7 +13376,7 @@ ada_print_subexp (struct expression *exp, int *pos,
     case OP_ATR_VAL:
       if (exp->elts[*pos].opcode == OP_TYPE)
         {
-          if (TYPE_CODE (exp->elts[*pos + 1].type) != TYPE_CODE_VOID)
+          if (exp->elts[*pos + 1].type->code () != TYPE_CODE_VOID)
             LA_PRINT_TYPE (exp->elts[*pos + 1].type, "", stream, 0, 0,
                           &type_print_raw_options);
           *pos += 3;
@@ -13990,88 +13506,9 @@ enum ada_primitive_types {
   nr_ada_primitive_types
 };
 
-static void
-ada_language_arch_info (struct gdbarch *gdbarch,
-                       struct language_arch_info *lai)
-{
-  const struct builtin_type *builtin = builtin_type (gdbarch);
-
-  lai->primitive_type_vector
-    = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_ada_primitive_types + 1,
-                             struct type *);
-
-  lai->primitive_type_vector [ada_primitive_type_int]
-    = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
-                        0, "integer");
-  lai->primitive_type_vector [ada_primitive_type_long]
-    = arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch),
-                        0, "long_integer");
-  lai->primitive_type_vector [ada_primitive_type_short]
-    = arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch),
-                        0, "short_integer");
-  lai->string_char_type
-    = lai->primitive_type_vector [ada_primitive_type_char]
-    = arch_character_type (gdbarch, TARGET_CHAR_BIT, 0, "character");
-  lai->primitive_type_vector [ada_primitive_type_float]
-    = arch_float_type (gdbarch, gdbarch_float_bit (gdbarch),
-                      "float", gdbarch_float_format (gdbarch));
-  lai->primitive_type_vector [ada_primitive_type_double]
-    = arch_float_type (gdbarch, gdbarch_double_bit (gdbarch),
-                      "long_float", gdbarch_double_format (gdbarch));
-  lai->primitive_type_vector [ada_primitive_type_long_long]
-    = arch_integer_type (gdbarch, gdbarch_long_long_bit (gdbarch),
-                        0, "long_long_integer");
-  lai->primitive_type_vector [ada_primitive_type_long_double]
-    = arch_float_type (gdbarch, gdbarch_long_double_bit (gdbarch),
-                      "long_long_float", gdbarch_long_double_format (gdbarch));
-  lai->primitive_type_vector [ada_primitive_type_natural]
-    = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
-                        0, "natural");
-  lai->primitive_type_vector [ada_primitive_type_positive]
-    = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
-                        0, "positive");
-  lai->primitive_type_vector [ada_primitive_type_void]
-    = builtin->builtin_void;
-
-  lai->primitive_type_vector [ada_primitive_type_system_address]
-    = lookup_pointer_type (arch_type (gdbarch, TYPE_CODE_VOID, TARGET_CHAR_BIT,
-                                     "void"));
-  TYPE_NAME (lai->primitive_type_vector [ada_primitive_type_system_address])
-    = "system__address";
-
-  /* Create the equivalent of the System.Storage_Elements.Storage_Offset
-     type.  This is a signed integral type whose size is the same as
-     the size of addresses.  */
-  {
-    unsigned int addr_length = TYPE_LENGTH
-      (lai->primitive_type_vector [ada_primitive_type_system_address]);
-
-    lai->primitive_type_vector [ada_primitive_type_storage_offset]
-      = arch_integer_type (gdbarch, addr_length * HOST_CHAR_BIT, 0,
-                          "storage_offset");
-  }
-
-  lai->bool_type_symbol = NULL;
-  lai->bool_type_default = builtin->builtin_bool;
-}
 \f
                                /* Language vector */
 
-/* Not really used, but needed in the ada_language_defn.  */
-
-static void
-emit_char (int c, struct type *type, struct ui_file *stream, int quoter)
-{
-  ada_emit_char (c, type, stream, quoter, 1);
-}
-
-static int
-parse (struct parser_state *ps)
-{
-  warnings_issued = 0;
-  return ada_parse (ps);
-}
-
 static const struct exp_descriptor ada_exp_descriptor = {
   ada_print_subexp,
   ada_operator_length,
@@ -14115,14 +13552,16 @@ do_exact_match (const char *symbol_search_name,
 
 ada_lookup_name_info::ada_lookup_name_info (const lookup_name_info &lookup_name)
 {
-  const std::string &user_name = lookup_name.name ();
+  gdb::string_view user_name = lookup_name.name ();
 
   if (user_name[0] == '<')
     {
       if (user_name.back () == '>')
-       m_encoded_name = user_name.substr (1, user_name.size () - 2);
+       m_encoded_name
+         = gdb::to_string (user_name.substr (1, user_name.size () - 2));
       else
-       m_encoded_name = user_name.substr (1, user_name.size () - 1);
+       m_encoded_name
+         = gdb::to_string (user_name.substr (1, user_name.size () - 1));
       m_encoded_p = true;
       m_verbatim_p = true;
       m_wild_match_p = false;
@@ -14132,19 +13571,19 @@ ada_lookup_name_info::ada_lookup_name_info (const lookup_name_info &lookup_name)
     {
       m_verbatim_p = false;
 
-      m_encoded_p = user_name.find ("__") != std::string::npos;
+      m_encoded_p = user_name.find ("__") != gdb::string_view::npos;
 
       if (!m_encoded_p)
        {
-         const char *folded = ada_fold_name (user_name.c_str ());
+         const char *folded = ada_fold_name (user_name);
          const char *encoded = ada_encode_1 (folded, false);
          if (encoded != NULL)
            m_encoded_name = encoded;
          else
-           m_encoded_name = user_name;
+           m_encoded_name = gdb::to_string (user_name);
        }
       else
-       m_encoded_name = user_name;
+       m_encoded_name = gdb::to_string (user_name);
 
       /* Handle the 'package Standard' special case.  See description
         of m_standard_p.  */
@@ -14191,12 +13630,12 @@ literal_symbol_name_matcher (const char *symbol_search_name,
                             const lookup_name_info &lookup_name,
                             completion_match_result *comp_match_res)
 {
-  const std::string &name = lookup_name.name ();
+  gdb::string_view name_view = lookup_name.name ();
 
-  int cmp = (lookup_name.completion_mode ()
-            ? strncmp (symbol_search_name, name.c_str (), name.size ())
-            : strcmp (symbol_search_name, name.c_str ()));
-  if (cmp == 0)
+  if (lookup_name.completion_mode ()
+      ? (strncmp (symbol_search_name, name_view.data (),
+                 name_view.size ()) == 0)
+      : symbol_search_name == name_view)
     {
       if (comp_match_res != NULL)
        comp_match_res->set_match (symbol_search_name);
@@ -14206,7 +13645,7 @@ literal_symbol_name_matcher (const char *symbol_search_name,
     return false;
 }
 
-/* Implement the "la_get_symbol_name_matcher" language_defn method for
+/* Implement the "get_symbol_name_matcher" language_defn method for
    Ada.  */
 
 static symbol_name_matcher_ftype *
@@ -14228,32 +13667,15 @@ ada_get_symbol_name_matcher (const lookup_name_info &lookup_name)
     }
 }
 
-/* Implement the "la_read_var_value" language_defn method for Ada.  */
-
-static struct value *
-ada_read_var_value (struct symbol *var, const struct block *var_block,
-                   struct frame_info *frame)
-{
-  /* The only case where default_read_var_value is not sufficient
-     is when VAR is a renaming...  */
-  if (frame != nullptr)
-    {
-      const struct block *frame_block = get_frame_block (frame, NULL);
-      if (frame_block != nullptr && ada_is_renaming_symbol (var))
-       return ada_read_renaming_var_value (var, frame_block);
-    }
-
-  /* This is a typical case where we expect the default_read_var_value
-     function to work.  */
-  return default_read_var_value (var, var_block, frame);
-}
-
 static const char *ada_extensions[] =
 {
   ".adb", ".ads", ".a", ".ada", ".dg", NULL
 };
 
-extern const struct language_defn ada_language_defn = {
+/* Constant data that describes the Ada language.  */
+
+extern const struct language_data ada_language_data =
+{
   "ada",                        /* Language name */
   "Ada",
   language_ada,
@@ -14264,66 +13686,488 @@ extern const struct language_defn ada_language_defn = {
   macro_expansion_no,
   ada_extensions,
   &ada_exp_descriptor,
-  parse,
-  resolve,
-  ada_printchar,                /* Print a character constant */
-  ada_printstr,                 /* Function to print string constant */
-  emit_char,                    /* Function to print single char (not used) */
-  ada_print_type,               /* Print a type using appropriate syntax */
-  ada_print_typedef,            /* Print a typedef using appropriate syntax */
-  ada_val_print,                /* Print a value using appropriate syntax */
-  ada_value_print,              /* Print a top-level value */
-  ada_read_var_value,          /* la_read_var_value */
-  NULL,                         /* Language specific skip_trampoline */
   NULL,                         /* name_of_this */
   true,                         /* la_store_sym_names_in_linkage_form_p */
-  ada_lookup_symbol_nonlocal,   /* Looking up non-local symbols.  */
-  basic_lookup_transparent_type,        /* lookup_transparent_type */
-  ada_la_decode,                /* Language specific symbol demangler */
-  ada_sniff_from_mangled_name,
-  NULL,                         /* Language specific
-                                  class_name_from_physname */
   ada_op_print_tab,             /* expression operators for printing */
   0,                            /* c-style arrays */
   1,                            /* String lower bound */
-  ada_get_gdb_completer_word_break_characters,
-  ada_collect_symbol_completion_matches,
-  ada_language_arch_info,
-  ada_print_array_index,
-  default_pass_by_reference,
-  c_get_string,
-  ada_watch_location_expression,
-  ada_get_symbol_name_matcher, /* la_get_symbol_name_matcher */
-  ada_iterate_over_symbols,
-  default_search_name_hash,
   &ada_varobj_ops,
-  NULL,
-  NULL,
-  ada_is_string_type,
   "(...)"                      /* la_struct_too_deep_ellipsis */
 };
 
-/* Command-list for the "set/show ada" prefix command.  */
-static struct cmd_list_element *set_ada_list;
-static struct cmd_list_element *show_ada_list;
-
-/* Implement the "set ada" prefix command.  */
+/* Class representing the Ada language.  */
 
-static void
-set_ada_command (const char *arg, int from_tty)
+class ada_language : public language_defn
 {
-  printf_unfiltered (_(\
-"\"set ada\" must be followed by the name of a setting.\n"));
-  help_list (set_ada_list, "set ada ", all_commands, gdb_stdout);
-}
+public:
+  ada_language ()
+    : language_defn (language_ada, ada_language_data)
+  { /* Nothing.  */ }
 
-/* Implement the "show ada" prefix command.  */
+  /* Print an array element index using the Ada syntax.  */
 
-static void
-show_ada_command (const char *args, int from_tty)
-{
-  cmd_show_list (show_ada_list, from_tty, "");
-}
+  void print_array_index (struct type *index_type,
+                         LONGEST index,
+                         struct ui_file *stream,
+                         const value_print_options *options) const override
+  {
+    struct value *index_value = val_atr (index_type, index);
+
+    LA_VALUE_PRINT (index_value, stream, options);
+    fprintf_filtered (stream, " => ");
+  }
+
+  /* Implement the "read_var_value" language_defn method for Ada.  */
+
+  struct value *read_var_value (struct symbol *var,
+                               const struct block *var_block,
+                               struct frame_info *frame) const override
+  {
+    /* The only case where default_read_var_value is not sufficient
+       is when VAR is a renaming...  */
+    if (frame != nullptr)
+      {
+       const struct block *frame_block = get_frame_block (frame, NULL);
+       if (frame_block != nullptr && ada_is_renaming_symbol (var))
+         return ada_read_renaming_var_value (var, frame_block);
+      }
+
+    /* This is a typical case where we expect the default_read_var_value
+       function to work.  */
+    return language_defn::read_var_value (var, var_block, frame);
+  }
+
+  /* See language.h.  */
+  void language_arch_info (struct gdbarch *gdbarch,
+                          struct language_arch_info *lai) const override
+  {
+    const struct builtin_type *builtin = builtin_type (gdbarch);
+
+    lai->primitive_type_vector
+      = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_ada_primitive_types + 1,
+                               struct type *);
+
+    lai->primitive_type_vector [ada_primitive_type_int]
+      = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
+                          0, "integer");
+    lai->primitive_type_vector [ada_primitive_type_long]
+      = arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch),
+                          0, "long_integer");
+    lai->primitive_type_vector [ada_primitive_type_short]
+      = arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch),
+                          0, "short_integer");
+    lai->string_char_type
+      = lai->primitive_type_vector [ada_primitive_type_char]
+      = arch_character_type (gdbarch, TARGET_CHAR_BIT, 0, "character");
+    lai->primitive_type_vector [ada_primitive_type_float]
+      = arch_float_type (gdbarch, gdbarch_float_bit (gdbarch),
+                        "float", gdbarch_float_format (gdbarch));
+    lai->primitive_type_vector [ada_primitive_type_double]
+      = arch_float_type (gdbarch, gdbarch_double_bit (gdbarch),
+                        "long_float", gdbarch_double_format (gdbarch));
+    lai->primitive_type_vector [ada_primitive_type_long_long]
+      = arch_integer_type (gdbarch, gdbarch_long_long_bit (gdbarch),
+                          0, "long_long_integer");
+    lai->primitive_type_vector [ada_primitive_type_long_double]
+      = arch_float_type (gdbarch, gdbarch_long_double_bit (gdbarch),
+                        "long_long_float", gdbarch_long_double_format (gdbarch));
+    lai->primitive_type_vector [ada_primitive_type_natural]
+      = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
+                          0, "natural");
+    lai->primitive_type_vector [ada_primitive_type_positive]
+      = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
+                          0, "positive");
+    lai->primitive_type_vector [ada_primitive_type_void]
+      = builtin->builtin_void;
+
+    lai->primitive_type_vector [ada_primitive_type_system_address]
+      = lookup_pointer_type (arch_type (gdbarch, TYPE_CODE_VOID, TARGET_CHAR_BIT,
+                                       "void"));
+    lai->primitive_type_vector [ada_primitive_type_system_address]
+      ->set_name ("system__address");
+
+    /* Create the equivalent of the System.Storage_Elements.Storage_Offset
+       type.  This is a signed integral type whose size is the same as
+       the size of addresses.  */
+    {
+      unsigned int addr_length = TYPE_LENGTH
+       (lai->primitive_type_vector [ada_primitive_type_system_address]);
+
+      lai->primitive_type_vector [ada_primitive_type_storage_offset]
+       = arch_integer_type (gdbarch, addr_length * HOST_CHAR_BIT, 0,
+                            "storage_offset");
+    }
+
+    lai->bool_type_symbol = NULL;
+    lai->bool_type_default = builtin->builtin_bool;
+  }
+
+  /* See language.h.  */
+
+  bool iterate_over_symbols
+       (const struct block *block, const lookup_name_info &name,
+        domain_enum domain,
+        gdb::function_view<symbol_found_callback_ftype> callback) const override
+  {
+    std::vector<struct block_symbol> results;
+
+    ada_lookup_symbol_list_worker (name, block, domain, &results, 0);
+    for (block_symbol &sym : results)
+      {
+       if (!callback (&sym))
+         return false;
+      }
+
+    return true;
+  }
+
+  /* See language.h.  */
+  bool sniff_from_mangled_name (const char *mangled,
+                               char **out) const override
+  {
+    std::string demangled = ada_decode (mangled);
+
+    *out = NULL;
+
+    if (demangled != mangled && demangled[0] != '<')
+      {
+       /* Set the gsymbol language to Ada, but still return 0.
+          Two reasons for that:
+
+          1. For Ada, we prefer computing the symbol's decoded name
+          on the fly rather than pre-compute it, in order to save
+          memory (Ada projects are typically very large).
+
+          2. There are some areas in the definition of the GNAT
+          encoding where, with a bit of bad luck, we might be able
+          to decode a non-Ada symbol, generating an incorrect
+          demangled name (Eg: names ending with "TB" for instance
+          are identified as task bodies and so stripped from
+          the decoded name returned).
+
+          Returning true, here, but not setting *DEMANGLED, helps us get
+          a little bit of the best of both worlds.  Because we're last,
+          we should not affect any of the other languages that were
+          able to demangle the symbol before us; we get to correctly
+          tag Ada symbols as such; and even if we incorrectly tagged a
+          non-Ada symbol, which should be rare, any routing through the
+          Ada language should be transparent (Ada tries to behave much
+          like C/C++ with non-Ada symbols).  */
+       return true;
+      }
+
+    return false;
+  }
+
+  /* See language.h.  */
+
+  char *demangle (const char *mangled, int options) const override
+  {
+    return ada_la_decode (mangled, options);
+  }
+
+  /* See language.h.  */
+
+  void print_type (struct type *type, const char *varstring,
+                  struct ui_file *stream, int show, int level,
+                  const struct type_print_options *flags) const override
+  {
+    ada_print_type (type, varstring, stream, show, level, flags);
+  }
+
+  /* See language.h.  */
+
+  const char *word_break_characters (void) const override
+  {
+    return ada_completer_word_break_characters;
+  }
+
+  /* See language.h.  */
+
+  void collect_symbol_completion_matches (completion_tracker &tracker,
+                                         complete_symbol_mode mode,
+                                         symbol_name_match_type name_match_type,
+                                         const char *text, const char *word,
+                                         enum type_code code) const override
+  {
+    struct symbol *sym;
+    const struct block *b, *surrounding_static_block = 0;
+    struct block_iterator iter;
+
+    gdb_assert (code == TYPE_CODE_UNDEF);
+
+    lookup_name_info lookup_name (text, name_match_type, true);
+
+    /* First, look at the partial symtab symbols.  */
+    expand_symtabs_matching (NULL,
+                            lookup_name,
+                            NULL,
+                            NULL,
+                            ALL_DOMAIN);
+
+    /* At this point scan through the misc symbol vectors and add each
+       symbol you find to the list.  Eventually we want to ignore
+       anything that isn't a text symbol (everything else will be
+       handled by the psymtab code above).  */
+
+    for (objfile *objfile : current_program_space->objfiles ())
+      {
+       for (minimal_symbol *msymbol : objfile->msymbols ())
+         {
+           QUIT;
+
+           if (completion_skip_symbol (mode, msymbol))
+             continue;
+
+           language symbol_language = msymbol->language ();
+
+           /* Ada minimal symbols won't have their language set to Ada.  If
+              we let completion_list_add_name compare using the
+              default/C-like matcher, then when completing e.g., symbols in a
+              package named "pck", we'd match internal Ada symbols like
+              "pckS", which are invalid in an Ada expression, unless you wrap
+              them in '<' '>' to request a verbatim match.
+
+              Unfortunately, some Ada encoded names successfully demangle as
+              C++ symbols (using an old mangling scheme), such as "name__2Xn"
+              -> "Xn::name(void)" and thus some Ada minimal symbols end up
+              with the wrong language set.  Paper over that issue here.  */
+           if (symbol_language == language_auto
+               || symbol_language == language_cplus)
+             symbol_language = language_ada;
+
+           completion_list_add_name (tracker,
+                                     symbol_language,
+                                     msymbol->linkage_name (),
+                                     lookup_name, text, word);
+         }
+      }
+
+    /* Search upwards from currently selected frame (so that we can
+       complete on local vars.  */
+
+    for (b = get_selected_block (0); b != NULL; b = BLOCK_SUPERBLOCK (b))
+      {
+       if (!BLOCK_SUPERBLOCK (b))
+         surrounding_static_block = b;   /* For elmin of dups */
+
+       ALL_BLOCK_SYMBOLS (b, iter, sym)
+         {
+           if (completion_skip_symbol (mode, sym))
+             continue;
+
+           completion_list_add_name (tracker,
+                                     sym->language (),
+                                     sym->linkage_name (),
+                                     lookup_name, text, word);
+         }
+      }
+
+    /* Go through the symtabs and check the externs and statics for
+       symbols which match.  */
+
+    for (objfile *objfile : current_program_space->objfiles ())
+      {
+       for (compunit_symtab *s : objfile->compunits ())
+         {
+           QUIT;
+           b = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (s), GLOBAL_BLOCK);
+           ALL_BLOCK_SYMBOLS (b, iter, sym)
+             {
+               if (completion_skip_symbol (mode, sym))
+                 continue;
+
+               completion_list_add_name (tracker,
+                                         sym->language (),
+                                         sym->linkage_name (),
+                                         lookup_name, text, word);
+             }
+         }
+      }
+
+    for (objfile *objfile : current_program_space->objfiles ())
+      {
+       for (compunit_symtab *s : objfile->compunits ())
+         {
+           QUIT;
+           b = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (s), STATIC_BLOCK);
+           /* Don't do this block twice.  */
+           if (b == surrounding_static_block)
+             continue;
+           ALL_BLOCK_SYMBOLS (b, iter, sym)
+             {
+               if (completion_skip_symbol (mode, sym))
+                 continue;
+
+               completion_list_add_name (tracker,
+                                         sym->language (),
+                                         sym->linkage_name (),
+                                         lookup_name, text, word);
+             }
+         }
+      }
+  }
+
+  /* See language.h.  */
+
+  gdb::unique_xmalloc_ptr<char> watch_location_expression
+       (struct type *type, CORE_ADDR addr) const override
+  {
+    type = check_typedef (TYPE_TARGET_TYPE (check_typedef (type)));
+    std::string name = type_to_string (type);
+    return gdb::unique_xmalloc_ptr<char>
+      (xstrprintf ("{%s} %s", name.c_str (), core_addr_to_string (addr)));
+  }
+
+  /* See language.h.  */
+
+  void value_print (struct value *val, struct ui_file *stream,
+                   const struct value_print_options *options) const override
+  {
+    return ada_value_print (val, stream, options);
+  }
+
+  /* See language.h.  */
+
+  void value_print_inner
+       (struct value *val, struct ui_file *stream, int recurse,
+        const struct value_print_options *options) const override
+  {
+    return ada_value_print_inner (val, stream, recurse, options);
+  }
+
+  /* See language.h.  */
+
+  struct block_symbol lookup_symbol_nonlocal
+       (const char *name, const struct block *block,
+        const domain_enum domain) const override
+  {
+    struct block_symbol sym;
+
+    sym = ada_lookup_symbol (name, block_static_block (block), domain);
+    if (sym.symbol != NULL)
+      return sym;
+
+    /* If we haven't found a match at this point, try the primitive
+       types.  In other languages, this search is performed before
+       searching for global symbols in order to short-circuit that
+       global-symbol search if it happens that the name corresponds
+       to a primitive type.  But we cannot do the same in Ada, because
+       it is perfectly legitimate for a program to declare a type which
+       has the same name as a standard type.  If looking up a type in
+       that situation, we have traditionally ignored the primitive type
+       in favor of user-defined types.  This is why, unlike most other
+       languages, we search the primitive types this late and only after
+       having searched the global symbols without success.  */
+
+    if (domain == VAR_DOMAIN)
+      {
+       struct gdbarch *gdbarch;
+
+       if (block == NULL)
+         gdbarch = target_gdbarch ();
+       else
+         gdbarch = block_gdbarch (block);
+       sym.symbol
+         = language_lookup_primitive_type_as_symbol (this, gdbarch, name);
+       if (sym.symbol != NULL)
+         return sym;
+      }
+
+    return {};
+  }
+
+  /* See language.h.  */
+
+  int parser (struct parser_state *ps) const override
+  {
+    warnings_issued = 0;
+    return ada_parse (ps);
+  }
+
+  /* See language.h.
+
+     Same as evaluate_type (*EXP), but resolves ambiguous symbol references
+     (marked by OP_VAR_VALUE nodes in which the symbol has an undefined
+     namespace) and converts operators that are user-defined into
+     appropriate function calls.  If CONTEXT_TYPE is non-null, it provides
+     a preferred result type [at the moment, only type void has any
+     effect---causing procedures to be preferred over functions in calls].
+     A null CONTEXT_TYPE indicates that a non-void return type is
+     preferred.  May change (expand) *EXP.  */
+
+  void post_parser (expression_up *expp, int void_context_p, int completing,
+                   innermost_block_tracker *tracker) const override
+  {
+    struct type *context_type = NULL;
+    int pc = 0;
+
+    if (void_context_p)
+      context_type = builtin_type ((*expp)->gdbarch)->builtin_void;
+
+    resolve_subexp (expp, &pc, 1, context_type, completing, tracker);
+  }
+
+  /* See language.h.  */
+
+  void emitchar (int ch, struct type *chtype,
+                struct ui_file *stream, int quoter) const override
+  {
+    ada_emit_char (ch, chtype, stream, quoter, 1);
+  }
+
+  /* See language.h.  */
+
+  void printchar (int ch, struct type *chtype,
+                 struct ui_file *stream) const override
+  {
+    ada_printchar (ch, chtype, stream);
+  }
+
+  /* See language.h.  */
+
+  void printstr (struct ui_file *stream, struct type *elttype,
+                const gdb_byte *string, unsigned int length,
+                const char *encoding, int force_ellipses,
+                const struct value_print_options *options) const override
+  {
+    ada_printstr (stream, elttype, string, length, encoding,
+                 force_ellipses, options);
+  }
+
+  /* See language.h.  */
+
+  void print_typedef (struct type *type, struct symbol *new_symbol,
+                     struct ui_file *stream) const override
+  {
+    ada_print_typedef (type, new_symbol, stream);
+  }
+
+  /* See language.h.  */
+
+  bool is_string_type_p (struct type *type) const override
+  {
+    return ada_is_string_type (type);
+  }
+
+
+protected:
+  /* See language.h.  */
+
+  symbol_name_matcher_ftype *get_symbol_name_matcher_inner
+       (const lookup_name_info &lookup_name) const override
+  {
+    return ada_get_symbol_name_matcher (lookup_name);
+  }
+};
+
+/* Single instance of the Ada language class.  */
+
+static ada_language ada_language_defn;
+
+/* Command-list for the "set/show ada" prefix command.  */
+static struct cmd_list_element *set_ada_list;
+static struct cmd_list_element *show_ada_list;
 
 static void
 initialize_ada_catchpoint_ops (void)
@@ -14334,43 +14178,43 @@ initialize_ada_catchpoint_ops (void)
 
   ops = &catch_exception_breakpoint_ops;
   *ops = bkpt_breakpoint_ops;
-  ops->allocate_location = allocate_location_catch_exception;
-  ops->re_set = re_set_catch_exception;
-  ops->check_status = check_status_catch_exception;
-  ops->print_it = print_it_catch_exception;
-  ops->print_one = print_one_catch_exception;
-  ops->print_mention = print_mention_catch_exception;
-  ops->print_recreate = print_recreate_catch_exception;
+  ops->allocate_location = allocate_location_exception;
+  ops->re_set = re_set_exception;
+  ops->check_status = check_status_exception;
+  ops->print_it = print_it_exception;
+  ops->print_one = print_one_exception;
+  ops->print_mention = print_mention_exception;
+  ops->print_recreate = print_recreate_exception;
 
   ops = &catch_exception_unhandled_breakpoint_ops;
   *ops = bkpt_breakpoint_ops;
-  ops->allocate_location = allocate_location_catch_exception_unhandled;
-  ops->re_set = re_set_catch_exception_unhandled;
-  ops->check_status = check_status_catch_exception_unhandled;
-  ops->print_it = print_it_catch_exception_unhandled;
-  ops->print_one = print_one_catch_exception_unhandled;
-  ops->print_mention = print_mention_catch_exception_unhandled;
-  ops->print_recreate = print_recreate_catch_exception_unhandled;
+  ops->allocate_location = allocate_location_exception;
+  ops->re_set = re_set_exception;
+  ops->check_status = check_status_exception;
+  ops->print_it = print_it_exception;
+  ops->print_one = print_one_exception;
+  ops->print_mention = print_mention_exception;
+  ops->print_recreate = print_recreate_exception;
 
   ops = &catch_assert_breakpoint_ops;
   *ops = bkpt_breakpoint_ops;
-  ops->allocate_location = allocate_location_catch_assert;
-  ops->re_set = re_set_catch_assert;
-  ops->check_status = check_status_catch_assert;
-  ops->print_it = print_it_catch_assert;
-  ops->print_one = print_one_catch_assert;
-  ops->print_mention = print_mention_catch_assert;
-  ops->print_recreate = print_recreate_catch_assert;
+  ops->allocate_location = allocate_location_exception;
+  ops->re_set = re_set_exception;
+  ops->check_status = check_status_exception;
+  ops->print_it = print_it_exception;
+  ops->print_one = print_one_exception;
+  ops->print_mention = print_mention_exception;
+  ops->print_recreate = print_recreate_exception;
 
   ops = &catch_handlers_breakpoint_ops;
   *ops = bkpt_breakpoint_ops;
-  ops->allocate_location = allocate_location_catch_handlers;
-  ops->re_set = re_set_catch_handlers;
-  ops->check_status = check_status_catch_handlers;
-  ops->print_it = print_it_catch_handlers;
-  ops->print_one = print_one_catch_handlers;
-  ops->print_mention = print_mention_catch_handlers;
-  ops->print_recreate = print_recreate_catch_handlers;
+  ops->allocate_location = allocate_location_exception;
+  ops->re_set = re_set_exception;
+  ops->check_status = check_status_exception;
+  ops->print_it = print_it_exception;
+  ops->print_one = print_one_exception;
+  ops->print_mention = print_mention_exception;
+  ops->print_recreate = print_recreate_exception;
 }
 
 /* This module's 'new_objfile' observer.  */
@@ -14389,23 +14233,24 @@ ada_free_objfile_observer (struct objfile *objfile)
   ada_clear_symbol_cache ();
 }
 
+void _initialize_ada_language ();
 void
-_initialize_ada_language (void)
+_initialize_ada_language ()
 {
   initialize_ada_catchpoint_ops ();
 
-  add_prefix_cmd ("ada", no_class, set_ada_command,
-                  _("Prefix command for changing Ada-specific settings"),
-                  &set_ada_list, "set ada ", 0, &setlist);
+  add_basic_prefix_cmd ("ada", no_class,
+                       _("Prefix command for changing Ada-specific settings."),
+                       &set_ada_list, "set ada ", 0, &setlist);
 
-  add_prefix_cmd ("ada", no_class, show_ada_command,
-                  _("Generic command for showing Ada-specific settings."),
-                  &show_ada_list, "show ada ", 0, &showlist);
+  add_show_prefix_cmd ("ada", no_class,
+                      _("Generic command for showing Ada-specific settings."),
+                      &show_ada_list, "show ada ", 0, &showlist);
 
   add_setshow_boolean_cmd ("trust-PAD-over-XVS", class_obscure,
                            &trust_pad_over_xvs, _("\
-Enable or disable an optimization trusting PAD types over XVS types"), _("\
-Show whether an optimization trusting PAD types over XVS types is activated"),
+Enable or disable an optimization trusting PAD types over XVS types."), _("\
+Show whether an optimization trusting PAD types over XVS types is activated."),
                            _("\
 This is related to the encoding used by the GNAT compiler.  The debugger\n\
 should normally trust the contents of PAD types, but certain older versions\n\
@@ -14419,9 +14264,9 @@ this option to \"off\" unless necessary."),
   add_setshow_boolean_cmd ("print-signatures", class_vars,
                           &print_signatures, _("\
 Enable or disable the output of formal and return types for functions in the \
-overloads selection menu"), _("\
+overloads selection menu."), _("\
 Show whether the output of formal and return types for functions in the \
-overloads selection menu is activated"),
+overloads selection menu is activated."),
                           NULL, NULL, NULL, &set_ada_list, &show_ada_list);
 
   add_catch_command ("exception", _("\
@@ -14477,15 +14322,15 @@ Usage: info exceptions [REGEXP]\n\
 If a regular expression is passed as an argument, only those matching\n\
 the regular expression are listed."));
 
-  add_prefix_cmd ("ada", class_maintenance, maint_set_ada_cmd,
-                 _("Set Ada maintenance-related variables."),
-                  &maint_set_ada_cmdlist, "maintenance set ada ",
-                  0/*allow-unknown*/, &maintenance_set_cmdlist);
+  add_basic_prefix_cmd ("ada", class_maintenance,
+                       _("Set Ada maintenance-related variables."),
+                       &maint_set_ada_cmdlist, "maintenance set ada ",
+                       0/*allow-unknown*/, &maintenance_set_cmdlist);
 
-  add_prefix_cmd ("ada", class_maintenance, maint_show_ada_cmd,
-                 _("Show Ada maintenance-related variables"),
-                  &maint_show_ada_cmdlist, "maintenance show ada ",
-                  0/*allow-unknown*/, &maintenance_show_cmdlist);
+  add_show_prefix_cmd ("ada", class_maintenance,
+                      _("Show Ada maintenance-related variables."),
+                      &maint_show_ada_cmdlist, "maintenance show ada ",
+                      0/*allow-unknown*/, &maintenance_show_cmdlist);
 
   add_setshow_boolean_cmd
     ("ignore-descriptive-types", class_maintenance,
This page took 0.120293 seconds and 4 git commands to generate.