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