1 /* Support routines for manipulating internal types for GDB.
2 Copyright (C) 1992, 93, 94, 95, 96, 1998 Free Software Foundation, Inc.
3 Contributed by Cygnus Support, using pieces from other GDB modules.
5 This file is part of GDB.
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 2 of the License, or
10 (at your option) any later version.
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.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 #include "gdb_string.h"
29 #include "expression.h"
34 #include "complaints.h"
37 /* These variables point to the objects
38 representing the predefined C data types. */
40 struct type
*builtin_type_void
;
41 struct type
*builtin_type_char
;
42 struct type
*builtin_type_true_char
;
43 struct type
*builtin_type_short
;
44 struct type
*builtin_type_int
;
45 struct type
*builtin_type_long
;
46 struct type
*builtin_type_long_long
;
47 struct type
*builtin_type_signed_char
;
48 struct type
*builtin_type_unsigned_char
;
49 struct type
*builtin_type_unsigned_short
;
50 struct type
*builtin_type_unsigned_int
;
51 struct type
*builtin_type_unsigned_long
;
52 struct type
*builtin_type_unsigned_long_long
;
53 struct type
*builtin_type_float
;
54 struct type
*builtin_type_double
;
55 struct type
*builtin_type_long_double
;
56 struct type
*builtin_type_complex
;
57 struct type
*builtin_type_double_complex
;
58 struct type
*builtin_type_string
;
59 struct type
*builtin_type_int8
;
60 struct type
*builtin_type_uint8
;
61 struct type
*builtin_type_int16
;
62 struct type
*builtin_type_uint16
;
63 struct type
*builtin_type_int32
;
64 struct type
*builtin_type_uint32
;
65 struct type
*builtin_type_int64
;
66 struct type
*builtin_type_uint64
;
67 struct type
*builtin_type_bool
;
68 struct type
*builtin_type_v4sf
;
70 int opaque_type_resolution
= 1;
77 }; /* maximum extention is 128! FIXME */
79 static void add_name
PARAMS ((struct extra
*, char *));
80 static void add_mangled_type
PARAMS ((struct extra
*, struct type
*));
82 static void cfront_mangle_name
PARAMS ((struct type
*, int, int));
84 static void print_bit_vector
PARAMS ((B_TYPE
*, int));
85 static void print_arg_types
PARAMS ((struct type
**, int));
86 static void dump_fn_fieldlists
PARAMS ((struct type
*, int));
87 static void print_cplus_stuff
PARAMS ((struct type
*, int));
88 static void virtual_base_list_aux
PARAMS ((struct type
* dclass
));
91 /* Alloc a new type structure and fill it with some defaults. If
92 OBJFILE is non-NULL, then allocate the space for the type structure
93 in that objfile's type_obstack. */
97 struct objfile
*objfile
;
99 register struct type
*type
;
101 /* Alloc the structure and start off with all fields zeroed. */
105 type
= (struct type
*) xmalloc (sizeof (struct type
));
109 type
= (struct type
*) obstack_alloc (&objfile
->type_obstack
,
110 sizeof (struct type
));
111 OBJSTAT (objfile
, n_types
++);
113 memset ((char *) type
, 0, sizeof (struct type
));
115 /* Initialize the fields that might not be zero. */
117 TYPE_CODE (type
) = TYPE_CODE_UNDEF
;
118 TYPE_OBJFILE (type
) = objfile
;
119 TYPE_VPTR_FIELDNO (type
) = -1;
120 TYPE_CV_TYPE (type
) = type
; /* chain back to itself */
125 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
126 to a pointer to memory where the pointer type should be stored.
127 If *TYPEPTR is zero, update it to point to the pointer type we return.
128 We allocate new memory if needed. */
131 make_pointer_type (type
, typeptr
)
133 struct type
**typeptr
;
135 register struct type
*ntype
; /* New type */
136 struct objfile
*objfile
;
138 ntype
= TYPE_POINTER_TYPE (type
);
143 return ntype
; /* Don't care about alloc, and have new type. */
144 else if (*typeptr
== 0)
146 *typeptr
= ntype
; /* Tracking alloc, and we have new type. */
151 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
153 ntype
= alloc_type (TYPE_OBJFILE (type
));
158 /* We have storage, but need to reset it. */
161 objfile
= TYPE_OBJFILE (ntype
);
162 memset ((char *) ntype
, 0, sizeof (struct type
));
163 TYPE_OBJFILE (ntype
) = objfile
;
166 TYPE_TARGET_TYPE (ntype
) = type
;
167 TYPE_POINTER_TYPE (type
) = ntype
;
169 /* FIXME! Assume the machine has only one representation for pointers! */
171 TYPE_LENGTH (ntype
) = TARGET_PTR_BIT
/ TARGET_CHAR_BIT
;
172 TYPE_CODE (ntype
) = TYPE_CODE_PTR
;
174 /* pointers are unsigned */
175 TYPE_FLAGS (ntype
) |= TYPE_FLAG_UNSIGNED
;
177 if (!TYPE_POINTER_TYPE (type
)) /* Remember it, if don't have one. */
178 TYPE_POINTER_TYPE (type
) = ntype
;
183 /* Given a type TYPE, return a type of pointers to that type.
184 May need to construct such a type if this is the first use. */
187 lookup_pointer_type (type
)
190 return make_pointer_type (type
, (struct type
**) 0);
193 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero, points
194 to a pointer to memory where the reference type should be stored.
195 If *TYPEPTR is zero, update it to point to the reference type we return.
196 We allocate new memory if needed. */
199 make_reference_type (type
, typeptr
)
201 struct type
**typeptr
;
203 register struct type
*ntype
; /* New type */
204 struct objfile
*objfile
;
206 ntype
= TYPE_REFERENCE_TYPE (type
);
211 return ntype
; /* Don't care about alloc, and have new type. */
212 else if (*typeptr
== 0)
214 *typeptr
= ntype
; /* Tracking alloc, and we have new type. */
219 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
221 ntype
= alloc_type (TYPE_OBJFILE (type
));
226 /* We have storage, but need to reset it. */
229 objfile
= TYPE_OBJFILE (ntype
);
230 memset ((char *) ntype
, 0, sizeof (struct type
));
231 TYPE_OBJFILE (ntype
) = objfile
;
234 TYPE_TARGET_TYPE (ntype
) = type
;
235 TYPE_REFERENCE_TYPE (type
) = ntype
;
237 /* FIXME! Assume the machine has only one representation for references,
238 and that it matches the (only) representation for pointers! */
240 TYPE_LENGTH (ntype
) = TARGET_PTR_BIT
/ TARGET_CHAR_BIT
;
241 TYPE_CODE (ntype
) = TYPE_CODE_REF
;
243 if (!TYPE_REFERENCE_TYPE (type
)) /* Remember it, if don't have one. */
244 TYPE_REFERENCE_TYPE (type
) = ntype
;
249 /* Same as above, but caller doesn't care about memory allocation details. */
252 lookup_reference_type (type
)
255 return make_reference_type (type
, (struct type
**) 0);
258 /* Lookup a function type that returns type TYPE. TYPEPTR, if nonzero, points
259 to a pointer to memory where the function type should be stored.
260 If *TYPEPTR is zero, update it to point to the function type we return.
261 We allocate new memory if needed. */
264 make_function_type (type
, typeptr
)
266 struct type
**typeptr
;
268 register struct type
*ntype
; /* New type */
269 struct objfile
*objfile
;
271 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
273 ntype
= alloc_type (TYPE_OBJFILE (type
));
278 /* We have storage, but need to reset it. */
281 objfile
= TYPE_OBJFILE (ntype
);
282 memset ((char *) ntype
, 0, sizeof (struct type
));
283 TYPE_OBJFILE (ntype
) = objfile
;
286 TYPE_TARGET_TYPE (ntype
) = type
;
288 TYPE_LENGTH (ntype
) = 1;
289 TYPE_CODE (ntype
) = TYPE_CODE_FUNC
;
295 /* Given a type TYPE, return a type of functions that return that type.
296 May need to construct such a type if this is the first use. */
299 lookup_function_type (type
)
302 return make_function_type (type
, (struct type
**) 0);
306 /* Make a "c-v" variant of a type -- a type that is identical to the
307 one supplied except that it may have const or volatile attributes
308 CNST is a flag for setting the const attribute
309 VOLTL is a flag for setting the volatile attribute
310 TYPE is the base type whose variant we are creating.
311 TYPEPTR, if nonzero, points
312 to a pointer to memory where the reference type should be stored.
313 If *TYPEPTR is zero, update it to point to the reference type we return.
314 We allocate new memory if needed. */
317 make_cv_type (cnst
, voltl
, type
, typeptr
)
321 struct type
**typeptr
;
323 register struct type
*ntype
; /* New type */
324 register struct type
*tmp_type
= type
; /* tmp type */
325 struct objfile
*objfile
;
327 ntype
= TYPE_CV_TYPE (type
);
329 while (ntype
!= type
)
331 if ((TYPE_CONST (ntype
) == cnst
) &&
332 (TYPE_VOLATILE (ntype
) == voltl
))
336 else if (*typeptr
== 0)
338 *typeptr
= ntype
; /* Tracking alloc, and we have new type. */
343 ntype
= TYPE_CV_TYPE (ntype
);
346 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
348 ntype
= alloc_type (TYPE_OBJFILE (type
));
353 /* We have storage, but need to reset it. */
356 objfile
= TYPE_OBJFILE (ntype
);
357 /* memset ((char *) ntype, 0, sizeof (struct type)); */
358 TYPE_OBJFILE (ntype
) = objfile
;
361 /* Copy original type */
362 memcpy ((char *) ntype
, (char *) type
, sizeof (struct type
));
363 /* But zero out fields that shouldn't be copied */
364 TYPE_POINTER_TYPE (ntype
) = (struct type
*) 0; /* Need new pointer kind */
365 TYPE_REFERENCE_TYPE (ntype
) = (struct type
*) 0; /* Need new referene kind */
366 /* Note: TYPE_TARGET_TYPE can be left as is */
368 /* Set flags appropriately */
370 TYPE_FLAGS (ntype
) |= TYPE_FLAG_CONST
;
372 TYPE_FLAGS (ntype
) &= ~TYPE_FLAG_CONST
;
375 TYPE_FLAGS (ntype
) |= TYPE_FLAG_VOLATILE
;
377 TYPE_FLAGS (ntype
) &= ~TYPE_FLAG_VOLATILE
;
379 /* Fix the chain of cv variants */
380 TYPE_CV_TYPE (ntype
) = type
;
381 TYPE_CV_TYPE (tmp_type
) = ntype
;
389 /* Implement direct support for MEMBER_TYPE in GNU C++.
390 May need to construct such a type if this is the first use.
391 The TYPE is the type of the member. The DOMAIN is the type
392 of the aggregate that the member belongs to. */
395 lookup_member_type (type
, domain
)
399 register struct type
*mtype
;
401 mtype
= alloc_type (TYPE_OBJFILE (type
));
402 smash_to_member_type (mtype
, domain
, type
);
406 /* Allocate a stub method whose return type is TYPE.
407 This apparently happens for speed of symbol reading, since parsing
408 out the arguments to the method is cpu-intensive, the way we are doing
409 it. So, we will fill in arguments later.
410 This always returns a fresh type. */
413 allocate_stub_method (type
)
418 mtype
= alloc_type (TYPE_OBJFILE (type
));
419 TYPE_TARGET_TYPE (mtype
) = type
;
420 /* _DOMAIN_TYPE (mtype) = unknown yet */
421 /* _ARG_TYPES (mtype) = unknown yet */
422 TYPE_FLAGS (mtype
) = TYPE_FLAG_STUB
;
423 TYPE_CODE (mtype
) = TYPE_CODE_METHOD
;
424 TYPE_LENGTH (mtype
) = 1;
428 /* Create a range type using either a blank type supplied in RESULT_TYPE,
429 or creating a new type, inheriting the objfile from INDEX_TYPE.
431 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND to
432 HIGH_BOUND, inclusive.
434 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
435 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
438 create_range_type (result_type
, index_type
, low_bound
, high_bound
)
439 struct type
*result_type
;
440 struct type
*index_type
;
444 if (result_type
== NULL
)
446 result_type
= alloc_type (TYPE_OBJFILE (index_type
));
448 TYPE_CODE (result_type
) = TYPE_CODE_RANGE
;
449 TYPE_TARGET_TYPE (result_type
) = index_type
;
450 if (TYPE_FLAGS (index_type
) & TYPE_FLAG_STUB
)
451 TYPE_FLAGS (result_type
) |= TYPE_FLAG_TARGET_STUB
;
453 TYPE_LENGTH (result_type
) = TYPE_LENGTH (check_typedef (index_type
));
454 TYPE_NFIELDS (result_type
) = 2;
455 TYPE_FIELDS (result_type
) = (struct field
*)
456 TYPE_ALLOC (result_type
, 2 * sizeof (struct field
));
457 memset (TYPE_FIELDS (result_type
), 0, 2 * sizeof (struct field
));
458 TYPE_FIELD_BITPOS (result_type
, 0) = low_bound
;
459 TYPE_FIELD_BITPOS (result_type
, 1) = high_bound
;
460 TYPE_FIELD_TYPE (result_type
, 0) = builtin_type_int
; /* FIXME */
461 TYPE_FIELD_TYPE (result_type
, 1) = builtin_type_int
; /* FIXME */
464 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
466 return (result_type
);
469 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type TYPE.
470 Return 1 of type is a range type, 0 if it is discrete (and bounds
471 will fit in LONGEST), or -1 otherwise. */
474 get_discrete_bounds (type
, lowp
, highp
)
476 LONGEST
*lowp
, *highp
;
478 CHECK_TYPEDEF (type
);
479 switch (TYPE_CODE (type
))
481 case TYPE_CODE_RANGE
:
482 *lowp
= TYPE_LOW_BOUND (type
);
483 *highp
= TYPE_HIGH_BOUND (type
);
486 if (TYPE_NFIELDS (type
) > 0)
488 /* The enums may not be sorted by value, so search all
492 *lowp
= *highp
= TYPE_FIELD_BITPOS (type
, 0);
493 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
495 if (TYPE_FIELD_BITPOS (type
, i
) < *lowp
)
496 *lowp
= TYPE_FIELD_BITPOS (type
, i
);
497 if (TYPE_FIELD_BITPOS (type
, i
) > *highp
)
498 *highp
= TYPE_FIELD_BITPOS (type
, i
);
501 /* Set unsigned indicator if warranted. */
504 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
518 if (TYPE_LENGTH (type
) > sizeof (LONGEST
)) /* Too big */
520 if (!TYPE_UNSIGNED (type
))
522 *lowp
= -(1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1));
526 /* ... fall through for unsigned ints ... */
529 /* This round-about calculation is to avoid shifting by
530 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
531 if TYPE_LENGTH (type) == sizeof (LONGEST). */
532 *highp
= 1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1);
533 *highp
= (*highp
- 1) | *highp
;
540 /* Create an array type using either a blank type supplied in RESULT_TYPE,
541 or creating a new type, inheriting the objfile from RANGE_TYPE.
543 Elements will be of type ELEMENT_TYPE, the indices will be of type
546 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
547 sure it is TYPE_CODE_UNDEF before we bash it into an array type? */
550 create_array_type (result_type
, element_type
, range_type
)
551 struct type
*result_type
;
552 struct type
*element_type
;
553 struct type
*range_type
;
555 LONGEST low_bound
, high_bound
;
557 if (result_type
== NULL
)
559 result_type
= alloc_type (TYPE_OBJFILE (range_type
));
561 TYPE_CODE (result_type
) = TYPE_CODE_ARRAY
;
562 TYPE_TARGET_TYPE (result_type
) = element_type
;
563 if (get_discrete_bounds (range_type
, &low_bound
, &high_bound
) < 0)
564 low_bound
= high_bound
= 0;
565 CHECK_TYPEDEF (element_type
);
566 TYPE_LENGTH (result_type
) =
567 TYPE_LENGTH (element_type
) * (high_bound
- low_bound
+ 1);
568 TYPE_NFIELDS (result_type
) = 1;
569 TYPE_FIELDS (result_type
) =
570 (struct field
*) TYPE_ALLOC (result_type
, sizeof (struct field
));
571 memset (TYPE_FIELDS (result_type
), 0, sizeof (struct field
));
572 TYPE_FIELD_TYPE (result_type
, 0) = range_type
;
573 TYPE_VPTR_FIELDNO (result_type
) = -1;
575 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
576 if (TYPE_LENGTH (result_type
) == 0)
577 TYPE_FLAGS (result_type
) |= TYPE_FLAG_TARGET_STUB
;
579 return (result_type
);
582 /* Create a string type using either a blank type supplied in RESULT_TYPE,
583 or creating a new type. String types are similar enough to array of
584 char types that we can use create_array_type to build the basic type
585 and then bash it into a string type.
587 For fixed length strings, the range type contains 0 as the lower
588 bound and the length of the string minus one as the upper bound.
590 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
591 sure it is TYPE_CODE_UNDEF before we bash it into a string type? */
594 create_string_type (result_type
, range_type
)
595 struct type
*result_type
;
596 struct type
*range_type
;
598 result_type
= create_array_type (result_type
,
599 *current_language
->string_char_type
,
601 TYPE_CODE (result_type
) = TYPE_CODE_STRING
;
602 return (result_type
);
606 create_set_type (result_type
, domain_type
)
607 struct type
*result_type
;
608 struct type
*domain_type
;
610 LONGEST low_bound
, high_bound
, bit_length
;
611 if (result_type
== NULL
)
613 result_type
= alloc_type (TYPE_OBJFILE (domain_type
));
615 TYPE_CODE (result_type
) = TYPE_CODE_SET
;
616 TYPE_NFIELDS (result_type
) = 1;
617 TYPE_FIELDS (result_type
) = (struct field
*)
618 TYPE_ALLOC (result_type
, 1 * sizeof (struct field
));
619 memset (TYPE_FIELDS (result_type
), 0, sizeof (struct field
));
621 if (!(TYPE_FLAGS (domain_type
) & TYPE_FLAG_STUB
))
623 if (get_discrete_bounds (domain_type
, &low_bound
, &high_bound
) < 0)
624 low_bound
= high_bound
= 0;
625 bit_length
= high_bound
- low_bound
+ 1;
626 TYPE_LENGTH (result_type
)
627 = (bit_length
+ TARGET_CHAR_BIT
- 1) / TARGET_CHAR_BIT
;
629 TYPE_FIELD_TYPE (result_type
, 0) = domain_type
;
632 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
634 return (result_type
);
638 /* Construct and return a type of the form:
639 struct NAME { ELT_TYPE ELT_NAME[N]; }
640 We use these types for SIMD registers. For example, the type of
641 the SSE registers on the late x86-family processors is:
642 struct __builtin_v4sf { float f[4]; }
643 built by the function call:
644 init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4)
645 The type returned is a permanent type, allocated using malloc; it
646 doesn't live in any objfile's obstack. */
648 init_simd_type (char *name
,
649 struct type
*elt_type
,
656 /* Build the field structure. */
657 f
= xmalloc (sizeof (*f
));
658 memset (f
, 0, sizeof (*f
));
660 f
->type
= create_array_type (0, elt_type
,
661 create_range_type (0, builtin_type_int
,
665 /* Build a struct type with that field. */
666 t
= init_type (TYPE_CODE_STRUCT
, n
* TYPE_LENGTH (elt_type
), 0, 0, 0);
675 /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE.
676 A MEMBER is a wierd thing -- it amounts to a typed offset into
677 a struct, e.g. "an int at offset 8". A MEMBER TYPE doesn't
678 include the offset (that's the value of the MEMBER itself), but does
679 include the structure type into which it points (for some reason).
681 When "smashing" the type, we preserve the objfile that the
682 old type pointed to, since we aren't changing where the type is actually
686 smash_to_member_type (type
, domain
, to_type
)
689 struct type
*to_type
;
691 struct objfile
*objfile
;
693 objfile
= TYPE_OBJFILE (type
);
695 memset ((char *) type
, 0, sizeof (struct type
));
696 TYPE_OBJFILE (type
) = objfile
;
697 TYPE_TARGET_TYPE (type
) = to_type
;
698 TYPE_DOMAIN_TYPE (type
) = domain
;
699 TYPE_LENGTH (type
) = 1; /* In practice, this is never needed. */
700 TYPE_CODE (type
) = TYPE_CODE_MEMBER
;
703 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
704 METHOD just means `function that gets an extra "this" argument'.
706 When "smashing" the type, we preserve the objfile that the
707 old type pointed to, since we aren't changing where the type is actually
711 smash_to_method_type (type
, domain
, to_type
, args
)
714 struct type
*to_type
;
717 struct objfile
*objfile
;
719 objfile
= TYPE_OBJFILE (type
);
721 memset ((char *) type
, 0, sizeof (struct type
));
722 TYPE_OBJFILE (type
) = objfile
;
723 TYPE_TARGET_TYPE (type
) = to_type
;
724 TYPE_DOMAIN_TYPE (type
) = domain
;
725 TYPE_ARG_TYPES (type
) = args
;
726 TYPE_LENGTH (type
) = 1; /* In practice, this is never needed. */
727 TYPE_CODE (type
) = TYPE_CODE_METHOD
;
730 /* Return a typename for a struct/union/enum type without "struct ",
731 "union ", or "enum ". If the type has a NULL name, return NULL. */
734 type_name_no_tag (type
)
735 register const struct type
*type
;
737 if (TYPE_TAG_NAME (type
) != NULL
)
738 return TYPE_TAG_NAME (type
);
740 /* Is there code which expects this to return the name if there is no
741 tag name? My guess is that this is mainly used for C++ in cases where
742 the two will always be the same. */
743 return TYPE_NAME (type
);
746 /* Lookup a primitive type named NAME.
747 Return zero if NAME is not a primitive type. */
750 lookup_primitive_typename (name
)
753 struct type
**const *p
;
755 for (p
= current_language
->la_builtin_type_vector
; *p
!= NULL
; p
++)
757 if (STREQ ((**p
)->name
, name
))
765 /* Lookup a typedef or primitive type named NAME,
766 visible in lexical block BLOCK.
767 If NOERR is nonzero, return zero if NAME is not suitably defined. */
770 lookup_typename (name
, block
, noerr
)
775 register struct symbol
*sym
;
776 register struct type
*tmp
;
778 sym
= lookup_symbol (name
, block
, VAR_NAMESPACE
, 0, (struct symtab
**) NULL
);
779 if (sym
== NULL
|| SYMBOL_CLASS (sym
) != LOC_TYPEDEF
)
781 tmp
= lookup_primitive_typename (name
);
786 else if (!tmp
&& noerr
)
792 error ("No type named %s.", name
);
795 return (SYMBOL_TYPE (sym
));
799 lookup_unsigned_typename (name
)
802 char *uns
= alloca (strlen (name
) + 10);
804 strcpy (uns
, "unsigned ");
805 strcpy (uns
+ 9, name
);
806 return (lookup_typename (uns
, (struct block
*) NULL
, 0));
810 lookup_signed_typename (name
)
814 char *uns
= alloca (strlen (name
) + 8);
816 strcpy (uns
, "signed ");
817 strcpy (uns
+ 7, name
);
818 t
= lookup_typename (uns
, (struct block
*) NULL
, 1);
819 /* If we don't find "signed FOO" just try again with plain "FOO". */
822 return lookup_typename (name
, (struct block
*) NULL
, 0);
825 /* Lookup a structure type named "struct NAME",
826 visible in lexical block BLOCK. */
829 lookup_struct (name
, block
)
833 register struct symbol
*sym
;
835 sym
= lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0,
836 (struct symtab
**) NULL
);
840 error ("No struct type named %s.", name
);
842 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
844 error ("This context has class, union or enum %s, not a struct.", name
);
846 return (SYMBOL_TYPE (sym
));
849 /* Lookup a union type named "union NAME",
850 visible in lexical block BLOCK. */
853 lookup_union (name
, block
)
857 register struct symbol
*sym
;
860 sym
= lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0,
861 (struct symtab
**) NULL
);
864 error ("No union type named %s.", name
);
866 t
= SYMBOL_TYPE (sym
);
868 if (TYPE_CODE (t
) == TYPE_CODE_UNION
)
871 /* C++ unions may come out with TYPE_CODE_CLASS, but we look at
872 * a further "declared_type" field to discover it is really a union.
874 if (HAVE_CPLUS_STRUCT (t
))
875 if (TYPE_DECLARED_TYPE (t
) == DECLARED_TYPE_UNION
)
878 /* If we get here, it's not a union */
879 error ("This context has class, struct or enum %s, not a union.", name
);
883 /* Lookup an enum type named "enum NAME",
884 visible in lexical block BLOCK. */
887 lookup_enum (name
, block
)
891 register struct symbol
*sym
;
893 sym
= lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0,
894 (struct symtab
**) NULL
);
897 error ("No enum type named %s.", name
);
899 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_ENUM
)
901 error ("This context has class, struct or union %s, not an enum.", name
);
903 return (SYMBOL_TYPE (sym
));
906 /* Lookup a template type named "template NAME<TYPE>",
907 visible in lexical block BLOCK. */
910 lookup_template_type (name
, type
, block
)
916 char *nam
= (char *) alloca (strlen (name
) + strlen (type
->name
) + 4);
919 strcat (nam
, type
->name
);
920 strcat (nam
, " >"); /* FIXME, extra space still introduced in gcc? */
922 sym
= lookup_symbol (nam
, block
, VAR_NAMESPACE
, 0, (struct symtab
**) NULL
);
926 error ("No template type named %s.", name
);
928 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
930 error ("This context has class, union or enum %s, not a struct.", name
);
932 return (SYMBOL_TYPE (sym
));
935 /* Given a type TYPE, lookup the type of the component of type named NAME.
937 TYPE can be either a struct or union, or a pointer or reference to a struct or
938 union. If it is a pointer or reference, its target type is automatically used.
939 Thus '.' and '->' are interchangable, as specified for the definitions of the
940 expression element types STRUCTOP_STRUCT and STRUCTOP_PTR.
942 If NOERR is nonzero, return zero if NAME is not suitably defined.
943 If NAME is the name of a baseclass type, return that type. */
946 lookup_struct_elt_type (type
, name
, noerr
)
955 CHECK_TYPEDEF (type
);
956 if (TYPE_CODE (type
) != TYPE_CODE_PTR
957 && TYPE_CODE (type
) != TYPE_CODE_REF
)
959 type
= TYPE_TARGET_TYPE (type
);
962 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
&&
963 TYPE_CODE (type
) != TYPE_CODE_UNION
)
965 target_terminal_ours ();
966 gdb_flush (gdb_stdout
);
967 fprintf_unfiltered (gdb_stderr
, "Type ");
968 type_print (type
, "", gdb_stderr
, -1);
969 error (" is not a structure or union type.");
973 /* FIXME: This change put in by Michael seems incorrect for the case where
974 the structure tag name is the same as the member name. I.E. when doing
975 "ptype bell->bar" for "struct foo { int bar; int foo; } bell;"
980 typename
= type_name_no_tag (type
);
981 if (typename
!= NULL
&& STREQ (typename
, name
))
986 for (i
= TYPE_NFIELDS (type
) - 1; i
>= TYPE_N_BASECLASSES (type
); i
--)
988 char *t_field_name
= TYPE_FIELD_NAME (type
, i
);
990 if (t_field_name
&& STREQ (t_field_name
, name
))
992 return TYPE_FIELD_TYPE (type
, i
);
996 /* OK, it's not in this class. Recursively check the baseclasses. */
997 for (i
= TYPE_N_BASECLASSES (type
) - 1; i
>= 0; i
--)
1001 t
= lookup_struct_elt_type (TYPE_BASECLASS (type
, i
), name
, noerr
);
1013 target_terminal_ours ();
1014 gdb_flush (gdb_stdout
);
1015 fprintf_unfiltered (gdb_stderr
, "Type ");
1016 type_print (type
, "", gdb_stderr
, -1);
1017 fprintf_unfiltered (gdb_stderr
, " has no component named ");
1018 fputs_filtered (name
, gdb_stderr
);
1020 return (struct type
*) -1; /* For lint */
1023 /* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE
1024 valid. Callers should be aware that in some cases (for example,
1025 the type or one of its baseclasses is a stub type and we are
1026 debugging a .o file), this function will not be able to find the virtual
1027 function table pointer, and vptr_fieldno will remain -1 and vptr_basetype
1028 will remain NULL. */
1031 fill_in_vptr_fieldno (type
)
1034 CHECK_TYPEDEF (type
);
1036 if (TYPE_VPTR_FIELDNO (type
) < 0)
1040 /* We must start at zero in case the first (and only) baseclass is
1041 virtual (and hence we cannot share the table pointer). */
1042 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
1044 fill_in_vptr_fieldno (TYPE_BASECLASS (type
, i
));
1045 if (TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, i
)) >= 0)
1047 TYPE_VPTR_FIELDNO (type
)
1048 = TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, i
));
1049 TYPE_VPTR_BASETYPE (type
)
1050 = TYPE_VPTR_BASETYPE (TYPE_BASECLASS (type
, i
));
1057 /* Find the method and field indices for the destructor in class type T.
1058 Return 1 if the destructor was found, otherwise, return 0. */
1061 get_destructor_fn_field (t
, method_indexp
, field_indexp
)
1068 for (i
= 0; i
< TYPE_NFN_FIELDS (t
); i
++)
1071 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, i
);
1073 for (j
= 0; j
< TYPE_FN_FIELDLIST_LENGTH (t
, i
); j
++)
1075 if (DESTRUCTOR_PREFIX_P (TYPE_FN_FIELD_PHYSNAME (f
, j
)))
1086 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
1088 If this is a stubbed struct (i.e. declared as struct foo *), see if
1089 we can find a full definition in some other file. If so, copy this
1090 definition, so we can use it in future. There used to be a comment (but
1091 not any code) that if we don't find a full definition, we'd set a flag
1092 so we don't spend time in the future checking the same type. That would
1093 be a mistake, though--we might load in more symbols which contain a
1094 full definition for the type.
1096 This used to be coded as a macro, but I don't think it is called
1097 often enough to merit such treatment. */
1099 struct complaint stub_noname_complaint
=
1100 {"stub type has NULL name", 0, 0};
1103 check_typedef (type
)
1104 register struct type
*type
;
1106 struct type
*orig_type
= type
;
1107 while (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
1109 if (!TYPE_TARGET_TYPE (type
))
1114 /* It is dangerous to call lookup_symbol if we are currently
1115 reading a symtab. Infinite recursion is one danger. */
1116 if (currently_reading_symtab
)
1119 name
= type_name_no_tag (type
);
1120 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1121 TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE
1122 as appropriate? (this code was written before TYPE_NAME and
1123 TYPE_TAG_NAME were separate). */
1126 complain (&stub_noname_complaint
);
1129 sym
= lookup_symbol (name
, 0, STRUCT_NAMESPACE
, 0,
1130 (struct symtab
**) NULL
);
1132 TYPE_TARGET_TYPE (type
) = SYMBOL_TYPE (sym
);
1134 TYPE_TARGET_TYPE (type
) = alloc_type (NULL
); /* TYPE_CODE_UNDEF */
1136 type
= TYPE_TARGET_TYPE (type
);
1139 /* If this is a struct/class/union with no fields, then check whether a
1140 full definition exists somewhere else. This is for systems where a
1141 type definition with no fields is issued for such types, instead of
1142 identifying them as stub types in the first place */
1144 if (TYPE_IS_OPAQUE (type
) && opaque_type_resolution
&& !currently_reading_symtab
)
1146 char *name
= type_name_no_tag (type
);
1147 struct type
*newtype
;
1150 complain (&stub_noname_complaint
);
1153 newtype
= lookup_transparent_type (name
);
1156 memcpy ((char *) type
, (char *) newtype
, sizeof (struct type
));
1159 /* Otherwise, rely on the stub flag being set for opaque/stubbed types */
1160 else if ((TYPE_FLAGS (type
) & TYPE_FLAG_STUB
) && !currently_reading_symtab
)
1162 char *name
= type_name_no_tag (type
);
1163 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1164 TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE
1165 as appropriate? (this code was written before TYPE_NAME and
1166 TYPE_TAG_NAME were separate). */
1170 complain (&stub_noname_complaint
);
1173 sym
= lookup_symbol (name
, 0, STRUCT_NAMESPACE
, 0, (struct symtab
**) NULL
);
1176 memcpy ((char *) type
, (char *) SYMBOL_TYPE (sym
), sizeof (struct type
));
1180 if (TYPE_FLAGS (type
) & TYPE_FLAG_TARGET_STUB
)
1182 struct type
*range_type
;
1183 struct type
*target_type
= check_typedef (TYPE_TARGET_TYPE (type
));
1185 if (TYPE_FLAGS (target_type
) & (TYPE_FLAG_STUB
| TYPE_FLAG_TARGET_STUB
))
1188 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
1189 && TYPE_NFIELDS (type
) == 1
1190 && (TYPE_CODE (range_type
= TYPE_FIELD_TYPE (type
, 0))
1191 == TYPE_CODE_RANGE
))
1193 /* Now recompute the length of the array type, based on its
1194 number of elements and the target type's length. */
1195 TYPE_LENGTH (type
) =
1196 ((TYPE_FIELD_BITPOS (range_type
, 1)
1197 - TYPE_FIELD_BITPOS (range_type
, 0)
1199 * TYPE_LENGTH (target_type
));
1200 TYPE_FLAGS (type
) &= ~TYPE_FLAG_TARGET_STUB
;
1202 else if (TYPE_CODE (type
) == TYPE_CODE_RANGE
)
1204 TYPE_LENGTH (type
) = TYPE_LENGTH (target_type
);
1205 TYPE_FLAGS (type
) &= ~TYPE_FLAG_TARGET_STUB
;
1208 /* Cache TYPE_LENGTH for future use. */
1209 TYPE_LENGTH (orig_type
) = TYPE_LENGTH (type
);
1213 /* New code added to support parsing of Cfront stabs strings */
1215 #define INIT_EXTRA { pextras->len=0; pextras->str[0]='\0'; }
1216 #define ADD_EXTRA(c) { pextras->str[pextras->len++]=c; }
1219 add_name (pextras
, n
)
1220 struct extra
*pextras
;
1225 if ((nlen
= (n
? strlen (n
) : 0)) == 0)
1227 sprintf (pextras
->str
+ pextras
->len
, "%d%s", nlen
, n
);
1228 pextras
->len
= strlen (pextras
->str
);
1232 add_mangled_type (pextras
, t
)
1233 struct extra
*pextras
;
1236 enum type_code tcode
;
1240 tcode
= TYPE_CODE (t
);
1241 tlen
= TYPE_LENGTH (t
);
1242 tflags
= TYPE_FLAGS (t
);
1243 tname
= TYPE_NAME (t
);
1244 /* args of "..." seem to get mangled as "e" */
1262 if ((pname
= strrchr (tname
, 'l'), pname
) && !strcmp (pname
, "long"))
1275 static struct complaint msg
=
1276 {"Bad int type code length x%x\n", 0, 0};
1278 complain (&msg
, tlen
);
1297 static struct complaint msg
=
1298 {"Bad float type code length x%x\n", 0, 0};
1299 complain (&msg
, tlen
);
1305 /* followed by what it's a ref to */
1309 /* followed by what it's a ptr to */
1311 case TYPE_CODE_TYPEDEF
:
1313 static struct complaint msg
=
1314 {"Typedefs in overloaded functions not yet supported\n", 0, 0};
1317 /* followed by type bytes & name */
1319 case TYPE_CODE_FUNC
:
1321 /* followed by func's arg '_' & ret types */
1323 case TYPE_CODE_VOID
:
1326 case TYPE_CODE_METHOD
:
1328 /* followed by name of class and func's arg '_' & ret types */
1329 add_name (pextras
, tname
);
1330 ADD_EXTRA ('F'); /* then mangle function */
1332 case TYPE_CODE_STRUCT
: /* C struct */
1333 case TYPE_CODE_UNION
: /* C union */
1334 case TYPE_CODE_ENUM
: /* Enumeration type */
1335 /* followed by name of type */
1336 add_name (pextras
, tname
);
1339 /* errors possible types/not supported */
1340 case TYPE_CODE_CHAR
:
1341 case TYPE_CODE_ARRAY
: /* Array type */
1342 case TYPE_CODE_MEMBER
: /* Member type */
1343 case TYPE_CODE_BOOL
:
1344 case TYPE_CODE_COMPLEX
: /* Complex float */
1345 case TYPE_CODE_UNDEF
:
1346 case TYPE_CODE_SET
: /* Pascal sets */
1347 case TYPE_CODE_RANGE
:
1348 case TYPE_CODE_STRING
:
1349 case TYPE_CODE_BITSTRING
:
1350 case TYPE_CODE_ERROR
:
1353 static struct complaint msg
=
1354 {"Unknown type code x%x\n", 0, 0};
1355 complain (&msg
, tcode
);
1359 add_mangled_type (pextras
, t
->target_type
);
1364 cfront_mangle_name (type
, i
, j
)
1370 char *mangled_name
= gdb_mangle_name (type
, i
, j
);
1372 f
= TYPE_FN_FIELDLIST1 (type
, i
); /* moved from below */
1374 /* kludge to support cfront methods - gdb expects to find "F" for
1375 ARM_mangled names, so when we mangle, we have to add it here */
1379 char *arm_mangled_name
;
1380 struct fn_field
*method
= &f
[j
];
1381 char *field_name
= TYPE_FN_FIELDLIST_NAME (type
, i
);
1382 char *physname
= TYPE_FN_FIELD_PHYSNAME (f
, j
);
1383 char *newname
= type_name_no_tag (type
);
1385 struct type
*ftype
= TYPE_FN_FIELD_TYPE (f
, j
);
1386 int nargs
= TYPE_NFIELDS (ftype
); /* number of args */
1387 struct extra extras
, *pextras
= &extras
;
1390 if (TYPE_FN_FIELD_STATIC_P (f
, j
)) /* j for sublist within this list */
1393 /* add args here! */
1394 if (nargs
<= 1) /* no args besides this */
1398 for (k
= 1; k
< nargs
; k
++)
1401 t
= TYPE_FIELD_TYPE (ftype
, k
);
1402 add_mangled_type (pextras
, t
);
1406 printf ("add_mangled_type: %s\n", extras
.str
); /* FIXME */
1407 arm_mangled_name
= malloc (strlen (mangled_name
) + extras
.len
);
1408 sprintf (arm_mangled_name
, "%s%s", mangled_name
, extras
.str
);
1409 free (mangled_name
);
1410 mangled_name
= arm_mangled_name
;
1416 /* End of new code added to support parsing of Cfront stabs strings */
1418 /* Ugly hack to convert method stubs into method types.
1420 He ain't kiddin'. This demangles the name of the method into a string
1421 including argument types, parses out each argument type, generates
1422 a string casting a zero to that type, evaluates the string, and stuffs
1423 the resulting type into an argtype vector!!! Then it knows the type
1424 of the whole function (including argument types for overloading),
1425 which info used to be in the stab's but was removed to hack back
1426 the space required for them. */
1429 check_stub_method (type
, method_id
, signature_id
)
1435 char *mangled_name
= gdb_mangle_name (type
, method_id
, signature_id
);
1436 char *demangled_name
= cplus_demangle (mangled_name
,
1437 DMGL_PARAMS
| DMGL_ANSI
);
1438 char *argtypetext
, *p
;
1439 int depth
= 0, argcount
= 1;
1440 struct type
**argtypes
;
1443 /* Make sure we got back a function string that we can use. */
1445 p
= strchr (demangled_name
, '(');
1447 if (demangled_name
== NULL
|| p
== NULL
)
1448 error ("Internal: Cannot demangle mangled name `%s'.", mangled_name
);
1450 /* Now, read in the parameters that define this type. */
1463 else if (*p
== ',' && depth
== 0)
1471 /* We need two more slots: one for the THIS pointer, and one for the
1472 NULL [...] or void [end of arglist]. */
1474 argtypes
= (struct type
**)
1475 TYPE_ALLOC (type
, (argcount
+ 2) * sizeof (struct type
*));
1477 /* FIXME: This is wrong for static member functions. */
1478 argtypes
[0] = lookup_pointer_type (type
);
1481 if (*p
!= ')') /* () means no args, skip while */
1486 if (depth
<= 0 && (*p
== ',' || *p
== ')'))
1488 /* Avoid parsing of ellipsis, they will be handled below. */
1489 if (strncmp (argtypetext
, "...", p
- argtypetext
) != 0)
1491 argtypes
[argcount
] =
1492 parse_and_eval_type (argtypetext
, p
- argtypetext
);
1495 argtypetext
= p
+ 1;
1511 if (p
[-2] != '.') /* Not '...' */
1513 argtypes
[argcount
] = builtin_type_void
; /* List terminator */
1517 argtypes
[argcount
] = NULL
; /* Ellist terminator */
1520 free (demangled_name
);
1522 f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
1524 TYPE_FN_FIELD_PHYSNAME (f
, signature_id
) = mangled_name
;
1526 /* Now update the old "stub" type into a real type. */
1527 mtype
= TYPE_FN_FIELD_TYPE (f
, signature_id
);
1528 TYPE_DOMAIN_TYPE (mtype
) = type
;
1529 TYPE_ARG_TYPES (mtype
) = argtypes
;
1530 TYPE_FLAGS (mtype
) &= ~TYPE_FLAG_STUB
;
1531 TYPE_FN_FIELD_STUB (f
, signature_id
) = 0;
1534 const struct cplus_struct_type cplus_struct_default
;
1537 allocate_cplus_struct_type (type
)
1540 if (!HAVE_CPLUS_STRUCT (type
))
1542 TYPE_CPLUS_SPECIFIC (type
) = (struct cplus_struct_type
*)
1543 TYPE_ALLOC (type
, sizeof (struct cplus_struct_type
));
1544 *(TYPE_CPLUS_SPECIFIC (type
)) = cplus_struct_default
;
1548 /* Helper function to initialize the standard scalar types.
1550 If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy
1551 of the string pointed to by name in the type_obstack for that objfile,
1552 and initialize the type name to that copy. There are places (mipsread.c
1553 in particular, where init_type is called with a NULL value for NAME). */
1556 init_type (code
, length
, flags
, name
, objfile
)
1557 enum type_code code
;
1561 struct objfile
*objfile
;
1563 register struct type
*type
;
1565 type
= alloc_type (objfile
);
1566 TYPE_CODE (type
) = code
;
1567 TYPE_LENGTH (type
) = length
;
1568 TYPE_FLAGS (type
) |= flags
;
1569 if ((name
!= NULL
) && (objfile
!= NULL
))
1572 obsavestring (name
, strlen (name
), &objfile
->type_obstack
);
1576 TYPE_NAME (type
) = name
;
1581 if (code
== TYPE_CODE_STRUCT
|| code
== TYPE_CODE_UNION
)
1583 INIT_CPLUS_SPECIFIC (type
);
1588 /* Look up a fundamental type for the specified objfile.
1589 May need to construct such a type if this is the first use.
1591 Some object file formats (ELF, COFF, etc) do not define fundamental
1592 types such as "int" or "double". Others (stabs for example), do
1593 define fundamental types.
1595 For the formats which don't provide fundamental types, gdb can create
1596 such types, using defaults reasonable for the current language and
1597 the current target machine.
1599 NOTE: This routine is obsolescent. Each debugging format reader
1600 should manage it's own fundamental types, either creating them from
1601 suitable defaults or reading them from the debugging information,
1602 whichever is appropriate. The DWARF reader has already been
1603 fixed to do this. Once the other readers are fixed, this routine
1604 will go away. Also note that fundamental types should be managed
1605 on a compilation unit basis in a multi-language environment, not
1606 on a linkage unit basis as is done here. */
1610 lookup_fundamental_type (objfile
, typeid)
1611 struct objfile
*objfile
;
1614 register struct type
**typep
;
1615 register int nbytes
;
1617 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
1619 error ("internal error - invalid fundamental type id %d", typeid);
1622 /* If this is the first time we need a fundamental type for this objfile
1623 then we need to initialize the vector of type pointers. */
1625 if (objfile
->fundamental_types
== NULL
)
1627 nbytes
= FT_NUM_MEMBERS
* sizeof (struct type
*);
1628 objfile
->fundamental_types
= (struct type
**)
1629 obstack_alloc (&objfile
->type_obstack
, nbytes
);
1630 memset ((char *) objfile
->fundamental_types
, 0, nbytes
);
1631 OBJSTAT (objfile
, n_types
+= FT_NUM_MEMBERS
);
1634 /* Look for this particular type in the fundamental type vector. If one is
1635 not found, create and install one appropriate for the current language. */
1637 typep
= objfile
->fundamental_types
+ typeid;
1640 *typep
= create_fundamental_type (objfile
, typeid);
1650 /* FIXME: Should we return true for references as well as pointers? */
1654 && TYPE_CODE (t
) == TYPE_CODE_PTR
1655 && TYPE_CODE (TYPE_TARGET_TYPE (t
)) != TYPE_CODE_VOID
);
1659 is_integral_type (t
)
1665 && ((TYPE_CODE (t
) == TYPE_CODE_INT
)
1666 || (TYPE_CODE (t
) == TYPE_CODE_ENUM
)
1667 || (TYPE_CODE (t
) == TYPE_CODE_CHAR
)
1668 || (TYPE_CODE (t
) == TYPE_CODE_RANGE
)
1669 || (TYPE_CODE (t
) == TYPE_CODE_BOOL
)));
1672 /* Chill varying string and arrays are represented as follows:
1674 struct { int __var_length; ELEMENT_TYPE[MAX_SIZE] __var_data};
1676 Return true if TYPE is such a Chill varying type. */
1679 chill_varying_type (type
)
1682 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
1683 || TYPE_NFIELDS (type
) != 2
1684 || strcmp (TYPE_FIELD_NAME (type
, 0), "__var_length") != 0)
1689 /* Check whether BASE is an ancestor or base class or DCLASS
1690 Return 1 if so, and 0 if not.
1691 Note: callers may want to check for identity of the types before
1692 calling this function -- identical types are considered to satisfy
1693 the ancestor relationship even if they're identical */
1696 is_ancestor (base
, dclass
)
1698 struct type
*dclass
;
1702 CHECK_TYPEDEF (base
);
1703 CHECK_TYPEDEF (dclass
);
1708 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1709 if (is_ancestor (base
, TYPE_BASECLASS (dclass
, i
)))
1717 /* See whether DCLASS has a virtual table. This routine is aimed at
1718 the HP/Taligent ANSI C++ runtime model, and may not work with other
1719 runtime models. Return 1 => Yes, 0 => No. */
1723 struct type
*dclass
;
1725 /* In the HP ANSI C++ runtime model, a class has a vtable only if it
1726 has virtual functions or virtual bases. */
1730 if (TYPE_CODE (dclass
) != TYPE_CODE_CLASS
)
1733 /* First check for the presence of virtual bases */
1734 if (TYPE_FIELD_VIRTUAL_BITS (dclass
))
1735 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1736 if (B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass
), i
))
1739 /* Next check for virtual functions */
1740 if (TYPE_FN_FIELDLISTS (dclass
))
1741 for (i
= 0; i
< TYPE_NFN_FIELDS (dclass
); i
++)
1742 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass
, i
), 0))
1745 /* Recurse on non-virtual bases to see if any of them needs a vtable */
1746 if (TYPE_FIELD_VIRTUAL_BITS (dclass
))
1747 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1748 if ((!B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass
), i
)) &&
1749 (has_vtable (TYPE_FIELD_TYPE (dclass
, i
))))
1752 /* Well, maybe we don't need a virtual table */
1756 /* Return a pointer to the "primary base class" of DCLASS.
1758 A NULL return indicates that DCLASS has no primary base, or that it
1759 couldn't be found (insufficient information).
1761 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
1762 and may not work with other runtime models. */
1765 primary_base_class (dclass
)
1766 struct type
*dclass
;
1768 /* In HP ANSI C++'s runtime model, a "primary base class" of a class
1769 is the first directly inherited, non-virtual base class that
1770 requires a virtual table */
1774 if (TYPE_CODE (dclass
) != TYPE_CODE_CLASS
)
1777 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1778 if (!TYPE_FIELD_VIRTUAL (dclass
, i
) &&
1779 has_vtable (TYPE_FIELD_TYPE (dclass
, i
)))
1780 return TYPE_FIELD_TYPE (dclass
, i
);
1785 /* Global manipulated by virtual_base_list[_aux]() */
1787 static struct vbase
*current_vbase_list
= NULL
;
1789 /* Return a pointer to a null-terminated list of struct vbase
1790 items. The vbasetype pointer of each item in the list points to the
1791 type information for a virtual base of the argument DCLASS.
1793 Helper function for virtual_base_list().
1794 Note: the list goes backward, right-to-left. virtual_base_list()
1795 copies the items out in reverse order. */
1798 virtual_base_list_aux (dclass
)
1799 struct type
*dclass
;
1801 struct vbase
*tmp_vbase
;
1804 if (TYPE_CODE (dclass
) != TYPE_CODE_CLASS
)
1807 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1809 /* Recurse on this ancestor, first */
1810 virtual_base_list_aux (TYPE_FIELD_TYPE (dclass
, i
));
1812 /* If this current base is itself virtual, add it to the list */
1813 if (BASETYPE_VIA_VIRTUAL (dclass
, i
))
1815 struct type
*basetype
= TYPE_FIELD_TYPE (dclass
, i
);
1817 /* Check if base already recorded */
1818 tmp_vbase
= current_vbase_list
;
1821 if (tmp_vbase
->vbasetype
== basetype
)
1822 break; /* found it */
1823 tmp_vbase
= tmp_vbase
->next
;
1826 if (!tmp_vbase
) /* normal exit from loop */
1828 /* Allocate new item for this virtual base */
1829 tmp_vbase
= (struct vbase
*) xmalloc (sizeof (struct vbase
));
1831 /* Stick it on at the end of the list */
1832 tmp_vbase
->vbasetype
= basetype
;
1833 tmp_vbase
->next
= current_vbase_list
;
1834 current_vbase_list
= tmp_vbase
;
1837 } /* for loop over bases */
1841 /* Compute the list of virtual bases in the right order. Virtual
1842 bases are laid out in the object's memory area in order of their
1843 occurrence in a depth-first, left-to-right search through the
1846 Argument DCLASS is the type whose virtual bases are required.
1847 Return value is the address of a null-terminated array of pointers
1848 to struct type items.
1850 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
1851 and may not work with other runtime models.
1853 This routine merely hands off the argument to virtual_base_list_aux()
1854 and then copies the result into an array to save space. */
1857 virtual_base_list (dclass
)
1858 struct type
*dclass
;
1860 register struct vbase
*tmp_vbase
;
1861 register struct vbase
*tmp_vbase_2
;
1864 struct type
**vbase_array
;
1866 current_vbase_list
= NULL
;
1867 virtual_base_list_aux (dclass
);
1869 for (i
= 0, tmp_vbase
= current_vbase_list
; tmp_vbase
!= NULL
; i
++, tmp_vbase
= tmp_vbase
->next
)
1874 vbase_array
= (struct type
**) xmalloc ((count
+ 1) * sizeof (struct type
*));
1876 for (i
= count
- 1, tmp_vbase
= current_vbase_list
; i
>= 0; i
--, tmp_vbase
= tmp_vbase
->next
)
1877 vbase_array
[i
] = tmp_vbase
->vbasetype
;
1879 /* Get rid of constructed chain */
1880 tmp_vbase_2
= tmp_vbase
= current_vbase_list
;
1883 tmp_vbase
= tmp_vbase
->next
;
1885 tmp_vbase_2
= tmp_vbase
;
1888 vbase_array
[count
] = NULL
;
1892 /* Return the length of the virtual base list of the type DCLASS. */
1895 virtual_base_list_length (dclass
)
1896 struct type
*dclass
;
1899 register struct vbase
*tmp_vbase
;
1901 current_vbase_list
= NULL
;
1902 virtual_base_list_aux (dclass
);
1904 for (i
= 0, tmp_vbase
= current_vbase_list
; tmp_vbase
!= NULL
; i
++, tmp_vbase
= tmp_vbase
->next
)
1909 /* Return the number of elements of the virtual base list of the type
1910 DCLASS, ignoring those appearing in the primary base (and its
1911 primary base, recursively). */
1914 virtual_base_list_length_skip_primaries (dclass
)
1915 struct type
*dclass
;
1918 register struct vbase
*tmp_vbase
;
1919 struct type
*primary
;
1921 primary
= TYPE_RUNTIME_PTR (dclass
) ? TYPE_PRIMARY_BASE (dclass
) : NULL
;
1924 return virtual_base_list_length (dclass
);
1926 current_vbase_list
= NULL
;
1927 virtual_base_list_aux (dclass
);
1929 for (i
= 0, tmp_vbase
= current_vbase_list
; tmp_vbase
!= NULL
; tmp_vbase
= tmp_vbase
->next
)
1931 if (virtual_base_index (tmp_vbase
->vbasetype
, primary
) >= 0)
1939 /* Return the index (position) of type BASE, which is a virtual base
1940 class of DCLASS, in the latter's virtual base list. A return of -1
1941 indicates "not found" or a problem. */
1944 virtual_base_index (base
, dclass
)
1946 struct type
*dclass
;
1948 register struct type
*vbase
;
1951 if ((TYPE_CODE (dclass
) != TYPE_CODE_CLASS
) ||
1952 (TYPE_CODE (base
) != TYPE_CODE_CLASS
))
1956 vbase
= TYPE_VIRTUAL_BASE_LIST (dclass
)[0];
1961 vbase
= TYPE_VIRTUAL_BASE_LIST (dclass
)[++i
];
1964 return vbase
? i
: -1;
1969 /* Return the index (position) of type BASE, which is a virtual base
1970 class of DCLASS, in the latter's virtual base list. Skip over all
1971 bases that may appear in the virtual base list of the primary base
1972 class of DCLASS (recursively). A return of -1 indicates "not
1973 found" or a problem. */
1976 virtual_base_index_skip_primaries (base
, dclass
)
1978 struct type
*dclass
;
1980 register struct type
*vbase
;
1982 struct type
*primary
;
1984 if ((TYPE_CODE (dclass
) != TYPE_CODE_CLASS
) ||
1985 (TYPE_CODE (base
) != TYPE_CODE_CLASS
))
1988 primary
= TYPE_RUNTIME_PTR (dclass
) ? TYPE_PRIMARY_BASE (dclass
) : NULL
;
1992 vbase
= TYPE_VIRTUAL_BASE_LIST (dclass
)[0];
1995 if (!primary
|| (virtual_base_index_skip_primaries (vbase
, primary
) < 0))
1999 vbase
= TYPE_VIRTUAL_BASE_LIST (dclass
)[++i
];
2002 return vbase
? j
: -1;
2005 /* Return position of a derived class DCLASS in the list of
2006 * primary bases starting with the remotest ancestor.
2007 * Position returned is 0-based. */
2010 class_index_in_primary_list (dclass
)
2011 struct type
*dclass
;
2013 struct type
*pbc
; /* primary base class */
2015 /* Simply recurse on primary base */
2016 pbc
= TYPE_PRIMARY_BASE (dclass
);
2018 return 1 + class_index_in_primary_list (pbc
);
2023 /* Return a count of the number of virtual functions a type has.
2024 * This includes all the virtual functions it inherits from its
2028 /* pai: FIXME This doesn't do the right thing: count redefined virtual
2029 * functions only once (latest redefinition)
2033 count_virtual_fns (dclass
)
2034 struct type
*dclass
;
2036 int fn
, oi
; /* function and overloaded instance indices */
2037 int vfuncs
; /* count to return */
2039 /* recurse on bases that can share virtual table */
2040 struct type
*pbc
= primary_base_class (dclass
);
2042 vfuncs
= count_virtual_fns (pbc
);
2044 for (fn
= 0; fn
< TYPE_NFN_FIELDS (dclass
); fn
++)
2045 for (oi
= 0; oi
< TYPE_FN_FIELDLIST_LENGTH (dclass
, fn
); oi
++)
2046 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass
, fn
), oi
))
2054 /* Functions for overload resolution begin here */
2056 /* Compare two badness vectors A and B and return the result.
2057 * 0 => A and B are identical
2058 * 1 => A and B are incomparable
2059 * 2 => A is better than B
2060 * 3 => A is worse than B */
2063 compare_badness (a
, b
)
2064 struct badness_vector
*a
;
2065 struct badness_vector
*b
;
2069 short found_pos
= 0; /* any positives in c? */
2070 short found_neg
= 0; /* any negatives in c? */
2072 /* differing lengths => incomparable */
2073 if (a
->length
!= b
->length
)
2076 /* Subtract b from a */
2077 for (i
= 0; i
< a
->length
; i
++)
2079 tmp
= a
->rank
[i
] - b
->rank
[i
];
2089 return 1; /* incomparable */
2091 return 3; /* A > B */
2097 return 2; /* A < B */
2099 return 0; /* A == B */
2103 /* Rank a function by comparing its parameter types (PARMS, length NPARMS),
2104 * to the types of an argument list (ARGS, length NARGS).
2105 * Return a pointer to a badness vector. This has NARGS + 1 entries. */
2107 struct badness_vector
*
2108 rank_function (parms
, nparms
, args
, nargs
)
2109 struct type
**parms
;
2115 struct badness_vector
*bv
;
2116 int min_len
= nparms
< nargs
? nparms
: nargs
;
2118 bv
= xmalloc (sizeof (struct badness_vector
));
2119 bv
->length
= nargs
+ 1; /* add 1 for the length-match rank */
2120 bv
->rank
= xmalloc ((nargs
+ 1) * sizeof (int));
2122 /* First compare the lengths of the supplied lists.
2123 * If there is a mismatch, set it to a high value. */
2125 /* pai/1997-06-03 FIXME: when we have debug info about default
2126 * arguments and ellipsis parameter lists, we should consider those
2127 * and rank the length-match more finely. */
2129 LENGTH_MATCH (bv
) = (nargs
!= nparms
) ? LENGTH_MISMATCH_BADNESS
: 0;
2131 /* Now rank all the parameters of the candidate function */
2132 for (i
= 1; i
<= min_len
; i
++)
2133 bv
->rank
[i
] = rank_one_type (parms
[i
- 1], args
[i
- 1]);
2135 /* If more arguments than parameters, add dummy entries */
2136 for (i
= min_len
+ 1; i
<= nargs
; i
++)
2137 bv
->rank
[i
] = TOO_FEW_PARAMS_BADNESS
;
2142 /* Compare one type (PARM) for compatibility with another (ARG).
2143 * PARM is intended to be the parameter type of a function; and
2144 * ARG is the supplied argument's type. This function tests if
2145 * the latter can be converted to the former.
2147 * Return 0 if they are identical types;
2148 * Otherwise, return an integer which corresponds to how compatible
2149 * PARM is to ARG. The higher the return value, the worse the match.
2150 * Generally the "bad" conversions are all uniformly assigned a 100 */
2153 rank_one_type (parm
, arg
)
2157 /* Identical type pointers */
2158 /* However, this still doesn't catch all cases of same type for arg
2159 * and param. The reason is that builtin types are different from
2160 * the same ones constructed from the object. */
2164 /* Resolve typedefs */
2165 if (TYPE_CODE (parm
) == TYPE_CODE_TYPEDEF
)
2166 parm
= check_typedef (parm
);
2167 if (TYPE_CODE (arg
) == TYPE_CODE_TYPEDEF
)
2168 arg
= check_typedef (arg
);
2170 /* Check if identical after resolving typedefs */
2175 /* Debugging only */
2176 printf ("------ Arg is %s [%d], parm is %s [%d]\n",
2177 TYPE_NAME (arg
), TYPE_CODE (arg
), TYPE_NAME (parm
), TYPE_CODE (parm
));
2180 /* x -> y means arg of type x being supplied for parameter of type y */
2182 switch (TYPE_CODE (parm
))
2185 switch (TYPE_CODE (arg
))
2188 if (TYPE_CODE (TYPE_TARGET_TYPE (parm
)) == TYPE_CODE_VOID
)
2189 return VOID_PTR_CONVERSION_BADNESS
;
2191 return rank_one_type (TYPE_TARGET_TYPE (parm
), TYPE_TARGET_TYPE (arg
));
2192 case TYPE_CODE_ARRAY
:
2193 return rank_one_type (TYPE_TARGET_TYPE (parm
), TYPE_TARGET_TYPE (arg
));
2194 case TYPE_CODE_FUNC
:
2195 return rank_one_type (TYPE_TARGET_TYPE (parm
), arg
);
2197 case TYPE_CODE_ENUM
:
2198 case TYPE_CODE_CHAR
:
2199 case TYPE_CODE_RANGE
:
2200 case TYPE_CODE_BOOL
:
2201 return POINTER_CONVERSION_BADNESS
;
2203 return INCOMPATIBLE_TYPE_BADNESS
;
2205 case TYPE_CODE_ARRAY
:
2206 switch (TYPE_CODE (arg
))
2209 case TYPE_CODE_ARRAY
:
2210 return rank_one_type (TYPE_TARGET_TYPE (parm
), TYPE_TARGET_TYPE (arg
));
2212 return INCOMPATIBLE_TYPE_BADNESS
;
2214 case TYPE_CODE_FUNC
:
2215 switch (TYPE_CODE (arg
))
2217 case TYPE_CODE_PTR
: /* funcptr -> func */
2218 return rank_one_type (parm
, TYPE_TARGET_TYPE (arg
));
2220 return INCOMPATIBLE_TYPE_BADNESS
;
2223 switch (TYPE_CODE (arg
))
2226 if (TYPE_LENGTH (arg
) == TYPE_LENGTH (parm
))
2228 /* Deal with signed, unsigned, and plain chars and
2229 signed and unsigned ints */
2230 if (TYPE_NOSIGN (parm
))
2232 /* This case only for character types */
2233 if (TYPE_NOSIGN (arg
)) /* plain char -> plain char */
2236 return INTEGER_COERCION_BADNESS
; /* signed/unsigned char -> plain char */
2238 else if (TYPE_UNSIGNED (parm
))
2240 if (TYPE_UNSIGNED (arg
))
2242 if (!strcmp (TYPE_NAME (parm
), TYPE_NAME (arg
)))
2243 return 0; /* unsigned int -> unsigned int, or unsigned long -> unsigned long */
2244 else if (!strcmp (TYPE_NAME (arg
), "int") && !strcmp (TYPE_NAME (parm
), "long"))
2245 return INTEGER_PROMOTION_BADNESS
; /* unsigned int -> unsigned long */
2247 return INTEGER_COERCION_BADNESS
; /* unsigned long -> unsigned int */
2251 if (!strcmp (TYPE_NAME (arg
), "long") && !strcmp (TYPE_NAME (parm
), "int"))
2252 return INTEGER_COERCION_BADNESS
; /* signed long -> unsigned int */
2254 return INTEGER_CONVERSION_BADNESS
; /* signed int/long -> unsigned int/long */
2257 else if (!TYPE_NOSIGN (arg
) && !TYPE_UNSIGNED (arg
))
2259 if (!strcmp (TYPE_NAME (parm
), TYPE_NAME (arg
)))
2261 else if (!strcmp (TYPE_NAME (arg
), "int") && !strcmp (TYPE_NAME (parm
), "long"))
2262 return INTEGER_PROMOTION_BADNESS
;
2264 return INTEGER_COERCION_BADNESS
;
2267 return INTEGER_COERCION_BADNESS
;
2269 else if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2270 return INTEGER_PROMOTION_BADNESS
;
2272 return INTEGER_COERCION_BADNESS
;
2273 case TYPE_CODE_ENUM
:
2274 case TYPE_CODE_CHAR
:
2275 case TYPE_CODE_RANGE
:
2276 case TYPE_CODE_BOOL
:
2277 return INTEGER_PROMOTION_BADNESS
;
2279 return INT_FLOAT_CONVERSION_BADNESS
;
2281 return NS_POINTER_CONVERSION_BADNESS
;
2283 return INCOMPATIBLE_TYPE_BADNESS
;
2286 case TYPE_CODE_ENUM
:
2287 switch (TYPE_CODE (arg
))
2290 case TYPE_CODE_CHAR
:
2291 case TYPE_CODE_RANGE
:
2292 case TYPE_CODE_BOOL
:
2293 case TYPE_CODE_ENUM
:
2294 return INTEGER_COERCION_BADNESS
;
2296 return INT_FLOAT_CONVERSION_BADNESS
;
2298 return INCOMPATIBLE_TYPE_BADNESS
;
2301 case TYPE_CODE_CHAR
:
2302 switch (TYPE_CODE (arg
))
2304 case TYPE_CODE_RANGE
:
2305 case TYPE_CODE_BOOL
:
2306 case TYPE_CODE_ENUM
:
2307 return INTEGER_COERCION_BADNESS
;
2309 return INT_FLOAT_CONVERSION_BADNESS
;
2311 if (TYPE_LENGTH (arg
) > TYPE_LENGTH (parm
))
2312 return INTEGER_COERCION_BADNESS
;
2313 else if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2314 return INTEGER_PROMOTION_BADNESS
;
2315 /* >>> !! else fall through !! <<< */
2316 case TYPE_CODE_CHAR
:
2317 /* Deal with signed, unsigned, and plain chars for C++
2318 and with int cases falling through from previous case */
2319 if (TYPE_NOSIGN (parm
))
2321 if (TYPE_NOSIGN (arg
))
2324 return INTEGER_COERCION_BADNESS
;
2326 else if (TYPE_UNSIGNED (parm
))
2328 if (TYPE_UNSIGNED (arg
))
2331 return INTEGER_PROMOTION_BADNESS
;
2333 else if (!TYPE_NOSIGN (arg
) && !TYPE_UNSIGNED (arg
))
2336 return INTEGER_COERCION_BADNESS
;
2338 return INCOMPATIBLE_TYPE_BADNESS
;
2341 case TYPE_CODE_RANGE
:
2342 switch (TYPE_CODE (arg
))
2345 case TYPE_CODE_CHAR
:
2346 case TYPE_CODE_RANGE
:
2347 case TYPE_CODE_BOOL
:
2348 case TYPE_CODE_ENUM
:
2349 return INTEGER_COERCION_BADNESS
;
2351 return INT_FLOAT_CONVERSION_BADNESS
;
2353 return INCOMPATIBLE_TYPE_BADNESS
;
2356 case TYPE_CODE_BOOL
:
2357 switch (TYPE_CODE (arg
))
2360 case TYPE_CODE_CHAR
:
2361 case TYPE_CODE_RANGE
:
2362 case TYPE_CODE_ENUM
:
2365 return BOOLEAN_CONVERSION_BADNESS
;
2366 case TYPE_CODE_BOOL
:
2369 return INCOMPATIBLE_TYPE_BADNESS
;
2373 switch (TYPE_CODE (arg
))
2376 if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2377 return FLOAT_PROMOTION_BADNESS
;
2378 else if (TYPE_LENGTH (arg
) == TYPE_LENGTH (parm
))
2381 return FLOAT_CONVERSION_BADNESS
;
2383 case TYPE_CODE_BOOL
:
2384 case TYPE_CODE_ENUM
:
2385 case TYPE_CODE_RANGE
:
2386 case TYPE_CODE_CHAR
:
2387 return INT_FLOAT_CONVERSION_BADNESS
;
2389 return INCOMPATIBLE_TYPE_BADNESS
;
2392 case TYPE_CODE_COMPLEX
:
2393 switch (TYPE_CODE (arg
))
2394 { /* Strictly not needed for C++, but... */
2396 return FLOAT_PROMOTION_BADNESS
;
2397 case TYPE_CODE_COMPLEX
:
2400 return INCOMPATIBLE_TYPE_BADNESS
;
2403 case TYPE_CODE_STRUCT
:
2404 /* currently same as TYPE_CODE_CLASS */
2405 switch (TYPE_CODE (arg
))
2407 case TYPE_CODE_STRUCT
:
2408 /* Check for derivation */
2409 if (is_ancestor (parm
, arg
))
2410 return BASE_CONVERSION_BADNESS
;
2411 /* else fall through */
2413 return INCOMPATIBLE_TYPE_BADNESS
;
2416 case TYPE_CODE_UNION
:
2417 switch (TYPE_CODE (arg
))
2419 case TYPE_CODE_UNION
:
2421 return INCOMPATIBLE_TYPE_BADNESS
;
2424 case TYPE_CODE_MEMBER
:
2425 switch (TYPE_CODE (arg
))
2428 return INCOMPATIBLE_TYPE_BADNESS
;
2431 case TYPE_CODE_METHOD
:
2432 switch (TYPE_CODE (arg
))
2436 return INCOMPATIBLE_TYPE_BADNESS
;
2440 switch (TYPE_CODE (arg
))
2444 return INCOMPATIBLE_TYPE_BADNESS
;
2449 switch (TYPE_CODE (arg
))
2453 return rank_one_type (TYPE_FIELD_TYPE (parm
, 0), TYPE_FIELD_TYPE (arg
, 0));
2455 return INCOMPATIBLE_TYPE_BADNESS
;
2458 case TYPE_CODE_VOID
:
2460 return INCOMPATIBLE_TYPE_BADNESS
;
2461 } /* switch (TYPE_CODE (arg)) */
2465 /* End of functions for overload resolution */
2468 print_bit_vector (bits
, nbits
)
2474 for (bitno
= 0; bitno
< nbits
; bitno
++)
2476 if ((bitno
% 8) == 0)
2478 puts_filtered (" ");
2480 if (B_TST (bits
, bitno
))
2482 printf_filtered ("1");
2486 printf_filtered ("0");
2491 /* The args list is a strange beast. It is either terminated by a NULL
2492 pointer for varargs functions, or by a pointer to a TYPE_CODE_VOID
2493 type for normal fixed argcount functions. (FIXME someday)
2494 Also note the first arg should be the "this" pointer, we may not want to
2495 include it since we may get into a infinitely recursive situation. */
2498 print_arg_types (args
, spaces
)
2504 while (*args
!= NULL
)
2506 recursive_dump_type (*args
, spaces
+ 2);
2507 if ((*args
++)->code
== TYPE_CODE_VOID
)
2516 dump_fn_fieldlists (type
, spaces
)
2524 printfi_filtered (spaces
, "fn_fieldlists ");
2525 gdb_print_host_address (TYPE_FN_FIELDLISTS (type
), gdb_stdout
);
2526 printf_filtered ("\n");
2527 for (method_idx
= 0; method_idx
< TYPE_NFN_FIELDS (type
); method_idx
++)
2529 f
= TYPE_FN_FIELDLIST1 (type
, method_idx
);
2530 printfi_filtered (spaces
+ 2, "[%d] name '%s' (",
2532 TYPE_FN_FIELDLIST_NAME (type
, method_idx
));
2533 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type
, method_idx
),
2535 printf_filtered (") length %d\n",
2536 TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
));
2537 for (overload_idx
= 0;
2538 overload_idx
< TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
);
2541 printfi_filtered (spaces
+ 4, "[%d] physname '%s' (",
2543 TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
));
2544 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
),
2546 printf_filtered (")\n");
2547 printfi_filtered (spaces
+ 8, "type ");
2548 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f
, overload_idx
), gdb_stdout
);
2549 printf_filtered ("\n");
2551 recursive_dump_type (TYPE_FN_FIELD_TYPE (f
, overload_idx
),
2554 printfi_filtered (spaces
+ 8, "args ");
2555 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f
, overload_idx
), gdb_stdout
);
2556 printf_filtered ("\n");
2558 print_arg_types (TYPE_FN_FIELD_ARGS (f
, overload_idx
), spaces
);
2559 printfi_filtered (spaces
+ 8, "fcontext ");
2560 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f
, overload_idx
),
2562 printf_filtered ("\n");
2564 printfi_filtered (spaces
+ 8, "is_const %d\n",
2565 TYPE_FN_FIELD_CONST (f
, overload_idx
));
2566 printfi_filtered (spaces
+ 8, "is_volatile %d\n",
2567 TYPE_FN_FIELD_VOLATILE (f
, overload_idx
));
2568 printfi_filtered (spaces
+ 8, "is_private %d\n",
2569 TYPE_FN_FIELD_PRIVATE (f
, overload_idx
));
2570 printfi_filtered (spaces
+ 8, "is_protected %d\n",
2571 TYPE_FN_FIELD_PROTECTED (f
, overload_idx
));
2572 printfi_filtered (spaces
+ 8, "is_stub %d\n",
2573 TYPE_FN_FIELD_STUB (f
, overload_idx
));
2574 printfi_filtered (spaces
+ 8, "voffset %u\n",
2575 TYPE_FN_FIELD_VOFFSET (f
, overload_idx
));
2581 print_cplus_stuff (type
, spaces
)
2585 printfi_filtered (spaces
, "n_baseclasses %d\n",
2586 TYPE_N_BASECLASSES (type
));
2587 printfi_filtered (spaces
, "nfn_fields %d\n",
2588 TYPE_NFN_FIELDS (type
));
2589 printfi_filtered (spaces
, "nfn_fields_total %d\n",
2590 TYPE_NFN_FIELDS_TOTAL (type
));
2591 if (TYPE_N_BASECLASSES (type
) > 0)
2593 printfi_filtered (spaces
, "virtual_field_bits (%d bits at *",
2594 TYPE_N_BASECLASSES (type
));
2595 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type
), gdb_stdout
);
2596 printf_filtered (")");
2598 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type
),
2599 TYPE_N_BASECLASSES (type
));
2600 puts_filtered ("\n");
2602 if (TYPE_NFIELDS (type
) > 0)
2604 if (TYPE_FIELD_PRIVATE_BITS (type
) != NULL
)
2606 printfi_filtered (spaces
, "private_field_bits (%d bits at *",
2607 TYPE_NFIELDS (type
));
2608 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type
), gdb_stdout
);
2609 printf_filtered (")");
2610 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type
),
2611 TYPE_NFIELDS (type
));
2612 puts_filtered ("\n");
2614 if (TYPE_FIELD_PROTECTED_BITS (type
) != NULL
)
2616 printfi_filtered (spaces
, "protected_field_bits (%d bits at *",
2617 TYPE_NFIELDS (type
));
2618 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type
), gdb_stdout
);
2619 printf_filtered (")");
2620 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type
),
2621 TYPE_NFIELDS (type
));
2622 puts_filtered ("\n");
2625 if (TYPE_NFN_FIELDS (type
) > 0)
2627 dump_fn_fieldlists (type
, spaces
);
2631 static struct obstack dont_print_type_obstack
;
2634 recursive_dump_type (type
, spaces
)
2641 obstack_begin (&dont_print_type_obstack
, 0);
2643 if (TYPE_NFIELDS (type
) > 0
2644 || (TYPE_CPLUS_SPECIFIC (type
) && TYPE_NFN_FIELDS (type
) > 0))
2646 struct type
**first_dont_print
2647 = (struct type
**) obstack_base (&dont_print_type_obstack
);
2649 int i
= (struct type
**) obstack_next_free (&dont_print_type_obstack
)
2654 if (type
== first_dont_print
[i
])
2656 printfi_filtered (spaces
, "type node ");
2657 gdb_print_host_address (type
, gdb_stdout
);
2658 printf_filtered (" <same as already seen type>\n");
2663 obstack_ptr_grow (&dont_print_type_obstack
, type
);
2666 printfi_filtered (spaces
, "type node ");
2667 gdb_print_host_address (type
, gdb_stdout
);
2668 printf_filtered ("\n");
2669 printfi_filtered (spaces
, "name '%s' (",
2670 TYPE_NAME (type
) ? TYPE_NAME (type
) : "<NULL>");
2671 gdb_print_host_address (TYPE_NAME (type
), gdb_stdout
);
2672 printf_filtered (")\n");
2673 if (TYPE_TAG_NAME (type
) != NULL
)
2675 printfi_filtered (spaces
, "tagname '%s' (",
2676 TYPE_TAG_NAME (type
));
2677 gdb_print_host_address (TYPE_TAG_NAME (type
), gdb_stdout
);
2678 printf_filtered (")\n");
2680 printfi_filtered (spaces
, "code 0x%x ", TYPE_CODE (type
));
2681 switch (TYPE_CODE (type
))
2683 case TYPE_CODE_UNDEF
:
2684 printf_filtered ("(TYPE_CODE_UNDEF)");
2687 printf_filtered ("(TYPE_CODE_PTR)");
2689 case TYPE_CODE_ARRAY
:
2690 printf_filtered ("(TYPE_CODE_ARRAY)");
2692 case TYPE_CODE_STRUCT
:
2693 printf_filtered ("(TYPE_CODE_STRUCT)");
2695 case TYPE_CODE_UNION
:
2696 printf_filtered ("(TYPE_CODE_UNION)");
2698 case TYPE_CODE_ENUM
:
2699 printf_filtered ("(TYPE_CODE_ENUM)");
2701 case TYPE_CODE_FUNC
:
2702 printf_filtered ("(TYPE_CODE_FUNC)");
2705 printf_filtered ("(TYPE_CODE_INT)");
2708 printf_filtered ("(TYPE_CODE_FLT)");
2710 case TYPE_CODE_VOID
:
2711 printf_filtered ("(TYPE_CODE_VOID)");
2714 printf_filtered ("(TYPE_CODE_SET)");
2716 case TYPE_CODE_RANGE
:
2717 printf_filtered ("(TYPE_CODE_RANGE)");
2719 case TYPE_CODE_STRING
:
2720 printf_filtered ("(TYPE_CODE_STRING)");
2722 case TYPE_CODE_ERROR
:
2723 printf_filtered ("(TYPE_CODE_ERROR)");
2725 case TYPE_CODE_MEMBER
:
2726 printf_filtered ("(TYPE_CODE_MEMBER)");
2728 case TYPE_CODE_METHOD
:
2729 printf_filtered ("(TYPE_CODE_METHOD)");
2732 printf_filtered ("(TYPE_CODE_REF)");
2734 case TYPE_CODE_CHAR
:
2735 printf_filtered ("(TYPE_CODE_CHAR)");
2737 case TYPE_CODE_BOOL
:
2738 printf_filtered ("(TYPE_CODE_BOOL)");
2740 case TYPE_CODE_TYPEDEF
:
2741 printf_filtered ("(TYPE_CODE_TYPEDEF)");
2744 printf_filtered ("(UNKNOWN TYPE CODE)");
2747 puts_filtered ("\n");
2748 printfi_filtered (spaces
, "length %d\n", TYPE_LENGTH (type
));
2749 printfi_filtered (spaces
, "objfile ");
2750 gdb_print_host_address (TYPE_OBJFILE (type
), gdb_stdout
);
2751 printf_filtered ("\n");
2752 printfi_filtered (spaces
, "target_type ");
2753 gdb_print_host_address (TYPE_TARGET_TYPE (type
), gdb_stdout
);
2754 printf_filtered ("\n");
2755 if (TYPE_TARGET_TYPE (type
) != NULL
)
2757 recursive_dump_type (TYPE_TARGET_TYPE (type
), spaces
+ 2);
2759 printfi_filtered (spaces
, "pointer_type ");
2760 gdb_print_host_address (TYPE_POINTER_TYPE (type
), gdb_stdout
);
2761 printf_filtered ("\n");
2762 printfi_filtered (spaces
, "reference_type ");
2763 gdb_print_host_address (TYPE_REFERENCE_TYPE (type
), gdb_stdout
);
2764 printf_filtered ("\n");
2765 printfi_filtered (spaces
, "flags 0x%x", TYPE_FLAGS (type
));
2766 if (TYPE_FLAGS (type
) & TYPE_FLAG_UNSIGNED
)
2768 puts_filtered (" TYPE_FLAG_UNSIGNED");
2770 if (TYPE_FLAGS (type
) & TYPE_FLAG_STUB
)
2772 puts_filtered (" TYPE_FLAG_STUB");
2774 puts_filtered ("\n");
2775 printfi_filtered (spaces
, "nfields %d ", TYPE_NFIELDS (type
));
2776 gdb_print_host_address (TYPE_FIELDS (type
), gdb_stdout
);
2777 puts_filtered ("\n");
2778 for (idx
= 0; idx
< TYPE_NFIELDS (type
); idx
++)
2780 printfi_filtered (spaces
+ 2,
2781 "[%d] bitpos %d bitsize %d type ",
2782 idx
, TYPE_FIELD_BITPOS (type
, idx
),
2783 TYPE_FIELD_BITSIZE (type
, idx
));
2784 gdb_print_host_address (TYPE_FIELD_TYPE (type
, idx
), gdb_stdout
);
2785 printf_filtered (" name '%s' (",
2786 TYPE_FIELD_NAME (type
, idx
) != NULL
2787 ? TYPE_FIELD_NAME (type
, idx
)
2789 gdb_print_host_address (TYPE_FIELD_NAME (type
, idx
), gdb_stdout
);
2790 printf_filtered (")\n");
2791 if (TYPE_FIELD_TYPE (type
, idx
) != NULL
)
2793 recursive_dump_type (TYPE_FIELD_TYPE (type
, idx
), spaces
+ 4);
2796 printfi_filtered (spaces
, "vptr_basetype ");
2797 gdb_print_host_address (TYPE_VPTR_BASETYPE (type
), gdb_stdout
);
2798 puts_filtered ("\n");
2799 if (TYPE_VPTR_BASETYPE (type
) != NULL
)
2801 recursive_dump_type (TYPE_VPTR_BASETYPE (type
), spaces
+ 2);
2803 printfi_filtered (spaces
, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type
));
2804 switch (TYPE_CODE (type
))
2806 case TYPE_CODE_METHOD
:
2807 case TYPE_CODE_FUNC
:
2808 printfi_filtered (spaces
, "arg_types ");
2809 gdb_print_host_address (TYPE_ARG_TYPES (type
), gdb_stdout
);
2810 puts_filtered ("\n");
2811 print_arg_types (TYPE_ARG_TYPES (type
), spaces
);
2814 case TYPE_CODE_STRUCT
:
2815 printfi_filtered (spaces
, "cplus_stuff ");
2816 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type
), gdb_stdout
);
2817 puts_filtered ("\n");
2818 print_cplus_stuff (type
, spaces
);
2822 /* We have to pick one of the union types to be able print and test
2823 the value. Pick cplus_struct_type, even though we know it isn't
2824 any particular one. */
2825 printfi_filtered (spaces
, "type_specific ");
2826 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type
), gdb_stdout
);
2827 if (TYPE_CPLUS_SPECIFIC (type
) != NULL
)
2829 printf_filtered (" (unknown data form)");
2831 printf_filtered ("\n");
2836 obstack_free (&dont_print_type_obstack
, NULL
);
2839 static void build_gdbtypes
PARAMS ((void));
2844 init_type (TYPE_CODE_VOID
, 1,
2846 "void", (struct objfile
*) NULL
);
2848 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
2850 "char", (struct objfile
*) NULL
);
2851 TYPE_FLAGS (builtin_type_char
) |= TYPE_FLAG_NOSIGN
;
2852 builtin_type_true_char
=
2853 init_type (TYPE_CODE_CHAR
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
2855 "true character", (struct objfile
*) NULL
);
2856 builtin_type_signed_char
=
2857 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
2859 "signed char", (struct objfile
*) NULL
);
2860 builtin_type_unsigned_char
=
2861 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
2863 "unsigned char", (struct objfile
*) NULL
);
2864 builtin_type_short
=
2865 init_type (TYPE_CODE_INT
, TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
2867 "short", (struct objfile
*) NULL
);
2868 builtin_type_unsigned_short
=
2869 init_type (TYPE_CODE_INT
, TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
2871 "unsigned short", (struct objfile
*) NULL
);
2873 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
2875 "int", (struct objfile
*) NULL
);
2876 builtin_type_unsigned_int
=
2877 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
2879 "unsigned int", (struct objfile
*) NULL
);
2881 init_type (TYPE_CODE_INT
, TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
2883 "long", (struct objfile
*) NULL
);
2884 builtin_type_unsigned_long
=
2885 init_type (TYPE_CODE_INT
, TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
2887 "unsigned long", (struct objfile
*) NULL
);
2888 builtin_type_long_long
=
2889 init_type (TYPE_CODE_INT
, TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
2891 "long long", (struct objfile
*) NULL
);
2892 builtin_type_unsigned_long_long
=
2893 init_type (TYPE_CODE_INT
, TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
2895 "unsigned long long", (struct objfile
*) NULL
);
2896 builtin_type_float
=
2897 init_type (TYPE_CODE_FLT
, TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
2899 "float", (struct objfile
*) NULL
);
2900 builtin_type_double
=
2901 init_type (TYPE_CODE_FLT
, TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
2903 "double", (struct objfile
*) NULL
);
2904 builtin_type_long_double
=
2905 init_type (TYPE_CODE_FLT
, TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
2907 "long double", (struct objfile
*) NULL
);
2908 builtin_type_complex
=
2909 init_type (TYPE_CODE_COMPLEX
, 2 * TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
2911 "complex", (struct objfile
*) NULL
);
2912 TYPE_TARGET_TYPE (builtin_type_complex
) = builtin_type_float
;
2913 builtin_type_double_complex
=
2914 init_type (TYPE_CODE_COMPLEX
, 2 * TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
2916 "double complex", (struct objfile
*) NULL
);
2917 TYPE_TARGET_TYPE (builtin_type_double_complex
) = builtin_type_double
;
2918 builtin_type_string
=
2919 init_type (TYPE_CODE_STRING
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
2921 "string", (struct objfile
*) NULL
);
2923 init_type (TYPE_CODE_INT
, 8 / 8,
2925 "int8_t", (struct objfile
*) NULL
);
2926 builtin_type_uint8
=
2927 init_type (TYPE_CODE_INT
, 8 / 8,
2929 "uint8_t", (struct objfile
*) NULL
);
2930 builtin_type_int16
=
2931 init_type (TYPE_CODE_INT
, 16 / 8,
2933 "int16_t", (struct objfile
*) NULL
);
2934 builtin_type_uint16
=
2935 init_type (TYPE_CODE_INT
, 16 / 8,
2937 "uint16_t", (struct objfile
*) NULL
);
2938 builtin_type_int32
=
2939 init_type (TYPE_CODE_INT
, 32 / 8,
2941 "int32_t", (struct objfile
*) NULL
);
2942 builtin_type_uint32
=
2943 init_type (TYPE_CODE_INT
, 32 / 8,
2945 "uint32_t", (struct objfile
*) NULL
);
2946 builtin_type_int64
=
2947 init_type (TYPE_CODE_INT
, 64 / 8,
2949 "int64_t", (struct objfile
*) NULL
);
2950 builtin_type_uint64
=
2951 init_type (TYPE_CODE_INT
, 64 / 8,
2953 "uint64_t", (struct objfile
*) NULL
);
2955 init_type (TYPE_CODE_BOOL
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
2957 "bool", (struct objfile
*) NULL
);
2959 /* Add user knob for controlling resolution of opaque types */
2961 (add_set_cmd ("opaque-type-resolution", class_support
, var_boolean
, (char *) &opaque_type_resolution
,
2962 "Set resolution of opaque struct/class/union types (if set before loading symbols).",
2965 opaque_type_resolution
= 1;
2968 /* Build SIMD types. */
2970 = init_simd_type ("__builtin_v4sf", builtin_type_float
, "f", 4);
2974 extern void _initialize_gdbtypes
PARAMS ((void));
2976 _initialize_gdbtypes ()
2980 /* FIXME - For the moment, handle types by swapping them in and out.
2981 Should be using the per-architecture data-pointer and a large
2983 register_gdbarch_swap (&builtin_type_void
, sizeof (struct type
*), NULL
);
2984 register_gdbarch_swap (&builtin_type_char
, sizeof (struct type
*), NULL
);
2985 register_gdbarch_swap (&builtin_type_short
, sizeof (struct type
*), NULL
);
2986 register_gdbarch_swap (&builtin_type_int
, sizeof (struct type
*), NULL
);
2987 register_gdbarch_swap (&builtin_type_long
, sizeof (struct type
*), NULL
);
2988 register_gdbarch_swap (&builtin_type_long_long
, sizeof (struct type
*), NULL
);
2989 register_gdbarch_swap (&builtin_type_signed_char
, sizeof (struct type
*), NULL
);
2990 register_gdbarch_swap (&builtin_type_unsigned_char
, sizeof (struct type
*), NULL
);
2991 register_gdbarch_swap (&builtin_type_unsigned_short
, sizeof (struct type
*), NULL
);
2992 register_gdbarch_swap (&builtin_type_unsigned_int
, sizeof (struct type
*), NULL
);
2993 register_gdbarch_swap (&builtin_type_unsigned_long
, sizeof (struct type
*), NULL
);
2994 register_gdbarch_swap (&builtin_type_unsigned_long_long
, sizeof (struct type
*), NULL
);
2995 register_gdbarch_swap (&builtin_type_float
, sizeof (struct type
*), NULL
);
2996 register_gdbarch_swap (&builtin_type_double
, sizeof (struct type
*), NULL
);
2997 register_gdbarch_swap (&builtin_type_long_double
, sizeof (struct type
*), NULL
);
2998 register_gdbarch_swap (&builtin_type_complex
, sizeof (struct type
*), NULL
);
2999 register_gdbarch_swap (&builtin_type_double_complex
, sizeof (struct type
*), NULL
);
3000 register_gdbarch_swap (&builtin_type_string
, sizeof (struct type
*), NULL
);
3001 register_gdbarch_swap (&builtin_type_int8
, sizeof (struct type
*), NULL
);
3002 register_gdbarch_swap (&builtin_type_uint8
, sizeof (struct type
*), NULL
);
3003 register_gdbarch_swap (&builtin_type_int16
, sizeof (struct type
*), NULL
);
3004 register_gdbarch_swap (&builtin_type_uint16
, sizeof (struct type
*), NULL
);
3005 register_gdbarch_swap (&builtin_type_int32
, sizeof (struct type
*), NULL
);
3006 register_gdbarch_swap (&builtin_type_uint32
, sizeof (struct type
*), NULL
);
3007 register_gdbarch_swap (&builtin_type_int64
, sizeof (struct type
*), NULL
);
3008 register_gdbarch_swap (&builtin_type_uint64
, sizeof (struct type
*), NULL
);
3009 register_gdbarch_swap (&builtin_type_v4sf
, sizeof (struct type
*), NULL
);
3010 register_gdbarch_swap (NULL
, 0, build_gdbtypes
);