2003-09-11 Andrew Cagney <cagney@redhat.com>
[deliverable/binutils-gdb.git] / gdb / gdbtypes.c
CommitLineData
c906108c 1/* Support routines for manipulating internal types for GDB.
b5e5c35c 2 Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003
b6ba6518 3 Free Software Foundation, Inc.
c906108c
SS
4 Contributed by Cygnus Support, using pieces from other GDB modules.
5
c5aa993b 6 This file is part of GDB.
c906108c 7
c5aa993b
JM
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
c906108c 12
c5aa993b
JM
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
c906108c 17
c5aa993b
JM
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
c906108c
SS
22
23#include "defs.h"
24#include "gdb_string.h"
25#include "bfd.h"
26#include "symtab.h"
27#include "symfile.h"
28#include "objfiles.h"
29#include "gdbtypes.h"
30#include "expression.h"
31#include "language.h"
32#include "target.h"
33#include "value.h"
34#include "demangle.h"
35#include "complaints.h"
36#include "gdbcmd.h"
c91ecb25 37#include "wrapper.h"
015a42b4 38#include "cp-abi.h"
a02fd225 39#include "gdb_assert.h"
c906108c
SS
40
41/* These variables point to the objects
42 representing the predefined C data types. */
43
44struct type *builtin_type_void;
45struct type *builtin_type_char;
9e0b60a8 46struct type *builtin_type_true_char;
c906108c
SS
47struct type *builtin_type_short;
48struct type *builtin_type_int;
49struct type *builtin_type_long;
50struct type *builtin_type_long_long;
51struct type *builtin_type_signed_char;
52struct type *builtin_type_unsigned_char;
53struct type *builtin_type_unsigned_short;
54struct type *builtin_type_unsigned_int;
55struct type *builtin_type_unsigned_long;
56struct type *builtin_type_unsigned_long_long;
57struct type *builtin_type_float;
58struct type *builtin_type_double;
59struct type *builtin_type_long_double;
60struct type *builtin_type_complex;
61struct type *builtin_type_double_complex;
62struct type *builtin_type_string;
449a5da4 63struct type *builtin_type_int0;
c906108c
SS
64struct type *builtin_type_int8;
65struct type *builtin_type_uint8;
66struct type *builtin_type_int16;
67struct type *builtin_type_uint16;
68struct type *builtin_type_int32;
69struct type *builtin_type_uint32;
70struct type *builtin_type_int64;
71struct type *builtin_type_uint64;
8b982acf
EZ
72struct type *builtin_type_int128;
73struct type *builtin_type_uint128;
c906108c 74struct type *builtin_type_bool;
ac3aafc7
EZ
75
76/* 128 bit long vector types */
3139facc 77struct type *builtin_type_v2_double;
ac3aafc7 78struct type *builtin_type_v4_float;
3139facc 79struct type *builtin_type_v2_int64;
ac3aafc7
EZ
80struct type *builtin_type_v4_int32;
81struct type *builtin_type_v8_int16;
82struct type *builtin_type_v16_int8;
83/* 64 bit long vector types */
6599f021 84struct type *builtin_type_v2_float;
ac3aafc7
EZ
85struct type *builtin_type_v2_int32;
86struct type *builtin_type_v4_int16;
87struct type *builtin_type_v8_int8;
88
917317f4 89struct type *builtin_type_v4sf;
c2d11a7d 90struct type *builtin_type_v4si;
08cf96df 91struct type *builtin_type_v16qi;
c2d11a7d 92struct type *builtin_type_v8qi;
08cf96df 93struct type *builtin_type_v8hi;
c2d11a7d
JM
94struct type *builtin_type_v4hi;
95struct type *builtin_type_v2si;
b063e7a2
AC
96struct type *builtin_type_vec64;
97struct type *builtin_type_vec64i;
08cf96df 98struct type *builtin_type_vec128;
3139facc 99struct type *builtin_type_vec128i;
598f52df
AC
100struct type *builtin_type_ieee_single_big;
101struct type *builtin_type_ieee_single_little;
102struct type *builtin_type_ieee_double_big;
103struct type *builtin_type_ieee_double_little;
104struct type *builtin_type_ieee_double_littlebyte_bigword;
105struct type *builtin_type_i387_ext;
106struct type *builtin_type_m68881_ext;
107struct type *builtin_type_i960_ext;
108struct type *builtin_type_m88110_ext;
109struct type *builtin_type_m88110_harris_ext;
110struct type *builtin_type_arm_ext_big;
111struct type *builtin_type_arm_ext_littlebyte_bigword;
112struct type *builtin_type_ia64_spill_big;
113struct type *builtin_type_ia64_spill_little;
114struct type *builtin_type_ia64_quad_big;
115struct type *builtin_type_ia64_quad_little;
090a2205 116struct type *builtin_type_void_data_ptr;
ee3a7b7f 117struct type *builtin_type_void_func_ptr;
c4093a6a
JM
118struct type *builtin_type_CORE_ADDR;
119struct type *builtin_type_bfd_vma;
c906108c
SS
120
121int opaque_type_resolution = 1;
5d161b24 122int overload_debug = 0;
c906108c 123
c5aa993b
JM
124struct extra
125 {
126 char str[128];
127 int len;
8c990f3c 128 }; /* maximum extension is 128! FIXME */
c906108c 129
a14ed312
KB
130static void add_name (struct extra *, char *);
131static void add_mangled_type (struct extra *, struct type *);
25caa7a8
EZ
132#if 0 /* OBSOLETE CFront */
133// OBSOLETE static void cfront_mangle_name (struct type *, int, int);
134#endif /* OBSOLETE CFront */
a14ed312 135static void print_bit_vector (B_TYPE *, int);
ad2f7632 136static void print_arg_types (struct field *, int, int);
a14ed312
KB
137static void dump_fn_fieldlists (struct type *, int);
138static void print_cplus_stuff (struct type *, int);
139static void virtual_base_list_aux (struct type *dclass);
7a292a7a 140
c906108c
SS
141
142/* Alloc a new type structure and fill it with some defaults. If
143 OBJFILE is non-NULL, then allocate the space for the type structure
2fdde8f8
DJ
144 in that objfile's type_obstack. Otherwise allocate the new type structure
145 by xmalloc () (for permanent types). */
c906108c
SS
146
147struct type *
fba45db2 148alloc_type (struct objfile *objfile)
c906108c
SS
149{
150 register struct type *type;
151
152 /* Alloc the structure and start off with all fields zeroed. */
153
154 if (objfile == NULL)
155 {
2fdde8f8
DJ
156 type = xmalloc (sizeof (struct type));
157 memset (type, 0, sizeof (struct type));
158 TYPE_MAIN_TYPE (type) = xmalloc (sizeof (struct main_type));
c906108c
SS
159 }
160 else
161 {
2fdde8f8
DJ
162 type = obstack_alloc (&objfile->type_obstack,
163 sizeof (struct type));
164 memset (type, 0, sizeof (struct type));
165 TYPE_MAIN_TYPE (type) = obstack_alloc (&objfile->type_obstack,
166 sizeof (struct main_type));
c906108c
SS
167 OBJSTAT (objfile, n_types++);
168 }
2fdde8f8 169 memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type));
c906108c
SS
170
171 /* Initialize the fields that might not be zero. */
172
173 TYPE_CODE (type) = TYPE_CODE_UNDEF;
174 TYPE_OBJFILE (type) = objfile;
175 TYPE_VPTR_FIELDNO (type) = -1;
2fdde8f8 176 TYPE_CHAIN (type) = type; /* Chain back to itself. */
c906108c
SS
177
178 return (type);
179}
180
2fdde8f8
DJ
181/* Alloc a new type instance structure, fill it with some defaults,
182 and point it at OLDTYPE. Allocate the new type instance from the
183 same place as OLDTYPE. */
184
185static struct type *
186alloc_type_instance (struct type *oldtype)
187{
188 struct type *type;
189
190 /* Allocate the structure. */
191
192 if (TYPE_OBJFILE (oldtype) == NULL)
193 {
194 type = xmalloc (sizeof (struct type));
195 memset (type, 0, sizeof (struct type));
196 }
197 else
198 {
199 type = obstack_alloc (&TYPE_OBJFILE (oldtype)->type_obstack,
200 sizeof (struct type));
201 memset (type, 0, sizeof (struct type));
202 }
203 TYPE_MAIN_TYPE (type) = TYPE_MAIN_TYPE (oldtype);
204
205 TYPE_CHAIN (type) = type; /* Chain back to itself for now. */
206
207 return (type);
208}
209
210/* Clear all remnants of the previous type at TYPE, in preparation for
211 replacing it with something else. */
212static void
213smash_type (struct type *type)
214{
215 memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type));
216
217 /* For now, delete the rings. */
218 TYPE_CHAIN (type) = type;
219
220 /* For now, leave the pointer/reference types alone. */
221}
222
c906108c
SS
223/* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
224 to a pointer to memory where the pointer type should be stored.
225 If *TYPEPTR is zero, update it to point to the pointer type we return.
226 We allocate new memory if needed. */
227
228struct type *
fba45db2 229make_pointer_type (struct type *type, struct type **typeptr)
c906108c 230{
c5aa993b 231 register struct type *ntype; /* New type */
c906108c
SS
232 struct objfile *objfile;
233
234 ntype = TYPE_POINTER_TYPE (type);
235
c5aa993b 236 if (ntype)
c906108c 237 {
c5aa993b
JM
238 if (typeptr == 0)
239 return ntype; /* Don't care about alloc, and have new type. */
c906108c 240 else if (*typeptr == 0)
c5aa993b 241 {
c906108c
SS
242 *typeptr = ntype; /* Tracking alloc, and we have new type. */
243 return ntype;
c5aa993b 244 }
c906108c
SS
245 }
246
247 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
248 {
249 ntype = alloc_type (TYPE_OBJFILE (type));
250 if (typeptr)
251 *typeptr = ntype;
252 }
c5aa993b
JM
253 else
254 /* We have storage, but need to reset it. */
c906108c
SS
255 {
256 ntype = *typeptr;
257 objfile = TYPE_OBJFILE (ntype);
2fdde8f8 258 smash_type (ntype);
c906108c
SS
259 TYPE_OBJFILE (ntype) = objfile;
260 }
261
262 TYPE_TARGET_TYPE (ntype) = type;
263 TYPE_POINTER_TYPE (type) = ntype;
264
265 /* FIXME! Assume the machine has only one representation for pointers! */
266
267 TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
268 TYPE_CODE (ntype) = TYPE_CODE_PTR;
269
67b2adb2
AC
270 /* Mark pointers as unsigned. The target converts between pointers
271 and addresses (CORE_ADDRs) using POINTER_TO_ADDRESS() and
272 ADDRESS_TO_POINTER(). */
c906108c 273 TYPE_FLAGS (ntype) |= TYPE_FLAG_UNSIGNED;
c5aa993b 274
c906108c
SS
275 if (!TYPE_POINTER_TYPE (type)) /* Remember it, if don't have one. */
276 TYPE_POINTER_TYPE (type) = ntype;
277
278 return ntype;
279}
280
281/* Given a type TYPE, return a type of pointers to that type.
282 May need to construct such a type if this is the first use. */
283
284struct type *
fba45db2 285lookup_pointer_type (struct type *type)
c906108c 286{
c5aa993b 287 return make_pointer_type (type, (struct type **) 0);
c906108c
SS
288}
289
290/* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero, points
291 to a pointer to memory where the reference type should be stored.
292 If *TYPEPTR is zero, update it to point to the reference type we return.
293 We allocate new memory if needed. */
294
295struct type *
fba45db2 296make_reference_type (struct type *type, struct type **typeptr)
c906108c 297{
c5aa993b 298 register struct type *ntype; /* New type */
c906108c
SS
299 struct objfile *objfile;
300
301 ntype = TYPE_REFERENCE_TYPE (type);
302
c5aa993b 303 if (ntype)
c906108c 304 {
c5aa993b
JM
305 if (typeptr == 0)
306 return ntype; /* Don't care about alloc, and have new type. */
c906108c 307 else if (*typeptr == 0)
c5aa993b 308 {
c906108c
SS
309 *typeptr = ntype; /* Tracking alloc, and we have new type. */
310 return ntype;
c5aa993b 311 }
c906108c
SS
312 }
313
314 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
315 {
316 ntype = alloc_type (TYPE_OBJFILE (type));
317 if (typeptr)
318 *typeptr = ntype;
319 }
c5aa993b
JM
320 else
321 /* We have storage, but need to reset it. */
c906108c
SS
322 {
323 ntype = *typeptr;
324 objfile = TYPE_OBJFILE (ntype);
2fdde8f8 325 smash_type (ntype);
c906108c
SS
326 TYPE_OBJFILE (ntype) = objfile;
327 }
328
329 TYPE_TARGET_TYPE (ntype) = type;
330 TYPE_REFERENCE_TYPE (type) = ntype;
331
332 /* FIXME! Assume the machine has only one representation for references,
333 and that it matches the (only) representation for pointers! */
334
335 TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
336 TYPE_CODE (ntype) = TYPE_CODE_REF;
c5aa993b 337
c906108c
SS
338 if (!TYPE_REFERENCE_TYPE (type)) /* Remember it, if don't have one. */
339 TYPE_REFERENCE_TYPE (type) = ntype;
340
341 return ntype;
342}
343
344/* Same as above, but caller doesn't care about memory allocation details. */
345
346struct type *
fba45db2 347lookup_reference_type (struct type *type)
c906108c 348{
c5aa993b 349 return make_reference_type (type, (struct type **) 0);
c906108c
SS
350}
351
352/* Lookup a function type that returns type TYPE. TYPEPTR, if nonzero, points
353 to a pointer to memory where the function type should be stored.
354 If *TYPEPTR is zero, update it to point to the function type we return.
355 We allocate new memory if needed. */
356
357struct type *
fba45db2 358make_function_type (struct type *type, struct type **typeptr)
c906108c 359{
c5aa993b 360 register struct type *ntype; /* New type */
c906108c
SS
361 struct objfile *objfile;
362
363 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
364 {
365 ntype = alloc_type (TYPE_OBJFILE (type));
366 if (typeptr)
367 *typeptr = ntype;
368 }
c5aa993b
JM
369 else
370 /* We have storage, but need to reset it. */
c906108c
SS
371 {
372 ntype = *typeptr;
373 objfile = TYPE_OBJFILE (ntype);
2fdde8f8 374 smash_type (ntype);
c906108c
SS
375 TYPE_OBJFILE (ntype) = objfile;
376 }
377
378 TYPE_TARGET_TYPE (ntype) = type;
379
380 TYPE_LENGTH (ntype) = 1;
381 TYPE_CODE (ntype) = TYPE_CODE_FUNC;
c5aa993b 382
c906108c
SS
383 return ntype;
384}
385
386
387/* Given a type TYPE, return a type of functions that return that type.
388 May need to construct such a type if this is the first use. */
389
390struct type *
fba45db2 391lookup_function_type (struct type *type)
c906108c 392{
c5aa993b 393 return make_function_type (type, (struct type **) 0);
c906108c
SS
394}
395
47663de5
MS
396/* Identify address space identifier by name --
397 return the integer flag defined in gdbtypes.h. */
398extern int
399address_space_name_to_int (char *space_identifier)
400{
5f11f355 401 struct gdbarch *gdbarch = current_gdbarch;
8b2dbe47 402 int type_flags;
47663de5
MS
403 /* Check for known address space delimiters. */
404 if (!strcmp (space_identifier, "code"))
405 return TYPE_FLAG_CODE_SPACE;
406 else if (!strcmp (space_identifier, "data"))
407 return TYPE_FLAG_DATA_SPACE;
5f11f355
AC
408 else if (gdbarch_address_class_name_to_type_flags_p (gdbarch)
409 && gdbarch_address_class_name_to_type_flags (gdbarch,
410 space_identifier,
411 &type_flags))
8b2dbe47 412 return type_flags;
47663de5
MS
413 else
414 error ("Unknown address space specifier: \"%s\"", space_identifier);
415}
416
417/* Identify address space identifier by integer flag as defined in
418 gdbtypes.h -- return the string version of the adress space name. */
419
321432c0 420const char *
47663de5
MS
421address_space_int_to_name (int space_flag)
422{
5f11f355 423 struct gdbarch *gdbarch = current_gdbarch;
47663de5
MS
424 if (space_flag & TYPE_FLAG_CODE_SPACE)
425 return "code";
426 else if (space_flag & TYPE_FLAG_DATA_SPACE)
427 return "data";
8b2dbe47 428 else if ((space_flag & TYPE_FLAG_ADDRESS_CLASS_ALL)
5f11f355
AC
429 && gdbarch_address_class_type_flags_to_name_p (gdbarch))
430 return gdbarch_address_class_type_flags_to_name (gdbarch, space_flag);
47663de5
MS
431 else
432 return NULL;
433}
434
2fdde8f8
DJ
435/* Create a new type with instance flags NEW_FLAGS, based on TYPE.
436 If STORAGE is non-NULL, create the new type instance there. */
47663de5 437
b9362cc7 438static struct type *
2fdde8f8
DJ
439make_qualified_type (struct type *type, int new_flags,
440 struct type *storage)
47663de5
MS
441{
442 struct type *ntype;
443
444 ntype = type;
445 do {
2fdde8f8 446 if (TYPE_INSTANCE_FLAGS (ntype) == new_flags)
47663de5 447 return ntype;
2fdde8f8 448 ntype = TYPE_CHAIN (ntype);
47663de5
MS
449 } while (ntype != type);
450
2fdde8f8
DJ
451 /* Create a new type instance. */
452 if (storage == NULL)
453 ntype = alloc_type_instance (type);
454 else
455 {
456 ntype = storage;
457 TYPE_MAIN_TYPE (ntype) = TYPE_MAIN_TYPE (type);
458 TYPE_CHAIN (ntype) = ntype;
459 }
47663de5
MS
460
461 /* Pointers or references to the original type are not relevant to
2fdde8f8 462 the new type. */
47663de5
MS
463 TYPE_POINTER_TYPE (ntype) = (struct type *) 0;
464 TYPE_REFERENCE_TYPE (ntype) = (struct type *) 0;
47663de5 465
2fdde8f8
DJ
466 /* Chain the new qualified type to the old type. */
467 TYPE_CHAIN (ntype) = TYPE_CHAIN (type);
468 TYPE_CHAIN (type) = ntype;
469
470 /* Now set the instance flags and return the new type. */
471 TYPE_INSTANCE_FLAGS (ntype) = new_flags;
47663de5 472
ab5d3da6
KB
473 /* Set length of new type to that of the original type. */
474 TYPE_LENGTH (ntype) = TYPE_LENGTH (type);
475
47663de5
MS
476 return ntype;
477}
478
2fdde8f8
DJ
479/* Make an address-space-delimited variant of a type -- a type that
480 is identical to the one supplied except that it has an address
481 space attribute attached to it (such as "code" or "data").
482
8b2dbe47
KB
483 The space attributes "code" and "data" are for Harvard architectures.
484 The address space attributes are for architectures which have
485 alternately sized pointers or pointers with alternate representations. */
2fdde8f8
DJ
486
487struct type *
488make_type_with_address_space (struct type *type, int space_flag)
489{
490 struct type *ntype;
491 int new_flags = ((TYPE_INSTANCE_FLAGS (type)
8b2dbe47
KB
492 & ~(TYPE_FLAG_CODE_SPACE | TYPE_FLAG_DATA_SPACE
493 | TYPE_FLAG_ADDRESS_CLASS_ALL))
2fdde8f8
DJ
494 | space_flag);
495
496 return make_qualified_type (type, new_flags, NULL);
497}
c906108c
SS
498
499/* Make a "c-v" variant of a type -- a type that is identical to the
500 one supplied except that it may have const or volatile attributes
501 CNST is a flag for setting the const attribute
502 VOLTL is a flag for setting the volatile attribute
503 TYPE is the base type whose variant we are creating.
504 TYPEPTR, if nonzero, points
505 to a pointer to memory where the reference type should be stored.
506 If *TYPEPTR is zero, update it to point to the reference type we return.
507 We allocate new memory if needed. */
508
509struct type *
fba45db2 510make_cv_type (int cnst, int voltl, struct type *type, struct type **typeptr)
c906108c 511{
c5aa993b
JM
512 register struct type *ntype; /* New type */
513 register struct type *tmp_type = type; /* tmp type */
c906108c
SS
514 struct objfile *objfile;
515
2fdde8f8
DJ
516 int new_flags = (TYPE_INSTANCE_FLAGS (type)
517 & ~(TYPE_FLAG_CONST | TYPE_FLAG_VOLATILE));
c906108c 518
c906108c 519 if (cnst)
2fdde8f8 520 new_flags |= TYPE_FLAG_CONST;
c906108c
SS
521
522 if (voltl)
2fdde8f8 523 new_flags |= TYPE_FLAG_VOLATILE;
a02fd225 524
2fdde8f8 525 if (typeptr && *typeptr != NULL)
a02fd225 526 {
2fdde8f8
DJ
527 /* Objfile is per-core-type. This const-qualified type had best
528 belong to the same objfile as the type it is qualifying, unless
529 we are overwriting a stub type, in which case the safest thing
530 to do is to copy the core type into the new objfile. */
a02fd225 531
2fdde8f8
DJ
532 gdb_assert (TYPE_OBJFILE (*typeptr) == TYPE_OBJFILE (type)
533 || TYPE_STUB (*typeptr));
534 if (TYPE_OBJFILE (*typeptr) != TYPE_OBJFILE (type))
535 {
536 TYPE_MAIN_TYPE (*typeptr)
537 = TYPE_ALLOC (*typeptr, sizeof (struct main_type));
538 *TYPE_MAIN_TYPE (*typeptr)
539 = *TYPE_MAIN_TYPE (type);
540 }
541 }
542
543 ntype = make_qualified_type (type, new_flags, typeptr ? *typeptr : NULL);
c906108c 544
2fdde8f8
DJ
545 if (typeptr != NULL)
546 *typeptr = ntype;
a02fd225 547
2fdde8f8 548 return ntype;
a02fd225 549}
c906108c 550
2fdde8f8
DJ
551/* Replace the contents of ntype with the type *type. This changes the
552 contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus
553 the changes are propogated to all types in the TYPE_CHAIN.
dd6bda65 554
cda6c68a
JB
555 In order to build recursive types, it's inevitable that we'll need
556 to update types in place --- but this sort of indiscriminate
557 smashing is ugly, and needs to be replaced with something more
2fdde8f8
DJ
558 controlled. TYPE_MAIN_TYPE is a step in this direction; it's not
559 clear if more steps are needed. */
dd6bda65
DJ
560void
561replace_type (struct type *ntype, struct type *type)
562{
ab5d3da6 563 struct type *chain;
dd6bda65 564
2fdde8f8 565 *TYPE_MAIN_TYPE (ntype) = *TYPE_MAIN_TYPE (type);
dd6bda65 566
ab5d3da6
KB
567 /* The type length is not a part of the main type. Update it for each
568 type on the variant chain. */
569 chain = ntype;
570 do {
571 /* Assert that this element of the chain has no address-class bits
572 set in its flags. Such type variants might have type lengths
573 which are supposed to be different from the non-address-class
574 variants. This assertion shouldn't ever be triggered because
575 symbol readers which do construct address-class variants don't
576 call replace_type(). */
577 gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain) == 0);
578
579 TYPE_LENGTH (ntype) = TYPE_LENGTH (type);
580 chain = TYPE_CHAIN (chain);
581 } while (ntype != chain);
582
2fdde8f8
DJ
583 /* Assert that the two types have equivalent instance qualifiers.
584 This should be true for at least all of our debug readers. */
585 gdb_assert (TYPE_INSTANCE_FLAGS (ntype) == TYPE_INSTANCE_FLAGS (type));
dd6bda65
DJ
586}
587
c906108c
SS
588/* Implement direct support for MEMBER_TYPE in GNU C++.
589 May need to construct such a type if this is the first use.
590 The TYPE is the type of the member. The DOMAIN is the type
591 of the aggregate that the member belongs to. */
592
593struct type *
fba45db2 594lookup_member_type (struct type *type, struct type *domain)
c906108c
SS
595{
596 register struct type *mtype;
597
598 mtype = alloc_type (TYPE_OBJFILE (type));
599 smash_to_member_type (mtype, domain, type);
600 return (mtype);
601}
602
7b83ea04 603/* Allocate a stub method whose return type is TYPE.
c906108c
SS
604 This apparently happens for speed of symbol reading, since parsing
605 out the arguments to the method is cpu-intensive, the way we are doing
606 it. So, we will fill in arguments later.
607 This always returns a fresh type. */
608
609struct type *
fba45db2 610allocate_stub_method (struct type *type)
c906108c
SS
611{
612 struct type *mtype;
613
7e956337
FF
614 mtype = init_type (TYPE_CODE_METHOD, 1, TYPE_FLAG_STUB, NULL,
615 TYPE_OBJFILE (type));
c906108c
SS
616 TYPE_TARGET_TYPE (mtype) = type;
617 /* _DOMAIN_TYPE (mtype) = unknown yet */
c906108c
SS
618 return (mtype);
619}
620
621/* Create a range type using either a blank type supplied in RESULT_TYPE,
622 or creating a new type, inheriting the objfile from INDEX_TYPE.
623
624 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND to
625 HIGH_BOUND, inclusive.
626
627 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
628 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
629
630struct type *
fba45db2
KB
631create_range_type (struct type *result_type, struct type *index_type,
632 int low_bound, int high_bound)
c906108c
SS
633{
634 if (result_type == NULL)
635 {
636 result_type = alloc_type (TYPE_OBJFILE (index_type));
637 }
638 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
639 TYPE_TARGET_TYPE (result_type) = index_type;
74a9bb82 640 if (TYPE_STUB (index_type))
c906108c
SS
641 TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB;
642 else
643 TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
644 TYPE_NFIELDS (result_type) = 2;
645 TYPE_FIELDS (result_type) = (struct field *)
646 TYPE_ALLOC (result_type, 2 * sizeof (struct field));
647 memset (TYPE_FIELDS (result_type), 0, 2 * sizeof (struct field));
648 TYPE_FIELD_BITPOS (result_type, 0) = low_bound;
649 TYPE_FIELD_BITPOS (result_type, 1) = high_bound;
c5aa993b
JM
650 TYPE_FIELD_TYPE (result_type, 0) = builtin_type_int; /* FIXME */
651 TYPE_FIELD_TYPE (result_type, 1) = builtin_type_int; /* FIXME */
c906108c 652
c5aa993b 653 if (low_bound >= 0)
c906108c
SS
654 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
655
656 return (result_type);
657}
658
659/* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type TYPE.
660 Return 1 of type is a range type, 0 if it is discrete (and bounds
661 will fit in LONGEST), or -1 otherwise. */
662
663int
fba45db2 664get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
c906108c
SS
665{
666 CHECK_TYPEDEF (type);
667 switch (TYPE_CODE (type))
668 {
669 case TYPE_CODE_RANGE:
670 *lowp = TYPE_LOW_BOUND (type);
671 *highp = TYPE_HIGH_BOUND (type);
672 return 1;
673 case TYPE_CODE_ENUM:
674 if (TYPE_NFIELDS (type) > 0)
675 {
676 /* The enums may not be sorted by value, so search all
677 entries */
678 int i;
679
680 *lowp = *highp = TYPE_FIELD_BITPOS (type, 0);
681 for (i = 0; i < TYPE_NFIELDS (type); i++)
682 {
683 if (TYPE_FIELD_BITPOS (type, i) < *lowp)
684 *lowp = TYPE_FIELD_BITPOS (type, i);
685 if (TYPE_FIELD_BITPOS (type, i) > *highp)
686 *highp = TYPE_FIELD_BITPOS (type, i);
687 }
688
689 /* Set unsigned indicator if warranted. */
c5aa993b 690 if (*lowp >= 0)
c906108c
SS
691 {
692 TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
693 }
694 }
695 else
696 {
697 *lowp = 0;
698 *highp = -1;
699 }
700 return 0;
701 case TYPE_CODE_BOOL:
702 *lowp = 0;
703 *highp = 1;
704 return 0;
705 case TYPE_CODE_INT:
c5aa993b 706 if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */
c906108c
SS
707 return -1;
708 if (!TYPE_UNSIGNED (type))
709 {
c5aa993b 710 *lowp = -(1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1));
c906108c
SS
711 *highp = -*lowp - 1;
712 return 0;
713 }
714 /* ... fall through for unsigned ints ... */
715 case TYPE_CODE_CHAR:
716 *lowp = 0;
717 /* This round-about calculation is to avoid shifting by
7b83ea04
AC
718 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
719 if TYPE_LENGTH (type) == sizeof (LONGEST). */
c906108c
SS
720 *highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1);
721 *highp = (*highp - 1) | *highp;
722 return 0;
723 default:
724 return -1;
725 }
726}
727
728/* Create an array type using either a blank type supplied in RESULT_TYPE,
729 or creating a new type, inheriting the objfile from RANGE_TYPE.
730
731 Elements will be of type ELEMENT_TYPE, the indices will be of type
732 RANGE_TYPE.
733
734 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
735 sure it is TYPE_CODE_UNDEF before we bash it into an array type? */
736
737struct type *
fba45db2
KB
738create_array_type (struct type *result_type, struct type *element_type,
739 struct type *range_type)
c906108c
SS
740{
741 LONGEST low_bound, high_bound;
742
743 if (result_type == NULL)
744 {
745 result_type = alloc_type (TYPE_OBJFILE (range_type));
746 }
747 TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
748 TYPE_TARGET_TYPE (result_type) = element_type;
749 if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
750 low_bound = high_bound = 0;
751 CHECK_TYPEDEF (element_type);
752 TYPE_LENGTH (result_type) =
753 TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
754 TYPE_NFIELDS (result_type) = 1;
755 TYPE_FIELDS (result_type) =
756 (struct field *) TYPE_ALLOC (result_type, sizeof (struct field));
757 memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
758 TYPE_FIELD_TYPE (result_type, 0) = range_type;
759 TYPE_VPTR_FIELDNO (result_type) = -1;
760
761 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
762 if (TYPE_LENGTH (result_type) == 0)
763 TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB;
764
765 return (result_type);
766}
767
768/* Create a string type using either a blank type supplied in RESULT_TYPE,
769 or creating a new type. String types are similar enough to array of
770 char types that we can use create_array_type to build the basic type
771 and then bash it into a string type.
772
773 For fixed length strings, the range type contains 0 as the lower
774 bound and the length of the string minus one as the upper bound.
775
776 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
777 sure it is TYPE_CODE_UNDEF before we bash it into a string type? */
778
779struct type *
fba45db2 780create_string_type (struct type *result_type, struct type *range_type)
c906108c
SS
781{
782 result_type = create_array_type (result_type,
783 *current_language->string_char_type,
784 range_type);
785 TYPE_CODE (result_type) = TYPE_CODE_STRING;
786 return (result_type);
787}
788
789struct type *
fba45db2 790create_set_type (struct type *result_type, struct type *domain_type)
c906108c
SS
791{
792 LONGEST low_bound, high_bound, bit_length;
793 if (result_type == NULL)
794 {
795 result_type = alloc_type (TYPE_OBJFILE (domain_type));
796 }
797 TYPE_CODE (result_type) = TYPE_CODE_SET;
798 TYPE_NFIELDS (result_type) = 1;
799 TYPE_FIELDS (result_type) = (struct field *)
800 TYPE_ALLOC (result_type, 1 * sizeof (struct field));
801 memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
802
74a9bb82 803 if (!TYPE_STUB (domain_type))
c906108c
SS
804 {
805 if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0)
806 low_bound = high_bound = 0;
807 bit_length = high_bound - low_bound + 1;
808 TYPE_LENGTH (result_type)
809 = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
810 }
811 TYPE_FIELD_TYPE (result_type, 0) = domain_type;
812
c5aa993b 813 if (low_bound >= 0)
c906108c
SS
814 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
815
816 return (result_type);
817}
818
917317f4
JM
819/* Construct and return a type of the form:
820 struct NAME { ELT_TYPE ELT_NAME[N]; }
821 We use these types for SIMD registers. For example, the type of
822 the SSE registers on the late x86-family processors is:
823 struct __builtin_v4sf { float f[4]; }
824 built by the function call:
825 init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4)
826 The type returned is a permanent type, allocated using malloc; it
827 doesn't live in any objfile's obstack. */
c2d11a7d 828static struct type *
917317f4
JM
829init_simd_type (char *name,
830 struct type *elt_type,
831 char *elt_name,
832 int n)
833{
73d322b1
EZ
834 struct type *simd_type;
835 struct type *array_type;
836
837 simd_type = init_composite_type (name, TYPE_CODE_STRUCT);
838 array_type = create_array_type (0, elt_type,
839 create_range_type (0, builtin_type_int,
840 0, n-1));
841 append_composite_type_field (simd_type, elt_name, array_type);
842 return simd_type;
917317f4
JM
843}
844
ac3aafc7
EZ
845static struct type *
846init_vector_type (struct type *elt_type, int n)
847{
848 struct type *array_type;
849
850 array_type = create_array_type (0, elt_type,
851 create_range_type (0, builtin_type_int,
852 0, n-1));
853 TYPE_FLAGS (array_type) |= TYPE_FLAG_VECTOR;
854 return array_type;
855}
856
b063e7a2
AC
857static struct type *
858build_builtin_type_vec64 (void)
859{
860 /* Construct a type for the 64 bit registers. The type we're
861 building is this: */
862#if 0
863 union __gdb_builtin_type_vec64
864 {
865 int64_t uint64;
866 float v2_float[2];
867 int32_t v2_int32[2];
868 int16_t v4_int16[4];
869 int8_t v8_int8[8];
870 };
871#endif
872
873 struct type *t;
874
875 t = init_composite_type ("__gdb_builtin_type_vec64", TYPE_CODE_UNION);
876 append_composite_type_field (t, "uint64", builtin_type_int64);
877 append_composite_type_field (t, "v2_float", builtin_type_v2_float);
878 append_composite_type_field (t, "v2_int32", builtin_type_v2_int32);
879 append_composite_type_field (t, "v4_int16", builtin_type_v4_int16);
880 append_composite_type_field (t, "v8_int8", builtin_type_v8_int8);
881
882 TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR;
216b504f 883 TYPE_NAME (t) = "builtin_type_vec64";
b063e7a2
AC
884 return t;
885}
886
887static struct type *
888build_builtin_type_vec64i (void)
889{
890 /* Construct a type for the 64 bit registers. The type we're
891 building is this: */
892#if 0
893 union __gdb_builtin_type_vec64i
894 {
895 int64_t uint64;
896 int32_t v2_int32[2];
897 int16_t v4_int16[4];
898 int8_t v8_int8[8];
899 };
900#endif
901
902 struct type *t;
903
904 t = init_composite_type ("__gdb_builtin_type_vec64i", TYPE_CODE_UNION);
905 append_composite_type_field (t, "uint64", builtin_type_int64);
906 append_composite_type_field (t, "v2_int32", builtin_type_v2_int32);
907 append_composite_type_field (t, "v4_int16", builtin_type_v4_int16);
908 append_composite_type_field (t, "v8_int8", builtin_type_v8_int8);
909
910 TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR;
216b504f 911 TYPE_NAME (t) = "builtin_type_vec64i";
b063e7a2
AC
912 return t;
913}
914
08cf96df
EZ
915static struct type *
916build_builtin_type_vec128 (void)
917{
918 /* Construct a type for the 128 bit registers. The type we're
919 building is this: */
920#if 0
ac3aafc7 921 union __gdb_builtin_type_vec128
08cf96df 922 {
ac3aafc7
EZ
923 int128_t uint128;
924 float v4_float[4];
925 int32_t v4_int32[4];
926 int16_t v8_int16[8];
927 int8_t v16_int8[16];
08cf96df
EZ
928 };
929#endif
930
931 struct type *t;
08cf96df 932
73d322b1
EZ
933 t = init_composite_type ("__gdb_builtin_type_vec128", TYPE_CODE_UNION);
934 append_composite_type_field (t, "uint128", builtin_type_int128);
ac3aafc7
EZ
935 append_composite_type_field (t, "v4_float", builtin_type_v4_float);
936 append_composite_type_field (t, "v4_int32", builtin_type_v4_int32);
937 append_composite_type_field (t, "v8_int16", builtin_type_v8_int16);
938 append_composite_type_field (t, "v16_int8", builtin_type_v16_int8);
08cf96df 939
b063e7a2 940 TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR;
216b504f 941 TYPE_NAME (t) = "builtin_type_vec128";
08cf96df
EZ
942 return t;
943}
917317f4 944
3139facc
MH
945static struct type *
946build_builtin_type_vec128i (void)
947{
948 /* 128-bit Intel SIMD registers */
949 struct type *t;
950
951 t = init_composite_type ("__gdb_builtin_type_vec128i", TYPE_CODE_UNION);
952 append_composite_type_field (t, "v4_float", builtin_type_v4_float);
953 append_composite_type_field (t, "v2_double", builtin_type_v2_double);
954 append_composite_type_field (t, "v16_int8", builtin_type_v16_int8);
955 append_composite_type_field (t, "v8_int16", builtin_type_v8_int16);
956 append_composite_type_field (t, "v4_int32", builtin_type_v4_int32);
957 append_composite_type_field (t, "v2_int64", builtin_type_v2_int64);
958 append_composite_type_field (t, "uint128", builtin_type_int128);
959
b063e7a2 960 TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR;
216b504f 961 TYPE_NAME (t) = "builtin_type_vec128i";
3139facc
MH
962 return t;
963}
964
7b83ea04 965/* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE.
c906108c
SS
966 A MEMBER is a wierd thing -- it amounts to a typed offset into
967 a struct, e.g. "an int at offset 8". A MEMBER TYPE doesn't
968 include the offset (that's the value of the MEMBER itself), but does
969 include the structure type into which it points (for some reason).
970
971 When "smashing" the type, we preserve the objfile that the
972 old type pointed to, since we aren't changing where the type is actually
973 allocated. */
974
975void
fba45db2
KB
976smash_to_member_type (struct type *type, struct type *domain,
977 struct type *to_type)
c906108c
SS
978{
979 struct objfile *objfile;
980
981 objfile = TYPE_OBJFILE (type);
982
2fdde8f8 983 smash_type (type);
c906108c
SS
984 TYPE_OBJFILE (type) = objfile;
985 TYPE_TARGET_TYPE (type) = to_type;
986 TYPE_DOMAIN_TYPE (type) = domain;
987 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
988 TYPE_CODE (type) = TYPE_CODE_MEMBER;
989}
990
991/* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
992 METHOD just means `function that gets an extra "this" argument'.
993
994 When "smashing" the type, we preserve the objfile that the
995 old type pointed to, since we aren't changing where the type is actually
996 allocated. */
997
998void
fba45db2 999smash_to_method_type (struct type *type, struct type *domain,
ad2f7632
DJ
1000 struct type *to_type, struct field *args,
1001 int nargs, int varargs)
c906108c
SS
1002{
1003 struct objfile *objfile;
1004
1005 objfile = TYPE_OBJFILE (type);
1006
2fdde8f8 1007 smash_type (type);
c906108c
SS
1008 TYPE_OBJFILE (type) = objfile;
1009 TYPE_TARGET_TYPE (type) = to_type;
1010 TYPE_DOMAIN_TYPE (type) = domain;
ad2f7632
DJ
1011 TYPE_FIELDS (type) = args;
1012 TYPE_NFIELDS (type) = nargs;
1013 if (varargs)
1014 TYPE_FLAGS (type) |= TYPE_FLAG_VARARGS;
c906108c
SS
1015 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
1016 TYPE_CODE (type) = TYPE_CODE_METHOD;
1017}
1018
1019/* Return a typename for a struct/union/enum type without "struct ",
1020 "union ", or "enum ". If the type has a NULL name, return NULL. */
1021
1022char *
fba45db2 1023type_name_no_tag (register const struct type *type)
c906108c
SS
1024{
1025 if (TYPE_TAG_NAME (type) != NULL)
1026 return TYPE_TAG_NAME (type);
1027
1028 /* Is there code which expects this to return the name if there is no
1029 tag name? My guess is that this is mainly used for C++ in cases where
1030 the two will always be the same. */
1031 return TYPE_NAME (type);
1032}
1033
7b83ea04 1034/* Lookup a primitive type named NAME.
c5aa993b 1035 Return zero if NAME is not a primitive type. */
c906108c
SS
1036
1037struct type *
fba45db2 1038lookup_primitive_typename (char *name)
c906108c 1039{
c5aa993b
JM
1040 struct type **const *p;
1041
1042 for (p = current_language->la_builtin_type_vector; *p != NULL; p++)
1043 {
762f08a3 1044 if (strcmp (TYPE_NAME (**p), name) == 0)
c5aa993b
JM
1045 {
1046 return (**p);
1047 }
1048 }
1049 return (NULL);
c906108c
SS
1050}
1051
1052/* Lookup a typedef or primitive type named NAME,
1053 visible in lexical block BLOCK.
1054 If NOERR is nonzero, return zero if NAME is not suitably defined. */
1055
1056struct type *
fba45db2 1057lookup_typename (char *name, struct block *block, int noerr)
c906108c
SS
1058{
1059 register struct symbol *sym;
1060 register struct type *tmp;
1061
176620f1 1062 sym = lookup_symbol (name, block, VAR_DOMAIN, 0, (struct symtab **) NULL);
c906108c
SS
1063 if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
1064 {
1065 tmp = lookup_primitive_typename (name);
1066 if (tmp)
1067 {
1068 return (tmp);
1069 }
1070 else if (!tmp && noerr)
1071 {
1072 return (NULL);
1073 }
1074 else
1075 {
1076 error ("No type named %s.", name);
1077 }
1078 }
1079 return (SYMBOL_TYPE (sym));
1080}
1081
1082struct type *
fba45db2 1083lookup_unsigned_typename (char *name)
c906108c
SS
1084{
1085 char *uns = alloca (strlen (name) + 10);
1086
1087 strcpy (uns, "unsigned ");
1088 strcpy (uns + 9, name);
1089 return (lookup_typename (uns, (struct block *) NULL, 0));
1090}
1091
1092struct type *
fba45db2 1093lookup_signed_typename (char *name)
c906108c
SS
1094{
1095 struct type *t;
1096 char *uns = alloca (strlen (name) + 8);
1097
1098 strcpy (uns, "signed ");
1099 strcpy (uns + 7, name);
1100 t = lookup_typename (uns, (struct block *) NULL, 1);
1101 /* If we don't find "signed FOO" just try again with plain "FOO". */
1102 if (t != NULL)
1103 return t;
1104 return lookup_typename (name, (struct block *) NULL, 0);
1105}
1106
1107/* Lookup a structure type named "struct NAME",
1108 visible in lexical block BLOCK. */
1109
1110struct type *
fba45db2 1111lookup_struct (char *name, struct block *block)
c906108c
SS
1112{
1113 register struct symbol *sym;
1114
176620f1 1115 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0,
c906108c
SS
1116 (struct symtab **) NULL);
1117
1118 if (sym == NULL)
1119 {
1120 error ("No struct type named %s.", name);
1121 }
1122 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
1123 {
1124 error ("This context has class, union or enum %s, not a struct.", name);
1125 }
1126 return (SYMBOL_TYPE (sym));
1127}
1128
1129/* Lookup a union type named "union NAME",
1130 visible in lexical block BLOCK. */
1131
1132struct type *
fba45db2 1133lookup_union (char *name, struct block *block)
c906108c
SS
1134{
1135 register struct symbol *sym;
c5aa993b 1136 struct type *t;
c906108c 1137
176620f1 1138 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0,
c906108c
SS
1139 (struct symtab **) NULL);
1140
1141 if (sym == NULL)
1142 error ("No union type named %s.", name);
1143
c5aa993b 1144 t = SYMBOL_TYPE (sym);
c906108c
SS
1145
1146 if (TYPE_CODE (t) == TYPE_CODE_UNION)
1147 return (t);
1148
1149 /* C++ unions may come out with TYPE_CODE_CLASS, but we look at
1150 * a further "declared_type" field to discover it is really a union.
1151 */
c5aa993b
JM
1152 if (HAVE_CPLUS_STRUCT (t))
1153 if (TYPE_DECLARED_TYPE (t) == DECLARED_TYPE_UNION)
c906108c
SS
1154 return (t);
1155
1156 /* If we get here, it's not a union */
1157 error ("This context has class, struct or enum %s, not a union.", name);
1158}
1159
1160
1161/* Lookup an enum type named "enum NAME",
1162 visible in lexical block BLOCK. */
1163
1164struct type *
fba45db2 1165lookup_enum (char *name, struct block *block)
c906108c
SS
1166{
1167 register struct symbol *sym;
1168
176620f1 1169 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0,
c906108c
SS
1170 (struct symtab **) NULL);
1171 if (sym == NULL)
1172 {
1173 error ("No enum type named %s.", name);
1174 }
1175 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM)
1176 {
1177 error ("This context has class, struct or union %s, not an enum.", name);
1178 }
1179 return (SYMBOL_TYPE (sym));
1180}
1181
1182/* Lookup a template type named "template NAME<TYPE>",
1183 visible in lexical block BLOCK. */
1184
1185struct type *
fba45db2 1186lookup_template_type (char *name, struct type *type, struct block *block)
c906108c
SS
1187{
1188 struct symbol *sym;
0004e5a2 1189 char *nam = (char *) alloca (strlen (name) + strlen (TYPE_NAME (type)) + 4);
c906108c
SS
1190 strcpy (nam, name);
1191 strcat (nam, "<");
0004e5a2 1192 strcat (nam, TYPE_NAME (type));
c5aa993b 1193 strcat (nam, " >"); /* FIXME, extra space still introduced in gcc? */
c906108c 1194
176620f1 1195 sym = lookup_symbol (nam, block, VAR_DOMAIN, 0, (struct symtab **) NULL);
c906108c
SS
1196
1197 if (sym == NULL)
1198 {
1199 error ("No template type named %s.", name);
1200 }
1201 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
1202 {
1203 error ("This context has class, union or enum %s, not a struct.", name);
1204 }
1205 return (SYMBOL_TYPE (sym));
1206}
1207
7b83ea04 1208/* Given a type TYPE, lookup the type of the component of type named NAME.
c906108c
SS
1209
1210 TYPE can be either a struct or union, or a pointer or reference to a struct or
1211 union. If it is a pointer or reference, its target type is automatically used.
1212 Thus '.' and '->' are interchangable, as specified for the definitions of the
1213 expression element types STRUCTOP_STRUCT and STRUCTOP_PTR.
1214
1215 If NOERR is nonzero, return zero if NAME is not suitably defined.
1216 If NAME is the name of a baseclass type, return that type. */
1217
1218struct type *
fba45db2 1219lookup_struct_elt_type (struct type *type, char *name, int noerr)
c906108c
SS
1220{
1221 int i;
1222
1223 for (;;)
1224 {
1225 CHECK_TYPEDEF (type);
1226 if (TYPE_CODE (type) != TYPE_CODE_PTR
1227 && TYPE_CODE (type) != TYPE_CODE_REF)
1228 break;
1229 type = TYPE_TARGET_TYPE (type);
1230 }
1231
1232 if (TYPE_CODE (type) != TYPE_CODE_STRUCT &&
1233 TYPE_CODE (type) != TYPE_CODE_UNION)
1234 {
1235 target_terminal_ours ();
1236 gdb_flush (gdb_stdout);
1237 fprintf_unfiltered (gdb_stderr, "Type ");
1238 type_print (type, "", gdb_stderr, -1);
1239 error (" is not a structure or union type.");
1240 }
1241
1242#if 0
1243 /* FIXME: This change put in by Michael seems incorrect for the case where
1244 the structure tag name is the same as the member name. I.E. when doing
1245 "ptype bell->bar" for "struct foo { int bar; int foo; } bell;"
1246 Disabled by fnf. */
1247 {
1248 char *typename;
1249
1250 typename = type_name_no_tag (type);
762f08a3 1251 if (typename != NULL && strcmp (typename, name) == 0)
c906108c
SS
1252 return type;
1253 }
1254#endif
1255
1256 for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
1257 {
1258 char *t_field_name = TYPE_FIELD_NAME (type, i);
1259
db577aea 1260 if (t_field_name && (strcmp_iw (t_field_name, name) == 0))
c906108c
SS
1261 {
1262 return TYPE_FIELD_TYPE (type, i);
1263 }
1264 }
1265
1266 /* OK, it's not in this class. Recursively check the baseclasses. */
1267 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
1268 {
1269 struct type *t;
1270
1271 t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, noerr);
1272 if (t != NULL)
1273 {
1274 return t;
1275 }
1276 }
1277
1278 if (noerr)
1279 {
1280 return NULL;
1281 }
c5aa993b 1282
c906108c
SS
1283 target_terminal_ours ();
1284 gdb_flush (gdb_stdout);
1285 fprintf_unfiltered (gdb_stderr, "Type ");
1286 type_print (type, "", gdb_stderr, -1);
1287 fprintf_unfiltered (gdb_stderr, " has no component named ");
1288 fputs_filtered (name, gdb_stderr);
1289 error (".");
c5aa993b 1290 return (struct type *) -1; /* For lint */
c906108c
SS
1291}
1292
1293/* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE
1294 valid. Callers should be aware that in some cases (for example,
1295 the type or one of its baseclasses is a stub type and we are
1296 debugging a .o file), this function will not be able to find the virtual
1297 function table pointer, and vptr_fieldno will remain -1 and vptr_basetype
1298 will remain NULL. */
1299
1300void
fba45db2 1301fill_in_vptr_fieldno (struct type *type)
c906108c
SS
1302{
1303 CHECK_TYPEDEF (type);
1304
1305 if (TYPE_VPTR_FIELDNO (type) < 0)
1306 {
1307 int i;
1308
1309 /* We must start at zero in case the first (and only) baseclass is
7b83ea04 1310 virtual (and hence we cannot share the table pointer). */
c906108c
SS
1311 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
1312 {
cef4f5dd
DJ
1313 struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i));
1314 fill_in_vptr_fieldno (baseclass);
1315 if (TYPE_VPTR_FIELDNO (baseclass) >= 0)
c906108c 1316 {
cef4f5dd
DJ
1317 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (baseclass);
1318 TYPE_VPTR_BASETYPE (type) = TYPE_VPTR_BASETYPE (baseclass);
c906108c
SS
1319 break;
1320 }
1321 }
1322 }
1323}
1324
1325/* Find the method and field indices for the destructor in class type T.
1326 Return 1 if the destructor was found, otherwise, return 0. */
1327
1328int
fba45db2 1329get_destructor_fn_field (struct type *t, int *method_indexp, int *field_indexp)
c906108c
SS
1330{
1331 int i;
1332
1333 for (i = 0; i < TYPE_NFN_FIELDS (t); i++)
1334 {
1335 int j;
1336 struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i);
1337
1338 for (j = 0; j < TYPE_FN_FIELDLIST_LENGTH (t, i); j++)
1339 {
015a42b4 1340 if (is_destructor_name (TYPE_FN_FIELD_PHYSNAME (f, j)) != 0)
c906108c
SS
1341 {
1342 *method_indexp = i;
1343 *field_indexp = j;
1344 return 1;
1345 }
1346 }
1347 }
1348 return 0;
1349}
1350
1351/* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
1352
1353 If this is a stubbed struct (i.e. declared as struct foo *), see if
1354 we can find a full definition in some other file. If so, copy this
1355 definition, so we can use it in future. There used to be a comment (but
1356 not any code) that if we don't find a full definition, we'd set a flag
1357 so we don't spend time in the future checking the same type. That would
1358 be a mistake, though--we might load in more symbols which contain a
1359 full definition for the type.
1360
7b83ea04 1361 This used to be coded as a macro, but I don't think it is called
c906108c
SS
1362 often enough to merit such treatment. */
1363
23136709
KB
1364static void
1365stub_noname_complaint (void)
1366{
1367 complaint (&symfile_complaints, "stub type has NULL name");
1368}
c906108c
SS
1369
1370struct type *
a02fd225 1371check_typedef (struct type *type)
c906108c
SS
1372{
1373 struct type *orig_type = type;
a02fd225
DJ
1374 int is_const, is_volatile;
1375
c906108c
SS
1376 while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
1377 {
1378 if (!TYPE_TARGET_TYPE (type))
1379 {
c5aa993b 1380 char *name;
c906108c
SS
1381 struct symbol *sym;
1382
1383 /* It is dangerous to call lookup_symbol if we are currently
1384 reading a symtab. Infinite recursion is one danger. */
1385 if (currently_reading_symtab)
1386 return type;
1387
1388 name = type_name_no_tag (type);
1389 /* FIXME: shouldn't we separately check the TYPE_NAME and the
176620f1 1390 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
c906108c
SS
1391 as appropriate? (this code was written before TYPE_NAME and
1392 TYPE_TAG_NAME were separate). */
1393 if (name == NULL)
1394 {
23136709 1395 stub_noname_complaint ();
c906108c
SS
1396 return type;
1397 }
176620f1 1398 sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0,
c906108c
SS
1399 (struct symtab **) NULL);
1400 if (sym)
1401 TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym);
1402 else
c5aa993b 1403 TYPE_TARGET_TYPE (type) = alloc_type (NULL); /* TYPE_CODE_UNDEF */
c906108c
SS
1404 }
1405 type = TYPE_TARGET_TYPE (type);
1406 }
1407
a02fd225
DJ
1408 is_const = TYPE_CONST (type);
1409 is_volatile = TYPE_VOLATILE (type);
1410
c906108c
SS
1411 /* If this is a struct/class/union with no fields, then check whether a
1412 full definition exists somewhere else. This is for systems where a
1413 type definition with no fields is issued for such types, instead of
c5aa993b
JM
1414 identifying them as stub types in the first place */
1415
c906108c
SS
1416 if (TYPE_IS_OPAQUE (type) && opaque_type_resolution && !currently_reading_symtab)
1417 {
c5aa993b
JM
1418 char *name = type_name_no_tag (type);
1419 struct type *newtype;
c906108c
SS
1420 if (name == NULL)
1421 {
23136709 1422 stub_noname_complaint ();
c906108c
SS
1423 return type;
1424 }
1425 newtype = lookup_transparent_type (name);
1426 if (newtype)
a02fd225 1427 make_cv_type (is_const, is_volatile, newtype, &type);
c906108c
SS
1428 }
1429 /* Otherwise, rely on the stub flag being set for opaque/stubbed types */
74a9bb82 1430 else if (TYPE_STUB (type) && !currently_reading_symtab)
c906108c 1431 {
c5aa993b 1432 char *name = type_name_no_tag (type);
c906108c 1433 /* FIXME: shouldn't we separately check the TYPE_NAME and the
176620f1 1434 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
7b83ea04
AC
1435 as appropriate? (this code was written before TYPE_NAME and
1436 TYPE_TAG_NAME were separate). */
c906108c
SS
1437 struct symbol *sym;
1438 if (name == NULL)
1439 {
23136709 1440 stub_noname_complaint ();
c906108c
SS
1441 return type;
1442 }
176620f1 1443 sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0, (struct symtab **) NULL);
c906108c 1444 if (sym)
a02fd225 1445 make_cv_type (is_const, is_volatile, SYMBOL_TYPE (sym), &type);
c906108c
SS
1446 }
1447
74a9bb82 1448 if (TYPE_TARGET_STUB (type))
c906108c
SS
1449 {
1450 struct type *range_type;
1451 struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
1452
74a9bb82 1453 if (TYPE_STUB (target_type) || TYPE_TARGET_STUB (target_type))
c5aa993b
JM
1454 {
1455 }
c906108c
SS
1456 else if (TYPE_CODE (type) == TYPE_CODE_ARRAY
1457 && TYPE_NFIELDS (type) == 1
1458 && (TYPE_CODE (range_type = TYPE_FIELD_TYPE (type, 0))
1459 == TYPE_CODE_RANGE))
1460 {
1461 /* Now recompute the length of the array type, based on its
1462 number of elements and the target type's length. */
1463 TYPE_LENGTH (type) =
1464 ((TYPE_FIELD_BITPOS (range_type, 1)
1465 - TYPE_FIELD_BITPOS (range_type, 0)
1466 + 1)
1467 * TYPE_LENGTH (target_type));
1468 TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
1469 }
1470 else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
1471 {
1472 TYPE_LENGTH (type) = TYPE_LENGTH (target_type);
1473 TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
1474 }
1475 }
1476 /* Cache TYPE_LENGTH for future use. */
1477 TYPE_LENGTH (orig_type) = TYPE_LENGTH (type);
1478 return type;
1479}
1480
25caa7a8
EZ
1481#if 0 /* OBSOLETE CFront */
1482// OBSOLETE /* New code added to support parsing of Cfront stabs strings */
1483// OBSOLETE #define INIT_EXTRA { pextras->len=0; pextras->str[0]='\0'; }
1484// OBSOLETE #define ADD_EXTRA(c) { pextras->str[pextras->len++]=c; }
1485
1486// OBSOLETE static void
1487// OBSOLETE add_name (struct extra *pextras, char *n)
1488// OBSOLETE {
1489// OBSOLETE int nlen;
1490
1491// OBSOLETE if ((nlen = (n ? strlen (n) : 0)) == 0)
1492// OBSOLETE return;
1493// OBSOLETE sprintf (pextras->str + pextras->len, "%d%s", nlen, n);
1494// OBSOLETE pextras->len = strlen (pextras->str);
1495// OBSOLETE }
1496
1497// OBSOLETE static void
1498// OBSOLETE add_mangled_type (struct extra *pextras, struct type *t)
1499// OBSOLETE {
1500// OBSOLETE enum type_code tcode;
1501// OBSOLETE int tlen, tflags;
1502// OBSOLETE char *tname;
1503
1504// OBSOLETE tcode = TYPE_CODE (t);
1505// OBSOLETE tlen = TYPE_LENGTH (t);
1506// OBSOLETE tflags = TYPE_FLAGS (t);
1507// OBSOLETE tname = TYPE_NAME (t);
1508// OBSOLETE /* args of "..." seem to get mangled as "e" */
1509
1510// OBSOLETE switch (tcode)
1511// OBSOLETE {
1512// OBSOLETE case TYPE_CODE_INT:
1513// OBSOLETE if (tflags == 1)
1514// OBSOLETE ADD_EXTRA ('U');
1515// OBSOLETE switch (tlen)
1516// OBSOLETE {
1517// OBSOLETE case 1:
1518// OBSOLETE ADD_EXTRA ('c');
1519// OBSOLETE break;
1520// OBSOLETE case 2:
1521// OBSOLETE ADD_EXTRA ('s');
1522// OBSOLETE break;
1523// OBSOLETE case 4:
1524// OBSOLETE {
1525// OBSOLETE char *pname;
1526// OBSOLETE if ((pname = strrchr (tname, 'l'), pname) && !strcmp (pname, "long"))
1527// OBSOLETE {
1528// OBSOLETE ADD_EXTRA ('l');
1529// OBSOLETE }
1530// OBSOLETE else
1531// OBSOLETE {
1532// OBSOLETE ADD_EXTRA ('i');
1533// OBSOLETE }
1534// OBSOLETE }
1535// OBSOLETE break;
1536// OBSOLETE default:
1537// OBSOLETE {
1538// OBSOLETE complaint (&symfile_complaints, "Bad int type code length x%x",
1539// OBSOLETE tlen);
1540// OBSOLETE }
1541// OBSOLETE }
1542// OBSOLETE break;
1543// OBSOLETE case TYPE_CODE_FLT:
1544// OBSOLETE switch (tlen)
1545// OBSOLETE {
1546// OBSOLETE case 4:
1547// OBSOLETE ADD_EXTRA ('f');
1548// OBSOLETE break;
1549// OBSOLETE case 8:
1550// OBSOLETE ADD_EXTRA ('d');
1551// OBSOLETE break;
1552// OBSOLETE case 16:
1553// OBSOLETE ADD_EXTRA ('r');
1554// OBSOLETE break;
1555// OBSOLETE default:
1556// OBSOLETE {
1557// OBSOLETE complaint (&symfile_complaints, "Bad float type code length x%x",
1558// OBSOLETE tlen);
1559// OBSOLETE }
1560// OBSOLETE }
1561// OBSOLETE break;
1562// OBSOLETE case TYPE_CODE_REF:
1563// OBSOLETE ADD_EXTRA ('R');
1564// OBSOLETE /* followed by what it's a ref to */
1565// OBSOLETE break;
1566// OBSOLETE case TYPE_CODE_PTR:
1567// OBSOLETE ADD_EXTRA ('P');
1568// OBSOLETE /* followed by what it's a ptr to */
1569// OBSOLETE break;
1570// OBSOLETE case TYPE_CODE_TYPEDEF:
1571// OBSOLETE {
1572// OBSOLETE complaint (&symfile_complaints,
1573// OBSOLETE "Typedefs in overloaded functions not yet supported");
1574// OBSOLETE }
1575// OBSOLETE /* followed by type bytes & name */
1576// OBSOLETE break;
1577// OBSOLETE case TYPE_CODE_FUNC:
1578// OBSOLETE ADD_EXTRA ('F');
1579// OBSOLETE /* followed by func's arg '_' & ret types */
1580// OBSOLETE break;
1581// OBSOLETE case TYPE_CODE_VOID:
1582// OBSOLETE ADD_EXTRA ('v');
1583// OBSOLETE break;
1584// OBSOLETE case TYPE_CODE_METHOD:
1585// OBSOLETE ADD_EXTRA ('M');
1586// OBSOLETE /* followed by name of class and func's arg '_' & ret types */
1587// OBSOLETE add_name (pextras, tname);
1588// OBSOLETE ADD_EXTRA ('F'); /* then mangle function */
1589// OBSOLETE break;
1590// OBSOLETE case TYPE_CODE_STRUCT: /* C struct */
1591// OBSOLETE case TYPE_CODE_UNION: /* C union */
1592// OBSOLETE case TYPE_CODE_ENUM: /* Enumeration type */
1593// OBSOLETE /* followed by name of type */
1594// OBSOLETE add_name (pextras, tname);
1595// OBSOLETE break;
1596
1597// OBSOLETE /* errors possible types/not supported */
1598// OBSOLETE case TYPE_CODE_CHAR:
1599// OBSOLETE case TYPE_CODE_ARRAY: /* Array type */
1600// OBSOLETE case TYPE_CODE_MEMBER: /* Member type */
1601// OBSOLETE case TYPE_CODE_BOOL:
1602// OBSOLETE case TYPE_CODE_COMPLEX: /* Complex float */
1603// OBSOLETE case TYPE_CODE_UNDEF:
1604// OBSOLETE case TYPE_CODE_SET: /* Pascal sets */
1605// OBSOLETE case TYPE_CODE_RANGE:
1606// OBSOLETE case TYPE_CODE_STRING:
1607// OBSOLETE case TYPE_CODE_BITSTRING:
1608// OBSOLETE case TYPE_CODE_ERROR:
1609// OBSOLETE default:
1610// OBSOLETE {
1611// OBSOLETE complaint (&symfile_complaints, "Unknown type code x%x", tcode);
1612// OBSOLETE }
1613// OBSOLETE }
1614// OBSOLETE if (TYPE_TARGET_TYPE (t))
1615// OBSOLETE add_mangled_type (pextras, TYPE_TARGET_TYPE (t));
1616// OBSOLETE }
1617
1618// OBSOLETE void
1619// OBSOLETE cfront_mangle_name (struct type *type, int i, int j)
1620// OBSOLETE {
1621// OBSOLETE struct fn_field *f;
1622// OBSOLETE char *mangled_name = gdb_mangle_name (type, i, j);
1623
1624// OBSOLETE f = TYPE_FN_FIELDLIST1 (type, i); /* moved from below */
1625
1626// OBSOLETE /* kludge to support cfront methods - gdb expects to find "F" for
1627// OBSOLETE ARM_mangled names, so when we mangle, we have to add it here */
1628// OBSOLETE if (ARM_DEMANGLING)
1629// OBSOLETE {
1630// OBSOLETE int k;
1631// OBSOLETE char *arm_mangled_name;
1632// OBSOLETE struct fn_field *method = &f[j];
1633// OBSOLETE char *field_name = TYPE_FN_FIELDLIST_NAME (type, i);
1634// OBSOLETE char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);
1635// OBSOLETE char *newname = type_name_no_tag (type);
1636
1637// OBSOLETE struct type *ftype = TYPE_FN_FIELD_TYPE (f, j);
1638// OBSOLETE int nargs = TYPE_NFIELDS (ftype); /* number of args */
1639// OBSOLETE struct extra extras, *pextras = &extras;
1640// OBSOLETE INIT_EXTRA
1641
1642// OBSOLETE if (TYPE_FN_FIELD_STATIC_P (f, j)) /* j for sublist within this list */
1643// OBSOLETE ADD_EXTRA ('S')
1644// OBSOLETE ADD_EXTRA ('F')
1645// OBSOLETE /* add args here! */
1646// OBSOLETE if (nargs <= 1) /* no args besides this */
1647// OBSOLETE ADD_EXTRA ('v')
1648// OBSOLETE else
1649// OBSOLETE {
1650// OBSOLETE for (k = 1; k < nargs; k++)
1651// OBSOLETE {
1652// OBSOLETE struct type *t;
1653// OBSOLETE t = TYPE_FIELD_TYPE (ftype, k);
1654// OBSOLETE add_mangled_type (pextras, t);
1655// OBSOLETE }
1656// OBSOLETE }
1657// OBSOLETE ADD_EXTRA ('\0')
1658// OBSOLETE printf ("add_mangled_type: %s\n", extras.str); /* FIXME */
1659// OBSOLETE xasprintf (&arm_mangled_name, "%s%s", mangled_name, extras.str);
1660// OBSOLETE xfree (mangled_name);
1661// OBSOLETE mangled_name = arm_mangled_name;
1662// OBSOLETE }
1663// OBSOLETE }
1664
1665// OBSOLETE #undef ADD_EXTRA
1666// OBSOLETE /* End of new code added to support parsing of Cfront stabs strings */
1667#endif /* OBSOLETE CFront */
c906108c 1668
c91ecb25
ND
1669/* Parse a type expression in the string [P..P+LENGTH). If an error occurs,
1670 silently return builtin_type_void. */
1671
b9362cc7 1672static struct type *
c91ecb25
ND
1673safe_parse_type (char *p, int length)
1674{
1675 struct ui_file *saved_gdb_stderr;
1676 struct type *type;
1677
1678 /* Suppress error messages. */
1679 saved_gdb_stderr = gdb_stderr;
1680 gdb_stderr = ui_file_new ();
1681
1682 /* Call parse_and_eval_type() without fear of longjmp()s. */
1683 if (!gdb_parse_and_eval_type (p, length, &type))
1684 type = builtin_type_void;
1685
1686 /* Stop suppressing error messages. */
1687 ui_file_delete (gdb_stderr);
1688 gdb_stderr = saved_gdb_stderr;
1689
1690 return type;
1691}
1692
c906108c
SS
1693/* Ugly hack to convert method stubs into method types.
1694
1695 He ain't kiddin'. This demangles the name of the method into a string
1696 including argument types, parses out each argument type, generates
1697 a string casting a zero to that type, evaluates the string, and stuffs
1698 the resulting type into an argtype vector!!! Then it knows the type
1699 of the whole function (including argument types for overloading),
1700 which info used to be in the stab's but was removed to hack back
1701 the space required for them. */
1702
de17c821 1703static void
fba45db2 1704check_stub_method (struct type *type, int method_id, int signature_id)
c906108c
SS
1705{
1706 struct fn_field *f;
1707 char *mangled_name = gdb_mangle_name (type, method_id, signature_id);
1708 char *demangled_name = cplus_demangle (mangled_name,
1709 DMGL_PARAMS | DMGL_ANSI);
1710 char *argtypetext, *p;
1711 int depth = 0, argcount = 1;
ad2f7632 1712 struct field *argtypes;
c906108c
SS
1713 struct type *mtype;
1714
1715 /* Make sure we got back a function string that we can use. */
1716 if (demangled_name)
1717 p = strchr (demangled_name, '(');
502dcf4e
AC
1718 else
1719 p = NULL;
c906108c
SS
1720
1721 if (demangled_name == NULL || p == NULL)
1722 error ("Internal: Cannot demangle mangled name `%s'.", mangled_name);
1723
1724 /* Now, read in the parameters that define this type. */
1725 p += 1;
1726 argtypetext = p;
1727 while (*p)
1728 {
070ad9f0 1729 if (*p == '(' || *p == '<')
c906108c
SS
1730 {
1731 depth += 1;
1732 }
070ad9f0 1733 else if (*p == ')' || *p == '>')
c906108c
SS
1734 {
1735 depth -= 1;
1736 }
1737 else if (*p == ',' && depth == 0)
1738 {
1739 argcount += 1;
1740 }
1741
1742 p += 1;
1743 }
1744
ad2f7632
DJ
1745 /* If we read one argument and it was ``void'', don't count it. */
1746 if (strncmp (argtypetext, "(void)", 6) == 0)
1747 argcount -= 1;
c906108c 1748
ad2f7632
DJ
1749 /* We need one extra slot, for the THIS pointer. */
1750
1751 argtypes = (struct field *)
1752 TYPE_ALLOC (type, (argcount + 1) * sizeof (struct field));
c906108c 1753 p = argtypetext;
4a1970e4
DJ
1754
1755 /* Add THIS pointer for non-static methods. */
1756 f = TYPE_FN_FIELDLIST1 (type, method_id);
1757 if (TYPE_FN_FIELD_STATIC_P (f, signature_id))
1758 argcount = 0;
1759 else
1760 {
ad2f7632 1761 argtypes[0].type = lookup_pointer_type (type);
4a1970e4
DJ
1762 argcount = 1;
1763 }
c906108c 1764
c5aa993b 1765 if (*p != ')') /* () means no args, skip while */
c906108c
SS
1766 {
1767 depth = 0;
1768 while (*p)
1769 {
1770 if (depth <= 0 && (*p == ',' || *p == ')'))
1771 {
ad2f7632
DJ
1772 /* Avoid parsing of ellipsis, they will be handled below.
1773 Also avoid ``void'' as above. */
1774 if (strncmp (argtypetext, "...", p - argtypetext) != 0
1775 && strncmp (argtypetext, "void", p - argtypetext) != 0)
c906108c 1776 {
ad2f7632 1777 argtypes[argcount].type =
c91ecb25 1778 safe_parse_type (argtypetext, p - argtypetext);
c906108c
SS
1779 argcount += 1;
1780 }
1781 argtypetext = p + 1;
1782 }
1783
070ad9f0 1784 if (*p == '(' || *p == '<')
c906108c
SS
1785 {
1786 depth += 1;
1787 }
070ad9f0 1788 else if (*p == ')' || *p == '>')
c906108c
SS
1789 {
1790 depth -= 1;
1791 }
1792
1793 p += 1;
1794 }
1795 }
1796
c906108c
SS
1797 TYPE_FN_FIELD_PHYSNAME (f, signature_id) = mangled_name;
1798
1799 /* Now update the old "stub" type into a real type. */
1800 mtype = TYPE_FN_FIELD_TYPE (f, signature_id);
1801 TYPE_DOMAIN_TYPE (mtype) = type;
ad2f7632
DJ
1802 TYPE_FIELDS (mtype) = argtypes;
1803 TYPE_NFIELDS (mtype) = argcount;
c906108c
SS
1804 TYPE_FLAGS (mtype) &= ~TYPE_FLAG_STUB;
1805 TYPE_FN_FIELD_STUB (f, signature_id) = 0;
ad2f7632
DJ
1806 if (p[-2] == '.')
1807 TYPE_FLAGS (mtype) |= TYPE_FLAG_VARARGS;
1808
1809 xfree (demangled_name);
c906108c
SS
1810}
1811
de17c821
DJ
1812/* This is the external interface to check_stub_method, above. This function
1813 unstubs all of the signatures for TYPE's METHOD_ID method name. After
1814 calling this function TYPE_FN_FIELD_STUB will be cleared for each signature
1815 and TYPE_FN_FIELDLIST_NAME will be correct.
1816
1817 This function unfortunately can not die until stabs do. */
1818
1819void
1820check_stub_method_group (struct type *type, int method_id)
1821{
1822 int len = TYPE_FN_FIELDLIST_LENGTH (type, method_id);
1823 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, method_id);
f710f4fc 1824 int j, found_stub = 0;
de17c821
DJ
1825
1826 for (j = 0; j < len; j++)
1827 if (TYPE_FN_FIELD_STUB (f, j))
1828 {
1829 found_stub = 1;
1830 check_stub_method (type, method_id, j);
1831 }
1832
1833 /* GNU v3 methods with incorrect names were corrected when we read in
1834 type information, because it was cheaper to do it then. The only GNU v2
1835 methods with incorrect method names are operators and destructors;
1836 destructors were also corrected when we read in type information.
1837
1838 Therefore the only thing we need to handle here are v2 operator
1839 names. */
1840 if (found_stub && strncmp (TYPE_FN_FIELD_PHYSNAME (f, 0), "_Z", 2) != 0)
1841 {
1842 int ret;
1843 char dem_opname[256];
1844
1845 ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type, method_id),
1846 dem_opname, DMGL_ANSI);
1847 if (!ret)
1848 ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type, method_id),
1849 dem_opname, 0);
1850 if (ret)
1851 TYPE_FN_FIELDLIST_NAME (type, method_id) = xstrdup (dem_opname);
1852 }
1853}
1854
c906108c
SS
1855const struct cplus_struct_type cplus_struct_default;
1856
1857void
fba45db2 1858allocate_cplus_struct_type (struct type *type)
c906108c
SS
1859{
1860 if (!HAVE_CPLUS_STRUCT (type))
1861 {
1862 TYPE_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *)
1863 TYPE_ALLOC (type, sizeof (struct cplus_struct_type));
c5aa993b 1864 *(TYPE_CPLUS_SPECIFIC (type)) = cplus_struct_default;
c906108c
SS
1865 }
1866}
1867
1868/* Helper function to initialize the standard scalar types.
1869
1870 If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy
1871 of the string pointed to by name in the type_obstack for that objfile,
1872 and initialize the type name to that copy. There are places (mipsread.c
1873 in particular, where init_type is called with a NULL value for NAME). */
1874
1875struct type *
fba45db2
KB
1876init_type (enum type_code code, int length, int flags, char *name,
1877 struct objfile *objfile)
c906108c
SS
1878{
1879 register struct type *type;
1880
1881 type = alloc_type (objfile);
1882 TYPE_CODE (type) = code;
1883 TYPE_LENGTH (type) = length;
1884 TYPE_FLAGS (type) |= flags;
1885 if ((name != NULL) && (objfile != NULL))
1886 {
1887 TYPE_NAME (type) =
c5aa993b 1888 obsavestring (name, strlen (name), &objfile->type_obstack);
c906108c
SS
1889 }
1890 else
1891 {
1892 TYPE_NAME (type) = name;
1893 }
1894
1895 /* C++ fancies. */
1896
973ccf8b
DJ
1897 if (name && strcmp (name, "char") == 0)
1898 TYPE_FLAGS (type) |= TYPE_FLAG_NOSIGN;
1899
c906108c
SS
1900 if (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION)
1901 {
1902 INIT_CPLUS_SPECIFIC (type);
1903 }
1904 return (type);
1905}
1906
0e101458
AC
1907/* Helper function. Create an empty composite type. */
1908
1909struct type *
1910init_composite_type (char *name, enum type_code code)
1911{
1912 struct type *t;
1913 gdb_assert (code == TYPE_CODE_STRUCT
1914 || code == TYPE_CODE_UNION);
1915 t = init_type (code, 0, 0, NULL, NULL);
1916 TYPE_TAG_NAME (t) = name;
1917 return t;
1918}
1919
1920/* Helper function. Append a field to a composite type. */
1921
1922void
1923append_composite_type_field (struct type *t, char *name, struct type *field)
1924{
1925 struct field *f;
1926 TYPE_NFIELDS (t) = TYPE_NFIELDS (t) + 1;
1927 TYPE_FIELDS (t) = xrealloc (TYPE_FIELDS (t),
1928 sizeof (struct field) * TYPE_NFIELDS (t));
1929 f = &(TYPE_FIELDS (t)[TYPE_NFIELDS (t) - 1]);
1930 memset (f, 0, sizeof f[0]);
1931 FIELD_TYPE (f[0]) = field;
1932 FIELD_NAME (f[0]) = name;
1933 if (TYPE_CODE (t) == TYPE_CODE_UNION)
1934 {
73d322b1 1935 if (TYPE_LENGTH (t) < TYPE_LENGTH (field))
0e101458
AC
1936 TYPE_LENGTH (t) = TYPE_LENGTH (field);
1937 }
1938 else if (TYPE_CODE (t) == TYPE_CODE_STRUCT)
1939 {
1940 TYPE_LENGTH (t) = TYPE_LENGTH (t) + TYPE_LENGTH (field);
1941 if (TYPE_NFIELDS (t) > 1)
1942 {
1943 FIELD_BITPOS (f[0]) = (FIELD_BITPOS (f[-1])
1944 + TYPE_LENGTH (field) * TARGET_CHAR_BIT);
1945 }
1946 }
1947}
1948
c906108c
SS
1949/* Look up a fundamental type for the specified objfile.
1950 May need to construct such a type if this is the first use.
1951
1952 Some object file formats (ELF, COFF, etc) do not define fundamental
1953 types such as "int" or "double". Others (stabs for example), do
1954 define fundamental types.
1955
1956 For the formats which don't provide fundamental types, gdb can create
1957 such types, using defaults reasonable for the current language and
1958 the current target machine.
1959
1960 NOTE: This routine is obsolescent. Each debugging format reader
1961 should manage it's own fundamental types, either creating them from
1962 suitable defaults or reading them from the debugging information,
1963 whichever is appropriate. The DWARF reader has already been
1964 fixed to do this. Once the other readers are fixed, this routine
1965 will go away. Also note that fundamental types should be managed
1966 on a compilation unit basis in a multi-language environment, not
1967 on a linkage unit basis as is done here. */
1968
1969
1970struct type *
fba45db2 1971lookup_fundamental_type (struct objfile *objfile, int typeid)
c906108c
SS
1972{
1973 register struct type **typep;
1974 register int nbytes;
1975
1976 if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
1977 {
1978 error ("internal error - invalid fundamental type id %d", typeid);
1979 }
1980
1981 /* If this is the first time we need a fundamental type for this objfile
1982 then we need to initialize the vector of type pointers. */
c5aa993b
JM
1983
1984 if (objfile->fundamental_types == NULL)
c906108c
SS
1985 {
1986 nbytes = FT_NUM_MEMBERS * sizeof (struct type *);
c5aa993b
JM
1987 objfile->fundamental_types = (struct type **)
1988 obstack_alloc (&objfile->type_obstack, nbytes);
1989 memset ((char *) objfile->fundamental_types, 0, nbytes);
c906108c
SS
1990 OBJSTAT (objfile, n_types += FT_NUM_MEMBERS);
1991 }
1992
1993 /* Look for this particular type in the fundamental type vector. If one is
1994 not found, create and install one appropriate for the current language. */
1995
c5aa993b 1996 typep = objfile->fundamental_types + typeid;
c906108c
SS
1997 if (*typep == NULL)
1998 {
1999 *typep = create_fundamental_type (objfile, typeid);
2000 }
2001
2002 return (*typep);
2003}
2004
2005int
fba45db2 2006can_dereference (struct type *t)
c906108c
SS
2007{
2008 /* FIXME: Should we return true for references as well as pointers? */
2009 CHECK_TYPEDEF (t);
2010 return
2011 (t != NULL
2012 && TYPE_CODE (t) == TYPE_CODE_PTR
2013 && TYPE_CODE (TYPE_TARGET_TYPE (t)) != TYPE_CODE_VOID);
2014}
2015
adf40b2e 2016int
fba45db2 2017is_integral_type (struct type *t)
adf40b2e
JM
2018{
2019 CHECK_TYPEDEF (t);
2020 return
2021 ((t != NULL)
d4f3574e
SS
2022 && ((TYPE_CODE (t) == TYPE_CODE_INT)
2023 || (TYPE_CODE (t) == TYPE_CODE_ENUM)
2024 || (TYPE_CODE (t) == TYPE_CODE_CHAR)
2025 || (TYPE_CODE (t) == TYPE_CODE_RANGE)
2026 || (TYPE_CODE (t) == TYPE_CODE_BOOL)));
adf40b2e
JM
2027}
2028
7b83ea04 2029/* Check whether BASE is an ancestor or base class or DCLASS
c906108c
SS
2030 Return 1 if so, and 0 if not.
2031 Note: callers may want to check for identity of the types before
2032 calling this function -- identical types are considered to satisfy
2033 the ancestor relationship even if they're identical */
2034
2035int
fba45db2 2036is_ancestor (struct type *base, struct type *dclass)
c906108c
SS
2037{
2038 int i;
c5aa993b 2039
c906108c
SS
2040 CHECK_TYPEDEF (base);
2041 CHECK_TYPEDEF (dclass);
2042
2043 if (base == dclass)
2044 return 1;
6b1ba9a0
ND
2045 if (TYPE_NAME (base) && TYPE_NAME (dclass) &&
2046 !strcmp (TYPE_NAME (base), TYPE_NAME (dclass)))
2047 return 1;
c906108c
SS
2048
2049 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
2050 if (is_ancestor (base, TYPE_BASECLASS (dclass, i)))
2051 return 1;
2052
2053 return 0;
2054}
2055
2056
2057
2058/* See whether DCLASS has a virtual table. This routine is aimed at
2059 the HP/Taligent ANSI C++ runtime model, and may not work with other
2060 runtime models. Return 1 => Yes, 0 => No. */
2061
2062int
fba45db2 2063has_vtable (struct type *dclass)
c906108c
SS
2064{
2065 /* In the HP ANSI C++ runtime model, a class has a vtable only if it
2066 has virtual functions or virtual bases. */
2067
2068 register int i;
2069
c5aa993b 2070 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
c906108c 2071 return 0;
c5aa993b 2072
c906108c 2073 /* First check for the presence of virtual bases */
c5aa993b
JM
2074 if (TYPE_FIELD_VIRTUAL_BITS (dclass))
2075 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
2076 if (B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i))
2077 return 1;
2078
c906108c 2079 /* Next check for virtual functions */
c5aa993b
JM
2080 if (TYPE_FN_FIELDLISTS (dclass))
2081 for (i = 0; i < TYPE_NFN_FIELDS (dclass); i++)
2082 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, i), 0))
c906108c 2083 return 1;
c5aa993b
JM
2084
2085 /* Recurse on non-virtual bases to see if any of them needs a vtable */
2086 if (TYPE_FIELD_VIRTUAL_BITS (dclass))
2087 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
2088 if ((!B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i)) &&
2089 (has_vtable (TYPE_FIELD_TYPE (dclass, i))))
2090 return 1;
2091
2092 /* Well, maybe we don't need a virtual table */
c906108c
SS
2093 return 0;
2094}
2095
2096/* Return a pointer to the "primary base class" of DCLASS.
c5aa993b 2097
c906108c
SS
2098 A NULL return indicates that DCLASS has no primary base, or that it
2099 couldn't be found (insufficient information).
c5aa993b 2100
c906108c
SS
2101 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
2102 and may not work with other runtime models. */
2103
2104struct type *
fba45db2 2105primary_base_class (struct type *dclass)
c906108c
SS
2106{
2107 /* In HP ANSI C++'s runtime model, a "primary base class" of a class
2108 is the first directly inherited, non-virtual base class that
2109 requires a virtual table */
2110
2111 register int i;
2112
c5aa993b 2113 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
c906108c
SS
2114 return NULL;
2115
c5aa993b
JM
2116 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
2117 if (!TYPE_FIELD_VIRTUAL (dclass, i) &&
2118 has_vtable (TYPE_FIELD_TYPE (dclass, i)))
2119 return TYPE_FIELD_TYPE (dclass, i);
c906108c
SS
2120
2121 return NULL;
2122}
2123
2124/* Global manipulated by virtual_base_list[_aux]() */
2125
c5aa993b 2126static struct vbase *current_vbase_list = NULL;
c906108c
SS
2127
2128/* Return a pointer to a null-terminated list of struct vbase
2129 items. The vbasetype pointer of each item in the list points to the
2130 type information for a virtual base of the argument DCLASS.
c5aa993b 2131
7b83ea04 2132 Helper function for virtual_base_list().
c906108c
SS
2133 Note: the list goes backward, right-to-left. virtual_base_list()
2134 copies the items out in reverse order. */
2135
7a292a7a 2136static void
fba45db2 2137virtual_base_list_aux (struct type *dclass)
c906108c 2138{
c5aa993b 2139 struct vbase *tmp_vbase;
c906108c
SS
2140 register int i;
2141
c5aa993b 2142 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
7a292a7a 2143 return;
c906108c
SS
2144
2145 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
2146 {
2147 /* Recurse on this ancestor, first */
c5aa993b 2148 virtual_base_list_aux (TYPE_FIELD_TYPE (dclass, i));
c906108c
SS
2149
2150 /* If this current base is itself virtual, add it to the list */
c5aa993b
JM
2151 if (BASETYPE_VIA_VIRTUAL (dclass, i))
2152 {
2153 struct type *basetype = TYPE_FIELD_TYPE (dclass, i);
2154
2155 /* Check if base already recorded */
2156 tmp_vbase = current_vbase_list;
2157 while (tmp_vbase)
2158 {
2159 if (tmp_vbase->vbasetype == basetype)
2160 break; /* found it */
2161 tmp_vbase = tmp_vbase->next;
2162 }
2163
2164 if (!tmp_vbase) /* normal exit from loop */
2165 {
2166 /* Allocate new item for this virtual base */
2167 tmp_vbase = (struct vbase *) xmalloc (sizeof (struct vbase));
2168
2169 /* Stick it on at the end of the list */
2170 tmp_vbase->vbasetype = basetype;
2171 tmp_vbase->next = current_vbase_list;
2172 current_vbase_list = tmp_vbase;
2173 }
2174 } /* if virtual */
2175 } /* for loop over bases */
c906108c
SS
2176}
2177
2178
2179/* Compute the list of virtual bases in the right order. Virtual
2180 bases are laid out in the object's memory area in order of their
2181 occurrence in a depth-first, left-to-right search through the
2182 ancestors.
c5aa993b 2183
c906108c
SS
2184 Argument DCLASS is the type whose virtual bases are required.
2185 Return value is the address of a null-terminated array of pointers
2186 to struct type items.
c5aa993b 2187
c906108c
SS
2188 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
2189 and may not work with other runtime models.
c5aa993b 2190
c906108c
SS
2191 This routine merely hands off the argument to virtual_base_list_aux()
2192 and then copies the result into an array to save space. */
2193
2194struct type **
fba45db2 2195virtual_base_list (struct type *dclass)
c906108c 2196{
c5aa993b
JM
2197 register struct vbase *tmp_vbase;
2198 register struct vbase *tmp_vbase_2;
c906108c
SS
2199 register int i;
2200 int count;
c5aa993b 2201 struct type **vbase_array;
c906108c
SS
2202
2203 current_vbase_list = NULL;
c5aa993b 2204 virtual_base_list_aux (dclass);
c906108c 2205
c5aa993b 2206 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next)
c906108c
SS
2207 /* no body */ ;
2208
2209 count = i;
2210
c5aa993b 2211 vbase_array = (struct type **) xmalloc ((count + 1) * sizeof (struct type *));
c906108c 2212
c5aa993b 2213 for (i = count - 1, tmp_vbase = current_vbase_list; i >= 0; i--, tmp_vbase = tmp_vbase->next)
c906108c
SS
2214 vbase_array[i] = tmp_vbase->vbasetype;
2215
2216 /* Get rid of constructed chain */
2217 tmp_vbase_2 = tmp_vbase = current_vbase_list;
2218 while (tmp_vbase)
2219 {
2220 tmp_vbase = tmp_vbase->next;
b8c9b27d 2221 xfree (tmp_vbase_2);
c906108c
SS
2222 tmp_vbase_2 = tmp_vbase;
2223 }
c5aa993b 2224
c906108c
SS
2225 vbase_array[count] = NULL;
2226 return vbase_array;
2227}
2228
2229/* Return the length of the virtual base list of the type DCLASS. */
2230
2231int
fba45db2 2232virtual_base_list_length (struct type *dclass)
c906108c
SS
2233{
2234 register int i;
c5aa993b
JM
2235 register struct vbase *tmp_vbase;
2236
c906108c 2237 current_vbase_list = NULL;
c5aa993b 2238 virtual_base_list_aux (dclass);
c906108c 2239
c5aa993b 2240 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next)
c906108c
SS
2241 /* no body */ ;
2242 return i;
2243}
2244
2245/* Return the number of elements of the virtual base list of the type
2246 DCLASS, ignoring those appearing in the primary base (and its
2247 primary base, recursively). */
2248
2249int
fba45db2 2250virtual_base_list_length_skip_primaries (struct type *dclass)
c906108c
SS
2251{
2252 register int i;
c5aa993b
JM
2253 register struct vbase *tmp_vbase;
2254 struct type *primary;
c906108c
SS
2255
2256 primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL;
2257
2258 if (!primary)
2259 return virtual_base_list_length (dclass);
2260
2261 current_vbase_list = NULL;
c5aa993b 2262 virtual_base_list_aux (dclass);
c906108c 2263
c5aa993b 2264 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; tmp_vbase = tmp_vbase->next)
c906108c
SS
2265 {
2266 if (virtual_base_index (tmp_vbase->vbasetype, primary) >= 0)
c5aa993b 2267 continue;
c906108c
SS
2268 i++;
2269 }
2270 return i;
2271}
2272
2273
2274/* Return the index (position) of type BASE, which is a virtual base
2275 class of DCLASS, in the latter's virtual base list. A return of -1
2276 indicates "not found" or a problem. */
2277
2278int
fba45db2 2279virtual_base_index (struct type *base, struct type *dclass)
c906108c 2280{
c5aa993b 2281 register struct type *vbase;
c906108c
SS
2282 register int i;
2283
c5aa993b
JM
2284 if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) ||
2285 (TYPE_CODE (base) != TYPE_CODE_CLASS))
c906108c
SS
2286 return -1;
2287
2288 i = 0;
015a42b4 2289 vbase = virtual_base_list (dclass)[0];
c906108c
SS
2290 while (vbase)
2291 {
2292 if (vbase == base)
c5aa993b 2293 break;
015a42b4 2294 vbase = virtual_base_list (dclass)[++i];
c906108c
SS
2295 }
2296
2297 return vbase ? i : -1;
2298}
2299
2300
2301
2302/* Return the index (position) of type BASE, which is a virtual base
2303 class of DCLASS, in the latter's virtual base list. Skip over all
2304 bases that may appear in the virtual base list of the primary base
2305 class of DCLASS (recursively). A return of -1 indicates "not
2306 found" or a problem. */
2307
2308int
fba45db2 2309virtual_base_index_skip_primaries (struct type *base, struct type *dclass)
c906108c 2310{
c5aa993b 2311 register struct type *vbase;
c906108c 2312 register int i, j;
c5aa993b 2313 struct type *primary;
c906108c 2314
c5aa993b
JM
2315 if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) ||
2316 (TYPE_CODE (base) != TYPE_CODE_CLASS))
c906108c
SS
2317 return -1;
2318
c5aa993b 2319 primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL;
c906108c
SS
2320
2321 j = -1;
2322 i = 0;
015a42b4 2323 vbase = virtual_base_list (dclass)[0];
c906108c
SS
2324 while (vbase)
2325 {
c5aa993b
JM
2326 if (!primary || (virtual_base_index_skip_primaries (vbase, primary) < 0))
2327 j++;
c906108c 2328 if (vbase == base)
c5aa993b 2329 break;
015a42b4 2330 vbase = virtual_base_list (dclass)[++i];
c906108c
SS
2331 }
2332
2333 return vbase ? j : -1;
2334}
2335
2336/* Return position of a derived class DCLASS in the list of
2337 * primary bases starting with the remotest ancestor.
2338 * Position returned is 0-based. */
2339
2340int
fba45db2 2341class_index_in_primary_list (struct type *dclass)
c906108c 2342{
c5aa993b 2343 struct type *pbc; /* primary base class */
c906108c 2344
c5aa993b 2345 /* Simply recurse on primary base */
c906108c
SS
2346 pbc = TYPE_PRIMARY_BASE (dclass);
2347 if (pbc)
2348 return 1 + class_index_in_primary_list (pbc);
2349 else
2350 return 0;
2351}
2352
2353/* Return a count of the number of virtual functions a type has.
2354 * This includes all the virtual functions it inherits from its
2355 * base classes too.
2356 */
2357
2358/* pai: FIXME This doesn't do the right thing: count redefined virtual
2359 * functions only once (latest redefinition)
2360 */
2361
2362int
fba45db2 2363count_virtual_fns (struct type *dclass)
c906108c 2364{
c5aa993b 2365 int fn, oi; /* function and overloaded instance indices */
c5aa993b
JM
2366 int vfuncs; /* count to return */
2367
2368 /* recurse on bases that can share virtual table */
2369 struct type *pbc = primary_base_class (dclass);
c906108c
SS
2370 if (pbc)
2371 vfuncs = count_virtual_fns (pbc);
7f7e9482
AC
2372 else
2373 vfuncs = 0;
c5aa993b 2374
c906108c
SS
2375 for (fn = 0; fn < TYPE_NFN_FIELDS (dclass); fn++)
2376 for (oi = 0; oi < TYPE_FN_FIELDLIST_LENGTH (dclass, fn); oi++)
2377 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, fn), oi))
c5aa993b 2378 vfuncs++;
c906108c
SS
2379
2380 return vfuncs;
2381}
c906108c
SS
2382\f
2383
c5aa993b 2384
c906108c
SS
2385/* Functions for overload resolution begin here */
2386
2387/* Compare two badness vectors A and B and return the result.
2388 * 0 => A and B are identical
2389 * 1 => A and B are incomparable
2390 * 2 => A is better than B
2391 * 3 => A is worse than B */
2392
2393int
fba45db2 2394compare_badness (struct badness_vector *a, struct badness_vector *b)
c906108c
SS
2395{
2396 int i;
2397 int tmp;
c5aa993b
JM
2398 short found_pos = 0; /* any positives in c? */
2399 short found_neg = 0; /* any negatives in c? */
2400
2401 /* differing lengths => incomparable */
c906108c
SS
2402 if (a->length != b->length)
2403 return 1;
2404
c5aa993b
JM
2405 /* Subtract b from a */
2406 for (i = 0; i < a->length; i++)
c906108c
SS
2407 {
2408 tmp = a->rank[i] - b->rank[i];
2409 if (tmp > 0)
c5aa993b 2410 found_pos = 1;
c906108c 2411 else if (tmp < 0)
c5aa993b 2412 found_neg = 1;
c906108c
SS
2413 }
2414
2415 if (found_pos)
2416 {
2417 if (found_neg)
c5aa993b 2418 return 1; /* incomparable */
c906108c 2419 else
c5aa993b 2420 return 3; /* A > B */
c906108c 2421 }
c5aa993b
JM
2422 else
2423 /* no positives */
c906108c
SS
2424 {
2425 if (found_neg)
c5aa993b 2426 return 2; /* A < B */
c906108c 2427 else
c5aa993b 2428 return 0; /* A == B */
c906108c
SS
2429 }
2430}
2431
2432/* Rank a function by comparing its parameter types (PARMS, length NPARMS),
2433 * to the types of an argument list (ARGS, length NARGS).
2434 * Return a pointer to a badness vector. This has NARGS + 1 entries. */
2435
2436struct badness_vector *
fba45db2 2437rank_function (struct type **parms, int nparms, struct type **args, int nargs)
c906108c
SS
2438{
2439 int i;
c5aa993b 2440 struct badness_vector *bv;
c906108c
SS
2441 int min_len = nparms < nargs ? nparms : nargs;
2442
2443 bv = xmalloc (sizeof (struct badness_vector));
c5aa993b 2444 bv->length = nargs + 1; /* add 1 for the length-match rank */
c906108c
SS
2445 bv->rank = xmalloc ((nargs + 1) * sizeof (int));
2446
2447 /* First compare the lengths of the supplied lists.
2448 * If there is a mismatch, set it to a high value. */
c5aa993b 2449
c906108c
SS
2450 /* pai/1997-06-03 FIXME: when we have debug info about default
2451 * arguments and ellipsis parameter lists, we should consider those
2452 * and rank the length-match more finely. */
2453
2454 LENGTH_MATCH (bv) = (nargs != nparms) ? LENGTH_MISMATCH_BADNESS : 0;
2455
2456 /* Now rank all the parameters of the candidate function */
74cc24b0
DB
2457 for (i = 1; i <= min_len; i++)
2458 bv->rank[i] = rank_one_type (parms[i-1], args[i-1]);
c906108c 2459
c5aa993b
JM
2460 /* If more arguments than parameters, add dummy entries */
2461 for (i = min_len + 1; i <= nargs; i++)
c906108c
SS
2462 bv->rank[i] = TOO_FEW_PARAMS_BADNESS;
2463
2464 return bv;
2465}
2466
973ccf8b
DJ
2467/* Compare the names of two integer types, assuming that any sign
2468 qualifiers have been checked already. We do it this way because
2469 there may be an "int" in the name of one of the types. */
2470
2471static int
2472integer_types_same_name_p (const char *first, const char *second)
2473{
2474 int first_p, second_p;
2475
2476 /* If both are shorts, return 1; if neither is a short, keep checking. */
2477 first_p = (strstr (first, "short") != NULL);
2478 second_p = (strstr (second, "short") != NULL);
2479 if (first_p && second_p)
2480 return 1;
2481 if (first_p || second_p)
2482 return 0;
2483
2484 /* Likewise for long. */
2485 first_p = (strstr (first, "long") != NULL);
2486 second_p = (strstr (second, "long") != NULL);
2487 if (first_p && second_p)
2488 return 1;
2489 if (first_p || second_p)
2490 return 0;
2491
2492 /* Likewise for char. */
2493 first_p = (strstr (first, "char") != NULL);
2494 second_p = (strstr (second, "char") != NULL);
2495 if (first_p && second_p)
2496 return 1;
2497 if (first_p || second_p)
2498 return 0;
2499
2500 /* They must both be ints. */
2501 return 1;
2502}
2503
c906108c
SS
2504/* Compare one type (PARM) for compatibility with another (ARG).
2505 * PARM is intended to be the parameter type of a function; and
2506 * ARG is the supplied argument's type. This function tests if
2507 * the latter can be converted to the former.
2508 *
2509 * Return 0 if they are identical types;
2510 * Otherwise, return an integer which corresponds to how compatible
2511 * PARM is to ARG. The higher the return value, the worse the match.
2512 * Generally the "bad" conversions are all uniformly assigned a 100 */
2513
2514int
fba45db2 2515rank_one_type (struct type *parm, struct type *arg)
c906108c
SS
2516{
2517 /* Identical type pointers */
2518 /* However, this still doesn't catch all cases of same type for arg
2519 * and param. The reason is that builtin types are different from
2520 * the same ones constructed from the object. */
2521 if (parm == arg)
2522 return 0;
2523
2524 /* Resolve typedefs */
2525 if (TYPE_CODE (parm) == TYPE_CODE_TYPEDEF)
2526 parm = check_typedef (parm);
2527 if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF)
2528 arg = check_typedef (arg);
2529
070ad9f0
DB
2530 /*
2531 Well, damnit, if the names are exactly the same,
2532 i'll say they are exactly the same. This happens when we generate
2533 method stubs. The types won't point to the same address, but they
2534 really are the same.
2535 */
2536
6b1ba9a0
ND
2537 if (TYPE_NAME (parm) && TYPE_NAME (arg) &&
2538 !strcmp (TYPE_NAME (parm), TYPE_NAME (arg)))
070ad9f0
DB
2539 return 0;
2540
c906108c
SS
2541 /* Check if identical after resolving typedefs */
2542 if (parm == arg)
2543 return 0;
2544
db577aea
AC
2545 /* See through references, since we can almost make non-references
2546 references. */
2547 if (TYPE_CODE (arg) == TYPE_CODE_REF)
6b1ba9a0 2548 return (rank_one_type (parm, TYPE_TARGET_TYPE (arg))
db577aea
AC
2549 + REFERENCE_CONVERSION_BADNESS);
2550 if (TYPE_CODE (parm) == TYPE_CODE_REF)
6b1ba9a0 2551 return (rank_one_type (TYPE_TARGET_TYPE (parm), arg)
db577aea 2552 + REFERENCE_CONVERSION_BADNESS);
5d161b24 2553 if (overload_debug)
db577aea 2554 /* Debugging only. */
5d161b24
DB
2555 fprintf_filtered (gdb_stderr,"------ Arg is %s [%d], parm is %s [%d]\n",
2556 TYPE_NAME (arg), TYPE_CODE (arg), TYPE_NAME (parm), TYPE_CODE (parm));
c906108c
SS
2557
2558 /* x -> y means arg of type x being supplied for parameter of type y */
2559
2560 switch (TYPE_CODE (parm))
2561 {
c5aa993b
JM
2562 case TYPE_CODE_PTR:
2563 switch (TYPE_CODE (arg))
2564 {
2565 case TYPE_CODE_PTR:
2566 if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID)
2567 return VOID_PTR_CONVERSION_BADNESS;
2568 else
2569 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2570 case TYPE_CODE_ARRAY:
2571 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2572 case TYPE_CODE_FUNC:
2573 return rank_one_type (TYPE_TARGET_TYPE (parm), arg);
2574 case TYPE_CODE_INT:
2575 case TYPE_CODE_ENUM:
2576 case TYPE_CODE_CHAR:
2577 case TYPE_CODE_RANGE:
2578 case TYPE_CODE_BOOL:
2579 return POINTER_CONVERSION_BADNESS;
2580 default:
2581 return INCOMPATIBLE_TYPE_BADNESS;
2582 }
2583 case TYPE_CODE_ARRAY:
2584 switch (TYPE_CODE (arg))
2585 {
2586 case TYPE_CODE_PTR:
2587 case TYPE_CODE_ARRAY:
2588 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2589 default:
2590 return INCOMPATIBLE_TYPE_BADNESS;
2591 }
2592 case TYPE_CODE_FUNC:
2593 switch (TYPE_CODE (arg))
2594 {
2595 case TYPE_CODE_PTR: /* funcptr -> func */
2596 return rank_one_type (parm, TYPE_TARGET_TYPE (arg));
2597 default:
2598 return INCOMPATIBLE_TYPE_BADNESS;
2599 }
2600 case TYPE_CODE_INT:
2601 switch (TYPE_CODE (arg))
2602 {
2603 case TYPE_CODE_INT:
2604 if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
2605 {
2606 /* Deal with signed, unsigned, and plain chars and
7b83ea04 2607 signed and unsigned ints */
c5aa993b
JM
2608 if (TYPE_NOSIGN (parm))
2609 {
2610 /* This case only for character types */
2611 if (TYPE_NOSIGN (arg)) /* plain char -> plain char */
2612 return 0;
2613 else
1c5cb38e 2614 return INTEGER_CONVERSION_BADNESS; /* signed/unsigned char -> plain char */
c5aa993b
JM
2615 }
2616 else if (TYPE_UNSIGNED (parm))
2617 {
2618 if (TYPE_UNSIGNED (arg))
2619 {
973ccf8b
DJ
2620 /* unsigned int -> unsigned int, or unsigned long -> unsigned long */
2621 if (integer_types_same_name_p (TYPE_NAME (parm), TYPE_NAME (arg)))
2622 return 0;
2623 else if (integer_types_same_name_p (TYPE_NAME (arg), "int")
2624 && integer_types_same_name_p (TYPE_NAME (parm), "long"))
c5aa993b
JM
2625 return INTEGER_PROMOTION_BADNESS; /* unsigned int -> unsigned long */
2626 else
1c5cb38e 2627 return INTEGER_CONVERSION_BADNESS; /* unsigned long -> unsigned int */
c5aa993b
JM
2628 }
2629 else
2630 {
973ccf8b
DJ
2631 if (integer_types_same_name_p (TYPE_NAME (arg), "long")
2632 && integer_types_same_name_p (TYPE_NAME (parm), "int"))
1c5cb38e 2633 return INTEGER_CONVERSION_BADNESS; /* signed long -> unsigned int */
c5aa993b
JM
2634 else
2635 return INTEGER_CONVERSION_BADNESS; /* signed int/long -> unsigned int/long */
2636 }
2637 }
2638 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
2639 {
973ccf8b 2640 if (integer_types_same_name_p (TYPE_NAME (parm), TYPE_NAME (arg)))
c5aa993b 2641 return 0;
973ccf8b
DJ
2642 else if (integer_types_same_name_p (TYPE_NAME (arg), "int")
2643 && integer_types_same_name_p (TYPE_NAME (parm), "long"))
c5aa993b
JM
2644 return INTEGER_PROMOTION_BADNESS;
2645 else
1c5cb38e 2646 return INTEGER_CONVERSION_BADNESS;
c5aa993b
JM
2647 }
2648 else
1c5cb38e 2649 return INTEGER_CONVERSION_BADNESS;
c5aa993b
JM
2650 }
2651 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2652 return INTEGER_PROMOTION_BADNESS;
2653 else
1c5cb38e 2654 return INTEGER_CONVERSION_BADNESS;
c5aa993b
JM
2655 case TYPE_CODE_ENUM:
2656 case TYPE_CODE_CHAR:
2657 case TYPE_CODE_RANGE:
2658 case TYPE_CODE_BOOL:
2659 return INTEGER_PROMOTION_BADNESS;
2660 case TYPE_CODE_FLT:
2661 return INT_FLOAT_CONVERSION_BADNESS;
2662 case TYPE_CODE_PTR:
2663 return NS_POINTER_CONVERSION_BADNESS;
2664 default:
2665 return INCOMPATIBLE_TYPE_BADNESS;
2666 }
2667 break;
2668 case TYPE_CODE_ENUM:
2669 switch (TYPE_CODE (arg))
2670 {
2671 case TYPE_CODE_INT:
2672 case TYPE_CODE_CHAR:
2673 case TYPE_CODE_RANGE:
2674 case TYPE_CODE_BOOL:
2675 case TYPE_CODE_ENUM:
1c5cb38e 2676 return INTEGER_CONVERSION_BADNESS;
c5aa993b
JM
2677 case TYPE_CODE_FLT:
2678 return INT_FLOAT_CONVERSION_BADNESS;
2679 default:
2680 return INCOMPATIBLE_TYPE_BADNESS;
2681 }
2682 break;
2683 case TYPE_CODE_CHAR:
2684 switch (TYPE_CODE (arg))
2685 {
2686 case TYPE_CODE_RANGE:
2687 case TYPE_CODE_BOOL:
2688 case TYPE_CODE_ENUM:
1c5cb38e 2689 return INTEGER_CONVERSION_BADNESS;
c5aa993b
JM
2690 case TYPE_CODE_FLT:
2691 return INT_FLOAT_CONVERSION_BADNESS;
2692 case TYPE_CODE_INT:
2693 if (TYPE_LENGTH (arg) > TYPE_LENGTH (parm))
1c5cb38e 2694 return INTEGER_CONVERSION_BADNESS;
c5aa993b
JM
2695 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2696 return INTEGER_PROMOTION_BADNESS;
2697 /* >>> !! else fall through !! <<< */
2698 case TYPE_CODE_CHAR:
2699 /* Deal with signed, unsigned, and plain chars for C++
2700 and with int cases falling through from previous case */
2701 if (TYPE_NOSIGN (parm))
2702 {
2703 if (TYPE_NOSIGN (arg))
2704 return 0;
2705 else
1c5cb38e 2706 return INTEGER_CONVERSION_BADNESS;
c5aa993b
JM
2707 }
2708 else if (TYPE_UNSIGNED (parm))
2709 {
2710 if (TYPE_UNSIGNED (arg))
2711 return 0;
2712 else
2713 return INTEGER_PROMOTION_BADNESS;
2714 }
2715 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
2716 return 0;
2717 else
1c5cb38e 2718 return INTEGER_CONVERSION_BADNESS;
c5aa993b
JM
2719 default:
2720 return INCOMPATIBLE_TYPE_BADNESS;
2721 }
2722 break;
2723 case TYPE_CODE_RANGE:
2724 switch (TYPE_CODE (arg))
2725 {
2726 case TYPE_CODE_INT:
2727 case TYPE_CODE_CHAR:
2728 case TYPE_CODE_RANGE:
2729 case TYPE_CODE_BOOL:
2730 case TYPE_CODE_ENUM:
1c5cb38e 2731 return INTEGER_CONVERSION_BADNESS;
c5aa993b
JM
2732 case TYPE_CODE_FLT:
2733 return INT_FLOAT_CONVERSION_BADNESS;
2734 default:
2735 return INCOMPATIBLE_TYPE_BADNESS;
2736 }
2737 break;
2738 case TYPE_CODE_BOOL:
2739 switch (TYPE_CODE (arg))
2740 {
2741 case TYPE_CODE_INT:
2742 case TYPE_CODE_CHAR:
2743 case TYPE_CODE_RANGE:
2744 case TYPE_CODE_ENUM:
2745 case TYPE_CODE_FLT:
2746 case TYPE_CODE_PTR:
2747 return BOOLEAN_CONVERSION_BADNESS;
2748 case TYPE_CODE_BOOL:
2749 return 0;
2750 default:
2751 return INCOMPATIBLE_TYPE_BADNESS;
2752 }
2753 break;
2754 case TYPE_CODE_FLT:
2755 switch (TYPE_CODE (arg))
2756 {
2757 case TYPE_CODE_FLT:
2758 if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2759 return FLOAT_PROMOTION_BADNESS;
2760 else if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
2761 return 0;
2762 else
2763 return FLOAT_CONVERSION_BADNESS;
2764 case TYPE_CODE_INT:
2765 case TYPE_CODE_BOOL:
2766 case TYPE_CODE_ENUM:
2767 case TYPE_CODE_RANGE:
2768 case TYPE_CODE_CHAR:
2769 return INT_FLOAT_CONVERSION_BADNESS;
2770 default:
2771 return INCOMPATIBLE_TYPE_BADNESS;
2772 }
2773 break;
2774 case TYPE_CODE_COMPLEX:
2775 switch (TYPE_CODE (arg))
2776 { /* Strictly not needed for C++, but... */
2777 case TYPE_CODE_FLT:
2778 return FLOAT_PROMOTION_BADNESS;
2779 case TYPE_CODE_COMPLEX:
2780 return 0;
2781 default:
2782 return INCOMPATIBLE_TYPE_BADNESS;
2783 }
2784 break;
2785 case TYPE_CODE_STRUCT:
c906108c 2786 /* currently same as TYPE_CODE_CLASS */
c5aa993b
JM
2787 switch (TYPE_CODE (arg))
2788 {
2789 case TYPE_CODE_STRUCT:
2790 /* Check for derivation */
2791 if (is_ancestor (parm, arg))
2792 return BASE_CONVERSION_BADNESS;
2793 /* else fall through */
2794 default:
2795 return INCOMPATIBLE_TYPE_BADNESS;
2796 }
2797 break;
2798 case TYPE_CODE_UNION:
2799 switch (TYPE_CODE (arg))
2800 {
2801 case TYPE_CODE_UNION:
2802 default:
2803 return INCOMPATIBLE_TYPE_BADNESS;
2804 }
2805 break;
2806 case TYPE_CODE_MEMBER:
2807 switch (TYPE_CODE (arg))
2808 {
2809 default:
2810 return INCOMPATIBLE_TYPE_BADNESS;
2811 }
2812 break;
2813 case TYPE_CODE_METHOD:
2814 switch (TYPE_CODE (arg))
2815 {
2816
2817 default:
2818 return INCOMPATIBLE_TYPE_BADNESS;
2819 }
2820 break;
2821 case TYPE_CODE_REF:
2822 switch (TYPE_CODE (arg))
2823 {
2824
2825 default:
2826 return INCOMPATIBLE_TYPE_BADNESS;
2827 }
2828
2829 break;
2830 case TYPE_CODE_SET:
2831 switch (TYPE_CODE (arg))
2832 {
2833 /* Not in C++ */
2834 case TYPE_CODE_SET:
2835 return rank_one_type (TYPE_FIELD_TYPE (parm, 0), TYPE_FIELD_TYPE (arg, 0));
2836 default:
2837 return INCOMPATIBLE_TYPE_BADNESS;
2838 }
2839 break;
2840 case TYPE_CODE_VOID:
2841 default:
2842 return INCOMPATIBLE_TYPE_BADNESS;
2843 } /* switch (TYPE_CODE (arg)) */
c906108c
SS
2844}
2845
c5aa993b
JM
2846
2847/* End of functions for overload resolution */
c906108c 2848
c906108c 2849static void
fba45db2 2850print_bit_vector (B_TYPE *bits, int nbits)
c906108c
SS
2851{
2852 int bitno;
2853
2854 for (bitno = 0; bitno < nbits; bitno++)
2855 {
2856 if ((bitno % 8) == 0)
2857 {
2858 puts_filtered (" ");
2859 }
2860 if (B_TST (bits, bitno))
2861 {
2862 printf_filtered ("1");
2863 }
2864 else
2865 {
2866 printf_filtered ("0");
2867 }
2868 }
2869}
2870
ad2f7632
DJ
2871/* Note the first arg should be the "this" pointer, we may not want to
2872 include it since we may get into a infinitely recursive situation. */
c906108c
SS
2873
2874static void
ad2f7632 2875print_arg_types (struct field *args, int nargs, int spaces)
c906108c
SS
2876{
2877 if (args != NULL)
2878 {
ad2f7632
DJ
2879 int i;
2880
2881 for (i = 0; i < nargs; i++)
2882 recursive_dump_type (args[i].type, spaces + 2);
c906108c
SS
2883 }
2884}
2885
2886static void
fba45db2 2887dump_fn_fieldlists (struct type *type, int spaces)
c906108c
SS
2888{
2889 int method_idx;
2890 int overload_idx;
2891 struct fn_field *f;
2892
2893 printfi_filtered (spaces, "fn_fieldlists ");
d4f3574e 2894 gdb_print_host_address (TYPE_FN_FIELDLISTS (type), gdb_stdout);
c906108c
SS
2895 printf_filtered ("\n");
2896 for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++)
2897 {
2898 f = TYPE_FN_FIELDLIST1 (type, method_idx);
2899 printfi_filtered (spaces + 2, "[%d] name '%s' (",
2900 method_idx,
2901 TYPE_FN_FIELDLIST_NAME (type, method_idx));
d4f3574e
SS
2902 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type, method_idx),
2903 gdb_stdout);
c906108c
SS
2904 printf_filtered (") length %d\n",
2905 TYPE_FN_FIELDLIST_LENGTH (type, method_idx));
2906 for (overload_idx = 0;
2907 overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx);
2908 overload_idx++)
2909 {
2910 printfi_filtered (spaces + 4, "[%d] physname '%s' (",
2911 overload_idx,
2912 TYPE_FN_FIELD_PHYSNAME (f, overload_idx));
d4f3574e
SS
2913 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f, overload_idx),
2914 gdb_stdout);
c906108c
SS
2915 printf_filtered (")\n");
2916 printfi_filtered (spaces + 8, "type ");
d4f3574e 2917 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f, overload_idx), gdb_stdout);
c906108c
SS
2918 printf_filtered ("\n");
2919
2920 recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx),
2921 spaces + 8 + 2);
2922
2923 printfi_filtered (spaces + 8, "args ");
d4f3574e 2924 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f, overload_idx), gdb_stdout);
c906108c
SS
2925 printf_filtered ("\n");
2926
ad2f7632
DJ
2927 print_arg_types (TYPE_FN_FIELD_ARGS (f, overload_idx),
2928 TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f, overload_idx)),
2929 spaces);
c906108c 2930 printfi_filtered (spaces + 8, "fcontext ");
d4f3574e
SS
2931 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx),
2932 gdb_stdout);
c906108c
SS
2933 printf_filtered ("\n");
2934
2935 printfi_filtered (spaces + 8, "is_const %d\n",
2936 TYPE_FN_FIELD_CONST (f, overload_idx));
2937 printfi_filtered (spaces + 8, "is_volatile %d\n",
2938 TYPE_FN_FIELD_VOLATILE (f, overload_idx));
2939 printfi_filtered (spaces + 8, "is_private %d\n",
2940 TYPE_FN_FIELD_PRIVATE (f, overload_idx));
2941 printfi_filtered (spaces + 8, "is_protected %d\n",
2942 TYPE_FN_FIELD_PROTECTED (f, overload_idx));
2943 printfi_filtered (spaces + 8, "is_stub %d\n",
2944 TYPE_FN_FIELD_STUB (f, overload_idx));
2945 printfi_filtered (spaces + 8, "voffset %u\n",
2946 TYPE_FN_FIELD_VOFFSET (f, overload_idx));
2947 }
2948 }
2949}
2950
2951static void
fba45db2 2952print_cplus_stuff (struct type *type, int spaces)
c906108c
SS
2953{
2954 printfi_filtered (spaces, "n_baseclasses %d\n",
2955 TYPE_N_BASECLASSES (type));
2956 printfi_filtered (spaces, "nfn_fields %d\n",
2957 TYPE_NFN_FIELDS (type));
2958 printfi_filtered (spaces, "nfn_fields_total %d\n",
2959 TYPE_NFN_FIELDS_TOTAL (type));
2960 if (TYPE_N_BASECLASSES (type) > 0)
2961 {
2962 printfi_filtered (spaces, "virtual_field_bits (%d bits at *",
2963 TYPE_N_BASECLASSES (type));
d4f3574e 2964 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type), gdb_stdout);
c906108c
SS
2965 printf_filtered (")");
2966
2967 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type),
2968 TYPE_N_BASECLASSES (type));
2969 puts_filtered ("\n");
2970 }
2971 if (TYPE_NFIELDS (type) > 0)
2972 {
2973 if (TYPE_FIELD_PRIVATE_BITS (type) != NULL)
2974 {
2975 printfi_filtered (spaces, "private_field_bits (%d bits at *",
2976 TYPE_NFIELDS (type));
d4f3574e 2977 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type), gdb_stdout);
c906108c
SS
2978 printf_filtered (")");
2979 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type),
2980 TYPE_NFIELDS (type));
2981 puts_filtered ("\n");
2982 }
2983 if (TYPE_FIELD_PROTECTED_BITS (type) != NULL)
2984 {
2985 printfi_filtered (spaces, "protected_field_bits (%d bits at *",
2986 TYPE_NFIELDS (type));
d4f3574e 2987 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type), gdb_stdout);
c906108c
SS
2988 printf_filtered (")");
2989 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type),
2990 TYPE_NFIELDS (type));
2991 puts_filtered ("\n");
2992 }
2993 }
2994 if (TYPE_NFN_FIELDS (type) > 0)
2995 {
2996 dump_fn_fieldlists (type, spaces);
2997 }
2998}
2999
e9e79dd9
FF
3000static void
3001print_bound_type (int bt)
3002{
3003 switch (bt)
3004 {
3005 case BOUND_CANNOT_BE_DETERMINED:
3006 printf_filtered ("(BOUND_CANNOT_BE_DETERMINED)");
3007 break;
3008 case BOUND_BY_REF_ON_STACK:
3009 printf_filtered ("(BOUND_BY_REF_ON_STACK)");
3010 break;
3011 case BOUND_BY_VALUE_ON_STACK:
3012 printf_filtered ("(BOUND_BY_VALUE_ON_STACK)");
3013 break;
3014 case BOUND_BY_REF_IN_REG:
3015 printf_filtered ("(BOUND_BY_REF_IN_REG)");
3016 break;
3017 case BOUND_BY_VALUE_IN_REG:
3018 printf_filtered ("(BOUND_BY_VALUE_IN_REG)");
3019 break;
3020 case BOUND_SIMPLE:
3021 printf_filtered ("(BOUND_SIMPLE)");
3022 break;
3023 default:
3024 printf_filtered ("(unknown bound type)");
3025 break;
3026 }
3027}
3028
c906108c
SS
3029static struct obstack dont_print_type_obstack;
3030
3031void
fba45db2 3032recursive_dump_type (struct type *type, int spaces)
c906108c
SS
3033{
3034 int idx;
3035
3036 if (spaces == 0)
3037 obstack_begin (&dont_print_type_obstack, 0);
3038
3039 if (TYPE_NFIELDS (type) > 0
3040 || (TYPE_CPLUS_SPECIFIC (type) && TYPE_NFN_FIELDS (type) > 0))
3041 {
3042 struct type **first_dont_print
c5aa993b 3043 = (struct type **) obstack_base (&dont_print_type_obstack);
c906108c 3044
c5aa993b
JM
3045 int i = (struct type **) obstack_next_free (&dont_print_type_obstack)
3046 - first_dont_print;
c906108c
SS
3047
3048 while (--i >= 0)
3049 {
3050 if (type == first_dont_print[i])
3051 {
3052 printfi_filtered (spaces, "type node ");
d4f3574e 3053 gdb_print_host_address (type, gdb_stdout);
c906108c
SS
3054 printf_filtered (" <same as already seen type>\n");
3055 return;
3056 }
3057 }
3058
3059 obstack_ptr_grow (&dont_print_type_obstack, type);
3060 }
3061
3062 printfi_filtered (spaces, "type node ");
d4f3574e 3063 gdb_print_host_address (type, gdb_stdout);
c906108c
SS
3064 printf_filtered ("\n");
3065 printfi_filtered (spaces, "name '%s' (",
3066 TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>");
d4f3574e 3067 gdb_print_host_address (TYPE_NAME (type), gdb_stdout);
c906108c 3068 printf_filtered (")\n");
e9e79dd9
FF
3069 printfi_filtered (spaces, "tagname '%s' (",
3070 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : "<NULL>");
3071 gdb_print_host_address (TYPE_TAG_NAME (type), gdb_stdout);
3072 printf_filtered (")\n");
c906108c
SS
3073 printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type));
3074 switch (TYPE_CODE (type))
3075 {
c5aa993b
JM
3076 case TYPE_CODE_UNDEF:
3077 printf_filtered ("(TYPE_CODE_UNDEF)");
3078 break;
3079 case TYPE_CODE_PTR:
3080 printf_filtered ("(TYPE_CODE_PTR)");
3081 break;
3082 case TYPE_CODE_ARRAY:
3083 printf_filtered ("(TYPE_CODE_ARRAY)");
3084 break;
3085 case TYPE_CODE_STRUCT:
3086 printf_filtered ("(TYPE_CODE_STRUCT)");
3087 break;
3088 case TYPE_CODE_UNION:
3089 printf_filtered ("(TYPE_CODE_UNION)");
3090 break;
3091 case TYPE_CODE_ENUM:
3092 printf_filtered ("(TYPE_CODE_ENUM)");
3093 break;
3094 case TYPE_CODE_FUNC:
3095 printf_filtered ("(TYPE_CODE_FUNC)");
3096 break;
3097 case TYPE_CODE_INT:
3098 printf_filtered ("(TYPE_CODE_INT)");
3099 break;
3100 case TYPE_CODE_FLT:
3101 printf_filtered ("(TYPE_CODE_FLT)");
3102 break;
3103 case TYPE_CODE_VOID:
3104 printf_filtered ("(TYPE_CODE_VOID)");
3105 break;
3106 case TYPE_CODE_SET:
3107 printf_filtered ("(TYPE_CODE_SET)");
3108 break;
3109 case TYPE_CODE_RANGE:
3110 printf_filtered ("(TYPE_CODE_RANGE)");
3111 break;
3112 case TYPE_CODE_STRING:
3113 printf_filtered ("(TYPE_CODE_STRING)");
3114 break;
e9e79dd9
FF
3115 case TYPE_CODE_BITSTRING:
3116 printf_filtered ("(TYPE_CODE_BITSTRING)");
3117 break;
c5aa993b
JM
3118 case TYPE_CODE_ERROR:
3119 printf_filtered ("(TYPE_CODE_ERROR)");
3120 break;
3121 case TYPE_CODE_MEMBER:
3122 printf_filtered ("(TYPE_CODE_MEMBER)");
3123 break;
3124 case TYPE_CODE_METHOD:
3125 printf_filtered ("(TYPE_CODE_METHOD)");
3126 break;
3127 case TYPE_CODE_REF:
3128 printf_filtered ("(TYPE_CODE_REF)");
3129 break;
3130 case TYPE_CODE_CHAR:
3131 printf_filtered ("(TYPE_CODE_CHAR)");
3132 break;
3133 case TYPE_CODE_BOOL:
3134 printf_filtered ("(TYPE_CODE_BOOL)");
3135 break;
e9e79dd9
FF
3136 case TYPE_CODE_COMPLEX:
3137 printf_filtered ("(TYPE_CODE_COMPLEX)");
3138 break;
c5aa993b
JM
3139 case TYPE_CODE_TYPEDEF:
3140 printf_filtered ("(TYPE_CODE_TYPEDEF)");
3141 break;
e9e79dd9
FF
3142 case TYPE_CODE_TEMPLATE:
3143 printf_filtered ("(TYPE_CODE_TEMPLATE)");
3144 break;
3145 case TYPE_CODE_TEMPLATE_ARG:
3146 printf_filtered ("(TYPE_CODE_TEMPLATE_ARG)");
3147 break;
c5aa993b
JM
3148 default:
3149 printf_filtered ("(UNKNOWN TYPE CODE)");
3150 break;
c906108c
SS
3151 }
3152 puts_filtered ("\n");
3153 printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type));
e9e79dd9
FF
3154 printfi_filtered (spaces, "upper_bound_type 0x%x ",
3155 TYPE_ARRAY_UPPER_BOUND_TYPE (type));
3156 print_bound_type (TYPE_ARRAY_UPPER_BOUND_TYPE (type));
3157 puts_filtered ("\n");
3158 printfi_filtered (spaces, "lower_bound_type 0x%x ",
3159 TYPE_ARRAY_LOWER_BOUND_TYPE (type));
3160 print_bound_type (TYPE_ARRAY_LOWER_BOUND_TYPE (type));
3161 puts_filtered ("\n");
c906108c 3162 printfi_filtered (spaces, "objfile ");
d4f3574e 3163 gdb_print_host_address (TYPE_OBJFILE (type), gdb_stdout);
c906108c
SS
3164 printf_filtered ("\n");
3165 printfi_filtered (spaces, "target_type ");
d4f3574e 3166 gdb_print_host_address (TYPE_TARGET_TYPE (type), gdb_stdout);
c906108c
SS
3167 printf_filtered ("\n");
3168 if (TYPE_TARGET_TYPE (type) != NULL)
3169 {
3170 recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2);
3171 }
3172 printfi_filtered (spaces, "pointer_type ");
d4f3574e 3173 gdb_print_host_address (TYPE_POINTER_TYPE (type), gdb_stdout);
c906108c
SS
3174 printf_filtered ("\n");
3175 printfi_filtered (spaces, "reference_type ");
d4f3574e 3176 gdb_print_host_address (TYPE_REFERENCE_TYPE (type), gdb_stdout);
c906108c 3177 printf_filtered ("\n");
2fdde8f8
DJ
3178 printfi_filtered (spaces, "type_chain ");
3179 gdb_print_host_address (TYPE_CHAIN (type), gdb_stdout);
e9e79dd9 3180 printf_filtered ("\n");
2fdde8f8
DJ
3181 printfi_filtered (spaces, "instance_flags 0x%x", TYPE_INSTANCE_FLAGS (type));
3182 if (TYPE_CONST (type))
3183 {
3184 puts_filtered (" TYPE_FLAG_CONST");
3185 }
3186 if (TYPE_VOLATILE (type))
3187 {
3188 puts_filtered (" TYPE_FLAG_VOLATILE");
3189 }
3190 if (TYPE_CODE_SPACE (type))
3191 {
3192 puts_filtered (" TYPE_FLAG_CODE_SPACE");
3193 }
3194 if (TYPE_DATA_SPACE (type))
3195 {
3196 puts_filtered (" TYPE_FLAG_DATA_SPACE");
3197 }
8b2dbe47
KB
3198 if (TYPE_ADDRESS_CLASS_1 (type))
3199 {
3200 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_1");
3201 }
3202 if (TYPE_ADDRESS_CLASS_2 (type))
3203 {
3204 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_2");
3205 }
2fdde8f8 3206 puts_filtered ("\n");
c906108c 3207 printfi_filtered (spaces, "flags 0x%x", TYPE_FLAGS (type));
762a036f 3208 if (TYPE_UNSIGNED (type))
c906108c
SS
3209 {
3210 puts_filtered (" TYPE_FLAG_UNSIGNED");
3211 }
762a036f
FF
3212 if (TYPE_NOSIGN (type))
3213 {
3214 puts_filtered (" TYPE_FLAG_NOSIGN");
3215 }
3216 if (TYPE_STUB (type))
c906108c
SS
3217 {
3218 puts_filtered (" TYPE_FLAG_STUB");
3219 }
762a036f
FF
3220 if (TYPE_TARGET_STUB (type))
3221 {
3222 puts_filtered (" TYPE_FLAG_TARGET_STUB");
3223 }
3224 if (TYPE_STATIC (type))
3225 {
3226 puts_filtered (" TYPE_FLAG_STATIC");
3227 }
762a036f
FF
3228 if (TYPE_PROTOTYPED (type))
3229 {
3230 puts_filtered (" TYPE_FLAG_PROTOTYPED");
3231 }
3232 if (TYPE_INCOMPLETE (type))
3233 {
3234 puts_filtered (" TYPE_FLAG_INCOMPLETE");
3235 }
762a036f
FF
3236 if (TYPE_VARARGS (type))
3237 {
3238 puts_filtered (" TYPE_FLAG_VARARGS");
3239 }
f5f8a009
EZ
3240 /* This is used for things like AltiVec registers on ppc. Gcc emits
3241 an attribute for the array type, which tells whether or not we
3242 have a vector, instead of a regular array. */
3243 if (TYPE_VECTOR (type))
3244 {
3245 puts_filtered (" TYPE_FLAG_VECTOR");
3246 }
c906108c
SS
3247 puts_filtered ("\n");
3248 printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type));
d4f3574e 3249 gdb_print_host_address (TYPE_FIELDS (type), gdb_stdout);
c906108c
SS
3250 puts_filtered ("\n");
3251 for (idx = 0; idx < TYPE_NFIELDS (type); idx++)
3252 {
3253 printfi_filtered (spaces + 2,
3254 "[%d] bitpos %d bitsize %d type ",
3255 idx, TYPE_FIELD_BITPOS (type, idx),
3256 TYPE_FIELD_BITSIZE (type, idx));
d4f3574e 3257 gdb_print_host_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout);
c906108c
SS
3258 printf_filtered (" name '%s' (",
3259 TYPE_FIELD_NAME (type, idx) != NULL
3260 ? TYPE_FIELD_NAME (type, idx)
3261 : "<NULL>");
d4f3574e 3262 gdb_print_host_address (TYPE_FIELD_NAME (type, idx), gdb_stdout);
c906108c
SS
3263 printf_filtered (")\n");
3264 if (TYPE_FIELD_TYPE (type, idx) != NULL)
3265 {
3266 recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4);
3267 }
3268 }
3269 printfi_filtered (spaces, "vptr_basetype ");
d4f3574e 3270 gdb_print_host_address (TYPE_VPTR_BASETYPE (type), gdb_stdout);
c906108c
SS
3271 puts_filtered ("\n");
3272 if (TYPE_VPTR_BASETYPE (type) != NULL)
3273 {
3274 recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2);
3275 }
3276 printfi_filtered (spaces, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type));
3277 switch (TYPE_CODE (type))
3278 {
c5aa993b
JM
3279 case TYPE_CODE_STRUCT:
3280 printfi_filtered (spaces, "cplus_stuff ");
d4f3574e 3281 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
c5aa993b
JM
3282 puts_filtered ("\n");
3283 print_cplus_stuff (type, spaces);
3284 break;
c906108c 3285
701c159d
AC
3286 case TYPE_CODE_FLT:
3287 printfi_filtered (spaces, "floatformat ");
3288 if (TYPE_FLOATFORMAT (type) == NULL
3289 || TYPE_FLOATFORMAT (type)->name == NULL)
3290 puts_filtered ("(null)");
3291 else
3292 puts_filtered (TYPE_FLOATFORMAT (type)->name);
3293 puts_filtered ("\n");
3294 break;
3295
c5aa993b
JM
3296 default:
3297 /* We have to pick one of the union types to be able print and test
7b83ea04
AC
3298 the value. Pick cplus_struct_type, even though we know it isn't
3299 any particular one. */
c5aa993b 3300 printfi_filtered (spaces, "type_specific ");
d4f3574e 3301 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
c5aa993b
JM
3302 if (TYPE_CPLUS_SPECIFIC (type) != NULL)
3303 {
3304 printf_filtered (" (unknown data form)");
3305 }
3306 printf_filtered ("\n");
3307 break;
c906108c
SS
3308
3309 }
3310 if (spaces == 0)
3311 obstack_free (&dont_print_type_obstack, NULL);
3312}
3313
a14ed312 3314static void build_gdbtypes (void);
c906108c 3315static void
fba45db2 3316build_gdbtypes (void)
c906108c
SS
3317{
3318 builtin_type_void =
3319 init_type (TYPE_CODE_VOID, 1,
3320 0,
3321 "void", (struct objfile *) NULL);
3322 builtin_type_char =
3323 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
4e409299
JB
3324 (TYPE_FLAG_NOSIGN
3325 | (TARGET_CHAR_SIGNED ? 0 : TYPE_FLAG_UNSIGNED)),
c906108c 3326 "char", (struct objfile *) NULL);
c5aa993b 3327 builtin_type_true_char =
9e0b60a8
JM
3328 init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3329 0,
3330 "true character", (struct objfile *) NULL);
c906108c
SS
3331 builtin_type_signed_char =
3332 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3333 0,
3334 "signed char", (struct objfile *) NULL);
3335 builtin_type_unsigned_char =
3336 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3337 TYPE_FLAG_UNSIGNED,
3338 "unsigned char", (struct objfile *) NULL);
3339 builtin_type_short =
3340 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
3341 0,
3342 "short", (struct objfile *) NULL);
3343 builtin_type_unsigned_short =
3344 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
3345 TYPE_FLAG_UNSIGNED,
3346 "unsigned short", (struct objfile *) NULL);
3347 builtin_type_int =
3348 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
3349 0,
3350 "int", (struct objfile *) NULL);
3351 builtin_type_unsigned_int =
3352 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
3353 TYPE_FLAG_UNSIGNED,
3354 "unsigned int", (struct objfile *) NULL);
3355 builtin_type_long =
3356 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
3357 0,
3358 "long", (struct objfile *) NULL);
3359 builtin_type_unsigned_long =
3360 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
3361 TYPE_FLAG_UNSIGNED,
3362 "unsigned long", (struct objfile *) NULL);
3363 builtin_type_long_long =
3364 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
3365 0,
3366 "long long", (struct objfile *) NULL);
c5aa993b 3367 builtin_type_unsigned_long_long =
c906108c
SS
3368 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
3369 TYPE_FLAG_UNSIGNED,
3370 "unsigned long long", (struct objfile *) NULL);
3371 builtin_type_float =
3372 init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
3373 0,
3374 "float", (struct objfile *) NULL);
9c9532c9
CV
3375/* vinschen@redhat.com 2002-02-08:
3376 The below lines are disabled since they are doing the wrong
3377 thing for non-multiarch targets. They are setting the correct
3378 type of floats for the target but while on multiarch targets
3379 this is done everytime the architecture changes, it's done on
3380 non-multiarch targets only on startup, leaving the wrong values
3381 in even if the architecture changes (eg. from big-endian to
3382 little-endian). */
3383#if 0
701c159d 3384 TYPE_FLOATFORMAT (builtin_type_float) = TARGET_FLOAT_FORMAT;
9c9532c9 3385#endif
c906108c
SS
3386 builtin_type_double =
3387 init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
3388 0,
3389 "double", (struct objfile *) NULL);
9c9532c9 3390#if 0
701c159d 3391 TYPE_FLOATFORMAT (builtin_type_double) = TARGET_DOUBLE_FORMAT;
9c9532c9 3392#endif
c906108c
SS
3393 builtin_type_long_double =
3394 init_type (TYPE_CODE_FLT, TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
3395 0,
3396 "long double", (struct objfile *) NULL);
9c9532c9 3397#if 0
701c159d 3398 TYPE_FLOATFORMAT (builtin_type_long_double) = TARGET_LONG_DOUBLE_FORMAT;
9c9532c9 3399#endif
c906108c
SS
3400 builtin_type_complex =
3401 init_type (TYPE_CODE_COMPLEX, 2 * TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
3402 0,
3403 "complex", (struct objfile *) NULL);
3404 TYPE_TARGET_TYPE (builtin_type_complex) = builtin_type_float;
3405 builtin_type_double_complex =
3406 init_type (TYPE_CODE_COMPLEX, 2 * TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
3407 0,
3408 "double complex", (struct objfile *) NULL);
3409 TYPE_TARGET_TYPE (builtin_type_double_complex) = builtin_type_double;
3410 builtin_type_string =
3411 init_type (TYPE_CODE_STRING, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3412 0,
3413 "string", (struct objfile *) NULL);
449a5da4
AC
3414 builtin_type_int0 =
3415 init_type (TYPE_CODE_INT, 0 / 8,
3416 0,
3417 "int0_t", (struct objfile *) NULL);
c906108c
SS
3418 builtin_type_int8 =
3419 init_type (TYPE_CODE_INT, 8 / 8,
3420 0,
3421 "int8_t", (struct objfile *) NULL);
3422 builtin_type_uint8 =
3423 init_type (TYPE_CODE_INT, 8 / 8,
3424 TYPE_FLAG_UNSIGNED,
3425 "uint8_t", (struct objfile *) NULL);
3426 builtin_type_int16 =
3427 init_type (TYPE_CODE_INT, 16 / 8,
3428 0,
3429 "int16_t", (struct objfile *) NULL);
3430 builtin_type_uint16 =
3431 init_type (TYPE_CODE_INT, 16 / 8,
3432 TYPE_FLAG_UNSIGNED,
3433 "uint16_t", (struct objfile *) NULL);
3434 builtin_type_int32 =
3435 init_type (TYPE_CODE_INT, 32 / 8,
3436 0,
3437 "int32_t", (struct objfile *) NULL);
3438 builtin_type_uint32 =
3439 init_type (TYPE_CODE_INT, 32 / 8,
3440 TYPE_FLAG_UNSIGNED,
3441 "uint32_t", (struct objfile *) NULL);
3442 builtin_type_int64 =
3443 init_type (TYPE_CODE_INT, 64 / 8,
3444 0,
3445 "int64_t", (struct objfile *) NULL);
3446 builtin_type_uint64 =
3447 init_type (TYPE_CODE_INT, 64 / 8,
3448 TYPE_FLAG_UNSIGNED,
3449 "uint64_t", (struct objfile *) NULL);
8b982acf
EZ
3450 builtin_type_int128 =
3451 init_type (TYPE_CODE_INT, 128 / 8,
3452 0,
3453 "int128_t", (struct objfile *) NULL);
3454 builtin_type_uint128 =
3455 init_type (TYPE_CODE_INT, 128 / 8,
3456 TYPE_FLAG_UNSIGNED,
3457 "uint128_t", (struct objfile *) NULL);
c906108c
SS
3458 builtin_type_bool =
3459 init_type (TYPE_CODE_BOOL, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3460 0,
3461 "bool", (struct objfile *) NULL);
3462
c5aa993b 3463 /* Add user knob for controlling resolution of opaque types */
c906108c 3464 add_show_from_set
c5aa993b 3465 (add_set_cmd ("opaque-type-resolution", class_support, var_boolean, (char *) &opaque_type_resolution,
c906108c
SS
3466 "Set resolution of opaque struct/class/union types (if set before loading symbols).",
3467 &setlist),
3468 &showlist);
3469 opaque_type_resolution = 1;
3470
917317f4
JM
3471 /* Build SIMD types. */
3472 builtin_type_v4sf
3473 = init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4);
c2d11a7d
JM
3474 builtin_type_v4si
3475 = init_simd_type ("__builtin_v4si", builtin_type_int32, "f", 4);
08cf96df
EZ
3476 builtin_type_v16qi
3477 = init_simd_type ("__builtin_v16qi", builtin_type_int8, "f", 16);
c2d11a7d
JM
3478 builtin_type_v8qi
3479 = init_simd_type ("__builtin_v8qi", builtin_type_int8, "f", 8);
08cf96df
EZ
3480 builtin_type_v8hi
3481 = init_simd_type ("__builtin_v8hi", builtin_type_int16, "f", 8);
c2d11a7d
JM
3482 builtin_type_v4hi
3483 = init_simd_type ("__builtin_v4hi", builtin_type_int16, "f", 4);
3484 builtin_type_v2si
3485 = init_simd_type ("__builtin_v2si", builtin_type_int32, "f", 2);
c4093a6a 3486
ac3aafc7 3487 /* 128 bit vectors. */
3139facc 3488 builtin_type_v2_double = init_vector_type (builtin_type_double, 2);
ac3aafc7 3489 builtin_type_v4_float = init_vector_type (builtin_type_float, 4);
3139facc 3490 builtin_type_v2_int64 = init_vector_type (builtin_type_int64, 2);
ac3aafc7
EZ
3491 builtin_type_v4_int32 = init_vector_type (builtin_type_int32, 4);
3492 builtin_type_v8_int16 = init_vector_type (builtin_type_int16, 8);
3493 builtin_type_v16_int8 = init_vector_type (builtin_type_int8, 16);
3494 /* 64 bit vectors. */
6599f021 3495 builtin_type_v2_float = init_vector_type (builtin_type_float, 2);
ac3aafc7
EZ
3496 builtin_type_v2_int32 = init_vector_type (builtin_type_int32, 2);
3497 builtin_type_v4_int16 = init_vector_type (builtin_type_int16, 4);
3498 builtin_type_v8_int8 = init_vector_type (builtin_type_int8, 8);
3499
b063e7a2
AC
3500 /* Vector types. */
3501 builtin_type_vec64 = build_builtin_type_vec64 ();
3502 builtin_type_vec64i = build_builtin_type_vec64i ();
ac3aafc7 3503 builtin_type_vec128 = build_builtin_type_vec128 ();
3139facc 3504 builtin_type_vec128i = build_builtin_type_vec128i ();
08cf96df 3505
c4093a6a 3506 /* Pointer/Address types. */
ee3a7b7f
JB
3507
3508 /* NOTE: on some targets, addresses and pointers are not necessarily
3509 the same --- for example, on the D10V, pointers are 16 bits long,
3510 but addresses are 32 bits long. See doc/gdbint.texinfo,
3511 ``Pointers Are Not Always Addresses''.
3512
3513 The upshot is:
3514 - gdb's `struct type' always describes the target's
3515 representation.
3516 - gdb's `struct value' objects should always hold values in
3517 target form.
3518 - gdb's CORE_ADDR values are addresses in the unified virtual
3519 address space that the assembler and linker work with. Thus,
3520 since target_read_memory takes a CORE_ADDR as an argument, it
3521 can access any memory on the target, even if the processor has
3522 separate code and data address spaces.
3523
3524 So, for example:
3525 - If v is a value holding a D10V code pointer, its contents are
3526 in target form: a big-endian address left-shifted two bits.
3527 - If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as
3528 sizeof (void *) == 2 on the target.
3529
3530 In this context, builtin_type_CORE_ADDR is a bit odd: it's a
3531 target type for a value the target will never see. It's only
3532 used to hold the values of (typeless) linker symbols, which are
3533 indeed in the unified virtual address space. */
090a2205 3534 builtin_type_void_data_ptr = make_pointer_type (builtin_type_void, NULL);
ee3a7b7f
JB
3535 builtin_type_void_func_ptr
3536 = lookup_pointer_type (lookup_function_type (builtin_type_void));
c4093a6a 3537 builtin_type_CORE_ADDR =
52204a0b 3538 init_type (TYPE_CODE_INT, TARGET_ADDR_BIT / 8,
c4093a6a
JM
3539 TYPE_FLAG_UNSIGNED,
3540 "__CORE_ADDR", (struct objfile *) NULL);
3541 builtin_type_bfd_vma =
3542 init_type (TYPE_CODE_INT, TARGET_BFD_VMA_BIT / 8,
3543 TYPE_FLAG_UNSIGNED,
3544 "__bfd_vma", (struct objfile *) NULL);
c906108c
SS
3545}
3546
a14ed312 3547extern void _initialize_gdbtypes (void);
c906108c 3548void
fba45db2 3549_initialize_gdbtypes (void)
c906108c 3550{
5d161b24 3551 struct cmd_list_element *c;
c906108c 3552 build_gdbtypes ();
0f71a2f6
JM
3553
3554 /* FIXME - For the moment, handle types by swapping them in and out.
3555 Should be using the per-architecture data-pointer and a large
3556 struct. */
c5aa993b
JM
3557 register_gdbarch_swap (&builtin_type_void, sizeof (struct type *), NULL);
3558 register_gdbarch_swap (&builtin_type_char, sizeof (struct type *), NULL);
3559 register_gdbarch_swap (&builtin_type_short, sizeof (struct type *), NULL);
3560 register_gdbarch_swap (&builtin_type_int, sizeof (struct type *), NULL);
3561 register_gdbarch_swap (&builtin_type_long, sizeof (struct type *), NULL);
3562 register_gdbarch_swap (&builtin_type_long_long, sizeof (struct type *), NULL);
3563 register_gdbarch_swap (&builtin_type_signed_char, sizeof (struct type *), NULL);
3564 register_gdbarch_swap (&builtin_type_unsigned_char, sizeof (struct type *), NULL);
3565 register_gdbarch_swap (&builtin_type_unsigned_short, sizeof (struct type *), NULL);
3566 register_gdbarch_swap (&builtin_type_unsigned_int, sizeof (struct type *), NULL);
3567 register_gdbarch_swap (&builtin_type_unsigned_long, sizeof (struct type *), NULL);
3568 register_gdbarch_swap (&builtin_type_unsigned_long_long, sizeof (struct type *), NULL);
3569 register_gdbarch_swap (&builtin_type_float, sizeof (struct type *), NULL);
3570 register_gdbarch_swap (&builtin_type_double, sizeof (struct type *), NULL);
3571 register_gdbarch_swap (&builtin_type_long_double, sizeof (struct type *), NULL);
3572 register_gdbarch_swap (&builtin_type_complex, sizeof (struct type *), NULL);
3573 register_gdbarch_swap (&builtin_type_double_complex, sizeof (struct type *), NULL);
3574 register_gdbarch_swap (&builtin_type_string, sizeof (struct type *), NULL);
3575 register_gdbarch_swap (&builtin_type_int8, sizeof (struct type *), NULL);
3576 register_gdbarch_swap (&builtin_type_uint8, sizeof (struct type *), NULL);
3577 register_gdbarch_swap (&builtin_type_int16, sizeof (struct type *), NULL);
3578 register_gdbarch_swap (&builtin_type_uint16, sizeof (struct type *), NULL);
3579 register_gdbarch_swap (&builtin_type_int32, sizeof (struct type *), NULL);
3580 register_gdbarch_swap (&builtin_type_uint32, sizeof (struct type *), NULL);
3581 register_gdbarch_swap (&builtin_type_int64, sizeof (struct type *), NULL);
3582 register_gdbarch_swap (&builtin_type_uint64, sizeof (struct type *), NULL);
8b982acf
EZ
3583 register_gdbarch_swap (&builtin_type_int128, sizeof (struct type *), NULL);
3584 register_gdbarch_swap (&builtin_type_uint128, sizeof (struct type *), NULL);
917317f4 3585 register_gdbarch_swap (&builtin_type_v4sf, sizeof (struct type *), NULL);
c2d11a7d 3586 register_gdbarch_swap (&builtin_type_v4si, sizeof (struct type *), NULL);
08cf96df 3587 register_gdbarch_swap (&builtin_type_v16qi, sizeof (struct type *), NULL);
c2d11a7d 3588 register_gdbarch_swap (&builtin_type_v8qi, sizeof (struct type *), NULL);
08cf96df 3589 register_gdbarch_swap (&builtin_type_v8hi, sizeof (struct type *), NULL);
c2d11a7d
JM
3590 register_gdbarch_swap (&builtin_type_v4hi, sizeof (struct type *), NULL);
3591 register_gdbarch_swap (&builtin_type_v2si, sizeof (struct type *), NULL);
3139facc 3592 register_gdbarch_swap (&builtin_type_v2_double, sizeof (struct type *), NULL);
ac3aafc7 3593 register_gdbarch_swap (&builtin_type_v4_float, sizeof (struct type *), NULL);
3139facc 3594 register_gdbarch_swap (&builtin_type_v2_int64, sizeof (struct type *), NULL);
ac3aafc7
EZ
3595 register_gdbarch_swap (&builtin_type_v4_int32, sizeof (struct type *), NULL);
3596 register_gdbarch_swap (&builtin_type_v8_int16, sizeof (struct type *), NULL);
3597 register_gdbarch_swap (&builtin_type_v16_int8, sizeof (struct type *), NULL);
6599f021 3598 register_gdbarch_swap (&builtin_type_v2_float, sizeof (struct type *), NULL);
ac3aafc7
EZ
3599 register_gdbarch_swap (&builtin_type_v2_int32, sizeof (struct type *), NULL);
3600 register_gdbarch_swap (&builtin_type_v8_int8, sizeof (struct type *), NULL);
3601 register_gdbarch_swap (&builtin_type_v4_int16, sizeof (struct type *), NULL);
08cf96df 3602 register_gdbarch_swap (&builtin_type_vec128, sizeof (struct type *), NULL);
3139facc 3603 register_gdbarch_swap (&builtin_type_vec128i, sizeof (struct type *), NULL);
090a2205 3604 REGISTER_GDBARCH_SWAP (builtin_type_void_data_ptr);
ee3a7b7f 3605 REGISTER_GDBARCH_SWAP (builtin_type_void_func_ptr);
c4093a6a
JM
3606 REGISTER_GDBARCH_SWAP (builtin_type_CORE_ADDR);
3607 REGISTER_GDBARCH_SWAP (builtin_type_bfd_vma);
0f71a2f6 3608 register_gdbarch_swap (NULL, 0, build_gdbtypes);
5d161b24 3609
598f52df
AC
3610 /* Note: These types do not need to be swapped - they are target
3611 neutral. */
3612 builtin_type_ieee_single_big =
3613 init_type (TYPE_CODE_FLT, floatformat_ieee_single_big.totalsize / 8,
3614 0, "builtin_type_ieee_single_big", NULL);
3615 TYPE_FLOATFORMAT (builtin_type_ieee_single_big) = &floatformat_ieee_single_big;
3616 builtin_type_ieee_single_little =
3617 init_type (TYPE_CODE_FLT, floatformat_ieee_single_little.totalsize / 8,
3618 0, "builtin_type_ieee_single_little", NULL);
069e84fd 3619 TYPE_FLOATFORMAT (builtin_type_ieee_single_little) = &floatformat_ieee_single_little;
598f52df
AC
3620 builtin_type_ieee_double_big =
3621 init_type (TYPE_CODE_FLT, floatformat_ieee_double_big.totalsize / 8,
3622 0, "builtin_type_ieee_double_big", NULL);
069e84fd 3623 TYPE_FLOATFORMAT (builtin_type_ieee_double_big) = &floatformat_ieee_double_big;
598f52df
AC
3624 builtin_type_ieee_double_little =
3625 init_type (TYPE_CODE_FLT, floatformat_ieee_double_little.totalsize / 8,
3626 0, "builtin_type_ieee_double_little", NULL);
069e84fd 3627 TYPE_FLOATFORMAT (builtin_type_ieee_double_little) = &floatformat_ieee_double_little;
598f52df
AC
3628 builtin_type_ieee_double_littlebyte_bigword =
3629 init_type (TYPE_CODE_FLT, floatformat_ieee_double_littlebyte_bigword.totalsize / 8,
3630 0, "builtin_type_ieee_double_littlebyte_bigword", NULL);
069e84fd 3631 TYPE_FLOATFORMAT (builtin_type_ieee_double_littlebyte_bigword) = &floatformat_ieee_double_littlebyte_bigword;
598f52df
AC
3632 builtin_type_i387_ext =
3633 init_type (TYPE_CODE_FLT, floatformat_i387_ext.totalsize / 8,
3634 0, "builtin_type_i387_ext", NULL);
e371b258 3635 TYPE_FLOATFORMAT (builtin_type_i387_ext) = &floatformat_i387_ext;
598f52df
AC
3636 builtin_type_m68881_ext =
3637 init_type (TYPE_CODE_FLT, floatformat_m68881_ext.totalsize / 8,
3638 0, "builtin_type_m68881_ext", NULL);
069e84fd 3639 TYPE_FLOATFORMAT (builtin_type_m68881_ext) = &floatformat_m68881_ext;
598f52df
AC
3640 builtin_type_i960_ext =
3641 init_type (TYPE_CODE_FLT, floatformat_i960_ext.totalsize / 8,
3642 0, "builtin_type_i960_ext", NULL);
069e84fd 3643 TYPE_FLOATFORMAT (builtin_type_i960_ext) = &floatformat_i960_ext;
598f52df
AC
3644 builtin_type_m88110_ext =
3645 init_type (TYPE_CODE_FLT, floatformat_m88110_ext.totalsize / 8,
3646 0, "builtin_type_m88110_ext", NULL);
069e84fd 3647 TYPE_FLOATFORMAT (builtin_type_m88110_ext) = &floatformat_m88110_ext;
598f52df
AC
3648 builtin_type_m88110_harris_ext =
3649 init_type (TYPE_CODE_FLT, floatformat_m88110_harris_ext.totalsize / 8,
3650 0, "builtin_type_m88110_harris_ext", NULL);
069e84fd 3651 TYPE_FLOATFORMAT (builtin_type_m88110_harris_ext) = &floatformat_m88110_harris_ext;
598f52df
AC
3652 builtin_type_arm_ext_big =
3653 init_type (TYPE_CODE_FLT, floatformat_arm_ext_big.totalsize / 8,
3654 0, "builtin_type_arm_ext_big", NULL);
069e84fd 3655 TYPE_FLOATFORMAT (builtin_type_arm_ext_big) = &floatformat_arm_ext_big;
598f52df
AC
3656 builtin_type_arm_ext_littlebyte_bigword =
3657 init_type (TYPE_CODE_FLT, floatformat_arm_ext_littlebyte_bigword.totalsize / 8,
3658 0, "builtin_type_arm_ext_littlebyte_bigword", NULL);
069e84fd 3659 TYPE_FLOATFORMAT (builtin_type_arm_ext_littlebyte_bigword) = &floatformat_arm_ext_littlebyte_bigword;
598f52df
AC
3660 builtin_type_ia64_spill_big =
3661 init_type (TYPE_CODE_FLT, floatformat_ia64_spill_big.totalsize / 8,
3662 0, "builtin_type_ia64_spill_big", NULL);
069e84fd 3663 TYPE_FLOATFORMAT (builtin_type_ia64_spill_big) = &floatformat_ia64_spill_big;
598f52df
AC
3664 builtin_type_ia64_spill_little =
3665 init_type (TYPE_CODE_FLT, floatformat_ia64_spill_little.totalsize / 8,
3666 0, "builtin_type_ia64_spill_little", NULL);
069e84fd 3667 TYPE_FLOATFORMAT (builtin_type_ia64_spill_little) = &floatformat_ia64_spill_little;
598f52df
AC
3668 builtin_type_ia64_quad_big =
3669 init_type (TYPE_CODE_FLT, floatformat_ia64_quad_big.totalsize / 8,
3670 0, "builtin_type_ia64_quad_big", NULL);
069e84fd 3671 TYPE_FLOATFORMAT (builtin_type_ia64_quad_big) = &floatformat_ia64_quad_big;
598f52df
AC
3672 builtin_type_ia64_quad_little =
3673 init_type (TYPE_CODE_FLT, floatformat_ia64_quad_little.totalsize / 8,
3674 0, "builtin_type_ia64_quad_little", NULL);
069e84fd 3675 TYPE_FLOATFORMAT (builtin_type_ia64_quad_little) = &floatformat_ia64_quad_little;
598f52df 3676
5d161b24
DB
3677 add_show_from_set (
3678 add_set_cmd ("overload", no_class, var_zinteger, (char *) &overload_debug,
3679 "Set debugging of C++ overloading.\n\
3680 When enabled, ranking of the functions\n\
3681 is displayed.", &setdebuglist),
3682 &showdebuglist);
c906108c 3683}
This page took 0.726561 seconds and 4 git commands to generate.