Remove parameter from language_info
[binutils-gdb.git] / gdb / language.c
index 1a0e20ea95037d39d9b870a50e40d3f2a635bc1d..4cb71d6dfb16beef5a9be65818ff0c56c253ce30 100644 (file)
@@ -1,6 +1,6 @@
 /* Multiple source language support for GDB.
 
-   Copyright (C) 1991-2020 Free Software Foundation, Inc.
+   Copyright (C) 1991-2021 Free Software Foundation, Inc.
 
    Contributed by the Department of Computer Science at the State University
    of New York at Buffalo.
@@ -46,6 +46,7 @@
 #include "c-lang.h"
 #include <algorithm>
 #include "gdbarch.h"
+#include "compile/compile-internal.h"
 
 static void set_range_case (void);
 
@@ -373,26 +374,17 @@ set_language (enum language lang)
 }
 \f
 
-/* Print out the current language settings: language, range and
-   type checking.  If QUIETLY, print only what has changed.  */
+/* See language.h.  */
 
 void
-language_info (int quietly)
+language_info ()
 {
-  if (quietly && expected_language == current_language)
+  if (expected_language == current_language)
     return;
 
   expected_language = current_language;
   printf_unfiltered (_("Current language:  %s\n"), language);
   show_language_command (NULL, 1, NULL, NULL);
-
-  if (!quietly)
-    {
-      printf_unfiltered (_("Range checking:    %s\n"), range);
-      show_range_command (NULL, 1, NULL, NULL);
-      printf_unfiltered (_("Case sensitivity:  %s\n"), case_sensitive);
-      show_case_command (NULL, 1, NULL, NULL);
-    }
 }
 \f
 
@@ -677,15 +669,6 @@ language_defn::emitchar (int ch, struct type *chtype,
 
 /* See language.h.  */
 
-void
-language_defn::printchar (int ch, struct type *chtype,
-                         struct ui_file * stream) const
-{
-  c_printchar (ch, chtype, stream);
-}
-
-/* See language.h.  */
-
 void
 language_defn::printstr (struct ui_file *stream, struct type *elttype,
                         const gdb_byte *string, unsigned int length,
@@ -713,6 +696,14 @@ language_defn::is_string_type_p (struct type *type) const
   return c_is_string_type_p (type);
 }
 
+/* See language.h.  */
+
+std::unique_ptr<compile_instance>
+language_defn::get_compile_instance () const
+{
+  return {};
+}
+
 /* The default implementation of the get_symbol_name_matcher_inner method
    from the language_defn class.  Matches with strncmp_iw.  */
 
@@ -774,14 +765,6 @@ language_defn::varobj_ops () const
   return &c_varobj_ops;
 }
 
-/* See language.h.  */
-
-const struct exp_descriptor *
-language_defn::expression_ops () const
-{
-  return &exp_descriptor_standard;
-}
-
 /* Parent class for both the "auto" and "unknown" languages.  These two
    pseudo-languages are very similar so merging their implementations like
    this makes sense.  */
@@ -797,10 +780,8 @@ public:
   void language_arch_info (struct gdbarch *gdbarch,
                           struct language_arch_info *lai) const override
   {
-    lai->string_char_type = builtin_type (gdbarch)->builtin_char;
-    lai->bool_type_default = builtin_type (gdbarch)->builtin_int;
-    lai->primitive_type_vector = GDBARCH_OBSTACK_CALLOC (gdbarch, 1,
-                                                      struct type *);
+    lai->set_string_char_type (builtin_type (gdbarch)->builtin_char);
+    lai->set_bool_type (builtin_type (gdbarch)->builtin_int);
   }
 
   /* See language.h.  */
@@ -903,18 +884,6 @@ public:
 
   const char *name_of_this () const override
   { return "this"; }
-
-  /* See language.h.  */
-
-  const struct op_print *opcode_print_table () const override
-  {
-    static const struct op_print unk_op_print_tab[] =
-      {
-       {NULL, OP_NULL, PREC_NULL, 0}
-      };
-
-    return unk_op_print_tab;
-  }
 };
 
 /* Class representing the fake "auto" language.  */
@@ -985,143 +954,166 @@ struct language_gdbarch
 static void *
 language_gdbarch_post_init (struct gdbarch *gdbarch)
 {
-  struct language_gdbarch *l;
-
-  l = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct language_gdbarch);
+  struct language_gdbarch *l
+    = obstack_new<struct language_gdbarch> (gdbarch_obstack (gdbarch));
   for (const auto &lang : language_defn::languages)
     {
       gdb_assert (lang != nullptr);
-      lang->language_arch_info (gdbarch,
-                               l->arch_info + lang->la_language);
+      lang->language_arch_info (gdbarch, &l->arch_info[lang->la_language]);
     }
 
   return l;
 }
 
+/* See language.h.  */
+
 struct type *
 language_string_char_type (const struct language_defn *la,
                           struct gdbarch *gdbarch)
 {
   struct language_gdbarch *ld
     = (struct language_gdbarch *) gdbarch_data (gdbarch, language_gdbarch_data);
-
-  return ld->arch_info[la->la_language].string_char_type;
+  return ld->arch_info[la->la_language].string_char_type ();
 }
 
+/* See language.h.  */
+
 struct type *
 language_bool_type (const struct language_defn *la,
                    struct gdbarch *gdbarch)
 {
   struct language_gdbarch *ld
     = (struct language_gdbarch *) gdbarch_data (gdbarch, language_gdbarch_data);
+  return ld->arch_info[la->la_language].bool_type ();
+}
 
-  if (ld->arch_info[la->la_language].bool_type_symbol)
+/* See language.h.  */
+
+struct type *
+language_arch_info::bool_type () const
+{
+  if (m_bool_type_name != nullptr)
     {
       struct symbol *sym;
 
-      sym = lookup_symbol (ld->arch_info[la->la_language].bool_type_symbol,
-                          NULL, VAR_DOMAIN, NULL).symbol;
-      if (sym)
+      sym = lookup_symbol (m_bool_type_name, NULL, VAR_DOMAIN, NULL).symbol;
+      if (sym != nullptr)
        {
          struct type *type = SYMBOL_TYPE (sym);
-
-         if (type && type->code () == TYPE_CODE_BOOL)
+         if (type != nullptr && type->code () == TYPE_CODE_BOOL)
            return type;
        }
     }
 
-  return ld->arch_info[la->la_language].bool_type_default;
+  return m_bool_type_default;
 }
 
-/* Helper function for primitive type lookup.  */
+/* See language.h.  */
 
-static struct type **
-language_lookup_primitive_type_1 (const struct language_arch_info *lai,
-                                 const char *name)
+struct symbol *
+language_arch_info::type_and_symbol::alloc_type_symbol
+       (enum language lang, struct type *type)
 {
-  struct type **p;
+  struct symbol *symbol;
+  struct gdbarch *gdbarch;
+  gdb_assert (!type->is_objfile_owned ());
+  gdbarch = type->arch_owner ();
+  symbol = new (gdbarch_obstack (gdbarch)) struct symbol ();
+  symbol->m_name = type->name ();
+  symbol->set_language (lang, nullptr);
+  symbol->owner.arch = gdbarch;
+  SYMBOL_OBJFILE_OWNED (symbol) = 0;
+  symbol->set_section_index (0);
+  SYMBOL_TYPE (symbol) = type;
+  SYMBOL_DOMAIN (symbol) = VAR_DOMAIN;
+  SYMBOL_ACLASS_INDEX (symbol) = LOC_TYPEDEF;
+  return symbol;
+}
 
-  for (p = lai->primitive_type_vector; (*p) != NULL; p++)
+/* See language.h.  */
+
+language_arch_info::type_and_symbol *
+language_arch_info::lookup_primitive_type_and_symbol (const char *name)
+{
+  for (struct type_and_symbol &tas : primitive_types_and_symbols)
     {
-      if (strcmp ((*p)->name (), name) == 0)
-       return p;
+      if (strcmp (tas.type ()->name (), name) == 0)
+       return &tas;
     }
-  return NULL;
+
+  return nullptr;
 }
 
 /* See language.h.  */
 
 struct type *
-language_lookup_primitive_type (const struct language_defn *la,
-                               struct gdbarch *gdbarch,
-                               const char *name)
+language_arch_info::lookup_primitive_type (const char *name)
 {
-  struct language_gdbarch *ld =
-    (struct language_gdbarch *) gdbarch_data (gdbarch, language_gdbarch_data);
-  struct type **typep;
-
-  typep = language_lookup_primitive_type_1 (&ld->arch_info[la->la_language],
-                                           name);
-  if (typep == NULL)
-    return NULL;
-  return *typep;
+  type_and_symbol *tas = lookup_primitive_type_and_symbol (name);
+  if (tas != nullptr)
+    return tas->type ();
+  return nullptr;
 }
 
-/* Helper function for type lookup as a symbol.
-   Create the symbol corresponding to type TYPE in language LANG.  */
+/* See language.h.  */
 
-static struct symbol *
-language_alloc_type_symbol (enum language lang, struct type *type)
+struct type *
+language_arch_info::lookup_primitive_type
+  (gdb::function_view<bool (struct type *)> filter)
 {
-  struct symbol *symbol;
-  struct gdbarch *gdbarch;
-
-  gdb_assert (!TYPE_OBJFILE_OWNED (type));
+  for (struct type_and_symbol &tas : primitive_types_and_symbols)
+    {
+      if (filter (tas.type ()))
+       return tas.type ();
+    }
 
-  gdbarch = TYPE_OWNER (type).gdbarch;
-  symbol = new (gdbarch_obstack (gdbarch)) struct symbol ();
+  return nullptr;
+}
 
-  symbol->m_name = type->name ();
-  symbol->set_language (lang, nullptr);
-  symbol->owner.arch = gdbarch;
-  SYMBOL_OBJFILE_OWNED (symbol) = 0;
-  SYMBOL_SECTION (symbol) = 0;
-  SYMBOL_TYPE (symbol) = type;
-  SYMBOL_DOMAIN (symbol) = VAR_DOMAIN;
-  SYMBOL_ACLASS_INDEX (symbol) = LOC_TYPEDEF;
+/* See language.h.  */
 
-  return symbol;
+struct symbol *
+language_arch_info::lookup_primitive_type_as_symbol (const char *name,
+                                                    enum language lang)
+{
+  type_and_symbol *tas = lookup_primitive_type_and_symbol (name);
+  if (tas != nullptr)
+    return tas->symbol (lang);
+  return nullptr;
 }
 
-/* Initialize the primitive type symbols of language LD.
-   The primitive type vector must have already been initialized.  */
+/* Helper for the language_lookup_primitive_type overloads to forward
+   to the corresponding language's lookup_primitive_type overload.  */
 
-static void
-language_init_primitive_type_symbols (struct language_arch_info *lai,
-                                     const struct language_defn *la,
-                                     struct gdbarch *gdbarch)
+template<typename T>
+static struct type *
+language_lookup_primitive_type_1 (const struct language_defn *la,
+                                 struct gdbarch *gdbarch,
+                                 T arg)
 {
-  int n;
-
-  gdb_assert (lai->primitive_type_vector != NULL);
+  struct language_gdbarch *ld =
+    (struct language_gdbarch *) gdbarch_data (gdbarch, language_gdbarch_data);
+  return ld->arch_info[la->la_language].lookup_primitive_type (arg);
+}
 
-  for (n = 0; lai->primitive_type_vector[n] != NULL; ++n)
-    continue;
+/* See language.h.  */
 
-  lai->primitive_type_symbols
-    = GDBARCH_OBSTACK_CALLOC (gdbarch, n + 1, struct symbol *);
+struct type *
+language_lookup_primitive_type (const struct language_defn *la,
+                               struct gdbarch *gdbarch,
+                               const char *name)
+{
+  return language_lookup_primitive_type_1 (la, gdbarch, name);
+}
 
-  for (n = 0; lai->primitive_type_vector[n] != NULL; ++n)
-    {
-      lai->primitive_type_symbols[n]
-       = language_alloc_type_symbol (la->la_language,
-                                     lai->primitive_type_vector[n]);
-    }
+/* See language.h.  */
 
-  /* Note: The result of symbol lookup is normally a symbol *and* the block
-     it was found in.  Builtin types don't live in blocks.  We *could* give
-     them one, but there is no current need so to keep things simple symbol
-     lookup is extended to allow for BLOCK_FOUND to be NULL.  */
+struct type *
+language_lookup_primitive_type (const struct language_defn *la,
+                               struct gdbarch *gdbarch,
+                               gdb::function_view<bool (struct type *)> filter)
+{
+  return language_lookup_primitive_type_1 (la, gdbarch, filter);
 }
 
 /* See language.h.  */
@@ -1134,33 +1126,24 @@ language_lookup_primitive_type_as_symbol (const struct language_defn *la,
   struct language_gdbarch *ld
     = (struct language_gdbarch *) gdbarch_data (gdbarch, language_gdbarch_data);
   struct language_arch_info *lai = &ld->arch_info[la->la_language];
-  struct type **typep;
-  struct symbol *sym;
 
   if (symbol_lookup_debug)
-    {
-      fprintf_unfiltered (gdb_stdlog,
-                         "language_lookup_primitive_type_as_symbol"
-                         " (%s, %s, %s)",
-                         la->name (), host_address_to_string (gdbarch), name);
-    }
-
-  typep = language_lookup_primitive_type_1 (lai, name);
-  if (typep == NULL)
-    {
-      if (symbol_lookup_debug)
-       fprintf_unfiltered (gdb_stdlog, " = NULL\n");
-      return NULL;
-    }
+    fprintf_unfiltered (gdb_stdlog,
+                       "language_lookup_primitive_type_as_symbol"
+                       " (%s, %s, %s)",
+                       la->name (), host_address_to_string (gdbarch), name);
 
-  /* The set of symbols is lazily initialized.  */
-  if (lai->primitive_type_symbols == NULL)
-    language_init_primitive_type_symbols (lai, la, gdbarch);
-
-  sym = lai->primitive_type_symbols[typep - lai->primitive_type_vector];
+  struct symbol *sym
+    = lai->lookup_primitive_type_as_symbol (name, la->la_language);
 
   if (symbol_lookup_debug)
     fprintf_unfiltered (gdb_stdlog, " = %s\n", host_address_to_string (sym));
+
+  /* Note: The result of symbol lookup is normally a symbol *and* the block
+     it was found in.  Builtin types don't live in blocks.  We *could* give
+     them one, but there is no current need so to keep things simple symbol
+     lookup is extended to allow for BLOCK_FOUND to be NULL.  */
+
   return sym;
 }