/* Convert types from GDB to GCC
- Copyright (C) 2014-2020 Free Software Foundation, Inc.
+ Copyright (C) 2014-2021 Free Software Foundation, Inc.
This file is part of GDB.
{
scope_component comp
= {
- decl_name (type->name ()).get (),
+ decl_name (type->name ()).get (),
lookup_symbol (type->name (), block (), VAR_DOMAIN, nullptr)
};
scope.push_back (comp);
{
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
{
gcc_decl resuld;
if (type->code () == TYPE_CODE_STRUCT)
{
- const char *what = TYPE_DECLARED_CLASS (type) ? "struct" : "class";
+ const char *what = TYPE_DECLARED_CLASS (type) ? "class" : "struct";
resuld = instance->plugin ().build_decl
(what, name.get (), (GCC_CP_SYMBOL_CLASS | nested_access
gcc_type result;
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'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"));
}
types. Those are impossible in C, though. */
gcc_type return_type = instance->convert_type (target_type);
- struct gcc_type_array array =
- { type->num_fields (), XNEWVEC (gcc_type, type->num_fields ()) };
+ 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->num_fields (); ++i)
{
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;
}