]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/gdbtypes.c
Fix a GDB assert failure on windows
[thirdparty/binutils-gdb.git] / gdb / gdbtypes.c
CommitLineData
c906108c 1/* Support routines for manipulating internal types for GDB.
4f2aea11 2
ecd75fc8 3 Copyright (C) 1992-2014 Free Software Foundation, Inc.
4f2aea11 4
c906108c
SS
5 Contributed by Cygnus Support, using pieces from other GDB modules.
6
c5aa993b 7 This file is part of GDB.
c906108c 8
c5aa993b
JM
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
a9762ec7 11 the Free Software Foundation; either version 3 of the License, or
c5aa993b 12 (at your option) any later version.
c906108c 13
c5aa993b
JM
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
c906108c 18
c5aa993b 19 You should have received a copy of the GNU General Public License
a9762ec7 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
21
22#include "defs.h"
0e9f083f 23#include <string.h>
c906108c
SS
24#include "bfd.h"
25#include "symtab.h"
26#include "symfile.h"
27#include "objfiles.h"
28#include "gdbtypes.h"
29#include "expression.h"
30#include "language.h"
31#include "target.h"
32#include "value.h"
33#include "demangle.h"
34#include "complaints.h"
35#include "gdbcmd.h"
015a42b4 36#include "cp-abi.h"
a02fd225 37#include "gdb_assert.h"
ae5a43e0 38#include "hashtab.h"
8e7b59a5 39#include "exceptions.h"
8de20a37 40#include "cp-support.h"
ca092b61
DE
41#include "bcache.h"
42#include "dwarf2loc.h"
ac3aafc7 43
6403aeea
SW
44/* Initialize BADNESS constants. */
45
a9d5ef47 46const struct rank LENGTH_MISMATCH_BADNESS = {100,0};
6403aeea 47
a9d5ef47
SW
48const struct rank TOO_FEW_PARAMS_BADNESS = {100,0};
49const struct rank INCOMPATIBLE_TYPE_BADNESS = {100,0};
6403aeea 50
a9d5ef47 51const struct rank EXACT_MATCH_BADNESS = {0,0};
6403aeea 52
a9d5ef47
SW
53const struct rank INTEGER_PROMOTION_BADNESS = {1,0};
54const struct rank FLOAT_PROMOTION_BADNESS = {1,0};
55const struct rank BASE_PTR_CONVERSION_BADNESS = {1,0};
56const struct rank INTEGER_CONVERSION_BADNESS = {2,0};
57const struct rank FLOAT_CONVERSION_BADNESS = {2,0};
58const struct rank INT_FLOAT_CONVERSION_BADNESS = {2,0};
59const struct rank VOID_PTR_CONVERSION_BADNESS = {2,0};
5b4f6e25 60const struct rank BOOL_CONVERSION_BADNESS = {3,0};
a9d5ef47
SW
61const struct rank BASE_CONVERSION_BADNESS = {2,0};
62const struct rank REFERENCE_CONVERSION_BADNESS = {2,0};
da096638 63const struct rank NULL_POINTER_CONVERSION_BADNESS = {2,0};
a9d5ef47 64const struct rank NS_POINTER_CONVERSION_BADNESS = {10,0};
a451cb65 65const struct rank NS_INTEGER_POINTER_CONVERSION_BADNESS = {3,0};
6403aeea 66
8da61cc4 67/* Floatformat pairs. */
f9e9243a
UW
68const struct floatformat *floatformats_ieee_half[BFD_ENDIAN_UNKNOWN] = {
69 &floatformat_ieee_half_big,
70 &floatformat_ieee_half_little
71};
8da61cc4
DJ
72const struct floatformat *floatformats_ieee_single[BFD_ENDIAN_UNKNOWN] = {
73 &floatformat_ieee_single_big,
74 &floatformat_ieee_single_little
75};
76const struct floatformat *floatformats_ieee_double[BFD_ENDIAN_UNKNOWN] = {
77 &floatformat_ieee_double_big,
78 &floatformat_ieee_double_little
79};
80const struct floatformat *floatformats_ieee_double_littlebyte_bigword[BFD_ENDIAN_UNKNOWN] = {
81 &floatformat_ieee_double_big,
82 &floatformat_ieee_double_littlebyte_bigword
83};
84const struct floatformat *floatformats_i387_ext[BFD_ENDIAN_UNKNOWN] = {
85 &floatformat_i387_ext,
86 &floatformat_i387_ext
87};
88const struct floatformat *floatformats_m68881_ext[BFD_ENDIAN_UNKNOWN] = {
89 &floatformat_m68881_ext,
90 &floatformat_m68881_ext
91};
92const struct floatformat *floatformats_arm_ext[BFD_ENDIAN_UNKNOWN] = {
93 &floatformat_arm_ext_big,
94 &floatformat_arm_ext_littlebyte_bigword
95};
96const struct floatformat *floatformats_ia64_spill[BFD_ENDIAN_UNKNOWN] = {
97 &floatformat_ia64_spill_big,
98 &floatformat_ia64_spill_little
99};
100const struct floatformat *floatformats_ia64_quad[BFD_ENDIAN_UNKNOWN] = {
101 &floatformat_ia64_quad_big,
102 &floatformat_ia64_quad_little
103};
104const struct floatformat *floatformats_vax_f[BFD_ENDIAN_UNKNOWN] = {
105 &floatformat_vax_f,
106 &floatformat_vax_f
107};
108const struct floatformat *floatformats_vax_d[BFD_ENDIAN_UNKNOWN] = {
109 &floatformat_vax_d,
110 &floatformat_vax_d
111};
b14d30e1 112const struct floatformat *floatformats_ibm_long_double[BFD_ENDIAN_UNKNOWN] = {
f5aee5ee
AM
113 &floatformat_ibm_long_double_big,
114 &floatformat_ibm_long_double_little
b14d30e1 115};
8da61cc4 116
2873700e
KS
117/* Should opaque types be resolved? */
118
119static int opaque_type_resolution = 1;
120
121/* A flag to enable printing of debugging information of C++
122 overloading. */
123
124unsigned int overload_debug = 0;
125
a451cb65
KS
126/* A flag to enable strict type checking. */
127
128static int strict_type_checking = 1;
129
2873700e 130/* A function to show whether opaque types are resolved. */
5212577a 131
920d2a44
AC
132static void
133show_opaque_type_resolution (struct ui_file *file, int from_tty,
7ba81444
MS
134 struct cmd_list_element *c,
135 const char *value)
920d2a44 136{
3e43a32a
MS
137 fprintf_filtered (file, _("Resolution of opaque struct/class/union types "
138 "(if set before loading symbols) is %s.\n"),
920d2a44
AC
139 value);
140}
141
2873700e 142/* A function to show whether C++ overload debugging is enabled. */
5212577a 143
920d2a44
AC
144static void
145show_overload_debug (struct ui_file *file, int from_tty,
146 struct cmd_list_element *c, const char *value)
147{
7ba81444
MS
148 fprintf_filtered (file, _("Debugging of C++ overloading is %s.\n"),
149 value);
920d2a44 150}
c906108c 151
a451cb65
KS
152/* A function to show the status of strict type checking. */
153
154static void
155show_strict_type_checking (struct ui_file *file, int from_tty,
156 struct cmd_list_element *c, const char *value)
157{
158 fprintf_filtered (file, _("Strict type checking is %s.\n"), value);
159}
160
5212577a 161\f
e9bb382b
UW
162/* Allocate a new OBJFILE-associated type structure and fill it
163 with some defaults. Space for the type structure is allocated
164 on the objfile's objfile_obstack. */
c906108c
SS
165
166struct type *
fba45db2 167alloc_type (struct objfile *objfile)
c906108c 168{
52f0bd74 169 struct type *type;
c906108c 170
e9bb382b
UW
171 gdb_assert (objfile != NULL);
172
7ba81444 173 /* Alloc the structure and start off with all fields zeroed. */
e9bb382b
UW
174 type = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct type);
175 TYPE_MAIN_TYPE (type) = OBSTACK_ZALLOC (&objfile->objfile_obstack,
176 struct main_type);
177 OBJSTAT (objfile, n_types++);
c906108c 178
e9bb382b
UW
179 TYPE_OBJFILE_OWNED (type) = 1;
180 TYPE_OWNER (type).objfile = objfile;
c906108c 181
7ba81444 182 /* Initialize the fields that might not be zero. */
c906108c
SS
183
184 TYPE_CODE (type) = TYPE_CODE_UNDEF;
c906108c 185 TYPE_VPTR_FIELDNO (type) = -1;
2fdde8f8 186 TYPE_CHAIN (type) = type; /* Chain back to itself. */
c906108c 187
c16abbde 188 return type;
c906108c
SS
189}
190
e9bb382b
UW
191/* Allocate a new GDBARCH-associated type structure and fill it
192 with some defaults. Space for the type structure is allocated
193 on the heap. */
194
195struct type *
196alloc_type_arch (struct gdbarch *gdbarch)
197{
198 struct type *type;
199
200 gdb_assert (gdbarch != NULL);
201
202 /* Alloc the structure and start off with all fields zeroed. */
203
41bf6aca
TT
204 type = XCNEW (struct type);
205 TYPE_MAIN_TYPE (type) = XCNEW (struct main_type);
e9bb382b
UW
206
207 TYPE_OBJFILE_OWNED (type) = 0;
208 TYPE_OWNER (type).gdbarch = gdbarch;
209
210 /* Initialize the fields that might not be zero. */
211
212 TYPE_CODE (type) = TYPE_CODE_UNDEF;
213 TYPE_VPTR_FIELDNO (type) = -1;
214 TYPE_CHAIN (type) = type; /* Chain back to itself. */
215
216 return type;
217}
218
219/* If TYPE is objfile-associated, allocate a new type structure
220 associated with the same objfile. If TYPE is gdbarch-associated,
221 allocate a new type structure associated with the same gdbarch. */
222
223struct type *
224alloc_type_copy (const struct type *type)
225{
226 if (TYPE_OBJFILE_OWNED (type))
227 return alloc_type (TYPE_OWNER (type).objfile);
228 else
229 return alloc_type_arch (TYPE_OWNER (type).gdbarch);
230}
231
232/* If TYPE is gdbarch-associated, return that architecture.
233 If TYPE is objfile-associated, return that objfile's architecture. */
234
235struct gdbarch *
236get_type_arch (const struct type *type)
237{
238 if (TYPE_OBJFILE_OWNED (type))
239 return get_objfile_arch (TYPE_OWNER (type).objfile);
240 else
241 return TYPE_OWNER (type).gdbarch;
242}
243
99ad9427
YQ
244/* See gdbtypes.h. */
245
246struct type *
247get_target_type (struct type *type)
248{
249 if (type != NULL)
250 {
251 type = TYPE_TARGET_TYPE (type);
252 if (type != NULL)
253 type = check_typedef (type);
254 }
255
256 return type;
257}
258
2fdde8f8
DJ
259/* Alloc a new type instance structure, fill it with some defaults,
260 and point it at OLDTYPE. Allocate the new type instance from the
261 same place as OLDTYPE. */
262
263static struct type *
264alloc_type_instance (struct type *oldtype)
265{
266 struct type *type;
267
268 /* Allocate the structure. */
269
e9bb382b 270 if (! TYPE_OBJFILE_OWNED (oldtype))
41bf6aca 271 type = XCNEW (struct type);
2fdde8f8 272 else
1deafd4e
PA
273 type = OBSTACK_ZALLOC (&TYPE_OBJFILE (oldtype)->objfile_obstack,
274 struct type);
275
2fdde8f8
DJ
276 TYPE_MAIN_TYPE (type) = TYPE_MAIN_TYPE (oldtype);
277
278 TYPE_CHAIN (type) = type; /* Chain back to itself for now. */
279
c16abbde 280 return type;
2fdde8f8
DJ
281}
282
283/* Clear all remnants of the previous type at TYPE, in preparation for
e9bb382b 284 replacing it with something else. Preserve owner information. */
5212577a 285
2fdde8f8
DJ
286static void
287smash_type (struct type *type)
288{
e9bb382b
UW
289 int objfile_owned = TYPE_OBJFILE_OWNED (type);
290 union type_owner owner = TYPE_OWNER (type);
291
2fdde8f8
DJ
292 memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type));
293
e9bb382b
UW
294 /* Restore owner information. */
295 TYPE_OBJFILE_OWNED (type) = objfile_owned;
296 TYPE_OWNER (type) = owner;
297
2fdde8f8
DJ
298 /* For now, delete the rings. */
299 TYPE_CHAIN (type) = type;
300
301 /* For now, leave the pointer/reference types alone. */
302}
303
c906108c
SS
304/* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
305 to a pointer to memory where the pointer type should be stored.
306 If *TYPEPTR is zero, update it to point to the pointer type we return.
307 We allocate new memory if needed. */
308
309struct type *
fba45db2 310make_pointer_type (struct type *type, struct type **typeptr)
c906108c 311{
52f0bd74 312 struct type *ntype; /* New type */
053cb41b 313 struct type *chain;
c906108c
SS
314
315 ntype = TYPE_POINTER_TYPE (type);
316
c5aa993b 317 if (ntype)
c906108c 318 {
c5aa993b 319 if (typeptr == 0)
7ba81444
MS
320 return ntype; /* Don't care about alloc,
321 and have new type. */
c906108c 322 else if (*typeptr == 0)
c5aa993b 323 {
7ba81444 324 *typeptr = ntype; /* Tracking alloc, and have new type. */
c906108c 325 return ntype;
c5aa993b 326 }
c906108c
SS
327 }
328
329 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
330 {
e9bb382b 331 ntype = alloc_type_copy (type);
c906108c
SS
332 if (typeptr)
333 *typeptr = ntype;
334 }
7ba81444 335 else /* We have storage, but need to reset it. */
c906108c
SS
336 {
337 ntype = *typeptr;
053cb41b 338 chain = TYPE_CHAIN (ntype);
2fdde8f8 339 smash_type (ntype);
053cb41b 340 TYPE_CHAIN (ntype) = chain;
c906108c
SS
341 }
342
343 TYPE_TARGET_TYPE (ntype) = type;
344 TYPE_POINTER_TYPE (type) = ntype;
345
5212577a 346 /* FIXME! Assumes the machine has only one representation for pointers! */
c906108c 347
50810684
UW
348 TYPE_LENGTH (ntype)
349 = gdbarch_ptr_bit (get_type_arch (type)) / TARGET_CHAR_BIT;
c906108c
SS
350 TYPE_CODE (ntype) = TYPE_CODE_PTR;
351
67b2adb2 352 /* Mark pointers as unsigned. The target converts between pointers
76e71323 353 and addresses (CORE_ADDRs) using gdbarch_pointer_to_address and
7ba81444 354 gdbarch_address_to_pointer. */
876cecd0 355 TYPE_UNSIGNED (ntype) = 1;
c5aa993b 356
053cb41b
JB
357 /* Update the length of all the other variants of this type. */
358 chain = TYPE_CHAIN (ntype);
359 while (chain != ntype)
360 {
361 TYPE_LENGTH (chain) = TYPE_LENGTH (ntype);
362 chain = TYPE_CHAIN (chain);
363 }
364
c906108c
SS
365 return ntype;
366}
367
368/* Given a type TYPE, return a type of pointers to that type.
369 May need to construct such a type if this is the first use. */
370
371struct type *
fba45db2 372lookup_pointer_type (struct type *type)
c906108c 373{
c5aa993b 374 return make_pointer_type (type, (struct type **) 0);
c906108c
SS
375}
376
7ba81444
MS
377/* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero,
378 points to a pointer to memory where the reference type should be
379 stored. If *TYPEPTR is zero, update it to point to the reference
380 type we return. We allocate new memory if needed. */
c906108c
SS
381
382struct type *
fba45db2 383make_reference_type (struct type *type, struct type **typeptr)
c906108c 384{
52f0bd74 385 struct type *ntype; /* New type */
1e98b326 386 struct type *chain;
c906108c
SS
387
388 ntype = TYPE_REFERENCE_TYPE (type);
389
c5aa993b 390 if (ntype)
c906108c 391 {
c5aa993b 392 if (typeptr == 0)
7ba81444
MS
393 return ntype; /* Don't care about alloc,
394 and have new type. */
c906108c 395 else if (*typeptr == 0)
c5aa993b 396 {
7ba81444 397 *typeptr = ntype; /* Tracking alloc, and have new type. */
c906108c 398 return ntype;
c5aa993b 399 }
c906108c
SS
400 }
401
402 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
403 {
e9bb382b 404 ntype = alloc_type_copy (type);
c906108c
SS
405 if (typeptr)
406 *typeptr = ntype;
407 }
7ba81444 408 else /* We have storage, but need to reset it. */
c906108c
SS
409 {
410 ntype = *typeptr;
1e98b326 411 chain = TYPE_CHAIN (ntype);
2fdde8f8 412 smash_type (ntype);
1e98b326 413 TYPE_CHAIN (ntype) = chain;
c906108c
SS
414 }
415
416 TYPE_TARGET_TYPE (ntype) = type;
417 TYPE_REFERENCE_TYPE (type) = ntype;
418
7ba81444
MS
419 /* FIXME! Assume the machine has only one representation for
420 references, and that it matches the (only) representation for
421 pointers! */
c906108c 422
50810684
UW
423 TYPE_LENGTH (ntype) =
424 gdbarch_ptr_bit (get_type_arch (type)) / TARGET_CHAR_BIT;
c906108c 425 TYPE_CODE (ntype) = TYPE_CODE_REF;
c5aa993b 426
c906108c
SS
427 if (!TYPE_REFERENCE_TYPE (type)) /* Remember it, if don't have one. */
428 TYPE_REFERENCE_TYPE (type) = ntype;
429
1e98b326
JB
430 /* Update the length of all the other variants of this type. */
431 chain = TYPE_CHAIN (ntype);
432 while (chain != ntype)
433 {
434 TYPE_LENGTH (chain) = TYPE_LENGTH (ntype);
435 chain = TYPE_CHAIN (chain);
436 }
437
c906108c
SS
438 return ntype;
439}
440
7ba81444
MS
441/* Same as above, but caller doesn't care about memory allocation
442 details. */
c906108c
SS
443
444struct type *
fba45db2 445lookup_reference_type (struct type *type)
c906108c 446{
c5aa993b 447 return make_reference_type (type, (struct type **) 0);
c906108c
SS
448}
449
7ba81444
MS
450/* Lookup a function type that returns type TYPE. TYPEPTR, if
451 nonzero, points to a pointer to memory where the function type
452 should be stored. If *TYPEPTR is zero, update it to point to the
0c8b41f1 453 function type we return. We allocate new memory if needed. */
c906108c
SS
454
455struct type *
0c8b41f1 456make_function_type (struct type *type, struct type **typeptr)
c906108c 457{
52f0bd74 458 struct type *ntype; /* New type */
c906108c
SS
459
460 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
461 {
e9bb382b 462 ntype = alloc_type_copy (type);
c906108c
SS
463 if (typeptr)
464 *typeptr = ntype;
465 }
7ba81444 466 else /* We have storage, but need to reset it. */
c906108c
SS
467 {
468 ntype = *typeptr;
2fdde8f8 469 smash_type (ntype);
c906108c
SS
470 }
471
472 TYPE_TARGET_TYPE (ntype) = type;
473
474 TYPE_LENGTH (ntype) = 1;
475 TYPE_CODE (ntype) = TYPE_CODE_FUNC;
c5aa993b 476
b6cdc2c1
JK
477 INIT_FUNC_SPECIFIC (ntype);
478
c906108c
SS
479 return ntype;
480}
481
c906108c
SS
482/* Given a type TYPE, return a type of functions that return that type.
483 May need to construct such a type if this is the first use. */
484
485struct type *
fba45db2 486lookup_function_type (struct type *type)
c906108c 487{
0c8b41f1 488 return make_function_type (type, (struct type **) 0);
c906108c
SS
489}
490
71918a86 491/* Given a type TYPE and argument types, return the appropriate
a6fb9c08
TT
492 function type. If the final type in PARAM_TYPES is NULL, make a
493 varargs function. */
71918a86
TT
494
495struct type *
496lookup_function_type_with_arguments (struct type *type,
497 int nparams,
498 struct type **param_types)
499{
500 struct type *fn = make_function_type (type, (struct type **) 0);
501 int i;
502
e314d629 503 if (nparams > 0)
a6fb9c08 504 {
e314d629
TT
505 if (param_types[nparams - 1] == NULL)
506 {
507 --nparams;
508 TYPE_VARARGS (fn) = 1;
509 }
510 else if (TYPE_CODE (check_typedef (param_types[nparams - 1]))
511 == TYPE_CODE_VOID)
512 {
513 --nparams;
514 /* Caller should have ensured this. */
515 gdb_assert (nparams == 0);
516 TYPE_PROTOTYPED (fn) = 1;
517 }
a6fb9c08
TT
518 }
519
71918a86
TT
520 TYPE_NFIELDS (fn) = nparams;
521 TYPE_FIELDS (fn) = TYPE_ZALLOC (fn, nparams * sizeof (struct field));
522 for (i = 0; i < nparams; ++i)
523 TYPE_FIELD_TYPE (fn, i) = param_types[i];
524
525 return fn;
526}
527
47663de5
MS
528/* Identify address space identifier by name --
529 return the integer flag defined in gdbtypes.h. */
5212577a
DE
530
531int
50810684 532address_space_name_to_int (struct gdbarch *gdbarch, char *space_identifier)
47663de5 533{
8b2dbe47 534 int type_flags;
d8734c88 535
7ba81444 536 /* Check for known address space delimiters. */
47663de5 537 if (!strcmp (space_identifier, "code"))
876cecd0 538 return TYPE_INSTANCE_FLAG_CODE_SPACE;
47663de5 539 else if (!strcmp (space_identifier, "data"))
876cecd0 540 return TYPE_INSTANCE_FLAG_DATA_SPACE;
5f11f355
AC
541 else if (gdbarch_address_class_name_to_type_flags_p (gdbarch)
542 && gdbarch_address_class_name_to_type_flags (gdbarch,
543 space_identifier,
544 &type_flags))
8b2dbe47 545 return type_flags;
47663de5 546 else
8a3fe4f8 547 error (_("Unknown address space specifier: \"%s\""), space_identifier);
47663de5
MS
548}
549
550/* Identify address space identifier by integer flag as defined in
7ba81444 551 gdbtypes.h -- return the string version of the adress space name. */
47663de5 552
321432c0 553const char *
50810684 554address_space_int_to_name (struct gdbarch *gdbarch, int space_flag)
47663de5 555{
876cecd0 556 if (space_flag & TYPE_INSTANCE_FLAG_CODE_SPACE)
47663de5 557 return "code";
876cecd0 558 else if (space_flag & TYPE_INSTANCE_FLAG_DATA_SPACE)
47663de5 559 return "data";
876cecd0 560 else if ((space_flag & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
5f11f355
AC
561 && gdbarch_address_class_type_flags_to_name_p (gdbarch))
562 return gdbarch_address_class_type_flags_to_name (gdbarch, space_flag);
47663de5
MS
563 else
564 return NULL;
565}
566
2fdde8f8 567/* Create a new type with instance flags NEW_FLAGS, based on TYPE.
ad766c0a
JB
568
569 If STORAGE is non-NULL, create the new type instance there.
570 STORAGE must be in the same obstack as TYPE. */
47663de5 571
b9362cc7 572static struct type *
2fdde8f8
DJ
573make_qualified_type (struct type *type, int new_flags,
574 struct type *storage)
47663de5
MS
575{
576 struct type *ntype;
577
578 ntype = type;
5f61c20e
JK
579 do
580 {
581 if (TYPE_INSTANCE_FLAGS (ntype) == new_flags)
582 return ntype;
583 ntype = TYPE_CHAIN (ntype);
584 }
585 while (ntype != type);
47663de5 586
2fdde8f8
DJ
587 /* Create a new type instance. */
588 if (storage == NULL)
589 ntype = alloc_type_instance (type);
590 else
591 {
7ba81444
MS
592 /* If STORAGE was provided, it had better be in the same objfile
593 as TYPE. Otherwise, we can't link it into TYPE's cv chain:
594 if one objfile is freed and the other kept, we'd have
595 dangling pointers. */
ad766c0a
JB
596 gdb_assert (TYPE_OBJFILE (type) == TYPE_OBJFILE (storage));
597
2fdde8f8
DJ
598 ntype = storage;
599 TYPE_MAIN_TYPE (ntype) = TYPE_MAIN_TYPE (type);
600 TYPE_CHAIN (ntype) = ntype;
601 }
47663de5
MS
602
603 /* Pointers or references to the original type are not relevant to
2fdde8f8 604 the new type. */
47663de5
MS
605 TYPE_POINTER_TYPE (ntype) = (struct type *) 0;
606 TYPE_REFERENCE_TYPE (ntype) = (struct type *) 0;
47663de5 607
2fdde8f8
DJ
608 /* Chain the new qualified type to the old type. */
609 TYPE_CHAIN (ntype) = TYPE_CHAIN (type);
610 TYPE_CHAIN (type) = ntype;
611
612 /* Now set the instance flags and return the new type. */
613 TYPE_INSTANCE_FLAGS (ntype) = new_flags;
47663de5 614
ab5d3da6
KB
615 /* Set length of new type to that of the original type. */
616 TYPE_LENGTH (ntype) = TYPE_LENGTH (type);
617
47663de5
MS
618 return ntype;
619}
620
2fdde8f8
DJ
621/* Make an address-space-delimited variant of a type -- a type that
622 is identical to the one supplied except that it has an address
623 space attribute attached to it (such as "code" or "data").
624
7ba81444
MS
625 The space attributes "code" and "data" are for Harvard
626 architectures. The address space attributes are for architectures
627 which have alternately sized pointers or pointers with alternate
628 representations. */
2fdde8f8
DJ
629
630struct type *
631make_type_with_address_space (struct type *type, int space_flag)
632{
2fdde8f8 633 int new_flags = ((TYPE_INSTANCE_FLAGS (type)
876cecd0
TT
634 & ~(TYPE_INSTANCE_FLAG_CODE_SPACE
635 | TYPE_INSTANCE_FLAG_DATA_SPACE
636 | TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL))
2fdde8f8
DJ
637 | space_flag);
638
639 return make_qualified_type (type, new_flags, NULL);
640}
c906108c
SS
641
642/* Make a "c-v" variant of a type -- a type that is identical to the
643 one supplied except that it may have const or volatile attributes
644 CNST is a flag for setting the const attribute
645 VOLTL is a flag for setting the volatile attribute
646 TYPE is the base type whose variant we are creating.
c906108c 647
ad766c0a
JB
648 If TYPEPTR and *TYPEPTR are non-zero, then *TYPEPTR points to
649 storage to hold the new qualified type; *TYPEPTR and TYPE must be
650 in the same objfile. Otherwise, allocate fresh memory for the new
651 type whereever TYPE lives. If TYPEPTR is non-zero, set it to the
652 new type we construct. */
5212577a 653
c906108c 654struct type *
7ba81444
MS
655make_cv_type (int cnst, int voltl,
656 struct type *type,
657 struct type **typeptr)
c906108c 658{
52f0bd74 659 struct type *ntype; /* New type */
c906108c 660
2fdde8f8 661 int new_flags = (TYPE_INSTANCE_FLAGS (type)
308d96ed
MS
662 & ~(TYPE_INSTANCE_FLAG_CONST
663 | TYPE_INSTANCE_FLAG_VOLATILE));
c906108c 664
c906108c 665 if (cnst)
876cecd0 666 new_flags |= TYPE_INSTANCE_FLAG_CONST;
c906108c
SS
667
668 if (voltl)
876cecd0 669 new_flags |= TYPE_INSTANCE_FLAG_VOLATILE;
a02fd225 670
2fdde8f8 671 if (typeptr && *typeptr != NULL)
a02fd225 672 {
ad766c0a
JB
673 /* TYPE and *TYPEPTR must be in the same objfile. We can't have
674 a C-V variant chain that threads across objfiles: if one
675 objfile gets freed, then the other has a broken C-V chain.
676
677 This code used to try to copy over the main type from TYPE to
678 *TYPEPTR if they were in different objfiles, but that's
679 wrong, too: TYPE may have a field list or member function
680 lists, which refer to types of their own, etc. etc. The
681 whole shebang would need to be copied over recursively; you
682 can't have inter-objfile pointers. The only thing to do is
683 to leave stub types as stub types, and look them up afresh by
684 name each time you encounter them. */
685 gdb_assert (TYPE_OBJFILE (*typeptr) == TYPE_OBJFILE (type));
2fdde8f8
DJ
686 }
687
7ba81444
MS
688 ntype = make_qualified_type (type, new_flags,
689 typeptr ? *typeptr : NULL);
c906108c 690
2fdde8f8
DJ
691 if (typeptr != NULL)
692 *typeptr = ntype;
a02fd225 693
2fdde8f8 694 return ntype;
a02fd225 695}
c906108c 696
06d66ee9
TT
697/* Make a 'restrict'-qualified version of TYPE. */
698
699struct type *
700make_restrict_type (struct type *type)
701{
702 return make_qualified_type (type,
703 (TYPE_INSTANCE_FLAGS (type)
704 | TYPE_INSTANCE_FLAG_RESTRICT),
705 NULL);
706}
707
2fdde8f8
DJ
708/* Replace the contents of ntype with the type *type. This changes the
709 contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus
710 the changes are propogated to all types in the TYPE_CHAIN.
dd6bda65 711
cda6c68a
JB
712 In order to build recursive types, it's inevitable that we'll need
713 to update types in place --- but this sort of indiscriminate
714 smashing is ugly, and needs to be replaced with something more
2fdde8f8
DJ
715 controlled. TYPE_MAIN_TYPE is a step in this direction; it's not
716 clear if more steps are needed. */
5212577a 717
dd6bda65
DJ
718void
719replace_type (struct type *ntype, struct type *type)
720{
ab5d3da6 721 struct type *chain;
dd6bda65 722
ad766c0a
JB
723 /* These two types had better be in the same objfile. Otherwise,
724 the assignment of one type's main type structure to the other
725 will produce a type with references to objects (names; field
726 lists; etc.) allocated on an objfile other than its own. */
727 gdb_assert (TYPE_OBJFILE (ntype) == TYPE_OBJFILE (ntype));
728
2fdde8f8 729 *TYPE_MAIN_TYPE (ntype) = *TYPE_MAIN_TYPE (type);
dd6bda65 730
7ba81444
MS
731 /* The type length is not a part of the main type. Update it for
732 each type on the variant chain. */
ab5d3da6 733 chain = ntype;
5f61c20e
JK
734 do
735 {
736 /* Assert that this element of the chain has no address-class bits
737 set in its flags. Such type variants might have type lengths
738 which are supposed to be different from the non-address-class
739 variants. This assertion shouldn't ever be triggered because
740 symbol readers which do construct address-class variants don't
741 call replace_type(). */
742 gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain) == 0);
743
744 TYPE_LENGTH (chain) = TYPE_LENGTH (type);
745 chain = TYPE_CHAIN (chain);
746 }
747 while (ntype != chain);
ab5d3da6 748
2fdde8f8
DJ
749 /* Assert that the two types have equivalent instance qualifiers.
750 This should be true for at least all of our debug readers. */
751 gdb_assert (TYPE_INSTANCE_FLAGS (ntype) == TYPE_INSTANCE_FLAGS (type));
dd6bda65
DJ
752}
753
c906108c
SS
754/* Implement direct support for MEMBER_TYPE in GNU C++.
755 May need to construct such a type if this is the first use.
756 The TYPE is the type of the member. The DOMAIN is the type
757 of the aggregate that the member belongs to. */
758
759struct type *
0d5de010 760lookup_memberptr_type (struct type *type, struct type *domain)
c906108c 761{
52f0bd74 762 struct type *mtype;
c906108c 763
e9bb382b 764 mtype = alloc_type_copy (type);
0d5de010 765 smash_to_memberptr_type (mtype, domain, type);
c16abbde 766 return mtype;
c906108c
SS
767}
768
0d5de010
DJ
769/* Return a pointer-to-method type, for a method of type TO_TYPE. */
770
771struct type *
772lookup_methodptr_type (struct type *to_type)
773{
774 struct type *mtype;
775
e9bb382b 776 mtype = alloc_type_copy (to_type);
0b92b5bb 777 smash_to_methodptr_type (mtype, to_type);
0d5de010
DJ
778 return mtype;
779}
780
7ba81444
MS
781/* Allocate a stub method whose return type is TYPE. This apparently
782 happens for speed of symbol reading, since parsing out the
783 arguments to the method is cpu-intensive, the way we are doing it.
784 So, we will fill in arguments later. This always returns a fresh
785 type. */
c906108c
SS
786
787struct type *
fba45db2 788allocate_stub_method (struct type *type)
c906108c
SS
789{
790 struct type *mtype;
791
e9bb382b
UW
792 mtype = alloc_type_copy (type);
793 TYPE_CODE (mtype) = TYPE_CODE_METHOD;
794 TYPE_LENGTH (mtype) = 1;
795 TYPE_STUB (mtype) = 1;
c906108c
SS
796 TYPE_TARGET_TYPE (mtype) = type;
797 /* _DOMAIN_TYPE (mtype) = unknown yet */
c16abbde 798 return mtype;
c906108c
SS
799}
800
7ba81444
MS
801/* Create a range type using either a blank type supplied in
802 RESULT_TYPE, or creating a new type, inheriting the objfile from
803 INDEX_TYPE.
c906108c 804
7ba81444
MS
805 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND
806 to HIGH_BOUND, inclusive.
c906108c 807
7ba81444
MS
808 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
809 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
c906108c
SS
810
811struct type *
fba45db2 812create_range_type (struct type *result_type, struct type *index_type,
43bbcdc2 813 LONGEST low_bound, LONGEST high_bound)
c906108c
SS
814{
815 if (result_type == NULL)
e9bb382b 816 result_type = alloc_type_copy (index_type);
c906108c
SS
817 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
818 TYPE_TARGET_TYPE (result_type) = index_type;
74a9bb82 819 if (TYPE_STUB (index_type))
876cecd0 820 TYPE_TARGET_STUB (result_type) = 1;
c906108c
SS
821 else
822 TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
43bbcdc2
PH
823 TYPE_RANGE_DATA (result_type) = (struct range_bounds *)
824 TYPE_ZALLOC (result_type, sizeof (struct range_bounds));
262452ec
JK
825 TYPE_LOW_BOUND (result_type) = low_bound;
826 TYPE_HIGH_BOUND (result_type) = high_bound;
c906108c 827
c5aa993b 828 if (low_bound >= 0)
876cecd0 829 TYPE_UNSIGNED (result_type) = 1;
c906108c 830
262452ec 831 return result_type;
c906108c
SS
832}
833
7ba81444
MS
834/* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type
835 TYPE. Return 1 if type is a range type, 0 if it is discrete (and
836 bounds will fit in LONGEST), or -1 otherwise. */
c906108c
SS
837
838int
fba45db2 839get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
c906108c
SS
840{
841 CHECK_TYPEDEF (type);
842 switch (TYPE_CODE (type))
843 {
844 case TYPE_CODE_RANGE:
845 *lowp = TYPE_LOW_BOUND (type);
846 *highp = TYPE_HIGH_BOUND (type);
847 return 1;
848 case TYPE_CODE_ENUM:
849 if (TYPE_NFIELDS (type) > 0)
850 {
851 /* The enums may not be sorted by value, so search all
0963b4bd 852 entries. */
c906108c
SS
853 int i;
854
14e75d8e 855 *lowp = *highp = TYPE_FIELD_ENUMVAL (type, 0);
c906108c
SS
856 for (i = 0; i < TYPE_NFIELDS (type); i++)
857 {
14e75d8e
JK
858 if (TYPE_FIELD_ENUMVAL (type, i) < *lowp)
859 *lowp = TYPE_FIELD_ENUMVAL (type, i);
860 if (TYPE_FIELD_ENUMVAL (type, i) > *highp)
861 *highp = TYPE_FIELD_ENUMVAL (type, i);
c906108c
SS
862 }
863
7ba81444 864 /* Set unsigned indicator if warranted. */
c5aa993b 865 if (*lowp >= 0)
c906108c 866 {
876cecd0 867 TYPE_UNSIGNED (type) = 1;
c906108c
SS
868 }
869 }
870 else
871 {
872 *lowp = 0;
873 *highp = -1;
874 }
875 return 0;
876 case TYPE_CODE_BOOL:
877 *lowp = 0;
878 *highp = 1;
879 return 0;
880 case TYPE_CODE_INT:
c5aa993b 881 if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */
c906108c
SS
882 return -1;
883 if (!TYPE_UNSIGNED (type))
884 {
c5aa993b 885 *lowp = -(1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1));
c906108c
SS
886 *highp = -*lowp - 1;
887 return 0;
888 }
7ba81444 889 /* ... fall through for unsigned ints ... */
c906108c
SS
890 case TYPE_CODE_CHAR:
891 *lowp = 0;
892 /* This round-about calculation is to avoid shifting by
7b83ea04 893 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
7ba81444 894 if TYPE_LENGTH (type) == sizeof (LONGEST). */
c906108c
SS
895 *highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1);
896 *highp = (*highp - 1) | *highp;
897 return 0;
898 default:
899 return -1;
900 }
901}
902
dbc98a8b
KW
903/* Assuming TYPE is a simple, non-empty array type, compute its upper
904 and lower bound. Save the low bound into LOW_BOUND if not NULL.
905 Save the high bound into HIGH_BOUND if not NULL.
906
0963b4bd 907 Return 1 if the operation was successful. Return zero otherwise,
dbc98a8b
KW
908 in which case the values of LOW_BOUND and HIGH_BOUNDS are unmodified.
909
910 We now simply use get_discrete_bounds call to get the values
911 of the low and high bounds.
912 get_discrete_bounds can return three values:
913 1, meaning that index is a range,
914 0, meaning that index is a discrete type,
915 or -1 for failure. */
916
917int
918get_array_bounds (struct type *type, LONGEST *low_bound, LONGEST *high_bound)
919{
920 struct type *index = TYPE_INDEX_TYPE (type);
921 LONGEST low = 0;
922 LONGEST high = 0;
923 int res;
924
925 if (index == NULL)
926 return 0;
927
928 res = get_discrete_bounds (index, &low, &high);
929 if (res == -1)
930 return 0;
931
932 /* Check if the array bounds are undefined. */
933 if (res == 1
934 && ((low_bound && TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED (type))
935 || (high_bound && TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))))
936 return 0;
937
938 if (low_bound)
939 *low_bound = low;
940
941 if (high_bound)
942 *high_bound = high;
943
944 return 1;
945}
946
7ba81444
MS
947/* Create an array type using either a blank type supplied in
948 RESULT_TYPE, or creating a new type, inheriting the objfile from
949 RANGE_TYPE.
c906108c
SS
950
951 Elements will be of type ELEMENT_TYPE, the indices will be of type
952 RANGE_TYPE.
953
7ba81444
MS
954 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
955 sure it is TYPE_CODE_UNDEF before we bash it into an array
956 type? */
c906108c
SS
957
958struct type *
7ba81444
MS
959create_array_type (struct type *result_type,
960 struct type *element_type,
fba45db2 961 struct type *range_type)
c906108c
SS
962{
963 LONGEST low_bound, high_bound;
964
965 if (result_type == NULL)
e9bb382b
UW
966 result_type = alloc_type_copy (range_type);
967
c906108c
SS
968 TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
969 TYPE_TARGET_TYPE (result_type) = element_type;
970 if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
971 low_bound = high_bound = 0;
972 CHECK_TYPEDEF (element_type);
ab0d6e0d
JB
973 /* Be careful when setting the array length. Ada arrays can be
974 empty arrays with the high_bound being smaller than the low_bound.
975 In such cases, the array length should be zero. */
976 if (high_bound < low_bound)
977 TYPE_LENGTH (result_type) = 0;
978 else
979 TYPE_LENGTH (result_type) =
980 TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
c906108c
SS
981 TYPE_NFIELDS (result_type) = 1;
982 TYPE_FIELDS (result_type) =
1deafd4e 983 (struct field *) TYPE_ZALLOC (result_type, sizeof (struct field));
262452ec 984 TYPE_INDEX_TYPE (result_type) = range_type;
c906108c
SS
985 TYPE_VPTR_FIELDNO (result_type) = -1;
986
0963b4bd 987 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays. */
c906108c 988 if (TYPE_LENGTH (result_type) == 0)
876cecd0 989 TYPE_TARGET_STUB (result_type) = 1;
c906108c 990
c16abbde 991 return result_type;
c906108c
SS
992}
993
e3506a9f
UW
994struct type *
995lookup_array_range_type (struct type *element_type,
63375b74 996 LONGEST low_bound, LONGEST high_bound)
e3506a9f 997{
50810684 998 struct gdbarch *gdbarch = get_type_arch (element_type);
e3506a9f
UW
999 struct type *index_type = builtin_type (gdbarch)->builtin_int;
1000 struct type *range_type
1001 = create_range_type (NULL, index_type, low_bound, high_bound);
d8734c88 1002
e3506a9f
UW
1003 return create_array_type (NULL, element_type, range_type);
1004}
1005
7ba81444
MS
1006/* Create a string type using either a blank type supplied in
1007 RESULT_TYPE, or creating a new type. String types are similar
1008 enough to array of char types that we can use create_array_type to
1009 build the basic type and then bash it into a string type.
c906108c
SS
1010
1011 For fixed length strings, the range type contains 0 as the lower
1012 bound and the length of the string minus one as the upper bound.
1013
7ba81444
MS
1014 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
1015 sure it is TYPE_CODE_UNDEF before we bash it into a string
1016 type? */
c906108c
SS
1017
1018struct type *
3b7538c0
UW
1019create_string_type (struct type *result_type,
1020 struct type *string_char_type,
7ba81444 1021 struct type *range_type)
c906108c
SS
1022{
1023 result_type = create_array_type (result_type,
f290d38e 1024 string_char_type,
c906108c
SS
1025 range_type);
1026 TYPE_CODE (result_type) = TYPE_CODE_STRING;
c16abbde 1027 return result_type;
c906108c
SS
1028}
1029
e3506a9f
UW
1030struct type *
1031lookup_string_range_type (struct type *string_char_type,
63375b74 1032 LONGEST low_bound, LONGEST high_bound)
e3506a9f
UW
1033{
1034 struct type *result_type;
d8734c88 1035
e3506a9f
UW
1036 result_type = lookup_array_range_type (string_char_type,
1037 low_bound, high_bound);
1038 TYPE_CODE (result_type) = TYPE_CODE_STRING;
1039 return result_type;
1040}
1041
c906108c 1042struct type *
fba45db2 1043create_set_type (struct type *result_type, struct type *domain_type)
c906108c 1044{
c906108c 1045 if (result_type == NULL)
e9bb382b
UW
1046 result_type = alloc_type_copy (domain_type);
1047
c906108c
SS
1048 TYPE_CODE (result_type) = TYPE_CODE_SET;
1049 TYPE_NFIELDS (result_type) = 1;
1deafd4e 1050 TYPE_FIELDS (result_type) = TYPE_ZALLOC (result_type, sizeof (struct field));
c906108c 1051
74a9bb82 1052 if (!TYPE_STUB (domain_type))
c906108c 1053 {
f9780d5b 1054 LONGEST low_bound, high_bound, bit_length;
d8734c88 1055
c906108c
SS
1056 if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0)
1057 low_bound = high_bound = 0;
1058 bit_length = high_bound - low_bound + 1;
1059 TYPE_LENGTH (result_type)
1060 = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
f9780d5b 1061 if (low_bound >= 0)
876cecd0 1062 TYPE_UNSIGNED (result_type) = 1;
c906108c
SS
1063 }
1064 TYPE_FIELD_TYPE (result_type, 0) = domain_type;
1065
c16abbde 1066 return result_type;
c906108c
SS
1067}
1068
ea37ba09
DJ
1069/* Convert ARRAY_TYPE to a vector type. This may modify ARRAY_TYPE
1070 and any array types nested inside it. */
1071
1072void
1073make_vector_type (struct type *array_type)
1074{
1075 struct type *inner_array, *elt_type;
1076 int flags;
1077
1078 /* Find the innermost array type, in case the array is
1079 multi-dimensional. */
1080 inner_array = array_type;
1081 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY)
1082 inner_array = TYPE_TARGET_TYPE (inner_array);
1083
1084 elt_type = TYPE_TARGET_TYPE (inner_array);
1085 if (TYPE_CODE (elt_type) == TYPE_CODE_INT)
1086 {
2844d6b5 1087 flags = TYPE_INSTANCE_FLAGS (elt_type) | TYPE_INSTANCE_FLAG_NOTTEXT;
ea37ba09
DJ
1088 elt_type = make_qualified_type (elt_type, flags, NULL);
1089 TYPE_TARGET_TYPE (inner_array) = elt_type;
1090 }
1091
876cecd0 1092 TYPE_VECTOR (array_type) = 1;
ea37ba09
DJ
1093}
1094
794ac428 1095struct type *
ac3aafc7
EZ
1096init_vector_type (struct type *elt_type, int n)
1097{
1098 struct type *array_type;
d8734c88 1099
e3506a9f 1100 array_type = lookup_array_range_type (elt_type, 0, n - 1);
ea37ba09 1101 make_vector_type (array_type);
ac3aafc7
EZ
1102 return array_type;
1103}
1104
0d5de010
DJ
1105/* Smash TYPE to be a type of pointers to members of DOMAIN with type
1106 TO_TYPE. A member pointer is a wierd thing -- it amounts to a
1107 typed offset into a struct, e.g. "an int at offset 8". A MEMBER
1108 TYPE doesn't include the offset (that's the value of the MEMBER
1109 itself), but does include the structure type into which it points
1110 (for some reason).
c906108c 1111
7ba81444
MS
1112 When "smashing" the type, we preserve the objfile that the old type
1113 pointed to, since we aren't changing where the type is actually
c906108c
SS
1114 allocated. */
1115
1116void
0d5de010
DJ
1117smash_to_memberptr_type (struct type *type, struct type *domain,
1118 struct type *to_type)
c906108c 1119{
2fdde8f8 1120 smash_type (type);
c906108c
SS
1121 TYPE_TARGET_TYPE (type) = to_type;
1122 TYPE_DOMAIN_TYPE (type) = domain;
0d5de010
DJ
1123 /* Assume that a data member pointer is the same size as a normal
1124 pointer. */
50810684
UW
1125 TYPE_LENGTH (type)
1126 = gdbarch_ptr_bit (get_type_arch (to_type)) / TARGET_CHAR_BIT;
0d5de010 1127 TYPE_CODE (type) = TYPE_CODE_MEMBERPTR;
c906108c
SS
1128}
1129
0b92b5bb
TT
1130/* Smash TYPE to be a type of pointer to methods type TO_TYPE.
1131
1132 When "smashing" the type, we preserve the objfile that the old type
1133 pointed to, since we aren't changing where the type is actually
1134 allocated. */
1135
1136void
1137smash_to_methodptr_type (struct type *type, struct type *to_type)
1138{
1139 smash_type (type);
1140 TYPE_TARGET_TYPE (type) = to_type;
1141 TYPE_DOMAIN_TYPE (type) = TYPE_DOMAIN_TYPE (to_type);
1142 TYPE_LENGTH (type) = cplus_method_ptr_size (to_type);
1143 TYPE_CODE (type) = TYPE_CODE_METHODPTR;
1144}
1145
c906108c
SS
1146/* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
1147 METHOD just means `function that gets an extra "this" argument'.
1148
7ba81444
MS
1149 When "smashing" the type, we preserve the objfile that the old type
1150 pointed to, since we aren't changing where the type is actually
c906108c
SS
1151 allocated. */
1152
1153void
fba45db2 1154smash_to_method_type (struct type *type, struct type *domain,
ad2f7632
DJ
1155 struct type *to_type, struct field *args,
1156 int nargs, int varargs)
c906108c 1157{
2fdde8f8 1158 smash_type (type);
c906108c
SS
1159 TYPE_TARGET_TYPE (type) = to_type;
1160 TYPE_DOMAIN_TYPE (type) = domain;
ad2f7632
DJ
1161 TYPE_FIELDS (type) = args;
1162 TYPE_NFIELDS (type) = nargs;
1163 if (varargs)
876cecd0 1164 TYPE_VARARGS (type) = 1;
c906108c
SS
1165 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
1166 TYPE_CODE (type) = TYPE_CODE_METHOD;
1167}
1168
1169/* Return a typename for a struct/union/enum type without "struct ",
1170 "union ", or "enum ". If the type has a NULL name, return NULL. */
1171
0d5cff50 1172const char *
aa1ee363 1173type_name_no_tag (const struct type *type)
c906108c
SS
1174{
1175 if (TYPE_TAG_NAME (type) != NULL)
1176 return TYPE_TAG_NAME (type);
1177
7ba81444
MS
1178 /* Is there code which expects this to return the name if there is
1179 no tag name? My guess is that this is mainly used for C++ in
1180 cases where the two will always be the same. */
c906108c
SS
1181 return TYPE_NAME (type);
1182}
1183
d8228535
JK
1184/* A wrapper of type_name_no_tag which calls error if the type is anonymous.
1185 Since GCC PR debug/47510 DWARF provides associated information to detect the
1186 anonymous class linkage name from its typedef.
1187
1188 Parameter TYPE should not yet have CHECK_TYPEDEF applied, this function will
1189 apply it itself. */
1190
1191const char *
1192type_name_no_tag_or_error (struct type *type)
1193{
1194 struct type *saved_type = type;
1195 const char *name;
1196 struct objfile *objfile;
1197
1198 CHECK_TYPEDEF (type);
1199
1200 name = type_name_no_tag (type);
1201 if (name != NULL)
1202 return name;
1203
1204 name = type_name_no_tag (saved_type);
1205 objfile = TYPE_OBJFILE (saved_type);
1206 error (_("Invalid anonymous type %s [in module %s], GCC PR debug/47510 bug?"),
4262abfb
JK
1207 name ? name : "<anonymous>",
1208 objfile ? objfile_name (objfile) : "<arch>");
d8228535
JK
1209}
1210
7ba81444
MS
1211/* Lookup a typedef or primitive type named NAME, visible in lexical
1212 block BLOCK. If NOERR is nonzero, return zero if NAME is not
1213 suitably defined. */
c906108c
SS
1214
1215struct type *
e6c014f2 1216lookup_typename (const struct language_defn *language,
ddd49eee 1217 struct gdbarch *gdbarch, const char *name,
34eaf542 1218 const struct block *block, int noerr)
c906108c 1219{
52f0bd74 1220 struct symbol *sym;
659c9f3a 1221 struct type *type;
c906108c 1222
774b6a14 1223 sym = lookup_symbol (name, block, VAR_DOMAIN, 0);
c51fe631
DE
1224 if (sym != NULL && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
1225 return SYMBOL_TYPE (sym);
1226
659c9f3a
DE
1227 type = language_lookup_primitive_type_by_name (language, gdbarch, name);
1228 if (type)
1229 return type;
c51fe631
DE
1230
1231 if (noerr)
1232 return NULL;
1233 error (_("No type named %s."), name);
c906108c
SS
1234}
1235
1236struct type *
e6c014f2 1237lookup_unsigned_typename (const struct language_defn *language,
0d5cff50 1238 struct gdbarch *gdbarch, const char *name)
c906108c
SS
1239{
1240 char *uns = alloca (strlen (name) + 10);
1241
1242 strcpy (uns, "unsigned ");
1243 strcpy (uns + 9, name);
e6c014f2 1244 return lookup_typename (language, gdbarch, uns, (struct block *) NULL, 0);
c906108c
SS
1245}
1246
1247struct type *
e6c014f2 1248lookup_signed_typename (const struct language_defn *language,
0d5cff50 1249 struct gdbarch *gdbarch, const char *name)
c906108c
SS
1250{
1251 struct type *t;
1252 char *uns = alloca (strlen (name) + 8);
1253
1254 strcpy (uns, "signed ");
1255 strcpy (uns + 7, name);
e6c014f2 1256 t = lookup_typename (language, gdbarch, uns, (struct block *) NULL, 1);
7ba81444 1257 /* If we don't find "signed FOO" just try again with plain "FOO". */
c906108c
SS
1258 if (t != NULL)
1259 return t;
e6c014f2 1260 return lookup_typename (language, gdbarch, name, (struct block *) NULL, 0);
c906108c
SS
1261}
1262
1263/* Lookup a structure type named "struct NAME",
1264 visible in lexical block BLOCK. */
1265
1266struct type *
270140bd 1267lookup_struct (const char *name, const struct block *block)
c906108c 1268{
52f0bd74 1269 struct symbol *sym;
c906108c 1270
2570f2b7 1271 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0);
c906108c
SS
1272
1273 if (sym == NULL)
1274 {
8a3fe4f8 1275 error (_("No struct type named %s."), name);
c906108c
SS
1276 }
1277 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
1278 {
7ba81444
MS
1279 error (_("This context has class, union or enum %s, not a struct."),
1280 name);
c906108c
SS
1281 }
1282 return (SYMBOL_TYPE (sym));
1283}
1284
1285/* Lookup a union type named "union NAME",
1286 visible in lexical block BLOCK. */
1287
1288struct type *
270140bd 1289lookup_union (const char *name, const struct block *block)
c906108c 1290{
52f0bd74 1291 struct symbol *sym;
c5aa993b 1292 struct type *t;
c906108c 1293
2570f2b7 1294 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0);
c906108c
SS
1295
1296 if (sym == NULL)
8a3fe4f8 1297 error (_("No union type named %s."), name);
c906108c 1298
c5aa993b 1299 t = SYMBOL_TYPE (sym);
c906108c
SS
1300
1301 if (TYPE_CODE (t) == TYPE_CODE_UNION)
c16abbde 1302 return t;
c906108c 1303
7ba81444
MS
1304 /* If we get here, it's not a union. */
1305 error (_("This context has class, struct or enum %s, not a union."),
1306 name);
c906108c
SS
1307}
1308
c906108c
SS
1309/* Lookup an enum type named "enum NAME",
1310 visible in lexical block BLOCK. */
1311
1312struct type *
270140bd 1313lookup_enum (const char *name, const struct block *block)
c906108c 1314{
52f0bd74 1315 struct symbol *sym;
c906108c 1316
2570f2b7 1317 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0);
c906108c
SS
1318 if (sym == NULL)
1319 {
8a3fe4f8 1320 error (_("No enum type named %s."), name);
c906108c
SS
1321 }
1322 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM)
1323 {
7ba81444
MS
1324 error (_("This context has class, struct or union %s, not an enum."),
1325 name);
c906108c
SS
1326 }
1327 return (SYMBOL_TYPE (sym));
1328}
1329
1330/* Lookup a template type named "template NAME<TYPE>",
1331 visible in lexical block BLOCK. */
1332
1333struct type *
7ba81444 1334lookup_template_type (char *name, struct type *type,
270140bd 1335 const struct block *block)
c906108c
SS
1336{
1337 struct symbol *sym;
7ba81444
MS
1338 char *nam = (char *)
1339 alloca (strlen (name) + strlen (TYPE_NAME (type)) + 4);
d8734c88 1340
c906108c
SS
1341 strcpy (nam, name);
1342 strcat (nam, "<");
0004e5a2 1343 strcat (nam, TYPE_NAME (type));
0963b4bd 1344 strcat (nam, " >"); /* FIXME, extra space still introduced in gcc? */
c906108c 1345
2570f2b7 1346 sym = lookup_symbol (nam, block, VAR_DOMAIN, 0);
c906108c
SS
1347
1348 if (sym == NULL)
1349 {
8a3fe4f8 1350 error (_("No template type named %s."), name);
c906108c
SS
1351 }
1352 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
1353 {
7ba81444
MS
1354 error (_("This context has class, union or enum %s, not a struct."),
1355 name);
c906108c
SS
1356 }
1357 return (SYMBOL_TYPE (sym));
1358}
1359
7ba81444
MS
1360/* Given a type TYPE, lookup the type of the component of type named
1361 NAME.
c906108c 1362
7ba81444
MS
1363 TYPE can be either a struct or union, or a pointer or reference to
1364 a struct or union. If it is a pointer or reference, its target
1365 type is automatically used. Thus '.' and '->' are interchangable,
1366 as specified for the definitions of the expression element types
1367 STRUCTOP_STRUCT and STRUCTOP_PTR.
c906108c
SS
1368
1369 If NOERR is nonzero, return zero if NAME is not suitably defined.
1370 If NAME is the name of a baseclass type, return that type. */
1371
1372struct type *
d7561cbb 1373lookup_struct_elt_type (struct type *type, const char *name, int noerr)
c906108c
SS
1374{
1375 int i;
c92817ce 1376 char *typename;
c906108c
SS
1377
1378 for (;;)
1379 {
1380 CHECK_TYPEDEF (type);
1381 if (TYPE_CODE (type) != TYPE_CODE_PTR
1382 && TYPE_CODE (type) != TYPE_CODE_REF)
1383 break;
1384 type = TYPE_TARGET_TYPE (type);
1385 }
1386
687d6395
MS
1387 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
1388 && TYPE_CODE (type) != TYPE_CODE_UNION)
c906108c 1389 {
c92817ce
TT
1390 typename = type_to_string (type);
1391 make_cleanup (xfree, typename);
1392 error (_("Type %s is not a structure or union type."), typename);
c906108c
SS
1393 }
1394
1395#if 0
7ba81444
MS
1396 /* FIXME: This change put in by Michael seems incorrect for the case
1397 where the structure tag name is the same as the member name.
0963b4bd 1398 I.e. when doing "ptype bell->bar" for "struct foo { int bar; int
7ba81444 1399 foo; } bell;" Disabled by fnf. */
c906108c
SS
1400 {
1401 char *typename;
1402
1403 typename = type_name_no_tag (type);
762f08a3 1404 if (typename != NULL && strcmp (typename, name) == 0)
c906108c
SS
1405 return type;
1406 }
1407#endif
1408
1409 for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
1410 {
0d5cff50 1411 const char *t_field_name = TYPE_FIELD_NAME (type, i);
c906108c 1412
db577aea 1413 if (t_field_name && (strcmp_iw (t_field_name, name) == 0))
c906108c
SS
1414 {
1415 return TYPE_FIELD_TYPE (type, i);
1416 }
f5a010c0
PM
1417 else if (!t_field_name || *t_field_name == '\0')
1418 {
d8734c88
MS
1419 struct type *subtype
1420 = lookup_struct_elt_type (TYPE_FIELD_TYPE (type, i), name, 1);
1421
f5a010c0
PM
1422 if (subtype != NULL)
1423 return subtype;
1424 }
c906108c
SS
1425 }
1426
1427 /* OK, it's not in this class. Recursively check the baseclasses. */
1428 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
1429 {
1430 struct type *t;
1431
9733fc94 1432 t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, 1);
c906108c
SS
1433 if (t != NULL)
1434 {
1435 return t;
1436 }
1437 }
1438
1439 if (noerr)
1440 {
1441 return NULL;
1442 }
c5aa993b 1443
c92817ce
TT
1444 typename = type_to_string (type);
1445 make_cleanup (xfree, typename);
1446 error (_("Type %s has no component named %s."), typename, name);
c906108c
SS
1447}
1448
ed3ef339
DE
1449/* Store in *MAX the largest number representable by unsigned integer type
1450 TYPE. */
1451
1452void
1453get_unsigned_type_max (struct type *type, ULONGEST *max)
1454{
1455 unsigned int n;
1456
1457 CHECK_TYPEDEF (type);
1458 gdb_assert (TYPE_CODE (type) == TYPE_CODE_INT && TYPE_UNSIGNED (type));
1459 gdb_assert (TYPE_LENGTH (type) <= sizeof (ULONGEST));
1460
1461 /* Written this way to avoid overflow. */
1462 n = TYPE_LENGTH (type) * TARGET_CHAR_BIT;
1463 *max = ((((ULONGEST) 1 << (n - 1)) - 1) << 1) | 1;
1464}
1465
1466/* Store in *MIN, *MAX the smallest and largest numbers representable by
1467 signed integer type TYPE. */
1468
1469void
1470get_signed_type_minmax (struct type *type, LONGEST *min, LONGEST *max)
1471{
1472 unsigned int n;
1473
1474 CHECK_TYPEDEF (type);
1475 gdb_assert (TYPE_CODE (type) == TYPE_CODE_INT && !TYPE_UNSIGNED (type));
1476 gdb_assert (TYPE_LENGTH (type) <= sizeof (LONGEST));
1477
1478 n = TYPE_LENGTH (type) * TARGET_CHAR_BIT;
1479 *min = -((ULONGEST) 1 << (n - 1));
1480 *max = ((ULONGEST) 1 << (n - 1)) - 1;
1481}
1482
81fe8080
DE
1483/* Lookup the vptr basetype/fieldno values for TYPE.
1484 If found store vptr_basetype in *BASETYPEP if non-NULL, and return
1485 vptr_fieldno. Also, if found and basetype is from the same objfile,
1486 cache the results.
1487 If not found, return -1 and ignore BASETYPEP.
1488 Callers should be aware that in some cases (for example,
c906108c 1489 the type or one of its baseclasses is a stub type and we are
d48cc9dd
DJ
1490 debugging a .o file, or the compiler uses DWARF-2 and is not GCC),
1491 this function will not be able to find the
7ba81444 1492 virtual function table pointer, and vptr_fieldno will remain -1 and
81fe8080 1493 vptr_basetype will remain NULL or incomplete. */
c906108c 1494
81fe8080
DE
1495int
1496get_vptr_fieldno (struct type *type, struct type **basetypep)
c906108c
SS
1497{
1498 CHECK_TYPEDEF (type);
1499
1500 if (TYPE_VPTR_FIELDNO (type) < 0)
1501 {
1502 int i;
1503
7ba81444
MS
1504 /* We must start at zero in case the first (and only) baseclass
1505 is virtual (and hence we cannot share the table pointer). */
c906108c
SS
1506 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
1507 {
81fe8080
DE
1508 struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i));
1509 int fieldno;
1510 struct type *basetype;
1511
1512 fieldno = get_vptr_fieldno (baseclass, &basetype);
1513 if (fieldno >= 0)
c906108c 1514 {
81fe8080 1515 /* If the type comes from a different objfile we can't cache
0963b4bd 1516 it, it may have a different lifetime. PR 2384 */
5ef73790 1517 if (TYPE_OBJFILE (type) == TYPE_OBJFILE (basetype))
81fe8080
DE
1518 {
1519 TYPE_VPTR_FIELDNO (type) = fieldno;
1520 TYPE_VPTR_BASETYPE (type) = basetype;
1521 }
1522 if (basetypep)
1523 *basetypep = basetype;
1524 return fieldno;
c906108c
SS
1525 }
1526 }
81fe8080
DE
1527
1528 /* Not found. */
1529 return -1;
1530 }
1531 else
1532 {
1533 if (basetypep)
1534 *basetypep = TYPE_VPTR_BASETYPE (type);
1535 return TYPE_VPTR_FIELDNO (type);
c906108c
SS
1536 }
1537}
1538
44e1a9eb
DJ
1539static void
1540stub_noname_complaint (void)
1541{
e2e0b3e5 1542 complaint (&symfile_complaints, _("stub type has NULL name"));
44e1a9eb
DJ
1543}
1544
92163a10
JK
1545/* Find the real type of TYPE. This function returns the real type,
1546 after removing all layers of typedefs, and completing opaque or stub
1547 types. Completion changes the TYPE argument, but stripping of
1548 typedefs does not.
1549
1550 Instance flags (e.g. const/volatile) are preserved as typedefs are
1551 stripped. If necessary a new qualified form of the underlying type
1552 is created.
1553
1554 NOTE: This will return a typedef if TYPE_TARGET_TYPE for the typedef has
1555 not been computed and we're either in the middle of reading symbols, or
1556 there was no name for the typedef in the debug info.
1557
9bc118a5
DE
1558 NOTE: Lookup of opaque types can throw errors for invalid symbol files.
1559 QUITs in the symbol reading code can also throw.
1560 Thus this function can throw an exception.
1561
92163a10
JK
1562 If TYPE is a TYPE_CODE_TYPEDEF, its length is updated to the length of
1563 the target type.
c906108c
SS
1564
1565 If this is a stubbed struct (i.e. declared as struct foo *), see if
0963b4bd 1566 we can find a full definition in some other file. If so, copy this
7ba81444
MS
1567 definition, so we can use it in future. There used to be a comment
1568 (but not any code) that if we don't find a full definition, we'd
1569 set a flag so we don't spend time in the future checking the same
1570 type. That would be a mistake, though--we might load in more
92163a10 1571 symbols which contain a full definition for the type. */
c906108c
SS
1572
1573struct type *
a02fd225 1574check_typedef (struct type *type)
c906108c
SS
1575{
1576 struct type *orig_type = type;
92163a10
JK
1577 /* While we're removing typedefs, we don't want to lose qualifiers.
1578 E.g., const/volatile. */
1579 int instance_flags = TYPE_INSTANCE_FLAGS (type);
a02fd225 1580
423c0af8
MS
1581 gdb_assert (type);
1582
c906108c
SS
1583 while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
1584 {
1585 if (!TYPE_TARGET_TYPE (type))
1586 {
0d5cff50 1587 const char *name;
c906108c
SS
1588 struct symbol *sym;
1589
1590 /* It is dangerous to call lookup_symbol if we are currently
7ba81444 1591 reading a symtab. Infinite recursion is one danger. */
c906108c 1592 if (currently_reading_symtab)
92163a10 1593 return make_qualified_type (type, instance_flags, NULL);
c906108c
SS
1594
1595 name = type_name_no_tag (type);
7ba81444
MS
1596 /* FIXME: shouldn't we separately check the TYPE_NAME and
1597 the TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or
1598 VAR_DOMAIN as appropriate? (this code was written before
1599 TYPE_NAME and TYPE_TAG_NAME were separate). */
c906108c
SS
1600 if (name == NULL)
1601 {
23136709 1602 stub_noname_complaint ();
92163a10 1603 return make_qualified_type (type, instance_flags, NULL);
c906108c 1604 }
2570f2b7 1605 sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0);
c906108c
SS
1606 if (sym)
1607 TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym);
7ba81444 1608 else /* TYPE_CODE_UNDEF */
e9bb382b 1609 TYPE_TARGET_TYPE (type) = alloc_type_arch (get_type_arch (type));
c906108c
SS
1610 }
1611 type = TYPE_TARGET_TYPE (type);
c906108c 1612
92163a10
JK
1613 /* Preserve the instance flags as we traverse down the typedef chain.
1614
1615 Handling address spaces/classes is nasty, what do we do if there's a
1616 conflict?
1617 E.g., what if an outer typedef marks the type as class_1 and an inner
1618 typedef marks the type as class_2?
1619 This is the wrong place to do such error checking. We leave it to
1620 the code that created the typedef in the first place to flag the
1621 error. We just pick the outer address space (akin to letting the
1622 outer cast in a chain of casting win), instead of assuming
1623 "it can't happen". */
1624 {
1625 const int ALL_SPACES = (TYPE_INSTANCE_FLAG_CODE_SPACE
1626 | TYPE_INSTANCE_FLAG_DATA_SPACE);
1627 const int ALL_CLASSES = TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL;
1628 int new_instance_flags = TYPE_INSTANCE_FLAGS (type);
1629
1630 /* Treat code vs data spaces and address classes separately. */
1631 if ((instance_flags & ALL_SPACES) != 0)
1632 new_instance_flags &= ~ALL_SPACES;
1633 if ((instance_flags & ALL_CLASSES) != 0)
1634 new_instance_flags &= ~ALL_CLASSES;
1635
1636 instance_flags |= new_instance_flags;
1637 }
1638 }
a02fd225 1639
7ba81444
MS
1640 /* If this is a struct/class/union with no fields, then check
1641 whether a full definition exists somewhere else. This is for
1642 systems where a type definition with no fields is issued for such
1643 types, instead of identifying them as stub types in the first
1644 place. */
c5aa993b 1645
7ba81444
MS
1646 if (TYPE_IS_OPAQUE (type)
1647 && opaque_type_resolution
1648 && !currently_reading_symtab)
c906108c 1649 {
0d5cff50 1650 const char *name = type_name_no_tag (type);
c5aa993b 1651 struct type *newtype;
d8734c88 1652
c906108c
SS
1653 if (name == NULL)
1654 {
23136709 1655 stub_noname_complaint ();
92163a10 1656 return make_qualified_type (type, instance_flags, NULL);
c906108c
SS
1657 }
1658 newtype = lookup_transparent_type (name);
ad766c0a 1659
c906108c 1660 if (newtype)
ad766c0a 1661 {
7ba81444
MS
1662 /* If the resolved type and the stub are in the same
1663 objfile, then replace the stub type with the real deal.
1664 But if they're in separate objfiles, leave the stub
1665 alone; we'll just look up the transparent type every time
1666 we call check_typedef. We can't create pointers between
1667 types allocated to different objfiles, since they may
1668 have different lifetimes. Trying to copy NEWTYPE over to
1669 TYPE's objfile is pointless, too, since you'll have to
1670 move over any other types NEWTYPE refers to, which could
1671 be an unbounded amount of stuff. */
ad766c0a 1672 if (TYPE_OBJFILE (newtype) == TYPE_OBJFILE (type))
92163a10
JK
1673 type = make_qualified_type (newtype,
1674 TYPE_INSTANCE_FLAGS (type),
1675 type);
ad766c0a
JB
1676 else
1677 type = newtype;
1678 }
c906108c 1679 }
7ba81444
MS
1680 /* Otherwise, rely on the stub flag being set for opaque/stubbed
1681 types. */
74a9bb82 1682 else if (TYPE_STUB (type) && !currently_reading_symtab)
c906108c 1683 {
0d5cff50 1684 const char *name = type_name_no_tag (type);
c906108c 1685 /* FIXME: shouldn't we separately check the TYPE_NAME and the
176620f1 1686 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
7b83ea04
AC
1687 as appropriate? (this code was written before TYPE_NAME and
1688 TYPE_TAG_NAME were separate). */
c906108c 1689 struct symbol *sym;
d8734c88 1690
c906108c
SS
1691 if (name == NULL)
1692 {
23136709 1693 stub_noname_complaint ();
92163a10 1694 return make_qualified_type (type, instance_flags, NULL);
c906108c 1695 }
2570f2b7 1696 sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0);
c906108c 1697 if (sym)
c26f2453
JB
1698 {
1699 /* Same as above for opaque types, we can replace the stub
92163a10 1700 with the complete type only if they are in the same
c26f2453
JB
1701 objfile. */
1702 if (TYPE_OBJFILE (SYMBOL_TYPE(sym)) == TYPE_OBJFILE (type))
92163a10
JK
1703 type = make_qualified_type (SYMBOL_TYPE (sym),
1704 TYPE_INSTANCE_FLAGS (type),
1705 type);
c26f2453
JB
1706 else
1707 type = SYMBOL_TYPE (sym);
1708 }
c906108c
SS
1709 }
1710
74a9bb82 1711 if (TYPE_TARGET_STUB (type))
c906108c
SS
1712 {
1713 struct type *range_type;
1714 struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
1715
74a9bb82 1716 if (TYPE_STUB (target_type) || TYPE_TARGET_STUB (target_type))
c5aa993b 1717 {
73e2eb35 1718 /* Nothing we can do. */
c5aa993b 1719 }
c906108c
SS
1720 else if (TYPE_CODE (type) == TYPE_CODE_ARRAY
1721 && TYPE_NFIELDS (type) == 1
262452ec 1722 && (TYPE_CODE (range_type = TYPE_INDEX_TYPE (type))
c906108c
SS
1723 == TYPE_CODE_RANGE))
1724 {
1725 /* Now recompute the length of the array type, based on its
ab0d6e0d
JB
1726 number of elements and the target type's length.
1727 Watch out for Ada null Ada arrays where the high bound
0963b4bd 1728 is smaller than the low bound. */
43bbcdc2
PH
1729 const LONGEST low_bound = TYPE_LOW_BOUND (range_type);
1730 const LONGEST high_bound = TYPE_HIGH_BOUND (range_type);
1731 ULONGEST len;
1732
ab0d6e0d 1733 if (high_bound < low_bound)
43bbcdc2 1734 len = 0;
d8734c88
MS
1735 else
1736 {
1737 /* For now, we conservatively take the array length to be 0
1738 if its length exceeds UINT_MAX. The code below assumes
1739 that for x < 0, (ULONGEST) x == -x + ULONGEST_MAX + 1,
1740 which is technically not guaranteed by C, but is usually true
1741 (because it would be true if x were unsigned with its
0963b4bd 1742 high-order bit on). It uses the fact that
d8734c88
MS
1743 high_bound-low_bound is always representable in
1744 ULONGEST and that if high_bound-low_bound+1 overflows,
1745 it overflows to 0. We must change these tests if we
1746 decide to increase the representation of TYPE_LENGTH
0963b4bd 1747 from unsigned int to ULONGEST. */
d8734c88
MS
1748 ULONGEST ulow = low_bound, uhigh = high_bound;
1749 ULONGEST tlen = TYPE_LENGTH (target_type);
1750
1751 len = tlen * (uhigh - ulow + 1);
1752 if (tlen == 0 || (len / tlen - 1 + ulow) != uhigh
1753 || len > UINT_MAX)
1754 len = 0;
1755 }
43bbcdc2 1756 TYPE_LENGTH (type) = len;
876cecd0 1757 TYPE_TARGET_STUB (type) = 0;
c906108c
SS
1758 }
1759 else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
1760 {
1761 TYPE_LENGTH (type) = TYPE_LENGTH (target_type);
876cecd0 1762 TYPE_TARGET_STUB (type) = 0;
c906108c
SS
1763 }
1764 }
92163a10
JK
1765
1766 type = make_qualified_type (type, instance_flags, NULL);
1767
7ba81444 1768 /* Cache TYPE_LENGTH for future use. */
c906108c 1769 TYPE_LENGTH (orig_type) = TYPE_LENGTH (type);
92163a10 1770
c906108c
SS
1771 return type;
1772}
1773
7ba81444 1774/* Parse a type expression in the string [P..P+LENGTH). If an error
48319d1f 1775 occurs, silently return a void type. */
c91ecb25 1776
b9362cc7 1777static struct type *
48319d1f 1778safe_parse_type (struct gdbarch *gdbarch, char *p, int length)
c91ecb25
ND
1779{
1780 struct ui_file *saved_gdb_stderr;
34365054 1781 struct type *type = NULL; /* Initialize to keep gcc happy. */
8e7b59a5 1782 volatile struct gdb_exception except;
c91ecb25 1783
7ba81444 1784 /* Suppress error messages. */
c91ecb25
ND
1785 saved_gdb_stderr = gdb_stderr;
1786 gdb_stderr = ui_file_new ();
1787
7ba81444 1788 /* Call parse_and_eval_type() without fear of longjmp()s. */
8e7b59a5
KS
1789 TRY_CATCH (except, RETURN_MASK_ERROR)
1790 {
1791 type = parse_and_eval_type (p, length);
1792 }
1793
1794 if (except.reason < 0)
48319d1f 1795 type = builtin_type (gdbarch)->builtin_void;
c91ecb25 1796
7ba81444 1797 /* Stop suppressing error messages. */
c91ecb25
ND
1798 ui_file_delete (gdb_stderr);
1799 gdb_stderr = saved_gdb_stderr;
1800
1801 return type;
1802}
1803
c906108c
SS
1804/* Ugly hack to convert method stubs into method types.
1805
7ba81444
MS
1806 He ain't kiddin'. This demangles the name of the method into a
1807 string including argument types, parses out each argument type,
1808 generates a string casting a zero to that type, evaluates the
1809 string, and stuffs the resulting type into an argtype vector!!!
1810 Then it knows the type of the whole function (including argument
1811 types for overloading), which info used to be in the stab's but was
1812 removed to hack back the space required for them. */
c906108c 1813
de17c821 1814static void
fba45db2 1815check_stub_method (struct type *type, int method_id, int signature_id)
c906108c 1816{
50810684 1817 struct gdbarch *gdbarch = get_type_arch (type);
c906108c
SS
1818 struct fn_field *f;
1819 char *mangled_name = gdb_mangle_name (type, method_id, signature_id);
8de20a37
TT
1820 char *demangled_name = gdb_demangle (mangled_name,
1821 DMGL_PARAMS | DMGL_ANSI);
c906108c
SS
1822 char *argtypetext, *p;
1823 int depth = 0, argcount = 1;
ad2f7632 1824 struct field *argtypes;
c906108c
SS
1825 struct type *mtype;
1826
1827 /* Make sure we got back a function string that we can use. */
1828 if (demangled_name)
1829 p = strchr (demangled_name, '(');
502dcf4e
AC
1830 else
1831 p = NULL;
c906108c
SS
1832
1833 if (demangled_name == NULL || p == NULL)
7ba81444
MS
1834 error (_("Internal: Cannot demangle mangled name `%s'."),
1835 mangled_name);
c906108c
SS
1836
1837 /* Now, read in the parameters that define this type. */
1838 p += 1;
1839 argtypetext = p;
1840 while (*p)
1841 {
070ad9f0 1842 if (*p == '(' || *p == '<')
c906108c
SS
1843 {
1844 depth += 1;
1845 }
070ad9f0 1846 else if (*p == ')' || *p == '>')
c906108c
SS
1847 {
1848 depth -= 1;
1849 }
1850 else if (*p == ',' && depth == 0)
1851 {
1852 argcount += 1;
1853 }
1854
1855 p += 1;
1856 }
1857
ad2f7632
DJ
1858 /* If we read one argument and it was ``void'', don't count it. */
1859 if (strncmp (argtypetext, "(void)", 6) == 0)
1860 argcount -= 1;
c906108c 1861
ad2f7632
DJ
1862 /* We need one extra slot, for the THIS pointer. */
1863
1864 argtypes = (struct field *)
1865 TYPE_ALLOC (type, (argcount + 1) * sizeof (struct field));
c906108c 1866 p = argtypetext;
4a1970e4
DJ
1867
1868 /* Add THIS pointer for non-static methods. */
1869 f = TYPE_FN_FIELDLIST1 (type, method_id);
1870 if (TYPE_FN_FIELD_STATIC_P (f, signature_id))
1871 argcount = 0;
1872 else
1873 {
ad2f7632 1874 argtypes[0].type = lookup_pointer_type (type);
4a1970e4
DJ
1875 argcount = 1;
1876 }
c906108c 1877
0963b4bd 1878 if (*p != ')') /* () means no args, skip while. */
c906108c
SS
1879 {
1880 depth = 0;
1881 while (*p)
1882 {
1883 if (depth <= 0 && (*p == ',' || *p == ')'))
1884 {
ad2f7632
DJ
1885 /* Avoid parsing of ellipsis, they will be handled below.
1886 Also avoid ``void'' as above. */
1887 if (strncmp (argtypetext, "...", p - argtypetext) != 0
1888 && strncmp (argtypetext, "void", p - argtypetext) != 0)
c906108c 1889 {
ad2f7632 1890 argtypes[argcount].type =
48319d1f 1891 safe_parse_type (gdbarch, argtypetext, p - argtypetext);
c906108c
SS
1892 argcount += 1;
1893 }
1894 argtypetext = p + 1;
1895 }
1896
070ad9f0 1897 if (*p == '(' || *p == '<')
c906108c
SS
1898 {
1899 depth += 1;
1900 }
070ad9f0 1901 else if (*p == ')' || *p == '>')
c906108c
SS
1902 {
1903 depth -= 1;
1904 }
1905
1906 p += 1;
1907 }
1908 }
1909
c906108c
SS
1910 TYPE_FN_FIELD_PHYSNAME (f, signature_id) = mangled_name;
1911
1912 /* Now update the old "stub" type into a real type. */
1913 mtype = TYPE_FN_FIELD_TYPE (f, signature_id);
1914 TYPE_DOMAIN_TYPE (mtype) = type;
ad2f7632
DJ
1915 TYPE_FIELDS (mtype) = argtypes;
1916 TYPE_NFIELDS (mtype) = argcount;
876cecd0 1917 TYPE_STUB (mtype) = 0;
c906108c 1918 TYPE_FN_FIELD_STUB (f, signature_id) = 0;
ad2f7632 1919 if (p[-2] == '.')
876cecd0 1920 TYPE_VARARGS (mtype) = 1;
ad2f7632
DJ
1921
1922 xfree (demangled_name);
c906108c
SS
1923}
1924
7ba81444
MS
1925/* This is the external interface to check_stub_method, above. This
1926 function unstubs all of the signatures for TYPE's METHOD_ID method
1927 name. After calling this function TYPE_FN_FIELD_STUB will be
1928 cleared for each signature and TYPE_FN_FIELDLIST_NAME will be
1929 correct.
de17c821
DJ
1930
1931 This function unfortunately can not die until stabs do. */
1932
1933void
1934check_stub_method_group (struct type *type, int method_id)
1935{
1936 int len = TYPE_FN_FIELDLIST_LENGTH (type, method_id);
1937 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, method_id);
f710f4fc 1938 int j, found_stub = 0;
de17c821
DJ
1939
1940 for (j = 0; j < len; j++)
1941 if (TYPE_FN_FIELD_STUB (f, j))
1942 {
1943 found_stub = 1;
1944 check_stub_method (type, method_id, j);
1945 }
1946
7ba81444
MS
1947 /* GNU v3 methods with incorrect names were corrected when we read
1948 in type information, because it was cheaper to do it then. The
1949 only GNU v2 methods with incorrect method names are operators and
1950 destructors; destructors were also corrected when we read in type
1951 information.
de17c821
DJ
1952
1953 Therefore the only thing we need to handle here are v2 operator
1954 names. */
1955 if (found_stub && strncmp (TYPE_FN_FIELD_PHYSNAME (f, 0), "_Z", 2) != 0)
1956 {
1957 int ret;
1958 char dem_opname[256];
1959
7ba81444
MS
1960 ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type,
1961 method_id),
de17c821
DJ
1962 dem_opname, DMGL_ANSI);
1963 if (!ret)
7ba81444
MS
1964 ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type,
1965 method_id),
de17c821
DJ
1966 dem_opname, 0);
1967 if (ret)
1968 TYPE_FN_FIELDLIST_NAME (type, method_id) = xstrdup (dem_opname);
1969 }
1970}
1971
9655fd1a
JK
1972/* Ensure it is in .rodata (if available) by workarounding GCC PR 44690. */
1973const struct cplus_struct_type cplus_struct_default = { };
c906108c
SS
1974
1975void
fba45db2 1976allocate_cplus_struct_type (struct type *type)
c906108c 1977{
b4ba55a1
JB
1978 if (HAVE_CPLUS_STRUCT (type))
1979 /* Structure was already allocated. Nothing more to do. */
1980 return;
1981
1982 TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_CPLUS_STUFF;
1983 TYPE_RAW_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *)
1984 TYPE_ALLOC (type, sizeof (struct cplus_struct_type));
1985 *(TYPE_RAW_CPLUS_SPECIFIC (type)) = cplus_struct_default;
c906108c
SS
1986}
1987
b4ba55a1
JB
1988const struct gnat_aux_type gnat_aux_default =
1989 { NULL };
1990
1991/* Set the TYPE's type-specific kind to TYPE_SPECIFIC_GNAT_STUFF,
1992 and allocate the associated gnat-specific data. The gnat-specific
1993 data is also initialized to gnat_aux_default. */
5212577a 1994
b4ba55a1
JB
1995void
1996allocate_gnat_aux_type (struct type *type)
1997{
1998 TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_GNAT_STUFF;
1999 TYPE_GNAT_SPECIFIC (type) = (struct gnat_aux_type *)
2000 TYPE_ALLOC (type, sizeof (struct gnat_aux_type));
2001 *(TYPE_GNAT_SPECIFIC (type)) = gnat_aux_default;
2002}
2003
c906108c
SS
2004/* Helper function to initialize the standard scalar types.
2005
86f62fd7
TT
2006 If NAME is non-NULL, then it is used to initialize the type name.
2007 Note that NAME is not copied; it is required to have a lifetime at
2008 least as long as OBJFILE. */
c906108c
SS
2009
2010struct type *
7ba81444 2011init_type (enum type_code code, int length, int flags,
748e18ae 2012 const char *name, struct objfile *objfile)
c906108c 2013{
52f0bd74 2014 struct type *type;
c906108c
SS
2015
2016 type = alloc_type (objfile);
2017 TYPE_CODE (type) = code;
2018 TYPE_LENGTH (type) = length;
876cecd0
TT
2019
2020 gdb_assert (!(flags & (TYPE_FLAG_MIN - 1)));
2021 if (flags & TYPE_FLAG_UNSIGNED)
2022 TYPE_UNSIGNED (type) = 1;
2023 if (flags & TYPE_FLAG_NOSIGN)
2024 TYPE_NOSIGN (type) = 1;
2025 if (flags & TYPE_FLAG_STUB)
2026 TYPE_STUB (type) = 1;
2027 if (flags & TYPE_FLAG_TARGET_STUB)
2028 TYPE_TARGET_STUB (type) = 1;
2029 if (flags & TYPE_FLAG_STATIC)
2030 TYPE_STATIC (type) = 1;
2031 if (flags & TYPE_FLAG_PROTOTYPED)
2032 TYPE_PROTOTYPED (type) = 1;
2033 if (flags & TYPE_FLAG_INCOMPLETE)
2034 TYPE_INCOMPLETE (type) = 1;
2035 if (flags & TYPE_FLAG_VARARGS)
2036 TYPE_VARARGS (type) = 1;
2037 if (flags & TYPE_FLAG_VECTOR)
2038 TYPE_VECTOR (type) = 1;
2039 if (flags & TYPE_FLAG_STUB_SUPPORTED)
2040 TYPE_STUB_SUPPORTED (type) = 1;
876cecd0
TT
2041 if (flags & TYPE_FLAG_FIXED_INSTANCE)
2042 TYPE_FIXED_INSTANCE (type) = 1;
0875794a
JK
2043 if (flags & TYPE_FLAG_GNU_IFUNC)
2044 TYPE_GNU_IFUNC (type) = 1;
876cecd0 2045
86f62fd7 2046 TYPE_NAME (type) = name;
c906108c
SS
2047
2048 /* C++ fancies. */
2049
973ccf8b 2050 if (name && strcmp (name, "char") == 0)
876cecd0 2051 TYPE_NOSIGN (type) = 1;
973ccf8b 2052
b4ba55a1 2053 switch (code)
c906108c 2054 {
b4ba55a1
JB
2055 case TYPE_CODE_STRUCT:
2056 case TYPE_CODE_UNION:
2057 case TYPE_CODE_NAMESPACE:
2058 INIT_CPLUS_SPECIFIC (type);
2059 break;
2060 case TYPE_CODE_FLT:
2061 TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_FLOATFORMAT;
2062 break;
2063 case TYPE_CODE_FUNC:
b6cdc2c1 2064 INIT_FUNC_SPECIFIC (type);
b4ba55a1 2065 break;
c906108c 2066 }
c16abbde 2067 return type;
c906108c 2068}
5212577a
DE
2069\f
2070/* Queries on types. */
c906108c 2071
c906108c 2072int
fba45db2 2073can_dereference (struct type *t)
c906108c 2074{
7ba81444
MS
2075 /* FIXME: Should we return true for references as well as
2076 pointers? */
c906108c
SS
2077 CHECK_TYPEDEF (t);
2078 return
2079 (t != NULL
2080 && TYPE_CODE (t) == TYPE_CODE_PTR
2081 && TYPE_CODE (TYPE_TARGET_TYPE (t)) != TYPE_CODE_VOID);
2082}
2083
adf40b2e 2084int
fba45db2 2085is_integral_type (struct type *t)
adf40b2e
JM
2086{
2087 CHECK_TYPEDEF (t);
2088 return
2089 ((t != NULL)
d4f3574e
SS
2090 && ((TYPE_CODE (t) == TYPE_CODE_INT)
2091 || (TYPE_CODE (t) == TYPE_CODE_ENUM)
4f2aea11 2092 || (TYPE_CODE (t) == TYPE_CODE_FLAGS)
d4f3574e
SS
2093 || (TYPE_CODE (t) == TYPE_CODE_CHAR)
2094 || (TYPE_CODE (t) == TYPE_CODE_RANGE)
2095 || (TYPE_CODE (t) == TYPE_CODE_BOOL)));
adf40b2e
JM
2096}
2097
e09342b5
TJB
2098/* Return true if TYPE is scalar. */
2099
2100static int
2101is_scalar_type (struct type *type)
2102{
2103 CHECK_TYPEDEF (type);
2104
2105 switch (TYPE_CODE (type))
2106 {
2107 case TYPE_CODE_ARRAY:
2108 case TYPE_CODE_STRUCT:
2109 case TYPE_CODE_UNION:
2110 case TYPE_CODE_SET:
2111 case TYPE_CODE_STRING:
e09342b5
TJB
2112 return 0;
2113 default:
2114 return 1;
2115 }
2116}
2117
2118/* Return true if T is scalar, or a composite type which in practice has
90e4670f
TJB
2119 the memory layout of a scalar type. E.g., an array or struct with only
2120 one scalar element inside it, or a union with only scalar elements. */
e09342b5
TJB
2121
2122int
2123is_scalar_type_recursive (struct type *t)
2124{
2125 CHECK_TYPEDEF (t);
2126
2127 if (is_scalar_type (t))
2128 return 1;
2129 /* Are we dealing with an array or string of known dimensions? */
2130 else if ((TYPE_CODE (t) == TYPE_CODE_ARRAY
2131 || TYPE_CODE (t) == TYPE_CODE_STRING) && TYPE_NFIELDS (t) == 1
2132 && TYPE_CODE (TYPE_INDEX_TYPE (t)) == TYPE_CODE_RANGE)
2133 {
2134 LONGEST low_bound, high_bound;
2135 struct type *elt_type = check_typedef (TYPE_TARGET_TYPE (t));
2136
2137 get_discrete_bounds (TYPE_INDEX_TYPE (t), &low_bound, &high_bound);
2138
2139 return high_bound == low_bound && is_scalar_type_recursive (elt_type);
2140 }
2141 /* Are we dealing with a struct with one element? */
2142 else if (TYPE_CODE (t) == TYPE_CODE_STRUCT && TYPE_NFIELDS (t) == 1)
2143 return is_scalar_type_recursive (TYPE_FIELD_TYPE (t, 0));
2144 else if (TYPE_CODE (t) == TYPE_CODE_UNION)
2145 {
2146 int i, n = TYPE_NFIELDS (t);
2147
2148 /* If all elements of the union are scalar, then the union is scalar. */
2149 for (i = 0; i < n; i++)
2150 if (!is_scalar_type_recursive (TYPE_FIELD_TYPE (t, i)))
2151 return 0;
2152
2153 return 1;
2154 }
2155
2156 return 0;
2157}
2158
4e8f195d
TT
2159/* A helper function which returns true if types A and B represent the
2160 "same" class type. This is true if the types have the same main
2161 type, or the same name. */
2162
2163int
2164class_types_same_p (const struct type *a, const struct type *b)
2165{
2166 return (TYPE_MAIN_TYPE (a) == TYPE_MAIN_TYPE (b)
2167 || (TYPE_NAME (a) && TYPE_NAME (b)
2168 && !strcmp (TYPE_NAME (a), TYPE_NAME (b))));
2169}
2170
a9d5ef47
SW
2171/* If BASE is an ancestor of DCLASS return the distance between them.
2172 otherwise return -1;
2173 eg:
2174
2175 class A {};
2176 class B: public A {};
2177 class C: public B {};
2178 class D: C {};
2179
2180 distance_to_ancestor (A, A, 0) = 0
2181 distance_to_ancestor (A, B, 0) = 1
2182 distance_to_ancestor (A, C, 0) = 2
2183 distance_to_ancestor (A, D, 0) = 3
2184
2185 If PUBLIC is 1 then only public ancestors are considered,
2186 and the function returns the distance only if BASE is a public ancestor
2187 of DCLASS.
2188 Eg:
2189
0963b4bd 2190 distance_to_ancestor (A, D, 1) = -1. */
c906108c 2191
0526b37a 2192static int
a9d5ef47 2193distance_to_ancestor (struct type *base, struct type *dclass, int public)
c906108c
SS
2194{
2195 int i;
a9d5ef47 2196 int d;
c5aa993b 2197
c906108c
SS
2198 CHECK_TYPEDEF (base);
2199 CHECK_TYPEDEF (dclass);
2200
4e8f195d 2201 if (class_types_same_p (base, dclass))
a9d5ef47 2202 return 0;
c906108c
SS
2203
2204 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
4e8f195d 2205 {
0526b37a
SW
2206 if (public && ! BASETYPE_VIA_PUBLIC (dclass, i))
2207 continue;
2208
a9d5ef47
SW
2209 d = distance_to_ancestor (base, TYPE_BASECLASS (dclass, i), public);
2210 if (d >= 0)
2211 return 1 + d;
4e8f195d 2212 }
c906108c 2213
a9d5ef47 2214 return -1;
c906108c 2215}
4e8f195d 2216
0526b37a
SW
2217/* Check whether BASE is an ancestor or base class or DCLASS
2218 Return 1 if so, and 0 if not.
2219 Note: If BASE and DCLASS are of the same type, this function
2220 will return 1. So for some class A, is_ancestor (A, A) will
2221 return 1. */
2222
2223int
2224is_ancestor (struct type *base, struct type *dclass)
2225{
a9d5ef47 2226 return distance_to_ancestor (base, dclass, 0) >= 0;
0526b37a
SW
2227}
2228
4e8f195d
TT
2229/* Like is_ancestor, but only returns true when BASE is a public
2230 ancestor of DCLASS. */
2231
2232int
2233is_public_ancestor (struct type *base, struct type *dclass)
2234{
a9d5ef47 2235 return distance_to_ancestor (base, dclass, 1) >= 0;
4e8f195d
TT
2236}
2237
2238/* A helper function for is_unique_ancestor. */
2239
2240static int
2241is_unique_ancestor_worker (struct type *base, struct type *dclass,
2242 int *offset,
8af8e3bc
PA
2243 const gdb_byte *valaddr, int embedded_offset,
2244 CORE_ADDR address, struct value *val)
4e8f195d
TT
2245{
2246 int i, count = 0;
2247
2248 CHECK_TYPEDEF (base);
2249 CHECK_TYPEDEF (dclass);
2250
2251 for (i = 0; i < TYPE_N_BASECLASSES (dclass) && count < 2; ++i)
2252 {
8af8e3bc
PA
2253 struct type *iter;
2254 int this_offset;
4e8f195d 2255
8af8e3bc
PA
2256 iter = check_typedef (TYPE_BASECLASS (dclass, i));
2257
2258 this_offset = baseclass_offset (dclass, i, valaddr, embedded_offset,
2259 address, val);
4e8f195d
TT
2260
2261 if (class_types_same_p (base, iter))
2262 {
2263 /* If this is the first subclass, set *OFFSET and set count
2264 to 1. Otherwise, if this is at the same offset as
2265 previous instances, do nothing. Otherwise, increment
2266 count. */
2267 if (*offset == -1)
2268 {
2269 *offset = this_offset;
2270 count = 1;
2271 }
2272 else if (this_offset == *offset)
2273 {
2274 /* Nothing. */
2275 }
2276 else
2277 ++count;
2278 }
2279 else
2280 count += is_unique_ancestor_worker (base, iter, offset,
8af8e3bc
PA
2281 valaddr,
2282 embedded_offset + this_offset,
2283 address, val);
4e8f195d
TT
2284 }
2285
2286 return count;
2287}
2288
2289/* Like is_ancestor, but only returns true if BASE is a unique base
2290 class of the type of VAL. */
2291
2292int
2293is_unique_ancestor (struct type *base, struct value *val)
2294{
2295 int offset = -1;
2296
2297 return is_unique_ancestor_worker (base, value_type (val), &offset,
8af8e3bc
PA
2298 value_contents_for_printing (val),
2299 value_embedded_offset (val),
2300 value_address (val), val) == 1;
4e8f195d
TT
2301}
2302
c906108c 2303\f
5212577a 2304/* Overload resolution. */
c906108c 2305
6403aeea
SW
2306/* Return the sum of the rank of A with the rank of B. */
2307
2308struct rank
2309sum_ranks (struct rank a, struct rank b)
2310{
2311 struct rank c;
2312 c.rank = a.rank + b.rank;
a9d5ef47 2313 c.subrank = a.subrank + b.subrank;
6403aeea
SW
2314 return c;
2315}
2316
2317/* Compare rank A and B and return:
2318 0 if a = b
2319 1 if a is better than b
2320 -1 if b is better than a. */
2321
2322int
2323compare_ranks (struct rank a, struct rank b)
2324{
2325 if (a.rank == b.rank)
a9d5ef47
SW
2326 {
2327 if (a.subrank == b.subrank)
2328 return 0;
2329 if (a.subrank < b.subrank)
2330 return 1;
2331 if (a.subrank > b.subrank)
2332 return -1;
2333 }
6403aeea
SW
2334
2335 if (a.rank < b.rank)
2336 return 1;
2337
0963b4bd 2338 /* a.rank > b.rank */
6403aeea
SW
2339 return -1;
2340}
c5aa993b 2341
0963b4bd 2342/* Functions for overload resolution begin here. */
c906108c
SS
2343
2344/* Compare two badness vectors A and B and return the result.
7ba81444
MS
2345 0 => A and B are identical
2346 1 => A and B are incomparable
2347 2 => A is better than B
2348 3 => A is worse than B */
c906108c
SS
2349
2350int
fba45db2 2351compare_badness (struct badness_vector *a, struct badness_vector *b)
c906108c
SS
2352{
2353 int i;
2354 int tmp;
c5aa993b
JM
2355 short found_pos = 0; /* any positives in c? */
2356 short found_neg = 0; /* any negatives in c? */
2357
2358 /* differing lengths => incomparable */
c906108c
SS
2359 if (a->length != b->length)
2360 return 1;
2361
c5aa993b
JM
2362 /* Subtract b from a */
2363 for (i = 0; i < a->length; i++)
c906108c 2364 {
6403aeea 2365 tmp = compare_ranks (b->rank[i], a->rank[i]);
c906108c 2366 if (tmp > 0)
c5aa993b 2367 found_pos = 1;
c906108c 2368 else if (tmp < 0)
c5aa993b 2369 found_neg = 1;
c906108c
SS
2370 }
2371
2372 if (found_pos)
2373 {
2374 if (found_neg)
c5aa993b 2375 return 1; /* incomparable */
c906108c 2376 else
c5aa993b 2377 return 3; /* A > B */
c906108c 2378 }
c5aa993b
JM
2379 else
2380 /* no positives */
c906108c
SS
2381 {
2382 if (found_neg)
c5aa993b 2383 return 2; /* A < B */
c906108c 2384 else
c5aa993b 2385 return 0; /* A == B */
c906108c
SS
2386 }
2387}
2388
7ba81444
MS
2389/* Rank a function by comparing its parameter types (PARMS, length
2390 NPARMS), to the types of an argument list (ARGS, length NARGS).
2391 Return a pointer to a badness vector. This has NARGS + 1
2392 entries. */
c906108c
SS
2393
2394struct badness_vector *
7ba81444 2395rank_function (struct type **parms, int nparms,
da096638 2396 struct value **args, int nargs)
c906108c
SS
2397{
2398 int i;
c5aa993b 2399 struct badness_vector *bv;
c906108c
SS
2400 int min_len = nparms < nargs ? nparms : nargs;
2401
2402 bv = xmalloc (sizeof (struct badness_vector));
0963b4bd 2403 bv->length = nargs + 1; /* add 1 for the length-match rank. */
c906108c
SS
2404 bv->rank = xmalloc ((nargs + 1) * sizeof (int));
2405
2406 /* First compare the lengths of the supplied lists.
7ba81444 2407 If there is a mismatch, set it to a high value. */
c5aa993b 2408
c906108c 2409 /* pai/1997-06-03 FIXME: when we have debug info about default
7ba81444
MS
2410 arguments and ellipsis parameter lists, we should consider those
2411 and rank the length-match more finely. */
c906108c 2412
6403aeea
SW
2413 LENGTH_MATCH (bv) = (nargs != nparms)
2414 ? LENGTH_MISMATCH_BADNESS
2415 : EXACT_MATCH_BADNESS;
c906108c 2416
0963b4bd 2417 /* Now rank all the parameters of the candidate function. */
74cc24b0 2418 for (i = 1; i <= min_len; i++)
da096638
KS
2419 bv->rank[i] = rank_one_type (parms[i - 1], value_type (args[i - 1]),
2420 args[i - 1]);
c906108c 2421
0963b4bd 2422 /* If more arguments than parameters, add dummy entries. */
c5aa993b 2423 for (i = min_len + 1; i <= nargs; i++)
c906108c
SS
2424 bv->rank[i] = TOO_FEW_PARAMS_BADNESS;
2425
2426 return bv;
2427}
2428
973ccf8b
DJ
2429/* Compare the names of two integer types, assuming that any sign
2430 qualifiers have been checked already. We do it this way because
2431 there may be an "int" in the name of one of the types. */
2432
2433static int
2434integer_types_same_name_p (const char *first, const char *second)
2435{
2436 int first_p, second_p;
2437
7ba81444
MS
2438 /* If both are shorts, return 1; if neither is a short, keep
2439 checking. */
973ccf8b
DJ
2440 first_p = (strstr (first, "short") != NULL);
2441 second_p = (strstr (second, "short") != NULL);
2442 if (first_p && second_p)
2443 return 1;
2444 if (first_p || second_p)
2445 return 0;
2446
2447 /* Likewise for long. */
2448 first_p = (strstr (first, "long") != NULL);
2449 second_p = (strstr (second, "long") != NULL);
2450 if (first_p && second_p)
2451 return 1;
2452 if (first_p || second_p)
2453 return 0;
2454
2455 /* Likewise for char. */
2456 first_p = (strstr (first, "char") != NULL);
2457 second_p = (strstr (second, "char") != NULL);
2458 if (first_p && second_p)
2459 return 1;
2460 if (first_p || second_p)
2461 return 0;
2462
2463 /* They must both be ints. */
2464 return 1;
2465}
2466
7062b0a0
SW
2467/* Compares type A to type B returns 1 if the represent the same type
2468 0 otherwise. */
2469
bd69fc68 2470int
7062b0a0
SW
2471types_equal (struct type *a, struct type *b)
2472{
2473 /* Identical type pointers. */
2474 /* However, this still doesn't catch all cases of same type for b
2475 and a. The reason is that builtin types are different from
2476 the same ones constructed from the object. */
2477 if (a == b)
2478 return 1;
2479
2480 /* Resolve typedefs */
2481 if (TYPE_CODE (a) == TYPE_CODE_TYPEDEF)
2482 a = check_typedef (a);
2483 if (TYPE_CODE (b) == TYPE_CODE_TYPEDEF)
2484 b = check_typedef (b);
2485
2486 /* If after resolving typedefs a and b are not of the same type
2487 code then they are not equal. */
2488 if (TYPE_CODE (a) != TYPE_CODE (b))
2489 return 0;
2490
2491 /* If a and b are both pointers types or both reference types then
2492 they are equal of the same type iff the objects they refer to are
2493 of the same type. */
2494 if (TYPE_CODE (a) == TYPE_CODE_PTR
2495 || TYPE_CODE (a) == TYPE_CODE_REF)
2496 return types_equal (TYPE_TARGET_TYPE (a),
2497 TYPE_TARGET_TYPE (b));
2498
0963b4bd 2499 /* Well, damnit, if the names are exactly the same, I'll say they
7062b0a0
SW
2500 are exactly the same. This happens when we generate method
2501 stubs. The types won't point to the same address, but they
0963b4bd 2502 really are the same. */
7062b0a0
SW
2503
2504 if (TYPE_NAME (a) && TYPE_NAME (b)
2505 && strcmp (TYPE_NAME (a), TYPE_NAME (b)) == 0)
2506 return 1;
2507
2508 /* Check if identical after resolving typedefs. */
2509 if (a == b)
2510 return 1;
2511
9ce98649
TT
2512 /* Two function types are equal if their argument and return types
2513 are equal. */
2514 if (TYPE_CODE (a) == TYPE_CODE_FUNC)
2515 {
2516 int i;
2517
2518 if (TYPE_NFIELDS (a) != TYPE_NFIELDS (b))
2519 return 0;
2520
2521 if (!types_equal (TYPE_TARGET_TYPE (a), TYPE_TARGET_TYPE (b)))
2522 return 0;
2523
2524 for (i = 0; i < TYPE_NFIELDS (a); ++i)
2525 if (!types_equal (TYPE_FIELD_TYPE (a, i), TYPE_FIELD_TYPE (b, i)))
2526 return 0;
2527
2528 return 1;
2529 }
2530
7062b0a0
SW
2531 return 0;
2532}
ca092b61
DE
2533\f
2534/* Deep comparison of types. */
2535
2536/* An entry in the type-equality bcache. */
2537
2538typedef struct type_equality_entry
2539{
2540 struct type *type1, *type2;
2541} type_equality_entry_d;
2542
2543DEF_VEC_O (type_equality_entry_d);
2544
2545/* A helper function to compare two strings. Returns 1 if they are
2546 the same, 0 otherwise. Handles NULLs properly. */
2547
2548static int
2549compare_maybe_null_strings (const char *s, const char *t)
2550{
2551 if (s == NULL && t != NULL)
2552 return 0;
2553 else if (s != NULL && t == NULL)
2554 return 0;
2555 else if (s == NULL && t== NULL)
2556 return 1;
2557 return strcmp (s, t) == 0;
2558}
2559
2560/* A helper function for check_types_worklist that checks two types for
2561 "deep" equality. Returns non-zero if the types are considered the
2562 same, zero otherwise. */
2563
2564static int
2565check_types_equal (struct type *type1, struct type *type2,
2566 VEC (type_equality_entry_d) **worklist)
2567{
2568 CHECK_TYPEDEF (type1);
2569 CHECK_TYPEDEF (type2);
2570
2571 if (type1 == type2)
2572 return 1;
2573
2574 if (TYPE_CODE (type1) != TYPE_CODE (type2)
2575 || TYPE_LENGTH (type1) != TYPE_LENGTH (type2)
2576 || TYPE_UNSIGNED (type1) != TYPE_UNSIGNED (type2)
2577 || TYPE_NOSIGN (type1) != TYPE_NOSIGN (type2)
2578 || TYPE_VARARGS (type1) != TYPE_VARARGS (type2)
2579 || TYPE_VECTOR (type1) != TYPE_VECTOR (type2)
2580 || TYPE_NOTTEXT (type1) != TYPE_NOTTEXT (type2)
2581 || TYPE_INSTANCE_FLAGS (type1) != TYPE_INSTANCE_FLAGS (type2)
2582 || TYPE_NFIELDS (type1) != TYPE_NFIELDS (type2))
2583 return 0;
2584
2585 if (!compare_maybe_null_strings (TYPE_TAG_NAME (type1),
2586 TYPE_TAG_NAME (type2)))
2587 return 0;
2588 if (!compare_maybe_null_strings (TYPE_NAME (type1), TYPE_NAME (type2)))
2589 return 0;
2590
2591 if (TYPE_CODE (type1) == TYPE_CODE_RANGE)
2592 {
2593 if (memcmp (TYPE_RANGE_DATA (type1), TYPE_RANGE_DATA (type2),
2594 sizeof (*TYPE_RANGE_DATA (type1))) != 0)
2595 return 0;
2596 }
2597 else
2598 {
2599 int i;
2600
2601 for (i = 0; i < TYPE_NFIELDS (type1); ++i)
2602 {
2603 const struct field *field1 = &TYPE_FIELD (type1, i);
2604 const struct field *field2 = &TYPE_FIELD (type2, i);
2605 struct type_equality_entry entry;
2606
2607 if (FIELD_ARTIFICIAL (*field1) != FIELD_ARTIFICIAL (*field2)
2608 || FIELD_BITSIZE (*field1) != FIELD_BITSIZE (*field2)
2609 || FIELD_LOC_KIND (*field1) != FIELD_LOC_KIND (*field2))
2610 return 0;
2611 if (!compare_maybe_null_strings (FIELD_NAME (*field1),
2612 FIELD_NAME (*field2)))
2613 return 0;
2614 switch (FIELD_LOC_KIND (*field1))
2615 {
2616 case FIELD_LOC_KIND_BITPOS:
2617 if (FIELD_BITPOS (*field1) != FIELD_BITPOS (*field2))
2618 return 0;
2619 break;
2620 case FIELD_LOC_KIND_ENUMVAL:
2621 if (FIELD_ENUMVAL (*field1) != FIELD_ENUMVAL (*field2))
2622 return 0;
2623 break;
2624 case FIELD_LOC_KIND_PHYSADDR:
2625 if (FIELD_STATIC_PHYSADDR (*field1)
2626 != FIELD_STATIC_PHYSADDR (*field2))
2627 return 0;
2628 break;
2629 case FIELD_LOC_KIND_PHYSNAME:
2630 if (!compare_maybe_null_strings (FIELD_STATIC_PHYSNAME (*field1),
2631 FIELD_STATIC_PHYSNAME (*field2)))
2632 return 0;
2633 break;
2634 case FIELD_LOC_KIND_DWARF_BLOCK:
2635 {
2636 struct dwarf2_locexpr_baton *block1, *block2;
2637
2638 block1 = FIELD_DWARF_BLOCK (*field1);
2639 block2 = FIELD_DWARF_BLOCK (*field2);
2640 if (block1->per_cu != block2->per_cu
2641 || block1->size != block2->size
2642 || memcmp (block1->data, block2->data, block1->size) != 0)
2643 return 0;
2644 }
2645 break;
2646 default:
2647 internal_error (__FILE__, __LINE__, _("Unsupported field kind "
2648 "%d by check_types_equal"),
2649 FIELD_LOC_KIND (*field1));
2650 }
2651
2652 entry.type1 = FIELD_TYPE (*field1);
2653 entry.type2 = FIELD_TYPE (*field2);
2654 VEC_safe_push (type_equality_entry_d, *worklist, &entry);
2655 }
2656 }
2657
2658 if (TYPE_TARGET_TYPE (type1) != NULL)
2659 {
2660 struct type_equality_entry entry;
2661
2662 if (TYPE_TARGET_TYPE (type2) == NULL)
2663 return 0;
2664
2665 entry.type1 = TYPE_TARGET_TYPE (type1);
2666 entry.type2 = TYPE_TARGET_TYPE (type2);
2667 VEC_safe_push (type_equality_entry_d, *worklist, &entry);
2668 }
2669 else if (TYPE_TARGET_TYPE (type2) != NULL)
2670 return 0;
2671
2672 return 1;
2673}
2674
2675/* Check types on a worklist for equality. Returns zero if any pair
2676 is not equal, non-zero if they are all considered equal. */
2677
2678static int
2679check_types_worklist (VEC (type_equality_entry_d) **worklist,
2680 struct bcache *cache)
2681{
2682 while (!VEC_empty (type_equality_entry_d, *worklist))
2683 {
2684 struct type_equality_entry entry;
2685 int added;
2686
2687 entry = *VEC_last (type_equality_entry_d, *worklist);
2688 VEC_pop (type_equality_entry_d, *worklist);
2689
2690 /* If the type pair has already been visited, we know it is
2691 ok. */
2692 bcache_full (&entry, sizeof (entry), cache, &added);
2693 if (!added)
2694 continue;
2695
2696 if (check_types_equal (entry.type1, entry.type2, worklist) == 0)
2697 return 0;
2698 }
7062b0a0 2699
ca092b61
DE
2700 return 1;
2701}
2702
2703/* Return non-zero if types TYPE1 and TYPE2 are equal, as determined by a
2704 "deep comparison". Otherwise return zero. */
2705
2706int
2707types_deeply_equal (struct type *type1, struct type *type2)
2708{
2709 volatile struct gdb_exception except;
2710 int result = 0;
2711 struct bcache *cache;
2712 VEC (type_equality_entry_d) *worklist = NULL;
2713 struct type_equality_entry entry;
2714
2715 gdb_assert (type1 != NULL && type2 != NULL);
2716
2717 /* Early exit for the simple case. */
2718 if (type1 == type2)
2719 return 1;
2720
2721 cache = bcache_xmalloc (NULL, NULL);
2722
2723 entry.type1 = type1;
2724 entry.type2 = type2;
2725 VEC_safe_push (type_equality_entry_d, worklist, &entry);
2726
2727 TRY_CATCH (except, RETURN_MASK_ALL)
2728 {
2729 result = check_types_worklist (&worklist, cache);
2730 }
2731 /* check_types_worklist calls several nested helper functions,
2732 some of which can raise a GDB Exception, so we just check
2733 and rethrow here. If there is a GDB exception, a comparison
2734 is not capable (or trusted), so exit. */
2735 bcache_xfree (cache);
2736 VEC_free (type_equality_entry_d, worklist);
2737 /* Rethrow if there was a problem. */
2738 if (except.reason < 0)
2739 throw_exception (except);
2740
2741 return result;
2742}
2743\f
c906108c
SS
2744/* Compare one type (PARM) for compatibility with another (ARG).
2745 * PARM is intended to be the parameter type of a function; and
2746 * ARG is the supplied argument's type. This function tests if
2747 * the latter can be converted to the former.
da096638 2748 * VALUE is the argument's value or NULL if none (or called recursively)
c906108c
SS
2749 *
2750 * Return 0 if they are identical types;
2751 * Otherwise, return an integer which corresponds to how compatible
7ba81444
MS
2752 * PARM is to ARG. The higher the return value, the worse the match.
2753 * Generally the "bad" conversions are all uniformly assigned a 100. */
c906108c 2754
6403aeea 2755struct rank
da096638 2756rank_one_type (struct type *parm, struct type *arg, struct value *value)
c906108c 2757{
a9d5ef47 2758 struct rank rank = {0,0};
7062b0a0
SW
2759
2760 if (types_equal (parm, arg))
6403aeea 2761 return EXACT_MATCH_BADNESS;
c906108c
SS
2762
2763 /* Resolve typedefs */
2764 if (TYPE_CODE (parm) == TYPE_CODE_TYPEDEF)
2765 parm = check_typedef (parm);
2766 if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF)
2767 arg = check_typedef (arg);
2768
db577aea 2769 /* See through references, since we can almost make non-references
7ba81444 2770 references. */
db577aea 2771 if (TYPE_CODE (arg) == TYPE_CODE_REF)
da096638 2772 return (sum_ranks (rank_one_type (parm, TYPE_TARGET_TYPE (arg), NULL),
6403aeea 2773 REFERENCE_CONVERSION_BADNESS));
db577aea 2774 if (TYPE_CODE (parm) == TYPE_CODE_REF)
da096638 2775 return (sum_ranks (rank_one_type (TYPE_TARGET_TYPE (parm), arg, NULL),
6403aeea 2776 REFERENCE_CONVERSION_BADNESS));
5d161b24 2777 if (overload_debug)
7ba81444
MS
2778 /* Debugging only. */
2779 fprintf_filtered (gdb_stderr,
2780 "------ Arg is %s [%d], parm is %s [%d]\n",
2781 TYPE_NAME (arg), TYPE_CODE (arg),
2782 TYPE_NAME (parm), TYPE_CODE (parm));
c906108c 2783
0963b4bd 2784 /* x -> y means arg of type x being supplied for parameter of type y. */
c906108c
SS
2785
2786 switch (TYPE_CODE (parm))
2787 {
c5aa993b
JM
2788 case TYPE_CODE_PTR:
2789 switch (TYPE_CODE (arg))
2790 {
2791 case TYPE_CODE_PTR:
7062b0a0
SW
2792
2793 /* Allowed pointer conversions are:
2794 (a) pointer to void-pointer conversion. */
2795 if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID)
c5aa993b 2796 return VOID_PTR_CONVERSION_BADNESS;
7062b0a0
SW
2797
2798 /* (b) pointer to ancestor-pointer conversion. */
a9d5ef47
SW
2799 rank.subrank = distance_to_ancestor (TYPE_TARGET_TYPE (parm),
2800 TYPE_TARGET_TYPE (arg),
2801 0);
2802 if (rank.subrank >= 0)
2803 return sum_ranks (BASE_PTR_CONVERSION_BADNESS, rank);
7062b0a0
SW
2804
2805 return INCOMPATIBLE_TYPE_BADNESS;
c5aa993b 2806 case TYPE_CODE_ARRAY:
7062b0a0
SW
2807 if (types_equal (TYPE_TARGET_TYPE (parm),
2808 TYPE_TARGET_TYPE (arg)))
6403aeea 2809 return EXACT_MATCH_BADNESS;
7062b0a0 2810 return INCOMPATIBLE_TYPE_BADNESS;
c5aa993b 2811 case TYPE_CODE_FUNC:
da096638 2812 return rank_one_type (TYPE_TARGET_TYPE (parm), arg, NULL);
c5aa993b 2813 case TYPE_CODE_INT:
a451cb65 2814 if (value != NULL && TYPE_CODE (value_type (value)) == TYPE_CODE_INT)
da096638 2815 {
a451cb65
KS
2816 if (value_as_long (value) == 0)
2817 {
2818 /* Null pointer conversion: allow it to be cast to a pointer.
2819 [4.10.1 of C++ standard draft n3290] */
2820 return NULL_POINTER_CONVERSION_BADNESS;
2821 }
2822 else
2823 {
2824 /* If type checking is disabled, allow the conversion. */
2825 if (!strict_type_checking)
2826 return NS_INTEGER_POINTER_CONVERSION_BADNESS;
2827 }
da096638
KS
2828 }
2829 /* fall through */
c5aa993b 2830 case TYPE_CODE_ENUM:
4f2aea11 2831 case TYPE_CODE_FLAGS:
c5aa993b
JM
2832 case TYPE_CODE_CHAR:
2833 case TYPE_CODE_RANGE:
2834 case TYPE_CODE_BOOL:
c5aa993b
JM
2835 default:
2836 return INCOMPATIBLE_TYPE_BADNESS;
2837 }
2838 case TYPE_CODE_ARRAY:
2839 switch (TYPE_CODE (arg))
2840 {
2841 case TYPE_CODE_PTR:
2842 case TYPE_CODE_ARRAY:
7ba81444 2843 return rank_one_type (TYPE_TARGET_TYPE (parm),
da096638 2844 TYPE_TARGET_TYPE (arg), NULL);
c5aa993b
JM
2845 default:
2846 return INCOMPATIBLE_TYPE_BADNESS;
2847 }
2848 case TYPE_CODE_FUNC:
2849 switch (TYPE_CODE (arg))
2850 {
2851 case TYPE_CODE_PTR: /* funcptr -> func */
da096638 2852 return rank_one_type (parm, TYPE_TARGET_TYPE (arg), NULL);
c5aa993b
JM
2853 default:
2854 return INCOMPATIBLE_TYPE_BADNESS;
2855 }
2856 case TYPE_CODE_INT:
2857 switch (TYPE_CODE (arg))
2858 {
2859 case TYPE_CODE_INT:
2860 if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
2861 {
2862 /* Deal with signed, unsigned, and plain chars and
7ba81444 2863 signed and unsigned ints. */
c5aa993b
JM
2864 if (TYPE_NOSIGN (parm))
2865 {
0963b4bd 2866 /* This case only for character types. */
7ba81444 2867 if (TYPE_NOSIGN (arg))
6403aeea 2868 return EXACT_MATCH_BADNESS; /* plain char -> plain char */
7ba81444
MS
2869 else /* signed/unsigned char -> plain char */
2870 return INTEGER_CONVERSION_BADNESS;
c5aa993b
JM
2871 }
2872 else if (TYPE_UNSIGNED (parm))
2873 {
2874 if (TYPE_UNSIGNED (arg))
2875 {
7ba81444
MS
2876 /* unsigned int -> unsigned int, or
2877 unsigned long -> unsigned long */
2878 if (integer_types_same_name_p (TYPE_NAME (parm),
2879 TYPE_NAME (arg)))
6403aeea 2880 return EXACT_MATCH_BADNESS;
7ba81444
MS
2881 else if (integer_types_same_name_p (TYPE_NAME (arg),
2882 "int")
2883 && integer_types_same_name_p (TYPE_NAME (parm),
2884 "long"))
3e43a32a
MS
2885 /* unsigned int -> unsigned long */
2886 return INTEGER_PROMOTION_BADNESS;
c5aa993b 2887 else
3e43a32a
MS
2888 /* unsigned long -> unsigned int */
2889 return INTEGER_CONVERSION_BADNESS;
c5aa993b
JM
2890 }
2891 else
2892 {
7ba81444
MS
2893 if (integer_types_same_name_p (TYPE_NAME (arg),
2894 "long")
2895 && integer_types_same_name_p (TYPE_NAME (parm),
2896 "int"))
3e43a32a
MS
2897 /* signed long -> unsigned int */
2898 return INTEGER_CONVERSION_BADNESS;
c5aa993b 2899 else
3e43a32a
MS
2900 /* signed int/long -> unsigned int/long */
2901 return INTEGER_CONVERSION_BADNESS;
c5aa993b
JM
2902 }
2903 }
2904 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
2905 {
7ba81444
MS
2906 if (integer_types_same_name_p (TYPE_NAME (parm),
2907 TYPE_NAME (arg)))
6403aeea 2908 return EXACT_MATCH_BADNESS;
7ba81444
MS
2909 else if (integer_types_same_name_p (TYPE_NAME (arg),
2910 "int")
2911 && integer_types_same_name_p (TYPE_NAME (parm),
2912 "long"))
c5aa993b
JM
2913 return INTEGER_PROMOTION_BADNESS;
2914 else
1c5cb38e 2915 return INTEGER_CONVERSION_BADNESS;
c5aa993b
JM
2916 }
2917 else
1c5cb38e 2918 return INTEGER_CONVERSION_BADNESS;
c5aa993b
JM
2919 }
2920 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2921 return INTEGER_PROMOTION_BADNESS;
2922 else
1c5cb38e 2923 return INTEGER_CONVERSION_BADNESS;
c5aa993b 2924 case TYPE_CODE_ENUM:
4f2aea11 2925 case TYPE_CODE_FLAGS:
c5aa993b
JM
2926 case TYPE_CODE_CHAR:
2927 case TYPE_CODE_RANGE:
2928 case TYPE_CODE_BOOL:
2929 return INTEGER_PROMOTION_BADNESS;
2930 case TYPE_CODE_FLT:
2931 return INT_FLOAT_CONVERSION_BADNESS;
2932 case TYPE_CODE_PTR:
2933 return NS_POINTER_CONVERSION_BADNESS;
2934 default:
2935 return INCOMPATIBLE_TYPE_BADNESS;
2936 }
2937 break;
2938 case TYPE_CODE_ENUM:
2939 switch (TYPE_CODE (arg))
2940 {
2941 case TYPE_CODE_INT:
2942 case TYPE_CODE_CHAR:
2943 case TYPE_CODE_RANGE:
2944 case TYPE_CODE_BOOL:
2945 case TYPE_CODE_ENUM:
1c5cb38e 2946 return INTEGER_CONVERSION_BADNESS;
c5aa993b
JM
2947 case TYPE_CODE_FLT:
2948 return INT_FLOAT_CONVERSION_BADNESS;
2949 default:
2950 return INCOMPATIBLE_TYPE_BADNESS;
2951 }
2952 break;
2953 case TYPE_CODE_CHAR:
2954 switch (TYPE_CODE (arg))
2955 {
2956 case TYPE_CODE_RANGE:
2957 case TYPE_CODE_BOOL:
2958 case TYPE_CODE_ENUM:
1c5cb38e 2959 return INTEGER_CONVERSION_BADNESS;
c5aa993b
JM
2960 case TYPE_CODE_FLT:
2961 return INT_FLOAT_CONVERSION_BADNESS;
2962 case TYPE_CODE_INT:
2963 if (TYPE_LENGTH (arg) > TYPE_LENGTH (parm))
1c5cb38e 2964 return INTEGER_CONVERSION_BADNESS;
c5aa993b
JM
2965 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2966 return INTEGER_PROMOTION_BADNESS;
2967 /* >>> !! else fall through !! <<< */
2968 case TYPE_CODE_CHAR:
7ba81444
MS
2969 /* Deal with signed, unsigned, and plain chars for C++ and
2970 with int cases falling through from previous case. */
c5aa993b
JM
2971 if (TYPE_NOSIGN (parm))
2972 {
2973 if (TYPE_NOSIGN (arg))
6403aeea 2974 return EXACT_MATCH_BADNESS;
c5aa993b 2975 else
1c5cb38e 2976 return INTEGER_CONVERSION_BADNESS;
c5aa993b
JM
2977 }
2978 else if (TYPE_UNSIGNED (parm))
2979 {
2980 if (TYPE_UNSIGNED (arg))
6403aeea 2981 return EXACT_MATCH_BADNESS;
c5aa993b
JM
2982 else
2983 return INTEGER_PROMOTION_BADNESS;
2984 }
2985 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
6403aeea 2986 return EXACT_MATCH_BADNESS;
c5aa993b 2987 else
1c5cb38e 2988 return INTEGER_CONVERSION_BADNESS;
c5aa993b
JM
2989 default:
2990 return INCOMPATIBLE_TYPE_BADNESS;
2991 }
2992 break;
2993 case TYPE_CODE_RANGE:
2994 switch (TYPE_CODE (arg))
2995 {
2996 case TYPE_CODE_INT:
2997 case TYPE_CODE_CHAR:
2998 case TYPE_CODE_RANGE:
2999 case TYPE_CODE_BOOL:
3000 case TYPE_CODE_ENUM:
1c5cb38e 3001 return INTEGER_CONVERSION_BADNESS;
c5aa993b
JM
3002 case TYPE_CODE_FLT:
3003 return INT_FLOAT_CONVERSION_BADNESS;
3004 default:
3005 return INCOMPATIBLE_TYPE_BADNESS;
3006 }
3007 break;
3008 case TYPE_CODE_BOOL:
3009 switch (TYPE_CODE (arg))
3010 {
5b4f6e25
KS
3011 /* n3290 draft, section 4.12.1 (conv.bool):
3012
3013 "A prvalue of arithmetic, unscoped enumeration, pointer, or
3014 pointer to member type can be converted to a prvalue of type
3015 bool. A zero value, null pointer value, or null member pointer
3016 value is converted to false; any other value is converted to
3017 true. A prvalue of type std::nullptr_t can be converted to a
3018 prvalue of type bool; the resulting value is false." */
c5aa993b
JM
3019 case TYPE_CODE_INT:
3020 case TYPE_CODE_CHAR:
c5aa993b
JM
3021 case TYPE_CODE_ENUM:
3022 case TYPE_CODE_FLT:
5b4f6e25 3023 case TYPE_CODE_MEMBERPTR:
c5aa993b 3024 case TYPE_CODE_PTR:
5b4f6e25
KS
3025 return BOOL_CONVERSION_BADNESS;
3026 case TYPE_CODE_RANGE:
3027 return INCOMPATIBLE_TYPE_BADNESS;
c5aa993b 3028 case TYPE_CODE_BOOL:
6403aeea 3029 return EXACT_MATCH_BADNESS;
c5aa993b
JM
3030 default:
3031 return INCOMPATIBLE_TYPE_BADNESS;
3032 }
3033 break;
3034 case TYPE_CODE_FLT:
3035 switch (TYPE_CODE (arg))
3036 {
3037 case TYPE_CODE_FLT:
3038 if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
3039 return FLOAT_PROMOTION_BADNESS;
3040 else if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
6403aeea 3041 return EXACT_MATCH_BADNESS;
c5aa993b
JM
3042 else
3043 return FLOAT_CONVERSION_BADNESS;
3044 case TYPE_CODE_INT:
3045 case TYPE_CODE_BOOL:
3046 case TYPE_CODE_ENUM:
3047 case TYPE_CODE_RANGE:
3048 case TYPE_CODE_CHAR:
3049 return INT_FLOAT_CONVERSION_BADNESS;
3050 default:
3051 return INCOMPATIBLE_TYPE_BADNESS;
3052 }
3053 break;
3054 case TYPE_CODE_COMPLEX:
3055 switch (TYPE_CODE (arg))
7ba81444 3056 { /* Strictly not needed for C++, but... */
c5aa993b
JM
3057 case TYPE_CODE_FLT:
3058 return FLOAT_PROMOTION_BADNESS;
3059 case TYPE_CODE_COMPLEX:
6403aeea 3060 return EXACT_MATCH_BADNESS;
c5aa993b
JM
3061 default:
3062 return INCOMPATIBLE_TYPE_BADNESS;
3063 }
3064 break;
3065 case TYPE_CODE_STRUCT:
0963b4bd 3066 /* currently same as TYPE_CODE_CLASS. */
c5aa993b
JM
3067 switch (TYPE_CODE (arg))
3068 {
3069 case TYPE_CODE_STRUCT:
3070 /* Check for derivation */
a9d5ef47
SW
3071 rank.subrank = distance_to_ancestor (parm, arg, 0);
3072 if (rank.subrank >= 0)
3073 return sum_ranks (BASE_CONVERSION_BADNESS, rank);
c5aa993b
JM
3074 /* else fall through */
3075 default:
3076 return INCOMPATIBLE_TYPE_BADNESS;
3077 }
3078 break;
3079 case TYPE_CODE_UNION:
3080 switch (TYPE_CODE (arg))
3081 {
3082 case TYPE_CODE_UNION:
3083 default:
3084 return INCOMPATIBLE_TYPE_BADNESS;
3085 }
3086 break;
0d5de010 3087 case TYPE_CODE_MEMBERPTR:
c5aa993b
JM
3088 switch (TYPE_CODE (arg))
3089 {
3090 default:
3091 return INCOMPATIBLE_TYPE_BADNESS;
3092 }
3093 break;
3094 case TYPE_CODE_METHOD:
3095 switch (TYPE_CODE (arg))
3096 {
3097
3098 default:
3099 return INCOMPATIBLE_TYPE_BADNESS;
3100 }
3101 break;
3102 case TYPE_CODE_REF:
3103 switch (TYPE_CODE (arg))
3104 {
3105
3106 default:
3107 return INCOMPATIBLE_TYPE_BADNESS;
3108 }
3109
3110 break;
3111 case TYPE_CODE_SET:
3112 switch (TYPE_CODE (arg))
3113 {
3114 /* Not in C++ */
3115 case TYPE_CODE_SET:
7ba81444 3116 return rank_one_type (TYPE_FIELD_TYPE (parm, 0),
da096638 3117 TYPE_FIELD_TYPE (arg, 0), NULL);
c5aa993b
JM
3118 default:
3119 return INCOMPATIBLE_TYPE_BADNESS;
3120 }
3121 break;
3122 case TYPE_CODE_VOID:
3123 default:
3124 return INCOMPATIBLE_TYPE_BADNESS;
3125 } /* switch (TYPE_CODE (arg)) */
c906108c
SS
3126}
3127
0963b4bd 3128/* End of functions for overload resolution. */
5212577a
DE
3129\f
3130/* Routines to pretty-print types. */
c906108c 3131
c906108c 3132static void
fba45db2 3133print_bit_vector (B_TYPE *bits, int nbits)
c906108c
SS
3134{
3135 int bitno;
3136
3137 for (bitno = 0; bitno < nbits; bitno++)
3138 {
3139 if ((bitno % 8) == 0)
3140 {
3141 puts_filtered (" ");
3142 }
3143 if (B_TST (bits, bitno))
a3f17187 3144 printf_filtered (("1"));
c906108c 3145 else
a3f17187 3146 printf_filtered (("0"));
c906108c
SS
3147 }
3148}
3149
ad2f7632 3150/* Note the first arg should be the "this" pointer, we may not want to
7ba81444
MS
3151 include it since we may get into a infinitely recursive
3152 situation. */
c906108c
SS
3153
3154static void
ad2f7632 3155print_arg_types (struct field *args, int nargs, int spaces)
c906108c
SS
3156{
3157 if (args != NULL)
3158 {
ad2f7632
DJ
3159 int i;
3160
3161 for (i = 0; i < nargs; i++)
3162 recursive_dump_type (args[i].type, spaces + 2);
c906108c
SS
3163 }
3164}
3165
d6a843b5
JK
3166int
3167field_is_static (struct field *f)
3168{
3169 /* "static" fields are the fields whose location is not relative
3170 to the address of the enclosing struct. It would be nice to
3171 have a dedicated flag that would be set for static fields when
3172 the type is being created. But in practice, checking the field
254e6b9e 3173 loc_kind should give us an accurate answer. */
d6a843b5
JK
3174 return (FIELD_LOC_KIND (*f) == FIELD_LOC_KIND_PHYSNAME
3175 || FIELD_LOC_KIND (*f) == FIELD_LOC_KIND_PHYSADDR);
3176}
3177
c906108c 3178static void
fba45db2 3179dump_fn_fieldlists (struct type *type, int spaces)
c906108c
SS
3180{
3181 int method_idx;
3182 int overload_idx;
3183 struct fn_field *f;
3184
3185 printfi_filtered (spaces, "fn_fieldlists ");
d4f3574e 3186 gdb_print_host_address (TYPE_FN_FIELDLISTS (type), gdb_stdout);
c906108c
SS
3187 printf_filtered ("\n");
3188 for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++)
3189 {
3190 f = TYPE_FN_FIELDLIST1 (type, method_idx);
3191 printfi_filtered (spaces + 2, "[%d] name '%s' (",
3192 method_idx,
3193 TYPE_FN_FIELDLIST_NAME (type, method_idx));
d4f3574e
SS
3194 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type, method_idx),
3195 gdb_stdout);
a3f17187 3196 printf_filtered (_(") length %d\n"),
c906108c
SS
3197 TYPE_FN_FIELDLIST_LENGTH (type, method_idx));
3198 for (overload_idx = 0;
3199 overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx);
3200 overload_idx++)
3201 {
3202 printfi_filtered (spaces + 4, "[%d] physname '%s' (",
3203 overload_idx,
3204 TYPE_FN_FIELD_PHYSNAME (f, overload_idx));
d4f3574e
SS
3205 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f, overload_idx),
3206 gdb_stdout);
c906108c
SS
3207 printf_filtered (")\n");
3208 printfi_filtered (spaces + 8, "type ");
7ba81444
MS
3209 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f, overload_idx),
3210 gdb_stdout);
c906108c
SS
3211 printf_filtered ("\n");
3212
3213 recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx),
3214 spaces + 8 + 2);
3215
3216 printfi_filtered (spaces + 8, "args ");
7ba81444
MS
3217 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f, overload_idx),
3218 gdb_stdout);
c906108c
SS
3219 printf_filtered ("\n");
3220
ad2f7632 3221 print_arg_types (TYPE_FN_FIELD_ARGS (f, overload_idx),
7ba81444
MS
3222 TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f,
3223 overload_idx)),
ad2f7632 3224 spaces);
c906108c 3225 printfi_filtered (spaces + 8, "fcontext ");
d4f3574e
SS
3226 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx),
3227 gdb_stdout);
c906108c
SS
3228 printf_filtered ("\n");
3229
3230 printfi_filtered (spaces + 8, "is_const %d\n",
3231 TYPE_FN_FIELD_CONST (f, overload_idx));
3232 printfi_filtered (spaces + 8, "is_volatile %d\n",
3233 TYPE_FN_FIELD_VOLATILE (f, overload_idx));
3234 printfi_filtered (spaces + 8, "is_private %d\n",
3235 TYPE_FN_FIELD_PRIVATE (f, overload_idx));
3236 printfi_filtered (spaces + 8, "is_protected %d\n",
3237 TYPE_FN_FIELD_PROTECTED (f, overload_idx));
3238 printfi_filtered (spaces + 8, "is_stub %d\n",
3239 TYPE_FN_FIELD_STUB (f, overload_idx));
3240 printfi_filtered (spaces + 8, "voffset %u\n",
3241 TYPE_FN_FIELD_VOFFSET (f, overload_idx));
3242 }
3243 }
3244}
3245
3246static void
fba45db2 3247print_cplus_stuff (struct type *type, int spaces)
c906108c
SS
3248{
3249 printfi_filtered (spaces, "n_baseclasses %d\n",
3250 TYPE_N_BASECLASSES (type));
3251 printfi_filtered (spaces, "nfn_fields %d\n",
3252 TYPE_NFN_FIELDS (type));
c906108c
SS
3253 if (TYPE_N_BASECLASSES (type) > 0)
3254 {
3255 printfi_filtered (spaces, "virtual_field_bits (%d bits at *",
3256 TYPE_N_BASECLASSES (type));
7ba81444
MS
3257 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type),
3258 gdb_stdout);
c906108c
SS
3259 printf_filtered (")");
3260
3261 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type),
3262 TYPE_N_BASECLASSES (type));
3263 puts_filtered ("\n");
3264 }
3265 if (TYPE_NFIELDS (type) > 0)
3266 {
3267 if (TYPE_FIELD_PRIVATE_BITS (type) != NULL)
3268 {
7ba81444
MS
3269 printfi_filtered (spaces,
3270 "private_field_bits (%d bits at *",
c906108c 3271 TYPE_NFIELDS (type));
7ba81444
MS
3272 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type),
3273 gdb_stdout);
c906108c
SS
3274 printf_filtered (")");
3275 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type),
3276 TYPE_NFIELDS (type));
3277 puts_filtered ("\n");
3278 }
3279 if (TYPE_FIELD_PROTECTED_BITS (type) != NULL)
3280 {
7ba81444
MS
3281 printfi_filtered (spaces,
3282 "protected_field_bits (%d bits at *",
c906108c 3283 TYPE_NFIELDS (type));
7ba81444
MS
3284 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type),
3285 gdb_stdout);
c906108c
SS
3286 printf_filtered (")");
3287 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type),
3288 TYPE_NFIELDS (type));
3289 puts_filtered ("\n");
3290 }
3291 }
3292 if (TYPE_NFN_FIELDS (type) > 0)
3293 {
3294 dump_fn_fieldlists (type, spaces);
3295 }
3296}
3297
b4ba55a1
JB
3298/* Print the contents of the TYPE's type_specific union, assuming that
3299 its type-specific kind is TYPE_SPECIFIC_GNAT_STUFF. */
3300
3301static void
3302print_gnat_stuff (struct type *type, int spaces)
3303{
3304 struct type *descriptive_type = TYPE_DESCRIPTIVE_TYPE (type);
3305
3306 recursive_dump_type (descriptive_type, spaces + 2);
3307}
3308
c906108c
SS
3309static struct obstack dont_print_type_obstack;
3310
3311void
fba45db2 3312recursive_dump_type (struct type *type, int spaces)
c906108c
SS
3313{
3314 int idx;
3315
3316 if (spaces == 0)
3317 obstack_begin (&dont_print_type_obstack, 0);
3318
3319 if (TYPE_NFIELDS (type) > 0
b4ba55a1 3320 || (HAVE_CPLUS_STRUCT (type) && TYPE_NFN_FIELDS (type) > 0))
c906108c
SS
3321 {
3322 struct type **first_dont_print
7ba81444 3323 = (struct type **) obstack_base (&dont_print_type_obstack);
c906108c 3324
7ba81444
MS
3325 int i = (struct type **)
3326 obstack_next_free (&dont_print_type_obstack) - first_dont_print;
c906108c
SS
3327
3328 while (--i >= 0)
3329 {
3330 if (type == first_dont_print[i])
3331 {
3332 printfi_filtered (spaces, "type node ");
d4f3574e 3333 gdb_print_host_address (type, gdb_stdout);
a3f17187 3334 printf_filtered (_(" <same as already seen type>\n"));
c906108c
SS
3335 return;
3336 }
3337 }
3338
3339 obstack_ptr_grow (&dont_print_type_obstack, type);
3340 }
3341
3342 printfi_filtered (spaces, "type node ");
d4f3574e 3343 gdb_print_host_address (type, gdb_stdout);
c906108c
SS
3344 printf_filtered ("\n");
3345 printfi_filtered (spaces, "name '%s' (",
3346 TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>");
d4f3574e 3347 gdb_print_host_address (TYPE_NAME (type), gdb_stdout);
c906108c 3348 printf_filtered (")\n");
e9e79dd9
FF
3349 printfi_filtered (spaces, "tagname '%s' (",
3350 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : "<NULL>");
3351 gdb_print_host_address (TYPE_TAG_NAME (type), gdb_stdout);
3352 printf_filtered (")\n");
c906108c
SS
3353 printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type));
3354 switch (TYPE_CODE (type))
3355 {
c5aa993b
JM
3356 case TYPE_CODE_UNDEF:
3357 printf_filtered ("(TYPE_CODE_UNDEF)");
3358 break;
3359 case TYPE_CODE_PTR:
3360 printf_filtered ("(TYPE_CODE_PTR)");
3361 break;
3362 case TYPE_CODE_ARRAY:
3363 printf_filtered ("(TYPE_CODE_ARRAY)");
3364 break;
3365 case TYPE_CODE_STRUCT:
3366 printf_filtered ("(TYPE_CODE_STRUCT)");
3367 break;
3368 case TYPE_CODE_UNION:
3369 printf_filtered ("(TYPE_CODE_UNION)");
3370 break;
3371 case TYPE_CODE_ENUM:
3372 printf_filtered ("(TYPE_CODE_ENUM)");
3373 break;
4f2aea11
MK
3374 case TYPE_CODE_FLAGS:
3375 printf_filtered ("(TYPE_CODE_FLAGS)");
3376 break;
c5aa993b
JM
3377 case TYPE_CODE_FUNC:
3378 printf_filtered ("(TYPE_CODE_FUNC)");
3379 break;
3380 case TYPE_CODE_INT:
3381 printf_filtered ("(TYPE_CODE_INT)");
3382 break;
3383 case TYPE_CODE_FLT:
3384 printf_filtered ("(TYPE_CODE_FLT)");
3385 break;
3386 case TYPE_CODE_VOID:
3387 printf_filtered ("(TYPE_CODE_VOID)");
3388 break;
3389 case TYPE_CODE_SET:
3390 printf_filtered ("(TYPE_CODE_SET)");
3391 break;
3392 case TYPE_CODE_RANGE:
3393 printf_filtered ("(TYPE_CODE_RANGE)");
3394 break;
3395 case TYPE_CODE_STRING:
3396 printf_filtered ("(TYPE_CODE_STRING)");
3397 break;
3398 case TYPE_CODE_ERROR:
3399 printf_filtered ("(TYPE_CODE_ERROR)");
3400 break;
0d5de010
DJ
3401 case TYPE_CODE_MEMBERPTR:
3402 printf_filtered ("(TYPE_CODE_MEMBERPTR)");
3403 break;
3404 case TYPE_CODE_METHODPTR:
3405 printf_filtered ("(TYPE_CODE_METHODPTR)");
c5aa993b
JM
3406 break;
3407 case TYPE_CODE_METHOD:
3408 printf_filtered ("(TYPE_CODE_METHOD)");
3409 break;
3410 case TYPE_CODE_REF:
3411 printf_filtered ("(TYPE_CODE_REF)");
3412 break;
3413 case TYPE_CODE_CHAR:
3414 printf_filtered ("(TYPE_CODE_CHAR)");
3415 break;
3416 case TYPE_CODE_BOOL:
3417 printf_filtered ("(TYPE_CODE_BOOL)");
3418 break;
e9e79dd9
FF
3419 case TYPE_CODE_COMPLEX:
3420 printf_filtered ("(TYPE_CODE_COMPLEX)");
3421 break;
c5aa993b
JM
3422 case TYPE_CODE_TYPEDEF:
3423 printf_filtered ("(TYPE_CODE_TYPEDEF)");
3424 break;
5c4e30ca
DC
3425 case TYPE_CODE_NAMESPACE:
3426 printf_filtered ("(TYPE_CODE_NAMESPACE)");
3427 break;
c5aa993b
JM
3428 default:
3429 printf_filtered ("(UNKNOWN TYPE CODE)");
3430 break;
c906108c
SS
3431 }
3432 puts_filtered ("\n");
3433 printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type));
e9bb382b
UW
3434 if (TYPE_OBJFILE_OWNED (type))
3435 {
3436 printfi_filtered (spaces, "objfile ");
3437 gdb_print_host_address (TYPE_OWNER (type).objfile, gdb_stdout);
3438 }
3439 else
3440 {
3441 printfi_filtered (spaces, "gdbarch ");
3442 gdb_print_host_address (TYPE_OWNER (type).gdbarch, gdb_stdout);
3443 }
c906108c
SS
3444 printf_filtered ("\n");
3445 printfi_filtered (spaces, "target_type ");
d4f3574e 3446 gdb_print_host_address (TYPE_TARGET_TYPE (type), gdb_stdout);
c906108c
SS
3447 printf_filtered ("\n");
3448 if (TYPE_TARGET_TYPE (type) != NULL)
3449 {
3450 recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2);
3451 }
3452 printfi_filtered (spaces, "pointer_type ");
d4f3574e 3453 gdb_print_host_address (TYPE_POINTER_TYPE (type), gdb_stdout);
c906108c
SS
3454 printf_filtered ("\n");
3455 printfi_filtered (spaces, "reference_type ");
d4f3574e 3456 gdb_print_host_address (TYPE_REFERENCE_TYPE (type), gdb_stdout);
c906108c 3457 printf_filtered ("\n");
2fdde8f8
DJ
3458 printfi_filtered (spaces, "type_chain ");
3459 gdb_print_host_address (TYPE_CHAIN (type), gdb_stdout);
e9e79dd9 3460 printf_filtered ("\n");
7ba81444
MS
3461 printfi_filtered (spaces, "instance_flags 0x%x",
3462 TYPE_INSTANCE_FLAGS (type));
2fdde8f8
DJ
3463 if (TYPE_CONST (type))
3464 {
3465 puts_filtered (" TYPE_FLAG_CONST");
3466 }
3467 if (TYPE_VOLATILE (type))
3468 {
3469 puts_filtered (" TYPE_FLAG_VOLATILE");
3470 }
3471 if (TYPE_CODE_SPACE (type))
3472 {
3473 puts_filtered (" TYPE_FLAG_CODE_SPACE");
3474 }
3475 if (TYPE_DATA_SPACE (type))
3476 {
3477 puts_filtered (" TYPE_FLAG_DATA_SPACE");
3478 }
8b2dbe47
KB
3479 if (TYPE_ADDRESS_CLASS_1 (type))
3480 {
3481 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_1");
3482 }
3483 if (TYPE_ADDRESS_CLASS_2 (type))
3484 {
3485 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_2");
3486 }
06d66ee9
TT
3487 if (TYPE_RESTRICT (type))
3488 {
3489 puts_filtered (" TYPE_FLAG_RESTRICT");
3490 }
2fdde8f8 3491 puts_filtered ("\n");
876cecd0
TT
3492
3493 printfi_filtered (spaces, "flags");
762a036f 3494 if (TYPE_UNSIGNED (type))
c906108c
SS
3495 {
3496 puts_filtered (" TYPE_FLAG_UNSIGNED");
3497 }
762a036f
FF
3498 if (TYPE_NOSIGN (type))
3499 {
3500 puts_filtered (" TYPE_FLAG_NOSIGN");
3501 }
3502 if (TYPE_STUB (type))
c906108c
SS
3503 {
3504 puts_filtered (" TYPE_FLAG_STUB");
3505 }
762a036f
FF
3506 if (TYPE_TARGET_STUB (type))
3507 {
3508 puts_filtered (" TYPE_FLAG_TARGET_STUB");
3509 }
3510 if (TYPE_STATIC (type))
3511 {
3512 puts_filtered (" TYPE_FLAG_STATIC");
3513 }
762a036f
FF
3514 if (TYPE_PROTOTYPED (type))
3515 {
3516 puts_filtered (" TYPE_FLAG_PROTOTYPED");
3517 }
3518 if (TYPE_INCOMPLETE (type))
3519 {
3520 puts_filtered (" TYPE_FLAG_INCOMPLETE");
3521 }
762a036f
FF
3522 if (TYPE_VARARGS (type))
3523 {
3524 puts_filtered (" TYPE_FLAG_VARARGS");
3525 }
f5f8a009
EZ
3526 /* This is used for things like AltiVec registers on ppc. Gcc emits
3527 an attribute for the array type, which tells whether or not we
3528 have a vector, instead of a regular array. */
3529 if (TYPE_VECTOR (type))
3530 {
3531 puts_filtered (" TYPE_FLAG_VECTOR");
3532 }
876cecd0
TT
3533 if (TYPE_FIXED_INSTANCE (type))
3534 {
3535 puts_filtered (" TYPE_FIXED_INSTANCE");
3536 }
3537 if (TYPE_STUB_SUPPORTED (type))
3538 {
3539 puts_filtered (" TYPE_STUB_SUPPORTED");
3540 }
3541 if (TYPE_NOTTEXT (type))
3542 {
3543 puts_filtered (" TYPE_NOTTEXT");
3544 }
c906108c
SS
3545 puts_filtered ("\n");
3546 printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type));
d4f3574e 3547 gdb_print_host_address (TYPE_FIELDS (type), gdb_stdout);
c906108c
SS
3548 puts_filtered ("\n");
3549 for (idx = 0; idx < TYPE_NFIELDS (type); idx++)
3550 {
14e75d8e
JK
3551 if (TYPE_CODE (type) == TYPE_CODE_ENUM)
3552 printfi_filtered (spaces + 2,
3553 "[%d] enumval %s type ",
3554 idx, plongest (TYPE_FIELD_ENUMVAL (type, idx)));
3555 else
3556 printfi_filtered (spaces + 2,
3557 "[%d] bitpos %d bitsize %d type ",
3558 idx, TYPE_FIELD_BITPOS (type, idx),
3559 TYPE_FIELD_BITSIZE (type, idx));
d4f3574e 3560 gdb_print_host_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout);
c906108c
SS
3561 printf_filtered (" name '%s' (",
3562 TYPE_FIELD_NAME (type, idx) != NULL
3563 ? TYPE_FIELD_NAME (type, idx)
3564 : "<NULL>");
d4f3574e 3565 gdb_print_host_address (TYPE_FIELD_NAME (type, idx), gdb_stdout);
c906108c
SS
3566 printf_filtered (")\n");
3567 if (TYPE_FIELD_TYPE (type, idx) != NULL)
3568 {
3569 recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4);
3570 }
3571 }
43bbcdc2
PH
3572 if (TYPE_CODE (type) == TYPE_CODE_RANGE)
3573 {
3574 printfi_filtered (spaces, "low %s%s high %s%s\n",
3575 plongest (TYPE_LOW_BOUND (type)),
3576 TYPE_LOW_BOUND_UNDEFINED (type) ? " (undefined)" : "",
3577 plongest (TYPE_HIGH_BOUND (type)),
3e43a32a
MS
3578 TYPE_HIGH_BOUND_UNDEFINED (type)
3579 ? " (undefined)" : "");
43bbcdc2 3580 }
c906108c 3581 printfi_filtered (spaces, "vptr_basetype ");
d4f3574e 3582 gdb_print_host_address (TYPE_VPTR_BASETYPE (type), gdb_stdout);
c906108c
SS
3583 puts_filtered ("\n");
3584 if (TYPE_VPTR_BASETYPE (type) != NULL)
3585 {
3586 recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2);
3587 }
7ba81444
MS
3588 printfi_filtered (spaces, "vptr_fieldno %d\n",
3589 TYPE_VPTR_FIELDNO (type));
c906108c 3590
b4ba55a1
JB
3591 switch (TYPE_SPECIFIC_FIELD (type))
3592 {
3593 case TYPE_SPECIFIC_CPLUS_STUFF:
3594 printfi_filtered (spaces, "cplus_stuff ");
3595 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type),
3596 gdb_stdout);
3597 puts_filtered ("\n");
3598 print_cplus_stuff (type, spaces);
3599 break;
8da61cc4 3600
b4ba55a1
JB
3601 case TYPE_SPECIFIC_GNAT_STUFF:
3602 printfi_filtered (spaces, "gnat_stuff ");
3603 gdb_print_host_address (TYPE_GNAT_SPECIFIC (type), gdb_stdout);
3604 puts_filtered ("\n");
3605 print_gnat_stuff (type, spaces);
3606 break;
701c159d 3607
b4ba55a1
JB
3608 case TYPE_SPECIFIC_FLOATFORMAT:
3609 printfi_filtered (spaces, "floatformat ");
3610 if (TYPE_FLOATFORMAT (type) == NULL)
3611 puts_filtered ("(null)");
3612 else
3613 {
3614 puts_filtered ("{ ");
3615 if (TYPE_FLOATFORMAT (type)[0] == NULL
3616 || TYPE_FLOATFORMAT (type)[0]->name == NULL)
3617 puts_filtered ("(null)");
3618 else
3619 puts_filtered (TYPE_FLOATFORMAT (type)[0]->name);
3620
3621 puts_filtered (", ");
3622 if (TYPE_FLOATFORMAT (type)[1] == NULL
3623 || TYPE_FLOATFORMAT (type)[1]->name == NULL)
3624 puts_filtered ("(null)");
3625 else
3626 puts_filtered (TYPE_FLOATFORMAT (type)[1]->name);
3627
3628 puts_filtered (" }");
3629 }
3630 puts_filtered ("\n");
3631 break;
c906108c 3632
b6cdc2c1 3633 case TYPE_SPECIFIC_FUNC:
b4ba55a1
JB
3634 printfi_filtered (spaces, "calling_convention %d\n",
3635 TYPE_CALLING_CONVENTION (type));
b6cdc2c1 3636 /* tail_call_list is not printed. */
b4ba55a1 3637 break;
c906108c 3638 }
b4ba55a1 3639
c906108c
SS
3640 if (spaces == 0)
3641 obstack_free (&dont_print_type_obstack, NULL);
3642}
5212577a 3643\f
ae5a43e0
DJ
3644/* Trivial helpers for the libiberty hash table, for mapping one
3645 type to another. */
3646
3647struct type_pair
3648{
3649 struct type *old, *new;
3650};
3651
3652static hashval_t
3653type_pair_hash (const void *item)
3654{
3655 const struct type_pair *pair = item;
d8734c88 3656
ae5a43e0
DJ
3657 return htab_hash_pointer (pair->old);
3658}
3659
3660static int
3661type_pair_eq (const void *item_lhs, const void *item_rhs)
3662{
3663 const struct type_pair *lhs = item_lhs, *rhs = item_rhs;
d8734c88 3664
ae5a43e0
DJ
3665 return lhs->old == rhs->old;
3666}
3667
3668/* Allocate the hash table used by copy_type_recursive to walk
3669 types without duplicates. We use OBJFILE's obstack, because
3670 OBJFILE is about to be deleted. */
3671
3672htab_t
3673create_copied_types_hash (struct objfile *objfile)
3674{
3675 return htab_create_alloc_ex (1, type_pair_hash, type_pair_eq,
3676 NULL, &objfile->objfile_obstack,
3677 hashtab_obstack_allocate,
3678 dummy_obstack_deallocate);
3679}
3680
7ba81444
MS
3681/* Recursively copy (deep copy) TYPE, if it is associated with
3682 OBJFILE. Return a new type allocated using malloc, a saved type if
3683 we have already visited TYPE (using COPIED_TYPES), or TYPE if it is
3684 not associated with OBJFILE. */
ae5a43e0
DJ
3685
3686struct type *
7ba81444
MS
3687copy_type_recursive (struct objfile *objfile,
3688 struct type *type,
ae5a43e0
DJ
3689 htab_t copied_types)
3690{
3691 struct type_pair *stored, pair;
3692 void **slot;
3693 struct type *new_type;
3694
e9bb382b 3695 if (! TYPE_OBJFILE_OWNED (type))
ae5a43e0
DJ
3696 return type;
3697
7ba81444
MS
3698 /* This type shouldn't be pointing to any types in other objfiles;
3699 if it did, the type might disappear unexpectedly. */
ae5a43e0
DJ
3700 gdb_assert (TYPE_OBJFILE (type) == objfile);
3701
3702 pair.old = type;
3703 slot = htab_find_slot (copied_types, &pair, INSERT);
3704 if (*slot != NULL)
3705 return ((struct type_pair *) *slot)->new;
3706
e9bb382b 3707 new_type = alloc_type_arch (get_type_arch (type));
ae5a43e0
DJ
3708
3709 /* We must add the new type to the hash table immediately, in case
3710 we encounter this type again during a recursive call below. */
3e43a32a
MS
3711 stored
3712 = obstack_alloc (&objfile->objfile_obstack, sizeof (struct type_pair));
ae5a43e0
DJ
3713 stored->old = type;
3714 stored->new = new_type;
3715 *slot = stored;
3716
876cecd0
TT
3717 /* Copy the common fields of types. For the main type, we simply
3718 copy the entire thing and then update specific fields as needed. */
3719 *TYPE_MAIN_TYPE (new_type) = *TYPE_MAIN_TYPE (type);
e9bb382b
UW
3720 TYPE_OBJFILE_OWNED (new_type) = 0;
3721 TYPE_OWNER (new_type).gdbarch = get_type_arch (type);
876cecd0 3722
ae5a43e0
DJ
3723 if (TYPE_NAME (type))
3724 TYPE_NAME (new_type) = xstrdup (TYPE_NAME (type));
3725 if (TYPE_TAG_NAME (type))
3726 TYPE_TAG_NAME (new_type) = xstrdup (TYPE_TAG_NAME (type));
ae5a43e0
DJ
3727
3728 TYPE_INSTANCE_FLAGS (new_type) = TYPE_INSTANCE_FLAGS (type);
3729 TYPE_LENGTH (new_type) = TYPE_LENGTH (type);
3730
3731 /* Copy the fields. */
ae5a43e0
DJ
3732 if (TYPE_NFIELDS (type))
3733 {
3734 int i, nfields;
3735
3736 nfields = TYPE_NFIELDS (type);
fc270c35 3737 TYPE_FIELDS (new_type) = XCNEWVEC (struct field, nfields);
ae5a43e0
DJ
3738 for (i = 0; i < nfields; i++)
3739 {
7ba81444
MS
3740 TYPE_FIELD_ARTIFICIAL (new_type, i) =
3741 TYPE_FIELD_ARTIFICIAL (type, i);
ae5a43e0
DJ
3742 TYPE_FIELD_BITSIZE (new_type, i) = TYPE_FIELD_BITSIZE (type, i);
3743 if (TYPE_FIELD_TYPE (type, i))
3744 TYPE_FIELD_TYPE (new_type, i)
3745 = copy_type_recursive (objfile, TYPE_FIELD_TYPE (type, i),
3746 copied_types);
3747 if (TYPE_FIELD_NAME (type, i))
7ba81444
MS
3748 TYPE_FIELD_NAME (new_type, i) =
3749 xstrdup (TYPE_FIELD_NAME (type, i));
d6a843b5 3750 switch (TYPE_FIELD_LOC_KIND (type, i))
ae5a43e0 3751 {
d6a843b5
JK
3752 case FIELD_LOC_KIND_BITPOS:
3753 SET_FIELD_BITPOS (TYPE_FIELD (new_type, i),
3754 TYPE_FIELD_BITPOS (type, i));
3755 break;
14e75d8e
JK
3756 case FIELD_LOC_KIND_ENUMVAL:
3757 SET_FIELD_ENUMVAL (TYPE_FIELD (new_type, i),
3758 TYPE_FIELD_ENUMVAL (type, i));
3759 break;
d6a843b5
JK
3760 case FIELD_LOC_KIND_PHYSADDR:
3761 SET_FIELD_PHYSADDR (TYPE_FIELD (new_type, i),
3762 TYPE_FIELD_STATIC_PHYSADDR (type, i));
3763 break;
3764 case FIELD_LOC_KIND_PHYSNAME:
3765 SET_FIELD_PHYSNAME (TYPE_FIELD (new_type, i),
3766 xstrdup (TYPE_FIELD_STATIC_PHYSNAME (type,
3767 i)));
3768 break;
3769 default:
3770 internal_error (__FILE__, __LINE__,
3771 _("Unexpected type field location kind: %d"),
3772 TYPE_FIELD_LOC_KIND (type, i));
ae5a43e0
DJ
3773 }
3774 }
3775 }
3776
0963b4bd 3777 /* For range types, copy the bounds information. */
43bbcdc2
PH
3778 if (TYPE_CODE (type) == TYPE_CODE_RANGE)
3779 {
3780 TYPE_RANGE_DATA (new_type) = xmalloc (sizeof (struct range_bounds));
3781 *TYPE_RANGE_DATA (new_type) = *TYPE_RANGE_DATA (type);
3782 }
3783
ae5a43e0
DJ
3784 /* Copy pointers to other types. */
3785 if (TYPE_TARGET_TYPE (type))
7ba81444
MS
3786 TYPE_TARGET_TYPE (new_type) =
3787 copy_type_recursive (objfile,
3788 TYPE_TARGET_TYPE (type),
3789 copied_types);
ae5a43e0 3790 if (TYPE_VPTR_BASETYPE (type))
7ba81444
MS
3791 TYPE_VPTR_BASETYPE (new_type) =
3792 copy_type_recursive (objfile,
3793 TYPE_VPTR_BASETYPE (type),
3794 copied_types);
ae5a43e0
DJ
3795 /* Maybe copy the type_specific bits.
3796
3797 NOTE drow/2005-12-09: We do not copy the C++-specific bits like
3798 base classes and methods. There's no fundamental reason why we
3799 can't, but at the moment it is not needed. */
3800
3801 if (TYPE_CODE (type) == TYPE_CODE_FLT)
d5d6fca5 3802 TYPE_FLOATFORMAT (new_type) = TYPE_FLOATFORMAT (type);
ae5a43e0
DJ
3803 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
3804 || TYPE_CODE (type) == TYPE_CODE_UNION
ae5a43e0
DJ
3805 || TYPE_CODE (type) == TYPE_CODE_NAMESPACE)
3806 INIT_CPLUS_SPECIFIC (new_type);
3807
3808 return new_type;
3809}
3810
4af88198
JB
3811/* Make a copy of the given TYPE, except that the pointer & reference
3812 types are not preserved.
3813
3814 This function assumes that the given type has an associated objfile.
3815 This objfile is used to allocate the new type. */
3816
3817struct type *
3818copy_type (const struct type *type)
3819{
3820 struct type *new_type;
3821
e9bb382b 3822 gdb_assert (TYPE_OBJFILE_OWNED (type));
4af88198 3823
e9bb382b 3824 new_type = alloc_type_copy (type);
4af88198
JB
3825 TYPE_INSTANCE_FLAGS (new_type) = TYPE_INSTANCE_FLAGS (type);
3826 TYPE_LENGTH (new_type) = TYPE_LENGTH (type);
3827 memcpy (TYPE_MAIN_TYPE (new_type), TYPE_MAIN_TYPE (type),
3828 sizeof (struct main_type));
3829
3830 return new_type;
3831}
5212577a 3832\f
e9bb382b
UW
3833/* Helper functions to initialize architecture-specific types. */
3834
3835/* Allocate a type structure associated with GDBARCH and set its
3836 CODE, LENGTH, and NAME fields. */
5212577a 3837
e9bb382b
UW
3838struct type *
3839arch_type (struct gdbarch *gdbarch,
3840 enum type_code code, int length, char *name)
3841{
3842 struct type *type;
3843
3844 type = alloc_type_arch (gdbarch);
3845 TYPE_CODE (type) = code;
3846 TYPE_LENGTH (type) = length;
3847
3848 if (name)
3849 TYPE_NAME (type) = xstrdup (name);
3850
3851 return type;
3852}
3853
3854/* Allocate a TYPE_CODE_INT type structure associated with GDBARCH.
3855 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
3856 the type's TYPE_UNSIGNED flag. NAME is the type name. */
5212577a 3857
e9bb382b
UW
3858struct type *
3859arch_integer_type (struct gdbarch *gdbarch,
3860 int bit, int unsigned_p, char *name)
3861{
3862 struct type *t;
3863
3864 t = arch_type (gdbarch, TYPE_CODE_INT, bit / TARGET_CHAR_BIT, name);
3865 if (unsigned_p)
3866 TYPE_UNSIGNED (t) = 1;
3867 if (name && strcmp (name, "char") == 0)
3868 TYPE_NOSIGN (t) = 1;
3869
3870 return t;
3871}
3872
3873/* Allocate a TYPE_CODE_CHAR type structure associated with GDBARCH.
3874 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
3875 the type's TYPE_UNSIGNED flag. NAME is the type name. */
5212577a 3876
e9bb382b
UW
3877struct type *
3878arch_character_type (struct gdbarch *gdbarch,
3879 int bit, int unsigned_p, char *name)
3880{
3881 struct type *t;
3882
3883 t = arch_type (gdbarch, TYPE_CODE_CHAR, bit / TARGET_CHAR_BIT, name);
3884 if (unsigned_p)
3885 TYPE_UNSIGNED (t) = 1;
3886
3887 return t;
3888}
3889
3890/* Allocate a TYPE_CODE_BOOL type structure associated with GDBARCH.
3891 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
3892 the type's TYPE_UNSIGNED flag. NAME is the type name. */
5212577a 3893
e9bb382b
UW
3894struct type *
3895arch_boolean_type (struct gdbarch *gdbarch,
3896 int bit, int unsigned_p, char *name)
3897{
3898 struct type *t;
3899
3900 t = arch_type (gdbarch, TYPE_CODE_BOOL, bit / TARGET_CHAR_BIT, name);
3901 if (unsigned_p)
3902 TYPE_UNSIGNED (t) = 1;
3903
3904 return t;
3905}
3906
3907/* Allocate a TYPE_CODE_FLT type structure associated with GDBARCH.
3908 BIT is the type size in bits; if BIT equals -1, the size is
3909 determined by the floatformat. NAME is the type name. Set the
3910 TYPE_FLOATFORMAT from FLOATFORMATS. */
5212577a 3911
27067745 3912struct type *
e9bb382b
UW
3913arch_float_type (struct gdbarch *gdbarch,
3914 int bit, char *name, const struct floatformat **floatformats)
8da61cc4
DJ
3915{
3916 struct type *t;
3917
3918 if (bit == -1)
3919 {
3920 gdb_assert (floatformats != NULL);
3921 gdb_assert (floatformats[0] != NULL && floatformats[1] != NULL);
3922 bit = floatformats[0]->totalsize;
3923 }
3924 gdb_assert (bit >= 0);
3925
e9bb382b 3926 t = arch_type (gdbarch, TYPE_CODE_FLT, bit / TARGET_CHAR_BIT, name);
8da61cc4
DJ
3927 TYPE_FLOATFORMAT (t) = floatformats;
3928 return t;
3929}
3930
e9bb382b
UW
3931/* Allocate a TYPE_CODE_COMPLEX type structure associated with GDBARCH.
3932 NAME is the type name. TARGET_TYPE is the component float type. */
5212577a 3933
27067745 3934struct type *
e9bb382b
UW
3935arch_complex_type (struct gdbarch *gdbarch,
3936 char *name, struct type *target_type)
27067745
UW
3937{
3938 struct type *t;
d8734c88 3939
e9bb382b
UW
3940 t = arch_type (gdbarch, TYPE_CODE_COMPLEX,
3941 2 * TYPE_LENGTH (target_type), name);
27067745
UW
3942 TYPE_TARGET_TYPE (t) = target_type;
3943 return t;
3944}
3945
e9bb382b 3946/* Allocate a TYPE_CODE_FLAGS type structure associated with GDBARCH.
eb90ce83 3947 NAME is the type name. LENGTH is the size of the flag word in bytes. */
5212577a 3948
e9bb382b
UW
3949struct type *
3950arch_flags_type (struct gdbarch *gdbarch, char *name, int length)
3951{
3952 int nfields = length * TARGET_CHAR_BIT;
3953 struct type *type;
3954
3955 type = arch_type (gdbarch, TYPE_CODE_FLAGS, length, name);
3956 TYPE_UNSIGNED (type) = 1;
3957 TYPE_NFIELDS (type) = nfields;
3958 TYPE_FIELDS (type) = TYPE_ZALLOC (type, nfields * sizeof (struct field));
3959
3960 return type;
3961}
3962
3963/* Add field to TYPE_CODE_FLAGS type TYPE to indicate the bit at
3964 position BITPOS is called NAME. */
5212577a 3965
e9bb382b
UW
3966void
3967append_flags_type_flag (struct type *type, int bitpos, char *name)
3968{
3969 gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLAGS);
3970 gdb_assert (bitpos < TYPE_NFIELDS (type));
3971 gdb_assert (bitpos >= 0);
3972
3973 if (name)
3974 {
3975 TYPE_FIELD_NAME (type, bitpos) = xstrdup (name);
945b3a32 3976 SET_FIELD_BITPOS (TYPE_FIELD (type, bitpos), bitpos);
e9bb382b
UW
3977 }
3978 else
3979 {
3980 /* Don't show this field to the user. */
945b3a32 3981 SET_FIELD_BITPOS (TYPE_FIELD (type, bitpos), -1);
e9bb382b
UW
3982 }
3983}
3984
3985/* Allocate a TYPE_CODE_STRUCT or TYPE_CODE_UNION type structure (as
3986 specified by CODE) associated with GDBARCH. NAME is the type name. */
5212577a 3987
e9bb382b
UW
3988struct type *
3989arch_composite_type (struct gdbarch *gdbarch, char *name, enum type_code code)
3990{
3991 struct type *t;
d8734c88 3992
e9bb382b
UW
3993 gdb_assert (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION);
3994 t = arch_type (gdbarch, code, 0, NULL);
3995 TYPE_TAG_NAME (t) = name;
3996 INIT_CPLUS_SPECIFIC (t);
3997 return t;
3998}
3999
4000/* Add new field with name NAME and type FIELD to composite type T.
f5dff777
DJ
4001 Do not set the field's position or adjust the type's length;
4002 the caller should do so. Return the new field. */
5212577a 4003
f5dff777
DJ
4004struct field *
4005append_composite_type_field_raw (struct type *t, char *name,
4006 struct type *field)
e9bb382b
UW
4007{
4008 struct field *f;
d8734c88 4009
e9bb382b
UW
4010 TYPE_NFIELDS (t) = TYPE_NFIELDS (t) + 1;
4011 TYPE_FIELDS (t) = xrealloc (TYPE_FIELDS (t),
4012 sizeof (struct field) * TYPE_NFIELDS (t));
4013 f = &(TYPE_FIELDS (t)[TYPE_NFIELDS (t) - 1]);
4014 memset (f, 0, sizeof f[0]);
4015 FIELD_TYPE (f[0]) = field;
4016 FIELD_NAME (f[0]) = name;
f5dff777
DJ
4017 return f;
4018}
4019
4020/* Add new field with name NAME and type FIELD to composite type T.
4021 ALIGNMENT (if non-zero) specifies the minimum field alignment. */
5212577a 4022
f5dff777
DJ
4023void
4024append_composite_type_field_aligned (struct type *t, char *name,
4025 struct type *field, int alignment)
4026{
4027 struct field *f = append_composite_type_field_raw (t, name, field);
d8734c88 4028
e9bb382b
UW
4029 if (TYPE_CODE (t) == TYPE_CODE_UNION)
4030 {
4031 if (TYPE_LENGTH (t) < TYPE_LENGTH (field))
4032 TYPE_LENGTH (t) = TYPE_LENGTH (field);
4033 }
4034 else if (TYPE_CODE (t) == TYPE_CODE_STRUCT)
4035 {
4036 TYPE_LENGTH (t) = TYPE_LENGTH (t) + TYPE_LENGTH (field);
4037 if (TYPE_NFIELDS (t) > 1)
4038 {
f41f5e61
PA
4039 SET_FIELD_BITPOS (f[0],
4040 (FIELD_BITPOS (f[-1])
4041 + (TYPE_LENGTH (FIELD_TYPE (f[-1]))
4042 * TARGET_CHAR_BIT)));
e9bb382b
UW
4043
4044 if (alignment)
4045 {
86c3c1fc
AB
4046 int left;
4047
4048 alignment *= TARGET_CHAR_BIT;
4049 left = FIELD_BITPOS (f[0]) % alignment;
d8734c88 4050
e9bb382b
UW
4051 if (left)
4052 {
f41f5e61 4053 SET_FIELD_BITPOS (f[0], FIELD_BITPOS (f[0]) + (alignment - left));
86c3c1fc 4054 TYPE_LENGTH (t) += (alignment - left) / TARGET_CHAR_BIT;
e9bb382b
UW
4055 }
4056 }
4057 }
4058 }
4059}
4060
4061/* Add new field with name NAME and type FIELD to composite type T. */
5212577a 4062
e9bb382b
UW
4063void
4064append_composite_type_field (struct type *t, char *name,
4065 struct type *field)
4066{
4067 append_composite_type_field_aligned (t, name, field, 0);
4068}
4069
000177f0
AC
4070static struct gdbarch_data *gdbtypes_data;
4071
4072const struct builtin_type *
4073builtin_type (struct gdbarch *gdbarch)
4074{
4075 return gdbarch_data (gdbarch, gdbtypes_data);
4076}
4077
4078static void *
4079gdbtypes_post_init (struct gdbarch *gdbarch)
4080{
4081 struct builtin_type *builtin_type
4082 = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_type);
4083
46bf5051 4084 /* Basic types. */
e9bb382b
UW
4085 builtin_type->builtin_void
4086 = arch_type (gdbarch, TYPE_CODE_VOID, 1, "void");
4087 builtin_type->builtin_char
4088 = arch_integer_type (gdbarch, TARGET_CHAR_BIT,
4089 !gdbarch_char_signed (gdbarch), "char");
4090 builtin_type->builtin_signed_char
4091 = arch_integer_type (gdbarch, TARGET_CHAR_BIT,
4092 0, "signed char");
4093 builtin_type->builtin_unsigned_char
4094 = arch_integer_type (gdbarch, TARGET_CHAR_BIT,
4095 1, "unsigned char");
4096 builtin_type->builtin_short
4097 = arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch),
4098 0, "short");
4099 builtin_type->builtin_unsigned_short
4100 = arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch),
4101 1, "unsigned short");
4102 builtin_type->builtin_int
4103 = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
4104 0, "int");
4105 builtin_type->builtin_unsigned_int
4106 = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
4107 1, "unsigned int");
4108 builtin_type->builtin_long
4109 = arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch),
4110 0, "long");
4111 builtin_type->builtin_unsigned_long
4112 = arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch),
4113 1, "unsigned long");
4114 builtin_type->builtin_long_long
4115 = arch_integer_type (gdbarch, gdbarch_long_long_bit (gdbarch),
4116 0, "long long");
4117 builtin_type->builtin_unsigned_long_long
4118 = arch_integer_type (gdbarch, gdbarch_long_long_bit (gdbarch),
4119 1, "unsigned long long");
70bd8e24 4120 builtin_type->builtin_float
e9bb382b 4121 = arch_float_type (gdbarch, gdbarch_float_bit (gdbarch),
27067745 4122 "float", gdbarch_float_format (gdbarch));
70bd8e24 4123 builtin_type->builtin_double
e9bb382b 4124 = arch_float_type (gdbarch, gdbarch_double_bit (gdbarch),
27067745 4125 "double", gdbarch_double_format (gdbarch));
70bd8e24 4126 builtin_type->builtin_long_double
e9bb382b 4127 = arch_float_type (gdbarch, gdbarch_long_double_bit (gdbarch),
27067745 4128 "long double", gdbarch_long_double_format (gdbarch));
70bd8e24 4129 builtin_type->builtin_complex
e9bb382b
UW
4130 = arch_complex_type (gdbarch, "complex",
4131 builtin_type->builtin_float);
70bd8e24 4132 builtin_type->builtin_double_complex
e9bb382b
UW
4133 = arch_complex_type (gdbarch, "double complex",
4134 builtin_type->builtin_double);
4135 builtin_type->builtin_string
4136 = arch_type (gdbarch, TYPE_CODE_STRING, 1, "string");
4137 builtin_type->builtin_bool
4138 = arch_type (gdbarch, TYPE_CODE_BOOL, 1, "bool");
000177f0 4139
7678ef8f
TJB
4140 /* The following three are about decimal floating point types, which
4141 are 32-bits, 64-bits and 128-bits respectively. */
4142 builtin_type->builtin_decfloat
e9bb382b 4143 = arch_type (gdbarch, TYPE_CODE_DECFLOAT, 32 / 8, "_Decimal32");
7678ef8f 4144 builtin_type->builtin_decdouble
e9bb382b 4145 = arch_type (gdbarch, TYPE_CODE_DECFLOAT, 64 / 8, "_Decimal64");
7678ef8f 4146 builtin_type->builtin_declong
e9bb382b 4147 = arch_type (gdbarch, TYPE_CODE_DECFLOAT, 128 / 8, "_Decimal128");
7678ef8f 4148
69feb676 4149 /* "True" character types. */
e9bb382b
UW
4150 builtin_type->builtin_true_char
4151 = arch_character_type (gdbarch, TARGET_CHAR_BIT, 0, "true character");
4152 builtin_type->builtin_true_unsigned_char
4153 = arch_character_type (gdbarch, TARGET_CHAR_BIT, 1, "true character");
69feb676 4154
df4df182 4155 /* Fixed-size integer types. */
e9bb382b
UW
4156 builtin_type->builtin_int0
4157 = arch_integer_type (gdbarch, 0, 0, "int0_t");
4158 builtin_type->builtin_int8
4159 = arch_integer_type (gdbarch, 8, 0, "int8_t");
4160 builtin_type->builtin_uint8
4161 = arch_integer_type (gdbarch, 8, 1, "uint8_t");
4162 builtin_type->builtin_int16
4163 = arch_integer_type (gdbarch, 16, 0, "int16_t");
4164 builtin_type->builtin_uint16
4165 = arch_integer_type (gdbarch, 16, 1, "uint16_t");
4166 builtin_type->builtin_int32
4167 = arch_integer_type (gdbarch, 32, 0, "int32_t");
4168 builtin_type->builtin_uint32
4169 = arch_integer_type (gdbarch, 32, 1, "uint32_t");
4170 builtin_type->builtin_int64
4171 = arch_integer_type (gdbarch, 64, 0, "int64_t");
4172 builtin_type->builtin_uint64
4173 = arch_integer_type (gdbarch, 64, 1, "uint64_t");
4174 builtin_type->builtin_int128
4175 = arch_integer_type (gdbarch, 128, 0, "int128_t");
4176 builtin_type->builtin_uint128
4177 = arch_integer_type (gdbarch, 128, 1, "uint128_t");
2844d6b5
KW
4178 TYPE_INSTANCE_FLAGS (builtin_type->builtin_int8) |=
4179 TYPE_INSTANCE_FLAG_NOTTEXT;
4180 TYPE_INSTANCE_FLAGS (builtin_type->builtin_uint8) |=
4181 TYPE_INSTANCE_FLAG_NOTTEXT;
df4df182 4182
9a22f0d0
PM
4183 /* Wide character types. */
4184 builtin_type->builtin_char16
4185 = arch_integer_type (gdbarch, 16, 0, "char16_t");
4186 builtin_type->builtin_char32
4187 = arch_integer_type (gdbarch, 32, 0, "char32_t");
4188
4189
46bf5051 4190 /* Default data/code pointer types. */
e9bb382b
UW
4191 builtin_type->builtin_data_ptr
4192 = lookup_pointer_type (builtin_type->builtin_void);
4193 builtin_type->builtin_func_ptr
4194 = lookup_pointer_type (lookup_function_type (builtin_type->builtin_void));
0875794a
JK
4195 builtin_type->builtin_func_func
4196 = lookup_function_type (builtin_type->builtin_func_ptr);
46bf5051 4197
78267919 4198 /* This type represents a GDB internal function. */
e9bb382b
UW
4199 builtin_type->internal_fn
4200 = arch_type (gdbarch, TYPE_CODE_INTERNAL_FUNCTION, 0,
4201 "<internal function>");
78267919 4202
46bf5051
UW
4203 return builtin_type;
4204}
4205
46bf5051
UW
4206/* This set of objfile-based types is intended to be used by symbol
4207 readers as basic types. */
4208
4209static const struct objfile_data *objfile_type_data;
4210
4211const struct objfile_type *
4212objfile_type (struct objfile *objfile)
4213{
4214 struct gdbarch *gdbarch;
4215 struct objfile_type *objfile_type
4216 = objfile_data (objfile, objfile_type_data);
4217
4218 if (objfile_type)
4219 return objfile_type;
4220
4221 objfile_type = OBSTACK_CALLOC (&objfile->objfile_obstack,
4222 1, struct objfile_type);
4223
4224 /* Use the objfile architecture to determine basic type properties. */
4225 gdbarch = get_objfile_arch (objfile);
4226
4227 /* Basic types. */
4228 objfile_type->builtin_void
4229 = init_type (TYPE_CODE_VOID, 1,
4230 0,
4231 "void", objfile);
4232
4233 objfile_type->builtin_char
4234 = init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
4235 (TYPE_FLAG_NOSIGN
4236 | (gdbarch_char_signed (gdbarch) ? 0 : TYPE_FLAG_UNSIGNED)),
4237 "char", objfile);
4238 objfile_type->builtin_signed_char
4239 = init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
4240 0,
4241 "signed char", objfile);
4242 objfile_type->builtin_unsigned_char
4243 = init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
4244 TYPE_FLAG_UNSIGNED,
4245 "unsigned char", objfile);
4246 objfile_type->builtin_short
4247 = init_type (TYPE_CODE_INT,
4248 gdbarch_short_bit (gdbarch) / TARGET_CHAR_BIT,
4249 0, "short", objfile);
4250 objfile_type->builtin_unsigned_short
4251 = init_type (TYPE_CODE_INT,
4252 gdbarch_short_bit (gdbarch) / TARGET_CHAR_BIT,
4253 TYPE_FLAG_UNSIGNED, "unsigned short", objfile);
4254 objfile_type->builtin_int
4255 = init_type (TYPE_CODE_INT,
4256 gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT,
4257 0, "int", objfile);
4258 objfile_type->builtin_unsigned_int
4259 = init_type (TYPE_CODE_INT,
4260 gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT,
4261 TYPE_FLAG_UNSIGNED, "unsigned int", objfile);
4262 objfile_type->builtin_long
4263 = init_type (TYPE_CODE_INT,
4264 gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT,
4265 0, "long", objfile);
4266 objfile_type->builtin_unsigned_long
4267 = init_type (TYPE_CODE_INT,
4268 gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT,
4269 TYPE_FLAG_UNSIGNED, "unsigned long", objfile);
4270 objfile_type->builtin_long_long
4271 = init_type (TYPE_CODE_INT,
4272 gdbarch_long_long_bit (gdbarch) / TARGET_CHAR_BIT,
4273 0, "long long", objfile);
4274 objfile_type->builtin_unsigned_long_long
4275 = init_type (TYPE_CODE_INT,
4276 gdbarch_long_long_bit (gdbarch) / TARGET_CHAR_BIT,
4277 TYPE_FLAG_UNSIGNED, "unsigned long long", objfile);
4278
4279 objfile_type->builtin_float
4280 = init_type (TYPE_CODE_FLT,
4281 gdbarch_float_bit (gdbarch) / TARGET_CHAR_BIT,
4282 0, "float", objfile);
4283 TYPE_FLOATFORMAT (objfile_type->builtin_float)
4284 = gdbarch_float_format (gdbarch);
4285 objfile_type->builtin_double
4286 = init_type (TYPE_CODE_FLT,
4287 gdbarch_double_bit (gdbarch) / TARGET_CHAR_BIT,
4288 0, "double", objfile);
4289 TYPE_FLOATFORMAT (objfile_type->builtin_double)
4290 = gdbarch_double_format (gdbarch);
4291 objfile_type->builtin_long_double
4292 = init_type (TYPE_CODE_FLT,
4293 gdbarch_long_double_bit (gdbarch) / TARGET_CHAR_BIT,
4294 0, "long double", objfile);
4295 TYPE_FLOATFORMAT (objfile_type->builtin_long_double)
4296 = gdbarch_long_double_format (gdbarch);
4297
4298 /* This type represents a type that was unrecognized in symbol read-in. */
4299 objfile_type->builtin_error
4300 = init_type (TYPE_CODE_ERROR, 0, 0, "<unknown type>", objfile);
4301
4302 /* The following set of types is used for symbols with no
4303 debug information. */
4304 objfile_type->nodebug_text_symbol
4305 = init_type (TYPE_CODE_FUNC, 1, 0,
4306 "<text variable, no debug info>", objfile);
4307 TYPE_TARGET_TYPE (objfile_type->nodebug_text_symbol)
4308 = objfile_type->builtin_int;
0875794a
JK
4309 objfile_type->nodebug_text_gnu_ifunc_symbol
4310 = init_type (TYPE_CODE_FUNC, 1, TYPE_FLAG_GNU_IFUNC,
4311 "<text gnu-indirect-function variable, no debug info>",
4312 objfile);
4313 TYPE_TARGET_TYPE (objfile_type->nodebug_text_gnu_ifunc_symbol)
4314 = objfile_type->nodebug_text_symbol;
4315 objfile_type->nodebug_got_plt_symbol
4316 = init_type (TYPE_CODE_PTR, gdbarch_addr_bit (gdbarch) / 8, 0,
4317 "<text from jump slot in .got.plt, no debug info>",
4318 objfile);
4319 TYPE_TARGET_TYPE (objfile_type->nodebug_got_plt_symbol)
4320 = objfile_type->nodebug_text_symbol;
46bf5051
UW
4321 objfile_type->nodebug_data_symbol
4322 = init_type (TYPE_CODE_INT,
4323 gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT, 0,
4324 "<data variable, no debug info>", objfile);
4325 objfile_type->nodebug_unknown_symbol
4326 = init_type (TYPE_CODE_INT, 1, 0,
4327 "<variable (not text or data), no debug info>", objfile);
4328 objfile_type->nodebug_tls_symbol
4329 = init_type (TYPE_CODE_INT,
4330 gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT, 0,
4331 "<thread local variable, no debug info>", objfile);
000177f0
AC
4332
4333 /* NOTE: on some targets, addresses and pointers are not necessarily
0a7cfe2c 4334 the same.
000177f0
AC
4335
4336 The upshot is:
4337 - gdb's `struct type' always describes the target's
4338 representation.
4339 - gdb's `struct value' objects should always hold values in
4340 target form.
4341 - gdb's CORE_ADDR values are addresses in the unified virtual
4342 address space that the assembler and linker work with. Thus,
4343 since target_read_memory takes a CORE_ADDR as an argument, it
4344 can access any memory on the target, even if the processor has
4345 separate code and data address spaces.
4346
46bf5051
UW
4347 In this context, objfile_type->builtin_core_addr is a bit odd:
4348 it's a target type for a value the target will never see. It's
4349 only used to hold the values of (typeless) linker symbols, which
4350 are indeed in the unified virtual address space. */
000177f0 4351
46bf5051
UW
4352 objfile_type->builtin_core_addr
4353 = init_type (TYPE_CODE_INT,
4354 gdbarch_addr_bit (gdbarch) / 8,
4355 TYPE_FLAG_UNSIGNED, "__CORE_ADDR", objfile);
64c50499 4356
46bf5051
UW
4357 set_objfile_data (objfile, objfile_type_data, objfile_type);
4358 return objfile_type;
000177f0
AC
4359}
4360
5212577a 4361extern initialize_file_ftype _initialize_gdbtypes;
46bf5051 4362
c906108c 4363void
fba45db2 4364_initialize_gdbtypes (void)
c906108c 4365{
5674de60 4366 gdbtypes_data = gdbarch_data_register_post_init (gdbtypes_post_init);
46bf5051 4367 objfile_type_data = register_objfile_data ();
5674de60 4368
ccce17b0
YQ
4369 add_setshow_zuinteger_cmd ("overload", no_class, &overload_debug,
4370 _("Set debugging of C++ overloading."),
4371 _("Show debugging of C++ overloading."),
4372 _("When enabled, ranking of the "
4373 "functions is displayed."),
4374 NULL,
4375 show_overload_debug,
4376 &setdebuglist, &showdebuglist);
5674de60 4377
7ba81444 4378 /* Add user knob for controlling resolution of opaque types. */
5674de60 4379 add_setshow_boolean_cmd ("opaque-type-resolution", class_support,
3e43a32a
MS
4380 &opaque_type_resolution,
4381 _("Set resolution of opaque struct/class/union"
4382 " types (if set before loading symbols)."),
4383 _("Show resolution of opaque struct/class/union"
4384 " types (if set before loading symbols)."),
4385 NULL, NULL,
5674de60
UW
4386 show_opaque_type_resolution,
4387 &setlist, &showlist);
a451cb65
KS
4388
4389 /* Add an option to permit non-strict type checking. */
4390 add_setshow_boolean_cmd ("type", class_support,
4391 &strict_type_checking,
4392 _("Set strict type checking."),
4393 _("Show strict type checking."),
4394 NULL, NULL,
4395 show_strict_type_checking,
4396 &setchecklist, &showchecklist);
c906108c 4397}