{
struct type *type = ((type_object *) self)->type;
- return PyInt_FromLong (TYPE_CODE (type));
+ return PyInt_FromLong (type->code ());
}
/* Helper function for typy_fields which converts a single field to a
if (PyObject_SetAttrString (result.get (), "parent_type", arg.get ()) < 0)
return NULL;
- if (!field_is_static (&TYPE_FIELD (type, field)))
+ if (!field_is_static (&type->field (field)))
{
const char *attrstring;
- if (TYPE_CODE (type) == TYPE_CODE_ENUM)
+ if (type->code () == TYPE_CODE_ENUM)
{
arg.reset (gdb_py_long_from_longest (TYPE_FIELD_ENUMVAL (type,
field)));
}
else
{
- arg.reset (gdb_py_long_from_longest (TYPE_FIELD_BITPOS (type,
- field)));
+ if (TYPE_FIELD_LOC_KIND (type, field) == FIELD_LOC_KIND_DWARF_BLOCK)
+ arg = gdbpy_ref<>::new_reference (Py_None);
+ else
+ arg.reset (gdb_py_long_from_longest (TYPE_FIELD_BITPOS (type,
+ field)));
attrstring = "bitpos";
}
if (PyObject_SetAttrString (result.get (), "artificial", arg.get ()) < 0)
return NULL;
- if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
+ if (type->code () == TYPE_CODE_STRUCT)
arg = gdbpy_ref<>::new_reference (field < TYPE_N_BASECLASSES (type)
? Py_True : Py_False);
else
return NULL;
/* A field can have a NULL type in some situations. */
- if (TYPE_FIELD_TYPE (type, field) == NULL)
+ if (type->field (field).type () == NULL)
arg = gdbpy_ref<>::new_reference (Py_None);
else
- arg.reset (type_to_type_object (TYPE_FIELD_TYPE (type, field)));
+ arg.reset (type_to_type_object (type->field (field).type ()));
if (arg == NULL)
return NULL;
if (PyObject_SetAttrString (result.get (), "type", arg.get ()) < 0)
{
struct type *type = ((type_object *) self)->type;
- if (TYPE_CODE (type) != TYPE_CODE_ARRAY)
+ if (type->code () != TYPE_CODE_ARRAY)
return typy_fields_items (self, iter_values);
/* Array type. Handle this as a special case because the common
{
struct type *type = ((type_object *) self)->type;
- if (TYPE_NAME (type) == NULL)
+ if (type->name () == NULL)
Py_RETURN_NONE;
- return PyString_FromString (TYPE_NAME (type));
+ return PyString_FromString (type->name ());
}
/* Return the type's tag, or None. */
struct type *type = ((type_object *) self)->type;
const char *tagname = nullptr;
- if (TYPE_CODE (type) == TYPE_CODE_STRUCT
- || TYPE_CODE (type) == TYPE_CODE_UNION
- || TYPE_CODE (type) == TYPE_CODE_ENUM)
- tagname = TYPE_NAME (type);
+ if (type->code () == TYPE_CODE_STRUCT
+ || type->code () == TYPE_CODE_UNION
+ || type->code () == TYPE_CODE_ENUM)
+ tagname = type->name ();
if (tagname == nullptr)
Py_RETURN_NONE;
GDB_PY_HANDLE_EXCEPTION (except);
}
- if (TYPE_CODE (type) != TYPE_CODE_PTR && !TYPE_IS_REFERENCE (type))
+ if (type->code () != TYPE_CODE_PTR && !TYPE_IS_REFERENCE (type))
break;
type = TYPE_TARGET_TYPE (type);
}
/* If this is not a struct, union, or enum type, raise TypeError
exception. */
- if (TYPE_CODE (type) != TYPE_CODE_STRUCT
- && TYPE_CODE (type) != TYPE_CODE_UNION
- && TYPE_CODE (type) != TYPE_CODE_ENUM
- && TYPE_CODE (type) != TYPE_CODE_FUNC)
+ if (type->code () != TYPE_CODE_STRUCT
+ && type->code () != TYPE_CODE_UNION
+ && type->code () != TYPE_CODE_ENUM
+ && type->code () != TYPE_CODE_FUNC)
{
PyErr_SetString (PyExc_TypeError,
"Type is not a structure, union, enum, or function type.");
/* Initialize these to appease GCC warnings. */
LONGEST low = 0, high = 0;
- if (TYPE_CODE (type) != TYPE_CODE_ARRAY
- && TYPE_CODE (type) != TYPE_CODE_STRING
- && TYPE_CODE (type) != TYPE_CODE_RANGE)
+ if (type->code () != TYPE_CODE_ARRAY
+ && type->code () != TYPE_CODE_STRING
+ && type->code () != TYPE_CODE_RANGE)
{
PyErr_SetString (PyExc_RuntimeError,
_("This type does not have a range."));
return NULL;
}
- switch (TYPE_CODE (type))
+ switch (type->code ())
{
case TYPE_CODE_ARRAY:
case TYPE_CODE_STRING:
- low = TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type));
- high = TYPE_HIGH_BOUND (TYPE_INDEX_TYPE (type));
+ low = TYPE_LOW_BOUND (type->index_type ());
+ high = TYPE_HIGH_BOUND (type->index_type ());
break;
case TYPE_CODE_RANGE:
low = TYPE_LOW_BOUND (type);
{
struct type *type = ((type_object *) self)->type;
+ bool size_varies = false;
try
{
check_typedef (type);
+
+ size_varies = TYPE_HAS_DYNAMIC_LENGTH (type);
}
catch (const gdb_exception &except)
{
/* Ignore exceptions. */
+ if (size_varies)
+ Py_RETURN_NONE;
return gdb_py_long_from_longest (TYPE_LENGTH (type));
}
return gdb_py_object_from_ulongest (align).release ();
}
+/* Return whether or not the type is dynamic. */
+static PyObject *
+typy_get_dynamic (PyObject *self, void *closure)
+{
+ struct type *type = ((type_object *) self)->type;
+
+ bool result = false;
+ try
+ {
+ result = is_dynamic_type (type);
+ }
+ catch (const gdb_exception &except)
+ {
+ /* Ignore exceptions. */
+ }
+
+ if (result)
+ Py_RETURN_TRUE;
+ Py_RETURN_FALSE;
+}
+
static struct type *
typy_lookup_typename (const char *type_name, const struct block *block)
{
std::string err;
struct type *argtype;
- if (TYPE_NAME (type) == NULL)
+ if (type->name () == NULL)
{
PyErr_SetString (PyExc_RuntimeError, _("Null type name."));
return NULL;
try
{
/* Note -- this is not thread-safe. */
- info = cp_demangled_name_to_comp (TYPE_NAME (type), &err);
+ info = cp_demangled_name_to_comp (type->name (), &err);
}
catch (const gdb_exception &except)
{
if (type == NULL)
return -1;
- return TYPE_NFIELDS (type);
+ return type->num_fields ();
}
/* Implements boolean evaluation of gdb.Type. Handle this like other
if (type == NULL)
return NULL;
- for (i = 0; i < TYPE_NFIELDS (type); i++)
+ for (i = 0; i < type->num_fields (); i++)
{
const char *t_field_name = TYPE_FIELD_NAME (type, i);
if (type == NULL)
return NULL;
- for (i = 0; i < TYPE_NFIELDS (type); i++)
+ for (i = 0; i < type->num_fields (); i++)
{
const char *t_field_name = TYPE_FIELD_NAME (type, i);
typy_iterator_object *iter_obj = (typy_iterator_object *) self;
struct type *type = iter_obj->source->type;
- if (iter_obj->field < TYPE_NFIELDS (type))
+ if (iter_obj->field < type->num_fields ())
{
gdbpy_ref<> result = make_fielditem (type, iter_obj->field,
iter_obj->kind);
"The alignment of this type, in bytes.", NULL },
{ "code", typy_get_code, NULL,
"The code for this type.", NULL },
+ { "dynamic", typy_get_dynamic, NULL,
+ "Whether this type is dynamic.", NULL },
{ "name", typy_get_name, NULL,
"The name for this type, or None.", NULL },
{ "sizeof", typy_get_sizeof, NULL,