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