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