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