/* Support routines for manipulating internal types for GDB.
- Copyright (C) 1992-2019 Free Software Foundation, Inc.
+ Copyright (C) 1992-2020 Free Software Foundation, Inc.
Contributed by Cygnus Support, using pieces from other GDB modules.
#include "hashtab.h"
#include "cp-support.h"
#include "bcache.h"
-#include "dwarf2loc.h"
+#include "dwarf2/loc.h"
#include "gdbcore.h"
#include "floatformat.h"
const struct rank BOOL_CONVERSION_BADNESS = {3,0};
const struct rank BASE_CONVERSION_BADNESS = {2,0};
const struct rank REFERENCE_CONVERSION_BADNESS = {2,0};
+const struct rank REFERENCE_SEE_THROUGH_BADNESS = {0,1};
const struct rank NULL_POINTER_CONVERSION_BADNESS = {2,0};
const struct rank NS_POINTER_CONVERSION_BADNESS = {10,0};
const struct rank NS_INTEGER_POINTER_CONVERSION_BADNESS = {3,0};
if (high_bound->kind == PROP_CONST && high_bound->data.const_val < 0)
TYPE_UNSIGNED (result_type) = 0;
+ TYPE_ENDIANITY_NOT_DEFAULT (result_type)
+ = TYPE_ENDIANITY_NOT_DEFAULT (index_type);
+
return result_type;
}
&& !type_not_allocated (result_type)))
{
LONGEST low_bound, high_bound;
- unsigned int stride;
+ int stride;
/* If the array itself doesn't provide a stride value then take
whatever stride the range provides. Don't update BIT_STRIDE as
In such cases, the array length should be zero. */
if (high_bound < low_bound)
TYPE_LENGTH (result_type) = 0;
- else if (stride > 0)
- TYPE_LENGTH (result_type) =
- (stride * (high_bound - low_bound + 1) + 7) / 8;
+ else if (stride != 0)
+ {
+ /* Ensure that the type length is always positive, even in the
+ case where (for example in Fortran) we have a negative
+ stride. It is possible to have a single element array with a
+ negative stride in Fortran (this doesn't mean anything
+ special, it's still just a single element array) so do
+ consider that case when touching this code. */
+ LONGEST element_count = std::abs (high_bound - low_bound + 1);
+ TYPE_LENGTH (result_type)
+ = ((std::abs (stride) * element_count) + 7) / 8;
+ }
else
TYPE_LENGTH (result_type) =
TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
struct type *
lookup_typename (const struct language_defn *language,
- struct gdbarch *gdbarch, const char *name,
+ const char *name,
const struct block *block, int noerr)
{
struct symbol *sym;
struct type *
lookup_unsigned_typename (const struct language_defn *language,
- struct gdbarch *gdbarch, const char *name)
+ const char *name)
{
char *uns = (char *) alloca (strlen (name) + 10);
strcpy (uns, "unsigned ");
strcpy (uns + 9, name);
- return lookup_typename (language, gdbarch, uns, NULL, 0);
+ return lookup_typename (language, uns, NULL, 0);
}
struct type *
-lookup_signed_typename (const struct language_defn *language,
- struct gdbarch *gdbarch, const char *name)
+lookup_signed_typename (const struct language_defn *language, const char *name)
{
struct type *t;
char *uns = (char *) alloca (strlen (name) + 8);
strcpy (uns, "signed ");
strcpy (uns + 7, name);
- t = lookup_typename (language, gdbarch, uns, NULL, 1);
+ t = lookup_typename (language, uns, NULL, 1);
/* If we don't find "signed FOO" just try again with plain "FOO". */
if (t != NULL)
return t;
- return lookup_typename (language, gdbarch, name, NULL, 0);
+ return lookup_typename (language, name, NULL, 0);
}
/* Lookup a structure type named "struct NAME",
return t;
}
-/* Allocate a TYPE_CODE_COMPLEX type structure associated with OBJFILE.
- NAME is the type name. TARGET_TYPE is the component float type. */
+/* Allocate a TYPE_CODE_COMPLEX type structure. NAME is the type
+ name. TARGET_TYPE is the component type. */
struct type *
-init_complex_type (struct objfile *objfile,
- const char *name, struct type *target_type)
+init_complex_type (const char *name, struct type *target_type)
{
struct type *t;
- t = init_type (objfile, TYPE_CODE_COMPLEX,
- 2 * TYPE_LENGTH (target_type) * TARGET_CHAR_BIT, name);
- TYPE_TARGET_TYPE (t) = target_type;
- return t;
+ gdb_assert (TYPE_CODE (target_type) == TYPE_CODE_INT
+ || TYPE_CODE (target_type) == TYPE_CODE_FLT);
+
+ if (TYPE_MAIN_TYPE (target_type)->flds_bnds.complex_type == nullptr)
+ {
+ if (name == nullptr)
+ {
+ char *new_name
+ = (char *) TYPE_ALLOC (target_type,
+ strlen (TYPE_NAME (target_type))
+ + strlen ("_Complex ") + 1);
+ strcpy (new_name, "_Complex ");
+ strcat (new_name, TYPE_NAME (target_type));
+ name = new_name;
+ }
+
+ t = alloc_type_copy (target_type);
+ set_type_code (t, TYPE_CODE_COMPLEX);
+ TYPE_LENGTH (t) = 2 * TYPE_LENGTH (target_type);
+ TYPE_NAME (t) = name;
+
+ TYPE_TARGET_TYPE (t) = target_type;
+ TYPE_MAIN_TYPE (target_type)->flds_bnds.complex_type = t;
+ }
+
+ return TYPE_MAIN_TYPE (target_type)->flds_bnds.complex_type;
}
/* Allocate a TYPE_CODE_PTR type structure associated with OBJFILE.
value_address (val), val) == 1;
}
+/* See gdbtypes.h. */
+
+enum bfd_endian
+type_byte_order (const struct type *type)
+{
+ bfd_endian byteorder = gdbarch_byte_order (get_type_arch (type));
+ if (TYPE_ENDIANITY_NOT_DEFAULT (type))
+ {
+ if (byteorder == BFD_ENDIAN_BIG)
+ return BFD_ENDIAN_LITTLE;
+ else
+ {
+ gdb_assert (byteorder == BFD_ENDIAN_LITTLE);
+ return BFD_ENDIAN_BIG;
+ }
+ }
+
+ return byteorder;
+}
+
\f
/* Overload resolution. */
static bool
check_types_worklist (std::vector<type_equality_entry> *worklist,
- struct bcache *cache)
+ gdb::bcache *cache)
{
while (!worklist->empty ())
{
if (type1 == type2)
return true;
- struct bcache cache (nullptr, nullptr);
+ gdb::bcache cache (nullptr, nullptr);
worklist.emplace_back (type1, type2);
return check_types_worklist (&worklist, &cache);
}
}
else
{
- /* Lvalues should prefer lvalue overloads. */
+ /* It's illegal to pass an lvalue as an rvalue. */
if (TYPE_CODE (parm) == TYPE_CODE_RVALUE_REF)
- {
- rank.subrank = REFERENCE_CONVERSION_RVALUE;
- return sum_ranks (rank, REFERENCE_CONVERSION_BADNESS);
- }
+ return INCOMPATIBLE_TYPE_BADNESS;
}
}
if (TYPE_IS_REFERENCE (arg))
return (sum_ranks (rank_one_type (parm, TYPE_TARGET_TYPE (arg), NULL),
- REFERENCE_CONVERSION_BADNESS));
+ REFERENCE_SEE_THROUGH_BADNESS));
if (TYPE_IS_REFERENCE (parm))
return (sum_ranks (rank_one_type (TYPE_TARGET_TYPE (parm), arg, NULL),
- REFERENCE_CONVERSION_BADNESS));
+ REFERENCE_SEE_THROUGH_BADNESS));
if (overload_debug)
/* Debugging only. */
fprintf_filtered (gdb_stderr,
TYPE_FN_FIELD_PROTECTED (f, overload_idx));
printfi_filtered (spaces + 8, "is_stub %d\n",
TYPE_FN_FIELD_STUB (f, overload_idx));
+ printfi_filtered (spaces + 8, "defaulted %d\n",
+ TYPE_FN_FIELD_DEFAULTED (f, overload_idx));
+ printfi_filtered (spaces + 8, "is_deleted %d\n",
+ TYPE_FN_FIELD_DELETED (f, overload_idx));
printfi_filtered (spaces + 8, "voffset %u\n",
TYPE_FN_FIELD_VOFFSET (f, overload_idx));
}
{
dump_fn_fieldlists (type, spaces);
}
+
+ printfi_filtered (spaces, "calling_convention %d\n",
+ TYPE_CPLUS_CALLING_CONVENTION (type));
}
/* Print the contents of the TYPE's type_specific union, assuming that
return t;
}
-/* Allocate a TYPE_CODE_COMPLEX type structure associated with GDBARCH.
- NAME is the type name. TARGET_TYPE is the component float type. */
-
-struct type *
-arch_complex_type (struct gdbarch *gdbarch,
- const char *name, struct type *target_type)
-{
- struct type *t;
-
- t = arch_type (gdbarch, TYPE_CODE_COMPLEX,
- 2 * TYPE_LENGTH (target_type) * TARGET_CHAR_BIT, name);
- TYPE_TARGET_TYPE (t) = target_type;
- return t;
-}
-
/* Allocate a TYPE_CODE_PTR type structure associated with GDBARCH.
BIT is the pointer type size in bits. NAME is the type name.
TARGET_TYPE is the pointer target type. Always sets the pointer type's
= arch_float_type (gdbarch, gdbarch_long_double_bit (gdbarch),
"long double", gdbarch_long_double_format (gdbarch));
builtin_type->builtin_complex
- = arch_complex_type (gdbarch, "complex",
- builtin_type->builtin_float);
+ = init_complex_type ("complex", builtin_type->builtin_float);
builtin_type->builtin_double_complex
- = arch_complex_type (gdbarch, "double complex",
- builtin_type->builtin_double);
+ = init_complex_type ("double complex", builtin_type->builtin_double);
builtin_type->builtin_string
= arch_type (gdbarch, TYPE_CODE_STRING, TARGET_CHAR_BIT, "string");
builtin_type->builtin_bool
return objfile_type;
}
+void _initialize_gdbtypes ();
void
-_initialize_gdbtypes (void)
+_initialize_gdbtypes ()
{
gdbtypes_data = gdbarch_data_register_post_init (gdbtypes_post_init);
show_strict_type_checking,
&setchecklist, &showchecklist);
}
-
-/* See gdbtypes.h. */
-enum bfd_endian
-type_byte_order (const struct type *type)
-{
- bfd_endian byteorder = gdbarch_byte_order (get_type_arch (type));
- if (TYPE_ENDIANITY_NOT_DEFAULT (type))
- {
- if (byteorder == BFD_ENDIAN_BIG)
- return BFD_ENDIAN_LITTLE;
- else if (byteorder == BFD_ENDIAN_LITTLE)
- return BFD_ENDIAN_BIG;
- else
- return BFD_ENDIAN_UNKNOWN;
- }
-
- return byteorder;
-}