gdb: add type::code / type::set_code
[deliverable/binutils-gdb.git] / gdb / ada-lang.c
index 030c4aa131b5981f9931c3506eaa4b63b0ebd7f9..9bed6430cc3f6689c83f8549073da6502d0ce5ac 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.
 
@@ -204,9 +204,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 *);
 
@@ -332,23 +329,6 @@ 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 bool ada_ignore_descriptive_types_p = false;
@@ -769,7 +749,7 @@ min_of_type (struct type *t)
 LONGEST
 ada_discrete_type_high_bound (struct type *type)
 {
-  type = resolve_dynamic_type (type, NULL, 0);
+  type = resolve_dynamic_type (type, {}, 0);
   switch (TYPE_CODE (type))
     {
     case TYPE_CODE_RANGE:
@@ -790,7 +770,7 @@ ada_discrete_type_high_bound (struct type *type)
 LONGEST
 ada_discrete_type_low_bound (struct type *type)
 {
-  type = resolve_dynamic_type (type, NULL, 0);
+  type = resolve_dynamic_type (type, {}, 0);
   switch (TYPE_CODE (type))
     {
     case TYPE_CODE_RANGE:
@@ -1016,17 +996,17 @@ ada_encode (const char *decoded)
    to next call.  */
 
 static char *
-ada_fold_name (const char *name)
+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
@@ -1376,7 +1356,7 @@ ada_decode_symbol (const struct general_symbol_info *arg)
 
   if (!gsymbol->ada_mangled)
     {
-      std::string decoded = ada_decode (gsymbol->name);
+      std::string decoded = ada_decode (gsymbol->linkage_name ());
       struct obstack *obstack = gsymbol->language_specific.obstack;
 
       gsymbol->ada_mangled = 1;
@@ -2525,7 +2505,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,
@@ -2829,7 +2809,7 @@ ada_value_slice_from_ptr (struct value *array_ptr, struct type *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));
   LONGEST base_low_pos, low_pos;
@@ -2859,7 +2839,7 @@ ada_value_slice (struct value *array, int low, int high)
     = create_static_range_type (NULL, TYPE_INDEX_TYPE (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;
 
@@ -4710,7 +4690,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.
@@ -4733,9 +4712,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;
@@ -5660,8 +5637,8 @@ add_nonlocal_symbols (struct obstack *obstackp,
   if (num_defns_collected (obstackp) == 0 && global && !is_wild_match)
     {
       const char *name = ada_lookup_name (lookup_name);
-      lookup_name_info name1 (std::string ("<_ada_") + name + '>',
-                             symbol_name_match_type::FULL);
+      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 ())
         {
@@ -7145,7 +7122,7 @@ 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)
 {
@@ -7664,26 +7641,21 @@ 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;
@@ -7774,15 +7746,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
@@ -8064,7 +8027,7 @@ empty_record (struct type *templ)
 {
   struct type *type = alloc_type_copy (templ);
 
-  TYPE_CODE (type) = TYPE_CODE_STRUCT;
+  type->set_code (TYPE_CODE_STRUCT);
   TYPE_NFIELDS (type) = 0;
   TYPE_FIELDS (type) = NULL;
   INIT_NONE_SPECIFIC (type);
@@ -8120,7 +8083,7 @@ ada_template_to_fixed_record_type_1 (struct type *type,
     }
 
   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 *)
@@ -8135,7 +8098,7 @@ 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);
       TYPE_FIELD_BITSIZE (rtype, f) = 0;
@@ -8256,7 +8219,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
@@ -8302,7 +8265,7 @@ ada_template_to_fixed_record_type_1 (struct type *type,
           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;
         }
     }
 
@@ -8323,8 +8286,8 @@ ada_template_to_fixed_record_type_1 (struct type *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);
@@ -8395,7 +8358,7 @@ 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 (TYPE_CODE(type0));
              INIT_NONE_SPECIFIC (type);
              TYPE_NFIELDS (type) = nfields;
              TYPE_FIELDS (type) = (struct field *)
@@ -8444,7 +8407,7 @@ 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) =
@@ -8558,9 +8521,7 @@ 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);
@@ -10415,7 +10376,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
         /* 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;
+          value_type (result)->set_code (TYPE_CODE_ARRAY);
         return result;
       }
 
@@ -13956,14 +13917,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
+         = user_name.substr (1, user_name.size () - 2).to_string ();
       else
-       m_encoded_name = user_name.substr (1, user_name.size () - 1);
+       m_encoded_name
+         = user_name.substr (1, user_name.size () - 1).to_string ();
       m_encoded_p = true;
       m_verbatim_p = true;
       m_wild_match_p = false;
@@ -13973,19 +13936,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 = user_name.to_string ();
        }
       else
-       m_encoded_name = user_name;
+       m_encoded_name = user_name.to_string ();
 
       /* Handle the 'package Standard' special case.  See description
         of m_standard_p.  */
@@ -14032,12 +13995,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);
@@ -14112,7 +14075,7 @@ extern const struct language_defn ada_language_defn = {
   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_inner,       /* la_value_print_inner */
   ada_value_print,              /* Print a top-level value */
   ada_read_var_value,          /* la_read_var_value */
   NULL,                         /* Language specific skip_trampoline */
@@ -14147,24 +14110,6 @@ extern const struct language_defn ada_language_defn = {
 static struct cmd_list_element *set_ada_list;
 static struct cmd_list_element *show_ada_list;
 
-/* Implement the "set ada" prefix command.  */
-
-static void
-set_ada_command (const char *arg, int from_tty)
-{
-  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);
-}
-
-/* Implement the "show ada" prefix command.  */
-
-static void
-show_ada_command (const char *args, int from_tty)
-{
-  cmd_show_list (show_ada_list, from_tty, "");
-}
-
 static void
 initialize_ada_catchpoint_ops (void)
 {
@@ -14229,18 +14174,19 @@ 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, _("\
@@ -14317,15 +14263,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.035142 seconds and 4 git commands to generate.