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