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