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