/* Convert types from GDB to GCC
- Copyright (C) 2014-2018 Free Software Foundation, Inc.
+ Copyright (C) 2014-2020 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++. */
/* 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. */
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. */
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))
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 (),
scope.push_back (comp);
- if (TYPE_CODE (SYMBOL_TYPE (bsymbol.symbol)) != TYPE_CODE_NAMESPACE)
+ if (SYMBOL_TYPE (bsymbol.symbol)->code () != TYPE_CODE_NAMESPACE)
{
/* We're done. */
break;
/* 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 %p\n", new_scope);
+ {
+ fprintf_unfiltered (gdb_stdlog, "entering new scope %s\n",
+ host_address_to_string (&m_scopes.back ()));
+ }
/* Push the global namespace. */
plugin ().push_namespace ("");
/* 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 (SYMBOL_TYPE (comp.bsymbol.symbol)->code ()
== TYPE_CODE_NAMESPACE);
const char *ns = (comp.name == CP_ANONYMOUS_NAMESPACE_STR ? nullptr
if (current.m_pushed)
{
if (debug_compile_cplus_scopes)
- fprintf_unfiltered (gdb_stdlog, "leaving scope %p\n", current);
+ {
+ fprintf_unfiltered (gdb_stdlog, "leaving scope %s\n",
+ host_address_to_string (¤t));
+ }
/* 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 (SYMBOL_TYPE (comp.bsymbol.symbol)->code ()
== TYPE_CODE_NAMESPACE);
this->plugin ().pop_binding_level (comp.name.c_str ());
});
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 */
{
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);
}
gcc_type target = instance->convert_type (TYPE_TARGET_TYPE (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;
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));
/* 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)
{
}
/* 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";
}
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);
}
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);
}
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)
{
}
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),
}
return instance->plugin ().get_int_type
- (TYPE_UNSIGNED (type), TYPE_LENGTH (type), TYPE_NAME (type));
+ (TYPE_UNSIGNED (type), TYPE_LENGTH (type), type->name ());
}
/* Convert a floating-point type to its gcc representation. */
struct type *type)
{
return instance->plugin ().get_float_type
- (TYPE_LENGTH (type), TYPE_NAME (type));
+ (TYPE_LENGTH (type), type->name ());
}
/* Convert the 'void' type to its gcc representation. */
{
gcc_type result = base;
- if (quals != GCC_CP_REF_QUAL_NONE)
+ if (quals != 0)
result = plugin ().build_qualified_type (base, quals);
return result;
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 ());
| 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:
}
std::string s = string_printf (_("unhandled TYPE_CODE %d"),
- TYPE_CODE (type));
+ type->code ());
return instance->plugin ().error (s.c_str ());
}
{
/* 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
gcc_decl. */
static void
-compile_cplus_debug_output_1 (gcc_type arg)
+compile_cplus_debug_output_1 (ULONGEST arg)
{
- fprintf_unfiltered (gdb_stdlog, "%lld", arg);
+ fprintf_unfiltered (gdb_stdlog, "%s", pulongest (arg));
}
static void
return pop_binding_level ();
}
+void _initialize_compile_cplus_types ();
void
_initialize_compile_cplus_types ()
{