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