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