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