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