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