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