We will fill it in later if we find out how. */
if (type == NULL)
{
- type = type_allocator (coffread_objfile).new_type ();
+ type = type_allocator (coffread_objfile, language_c).new_type ();
*type_addr = type;
}
return type;
base_type = decode_type (cs, new_c_type, aux, objfile);
index_type = builtin_type (objfile)->builtin_int;
- type_allocator alloc (objfile);
+ type_allocator alloc (objfile, language_c);
range_type
= create_static_range_type (alloc, index_type, 0, n - 1);
type = create_array_type (alloc, base_type, range_type);
const struct floatformat **format;
struct type *type;
- type_allocator alloc (objfile);
+ type_allocator alloc (objfile, language_c);
format = gdbarch_floatformat_for_type (gdbarch, name_hint, bits);
if (format != nullptr)
type = init_float_type (alloc, bits, name, format);
ctf_errmsg (ctf_errno (fp)));
}
- type_allocator alloc (of);
+ type_allocator alloc (of, language_c);
kind = ctf_type_kind (fp, tid);
if (kind == CTF_K_INTEGER)
{
struct type *type;
uint32_t kind;
- type = type_allocator (of).new_type ();
+ type = type_allocator (of, language_c).new_type ();
const char *name = ctf_type_name_raw (fp, tid);
if (name != nullptr && strlen (name) != 0)
ctf_funcinfo_t cfi;
uint32_t argc;
- type = type_allocator (of).new_type ();
+ type = type_allocator (of, language_c).new_type ();
type->set_code (TYPE_CODE_FUNC);
if (ctf_func_type_info (fp, tid, &cfi) < 0)
ctf_dict_t *fp = ccp->fp;
struct type *type;
- type = type_allocator (of).new_type ();
+ type = type_allocator (of, language_c).new_type ();
const char *name = ctf_type_name_raw (fp, tid);
if (name != nullptr && strlen (name) != 0)
if (idx_type == nullptr)
idx_type = builtin_type (objfile)->builtin_int;
- type_allocator alloc (objfile);
+ type_allocator alloc (objfile, language_c);
range_type = create_static_range_type (alloc, idx_type, 0, ar.ctr_nelems - 1);
type = create_array_type (alloc, element_type, range_type);
if (ar.ctr_nelems <= 1) /* Check if undefined upper bound. */
struct type *this_type, *target_type;
char *aname = obstack_strdup (&objfile->objfile_obstack, name);
- this_type = type_allocator (objfile).new_type (TYPE_CODE_TYPEDEF, 0, aname);
+ this_type = type_allocator (objfile, language_c).new_type (TYPE_CODE_TYPEDEF,
+ 0, aname);
set_tid_type (objfile, tid, this_type);
target_type = fetch_tid_type (ccp, btid);
if (target_type != this_type)
struct type *type;
uint32_t kind;
- type = type_allocator (of).new_type ();
+ type = type_allocator (of, language_c).new_type ();
const char *name = ctf_type_name_raw (fp, tid);
if (name != nullptr && strlen (name) != 0)
struct objfile *objfile = cu->per_objfile->objfile;
const char *saved_package_name = objfile->intern (package_name.get ());
struct type *type
- = type_allocator (objfile).new_type (TYPE_CODE_MODULE, 0,
- saved_package_name);
+ = type_allocator (objfile, cu->lang ()).new_type (TYPE_CODE_MODULE, 0,
+ saved_package_name);
struct symbol *sym;
sym = new (&objfile->objfile_obstack) symbol;
= rust_fully_qualify (&objfile->objfile_obstack, type->name (),
name);
struct type *dataless_type
- = type_allocator (objfile).new_type (TYPE_CODE_VOID, 0,
- dataless_name);
+ = type_allocator (type).new_type (TYPE_CODE_VOID, 0,
+ dataless_name);
type->field (2).set_type (dataless_type);
/* NAME points into the original discriminant name, which
already has the correct lifetime. */
fnp->physname = physname ? physname : "";
}
- fnp->type = type_allocator (objfile).new_type ();
+ fnp->type = type_allocator (objfile, cu->lang ()).new_type ();
this_type = read_type_die (die, cu);
if (this_type && this_type->code () == TYPE_CODE_FUNC)
{
return;
self_type = pfn_type->field (0).type ()->target_type ();
- new_type = type_allocator (objfile).new_type ();
+ new_type = type_allocator (type).new_type ();
smash_to_method_type (new_type, self_type, pfn_type->target_type (),
pfn_type->fields (), pfn_type->num_fields (),
pfn_type->has_varargs ());
return set_die_type (die, type, cu);
}
- type = type_allocator (objfile).new_type ();
- if (cu->lang () == language_rust)
- {
- /* This is currently only needed for types that might be
- slices. */
- INIT_RUST_SPECIFIC (type);
- }
- else
- INIT_CPLUS_SPECIFIC (type);
+ type = type_allocator (objfile, cu->lang ()).new_type ();
+ INIT_CPLUS_SPECIFIC (type);
name = dwarf2_name (die, cu);
if (name != NULL)
return set_die_type (die, type, cu);
}
- type = type_allocator (objfile).new_type ();
+ type = type_allocator (objfile, cu->lang ()).new_type ();
type->set_code (TYPE_CODE_ENUM);
name = dwarf2_full_name (NULL, die, cu);
range_fields[i + 1].set_name (objfile->intern (name));
}
- type_allocator alloc (objfile);
+ type_allocator alloc (objfile, cu->lang ());
struct type *bounds = alloc.new_type ();
bounds->set_code (TYPE_CODE_STRUCT);
iter = iter->target_type ();
}
- struct type *result = type_allocator (objfile).new_type ();
+ struct type *result = type_allocator (objfile, cu->lang ()).new_type ();
result->set_code (TYPE_CODE_STRUCT);
result->alloc_fields (2);
if (die->child == NULL)
{
index_type = builtin_type (objfile)->builtin_int;
- type_allocator alloc (objfile);
+ type_allocator alloc (objfile, cu->lang ());
range_type = create_static_range_type (alloc, index_type, 0, -1);
type = create_array_type_with_stride (alloc, element_type, range_type,
byte_stride_prop, bit_stride);
type = element_type;
- type_allocator alloc (cu->per_objfile->objfile);
+ type_allocator alloc (cu->per_objfile->objfile, cu->lang ());
if (read_array_order (die, cu) == DW_ORD_col_major)
{
int i = 0;
if (set_type)
return set_type;
- type_allocator alloc (cu->per_objfile->objfile);
+ type_allocator alloc (cu->per_objfile->objfile, cu->lang ());
set_type = create_set_type (alloc, domain_type);
attr = dwarf2_attr (die, DW_AT_byte_size, cu);
previous_prefix, name, 0, cu);
/* Create the type. */
- type = type_allocator (objfile).new_type (TYPE_CODE_NAMESPACE, 0, name);
+ type = type_allocator (objfile, cu->lang ()).new_type (TYPE_CODE_NAMESPACE,
+ 0, name);
return set_die_type (die, type, cu);
}
struct type *type;
module_name = dwarf2_name (die, cu);
- type = type_allocator (objfile).new_type (TYPE_CODE_MODULE, 0, module_name);
+ type = type_allocator (objfile, cu->lang ()).new_type (TYPE_CODE_MODULE,
+ 0, module_name);
return set_die_type (die, type, cu);
}
else if (check_typedef (to_type)->code () == TYPE_CODE_FUNC)
{
struct type *new_type
- = type_allocator (cu->per_objfile->objfile).new_type ();
+ = type_allocator (cu->per_objfile->objfile, cu->lang ()).new_type ();
smash_to_method_type (new_type, domain, to_type->target_type (),
to_type->fields (), to_type->num_fields (),
}
index_type = builtin_type (objfile)->builtin_int;
- type_allocator alloc (objfile);
+ type_allocator alloc (objfile, cu->lang ());
if (length_is_constant)
range_type = create_static_range_type (alloc, index_type, 1, length);
else
return this_type;
}
- this_type = type_allocator (objfile).new_type (TYPE_CODE_TYPEDEF, 0, name);
+ type_allocator alloc (objfile, cu->lang ());
+ this_type = alloc.new_type (TYPE_CODE_TYPEDEF, 0, name);
this_type->set_target_is_stub (true);
set_die_type (die, this_type, cu);
if (target_type != this_type)
const struct floatformat **format;
struct type *type;
- type_allocator alloc (objfile);
+ type_allocator alloc (objfile, cu->lang ());
format = gdbarch_floatformat_for_type (gdbarch, name_hint, bits);
if (format)
type = init_float_type (alloc, bits, name, format, byte_order);
type = builtin_type (objfile)->builtin_void;
else
{
- type_allocator alloc (objfile);
+ type_allocator alloc (objfile, cu->lang ());
type = init_integer_type (alloc, bits, unsigned_p, name);
}
}
}
- type_allocator alloc (objfile);
+ type_allocator alloc (objfile, cu->lang ());
switch (encoding)
{
case DW_ATE_address:
}
}
- type_allocator alloc (cu->per_objfile->objfile);
+ type_allocator alloc (cu->per_objfile->objfile, cu->lang ());
if (attr_byte_stride != nullptr
|| attr_bit_stride != nullptr)
{
{
struct type *type;
- type = (type_allocator (cu->per_objfile->objfile)
+ type = (type_allocator (cu->per_objfile->objfile, cu->lang ())
.new_type (TYPE_CODE_VOID, 0, nullptr));
type->set_name (dwarf2_name (die, cu));
sect_offset_str (die->sect_off));
saved = obstack_strdup (&objfile->objfile_obstack, message);
- return type_allocator (objfile).new_type (TYPE_CODE_ERROR, 0, saved);
+ return type_allocator (objfile, cu->lang ()).new_type (TYPE_CODE_ERROR,
+ 0, saved);
}
/* Look up the type of DIE in CU using its type attribute ATTR.
/* Alloc the structure and start off with all fields zeroed. */
struct type *type = OBSTACK_ZALLOC (obstack, struct type);
TYPE_MAIN_TYPE (type) = OBSTACK_ZALLOC (obstack, struct main_type);
+ TYPE_MAIN_TYPE (type)->m_lang = m_lang;
if (m_is_objfile)
{
print_gnat_stuff (type, spaces);
break;
- case TYPE_SPECIFIC_RUST_STUFF:
- gdb_printf ("%*srust\n", spaces, "");
- break;
-
case TYPE_SPECIFIC_FLOATFORMAT:
gdb_printf ("%*sfloatformat ", spaces, "");
if (TYPE_FLOATFORMAT (type) == NULL
case TYPE_SPECIFIC_GNAT_STUFF:
INIT_GNAT_SPECIFIC (new_type);
break;
- case TYPE_SPECIFIC_RUST_STUFF:
- INIT_RUST_SPECIFIC (new_type);
- break;
case TYPE_SPECIFIC_SELF_TYPE:
set_type_self_type (new_type,
copy_type_recursive (TYPE_SELF_TYPE (type),
memcpy (this->fields (), src.data (), size);
}
+/* See gdbtypes.h. */
+
+bool
+type::is_string_like ()
+{
+ const language_defn *defn = language_def (this->language ());
+ return defn->is_string_type_p (this);
+}
+
+/* See gdbtypes.h. */
+
bool
type::is_array_like ()
{
if (code () == TYPE_CODE_ARRAY)
return true;
- if (HAVE_GNAT_AUX_INFO (this))
- return (ada_is_constrained_packed_array_type (this)
- || ada_is_array_descriptor_type (this));
- if (HAVE_RUST_SPECIFIC (this))
- return rust_slice_type_p (this);
- return false;
+ const language_defn *defn = language_def (this->language ());
+ return defn->is_array_like (this);
}
\f
TYPE_SPECIFIC_NONE,
TYPE_SPECIFIC_CPLUS_STUFF,
TYPE_SPECIFIC_GNAT_STUFF,
- TYPE_SPECIFIC_RUST_STUFF,
TYPE_SPECIFIC_FLOATFORMAT,
/* Note: This is used by TYPE_CODE_FUNC and TYPE_CODE_METHOD. */
TYPE_SPECIFIC_FUNC,
/* * A discriminant telling us which field of the type_specific
union is being used for this type, if any. */
- ENUM_BITFIELD(type_specific_kind) type_specific_field : 4;
+ ENUM_BITFIELD(type_specific_kind) type_specific_field : 3;
+
+ /* The language for this type. */
+
+ ENUM_BITFIELD(language) m_lang : LANGUAGE_BITS;
/* * Number of fields described for this type. This field appears
at this location because it packs nicely here. */
return this->code () == TYPE_CODE_PTR || TYPE_IS_REFERENCE (this);
}
+ /* Return true if this type is "string-like", according to its
+ defining language. */
+ bool is_string_like ();
+
/* Return true if this type is "array-like". This includes arrays,
but also some forms of structure type that are recognized as
representations of arrays by the type's language. */
bool is_array_like ();
+ /* Return the language that this type came from. */
+ enum language language () const
+ { return main_type->m_lang; }
+
/* * Type that is a pointer to this type.
NULL if no such pointer-to type is known yet.
The debugger may add the address of such a type
|| (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_NONE \
&& (type)->is_fixed_instance ()))
-/* Currently there isn't any associated data -- this is just a
- marker. */
-#define INIT_RUST_SPECIFIC(type) \
- TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_RUST_STUFF
-
-#define HAVE_RUST_SPECIFIC(type) \
- (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_RUST_STUFF)
-
#define INIT_FUNC_SPECIFIC(type) \
(TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_FUNC, \
TYPE_MAIN_TYPE (type)->type_specific.func_stuff = (struct func_type *) \
public:
/* Create new types on OBJFILE. */
- explicit type_allocator (objfile *objfile)
- : m_is_objfile (true)
+ type_allocator (objfile *objfile, enum language lang)
+ : m_is_objfile (true),
+ m_lang (lang)
{
m_data.objfile = objfile;
}
/* Create new types on GDBARCH. */
explicit type_allocator (gdbarch *gdbarch)
+ : m_lang (language_minimal)
{
m_data.gdbarch = gdbarch;
}
is passed, overwrite TYPE. */
explicit type_allocator (struct type *type,
type_allocator_kind kind = SAME)
+ : m_lang (type->language ())
{
if (kind == SAME)
{
/* Create new types on the same obstack as TYPE. */
explicit type_allocator (const struct type *type)
- : m_is_objfile (type->is_objfile_owned ())
+ : m_is_objfile (type->is_objfile_owned ()),
+ m_lang (type->language ())
{
if (type->is_objfile_owned ())
m_data.objfile = type->objfile_owner ();
/* True if this allocator uses the type field above, indicating that
the "allocation" should be done in-place. */
bool m_smash = false;
+ /* The language for types created by this allocator. */
+ enum language m_lang;
};
/* Allocate a TYPE_CODE_INT type structure using ALLOC. BIT is the
if (map_bt[bt])
return map_bt[bt];
- type_allocator alloc (objfile);
+ type_allocator alloc (objfile, get_current_subfile ()->language);
switch (bt)
{
}
}
- type_allocator alloc (mdebugread_objfile);
+ type_allocator alloc (mdebugread_objfile, get_current_subfile ()->language);
/* Move on to next aux. */
ax++;
rf = rn->rfd;
}
- type_allocator alloc (mdebugread_objfile);
+ type_allocator alloc (mdebugread_objfile, get_current_subfile ()->language);
/* mips cc uses a rf of -1 for opaque struct definitions.
Set TYPE_STUB for these types so that check_typedef will
{
struct type *t;
- t = type_allocator (mdebugread_objfile).new_type ();
+ t = type_allocator (mdebugread_objfile,
+ get_current_subfile ()->language).new_type ();
t->set_name (name);
INIT_CPLUS_SPECIFIC (t);
return t;
typy_is_array_like (PyObject *self, void *closure)
{
struct type *type = ((type_object *) self)->type;
+ bool result = false;
try
{
type = check_typedef (type);
+ result = type->is_array_like ();
}
catch (const gdb_exception &except)
{
GDB_PY_HANDLE_EXCEPTION (except);
}
- if (type->is_array_like ())
+ if (result)
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
try
{
type = check_typedef (type);
-
- const language_defn *lang = nullptr;
- if (HAVE_GNAT_AUX_INFO (type))
- lang = language_def (language_ada);
- else if (HAVE_RUST_SPECIFIC (type))
- lang = language_def (language_rust);
- if (lang != nullptr)
- result = lang->is_string_type_p (type);
+ result = type->is_string_like ();
}
catch (const gdb_exception &except)
{
if (typenums[0] == -1)
{
- return type_allocator (objfile).new_type ();
+ return type_allocator (objfile,
+ get_current_subfile ()->language).new_type ();
}
type_addr = dbx_lookup_type (typenums, objfile);
We will fill it in later if we find out how. */
if (*type_addr == 0)
{
- *type_addr = type_allocator (objfile).new_type ();
+ *type_addr = type_allocator (objfile,
+ get_current_subfile ()->language).new_type ();
}
return (*type_addr);
struct type *type;
format = gdbarch_floatformat_for_type (gdbarch, NULL, bits);
- type_allocator alloc (objfile);
+ type_allocator alloc (objfile, get_current_subfile ()->language);
if (format)
type = init_float_type (alloc, bits, NULL, format);
else
/* NULL terminate the string. */
string_local[ind] = 0;
- type_allocator alloc (objfile);
+ type_allocator alloc (objfile, get_current_subfile ()->language);
range_type
= create_static_range_type (alloc,
builtin_type (objfile)->builtin_int,
case 'S': /* Set type */
{
type1 = read_type (pp, objfile);
- type_allocator alloc (objfile);
+ type_allocator alloc (objfile, get_current_subfile ()->language);
type = create_set_type (alloc, type1);
if (typenums[0] != -1)
*dbx_lookup_type (typenums, objfile) = type;
TARGET_CHAR_BIT. */
#endif
- type_allocator alloc (objfile);
+ type_allocator alloc (objfile, get_current_subfile ()->language);
switch (-typenum)
{
case 1:
upper = -1;
}
- type_allocator alloc (objfile);
+ type_allocator alloc (objfile, get_current_subfile ()->language);
range_type =
create_static_range_type (alloc, index_type, lower, upper);
type_allocator smash_alloc (type, type_allocator::SMASH);
if (**pp == ';')
++(*pp);
- type_allocator alloc (objfile);
+ type_allocator alloc (objfile, get_current_subfile ()->language);
if (type_bits == 0)
{
struct type *type = alloc.new_type (TYPE_CODE_VOID,
if (n2bits == -1 || n3bits == -1)
return error_type (pp, objfile);
- type_allocator alloc (objfile);
+ type_allocator alloc (objfile, get_current_subfile ()->language);
if (index_type)
goto handle_true_range;
if (type->is_array_like ())
{
- if (HAVE_GNAT_AUX_INFO (type))
- return ada_coerce_to_simple_array (val);
- if (HAVE_RUST_SPECIFIC (type))
- return rust_slice_to_array (val);
+ const language_defn *defn = language_def (type->language ());
+ return defn->to_array (val);
}
return nullptr;
}