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