]> Git Repo - binutils.git/blobdiff - gdb/compile/compile-cplus-types.c
Automatic date update in version.in
[binutils.git] / gdb / compile / compile-cplus-types.c
index 271cc665f85c5739946415a68ef73a9d584a12a6..bd90753eae17dfb09c8c00beb9f2cc68608af527 100644 (file)
@@ -1,6 +1,6 @@
 /* Convert types from GDB to GCC
 
-   Copyright (C) 2014-2018 Free Software Foundation, Inc.
+   Copyright (C) 2014-2022 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
 
 
 #include "defs.h"
-#include "common/preprocessor.h"
+#include "gdbsupport/preprocessor.h"
 #include "gdbtypes.h"
 #include "compile-internal.h"
 #include "compile-cplus.h"
-#include "gdb_assert.h"
+#include "gdbsupport/gdb_assert.h"
 #include "symtab.h"
 #include "source.h"
 #include "cp-support.h"
 #include "cp-abi.h"
-#include "symtab.h"
 #include "objfiles.h"
 #include "block.h"
 #include "gdbcmd.h"
 #include "c-lang.h"
-#include "compile-c.h"                 /* Included for c_get_range_decl_name
-                                  et al.  */
+#include "compile-c.h"
 #include <algorithm>
 
 /* Default compile flags for C++.  */
@@ -43,11 +41,11 @@ const char *compile_cplus_instance::m_default_cflags = "-std=gnu++11";
 
 /* Flag to enable internal debugging.  */
 
-static int debug_compile_cplus_types = 0;
+static bool debug_compile_cplus_types = false;
 
 /* Flag to enable internal scope switching debugging.  */
 
-static int debug_compile_cplus_scopes = 0;
+static bool debug_compile_cplus_scopes = false;
 
 /* Forward declarations.  */
 
@@ -63,11 +61,11 @@ compile_cplus_instance::decl_name (const char *natural)
   if (natural == nullptr)
     return nullptr;
 
-  char *name = cp_func_name (natural);
+  gdb::unique_xmalloc_ptr<char> name = cp_func_name (natural);
   if (name != nullptr)
-    return gdb::unique_xmalloc_ptr<char> (name);
+    return name;
 
-  return gdb::unique_xmalloc_ptr<char> (xstrdup (natural));
+  return make_unique_xstrdup (natural);
 }
 
 /* Get the access flag for the NUM'th field of TYPE.  */
@@ -90,10 +88,10 @@ get_field_access_flag (const struct type *type, int num)
 enum gcc_cp_symbol_kind
 get_method_access_flag (const struct type *type, int fni, int num)
 {
-  gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT);
+  gdb_assert (type->code () == TYPE_CODE_STRUCT);
 
   /* If this type was not declared a class, everything is public.  */
-  if (!TYPE_DECLARED_CLASS (type))
+  if (!type->is_declared_class ())
     return GCC_CP_ACCESS_PUBLIC;
 
   /* Otherwise, read accessibility from the fn_field.  */
@@ -114,7 +112,7 @@ debug_print_scope (const compile_scope &scope)
   for (const auto &comp: scope)
     {
       const char *symbol = (comp.bsymbol.symbol != nullptr
-                           ? SYMBOL_NATURAL_NAME (comp.bsymbol.symbol)
+                           ? comp.bsymbol.symbol->natural_name ()
                            : "<none>");
 
       printf_unfiltered ("\tname = %s, symbol = %s\n", comp.name.c_str (),
@@ -163,7 +161,7 @@ type_name_to_scope (const char *type_name, const struct block *block)
 
          scope.push_back (comp);
 
-         if (TYPE_CODE (SYMBOL_TYPE (bsymbol.symbol)) != TYPE_CODE_NAMESPACE)
+         if (bsymbol.symbol->type ()->code () != TYPE_CODE_NAMESPACE)
            {
              /* We're done.  */
              break;
@@ -180,8 +178,7 @@ type_name_to_scope (const char *type_name, const struct block *block)
              /* This shouldn't happen since we are not attempting to
                 loop over user input.  This name is generated by GDB
                 from debug info.  */
-             internal_error (__FILE__, __LINE__,
-                             _("malformed TYPE_NAME during parsing"));
+             internal_error (_("malformed TYPE_NAME during parsing"));
            }
        }
     }
@@ -247,21 +244,21 @@ operator!= (const compile_scope &lhs, const compile_scope &rhs)
 /* See description in compile-cplus.h.  */
 
 void
-compile_cplus_instance::enter_scope (compile_scope &new_scope)
+compile_cplus_instance::enter_scope (compile_scope &&new_scope)
 {
   bool must_push = m_scopes.empty () || m_scopes.back () != new_scope;
 
   new_scope.m_pushed = must_push;
 
   /* Save the new scope.  */
-  m_scopes.push_back (new_scope);
+  m_scopes.push_back (std::move (new_scope));
 
   if (must_push)
     {
       if (debug_compile_cplus_scopes)
        {
-         fprintf_unfiltered (gdb_stdlog, "entering new scope %s\n",
-                             host_address_to_string (&new_scope));
+         gdb_printf (gdb_stdlog, "entering new scope %s\n",
+                     host_address_to_string (&m_scopes.back ()));
        }
 
       /* Push the global namespace. */
@@ -270,10 +267,10 @@ compile_cplus_instance::enter_scope (compile_scope &new_scope)
       /* Push all other namespaces.  Note that we do not push the last
         scope_component -- that's the actual type we are converting.  */
       std::for_each
-       (new_scope.begin (), new_scope.end () - 1,
+       (m_scopes.back ().begin (), m_scopes.back ().end () - 1,
         [this] (const scope_component &comp)
         {
-         gdb_assert (TYPE_CODE (SYMBOL_TYPE (comp.bsymbol.symbol))
+         gdb_assert (comp.bsymbol.symbol->type ()->code ()
                      == TYPE_CODE_NAMESPACE);
 
          const char *ns = (comp.name == CP_ANONYMOUS_NAMESPACE_STR ? nullptr
@@ -286,8 +283,8 @@ compile_cplus_instance::enter_scope (compile_scope &new_scope)
     {
       if (debug_compile_cplus_scopes)
        {
-         fprintf_unfiltered (gdb_stdlog, "staying in current scope -- "
-                             "scopes are identical\n");
+         gdb_printf (gdb_stdlog, "staying in current scope -- "
+                     "scopes are identical\n");
        }
     }
 }
@@ -307,15 +304,15 @@ compile_cplus_instance::leave_scope ()
     {
       if (debug_compile_cplus_scopes)
        {
-         fprintf_unfiltered (gdb_stdlog, "leaving scope %s\n",
-                             host_address_to_string (&current));
+         gdb_printf (gdb_stdlog, "leaving scope %s\n",
+                     host_address_to_string (&current));
        }
 
       /* Pop namespaces.  */
       std::for_each
        (current.begin (),current.end () - 1,
         [this] (const scope_component &comp) {
-         gdb_assert (TYPE_CODE (SYMBOL_TYPE (comp.bsymbol.symbol))
+         gdb_assert (comp.bsymbol.symbol->type ()->code ()
                      == TYPE_CODE_NAMESPACE);
          this->plugin ().pop_binding_level (comp.name.c_str ());
        });
@@ -326,8 +323,8 @@ compile_cplus_instance::leave_scope ()
   else
     {
       if (debug_compile_cplus_scopes)
-       fprintf_unfiltered (gdb_stdlog,
-                           "identical scopes -- not leaving scope\n");
+       gdb_printf (gdb_stdlog,
+                   "identical scopes -- not leaving scope\n");
     }
 }
 
@@ -347,26 +344,26 @@ compile_cplus_instance::new_scope (const char *type_name, struct type *type)
         unqualified name of the type to process.  */
       scope_component &comp = scope.back ();
 
-      if (!types_equal (type, SYMBOL_TYPE (comp.bsymbol.symbol))
+      if (!types_equal (type, comp.bsymbol.symbol->type ())
          && (m_scopes.empty ()
              || (m_scopes.back ().back ().bsymbol.symbol
                  != comp.bsymbol.symbol)))
        {
          /* The type is defined inside another class(es).  Convert that
             type instead of defining this type.  */
-         convert_type (SYMBOL_TYPE (comp.bsymbol.symbol));
+         convert_type (comp.bsymbol.symbol->type ());
 
          /* If the original type (passed in to us) is defined in a nested
             class, the previous call will give us that type's gcc_type.
             Upper layers are expecting to get the original type's
             gcc_type!  */
-         get_cached_type (type, scope.m_nested_type);
+         get_cached_type (type, &scope.m_nested_type);
          return scope;
        }
     }
   else
     {
-      if (TYPE_NAME (type) == nullptr)
+      if (type->name () == nullptr)
        {
          /* Anonymous type  */
 
@@ -385,8 +382,8 @@ compile_cplus_instance::new_scope (const char *type_name, struct type *type)
        {
          scope_component comp
            = {
-               decl_name (TYPE_NAME (type)).get (),
-               lookup_symbol (TYPE_NAME (type), block (), VAR_DOMAIN, nullptr)
+               decl_name (type->name ()).get (),
+               lookup_symbol (type->name (), block (), VAR_DOMAIN, nullptr)
              };
          scope.push_back (comp);
        }
@@ -412,10 +409,10 @@ static gcc_type
 compile_cplus_convert_reference (compile_cplus_instance *instance,
                                 struct type *type)
 {
-  gcc_type target = instance->convert_type (TYPE_TARGET_TYPE (type));
+  gcc_type target = instance->convert_type (type->target_type ());
 
   enum gcc_cp_ref_qualifiers quals = GCC_CP_REF_QUAL_NONE;
-  switch (TYPE_CODE (type))
+  switch (type->code ())
     {
     case TYPE_CODE_REF:
       quals = GCC_CP_REF_QUAL_LVALUE;
@@ -444,7 +441,7 @@ static gcc_type
 compile_cplus_convert_pointer (compile_cplus_instance *instance,
                               struct type *type)
 {
-  gcc_type target = instance->convert_type (TYPE_TARGET_TYPE (type));
+  gcc_type target = instance->convert_type (type->target_type ());
 
   return instance->convert_pointer_base (target);
 }
@@ -455,10 +452,10 @@ static gcc_type
 compile_cplus_convert_array (compile_cplus_instance *instance,
                             struct type *type)
 {
-  struct type *range = TYPE_INDEX_TYPE (type);
-  gcc_type element_type = instance->convert_type (TYPE_TARGET_TYPE (type));
+  struct type *range = type->index_type ();
+  gcc_type element_type = instance->convert_type (type->target_type ());
 
-  if (TYPE_LOW_BOUND_KIND (range) != PROP_CONST)
+  if (range->bounds ()->low.kind () != PROP_CONST)
     {
       const char *s = _("array type with non-constant"
                        " lower bound is not supported");
@@ -466,7 +463,7 @@ compile_cplus_convert_array (compile_cplus_instance *instance,
       return instance->plugin ().error (s);
     }
 
-  if (TYPE_LOW_BOUND (range) != 0)
+  if (range->bounds ()->low.const_val () != 0)
     {
       const char *s = _("cannot convert array type with "
                        "non-zero lower bound to C");
@@ -474,10 +471,10 @@ compile_cplus_convert_array (compile_cplus_instance *instance,
       return instance->plugin ().error (s);
     }
 
-  if (TYPE_HIGH_BOUND_KIND (range) == PROP_LOCEXPR
-      || TYPE_HIGH_BOUND_KIND (range) == PROP_LOCLIST)
+  if (range->bounds ()->high.kind () == PROP_LOCEXPR
+      || range->bounds ()->high.kind () == PROP_LOCLIST)
     {
-      if (TYPE_VECTOR (type))
+      if (type->is_vector ())
        {
          const char *s = _("variably-sized vector type is not supported");
 
@@ -485,7 +482,7 @@ compile_cplus_convert_array (compile_cplus_instance *instance,
        }
 
       std::string upper_bound
-       = c_get_range_decl_name (&TYPE_RANGE_DATA (range)->high);
+       = c_get_range_decl_name (&range->bounds ()->high);
       return instance->plugin ().build_vla_array_type (element_type,
                                             upper_bound.c_str ());
     }
@@ -493,7 +490,7 @@ compile_cplus_convert_array (compile_cplus_instance *instance,
     {
       LONGEST low_bound, high_bound, count;
 
-      if (get_array_bounds (type, &low_bound, &high_bound) == 0)
+      if (!get_array_bounds (type, &low_bound, &high_bound))
        count = -1;
       else
        {
@@ -501,7 +498,7 @@ compile_cplus_convert_array (compile_cplus_instance *instance,
          count = high_bound + 1;
        }
 
-      if (TYPE_VECTOR (type))
+      if (type->is_vector ())
        return instance->plugin ().build_vector_type (element_type, count);
 
       return instance->plugin ().build_array_type (element_type, count);
@@ -517,16 +514,16 @@ compile_cplus_convert_typedef (compile_cplus_instance *instance,
                               struct type *type,
                               enum gcc_cp_symbol_kind nested_access)
 {
-  compile_scope scope = instance->new_scope (TYPE_NAME (type), type);
+  compile_scope scope = instance->new_scope (type->name (), type);
 
   if (scope.nested_type () != GCC_TYPE_NONE)
     return scope.nested_type ();
 
   gdb::unique_xmalloc_ptr<char> name
-    = compile_cplus_instance::decl_name (TYPE_NAME (type));
+    = compile_cplus_instance::decl_name (type->name ());
 
   /* Make sure the scope for this type has been pushed.  */
-  instance->enter_scope (scope);
+  instance->enter_scope (std::move (scope));
 
   /* Convert the typedef's real type.  */
   gcc_type typedef_type = instance->convert_type (check_typedef (type));
@@ -582,9 +579,9 @@ static void
 compile_cplus_convert_struct_or_union_members
   (compile_cplus_instance *instance, struct type *type, gcc_type comp_type)
 {
-  for (int i = TYPE_N_BASECLASSES (type); i < TYPE_NFIELDS (type); ++i)
+  for (int i = TYPE_N_BASECLASSES (type); i < type->num_fields (); ++i)
     {
-      const char *field_name = TYPE_FIELD_NAME (type, i);
+      const char *field_name = type->field (i).name ();
 
       if (TYPE_FIELD_IGNORE (type, i)
          || TYPE_FIELD_ARTIFICIAL (type, i))
@@ -595,17 +592,17 @@ compile_cplus_convert_struct_or_union_members
        field_name = nullptr;
 
       gcc_type field_type
-       = instance->convert_type (TYPE_FIELD_TYPE (type, i));
+       = instance->convert_type (type->field (i).type ());
 
-      if (field_is_static (&TYPE_FIELD (type, i)))
+      if (field_is_static (&type->field (i)))
        {
          CORE_ADDR physaddr;
 
-         switch (TYPE_FIELD_LOC_KIND (type, i))
+         switch (type->field (i).loc_kind ())
            {
            case FIELD_LOC_KIND_PHYSADDR:
              {
-               physaddr = TYPE_FIELD_STATIC_PHYSADDR (type, i);
+               physaddr = type->field (i).loc_physaddr ();
 
                instance->plugin ().build_decl
                  ("field physaddr", field_name,
@@ -616,7 +613,7 @@ compile_cplus_convert_struct_or_union_members
 
            case FIELD_LOC_KIND_PHYSNAME:
              {
-               const char *physname = TYPE_FIELD_STATIC_PHYSNAME (type, i);
+               const char *physname = type->field (i).loc_physname ();
                struct block_symbol sym
                  = lookup_symbol (physname, instance->block (),
                                   VAR_DOMAIN, nullptr);
@@ -627,10 +624,10 @@ compile_cplus_convert_struct_or_union_members
                       we can do but ignore this member.  */
                    continue;
                  }
-               const char *filename = symbol_symtab (sym.symbol)->filename;
-               unsigned int line = SYMBOL_LINE (sym.symbol);
+               const char *filename = sym.symbol->symtab ()->filename;
+               unsigned int line = sym.symbol->line ();
 
-               physaddr = SYMBOL_VALUE_ADDRESS (sym.symbol);
+               physaddr = sym.symbol->value_address ();
                instance->plugin ().build_decl
                  ("field physname", field_name,
                   (GCC_CP_SYMBOL_VARIABLE| get_field_access_flag (type, i)),
@@ -650,11 +647,11 @@ compile_cplus_convert_struct_or_union_members
            | get_field_access_flag (type, i);
 
          if (bitsize == 0)
-           bitsize = 8 * TYPE_LENGTH (TYPE_FIELD_TYPE (type, i));
+           bitsize = 8 * type->field (i).type ()->length ();
 
          instance->plugin ().build_field
            (field_name, field_type, field_flags, bitsize,
-            TYPE_FIELD_BITPOS (type, i));
+            type->field (i).loc_bitpos ());
        }
     }
 }
@@ -670,7 +667,7 @@ compile_cplus_convert_method (compile_cplus_instance *instance,
      type and corresponding qualifier flags.  */
   gcc_type func_type = compile_cplus_convert_func (instance, method_type, true);
   gcc_type class_type = instance->convert_type (parent_type);
-  gcc_cp_qualifiers_flags quals = (enum gcc_cp_qualifiers) 0;
+  gcc_cp_qualifiers_flags quals = 0;
 
   if (TYPE_CONST (method_type))
     quals |= GCC_CP_QUALIFIER_CONST;
@@ -683,7 +680,7 @@ compile_cplus_convert_method (compile_cplus_instance *instance,
   gcc_cp_ref_qualifiers_flags rquals = GCC_CP_REF_QUAL_NONE;
 
   return instance->plugin ().build_method_type
-    (class_type, func_type, quals, rquals);
+    (class_type, func_type, quals.raw (), rquals.raw ());
 }
 
 /* Convert a member or method pointer represented by TYPE.  */
@@ -699,7 +696,7 @@ compile_cplus_convert_memberptr (compile_cplus_instance *instance,
 
   gcc_type class_type = instance->convert_type (containing_class);
   gcc_type member_type
-    = instance->convert_type (TYPE_TARGET_TYPE (type));
+    = instance->convert_type (type->target_type ());
 
   return instance->plugin ().build_pointer_to_member_type
     (class_type, member_type);
@@ -747,7 +744,7 @@ compile_cplus_convert_struct_or_union_methods (compile_cplus_instance *instance,
                     (sym_kind
                      | get_method_access_flag (type, i, j)
                      | GCC_CP_FLAG_VIRTUAL_FUNCTION
-                     | GCC_CP_FLAG_PURE_VIRTUAL_FUNCTION),
+                     | GCC_CP_FLAG_PURE_VIRTUAL_FUNCTION).raw (),
                     method_type, nullptr, 0, nullptr, 0);
                  continue;
                }
@@ -766,9 +763,9 @@ compile_cplus_convert_struct_or_union_methods (compile_cplus_instance *instance,
              continue;
            }
 
-         const char *filename = symbol_symtab (sym.symbol)->filename;
-         unsigned int line = SYMBOL_LINE (sym.symbol);
-         CORE_ADDR address = BLOCK_START (SYMBOL_BLOCK_VALUE (sym.symbol));
+         const char *filename = sym.symbol->symtab ()->filename;
+         unsigned int line = sym.symbol->line ();
+         CORE_ADDR address = sym.symbol->value_block()->start ();
          const char *kind;
 
          if (TYPE_FN_FIELD_STATIC_P (methods, j))
@@ -789,7 +786,7 @@ compile_cplus_convert_struct_or_union_methods (compile_cplus_instance *instance,
 
          instance->plugin ().build_decl
            (kind, overloaded_name.get (),
-            sym_kind | get_method_access_flag (type, i, j),
+            (sym_kind | get_method_access_flag (type, i, j)).raw (),
             method_type, nullptr, address, filename, line);
        }
     }
@@ -809,10 +806,10 @@ compile_cplus_convert_struct_or_union (compile_cplus_instance *instance,
 
   /* Get the decl name of this type.  */
   gdb::unique_xmalloc_ptr<char> name
-    = compile_cplus_instance::decl_name (TYPE_NAME (type));
+    = compile_cplus_instance::decl_name (type->name ());
 
   /* Create a new scope for TYPE.  */
-  compile_scope scope = instance->new_scope (TYPE_NAME (type), type);
+  compile_scope scope = instance->new_scope (type->name (), type);
 
   if (scope.nested_type () != GCC_TYPE_NONE)
     {
@@ -822,65 +819,61 @@ compile_cplus_convert_struct_or_union (compile_cplus_instance *instance,
     }
 
   /* Push all scopes.  */
-  instance->enter_scope (scope);
+  instance->enter_scope (std::move (scope));
 
   /* First we create the resulting type and enter it into our hash
      table.  This lets recursive types work.  */
 
   gcc_decl resuld;
-  if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
+  if (type->code () == TYPE_CODE_STRUCT)
     {
-      const char *what = TYPE_DECLARED_CLASS (type) ? "struct" : "class";
+      const char *what = type->is_declared_class () ? "class" : "struct";
 
       resuld = instance->plugin ().build_decl
        (what, name.get (), (GCC_CP_SYMBOL_CLASS | nested_access
-                            | (TYPE_DECLARED_CLASS (type)
+                            | (type->is_declared_class ()
                                ? GCC_CP_FLAG_CLASS_NOFLAG
                                : GCC_CP_FLAG_CLASS_IS_STRUCT)),
         0, nullptr, 0, filename, line);
     }
   else
     {
-      gdb_assert (TYPE_CODE (type) == TYPE_CODE_UNION);
+      gdb_assert (type->code () == TYPE_CODE_UNION);
       resuld = instance->plugin ().build_decl
        ("union", name.get (), GCC_CP_SYMBOL_UNION | nested_access,
         0, nullptr, 0, filename, line);
     }
 
   gcc_type result;
-  if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
+  if (type->code () == TYPE_CODE_STRUCT)
     {
-      struct gcc_vbase_array bases;
       int num_baseclasses = TYPE_N_BASECLASSES (type);
+      std::vector<gcc_type> elements (num_baseclasses);
+      std::vector<enum gcc_cp_symbol_kind> flags (num_baseclasses);
 
-      memset (&bases, 0, sizeof (bases));
+      struct gcc_vbase_array bases {};
+      bases.elements = elements.data ();
+      bases.flags = flags.data ();
+      bases.n_elements = num_baseclasses;
 
-      if (num_baseclasses > 0)
+      for (int i = 0; i < num_baseclasses; ++i)
        {
-         bases.elements = XNEWVEC (gcc_type, num_baseclasses);
-         bases.flags = XNEWVEC (enum gcc_cp_symbol_kind, num_baseclasses);
-         bases.n_elements = num_baseclasses;
-         for (int i = 0; i < num_baseclasses; ++i)
-           {
-             struct type *base_type = TYPE_BASECLASS (type, i);
-
-             bases.flags[i] = GCC_CP_SYMBOL_BASECLASS
-               | get_field_access_flag (type, i)
-               | (BASETYPE_VIA_VIRTUAL (type, i)
-                  ? GCC_CP_FLAG_BASECLASS_VIRTUAL
-                  : GCC_CP_FLAG_BASECLASS_NOFLAG);
-             bases.elements[i] = instance->convert_type (base_type);
-           }
+         struct type *base_type = TYPE_BASECLASS (type, i);
+
+         bases.flags[i] = (GCC_CP_SYMBOL_BASECLASS
+                           | get_field_access_flag (type, i)
+                           | (BASETYPE_VIA_VIRTUAL (type, i)
+                              ? GCC_CP_FLAG_BASECLASS_VIRTUAL
+                              : GCC_CP_FLAG_BASECLASS_NOFLAG));
+         bases.elements[i] = instance->convert_type (base_type);
        }
 
       result = instance->plugin ().start_class_type
        (name.get (), resuld, &bases, filename, line);
-      xfree (bases.flags);
-      xfree (bases.elements);
     }
   else
     {
-      gdb_assert (TYPE_CODE (type) == TYPE_CODE_UNION);
+      gdb_assert (type->code () == TYPE_CODE_UNION);
       result = instance->plugin ().start_class_type
        (name.get (), resuld, nullptr, filename, line);
     }
@@ -897,7 +890,7 @@ compile_cplus_convert_struct_or_union (compile_cplus_instance *instance,
   compile_cplus_convert_struct_or_union_members (instance, type, result);
 
   /* All finished.  */
-  instance->plugin ().finish_class_type (name.get (), TYPE_LENGTH (type));
+  instance->plugin ().finish_class_type (name.get (), type->length ());
 
   /* Pop all scopes.  */
   instance->leave_scope ();
@@ -912,10 +905,10 @@ static gcc_type
 compile_cplus_convert_enum (compile_cplus_instance *instance, struct type *type,
                            enum gcc_cp_symbol_kind nested_access)
 {
-  int scoped_enum_p = FALSE;
+  bool scoped_enum_p = false;
 
   /* Create a new scope for this type.  */
-  compile_scope scope = instance->new_scope (TYPE_NAME (type), type);
+  compile_scope scope = instance->new_scope (type->name (), type);
 
   if (scope.nested_type () != GCC_TYPE_NONE)
     {
@@ -925,14 +918,14 @@ compile_cplus_convert_enum (compile_cplus_instance *instance, struct type *type,
     }
 
   gdb::unique_xmalloc_ptr<char> name
-    = compile_cplus_instance::decl_name (TYPE_NAME (type));
+    = compile_cplus_instance::decl_name (type->name ());
 
   /* Push all scopes.  */
-  instance->enter_scope (scope);
+  instance->enter_scope (std::move (scope));
 
   gcc_type int_type
-    = instance->plugin ().get_int_type (TYPE_UNSIGNED (type),
-                                       TYPE_LENGTH (type), nullptr);
+    = instance->plugin ().get_int_type (type->is_unsigned (),
+                                       type->length (), nullptr);
   gcc_type result
     = instance->plugin ().start_enum_type (name.get (), int_type,
                                           GCC_CP_SYMBOL_ENUM | nested_access
@@ -940,17 +933,17 @@ compile_cplus_convert_enum (compile_cplus_instance *instance, struct type *type,
                                              ? GCC_CP_FLAG_ENUM_SCOPED
                                              : GCC_CP_FLAG_ENUM_NOFLAG),
                                           nullptr, 0);
-  for (int i = 0; i < TYPE_NFIELDS (type); ++i)
+  for (int i = 0; i < type->num_fields (); ++i)
     {
       gdb::unique_xmalloc_ptr<char> fname
-       = compile_cplus_instance::decl_name (TYPE_FIELD_NAME (type, i));
+       = compile_cplus_instance::decl_name (type->field (i).name ());
 
-      if (TYPE_FIELD_LOC_KIND (type, i) != FIELD_LOC_KIND_ENUMVAL
+      if (type->field (i).loc_kind () != FIELD_LOC_KIND_ENUMVAL
          || fname == nullptr)
        continue;
 
       instance->plugin ().build_enum_constant (result, fname.get (),
-                                              TYPE_FIELD_ENUMVAL (type, i));
+                                              type->field (i).loc_enumval ());
     }
 
   /* Finish enum definition and pop scopes.  */
@@ -966,8 +959,8 @@ static gcc_type
 compile_cplus_convert_func (compile_cplus_instance *instance,
                            struct type *type, bool strip_artificial)
 {
-  int is_varargs = TYPE_VARARGS (type);
-  struct type *target_type = TYPE_TARGET_TYPE (type);
+  int is_varargs = type->has_varargs ();
+  struct type *target_type = type->target_type ();
 
   /* Functions with no debug info have no return type.  Ideally we'd
      want to fallback to the type of the cast just before the
@@ -976,10 +969,10 @@ compile_cplus_convert_func (compile_cplus_instance *instance,
      GDB's parser used to do.  */
   if (target_type == nullptr)
     {
-      if (TYPE_OBJFILE_OWNED (type))
-       target_type = objfile_type (TYPE_OWNER (type).objfile)->builtin_int;
+      if (type->is_objfile_owned ())
+       target_type = objfile_type (type->objfile_owner ())->builtin_int;
       else
-       target_type = builtin_type (TYPE_OWNER (type).gdbarch)->builtin_int;
+       target_type = builtin_type (type->arch_owner ())->builtin_int;
       warning (_("function has unknown return type; assuming int"));
     }
 
@@ -987,10 +980,10 @@ compile_cplus_convert_func (compile_cplus_instance *instance,
      types.  Those are impossible in C, though.  */
   gcc_type return_type = instance->convert_type (target_type);
 
-  struct gcc_type_array array =
-    { TYPE_NFIELDS (type), XNEWVEC (gcc_type, TYPE_NFIELDS (type)) };
+  std::vector<gcc_type> elements (type->num_fields ());
+  struct gcc_type_array array = { type->num_fields (), elements.data () };
   int artificials = 0;
-  for (int i = 0; i < TYPE_NFIELDS (type); ++i)
+  for (int i = 0; i < type->num_fields (); ++i)
     {
       if (strip_artificial && TYPE_FIELD_ARTIFICIAL (type, i))
        {
@@ -1000,7 +993,7 @@ compile_cplus_convert_func (compile_cplus_instance *instance,
       else
        {
          array.elements[i - artificials]
-           = instance->convert_type (TYPE_FIELD_TYPE (type, i));
+           = instance->convert_type (type->field (i).type ());
        }
     }
 
@@ -1008,7 +1001,6 @@ compile_cplus_convert_func (compile_cplus_instance *instance,
      with some minsyms like printf (compile-cplus.exp has examples).  */
   gcc_type result = instance->plugin ().build_function_type
     (return_type, &array, is_varargs);
-  xfree (array.elements);
   return result;
 }
 
@@ -1017,14 +1009,14 @@ compile_cplus_convert_func (compile_cplus_instance *instance,
 static gcc_type
 compile_cplus_convert_int (compile_cplus_instance *instance, struct type *type)
 {
-  if (TYPE_NOSIGN (type))
+  if (type->has_no_signedness ())
     {
-      gdb_assert (TYPE_LENGTH (type) == 1);
+      gdb_assert (type->length () == 1);
       return instance->plugin ().get_char_type ();
     }
 
   return instance->plugin ().get_int_type
-    (TYPE_UNSIGNED (type), TYPE_LENGTH (type), TYPE_NAME (type));
+    (type->is_unsigned (), type->length (), type->name ());
 }
 
 /* Convert a floating-point type to its gcc representation.  */
@@ -1034,7 +1026,7 @@ compile_cplus_convert_float (compile_cplus_instance *instance,
                             struct type *type)
 {
   return instance->plugin ().get_float_type
-    (TYPE_LENGTH (type), TYPE_NAME (type));
+    (type->length (), type->name ());
 }
 
 /* Convert the 'void' type to its gcc representation.  */
@@ -1062,7 +1054,7 @@ compile_cplus_instance::convert_qualified_base (gcc_type base,
   gcc_type result = base;
 
   if (quals != 0)
-    result = plugin ().build_qualified_type (base, quals);
+    result = plugin ().build_qualified_type (base, quals.raw ());
 
   return result;
 }
@@ -1093,7 +1085,7 @@ static gcc_type
 compile_cplus_convert_complex (compile_cplus_instance *instance,
                               struct type *type)
 {
-  gcc_type base = instance->convert_type (TYPE_TARGET_TYPE (type));
+  gcc_type base = instance->convert_type (type->target_type ());
 
   return instance->plugin ().build_complex_type (base);
 }
@@ -1104,12 +1096,12 @@ static gcc_type
 compile_cplus_convert_namespace (compile_cplus_instance *instance,
                                 struct type *type)
 {
-  compile_scope scope = instance->new_scope (TYPE_NAME (type), type);
+  compile_scope scope = instance->new_scope (type->name (), type);
   gdb::unique_xmalloc_ptr<char> name
-    = compile_cplus_instance::decl_name (TYPE_NAME (type));
+    = compile_cplus_instance::decl_name (type->name ());
 
   /* Push scope.  */
-  instance->enter_scope (scope);
+  instance->enter_scope (std::move (scope));
 
   /* Convert this namespace.  */
   instance->plugin ().push_namespace (name.get ());
@@ -1137,12 +1129,12 @@ convert_type_cplus_basic (compile_cplus_instance *instance,
 {
   /* If we are converting a qualified type, first convert the
      unqualified type and then apply the qualifiers.  */
-  if ((TYPE_INSTANCE_FLAGS (type) & (TYPE_INSTANCE_FLAG_CONST
-                                    | TYPE_INSTANCE_FLAG_VOLATILE
-                                    | TYPE_INSTANCE_FLAG_RESTRICT)) != 0)
+  if ((type->instance_flags () & (TYPE_INSTANCE_FLAG_CONST
+                                 | TYPE_INSTANCE_FLAG_VOLATILE
+                                 | TYPE_INSTANCE_FLAG_RESTRICT)) != 0)
     return compile_cplus_convert_qualified (instance, type);
 
-  switch (TYPE_CODE (type))
+  switch (type->code ())
     {
     case TYPE_CODE_REF:
     case TYPE_CODE_RVALUE_REF:
@@ -1200,7 +1192,7 @@ convert_type_cplus_basic (compile_cplus_instance *instance,
     }
 
   std::string s = string_printf (_("unhandled TYPE_CODE %d"),
-                                TYPE_CODE (type));
+                                type->code ());
 
   return instance->plugin ().error (s.c_str ());
 }
@@ -1211,7 +1203,7 @@ compile_cplus_instance::convert_type (struct type *type,
 {
   /* Check if TYPE has already been converted.  */
   gcc_type result;
-  if (get_cached_type (type, result))
+  if (get_cached_type (type, &result))
     return result;
 
   /* It is the first time this type has been seen -- convert it
@@ -1246,16 +1238,16 @@ compile_cplus_instance::gcc_cplus_leave_scope
 static void
 compile_cplus_debug_output_1 (ULONGEST arg)
 {
-  fprintf_unfiltered (gdb_stdlog, "%s", pulongest (arg));
+  gdb_printf (gdb_stdlog, "%s", pulongest (arg));
 }
 
 static void
 compile_cplus_debug_output_1 (const char *arg)
 {
   if (arg == nullptr)
-    fputs_unfiltered ("NULL", gdb_stdlog);
+    gdb_puts ("NULL", gdb_stdlog);
   else
-    fputs_unfiltered (arg, gdb_stdlog);
+    gdb_puts (arg, gdb_stdlog);
 }
 
 static void
@@ -1274,7 +1266,7 @@ static void
 compile_cplus_debug_output (T arg, Targs... Args)
 {
   compile_cplus_debug_output_1 (arg);
-  fputc_unfiltered (' ', gdb_stdlog);
+  gdb_putc (' ', gdb_stdlog);
   compile_cplus_debug_output (Args...);
 }
 
@@ -1282,9 +1274,9 @@ compile_cplus_debug_output (T arg, Targs... Args)
 #define OUTPUT_DEBUG_RESULT(R)                   \
   if (debug_compile_cplus_types)                 \
     {                                            \
-      fputs_unfiltered (": ", gdb_stdlog);       \
+      gdb_puts (": ", gdb_stdlog);               \
       compile_cplus_debug_output (R);            \
-      fputc_unfiltered ('\n', gdb_stdlog);       \
+      gdb_putc ('\n', gdb_stdlog);               \
     }                                            \
 
 #define GCC_METHOD0(R, N)                        \
@@ -1370,7 +1362,7 @@ gcc_cp_plugin::build_decl (const char *debug_decltype, const char *name,
                           const char *filename, unsigned int line_number)
 {
   if (debug_compile_cplus_types)
-    fprintf_unfiltered (gdb_stdlog, "<%s> ", debug_decltype);
+    gdb_printf (gdb_stdlog, "<%s> ", debug_decltype);
 
   return build_decl (name, sym_kind, sym_type, substitution_name,
                     address, filename, line_number);
@@ -1382,7 +1374,7 @@ gcc_cp_plugin::start_class_type (const char *debug_name, gcc_decl typedecl,
                                 const char *filename, unsigned int line_number)
 {
   if (debug_compile_cplus_types)
-    fprintf_unfiltered (gdb_stdlog, "<%s> ", debug_name);
+    gdb_printf (gdb_stdlog, "<%s> ", debug_name);
 
   return start_class_type (typedecl, base_classes, filename, line_number);
 }
@@ -1392,7 +1384,7 @@ gcc_cp_plugin::finish_class_type (const char *debug_name,
                                  unsigned long size_in_bytes)
 {
   if (debug_compile_cplus_types)
-    fprintf_unfiltered (gdb_stdlog, "<%s> ", debug_name);
+    gdb_printf (gdb_stdlog, "<%s> ", debug_name);
 
   return finish_class_type (size_in_bytes);
 }
@@ -1401,11 +1393,12 @@ int
 gcc_cp_plugin::pop_binding_level (const char *debug_name)
 {
   if (debug_compile_cplus_types)
-    fprintf_unfiltered (gdb_stdlog, "<%s> ", debug_name);
+    gdb_printf (gdb_stdlog, "<%s> ", debug_name);
 
   return pop_binding_level ();
 }
 
+void _initialize_compile_cplus_types ();
 void
 _initialize_compile_cplus_types ()
 {
This page took 0.063761 seconds and 4 git commands to generate.