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