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