]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/gdbtypes.c
* config/tc-mips.c (HAVE_64BIT_ADDRESS_CONSTANTS): Remove.
[thirdparty/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
5c4e30ca
DC
1900 if (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION
1901 || code == TYPE_CODE_NAMESPACE)
c906108c
SS
1902 {
1903 INIT_CPLUS_SPECIFIC (type);
1904 }
1905 return (type);
1906}
1907
0e101458
AC
1908/* Helper function. Create an empty composite type. */
1909
1910struct type *
1911init_composite_type (char *name, enum type_code code)
1912{
1913 struct type *t;
1914 gdb_assert (code == TYPE_CODE_STRUCT
1915 || code == TYPE_CODE_UNION);
1916 t = init_type (code, 0, 0, NULL, NULL);
1917 TYPE_TAG_NAME (t) = name;
1918 return t;
1919}
1920
1921/* Helper function. Append a field to a composite type. */
1922
1923void
1924append_composite_type_field (struct type *t, char *name, struct type *field)
1925{
1926 struct field *f;
1927 TYPE_NFIELDS (t) = TYPE_NFIELDS (t) + 1;
1928 TYPE_FIELDS (t) = xrealloc (TYPE_FIELDS (t),
1929 sizeof (struct field) * TYPE_NFIELDS (t));
1930 f = &(TYPE_FIELDS (t)[TYPE_NFIELDS (t) - 1]);
1931 memset (f, 0, sizeof f[0]);
1932 FIELD_TYPE (f[0]) = field;
1933 FIELD_NAME (f[0]) = name;
1934 if (TYPE_CODE (t) == TYPE_CODE_UNION)
1935 {
73d322b1 1936 if (TYPE_LENGTH (t) < TYPE_LENGTH (field))
0e101458
AC
1937 TYPE_LENGTH (t) = TYPE_LENGTH (field);
1938 }
1939 else if (TYPE_CODE (t) == TYPE_CODE_STRUCT)
1940 {
1941 TYPE_LENGTH (t) = TYPE_LENGTH (t) + TYPE_LENGTH (field);
1942 if (TYPE_NFIELDS (t) > 1)
1943 {
1944 FIELD_BITPOS (f[0]) = (FIELD_BITPOS (f[-1])
1945 + TYPE_LENGTH (field) * TARGET_CHAR_BIT);
1946 }
1947 }
1948}
1949
c906108c
SS
1950/* Look up a fundamental type for the specified objfile.
1951 May need to construct such a type if this is the first use.
1952
1953 Some object file formats (ELF, COFF, etc) do not define fundamental
1954 types such as "int" or "double". Others (stabs for example), do
1955 define fundamental types.
1956
1957 For the formats which don't provide fundamental types, gdb can create
1958 such types, using defaults reasonable for the current language and
1959 the current target machine.
1960
1961 NOTE: This routine is obsolescent. Each debugging format reader
1962 should manage it's own fundamental types, either creating them from
1963 suitable defaults or reading them from the debugging information,
1964 whichever is appropriate. The DWARF reader has already been
1965 fixed to do this. Once the other readers are fixed, this routine
1966 will go away. Also note that fundamental types should be managed
1967 on a compilation unit basis in a multi-language environment, not
1968 on a linkage unit basis as is done here. */
1969
1970
1971struct type *
fba45db2 1972lookup_fundamental_type (struct objfile *objfile, int typeid)
c906108c
SS
1973{
1974 register struct type **typep;
1975 register int nbytes;
1976
1977 if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
1978 {
1979 error ("internal error - invalid fundamental type id %d", typeid);
1980 }
1981
1982 /* If this is the first time we need a fundamental type for this objfile
1983 then we need to initialize the vector of type pointers. */
c5aa993b
JM
1984
1985 if (objfile->fundamental_types == NULL)
c906108c
SS
1986 {
1987 nbytes = FT_NUM_MEMBERS * sizeof (struct type *);
c5aa993b
JM
1988 objfile->fundamental_types = (struct type **)
1989 obstack_alloc (&objfile->type_obstack, nbytes);
1990 memset ((char *) objfile->fundamental_types, 0, nbytes);
c906108c
SS
1991 OBJSTAT (objfile, n_types += FT_NUM_MEMBERS);
1992 }
1993
1994 /* Look for this particular type in the fundamental type vector. If one is
1995 not found, create and install one appropriate for the current language. */
1996
c5aa993b 1997 typep = objfile->fundamental_types + typeid;
c906108c
SS
1998 if (*typep == NULL)
1999 {
2000 *typep = create_fundamental_type (objfile, typeid);
2001 }
2002
2003 return (*typep);
2004}
2005
2006int
fba45db2 2007can_dereference (struct type *t)
c906108c
SS
2008{
2009 /* FIXME: Should we return true for references as well as pointers? */
2010 CHECK_TYPEDEF (t);
2011 return
2012 (t != NULL
2013 && TYPE_CODE (t) == TYPE_CODE_PTR
2014 && TYPE_CODE (TYPE_TARGET_TYPE (t)) != TYPE_CODE_VOID);
2015}
2016
adf40b2e 2017int
fba45db2 2018is_integral_type (struct type *t)
adf40b2e
JM
2019{
2020 CHECK_TYPEDEF (t);
2021 return
2022 ((t != NULL)
d4f3574e
SS
2023 && ((TYPE_CODE (t) == TYPE_CODE_INT)
2024 || (TYPE_CODE (t) == TYPE_CODE_ENUM)
2025 || (TYPE_CODE (t) == TYPE_CODE_CHAR)
2026 || (TYPE_CODE (t) == TYPE_CODE_RANGE)
2027 || (TYPE_CODE (t) == TYPE_CODE_BOOL)));
adf40b2e
JM
2028}
2029
7b83ea04 2030/* Check whether BASE is an ancestor or base class or DCLASS
c906108c
SS
2031 Return 1 if so, and 0 if not.
2032 Note: callers may want to check for identity of the types before
2033 calling this function -- identical types are considered to satisfy
2034 the ancestor relationship even if they're identical */
2035
2036int
fba45db2 2037is_ancestor (struct type *base, struct type *dclass)
c906108c
SS
2038{
2039 int i;
c5aa993b 2040
c906108c
SS
2041 CHECK_TYPEDEF (base);
2042 CHECK_TYPEDEF (dclass);
2043
2044 if (base == dclass)
2045 return 1;
6b1ba9a0
ND
2046 if (TYPE_NAME (base) && TYPE_NAME (dclass) &&
2047 !strcmp (TYPE_NAME (base), TYPE_NAME (dclass)))
2048 return 1;
c906108c
SS
2049
2050 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
2051 if (is_ancestor (base, TYPE_BASECLASS (dclass, i)))
2052 return 1;
2053
2054 return 0;
2055}
2056
2057
2058
2059/* See whether DCLASS has a virtual table. This routine is aimed at
2060 the HP/Taligent ANSI C++ runtime model, and may not work with other
2061 runtime models. Return 1 => Yes, 0 => No. */
2062
2063int
fba45db2 2064has_vtable (struct type *dclass)
c906108c
SS
2065{
2066 /* In the HP ANSI C++ runtime model, a class has a vtable only if it
2067 has virtual functions or virtual bases. */
2068
2069 register int i;
2070
c5aa993b 2071 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
c906108c 2072 return 0;
c5aa993b 2073
c906108c 2074 /* First check for the presence of virtual bases */
c5aa993b
JM
2075 if (TYPE_FIELD_VIRTUAL_BITS (dclass))
2076 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
2077 if (B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i))
2078 return 1;
2079
c906108c 2080 /* Next check for virtual functions */
c5aa993b
JM
2081 if (TYPE_FN_FIELDLISTS (dclass))
2082 for (i = 0; i < TYPE_NFN_FIELDS (dclass); i++)
2083 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, i), 0))
c906108c 2084 return 1;
c5aa993b
JM
2085
2086 /* Recurse on non-virtual bases to see if any of them needs a vtable */
2087 if (TYPE_FIELD_VIRTUAL_BITS (dclass))
2088 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
2089 if ((!B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i)) &&
2090 (has_vtable (TYPE_FIELD_TYPE (dclass, i))))
2091 return 1;
2092
2093 /* Well, maybe we don't need a virtual table */
c906108c
SS
2094 return 0;
2095}
2096
2097/* Return a pointer to the "primary base class" of DCLASS.
c5aa993b 2098
c906108c
SS
2099 A NULL return indicates that DCLASS has no primary base, or that it
2100 couldn't be found (insufficient information).
c5aa993b 2101
c906108c
SS
2102 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
2103 and may not work with other runtime models. */
2104
2105struct type *
fba45db2 2106primary_base_class (struct type *dclass)
c906108c
SS
2107{
2108 /* In HP ANSI C++'s runtime model, a "primary base class" of a class
2109 is the first directly inherited, non-virtual base class that
2110 requires a virtual table */
2111
2112 register int i;
2113
c5aa993b 2114 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
c906108c
SS
2115 return NULL;
2116
c5aa993b
JM
2117 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
2118 if (!TYPE_FIELD_VIRTUAL (dclass, i) &&
2119 has_vtable (TYPE_FIELD_TYPE (dclass, i)))
2120 return TYPE_FIELD_TYPE (dclass, i);
c906108c
SS
2121
2122 return NULL;
2123}
2124
2125/* Global manipulated by virtual_base_list[_aux]() */
2126
c5aa993b 2127static struct vbase *current_vbase_list = NULL;
c906108c
SS
2128
2129/* Return a pointer to a null-terminated list of struct vbase
2130 items. The vbasetype pointer of each item in the list points to the
2131 type information for a virtual base of the argument DCLASS.
c5aa993b 2132
7b83ea04 2133 Helper function for virtual_base_list().
c906108c
SS
2134 Note: the list goes backward, right-to-left. virtual_base_list()
2135 copies the items out in reverse order. */
2136
7a292a7a 2137static void
fba45db2 2138virtual_base_list_aux (struct type *dclass)
c906108c 2139{
c5aa993b 2140 struct vbase *tmp_vbase;
c906108c
SS
2141 register int i;
2142
c5aa993b 2143 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
7a292a7a 2144 return;
c906108c
SS
2145
2146 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
2147 {
2148 /* Recurse on this ancestor, first */
c5aa993b 2149 virtual_base_list_aux (TYPE_FIELD_TYPE (dclass, i));
c906108c
SS
2150
2151 /* If this current base is itself virtual, add it to the list */
c5aa993b
JM
2152 if (BASETYPE_VIA_VIRTUAL (dclass, i))
2153 {
2154 struct type *basetype = TYPE_FIELD_TYPE (dclass, i);
2155
2156 /* Check if base already recorded */
2157 tmp_vbase = current_vbase_list;
2158 while (tmp_vbase)
2159 {
2160 if (tmp_vbase->vbasetype == basetype)
2161 break; /* found it */
2162 tmp_vbase = tmp_vbase->next;
2163 }
2164
2165 if (!tmp_vbase) /* normal exit from loop */
2166 {
2167 /* Allocate new item for this virtual base */
2168 tmp_vbase = (struct vbase *) xmalloc (sizeof (struct vbase));
2169
2170 /* Stick it on at the end of the list */
2171 tmp_vbase->vbasetype = basetype;
2172 tmp_vbase->next = current_vbase_list;
2173 current_vbase_list = tmp_vbase;
2174 }
2175 } /* if virtual */
2176 } /* for loop over bases */
c906108c
SS
2177}
2178
2179
2180/* Compute the list of virtual bases in the right order. Virtual
2181 bases are laid out in the object's memory area in order of their
2182 occurrence in a depth-first, left-to-right search through the
2183 ancestors.
c5aa993b 2184
c906108c
SS
2185 Argument DCLASS is the type whose virtual bases are required.
2186 Return value is the address of a null-terminated array of pointers
2187 to struct type items.
c5aa993b 2188
c906108c
SS
2189 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
2190 and may not work with other runtime models.
c5aa993b 2191
c906108c
SS
2192 This routine merely hands off the argument to virtual_base_list_aux()
2193 and then copies the result into an array to save space. */
2194
2195struct type **
fba45db2 2196virtual_base_list (struct type *dclass)
c906108c 2197{
c5aa993b
JM
2198 register struct vbase *tmp_vbase;
2199 register struct vbase *tmp_vbase_2;
c906108c
SS
2200 register int i;
2201 int count;
c5aa993b 2202 struct type **vbase_array;
c906108c
SS
2203
2204 current_vbase_list = NULL;
c5aa993b 2205 virtual_base_list_aux (dclass);
c906108c 2206
c5aa993b 2207 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next)
c906108c
SS
2208 /* no body */ ;
2209
2210 count = i;
2211
c5aa993b 2212 vbase_array = (struct type **) xmalloc ((count + 1) * sizeof (struct type *));
c906108c 2213
c5aa993b 2214 for (i = count - 1, tmp_vbase = current_vbase_list; i >= 0; i--, tmp_vbase = tmp_vbase->next)
c906108c
SS
2215 vbase_array[i] = tmp_vbase->vbasetype;
2216
2217 /* Get rid of constructed chain */
2218 tmp_vbase_2 = tmp_vbase = current_vbase_list;
2219 while (tmp_vbase)
2220 {
2221 tmp_vbase = tmp_vbase->next;
b8c9b27d 2222 xfree (tmp_vbase_2);
c906108c
SS
2223 tmp_vbase_2 = tmp_vbase;
2224 }
c5aa993b 2225
c906108c
SS
2226 vbase_array[count] = NULL;
2227 return vbase_array;
2228}
2229
2230/* Return the length of the virtual base list of the type DCLASS. */
2231
2232int
fba45db2 2233virtual_base_list_length (struct type *dclass)
c906108c
SS
2234{
2235 register int i;
c5aa993b
JM
2236 register struct vbase *tmp_vbase;
2237
c906108c 2238 current_vbase_list = NULL;
c5aa993b 2239 virtual_base_list_aux (dclass);
c906108c 2240
c5aa993b 2241 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next)
c906108c
SS
2242 /* no body */ ;
2243 return i;
2244}
2245
2246/* Return the number of elements of the virtual base list of the type
2247 DCLASS, ignoring those appearing in the primary base (and its
2248 primary base, recursively). */
2249
2250int
fba45db2 2251virtual_base_list_length_skip_primaries (struct type *dclass)
c906108c
SS
2252{
2253 register int i;
c5aa993b
JM
2254 register struct vbase *tmp_vbase;
2255 struct type *primary;
c906108c
SS
2256
2257 primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL;
2258
2259 if (!primary)
2260 return virtual_base_list_length (dclass);
2261
2262 current_vbase_list = NULL;
c5aa993b 2263 virtual_base_list_aux (dclass);
c906108c 2264
c5aa993b 2265 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; tmp_vbase = tmp_vbase->next)
c906108c
SS
2266 {
2267 if (virtual_base_index (tmp_vbase->vbasetype, primary) >= 0)
c5aa993b 2268 continue;
c906108c
SS
2269 i++;
2270 }
2271 return i;
2272}
2273
2274
2275/* Return the index (position) of type BASE, which is a virtual base
2276 class of DCLASS, in the latter's virtual base list. A return of -1
2277 indicates "not found" or a problem. */
2278
2279int
fba45db2 2280virtual_base_index (struct type *base, struct type *dclass)
c906108c 2281{
c5aa993b 2282 register struct type *vbase;
c906108c
SS
2283 register int i;
2284
c5aa993b
JM
2285 if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) ||
2286 (TYPE_CODE (base) != TYPE_CODE_CLASS))
c906108c
SS
2287 return -1;
2288
2289 i = 0;
015a42b4 2290 vbase = virtual_base_list (dclass)[0];
c906108c
SS
2291 while (vbase)
2292 {
2293 if (vbase == base)
c5aa993b 2294 break;
015a42b4 2295 vbase = virtual_base_list (dclass)[++i];
c906108c
SS
2296 }
2297
2298 return vbase ? i : -1;
2299}
2300
2301
2302
2303/* Return the index (position) of type BASE, which is a virtual base
2304 class of DCLASS, in the latter's virtual base list. Skip over all
2305 bases that may appear in the virtual base list of the primary base
2306 class of DCLASS (recursively). A return of -1 indicates "not
2307 found" or a problem. */
2308
2309int
fba45db2 2310virtual_base_index_skip_primaries (struct type *base, struct type *dclass)
c906108c 2311{
c5aa993b 2312 register struct type *vbase;
c906108c 2313 register int i, j;
c5aa993b 2314 struct type *primary;
c906108c 2315
c5aa993b
JM
2316 if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) ||
2317 (TYPE_CODE (base) != TYPE_CODE_CLASS))
c906108c
SS
2318 return -1;
2319
c5aa993b 2320 primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL;
c906108c
SS
2321
2322 j = -1;
2323 i = 0;
015a42b4 2324 vbase = virtual_base_list (dclass)[0];
c906108c
SS
2325 while (vbase)
2326 {
c5aa993b
JM
2327 if (!primary || (virtual_base_index_skip_primaries (vbase, primary) < 0))
2328 j++;
c906108c 2329 if (vbase == base)
c5aa993b 2330 break;
015a42b4 2331 vbase = virtual_base_list (dclass)[++i];
c906108c
SS
2332 }
2333
2334 return vbase ? j : -1;
2335}
2336
2337/* Return position of a derived class DCLASS in the list of
2338 * primary bases starting with the remotest ancestor.
2339 * Position returned is 0-based. */
2340
2341int
fba45db2 2342class_index_in_primary_list (struct type *dclass)
c906108c 2343{
c5aa993b 2344 struct type *pbc; /* primary base class */
c906108c 2345
c5aa993b 2346 /* Simply recurse on primary base */
c906108c
SS
2347 pbc = TYPE_PRIMARY_BASE (dclass);
2348 if (pbc)
2349 return 1 + class_index_in_primary_list (pbc);
2350 else
2351 return 0;
2352}
2353
2354/* Return a count of the number of virtual functions a type has.
2355 * This includes all the virtual functions it inherits from its
2356 * base classes too.
2357 */
2358
2359/* pai: FIXME This doesn't do the right thing: count redefined virtual
2360 * functions only once (latest redefinition)
2361 */
2362
2363int
fba45db2 2364count_virtual_fns (struct type *dclass)
c906108c 2365{
c5aa993b 2366 int fn, oi; /* function and overloaded instance indices */
c5aa993b
JM
2367 int vfuncs; /* count to return */
2368
2369 /* recurse on bases that can share virtual table */
2370 struct type *pbc = primary_base_class (dclass);
c906108c
SS
2371 if (pbc)
2372 vfuncs = count_virtual_fns (pbc);
7f7e9482
AC
2373 else
2374 vfuncs = 0;
c5aa993b 2375
c906108c
SS
2376 for (fn = 0; fn < TYPE_NFN_FIELDS (dclass); fn++)
2377 for (oi = 0; oi < TYPE_FN_FIELDLIST_LENGTH (dclass, fn); oi++)
2378 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, fn), oi))
c5aa993b 2379 vfuncs++;
c906108c
SS
2380
2381 return vfuncs;
2382}
c906108c
SS
2383\f
2384
c5aa993b 2385
c906108c
SS
2386/* Functions for overload resolution begin here */
2387
2388/* Compare two badness vectors A and B and return the result.
2389 * 0 => A and B are identical
2390 * 1 => A and B are incomparable
2391 * 2 => A is better than B
2392 * 3 => A is worse than B */
2393
2394int
fba45db2 2395compare_badness (struct badness_vector *a, struct badness_vector *b)
c906108c
SS
2396{
2397 int i;
2398 int tmp;
c5aa993b
JM
2399 short found_pos = 0; /* any positives in c? */
2400 short found_neg = 0; /* any negatives in c? */
2401
2402 /* differing lengths => incomparable */
c906108c
SS
2403 if (a->length != b->length)
2404 return 1;
2405
c5aa993b
JM
2406 /* Subtract b from a */
2407 for (i = 0; i < a->length; i++)
c906108c
SS
2408 {
2409 tmp = a->rank[i] - b->rank[i];
2410 if (tmp > 0)
c5aa993b 2411 found_pos = 1;
c906108c 2412 else if (tmp < 0)
c5aa993b 2413 found_neg = 1;
c906108c
SS
2414 }
2415
2416 if (found_pos)
2417 {
2418 if (found_neg)
c5aa993b 2419 return 1; /* incomparable */
c906108c 2420 else
c5aa993b 2421 return 3; /* A > B */
c906108c 2422 }
c5aa993b
JM
2423 else
2424 /* no positives */
c906108c
SS
2425 {
2426 if (found_neg)
c5aa993b 2427 return 2; /* A < B */
c906108c 2428 else
c5aa993b 2429 return 0; /* A == B */
c906108c
SS
2430 }
2431}
2432
2433/* Rank a function by comparing its parameter types (PARMS, length NPARMS),
2434 * to the types of an argument list (ARGS, length NARGS).
2435 * Return a pointer to a badness vector. This has NARGS + 1 entries. */
2436
2437struct badness_vector *
fba45db2 2438rank_function (struct type **parms, int nparms, struct type **args, int nargs)
c906108c
SS
2439{
2440 int i;
c5aa993b 2441 struct badness_vector *bv;
c906108c
SS
2442 int min_len = nparms < nargs ? nparms : nargs;
2443
2444 bv = xmalloc (sizeof (struct badness_vector));
c5aa993b 2445 bv->length = nargs + 1; /* add 1 for the length-match rank */
c906108c
SS
2446 bv->rank = xmalloc ((nargs + 1) * sizeof (int));
2447
2448 /* First compare the lengths of the supplied lists.
2449 * If there is a mismatch, set it to a high value. */
c5aa993b 2450
c906108c
SS
2451 /* pai/1997-06-03 FIXME: when we have debug info about default
2452 * arguments and ellipsis parameter lists, we should consider those
2453 * and rank the length-match more finely. */
2454
2455 LENGTH_MATCH (bv) = (nargs != nparms) ? LENGTH_MISMATCH_BADNESS : 0;
2456
2457 /* Now rank all the parameters of the candidate function */
74cc24b0
DB
2458 for (i = 1; i <= min_len; i++)
2459 bv->rank[i] = rank_one_type (parms[i-1], args[i-1]);
c906108c 2460
c5aa993b
JM
2461 /* If more arguments than parameters, add dummy entries */
2462 for (i = min_len + 1; i <= nargs; i++)
c906108c
SS
2463 bv->rank[i] = TOO_FEW_PARAMS_BADNESS;
2464
2465 return bv;
2466}
2467
973ccf8b
DJ
2468/* Compare the names of two integer types, assuming that any sign
2469 qualifiers have been checked already. We do it this way because
2470 there may be an "int" in the name of one of the types. */
2471
2472static int
2473integer_types_same_name_p (const char *first, const char *second)
2474{
2475 int first_p, second_p;
2476
2477 /* If both are shorts, return 1; if neither is a short, keep checking. */
2478 first_p = (strstr (first, "short") != NULL);
2479 second_p = (strstr (second, "short") != NULL);
2480 if (first_p && second_p)
2481 return 1;
2482 if (first_p || second_p)
2483 return 0;
2484
2485 /* Likewise for long. */
2486 first_p = (strstr (first, "long") != NULL);
2487 second_p = (strstr (second, "long") != NULL);
2488 if (first_p && second_p)
2489 return 1;
2490 if (first_p || second_p)
2491 return 0;
2492
2493 /* Likewise for char. */
2494 first_p = (strstr (first, "char") != NULL);
2495 second_p = (strstr (second, "char") != NULL);
2496 if (first_p && second_p)
2497 return 1;
2498 if (first_p || second_p)
2499 return 0;
2500
2501 /* They must both be ints. */
2502 return 1;
2503}
2504
c906108c
SS
2505/* Compare one type (PARM) for compatibility with another (ARG).
2506 * PARM is intended to be the parameter type of a function; and
2507 * ARG is the supplied argument's type. This function tests if
2508 * the latter can be converted to the former.
2509 *
2510 * Return 0 if they are identical types;
2511 * Otherwise, return an integer which corresponds to how compatible
2512 * PARM is to ARG. The higher the return value, the worse the match.
2513 * Generally the "bad" conversions are all uniformly assigned a 100 */
2514
2515int
fba45db2 2516rank_one_type (struct type *parm, struct type *arg)
c906108c
SS
2517{
2518 /* Identical type pointers */
2519 /* However, this still doesn't catch all cases of same type for arg
2520 * and param. The reason is that builtin types are different from
2521 * the same ones constructed from the object. */
2522 if (parm == arg)
2523 return 0;
2524
2525 /* Resolve typedefs */
2526 if (TYPE_CODE (parm) == TYPE_CODE_TYPEDEF)
2527 parm = check_typedef (parm);
2528 if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF)
2529 arg = check_typedef (arg);
2530
070ad9f0
DB
2531 /*
2532 Well, damnit, if the names are exactly the same,
2533 i'll say they are exactly the same. This happens when we generate
2534 method stubs. The types won't point to the same address, but they
2535 really are the same.
2536 */
2537
6b1ba9a0
ND
2538 if (TYPE_NAME (parm) && TYPE_NAME (arg) &&
2539 !strcmp (TYPE_NAME (parm), TYPE_NAME (arg)))
070ad9f0
DB
2540 return 0;
2541
c906108c
SS
2542 /* Check if identical after resolving typedefs */
2543 if (parm == arg)
2544 return 0;
2545
db577aea
AC
2546 /* See through references, since we can almost make non-references
2547 references. */
2548 if (TYPE_CODE (arg) == TYPE_CODE_REF)
6b1ba9a0 2549 return (rank_one_type (parm, TYPE_TARGET_TYPE (arg))
db577aea
AC
2550 + REFERENCE_CONVERSION_BADNESS);
2551 if (TYPE_CODE (parm) == TYPE_CODE_REF)
6b1ba9a0 2552 return (rank_one_type (TYPE_TARGET_TYPE (parm), arg)
db577aea 2553 + REFERENCE_CONVERSION_BADNESS);
5d161b24 2554 if (overload_debug)
db577aea 2555 /* Debugging only. */
5d161b24
DB
2556 fprintf_filtered (gdb_stderr,"------ Arg is %s [%d], parm is %s [%d]\n",
2557 TYPE_NAME (arg), TYPE_CODE (arg), TYPE_NAME (parm), TYPE_CODE (parm));
c906108c
SS
2558
2559 /* x -> y means arg of type x being supplied for parameter of type y */
2560
2561 switch (TYPE_CODE (parm))
2562 {
c5aa993b
JM
2563 case TYPE_CODE_PTR:
2564 switch (TYPE_CODE (arg))
2565 {
2566 case TYPE_CODE_PTR:
2567 if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID)
2568 return VOID_PTR_CONVERSION_BADNESS;
2569 else
2570 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2571 case TYPE_CODE_ARRAY:
2572 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2573 case TYPE_CODE_FUNC:
2574 return rank_one_type (TYPE_TARGET_TYPE (parm), arg);
2575 case TYPE_CODE_INT:
2576 case TYPE_CODE_ENUM:
2577 case TYPE_CODE_CHAR:
2578 case TYPE_CODE_RANGE:
2579 case TYPE_CODE_BOOL:
2580 return POINTER_CONVERSION_BADNESS;
2581 default:
2582 return INCOMPATIBLE_TYPE_BADNESS;
2583 }
2584 case TYPE_CODE_ARRAY:
2585 switch (TYPE_CODE (arg))
2586 {
2587 case TYPE_CODE_PTR:
2588 case TYPE_CODE_ARRAY:
2589 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2590 default:
2591 return INCOMPATIBLE_TYPE_BADNESS;
2592 }
2593 case TYPE_CODE_FUNC:
2594 switch (TYPE_CODE (arg))
2595 {
2596 case TYPE_CODE_PTR: /* funcptr -> func */
2597 return rank_one_type (parm, TYPE_TARGET_TYPE (arg));
2598 default:
2599 return INCOMPATIBLE_TYPE_BADNESS;
2600 }
2601 case TYPE_CODE_INT:
2602 switch (TYPE_CODE (arg))
2603 {
2604 case TYPE_CODE_INT:
2605 if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
2606 {
2607 /* Deal with signed, unsigned, and plain chars and
7b83ea04 2608 signed and unsigned ints */
c5aa993b
JM
2609 if (TYPE_NOSIGN (parm))
2610 {
2611 /* This case only for character types */
2612 if (TYPE_NOSIGN (arg)) /* plain char -> plain char */
2613 return 0;
2614 else
1c5cb38e 2615 return INTEGER_CONVERSION_BADNESS; /* signed/unsigned char -> plain char */
c5aa993b
JM
2616 }
2617 else if (TYPE_UNSIGNED (parm))
2618 {
2619 if (TYPE_UNSIGNED (arg))
2620 {
973ccf8b
DJ
2621 /* unsigned int -> unsigned int, or unsigned long -> unsigned long */
2622 if (integer_types_same_name_p (TYPE_NAME (parm), TYPE_NAME (arg)))
2623 return 0;
2624 else if (integer_types_same_name_p (TYPE_NAME (arg), "int")
2625 && integer_types_same_name_p (TYPE_NAME (parm), "long"))
c5aa993b
JM
2626 return INTEGER_PROMOTION_BADNESS; /* unsigned int -> unsigned long */
2627 else
1c5cb38e 2628 return INTEGER_CONVERSION_BADNESS; /* unsigned long -> unsigned int */
c5aa993b
JM
2629 }
2630 else
2631 {
973ccf8b
DJ
2632 if (integer_types_same_name_p (TYPE_NAME (arg), "long")
2633 && integer_types_same_name_p (TYPE_NAME (parm), "int"))
1c5cb38e 2634 return INTEGER_CONVERSION_BADNESS; /* signed long -> unsigned int */
c5aa993b
JM
2635 else
2636 return INTEGER_CONVERSION_BADNESS; /* signed int/long -> unsigned int/long */
2637 }
2638 }
2639 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
2640 {
973ccf8b 2641 if (integer_types_same_name_p (TYPE_NAME (parm), TYPE_NAME (arg)))
c5aa993b 2642 return 0;
973ccf8b
DJ
2643 else if (integer_types_same_name_p (TYPE_NAME (arg), "int")
2644 && integer_types_same_name_p (TYPE_NAME (parm), "long"))
c5aa993b
JM
2645 return INTEGER_PROMOTION_BADNESS;
2646 else
1c5cb38e 2647 return INTEGER_CONVERSION_BADNESS;
c5aa993b
JM
2648 }
2649 else
1c5cb38e 2650 return INTEGER_CONVERSION_BADNESS;
c5aa993b
JM
2651 }
2652 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2653 return INTEGER_PROMOTION_BADNESS;
2654 else
1c5cb38e 2655 return INTEGER_CONVERSION_BADNESS;
c5aa993b
JM
2656 case TYPE_CODE_ENUM:
2657 case TYPE_CODE_CHAR:
2658 case TYPE_CODE_RANGE:
2659 case TYPE_CODE_BOOL:
2660 return INTEGER_PROMOTION_BADNESS;
2661 case TYPE_CODE_FLT:
2662 return INT_FLOAT_CONVERSION_BADNESS;
2663 case TYPE_CODE_PTR:
2664 return NS_POINTER_CONVERSION_BADNESS;
2665 default:
2666 return INCOMPATIBLE_TYPE_BADNESS;
2667 }
2668 break;
2669 case TYPE_CODE_ENUM:
2670 switch (TYPE_CODE (arg))
2671 {
2672 case TYPE_CODE_INT:
2673 case TYPE_CODE_CHAR:
2674 case TYPE_CODE_RANGE:
2675 case TYPE_CODE_BOOL:
2676 case TYPE_CODE_ENUM:
1c5cb38e 2677 return INTEGER_CONVERSION_BADNESS;
c5aa993b
JM
2678 case TYPE_CODE_FLT:
2679 return INT_FLOAT_CONVERSION_BADNESS;
2680 default:
2681 return INCOMPATIBLE_TYPE_BADNESS;
2682 }
2683 break;
2684 case TYPE_CODE_CHAR:
2685 switch (TYPE_CODE (arg))
2686 {
2687 case TYPE_CODE_RANGE:
2688 case TYPE_CODE_BOOL:
2689 case TYPE_CODE_ENUM:
1c5cb38e 2690 return INTEGER_CONVERSION_BADNESS;
c5aa993b
JM
2691 case TYPE_CODE_FLT:
2692 return INT_FLOAT_CONVERSION_BADNESS;
2693 case TYPE_CODE_INT:
2694 if (TYPE_LENGTH (arg) > TYPE_LENGTH (parm))
1c5cb38e 2695 return INTEGER_CONVERSION_BADNESS;
c5aa993b
JM
2696 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2697 return INTEGER_PROMOTION_BADNESS;
2698 /* >>> !! else fall through !! <<< */
2699 case TYPE_CODE_CHAR:
2700 /* Deal with signed, unsigned, and plain chars for C++
2701 and with int cases falling through from previous case */
2702 if (TYPE_NOSIGN (parm))
2703 {
2704 if (TYPE_NOSIGN (arg))
2705 return 0;
2706 else
1c5cb38e 2707 return INTEGER_CONVERSION_BADNESS;
c5aa993b
JM
2708 }
2709 else if (TYPE_UNSIGNED (parm))
2710 {
2711 if (TYPE_UNSIGNED (arg))
2712 return 0;
2713 else
2714 return INTEGER_PROMOTION_BADNESS;
2715 }
2716 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
2717 return 0;
2718 else
1c5cb38e 2719 return INTEGER_CONVERSION_BADNESS;
c5aa993b
JM
2720 default:
2721 return INCOMPATIBLE_TYPE_BADNESS;
2722 }
2723 break;
2724 case TYPE_CODE_RANGE:
2725 switch (TYPE_CODE (arg))
2726 {
2727 case TYPE_CODE_INT:
2728 case TYPE_CODE_CHAR:
2729 case TYPE_CODE_RANGE:
2730 case TYPE_CODE_BOOL:
2731 case TYPE_CODE_ENUM:
1c5cb38e 2732 return INTEGER_CONVERSION_BADNESS;
c5aa993b
JM
2733 case TYPE_CODE_FLT:
2734 return INT_FLOAT_CONVERSION_BADNESS;
2735 default:
2736 return INCOMPATIBLE_TYPE_BADNESS;
2737 }
2738 break;
2739 case TYPE_CODE_BOOL:
2740 switch (TYPE_CODE (arg))
2741 {
2742 case TYPE_CODE_INT:
2743 case TYPE_CODE_CHAR:
2744 case TYPE_CODE_RANGE:
2745 case TYPE_CODE_ENUM:
2746 case TYPE_CODE_FLT:
2747 case TYPE_CODE_PTR:
2748 return BOOLEAN_CONVERSION_BADNESS;
2749 case TYPE_CODE_BOOL:
2750 return 0;
2751 default:
2752 return INCOMPATIBLE_TYPE_BADNESS;
2753 }
2754 break;
2755 case TYPE_CODE_FLT:
2756 switch (TYPE_CODE (arg))
2757 {
2758 case TYPE_CODE_FLT:
2759 if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2760 return FLOAT_PROMOTION_BADNESS;
2761 else if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
2762 return 0;
2763 else
2764 return FLOAT_CONVERSION_BADNESS;
2765 case TYPE_CODE_INT:
2766 case TYPE_CODE_BOOL:
2767 case TYPE_CODE_ENUM:
2768 case TYPE_CODE_RANGE:
2769 case TYPE_CODE_CHAR:
2770 return INT_FLOAT_CONVERSION_BADNESS;
2771 default:
2772 return INCOMPATIBLE_TYPE_BADNESS;
2773 }
2774 break;
2775 case TYPE_CODE_COMPLEX:
2776 switch (TYPE_CODE (arg))
2777 { /* Strictly not needed for C++, but... */
2778 case TYPE_CODE_FLT:
2779 return FLOAT_PROMOTION_BADNESS;
2780 case TYPE_CODE_COMPLEX:
2781 return 0;
2782 default:
2783 return INCOMPATIBLE_TYPE_BADNESS;
2784 }
2785 break;
2786 case TYPE_CODE_STRUCT:
c906108c 2787 /* currently same as TYPE_CODE_CLASS */
c5aa993b
JM
2788 switch (TYPE_CODE (arg))
2789 {
2790 case TYPE_CODE_STRUCT:
2791 /* Check for derivation */
2792 if (is_ancestor (parm, arg))
2793 return BASE_CONVERSION_BADNESS;
2794 /* else fall through */
2795 default:
2796 return INCOMPATIBLE_TYPE_BADNESS;
2797 }
2798 break;
2799 case TYPE_CODE_UNION:
2800 switch (TYPE_CODE (arg))
2801 {
2802 case TYPE_CODE_UNION:
2803 default:
2804 return INCOMPATIBLE_TYPE_BADNESS;
2805 }
2806 break;
2807 case TYPE_CODE_MEMBER:
2808 switch (TYPE_CODE (arg))
2809 {
2810 default:
2811 return INCOMPATIBLE_TYPE_BADNESS;
2812 }
2813 break;
2814 case TYPE_CODE_METHOD:
2815 switch (TYPE_CODE (arg))
2816 {
2817
2818 default:
2819 return INCOMPATIBLE_TYPE_BADNESS;
2820 }
2821 break;
2822 case TYPE_CODE_REF:
2823 switch (TYPE_CODE (arg))
2824 {
2825
2826 default:
2827 return INCOMPATIBLE_TYPE_BADNESS;
2828 }
2829
2830 break;
2831 case TYPE_CODE_SET:
2832 switch (TYPE_CODE (arg))
2833 {
2834 /* Not in C++ */
2835 case TYPE_CODE_SET:
2836 return rank_one_type (TYPE_FIELD_TYPE (parm, 0), TYPE_FIELD_TYPE (arg, 0));
2837 default:
2838 return INCOMPATIBLE_TYPE_BADNESS;
2839 }
2840 break;
2841 case TYPE_CODE_VOID:
2842 default:
2843 return INCOMPATIBLE_TYPE_BADNESS;
2844 } /* switch (TYPE_CODE (arg)) */
c906108c
SS
2845}
2846
c5aa993b
JM
2847
2848/* End of functions for overload resolution */
c906108c 2849
c906108c 2850static void
fba45db2 2851print_bit_vector (B_TYPE *bits, int nbits)
c906108c
SS
2852{
2853 int bitno;
2854
2855 for (bitno = 0; bitno < nbits; bitno++)
2856 {
2857 if ((bitno % 8) == 0)
2858 {
2859 puts_filtered (" ");
2860 }
2861 if (B_TST (bits, bitno))
2862 {
2863 printf_filtered ("1");
2864 }
2865 else
2866 {
2867 printf_filtered ("0");
2868 }
2869 }
2870}
2871
ad2f7632
DJ
2872/* Note the first arg should be the "this" pointer, we may not want to
2873 include it since we may get into a infinitely recursive situation. */
c906108c
SS
2874
2875static void
ad2f7632 2876print_arg_types (struct field *args, int nargs, int spaces)
c906108c
SS
2877{
2878 if (args != NULL)
2879 {
ad2f7632
DJ
2880 int i;
2881
2882 for (i = 0; i < nargs; i++)
2883 recursive_dump_type (args[i].type, spaces + 2);
c906108c
SS
2884 }
2885}
2886
2887static void
fba45db2 2888dump_fn_fieldlists (struct type *type, int spaces)
c906108c
SS
2889{
2890 int method_idx;
2891 int overload_idx;
2892 struct fn_field *f;
2893
2894 printfi_filtered (spaces, "fn_fieldlists ");
d4f3574e 2895 gdb_print_host_address (TYPE_FN_FIELDLISTS (type), gdb_stdout);
c906108c
SS
2896 printf_filtered ("\n");
2897 for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++)
2898 {
2899 f = TYPE_FN_FIELDLIST1 (type, method_idx);
2900 printfi_filtered (spaces + 2, "[%d] name '%s' (",
2901 method_idx,
2902 TYPE_FN_FIELDLIST_NAME (type, method_idx));
d4f3574e
SS
2903 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type, method_idx),
2904 gdb_stdout);
c906108c
SS
2905 printf_filtered (") length %d\n",
2906 TYPE_FN_FIELDLIST_LENGTH (type, method_idx));
2907 for (overload_idx = 0;
2908 overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx);
2909 overload_idx++)
2910 {
2911 printfi_filtered (spaces + 4, "[%d] physname '%s' (",
2912 overload_idx,
2913 TYPE_FN_FIELD_PHYSNAME (f, overload_idx));
d4f3574e
SS
2914 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f, overload_idx),
2915 gdb_stdout);
c906108c
SS
2916 printf_filtered (")\n");
2917 printfi_filtered (spaces + 8, "type ");
d4f3574e 2918 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f, overload_idx), gdb_stdout);
c906108c
SS
2919 printf_filtered ("\n");
2920
2921 recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx),
2922 spaces + 8 + 2);
2923
2924 printfi_filtered (spaces + 8, "args ");
d4f3574e 2925 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f, overload_idx), gdb_stdout);
c906108c
SS
2926 printf_filtered ("\n");
2927
ad2f7632
DJ
2928 print_arg_types (TYPE_FN_FIELD_ARGS (f, overload_idx),
2929 TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f, overload_idx)),
2930 spaces);
c906108c 2931 printfi_filtered (spaces + 8, "fcontext ");
d4f3574e
SS
2932 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx),
2933 gdb_stdout);
c906108c
SS
2934 printf_filtered ("\n");
2935
2936 printfi_filtered (spaces + 8, "is_const %d\n",
2937 TYPE_FN_FIELD_CONST (f, overload_idx));
2938 printfi_filtered (spaces + 8, "is_volatile %d\n",
2939 TYPE_FN_FIELD_VOLATILE (f, overload_idx));
2940 printfi_filtered (spaces + 8, "is_private %d\n",
2941 TYPE_FN_FIELD_PRIVATE (f, overload_idx));
2942 printfi_filtered (spaces + 8, "is_protected %d\n",
2943 TYPE_FN_FIELD_PROTECTED (f, overload_idx));
2944 printfi_filtered (spaces + 8, "is_stub %d\n",
2945 TYPE_FN_FIELD_STUB (f, overload_idx));
2946 printfi_filtered (spaces + 8, "voffset %u\n",
2947 TYPE_FN_FIELD_VOFFSET (f, overload_idx));
2948 }
2949 }
2950}
2951
2952static void
fba45db2 2953print_cplus_stuff (struct type *type, int spaces)
c906108c
SS
2954{
2955 printfi_filtered (spaces, "n_baseclasses %d\n",
2956 TYPE_N_BASECLASSES (type));
2957 printfi_filtered (spaces, "nfn_fields %d\n",
2958 TYPE_NFN_FIELDS (type));
2959 printfi_filtered (spaces, "nfn_fields_total %d\n",
2960 TYPE_NFN_FIELDS_TOTAL (type));
2961 if (TYPE_N_BASECLASSES (type) > 0)
2962 {
2963 printfi_filtered (spaces, "virtual_field_bits (%d bits at *",
2964 TYPE_N_BASECLASSES (type));
d4f3574e 2965 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type), gdb_stdout);
c906108c
SS
2966 printf_filtered (")");
2967
2968 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type),
2969 TYPE_N_BASECLASSES (type));
2970 puts_filtered ("\n");
2971 }
2972 if (TYPE_NFIELDS (type) > 0)
2973 {
2974 if (TYPE_FIELD_PRIVATE_BITS (type) != NULL)
2975 {
2976 printfi_filtered (spaces, "private_field_bits (%d bits at *",
2977 TYPE_NFIELDS (type));
d4f3574e 2978 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type), gdb_stdout);
c906108c
SS
2979 printf_filtered (")");
2980 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type),
2981 TYPE_NFIELDS (type));
2982 puts_filtered ("\n");
2983 }
2984 if (TYPE_FIELD_PROTECTED_BITS (type) != NULL)
2985 {
2986 printfi_filtered (spaces, "protected_field_bits (%d bits at *",
2987 TYPE_NFIELDS (type));
d4f3574e 2988 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type), gdb_stdout);
c906108c
SS
2989 printf_filtered (")");
2990 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type),
2991 TYPE_NFIELDS (type));
2992 puts_filtered ("\n");
2993 }
2994 }
2995 if (TYPE_NFN_FIELDS (type) > 0)
2996 {
2997 dump_fn_fieldlists (type, spaces);
2998 }
2999}
3000
e9e79dd9
FF
3001static void
3002print_bound_type (int bt)
3003{
3004 switch (bt)
3005 {
3006 case BOUND_CANNOT_BE_DETERMINED:
3007 printf_filtered ("(BOUND_CANNOT_BE_DETERMINED)");
3008 break;
3009 case BOUND_BY_REF_ON_STACK:
3010 printf_filtered ("(BOUND_BY_REF_ON_STACK)");
3011 break;
3012 case BOUND_BY_VALUE_ON_STACK:
3013 printf_filtered ("(BOUND_BY_VALUE_ON_STACK)");
3014 break;
3015 case BOUND_BY_REF_IN_REG:
3016 printf_filtered ("(BOUND_BY_REF_IN_REG)");
3017 break;
3018 case BOUND_BY_VALUE_IN_REG:
3019 printf_filtered ("(BOUND_BY_VALUE_IN_REG)");
3020 break;
3021 case BOUND_SIMPLE:
3022 printf_filtered ("(BOUND_SIMPLE)");
3023 break;
3024 default:
3025 printf_filtered ("(unknown bound type)");
3026 break;
3027 }
3028}
3029
c906108c
SS
3030static struct obstack dont_print_type_obstack;
3031
3032void
fba45db2 3033recursive_dump_type (struct type *type, int spaces)
c906108c
SS
3034{
3035 int idx;
3036
3037 if (spaces == 0)
3038 obstack_begin (&dont_print_type_obstack, 0);
3039
3040 if (TYPE_NFIELDS (type) > 0
3041 || (TYPE_CPLUS_SPECIFIC (type) && TYPE_NFN_FIELDS (type) > 0))
3042 {
3043 struct type **first_dont_print
c5aa993b 3044 = (struct type **) obstack_base (&dont_print_type_obstack);
c906108c 3045
c5aa993b
JM
3046 int i = (struct type **) obstack_next_free (&dont_print_type_obstack)
3047 - first_dont_print;
c906108c
SS
3048
3049 while (--i >= 0)
3050 {
3051 if (type == first_dont_print[i])
3052 {
3053 printfi_filtered (spaces, "type node ");
d4f3574e 3054 gdb_print_host_address (type, gdb_stdout);
c906108c
SS
3055 printf_filtered (" <same as already seen type>\n");
3056 return;
3057 }
3058 }
3059
3060 obstack_ptr_grow (&dont_print_type_obstack, type);
3061 }
3062
3063 printfi_filtered (spaces, "type node ");
d4f3574e 3064 gdb_print_host_address (type, gdb_stdout);
c906108c
SS
3065 printf_filtered ("\n");
3066 printfi_filtered (spaces, "name '%s' (",
3067 TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>");
d4f3574e 3068 gdb_print_host_address (TYPE_NAME (type), gdb_stdout);
c906108c 3069 printf_filtered (")\n");
e9e79dd9
FF
3070 printfi_filtered (spaces, "tagname '%s' (",
3071 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : "<NULL>");
3072 gdb_print_host_address (TYPE_TAG_NAME (type), gdb_stdout);
3073 printf_filtered (")\n");
c906108c
SS
3074 printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type));
3075 switch (TYPE_CODE (type))
3076 {
c5aa993b
JM
3077 case TYPE_CODE_UNDEF:
3078 printf_filtered ("(TYPE_CODE_UNDEF)");
3079 break;
3080 case TYPE_CODE_PTR:
3081 printf_filtered ("(TYPE_CODE_PTR)");
3082 break;
3083 case TYPE_CODE_ARRAY:
3084 printf_filtered ("(TYPE_CODE_ARRAY)");
3085 break;
3086 case TYPE_CODE_STRUCT:
3087 printf_filtered ("(TYPE_CODE_STRUCT)");
3088 break;
3089 case TYPE_CODE_UNION:
3090 printf_filtered ("(TYPE_CODE_UNION)");
3091 break;
3092 case TYPE_CODE_ENUM:
3093 printf_filtered ("(TYPE_CODE_ENUM)");
3094 break;
3095 case TYPE_CODE_FUNC:
3096 printf_filtered ("(TYPE_CODE_FUNC)");
3097 break;
3098 case TYPE_CODE_INT:
3099 printf_filtered ("(TYPE_CODE_INT)");
3100 break;
3101 case TYPE_CODE_FLT:
3102 printf_filtered ("(TYPE_CODE_FLT)");
3103 break;
3104 case TYPE_CODE_VOID:
3105 printf_filtered ("(TYPE_CODE_VOID)");
3106 break;
3107 case TYPE_CODE_SET:
3108 printf_filtered ("(TYPE_CODE_SET)");
3109 break;
3110 case TYPE_CODE_RANGE:
3111 printf_filtered ("(TYPE_CODE_RANGE)");
3112 break;
3113 case TYPE_CODE_STRING:
3114 printf_filtered ("(TYPE_CODE_STRING)");
3115 break;
e9e79dd9
FF
3116 case TYPE_CODE_BITSTRING:
3117 printf_filtered ("(TYPE_CODE_BITSTRING)");
3118 break;
c5aa993b
JM
3119 case TYPE_CODE_ERROR:
3120 printf_filtered ("(TYPE_CODE_ERROR)");
3121 break;
3122 case TYPE_CODE_MEMBER:
3123 printf_filtered ("(TYPE_CODE_MEMBER)");
3124 break;
3125 case TYPE_CODE_METHOD:
3126 printf_filtered ("(TYPE_CODE_METHOD)");
3127 break;
3128 case TYPE_CODE_REF:
3129 printf_filtered ("(TYPE_CODE_REF)");
3130 break;
3131 case TYPE_CODE_CHAR:
3132 printf_filtered ("(TYPE_CODE_CHAR)");
3133 break;
3134 case TYPE_CODE_BOOL:
3135 printf_filtered ("(TYPE_CODE_BOOL)");
3136 break;
e9e79dd9
FF
3137 case TYPE_CODE_COMPLEX:
3138 printf_filtered ("(TYPE_CODE_COMPLEX)");
3139 break;
c5aa993b
JM
3140 case TYPE_CODE_TYPEDEF:
3141 printf_filtered ("(TYPE_CODE_TYPEDEF)");
3142 break;
e9e79dd9
FF
3143 case TYPE_CODE_TEMPLATE:
3144 printf_filtered ("(TYPE_CODE_TEMPLATE)");
3145 break;
3146 case TYPE_CODE_TEMPLATE_ARG:
3147 printf_filtered ("(TYPE_CODE_TEMPLATE_ARG)");
3148 break;
5c4e30ca
DC
3149 case TYPE_CODE_NAMESPACE:
3150 printf_filtered ("(TYPE_CODE_NAMESPACE)");
3151 break;
c5aa993b
JM
3152 default:
3153 printf_filtered ("(UNKNOWN TYPE CODE)");
3154 break;
c906108c
SS
3155 }
3156 puts_filtered ("\n");
3157 printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type));
e9e79dd9
FF
3158 printfi_filtered (spaces, "upper_bound_type 0x%x ",
3159 TYPE_ARRAY_UPPER_BOUND_TYPE (type));
3160 print_bound_type (TYPE_ARRAY_UPPER_BOUND_TYPE (type));
3161 puts_filtered ("\n");
3162 printfi_filtered (spaces, "lower_bound_type 0x%x ",
3163 TYPE_ARRAY_LOWER_BOUND_TYPE (type));
3164 print_bound_type (TYPE_ARRAY_LOWER_BOUND_TYPE (type));
3165 puts_filtered ("\n");
c906108c 3166 printfi_filtered (spaces, "objfile ");
d4f3574e 3167 gdb_print_host_address (TYPE_OBJFILE (type), gdb_stdout);
c906108c
SS
3168 printf_filtered ("\n");
3169 printfi_filtered (spaces, "target_type ");
d4f3574e 3170 gdb_print_host_address (TYPE_TARGET_TYPE (type), gdb_stdout);
c906108c
SS
3171 printf_filtered ("\n");
3172 if (TYPE_TARGET_TYPE (type) != NULL)
3173 {
3174 recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2);
3175 }
3176 printfi_filtered (spaces, "pointer_type ");
d4f3574e 3177 gdb_print_host_address (TYPE_POINTER_TYPE (type), gdb_stdout);
c906108c
SS
3178 printf_filtered ("\n");
3179 printfi_filtered (spaces, "reference_type ");
d4f3574e 3180 gdb_print_host_address (TYPE_REFERENCE_TYPE (type), gdb_stdout);
c906108c 3181 printf_filtered ("\n");
2fdde8f8
DJ
3182 printfi_filtered (spaces, "type_chain ");
3183 gdb_print_host_address (TYPE_CHAIN (type), gdb_stdout);
e9e79dd9 3184 printf_filtered ("\n");
2fdde8f8
DJ
3185 printfi_filtered (spaces, "instance_flags 0x%x", TYPE_INSTANCE_FLAGS (type));
3186 if (TYPE_CONST (type))
3187 {
3188 puts_filtered (" TYPE_FLAG_CONST");
3189 }
3190 if (TYPE_VOLATILE (type))
3191 {
3192 puts_filtered (" TYPE_FLAG_VOLATILE");
3193 }
3194 if (TYPE_CODE_SPACE (type))
3195 {
3196 puts_filtered (" TYPE_FLAG_CODE_SPACE");
3197 }
3198 if (TYPE_DATA_SPACE (type))
3199 {
3200 puts_filtered (" TYPE_FLAG_DATA_SPACE");
3201 }
8b2dbe47
KB
3202 if (TYPE_ADDRESS_CLASS_1 (type))
3203 {
3204 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_1");
3205 }
3206 if (TYPE_ADDRESS_CLASS_2 (type))
3207 {
3208 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_2");
3209 }
2fdde8f8 3210 puts_filtered ("\n");
c906108c 3211 printfi_filtered (spaces, "flags 0x%x", TYPE_FLAGS (type));
762a036f 3212 if (TYPE_UNSIGNED (type))
c906108c
SS
3213 {
3214 puts_filtered (" TYPE_FLAG_UNSIGNED");
3215 }
762a036f
FF
3216 if (TYPE_NOSIGN (type))
3217 {
3218 puts_filtered (" TYPE_FLAG_NOSIGN");
3219 }
3220 if (TYPE_STUB (type))
c906108c
SS
3221 {
3222 puts_filtered (" TYPE_FLAG_STUB");
3223 }
762a036f
FF
3224 if (TYPE_TARGET_STUB (type))
3225 {
3226 puts_filtered (" TYPE_FLAG_TARGET_STUB");
3227 }
3228 if (TYPE_STATIC (type))
3229 {
3230 puts_filtered (" TYPE_FLAG_STATIC");
3231 }
762a036f
FF
3232 if (TYPE_PROTOTYPED (type))
3233 {
3234 puts_filtered (" TYPE_FLAG_PROTOTYPED");
3235 }
3236 if (TYPE_INCOMPLETE (type))
3237 {
3238 puts_filtered (" TYPE_FLAG_INCOMPLETE");
3239 }
762a036f
FF
3240 if (TYPE_VARARGS (type))
3241 {
3242 puts_filtered (" TYPE_FLAG_VARARGS");
3243 }
f5f8a009
EZ
3244 /* This is used for things like AltiVec registers on ppc. Gcc emits
3245 an attribute for the array type, which tells whether or not we
3246 have a vector, instead of a regular array. */
3247 if (TYPE_VECTOR (type))
3248 {
3249 puts_filtered (" TYPE_FLAG_VECTOR");
3250 }
c906108c
SS
3251 puts_filtered ("\n");
3252 printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type));
d4f3574e 3253 gdb_print_host_address (TYPE_FIELDS (type), gdb_stdout);
c906108c
SS
3254 puts_filtered ("\n");
3255 for (idx = 0; idx < TYPE_NFIELDS (type); idx++)
3256 {
3257 printfi_filtered (spaces + 2,
3258 "[%d] bitpos %d bitsize %d type ",
3259 idx, TYPE_FIELD_BITPOS (type, idx),
3260 TYPE_FIELD_BITSIZE (type, idx));
d4f3574e 3261 gdb_print_host_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout);
c906108c
SS
3262 printf_filtered (" name '%s' (",
3263 TYPE_FIELD_NAME (type, idx) != NULL
3264 ? TYPE_FIELD_NAME (type, idx)
3265 : "<NULL>");
d4f3574e 3266 gdb_print_host_address (TYPE_FIELD_NAME (type, idx), gdb_stdout);
c906108c
SS
3267 printf_filtered (")\n");
3268 if (TYPE_FIELD_TYPE (type, idx) != NULL)
3269 {
3270 recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4);
3271 }
3272 }
3273 printfi_filtered (spaces, "vptr_basetype ");
d4f3574e 3274 gdb_print_host_address (TYPE_VPTR_BASETYPE (type), gdb_stdout);
c906108c
SS
3275 puts_filtered ("\n");
3276 if (TYPE_VPTR_BASETYPE (type) != NULL)
3277 {
3278 recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2);
3279 }
3280 printfi_filtered (spaces, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type));
3281 switch (TYPE_CODE (type))
3282 {
c5aa993b
JM
3283 case TYPE_CODE_STRUCT:
3284 printfi_filtered (spaces, "cplus_stuff ");
d4f3574e 3285 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
c5aa993b
JM
3286 puts_filtered ("\n");
3287 print_cplus_stuff (type, spaces);
3288 break;
c906108c 3289
701c159d
AC
3290 case TYPE_CODE_FLT:
3291 printfi_filtered (spaces, "floatformat ");
3292 if (TYPE_FLOATFORMAT (type) == NULL
3293 || TYPE_FLOATFORMAT (type)->name == NULL)
3294 puts_filtered ("(null)");
3295 else
3296 puts_filtered (TYPE_FLOATFORMAT (type)->name);
3297 puts_filtered ("\n");
3298 break;
3299
c5aa993b
JM
3300 default:
3301 /* We have to pick one of the union types to be able print and test
7b83ea04
AC
3302 the value. Pick cplus_struct_type, even though we know it isn't
3303 any particular one. */
c5aa993b 3304 printfi_filtered (spaces, "type_specific ");
d4f3574e 3305 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
c5aa993b
JM
3306 if (TYPE_CPLUS_SPECIFIC (type) != NULL)
3307 {
3308 printf_filtered (" (unknown data form)");
3309 }
3310 printf_filtered ("\n");
3311 break;
c906108c
SS
3312
3313 }
3314 if (spaces == 0)
3315 obstack_free (&dont_print_type_obstack, NULL);
3316}
3317
a14ed312 3318static void build_gdbtypes (void);
c906108c 3319static void
fba45db2 3320build_gdbtypes (void)
c906108c
SS
3321{
3322 builtin_type_void =
3323 init_type (TYPE_CODE_VOID, 1,
3324 0,
3325 "void", (struct objfile *) NULL);
3326 builtin_type_char =
3327 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
4e409299
JB
3328 (TYPE_FLAG_NOSIGN
3329 | (TARGET_CHAR_SIGNED ? 0 : TYPE_FLAG_UNSIGNED)),
c906108c 3330 "char", (struct objfile *) NULL);
c5aa993b 3331 builtin_type_true_char =
9e0b60a8
JM
3332 init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3333 0,
3334 "true character", (struct objfile *) NULL);
c906108c
SS
3335 builtin_type_signed_char =
3336 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3337 0,
3338 "signed char", (struct objfile *) NULL);
3339 builtin_type_unsigned_char =
3340 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3341 TYPE_FLAG_UNSIGNED,
3342 "unsigned char", (struct objfile *) NULL);
3343 builtin_type_short =
3344 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
3345 0,
3346 "short", (struct objfile *) NULL);
3347 builtin_type_unsigned_short =
3348 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
3349 TYPE_FLAG_UNSIGNED,
3350 "unsigned short", (struct objfile *) NULL);
3351 builtin_type_int =
3352 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
3353 0,
3354 "int", (struct objfile *) NULL);
3355 builtin_type_unsigned_int =
3356 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
3357 TYPE_FLAG_UNSIGNED,
3358 "unsigned int", (struct objfile *) NULL);
3359 builtin_type_long =
3360 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
3361 0,
3362 "long", (struct objfile *) NULL);
3363 builtin_type_unsigned_long =
3364 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
3365 TYPE_FLAG_UNSIGNED,
3366 "unsigned long", (struct objfile *) NULL);
3367 builtin_type_long_long =
3368 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
3369 0,
3370 "long long", (struct objfile *) NULL);
c5aa993b 3371 builtin_type_unsigned_long_long =
c906108c
SS
3372 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
3373 TYPE_FLAG_UNSIGNED,
3374 "unsigned long long", (struct objfile *) NULL);
3375 builtin_type_float =
3376 init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
3377 0,
3378 "float", (struct objfile *) NULL);
9c9532c9
CV
3379/* vinschen@redhat.com 2002-02-08:
3380 The below lines are disabled since they are doing the wrong
3381 thing for non-multiarch targets. They are setting the correct
3382 type of floats for the target but while on multiarch targets
3383 this is done everytime the architecture changes, it's done on
3384 non-multiarch targets only on startup, leaving the wrong values
3385 in even if the architecture changes (eg. from big-endian to
3386 little-endian). */
3387#if 0
701c159d 3388 TYPE_FLOATFORMAT (builtin_type_float) = TARGET_FLOAT_FORMAT;
9c9532c9 3389#endif
c906108c
SS
3390 builtin_type_double =
3391 init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
3392 0,
3393 "double", (struct objfile *) NULL);
9c9532c9 3394#if 0
701c159d 3395 TYPE_FLOATFORMAT (builtin_type_double) = TARGET_DOUBLE_FORMAT;
9c9532c9 3396#endif
c906108c
SS
3397 builtin_type_long_double =
3398 init_type (TYPE_CODE_FLT, TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
3399 0,
3400 "long double", (struct objfile *) NULL);
9c9532c9 3401#if 0
701c159d 3402 TYPE_FLOATFORMAT (builtin_type_long_double) = TARGET_LONG_DOUBLE_FORMAT;
9c9532c9 3403#endif
c906108c
SS
3404 builtin_type_complex =
3405 init_type (TYPE_CODE_COMPLEX, 2 * TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
3406 0,
3407 "complex", (struct objfile *) NULL);
3408 TYPE_TARGET_TYPE (builtin_type_complex) = builtin_type_float;
3409 builtin_type_double_complex =
3410 init_type (TYPE_CODE_COMPLEX, 2 * TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
3411 0,
3412 "double complex", (struct objfile *) NULL);
3413 TYPE_TARGET_TYPE (builtin_type_double_complex) = builtin_type_double;
3414 builtin_type_string =
3415 init_type (TYPE_CODE_STRING, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3416 0,
3417 "string", (struct objfile *) NULL);
449a5da4
AC
3418 builtin_type_int0 =
3419 init_type (TYPE_CODE_INT, 0 / 8,
3420 0,
3421 "int0_t", (struct objfile *) NULL);
c906108c
SS
3422 builtin_type_int8 =
3423 init_type (TYPE_CODE_INT, 8 / 8,
3424 0,
3425 "int8_t", (struct objfile *) NULL);
3426 builtin_type_uint8 =
3427 init_type (TYPE_CODE_INT, 8 / 8,
3428 TYPE_FLAG_UNSIGNED,
3429 "uint8_t", (struct objfile *) NULL);
3430 builtin_type_int16 =
3431 init_type (TYPE_CODE_INT, 16 / 8,
3432 0,
3433 "int16_t", (struct objfile *) NULL);
3434 builtin_type_uint16 =
3435 init_type (TYPE_CODE_INT, 16 / 8,
3436 TYPE_FLAG_UNSIGNED,
3437 "uint16_t", (struct objfile *) NULL);
3438 builtin_type_int32 =
3439 init_type (TYPE_CODE_INT, 32 / 8,
3440 0,
3441 "int32_t", (struct objfile *) NULL);
3442 builtin_type_uint32 =
3443 init_type (TYPE_CODE_INT, 32 / 8,
3444 TYPE_FLAG_UNSIGNED,
3445 "uint32_t", (struct objfile *) NULL);
3446 builtin_type_int64 =
3447 init_type (TYPE_CODE_INT, 64 / 8,
3448 0,
3449 "int64_t", (struct objfile *) NULL);
3450 builtin_type_uint64 =
3451 init_type (TYPE_CODE_INT, 64 / 8,
3452 TYPE_FLAG_UNSIGNED,
3453 "uint64_t", (struct objfile *) NULL);
8b982acf
EZ
3454 builtin_type_int128 =
3455 init_type (TYPE_CODE_INT, 128 / 8,
3456 0,
3457 "int128_t", (struct objfile *) NULL);
3458 builtin_type_uint128 =
3459 init_type (TYPE_CODE_INT, 128 / 8,
3460 TYPE_FLAG_UNSIGNED,
3461 "uint128_t", (struct objfile *) NULL);
c906108c
SS
3462 builtin_type_bool =
3463 init_type (TYPE_CODE_BOOL, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3464 0,
3465 "bool", (struct objfile *) NULL);
3466
c5aa993b 3467 /* Add user knob for controlling resolution of opaque types */
c906108c 3468 add_show_from_set
c5aa993b 3469 (add_set_cmd ("opaque-type-resolution", class_support, var_boolean, (char *) &opaque_type_resolution,
c906108c
SS
3470 "Set resolution of opaque struct/class/union types (if set before loading symbols).",
3471 &setlist),
3472 &showlist);
3473 opaque_type_resolution = 1;
3474
917317f4
JM
3475 /* Build SIMD types. */
3476 builtin_type_v4sf
3477 = init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4);
c2d11a7d
JM
3478 builtin_type_v4si
3479 = init_simd_type ("__builtin_v4si", builtin_type_int32, "f", 4);
08cf96df
EZ
3480 builtin_type_v16qi
3481 = init_simd_type ("__builtin_v16qi", builtin_type_int8, "f", 16);
c2d11a7d
JM
3482 builtin_type_v8qi
3483 = init_simd_type ("__builtin_v8qi", builtin_type_int8, "f", 8);
08cf96df
EZ
3484 builtin_type_v8hi
3485 = init_simd_type ("__builtin_v8hi", builtin_type_int16, "f", 8);
c2d11a7d
JM
3486 builtin_type_v4hi
3487 = init_simd_type ("__builtin_v4hi", builtin_type_int16, "f", 4);
3488 builtin_type_v2si
3489 = init_simd_type ("__builtin_v2si", builtin_type_int32, "f", 2);
c4093a6a 3490
ac3aafc7 3491 /* 128 bit vectors. */
3139facc 3492 builtin_type_v2_double = init_vector_type (builtin_type_double, 2);
ac3aafc7 3493 builtin_type_v4_float = init_vector_type (builtin_type_float, 4);
3139facc 3494 builtin_type_v2_int64 = init_vector_type (builtin_type_int64, 2);
ac3aafc7
EZ
3495 builtin_type_v4_int32 = init_vector_type (builtin_type_int32, 4);
3496 builtin_type_v8_int16 = init_vector_type (builtin_type_int16, 8);
3497 builtin_type_v16_int8 = init_vector_type (builtin_type_int8, 16);
3498 /* 64 bit vectors. */
6599f021 3499 builtin_type_v2_float = init_vector_type (builtin_type_float, 2);
ac3aafc7
EZ
3500 builtin_type_v2_int32 = init_vector_type (builtin_type_int32, 2);
3501 builtin_type_v4_int16 = init_vector_type (builtin_type_int16, 4);
3502 builtin_type_v8_int8 = init_vector_type (builtin_type_int8, 8);
3503
b063e7a2
AC
3504 /* Vector types. */
3505 builtin_type_vec64 = build_builtin_type_vec64 ();
3506 builtin_type_vec64i = build_builtin_type_vec64i ();
ac3aafc7 3507 builtin_type_vec128 = build_builtin_type_vec128 ();
3139facc 3508 builtin_type_vec128i = build_builtin_type_vec128i ();
08cf96df 3509
c4093a6a 3510 /* Pointer/Address types. */
ee3a7b7f
JB
3511
3512 /* NOTE: on some targets, addresses and pointers are not necessarily
3513 the same --- for example, on the D10V, pointers are 16 bits long,
3514 but addresses are 32 bits long. See doc/gdbint.texinfo,
3515 ``Pointers Are Not Always Addresses''.
3516
3517 The upshot is:
3518 - gdb's `struct type' always describes the target's
3519 representation.
3520 - gdb's `struct value' objects should always hold values in
3521 target form.
3522 - gdb's CORE_ADDR values are addresses in the unified virtual
3523 address space that the assembler and linker work with. Thus,
3524 since target_read_memory takes a CORE_ADDR as an argument, it
3525 can access any memory on the target, even if the processor has
3526 separate code and data address spaces.
3527
3528 So, for example:
3529 - If v is a value holding a D10V code pointer, its contents are
3530 in target form: a big-endian address left-shifted two bits.
3531 - If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as
3532 sizeof (void *) == 2 on the target.
3533
3534 In this context, builtin_type_CORE_ADDR is a bit odd: it's a
3535 target type for a value the target will never see. It's only
3536 used to hold the values of (typeless) linker symbols, which are
3537 indeed in the unified virtual address space. */
090a2205 3538 builtin_type_void_data_ptr = make_pointer_type (builtin_type_void, NULL);
ee3a7b7f
JB
3539 builtin_type_void_func_ptr
3540 = lookup_pointer_type (lookup_function_type (builtin_type_void));
c4093a6a 3541 builtin_type_CORE_ADDR =
52204a0b 3542 init_type (TYPE_CODE_INT, TARGET_ADDR_BIT / 8,
c4093a6a
JM
3543 TYPE_FLAG_UNSIGNED,
3544 "__CORE_ADDR", (struct objfile *) NULL);
3545 builtin_type_bfd_vma =
3546 init_type (TYPE_CODE_INT, TARGET_BFD_VMA_BIT / 8,
3547 TYPE_FLAG_UNSIGNED,
3548 "__bfd_vma", (struct objfile *) NULL);
c906108c
SS
3549}
3550
a14ed312 3551extern void _initialize_gdbtypes (void);
c906108c 3552void
fba45db2 3553_initialize_gdbtypes (void)
c906108c 3554{
5d161b24 3555 struct cmd_list_element *c;
c906108c 3556 build_gdbtypes ();
0f71a2f6
JM
3557
3558 /* FIXME - For the moment, handle types by swapping them in and out.
3559 Should be using the per-architecture data-pointer and a large
3560 struct. */
c5aa993b
JM
3561 register_gdbarch_swap (&builtin_type_void, sizeof (struct type *), NULL);
3562 register_gdbarch_swap (&builtin_type_char, sizeof (struct type *), NULL);
3563 register_gdbarch_swap (&builtin_type_short, sizeof (struct type *), NULL);
3564 register_gdbarch_swap (&builtin_type_int, sizeof (struct type *), NULL);
3565 register_gdbarch_swap (&builtin_type_long, sizeof (struct type *), NULL);
3566 register_gdbarch_swap (&builtin_type_long_long, sizeof (struct type *), NULL);
3567 register_gdbarch_swap (&builtin_type_signed_char, sizeof (struct type *), NULL);
3568 register_gdbarch_swap (&builtin_type_unsigned_char, sizeof (struct type *), NULL);
3569 register_gdbarch_swap (&builtin_type_unsigned_short, sizeof (struct type *), NULL);
3570 register_gdbarch_swap (&builtin_type_unsigned_int, sizeof (struct type *), NULL);
3571 register_gdbarch_swap (&builtin_type_unsigned_long, sizeof (struct type *), NULL);
3572 register_gdbarch_swap (&builtin_type_unsigned_long_long, sizeof (struct type *), NULL);
3573 register_gdbarch_swap (&builtin_type_float, sizeof (struct type *), NULL);
3574 register_gdbarch_swap (&builtin_type_double, sizeof (struct type *), NULL);
3575 register_gdbarch_swap (&builtin_type_long_double, sizeof (struct type *), NULL);
3576 register_gdbarch_swap (&builtin_type_complex, sizeof (struct type *), NULL);
3577 register_gdbarch_swap (&builtin_type_double_complex, sizeof (struct type *), NULL);
3578 register_gdbarch_swap (&builtin_type_string, sizeof (struct type *), NULL);
3579 register_gdbarch_swap (&builtin_type_int8, sizeof (struct type *), NULL);
3580 register_gdbarch_swap (&builtin_type_uint8, sizeof (struct type *), NULL);
3581 register_gdbarch_swap (&builtin_type_int16, sizeof (struct type *), NULL);
3582 register_gdbarch_swap (&builtin_type_uint16, sizeof (struct type *), NULL);
3583 register_gdbarch_swap (&builtin_type_int32, sizeof (struct type *), NULL);
3584 register_gdbarch_swap (&builtin_type_uint32, sizeof (struct type *), NULL);
3585 register_gdbarch_swap (&builtin_type_int64, sizeof (struct type *), NULL);
3586 register_gdbarch_swap (&builtin_type_uint64, sizeof (struct type *), NULL);
8b982acf
EZ
3587 register_gdbarch_swap (&builtin_type_int128, sizeof (struct type *), NULL);
3588 register_gdbarch_swap (&builtin_type_uint128, sizeof (struct type *), NULL);
917317f4 3589 register_gdbarch_swap (&builtin_type_v4sf, sizeof (struct type *), NULL);
c2d11a7d 3590 register_gdbarch_swap (&builtin_type_v4si, sizeof (struct type *), NULL);
08cf96df 3591 register_gdbarch_swap (&builtin_type_v16qi, sizeof (struct type *), NULL);
c2d11a7d 3592 register_gdbarch_swap (&builtin_type_v8qi, sizeof (struct type *), NULL);
08cf96df 3593 register_gdbarch_swap (&builtin_type_v8hi, sizeof (struct type *), NULL);
c2d11a7d
JM
3594 register_gdbarch_swap (&builtin_type_v4hi, sizeof (struct type *), NULL);
3595 register_gdbarch_swap (&builtin_type_v2si, sizeof (struct type *), NULL);
3139facc 3596 register_gdbarch_swap (&builtin_type_v2_double, sizeof (struct type *), NULL);
ac3aafc7 3597 register_gdbarch_swap (&builtin_type_v4_float, sizeof (struct type *), NULL);
3139facc 3598 register_gdbarch_swap (&builtin_type_v2_int64, sizeof (struct type *), NULL);
ac3aafc7
EZ
3599 register_gdbarch_swap (&builtin_type_v4_int32, sizeof (struct type *), NULL);
3600 register_gdbarch_swap (&builtin_type_v8_int16, sizeof (struct type *), NULL);
3601 register_gdbarch_swap (&builtin_type_v16_int8, sizeof (struct type *), NULL);
6599f021 3602 register_gdbarch_swap (&builtin_type_v2_float, sizeof (struct type *), NULL);
ac3aafc7
EZ
3603 register_gdbarch_swap (&builtin_type_v2_int32, sizeof (struct type *), NULL);
3604 register_gdbarch_swap (&builtin_type_v8_int8, sizeof (struct type *), NULL);
3605 register_gdbarch_swap (&builtin_type_v4_int16, sizeof (struct type *), NULL);
08cf96df 3606 register_gdbarch_swap (&builtin_type_vec128, sizeof (struct type *), NULL);
3139facc 3607 register_gdbarch_swap (&builtin_type_vec128i, sizeof (struct type *), NULL);
090a2205 3608 REGISTER_GDBARCH_SWAP (builtin_type_void_data_ptr);
ee3a7b7f 3609 REGISTER_GDBARCH_SWAP (builtin_type_void_func_ptr);
c4093a6a
JM
3610 REGISTER_GDBARCH_SWAP (builtin_type_CORE_ADDR);
3611 REGISTER_GDBARCH_SWAP (builtin_type_bfd_vma);
0f71a2f6 3612 register_gdbarch_swap (NULL, 0, build_gdbtypes);
5d161b24 3613
598f52df
AC
3614 /* Note: These types do not need to be swapped - they are target
3615 neutral. */
3616 builtin_type_ieee_single_big =
3617 init_type (TYPE_CODE_FLT, floatformat_ieee_single_big.totalsize / 8,
3618 0, "builtin_type_ieee_single_big", NULL);
3619 TYPE_FLOATFORMAT (builtin_type_ieee_single_big) = &floatformat_ieee_single_big;
3620 builtin_type_ieee_single_little =
3621 init_type (TYPE_CODE_FLT, floatformat_ieee_single_little.totalsize / 8,
3622 0, "builtin_type_ieee_single_little", NULL);
069e84fd 3623 TYPE_FLOATFORMAT (builtin_type_ieee_single_little) = &floatformat_ieee_single_little;
598f52df
AC
3624 builtin_type_ieee_double_big =
3625 init_type (TYPE_CODE_FLT, floatformat_ieee_double_big.totalsize / 8,
3626 0, "builtin_type_ieee_double_big", NULL);
069e84fd 3627 TYPE_FLOATFORMAT (builtin_type_ieee_double_big) = &floatformat_ieee_double_big;
598f52df
AC
3628 builtin_type_ieee_double_little =
3629 init_type (TYPE_CODE_FLT, floatformat_ieee_double_little.totalsize / 8,
3630 0, "builtin_type_ieee_double_little", NULL);
069e84fd 3631 TYPE_FLOATFORMAT (builtin_type_ieee_double_little) = &floatformat_ieee_double_little;
598f52df
AC
3632 builtin_type_ieee_double_littlebyte_bigword =
3633 init_type (TYPE_CODE_FLT, floatformat_ieee_double_littlebyte_bigword.totalsize / 8,
3634 0, "builtin_type_ieee_double_littlebyte_bigword", NULL);
069e84fd 3635 TYPE_FLOATFORMAT (builtin_type_ieee_double_littlebyte_bigword) = &floatformat_ieee_double_littlebyte_bigword;
598f52df
AC
3636 builtin_type_i387_ext =
3637 init_type (TYPE_CODE_FLT, floatformat_i387_ext.totalsize / 8,
3638 0, "builtin_type_i387_ext", NULL);
e371b258 3639 TYPE_FLOATFORMAT (builtin_type_i387_ext) = &floatformat_i387_ext;
598f52df
AC
3640 builtin_type_m68881_ext =
3641 init_type (TYPE_CODE_FLT, floatformat_m68881_ext.totalsize / 8,
3642 0, "builtin_type_m68881_ext", NULL);
069e84fd 3643 TYPE_FLOATFORMAT (builtin_type_m68881_ext) = &floatformat_m68881_ext;
598f52df
AC
3644 builtin_type_i960_ext =
3645 init_type (TYPE_CODE_FLT, floatformat_i960_ext.totalsize / 8,
3646 0, "builtin_type_i960_ext", NULL);
069e84fd 3647 TYPE_FLOATFORMAT (builtin_type_i960_ext) = &floatformat_i960_ext;
598f52df
AC
3648 builtin_type_m88110_ext =
3649 init_type (TYPE_CODE_FLT, floatformat_m88110_ext.totalsize / 8,
3650 0, "builtin_type_m88110_ext", NULL);
069e84fd 3651 TYPE_FLOATFORMAT (builtin_type_m88110_ext) = &floatformat_m88110_ext;
598f52df
AC
3652 builtin_type_m88110_harris_ext =
3653 init_type (TYPE_CODE_FLT, floatformat_m88110_harris_ext.totalsize / 8,
3654 0, "builtin_type_m88110_harris_ext", NULL);
069e84fd 3655 TYPE_FLOATFORMAT (builtin_type_m88110_harris_ext) = &floatformat_m88110_harris_ext;
598f52df
AC
3656 builtin_type_arm_ext_big =
3657 init_type (TYPE_CODE_FLT, floatformat_arm_ext_big.totalsize / 8,
3658 0, "builtin_type_arm_ext_big", NULL);
069e84fd 3659 TYPE_FLOATFORMAT (builtin_type_arm_ext_big) = &floatformat_arm_ext_big;
598f52df
AC
3660 builtin_type_arm_ext_littlebyte_bigword =
3661 init_type (TYPE_CODE_FLT, floatformat_arm_ext_littlebyte_bigword.totalsize / 8,
3662 0, "builtin_type_arm_ext_littlebyte_bigword", NULL);
069e84fd 3663 TYPE_FLOATFORMAT (builtin_type_arm_ext_littlebyte_bigword) = &floatformat_arm_ext_littlebyte_bigword;
598f52df
AC
3664 builtin_type_ia64_spill_big =
3665 init_type (TYPE_CODE_FLT, floatformat_ia64_spill_big.totalsize / 8,
3666 0, "builtin_type_ia64_spill_big", NULL);
069e84fd 3667 TYPE_FLOATFORMAT (builtin_type_ia64_spill_big) = &floatformat_ia64_spill_big;
598f52df
AC
3668 builtin_type_ia64_spill_little =
3669 init_type (TYPE_CODE_FLT, floatformat_ia64_spill_little.totalsize / 8,
3670 0, "builtin_type_ia64_spill_little", NULL);
069e84fd 3671 TYPE_FLOATFORMAT (builtin_type_ia64_spill_little) = &floatformat_ia64_spill_little;
598f52df
AC
3672 builtin_type_ia64_quad_big =
3673 init_type (TYPE_CODE_FLT, floatformat_ia64_quad_big.totalsize / 8,
3674 0, "builtin_type_ia64_quad_big", NULL);
069e84fd 3675 TYPE_FLOATFORMAT (builtin_type_ia64_quad_big) = &floatformat_ia64_quad_big;
598f52df
AC
3676 builtin_type_ia64_quad_little =
3677 init_type (TYPE_CODE_FLT, floatformat_ia64_quad_little.totalsize / 8,
3678 0, "builtin_type_ia64_quad_little", NULL);
069e84fd 3679 TYPE_FLOATFORMAT (builtin_type_ia64_quad_little) = &floatformat_ia64_quad_little;
598f52df 3680
5d161b24
DB
3681 add_show_from_set (
3682 add_set_cmd ("overload", no_class, var_zinteger, (char *) &overload_debug,
3683 "Set debugging of C++ overloading.\n\
3684 When enabled, ranking of the functions\n\
3685 is displayed.", &setdebuglist),
3686 &showdebuglist);
c906108c 3687}