gdb: Convert la_name and la_natural_name to methods
[deliverable/binutils-gdb.git] / gdb / symtab.c
index b765a583c421ca0caa8451b49cc123ac5db72ad2..61f96b2ab8c2a035812c9956a82f80491c26dd12 100644 (file)
@@ -595,7 +595,7 @@ gdb_mangle_name (struct type *type, int method_id, int signature_id)
   struct fn_field *method = &f[signature_id];
   const char *field_name = TYPE_FN_FIELDLIST_NAME (type, method_id);
   const char *physname = TYPE_FN_FIELD_PHYSNAME (f, signature_id);
-  const char *newname = TYPE_NAME (type);
+  const char *newname = type->name ();
 
   /* Does the form of physname indicate that it is the full mangled name
      of a constructor (not just the args)?  */
@@ -807,7 +807,7 @@ symbol_find_demangled_name (struct general_symbol_info *gsymbol,
     {
       const struct language_defn *lang = language_def (gsymbol->language ());
 
-      language_sniff_from_mangled_name (lang, mangled, &demangled);
+      lang->sniff_from_mangled_name (mangled, &demangled);
       return demangled;
     }
 
@@ -816,7 +816,7 @@ symbol_find_demangled_name (struct general_symbol_info *gsymbol,
       enum language l = (enum language) i;
       const struct language_defn *lang = language_def (l);
 
-      if (language_sniff_from_mangled_name (lang, mangled, &demangled))
+      if (lang->sniff_from_mangled_name (mangled, &demangled))
        {
          gsymbol->m_language = l;
          return demangled;
@@ -1016,7 +1016,7 @@ symbol_matches_search_name (const struct general_symbol_info *gsymbol,
                            const lookup_name_info &name)
 {
   symbol_name_matcher_ftype *name_match
-    = get_symbol_name_matcher (language_def (gsymbol->language ()), name);
+    = language_def (gsymbol->language ())->get_symbol_name_matcher (name);
   return name_match (gsymbol->search_name (), name, NULL);
 }
 
@@ -1855,7 +1855,7 @@ demangle_for_lookup (const char *name, enum language lang,
 unsigned int
 search_name_hash (enum language language, const char *search_name)
 {
-  return language_def (language)->la_search_name_hash (search_name);
+  return language_def (language)->search_name_hash (search_name);
 }
 
 /* See symtab.h.
@@ -1912,16 +1912,16 @@ struct block_symbol
 lookup_language_this (const struct language_defn *lang,
                      const struct block *block)
 {
-  if (lang->la_name_of_this == NULL || block == NULL)
+  if (lang->name_of_this () == NULL || block == NULL)
     return {};
 
   if (symbol_lookup_debug > 1)
     {
-      struct objfile *objfile = lookup_objfile_from_block (block);
+      struct objfile *objfile = block_objfile (block);
 
       fprintf_unfiltered (gdb_stdlog,
                          "lookup_language_this (%s, %s (objfile %s))",
-                         lang->la_name, host_address_to_string (block),
+                         lang->name (), host_address_to_string (block),
                          objfile_debug_name (objfile));
     }
 
@@ -1929,7 +1929,7 @@ lookup_language_this (const struct language_defn *lang,
     {
       struct symbol *sym;
 
-      sym = block_lookup_symbol (block, lang->la_name_of_this,
+      sym = block_lookup_symbol (block, lang->name_of_this (),
                                 symbol_name_match_type::SEARCH_NAME,
                                 VAR_DOMAIN);
       if (sym != NULL)
@@ -1966,14 +1966,14 @@ check_field (struct type *type, const char *name,
   /* The type may be a stub.  */
   type = check_typedef (type);
 
-  for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
+  for (i = type->num_fields () - 1; i >= TYPE_N_BASECLASSES (type); i--)
     {
       const char *t_field_name = TYPE_FIELD_NAME (type, i);
 
       if (t_field_name && (strcmp_iw (t_field_name, name) == 0))
        {
          is_a_field_of_this->type = type;
-         is_a_field_of_this->field = &TYPE_FIELD (type, i);
+         is_a_field_of_this->field = &type->field (i);
          return 1;
        }
     }
@@ -2012,7 +2012,8 @@ lookup_symbol_aux (const char *name, symbol_name_match_type match_type,
 
   if (symbol_lookup_debug)
     {
-      struct objfile *objfile = lookup_objfile_from_block (block);
+      struct objfile *objfile = (block == nullptr
+                                ? nullptr : block_objfile (block));
 
       fprintf_unfiltered (gdb_stdlog,
                          "lookup_symbol_aux (%s, %s (objfile %s), %s, %s)\n",
@@ -2062,13 +2063,13 @@ lookup_symbol_aux (const char *name, symbol_name_match_type match_type,
          /* I'm not really sure that type of this can ever
             be typedefed; just be safe.  */
          t = check_typedef (t);
-         if (TYPE_CODE (t) == TYPE_CODE_PTR || TYPE_IS_REFERENCE (t))
+         if (t->code () == TYPE_CODE_PTR || TYPE_IS_REFERENCE (t))
            t = TYPE_TARGET_TYPE (t);
 
-         if (TYPE_CODE (t) != TYPE_CODE_STRUCT
-             && TYPE_CODE (t) != TYPE_CODE_UNION)
+         if (t->code () != TYPE_CODE_STRUCT
+             && t->code () != TYPE_CODE_UNION)
            error (_("Internal error: `%s' is not an aggregate"),
-                  langdef->la_name_of_this);
+                  langdef->name_of_this ());
 
          if (check_field (t, name, is_a_field_of_this))
            {
@@ -2085,7 +2086,7 @@ lookup_symbol_aux (const char *name, symbol_name_match_type match_type,
   /* Now do whatever is appropriate for LANGUAGE to look
      up static and global variables.  */
 
-  result = langdef->la_lookup_symbol_nonlocal (langdef, name, block, domain);
+  result = langdef->lookup_symbol_nonlocal (name, block, domain);
   if (result.symbol != NULL)
     {
       if (symbol_lookup_debug)
@@ -2157,32 +2158,6 @@ lookup_local_symbol (const char *name,
 
 /* See symtab.h.  */
 
-struct objfile *
-lookup_objfile_from_block (const struct block *block)
-{
-  if (block == NULL)
-    return NULL;
-
-  block = block_global_block (block);
-  /* Look through all blockvectors.  */
-  for (objfile *obj : current_program_space->objfiles ())
-    {
-      for (compunit_symtab *cust : obj->compunits ())
-       if (block == BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust),
-                                       GLOBAL_BLOCK))
-         {
-           if (obj->separate_debug_objfile_backlink)
-             obj = obj->separate_debug_objfile_backlink;
-
-           return obj;
-         }
-    }
-
-  return NULL;
-}
-
-/* See symtab.h.  */
-
 struct symbol *
 lookup_symbol_in_block (const char *name, symbol_name_match_type match_type,
                        const struct block *block,
@@ -2192,7 +2167,8 @@ lookup_symbol_in_block (const char *name, symbol_name_match_type match_type,
 
   if (symbol_lookup_debug > 1)
     {
-      struct objfile *objfile = lookup_objfile_from_block (block);
+      struct objfile *objfile = (block == nullptr
+                                ? nullptr : block_objfile (block));
 
       fprintf_unfiltered (gdb_stdlog,
                          "lookup_symbol_in_block (%s, %s (objfile %s), %s)",
@@ -2425,13 +2401,12 @@ lookup_symbol_via_quick_fns (struct objfile *objfile,
   return result;
 }
 
-/* See symtab.h.  */
+/* See language.h.  */
 
 struct block_symbol
-basic_lookup_symbol_nonlocal (const struct language_defn *langdef,
-                             const char *name,
-                             const struct block *block,
-                             const domain_enum domain)
+language_defn::lookup_symbol_nonlocal (const char *name,
+                                      const struct block *block,
+                                      const domain_enum domain) const
 {
   struct block_symbol result;
 
@@ -2457,7 +2432,7 @@ basic_lookup_symbol_nonlocal (const struct language_defn *langdef,
        gdbarch = target_gdbarch ();
       else
        gdbarch = block_gdbarch (block);
-      result.symbol = language_lookup_primitive_type_as_symbol (langdef,
+      result.symbol = language_lookup_primitive_type_as_symbol (this,
                                                                gdbarch, name);
       result.block = NULL;
       if (result.symbol != NULL)
@@ -2482,7 +2457,8 @@ lookup_symbol_in_static_block (const char *name,
 
   if (symbol_lookup_debug)
     {
-      struct objfile *objfile = lookup_objfile_from_block (static_block);
+      struct objfile *objfile = (block == nullptr
+                                ? nullptr : block_objfile (block));
 
       fprintf_unfiltered (gdb_stdlog,
                          "lookup_symbol_in_static_block (%s, %s (objfile %s),"
@@ -2704,7 +2680,14 @@ lookup_global_symbol (const char *name,
        return { sym, global_block };
     }
 
-  struct objfile *objfile = lookup_objfile_from_block (block);
+  struct objfile *objfile = nullptr;
+  if (block != nullptr)
+    {
+      objfile = block_objfile (block);
+      if (objfile->separate_debug_objfile_backlink != nullptr)
+       objfile = objfile->separate_debug_objfile_backlink;
+    }
+
   block_symbol bs
     = lookup_global_or_static_symbol (name, GLOBAL_BLOCK, objfile, domain);
   if (better_symbol (sym, bs.symbol, domain) == sym)
@@ -2738,7 +2721,7 @@ symbol_matches_domain (enum language symbol_language,
 struct type *
 lookup_transparent_type (const char *name)
 {
-  return current_language->la_lookup_transparent_type (name);
+  return current_language->lookup_transparent_type (name);
 }
 
 /* A helper for basic_lookup_transparent_type that interfaces with the
@@ -3253,12 +3236,7 @@ find_pc_sect_line (CORE_ADDR pc, struct obj_section *section, int notcurrent)
       struct linetable_entry *last = item + len;
       item = std::upper_bound (first, last, pc, pc_compare);
       if (item != first)
-       {
-         /* Found a matching item.  Skip backwards over any end of
-            sequence markers.  */
-         for (prev = item - 1; prev->line == 0 && prev != first; prev--)
-           /* Nothing.  */;
-       }
+       prev = item - 1;                /* Found a matching item.  */
 
       /* At this point, prev points at the line whose start addr is <= pc, and
          item points at the next line.  If we ran off the end of the linetable
@@ -4652,7 +4630,7 @@ global_symbol_searcher::add_matching_symbols
                              members.  We only want to skip enums
                              here.  */
                           && !(SYMBOL_CLASS (sym) == LOC_CONST
-                               && (TYPE_CODE (SYMBOL_TYPE (sym))
+                               && (SYMBOL_TYPE (sym)->code ()
                                    == TYPE_CODE_ENUM))
                           && (!treg.has_value ()
                               || treg_matches_sym_type_name (*treg, sym)))
@@ -4858,7 +4836,7 @@ symbol_to_info_string (struct symbol *sym, int block,
         For the struct printing case below, things are worse, we force
         printing of the ";" in this function, which is going to be wrong
         for languages that don't require a ";" between statements.  */
-      if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_TYPEDEF)
+      if (SYMBOL_TYPE (sym)->code () == TYPE_CODE_TYPEDEF)
        typedef_print (SYMBOL_TYPE (sym), sym, &tmp_stream);
       else
        type_print (SYMBOL_TYPE (sym), "", &tmp_stream, -1);
@@ -5212,6 +5190,11 @@ rbreak_command (const char *regexp, int from_tty)
     {
       const char *colon = strchr (regexp, ':');
 
+      /* Ignore the colon if it is part of a Windows drive.  */
+      if (HAS_DRIVE_SPEC (regexp)
+         && (regexp[2] == '/' || regexp[2] == '\\'))
+       colon = strchr (STRIP_DRIVE_SPEC (regexp), ':');
+
       if (colon && *(colon + 1) != ':')
        {
          int colon_index;
@@ -5269,14 +5252,14 @@ compare_symbol_name (const char *symbol_name, language symbol_language,
   const language_defn *lang = language_def (symbol_language);
 
   symbol_name_matcher_ftype *name_match
-    = get_symbol_name_matcher (lang, lookup_name);
+    = lang->get_symbol_name_matcher (lookup_name);
 
   return name_match (symbol_name, lookup_name, &match_res);
 }
 
 /*  See symtab.h.  */
 
-void
+bool
 completion_list_add_name (completion_tracker &tracker,
                          language symbol_language,
                          const char *symname,
@@ -5288,7 +5271,7 @@ completion_list_add_name (completion_tracker &tracker,
 
   /* Clip symbols that cannot match.  */
   if (!compare_symbol_name (symname, symbol_language, lookup_name, match_res))
-    return;
+    return false;
 
   /* Refresh SYMNAME from the match string.  It's potentially
      different depending on language.  (E.g., on Ada, the match may be
@@ -5312,6 +5295,8 @@ completion_list_add_name (completion_tracker &tracker,
     tracker.add_completion (std::move (completion),
                            &match_res.match_for_lcd, text, word);
   }
+
+  return true;
 }
 
 /* completion_list_add_name wrapper for struct symbol.  */
@@ -5322,9 +5307,10 @@ completion_list_add_symbol (completion_tracker &tracker,
                            const lookup_name_info &lookup_name,
                            const char *text, const char *word)
 {
-  completion_list_add_name (tracker, sym->language (),
-                           sym->natural_name (),
-                           lookup_name, text, word);
+  if (!completion_list_add_name (tracker, sym->language (),
+                                sym->natural_name (),
+                                lookup_name, text, word))
+    return;
 
   /* C++ function symbols include the parameters within both the msymbol
      name and the symbol name.  The problem is that the msymbol name will
@@ -5484,11 +5470,11 @@ completion_list_add_fields (completion_tracker &tracker,
   if (SYMBOL_CLASS (sym) == LOC_TYPEDEF)
     {
       struct type *t = SYMBOL_TYPE (sym);
-      enum type_code c = TYPE_CODE (t);
+      enum type_code c = t->code ();
       int j;
 
       if (c == TYPE_CODE_UNION || c == TYPE_CODE_STRUCT)
-       for (j = TYPE_N_BASECLASSES (t); j < TYPE_NFIELDS (t); j++)
+       for (j = TYPE_N_BASECLASSES (t); j < t->num_fields (); j++)
          if (TYPE_FIELD_NAME (t, j))
            completion_list_add_name (tracker, sym->language (),
                                      TYPE_FIELD_NAME (t, j),
@@ -5501,7 +5487,7 @@ completion_list_add_fields (completion_tracker &tracker,
 bool
 symbol_is_function_or_method (symbol *sym)
 {
-  switch (TYPE_CODE (SYMBOL_TYPE (sym)))
+  switch (SYMBOL_TYPE (sym)->code ())
     {
     case TYPE_CODE_FUNC:
     case TYPE_CODE_METHOD:
@@ -5601,7 +5587,7 @@ add_symtab_completions (struct compunit_symtab *cust,
 
          if (code == TYPE_CODE_UNDEF
              || (SYMBOL_DOMAIN (sym) == STRUCT_DOMAIN
-                 && TYPE_CODE (SYMBOL_TYPE (sym)) == code))
+                 && SYMBOL_TYPE (sym)->code () == code))
            completion_list_add_symbol (tracker, sym,
                                        lookup_name,
                                        text, word);
@@ -5752,7 +5738,7 @@ default_collect_symbol_completion_matches_break_on
                                            sym_text, word);
              }
            else if (SYMBOL_DOMAIN (sym) == STRUCT_DOMAIN
-                    && TYPE_CODE (SYMBOL_TYPE (sym)) == code)
+                    && SYMBOL_TYPE (sym)->code () == code)
              completion_list_add_symbol (tracker, sym, lookup_name,
                                          sym_text, word);
          }
@@ -5814,19 +5800,6 @@ default_collect_symbol_completion_matches_break_on
     }
 }
 
-void
-default_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)
-{
-  return default_collect_symbol_completion_matches_break_on (tracker, mode,
-                                                            name_match_type,
-                                                            text, word, "",
-                                                            code);
-}
-
 /* Collect all symbols (regardless of class) which begin by matching
    TEXT.  */
 
@@ -5836,10 +5809,10 @@ collect_symbol_completion_matches (completion_tracker &tracker,
                                   symbol_name_match_type name_match_type,
                                   const char *text, const char *word)
 {
-  current_language->la_collect_symbol_completion_matches (tracker, mode,
-                                                         name_match_type,
-                                                         text, word,
-                                                         TYPE_CODE_UNDEF);
+  current_language->collect_symbol_completion_matches (tracker, mode,
+                                                      name_match_type,
+                                                      text, word,
+                                                      TYPE_CODE_UNDEF);
 }
 
 /* Like collect_symbol_completion_matches, but only collect
@@ -5856,9 +5829,9 @@ collect_symbol_completion_matches_type (completion_tracker &tracker,
   gdb_assert (code == TYPE_CODE_UNION
              || code == TYPE_CODE_STRUCT
              || code == TYPE_CODE_ENUM);
-  current_language->la_collect_symbol_completion_matches (tracker, mode,
-                                                         name_match_type,
-                                                         text, word, code);
+  current_language->collect_symbol_completion_matches (tracker, mode,
+                                                      name_match_type,
+                                                      text, word, code);
 }
 
 /* Like collect_symbol_completion_matches, but collects a list of
@@ -6355,42 +6328,6 @@ initialize_ordinary_address_classes (void)
 
 \f
 
-/* Initialize the symbol SYM, and mark it as being owned by an objfile.  */
-
-void
-initialize_objfile_symbol (struct symbol *sym)
-{
-  SYMBOL_OBJFILE_OWNED (sym) = 1;
-  SYMBOL_SECTION (sym) = -1;
-}
-
-/* Allocate and initialize a new 'struct symbol' on OBJFILE's
-   obstack.  */
-
-struct symbol *
-allocate_symbol (struct objfile *objfile)
-{
-  struct symbol *result = new (&objfile->objfile_obstack) symbol ();
-
-  initialize_objfile_symbol (result);
-
-  return result;
-}
-
-/* Allocate and initialize a new 'struct template_symbol' on OBJFILE's
-   obstack.  */
-
-struct template_symbol *
-allocate_template_symbol (struct objfile *objfile)
-{
-  struct template_symbol *result;
-
-  result = new (&objfile->objfile_obstack) template_symbol ();
-  initialize_objfile_symbol (result);
-
-  return result;
-}
-
 /* See symtab.h.  */
 
 struct objfile *
This page took 0.037471 seconds and 4 git commands to generate.