86 #define ENTRY(X) { X, #X } 127 Py_XDECREF (f->
dict);
139 result->dict = PyDict_New ();
143 return (PyObject *) result.
release ();
179 if (PyObject_SetAttrString (result.
get (),
"parent_type", arg.
get ()) < 0)
184 const char *attrstring;
190 attrstring =
"enumval";
196 attrstring =
"bitpos";
203 if (PyObject_SetAttrString (result.
get (), (
char *) attrstring,
223 Py_INCREF (arg.
get ());
225 if (PyObject_SetAttrString (result.
get (),
"name", arg.
get ()) < 0)
229 Py_INCREF (arg.
get ());
230 if (PyObject_SetAttrString (result.
get (),
"artificial", arg.
get ()) < 0)
236 arg.
reset (Py_False);
237 Py_INCREF (arg.
get ());
238 if (PyObject_SetAttrString (result.
get (),
"is_base_class", arg.
get ()) < 0)
244 if (PyObject_SetAttrString (result.
get (),
"bitsize", arg.
get ()) < 0)
251 Py_INCREF (arg.
get ());
257 if (PyObject_SetAttrString (result.
get (),
"type", arg.
get ()) < 0)
303 PyTuple_SET_ITEM (item.
get (), 0, key.
release ());
304 PyTuple_SET_ITEM (item.
get (), 1,
value.release ());
321 PyObject *py_type =
self;
322 PyObject *result = NULL, *iter = NULL;
336 if (checked_type !=
type)
339 if (checked_type !=
type)
347 result = PySequence_List (iter);
382 return Py_BuildValue (
"[O]", r.
get ());
475 PyErr_SetString (PyExc_TypeError,
476 "Type is not a structure, union, enum, or function type.");
489 PyObject *n2_obj = NULL;
490 struct type *array = NULL;
493 if (! PyArg_ParseTuple (args,
"l|O", &n1, &n2_obj))
498 if (!PyInt_Check (n2_obj))
500 PyErr_SetString (PyExc_RuntimeError,
501 _(
"Array bound must be an integer"));
516 PyErr_SetString (PyExc_ValueError,
517 _(
"Array length must not be negative"));
585 PyErr_SetString (PyExc_RuntimeError,
586 _(
"This type does not have a range."));
604 if (low_bound == NULL)
608 if (high_bound == NULL)
615 if (PyTuple_SetItem (result.
get (), 0, low_bound.
release ()) != 0
616 || PyTuple_SetItem (result.
get (), 1, high_bound.
release ()) != 0)
648 PyErr_SetString (PyExc_RuntimeError,
649 _(
"Type does not have a target."));
748 type_name,
block, 0);
764 enum demangle_component_type demangled_type;
768 demangled_type = demangled->type;
770 if (demangled_type == DEMANGLE_COMPONENT_POINTER
771 || demangled_type == DEMANGLE_COMPONENT_REFERENCE
772 || demangled_type == DEMANGLE_COMPONENT_RVALUE_REFERENCE
773 || demangled_type == DEMANGLE_COMPONENT_CONST
774 || demangled_type == DEMANGLE_COMPONENT_VOLATILE)
786 switch (demangled_type)
788 case DEMANGLE_COMPONENT_REFERENCE:
791 case DEMANGLE_COMPONENT_RVALUE_REFERENCE:
794 case DEMANGLE_COMPONENT_POINTER:
797 case DEMANGLE_COMPONENT_CONST:
800 case DEMANGLE_COMPONENT_VOLATILE:
832 struct demangle_component *demangled;
833 std::unique_ptr<demangle_parse_info> info;
835 struct type *argtype;
839 PyErr_SetString (PyExc_RuntimeError,
_(
"Null type name."));
856 PyErr_SetString (PyExc_RuntimeError,
err);
859 demangled = info->tree;
862 while (demangled->type == DEMANGLE_COMPONENT_QUAL_NAME
863 || demangled->type == DEMANGLE_COMPONENT_LOCAL_NAME)
864 demangled = demangled->u.s_binary.right;
866 if (demangled->type != DEMANGLE_COMPONENT_TEMPLATE)
868 PyErr_SetString (PyExc_RuntimeError,
_(
"Type is not a template."));
873 demangled = demangled->u.s_binary.right;
875 for (i = 0; demangled && i < argno; ++i)
876 demangled = demangled->u.s_binary.right;
880 PyErr_Format (PyExc_RuntimeError,
_(
"No argument %d in template."),
898 PyObject *block_obj = NULL;
900 struct value *val = NULL;
902 if (! PyArg_ParseTuple (args,
"i|O", &argno, &block_obj))
910 PyErr_SetString (PyExc_RuntimeError,
911 _(
"Second argument must be block."));
936 PyErr_Format (PyExc_RuntimeError,
_(
"No argument %d in template."),
946 PyErr_Format (PyExc_RuntimeError,
947 _(
"Template argument is optimized out"));
980 return PyUnicode_Decode (thetype.
c_str (), thetype.
size (),
995 if (type2 == NULL || (op != Py_EQ && op != Py_NE))
997 Py_INCREF (Py_NotImplemented);
998 return Py_NotImplemented;
1018 if (op == (result ? Py_EQ : Py_NE))
1031 htab_t copied_types;
1046 htab_empty (copied_types);
1056 htab_delete (copied_types);
1157 if (t_field_name && (
strcmp_iw (t_field_name,
field.get ()) == 0))
1162 PyErr_SetObject (PyExc_KeyError, key);
1173 PyObject *key, *defval = Py_None, *result;
1175 if (!PyArg_UnpackTuple (args,
"get", 1, 2, &key, &defval))
1185 if (!PyErr_ExceptionMatches (PyExc_KeyError))
1202 if (!PyArg_ParseTuple (args,
"s", &
field))
1236 if (typy_iter_obj == NULL)
1239 typy_iter_obj->
field = 0;
1240 typy_iter_obj->
kind = kind;
1244 return (PyObject *) typy_iter_obj;
1328 return (PyObject *) type_obj;
1345 static const char *keywords[] = {
"name",
"block", NULL };
1346 const char *type_name = NULL;
1348 PyObject *block_obj = NULL;
1352 &type_name, &block_obj))
1360 PyErr_SetString (PyExc_RuntimeError,
1361 _(
"'block' argument must be a Block."));
1414 "The code for this type.", NULL },
1416 "The name for this type, or None.", NULL },
1418 "The size of this type, in bytes.", NULL },
1420 "The tag name for this type, or None.", NULL },
1427 "array ([LOW_BOUND,] HIGH_BOUND) -> Type\n\ 1428 Return a type which represents an array of objects of this type.\n\ 1429 The bounds of the array are [LOW_BOUND, HIGH_BOUND] inclusive.\n\ 1430 If LOW_BOUND is omitted, a value of zero is used." },
1432 "vector ([LOW_BOUND,] HIGH_BOUND) -> Type\n\ 1433 Return a type which represents a vector of objects of this type.\n\ 1434 The bounds of the array are [LOW_BOUND, HIGH_BOUND] inclusive.\n\ 1435 If LOW_BOUND is omitted, a value of zero is used.\n\ 1436 Vectors differ from arrays in that if the current language has C-style\n\ 1437 arrays, vectors don't decay to a pointer to the first element.\n\ 1438 They are first class values." },
1440 "T.__contains__(k) -> True if T has a field named k, else False" },
1442 "const () -> Type\n\ 1443 Return a const variant of this type." },
1445 "optimized_out() -> Value\n\ 1446 Return optimized out value of this type." },
1448 "fields () -> list\n\ 1449 Return a list holding all the fields of this type.\n\ 1450 Each field is a gdb.Field object." },
1452 "T.get(k[,default]) -> returns field named k in T, if it exists;\n\ 1453 otherwise returns default, if supplied, or None if not." },
1455 "T.has_key(k) -> True if T has a field named k, else False" },
1457 "items () -> list\n\ 1458 Return a list of (name, field) pairs of this type.\n\ 1459 Each field is a gdb.Field object." },
1461 "iteritems () -> an iterator over the (name, field)\n\ 1462 pairs of this type. Each field is a gdb.Field object." },
1464 "iterkeys () -> an iterator over the field names of this type." },
1466 "itervalues () -> an iterator over the fields of this type.\n\ 1467 Each field is a gdb.Field object." },
1470 Return a list holding all the fields names of this type." },
1472 "pointer () -> Type\n\ 1473 Return a type of pointer to this type." },
1475 "range () -> tuple\n\ 1476 Return a tuple containing the lower and upper range for this type."},
1478 "reference () -> Type\n\ 1479 Return a type of reference to this type." },
1481 "strip_typedefs () -> Type\n\ 1482 Return a type formed by stripping this type of all typedefs."},
1484 "target () -> Type\n\ 1485 Return the target type of this type." },
1487 "template_argument (arg, [block]) -> Type\n\ 1488 Return the type of a template argument." },
1490 "unqualified () -> Type\n\ 1491 Return a variant of this type without const or volatile attributes." },
1493 "values () -> list\n\ 1494 Return a list holding all the fields of this type.\n\ 1495 Each field is a gdb.Field object." },
1497 "volatile () -> Type\n\ 1498 Return a volatile variant of this type" },
1564 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER,
1613 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER,
1654 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER,
1655 "GDB type iterator object",
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t err
PyTypeObject type_object_type
int gdb_pymodule_addobject(PyObject *module, const char *name, PyObject *object)
struct std::unique_ptr< demangle_parse_info > cp_demangled_name_to_comp(const char *demangled_name, const char **errmsg)
struct type * lookup_array_range_type(struct type *element_type, LONGEST low_bound, LONGEST high_bound)
PyObject * gdb_py_generic_dict(PyObject *self, void *closure)
static gdb_PyGetSetDef type_object_getset[]
static PyObject * typy_volatile(PyObject *self, PyObject *args)
static PyObject * typy_fields(PyObject *self, PyObject *args)
#define TYPE_FIELD_NAME(thistype, n)
#define TYPE_N_BASECLASSES(thistype)
#define TYPE_LOW_BOUND(range_type)
gdb::unique_xmalloc_ptr< char > cp_comp_to_string(struct demangle_component *result, int estimated_len)
static PyObject * typy_str(PyObject *self)
int strcmp_iw(const char *string1, const char *string2)
struct type * type_object_to_type(PyObject *obj)
#define TYPE_NAME(thistype)
#define TYPE_FIELD_ARTIFICIAL(thistype, n)
#define TYPE_HIGH_BOUND(range_type)
static PyObject * typy_const(PyObject *self, PyObject *args)
const struct type_print_options type_print_raw_options
struct pyty_type_object type_object
static PyObject * convert_field(struct type *type, int field)
#define SYMBOL_CLASS(symbol)
static PyObject * typy_unqualified(PyObject *self, PyObject *args)
int gdbpy_is_field(PyObject *obj)
static Py_ssize_t typy_length(PyObject *self)
static PyObject * typy_fields_items(PyObject *self, enum gdbpy_iter_kind kind)
PyTypeObject type_object_type CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF("type_object")
static int gdb_PyArg_ParseTupleAndKeywords(PyObject *args, PyObject *kw, const char *format, const char **keywords,...)
#define PyVarObject_HEAD_INIT(type, size)
#define TYPE_FIELD(thistype, n)
PyObject * gdbpy_lookup_type(PyObject *self, PyObject *args, PyObject *kw)
static PyObject * field_new(void)
static void typy_dealloc(PyObject *obj)
#define TYPE_FIELD_ENUMVAL(thistype, n)
#define TYPE_FIELD_TYPE(thistype, n)
static struct type * typy_get_composite(struct type *type)
#define TYPE_IS_REFERENCE(t)
#define GDB_PY_HANDLE_EXCEPTION(Exception)
static PyObject * typy_range(PyObject *self, PyObject *args)
#define TYPE_N_TEMPLATE_ARGUMENTS(thistype)
int types_deeply_equal(struct type *type1, struct type *type2)
static void set_type(type_object *obj, struct type *type)
struct type * lookup_typename(const struct language_defn *language, struct gdbarch *gdbarch, const char *name, const struct block *block, int noerr)
static PyObject * typy_array_1(PyObject *self, PyObject *args, int is_vector)
static PyObject * typy_make_iter(PyObject *self, enum gdbpy_iter_kind kind)
static PyObject * typy_iter(PyObject *self)
static void typy_iterator_dealloc(PyObject *obj)
struct type * check_typedef(struct type *type)
#define CATCH(EXCEPTION, MASK)
struct type * lookup_rvalue_reference_type(struct type *type)
static PyObject * typy_items(PyObject *self, PyObject *args)
PyObject_HEAD PyObject * dict
std::unique_ptr< T, xfree_deleter< T > > unique_xmalloc_ptr
static PyObject * typy_get_name(PyObject *self, void *closure)
int field_is_static(struct field *f)
struct type * lookup_struct(const char *name, const struct block *block)
#define gdb_assert_not_reached(message)
static struct type * typy_lookup_typename(const char *type_name, const struct block *block)
static PyObject * typy_has_key(PyObject *self, PyObject *args)
struct type * lookup_enum(const char *name, const struct block *block)
struct type * copy_type_recursive(struct objfile *objfile, struct type *type, htab_t copied_types)
struct gdbarch * get_objfile_arch(const struct objfile *objfile)
PyTypeObject field_object_type
static int typy_nonzero(PyObject *self)
const struct block * block_object_to_block(PyObject *obj)
static void save_objfile_types(struct objfile *objfile, void *datum)
static PyObject * typy_strip_typedefs(PyObject *self, PyObject *args)
struct gdbarch * python_gdbarch
struct pyty_type_object * source
static PyObject * typy_target(PyObject *self, PyObject *args)
PyObject * value_to_value_object(struct value *val)
static int startswith(const char *string, const char *pattern)
htab_t create_copied_types_hash(struct objfile *objfile)
struct type * lookup_union(const char *name, const struct block *block)
int gdb_python_initialized
static PyObject * typy_get_code(PyObject *self, void *closure)
gdb::unique_xmalloc_ptr< char > python_string_to_host_string(PyObject *obj)
static PyObject * typy_richcompare(PyObject *self, PyObject *other, int op)
static PyObject * typy_reference(PyObject *self, PyObject *args)
#define TYPE_FIELD_BITSIZE(thistype, n)
#define TYPE_FIELD_BITPOS(thistype, n)
static PyObject * typy_array(PyObject *self, PyObject *args)
static PyObject * typy_iterator_iternext(PyObject *self)
#define gdb_py_long_from_longest
#define LA_PRINT_TYPE(type, varstring, stream, show, level, flags)
enum gdbpy_iter_kind kind
static PyMethodDef type_object_methods[]
struct type * make_cv_type(int cnst, int voltl, struct type *type, struct type **typeptr)
const struct language_defn * current_language
#define TYPE_TARGET_TYPE(thistype)
static PyObject * make_fielditem(struct type *type, int i, enum gdbpy_iter_kind kind)
int gdbpy_initialize_types(void)
#define TYPE_CODE(thistype)
#define TYPE_INDEX_TYPE(type)
const char * c_str() const
static PyObject * typy_iterator_iter(PyObject *self)
struct pyty_field_object field_object
struct value * value_of_variable(struct symbol *var, const struct block *b)
static PyObject * typy_getitem(PyObject *self, PyObject *key)
static PyObject * typy_field_names(PyObject *self, PyObject *args)
#define TYPE_NFIELDS(thistype)
static PyObject * typy_iteritems(PyObject *self, PyObject *args)
static PyObject * typy_values(PyObject *self, PyObject *args)
static const struct objfile_data * typy_objfile_data_key
struct pyty_type_object * next
struct pyty_type_object * prev
#define TYPE_TAG_NAME(type)
static PyObject * typy_optimized_out(PyObject *self, PyObject *args)
PyTypeObject type_iterator_object_type
static PyObject * typy_pointer(PyObject *self, PyObject *args)
static PyObject * field_name(struct type *type, int field)
int gdb_py_int_as_long(PyObject *obj, long *result)
#define TYPE_TEMPLATE_ARGUMENT(thistype, n)
#define SYMBOL_TYPE(symbol)
static PyObject * typy_legacy_template_argument(struct type *type, const struct block *block, int argno)
const struct language_defn * python_language
static PyObject * typy_iterkeys(PyObject *self, PyObject *args)
const char * host_charset(void)
#define TYPE_LENGTH(thistype)
static PyObject * typy_get(PyObject *self, PyObject *args)
struct value * allocate_optimized_out_value(struct type *type)
static struct pyty_code pyty_codes[]
static PyObject * typy_template_argument(PyObject *self, PyObject *args)
static struct type * typy_lookup_type(struct demangle_component *demangled, const struct block *block)
static PyObject * typy_itervalues(PyObject *self, PyObject *args)
static gdb_PyGetSetDef field_object_getset[]
static PyObject * typy_get_tag(PyObject *self, void *closure)
static PyObject * typy_vector(PyObject *self, PyObject *args)
static PyObject * typy_get_sizeof(PyObject *self, void *closure)
struct type * lookup_lvalue_reference_type(struct type *type)
void make_vector_type(struct type *array_type)
static void field_dealloc(PyObject *obj)
struct type * lookup_pointer_type(struct type *type)
static PyMappingMethods typy_mapping
static PyNumberMethods type_object_as_number
PyObject_HEAD struct type * type
PyObject * type_to_type_object(struct type *type)