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