include:
[external/binutils.git] / gdb / gdbtypes.h
1 /* Internal type definitions for GDB.
2
3    Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
4    2002, 2003, 2004, 2006, 2007 Free Software Foundation, Inc.
5
6    Contributed by Cygnus Support, using pieces from other GDB modules.
7
8    This file is part of GDB.
9
10    This program is free software; you can redistribute it and/or modify
11    it under the terms of the GNU General Public License as published by
12    the Free Software Foundation; either version 3 of the License, or
13    (at your option) any later version.
14
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
22
23 #if !defined (GDBTYPES_H)
24 #define GDBTYPES_H 1
25
26 #include "hashtab.h"
27
28 /* Forward declarations for prototypes.  */
29 struct field;
30 struct block;
31
32 /* Codes for `fundamental types'.  This is a monstrosity based on the
33    bogus notion that there are certain compiler-independent
34    `fundamental types'.  None of these is well-defined (how big is
35    FT_SHORT?  Does it depend on the language?  How does the
36    language-specific code know which type to correlate to FT_SHORT?)  */
37
38 #define FT_VOID                 0
39 #define FT_BOOLEAN              1
40 #define FT_CHAR                 2       /* we use this for not-unsigned C/C++ chars */
41 #define FT_SIGNED_CHAR          3       /* we use this for C++ signed chars */
42 #define FT_UNSIGNED_CHAR        4       /* we use this for C/C++ unsigned chars */
43 #define FT_SHORT                5
44 #define FT_SIGNED_SHORT         6
45 #define FT_UNSIGNED_SHORT       7
46 #define FT_INTEGER              8
47 #define FT_SIGNED_INTEGER       9
48 #define FT_UNSIGNED_INTEGER     10
49 #define FT_LONG                 11
50 #define FT_SIGNED_LONG          12
51 #define FT_UNSIGNED_LONG        13
52 #define FT_LONG_LONG            14
53 #define FT_SIGNED_LONG_LONG     15
54 #define FT_UNSIGNED_LONG_LONG   16
55 #define FT_FLOAT                17
56 #define FT_DBL_PREC_FLOAT       18
57 #define FT_EXT_PREC_FLOAT       19
58 #define FT_COMPLEX              20
59 #define FT_DBL_PREC_COMPLEX     21
60 #define FT_EXT_PREC_COMPLEX     22
61 #define FT_STRING               23
62 #define FT_FIXED_DECIMAL        24
63 #define FT_FLOAT_DECIMAL        25
64 #define FT_BYTE                 26
65 #define FT_UNSIGNED_BYTE        27
66 #define FT_TEMPLATE_ARG         28
67
68 /* The following three fundamental types are for decimal floating point.  */
69 #define FT_DECFLOAT             29
70 #define FT_DBL_PREC_DECFLOAT    30
71 #define FT_EXT_PREC_DECFLOAT    31
72
73 #define FT_NUM_MEMBERS          32      /* Highest FT_* above, plus one. */
74
75 /* Some macros for char-based bitfields.  */
76
77 #define B_SET(a,x)      ((a)[(x)>>3] |= (1 << ((x)&7)))
78 #define B_CLR(a,x)      ((a)[(x)>>3] &= ~(1 << ((x)&7)))
79 #define B_TST(a,x)      ((a)[(x)>>3] & (1 << ((x)&7)))
80 #define B_TYPE          unsigned char
81 #define B_BYTES(x)      ( 1 + ((x)>>3) )
82 #define B_CLRALL(a,x)   memset ((a), 0, B_BYTES(x))
83
84 /* Different kinds of data types are distinguished by the `code' field.  */
85
86 enum type_code
87   {
88     TYPE_CODE_UNDEF,            /* Not used; catches errors */
89     TYPE_CODE_PTR,              /* Pointer type */
90
91     /* Array type with lower & upper bounds.
92
93        Regardless of the language, GDB represents multidimensional
94        array types the way C does: as arrays of arrays.  So an
95        instance of a GDB array type T can always be seen as a series
96        of instances of TYPE_TARGET_TYPE (T) laid out sequentially in
97        memory.
98
99        Row-major languages like C lay out multi-dimensional arrays so
100        that incrementing the rightmost index in a subscripting
101        expression results in the smallest change in the address of the
102        element referred to.  Column-major languages like Fortran lay
103        them out so that incrementing the leftmost index results in the
104        smallest change.
105
106        This means that, in column-major languages, working our way
107        from type to target type corresponds to working through indices
108        from right to left, not left to right.  */
109     TYPE_CODE_ARRAY,
110
111     TYPE_CODE_STRUCT,           /* C struct or Pascal record */
112     TYPE_CODE_UNION,            /* C union or Pascal variant part */
113     TYPE_CODE_ENUM,             /* Enumeration type */
114     TYPE_CODE_FLAGS,            /* Bit flags type */
115     TYPE_CODE_FUNC,             /* Function type */
116     TYPE_CODE_INT,              /* Integer type */
117
118     /* Floating type.  This is *NOT* a complex type.  Beware, there are parts
119        of GDB which bogusly assume that TYPE_CODE_FLT can mean complex.  */
120     TYPE_CODE_FLT,
121
122     /* Void type.  The length field specifies the length (probably always
123        one) which is used in pointer arithmetic involving pointers to
124        this type, but actually dereferencing such a pointer is invalid;
125        a void type has no length and no actual representation in memory
126        or registers.  A pointer to a void type is a generic pointer.  */
127     TYPE_CODE_VOID,
128
129     TYPE_CODE_SET,              /* Pascal sets */
130     TYPE_CODE_RANGE,            /* Range (integers within spec'd bounds) */
131
132     /* A string type which is like an array of character but prints
133        differently (at least for (the deleted) CHILL).  It does not
134        contain a length field as Pascal strings (for many Pascals,
135        anyway) do; if we want to deal with such strings, we should use
136        a new type code.  */
137     TYPE_CODE_STRING,
138
139     /* String of bits; like TYPE_CODE_SET but prints differently (at
140        least for (the deleted) CHILL).  */
141     TYPE_CODE_BITSTRING,
142
143     /* Unknown type.  The length field is valid if we were able to
144        deduce that much about the type, or 0 if we don't even know that.  */
145     TYPE_CODE_ERROR,
146
147     /* C++ */
148     TYPE_CODE_METHOD,           /* Method type */
149
150     /* Pointer-to-member-function type.  This describes how to access a
151        particular member function of a class (possibly a virtual
152        member function).  The representation may vary between different
153        C++ ABIs.  */
154     TYPE_CODE_METHODPTR,
155
156     /* Pointer-to-member type.  This is the offset within a class to some
157        particular data member.  The only currently supported representation
158        uses an unbiased offset, with -1 representing NULL; this is used
159        by the Itanium C++ ABI (used by GCC on all platforms).  */
160     TYPE_CODE_MEMBERPTR,
161
162     TYPE_CODE_REF,              /* C++ Reference types */
163
164     TYPE_CODE_CHAR,             /* *real* character type */
165
166     /* Boolean type.  0 is false, 1 is true, and other values are non-boolean
167        (e.g. FORTRAN "logical" used as unsigned int).  */
168     TYPE_CODE_BOOL,
169
170     /* Fortran */
171     TYPE_CODE_COMPLEX,          /* Complex float */
172
173     TYPE_CODE_TYPEDEF,
174     TYPE_CODE_TEMPLATE,         /* C++ template */
175     TYPE_CODE_TEMPLATE_ARG,     /* C++ template arg */
176
177     TYPE_CODE_NAMESPACE,        /* C++ namespace.  */
178
179     TYPE_CODE_DECFLOAT          /* Decimal floating point.  */
180   };
181
182 /* For now allow source to use TYPE_CODE_CLASS for C++ classes, as an
183    alias for TYPE_CODE_STRUCT.  This is for DWARF, which has a distinct
184    "class" attribute.  Perhaps we should actually have a separate TYPE_CODE
185    so that we can print "class" or "struct" depending on what the debug
186    info said.  It's not clear we should bother.  */
187
188 #define TYPE_CODE_CLASS TYPE_CODE_STRUCT
189
190 /* Some bits for the type's flags word, and macros to test them. */
191
192 /* Unsigned integer type.  If this is not set for a TYPE_CODE_INT, the
193    type is signed (unless TYPE_FLAG_NOSIGN (below) is set). */
194
195 #define TYPE_FLAG_UNSIGNED      (1 << 0)
196 #define TYPE_UNSIGNED(t)        (TYPE_FLAGS (t) & TYPE_FLAG_UNSIGNED)
197
198 /* No sign for this type.  In C++, "char", "signed char", and "unsigned
199    char" are distinct types; so we need an extra flag to indicate the
200    absence of a sign! */
201
202 #define TYPE_FLAG_NOSIGN        (1 << 1)
203 #define TYPE_NOSIGN(t)          (TYPE_FLAGS (t) & TYPE_FLAG_NOSIGN)
204
205 /* This appears in a type's flags word if it is a stub type (e.g., if
206    someone referenced a type that wasn't defined in a source file
207    via (struct sir_not_appearing_in_this_film *)).  */
208
209 #define TYPE_FLAG_STUB          (1 << 2)
210 #define TYPE_STUB(t)            (TYPE_FLAGS (t) & TYPE_FLAG_STUB)
211
212 /* The target type of this type is a stub type, and this type needs to
213    be updated if it gets un-stubbed in check_typedef.
214    Used for arrays and ranges, in which TYPE_LENGTH of the array/range
215    gets set based on the TYPE_LENGTH of the target type.
216    Also, set for TYPE_CODE_TYPEDEF. */
217
218 #define TYPE_FLAG_TARGET_STUB   (1 << 3)
219 #define TYPE_TARGET_STUB(t)     (TYPE_FLAGS (t) & TYPE_FLAG_TARGET_STUB)
220
221 /* Static type.  If this is set, the corresponding type had 
222  * a static modifier.
223  * Note: This may be unnecessary, since static data members
224  * are indicated by other means (bitpos == -1)
225  */
226
227 #define TYPE_FLAG_STATIC        (1 << 4)
228 #define TYPE_STATIC(t)          (TYPE_FLAGS (t) & TYPE_FLAG_STATIC)
229
230 /* Constant type.  If this is set, the corresponding type has a
231  * const modifier.
232  */
233
234 #define TYPE_FLAG_CONST         (1 << 5)
235 #define TYPE_CONST(t)           (TYPE_INSTANCE_FLAGS (t) & TYPE_FLAG_CONST)
236
237 /* Volatile type.  If this is set, the corresponding type has a
238  * volatile modifier.
239  */
240
241 #define TYPE_FLAG_VOLATILE      (1 << 6)
242 #define TYPE_VOLATILE(t)        (TYPE_INSTANCE_FLAGS (t) & TYPE_FLAG_VOLATILE)
243
244
245 /* This is a function type which appears to have a prototype.  We need this
246    for function calls in order to tell us if it's necessary to coerce the args,
247    or to just do the standard conversions.  This is used with a short field. */
248
249 #define TYPE_FLAG_PROTOTYPED    (1 << 7)
250 #define TYPE_PROTOTYPED(t)      (TYPE_FLAGS (t) & TYPE_FLAG_PROTOTYPED)
251
252 /* This flag is used to indicate that processing for this type
253    is incomplete.
254
255    (Mostly intended for HP platforms, where class methods, for
256    instance, can be encountered before their classes in the debug
257    info; the incomplete type has to be marked so that the class and
258    the method can be assigned correct types.) */
259
260 #define TYPE_FLAG_INCOMPLETE    (1 << 8)
261 #define TYPE_INCOMPLETE(t)      (TYPE_FLAGS (t) & TYPE_FLAG_INCOMPLETE)
262
263 /* Instruction-space delimited type.  This is for Harvard architectures
264    which have separate instruction and data address spaces (and perhaps
265    others).
266
267    GDB usually defines a flat address space that is a superset of the
268    architecture's two (or more) address spaces, but this is an extension
269    of the architecture's model.
270
271    If TYPE_FLAG_INST is set, an object of the corresponding type
272    resides in instruction memory, even if its address (in the extended
273    flat address space) does not reflect this.
274
275    Similarly, if TYPE_FLAG_DATA is set, then an object of the 
276    corresponding type resides in the data memory space, even if
277    this is not indicated by its (flat address space) address.
278
279    If neither flag is set, the default space for functions / methods
280    is instruction space, and for data objects is data memory.  */
281
282 #define TYPE_FLAG_CODE_SPACE    (1 << 9)
283 #define TYPE_CODE_SPACE(t)      (TYPE_INSTANCE_FLAGS (t) & TYPE_FLAG_CODE_SPACE)
284
285 #define TYPE_FLAG_DATA_SPACE    (1 << 10)
286 #define TYPE_DATA_SPACE(t)      (TYPE_INSTANCE_FLAGS (t) & TYPE_FLAG_DATA_SPACE)
287
288 /* FIXME drow/2002-06-03:  Only used for methods, but applies as well
289    to functions.  */
290
291 #define TYPE_FLAG_VARARGS       (1 << 11)
292 #define TYPE_VARARGS(t)         (TYPE_FLAGS (t) & TYPE_FLAG_VARARGS)
293
294 /* Identify a vector type.  Gcc is handling this by adding an extra
295    attribute to the array type.  We slurp that in as a new flag of a
296    type.  This is used only in dwarf2read.c.  */
297 #define TYPE_FLAG_VECTOR        (1 << 12)
298 #define TYPE_VECTOR(t)          (TYPE_FLAGS (t) & TYPE_FLAG_VECTOR)
299
300 /* Address class flags.  Some environments provide for pointers whose
301    size is different from that of a normal pointer or address types
302    where the bits are interpreted differently than normal addresses.  The
303    TYPE_FLAG_ADDRESS_CLASS_n flags may be used in target specific
304    ways to represent these different types of address classes.  */
305 #define TYPE_FLAG_ADDRESS_CLASS_1 (1 << 13)
306 #define TYPE_ADDRESS_CLASS_1(t) (TYPE_INSTANCE_FLAGS(t) \
307                                  & TYPE_FLAG_ADDRESS_CLASS_1)
308 #define TYPE_FLAG_ADDRESS_CLASS_2 (1 << 14)
309 #define TYPE_ADDRESS_CLASS_2(t) (TYPE_INSTANCE_FLAGS(t) \
310                                  & TYPE_FLAG_ADDRESS_CLASS_2)
311 #define TYPE_FLAG_ADDRESS_CLASS_ALL (TYPE_FLAG_ADDRESS_CLASS_1 \
312                                      | TYPE_FLAG_ADDRESS_CLASS_2)
313 #define TYPE_ADDRESS_CLASS_ALL(t) (TYPE_INSTANCE_FLAGS(t) \
314                                    & TYPE_FLAG_ADDRESS_CLASS_ALL)
315
316 /* The debugging formats (especially STABS) do not contain enough information
317    to represent all Ada types---especially those whose size depends on
318    dynamic quantities.  Therefore, the GNAT Ada compiler includes
319    extra information in the form of additional type definitions
320    connected by naming conventions.  This flag indicates that the 
321    type is an ordinary (unencoded) GDB type that has been created from 
322    the necessary run-time information, and does not need further 
323    interpretation. Optionally marks ordinary, fixed-size GDB type. */
324
325 #define TYPE_FLAG_FIXED_INSTANCE (1 << 15)
326
327 /* This debug target supports TYPE_STUB(t).  In the unsupported case we have to
328    rely on NFIELDS to be zero etc., see TYPE_IS_OPAQUE ().
329    TYPE_STUB(t) with !TYPE_STUB_SUPPORTED(t) may exist if we only guessed
330    the TYPE_STUB(t) value (see dwarfread.c).  */
331
332 #define TYPE_FLAG_STUB_SUPPORTED (1 << 16)
333 #define TYPE_STUB_SUPPORTED(t)   (TYPE_FLAGS (t) & TYPE_FLAG_STUB_SUPPORTED)
334
335 /* Not textual.  By default, GDB treats all single byte integers as
336    characters (or elements of strings) unless this flag is set.  */
337
338 #define TYPE_FLAG_NOTTEXT       (1 << 17)
339 #define TYPE_NOTTEXT(t)         (TYPE_FLAGS (t) & TYPE_FLAG_NOTTEXT)
340
341 /*  Array bound type.  */
342 enum array_bound_type
343 {
344   BOUND_SIMPLE = 0,
345   BOUND_BY_VALUE_IN_REG,
346   BOUND_BY_REF_IN_REG,
347   BOUND_BY_VALUE_ON_STACK,
348   BOUND_BY_REF_ON_STACK,
349   BOUND_CANNOT_BE_DETERMINED
350 };
351
352 /* This structure is space-critical.
353    Its layout has been tweaked to reduce the space used.  */
354
355 struct main_type
356 {
357   /* Code for kind of type */
358
359   ENUM_BITFIELD(type_code) code : 8;
360
361   /* Array bounds.  These fields appear at this location because
362      they pack nicely here.  */
363
364   ENUM_BITFIELD(array_bound_type) upper_bound_type : 4;
365   ENUM_BITFIELD(array_bound_type) lower_bound_type : 4;
366
367   /* Name of this type, or NULL if none.
368
369      This is used for printing only, except by poorly designed C++ code.
370      For looking up a name, look for a symbol in the VAR_DOMAIN.  */
371
372   char *name;
373
374   /* Tag name for this type, or NULL if none.  This means that the
375      name of the type consists of a keyword followed by the tag name.
376      Which keyword is determined by the type code ("struct" for
377      TYPE_CODE_STRUCT, etc.).  As far as I know C/C++ are the only languages
378      with this feature.
379
380      This is used for printing only, except by poorly designed C++ code.
381      For looking up a name, look for a symbol in the STRUCT_DOMAIN.
382      One more legitimate use is that if TYPE_FLAG_STUB is set, this is
383      the name to use to look for definitions in other files.  */
384
385   char *tag_name;
386
387   /* Every type is now associated with a particular objfile, and the
388      type is allocated on the objfile_obstack for that objfile.  One problem
389      however, is that there are times when gdb allocates new types while
390      it is not in the process of reading symbols from a particular objfile.
391      Fortunately, these happen when the type being created is a derived
392      type of an existing type, such as in lookup_pointer_type().  So
393      we can just allocate the new type using the same objfile as the
394      existing type, but to do this we need a backpointer to the objfile
395      from the existing type.  Yes this is somewhat ugly, but without
396      major overhaul of the internal type system, it can't be avoided
397      for now. */
398
399   struct objfile *objfile;
400
401   /* For a pointer type, describes the type of object pointed to.
402      For an array type, describes the type of the elements.
403      For a function or method type, describes the type of the return value.
404      For a range type, describes the type of the full range.
405      For a complex type, describes the type of each coordinate.
406      Unused otherwise.  */
407
408   struct type *target_type;
409
410   /* Flags about this type.  */
411
412   int flags;
413
414   /* Number of fields described for this type */
415
416   short nfields;
417
418   /* Field number of the virtual function table pointer in
419      VPTR_BASETYPE.  If -1, we were unable to find the virtual
420      function table pointer in initial symbol reading, and
421      fill_in_vptr_fieldno should be called to find it if possible.
422
423      Unused if this type does not have virtual functions.  */
424
425   short vptr_fieldno;
426
427   /* For structure and union types, a description of each field.
428      For set and pascal array types, there is one "field",
429      whose type is the domain type of the set or array.
430      For range types, there are two "fields",
431      the minimum and maximum values (both inclusive).
432      For enum types, each possible value is described by one "field".
433      For a function or method type, a "field" for each parameter.
434      For C++ classes, there is one field for each base class (if it is
435      a derived class) plus one field for each class data member.  Member
436      functions are recorded elsewhere.
437
438      Using a pointer to a separate array of fields
439      allows all types to have the same size, which is useful
440      because we can allocate the space for a type before
441      we know what to put in it.  */
442
443   struct field
444   {
445     union field_location
446     {
447       /* Position of this field, counting in bits from start of
448          containing structure.
449          For BITS_BIG_ENDIAN=1 targets, it is the bit offset to the MSB.
450          For BITS_BIG_ENDIAN=0 targets, it is the bit offset to the LSB.
451          For a range bound or enum value, this is the value itself. */
452
453       int bitpos;
454
455       /* For a static field, if TYPE_FIELD_STATIC_HAS_ADDR then physaddr
456          is the location (in the target) of the static field.
457          Otherwise, physname is the mangled label of the static field. */
458
459       CORE_ADDR physaddr;
460       char *physname;
461     }
462     loc;
463
464     /* For a function or member type, this is 1 if the argument is marked
465        artificial.  Artificial arguments should not be shown to the
466        user.  */
467     unsigned int artificial : 1;
468
469     /* This flag is zero for non-static fields, 1 for fields whose location
470        is specified by the label loc.physname, and 2 for fields whose location
471        is specified by loc.physaddr.  */
472
473     unsigned int static_kind : 2;
474
475     /* Size of this field, in bits, or zero if not packed.
476        For an unpacked field, the field's type's length
477        says how many bytes the field occupies.  */
478
479     unsigned int bitsize : 29;
480
481     /* In a struct or union type, type of this field.
482        In a function or member type, type of this argument.
483        In an array type, the domain-type of the array.  */
484
485     struct type *type;
486
487     /* Name of field, value or argument.
488        NULL for range bounds, array domains, and member function
489        arguments.  */
490
491     char *name;
492
493   } *fields;
494
495   /* For types with virtual functions (TYPE_CODE_STRUCT), VPTR_BASETYPE
496      is the base class which defined the virtual function table pointer.  
497
498      For types that are pointer to member types (TYPE_CODE_METHODPTR,
499      TYPE_CODE_MEMBERPTR), VPTR_BASETYPE is the type that this pointer
500      is a member of.
501
502      For method types (TYPE_CODE_METHOD), VPTR_BASETYPE is the aggregate
503      type that contains the method.
504
505      Unused otherwise.  */
506
507   struct type *vptr_basetype;
508
509   /* Slot to point to additional language-specific fields of this type.  */
510
511   union type_specific
512   {
513     /* CPLUS_STUFF is for TYPE_CODE_STRUCT.  It is initialized to point to
514        cplus_struct_default, a default static instance of a struct
515        cplus_struct_type. */
516
517     struct cplus_struct_type *cplus_stuff;
518
519     /* FLOATFORMAT is for TYPE_CODE_FLT.  It is a pointer to two
520        floatformat objects that describe the floating-point value
521        that resides within the type.  The first is for big endian
522        targets and the second is for little endian targets.  */
523
524     const struct floatformat **floatformat;
525   } type_specific;
526 };
527
528 /* A ``struct type'' describes a particular instance of a type, with
529    some particular qualification.  */
530 struct type
531 {
532   /* Type that is a pointer to this type.
533      NULL if no such pointer-to type is known yet.
534      The debugger may add the address of such a type
535      if it has to construct one later.  */
536
537   struct type *pointer_type;
538
539   /* C++: also need a reference type.  */
540
541   struct type *reference_type;
542
543   /* Variant chain.  This points to a type that differs from this one only
544      in qualifiers and length.  Currently, the possible qualifiers are
545      const, volatile, code-space, data-space, and address class.  The
546      length may differ only when one of the address class flags are set.
547      The variants are linked in a circular ring and share MAIN_TYPE.  */
548   struct type *chain;
549
550   /* Flags specific to this instance of the type, indicating where
551      on the ring we are.  */
552   int instance_flags;
553
554   /* Length of storage for a value of this type.  This is what
555      sizeof(type) would return; use it for address arithmetic,
556      memory reads and writes, etc.  This size includes padding.  For
557      example, an i386 extended-precision floating point value really
558      only occupies ten bytes, but most ABI's declare its size to be
559      12 bytes, to preserve alignment.  A `struct type' representing
560      such a floating-point type would have a `length' value of 12,
561      even though the last two bytes are unused.
562
563      There's a bit of a host/target mess here, if you're concerned
564      about machines whose bytes aren't eight bits long, or who don't
565      have byte-addressed memory.  Various places pass this to memcpy
566      and such, meaning it must be in units of host bytes.  Various
567      other places expect they can calculate addresses by adding it
568      and such, meaning it must be in units of target bytes.  For
569      some DSP targets, in which HOST_CHAR_BIT will (presumably) be 8
570      and TARGET_CHAR_BIT will be (say) 32, this is a problem.
571
572      One fix would be to make this field in bits (requiring that it
573      always be a multiple of HOST_CHAR_BIT and TARGET_CHAR_BIT) ---
574      the other choice would be to make it consistently in units of
575      HOST_CHAR_BIT.  However, this would still fail to address
576      machines based on a ternary or decimal representation.  */
577   
578   unsigned length;
579
580   /* Core type, shared by a group of qualified types.  */
581   struct main_type *main_type;
582 };
583
584 #define NULL_TYPE ((struct type *) 0)
585
586 /* C++ language-specific information for TYPE_CODE_STRUCT and TYPE_CODE_UNION
587    nodes.  */
588
589 struct cplus_struct_type
590   {
591     /* Number of base classes this type derives from.  The baseclasses are
592        stored in the first N_BASECLASSES fields (i.e. the `fields' field of
593        the struct type).  I think only the `type' field of such a field has
594        any meaning.  */
595
596     short n_baseclasses;
597
598     /* Number of methods with unique names.  All overloaded methods with
599        the same name count only once. */
600
601     short nfn_fields;
602
603     /* Number of methods described for this type, not including the
604        methods that it derives from.  */
605
606     short nfn_fields_total;
607
608     /* The "declared_type" field contains a code saying how the
609        user really declared this type, e.g., "class s", "union s",
610        "struct s".
611        The 3 above things come out from the C++ compiler looking like classes, 
612        but we keep track of the real declaration so we can give
613        the correct information on "ptype". (Note: TEMPLATE may not
614        belong in this list...)  */
615
616 #define DECLARED_TYPE_CLASS 0
617 #define DECLARED_TYPE_UNION 1
618 #define DECLARED_TYPE_STRUCT 2
619 #define DECLARED_TYPE_TEMPLATE 3
620     short declared_type;        /* One of the above codes */
621
622     /* For derived classes, the number of base classes is given by n_baseclasses
623        and virtual_field_bits is a bit vector containing one bit per base class.
624        If the base class is virtual, the corresponding bit will be set.
625        I.E, given:
626
627        class A{};
628        class B{};
629        class C : public B, public virtual A {};
630
631        B is a baseclass of C; A is a virtual baseclass for C.
632        This is a C++ 2.0 language feature. */
633
634     B_TYPE *virtual_field_bits;
635
636     /* For classes with private fields, the number of fields is given by
637        nfields and private_field_bits is a bit vector containing one bit
638        per field.
639        If the field is private, the corresponding bit will be set. */
640
641     B_TYPE *private_field_bits;
642
643     /* For classes with protected fields, the number of fields is given by
644        nfields and protected_field_bits is a bit vector containing one bit
645        per field.
646        If the field is private, the corresponding bit will be set. */
647
648     B_TYPE *protected_field_bits;
649
650     /* for classes with fields to be ignored, either this is optimized out
651        or this field has length 0 */
652
653     B_TYPE *ignore_field_bits;
654
655     /* For classes, structures, and unions, a description of each field,
656        which consists of an overloaded name, followed by the types of
657        arguments that the method expects, and then the name after it
658        has been renamed to make it distinct.
659
660        fn_fieldlists points to an array of nfn_fields of these. */
661
662     struct fn_fieldlist
663       {
664
665         /* The overloaded name.  */
666
667         char *name;
668
669         /* The number of methods with this name.  */
670
671         int length;
672
673         /* The list of methods.  */
674
675         struct fn_field
676           {
677
678             /* If is_stub is clear, this is the mangled name which we can
679                look up to find the address of the method (FIXME: it would
680                be cleaner to have a pointer to the struct symbol here
681                instead).  */
682
683             /* If is_stub is set, this is the portion of the mangled
684                name which specifies the arguments.  For example, "ii",
685                if there are two int arguments, or "" if there are no
686                arguments.  See gdb_mangle_name for the conversion from this
687                format to the one used if is_stub is clear.  */
688
689             char *physname;
690
691             /* The function type for the method.
692                (This comment used to say "The return value of the method",
693                but that's wrong. The function type 
694                is expected here, i.e. something with TYPE_CODE_FUNC,
695                and *not* the return-value type). */
696
697             struct type *type;
698
699             /* For virtual functions.
700                First baseclass that defines this virtual function.   */
701
702             struct type *fcontext;
703
704             /* Attributes. */
705
706             unsigned int is_const:1;
707             unsigned int is_volatile:1;
708             unsigned int is_private:1;
709             unsigned int is_protected:1;
710             unsigned int is_public:1;
711             unsigned int is_abstract:1;
712             unsigned int is_static:1;
713             unsigned int is_final:1;
714             unsigned int is_synchronized:1;
715             unsigned int is_native:1;
716             unsigned int is_artificial:1;
717
718             /* A stub method only has some fields valid (but they are enough
719                to reconstruct the rest of the fields).  */
720             unsigned int is_stub:1;
721
722             /* C++ method that is inlined */
723             unsigned int is_inlined:1;
724
725             /* Unused.  */
726             unsigned int dummy:3;
727
728             /* Index into that baseclass's virtual function table,
729                minus 2; else if static: VOFFSET_STATIC; else: 0.  */
730
731             unsigned int voffset:16;
732
733 #define VOFFSET_STATIC 1
734
735           }
736          *fn_fields;
737
738       }
739      *fn_fieldlists;
740
741     /* If this "struct type" describes a template, then it 
742      * has arguments. "template_args" points to an array of
743      * template arg descriptors, of length "ntemplate_args".
744      * The only real information in each of these template arg descriptors
745      * is a name. "type" will typically just point to a "struct type" with
746      * the placeholder TYPE_CODE_TEMPLATE_ARG type.
747      */
748     short ntemplate_args;
749     struct template_arg
750       {
751         char *name;
752         struct type *type;
753       }
754      *template_args;
755
756     /* If this "struct type" describes a template, it has a list
757      * of instantiations. "instantiations" is a pointer to an array
758      * of type's, one representing each instantiation. There
759      * are "ninstantiations" elements in this array.
760      */
761     short ninstantiations;
762     struct type **instantiations;
763
764     /* Pointer to information about enclosing scope, if this is a
765      * local type.  If it is not a local type, this is NULL
766      */
767     struct local_type_info
768       {
769         char *file;
770         int line;
771       }
772      *localtype_ptr;
773   };
774
775 /* Struct used in computing virtual base list */
776 struct vbase
777   {
778     struct type *vbasetype;     /* pointer to virtual base */
779     struct vbase *next;         /* next in chain */
780   };
781
782 /* Struct used for ranking a function for overload resolution */
783 struct badness_vector
784   {
785     int length;
786     int *rank;
787   };
788
789 /* The default value of TYPE_CPLUS_SPECIFIC(T) points to the
790    this shared static structure. */
791
792 extern const struct cplus_struct_type cplus_struct_default;
793
794 extern void allocate_cplus_struct_type (struct type *);
795
796 #define INIT_CPLUS_SPECIFIC(type) \
797   (TYPE_CPLUS_SPECIFIC(type)=(struct cplus_struct_type*)&cplus_struct_default)
798 #define ALLOCATE_CPLUS_STRUCT_TYPE(type) allocate_cplus_struct_type (type)
799 #define HAVE_CPLUS_STRUCT(type) \
800   (TYPE_CPLUS_SPECIFIC(type) != &cplus_struct_default)
801
802 #define TYPE_INSTANCE_FLAGS(thistype) (thistype)->instance_flags
803 #define TYPE_MAIN_TYPE(thistype) (thistype)->main_type
804 #define TYPE_NAME(thistype) TYPE_MAIN_TYPE(thistype)->name
805 #define TYPE_TAG_NAME(type) TYPE_MAIN_TYPE(type)->tag_name
806 #define TYPE_TARGET_TYPE(thistype) TYPE_MAIN_TYPE(thistype)->target_type
807 #define TYPE_POINTER_TYPE(thistype) (thistype)->pointer_type
808 #define TYPE_REFERENCE_TYPE(thistype) (thistype)->reference_type
809 #define TYPE_CHAIN(thistype) (thistype)->chain
810 /* Note that if thistype is a TYPEDEF type, you have to call check_typedef.
811    But check_typedef does set the TYPE_LENGTH of the TYPEDEF type,
812    so you only have to call check_typedef once.  Since allocate_value
813    calls check_typedef, TYPE_LENGTH (VALUE_TYPE (X)) is safe.  */
814 #define TYPE_LENGTH(thistype) (thistype)->length
815 #define TYPE_OBJFILE(thistype) TYPE_MAIN_TYPE(thistype)->objfile
816 #define TYPE_FLAGS(thistype) TYPE_MAIN_TYPE(thistype)->flags
817 /* Note that TYPE_CODE can be TYPE_CODE_TYPEDEF, so if you want the real
818    type, you need to do TYPE_CODE (check_type (this_type)). */
819 #define TYPE_CODE(thistype) TYPE_MAIN_TYPE(thistype)->code
820 #define TYPE_NFIELDS(thistype) TYPE_MAIN_TYPE(thistype)->nfields
821 #define TYPE_FIELDS(thistype) TYPE_MAIN_TYPE(thistype)->fields
822 #define TYPE_TEMPLATE_ARGS(thistype) TYPE_CPLUS_SPECIFIC(thistype)->template_args
823 #define TYPE_INSTANTIATIONS(thistype) TYPE_CPLUS_SPECIFIC(thistype)->instantiations
824
825 #define TYPE_INDEX_TYPE(type) TYPE_FIELD_TYPE (type, 0)
826 #define TYPE_LOW_BOUND(range_type) TYPE_FIELD_BITPOS (range_type, 0)
827 #define TYPE_HIGH_BOUND(range_type) TYPE_FIELD_BITPOS (range_type, 1)
828
829 /* Moto-specific stuff for FORTRAN arrays */
830
831 #define TYPE_ARRAY_UPPER_BOUND_TYPE(thistype) \
832         TYPE_MAIN_TYPE(thistype)->upper_bound_type
833 #define TYPE_ARRAY_LOWER_BOUND_TYPE(thistype) \
834         TYPE_MAIN_TYPE(thistype)->lower_bound_type
835
836 #define TYPE_ARRAY_UPPER_BOUND_VALUE(arraytype) \
837    (TYPE_FIELD_BITPOS((TYPE_FIELD_TYPE((arraytype),0)),1))
838
839 #define TYPE_ARRAY_LOWER_BOUND_VALUE(arraytype) \
840    (TYPE_FIELD_BITPOS((TYPE_FIELD_TYPE((arraytype),0)),0))
841
842 /* C++ */
843
844 #define TYPE_VPTR_BASETYPE(thistype) TYPE_MAIN_TYPE(thistype)->vptr_basetype
845 #define TYPE_DOMAIN_TYPE(thistype) TYPE_MAIN_TYPE(thistype)->vptr_basetype
846 #define TYPE_VPTR_FIELDNO(thistype) TYPE_MAIN_TYPE(thistype)->vptr_fieldno
847 #define TYPE_FN_FIELDS(thistype) TYPE_CPLUS_SPECIFIC(thistype)->fn_fields
848 #define TYPE_NFN_FIELDS(thistype) TYPE_CPLUS_SPECIFIC(thistype)->nfn_fields
849 #define TYPE_NFN_FIELDS_TOTAL(thistype) TYPE_CPLUS_SPECIFIC(thistype)->nfn_fields_total
850 #define TYPE_NTEMPLATE_ARGS(thistype) TYPE_CPLUS_SPECIFIC(thistype)->ntemplate_args
851 #define TYPE_NINSTANTIATIONS(thistype) TYPE_CPLUS_SPECIFIC(thistype)->ninstantiations
852 #define TYPE_DECLARED_TYPE(thistype) TYPE_CPLUS_SPECIFIC(thistype)->declared_type
853 #define TYPE_TYPE_SPECIFIC(thistype) TYPE_MAIN_TYPE(thistype)->type_specific
854 #define TYPE_CPLUS_SPECIFIC(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.cplus_stuff
855 #define TYPE_FLOATFORMAT(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.floatformat
856 #define TYPE_BASECLASS(thistype,index) TYPE_MAIN_TYPE(thistype)->fields[index].type
857 #define TYPE_N_BASECLASSES(thistype) TYPE_CPLUS_SPECIFIC(thistype)->n_baseclasses
858 #define TYPE_BASECLASS_NAME(thistype,index) TYPE_MAIN_TYPE(thistype)->fields[index].name
859 #define TYPE_BASECLASS_BITPOS(thistype,index) TYPE_FIELD_BITPOS(thistype,index)
860 #define BASETYPE_VIA_PUBLIC(thistype, index) \
861   ((!TYPE_FIELD_PRIVATE(thistype, index)) && (!TYPE_FIELD_PROTECTED(thistype, index)))
862
863 #define BASETYPE_VIA_VIRTUAL(thistype, index) \
864   (TYPE_CPLUS_SPECIFIC(thistype)->virtual_field_bits == NULL ? 0 \
865     : B_TST(TYPE_CPLUS_SPECIFIC(thistype)->virtual_field_bits, (index)))
866
867 #define FIELD_TYPE(thisfld) ((thisfld).type)
868 #define FIELD_NAME(thisfld) ((thisfld).name)
869 #define FIELD_BITPOS(thisfld) ((thisfld).loc.bitpos)
870 #define FIELD_ARTIFICIAL(thisfld) ((thisfld).artificial)
871 #define FIELD_BITSIZE(thisfld) ((thisfld).bitsize)
872 #define FIELD_STATIC_KIND(thisfld) ((thisfld).static_kind)
873 #define FIELD_PHYSNAME(thisfld) ((thisfld).loc.physname)
874 #define FIELD_PHYSADDR(thisfld) ((thisfld).loc.physaddr)
875 #define SET_FIELD_PHYSNAME(thisfld, name) \
876   ((thisfld).static_kind = 1, FIELD_PHYSNAME(thisfld) = (name))
877 #define SET_FIELD_PHYSADDR(thisfld, name) \
878   ((thisfld).static_kind = 2, FIELD_PHYSADDR(thisfld) = (name))
879 #define TYPE_FIELD(thistype, n) TYPE_MAIN_TYPE(thistype)->fields[n]
880 #define TYPE_FIELD_TYPE(thistype, n) FIELD_TYPE(TYPE_FIELD(thistype, n))
881 #define TYPE_FIELD_NAME(thistype, n) FIELD_NAME(TYPE_FIELD(thistype, n))
882 #define TYPE_FIELD_BITPOS(thistype, n) FIELD_BITPOS(TYPE_FIELD(thistype,n))
883 #define TYPE_FIELD_ARTIFICIAL(thistype, n) FIELD_ARTIFICIAL(TYPE_FIELD(thistype,n))
884 #define TYPE_FIELD_BITSIZE(thistype, n) FIELD_BITSIZE(TYPE_FIELD(thistype,n))
885 #define TYPE_FIELD_PACKED(thistype, n) (FIELD_BITSIZE(TYPE_FIELD(thistype,n))!=0)
886 #define TYPE_TEMPLATE_ARG(thistype, n) TYPE_CPLUS_SPECIFIC(thistype)->template_args[n]
887 #define TYPE_INSTANTIATION(thistype, n) TYPE_CPLUS_SPECIFIC(thistype)->instantiations[n]
888
889 #define TYPE_FIELD_PRIVATE_BITS(thistype) \
890   TYPE_CPLUS_SPECIFIC(thistype)->private_field_bits
891 #define TYPE_FIELD_PROTECTED_BITS(thistype) \
892   TYPE_CPLUS_SPECIFIC(thistype)->protected_field_bits
893 #define TYPE_FIELD_IGNORE_BITS(thistype) \
894   TYPE_CPLUS_SPECIFIC(thistype)->ignore_field_bits
895 #define TYPE_FIELD_VIRTUAL_BITS(thistype) \
896   TYPE_CPLUS_SPECIFIC(thistype)->virtual_field_bits
897 #define SET_TYPE_FIELD_PRIVATE(thistype, n) \
898   B_SET (TYPE_CPLUS_SPECIFIC(thistype)->private_field_bits, (n))
899 #define SET_TYPE_FIELD_PROTECTED(thistype, n) \
900   B_SET (TYPE_CPLUS_SPECIFIC(thistype)->protected_field_bits, (n))
901 #define SET_TYPE_FIELD_IGNORE(thistype, n) \
902   B_SET (TYPE_CPLUS_SPECIFIC(thistype)->ignore_field_bits, (n))
903 #define SET_TYPE_FIELD_VIRTUAL(thistype, n) \
904   B_SET (TYPE_CPLUS_SPECIFIC(thistype)->virtual_field_bits, (n))
905 #define TYPE_FIELD_PRIVATE(thistype, n) \
906   (TYPE_CPLUS_SPECIFIC(thistype)->private_field_bits == NULL ? 0 \
907     : B_TST(TYPE_CPLUS_SPECIFIC(thistype)->private_field_bits, (n)))
908 #define TYPE_FIELD_PROTECTED(thistype, n) \
909   (TYPE_CPLUS_SPECIFIC(thistype)->protected_field_bits == NULL ? 0 \
910     : B_TST(TYPE_CPLUS_SPECIFIC(thistype)->protected_field_bits, (n)))
911 #define TYPE_FIELD_IGNORE(thistype, n) \
912   (TYPE_CPLUS_SPECIFIC(thistype)->ignore_field_bits == NULL ? 0 \
913     : B_TST(TYPE_CPLUS_SPECIFIC(thistype)->ignore_field_bits, (n)))
914 #define TYPE_FIELD_VIRTUAL(thistype, n) \
915   (TYPE_CPLUS_SPECIFIC(thistype)->virtual_field_bits == NULL ? 0 \
916     : B_TST(TYPE_CPLUS_SPECIFIC(thistype)->virtual_field_bits, (n)))
917
918 #define TYPE_FIELD_STATIC(thistype, n) (TYPE_MAIN_TYPE (thistype)->fields[n].static_kind != 0)
919 #define TYPE_FIELD_STATIC_KIND(thistype, n) TYPE_MAIN_TYPE (thistype)->fields[n].static_kind
920 #define TYPE_FIELD_STATIC_HAS_ADDR(thistype, n) (TYPE_MAIN_TYPE (thistype)->fields[n].static_kind == 2)
921 #define TYPE_FIELD_STATIC_PHYSNAME(thistype, n) FIELD_PHYSNAME(TYPE_FIELD(thistype, n))
922 #define TYPE_FIELD_STATIC_PHYSADDR(thistype, n) FIELD_PHYSADDR(TYPE_FIELD(thistype, n))
923
924 #define TYPE_FN_FIELDLISTS(thistype) TYPE_CPLUS_SPECIFIC(thistype)->fn_fieldlists
925 #define TYPE_FN_FIELDLIST(thistype, n) TYPE_CPLUS_SPECIFIC(thistype)->fn_fieldlists[n]
926 #define TYPE_FN_FIELDLIST1(thistype, n) TYPE_CPLUS_SPECIFIC(thistype)->fn_fieldlists[n].fn_fields
927 #define TYPE_FN_FIELDLIST_NAME(thistype, n) TYPE_CPLUS_SPECIFIC(thistype)->fn_fieldlists[n].name
928 #define TYPE_FN_FIELDLIST_LENGTH(thistype, n) TYPE_CPLUS_SPECIFIC(thistype)->fn_fieldlists[n].length
929
930 #define TYPE_FN_FIELD(thisfn, n) (thisfn)[n]
931 #define TYPE_FN_FIELD_PHYSNAME(thisfn, n) (thisfn)[n].physname
932 #define TYPE_FN_FIELD_TYPE(thisfn, n) (thisfn)[n].type
933 #define TYPE_FN_FIELD_ARGS(thisfn, n) TYPE_FIELDS ((thisfn)[n].type)
934 #define TYPE_FN_FIELD_CONST(thisfn, n) ((thisfn)[n].is_const)
935 #define TYPE_FN_FIELD_VOLATILE(thisfn, n) ((thisfn)[n].is_volatile)
936 #define TYPE_FN_FIELD_PRIVATE(thisfn, n) ((thisfn)[n].is_private)
937 #define TYPE_FN_FIELD_PROTECTED(thisfn, n) ((thisfn)[n].is_protected)
938 #define TYPE_FN_FIELD_PUBLIC(thisfn, n) ((thisfn)[n].is_public)
939 #define TYPE_FN_FIELD_STATIC(thisfn, n) ((thisfn)[n].is_static)
940 #define TYPE_FN_FIELD_FINAL(thisfn, n) ((thisfn)[n].is_final)
941 #define TYPE_FN_FIELD_SYNCHRONIZED(thisfn, n) ((thisfn)[n].is_synchronized)
942 #define TYPE_FN_FIELD_NATIVE(thisfn, n) ((thisfn)[n].is_native)
943 #define TYPE_FN_FIELD_ARTIFICIAL(thisfn, n) ((thisfn)[n].is_artificial)
944 #define TYPE_FN_FIELD_ABSTRACT(thisfn, n) ((thisfn)[n].is_abstract)
945 #define TYPE_FN_FIELD_STUB(thisfn, n) ((thisfn)[n].is_stub)
946 #define TYPE_FN_FIELD_INLINED(thisfn, n) ((thisfn)[n].is_inlined)
947 #define TYPE_FN_FIELD_FCONTEXT(thisfn, n) ((thisfn)[n].fcontext)
948 #define TYPE_FN_FIELD_VOFFSET(thisfn, n) ((thisfn)[n].voffset-2)
949 #define TYPE_FN_FIELD_VIRTUAL_P(thisfn, n) ((thisfn)[n].voffset > 1)
950 #define TYPE_FN_FIELD_STATIC_P(thisfn, n) ((thisfn)[n].voffset == VOFFSET_STATIC)
951
952 #define TYPE_LOCALTYPE_PTR(thistype) (TYPE_CPLUS_SPECIFIC(thistype)->localtype_ptr)
953 #define TYPE_LOCALTYPE_FILE(thistype) (TYPE_CPLUS_SPECIFIC(thistype)->localtype_ptr->file)
954 #define TYPE_LOCALTYPE_LINE(thistype) (TYPE_CPLUS_SPECIFIC(thistype)->localtype_ptr->line)
955
956 #define TYPE_IS_OPAQUE(thistype) (((TYPE_CODE (thistype) == TYPE_CODE_STRUCT) ||        \
957                                    (TYPE_CODE (thistype) == TYPE_CODE_UNION))        && \
958                                   (TYPE_NFIELDS (thistype) == 0)                     && \
959                                   (TYPE_CPLUS_SPECIFIC (thistype) && (TYPE_NFN_FIELDS (thistype) == 0)) && \
960                                   (TYPE_STUB (thistype) || !TYPE_STUB_SUPPORTED (thistype)))
961
962 struct builtin_type
963 {
964   /* Address/pointer types.  */
965
966   /* `pointer to data' type.  Some target platforms use an implicitly
967      {sign,zero} -extended 32-bit ABI pointer on a 64-bit ISA.  */
968   struct type *builtin_data_ptr;
969
970   /* `pointer to function (returning void)' type.  Harvard
971      architectures mean that ABI function and code pointers are not
972      interconvertible.  Similarly, since ANSI, C standards have
973      explicitly said that pointers to functions and pointers to data
974      are not interconvertible --- that is, you can't cast a function
975      pointer to void * and back, and expect to get the same value.
976      However, all function pointer types are interconvertible, so void
977      (*) () can server as a generic function pointer.  */
978   struct type *builtin_func_ptr;
979
980   /* The target CPU's address type.  This is the ISA address size.  */
981   struct type *builtin_core_addr;
982
983
984   /* Types used for symbols with no debug information.  */
985   struct type *nodebug_text_symbol;
986   struct type *nodebug_data_symbol;
987   struct type *nodebug_unknown_symbol;
988   struct type *nodebug_tls_symbol;
989
990
991   /* Integral types.  */
992
993   /* We use these for the '/c' print format, because c_char is just a
994      one-byte integral type, which languages less laid back than C
995      will print as ... well, a one-byte integral type.  */
996   struct type *builtin_true_char;
997   struct type *builtin_true_unsigned_char;
998
999   /* Implicit size/sign (based on the the architecture's ABI).  */
1000   struct type *builtin_void;
1001   struct type *builtin_char;
1002   struct type *builtin_short;
1003   struct type *builtin_int;
1004   struct type *builtin_long;
1005   struct type *builtin_signed_char;
1006   struct type *builtin_unsigned_char;
1007   struct type *builtin_unsigned_short;
1008   struct type *builtin_unsigned_int;
1009   struct type *builtin_unsigned_long;
1010   struct type *builtin_float;
1011   struct type *builtin_double;
1012   struct type *builtin_long_double;
1013   struct type *builtin_complex;
1014   struct type *builtin_double_complex;
1015   struct type *builtin_string;
1016   struct type *builtin_bool;
1017   struct type *builtin_long_long;
1018   struct type *builtin_unsigned_long_long;
1019   struct type *builtin_decfloat;
1020   struct type *builtin_decdouble;
1021   struct type *builtin_declong;
1022 };
1023
1024 /* Return the type table for the specified architecture.  */
1025 extern const struct builtin_type *builtin_type (struct gdbarch *gdbarch);
1026
1027 /* Compatibility macros to access types for the current architecture.  */
1028 #define builtin_type_void_data_ptr \
1029         (builtin_type (current_gdbarch)->builtin_data_ptr)
1030 #define builtin_type_void_func_ptr \
1031         (builtin_type (current_gdbarch)->builtin_func_ptr)
1032 #define builtin_type_CORE_ADDR \
1033         (builtin_type (current_gdbarch)->builtin_core_addr)
1034 #define builtin_type_true_char \
1035         (builtin_type (current_gdbarch)->builtin_true_char)
1036 #define builtin_type_void \
1037         (builtin_type (current_gdbarch)->builtin_void)
1038 #define builtin_type_char \
1039         (builtin_type (current_gdbarch)->builtin_char)
1040 #define builtin_type_short \
1041         (builtin_type (current_gdbarch)->builtin_short)
1042 #define builtin_type_int \
1043         (builtin_type (current_gdbarch)->builtin_int)
1044 #define builtin_type_long \
1045         (builtin_type (current_gdbarch)->builtin_long)
1046 #define builtin_type_signed_char \
1047         (builtin_type (current_gdbarch)->builtin_signed_char)
1048 #define builtin_type_unsigned_char \
1049         (builtin_type (current_gdbarch)->builtin_unsigned_char)
1050 #define builtin_type_unsigned_short \
1051         (builtin_type (current_gdbarch)->builtin_unsigned_short)
1052 #define builtin_type_unsigned_int \
1053         (builtin_type (current_gdbarch)->builtin_unsigned_int)
1054 #define builtin_type_unsigned_long \
1055         (builtin_type (current_gdbarch)->builtin_unsigned_long)
1056 #define builtin_type_float \
1057         (builtin_type (current_gdbarch)->builtin_float)
1058 #define builtin_type_double \
1059         (builtin_type (current_gdbarch)->builtin_double)
1060 #define builtin_type_long_double \
1061         (builtin_type (current_gdbarch)->builtin_long_double)
1062 #define builtin_type_complex \
1063         (builtin_type (current_gdbarch)->builtin_complex)
1064 #define builtin_type_double_complex \
1065         (builtin_type (current_gdbarch)->builtin_double_complex)
1066 #define builtin_type_string \
1067         (builtin_type (current_gdbarch)->builtin_string)
1068 #define builtin_type_bool \
1069         (builtin_type (current_gdbarch)->builtin_bool)
1070 #define builtin_type_long_long \
1071         (builtin_type (current_gdbarch)->builtin_long_long)
1072 #define builtin_type_unsigned_long_long \
1073         (builtin_type (current_gdbarch)->builtin_unsigned_long_long)
1074
1075  
1076 /* Explicit sizes - see C9X <intypes.h> for naming scheme.  The "int0"
1077    is for when an architecture needs to describe a register that has
1078    no size.  */
1079 extern struct type *builtin_type_int0;
1080 extern struct type *builtin_type_int8;
1081 extern struct type *builtin_type_uint8;
1082 extern struct type *builtin_type_int16;
1083 extern struct type *builtin_type_uint16;
1084 extern struct type *builtin_type_int32;
1085 extern struct type *builtin_type_uint32;
1086 extern struct type *builtin_type_int64;
1087 extern struct type *builtin_type_uint64;
1088 extern struct type *builtin_type_int128;
1089 extern struct type *builtin_type_uint128;
1090
1091 /* Explicit floating-point formats.  See "floatformat.h".  */
1092 extern const struct floatformat *floatformats_ieee_single[BFD_ENDIAN_UNKNOWN];
1093 extern const struct floatformat *floatformats_ieee_double[BFD_ENDIAN_UNKNOWN];
1094 extern const struct floatformat *floatformats_ieee_double_littlebyte_bigword[BFD_ENDIAN_UNKNOWN];
1095 extern const struct floatformat *floatformats_i387_ext[BFD_ENDIAN_UNKNOWN];
1096 extern const struct floatformat *floatformats_m68881_ext[BFD_ENDIAN_UNKNOWN];
1097 extern const struct floatformat *floatformats_arm_ext[BFD_ENDIAN_UNKNOWN];
1098 extern const struct floatformat *floatformats_ia64_spill[BFD_ENDIAN_UNKNOWN];
1099 extern const struct floatformat *floatformats_ia64_quad[BFD_ENDIAN_UNKNOWN];
1100 extern const struct floatformat *floatformats_vax_f[BFD_ENDIAN_UNKNOWN];
1101 extern const struct floatformat *floatformats_vax_d[BFD_ENDIAN_UNKNOWN];
1102 extern const struct floatformat *floatformats_ibm_long_double[BFD_ENDIAN_UNKNOWN];
1103
1104 extern struct type *builtin_type_ieee_single;
1105 extern struct type *builtin_type_ieee_double;
1106 extern struct type *builtin_type_i387_ext;
1107 extern struct type *builtin_type_m68881_ext;
1108 extern struct type *builtin_type_arm_ext;
1109 extern struct type *builtin_type_ia64_spill;
1110 extern struct type *builtin_type_ia64_quad;
1111
1112 /* This type represents a type that was unrecognized in symbol
1113    read-in.  */
1114
1115 extern struct type *builtin_type_error;
1116
1117
1118 /* Modula-2 types */
1119
1120 struct builtin_m2_type
1121 {
1122   struct type *builtin_char;
1123   struct type *builtin_int;
1124   struct type *builtin_card;
1125   struct type *builtin_real;
1126   struct type *builtin_bool;
1127 };
1128
1129 /* Return the Modula-2 type table for the specified architecture.  */
1130 extern const struct builtin_m2_type *builtin_m2_type (struct gdbarch *gdbarch);
1131
1132 /* Compatibility macros to access types for the current architecture.  */
1133 #define builtin_type_m2_char \
1134         (builtin_m2_type (current_gdbarch)->builtin_char)
1135 #define builtin_type_m2_int \
1136         (builtin_m2_type (current_gdbarch)->builtin_int)
1137 #define builtin_type_m2_card \
1138         (builtin_m2_type (current_gdbarch)->builtin_card)
1139 #define builtin_type_m2_real \
1140         (builtin_m2_type (current_gdbarch)->builtin_real)
1141 #define builtin_type_m2_bool \
1142         (builtin_m2_type (current_gdbarch)->builtin_bool)
1143
1144
1145 /* Fortran (F77) types */
1146
1147 struct builtin_f_type
1148 {
1149   struct type *builtin_character;
1150   struct type *builtin_integer;
1151   struct type *builtin_integer_s2;
1152   struct type *builtin_logical;
1153   struct type *builtin_logical_s1;
1154   struct type *builtin_logical_s2;
1155   struct type *builtin_real;
1156   struct type *builtin_real_s8;
1157   struct type *builtin_real_s16;
1158   struct type *builtin_complex_s8;
1159   struct type *builtin_complex_s16;
1160   struct type *builtin_complex_s32;
1161   struct type *builtin_void;
1162 };
1163
1164 /* Return the Fortran type table for the specified architecture.  */
1165 extern const struct builtin_f_type *builtin_f_type (struct gdbarch *gdbarch);
1166
1167 /* Compatibility macros to access types for the current architecture.  */
1168 #define builtin_type_f_character \
1169         (builtin_f_type (current_gdbarch)->builtin_character)
1170 #define builtin_type_f_integer \
1171         (builtin_f_type (current_gdbarch)->builtin_integer)
1172 #define builtin_type_f_integer_s2 \
1173         (builtin_f_type (current_gdbarch)->builtin_integer_s2)
1174 #define builtin_type_f_logical \
1175         (builtin_f_type (current_gdbarch)->builtin_logical)
1176 #define builtin_type_f_logical_s1 \
1177         (builtin_f_type (current_gdbarch)->builtin_logical_s1)
1178 #define builtin_type_f_logical_s2 \
1179         (builtin_f_type (current_gdbarch)->builtin_logical_s2)
1180 #define builtin_type_f_real \
1181         (builtin_f_type (current_gdbarch)->builtin_real)
1182 #define builtin_type_f_real_s8 \
1183         (builtin_f_type (current_gdbarch)->builtin_real_s8)
1184 #define builtin_type_f_real_s16 \
1185         (builtin_f_type (current_gdbarch)->builtin_real_s16)
1186 #define builtin_type_f_complex_s8 \
1187         (builtin_f_type (current_gdbarch)->builtin_complex_s8)
1188 #define builtin_type_f_complex_s16 \
1189         (builtin_f_type (current_gdbarch)->builtin_complex_s16)
1190 #define builtin_type_f_complex_s32 \
1191         (builtin_f_type (current_gdbarch)->builtin_complex_s32)
1192 #define builtin_type_f_void \
1193         (builtin_f_type (current_gdbarch)->builtin_void)
1194
1195
1196 /* RTTI for C++ */
1197 /* extern struct type *builtin_type_cxx_typeinfo; */
1198
1199 /* Maximum and minimum values of built-in types */
1200
1201 #define MAX_OF_TYPE(t)  \
1202    (TYPE_UNSIGNED(t) ? UMAX_OF_SIZE(TYPE_LENGTH(t)) \
1203     : MAX_OF_SIZE(TYPE_LENGTH(t)))
1204
1205 #define MIN_OF_TYPE(t)  \
1206    (TYPE_UNSIGNED(t) ? UMIN_OF_SIZE(TYPE_LENGTH(t)) \
1207     : MIN_OF_SIZE(TYPE_LENGTH(t)))
1208
1209 /* Allocate space for storing data associated with a particular type.
1210    We ensure that the space is allocated using the same mechanism that
1211    was used to allocate the space for the type structure itself.  I.E.
1212    if the type is on an objfile's objfile_obstack, then the space for data
1213    associated with that type will also be allocated on the objfile_obstack.
1214    If the type is not associated with any particular objfile (such as
1215    builtin types), then the data space will be allocated with xmalloc,
1216    the same as for the type structure. */
1217
1218 #define TYPE_ALLOC(t,size)  \
1219    (TYPE_OBJFILE (t) != NULL  \
1220     ? obstack_alloc (&TYPE_OBJFILE (t) -> objfile_obstack, size) \
1221     : xmalloc (size))
1222
1223 #define TYPE_ZALLOC(t,size)  \
1224    (TYPE_OBJFILE (t) != NULL  \
1225     ? memset (obstack_alloc (&TYPE_OBJFILE (t)->objfile_obstack, size),  \
1226               0, size)  \
1227     : xzalloc (size))
1228
1229 extern struct type *alloc_type (struct objfile *);
1230
1231 extern struct type *init_type (enum type_code, int, int, char *,
1232                                struct objfile *);
1233
1234 /* Helper functions to construct a struct or record type.  An
1235    initially empty type is created using init_composite_type().
1236    Fields are then added using append_struct_type_field().  A union
1237    type has its size set to the largest field.  A struct type has each
1238    field packed against the previous.  */
1239
1240 extern struct type *init_composite_type (char *name, enum type_code code);
1241 extern void append_composite_type_field (struct type *t, char *name,
1242                                          struct type *field);
1243
1244 /* Helper functions to construct a bit flags type.  An initially empty
1245    type is created using init_flag_type().  Flags are then added using
1246    append_flag_type_flag().  */
1247 extern struct type *init_flags_type (char *name, int length);
1248 extern void append_flags_type_flag (struct type *type, int bitpos, char *name);
1249
1250 extern void make_vector_type (struct type *array_type);
1251 extern struct type *init_vector_type (struct type *elt_type, int n);
1252
1253 extern struct type *lookup_reference_type (struct type *);
1254
1255 extern struct type *make_reference_type (struct type *, struct type **);
1256
1257 extern struct type *make_cv_type (int, int, struct type *, struct type **);
1258
1259 extern void replace_type (struct type *, struct type *);
1260
1261 extern int address_space_name_to_int (char *);
1262
1263 extern const char *address_space_int_to_name (int);
1264
1265 extern struct type *make_type_with_address_space (struct type *type, 
1266                                                   int space_identifier);
1267
1268 extern struct type *lookup_memberptr_type (struct type *, struct type *);
1269
1270 extern struct type *lookup_methodptr_type (struct type *);
1271
1272 extern void smash_to_method_type (struct type *type, struct type *domain,
1273                                   struct type *to_type, struct field *args,
1274                                   int nargs, int varargs);
1275
1276 extern void smash_to_memberptr_type (struct type *, struct type *,
1277                                      struct type *);
1278
1279 extern struct type *allocate_stub_method (struct type *);
1280
1281 extern char *type_name_no_tag (const struct type *);
1282
1283 extern struct type *lookup_struct_elt_type (struct type *, char *, int);
1284
1285 extern struct type *make_pointer_type (struct type *, struct type **);
1286
1287 extern struct type *lookup_pointer_type (struct type *);
1288
1289 extern struct type *make_function_type (struct type *, struct type **);
1290
1291 extern struct type *lookup_function_type (struct type *);
1292
1293 extern struct type *create_range_type (struct type *, struct type *, int,
1294                                        int);
1295
1296 extern struct type *create_array_type (struct type *, struct type *,
1297                                        struct type *);
1298
1299 extern struct type *create_string_type (struct type *, struct type *);
1300
1301 extern struct type *create_set_type (struct type *, struct type *);
1302
1303 extern struct type *lookup_unsigned_typename (char *);
1304
1305 extern struct type *lookup_signed_typename (char *);
1306
1307 extern struct type *check_typedef (struct type *);
1308
1309 #define CHECK_TYPEDEF(TYPE) (TYPE) = check_typedef (TYPE)
1310
1311 extern void check_stub_method_group (struct type *, int);
1312
1313 extern char *gdb_mangle_name (struct type *, int, int);
1314
1315 extern struct type *lookup_typename (char *, struct block *, int);
1316
1317 extern struct type *lookup_template_type (char *, struct type *,
1318                                           struct block *);
1319
1320 extern struct type *lookup_fundamental_type (struct objfile *, int);
1321
1322 extern void fill_in_vptr_fieldno (struct type *);
1323
1324 extern int get_destructor_fn_field (struct type *, int *, int *);
1325
1326 extern int get_discrete_bounds (struct type *, LONGEST *, LONGEST *);
1327
1328 extern int is_ancestor (struct type *, struct type *);
1329
1330 /* Overload resolution */
1331
1332 #define LENGTH_MATCH(bv) ((bv)->rank[0])
1333
1334 /* Badness if parameter list length doesn't match arg list length */
1335 #define LENGTH_MISMATCH_BADNESS      100
1336 /* Dummy badness value for nonexistent parameter positions */
1337 #define TOO_FEW_PARAMS_BADNESS       100
1338 /* Badness if no conversion among types */
1339 #define INCOMPATIBLE_TYPE_BADNESS    100
1340
1341 /* Badness of integral promotion */
1342 #define INTEGER_PROMOTION_BADNESS      1
1343 /* Badness of floating promotion */
1344 #define FLOAT_PROMOTION_BADNESS        1
1345 /* Badness of integral conversion */
1346 #define INTEGER_CONVERSION_BADNESS     2
1347 /* Badness of floating conversion */
1348 #define FLOAT_CONVERSION_BADNESS       2
1349 /* Badness of integer<->floating conversions */
1350 #define INT_FLOAT_CONVERSION_BADNESS   2
1351 /* Badness of converting to a boolean */
1352 #define BOOLEAN_CONVERSION_BADNESS     2
1353 /* Badness of pointer conversion */
1354 #define POINTER_CONVERSION_BADNESS     2
1355 /* Badness of conversion of pointer to void pointer */
1356 #define VOID_PTR_CONVERSION_BADNESS    2
1357 /* Badness of converting derived to base class */
1358 #define BASE_CONVERSION_BADNESS        2
1359 /* Badness of converting from non-reference to reference */
1360 #define REFERENCE_CONVERSION_BADNESS   2
1361
1362 /* Non-standard conversions allowed by the debugger */
1363 /* Converting a pointer to an int is usually OK */
1364 #define NS_POINTER_CONVERSION_BADNESS 10
1365
1366
1367 extern int compare_badness (struct badness_vector *, struct badness_vector *);
1368
1369 extern struct badness_vector *rank_function (struct type **, int,
1370                                              struct type **, int);
1371
1372 extern int rank_one_type (struct type *, struct type *);
1373
1374 extern void recursive_dump_type (struct type *, int);
1375
1376 /* printcmd.c */
1377
1378 extern void print_scalar_formatted (const void *, struct type *, int, int,
1379                                     struct ui_file *);
1380
1381 extern int can_dereference (struct type *);
1382
1383 extern int is_integral_type (struct type *);
1384
1385 extern void maintenance_print_type (char *, int);
1386
1387 extern htab_t create_copied_types_hash (struct objfile *objfile);
1388
1389 extern struct type *copy_type_recursive (struct objfile *objfile,
1390                                          struct type *type,
1391                                          htab_t copied_types);
1392
1393 #endif /* GDBTYPES_H */