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