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