]> Git Repo - binutils.git/blob - gdb/python/py-type.c
4ad1e12bf5ef7dbeb6b91585f6604106d7849951
[binutils.git] / gdb / python / py-type.c
1 /* Python interface to types.
2
3    Copyright (C) 2008-2013 Free Software Foundation, Inc.
4
5    This file is part of GDB.
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19
20 #include "defs.h"
21 #include "value.h"
22 #include "exceptions.h"
23 #include "python-internal.h"
24 #include "charset.h"
25 #include "gdbtypes.h"
26 #include "cp-support.h"
27 #include "demangle.h"
28 #include "objfiles.h"
29 #include "language.h"
30 #include "vec.h"
31 #include "typeprint.h"
32
33 typedef struct pyty_type_object
34 {
35   PyObject_HEAD
36   struct type *type;
37
38   /* If a Type object is associated with an objfile, it is kept on a
39      doubly-linked list, rooted in the objfile.  This lets us copy the
40      underlying struct type when the objfile is deleted.  */
41   struct pyty_type_object *prev;
42   struct pyty_type_object *next;
43 } type_object;
44
45 static PyTypeObject type_object_type
46     CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("type_object");
47
48 /* A Field object.  */
49 typedef struct pyty_field_object
50 {
51   PyObject_HEAD
52
53   /* Dictionary holding our attributes.  */
54   PyObject *dict;
55 } field_object;
56
57 static PyTypeObject field_object_type
58     CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("field_object");
59
60 /* A type iterator object.  */
61 typedef struct {
62   PyObject_HEAD
63   /* The current field index.  */
64   int field;
65   /* What to return.  */
66   enum gdbpy_iter_kind kind;
67   /* Pointer back to the original source type object.  */
68   struct pyty_type_object *source;
69 } typy_iterator_object;
70
71 static PyTypeObject type_iterator_object_type
72     CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("typy_iterator_object");
73
74 /* This is used to initialize various gdb.TYPE_ constants.  */
75 struct pyty_code
76 {
77   /* The code.  */
78   enum type_code code;
79   /* The name.  */
80   const char *name;
81 };
82
83 /* Forward declarations.  */
84 static PyObject *typy_make_iter (PyObject *self, enum gdbpy_iter_kind kind);
85
86 #define ENTRY(X) { X, #X }
87
88 static struct pyty_code pyty_codes[] =
89 {
90   ENTRY (TYPE_CODE_BITSTRING),
91   ENTRY (TYPE_CODE_PTR),
92   ENTRY (TYPE_CODE_ARRAY),
93   ENTRY (TYPE_CODE_STRUCT),
94   ENTRY (TYPE_CODE_UNION),
95   ENTRY (TYPE_CODE_ENUM),
96   ENTRY (TYPE_CODE_FLAGS),
97   ENTRY (TYPE_CODE_FUNC),
98   ENTRY (TYPE_CODE_INT),
99   ENTRY (TYPE_CODE_FLT),
100   ENTRY (TYPE_CODE_VOID),
101   ENTRY (TYPE_CODE_SET),
102   ENTRY (TYPE_CODE_RANGE),
103   ENTRY (TYPE_CODE_STRING),
104   ENTRY (TYPE_CODE_ERROR),
105   ENTRY (TYPE_CODE_METHOD),
106   ENTRY (TYPE_CODE_METHODPTR),
107   ENTRY (TYPE_CODE_MEMBERPTR),
108   ENTRY (TYPE_CODE_REF),
109   ENTRY (TYPE_CODE_CHAR),
110   ENTRY (TYPE_CODE_BOOL),
111   ENTRY (TYPE_CODE_COMPLEX),
112   ENTRY (TYPE_CODE_TYPEDEF),
113   ENTRY (TYPE_CODE_NAMESPACE),
114   ENTRY (TYPE_CODE_DECFLOAT),
115   ENTRY (TYPE_CODE_INTERNAL_FUNCTION),
116   { TYPE_CODE_UNDEF, NULL }
117 };
118
119 \f
120
121 static void
122 field_dealloc (PyObject *obj)
123 {
124   field_object *f = (field_object *) obj;
125
126   Py_XDECREF (f->dict);
127   Py_TYPE (obj)->tp_free (obj);
128 }
129
130 static PyObject *
131 field_new (void)
132 {
133   field_object *result = PyObject_New (field_object, &field_object_type);
134
135   if (result)
136     {
137       result->dict = PyDict_New ();
138       if (!result->dict)
139         {
140           Py_DECREF (result);
141           result = NULL;
142         }
143     }
144   return (PyObject *) result;
145 }
146
147 \f
148
149 /* Return true if OBJ is of type gdb.Field, false otherwise.  */
150
151 int
152 gdbpy_is_field (PyObject *obj)
153 {
154   return PyObject_TypeCheck (obj, &field_object_type);
155 }
156
157 /* Return the code for this type.  */
158 static PyObject *
159 typy_get_code (PyObject *self, void *closure)
160 {
161   struct type *type = ((type_object *) self)->type;
162
163   return PyInt_FromLong (TYPE_CODE (type));
164 }
165
166 /* Helper function for typy_fields which converts a single field to a
167    gdb.Field object.  Returns NULL on error.  */
168
169 static PyObject *
170 convert_field (struct type *type, int field)
171 {
172   PyObject *result = field_new ();
173   PyObject *arg;
174
175   if (!result)
176     return NULL;
177
178   arg = type_to_type_object (type);
179   if (arg == NULL)
180     goto fail;
181   if (PyObject_SetAttrString (result, "parent_type", arg) < 0)
182     goto failarg;
183   Py_DECREF (arg);
184
185   if (!field_is_static (&TYPE_FIELD (type, field)))
186     {
187       const char *attrstring;
188
189       if (TYPE_CODE (type) == TYPE_CODE_ENUM)
190         {
191           arg = gdb_py_long_from_longest (TYPE_FIELD_ENUMVAL (type, field));
192           attrstring = "enumval";
193         }
194       else
195         {
196           arg = gdb_py_long_from_longest (TYPE_FIELD_BITPOS (type, field));
197           attrstring = "bitpos";
198         }
199
200       if (!arg)
201         goto fail;
202
203       /* At least python-2.4 had the second parameter non-const.  */
204       if (PyObject_SetAttrString (result, (char *) attrstring, arg) < 0)
205         goto failarg;
206       Py_DECREF (arg);
207     }
208
209   if (TYPE_FIELD_NAME (type, field))
210     arg = PyString_FromString (TYPE_FIELD_NAME (type, field));
211   else
212     {
213       arg = Py_None;
214       Py_INCREF (arg);
215     }
216   if (!arg)
217     goto fail;
218   if (PyObject_SetAttrString (result, "name", arg) < 0)
219     goto failarg;
220   Py_DECREF (arg);
221
222   arg = TYPE_FIELD_ARTIFICIAL (type, field) ? Py_True : Py_False;
223   Py_INCREF (arg);
224   if (PyObject_SetAttrString (result, "artificial", arg) < 0)
225     goto failarg;
226   Py_DECREF (arg);
227
228   if (TYPE_CODE (type) == TYPE_CODE_CLASS)
229     arg = field < TYPE_N_BASECLASSES (type) ? Py_True : Py_False;
230   else
231     arg = Py_False;
232   Py_INCREF (arg);
233   if (PyObject_SetAttrString (result, "is_base_class", arg) < 0)
234     goto failarg;
235   Py_DECREF (arg);
236
237   arg = PyLong_FromLong (TYPE_FIELD_BITSIZE (type, field));
238   if (!arg)
239     goto fail;
240   if (PyObject_SetAttrString (result, "bitsize", arg) < 0)
241     goto failarg;
242   Py_DECREF (arg);
243
244   /* A field can have a NULL type in some situations.  */
245   if (TYPE_FIELD_TYPE (type, field) == NULL)
246     {
247       arg = Py_None;
248       Py_INCREF (arg);
249     }
250   else
251     arg = type_to_type_object (TYPE_FIELD_TYPE (type, field));
252   if (!arg)
253     goto fail;
254   if (PyObject_SetAttrString (result, "type", arg) < 0)
255     goto failarg;
256   Py_DECREF (arg);
257
258   return result;
259
260  failarg:
261   Py_DECREF (arg);
262  fail:
263   Py_DECREF (result);
264   return NULL;
265 }
266
267 /* Helper function to return the name of a field, as a gdb.Field object.
268    If the field doesn't have a name, None is returned.  */
269
270 static PyObject *
271 field_name (struct type *type, int field)
272 {
273   PyObject *result;
274
275   if (TYPE_FIELD_NAME (type, field))
276     result = PyString_FromString (TYPE_FIELD_NAME (type, field));
277   else
278     {
279       result = Py_None;
280       Py_INCREF (result);
281     }
282   return result;
283 }
284
285 /* Helper function for Type standard mapping methods.  Returns a
286    Python object for field i of the type.  "kind" specifies what to
287    return: the name of the field, a gdb.Field object corresponding to
288    the field, or a tuple consisting of field name and gdb.Field
289    object.  */
290
291 static PyObject *
292 make_fielditem (struct type *type, int i, enum gdbpy_iter_kind kind)
293 {
294   PyObject *item = NULL, *key = NULL, *value = NULL;
295
296   switch (kind)
297     {
298     case iter_items:
299       key = field_name (type, i);
300       if (key == NULL)
301         goto fail;
302       value = convert_field (type, i);
303       if (value == NULL)
304         goto fail;
305       item = PyTuple_New (2);
306       if (item == NULL)
307         goto fail;
308       PyTuple_SET_ITEM (item, 0, key);
309       PyTuple_SET_ITEM (item, 1, value);
310       break;
311     case iter_keys:
312       item = field_name (type, i);
313       break;
314     case iter_values:
315       item =  convert_field (type, i);
316       break;
317     default:
318       gdb_assert_not_reached ("invalid gdbpy_iter_kind");
319     }
320   return item;
321
322  fail:
323   Py_XDECREF (key);
324   Py_XDECREF (value);
325   Py_XDECREF (item);
326   return NULL;
327 }
328
329 /* Return a sequence of all field names, fields, or (name, field) pairs.
330    Each field is a gdb.Field object.  */
331
332 static PyObject *
333 typy_fields_items (PyObject *self, enum gdbpy_iter_kind kind)
334 {
335   PyObject *py_type = self;
336   PyObject *result = NULL, *iter = NULL;
337   volatile struct gdb_exception except;
338   struct type *type = ((type_object *) py_type)->type;
339   struct type *checked_type = type;
340
341   TRY_CATCH (except, RETURN_MASK_ALL)
342     {
343       CHECK_TYPEDEF (checked_type);
344     }
345   GDB_PY_HANDLE_EXCEPTION (except);
346
347   if (checked_type != type)
348     py_type = type_to_type_object (checked_type);
349   iter = typy_make_iter (py_type, kind);
350   if (checked_type != type)
351     {
352       /* Need to wrap this in braces because Py_DECREF isn't wrapped
353          in a do{}while(0).  */
354       Py_DECREF (py_type);
355     }
356   if (iter != NULL)
357     {
358       result = PySequence_List (iter);
359       Py_DECREF (iter);
360     }
361
362   return result;
363 }
364
365 /* Return a sequence of all fields.  Each field is a gdb.Field object.  */
366
367 static PyObject *
368 typy_values (PyObject *self, PyObject *args)
369 {
370   return typy_fields_items (self, iter_values);
371 }
372
373 /* Return a sequence of all fields.  Each field is a gdb.Field object.
374    This method is similar to typy_values, except where the supplied
375    gdb.Type is an array, in which case it returns a list of one entry
376    which is a gdb.Field object for a range (the array bounds).  */
377
378 static PyObject *
379 typy_fields (PyObject *self, PyObject *args)
380 {
381   struct type *type = ((type_object *) self)->type;
382   PyObject *r, *rl;
383
384   if (TYPE_CODE (type) != TYPE_CODE_ARRAY)
385     return typy_fields_items (self, iter_values);
386
387   /* Array type.  Handle this as a special case because the common
388      machinery wants struct or union or enum types.  Build a list of
389      one entry which is the range for the array.  */
390   r = convert_field (type, 0);
391   if (r == NULL)
392     return NULL;
393
394   rl = Py_BuildValue ("[O]", r);
395   Py_DECREF (r);
396
397   return rl;
398 }
399
400 /* Return a sequence of all field names.  Each field is a gdb.Field object.  */
401
402 static PyObject *
403 typy_field_names (PyObject *self, PyObject *args)
404 {
405   return typy_fields_items (self, iter_keys);
406 }
407
408 /* Return a sequence of all (name, fields) pairs.  Each field is a
409    gdb.Field object.  */
410
411 static PyObject *
412 typy_items (PyObject *self, PyObject *args)
413 {
414   return typy_fields_items (self, iter_items);
415 }
416
417 /* Return the type's tag, or None.  */
418 static PyObject *
419 typy_get_tag (PyObject *self, void *closure)
420 {
421   struct type *type = ((type_object *) self)->type;
422
423   if (!TYPE_TAG_NAME (type))
424     Py_RETURN_NONE;
425   return PyString_FromString (TYPE_TAG_NAME (type));
426 }
427
428 /* Return the type, stripped of typedefs. */
429 static PyObject *
430 typy_strip_typedefs (PyObject *self, PyObject *args)
431 {
432   struct type *type = ((type_object *) self)->type;
433   volatile struct gdb_exception except;
434
435   TRY_CATCH (except, RETURN_MASK_ALL)
436     {
437       type = check_typedef (type);
438     }
439   GDB_PY_HANDLE_EXCEPTION (except);
440
441   return type_to_type_object (type);
442 }
443
444 /* Strip typedefs and pointers/reference from a type.  Then check that
445    it is a struct, union, or enum type.  If not, raise TypeError.  */
446
447 static struct type *
448 typy_get_composite (struct type *type)
449 {
450   volatile struct gdb_exception except;
451
452   for (;;)
453     {
454       TRY_CATCH (except, RETURN_MASK_ALL)
455         {
456           CHECK_TYPEDEF (type);
457         }
458       GDB_PY_HANDLE_EXCEPTION (except);
459
460       if (TYPE_CODE (type) != TYPE_CODE_PTR
461           && TYPE_CODE (type) != TYPE_CODE_REF)
462         break;
463       type = TYPE_TARGET_TYPE (type);
464     }
465
466   /* If this is not a struct, union, or enum type, raise TypeError
467      exception.  */
468   if (TYPE_CODE (type) != TYPE_CODE_STRUCT
469       && TYPE_CODE (type) != TYPE_CODE_UNION
470       && TYPE_CODE (type) != TYPE_CODE_ENUM)
471     {
472       PyErr_SetString (PyExc_TypeError,
473                        "Type is not a structure, union, or enum type.");
474       return NULL;
475     }
476
477   return type;
478 }
479
480 /* Helper for typy_array and typy_vector.  */
481
482 static PyObject *
483 typy_array_1 (PyObject *self, PyObject *args, int is_vector)
484 {
485   long n1, n2;
486   PyObject *n2_obj = NULL;
487   struct type *array = NULL;
488   struct type *type = ((type_object *) self)->type;
489   volatile struct gdb_exception except;
490
491   if (! PyArg_ParseTuple (args, "l|O", &n1, &n2_obj))
492     return NULL;
493
494   if (n2_obj)
495     {
496       if (!PyInt_Check (n2_obj))
497         {
498           PyErr_SetString (PyExc_RuntimeError,
499                            _("Array bound must be an integer"));
500           return NULL;
501         }
502
503       if (! gdb_py_int_as_long (n2_obj, &n2))
504         return NULL;
505     }
506   else
507     {
508       n2 = n1;
509       n1 = 0;
510     }
511
512   if (n2 < n1)
513     {
514       PyErr_SetString (PyExc_ValueError,
515                        _("Array length must not be negative"));
516       return NULL;
517     }
518
519   TRY_CATCH (except, RETURN_MASK_ALL)
520     {
521       array = lookup_array_range_type (type, n1, n2);
522       if (is_vector)
523         make_vector_type (array);
524     }
525   GDB_PY_HANDLE_EXCEPTION (except);
526
527   return type_to_type_object (array);
528 }
529
530 /* Return an array type.  */
531
532 static PyObject *
533 typy_array (PyObject *self, PyObject *args)
534 {
535   return typy_array_1 (self, args, 0);
536 }
537
538 /* Return a vector type.  */
539
540 static PyObject *
541 typy_vector (PyObject *self, PyObject *args)
542 {
543   return typy_array_1 (self, args, 1);
544 }
545
546 /* Return a Type object which represents a pointer to SELF.  */
547 static PyObject *
548 typy_pointer (PyObject *self, PyObject *args)
549 {
550   struct type *type = ((type_object *) self)->type;
551   volatile struct gdb_exception except;
552
553   TRY_CATCH (except, RETURN_MASK_ALL)
554     {
555       type = lookup_pointer_type (type);
556     }
557   GDB_PY_HANDLE_EXCEPTION (except);
558
559   return type_to_type_object (type);
560 }
561
562 /* Return the range of a type represented by SELF.  The return type is
563    a tuple.  The first element of the tuple contains the low bound,
564    while the second element of the tuple contains the high bound.  */
565 static PyObject *
566 typy_range (PyObject *self, PyObject *args)
567 {
568   struct type *type = ((type_object *) self)->type;
569   PyObject *result;
570   PyObject *low_bound = NULL, *high_bound = NULL;
571   /* Initialize these to appease GCC warnings.  */
572   LONGEST low = 0, high = 0;
573
574   if (TYPE_CODE (type) != TYPE_CODE_ARRAY
575       && TYPE_CODE (type) != TYPE_CODE_STRING
576       && TYPE_CODE (type) != TYPE_CODE_RANGE)
577     {
578       PyErr_SetString (PyExc_RuntimeError,
579                        _("This type does not have a range."));
580       return NULL;
581     }
582
583   switch (TYPE_CODE (type))
584     {
585     case TYPE_CODE_ARRAY:
586     case TYPE_CODE_STRING:
587       low = TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type));
588       high = TYPE_HIGH_BOUND (TYPE_INDEX_TYPE (type));
589       break;
590     case TYPE_CODE_RANGE:
591       low = TYPE_LOW_BOUND (type);
592       high = TYPE_HIGH_BOUND (type);
593       break;
594     }
595
596   low_bound = PyLong_FromLong (low);
597   if (!low_bound)
598     goto failarg;
599
600   high_bound = PyLong_FromLong (high);
601   if (!high_bound)
602     goto failarg;
603
604   result = PyTuple_New (2);
605   if (!result)
606     goto failarg;
607
608   if (PyTuple_SetItem (result, 0, low_bound) != 0)
609     {
610       Py_DECREF (result);
611       goto failarg;
612     }
613   if (PyTuple_SetItem (result, 1, high_bound) != 0)
614     {
615       Py_DECREF (high_bound);
616       Py_DECREF (result);
617       return NULL;
618     }
619   return result;
620
621  failarg:
622   Py_XDECREF (high_bound);
623   Py_XDECREF (low_bound);
624   return NULL;
625 }
626
627 /* Return a Type object which represents a reference to SELF.  */
628 static PyObject *
629 typy_reference (PyObject *self, PyObject *args)
630 {
631   struct type *type = ((type_object *) self)->type;
632   volatile struct gdb_exception except;
633
634   TRY_CATCH (except, RETURN_MASK_ALL)
635     {
636       type = lookup_reference_type (type);
637     }
638   GDB_PY_HANDLE_EXCEPTION (except);
639
640   return type_to_type_object (type);
641 }
642
643 /* Return a Type object which represents the target type of SELF.  */
644 static PyObject *
645 typy_target (PyObject *self, PyObject *args)
646 {
647   struct type *type = ((type_object *) self)->type;
648
649   if (!TYPE_TARGET_TYPE (type))
650     {
651       PyErr_SetString (PyExc_RuntimeError,
652                        _("Type does not have a target."));
653       return NULL;
654     }
655
656   return type_to_type_object (TYPE_TARGET_TYPE (type));
657 }
658
659 /* Return a const-qualified type variant.  */
660 static PyObject *
661 typy_const (PyObject *self, PyObject *args)
662 {
663   struct type *type = ((type_object *) self)->type;
664   volatile struct gdb_exception except;
665
666   TRY_CATCH (except, RETURN_MASK_ALL)
667     {
668       type = make_cv_type (1, 0, type, NULL);
669     }
670   GDB_PY_HANDLE_EXCEPTION (except);
671
672   return type_to_type_object (type);
673 }
674
675 /* Return a volatile-qualified type variant.  */
676 static PyObject *
677 typy_volatile (PyObject *self, PyObject *args)
678 {
679   struct type *type = ((type_object *) self)->type;
680   volatile struct gdb_exception except;
681
682   TRY_CATCH (except, RETURN_MASK_ALL)
683     {
684       type = make_cv_type (0, 1, type, NULL);
685     }
686   GDB_PY_HANDLE_EXCEPTION (except);
687
688   return type_to_type_object (type);
689 }
690
691 /* Return an unqualified type variant.  */
692 static PyObject *
693 typy_unqualified (PyObject *self, PyObject *args)
694 {
695   struct type *type = ((type_object *) self)->type;
696   volatile struct gdb_exception except;
697
698   TRY_CATCH (except, RETURN_MASK_ALL)
699     {
700       type = make_cv_type (0, 0, type, NULL);
701     }
702   GDB_PY_HANDLE_EXCEPTION (except);
703
704   return type_to_type_object (type);
705 }
706
707 /* Return the size of the type represented by SELF, in bytes.  */
708 static PyObject *
709 typy_get_sizeof (PyObject *self, void *closure)
710 {
711   struct type *type = ((type_object *) self)->type;
712   volatile struct gdb_exception except;
713
714   TRY_CATCH (except, RETURN_MASK_ALL)
715     {
716       check_typedef (type);
717     }
718   /* Ignore exceptions.  */
719
720   return gdb_py_long_from_longest (TYPE_LENGTH (type));
721 }
722
723 static struct type *
724 typy_lookup_typename (const char *type_name, const struct block *block)
725 {
726   struct type *type = NULL;
727   volatile struct gdb_exception except;
728
729   TRY_CATCH (except, RETURN_MASK_ALL)
730     {
731       if (!strncmp (type_name, "struct ", 7))
732         type = lookup_struct (type_name + 7, NULL);
733       else if (!strncmp (type_name, "union ", 6))
734         type = lookup_union (type_name + 6, NULL);
735       else if (!strncmp (type_name, "enum ", 5))
736         type = lookup_enum (type_name + 5, NULL);
737       else
738         type = lookup_typename (python_language, python_gdbarch,
739                                 type_name, block, 0);
740     }
741   GDB_PY_HANDLE_EXCEPTION (except);
742
743   return type;
744 }
745
746 static struct type *
747 typy_lookup_type (struct demangle_component *demangled,
748                   const struct block *block)
749 {
750   struct type *type, *rtype = NULL;
751   char *type_name = NULL;
752   enum demangle_component_type demangled_type;
753   volatile struct gdb_exception except;
754
755   /* Save the type: typy_lookup_type() may (indirectly) overwrite
756      memory pointed by demangled.  */
757   demangled_type = demangled->type;
758
759   if (demangled_type == DEMANGLE_COMPONENT_POINTER
760       || demangled_type == DEMANGLE_COMPONENT_REFERENCE
761       || demangled_type == DEMANGLE_COMPONENT_CONST
762       || demangled_type == DEMANGLE_COMPONENT_VOLATILE)
763     {
764       type = typy_lookup_type (demangled->u.s_binary.left, block);
765       if (! type)
766         return NULL;
767
768       TRY_CATCH (except, RETURN_MASK_ALL)
769         {
770           /* If the demangled_type matches with one of the types
771              below, run the corresponding function and save the type
772              to return later.  We cannot just return here as we are in
773              an exception handler.  */
774           switch (demangled_type)
775             {
776             case DEMANGLE_COMPONENT_REFERENCE:
777               rtype =  lookup_reference_type (type);
778               break;
779             case DEMANGLE_COMPONENT_POINTER:
780               rtype = lookup_pointer_type (type);
781               break;
782             case DEMANGLE_COMPONENT_CONST:
783               rtype = make_cv_type (1, 0, type, NULL);
784               break;
785             case DEMANGLE_COMPONENT_VOLATILE:
786               rtype = make_cv_type (0, 1, type, NULL);
787               break;
788             }
789         }
790       GDB_PY_HANDLE_EXCEPTION (except);
791     }
792
793   /* If we have a type from the switch statement above, just return
794      that.  */
795   if (rtype)
796     return rtype;
797
798   /* We don't have a type, so lookup the type.  */
799   type_name = cp_comp_to_string (demangled, 10);
800   type = typy_lookup_typename (type_name, block);
801   xfree (type_name);
802
803   return type;
804 }
805
806 /* This is a helper function for typy_template_argument that is used
807    when the type does not have template symbols attached.  It works by
808    parsing the type name.  This happens with compilers, like older
809    versions of GCC, that do not emit DW_TAG_template_*.  */
810
811 static PyObject *
812 typy_legacy_template_argument (struct type *type, const struct block *block,
813                                int argno)
814 {
815   int i;
816   struct demangle_component *demangled;
817   struct demangle_parse_info *info = NULL;
818   const char *err;
819   struct type *argtype;
820   struct cleanup *cleanup;
821   volatile struct gdb_exception except;
822
823   if (TYPE_NAME (type) == NULL)
824     {
825       PyErr_SetString (PyExc_RuntimeError, _("Null type name."));
826       return NULL;
827     }
828
829   TRY_CATCH (except, RETURN_MASK_ALL)
830     {
831       /* Note -- this is not thread-safe.  */
832       info = cp_demangled_name_to_comp (TYPE_NAME (type), &err);
833     }
834   GDB_PY_HANDLE_EXCEPTION (except);
835
836   if (! info)
837     {
838       PyErr_SetString (PyExc_RuntimeError, err);
839       return NULL;
840     }
841   demangled = info->tree;
842   cleanup = make_cleanup_cp_demangled_name_parse_free (info);
843
844   /* Strip off component names.  */
845   while (demangled->type == DEMANGLE_COMPONENT_QUAL_NAME
846          || demangled->type == DEMANGLE_COMPONENT_LOCAL_NAME)
847     demangled = demangled->u.s_binary.right;
848
849   if (demangled->type != DEMANGLE_COMPONENT_TEMPLATE)
850     {
851       do_cleanups (cleanup);
852       PyErr_SetString (PyExc_RuntimeError, _("Type is not a template."));
853       return NULL;
854     }
855
856   /* Skip from the template to the arguments.  */
857   demangled = demangled->u.s_binary.right;
858
859   for (i = 0; demangled && i < argno; ++i)
860     demangled = demangled->u.s_binary.right;
861
862   if (! demangled)
863     {
864       do_cleanups (cleanup);
865       PyErr_Format (PyExc_RuntimeError, _("No argument %d in template."),
866                     argno);
867       return NULL;
868     }
869
870   argtype = typy_lookup_type (demangled->u.s_binary.left, block);
871   do_cleanups (cleanup);
872   if (! argtype)
873     return NULL;
874
875   return type_to_type_object (argtype);
876 }
877
878 static PyObject *
879 typy_template_argument (PyObject *self, PyObject *args)
880 {
881   int argno;
882   struct type *type = ((type_object *) self)->type;
883   const struct block *block = NULL;
884   PyObject *block_obj = NULL;
885   struct symbol *sym;
886   struct value *val = NULL;
887   volatile struct gdb_exception except;
888
889   if (! PyArg_ParseTuple (args, "i|O", &argno, &block_obj))
890     return NULL;
891
892   if (block_obj)
893     {
894       block = block_object_to_block (block_obj);
895       if (! block)
896         {
897           PyErr_SetString (PyExc_RuntimeError,
898                            _("Second argument must be block."));
899           return NULL;
900         }
901     }
902
903   TRY_CATCH (except, RETURN_MASK_ALL)
904     {
905       type = check_typedef (type);
906       if (TYPE_CODE (type) == TYPE_CODE_REF)
907         type = check_typedef (TYPE_TARGET_TYPE (type));
908     }
909   GDB_PY_HANDLE_EXCEPTION (except);
910
911   /* We might not have DW_TAG_template_*, so try to parse the type's
912      name.  This is inefficient if we do not have a template type --
913      but that is going to wind up as an error anyhow.  */
914   if (! TYPE_N_TEMPLATE_ARGUMENTS (type))
915     return typy_legacy_template_argument (type, block, argno);
916
917   if (argno >= TYPE_N_TEMPLATE_ARGUMENTS (type))
918     {
919       PyErr_Format (PyExc_RuntimeError, _("No argument %d in template."),
920                     argno);
921       return NULL;
922     }
923
924   sym = TYPE_TEMPLATE_ARGUMENT (type, argno);
925   if (SYMBOL_CLASS (sym) == LOC_TYPEDEF)
926     return type_to_type_object (SYMBOL_TYPE (sym));
927   else if (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT)
928     {
929       PyErr_Format (PyExc_RuntimeError,
930                     _("Template argument is optimized out"));
931       return NULL;
932     }
933
934   TRY_CATCH (except, RETURN_MASK_ALL)
935     {
936       val = value_of_variable (sym, block);
937     }
938   GDB_PY_HANDLE_EXCEPTION (except);
939
940   return value_to_value_object (val);
941 }
942
943 static PyObject *
944 typy_str (PyObject *self)
945 {
946   volatile struct gdb_exception except;
947   char *thetype = NULL;
948   long length = 0;
949   PyObject *result;
950
951   TRY_CATCH (except, RETURN_MASK_ALL)
952     {
953       struct cleanup *old_chain;
954       struct ui_file *stb;
955
956       stb = mem_fileopen ();
957       old_chain = make_cleanup_ui_file_delete (stb);
958
959       LA_PRINT_TYPE (type_object_to_type (self), "", stb, -1, 0,
960                      &type_print_raw_options);
961
962       thetype = ui_file_xstrdup (stb, &length);
963       do_cleanups (old_chain);
964     }
965   if (except.reason < 0)
966     {
967       xfree (thetype);
968       GDB_PY_HANDLE_EXCEPTION (except);
969     }
970
971   result = PyUnicode_Decode (thetype, length, host_charset (), NULL);
972   xfree (thetype);
973
974   return result;
975 }
976
977 /* Implement the richcompare method.  */
978
979 static PyObject *
980 typy_richcompare (PyObject *self, PyObject *other, int op)
981 {
982   int result = Py_NE;
983   struct type *type1 = type_object_to_type (self);
984   struct type *type2 = type_object_to_type (other);
985   volatile struct gdb_exception except;
986
987   /* We can only compare ourselves to another Type object, and only
988      for equality or inequality.  */
989   if (type2 == NULL || (op != Py_EQ && op != Py_NE))
990     {
991       Py_INCREF (Py_NotImplemented);
992       return Py_NotImplemented;
993     }
994
995   if (type1 == type2)
996     result = Py_EQ;
997   else
998     {
999       TRY_CATCH (except, RETURN_MASK_ALL)
1000         {
1001           result = types_deeply_equal (type1, type2);
1002         }
1003       /* If there is a GDB exception, a comparison is not capable
1004          (or trusted), so exit.  */
1005       GDB_PY_HANDLE_EXCEPTION (except);
1006     }
1007
1008   if (op == (result ? Py_EQ : Py_NE))
1009     Py_RETURN_TRUE;
1010   Py_RETURN_FALSE;
1011 }
1012
1013 \f
1014
1015 static const struct objfile_data *typy_objfile_data_key;
1016
1017 static void
1018 save_objfile_types (struct objfile *objfile, void *datum)
1019 {
1020   type_object *obj = datum;
1021   htab_t copied_types;
1022   struct cleanup *cleanup;
1023
1024   if (!gdb_python_initialized)
1025     return;
1026
1027   /* This prevents another thread from freeing the objects we're
1028      operating on.  */
1029   cleanup = ensure_python_env (get_objfile_arch (objfile), current_language);
1030
1031   copied_types = create_copied_types_hash (objfile);
1032
1033   while (obj)
1034     {
1035       type_object *next = obj->next;
1036
1037       htab_empty (copied_types);
1038
1039       obj->type = copy_type_recursive (objfile, obj->type, copied_types);
1040
1041       obj->next = NULL;
1042       obj->prev = NULL;
1043
1044       obj = next;
1045     }
1046
1047   htab_delete (copied_types);
1048
1049   do_cleanups (cleanup);
1050 }
1051
1052 static void
1053 set_type (type_object *obj, struct type *type)
1054 {
1055   obj->type = type;
1056   obj->prev = NULL;
1057   if (type && TYPE_OBJFILE (type))
1058     {
1059       struct objfile *objfile = TYPE_OBJFILE (type);
1060
1061       obj->next = objfile_data (objfile, typy_objfile_data_key);
1062       if (obj->next)
1063         obj->next->prev = obj;
1064       set_objfile_data (objfile, typy_objfile_data_key, obj);
1065     }
1066   else
1067     obj->next = NULL;
1068 }
1069
1070 static void
1071 typy_dealloc (PyObject *obj)
1072 {
1073   type_object *type = (type_object *) obj;
1074
1075   if (type->prev)
1076     type->prev->next = type->next;
1077   else if (type->type && TYPE_OBJFILE (type->type))
1078     {
1079       /* Must reset head of list.  */
1080       struct objfile *objfile = TYPE_OBJFILE (type->type);
1081
1082       if (objfile)
1083         set_objfile_data (objfile, typy_objfile_data_key, type->next);
1084     }
1085   if (type->next)
1086     type->next->prev = type->prev;
1087
1088   Py_TYPE (type)->tp_free (type);
1089 }
1090
1091 /* Return number of fields ("length" of the field dictionary).  */
1092
1093 static Py_ssize_t
1094 typy_length (PyObject *self)
1095 {
1096   struct type *type = ((type_object *) self)->type;
1097
1098   type = typy_get_composite (type);
1099   if (type == NULL)
1100     return -1;
1101
1102   return TYPE_NFIELDS (type);
1103 }
1104
1105 /* Implements boolean evaluation of gdb.Type.  Handle this like other
1106    Python objects that don't have a meaningful truth value -- all
1107    values are true.  */
1108
1109 static int
1110 typy_nonzero (PyObject *self)
1111 {
1112   return 1;
1113 }
1114
1115 /* Return a gdb.Field object for the field named by the argument.  */
1116
1117 static PyObject *
1118 typy_getitem (PyObject *self, PyObject *key)
1119 {
1120   struct type *type = ((type_object *) self)->type;
1121   char *field;
1122   int i;
1123
1124   field = python_string_to_host_string (key);
1125   if (field == NULL)
1126     return NULL;
1127
1128   /* We want just fields of this type, not of base types, so instead of
1129      using lookup_struct_elt_type, portions of that function are
1130      copied here.  */
1131
1132   type = typy_get_composite (type);
1133   if (type == NULL)
1134     return NULL;
1135
1136   for (i = 0; i < TYPE_NFIELDS (type); i++)
1137     {
1138       const char *t_field_name = TYPE_FIELD_NAME (type, i);
1139
1140       if (t_field_name && (strcmp_iw (t_field_name, field) == 0))
1141         {
1142           return convert_field (type, i);
1143         }
1144     }
1145   PyErr_SetObject (PyExc_KeyError, key);
1146   return NULL;
1147 }
1148
1149 /* Implement the "get" method on the type object.  This is the
1150    same as getitem if the key is present, but returns the supplied
1151    default value or None if the key is not found.  */
1152
1153 static PyObject *
1154 typy_get (PyObject *self, PyObject *args)
1155 {
1156   PyObject *key, *defval = Py_None, *result;
1157
1158   if (!PyArg_UnpackTuple (args, "get", 1, 2, &key, &defval))
1159     return NULL;
1160
1161   result = typy_getitem (self, key);
1162   if (result != NULL)
1163     return result;
1164
1165   /* typy_getitem returned error status.  If the exception is
1166      KeyError, clear the exception status and return the defval
1167      instead.  Otherwise return the exception unchanged.  */
1168   if (!PyErr_ExceptionMatches (PyExc_KeyError))
1169     return NULL;
1170
1171   PyErr_Clear ();
1172   Py_INCREF (defval);
1173   return defval;
1174 }
1175
1176 /* Implement the "has_key" method on the type object.  */
1177
1178 static PyObject *
1179 typy_has_key (PyObject *self, PyObject *args)
1180 {
1181   struct type *type = ((type_object *) self)->type;
1182   const char *field;
1183   int i;
1184
1185   if (!PyArg_ParseTuple (args, "s", &field))
1186     return NULL;
1187
1188   /* We want just fields of this type, not of base types, so instead of
1189      using lookup_struct_elt_type, portions of that function are
1190      copied here.  */
1191
1192   type = typy_get_composite (type);
1193   if (type == NULL)
1194     return NULL;
1195
1196   for (i = 0; i < TYPE_NFIELDS (type); i++)
1197     {
1198       const char *t_field_name = TYPE_FIELD_NAME (type, i);
1199
1200       if (t_field_name && (strcmp_iw (t_field_name, field) == 0))
1201         Py_RETURN_TRUE;
1202     }
1203   Py_RETURN_FALSE;
1204 }
1205
1206 /* Make an iterator object to iterate over keys, values, or items.  */
1207
1208 static PyObject *
1209 typy_make_iter (PyObject *self, enum gdbpy_iter_kind kind)
1210 {
1211   typy_iterator_object *typy_iter_obj;
1212
1213   /* Check that "self" is a structure or union type.  */
1214   if (typy_get_composite (((type_object *) self)->type) == NULL)
1215     return NULL;
1216
1217   typy_iter_obj = PyObject_New (typy_iterator_object,
1218                                 &type_iterator_object_type);
1219   if (typy_iter_obj == NULL)
1220       return NULL;
1221
1222   typy_iter_obj->field = 0;
1223   typy_iter_obj->kind = kind;
1224   Py_INCREF (self);
1225   typy_iter_obj->source = (type_object *) self;
1226
1227   return (PyObject *) typy_iter_obj;
1228 }
1229
1230 /* iteritems() method.  */
1231
1232 static PyObject *
1233 typy_iteritems (PyObject *self, PyObject *args)
1234 {
1235   return typy_make_iter (self, iter_items);
1236 }
1237
1238 /* iterkeys() method.  */
1239
1240 static PyObject *
1241 typy_iterkeys (PyObject *self, PyObject *args)
1242 {
1243   return typy_make_iter (self, iter_keys);
1244 }
1245
1246 /* Iterating over the class, same as iterkeys except for the function
1247    signature.  */
1248
1249 static PyObject *
1250 typy_iter (PyObject *self)
1251 {
1252   return typy_make_iter (self, iter_keys);
1253 }
1254
1255 /* itervalues() method.  */
1256
1257 static PyObject *
1258 typy_itervalues (PyObject *self, PyObject *args)
1259 {
1260   return typy_make_iter (self, iter_values);
1261 }
1262
1263 /* Return a reference to the type iterator.  */
1264
1265 static PyObject *
1266 typy_iterator_iter (PyObject *self)
1267 {
1268   Py_INCREF (self);
1269   return self;
1270 }
1271
1272 /* Return the next field in the iteration through the list of fields
1273    of the type.  */
1274
1275 static PyObject *
1276 typy_iterator_iternext (PyObject *self)
1277 {
1278   typy_iterator_object *iter_obj = (typy_iterator_object *) self;
1279   struct type *type = iter_obj->source->type;
1280   PyObject *result;
1281
1282   if (iter_obj->field < TYPE_NFIELDS (type))
1283     {
1284       result = make_fielditem (type, iter_obj->field, iter_obj->kind);
1285       if (result != NULL)
1286         iter_obj->field++;
1287       return result;
1288     }
1289
1290   return NULL;
1291 }
1292
1293 static void
1294 typy_iterator_dealloc (PyObject *obj)
1295 {
1296   typy_iterator_object *iter_obj = (typy_iterator_object *) obj;
1297
1298   Py_DECREF (iter_obj->source);
1299 }
1300
1301 /* Create a new Type referring to TYPE.  */
1302 PyObject *
1303 type_to_type_object (struct type *type)
1304 {
1305   type_object *type_obj;
1306
1307   type_obj = PyObject_New (type_object, &type_object_type);
1308   if (type_obj)
1309     set_type (type_obj, type);
1310
1311   return (PyObject *) type_obj;
1312 }
1313
1314 struct type *
1315 type_object_to_type (PyObject *obj)
1316 {
1317   if (! PyObject_TypeCheck (obj, &type_object_type))
1318     return NULL;
1319   return ((type_object *) obj)->type;
1320 }
1321
1322 \f
1323
1324 /* Implementation of gdb.lookup_type.  */
1325 PyObject *
1326 gdbpy_lookup_type (PyObject *self, PyObject *args, PyObject *kw)
1327 {
1328   static char *keywords[] = { "name", "block", NULL };
1329   const char *type_name = NULL;
1330   struct type *type = NULL;
1331   PyObject *block_obj = NULL;
1332   const struct block *block = NULL;
1333
1334   if (! PyArg_ParseTupleAndKeywords (args, kw, "s|O", keywords,
1335                                      &type_name, &block_obj))
1336     return NULL;
1337
1338   if (block_obj)
1339     {
1340       block = block_object_to_block (block_obj);
1341       if (! block)
1342         {
1343           PyErr_SetString (PyExc_RuntimeError,
1344                            _("'block' argument must be a Block."));
1345           return NULL;
1346         }
1347     }
1348
1349   type = typy_lookup_typename (type_name, block);
1350   if (! type)
1351     return NULL;
1352
1353   return (PyObject *) type_to_type_object (type);
1354 }
1355
1356 int
1357 gdbpy_initialize_types (void)
1358 {
1359   int i;
1360
1361   typy_objfile_data_key
1362     = register_objfile_data_with_cleanup (save_objfile_types, NULL);
1363
1364   if (PyType_Ready (&type_object_type) < 0)
1365     return -1;
1366   if (PyType_Ready (&field_object_type) < 0)
1367     return -1;
1368   if (PyType_Ready (&type_iterator_object_type) < 0)
1369     return -1;
1370
1371   for (i = 0; pyty_codes[i].name; ++i)
1372     {
1373       if (PyModule_AddIntConstant (gdb_module,
1374                                    /* Cast needed for Python 2.4.  */
1375                                    (char *) pyty_codes[i].name,
1376                                    pyty_codes[i].code) < 0)
1377         return -1;
1378     }
1379
1380   if (gdb_pymodule_addobject (gdb_module, "Type",
1381                               (PyObject *) &type_object_type) < 0)
1382     return -1;
1383
1384   if (gdb_pymodule_addobject (gdb_module, "TypeIterator",
1385                               (PyObject *) &type_iterator_object_type) < 0)
1386     return -1;
1387
1388   return gdb_pymodule_addobject (gdb_module, "Field",
1389                                  (PyObject *) &field_object_type);
1390 }
1391
1392 \f
1393
1394 static PyGetSetDef type_object_getset[] =
1395 {
1396   { "code", typy_get_code, NULL,
1397     "The code for this type.", NULL },
1398   { "sizeof", typy_get_sizeof, NULL,
1399     "The size of this type, in bytes.", NULL },
1400   { "tag", typy_get_tag, NULL,
1401     "The tag name for this type, or None.", NULL },
1402   { NULL }
1403 };
1404
1405 static PyMethodDef type_object_methods[] =
1406 {
1407   { "array", typy_array, METH_VARARGS,
1408     "array ([LOW_BOUND,] HIGH_BOUND) -> Type\n\
1409 Return a type which represents an array of objects of this type.\n\
1410 The bounds of the array are [LOW_BOUND, HIGH_BOUND] inclusive.\n\
1411 If LOW_BOUND is omitted, a value of zero is used." },
1412   { "vector", typy_vector, METH_VARARGS,
1413     "vector ([LOW_BOUND,] HIGH_BOUND) -> Type\n\
1414 Return a type which represents a vector of objects of this type.\n\
1415 The bounds of the array are [LOW_BOUND, HIGH_BOUND] inclusive.\n\
1416 If LOW_BOUND is omitted, a value of zero is used.\n\
1417 Vectors differ from arrays in that if the current language has C-style\n\
1418 arrays, vectors don't decay to a pointer to the first element.\n\
1419 They are first class values." },
1420    { "__contains__", typy_has_key, METH_VARARGS,
1421      "T.__contains__(k) -> True if T has a field named k, else False" },
1422   { "const", typy_const, METH_NOARGS,
1423     "const () -> Type\n\
1424 Return a const variant of this type." },
1425   { "fields", typy_fields, METH_NOARGS,
1426     "fields () -> list\n\
1427 Return a list holding all the fields of this type.\n\
1428 Each field is a gdb.Field object." },
1429   { "get", typy_get, METH_VARARGS,
1430     "T.get(k[,default]) -> returns field named k in T, if it exists;\n\
1431 otherwise returns default, if supplied, or None if not." },
1432   { "has_key", typy_has_key, METH_VARARGS,
1433     "T.has_key(k) -> True if T has a field named k, else False" },
1434   { "items", typy_items, METH_NOARGS,
1435     "items () -> list\n\
1436 Return a list of (name, field) pairs of this type.\n\
1437 Each field is a gdb.Field object." },
1438   { "iteritems", typy_iteritems, METH_NOARGS,
1439     "iteritems () -> an iterator over the (name, field)\n\
1440 pairs of this type.  Each field is a gdb.Field object." },
1441   { "iterkeys", typy_iterkeys, METH_NOARGS,
1442     "iterkeys () -> an iterator over the field names of this type." },
1443   { "itervalues", typy_itervalues, METH_NOARGS,
1444     "itervalues () -> an iterator over the fields of this type.\n\
1445 Each field is a gdb.Field object." },
1446   { "keys", typy_field_names, METH_NOARGS,
1447     "keys () -> list\n\
1448 Return a list holding all the fields names of this type." },
1449   { "pointer", typy_pointer, METH_NOARGS,
1450     "pointer () -> Type\n\
1451 Return a type of pointer to this type." },
1452   { "range", typy_range, METH_NOARGS,
1453     "range () -> tuple\n\
1454 Return a tuple containing the lower and upper range for this type."},
1455   { "reference", typy_reference, METH_NOARGS,
1456     "reference () -> Type\n\
1457 Return a type of reference to this type." },
1458   { "strip_typedefs", typy_strip_typedefs, METH_NOARGS,
1459     "strip_typedefs () -> Type\n\
1460 Return a type formed by stripping this type of all typedefs."},
1461   { "target", typy_target, METH_NOARGS,
1462     "target () -> Type\n\
1463 Return the target type of this type." },
1464   { "template_argument", typy_template_argument, METH_VARARGS,
1465     "template_argument (arg, [block]) -> Type\n\
1466 Return the type of a template argument." },
1467   { "unqualified", typy_unqualified, METH_NOARGS,
1468     "unqualified () -> Type\n\
1469 Return a variant of this type without const or volatile attributes." },
1470   { "values", typy_values, METH_NOARGS,
1471     "values () -> list\n\
1472 Return a list holding all the fields of this type.\n\
1473 Each field is a gdb.Field object." },
1474   { "volatile", typy_volatile, METH_NOARGS,
1475     "volatile () -> Type\n\
1476 Return a volatile variant of this type" },
1477   { NULL }
1478 };
1479
1480 static PyNumberMethods type_object_as_number = {
1481   NULL,                       /* nb_add */
1482   NULL,                       /* nb_subtract */
1483   NULL,                       /* nb_multiply */
1484 #ifndef IS_PY3K
1485   NULL,                       /* nb_divide */
1486 #endif
1487   NULL,                       /* nb_remainder */
1488   NULL,                       /* nb_divmod */
1489   NULL,                       /* nb_power */
1490   NULL,                       /* nb_negative */
1491   NULL,                       /* nb_positive */
1492   NULL,                       /* nb_absolute */
1493   typy_nonzero,               /* nb_nonzero */
1494   NULL,                       /* nb_invert */
1495   NULL,                       /* nb_lshift */
1496   NULL,                       /* nb_rshift */
1497   NULL,                       /* nb_and */
1498   NULL,                       /* nb_xor */
1499   NULL,                       /* nb_or */
1500 #ifdef IS_PY3K
1501   NULL,                       /* nb_int */
1502   NULL,                       /* reserved */
1503 #else
1504   NULL,                       /* nb_coerce */
1505   NULL,                       /* nb_int */
1506   NULL,                       /* nb_long */
1507 #endif
1508   NULL,                       /* nb_float */
1509 #ifndef IS_PY3K
1510   NULL,                       /* nb_oct */
1511   NULL                        /* nb_hex */
1512 #endif
1513 };
1514
1515 static PyMappingMethods typy_mapping = {
1516   typy_length,
1517   typy_getitem,
1518   NULL                            /* no "set" method */
1519 };
1520
1521 static PyTypeObject type_object_type =
1522 {
1523   PyVarObject_HEAD_INIT (NULL, 0)
1524   "gdb.Type",                     /*tp_name*/
1525   sizeof (type_object),           /*tp_basicsize*/
1526   0,                              /*tp_itemsize*/
1527   typy_dealloc,                   /*tp_dealloc*/
1528   0,                              /*tp_print*/
1529   0,                              /*tp_getattr*/
1530   0,                              /*tp_setattr*/
1531   0,                              /*tp_compare*/
1532   0,                              /*tp_repr*/
1533   &type_object_as_number,         /*tp_as_number*/
1534   0,                              /*tp_as_sequence*/
1535   &typy_mapping,                  /*tp_as_mapping*/
1536   0,                              /*tp_hash */
1537   0,                              /*tp_call*/
1538   typy_str,                       /*tp_str*/
1539   0,                              /*tp_getattro*/
1540   0,                              /*tp_setattro*/
1541   0,                              /*tp_as_buffer*/
1542   Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER,  /*tp_flags*/
1543   "GDB type object",              /* tp_doc */
1544   0,                              /* tp_traverse */
1545   0,                              /* tp_clear */
1546   typy_richcompare,               /* tp_richcompare */
1547   0,                              /* tp_weaklistoffset */
1548   typy_iter,                      /* tp_iter */
1549   0,                              /* tp_iternext */
1550   type_object_methods,            /* tp_methods */
1551   0,                              /* tp_members */
1552   type_object_getset,             /* tp_getset */
1553   0,                              /* tp_base */
1554   0,                              /* tp_dict */
1555   0,                              /* tp_descr_get */
1556   0,                              /* tp_descr_set */
1557   0,                              /* tp_dictoffset */
1558   0,                              /* tp_init */
1559   0,                              /* tp_alloc */
1560   0,                              /* tp_new */
1561 };
1562
1563 static PyGetSetDef field_object_getset[] =
1564 {
1565   { "__dict__", gdb_py_generic_dict, NULL,
1566     "The __dict__ for this field.", &field_object_type },
1567   { NULL }
1568 };
1569
1570 static PyTypeObject field_object_type =
1571 {
1572   PyVarObject_HEAD_INIT (NULL, 0)
1573   "gdb.Field",                    /*tp_name*/
1574   sizeof (field_object),          /*tp_basicsize*/
1575   0,                              /*tp_itemsize*/
1576   field_dealloc,                  /*tp_dealloc*/
1577   0,                              /*tp_print*/
1578   0,                              /*tp_getattr*/
1579   0,                              /*tp_setattr*/
1580   0,                              /*tp_compare*/
1581   0,                              /*tp_repr*/
1582   0,                              /*tp_as_number*/
1583   0,                              /*tp_as_sequence*/
1584   0,                              /*tp_as_mapping*/
1585   0,                              /*tp_hash */
1586   0,                              /*tp_call*/
1587   0,                              /*tp_str*/
1588   0,                              /*tp_getattro*/
1589   0,                              /*tp_setattro*/
1590   0,                              /*tp_as_buffer*/
1591   Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER,  /*tp_flags*/
1592   "GDB field object",             /* tp_doc */
1593   0,                              /* tp_traverse */
1594   0,                              /* tp_clear */
1595   0,                              /* tp_richcompare */
1596   0,                              /* tp_weaklistoffset */
1597   0,                              /* tp_iter */
1598   0,                              /* tp_iternext */
1599   0,                              /* tp_methods */
1600   0,                              /* tp_members */
1601   field_object_getset,            /* tp_getset */
1602   0,                              /* tp_base */
1603   0,                              /* tp_dict */
1604   0,                              /* tp_descr_get */
1605   0,                              /* tp_descr_set */
1606   offsetof (field_object, dict),  /* tp_dictoffset */
1607   0,                              /* tp_init */
1608   0,                              /* tp_alloc */
1609   0,                              /* tp_new */
1610 };
1611
1612 static PyTypeObject type_iterator_object_type = {
1613   PyVarObject_HEAD_INIT (NULL, 0)
1614   "gdb.TypeIterator",             /*tp_name*/
1615   sizeof (typy_iterator_object),  /*tp_basicsize*/
1616   0,                              /*tp_itemsize*/
1617   typy_iterator_dealloc,          /*tp_dealloc*/
1618   0,                              /*tp_print*/
1619   0,                              /*tp_getattr*/
1620   0,                              /*tp_setattr*/
1621   0,                              /*tp_compare*/
1622   0,                              /*tp_repr*/
1623   0,                              /*tp_as_number*/
1624   0,                              /*tp_as_sequence*/
1625   0,                              /*tp_as_mapping*/
1626   0,                              /*tp_hash */
1627   0,                              /*tp_call*/
1628   0,                              /*tp_str*/
1629   0,                              /*tp_getattro*/
1630   0,                              /*tp_setattro*/
1631   0,                              /*tp_as_buffer*/
1632   Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER,  /*tp_flags*/
1633   "GDB type iterator object",     /*tp_doc */
1634   0,                              /*tp_traverse */
1635   0,                              /*tp_clear */
1636   0,                              /*tp_richcompare */
1637   0,                              /*tp_weaklistoffset */
1638   typy_iterator_iter,             /*tp_iter */
1639   typy_iterator_iternext,         /*tp_iternext */
1640   0                               /*tp_methods */
1641 };
This page took 0.108341 seconds and 2 git commands to generate.