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