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