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