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