OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.3/] [gdb/] [gdbtypes.c] - Blame information for rev 1780

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.