]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/gdbtypes.c
* cris-dis.c (format_hex): Remove ineffective warning fix.
[thirdparty/binutils-gdb.git] / gdb / gdbtypes.c
CommitLineData
c906108c 1/* Support routines for manipulating internal types for GDB.
b99607ea
EZ
2 Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003,
3 2004 Free Software Foundation, Inc.
c906108c
SS
4 Contributed by Cygnus Support, using pieces from other GDB modules.
5
c5aa993b 6 This file is part of GDB.
c906108c 7
c5aa993b
JM
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
c906108c 12
c5aa993b
JM
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
c906108c 17
c5aa993b
JM
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
c906108c
SS
22
23#include "defs.h"
24#include "gdb_string.h"
25#include "bfd.h"
26#include "symtab.h"
27#include "symfile.h"
28#include "objfiles.h"
29#include "gdbtypes.h"
30#include "expression.h"
31#include "language.h"
32#include "target.h"
33#include "value.h"
34#include "demangle.h"
35#include "complaints.h"
36#include "gdbcmd.h"
c91ecb25 37#include "wrapper.h"
015a42b4 38#include "cp-abi.h"
a02fd225 39#include "gdb_assert.h"
c906108c
SS
40
41/* These variables point to the objects
42 representing the predefined C data types. */
43
44struct type *builtin_type_void;
45struct type *builtin_type_char;
9e0b60a8 46struct type *builtin_type_true_char;
c906108c
SS
47struct type *builtin_type_short;
48struct type *builtin_type_int;
49struct type *builtin_type_long;
50struct type *builtin_type_long_long;
51struct type *builtin_type_signed_char;
52struct type *builtin_type_unsigned_char;
53struct type *builtin_type_unsigned_short;
54struct type *builtin_type_unsigned_int;
55struct type *builtin_type_unsigned_long;
56struct type *builtin_type_unsigned_long_long;
57struct type *builtin_type_float;
58struct type *builtin_type_double;
59struct type *builtin_type_long_double;
60struct type *builtin_type_complex;
61struct type *builtin_type_double_complex;
62struct type *builtin_type_string;
449a5da4 63struct type *builtin_type_int0;
c906108c
SS
64struct type *builtin_type_int8;
65struct type *builtin_type_uint8;
66struct type *builtin_type_int16;
67struct type *builtin_type_uint16;
68struct type *builtin_type_int32;
69struct type *builtin_type_uint32;
70struct type *builtin_type_int64;
71struct type *builtin_type_uint64;
8b982acf
EZ
72struct type *builtin_type_int128;
73struct type *builtin_type_uint128;
c906108c 74struct type *builtin_type_bool;
ac3aafc7
EZ
75
76/* 128 bit long vector types */
3139facc 77struct type *builtin_type_v2_double;
ac3aafc7 78struct type *builtin_type_v4_float;
3139facc 79struct type *builtin_type_v2_int64;
ac3aafc7
EZ
80struct type *builtin_type_v4_int32;
81struct type *builtin_type_v8_int16;
82struct type *builtin_type_v16_int8;
83/* 64 bit long vector types */
6599f021 84struct type *builtin_type_v2_float;
ac3aafc7
EZ
85struct type *builtin_type_v2_int32;
86struct type *builtin_type_v4_int16;
87struct type *builtin_type_v8_int8;
88
917317f4 89struct type *builtin_type_v4sf;
c2d11a7d 90struct type *builtin_type_v4si;
08cf96df 91struct type *builtin_type_v16qi;
c2d11a7d 92struct type *builtin_type_v8qi;
08cf96df 93struct type *builtin_type_v8hi;
c2d11a7d
JM
94struct type *builtin_type_v4hi;
95struct type *builtin_type_v2si;
b063e7a2
AC
96struct type *builtin_type_vec64;
97struct type *builtin_type_vec64i;
08cf96df 98struct type *builtin_type_vec128;
3139facc 99struct type *builtin_type_vec128i;
5ef2d0aa 100struct type *builtin_type_ieee_single[BFD_ENDIAN_UNKNOWN];
598f52df
AC
101struct type *builtin_type_ieee_single_big;
102struct type *builtin_type_ieee_single_little;
5ef2d0aa 103struct type *builtin_type_ieee_double[BFD_ENDIAN_UNKNOWN];
598f52df
AC
104struct type *builtin_type_ieee_double_big;
105struct type *builtin_type_ieee_double_little;
106struct type *builtin_type_ieee_double_littlebyte_bigword;
107struct type *builtin_type_i387_ext;
108struct type *builtin_type_m68881_ext;
109struct type *builtin_type_i960_ext;
110struct type *builtin_type_m88110_ext;
111struct type *builtin_type_m88110_harris_ext;
5ef2d0aa 112struct type *builtin_type_arm_ext[BFD_ENDIAN_UNKNOWN];
598f52df
AC
113struct type *builtin_type_arm_ext_big;
114struct type *builtin_type_arm_ext_littlebyte_bigword;
5ef2d0aa 115struct type *builtin_type_ia64_spill[BFD_ENDIAN_UNKNOWN];
598f52df
AC
116struct type *builtin_type_ia64_spill_big;
117struct type *builtin_type_ia64_spill_little;
5ef2d0aa 118struct type *builtin_type_ia64_quad[BFD_ENDIAN_UNKNOWN];
598f52df
AC
119struct type *builtin_type_ia64_quad_big;
120struct type *builtin_type_ia64_quad_little;
090a2205 121struct type *builtin_type_void_data_ptr;
ee3a7b7f 122struct type *builtin_type_void_func_ptr;
c4093a6a
JM
123struct type *builtin_type_CORE_ADDR;
124struct type *builtin_type_bfd_vma;
c906108c
SS
125
126int opaque_type_resolution = 1;
5d161b24 127int overload_debug = 0;
c906108c 128
c5aa993b
JM
129struct extra
130 {
131 char str[128];
132 int len;
8c990f3c 133 }; /* maximum extension is 128! FIXME */
c906108c 134
a14ed312 135static void print_bit_vector (B_TYPE *, int);
ad2f7632 136static void print_arg_types (struct field *, int, int);
a14ed312
KB
137static void dump_fn_fieldlists (struct type *, int);
138static void print_cplus_stuff (struct type *, int);
139static void virtual_base_list_aux (struct type *dclass);
7a292a7a 140
c906108c
SS
141
142/* Alloc a new type structure and fill it with some defaults. If
143 OBJFILE is non-NULL, then allocate the space for the type structure
b99607ea 144 in that objfile's objfile_obstack. Otherwise allocate the new type structure
2fdde8f8 145 by xmalloc () (for permanent types). */
c906108c
SS
146
147struct type *
fba45db2 148alloc_type (struct objfile *objfile)
c906108c 149{
52f0bd74 150 struct type *type;
c906108c
SS
151
152 /* Alloc the structure and start off with all fields zeroed. */
153
154 if (objfile == NULL)
155 {
2fdde8f8
DJ
156 type = xmalloc (sizeof (struct type));
157 memset (type, 0, sizeof (struct type));
158 TYPE_MAIN_TYPE (type) = xmalloc (sizeof (struct main_type));
c906108c
SS
159 }
160 else
161 {
b99607ea 162 type = obstack_alloc (&objfile->objfile_obstack,
2fdde8f8
DJ
163 sizeof (struct type));
164 memset (type, 0, sizeof (struct type));
b99607ea 165 TYPE_MAIN_TYPE (type) = obstack_alloc (&objfile->objfile_obstack,
2fdde8f8 166 sizeof (struct main_type));
c906108c
SS
167 OBJSTAT (objfile, n_types++);
168 }
2fdde8f8 169 memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type));
c906108c
SS
170
171 /* Initialize the fields that might not be zero. */
172
173 TYPE_CODE (type) = TYPE_CODE_UNDEF;
174 TYPE_OBJFILE (type) = objfile;
175 TYPE_VPTR_FIELDNO (type) = -1;
2fdde8f8 176 TYPE_CHAIN (type) = type; /* Chain back to itself. */
c906108c
SS
177
178 return (type);
179}
180
2fdde8f8
DJ
181/* Alloc a new type instance structure, fill it with some defaults,
182 and point it at OLDTYPE. Allocate the new type instance from the
183 same place as OLDTYPE. */
184
185static struct type *
186alloc_type_instance (struct type *oldtype)
187{
188 struct type *type;
189
190 /* Allocate the structure. */
191
192 if (TYPE_OBJFILE (oldtype) == NULL)
193 {
194 type = xmalloc (sizeof (struct type));
195 memset (type, 0, sizeof (struct type));
196 }
197 else
198 {
b99607ea 199 type = obstack_alloc (&TYPE_OBJFILE (oldtype)->objfile_obstack,
2fdde8f8
DJ
200 sizeof (struct type));
201 memset (type, 0, sizeof (struct type));
202 }
203 TYPE_MAIN_TYPE (type) = TYPE_MAIN_TYPE (oldtype);
204
205 TYPE_CHAIN (type) = type; /* Chain back to itself for now. */
206
207 return (type);
208}
209
210/* Clear all remnants of the previous type at TYPE, in preparation for
211 replacing it with something else. */
212static void
213smash_type (struct type *type)
214{
215 memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type));
216
217 /* For now, delete the rings. */
218 TYPE_CHAIN (type) = type;
219
220 /* For now, leave the pointer/reference types alone. */
221}
222
c906108c
SS
223/* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
224 to a pointer to memory where the pointer type should be stored.
225 If *TYPEPTR is zero, update it to point to the pointer type we return.
226 We allocate new memory if needed. */
227
228struct type *
fba45db2 229make_pointer_type (struct type *type, struct type **typeptr)
c906108c 230{
52f0bd74 231 struct type *ntype; /* New type */
c906108c
SS
232 struct objfile *objfile;
233
234 ntype = TYPE_POINTER_TYPE (type);
235
c5aa993b 236 if (ntype)
c906108c 237 {
c5aa993b
JM
238 if (typeptr == 0)
239 return ntype; /* Don't care about alloc, and have new type. */
c906108c 240 else if (*typeptr == 0)
c5aa993b 241 {
c906108c
SS
242 *typeptr = ntype; /* Tracking alloc, and we have new type. */
243 return ntype;
c5aa993b 244 }
c906108c
SS
245 }
246
247 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
248 {
249 ntype = alloc_type (TYPE_OBJFILE (type));
250 if (typeptr)
251 *typeptr = ntype;
252 }
c5aa993b
JM
253 else
254 /* We have storage, but need to reset it. */
c906108c
SS
255 {
256 ntype = *typeptr;
257 objfile = TYPE_OBJFILE (ntype);
2fdde8f8 258 smash_type (ntype);
c906108c
SS
259 TYPE_OBJFILE (ntype) = objfile;
260 }
261
262 TYPE_TARGET_TYPE (ntype) = type;
263 TYPE_POINTER_TYPE (type) = ntype;
264
265 /* FIXME! Assume the machine has only one representation for pointers! */
266
267 TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
268 TYPE_CODE (ntype) = TYPE_CODE_PTR;
269
67b2adb2
AC
270 /* Mark pointers as unsigned. The target converts between pointers
271 and addresses (CORE_ADDRs) using POINTER_TO_ADDRESS() and
272 ADDRESS_TO_POINTER(). */
c906108c 273 TYPE_FLAGS (ntype) |= TYPE_FLAG_UNSIGNED;
c5aa993b 274
c906108c
SS
275 if (!TYPE_POINTER_TYPE (type)) /* Remember it, if don't have one. */
276 TYPE_POINTER_TYPE (type) = ntype;
277
278 return ntype;
279}
280
281/* Given a type TYPE, return a type of pointers to that type.
282 May need to construct such a type if this is the first use. */
283
284struct type *
fba45db2 285lookup_pointer_type (struct type *type)
c906108c 286{
c5aa993b 287 return make_pointer_type (type, (struct type **) 0);
c906108c
SS
288}
289
290/* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero, points
291 to a pointer to memory where the reference type should be stored.
292 If *TYPEPTR is zero, update it to point to the reference type we return.
293 We allocate new memory if needed. */
294
295struct type *
fba45db2 296make_reference_type (struct type *type, struct type **typeptr)
c906108c 297{
52f0bd74 298 struct type *ntype; /* New type */
c906108c
SS
299 struct objfile *objfile;
300
301 ntype = TYPE_REFERENCE_TYPE (type);
302
c5aa993b 303 if (ntype)
c906108c 304 {
c5aa993b
JM
305 if (typeptr == 0)
306 return ntype; /* Don't care about alloc, and have new type. */
c906108c 307 else if (*typeptr == 0)
c5aa993b 308 {
c906108c
SS
309 *typeptr = ntype; /* Tracking alloc, and we have new type. */
310 return ntype;
c5aa993b 311 }
c906108c
SS
312 }
313
314 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
315 {
316 ntype = alloc_type (TYPE_OBJFILE (type));
317 if (typeptr)
318 *typeptr = ntype;
319 }
c5aa993b
JM
320 else
321 /* We have storage, but need to reset it. */
c906108c
SS
322 {
323 ntype = *typeptr;
324 objfile = TYPE_OBJFILE (ntype);
2fdde8f8 325 smash_type (ntype);
c906108c
SS
326 TYPE_OBJFILE (ntype) = objfile;
327 }
328
329 TYPE_TARGET_TYPE (ntype) = type;
330 TYPE_REFERENCE_TYPE (type) = ntype;
331
332 /* FIXME! Assume the machine has only one representation for references,
333 and that it matches the (only) representation for pointers! */
334
335 TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
336 TYPE_CODE (ntype) = TYPE_CODE_REF;
c5aa993b 337
c906108c
SS
338 if (!TYPE_REFERENCE_TYPE (type)) /* Remember it, if don't have one. */
339 TYPE_REFERENCE_TYPE (type) = ntype;
340
341 return ntype;
342}
343
344/* Same as above, but caller doesn't care about memory allocation details. */
345
346struct type *
fba45db2 347lookup_reference_type (struct type *type)
c906108c 348{
c5aa993b 349 return make_reference_type (type, (struct type **) 0);
c906108c
SS
350}
351
352/* Lookup a function type that returns type TYPE. TYPEPTR, if nonzero, points
353 to a pointer to memory where the function type should be stored.
354 If *TYPEPTR is zero, update it to point to the function type we return.
355 We allocate new memory if needed. */
356
357struct type *
fba45db2 358make_function_type (struct type *type, struct type **typeptr)
c906108c 359{
52f0bd74 360 struct type *ntype; /* New type */
c906108c
SS
361 struct objfile *objfile;
362
363 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
364 {
365 ntype = alloc_type (TYPE_OBJFILE (type));
366 if (typeptr)
367 *typeptr = ntype;
368 }
c5aa993b
JM
369 else
370 /* We have storage, but need to reset it. */
c906108c
SS
371 {
372 ntype = *typeptr;
373 objfile = TYPE_OBJFILE (ntype);
2fdde8f8 374 smash_type (ntype);
c906108c
SS
375 TYPE_OBJFILE (ntype) = objfile;
376 }
377
378 TYPE_TARGET_TYPE (ntype) = type;
379
380 TYPE_LENGTH (ntype) = 1;
381 TYPE_CODE (ntype) = TYPE_CODE_FUNC;
c5aa993b 382
c906108c
SS
383 return ntype;
384}
385
386
387/* Given a type TYPE, return a type of functions that return that type.
388 May need to construct such a type if this is the first use. */
389
390struct type *
fba45db2 391lookup_function_type (struct type *type)
c906108c 392{
c5aa993b 393 return make_function_type (type, (struct type **) 0);
c906108c
SS
394}
395
47663de5
MS
396/* Identify address space identifier by name --
397 return the integer flag defined in gdbtypes.h. */
398extern int
399address_space_name_to_int (char *space_identifier)
400{
5f11f355 401 struct gdbarch *gdbarch = current_gdbarch;
8b2dbe47 402 int type_flags;
47663de5
MS
403 /* Check for known address space delimiters. */
404 if (!strcmp (space_identifier, "code"))
405 return TYPE_FLAG_CODE_SPACE;
406 else if (!strcmp (space_identifier, "data"))
407 return TYPE_FLAG_DATA_SPACE;
5f11f355
AC
408 else if (gdbarch_address_class_name_to_type_flags_p (gdbarch)
409 && gdbarch_address_class_name_to_type_flags (gdbarch,
410 space_identifier,
411 &type_flags))
8b2dbe47 412 return type_flags;
47663de5 413 else
8a3fe4f8 414 error (_("Unknown address space specifier: \"%s\""), space_identifier);
47663de5
MS
415}
416
417/* Identify address space identifier by integer flag as defined in
418 gdbtypes.h -- return the string version of the adress space name. */
419
321432c0 420const char *
47663de5
MS
421address_space_int_to_name (int space_flag)
422{
5f11f355 423 struct gdbarch *gdbarch = current_gdbarch;
47663de5
MS
424 if (space_flag & TYPE_FLAG_CODE_SPACE)
425 return "code";
426 else if (space_flag & TYPE_FLAG_DATA_SPACE)
427 return "data";
8b2dbe47 428 else if ((space_flag & TYPE_FLAG_ADDRESS_CLASS_ALL)
5f11f355
AC
429 && gdbarch_address_class_type_flags_to_name_p (gdbarch))
430 return gdbarch_address_class_type_flags_to_name (gdbarch, space_flag);
47663de5
MS
431 else
432 return NULL;
433}
434
2fdde8f8 435/* Create a new type with instance flags NEW_FLAGS, based on TYPE.
ad766c0a
JB
436
437 If STORAGE is non-NULL, create the new type instance there.
438 STORAGE must be in the same obstack as TYPE. */
47663de5 439
b9362cc7 440static struct type *
2fdde8f8
DJ
441make_qualified_type (struct type *type, int new_flags,
442 struct type *storage)
47663de5
MS
443{
444 struct type *ntype;
445
446 ntype = type;
447 do {
2fdde8f8 448 if (TYPE_INSTANCE_FLAGS (ntype) == new_flags)
47663de5 449 return ntype;
2fdde8f8 450 ntype = TYPE_CHAIN (ntype);
47663de5
MS
451 } while (ntype != type);
452
2fdde8f8
DJ
453 /* Create a new type instance. */
454 if (storage == NULL)
455 ntype = alloc_type_instance (type);
456 else
457 {
ad766c0a
JB
458 /* If STORAGE was provided, it had better be in the same objfile as
459 TYPE. Otherwise, we can't link it into TYPE's cv chain: if one
460 objfile is freed and the other kept, we'd have dangling
461 pointers. */
462 gdb_assert (TYPE_OBJFILE (type) == TYPE_OBJFILE (storage));
463
2fdde8f8
DJ
464 ntype = storage;
465 TYPE_MAIN_TYPE (ntype) = TYPE_MAIN_TYPE (type);
466 TYPE_CHAIN (ntype) = ntype;
467 }
47663de5
MS
468
469 /* Pointers or references to the original type are not relevant to
2fdde8f8 470 the new type. */
47663de5
MS
471 TYPE_POINTER_TYPE (ntype) = (struct type *) 0;
472 TYPE_REFERENCE_TYPE (ntype) = (struct type *) 0;
47663de5 473
2fdde8f8
DJ
474 /* Chain the new qualified type to the old type. */
475 TYPE_CHAIN (ntype) = TYPE_CHAIN (type);
476 TYPE_CHAIN (type) = ntype;
477
478 /* Now set the instance flags and return the new type. */
479 TYPE_INSTANCE_FLAGS (ntype) = new_flags;
47663de5 480
ab5d3da6
KB
481 /* Set length of new type to that of the original type. */
482 TYPE_LENGTH (ntype) = TYPE_LENGTH (type);
483
47663de5
MS
484 return ntype;
485}
486
2fdde8f8
DJ
487/* Make an address-space-delimited variant of a type -- a type that
488 is identical to the one supplied except that it has an address
489 space attribute attached to it (such as "code" or "data").
490
8b2dbe47
KB
491 The space attributes "code" and "data" are for Harvard architectures.
492 The address space attributes are for architectures which have
493 alternately sized pointers or pointers with alternate representations. */
2fdde8f8
DJ
494
495struct type *
496make_type_with_address_space (struct type *type, int space_flag)
497{
498 struct type *ntype;
499 int new_flags = ((TYPE_INSTANCE_FLAGS (type)
8b2dbe47
KB
500 & ~(TYPE_FLAG_CODE_SPACE | TYPE_FLAG_DATA_SPACE
501 | TYPE_FLAG_ADDRESS_CLASS_ALL))
2fdde8f8
DJ
502 | space_flag);
503
504 return make_qualified_type (type, new_flags, NULL);
505}
c906108c
SS
506
507/* Make a "c-v" variant of a type -- a type that is identical to the
508 one supplied except that it may have const or volatile attributes
509 CNST is a flag for setting the const attribute
510 VOLTL is a flag for setting the volatile attribute
511 TYPE is the base type whose variant we are creating.
c906108c 512
ad766c0a
JB
513 If TYPEPTR and *TYPEPTR are non-zero, then *TYPEPTR points to
514 storage to hold the new qualified type; *TYPEPTR and TYPE must be
515 in the same objfile. Otherwise, allocate fresh memory for the new
516 type whereever TYPE lives. If TYPEPTR is non-zero, set it to the
517 new type we construct. */
c906108c 518struct type *
fba45db2 519make_cv_type (int cnst, int voltl, struct type *type, struct type **typeptr)
c906108c 520{
52f0bd74
AC
521 struct type *ntype; /* New type */
522 struct type *tmp_type = type; /* tmp type */
c906108c
SS
523 struct objfile *objfile;
524
2fdde8f8
DJ
525 int new_flags = (TYPE_INSTANCE_FLAGS (type)
526 & ~(TYPE_FLAG_CONST | TYPE_FLAG_VOLATILE));
c906108c 527
c906108c 528 if (cnst)
2fdde8f8 529 new_flags |= TYPE_FLAG_CONST;
c906108c
SS
530
531 if (voltl)
2fdde8f8 532 new_flags |= TYPE_FLAG_VOLATILE;
a02fd225 533
2fdde8f8 534 if (typeptr && *typeptr != NULL)
a02fd225 535 {
ad766c0a
JB
536 /* TYPE and *TYPEPTR must be in the same objfile. We can't have
537 a C-V variant chain that threads across objfiles: if one
538 objfile gets freed, then the other has a broken C-V chain.
539
540 This code used to try to copy over the main type from TYPE to
541 *TYPEPTR if they were in different objfiles, but that's
542 wrong, too: TYPE may have a field list or member function
543 lists, which refer to types of their own, etc. etc. The
544 whole shebang would need to be copied over recursively; you
545 can't have inter-objfile pointers. The only thing to do is
546 to leave stub types as stub types, and look them up afresh by
547 name each time you encounter them. */
548 gdb_assert (TYPE_OBJFILE (*typeptr) == TYPE_OBJFILE (type));
2fdde8f8
DJ
549 }
550
551 ntype = make_qualified_type (type, new_flags, typeptr ? *typeptr : NULL);
c906108c 552
2fdde8f8
DJ
553 if (typeptr != NULL)
554 *typeptr = ntype;
a02fd225 555
2fdde8f8 556 return ntype;
a02fd225 557}
c906108c 558
2fdde8f8
DJ
559/* Replace the contents of ntype with the type *type. This changes the
560 contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus
561 the changes are propogated to all types in the TYPE_CHAIN.
dd6bda65 562
cda6c68a
JB
563 In order to build recursive types, it's inevitable that we'll need
564 to update types in place --- but this sort of indiscriminate
565 smashing is ugly, and needs to be replaced with something more
2fdde8f8
DJ
566 controlled. TYPE_MAIN_TYPE is a step in this direction; it's not
567 clear if more steps are needed. */
dd6bda65
DJ
568void
569replace_type (struct type *ntype, struct type *type)
570{
ab5d3da6 571 struct type *chain;
dd6bda65 572
ad766c0a
JB
573 /* These two types had better be in the same objfile. Otherwise,
574 the assignment of one type's main type structure to the other
575 will produce a type with references to objects (names; field
576 lists; etc.) allocated on an objfile other than its own. */
577 gdb_assert (TYPE_OBJFILE (ntype) == TYPE_OBJFILE (ntype));
578
2fdde8f8 579 *TYPE_MAIN_TYPE (ntype) = *TYPE_MAIN_TYPE (type);
dd6bda65 580
ab5d3da6
KB
581 /* The type length is not a part of the main type. Update it for each
582 type on the variant chain. */
583 chain = ntype;
584 do {
585 /* Assert that this element of the chain has no address-class bits
586 set in its flags. Such type variants might have type lengths
587 which are supposed to be different from the non-address-class
588 variants. This assertion shouldn't ever be triggered because
589 symbol readers which do construct address-class variants don't
590 call replace_type(). */
591 gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain) == 0);
592
593 TYPE_LENGTH (ntype) = TYPE_LENGTH (type);
594 chain = TYPE_CHAIN (chain);
595 } while (ntype != chain);
596
2fdde8f8
DJ
597 /* Assert that the two types have equivalent instance qualifiers.
598 This should be true for at least all of our debug readers. */
599 gdb_assert (TYPE_INSTANCE_FLAGS (ntype) == TYPE_INSTANCE_FLAGS (type));
dd6bda65
DJ
600}
601
c906108c
SS
602/* Implement direct support for MEMBER_TYPE in GNU C++.
603 May need to construct such a type if this is the first use.
604 The TYPE is the type of the member. The DOMAIN is the type
605 of the aggregate that the member belongs to. */
606
607struct type *
fba45db2 608lookup_member_type (struct type *type, struct type *domain)
c906108c 609{
52f0bd74 610 struct type *mtype;
c906108c
SS
611
612 mtype = alloc_type (TYPE_OBJFILE (type));
613 smash_to_member_type (mtype, domain, type);
614 return (mtype);
615}
616
7b83ea04 617/* Allocate a stub method whose return type is TYPE.
c906108c
SS
618 This apparently happens for speed of symbol reading, since parsing
619 out the arguments to the method is cpu-intensive, the way we are doing
620 it. So, we will fill in arguments later.
621 This always returns a fresh type. */
622
623struct type *
fba45db2 624allocate_stub_method (struct type *type)
c906108c
SS
625{
626 struct type *mtype;
627
7e956337
FF
628 mtype = init_type (TYPE_CODE_METHOD, 1, TYPE_FLAG_STUB, NULL,
629 TYPE_OBJFILE (type));
c906108c
SS
630 TYPE_TARGET_TYPE (mtype) = type;
631 /* _DOMAIN_TYPE (mtype) = unknown yet */
c906108c
SS
632 return (mtype);
633}
634
635/* Create a range type using either a blank type supplied in RESULT_TYPE,
636 or creating a new type, inheriting the objfile from INDEX_TYPE.
637
638 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND to
639 HIGH_BOUND, inclusive.
640
641 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
642 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
643
644struct type *
fba45db2
KB
645create_range_type (struct type *result_type, struct type *index_type,
646 int low_bound, int high_bound)
c906108c
SS
647{
648 if (result_type == NULL)
649 {
650 result_type = alloc_type (TYPE_OBJFILE (index_type));
651 }
652 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
653 TYPE_TARGET_TYPE (result_type) = index_type;
74a9bb82 654 if (TYPE_STUB (index_type))
c906108c
SS
655 TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB;
656 else
657 TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
658 TYPE_NFIELDS (result_type) = 2;
659 TYPE_FIELDS (result_type) = (struct field *)
660 TYPE_ALLOC (result_type, 2 * sizeof (struct field));
661 memset (TYPE_FIELDS (result_type), 0, 2 * sizeof (struct field));
662 TYPE_FIELD_BITPOS (result_type, 0) = low_bound;
663 TYPE_FIELD_BITPOS (result_type, 1) = high_bound;
c5aa993b
JM
664 TYPE_FIELD_TYPE (result_type, 0) = builtin_type_int; /* FIXME */
665 TYPE_FIELD_TYPE (result_type, 1) = builtin_type_int; /* FIXME */
c906108c 666
c5aa993b 667 if (low_bound >= 0)
c906108c
SS
668 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
669
670 return (result_type);
671}
672
673/* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type TYPE.
674 Return 1 of type is a range type, 0 if it is discrete (and bounds
675 will fit in LONGEST), or -1 otherwise. */
676
677int
fba45db2 678get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
c906108c
SS
679{
680 CHECK_TYPEDEF (type);
681 switch (TYPE_CODE (type))
682 {
683 case TYPE_CODE_RANGE:
684 *lowp = TYPE_LOW_BOUND (type);
685 *highp = TYPE_HIGH_BOUND (type);
686 return 1;
687 case TYPE_CODE_ENUM:
688 if (TYPE_NFIELDS (type) > 0)
689 {
690 /* The enums may not be sorted by value, so search all
691 entries */
692 int i;
693
694 *lowp = *highp = TYPE_FIELD_BITPOS (type, 0);
695 for (i = 0; i < TYPE_NFIELDS (type); i++)
696 {
697 if (TYPE_FIELD_BITPOS (type, i) < *lowp)
698 *lowp = TYPE_FIELD_BITPOS (type, i);
699 if (TYPE_FIELD_BITPOS (type, i) > *highp)
700 *highp = TYPE_FIELD_BITPOS (type, i);
701 }
702
703 /* Set unsigned indicator if warranted. */
c5aa993b 704 if (*lowp >= 0)
c906108c
SS
705 {
706 TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
707 }
708 }
709 else
710 {
711 *lowp = 0;
712 *highp = -1;
713 }
714 return 0;
715 case TYPE_CODE_BOOL:
716 *lowp = 0;
717 *highp = 1;
718 return 0;
719 case TYPE_CODE_INT:
c5aa993b 720 if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */
c906108c
SS
721 return -1;
722 if (!TYPE_UNSIGNED (type))
723 {
c5aa993b 724 *lowp = -(1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1));
c906108c
SS
725 *highp = -*lowp - 1;
726 return 0;
727 }
728 /* ... fall through for unsigned ints ... */
729 case TYPE_CODE_CHAR:
730 *lowp = 0;
731 /* This round-about calculation is to avoid shifting by
7b83ea04
AC
732 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
733 if TYPE_LENGTH (type) == sizeof (LONGEST). */
c906108c
SS
734 *highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1);
735 *highp = (*highp - 1) | *highp;
736 return 0;
737 default:
738 return -1;
739 }
740}
741
742/* Create an array type using either a blank type supplied in RESULT_TYPE,
743 or creating a new type, inheriting the objfile from RANGE_TYPE.
744
745 Elements will be of type ELEMENT_TYPE, the indices will be of type
746 RANGE_TYPE.
747
748 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
749 sure it is TYPE_CODE_UNDEF before we bash it into an array type? */
750
751struct type *
fba45db2
KB
752create_array_type (struct type *result_type, struct type *element_type,
753 struct type *range_type)
c906108c
SS
754{
755 LONGEST low_bound, high_bound;
756
757 if (result_type == NULL)
758 {
759 result_type = alloc_type (TYPE_OBJFILE (range_type));
760 }
761 TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
762 TYPE_TARGET_TYPE (result_type) = element_type;
763 if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
764 low_bound = high_bound = 0;
765 CHECK_TYPEDEF (element_type);
766 TYPE_LENGTH (result_type) =
767 TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
768 TYPE_NFIELDS (result_type) = 1;
769 TYPE_FIELDS (result_type) =
770 (struct field *) TYPE_ALLOC (result_type, sizeof (struct field));
771 memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
772 TYPE_FIELD_TYPE (result_type, 0) = range_type;
773 TYPE_VPTR_FIELDNO (result_type) = -1;
774
775 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
776 if (TYPE_LENGTH (result_type) == 0)
777 TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB;
778
779 return (result_type);
780}
781
782/* Create a string type using either a blank type supplied in RESULT_TYPE,
783 or creating a new type. String types are similar enough to array of
784 char types that we can use create_array_type to build the basic type
785 and then bash it into a string type.
786
787 For fixed length strings, the range type contains 0 as the lower
788 bound and the length of the string minus one as the upper bound.
789
790 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
791 sure it is TYPE_CODE_UNDEF before we bash it into a string type? */
792
793struct type *
fba45db2 794create_string_type (struct type *result_type, struct type *range_type)
c906108c 795{
f290d38e
AC
796 struct type *string_char_type;
797
798 string_char_type = language_string_char_type (current_language,
799 current_gdbarch);
c906108c 800 result_type = create_array_type (result_type,
f290d38e 801 string_char_type,
c906108c
SS
802 range_type);
803 TYPE_CODE (result_type) = TYPE_CODE_STRING;
804 return (result_type);
805}
806
807struct type *
fba45db2 808create_set_type (struct type *result_type, struct type *domain_type)
c906108c
SS
809{
810 LONGEST low_bound, high_bound, bit_length;
811 if (result_type == NULL)
812 {
813 result_type = alloc_type (TYPE_OBJFILE (domain_type));
814 }
815 TYPE_CODE (result_type) = TYPE_CODE_SET;
816 TYPE_NFIELDS (result_type) = 1;
817 TYPE_FIELDS (result_type) = (struct field *)
818 TYPE_ALLOC (result_type, 1 * sizeof (struct field));
819 memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
820
74a9bb82 821 if (!TYPE_STUB (domain_type))
c906108c
SS
822 {
823 if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0)
824 low_bound = high_bound = 0;
825 bit_length = high_bound - low_bound + 1;
826 TYPE_LENGTH (result_type)
827 = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
828 }
829 TYPE_FIELD_TYPE (result_type, 0) = domain_type;
830
c5aa993b 831 if (low_bound >= 0)
c906108c
SS
832 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
833
834 return (result_type);
835}
836
917317f4
JM
837/* Construct and return a type of the form:
838 struct NAME { ELT_TYPE ELT_NAME[N]; }
839 We use these types for SIMD registers. For example, the type of
840 the SSE registers on the late x86-family processors is:
841 struct __builtin_v4sf { float f[4]; }
842 built by the function call:
843 init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4)
844 The type returned is a permanent type, allocated using malloc; it
845 doesn't live in any objfile's obstack. */
c2d11a7d 846static struct type *
917317f4
JM
847init_simd_type (char *name,
848 struct type *elt_type,
849 char *elt_name,
850 int n)
851{
73d322b1
EZ
852 struct type *simd_type;
853 struct type *array_type;
854
855 simd_type = init_composite_type (name, TYPE_CODE_STRUCT);
856 array_type = create_array_type (0, elt_type,
857 create_range_type (0, builtin_type_int,
858 0, n-1));
859 append_composite_type_field (simd_type, elt_name, array_type);
860 return simd_type;
917317f4
JM
861}
862
ac3aafc7
EZ
863static struct type *
864init_vector_type (struct type *elt_type, int n)
865{
866 struct type *array_type;
867
868 array_type = create_array_type (0, elt_type,
869 create_range_type (0, builtin_type_int,
870 0, n-1));
871 TYPE_FLAGS (array_type) |= TYPE_FLAG_VECTOR;
872 return array_type;
873}
874
b063e7a2
AC
875static struct type *
876build_builtin_type_vec64 (void)
877{
878 /* Construct a type for the 64 bit registers. The type we're
879 building is this: */
880#if 0
881 union __gdb_builtin_type_vec64
882 {
883 int64_t uint64;
884 float v2_float[2];
885 int32_t v2_int32[2];
886 int16_t v4_int16[4];
887 int8_t v8_int8[8];
888 };
889#endif
890
891 struct type *t;
892
893 t = init_composite_type ("__gdb_builtin_type_vec64", TYPE_CODE_UNION);
894 append_composite_type_field (t, "uint64", builtin_type_int64);
895 append_composite_type_field (t, "v2_float", builtin_type_v2_float);
896 append_composite_type_field (t, "v2_int32", builtin_type_v2_int32);
897 append_composite_type_field (t, "v4_int16", builtin_type_v4_int16);
898 append_composite_type_field (t, "v8_int8", builtin_type_v8_int8);
899
900 TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR;
216b504f 901 TYPE_NAME (t) = "builtin_type_vec64";
b063e7a2
AC
902 return t;
903}
904
905static struct type *
906build_builtin_type_vec64i (void)
907{
908 /* Construct a type for the 64 bit registers. The type we're
909 building is this: */
910#if 0
911 union __gdb_builtin_type_vec64i
912 {
913 int64_t uint64;
914 int32_t v2_int32[2];
915 int16_t v4_int16[4];
916 int8_t v8_int8[8];
917 };
918#endif
919
920 struct type *t;
921
922 t = init_composite_type ("__gdb_builtin_type_vec64i", TYPE_CODE_UNION);
923 append_composite_type_field (t, "uint64", builtin_type_int64);
924 append_composite_type_field (t, "v2_int32", builtin_type_v2_int32);
925 append_composite_type_field (t, "v4_int16", builtin_type_v4_int16);
926 append_composite_type_field (t, "v8_int8", builtin_type_v8_int8);
927
928 TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR;
216b504f 929 TYPE_NAME (t) = "builtin_type_vec64i";
b063e7a2
AC
930 return t;
931}
932
08cf96df
EZ
933static struct type *
934build_builtin_type_vec128 (void)
935{
936 /* Construct a type for the 128 bit registers. The type we're
937 building is this: */
938#if 0
ac3aafc7 939 union __gdb_builtin_type_vec128
08cf96df 940 {
ac3aafc7
EZ
941 int128_t uint128;
942 float v4_float[4];
943 int32_t v4_int32[4];
944 int16_t v8_int16[8];
945 int8_t v16_int8[16];
08cf96df
EZ
946 };
947#endif
948
949 struct type *t;
08cf96df 950
73d322b1
EZ
951 t = init_composite_type ("__gdb_builtin_type_vec128", TYPE_CODE_UNION);
952 append_composite_type_field (t, "uint128", builtin_type_int128);
ac3aafc7
EZ
953 append_composite_type_field (t, "v4_float", builtin_type_v4_float);
954 append_composite_type_field (t, "v4_int32", builtin_type_v4_int32);
955 append_composite_type_field (t, "v8_int16", builtin_type_v8_int16);
956 append_composite_type_field (t, "v16_int8", builtin_type_v16_int8);
08cf96df 957
b063e7a2 958 TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR;
216b504f 959 TYPE_NAME (t) = "builtin_type_vec128";
08cf96df
EZ
960 return t;
961}
917317f4 962
3139facc
MH
963static struct type *
964build_builtin_type_vec128i (void)
965{
966 /* 128-bit Intel SIMD registers */
967 struct type *t;
968
969 t = init_composite_type ("__gdb_builtin_type_vec128i", TYPE_CODE_UNION);
970 append_composite_type_field (t, "v4_float", builtin_type_v4_float);
971 append_composite_type_field (t, "v2_double", builtin_type_v2_double);
972 append_composite_type_field (t, "v16_int8", builtin_type_v16_int8);
973 append_composite_type_field (t, "v8_int16", builtin_type_v8_int16);
974 append_composite_type_field (t, "v4_int32", builtin_type_v4_int32);
975 append_composite_type_field (t, "v2_int64", builtin_type_v2_int64);
976 append_composite_type_field (t, "uint128", builtin_type_int128);
977
b063e7a2 978 TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR;
216b504f 979 TYPE_NAME (t) = "builtin_type_vec128i";
3139facc
MH
980 return t;
981}
982
7b83ea04 983/* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE.
c906108c
SS
984 A MEMBER is a wierd thing -- it amounts to a typed offset into
985 a struct, e.g. "an int at offset 8". A MEMBER TYPE doesn't
986 include the offset (that's the value of the MEMBER itself), but does
987 include the structure type into which it points (for some reason).
988
989 When "smashing" the type, we preserve the objfile that the
990 old type pointed to, since we aren't changing where the type is actually
991 allocated. */
992
993void
fba45db2
KB
994smash_to_member_type (struct type *type, struct type *domain,
995 struct type *to_type)
c906108c
SS
996{
997 struct objfile *objfile;
998
999 objfile = TYPE_OBJFILE (type);
1000
2fdde8f8 1001 smash_type (type);
c906108c
SS
1002 TYPE_OBJFILE (type) = objfile;
1003 TYPE_TARGET_TYPE (type) = to_type;
1004 TYPE_DOMAIN_TYPE (type) = domain;
1005 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
1006 TYPE_CODE (type) = TYPE_CODE_MEMBER;
1007}
1008
1009/* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
1010 METHOD just means `function that gets an extra "this" argument'.
1011
1012 When "smashing" the type, we preserve the objfile that the
1013 old type pointed to, since we aren't changing where the type is actually
1014 allocated. */
1015
1016void
fba45db2 1017smash_to_method_type (struct type *type, struct type *domain,
ad2f7632
DJ
1018 struct type *to_type, struct field *args,
1019 int nargs, int varargs)
c906108c
SS
1020{
1021 struct objfile *objfile;
1022
1023 objfile = TYPE_OBJFILE (type);
1024
2fdde8f8 1025 smash_type (type);
c906108c
SS
1026 TYPE_OBJFILE (type) = objfile;
1027 TYPE_TARGET_TYPE (type) = to_type;
1028 TYPE_DOMAIN_TYPE (type) = domain;
ad2f7632
DJ
1029 TYPE_FIELDS (type) = args;
1030 TYPE_NFIELDS (type) = nargs;
1031 if (varargs)
1032 TYPE_FLAGS (type) |= TYPE_FLAG_VARARGS;
c906108c
SS
1033 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
1034 TYPE_CODE (type) = TYPE_CODE_METHOD;
1035}
1036
1037/* Return a typename for a struct/union/enum type without "struct ",
1038 "union ", or "enum ". If the type has a NULL name, return NULL. */
1039
1040char *
aa1ee363 1041type_name_no_tag (const struct type *type)
c906108c
SS
1042{
1043 if (TYPE_TAG_NAME (type) != NULL)
1044 return TYPE_TAG_NAME (type);
1045
1046 /* Is there code which expects this to return the name if there is no
1047 tag name? My guess is that this is mainly used for C++ in cases where
1048 the two will always be the same. */
1049 return TYPE_NAME (type);
1050}
1051
c906108c
SS
1052/* Lookup a typedef or primitive type named NAME,
1053 visible in lexical block BLOCK.
1054 If NOERR is nonzero, return zero if NAME is not suitably defined. */
1055
1056struct type *
fba45db2 1057lookup_typename (char *name, struct block *block, int noerr)
c906108c 1058{
52f0bd74
AC
1059 struct symbol *sym;
1060 struct type *tmp;
c906108c 1061
176620f1 1062 sym = lookup_symbol (name, block, VAR_DOMAIN, 0, (struct symtab **) NULL);
c906108c
SS
1063 if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
1064 {
54a5b07d
AC
1065 tmp = language_lookup_primitive_type_by_name (current_language,
1066 current_gdbarch,
1067 name);
c906108c
SS
1068 if (tmp)
1069 {
1070 return (tmp);
1071 }
1072 else if (!tmp && noerr)
1073 {
1074 return (NULL);
1075 }
1076 else
1077 {
8a3fe4f8 1078 error (_("No type named %s."), name);
c906108c
SS
1079 }
1080 }
1081 return (SYMBOL_TYPE (sym));
1082}
1083
1084struct type *
fba45db2 1085lookup_unsigned_typename (char *name)
c906108c
SS
1086{
1087 char *uns = alloca (strlen (name) + 10);
1088
1089 strcpy (uns, "unsigned ");
1090 strcpy (uns + 9, name);
1091 return (lookup_typename (uns, (struct block *) NULL, 0));
1092}
1093
1094struct type *
fba45db2 1095lookup_signed_typename (char *name)
c906108c
SS
1096{
1097 struct type *t;
1098 char *uns = alloca (strlen (name) + 8);
1099
1100 strcpy (uns, "signed ");
1101 strcpy (uns + 7, name);
1102 t = lookup_typename (uns, (struct block *) NULL, 1);
1103 /* If we don't find "signed FOO" just try again with plain "FOO". */
1104 if (t != NULL)
1105 return t;
1106 return lookup_typename (name, (struct block *) NULL, 0);
1107}
1108
1109/* Lookup a structure type named "struct NAME",
1110 visible in lexical block BLOCK. */
1111
1112struct type *
fba45db2 1113lookup_struct (char *name, struct block *block)
c906108c 1114{
52f0bd74 1115 struct symbol *sym;
c906108c 1116
176620f1 1117 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0,
c906108c
SS
1118 (struct symtab **) NULL);
1119
1120 if (sym == NULL)
1121 {
8a3fe4f8 1122 error (_("No struct type named %s."), name);
c906108c
SS
1123 }
1124 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
1125 {
8a3fe4f8 1126 error (_("This context has class, union or enum %s, not a struct."), name);
c906108c
SS
1127 }
1128 return (SYMBOL_TYPE (sym));
1129}
1130
1131/* Lookup a union type named "union NAME",
1132 visible in lexical block BLOCK. */
1133
1134struct type *
fba45db2 1135lookup_union (char *name, struct block *block)
c906108c 1136{
52f0bd74 1137 struct symbol *sym;
c5aa993b 1138 struct type *t;
c906108c 1139
176620f1 1140 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0,
c906108c
SS
1141 (struct symtab **) NULL);
1142
1143 if (sym == NULL)
8a3fe4f8 1144 error (_("No union type named %s."), name);
c906108c 1145
c5aa993b 1146 t = SYMBOL_TYPE (sym);
c906108c
SS
1147
1148 if (TYPE_CODE (t) == TYPE_CODE_UNION)
1149 return (t);
1150
1151 /* C++ unions may come out with TYPE_CODE_CLASS, but we look at
1152 * a further "declared_type" field to discover it is really a union.
1153 */
c5aa993b
JM
1154 if (HAVE_CPLUS_STRUCT (t))
1155 if (TYPE_DECLARED_TYPE (t) == DECLARED_TYPE_UNION)
c906108c
SS
1156 return (t);
1157
1158 /* If we get here, it's not a union */
8a3fe4f8 1159 error (_("This context has class, struct or enum %s, not a union."), name);
c906108c
SS
1160}
1161
1162
1163/* Lookup an enum type named "enum NAME",
1164 visible in lexical block BLOCK. */
1165
1166struct type *
fba45db2 1167lookup_enum (char *name, struct block *block)
c906108c 1168{
52f0bd74 1169 struct symbol *sym;
c906108c 1170
176620f1 1171 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0,
c906108c
SS
1172 (struct symtab **) NULL);
1173 if (sym == NULL)
1174 {
8a3fe4f8 1175 error (_("No enum type named %s."), name);
c906108c
SS
1176 }
1177 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM)
1178 {
8a3fe4f8 1179 error (_("This context has class, struct or union %s, not an enum."), name);
c906108c
SS
1180 }
1181 return (SYMBOL_TYPE (sym));
1182}
1183
1184/* Lookup a template type named "template NAME<TYPE>",
1185 visible in lexical block BLOCK. */
1186
1187struct type *
fba45db2 1188lookup_template_type (char *name, struct type *type, struct block *block)
c906108c
SS
1189{
1190 struct symbol *sym;
0004e5a2 1191 char *nam = (char *) alloca (strlen (name) + strlen (TYPE_NAME (type)) + 4);
c906108c
SS
1192 strcpy (nam, name);
1193 strcat (nam, "<");
0004e5a2 1194 strcat (nam, TYPE_NAME (type));
c5aa993b 1195 strcat (nam, " >"); /* FIXME, extra space still introduced in gcc? */
c906108c 1196
176620f1 1197 sym = lookup_symbol (nam, block, VAR_DOMAIN, 0, (struct symtab **) NULL);
c906108c
SS
1198
1199 if (sym == NULL)
1200 {
8a3fe4f8 1201 error (_("No template type named %s."), name);
c906108c
SS
1202 }
1203 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
1204 {
8a3fe4f8 1205 error (_("This context has class, union or enum %s, not a struct."), name);
c906108c
SS
1206 }
1207 return (SYMBOL_TYPE (sym));
1208}
1209
7b83ea04 1210/* Given a type TYPE, lookup the type of the component of type named NAME.
c906108c
SS
1211
1212 TYPE can be either a struct or union, or a pointer or reference to a struct or
1213 union. If it is a pointer or reference, its target type is automatically used.
1214 Thus '.' and '->' are interchangable, as specified for the definitions of the
1215 expression element types STRUCTOP_STRUCT and STRUCTOP_PTR.
1216
1217 If NOERR is nonzero, return zero if NAME is not suitably defined.
1218 If NAME is the name of a baseclass type, return that type. */
1219
1220struct type *
fba45db2 1221lookup_struct_elt_type (struct type *type, char *name, int noerr)
c906108c
SS
1222{
1223 int i;
1224
1225 for (;;)
1226 {
1227 CHECK_TYPEDEF (type);
1228 if (TYPE_CODE (type) != TYPE_CODE_PTR
1229 && TYPE_CODE (type) != TYPE_CODE_REF)
1230 break;
1231 type = TYPE_TARGET_TYPE (type);
1232 }
1233
1234 if (TYPE_CODE (type) != TYPE_CODE_STRUCT &&
1235 TYPE_CODE (type) != TYPE_CODE_UNION)
1236 {
1237 target_terminal_ours ();
1238 gdb_flush (gdb_stdout);
1239 fprintf_unfiltered (gdb_stderr, "Type ");
1240 type_print (type, "", gdb_stderr, -1);
8a3fe4f8 1241 error (_(" is not a structure or union type."));
c906108c
SS
1242 }
1243
1244#if 0
1245 /* FIXME: This change put in by Michael seems incorrect for the case where
1246 the structure tag name is the same as the member name. I.E. when doing
1247 "ptype bell->bar" for "struct foo { int bar; int foo; } bell;"
1248 Disabled by fnf. */
1249 {
1250 char *typename;
1251
1252 typename = type_name_no_tag (type);
762f08a3 1253 if (typename != NULL && strcmp (typename, name) == 0)
c906108c
SS
1254 return type;
1255 }
1256#endif
1257
1258 for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
1259 {
1260 char *t_field_name = TYPE_FIELD_NAME (type, i);
1261
db577aea 1262 if (t_field_name && (strcmp_iw (t_field_name, name) == 0))
c906108c
SS
1263 {
1264 return TYPE_FIELD_TYPE (type, i);
1265 }
1266 }
1267
1268 /* OK, it's not in this class. Recursively check the baseclasses. */
1269 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
1270 {
1271 struct type *t;
1272
1273 t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, noerr);
1274 if (t != NULL)
1275 {
1276 return t;
1277 }
1278 }
1279
1280 if (noerr)
1281 {
1282 return NULL;
1283 }
c5aa993b 1284
c906108c
SS
1285 target_terminal_ours ();
1286 gdb_flush (gdb_stdout);
1287 fprintf_unfiltered (gdb_stderr, "Type ");
1288 type_print (type, "", gdb_stderr, -1);
1289 fprintf_unfiltered (gdb_stderr, " has no component named ");
1290 fputs_filtered (name, gdb_stderr);
8a3fe4f8 1291 error (("."));
c5aa993b 1292 return (struct type *) -1; /* For lint */
c906108c
SS
1293}
1294
1295/* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE
1296 valid. Callers should be aware that in some cases (for example,
1297 the type or one of its baseclasses is a stub type and we are
1298 debugging a .o file), this function will not be able to find the virtual
1299 function table pointer, and vptr_fieldno will remain -1 and vptr_basetype
1300 will remain NULL. */
1301
1302void
fba45db2 1303fill_in_vptr_fieldno (struct type *type)
c906108c
SS
1304{
1305 CHECK_TYPEDEF (type);
1306
1307 if (TYPE_VPTR_FIELDNO (type) < 0)
1308 {
1309 int i;
1310
1311 /* We must start at zero in case the first (and only) baseclass is
7b83ea04 1312 virtual (and hence we cannot share the table pointer). */
c906108c
SS
1313 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
1314 {
cef4f5dd
DJ
1315 struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i));
1316 fill_in_vptr_fieldno (baseclass);
1317 if (TYPE_VPTR_FIELDNO (baseclass) >= 0)
c906108c 1318 {
cef4f5dd
DJ
1319 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (baseclass);
1320 TYPE_VPTR_BASETYPE (type) = TYPE_VPTR_BASETYPE (baseclass);
c906108c
SS
1321 break;
1322 }
1323 }
1324 }
1325}
1326
1327/* Find the method and field indices for the destructor in class type T.
1328 Return 1 if the destructor was found, otherwise, return 0. */
1329
1330int
fba45db2 1331get_destructor_fn_field (struct type *t, int *method_indexp, int *field_indexp)
c906108c
SS
1332{
1333 int i;
1334
1335 for (i = 0; i < TYPE_NFN_FIELDS (t); i++)
1336 {
1337 int j;
1338 struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i);
1339
1340 for (j = 0; j < TYPE_FN_FIELDLIST_LENGTH (t, i); j++)
1341 {
015a42b4 1342 if (is_destructor_name (TYPE_FN_FIELD_PHYSNAME (f, j)) != 0)
c906108c
SS
1343 {
1344 *method_indexp = i;
1345 *field_indexp = j;
1346 return 1;
1347 }
1348 }
1349 }
1350 return 0;
1351}
1352
44e1a9eb
DJ
1353static void
1354stub_noname_complaint (void)
1355{
e2e0b3e5 1356 complaint (&symfile_complaints, _("stub type has NULL name"));
44e1a9eb
DJ
1357}
1358
c906108c
SS
1359/* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
1360
1361 If this is a stubbed struct (i.e. declared as struct foo *), see if
1362 we can find a full definition in some other file. If so, copy this
1363 definition, so we can use it in future. There used to be a comment (but
1364 not any code) that if we don't find a full definition, we'd set a flag
1365 so we don't spend time in the future checking the same type. That would
1366 be a mistake, though--we might load in more symbols which contain a
1367 full definition for the type.
1368
7b83ea04 1369 This used to be coded as a macro, but I don't think it is called
c906108c
SS
1370 often enough to merit such treatment. */
1371
44e1a9eb
DJ
1372/* Find the real type of TYPE. This function returns the real type, after
1373 removing all layers of typedefs and completing opaque or stub types.
1374 Completion changes the TYPE argument, but stripping of typedefs does
1375 not. */
c906108c
SS
1376
1377struct type *
a02fd225 1378check_typedef (struct type *type)
c906108c
SS
1379{
1380 struct type *orig_type = type;
a02fd225
DJ
1381 int is_const, is_volatile;
1382
c906108c
SS
1383 while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
1384 {
1385 if (!TYPE_TARGET_TYPE (type))
1386 {
c5aa993b 1387 char *name;
c906108c
SS
1388 struct symbol *sym;
1389
1390 /* It is dangerous to call lookup_symbol if we are currently
1391 reading a symtab. Infinite recursion is one danger. */
1392 if (currently_reading_symtab)
1393 return type;
1394
1395 name = type_name_no_tag (type);
1396 /* FIXME: shouldn't we separately check the TYPE_NAME and the
176620f1 1397 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
c906108c
SS
1398 as appropriate? (this code was written before TYPE_NAME and
1399 TYPE_TAG_NAME were separate). */
1400 if (name == NULL)
1401 {
23136709 1402 stub_noname_complaint ();
c906108c
SS
1403 return type;
1404 }
176620f1 1405 sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0,
c906108c
SS
1406 (struct symtab **) NULL);
1407 if (sym)
1408 TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym);
1409 else
c5aa993b 1410 TYPE_TARGET_TYPE (type) = alloc_type (NULL); /* TYPE_CODE_UNDEF */
c906108c
SS
1411 }
1412 type = TYPE_TARGET_TYPE (type);
1413 }
1414
a02fd225
DJ
1415 is_const = TYPE_CONST (type);
1416 is_volatile = TYPE_VOLATILE (type);
1417
c906108c
SS
1418 /* If this is a struct/class/union with no fields, then check whether a
1419 full definition exists somewhere else. This is for systems where a
1420 type definition with no fields is issued for such types, instead of
c5aa993b
JM
1421 identifying them as stub types in the first place */
1422
c906108c
SS
1423 if (TYPE_IS_OPAQUE (type) && opaque_type_resolution && !currently_reading_symtab)
1424 {
c5aa993b
JM
1425 char *name = type_name_no_tag (type);
1426 struct type *newtype;
c906108c
SS
1427 if (name == NULL)
1428 {
23136709 1429 stub_noname_complaint ();
c906108c
SS
1430 return type;
1431 }
1432 newtype = lookup_transparent_type (name);
ad766c0a 1433
c906108c 1434 if (newtype)
ad766c0a
JB
1435 {
1436 /* If the resolved type and the stub are in the same objfile,
1437 then replace the stub type with the real deal. But if
1438 they're in separate objfiles, leave the stub alone; we'll
1439 just look up the transparent type every time we call
1440 check_typedef. We can't create pointers between types
1441 allocated to different objfiles, since they may have
1442 different lifetimes. Trying to copy NEWTYPE over to TYPE's
1443 objfile is pointless, too, since you'll have to move over any
1444 other types NEWTYPE refers to, which could be an unbounded
1445 amount of stuff. */
1446 if (TYPE_OBJFILE (newtype) == TYPE_OBJFILE (type))
1447 make_cv_type (is_const, is_volatile, newtype, &type);
1448 else
1449 type = newtype;
1450 }
c906108c
SS
1451 }
1452 /* Otherwise, rely on the stub flag being set for opaque/stubbed types */
74a9bb82 1453 else if (TYPE_STUB (type) && !currently_reading_symtab)
c906108c 1454 {
c5aa993b 1455 char *name = type_name_no_tag (type);
c906108c 1456 /* FIXME: shouldn't we separately check the TYPE_NAME and the
176620f1 1457 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
7b83ea04
AC
1458 as appropriate? (this code was written before TYPE_NAME and
1459 TYPE_TAG_NAME were separate). */
c906108c
SS
1460 struct symbol *sym;
1461 if (name == NULL)
1462 {
23136709 1463 stub_noname_complaint ();
c906108c
SS
1464 return type;
1465 }
176620f1 1466 sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0, (struct symtab **) NULL);
c906108c 1467 if (sym)
a02fd225 1468 make_cv_type (is_const, is_volatile, SYMBOL_TYPE (sym), &type);
c906108c
SS
1469 }
1470
74a9bb82 1471 if (TYPE_TARGET_STUB (type))
c906108c
SS
1472 {
1473 struct type *range_type;
1474 struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
1475
74a9bb82 1476 if (TYPE_STUB (target_type) || TYPE_TARGET_STUB (target_type))
c5aa993b
JM
1477 {
1478 }
c906108c
SS
1479 else if (TYPE_CODE (type) == TYPE_CODE_ARRAY
1480 && TYPE_NFIELDS (type) == 1
1481 && (TYPE_CODE (range_type = TYPE_FIELD_TYPE (type, 0))
1482 == TYPE_CODE_RANGE))
1483 {
1484 /* Now recompute the length of the array type, based on its
1485 number of elements and the target type's length. */
1486 TYPE_LENGTH (type) =
1487 ((TYPE_FIELD_BITPOS (range_type, 1)
1488 - TYPE_FIELD_BITPOS (range_type, 0)
1489 + 1)
1490 * TYPE_LENGTH (target_type));
1491 TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
1492 }
1493 else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
1494 {
1495 TYPE_LENGTH (type) = TYPE_LENGTH (target_type);
1496 TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
1497 }
1498 }
1499 /* Cache TYPE_LENGTH for future use. */
1500 TYPE_LENGTH (orig_type) = TYPE_LENGTH (type);
1501 return type;
1502}
1503
c91ecb25
ND
1504/* Parse a type expression in the string [P..P+LENGTH). If an error occurs,
1505 silently return builtin_type_void. */
1506
b9362cc7 1507static struct type *
c91ecb25
ND
1508safe_parse_type (char *p, int length)
1509{
1510 struct ui_file *saved_gdb_stderr;
1511 struct type *type;
1512
1513 /* Suppress error messages. */
1514 saved_gdb_stderr = gdb_stderr;
1515 gdb_stderr = ui_file_new ();
1516
1517 /* Call parse_and_eval_type() without fear of longjmp()s. */
1518 if (!gdb_parse_and_eval_type (p, length, &type))
1519 type = builtin_type_void;
1520
1521 /* Stop suppressing error messages. */
1522 ui_file_delete (gdb_stderr);
1523 gdb_stderr = saved_gdb_stderr;
1524
1525 return type;
1526}
1527
c906108c
SS
1528/* Ugly hack to convert method stubs into method types.
1529
1530 He ain't kiddin'. This demangles the name of the method into a string
1531 including argument types, parses out each argument type, generates
1532 a string casting a zero to that type, evaluates the string, and stuffs
1533 the resulting type into an argtype vector!!! Then it knows the type
1534 of the whole function (including argument types for overloading),
1535 which info used to be in the stab's but was removed to hack back
1536 the space required for them. */
1537
de17c821 1538static void
fba45db2 1539check_stub_method (struct type *type, int method_id, int signature_id)
c906108c
SS
1540{
1541 struct fn_field *f;
1542 char *mangled_name = gdb_mangle_name (type, method_id, signature_id);
1543 char *demangled_name = cplus_demangle (mangled_name,
1544 DMGL_PARAMS | DMGL_ANSI);
1545 char *argtypetext, *p;
1546 int depth = 0, argcount = 1;
ad2f7632 1547 struct field *argtypes;
c906108c
SS
1548 struct type *mtype;
1549
1550 /* Make sure we got back a function string that we can use. */
1551 if (demangled_name)
1552 p = strchr (demangled_name, '(');
502dcf4e
AC
1553 else
1554 p = NULL;
c906108c
SS
1555
1556 if (demangled_name == NULL || p == NULL)
8a3fe4f8 1557 error (_("Internal: Cannot demangle mangled name `%s'."), mangled_name);
c906108c
SS
1558
1559 /* Now, read in the parameters that define this type. */
1560 p += 1;
1561 argtypetext = p;
1562 while (*p)
1563 {
070ad9f0 1564 if (*p == '(' || *p == '<')
c906108c
SS
1565 {
1566 depth += 1;
1567 }
070ad9f0 1568 else if (*p == ')' || *p == '>')
c906108c
SS
1569 {
1570 depth -= 1;
1571 }
1572 else if (*p == ',' && depth == 0)
1573 {
1574 argcount += 1;
1575 }
1576
1577 p += 1;
1578 }
1579
ad2f7632
DJ
1580 /* If we read one argument and it was ``void'', don't count it. */
1581 if (strncmp (argtypetext, "(void)", 6) == 0)
1582 argcount -= 1;
c906108c 1583
ad2f7632
DJ
1584 /* We need one extra slot, for the THIS pointer. */
1585
1586 argtypes = (struct field *)
1587 TYPE_ALLOC (type, (argcount + 1) * sizeof (struct field));
c906108c 1588 p = argtypetext;
4a1970e4
DJ
1589
1590 /* Add THIS pointer for non-static methods. */
1591 f = TYPE_FN_FIELDLIST1 (type, method_id);
1592 if (TYPE_FN_FIELD_STATIC_P (f, signature_id))
1593 argcount = 0;
1594 else
1595 {
ad2f7632 1596 argtypes[0].type = lookup_pointer_type (type);
4a1970e4
DJ
1597 argcount = 1;
1598 }
c906108c 1599
c5aa993b 1600 if (*p != ')') /* () means no args, skip while */
c906108c
SS
1601 {
1602 depth = 0;
1603 while (*p)
1604 {
1605 if (depth <= 0 && (*p == ',' || *p == ')'))
1606 {
ad2f7632
DJ
1607 /* Avoid parsing of ellipsis, they will be handled below.
1608 Also avoid ``void'' as above. */
1609 if (strncmp (argtypetext, "...", p - argtypetext) != 0
1610 && strncmp (argtypetext, "void", p - argtypetext) != 0)
c906108c 1611 {
ad2f7632 1612 argtypes[argcount].type =
c91ecb25 1613 safe_parse_type (argtypetext, p - argtypetext);
c906108c
SS
1614 argcount += 1;
1615 }
1616 argtypetext = p + 1;
1617 }
1618
070ad9f0 1619 if (*p == '(' || *p == '<')
c906108c
SS
1620 {
1621 depth += 1;
1622 }
070ad9f0 1623 else if (*p == ')' || *p == '>')
c906108c
SS
1624 {
1625 depth -= 1;
1626 }
1627
1628 p += 1;
1629 }
1630 }
1631
c906108c
SS
1632 TYPE_FN_FIELD_PHYSNAME (f, signature_id) = mangled_name;
1633
1634 /* Now update the old "stub" type into a real type. */
1635 mtype = TYPE_FN_FIELD_TYPE (f, signature_id);
1636 TYPE_DOMAIN_TYPE (mtype) = type;
ad2f7632
DJ
1637 TYPE_FIELDS (mtype) = argtypes;
1638 TYPE_NFIELDS (mtype) = argcount;
c906108c
SS
1639 TYPE_FLAGS (mtype) &= ~TYPE_FLAG_STUB;
1640 TYPE_FN_FIELD_STUB (f, signature_id) = 0;
ad2f7632
DJ
1641 if (p[-2] == '.')
1642 TYPE_FLAGS (mtype) |= TYPE_FLAG_VARARGS;
1643
1644 xfree (demangled_name);
c906108c
SS
1645}
1646
de17c821
DJ
1647/* This is the external interface to check_stub_method, above. This function
1648 unstubs all of the signatures for TYPE's METHOD_ID method name. After
1649 calling this function TYPE_FN_FIELD_STUB will be cleared for each signature
1650 and TYPE_FN_FIELDLIST_NAME will be correct.
1651
1652 This function unfortunately can not die until stabs do. */
1653
1654void
1655check_stub_method_group (struct type *type, int method_id)
1656{
1657 int len = TYPE_FN_FIELDLIST_LENGTH (type, method_id);
1658 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, method_id);
f710f4fc 1659 int j, found_stub = 0;
de17c821
DJ
1660
1661 for (j = 0; j < len; j++)
1662 if (TYPE_FN_FIELD_STUB (f, j))
1663 {
1664 found_stub = 1;
1665 check_stub_method (type, method_id, j);
1666 }
1667
1668 /* GNU v3 methods with incorrect names were corrected when we read in
1669 type information, because it was cheaper to do it then. The only GNU v2
1670 methods with incorrect method names are operators and destructors;
1671 destructors were also corrected when we read in type information.
1672
1673 Therefore the only thing we need to handle here are v2 operator
1674 names. */
1675 if (found_stub && strncmp (TYPE_FN_FIELD_PHYSNAME (f, 0), "_Z", 2) != 0)
1676 {
1677 int ret;
1678 char dem_opname[256];
1679
1680 ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type, method_id),
1681 dem_opname, DMGL_ANSI);
1682 if (!ret)
1683 ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type, method_id),
1684 dem_opname, 0);
1685 if (ret)
1686 TYPE_FN_FIELDLIST_NAME (type, method_id) = xstrdup (dem_opname);
1687 }
1688}
1689
c906108c
SS
1690const struct cplus_struct_type cplus_struct_default;
1691
1692void
fba45db2 1693allocate_cplus_struct_type (struct type *type)
c906108c
SS
1694{
1695 if (!HAVE_CPLUS_STRUCT (type))
1696 {
1697 TYPE_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *)
1698 TYPE_ALLOC (type, sizeof (struct cplus_struct_type));
c5aa993b 1699 *(TYPE_CPLUS_SPECIFIC (type)) = cplus_struct_default;
c906108c
SS
1700 }
1701}
1702
1703/* Helper function to initialize the standard scalar types.
1704
1705 If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy
b99607ea 1706 of the string pointed to by name in the objfile_obstack for that objfile,
c906108c
SS
1707 and initialize the type name to that copy. There are places (mipsread.c
1708 in particular, where init_type is called with a NULL value for NAME). */
1709
1710struct type *
fba45db2
KB
1711init_type (enum type_code code, int length, int flags, char *name,
1712 struct objfile *objfile)
c906108c 1713{
52f0bd74 1714 struct type *type;
c906108c
SS
1715
1716 type = alloc_type (objfile);
1717 TYPE_CODE (type) = code;
1718 TYPE_LENGTH (type) = length;
1719 TYPE_FLAGS (type) |= flags;
1720 if ((name != NULL) && (objfile != NULL))
1721 {
1722 TYPE_NAME (type) =
b99607ea 1723 obsavestring (name, strlen (name), &objfile->objfile_obstack);
c906108c
SS
1724 }
1725 else
1726 {
1727 TYPE_NAME (type) = name;
1728 }
1729
1730 /* C++ fancies. */
1731
973ccf8b
DJ
1732 if (name && strcmp (name, "char") == 0)
1733 TYPE_FLAGS (type) |= TYPE_FLAG_NOSIGN;
1734
5c4e30ca
DC
1735 if (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION
1736 || code == TYPE_CODE_NAMESPACE)
c906108c
SS
1737 {
1738 INIT_CPLUS_SPECIFIC (type);
1739 }
1740 return (type);
1741}
1742
0e101458
AC
1743/* Helper function. Create an empty composite type. */
1744
1745struct type *
1746init_composite_type (char *name, enum type_code code)
1747{
1748 struct type *t;
1749 gdb_assert (code == TYPE_CODE_STRUCT
1750 || code == TYPE_CODE_UNION);
1751 t = init_type (code, 0, 0, NULL, NULL);
1752 TYPE_TAG_NAME (t) = name;
1753 return t;
1754}
1755
1756/* Helper function. Append a field to a composite type. */
1757
1758void
1759append_composite_type_field (struct type *t, char *name, struct type *field)
1760{
1761 struct field *f;
1762 TYPE_NFIELDS (t) = TYPE_NFIELDS (t) + 1;
1763 TYPE_FIELDS (t) = xrealloc (TYPE_FIELDS (t),
1764 sizeof (struct field) * TYPE_NFIELDS (t));
1765 f = &(TYPE_FIELDS (t)[TYPE_NFIELDS (t) - 1]);
1766 memset (f, 0, sizeof f[0]);
1767 FIELD_TYPE (f[0]) = field;
1768 FIELD_NAME (f[0]) = name;
1769 if (TYPE_CODE (t) == TYPE_CODE_UNION)
1770 {
73d322b1 1771 if (TYPE_LENGTH (t) < TYPE_LENGTH (field))
0e101458
AC
1772 TYPE_LENGTH (t) = TYPE_LENGTH (field);
1773 }
1774 else if (TYPE_CODE (t) == TYPE_CODE_STRUCT)
1775 {
1776 TYPE_LENGTH (t) = TYPE_LENGTH (t) + TYPE_LENGTH (field);
1777 if (TYPE_NFIELDS (t) > 1)
1778 {
1779 FIELD_BITPOS (f[0]) = (FIELD_BITPOS (f[-1])
1780 + TYPE_LENGTH (field) * TARGET_CHAR_BIT);
1781 }
1782 }
1783}
1784
c906108c
SS
1785/* Look up a fundamental type for the specified objfile.
1786 May need to construct such a type if this is the first use.
1787
1788 Some object file formats (ELF, COFF, etc) do not define fundamental
1789 types such as "int" or "double". Others (stabs for example), do
1790 define fundamental types.
1791
1792 For the formats which don't provide fundamental types, gdb can create
1793 such types, using defaults reasonable for the current language and
1794 the current target machine.
1795
1796 NOTE: This routine is obsolescent. Each debugging format reader
1797 should manage it's own fundamental types, either creating them from
1798 suitable defaults or reading them from the debugging information,
1799 whichever is appropriate. The DWARF reader has already been
1800 fixed to do this. Once the other readers are fixed, this routine
1801 will go away. Also note that fundamental types should be managed
1802 on a compilation unit basis in a multi-language environment, not
1803 on a linkage unit basis as is done here. */
1804
1805
1806struct type *
fba45db2 1807lookup_fundamental_type (struct objfile *objfile, int typeid)
c906108c 1808{
52f0bd74
AC
1809 struct type **typep;
1810 int nbytes;
c906108c
SS
1811
1812 if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
1813 {
8a3fe4f8 1814 error (_("internal error - invalid fundamental type id %d"), typeid);
c906108c
SS
1815 }
1816
1817 /* If this is the first time we need a fundamental type for this objfile
1818 then we need to initialize the vector of type pointers. */
c5aa993b
JM
1819
1820 if (objfile->fundamental_types == NULL)
c906108c
SS
1821 {
1822 nbytes = FT_NUM_MEMBERS * sizeof (struct type *);
c5aa993b 1823 objfile->fundamental_types = (struct type **)
b99607ea 1824 obstack_alloc (&objfile->objfile_obstack, nbytes);
c5aa993b 1825 memset ((char *) objfile->fundamental_types, 0, nbytes);
c906108c
SS
1826 OBJSTAT (objfile, n_types += FT_NUM_MEMBERS);
1827 }
1828
1829 /* Look for this particular type in the fundamental type vector. If one is
1830 not found, create and install one appropriate for the current language. */
1831
c5aa993b 1832 typep = objfile->fundamental_types + typeid;
c906108c
SS
1833 if (*typep == NULL)
1834 {
1835 *typep = create_fundamental_type (objfile, typeid);
1836 }
1837
1838 return (*typep);
1839}
1840
1841int
fba45db2 1842can_dereference (struct type *t)
c906108c
SS
1843{
1844 /* FIXME: Should we return true for references as well as pointers? */
1845 CHECK_TYPEDEF (t);
1846 return
1847 (t != NULL
1848 && TYPE_CODE (t) == TYPE_CODE_PTR
1849 && TYPE_CODE (TYPE_TARGET_TYPE (t)) != TYPE_CODE_VOID);
1850}
1851
adf40b2e 1852int
fba45db2 1853is_integral_type (struct type *t)
adf40b2e
JM
1854{
1855 CHECK_TYPEDEF (t);
1856 return
1857 ((t != NULL)
d4f3574e
SS
1858 && ((TYPE_CODE (t) == TYPE_CODE_INT)
1859 || (TYPE_CODE (t) == TYPE_CODE_ENUM)
1860 || (TYPE_CODE (t) == TYPE_CODE_CHAR)
1861 || (TYPE_CODE (t) == TYPE_CODE_RANGE)
1862 || (TYPE_CODE (t) == TYPE_CODE_BOOL)));
adf40b2e
JM
1863}
1864
7b83ea04 1865/* Check whether BASE is an ancestor or base class or DCLASS
c906108c
SS
1866 Return 1 if so, and 0 if not.
1867 Note: callers may want to check for identity of the types before
1868 calling this function -- identical types are considered to satisfy
1869 the ancestor relationship even if they're identical */
1870
1871int
fba45db2 1872is_ancestor (struct type *base, struct type *dclass)
c906108c
SS
1873{
1874 int i;
c5aa993b 1875
c906108c
SS
1876 CHECK_TYPEDEF (base);
1877 CHECK_TYPEDEF (dclass);
1878
1879 if (base == dclass)
1880 return 1;
6b1ba9a0
ND
1881 if (TYPE_NAME (base) && TYPE_NAME (dclass) &&
1882 !strcmp (TYPE_NAME (base), TYPE_NAME (dclass)))
1883 return 1;
c906108c
SS
1884
1885 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1886 if (is_ancestor (base, TYPE_BASECLASS (dclass, i)))
1887 return 1;
1888
1889 return 0;
1890}
1891
1892
1893
1894/* See whether DCLASS has a virtual table. This routine is aimed at
1895 the HP/Taligent ANSI C++ runtime model, and may not work with other
1896 runtime models. Return 1 => Yes, 0 => No. */
1897
1898int
fba45db2 1899has_vtable (struct type *dclass)
c906108c
SS
1900{
1901 /* In the HP ANSI C++ runtime model, a class has a vtable only if it
1902 has virtual functions or virtual bases. */
1903
52f0bd74 1904 int i;
c906108c 1905
c5aa993b 1906 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
c906108c 1907 return 0;
c5aa993b 1908
c906108c 1909 /* First check for the presence of virtual bases */
c5aa993b
JM
1910 if (TYPE_FIELD_VIRTUAL_BITS (dclass))
1911 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1912 if (B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i))
1913 return 1;
1914
c906108c 1915 /* Next check for virtual functions */
c5aa993b
JM
1916 if (TYPE_FN_FIELDLISTS (dclass))
1917 for (i = 0; i < TYPE_NFN_FIELDS (dclass); i++)
1918 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, i), 0))
c906108c 1919 return 1;
c5aa993b
JM
1920
1921 /* Recurse on non-virtual bases to see if any of them needs a vtable */
1922 if (TYPE_FIELD_VIRTUAL_BITS (dclass))
1923 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1924 if ((!B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i)) &&
1925 (has_vtable (TYPE_FIELD_TYPE (dclass, i))))
1926 return 1;
1927
1928 /* Well, maybe we don't need a virtual table */
c906108c
SS
1929 return 0;
1930}
1931
1932/* Return a pointer to the "primary base class" of DCLASS.
c5aa993b 1933
c906108c
SS
1934 A NULL return indicates that DCLASS has no primary base, or that it
1935 couldn't be found (insufficient information).
c5aa993b 1936
c906108c
SS
1937 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
1938 and may not work with other runtime models. */
1939
1940struct type *
fba45db2 1941primary_base_class (struct type *dclass)
c906108c
SS
1942{
1943 /* In HP ANSI C++'s runtime model, a "primary base class" of a class
1944 is the first directly inherited, non-virtual base class that
1945 requires a virtual table */
1946
52f0bd74 1947 int i;
c906108c 1948
c5aa993b 1949 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
c906108c
SS
1950 return NULL;
1951
c5aa993b
JM
1952 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1953 if (!TYPE_FIELD_VIRTUAL (dclass, i) &&
1954 has_vtable (TYPE_FIELD_TYPE (dclass, i)))
1955 return TYPE_FIELD_TYPE (dclass, i);
c906108c
SS
1956
1957 return NULL;
1958}
1959
1960/* Global manipulated by virtual_base_list[_aux]() */
1961
c5aa993b 1962static struct vbase *current_vbase_list = NULL;
c906108c
SS
1963
1964/* Return a pointer to a null-terminated list of struct vbase
1965 items. The vbasetype pointer of each item in the list points to the
1966 type information for a virtual base of the argument DCLASS.
c5aa993b 1967
7b83ea04 1968 Helper function for virtual_base_list().
c906108c
SS
1969 Note: the list goes backward, right-to-left. virtual_base_list()
1970 copies the items out in reverse order. */
1971
7a292a7a 1972static void
fba45db2 1973virtual_base_list_aux (struct type *dclass)
c906108c 1974{
c5aa993b 1975 struct vbase *tmp_vbase;
52f0bd74 1976 int i;
c906108c 1977
c5aa993b 1978 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
7a292a7a 1979 return;
c906108c
SS
1980
1981 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1982 {
1983 /* Recurse on this ancestor, first */
c5aa993b 1984 virtual_base_list_aux (TYPE_FIELD_TYPE (dclass, i));
c906108c
SS
1985
1986 /* If this current base is itself virtual, add it to the list */
c5aa993b
JM
1987 if (BASETYPE_VIA_VIRTUAL (dclass, i))
1988 {
1989 struct type *basetype = TYPE_FIELD_TYPE (dclass, i);
1990
1991 /* Check if base already recorded */
1992 tmp_vbase = current_vbase_list;
1993 while (tmp_vbase)
1994 {
1995 if (tmp_vbase->vbasetype == basetype)
1996 break; /* found it */
1997 tmp_vbase = tmp_vbase->next;
1998 }
1999
2000 if (!tmp_vbase) /* normal exit from loop */
2001 {
2002 /* Allocate new item for this virtual base */
2003 tmp_vbase = (struct vbase *) xmalloc (sizeof (struct vbase));
2004
2005 /* Stick it on at the end of the list */
2006 tmp_vbase->vbasetype = basetype;
2007 tmp_vbase->next = current_vbase_list;
2008 current_vbase_list = tmp_vbase;
2009 }
2010 } /* if virtual */
2011 } /* for loop over bases */
c906108c
SS
2012}
2013
2014
2015/* Compute the list of virtual bases in the right order. Virtual
2016 bases are laid out in the object's memory area in order of their
2017 occurrence in a depth-first, left-to-right search through the
2018 ancestors.
c5aa993b 2019
c906108c
SS
2020 Argument DCLASS is the type whose virtual bases are required.
2021 Return value is the address of a null-terminated array of pointers
2022 to struct type items.
c5aa993b 2023
c906108c
SS
2024 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
2025 and may not work with other runtime models.
c5aa993b 2026
c906108c
SS
2027 This routine merely hands off the argument to virtual_base_list_aux()
2028 and then copies the result into an array to save space. */
2029
2030struct type **
fba45db2 2031virtual_base_list (struct type *dclass)
c906108c 2032{
52f0bd74
AC
2033 struct vbase *tmp_vbase;
2034 struct vbase *tmp_vbase_2;
2035 int i;
c906108c 2036 int count;
c5aa993b 2037 struct type **vbase_array;
c906108c
SS
2038
2039 current_vbase_list = NULL;
c5aa993b 2040 virtual_base_list_aux (dclass);
c906108c 2041
c5aa993b 2042 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next)
c906108c
SS
2043 /* no body */ ;
2044
2045 count = i;
2046
c5aa993b 2047 vbase_array = (struct type **) xmalloc ((count + 1) * sizeof (struct type *));
c906108c 2048
c5aa993b 2049 for (i = count - 1, tmp_vbase = current_vbase_list; i >= 0; i--, tmp_vbase = tmp_vbase->next)
c906108c
SS
2050 vbase_array[i] = tmp_vbase->vbasetype;
2051
2052 /* Get rid of constructed chain */
2053 tmp_vbase_2 = tmp_vbase = current_vbase_list;
2054 while (tmp_vbase)
2055 {
2056 tmp_vbase = tmp_vbase->next;
b8c9b27d 2057 xfree (tmp_vbase_2);
c906108c
SS
2058 tmp_vbase_2 = tmp_vbase;
2059 }
c5aa993b 2060
c906108c
SS
2061 vbase_array[count] = NULL;
2062 return vbase_array;
2063}
2064
2065/* Return the length of the virtual base list of the type DCLASS. */
2066
2067int
fba45db2 2068virtual_base_list_length (struct type *dclass)
c906108c 2069{
52f0bd74
AC
2070 int i;
2071 struct vbase *tmp_vbase;
c5aa993b 2072
c906108c 2073 current_vbase_list = NULL;
c5aa993b 2074 virtual_base_list_aux (dclass);
c906108c 2075
c5aa993b 2076 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next)
c906108c
SS
2077 /* no body */ ;
2078 return i;
2079}
2080
2081/* Return the number of elements of the virtual base list of the type
2082 DCLASS, ignoring those appearing in the primary base (and its
2083 primary base, recursively). */
2084
2085int
fba45db2 2086virtual_base_list_length_skip_primaries (struct type *dclass)
c906108c 2087{
52f0bd74
AC
2088 int i;
2089 struct vbase *tmp_vbase;
c5aa993b 2090 struct type *primary;
c906108c
SS
2091
2092 primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL;
2093
2094 if (!primary)
2095 return virtual_base_list_length (dclass);
2096
2097 current_vbase_list = NULL;
c5aa993b 2098 virtual_base_list_aux (dclass);
c906108c 2099
c5aa993b 2100 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; tmp_vbase = tmp_vbase->next)
c906108c
SS
2101 {
2102 if (virtual_base_index (tmp_vbase->vbasetype, primary) >= 0)
c5aa993b 2103 continue;
c906108c
SS
2104 i++;
2105 }
2106 return i;
2107}
2108
2109
2110/* Return the index (position) of type BASE, which is a virtual base
2111 class of DCLASS, in the latter's virtual base list. A return of -1
2112 indicates "not found" or a problem. */
2113
2114int
fba45db2 2115virtual_base_index (struct type *base, struct type *dclass)
c906108c 2116{
52f0bd74
AC
2117 struct type *vbase;
2118 int i;
c906108c 2119
c5aa993b
JM
2120 if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) ||
2121 (TYPE_CODE (base) != TYPE_CODE_CLASS))
c906108c
SS
2122 return -1;
2123
2124 i = 0;
015a42b4 2125 vbase = virtual_base_list (dclass)[0];
c906108c
SS
2126 while (vbase)
2127 {
2128 if (vbase == base)
c5aa993b 2129 break;
015a42b4 2130 vbase = virtual_base_list (dclass)[++i];
c906108c
SS
2131 }
2132
2133 return vbase ? i : -1;
2134}
2135
2136
2137
2138/* Return the index (position) of type BASE, which is a virtual base
2139 class of DCLASS, in the latter's virtual base list. Skip over all
2140 bases that may appear in the virtual base list of the primary base
2141 class of DCLASS (recursively). A return of -1 indicates "not
2142 found" or a problem. */
2143
2144int
fba45db2 2145virtual_base_index_skip_primaries (struct type *base, struct type *dclass)
c906108c 2146{
52f0bd74
AC
2147 struct type *vbase;
2148 int i, j;
c5aa993b 2149 struct type *primary;
c906108c 2150
c5aa993b
JM
2151 if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) ||
2152 (TYPE_CODE (base) != TYPE_CODE_CLASS))
c906108c
SS
2153 return -1;
2154
c5aa993b 2155 primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL;
c906108c
SS
2156
2157 j = -1;
2158 i = 0;
015a42b4 2159 vbase = virtual_base_list (dclass)[0];
c906108c
SS
2160 while (vbase)
2161 {
c5aa993b
JM
2162 if (!primary || (virtual_base_index_skip_primaries (vbase, primary) < 0))
2163 j++;
c906108c 2164 if (vbase == base)
c5aa993b 2165 break;
015a42b4 2166 vbase = virtual_base_list (dclass)[++i];
c906108c
SS
2167 }
2168
2169 return vbase ? j : -1;
2170}
2171
2172/* Return position of a derived class DCLASS in the list of
2173 * primary bases starting with the remotest ancestor.
2174 * Position returned is 0-based. */
2175
2176int
fba45db2 2177class_index_in_primary_list (struct type *dclass)
c906108c 2178{
c5aa993b 2179 struct type *pbc; /* primary base class */
c906108c 2180
c5aa993b 2181 /* Simply recurse on primary base */
c906108c
SS
2182 pbc = TYPE_PRIMARY_BASE (dclass);
2183 if (pbc)
2184 return 1 + class_index_in_primary_list (pbc);
2185 else
2186 return 0;
2187}
2188
2189/* Return a count of the number of virtual functions a type has.
2190 * This includes all the virtual functions it inherits from its
2191 * base classes too.
2192 */
2193
2194/* pai: FIXME This doesn't do the right thing: count redefined virtual
2195 * functions only once (latest redefinition)
2196 */
2197
2198int
fba45db2 2199count_virtual_fns (struct type *dclass)
c906108c 2200{
c5aa993b 2201 int fn, oi; /* function and overloaded instance indices */
c5aa993b
JM
2202 int vfuncs; /* count to return */
2203
2204 /* recurse on bases that can share virtual table */
2205 struct type *pbc = primary_base_class (dclass);
c906108c
SS
2206 if (pbc)
2207 vfuncs = count_virtual_fns (pbc);
7f7e9482
AC
2208 else
2209 vfuncs = 0;
c5aa993b 2210
c906108c
SS
2211 for (fn = 0; fn < TYPE_NFN_FIELDS (dclass); fn++)
2212 for (oi = 0; oi < TYPE_FN_FIELDLIST_LENGTH (dclass, fn); oi++)
2213 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, fn), oi))
c5aa993b 2214 vfuncs++;
c906108c
SS
2215
2216 return vfuncs;
2217}
c906108c
SS
2218\f
2219
c5aa993b 2220
c906108c
SS
2221/* Functions for overload resolution begin here */
2222
2223/* Compare two badness vectors A and B and return the result.
2224 * 0 => A and B are identical
2225 * 1 => A and B are incomparable
2226 * 2 => A is better than B
2227 * 3 => A is worse than B */
2228
2229int
fba45db2 2230compare_badness (struct badness_vector *a, struct badness_vector *b)
c906108c
SS
2231{
2232 int i;
2233 int tmp;
c5aa993b
JM
2234 short found_pos = 0; /* any positives in c? */
2235 short found_neg = 0; /* any negatives in c? */
2236
2237 /* differing lengths => incomparable */
c906108c
SS
2238 if (a->length != b->length)
2239 return 1;
2240
c5aa993b
JM
2241 /* Subtract b from a */
2242 for (i = 0; i < a->length; i++)
c906108c
SS
2243 {
2244 tmp = a->rank[i] - b->rank[i];
2245 if (tmp > 0)
c5aa993b 2246 found_pos = 1;
c906108c 2247 else if (tmp < 0)
c5aa993b 2248 found_neg = 1;
c906108c
SS
2249 }
2250
2251 if (found_pos)
2252 {
2253 if (found_neg)
c5aa993b 2254 return 1; /* incomparable */
c906108c 2255 else
c5aa993b 2256 return 3; /* A > B */
c906108c 2257 }
c5aa993b
JM
2258 else
2259 /* no positives */
c906108c
SS
2260 {
2261 if (found_neg)
c5aa993b 2262 return 2; /* A < B */
c906108c 2263 else
c5aa993b 2264 return 0; /* A == B */
c906108c
SS
2265 }
2266}
2267
2268/* Rank a function by comparing its parameter types (PARMS, length NPARMS),
2269 * to the types of an argument list (ARGS, length NARGS).
2270 * Return a pointer to a badness vector. This has NARGS + 1 entries. */
2271
2272struct badness_vector *
fba45db2 2273rank_function (struct type **parms, int nparms, struct type **args, int nargs)
c906108c
SS
2274{
2275 int i;
c5aa993b 2276 struct badness_vector *bv;
c906108c
SS
2277 int min_len = nparms < nargs ? nparms : nargs;
2278
2279 bv = xmalloc (sizeof (struct badness_vector));
c5aa993b 2280 bv->length = nargs + 1; /* add 1 for the length-match rank */
c906108c
SS
2281 bv->rank = xmalloc ((nargs + 1) * sizeof (int));
2282
2283 /* First compare the lengths of the supplied lists.
2284 * If there is a mismatch, set it to a high value. */
c5aa993b 2285
c906108c
SS
2286 /* pai/1997-06-03 FIXME: when we have debug info about default
2287 * arguments and ellipsis parameter lists, we should consider those
2288 * and rank the length-match more finely. */
2289
2290 LENGTH_MATCH (bv) = (nargs != nparms) ? LENGTH_MISMATCH_BADNESS : 0;
2291
2292 /* Now rank all the parameters of the candidate function */
74cc24b0
DB
2293 for (i = 1; i <= min_len; i++)
2294 bv->rank[i] = rank_one_type (parms[i-1], args[i-1]);
c906108c 2295
c5aa993b
JM
2296 /* If more arguments than parameters, add dummy entries */
2297 for (i = min_len + 1; i <= nargs; i++)
c906108c
SS
2298 bv->rank[i] = TOO_FEW_PARAMS_BADNESS;
2299
2300 return bv;
2301}
2302
973ccf8b
DJ
2303/* Compare the names of two integer types, assuming that any sign
2304 qualifiers have been checked already. We do it this way because
2305 there may be an "int" in the name of one of the types. */
2306
2307static int
2308integer_types_same_name_p (const char *first, const char *second)
2309{
2310 int first_p, second_p;
2311
2312 /* If both are shorts, return 1; if neither is a short, keep checking. */
2313 first_p = (strstr (first, "short") != NULL);
2314 second_p = (strstr (second, "short") != NULL);
2315 if (first_p && second_p)
2316 return 1;
2317 if (first_p || second_p)
2318 return 0;
2319
2320 /* Likewise for long. */
2321 first_p = (strstr (first, "long") != NULL);
2322 second_p = (strstr (second, "long") != NULL);
2323 if (first_p && second_p)
2324 return 1;
2325 if (first_p || second_p)
2326 return 0;
2327
2328 /* Likewise for char. */
2329 first_p = (strstr (first, "char") != NULL);
2330 second_p = (strstr (second, "char") != NULL);
2331 if (first_p && second_p)
2332 return 1;
2333 if (first_p || second_p)
2334 return 0;
2335
2336 /* They must both be ints. */
2337 return 1;
2338}
2339
c906108c
SS
2340/* Compare one type (PARM) for compatibility with another (ARG).
2341 * PARM is intended to be the parameter type of a function; and
2342 * ARG is the supplied argument's type. This function tests if
2343 * the latter can be converted to the former.
2344 *
2345 * Return 0 if they are identical types;
2346 * Otherwise, return an integer which corresponds to how compatible
2347 * PARM is to ARG. The higher the return value, the worse the match.
2348 * Generally the "bad" conversions are all uniformly assigned a 100 */
2349
2350int
fba45db2 2351rank_one_type (struct type *parm, struct type *arg)
c906108c
SS
2352{
2353 /* Identical type pointers */
2354 /* However, this still doesn't catch all cases of same type for arg
2355 * and param. The reason is that builtin types are different from
2356 * the same ones constructed from the object. */
2357 if (parm == arg)
2358 return 0;
2359
2360 /* Resolve typedefs */
2361 if (TYPE_CODE (parm) == TYPE_CODE_TYPEDEF)
2362 parm = check_typedef (parm);
2363 if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF)
2364 arg = check_typedef (arg);
2365
070ad9f0
DB
2366 /*
2367 Well, damnit, if the names are exactly the same,
2368 i'll say they are exactly the same. This happens when we generate
2369 method stubs. The types won't point to the same address, but they
2370 really are the same.
2371 */
2372
6b1ba9a0
ND
2373 if (TYPE_NAME (parm) && TYPE_NAME (arg) &&
2374 !strcmp (TYPE_NAME (parm), TYPE_NAME (arg)))
070ad9f0
DB
2375 return 0;
2376
c906108c
SS
2377 /* Check if identical after resolving typedefs */
2378 if (parm == arg)
2379 return 0;
2380
db577aea
AC
2381 /* See through references, since we can almost make non-references
2382 references. */
2383 if (TYPE_CODE (arg) == TYPE_CODE_REF)
6b1ba9a0 2384 return (rank_one_type (parm, TYPE_TARGET_TYPE (arg))
db577aea
AC
2385 + REFERENCE_CONVERSION_BADNESS);
2386 if (TYPE_CODE (parm) == TYPE_CODE_REF)
6b1ba9a0 2387 return (rank_one_type (TYPE_TARGET_TYPE (parm), arg)
db577aea 2388 + REFERENCE_CONVERSION_BADNESS);
5d161b24 2389 if (overload_debug)
db577aea 2390 /* Debugging only. */
5d161b24
DB
2391 fprintf_filtered (gdb_stderr,"------ Arg is %s [%d], parm is %s [%d]\n",
2392 TYPE_NAME (arg), TYPE_CODE (arg), TYPE_NAME (parm), TYPE_CODE (parm));
c906108c
SS
2393
2394 /* x -> y means arg of type x being supplied for parameter of type y */
2395
2396 switch (TYPE_CODE (parm))
2397 {
c5aa993b
JM
2398 case TYPE_CODE_PTR:
2399 switch (TYPE_CODE (arg))
2400 {
2401 case TYPE_CODE_PTR:
2402 if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID)
2403 return VOID_PTR_CONVERSION_BADNESS;
2404 else
2405 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2406 case TYPE_CODE_ARRAY:
2407 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2408 case TYPE_CODE_FUNC:
2409 return rank_one_type (TYPE_TARGET_TYPE (parm), arg);
2410 case TYPE_CODE_INT:
2411 case TYPE_CODE_ENUM:
2412 case TYPE_CODE_CHAR:
2413 case TYPE_CODE_RANGE:
2414 case TYPE_CODE_BOOL:
2415 return POINTER_CONVERSION_BADNESS;
2416 default:
2417 return INCOMPATIBLE_TYPE_BADNESS;
2418 }
2419 case TYPE_CODE_ARRAY:
2420 switch (TYPE_CODE (arg))
2421 {
2422 case TYPE_CODE_PTR:
2423 case TYPE_CODE_ARRAY:
2424 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2425 default:
2426 return INCOMPATIBLE_TYPE_BADNESS;
2427 }
2428 case TYPE_CODE_FUNC:
2429 switch (TYPE_CODE (arg))
2430 {
2431 case TYPE_CODE_PTR: /* funcptr -> func */
2432 return rank_one_type (parm, TYPE_TARGET_TYPE (arg));
2433 default:
2434 return INCOMPATIBLE_TYPE_BADNESS;
2435 }
2436 case TYPE_CODE_INT:
2437 switch (TYPE_CODE (arg))
2438 {
2439 case TYPE_CODE_INT:
2440 if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
2441 {
2442 /* Deal with signed, unsigned, and plain chars and
7b83ea04 2443 signed and unsigned ints */
c5aa993b
JM
2444 if (TYPE_NOSIGN (parm))
2445 {
2446 /* This case only for character types */
2447 if (TYPE_NOSIGN (arg)) /* plain char -> plain char */
2448 return 0;
2449 else
1c5cb38e 2450 return INTEGER_CONVERSION_BADNESS; /* signed/unsigned char -> plain char */
c5aa993b
JM
2451 }
2452 else if (TYPE_UNSIGNED (parm))
2453 {
2454 if (TYPE_UNSIGNED (arg))
2455 {
973ccf8b
DJ
2456 /* unsigned int -> unsigned int, or unsigned long -> unsigned long */
2457 if (integer_types_same_name_p (TYPE_NAME (parm), TYPE_NAME (arg)))
2458 return 0;
2459 else if (integer_types_same_name_p (TYPE_NAME (arg), "int")
2460 && integer_types_same_name_p (TYPE_NAME (parm), "long"))
c5aa993b
JM
2461 return INTEGER_PROMOTION_BADNESS; /* unsigned int -> unsigned long */
2462 else
1c5cb38e 2463 return INTEGER_CONVERSION_BADNESS; /* unsigned long -> unsigned int */
c5aa993b
JM
2464 }
2465 else
2466 {
973ccf8b
DJ
2467 if (integer_types_same_name_p (TYPE_NAME (arg), "long")
2468 && integer_types_same_name_p (TYPE_NAME (parm), "int"))
1c5cb38e 2469 return INTEGER_CONVERSION_BADNESS; /* signed long -> unsigned int */
c5aa993b
JM
2470 else
2471 return INTEGER_CONVERSION_BADNESS; /* signed int/long -> unsigned int/long */
2472 }
2473 }
2474 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
2475 {
973ccf8b 2476 if (integer_types_same_name_p (TYPE_NAME (parm), TYPE_NAME (arg)))
c5aa993b 2477 return 0;
973ccf8b
DJ
2478 else if (integer_types_same_name_p (TYPE_NAME (arg), "int")
2479 && integer_types_same_name_p (TYPE_NAME (parm), "long"))
c5aa993b
JM
2480 return INTEGER_PROMOTION_BADNESS;
2481 else
1c5cb38e 2482 return INTEGER_CONVERSION_BADNESS;
c5aa993b
JM
2483 }
2484 else
1c5cb38e 2485 return INTEGER_CONVERSION_BADNESS;
c5aa993b
JM
2486 }
2487 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2488 return INTEGER_PROMOTION_BADNESS;
2489 else
1c5cb38e 2490 return INTEGER_CONVERSION_BADNESS;
c5aa993b
JM
2491 case TYPE_CODE_ENUM:
2492 case TYPE_CODE_CHAR:
2493 case TYPE_CODE_RANGE:
2494 case TYPE_CODE_BOOL:
2495 return INTEGER_PROMOTION_BADNESS;
2496 case TYPE_CODE_FLT:
2497 return INT_FLOAT_CONVERSION_BADNESS;
2498 case TYPE_CODE_PTR:
2499 return NS_POINTER_CONVERSION_BADNESS;
2500 default:
2501 return INCOMPATIBLE_TYPE_BADNESS;
2502 }
2503 break;
2504 case TYPE_CODE_ENUM:
2505 switch (TYPE_CODE (arg))
2506 {
2507 case TYPE_CODE_INT:
2508 case TYPE_CODE_CHAR:
2509 case TYPE_CODE_RANGE:
2510 case TYPE_CODE_BOOL:
2511 case TYPE_CODE_ENUM:
1c5cb38e 2512 return INTEGER_CONVERSION_BADNESS;
c5aa993b
JM
2513 case TYPE_CODE_FLT:
2514 return INT_FLOAT_CONVERSION_BADNESS;
2515 default:
2516 return INCOMPATIBLE_TYPE_BADNESS;
2517 }
2518 break;
2519 case TYPE_CODE_CHAR:
2520 switch (TYPE_CODE (arg))
2521 {
2522 case TYPE_CODE_RANGE:
2523 case TYPE_CODE_BOOL:
2524 case TYPE_CODE_ENUM:
1c5cb38e 2525 return INTEGER_CONVERSION_BADNESS;
c5aa993b
JM
2526 case TYPE_CODE_FLT:
2527 return INT_FLOAT_CONVERSION_BADNESS;
2528 case TYPE_CODE_INT:
2529 if (TYPE_LENGTH (arg) > TYPE_LENGTH (parm))
1c5cb38e 2530 return INTEGER_CONVERSION_BADNESS;
c5aa993b
JM
2531 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2532 return INTEGER_PROMOTION_BADNESS;
2533 /* >>> !! else fall through !! <<< */
2534 case TYPE_CODE_CHAR:
2535 /* Deal with signed, unsigned, and plain chars for C++
2536 and with int cases falling through from previous case */
2537 if (TYPE_NOSIGN (parm))
2538 {
2539 if (TYPE_NOSIGN (arg))
2540 return 0;
2541 else
1c5cb38e 2542 return INTEGER_CONVERSION_BADNESS;
c5aa993b
JM
2543 }
2544 else if (TYPE_UNSIGNED (parm))
2545 {
2546 if (TYPE_UNSIGNED (arg))
2547 return 0;
2548 else
2549 return INTEGER_PROMOTION_BADNESS;
2550 }
2551 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
2552 return 0;
2553 else
1c5cb38e 2554 return INTEGER_CONVERSION_BADNESS;
c5aa993b
JM
2555 default:
2556 return INCOMPATIBLE_TYPE_BADNESS;
2557 }
2558 break;
2559 case TYPE_CODE_RANGE:
2560 switch (TYPE_CODE (arg))
2561 {
2562 case TYPE_CODE_INT:
2563 case TYPE_CODE_CHAR:
2564 case TYPE_CODE_RANGE:
2565 case TYPE_CODE_BOOL:
2566 case TYPE_CODE_ENUM:
1c5cb38e 2567 return INTEGER_CONVERSION_BADNESS;
c5aa993b
JM
2568 case TYPE_CODE_FLT:
2569 return INT_FLOAT_CONVERSION_BADNESS;
2570 default:
2571 return INCOMPATIBLE_TYPE_BADNESS;
2572 }
2573 break;
2574 case TYPE_CODE_BOOL:
2575 switch (TYPE_CODE (arg))
2576 {
2577 case TYPE_CODE_INT:
2578 case TYPE_CODE_CHAR:
2579 case TYPE_CODE_RANGE:
2580 case TYPE_CODE_ENUM:
2581 case TYPE_CODE_FLT:
2582 case TYPE_CODE_PTR:
2583 return BOOLEAN_CONVERSION_BADNESS;
2584 case TYPE_CODE_BOOL:
2585 return 0;
2586 default:
2587 return INCOMPATIBLE_TYPE_BADNESS;
2588 }
2589 break;
2590 case TYPE_CODE_FLT:
2591 switch (TYPE_CODE (arg))
2592 {
2593 case TYPE_CODE_FLT:
2594 if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2595 return FLOAT_PROMOTION_BADNESS;
2596 else if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
2597 return 0;
2598 else
2599 return FLOAT_CONVERSION_BADNESS;
2600 case TYPE_CODE_INT:
2601 case TYPE_CODE_BOOL:
2602 case TYPE_CODE_ENUM:
2603 case TYPE_CODE_RANGE:
2604 case TYPE_CODE_CHAR:
2605 return INT_FLOAT_CONVERSION_BADNESS;
2606 default:
2607 return INCOMPATIBLE_TYPE_BADNESS;
2608 }
2609 break;
2610 case TYPE_CODE_COMPLEX:
2611 switch (TYPE_CODE (arg))
2612 { /* Strictly not needed for C++, but... */
2613 case TYPE_CODE_FLT:
2614 return FLOAT_PROMOTION_BADNESS;
2615 case TYPE_CODE_COMPLEX:
2616 return 0;
2617 default:
2618 return INCOMPATIBLE_TYPE_BADNESS;
2619 }
2620 break;
2621 case TYPE_CODE_STRUCT:
c906108c 2622 /* currently same as TYPE_CODE_CLASS */
c5aa993b
JM
2623 switch (TYPE_CODE (arg))
2624 {
2625 case TYPE_CODE_STRUCT:
2626 /* Check for derivation */
2627 if (is_ancestor (parm, arg))
2628 return BASE_CONVERSION_BADNESS;
2629 /* else fall through */
2630 default:
2631 return INCOMPATIBLE_TYPE_BADNESS;
2632 }
2633 break;
2634 case TYPE_CODE_UNION:
2635 switch (TYPE_CODE (arg))
2636 {
2637 case TYPE_CODE_UNION:
2638 default:
2639 return INCOMPATIBLE_TYPE_BADNESS;
2640 }
2641 break;
2642 case TYPE_CODE_MEMBER:
2643 switch (TYPE_CODE (arg))
2644 {
2645 default:
2646 return INCOMPATIBLE_TYPE_BADNESS;
2647 }
2648 break;
2649 case TYPE_CODE_METHOD:
2650 switch (TYPE_CODE (arg))
2651 {
2652
2653 default:
2654 return INCOMPATIBLE_TYPE_BADNESS;
2655 }
2656 break;
2657 case TYPE_CODE_REF:
2658 switch (TYPE_CODE (arg))
2659 {
2660
2661 default:
2662 return INCOMPATIBLE_TYPE_BADNESS;
2663 }
2664
2665 break;
2666 case TYPE_CODE_SET:
2667 switch (TYPE_CODE (arg))
2668 {
2669 /* Not in C++ */
2670 case TYPE_CODE_SET:
2671 return rank_one_type (TYPE_FIELD_TYPE (parm, 0), TYPE_FIELD_TYPE (arg, 0));
2672 default:
2673 return INCOMPATIBLE_TYPE_BADNESS;
2674 }
2675 break;
2676 case TYPE_CODE_VOID:
2677 default:
2678 return INCOMPATIBLE_TYPE_BADNESS;
2679 } /* switch (TYPE_CODE (arg)) */
c906108c
SS
2680}
2681
c5aa993b
JM
2682
2683/* End of functions for overload resolution */
c906108c 2684
c906108c 2685static void
fba45db2 2686print_bit_vector (B_TYPE *bits, int nbits)
c906108c
SS
2687{
2688 int bitno;
2689
2690 for (bitno = 0; bitno < nbits; bitno++)
2691 {
2692 if ((bitno % 8) == 0)
2693 {
2694 puts_filtered (" ");
2695 }
2696 if (B_TST (bits, bitno))
a3f17187 2697 printf_filtered (("1"));
c906108c 2698 else
a3f17187 2699 printf_filtered (("0"));
c906108c
SS
2700 }
2701}
2702
ad2f7632
DJ
2703/* Note the first arg should be the "this" pointer, we may not want to
2704 include it since we may get into a infinitely recursive situation. */
c906108c
SS
2705
2706static void
ad2f7632 2707print_arg_types (struct field *args, int nargs, int spaces)
c906108c
SS
2708{
2709 if (args != NULL)
2710 {
ad2f7632
DJ
2711 int i;
2712
2713 for (i = 0; i < nargs; i++)
2714 recursive_dump_type (args[i].type, spaces + 2);
c906108c
SS
2715 }
2716}
2717
2718static void
fba45db2 2719dump_fn_fieldlists (struct type *type, int spaces)
c906108c
SS
2720{
2721 int method_idx;
2722 int overload_idx;
2723 struct fn_field *f;
2724
2725 printfi_filtered (spaces, "fn_fieldlists ");
d4f3574e 2726 gdb_print_host_address (TYPE_FN_FIELDLISTS (type), gdb_stdout);
c906108c
SS
2727 printf_filtered ("\n");
2728 for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++)
2729 {
2730 f = TYPE_FN_FIELDLIST1 (type, method_idx);
2731 printfi_filtered (spaces + 2, "[%d] name '%s' (",
2732 method_idx,
2733 TYPE_FN_FIELDLIST_NAME (type, method_idx));
d4f3574e
SS
2734 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type, method_idx),
2735 gdb_stdout);
a3f17187 2736 printf_filtered (_(") length %d\n"),
c906108c
SS
2737 TYPE_FN_FIELDLIST_LENGTH (type, method_idx));
2738 for (overload_idx = 0;
2739 overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx);
2740 overload_idx++)
2741 {
2742 printfi_filtered (spaces + 4, "[%d] physname '%s' (",
2743 overload_idx,
2744 TYPE_FN_FIELD_PHYSNAME (f, overload_idx));
d4f3574e
SS
2745 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f, overload_idx),
2746 gdb_stdout);
c906108c
SS
2747 printf_filtered (")\n");
2748 printfi_filtered (spaces + 8, "type ");
d4f3574e 2749 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f, overload_idx), gdb_stdout);
c906108c
SS
2750 printf_filtered ("\n");
2751
2752 recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx),
2753 spaces + 8 + 2);
2754
2755 printfi_filtered (spaces + 8, "args ");
d4f3574e 2756 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f, overload_idx), gdb_stdout);
c906108c
SS
2757 printf_filtered ("\n");
2758
ad2f7632
DJ
2759 print_arg_types (TYPE_FN_FIELD_ARGS (f, overload_idx),
2760 TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f, overload_idx)),
2761 spaces);
c906108c 2762 printfi_filtered (spaces + 8, "fcontext ");
d4f3574e
SS
2763 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx),
2764 gdb_stdout);
c906108c
SS
2765 printf_filtered ("\n");
2766
2767 printfi_filtered (spaces + 8, "is_const %d\n",
2768 TYPE_FN_FIELD_CONST (f, overload_idx));
2769 printfi_filtered (spaces + 8, "is_volatile %d\n",
2770 TYPE_FN_FIELD_VOLATILE (f, overload_idx));
2771 printfi_filtered (spaces + 8, "is_private %d\n",
2772 TYPE_FN_FIELD_PRIVATE (f, overload_idx));
2773 printfi_filtered (spaces + 8, "is_protected %d\n",
2774 TYPE_FN_FIELD_PROTECTED (f, overload_idx));
2775 printfi_filtered (spaces + 8, "is_stub %d\n",
2776 TYPE_FN_FIELD_STUB (f, overload_idx));
2777 printfi_filtered (spaces + 8, "voffset %u\n",
2778 TYPE_FN_FIELD_VOFFSET (f, overload_idx));
2779 }
2780 }
2781}
2782
2783static void
fba45db2 2784print_cplus_stuff (struct type *type, int spaces)
c906108c
SS
2785{
2786 printfi_filtered (spaces, "n_baseclasses %d\n",
2787 TYPE_N_BASECLASSES (type));
2788 printfi_filtered (spaces, "nfn_fields %d\n",
2789 TYPE_NFN_FIELDS (type));
2790 printfi_filtered (spaces, "nfn_fields_total %d\n",
2791 TYPE_NFN_FIELDS_TOTAL (type));
2792 if (TYPE_N_BASECLASSES (type) > 0)
2793 {
2794 printfi_filtered (spaces, "virtual_field_bits (%d bits at *",
2795 TYPE_N_BASECLASSES (type));
d4f3574e 2796 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type), gdb_stdout);
c906108c
SS
2797 printf_filtered (")");
2798
2799 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type),
2800 TYPE_N_BASECLASSES (type));
2801 puts_filtered ("\n");
2802 }
2803 if (TYPE_NFIELDS (type) > 0)
2804 {
2805 if (TYPE_FIELD_PRIVATE_BITS (type) != NULL)
2806 {
2807 printfi_filtered (spaces, "private_field_bits (%d bits at *",
2808 TYPE_NFIELDS (type));
d4f3574e 2809 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type), gdb_stdout);
c906108c
SS
2810 printf_filtered (")");
2811 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type),
2812 TYPE_NFIELDS (type));
2813 puts_filtered ("\n");
2814 }
2815 if (TYPE_FIELD_PROTECTED_BITS (type) != NULL)
2816 {
2817 printfi_filtered (spaces, "protected_field_bits (%d bits at *",
2818 TYPE_NFIELDS (type));
d4f3574e 2819 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type), gdb_stdout);
c906108c
SS
2820 printf_filtered (")");
2821 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type),
2822 TYPE_NFIELDS (type));
2823 puts_filtered ("\n");
2824 }
2825 }
2826 if (TYPE_NFN_FIELDS (type) > 0)
2827 {
2828 dump_fn_fieldlists (type, spaces);
2829 }
2830}
2831
e9e79dd9
FF
2832static void
2833print_bound_type (int bt)
2834{
2835 switch (bt)
2836 {
2837 case BOUND_CANNOT_BE_DETERMINED:
2838 printf_filtered ("(BOUND_CANNOT_BE_DETERMINED)");
2839 break;
2840 case BOUND_BY_REF_ON_STACK:
2841 printf_filtered ("(BOUND_BY_REF_ON_STACK)");
2842 break;
2843 case BOUND_BY_VALUE_ON_STACK:
2844 printf_filtered ("(BOUND_BY_VALUE_ON_STACK)");
2845 break;
2846 case BOUND_BY_REF_IN_REG:
2847 printf_filtered ("(BOUND_BY_REF_IN_REG)");
2848 break;
2849 case BOUND_BY_VALUE_IN_REG:
2850 printf_filtered ("(BOUND_BY_VALUE_IN_REG)");
2851 break;
2852 case BOUND_SIMPLE:
2853 printf_filtered ("(BOUND_SIMPLE)");
2854 break;
2855 default:
a3f17187 2856 printf_filtered (_("(unknown bound type)"));
e9e79dd9
FF
2857 break;
2858 }
2859}
2860
c906108c
SS
2861static struct obstack dont_print_type_obstack;
2862
2863void
fba45db2 2864recursive_dump_type (struct type *type, int spaces)
c906108c
SS
2865{
2866 int idx;
2867
2868 if (spaces == 0)
2869 obstack_begin (&dont_print_type_obstack, 0);
2870
2871 if (TYPE_NFIELDS (type) > 0
2872 || (TYPE_CPLUS_SPECIFIC (type) && TYPE_NFN_FIELDS (type) > 0))
2873 {
2874 struct type **first_dont_print
c5aa993b 2875 = (struct type **) obstack_base (&dont_print_type_obstack);
c906108c 2876
c5aa993b
JM
2877 int i = (struct type **) obstack_next_free (&dont_print_type_obstack)
2878 - first_dont_print;
c906108c
SS
2879
2880 while (--i >= 0)
2881 {
2882 if (type == first_dont_print[i])
2883 {
2884 printfi_filtered (spaces, "type node ");
d4f3574e 2885 gdb_print_host_address (type, gdb_stdout);
a3f17187 2886 printf_filtered (_(" <same as already seen type>\n"));
c906108c
SS
2887 return;
2888 }
2889 }
2890
2891 obstack_ptr_grow (&dont_print_type_obstack, type);
2892 }
2893
2894 printfi_filtered (spaces, "type node ");
d4f3574e 2895 gdb_print_host_address (type, gdb_stdout);
c906108c
SS
2896 printf_filtered ("\n");
2897 printfi_filtered (spaces, "name '%s' (",
2898 TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>");
d4f3574e 2899 gdb_print_host_address (TYPE_NAME (type), gdb_stdout);
c906108c 2900 printf_filtered (")\n");
e9e79dd9
FF
2901 printfi_filtered (spaces, "tagname '%s' (",
2902 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : "<NULL>");
2903 gdb_print_host_address (TYPE_TAG_NAME (type), gdb_stdout);
2904 printf_filtered (")\n");
c906108c
SS
2905 printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type));
2906 switch (TYPE_CODE (type))
2907 {
c5aa993b
JM
2908 case TYPE_CODE_UNDEF:
2909 printf_filtered ("(TYPE_CODE_UNDEF)");
2910 break;
2911 case TYPE_CODE_PTR:
2912 printf_filtered ("(TYPE_CODE_PTR)");
2913 break;
2914 case TYPE_CODE_ARRAY:
2915 printf_filtered ("(TYPE_CODE_ARRAY)");
2916 break;
2917 case TYPE_CODE_STRUCT:
2918 printf_filtered ("(TYPE_CODE_STRUCT)");
2919 break;
2920 case TYPE_CODE_UNION:
2921 printf_filtered ("(TYPE_CODE_UNION)");
2922 break;
2923 case TYPE_CODE_ENUM:
2924 printf_filtered ("(TYPE_CODE_ENUM)");
2925 break;
2926 case TYPE_CODE_FUNC:
2927 printf_filtered ("(TYPE_CODE_FUNC)");
2928 break;
2929 case TYPE_CODE_INT:
2930 printf_filtered ("(TYPE_CODE_INT)");
2931 break;
2932 case TYPE_CODE_FLT:
2933 printf_filtered ("(TYPE_CODE_FLT)");
2934 break;
2935 case TYPE_CODE_VOID:
2936 printf_filtered ("(TYPE_CODE_VOID)");
2937 break;
2938 case TYPE_CODE_SET:
2939 printf_filtered ("(TYPE_CODE_SET)");
2940 break;
2941 case TYPE_CODE_RANGE:
2942 printf_filtered ("(TYPE_CODE_RANGE)");
2943 break;
2944 case TYPE_CODE_STRING:
2945 printf_filtered ("(TYPE_CODE_STRING)");
2946 break;
e9e79dd9
FF
2947 case TYPE_CODE_BITSTRING:
2948 printf_filtered ("(TYPE_CODE_BITSTRING)");
2949 break;
c5aa993b
JM
2950 case TYPE_CODE_ERROR:
2951 printf_filtered ("(TYPE_CODE_ERROR)");
2952 break;
2953 case TYPE_CODE_MEMBER:
2954 printf_filtered ("(TYPE_CODE_MEMBER)");
2955 break;
2956 case TYPE_CODE_METHOD:
2957 printf_filtered ("(TYPE_CODE_METHOD)");
2958 break;
2959 case TYPE_CODE_REF:
2960 printf_filtered ("(TYPE_CODE_REF)");
2961 break;
2962 case TYPE_CODE_CHAR:
2963 printf_filtered ("(TYPE_CODE_CHAR)");
2964 break;
2965 case TYPE_CODE_BOOL:
2966 printf_filtered ("(TYPE_CODE_BOOL)");
2967 break;
e9e79dd9
FF
2968 case TYPE_CODE_COMPLEX:
2969 printf_filtered ("(TYPE_CODE_COMPLEX)");
2970 break;
c5aa993b
JM
2971 case TYPE_CODE_TYPEDEF:
2972 printf_filtered ("(TYPE_CODE_TYPEDEF)");
2973 break;
e9e79dd9
FF
2974 case TYPE_CODE_TEMPLATE:
2975 printf_filtered ("(TYPE_CODE_TEMPLATE)");
2976 break;
2977 case TYPE_CODE_TEMPLATE_ARG:
2978 printf_filtered ("(TYPE_CODE_TEMPLATE_ARG)");
2979 break;
5c4e30ca
DC
2980 case TYPE_CODE_NAMESPACE:
2981 printf_filtered ("(TYPE_CODE_NAMESPACE)");
2982 break;
c5aa993b
JM
2983 default:
2984 printf_filtered ("(UNKNOWN TYPE CODE)");
2985 break;
c906108c
SS
2986 }
2987 puts_filtered ("\n");
2988 printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type));
e9e79dd9
FF
2989 printfi_filtered (spaces, "upper_bound_type 0x%x ",
2990 TYPE_ARRAY_UPPER_BOUND_TYPE (type));
2991 print_bound_type (TYPE_ARRAY_UPPER_BOUND_TYPE (type));
2992 puts_filtered ("\n");
2993 printfi_filtered (spaces, "lower_bound_type 0x%x ",
2994 TYPE_ARRAY_LOWER_BOUND_TYPE (type));
2995 print_bound_type (TYPE_ARRAY_LOWER_BOUND_TYPE (type));
2996 puts_filtered ("\n");
c906108c 2997 printfi_filtered (spaces, "objfile ");
d4f3574e 2998 gdb_print_host_address (TYPE_OBJFILE (type), gdb_stdout);
c906108c
SS
2999 printf_filtered ("\n");
3000 printfi_filtered (spaces, "target_type ");
d4f3574e 3001 gdb_print_host_address (TYPE_TARGET_TYPE (type), gdb_stdout);
c906108c
SS
3002 printf_filtered ("\n");
3003 if (TYPE_TARGET_TYPE (type) != NULL)
3004 {
3005 recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2);
3006 }
3007 printfi_filtered (spaces, "pointer_type ");
d4f3574e 3008 gdb_print_host_address (TYPE_POINTER_TYPE (type), gdb_stdout);
c906108c
SS
3009 printf_filtered ("\n");
3010 printfi_filtered (spaces, "reference_type ");
d4f3574e 3011 gdb_print_host_address (TYPE_REFERENCE_TYPE (type), gdb_stdout);
c906108c 3012 printf_filtered ("\n");
2fdde8f8
DJ
3013 printfi_filtered (spaces, "type_chain ");
3014 gdb_print_host_address (TYPE_CHAIN (type), gdb_stdout);
e9e79dd9 3015 printf_filtered ("\n");
2fdde8f8
DJ
3016 printfi_filtered (spaces, "instance_flags 0x%x", TYPE_INSTANCE_FLAGS (type));
3017 if (TYPE_CONST (type))
3018 {
3019 puts_filtered (" TYPE_FLAG_CONST");
3020 }
3021 if (TYPE_VOLATILE (type))
3022 {
3023 puts_filtered (" TYPE_FLAG_VOLATILE");
3024 }
3025 if (TYPE_CODE_SPACE (type))
3026 {
3027 puts_filtered (" TYPE_FLAG_CODE_SPACE");
3028 }
3029 if (TYPE_DATA_SPACE (type))
3030 {
3031 puts_filtered (" TYPE_FLAG_DATA_SPACE");
3032 }
8b2dbe47
KB
3033 if (TYPE_ADDRESS_CLASS_1 (type))
3034 {
3035 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_1");
3036 }
3037 if (TYPE_ADDRESS_CLASS_2 (type))
3038 {
3039 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_2");
3040 }
2fdde8f8 3041 puts_filtered ("\n");
c906108c 3042 printfi_filtered (spaces, "flags 0x%x", TYPE_FLAGS (type));
762a036f 3043 if (TYPE_UNSIGNED (type))
c906108c
SS
3044 {
3045 puts_filtered (" TYPE_FLAG_UNSIGNED");
3046 }
762a036f
FF
3047 if (TYPE_NOSIGN (type))
3048 {
3049 puts_filtered (" TYPE_FLAG_NOSIGN");
3050 }
3051 if (TYPE_STUB (type))
c906108c
SS
3052 {
3053 puts_filtered (" TYPE_FLAG_STUB");
3054 }
762a036f
FF
3055 if (TYPE_TARGET_STUB (type))
3056 {
3057 puts_filtered (" TYPE_FLAG_TARGET_STUB");
3058 }
3059 if (TYPE_STATIC (type))
3060 {
3061 puts_filtered (" TYPE_FLAG_STATIC");
3062 }
762a036f
FF
3063 if (TYPE_PROTOTYPED (type))
3064 {
3065 puts_filtered (" TYPE_FLAG_PROTOTYPED");
3066 }
3067 if (TYPE_INCOMPLETE (type))
3068 {
3069 puts_filtered (" TYPE_FLAG_INCOMPLETE");
3070 }
762a036f
FF
3071 if (TYPE_VARARGS (type))
3072 {
3073 puts_filtered (" TYPE_FLAG_VARARGS");
3074 }
f5f8a009
EZ
3075 /* This is used for things like AltiVec registers on ppc. Gcc emits
3076 an attribute for the array type, which tells whether or not we
3077 have a vector, instead of a regular array. */
3078 if (TYPE_VECTOR (type))
3079 {
3080 puts_filtered (" TYPE_FLAG_VECTOR");
3081 }
c906108c
SS
3082 puts_filtered ("\n");
3083 printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type));
d4f3574e 3084 gdb_print_host_address (TYPE_FIELDS (type), gdb_stdout);
c906108c
SS
3085 puts_filtered ("\n");
3086 for (idx = 0; idx < TYPE_NFIELDS (type); idx++)
3087 {
3088 printfi_filtered (spaces + 2,
3089 "[%d] bitpos %d bitsize %d type ",
3090 idx, TYPE_FIELD_BITPOS (type, idx),
3091 TYPE_FIELD_BITSIZE (type, idx));
d4f3574e 3092 gdb_print_host_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout);
c906108c
SS
3093 printf_filtered (" name '%s' (",
3094 TYPE_FIELD_NAME (type, idx) != NULL
3095 ? TYPE_FIELD_NAME (type, idx)
3096 : "<NULL>");
d4f3574e 3097 gdb_print_host_address (TYPE_FIELD_NAME (type, idx), gdb_stdout);
c906108c
SS
3098 printf_filtered (")\n");
3099 if (TYPE_FIELD_TYPE (type, idx) != NULL)
3100 {
3101 recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4);
3102 }
3103 }
3104 printfi_filtered (spaces, "vptr_basetype ");
d4f3574e 3105 gdb_print_host_address (TYPE_VPTR_BASETYPE (type), gdb_stdout);
c906108c
SS
3106 puts_filtered ("\n");
3107 if (TYPE_VPTR_BASETYPE (type) != NULL)
3108 {
3109 recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2);
3110 }
3111 printfi_filtered (spaces, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type));
3112 switch (TYPE_CODE (type))
3113 {
c5aa993b
JM
3114 case TYPE_CODE_STRUCT:
3115 printfi_filtered (spaces, "cplus_stuff ");
d4f3574e 3116 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
c5aa993b
JM
3117 puts_filtered ("\n");
3118 print_cplus_stuff (type, spaces);
3119 break;
c906108c 3120
701c159d
AC
3121 case TYPE_CODE_FLT:
3122 printfi_filtered (spaces, "floatformat ");
3123 if (TYPE_FLOATFORMAT (type) == NULL
3124 || TYPE_FLOATFORMAT (type)->name == NULL)
3125 puts_filtered ("(null)");
3126 else
3127 puts_filtered (TYPE_FLOATFORMAT (type)->name);
3128 puts_filtered ("\n");
3129 break;
3130
c5aa993b
JM
3131 default:
3132 /* We have to pick one of the union types to be able print and test
7b83ea04
AC
3133 the value. Pick cplus_struct_type, even though we know it isn't
3134 any particular one. */
c5aa993b 3135 printfi_filtered (spaces, "type_specific ");
d4f3574e 3136 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
c5aa993b
JM
3137 if (TYPE_CPLUS_SPECIFIC (type) != NULL)
3138 {
a3f17187 3139 printf_filtered (_(" (unknown data form)"));
c5aa993b
JM
3140 }
3141 printf_filtered ("\n");
3142 break;
c906108c
SS
3143
3144 }
3145 if (spaces == 0)
3146 obstack_free (&dont_print_type_obstack, NULL);
3147}
3148
a14ed312 3149static void build_gdbtypes (void);
c906108c 3150static void
fba45db2 3151build_gdbtypes (void)
c906108c
SS
3152{
3153 builtin_type_void =
3154 init_type (TYPE_CODE_VOID, 1,
3155 0,
3156 "void", (struct objfile *) NULL);
3157 builtin_type_char =
3158 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
4e409299
JB
3159 (TYPE_FLAG_NOSIGN
3160 | (TARGET_CHAR_SIGNED ? 0 : TYPE_FLAG_UNSIGNED)),
c906108c 3161 "char", (struct objfile *) NULL);
c5aa993b 3162 builtin_type_true_char =
9e0b60a8
JM
3163 init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3164 0,
3165 "true character", (struct objfile *) NULL);
c906108c
SS
3166 builtin_type_signed_char =
3167 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3168 0,
3169 "signed char", (struct objfile *) NULL);
3170 builtin_type_unsigned_char =
3171 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3172 TYPE_FLAG_UNSIGNED,
3173 "unsigned char", (struct objfile *) NULL);
3174 builtin_type_short =
3175 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
3176 0,
3177 "short", (struct objfile *) NULL);
3178 builtin_type_unsigned_short =
3179 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
3180 TYPE_FLAG_UNSIGNED,
3181 "unsigned short", (struct objfile *) NULL);
3182 builtin_type_int =
3183 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
3184 0,
3185 "int", (struct objfile *) NULL);
3186 builtin_type_unsigned_int =
3187 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
3188 TYPE_FLAG_UNSIGNED,
3189 "unsigned int", (struct objfile *) NULL);
3190 builtin_type_long =
3191 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
3192 0,
3193 "long", (struct objfile *) NULL);
3194 builtin_type_unsigned_long =
3195 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
3196 TYPE_FLAG_UNSIGNED,
3197 "unsigned long", (struct objfile *) NULL);
3198 builtin_type_long_long =
3199 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
3200 0,
3201 "long long", (struct objfile *) NULL);
c5aa993b 3202 builtin_type_unsigned_long_long =
c906108c
SS
3203 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
3204 TYPE_FLAG_UNSIGNED,
3205 "unsigned long long", (struct objfile *) NULL);
3206 builtin_type_float =
3207 init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
3208 0,
3209 "float", (struct objfile *) NULL);
9c9532c9
CV
3210/* vinschen@redhat.com 2002-02-08:
3211 The below lines are disabled since they are doing the wrong
3212 thing for non-multiarch targets. They are setting the correct
3213 type of floats for the target but while on multiarch targets
3214 this is done everytime the architecture changes, it's done on
3215 non-multiarch targets only on startup, leaving the wrong values
3216 in even if the architecture changes (eg. from big-endian to
3217 little-endian). */
3218#if 0
701c159d 3219 TYPE_FLOATFORMAT (builtin_type_float) = TARGET_FLOAT_FORMAT;
9c9532c9 3220#endif
c906108c
SS
3221 builtin_type_double =
3222 init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
3223 0,
3224 "double", (struct objfile *) NULL);
9c9532c9 3225#if 0
701c159d 3226 TYPE_FLOATFORMAT (builtin_type_double) = TARGET_DOUBLE_FORMAT;
9c9532c9 3227#endif
c906108c
SS
3228 builtin_type_long_double =
3229 init_type (TYPE_CODE_FLT, TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
3230 0,
3231 "long double", (struct objfile *) NULL);
9c9532c9 3232#if 0
701c159d 3233 TYPE_FLOATFORMAT (builtin_type_long_double) = TARGET_LONG_DOUBLE_FORMAT;
9c9532c9 3234#endif
c906108c
SS
3235 builtin_type_complex =
3236 init_type (TYPE_CODE_COMPLEX, 2 * TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
3237 0,
3238 "complex", (struct objfile *) NULL);
3239 TYPE_TARGET_TYPE (builtin_type_complex) = builtin_type_float;
3240 builtin_type_double_complex =
3241 init_type (TYPE_CODE_COMPLEX, 2 * TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
3242 0,
3243 "double complex", (struct objfile *) NULL);
3244 TYPE_TARGET_TYPE (builtin_type_double_complex) = builtin_type_double;
3245 builtin_type_string =
3246 init_type (TYPE_CODE_STRING, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3247 0,
3248 "string", (struct objfile *) NULL);
c906108c
SS
3249 builtin_type_bool =
3250 init_type (TYPE_CODE_BOOL, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3251 0,
3252 "bool", (struct objfile *) NULL);
3253
c5aa993b 3254 /* Add user knob for controlling resolution of opaque types */
5bf193a2
AC
3255 add_setshow_boolean_cmd ("opaque-type-resolution", class_support,
3256 &opaque_type_resolution, _("\
3257Set resolution of opaque struct/class/union types (if set before loading symbols)."), _("\
3258Show resolution of opaque struct/class/union types (if set before loading symbols)."), NULL,
3259 NULL,
3260 NULL, /* FIXME: i18n: */
3261 &setlist, &showlist);
c906108c
SS
3262 opaque_type_resolution = 1;
3263
917317f4
JM
3264 /* Build SIMD types. */
3265 builtin_type_v4sf
3266 = init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4);
c2d11a7d
JM
3267 builtin_type_v4si
3268 = init_simd_type ("__builtin_v4si", builtin_type_int32, "f", 4);
08cf96df
EZ
3269 builtin_type_v16qi
3270 = init_simd_type ("__builtin_v16qi", builtin_type_int8, "f", 16);
c2d11a7d
JM
3271 builtin_type_v8qi
3272 = init_simd_type ("__builtin_v8qi", builtin_type_int8, "f", 8);
08cf96df
EZ
3273 builtin_type_v8hi
3274 = init_simd_type ("__builtin_v8hi", builtin_type_int16, "f", 8);
c2d11a7d
JM
3275 builtin_type_v4hi
3276 = init_simd_type ("__builtin_v4hi", builtin_type_int16, "f", 4);
3277 builtin_type_v2si
3278 = init_simd_type ("__builtin_v2si", builtin_type_int32, "f", 2);
c4093a6a 3279
ac3aafc7 3280 /* 128 bit vectors. */
3139facc 3281 builtin_type_v2_double = init_vector_type (builtin_type_double, 2);
ac3aafc7 3282 builtin_type_v4_float = init_vector_type (builtin_type_float, 4);
3139facc 3283 builtin_type_v2_int64 = init_vector_type (builtin_type_int64, 2);
ac3aafc7
EZ
3284 builtin_type_v4_int32 = init_vector_type (builtin_type_int32, 4);
3285 builtin_type_v8_int16 = init_vector_type (builtin_type_int16, 8);
3286 builtin_type_v16_int8 = init_vector_type (builtin_type_int8, 16);
3287 /* 64 bit vectors. */
6599f021 3288 builtin_type_v2_float = init_vector_type (builtin_type_float, 2);
ac3aafc7
EZ
3289 builtin_type_v2_int32 = init_vector_type (builtin_type_int32, 2);
3290 builtin_type_v4_int16 = init_vector_type (builtin_type_int16, 4);
3291 builtin_type_v8_int8 = init_vector_type (builtin_type_int8, 8);
3292
b063e7a2
AC
3293 /* Vector types. */
3294 builtin_type_vec64 = build_builtin_type_vec64 ();
3295 builtin_type_vec64i = build_builtin_type_vec64i ();
ac3aafc7 3296 builtin_type_vec128 = build_builtin_type_vec128 ();
3139facc 3297 builtin_type_vec128i = build_builtin_type_vec128i ();
08cf96df 3298
c4093a6a 3299 /* Pointer/Address types. */
ee3a7b7f
JB
3300
3301 /* NOTE: on some targets, addresses and pointers are not necessarily
3302 the same --- for example, on the D10V, pointers are 16 bits long,
3303 but addresses are 32 bits long. See doc/gdbint.texinfo,
3304 ``Pointers Are Not Always Addresses''.
3305
3306 The upshot is:
3307 - gdb's `struct type' always describes the target's
3308 representation.
3309 - gdb's `struct value' objects should always hold values in
3310 target form.
3311 - gdb's CORE_ADDR values are addresses in the unified virtual
3312 address space that the assembler and linker work with. Thus,
3313 since target_read_memory takes a CORE_ADDR as an argument, it
3314 can access any memory on the target, even if the processor has
3315 separate code and data address spaces.
3316
3317 So, for example:
3318 - If v is a value holding a D10V code pointer, its contents are
3319 in target form: a big-endian address left-shifted two bits.
3320 - If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as
3321 sizeof (void *) == 2 on the target.
3322
3323 In this context, builtin_type_CORE_ADDR is a bit odd: it's a
3324 target type for a value the target will never see. It's only
3325 used to hold the values of (typeless) linker symbols, which are
3326 indeed in the unified virtual address space. */
090a2205 3327 builtin_type_void_data_ptr = make_pointer_type (builtin_type_void, NULL);
ee3a7b7f
JB
3328 builtin_type_void_func_ptr
3329 = lookup_pointer_type (lookup_function_type (builtin_type_void));
c4093a6a 3330 builtin_type_CORE_ADDR =
52204a0b 3331 init_type (TYPE_CODE_INT, TARGET_ADDR_BIT / 8,
c4093a6a
JM
3332 TYPE_FLAG_UNSIGNED,
3333 "__CORE_ADDR", (struct objfile *) NULL);
3334 builtin_type_bfd_vma =
3335 init_type (TYPE_CODE_INT, TARGET_BFD_VMA_BIT / 8,
3336 TYPE_FLAG_UNSIGNED,
3337 "__bfd_vma", (struct objfile *) NULL);
c906108c
SS
3338}
3339
000177f0
AC
3340static struct gdbarch_data *gdbtypes_data;
3341
3342const struct builtin_type *
3343builtin_type (struct gdbarch *gdbarch)
3344{
3345 return gdbarch_data (gdbarch, gdbtypes_data);
3346}
3347
70bd8e24
AC
3348
3349static struct type *
3350build_flt (int bit, char *name, const struct floatformat *floatformat)
3351{
3352 struct type *t;
3353 if (bit <= 0 || floatformat == NULL)
3354 {
3355 gdb_assert (builtin_type_error != NULL);
3356 return builtin_type_error;
3357 }
3358 t = init_type (TYPE_CODE_FLT, bit / TARGET_CHAR_BIT,
3359 0, name, (struct objfile *) NULL);
3360 TYPE_FLOATFORMAT (t) = floatformat;
3361 return t;
3362}
3363
3364static struct type *
3365build_complex (int bit, char *name, struct type *target_type)
3366{
3367 struct type *t;
3368 if (bit <= 0 || target_type == builtin_type_error)
3369 {
3370 gdb_assert (builtin_type_error != NULL);
3371 return builtin_type_error;
3372 }
3373 t = init_type (TYPE_CODE_COMPLEX, 2 * bit / TARGET_CHAR_BIT,
3374 0, name, (struct objfile *) NULL);
3375 TYPE_TARGET_TYPE (t) = target_type;
3376 return t;
3377}
3378
000177f0
AC
3379static void *
3380gdbtypes_post_init (struct gdbarch *gdbarch)
3381{
3382 struct builtin_type *builtin_type
3383 = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_type);
3384
3385 builtin_type->builtin_void =
3386 init_type (TYPE_CODE_VOID, 1,
3387 0,
3388 "void", (struct objfile *) NULL);
3389 builtin_type->builtin_char =
3390 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3391 (TYPE_FLAG_NOSIGN
3392 | (TARGET_CHAR_SIGNED ? 0 : TYPE_FLAG_UNSIGNED)),
3393 "char", (struct objfile *) NULL);
685419e2 3394 builtin_type->builtin_true_char =
000177f0
AC
3395 init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3396 0,
3397 "true character", (struct objfile *) NULL);
3398 builtin_type->builtin_signed_char =
3399 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3400 0,
3401 "signed char", (struct objfile *) NULL);
3402 builtin_type->builtin_unsigned_char =
3403 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3404 TYPE_FLAG_UNSIGNED,
3405 "unsigned char", (struct objfile *) NULL);
3406 builtin_type->builtin_short =
3407 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
3408 0,
3409 "short", (struct objfile *) NULL);
3410 builtin_type->builtin_unsigned_short =
3411 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
3412 TYPE_FLAG_UNSIGNED,
3413 "unsigned short", (struct objfile *) NULL);
3414 builtin_type->builtin_int =
3415 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
3416 0,
3417 "int", (struct objfile *) NULL);
3418 builtin_type->builtin_unsigned_int =
3419 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
3420 TYPE_FLAG_UNSIGNED,
3421 "unsigned int", (struct objfile *) NULL);
3422 builtin_type->builtin_long =
3423 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
3424 0,
3425 "long", (struct objfile *) NULL);
3426 builtin_type->builtin_unsigned_long =
3427 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
3428 TYPE_FLAG_UNSIGNED,
3429 "unsigned long", (struct objfile *) NULL);
3430 builtin_type->builtin_long_long =
3431 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
3432 0,
3433 "long long", (struct objfile *) NULL);
3434 builtin_type->builtin_unsigned_long_long =
3435 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
3436 TYPE_FLAG_UNSIGNED,
3437 "unsigned long long", (struct objfile *) NULL);
70bd8e24
AC
3438 builtin_type->builtin_float
3439 = build_flt (gdbarch_float_bit (gdbarch), "float",
3440 gdbarch_float_format (gdbarch));
3441 builtin_type->builtin_double
3442 = build_flt (gdbarch_double_bit (gdbarch), "double",
3443 gdbarch_double_format (gdbarch));
3444 builtin_type->builtin_long_double
3445 = build_flt (gdbarch_long_double_bit (gdbarch), "long double",
3446 gdbarch_long_double_format (gdbarch));
3447 builtin_type->builtin_complex
3448 = build_complex (gdbarch_float_bit (gdbarch), "complex",
3449 builtin_type->builtin_float);
3450 builtin_type->builtin_double_complex
3451 = build_complex (gdbarch_double_bit (gdbarch), "double complex",
3452 builtin_type->builtin_double);
000177f0
AC
3453 builtin_type->builtin_string =
3454 init_type (TYPE_CODE_STRING, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3455 0,
3456 "string", (struct objfile *) NULL);
000177f0
AC
3457 builtin_type->builtin_bool =
3458 init_type (TYPE_CODE_BOOL, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3459 0,
3460 "bool", (struct objfile *) NULL);
3461
3462 /* Pointer/Address types. */
3463
3464 /* NOTE: on some targets, addresses and pointers are not necessarily
3465 the same --- for example, on the D10V, pointers are 16 bits long,
3466 but addresses are 32 bits long. See doc/gdbint.texinfo,
3467 ``Pointers Are Not Always Addresses''.
3468
3469 The upshot is:
3470 - gdb's `struct type' always describes the target's
3471 representation.
3472 - gdb's `struct value' objects should always hold values in
3473 target form.
3474 - gdb's CORE_ADDR values are addresses in the unified virtual
3475 address space that the assembler and linker work with. Thus,
3476 since target_read_memory takes a CORE_ADDR as an argument, it
3477 can access any memory on the target, even if the processor has
3478 separate code and data address spaces.
3479
3480 So, for example:
3481 - If v is a value holding a D10V code pointer, its contents are
3482 in target form: a big-endian address left-shifted two bits.
3483 - If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as
3484 sizeof (void *) == 2 on the target.
3485
3486 In this context, builtin_type->CORE_ADDR is a bit odd: it's a
3487 target type for a value the target will never see. It's only
3488 used to hold the values of (typeless) linker symbols, which are
3489 indeed in the unified virtual address space. */
3490 builtin_type->builtin_data_ptr
3491 = make_pointer_type (builtin_type->builtin_void, NULL);
3492 builtin_type->builtin_func_ptr
3493 = lookup_pointer_type (lookup_function_type (builtin_type->builtin_void));
3494 builtin_type->builtin_core_addr =
3495 init_type (TYPE_CODE_INT, TARGET_ADDR_BIT / 8,
3496 TYPE_FLAG_UNSIGNED,
3497 "__CORE_ADDR", (struct objfile *) NULL);
3498
3499 return builtin_type;
3500}
3501
a14ed312 3502extern void _initialize_gdbtypes (void);
c906108c 3503void
fba45db2 3504_initialize_gdbtypes (void)
c906108c 3505{
5d161b24 3506 struct cmd_list_element *c;
7ad6570d
AC
3507
3508 builtin_type_int0 =
3509 init_type (TYPE_CODE_INT, 0 / 8,
3510 0,
3511 "int0_t", (struct objfile *) NULL);
3512 builtin_type_int8 =
3513 init_type (TYPE_CODE_INT, 8 / 8,
3514 0,
3515 "int8_t", (struct objfile *) NULL);
3516 builtin_type_uint8 =
3517 init_type (TYPE_CODE_INT, 8 / 8,
3518 TYPE_FLAG_UNSIGNED,
3519 "uint8_t", (struct objfile *) NULL);
3520 builtin_type_int16 =
3521 init_type (TYPE_CODE_INT, 16 / 8,
3522 0,
3523 "int16_t", (struct objfile *) NULL);
3524 builtin_type_uint16 =
3525 init_type (TYPE_CODE_INT, 16 / 8,
3526 TYPE_FLAG_UNSIGNED,
3527 "uint16_t", (struct objfile *) NULL);
3528 builtin_type_int32 =
3529 init_type (TYPE_CODE_INT, 32 / 8,
3530 0,
3531 "int32_t", (struct objfile *) NULL);
3532 builtin_type_uint32 =
3533 init_type (TYPE_CODE_INT, 32 / 8,
3534 TYPE_FLAG_UNSIGNED,
3535 "uint32_t", (struct objfile *) NULL);
3536 builtin_type_int64 =
3537 init_type (TYPE_CODE_INT, 64 / 8,
3538 0,
3539 "int64_t", (struct objfile *) NULL);
3540 builtin_type_uint64 =
3541 init_type (TYPE_CODE_INT, 64 / 8,
3542 TYPE_FLAG_UNSIGNED,
3543 "uint64_t", (struct objfile *) NULL);
3544 builtin_type_int128 =
3545 init_type (TYPE_CODE_INT, 128 / 8,
3546 0,
3547 "int128_t", (struct objfile *) NULL);
3548 builtin_type_uint128 =
3549 init_type (TYPE_CODE_INT, 128 / 8,
3550 TYPE_FLAG_UNSIGNED,
3551 "uint128_t", (struct objfile *) NULL);
3552
c906108c 3553 build_gdbtypes ();
0f71a2f6 3554
000177f0
AC
3555 gdbtypes_data = gdbarch_data_register_post_init (gdbtypes_post_init);
3556
0f71a2f6
JM
3557 /* FIXME - For the moment, handle types by swapping them in and out.
3558 Should be using the per-architecture data-pointer and a large
3559 struct. */
046a4708
AC
3560 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_void);
3561 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_char);
3562 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_short);
3563 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_int);
3564 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_long);
3565 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_long_long);
3566 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_signed_char);
3567 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_char);
3568 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_short);
3569 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_int);
3570 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_long);
3571 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_long_long);
3572 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_float);
3573 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_double);
3574 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_long_double);
3575 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_complex);
3576 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_double_complex);
3577 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_string);
046a4708
AC
3578 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4sf);
3579 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4si);
3580 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v16qi);
3581 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v8qi);
3582 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v8hi);
3583 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4hi);
3584 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2si);
3585 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2_double);
3586 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4_float);
3587 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2_int64);
3588 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4_int32);
3589 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v8_int16);
3590 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v16_int8);
3591 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2_float);
3592 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2_int32);
3593 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v8_int8);
3594 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4_int16);
3595 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_vec128);
3596 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_vec128i);
3597 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_void_data_ptr);
3598 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_void_func_ptr);
3599 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_CORE_ADDR);
3600 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_bfd_vma);
3601 deprecated_register_gdbarch_swap (NULL, 0, build_gdbtypes);
5d161b24 3602
598f52df
AC
3603 /* Note: These types do not need to be swapped - they are target
3604 neutral. */
3605 builtin_type_ieee_single_big =
3606 init_type (TYPE_CODE_FLT, floatformat_ieee_single_big.totalsize / 8,
3607 0, "builtin_type_ieee_single_big", NULL);
3608 TYPE_FLOATFORMAT (builtin_type_ieee_single_big) = &floatformat_ieee_single_big;
3609 builtin_type_ieee_single_little =
3610 init_type (TYPE_CODE_FLT, floatformat_ieee_single_little.totalsize / 8,
3611 0, "builtin_type_ieee_single_little", NULL);
069e84fd 3612 TYPE_FLOATFORMAT (builtin_type_ieee_single_little) = &floatformat_ieee_single_little;
5ef2d0aa
AC
3613 builtin_type_ieee_single[BFD_ENDIAN_BIG]
3614 = build_flt (floatformat_ieee_single_big.totalsize,
3615 "builtin_type_ieee_single_big",
3616 &floatformat_ieee_single_big);
3617 builtin_type_ieee_single[BFD_ENDIAN_LITTLE]
3618 = build_flt (floatformat_ieee_single_little.totalsize,
3619 "builtin_type_ieee_single_little",
3620 &floatformat_ieee_single_little);
598f52df
AC
3621 builtin_type_ieee_double_big =
3622 init_type (TYPE_CODE_FLT, floatformat_ieee_double_big.totalsize / 8,
3623 0, "builtin_type_ieee_double_big", NULL);
069e84fd 3624 TYPE_FLOATFORMAT (builtin_type_ieee_double_big) = &floatformat_ieee_double_big;
598f52df
AC
3625 builtin_type_ieee_double_little =
3626 init_type (TYPE_CODE_FLT, floatformat_ieee_double_little.totalsize / 8,
3627 0, "builtin_type_ieee_double_little", NULL);
069e84fd 3628 TYPE_FLOATFORMAT (builtin_type_ieee_double_little) = &floatformat_ieee_double_little;
5ef2d0aa
AC
3629 builtin_type_ieee_double[BFD_ENDIAN_BIG]
3630 = build_flt (floatformat_ieee_double_big.totalsize,
3631 "builtin_type_ieee_double_big",
3632 &floatformat_ieee_double_big);
3633 builtin_type_ieee_double[BFD_ENDIAN_LITTLE]
3634 = build_flt (floatformat_ieee_double_little.totalsize,
3635 "builtin_type_ieee_double_little",
3636 &floatformat_ieee_double_little);
598f52df
AC
3637 builtin_type_ieee_double_littlebyte_bigword =
3638 init_type (TYPE_CODE_FLT, floatformat_ieee_double_littlebyte_bigword.totalsize / 8,
3639 0, "builtin_type_ieee_double_littlebyte_bigword", NULL);
069e84fd 3640 TYPE_FLOATFORMAT (builtin_type_ieee_double_littlebyte_bigword) = &floatformat_ieee_double_littlebyte_bigword;
598f52df
AC
3641 builtin_type_i387_ext =
3642 init_type (TYPE_CODE_FLT, floatformat_i387_ext.totalsize / 8,
3643 0, "builtin_type_i387_ext", NULL);
e371b258 3644 TYPE_FLOATFORMAT (builtin_type_i387_ext) = &floatformat_i387_ext;
598f52df
AC
3645 builtin_type_m68881_ext =
3646 init_type (TYPE_CODE_FLT, floatformat_m68881_ext.totalsize / 8,
3647 0, "builtin_type_m68881_ext", NULL);
069e84fd 3648 TYPE_FLOATFORMAT (builtin_type_m68881_ext) = &floatformat_m68881_ext;
598f52df
AC
3649 builtin_type_i960_ext =
3650 init_type (TYPE_CODE_FLT, floatformat_i960_ext.totalsize / 8,
3651 0, "builtin_type_i960_ext", NULL);
069e84fd 3652 TYPE_FLOATFORMAT (builtin_type_i960_ext) = &floatformat_i960_ext;
598f52df
AC
3653 builtin_type_m88110_ext =
3654 init_type (TYPE_CODE_FLT, floatformat_m88110_ext.totalsize / 8,
3655 0, "builtin_type_m88110_ext", NULL);
069e84fd 3656 TYPE_FLOATFORMAT (builtin_type_m88110_ext) = &floatformat_m88110_ext;
598f52df
AC
3657 builtin_type_m88110_harris_ext =
3658 init_type (TYPE_CODE_FLT, floatformat_m88110_harris_ext.totalsize / 8,
3659 0, "builtin_type_m88110_harris_ext", NULL);
069e84fd 3660 TYPE_FLOATFORMAT (builtin_type_m88110_harris_ext) = &floatformat_m88110_harris_ext;
598f52df
AC
3661 builtin_type_arm_ext_big =
3662 init_type (TYPE_CODE_FLT, floatformat_arm_ext_big.totalsize / 8,
3663 0, "builtin_type_arm_ext_big", NULL);
069e84fd 3664 TYPE_FLOATFORMAT (builtin_type_arm_ext_big) = &floatformat_arm_ext_big;
598f52df
AC
3665 builtin_type_arm_ext_littlebyte_bigword =
3666 init_type (TYPE_CODE_FLT, floatformat_arm_ext_littlebyte_bigword.totalsize / 8,
3667 0, "builtin_type_arm_ext_littlebyte_bigword", NULL);
069e84fd 3668 TYPE_FLOATFORMAT (builtin_type_arm_ext_littlebyte_bigword) = &floatformat_arm_ext_littlebyte_bigword;
5ef2d0aa
AC
3669 builtin_type_arm_ext[BFD_ENDIAN_BIG]
3670 = build_flt (floatformat_arm_ext_big.totalsize,
3671 "builtin_type_arm_ext_big",
3672 &floatformat_arm_ext_big);
3673 builtin_type_arm_ext[BFD_ENDIAN_LITTLE]
3674 = build_flt (floatformat_arm_ext_littlebyte_bigword.totalsize,
3675 "builtin_type_arm_ext_littlebyte_bigword",
3676 &floatformat_arm_ext_littlebyte_bigword);
598f52df
AC
3677 builtin_type_ia64_spill_big =
3678 init_type (TYPE_CODE_FLT, floatformat_ia64_spill_big.totalsize / 8,
3679 0, "builtin_type_ia64_spill_big", NULL);
069e84fd 3680 TYPE_FLOATFORMAT (builtin_type_ia64_spill_big) = &floatformat_ia64_spill_big;
598f52df
AC
3681 builtin_type_ia64_spill_little =
3682 init_type (TYPE_CODE_FLT, floatformat_ia64_spill_little.totalsize / 8,
3683 0, "builtin_type_ia64_spill_little", NULL);
069e84fd 3684 TYPE_FLOATFORMAT (builtin_type_ia64_spill_little) = &floatformat_ia64_spill_little;
5ef2d0aa
AC
3685 builtin_type_ia64_spill[BFD_ENDIAN_BIG]
3686 = build_flt (floatformat_ia64_spill_big.totalsize,
3687 "builtin_type_ia64_spill_big",
3688 &floatformat_ia64_spill_big);
3689 builtin_type_ia64_spill[BFD_ENDIAN_LITTLE]
3690 = build_flt (floatformat_ia64_spill_little.totalsize,
3691 "builtin_type_ia64_spill_little",
3692 &floatformat_ia64_spill_little);
598f52df
AC
3693 builtin_type_ia64_quad_big =
3694 init_type (TYPE_CODE_FLT, floatformat_ia64_quad_big.totalsize / 8,
3695 0, "builtin_type_ia64_quad_big", NULL);
069e84fd 3696 TYPE_FLOATFORMAT (builtin_type_ia64_quad_big) = &floatformat_ia64_quad_big;
598f52df
AC
3697 builtin_type_ia64_quad_little =
3698 init_type (TYPE_CODE_FLT, floatformat_ia64_quad_little.totalsize / 8,
3699 0, "builtin_type_ia64_quad_little", NULL);
069e84fd 3700 TYPE_FLOATFORMAT (builtin_type_ia64_quad_little) = &floatformat_ia64_quad_little;
5ef2d0aa
AC
3701 builtin_type_ia64_quad[BFD_ENDIAN_BIG]
3702 = build_flt (floatformat_ia64_quad_big.totalsize,
3703 "builtin_type_ia64_quad_big",
3704 &floatformat_ia64_quad_big);
3705 builtin_type_ia64_quad[BFD_ENDIAN_LITTLE]
3706 = build_flt (floatformat_ia64_quad_little.totalsize,
3707 "builtin_type_ia64_quad_little",
3708 &floatformat_ia64_quad_little);
598f52df 3709
85c07804
AC
3710 add_setshow_zinteger_cmd ("overload", no_class, &overload_debug, _("\
3711Set debugging of C++ overloading."), _("\
3712Show debugging of C++ overloading."), _("\
3713When enabled, ranking of the functions is displayed."),
3714 NULL,
3715 NULL, /* FIXME: i18n: */
3716 &setdebuglist, &showdebuglist);
c906108c 3717}