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