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