1 
2 /* Internal type definitions for GDB.
3 
4    Copyright (C) 1992-2024 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 /* * \page gdbtypes GDB Types
27 
28    GDB represents all the different kinds of types in programming
29    languages using a common representation defined in gdbtypes.h.
30 
31    The main data structure is main_type; it consists of a code (such
32    as #TYPE_CODE_ENUM for enumeration types), a number of
33    generally-useful fields such as the printable name, and finally a
34    field main_type::type_specific that is a union of info specific to
35    particular languages or other special cases (such as calling
36    convention).
37 
38    The available type codes are defined in enum #type_code.  The enum
39    includes codes both for types that are common across a variety
40    of languages, and for types that are language-specific.
41 
42    Most accesses to type fields go through macros such as
43    #TYPE_CODE(thistype) and #TYPE_FN_FIELD_CONST(thisfn, n).  These are
44    written such that they can be used as both rvalues and lvalues.
45  */
46 
47 #include "hashtab.h"
48 #include "gdbsupport/array-view.h"
49 #include "gdbsupport/gdb-hashtab.h"
50 #include <optional>
51 #include "gdbsupport/offset-type.h"
52 #include "gdbsupport/enum-flags.h"
53 #include "gdbsupport/underlying.h"
54 #include "gdbsupport/print-utils.h"
55 #include "gdbsupport/function-view.h"
56 #include "dwarf2.h"
57 #include "gdbsupport/gdb_obstack.h"
58 #include "gmp-utils.h"
59 
60 /* Forward declarations for prototypes.  */
61 struct field;
62 struct block;
63 struct value_print_options;
64 struct language_defn;
65 struct dwarf2_per_cu_data;
66 struct dwarf2_per_objfile;
67 struct dwarf2_property_baton;
68 
69 /* * Different kinds of data types are distinguished by the `code'
70    field.  */
71 
72 enum type_code
73   {
74     TYPE_CODE_UNDEF = 0,      /**< Not used; catches errors */
75 
76 #define OP(X) X,
77 #include "type-codes.def"
78 #undef OP
79 
80   };
81 
82 /* * Some bits for the type's instance_flags word.  See the macros
83    below for documentation on each bit.  */
84 
85 enum type_instance_flag_value : unsigned
86 {
87   TYPE_INSTANCE_FLAG_CONST = (1 << 0),
88   TYPE_INSTANCE_FLAG_VOLATILE = (1 << 1),
89   TYPE_INSTANCE_FLAG_CODE_SPACE = (1 << 2),
90   TYPE_INSTANCE_FLAG_DATA_SPACE = (1 << 3),
91   TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1 = (1 << 4),
92   TYPE_INSTANCE_FLAG_ADDRESS_CLASS_2 = (1 << 5),
93   TYPE_INSTANCE_FLAG_NOTTEXT = (1 << 6),
94   TYPE_INSTANCE_FLAG_RESTRICT = (1 << 7),
95   TYPE_INSTANCE_FLAG_ATOMIC = (1 << 8)
96 };
97 
98 DEF_ENUM_FLAGS_TYPE (enum type_instance_flag_value, type_instance_flags);
99 
100 /* * Not textual.  By default, GDB treats all single byte integers as
101    characters (or elements of strings) unless this flag is set.  */
102 
103 #define TYPE_NOTTEXT(t)       (((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_NOTTEXT)
104 
105 /* * Constant type.  If this is set, the corresponding type has a
106    const modifier.  */
107 
108 #define TYPE_CONST(t) ((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_CONST) != 0)
109 
110 /* * Volatile type.  If this is set, the corresponding type has a
111    volatile modifier.  */
112 
113 #define TYPE_VOLATILE(t) \
114   ((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_VOLATILE) != 0)
115 
116 /* * Restrict type.  If this is set, the corresponding type has a
117    restrict modifier.  */
118 
119 #define TYPE_RESTRICT(t) \
120   ((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_RESTRICT) != 0)
121 
122 /* * Atomic type.  If this is set, the corresponding type has an
123    _Atomic modifier.  */
124 
125 #define TYPE_ATOMIC(t) \
126   ((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_ATOMIC) != 0)
127 
128 /* * True if this type represents either an lvalue or lvalue reference type.  */
129 
130 #define TYPE_IS_REFERENCE(t) \
131   ((t)->code () == TYPE_CODE_REF || (t)->code () == TYPE_CODE_RVALUE_REF)
132 
133 /* * True if this type is allocatable.  */
134 #define TYPE_IS_ALLOCATABLE(t) \
135   ((t)->dyn_prop (DYN_PROP_ALLOCATED) != NULL)
136 
137 /* * True if this type has variant parts.  */
138 #define TYPE_HAS_VARIANT_PARTS(t) \
139   ((t)->dyn_prop (DYN_PROP_VARIANT_PARTS) != nullptr)
140 
141 /* * True if this type has a dynamic length.  */
142 #define TYPE_HAS_DYNAMIC_LENGTH(t) \
143   ((t)->dyn_prop (DYN_PROP_BYTE_SIZE) != nullptr)
144 
145 /* * Instruction-space delimited type.  This is for Harvard architectures
146    which have separate instruction and data address spaces (and perhaps
147    others).
148 
149    GDB usually defines a flat address space that is a superset of the
150    architecture's two (or more) address spaces, but this is an extension
151    of the architecture's model.
152 
153    If TYPE_INSTANCE_FLAG_CODE_SPACE is set, an object of the corresponding type
154    resides in instruction memory, even if its address (in the extended
155    flat address space) does not reflect this.
156 
157    Similarly, if TYPE_INSTANCE_FLAG_DATA_SPACE is set, then an object of the
158    corresponding type resides in the data memory space, even if
159    this is not indicated by its (flat address space) address.
160 
161    If neither flag is set, the default space for functions / methods
162    is instruction space, and for data objects is data memory.  */
163 
164 #define TYPE_CODE_SPACE(t) \
165   ((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_CODE_SPACE) != 0)
166 
167 #define TYPE_DATA_SPACE(t) \
168   ((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_DATA_SPACE) != 0)
169 
170 /* * Address class flags.  Some environments provide for pointers
171    whose size is different from that of a normal pointer or address
172    types where the bits are interpreted differently than normal
173    addresses.  The TYPE_INSTANCE_FLAG_ADDRESS_CLASS_n flags may be used in
174    target specific ways to represent these different types of address
175    classes.  */
176 
177 #define TYPE_ADDRESS_CLASS_1(t) (((t)->instance_flags ()) \
178                                          & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1)
179 #define TYPE_ADDRESS_CLASS_2(t) (((t)->instance_flags ()) \
180                                          & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_2)
181 #define TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL \
182   (TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1 | TYPE_INSTANCE_FLAG_ADDRESS_CLASS_2)
183 #define TYPE_ADDRESS_CLASS_ALL(t) (((t)->instance_flags ()) \
184                                            & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
185 
186 /* * Information about a single discriminant.  */
187 
188 struct discriminant_range
189 {
190   /* * The range of values for the variant.  This is an inclusive
191      range.  */
192   ULONGEST low, high;
193 
194   /* * Return true if VALUE is contained in this range.  IS_UNSIGNED
195      is true if this should be an unsigned comparison; false for
196      signed.  */
containsdiscriminant_range197   bool contains (ULONGEST value, bool is_unsigned) const
198   {
199     if (is_unsigned)
200       return value >= low && value <= high;
201     LONGEST valuel = (LONGEST) value;
202     return valuel >= (LONGEST) low && valuel <= (LONGEST) high;
203   }
204 };
205 
206 struct variant_part;
207 
208 /* * A single variant.  A variant has a list of discriminant values.
209    When the discriminator matches one of these, the variant is
210    enabled.  Each variant controls zero or more fields; and may also
211    control other variant parts as well.  This struct corresponds to
212    DW_TAG_variant in DWARF.  */
213 
214 struct variant : allocate_on_obstack<variant>
215 {
216   /* * The discriminant ranges for this variant.  */
217   gdb::array_view<discriminant_range> discriminants;
218 
219   /* * The fields controlled by this variant.  This is inclusive on
220      the low end and exclusive on the high end.  A variant may not
221      control any fields, in which case the two values will be equal.
222      These are indexes into the type's array of fields.  */
223   int first_field;
224   int last_field;
225 
226   /* * Variant parts controlled by this variant.  */
227   gdb::array_view<variant_part> parts;
228 
229   /* * Return true if this is the default variant.  The default
230      variant can be recognized because it has no associated
231      discriminants.  */
is_defaultvariant232   bool is_default () const
233   {
234     return discriminants.empty ();
235   }
236 
237   /* * Return true if this variant matches VALUE.  IS_UNSIGNED is true
238      if this should be an unsigned comparison; false for signed.  */
239   bool matches (ULONGEST value, bool is_unsigned) const;
240 };
241 
242 /* * A variant part.  Each variant part has an optional discriminant
243    and holds an array of variants.  This struct corresponds to
244    DW_TAG_variant_part in DWARF.  */
245 
246 struct variant_part : allocate_on_obstack<variant_part>
247 {
248   /* * The index of the discriminant field in the outer type.  This is
249      an index into the type's array of fields.  If this is -1, there
250      is no discriminant, and only the default variant can be
251      considered to be selected.  */
252   int discriminant_index;
253 
254   /* * True if this discriminant is unsigned; false if signed.  This
255      comes from the type of the discriminant.  */
256   bool is_unsigned;
257 
258   /* * The variants that are controlled by this variant part.  Note
259      that these will always be sorted by field number.  */
260   gdb::array_view<variant> variants;
261 };
262 
263 
264 enum dynamic_prop_kind
265 {
266   PROP_UNDEFINED, /* Not defined.  */
267   PROP_CONST,     /* Constant.  */
268   PROP_ADDR_OFFSET, /* Address offset.  */
269   PROP_LOCEXPR,   /* Location expression.  */
270   PROP_LOCLIST,    /* Location list.  */
271   PROP_VARIANT_PARTS, /* Variant parts.  */
272   PROP_TYPE,           /* Type.  */
273   PROP_VARIABLE_NAME, /* Variable name.  */
274   PROP_OPTIMIZED_OUT, /* Optimized out.  */
275 };
276 
277 union dynamic_prop_data
278 {
279   /* Storage for constant property.  */
280 
281   LONGEST const_val;
282 
283   /* Storage for dynamic property.  */
284 
285   const dwarf2_property_baton *baton;
286 
287   /* Storage of variant parts for a type.  A type with variant parts
288      has all its fields "linearized" -- stored in a single field
289      array, just as if they had all been declared that way.  The
290      variant parts are attached via a dynamic property, and then are
291      used to control which fields end up in the final type during
292      dynamic type resolution.  */
293 
294   const gdb::array_view<variant_part> *variant_parts;
295 
296   /* Once a variant type is resolved, we may want to be able to go
297      from the resolved type to the original type.  In this case we
298      rewrite the property's kind and set this field.  */
299 
300   struct type *original_type;
301 
302   /* Name of a variable to look up; the variable holds the value of
303      this property.  */
304 
305   const char *variable_name;
306 };
307 
308 /* * Used to store a dynamic property.  */
309 
310 struct dynamic_prop
311 {
kinddynamic_prop312   dynamic_prop_kind kind () const
313   {
314     return m_kind;
315   }
316 
set_undefineddynamic_prop317   void set_undefined ()
318   {
319     m_kind = PROP_UNDEFINED;
320   }
321 
set_optimized_outdynamic_prop322   void set_optimized_out ()
323   {
324     m_kind = PROP_OPTIMIZED_OUT;
325   }
326 
327   /* Return true if this property is "available", at least in theory
328      -- meaning it is neither undefined nor optimized out.  */
is_availabledynamic_prop329   bool is_available () const
330   {
331     return m_kind != PROP_UNDEFINED && m_kind != PROP_OPTIMIZED_OUT;
332   }
333 
const_valdynamic_prop334   LONGEST const_val () const
335   {
336     gdb_assert (m_kind == PROP_CONST);
337 
338     return m_data.const_val;
339   }
340 
set_const_valdynamic_prop341   void set_const_val (LONGEST const_val)
342   {
343     m_kind = PROP_CONST;
344     m_data.const_val = const_val;
345   }
346 
347   /* Return true if this property has a constant value, false
348      otherwise.  */
is_constantdynamic_prop349   bool is_constant () const
350   { return m_kind == PROP_CONST; }
351 
batondynamic_prop352   const dwarf2_property_baton *baton () const
353   {
354     gdb_assert (m_kind == PROP_LOCEXPR
355                     || m_kind == PROP_LOCLIST
356                     || m_kind == PROP_ADDR_OFFSET);
357 
358     return m_data.baton;
359   }
360 
set_locexprdynamic_prop361   void set_locexpr (const dwarf2_property_baton *baton)
362   {
363     m_kind = PROP_LOCEXPR;
364     m_data.baton = baton;
365   }
366 
set_loclistdynamic_prop367   void set_loclist (const dwarf2_property_baton *baton)
368   {
369     m_kind = PROP_LOCLIST;
370     m_data.baton = baton;
371   }
372 
set_addr_offsetdynamic_prop373   void set_addr_offset (const dwarf2_property_baton *baton)
374   {
375     m_kind = PROP_ADDR_OFFSET;
376     m_data.baton = baton;
377   }
378 
variant_partsdynamic_prop379   const gdb::array_view<variant_part> *variant_parts () const
380   {
381     gdb_assert (m_kind == PROP_VARIANT_PARTS);
382 
383     return m_data.variant_parts;
384   }
385 
set_variant_partsdynamic_prop386   void set_variant_parts (gdb::array_view<variant_part> *variant_parts)
387   {
388     m_kind = PROP_VARIANT_PARTS;
389     m_data.variant_parts = variant_parts;
390   }
391 
original_typedynamic_prop392   struct type *original_type () const
393   {
394     gdb_assert (m_kind == PROP_TYPE);
395 
396     return m_data.original_type;
397   }
398 
set_original_typedynamic_prop399   void set_original_type (struct type *original_type)
400   {
401     m_kind = PROP_TYPE;
402     m_data.original_type = original_type;
403   }
404 
405   /* Return the name of the variable that holds this property's value.
406      Only valid for PROP_VARIABLE_NAME.  */
variable_namedynamic_prop407   const char *variable_name () const
408   {
409     gdb_assert (m_kind == PROP_VARIABLE_NAME);
410     return m_data.variable_name;
411   }
412 
413   /* Set the name of the variable that holds this property's value,
414      and set this property to be of kind PROP_VARIABLE_NAME.  */
set_variable_namedynamic_prop415   void set_variable_name (const char *name)
416   {
417     m_kind = PROP_VARIABLE_NAME;
418     m_data.variable_name = name;
419   }
420 
421   /* Determine which field of the union dynamic_prop.data is used.  */
422   enum dynamic_prop_kind m_kind;
423 
424   /* Storage for dynamic or static value.  */
425   union dynamic_prop_data m_data;
426 };
427 
428 /* Compare two dynamic_prop objects for equality.  dynamic_prop
429    instances are equal iff they have the same type and storage.  */
430 extern bool operator== (const dynamic_prop &l, const dynamic_prop &r);
431 
432 /* Compare two dynamic_prop objects for inequality.  */
433 static inline bool operator!= (const dynamic_prop &l, const dynamic_prop &r)
434 {
435   return !(l == r);
436 }
437 
438 /* * Define a type's dynamic property node kind.  */
439 enum dynamic_prop_node_kind
440 {
441   /* A property providing a type's data location.
442      Evaluating this field yields to the location of an object's data.  */
443   DYN_PROP_DATA_LOCATION,
444 
445   /* A property representing DW_AT_allocated.  The presence of this attribute
446      indicates that the object of the type can be allocated/deallocated.  */
447   DYN_PROP_ALLOCATED,
448 
449   /* A property representing DW_AT_associated.  The presence of this attribute
450      indicated that the object of the type can be associated.  */
451   DYN_PROP_ASSOCIATED,
452 
453   /* A property providing an array's byte stride.  */
454   DYN_PROP_BYTE_STRIDE,
455 
456   /* A property holding variant parts.  */
457   DYN_PROP_VARIANT_PARTS,
458 
459   /* A property representing DW_AT_rank. The presence of this attribute
460      indicates that the object is of assumed rank array type.  */
461   DYN_PROP_RANK,
462 
463   /* A property holding the size of the type.  */
464   DYN_PROP_BYTE_SIZE,
465 };
466 
467 /* * List for dynamic type attributes.  */
468 struct dynamic_prop_list
469 {
470   /* The kind of dynamic prop in this node.  */
471   enum dynamic_prop_node_kind prop_kind;
472 
473   /* The dynamic property itself.  */
474   struct dynamic_prop prop;
475 
476   /* A pointer to the next dynamic property.  */
477   struct dynamic_prop_list *next;
478 };
479 
480 /* * Determine which field of the union main_type.fields[x].loc is
481    used.  */
482 
483 enum field_loc_kind
484   {
485     FIELD_LOC_KIND_BITPOS,    /**< bitpos */
486     FIELD_LOC_KIND_ENUMVAL,   /**< enumval */
487     FIELD_LOC_KIND_PHYSADDR,  /**< physaddr */
488     FIELD_LOC_KIND_PHYSNAME,  /**< physname */
489     FIELD_LOC_KIND_DWARF_BLOCK          /**< dwarf_block */
490   };
491 
492 /* * A discriminant to determine which field in the
493    main_type.type_specific union is being used, if any.
494 
495    For types such as TYPE_CODE_FLT, the use of this
496    discriminant is really redundant, as we know from the type code
497    which field is going to be used.  As such, it would be possible to
498    reduce the size of this enum in order to save a bit or two for
499    other fields of struct main_type.  But, since we still have extra
500    room , and for the sake of clarity and consistency, we treat all fields
501    of the union the same way.  */
502 
503 enum type_specific_kind
504 {
505   TYPE_SPECIFIC_NONE,
506   TYPE_SPECIFIC_CPLUS_STUFF,
507   TYPE_SPECIFIC_GNAT_STUFF,
508   TYPE_SPECIFIC_FLOATFORMAT,
509   /* Note: This is used by TYPE_CODE_FUNC and TYPE_CODE_METHOD.  */
510   TYPE_SPECIFIC_FUNC,
511   TYPE_SPECIFIC_SELF_TYPE,
512   TYPE_SPECIFIC_INT,
513   TYPE_SPECIFIC_FIXED_POINT,
514 };
515 
516 union type_owner
517 {
518   struct objfile *objfile;
519   struct gdbarch *gdbarch;
520 };
521 
522 union field_location
523 {
524   /* * Position of this field, counting in bits from start of
525      containing structure.  For big-endian targets, it is the bit
526      offset to the MSB.  For little-endian targets, it is the bit
527      offset to the LSB.  */
528 
529   LONGEST bitpos;
530 
531   /* * Enum value.  */
532   LONGEST enumval;
533 
534   /* * For a static field, if TYPE_FIELD_STATIC_HAS_ADDR then
535      physaddr is the location (in the target) of the static
536      field.  Otherwise, physname is the mangled label of the
537      static field.  */
538 
539   CORE_ADDR physaddr;
540   const char *physname;
541 
542   /* * The field location can be computed by evaluating the
543      following DWARF block.  Its DATA is allocated on
544      objfile_obstack - no CU load is needed to access it.  */
545 
546   struct dwarf2_locexpr_baton *dwarf_block;
547 };
548 
549 /* Accessibility of a member.  */
550 enum class accessibility : unsigned char
551 {
552   /* It's important that this be 0 so that fields default to
553      public.  */
554   PUBLIC = 0,
555   PROTECTED = 1,
556   PRIVATE = 2,
557 };
558 
559 struct field
560 {
typefield561   struct type *type () const
562   {
563     return this->m_type;
564   }
565 
set_typefield566   void set_type (struct type *type)
567   {
568     this->m_type = type;
569   }
570 
namefield571   const char *name () const
572   {
573     return m_name;
574   }
575 
set_namefield576   void set_name (const char *name)
577   {
578     m_name = name;
579   }
580 
is_artificialfield581   bool is_artificial () const
582   {
583     return m_artificial;
584   }
585 
set_is_artificialfield586   void set_is_artificial (bool is_artificial)
587   {
588     m_artificial = is_artificial;
589   }
590 
bitsizefield591   unsigned int bitsize () const
592   {
593     return m_bitsize;
594   }
595 
set_bitsizefield596   void set_bitsize (unsigned int bitsize)
597   {
598     m_bitsize = bitsize;
599   }
600 
is_packedfield601   bool is_packed () const
602   {
603     return m_bitsize != 0;
604   }
605 
606   /* Return true if this field is static; false if not.  */
is_staticfield607   bool is_static () const
608   {
609     /* "static" fields are the fields whose location is not relative
610        to the address of the enclosing struct.  It would be nice to
611        have a dedicated flag that would be set for static fields when
612        the type is being created.  But in practice, checking the field
613        loc_kind should give us an accurate answer.  */
614     return (m_loc_kind == FIELD_LOC_KIND_PHYSNAME
615               || m_loc_kind == FIELD_LOC_KIND_PHYSADDR);
616   }
617 
618   /* Location getters / setters.  */
619 
loc_kindfield620   field_loc_kind loc_kind () const
621   {
622     return m_loc_kind;
623   }
624 
loc_bitposfield625   LONGEST loc_bitpos () const
626   {
627     gdb_assert (m_loc_kind == FIELD_LOC_KIND_BITPOS);
628     return m_loc.bitpos;
629   }
630 
set_loc_bitposfield631   void set_loc_bitpos (LONGEST bitpos)
632   {
633     m_loc_kind = FIELD_LOC_KIND_BITPOS;
634     m_loc.bitpos = bitpos;
635   }
636 
loc_enumvalfield637   LONGEST loc_enumval () const
638   {
639     gdb_assert (m_loc_kind == FIELD_LOC_KIND_ENUMVAL);
640     return m_loc.enumval;
641   }
642 
set_loc_enumvalfield643   void set_loc_enumval (LONGEST enumval)
644   {
645     m_loc_kind = FIELD_LOC_KIND_ENUMVAL;
646     m_loc.enumval = enumval;
647   }
648 
loc_physaddrfield649   CORE_ADDR loc_physaddr () const
650   {
651     gdb_assert (m_loc_kind == FIELD_LOC_KIND_PHYSADDR);
652     return m_loc.physaddr;
653   }
654 
set_loc_physaddrfield655   void set_loc_physaddr (CORE_ADDR physaddr)
656   {
657     m_loc_kind = FIELD_LOC_KIND_PHYSADDR;
658     m_loc.physaddr = physaddr;
659   }
660 
loc_physnamefield661   const char *loc_physname () const
662   {
663     gdb_assert (m_loc_kind == FIELD_LOC_KIND_PHYSNAME);
664     return m_loc.physname;
665   }
666 
set_loc_physnamefield667   void set_loc_physname (const char *physname)
668   {
669     m_loc_kind = FIELD_LOC_KIND_PHYSNAME;
670     m_loc.physname = physname;
671   }
672 
loc_dwarf_blockfield673   dwarf2_locexpr_baton *loc_dwarf_block () const
674   {
675     gdb_assert (m_loc_kind == FIELD_LOC_KIND_DWARF_BLOCK);
676     return m_loc.dwarf_block;
677   }
678 
set_loc_dwarf_blockfield679   void set_loc_dwarf_block (dwarf2_locexpr_baton *dwarf_block)
680   {
681     m_loc_kind = FIELD_LOC_KIND_DWARF_BLOCK;
682     m_loc.dwarf_block = dwarf_block;
683   }
684 
685   /* Set the field's accessibility.  */
set_accessibilityfield686   void set_accessibility (accessibility acc)
687   { m_accessibility = acc; }
688 
689   /* Fetch the field's accessibility.  */
accessibilityfield690   enum accessibility accessibility () const
691   { return m_accessibility; }
692 
693   /* True if this field is 'public'.  */
is_publicfield694   bool is_public () const
695   { return m_accessibility == accessibility::PUBLIC; }
696 
697   /* True if this field is 'private'.  */
is_privatefield698   bool is_private () const
699   { return m_accessibility == accessibility::PRIVATE; }
700 
701   /* True if this field is 'protected'.  */
is_protectedfield702   bool is_protected () const
703   { return m_accessibility == accessibility::PROTECTED; }
704 
705   /* True if this field is 'virtual'.  */
is_virtualfield706   bool is_virtual () const
707   { return m_virtual; }
708 
709   /* Set the field's "virtual" flag.  */
set_virtualfield710   void set_virtual ()
711   { m_virtual = true; }
712 
713   /* True if this field is 'ignored'.  */
is_ignoredfield714   bool is_ignored () const
715   { return m_ignored; }
716 
717   /* Set the field's "ignored" flag.  Note that the 'ignored' bit is
718      deprecated.  It was used by some unknown stabs generator, and has
719      been replaced by the optimized-out approach -- however, it
720      remains because the stabs reader was never updated.  */
set_ignoredfield721   void set_ignored ()
722   { m_ignored = true; }
723 
724   union field_location m_loc;
725 
726   /* * For a function or member type, this is 1 if the argument is
727      marked artificial.  Artificial arguments should not be shown
728      to the user.  For TYPE_CODE_RANGE it is set if the specific
729      bound is not defined.  */
730 
731   unsigned int m_artificial : 1;
732 
733   /* Whether the field is 'virtual'.  */
734   bool m_virtual : 1;
735   /* Whether the field is 'ignored'.  */
736   bool m_ignored : 1;
737 
738   /* * Discriminant for union field_location.  */
739 
740   ENUM_BITFIELD(field_loc_kind) m_loc_kind : 3;
741 
742   /* Accessibility of the field.  */
743   enum accessibility m_accessibility;
744 
745   /* * Size of this field, in bits, or zero if not packed.
746      If non-zero in an array type, indicates the element size in
747      bits (used only in Ada at the moment).
748      For an unpacked field, the field's type's length
749      says how many bytes the field occupies.  */
750 
751   unsigned int m_bitsize;
752 
753   /* * In a struct or union type, type of this field.
754      - In a function or member type, type of this argument.
755      - In an array type, the domain-type of the array.  */
756 
757   struct type *m_type;
758 
759   /* * Name of field, value or argument.
760      NULL for range bounds, array domains, and member function
761      arguments.  */
762 
763   const char *m_name;
764 };
765 
766 struct range_bounds
767 {
bit_striderange_bounds768   ULONGEST bit_stride () const
769   {
770     if (this->flag_is_byte_stride)
771       return this->stride.const_val () * 8;
772     else
773       return this->stride.const_val ();
774   }
775 
776   /* Return true if either bounds is optimized out.  */
optimized_outrange_bounds777   bool optimized_out () const
778   {
779     return (low.kind () == PROP_OPTIMIZED_OUT
780               || high.kind () == PROP_OPTIMIZED_OUT);
781   }
782 
783   /* * Low bound of range.  */
784 
785   struct dynamic_prop low;
786 
787   /* * High bound of range.  */
788 
789   struct dynamic_prop high;
790 
791   /* The stride value for this range.  This can be stored in bits or bytes
792      based on the value of BYTE_STRIDE_P.  It is optional to have a stride
793      value, if this range has no stride value defined then this will be set
794      to the constant zero.  */
795 
796   struct dynamic_prop stride;
797 
798   /* * The bias.  Sometimes a range value is biased before storage.
799      The bias is added to the stored bits to form the true value.  */
800 
801   LONGEST bias;
802 
803   /* True if HIGH range bound contains the number of elements in the
804      subrange.  This affects how the final high bound is computed.  */
805 
806   unsigned int flag_upper_bound_is_count : 1;
807 
808   /* True if LOW or/and HIGH are resolved into a static bound from
809      a dynamic one.  */
810 
811   unsigned int flag_bound_evaluated : 1;
812 
813   /* If this is true this STRIDE is in bytes, otherwise STRIDE is in bits.  */
814 
815   unsigned int flag_is_byte_stride : 1;
816 };
817 
818 /* Compare two range_bounds objects for equality.  Simply does
819    memberwise comparison.  */
820 extern bool operator== (const range_bounds &l, const range_bounds &r);
821 
822 /* Compare two range_bounds objects for inequality.  */
823 static inline bool operator!= (const range_bounds &l, const range_bounds &r)
824 {
825   return !(l == r);
826 }
827 
828 union type_specific
829 {
830   /* * CPLUS_STUFF is for TYPE_CODE_STRUCT.  It is initialized to
831      point to cplus_struct_default, a default static instance of a
832      struct cplus_struct_type.  */
833 
834   struct cplus_struct_type *cplus_stuff;
835 
836   /* * GNAT_STUFF is for types for which the GNAT Ada compiler
837      provides additional information.  */
838 
839   struct gnat_aux_type *gnat_stuff;
840 
841   /* * FLOATFORMAT is for TYPE_CODE_FLT.  It is a pointer to a
842      floatformat object that describes the floating-point value
843      that resides within the type.  */
844 
845   const struct floatformat *floatformat;
846 
847   /* * For TYPE_CODE_FUNC and TYPE_CODE_METHOD types.  */
848 
849   struct func_type *func_stuff;
850 
851   /* * For types that are pointer to member types (TYPE_CODE_METHODPTR,
852      TYPE_CODE_MEMBERPTR), SELF_TYPE is the type that this pointer
853      is a member of.  */
854 
855   struct type *self_type;
856 
857   /* * For TYPE_CODE_FIXED_POINT types, the info necessary to decode
858      values of that type.  */
859   struct fixed_point_type_info *fixed_point_info;
860 
861   /* * An integer-like scalar type may be stored in just part of its
862      enclosing storage bytes.  This structure describes this
863      situation.  */
864   struct
865   {
866     /* * The bit size of the integer.  This can be 0.  For integers
867        that fill their storage (the ordinary case), this field holds
868        the byte size times 8.  */
869     unsigned short bit_size;
870     /* * The bit offset of the integer.  This is ordinarily 0, and can
871        only be non-zero if the bit size is less than the storage
872        size.  */
873     unsigned short bit_offset;
874   } int_stuff;
875 };
876 
877 /* * Main structure representing a type in GDB.
878 
879    This structure is space-critical.  Its layout has been tweaked to
880    reduce the space used.  */
881 
882 struct main_type
883 {
884   /* * Code for kind of type.  */
885 
886   ENUM_BITFIELD(type_code) code : 8;
887 
888   /* * Flags about this type.  These fields appear at this location
889      because they packs nicely here.  See the TYPE_* macros for
890      documentation about these fields.  */
891 
892   unsigned int m_flag_unsigned : 1;
893   unsigned int m_flag_nosign : 1;
894   unsigned int m_flag_stub : 1;
895   unsigned int m_flag_target_stub : 1;
896   unsigned int m_flag_prototyped : 1;
897   unsigned int m_flag_varargs : 1;
898   unsigned int m_flag_vector : 1;
899   unsigned int m_flag_stub_supported : 1;
900   unsigned int m_flag_gnu_ifunc : 1;
901   unsigned int m_flag_fixed_instance : 1;
902   unsigned int m_flag_objfile_owned : 1;
903   unsigned int m_flag_endianity_not_default : 1;
904 
905   /* * True if this type was declared with "class" rather than
906      "struct".  */
907 
908   unsigned int m_flag_declared_class : 1;
909 
910   /* * True if this is an enum type with disjoint values.  This
911      affects how the enum is printed.  */
912 
913   unsigned int m_flag_flag_enum : 1;
914 
915   /* * For TYPE_CODE_ARRAY, this is true if this type is part of a
916      multi-dimensional array.  Multi-dimensional arrays are
917      represented internally as arrays of arrays, and this flag lets
918      gdb distinguish between multiple dimensions and an ordinary array
919      of arrays.  The flag is set on each inner dimension, but not the
920      outermost dimension.  */
921 
922   unsigned int m_multi_dimensional : 1;
923 
924   /* * A discriminant telling us which field of the type_specific
925      union is being used for this type, if any.  */
926 
927   ENUM_BITFIELD(type_specific_kind) type_specific_field : 3;
928 
929   /* The language for this type.  */
930 
931   ENUM_BITFIELD(language) m_lang : LANGUAGE_BITS;
932 
933   /* * Number of fields described for this type.  This field appears
934      at this location because it packs nicely here.  */
935 
936   unsigned int m_nfields;
937 
938   /* * Name of this type, or NULL if none.
939 
940      This is used for printing only.  For looking up a name, look for
941      a symbol in the VAR_DOMAIN.  This is generally allocated in the
942      objfile's obstack.  However coffread.c uses malloc.  */
943 
944   const char *name;
945 
946   /* * Every type is now associated with a particular objfile, and the
947      type is allocated on the objfile_obstack for that objfile.  One
948      problem however, is that there are times when gdb allocates new
949      types while it is not in the process of reading symbols from a
950      particular objfile.  Fortunately, these happen when the type
951      being created is a derived type of an existing type, such as in
952      lookup_pointer_type().  So we can just allocate the new type
953      using the same objfile as the existing type, but to do this we
954      need a backpointer to the objfile from the existing type.  Yes
955      this is somewhat ugly, but without major overhaul of the internal
956      type system, it can't be avoided for now.  */
957 
958   union type_owner m_owner;
959 
960   /* * For a pointer type, describes the type of object pointed to.
961      - For an array type, describes the type of the elements.
962      - For a function or method type, describes the type of the return value.
963      - For a range type, describes the type of the full range.
964      - For a complex type, describes the type of each coordinate.
965      - For a special record or union type encoding a dynamic-sized type
966      in GNAT, a memoized pointer to a corresponding static version of
967      the type.
968      - Unused otherwise.  */
969 
970   struct type *m_target_type;
971 
972   /* * For structure and union types, a description of each field.
973      For set and pascal array types, there is one "field",
974      whose type is the domain type of the set or array.
975      For range types, there are two "fields",
976      the minimum and maximum values (both inclusive).
977      For enum types, each possible value is described by one "field".
978      For a function or method type, a "field" for each parameter.
979      For C++ classes, there is one field for each base class (if it is
980      a derived class) plus one field for each class data member.  Member
981      functions are recorded elsewhere.
982 
983      Using a pointer to a separate array of fields
984      allows all types to have the same size, which is useful
985      because we can allocate the space for a type before
986      we know what to put in it.  */
987 
988   union
989   {
990     struct field *fields;
991 
992     /* * Union member used for range types.  */
993 
994     struct range_bounds *bounds;
995 
996     /* If this is a scalar type, then this is its corresponding
997        complex type.  */
998     struct type *complex_type;
999 
1000   } flds_bnds;
1001 
1002   /* * Slot to point to additional language-specific fields of this
1003      type.  */
1004 
1005   union type_specific type_specific;
1006 
1007   /* * Contains all dynamic type properties.  */
1008   struct dynamic_prop_list *dyn_prop_list;
1009 };
1010 
1011 /* * Number of bits allocated for alignment.  */
1012 
1013 #define TYPE_ALIGN_BITS 8
1014 
1015 /* * A ``struct type'' describes a particular instance of a type, with
1016    some particular qualification.  */
1017 
1018 struct type
1019 {
1020   /* Get the type code of this type.
1021 
1022      Note that the code can be TYPE_CODE_TYPEDEF, so if you want the real
1023      type, you need to do `check_typedef (type)->code ()`.  */
codetype1024   type_code code () const
1025   {
1026     return this->main_type->code;
1027   }
1028 
1029   /* Set the type code of this type.  */
set_codetype1030   void set_code (type_code code)
1031   {
1032     this->main_type->code = code;
1033   }
1034 
1035   /* Get the name of this type.  */
nametype1036   const char *name () const
1037   {
1038     return this->main_type->name;
1039   }
1040 
1041   /* Set the name of this type.  */
set_nametype1042   void set_name (const char *name)
1043   {
1044     this->main_type->name = name;
1045   }
1046 
1047   /* Note that if thistype is a TYPEDEF type, you have to call check_typedef.
1048      But check_typedef does set the TYPE_LENGTH of the TYPEDEF type,
1049      so you only have to call check_typedef once.  Since value::allocate
1050      calls check_typedef, X->type ()->length () is safe.  */
lengthtype1051   ULONGEST length () const
1052   {
1053     return this->m_length;
1054   }
1055 
set_lengthtype1056   void set_length (ULONGEST length)
1057   {
1058     this->m_length = length;
1059   }
1060 
1061   /* Get the number of fields of this type.  */
num_fieldstype1062   unsigned int num_fields () const
1063   {
1064     return this->main_type->m_nfields;
1065   }
1066 
1067   /* Set the number of fields of this type.  */
set_num_fieldstype1068   void set_num_fields (unsigned int num_fields)
1069   {
1070     this->main_type->m_nfields = num_fields;
1071   }
1072 
1073   /* Get the fields array of this type.  */
fieldstype1074   struct field *fields () const
1075   {
1076     return this->main_type->flds_bnds.fields;
1077   }
1078 
1079   /* Get the field at index IDX.  */
fieldtype1080   struct field &field (int idx) const
1081   {
1082     gdb_assert (idx >= 0 && idx < num_fields ());
1083     return this->fields ()[idx];
1084   }
1085 
1086   /* Set the fields array of this type.  */
set_fieldstype1087   void set_fields (struct field *fields)
1088   {
1089     this->main_type->flds_bnds.fields = fields;
1090   }
1091 
1092   /* Allocate the fields array of this type, with NFIELDS elements.  If INIT,
1093      zero-initialize the allocated memory.  */
1094   void alloc_fields (unsigned int nfields, bool init = true);
1095 
1096   /* Allocate the fields array of this type, and copy the fields from SRC.  */
1097   void copy_fields (struct type *src);
1098   void copy_fields (std::vector<struct field> &src);
1099 
index_typetype1100   type *index_type () const
1101   {
1102     return this->field (0).type ();
1103   }
1104 
target_typetype1105   struct type *target_type () const
1106   {
1107     return this->main_type->m_target_type;
1108   }
1109 
set_target_typetype1110   void set_target_type (struct type *target_type)
1111   {
1112     this->main_type->m_target_type = target_type;
1113   }
1114 
set_index_typetype1115   void set_index_type (type *index_type)
1116   {
1117     this->field (0).set_type (index_type);
1118   }
1119 
1120   /* Return the instance flags converted to the correct type.  */
instance_flagstype1121   const type_instance_flags instance_flags () const
1122   {
1123     return (enum type_instance_flag_value) this->m_instance_flags;
1124   }
1125 
1126   /* Set the instance flags.  */
set_instance_flagstype1127   void set_instance_flags (type_instance_flags flags)
1128   {
1129     this->m_instance_flags = flags;
1130   }
1131 
1132   /* Get the bounds bounds of this type.  The type must be a range type.  */
boundstype1133   range_bounds *bounds () const
1134   {
1135     switch (this->code ())
1136       {
1137       case TYPE_CODE_RANGE:
1138           return this->main_type->flds_bnds.bounds;
1139 
1140       case TYPE_CODE_ARRAY:
1141       case TYPE_CODE_STRING:
1142           return this->index_type ()->bounds ();
1143 
1144       default:
1145           gdb_assert_not_reached
1146             ("type::bounds called on type with invalid code");
1147       }
1148   }
1149 
1150   /* Set the bounds of this type.  The type must be a range type.  */
set_boundstype1151   void set_bounds (range_bounds *bounds)
1152   {
1153     gdb_assert (this->code () == TYPE_CODE_RANGE);
1154 
1155     this->main_type->flds_bnds.bounds = bounds;
1156   }
1157 
1158   /* Return true if this type's bounds were optimized out.  */
bound_optimized_outtype1159   bool bound_optimized_out () const
1160   {
1161     return bounds ()->optimized_out ();
1162   }
1163 
bit_stridetype1164   ULONGEST bit_stride () const
1165   {
1166     if (this->code () == TYPE_CODE_ARRAY && this->field (0).bitsize () != 0)
1167       return this->field (0).bitsize ();
1168     return this->bounds ()->bit_stride ();
1169   }
1170 
1171   /* Unsigned integer type.  If this is not set for a TYPE_CODE_INT,
1172      the type is signed (unless TYPE_NOSIGN is set).  */
1173 
is_unsignedtype1174   bool is_unsigned () const
1175   {
1176     return this->main_type->m_flag_unsigned;
1177   }
1178 
set_is_unsignedtype1179   void set_is_unsigned (bool is_unsigned)
1180   {
1181     this->main_type->m_flag_unsigned = is_unsigned;
1182   }
1183 
1184   /* No sign for this type.  In C++, "char", "signed char", and
1185      "unsigned char" are distinct types; so we need an extra flag to
1186      indicate the absence of a sign!  */
1187 
has_no_signednesstype1188   bool has_no_signedness () const
1189   {
1190     return this->main_type->m_flag_nosign;
1191   }
1192 
set_has_no_signednesstype1193   void set_has_no_signedness (bool has_no_signedness)
1194   {
1195     this->main_type->m_flag_nosign = has_no_signedness;
1196   }
1197 
1198   /* This appears in a type's flags word if it is a stub type (e.g.,
1199      if someone referenced a type that wasn't defined in a source file
1200      via (struct sir_not_appearing_in_this_film *)).  */
1201 
is_stubtype1202   bool is_stub () const
1203   {
1204     return this->main_type->m_flag_stub;
1205   }
1206 
set_is_stubtype1207   void set_is_stub (bool is_stub)
1208   {
1209     this->main_type->m_flag_stub = is_stub;
1210   }
1211 
1212   /* The target type of this type is a stub type, and this type needs
1213      to be updated if it gets un-stubbed in check_typedef.  Used for
1214      arrays and ranges, in which TYPE_LENGTH of the array/range gets set
1215      based on the TYPE_LENGTH of the target type.  Also, set for
1216      TYPE_CODE_TYPEDEF.  */
1217 
target_is_stubtype1218   bool target_is_stub () const
1219   {
1220     return this->main_type->m_flag_target_stub;
1221   }
1222 
set_target_is_stubtype1223   void set_target_is_stub (bool target_is_stub)
1224   {
1225     this->main_type->m_flag_target_stub = target_is_stub;
1226   }
1227 
1228   /* This is a function type which appears to have a prototype.  We
1229      need this for function calls in order to tell us if it's necessary
1230      to coerce the args, or to just do the standard conversions.  This
1231      is used with a short field.  */
1232 
is_prototypedtype1233   bool is_prototyped () const
1234   {
1235     return this->main_type->m_flag_prototyped;
1236   }
1237 
set_is_prototypedtype1238   void set_is_prototyped (bool is_prototyped)
1239   {
1240     this->main_type->m_flag_prototyped = is_prototyped;
1241   }
1242 
1243   /* FIXME drow/2002-06-03:  Only used for methods, but applies as well
1244      to functions.  */
1245 
has_varargstype1246   bool has_varargs () const
1247   {
1248     return this->main_type->m_flag_varargs;
1249   }
1250 
set_has_varargstype1251   void set_has_varargs (bool has_varargs)
1252   {
1253     this->main_type->m_flag_varargs = has_varargs;
1254   }
1255 
1256   /* Identify a vector type.  Gcc is handling this by adding an extra
1257      attribute to the array type.  We slurp that in as a new flag of a
1258      type.  This is used only in dwarf2read.c.  */
1259 
is_vectortype1260   bool is_vector () const
1261   {
1262     return this->main_type->m_flag_vector;
1263   }
1264 
set_is_vectortype1265   void set_is_vector (bool is_vector)
1266   {
1267     this->main_type->m_flag_vector = is_vector;
1268   }
1269 
1270   /* This debug target supports TYPE_STUB(t).  In the unsupported case
1271      we have to rely on NFIELDS to be zero etc., see TYPE_IS_OPAQUE().
1272      TYPE_STUB(t) with !TYPE_STUB_SUPPORTED(t) may exist if we only
1273      guessed the TYPE_STUB(t) value (see dwarfread.c).  */
1274 
stub_is_supportedtype1275   bool stub_is_supported () const
1276   {
1277     return this->main_type->m_flag_stub_supported;
1278   }
1279 
set_stub_is_supportedtype1280   void set_stub_is_supported (bool stub_is_supported)
1281   {
1282     this->main_type->m_flag_stub_supported = stub_is_supported;
1283   }
1284 
1285   /* Used only for TYPE_CODE_FUNC where it specifies the real function
1286      address is returned by this function call.  The target_type method
1287      determines the final returned function type to be presented to
1288      user.  */
1289 
is_gnu_ifunctype1290   bool is_gnu_ifunc () const
1291   {
1292     return this->main_type->m_flag_gnu_ifunc;
1293   }
1294 
set_is_gnu_ifunctype1295   void set_is_gnu_ifunc (bool is_gnu_ifunc)
1296   {
1297     this->main_type->m_flag_gnu_ifunc = is_gnu_ifunc;
1298   }
1299 
1300   /* The debugging formats (especially STABS) do not contain enough
1301      information to represent all Ada types---especially those whose
1302      size depends on dynamic quantities.  Therefore, the GNAT Ada
1303      compiler includes extra information in the form of additional type
1304      definitions connected by naming conventions.  This flag indicates
1305      that the type is an ordinary (unencoded) GDB type that has been
1306      created from the necessary run-time information, and does not need
1307      further interpretation.  Optionally marks ordinary, fixed-size GDB
1308      type.  */
1309 
is_fixed_instancetype1310   bool is_fixed_instance () const
1311   {
1312     return this->main_type->m_flag_fixed_instance;
1313   }
1314 
set_is_fixed_instancetype1315   void set_is_fixed_instance (bool is_fixed_instance)
1316   {
1317     this->main_type->m_flag_fixed_instance = is_fixed_instance;
1318   }
1319 
1320   /* A compiler may supply dwarf instrumentation that indicates the desired
1321      endian interpretation of the variable differs from the native endian
1322      representation. */
1323 
endianity_is_not_defaulttype1324   bool endianity_is_not_default () const
1325   {
1326     return this->main_type->m_flag_endianity_not_default;
1327   }
1328 
set_endianity_is_not_defaulttype1329   void set_endianity_is_not_default (bool endianity_is_not_default)
1330   {
1331     this->main_type->m_flag_endianity_not_default = endianity_is_not_default;
1332   }
1333 
1334 
1335   /* True if this type was declared using the "class" keyword.  This is
1336      only valid for C++ structure and enum types.  If false, a structure
1337      was declared as a "struct"; if true it was declared "class".  For
1338      enum types, this is true when "enum class" or "enum struct" was
1339      used to declare the type.  */
1340 
is_declared_classtype1341   bool is_declared_class () const
1342   {
1343     return this->main_type->m_flag_declared_class;
1344   }
1345 
set_is_declared_classtype1346   void set_is_declared_class (bool is_declared_class) const
1347   {
1348     this->main_type->m_flag_declared_class = is_declared_class;
1349   }
1350 
1351   /* True if this type is a "flag" enum.  A flag enum is one where all
1352      the values are pairwise disjoint when "and"ed together.  This
1353      affects how enum values are printed.  */
1354 
is_flag_enumtype1355   bool is_flag_enum () const
1356   {
1357     return this->main_type->m_flag_flag_enum;
1358   }
1359 
set_is_flag_enumtype1360   void set_is_flag_enum (bool is_flag_enum)
1361   {
1362     this->main_type->m_flag_flag_enum = is_flag_enum;
1363   }
1364 
1365   /* True if this array type is part of a multi-dimensional array.  */
1366 
is_multi_dimensionaltype1367   bool is_multi_dimensional () const
1368   {
1369     return this->main_type->m_multi_dimensional;
1370   }
1371 
set_is_multi_dimensionaltype1372   void set_is_multi_dimensional (bool value)
1373   {
1374     this->main_type->m_multi_dimensional = value;
1375   }
1376 
1377   /* * Assuming that THIS is a TYPE_CODE_FIXED_POINT, return a reference
1378      to this type's fixed_point_info.  */
1379 
fixed_point_infotype1380   struct fixed_point_type_info &fixed_point_info () const
1381   {
1382     gdb_assert (this->code () == TYPE_CODE_FIXED_POINT);
1383     gdb_assert (this->main_type->type_specific.fixed_point_info != nullptr);
1384 
1385     return *this->main_type->type_specific.fixed_point_info;
1386   }
1387 
1388   /* * Assuming that THIS is a TYPE_CODE_FIXED_POINT, set this type's
1389      fixed_point_info to INFO.  */
1390 
set_fixed_point_infotype1391   void set_fixed_point_info (struct fixed_point_type_info *info) const
1392   {
1393     gdb_assert (this->code () == TYPE_CODE_FIXED_POINT);
1394 
1395     this->main_type->type_specific.fixed_point_info = info;
1396   }
1397 
1398   /* * Assuming that THIS is a TYPE_CODE_FIXED_POINT, return its base type.
1399 
1400      In other words, this returns the type after having peeled all
1401      intermediate type layers (such as TYPE_CODE_RANGE, for instance).
1402      The TYPE_CODE of the type returned is guaranteed to be
1403      a TYPE_CODE_FIXED_POINT.  */
1404 
1405   struct type *fixed_point_type_base_type ();
1406 
1407   /* * Assuming that THIS is a TYPE_CODE_FIXED_POINT, return its scaling
1408      factor.  */
1409 
1410   const gdb_mpq &fixed_point_scaling_factor ();
1411 
1412   /* * Return the dynamic property of the requested KIND from this type's
1413      list of dynamic properties.  */
1414   dynamic_prop *dyn_prop (dynamic_prop_node_kind kind) const;
1415 
1416   /* * Given a dynamic property PROP of a given KIND, add this dynamic
1417      property to this type.
1418 
1419      This function assumes that this type is objfile-owned.  */
1420   void add_dyn_prop (dynamic_prop_node_kind kind, dynamic_prop prop);
1421 
1422   /* * Remove dynamic property of kind KIND from this type, if it exists.  */
1423   void remove_dyn_prop (dynamic_prop_node_kind kind);
1424 
1425   /* Return true if this type is owned by an objfile.  Return false if it is
1426      owned by an architecture.  */
is_objfile_ownedtype1427   bool is_objfile_owned () const
1428   {
1429     return this->main_type->m_flag_objfile_owned;
1430   }
1431 
1432   /* Set the owner of the type to be OBJFILE.  */
set_ownertype1433   void set_owner (objfile *objfile)
1434   {
1435     gdb_assert (objfile != nullptr);
1436 
1437     this->main_type->m_owner.objfile = objfile;
1438     this->main_type->m_flag_objfile_owned = true;
1439   }
1440 
1441   /* Set the owner of the type to be ARCH.  */
set_ownertype1442   void set_owner (gdbarch *arch)
1443   {
1444     gdb_assert (arch != nullptr);
1445 
1446     this->main_type->m_owner.gdbarch = arch;
1447     this->main_type->m_flag_objfile_owned = false;
1448   }
1449 
1450   /* Return the objfile owner of this type.
1451 
1452      Return nullptr if this type is not objfile-owned.  */
objfile_ownertype1453   struct objfile *objfile_owner () const
1454   {
1455     if (!this->is_objfile_owned ())
1456       return nullptr;
1457 
1458     return this->main_type->m_owner.objfile;
1459   }
1460 
1461   /* Return the gdbarch owner of this type.
1462 
1463      Return nullptr if this type is not gdbarch-owned.  */
arch_ownertype1464   gdbarch *arch_owner () const
1465   {
1466     if (this->is_objfile_owned ())
1467       return nullptr;
1468 
1469     return this->main_type->m_owner.gdbarch;
1470   }
1471 
1472   /* Return the type's architecture.  For types owned by an
1473      architecture, that architecture is returned.  For types owned by an
1474      objfile, that objfile's architecture is returned.
1475 
1476      The return value is always non-nullptr.  */
1477   gdbarch *arch () const;
1478 
1479   /* * Return true if this is an integer type whose logical (bit) size
1480      differs from its storage size; false otherwise.  Always return
1481      false for non-integer (i.e., non-TYPE_SPECIFIC_INT) types.  */
bit_size_differs_ptype1482   bool bit_size_differs_p () const
1483   {
1484     return (main_type->type_specific_field == TYPE_SPECIFIC_INT
1485               && main_type->type_specific.int_stuff.bit_size != 8 * length ());
1486   }
1487 
1488   /* * Return the logical (bit) size for this integer type.  Only
1489      valid for integer (TYPE_SPECIFIC_INT) types.  */
bit_sizetype1490   unsigned short bit_size () const
1491   {
1492     gdb_assert (main_type->type_specific_field == TYPE_SPECIFIC_INT);
1493     return main_type->type_specific.int_stuff.bit_size;
1494   }
1495 
1496   /* * Return the bit offset for this integer type.  Only valid for
1497      integer (TYPE_SPECIFIC_INT) types.  */
bit_offsettype1498   unsigned short bit_offset () const
1499   {
1500     gdb_assert (main_type->type_specific_field == TYPE_SPECIFIC_INT);
1501     return main_type->type_specific.int_stuff.bit_offset;
1502   }
1503 
1504   /* Return true if this is a pointer or reference type.  */
is_pointer_or_referencetype1505   bool is_pointer_or_reference () const
1506   {
1507     return this->code () == TYPE_CODE_PTR || TYPE_IS_REFERENCE (this);
1508   }
1509 
1510   /* Return true if this type is "string-like", according to its
1511      defining language.  */
1512   bool is_string_like ();
1513 
1514   /* Return true if this type is "array-like".  This includes arrays,
1515      but also some forms of structure type that are recognized as
1516      representations of arrays by the type's language.  */
1517   bool is_array_like ();
1518 
1519   /* Return the language that this type came from.  */
languagetype1520   enum language language () const
1521   { return main_type->m_lang; }
1522 
1523   /* * Type that is a pointer to this type.
1524      NULL if no such pointer-to type is known yet.
1525      The debugger may add the address of such a type
1526      if it has to construct one later.  */
1527 
1528   struct type *pointer_type;
1529 
1530   /* * C++: also need a reference type.  */
1531 
1532   struct type *reference_type;
1533 
1534   /* * A C++ rvalue reference type added in C++11. */
1535 
1536   struct type *rvalue_reference_type;
1537 
1538   /* * Variant chain.  This points to a type that differs from this
1539      one only in qualifiers and length.  Currently, the possible
1540      qualifiers are const, volatile, code-space, data-space, and
1541      address class.  The length may differ only when one of the
1542      address class flags are set.  The variants are linked in a
1543      circular ring and share MAIN_TYPE.  */
1544 
1545   struct type *chain;
1546 
1547   /* * The alignment for this type.  Zero means that the alignment was
1548      not specified in the debug info.  Note that this is stored in a
1549      funny way: as the log base 2 (plus 1) of the alignment; so a
1550      value of 1 means the alignment is 1, and a value of 9 means the
1551      alignment is 256.  */
1552 
1553   unsigned align_log2 : TYPE_ALIGN_BITS;
1554 
1555   /* * Flags specific to this instance of the type, indicating where
1556      on the ring we are.
1557 
1558      For TYPE_CODE_TYPEDEF the flags of the typedef type should be
1559      binary or-ed with the target type, with a special case for
1560      address class and space class.  For example if this typedef does
1561      not specify any new qualifiers, TYPE_INSTANCE_FLAGS is 0 and the
1562      instance flags are completely inherited from the target type.  No
1563      qualifiers can be cleared by the typedef.  See also
1564      check_typedef.  */
1565   unsigned m_instance_flags : 9;
1566 
1567   /* * Length of storage for a value of this type.  The value is the
1568      expression in host bytes of what sizeof(type) would return.  This
1569      size includes padding.  For example, an i386 extended-precision
1570      floating point value really only occupies ten bytes, but most
1571      ABI's declare its size to be 12 bytes, to preserve alignment.
1572      A `struct type' representing such a floating-point type would
1573      have a `length' value of 12, even though the last two bytes are
1574      unused.
1575 
1576      Since this field is expressed in host bytes, its value is appropriate
1577      to pass to memcpy and such (it is assumed that GDB itself always runs
1578      on an 8-bits addressable architecture).  However, when using it for
1579      target address arithmetic (e.g. adding it to a target address), the
1580      type_length_units function should be used in order to get the length
1581      expressed in target addressable memory units.  */
1582 
1583   ULONGEST m_length;
1584 
1585   /* * Core type, shared by a group of qualified types.  */
1586 
1587   struct main_type *main_type;
1588 };
1589 
1590 struct fn_fieldlist
1591 {
1592 
1593   /* * The overloaded name.
1594      This is generally allocated in the objfile's obstack.
1595      However stabsread.c sometimes uses malloc.  */
1596 
1597   const char *name;
1598 
1599   /* * The number of methods with this name.  */
1600 
1601   int length;
1602 
1603   /* * The list of methods.  */
1604 
1605   struct fn_field *fn_fields;
1606 };
1607 
1608 
1609 
1610 struct fn_field
1611 {
1612   /* * If is_stub is clear, this is the mangled name which we can look
1613      up to find the address of the method (FIXME: it would be cleaner
1614      to have a pointer to the struct symbol here instead).
1615 
1616      If is_stub is set, this is the portion of the mangled name which
1617      specifies the arguments.  For example, "ii", if there are two int
1618      arguments, or "" if there are no arguments.  See gdb_mangle_name
1619      for the conversion from this format to the one used if is_stub is
1620      clear.  */
1621 
1622   const char *physname;
1623 
1624   /* * The function type for the method.
1625 
1626      (This comment used to say "The return value of the method", but
1627      that's wrong.  The function type is expected here, i.e. something
1628      with TYPE_CODE_METHOD, and *not* the return-value type).  */
1629 
1630   struct type *type;
1631 
1632   /* * For virtual functions.  First baseclass that defines this
1633      virtual function.  */
1634 
1635   struct type *fcontext;
1636 
1637   /* Attributes.  */
1638 
1639   unsigned int is_const:1;
1640   unsigned int is_volatile:1;
1641   unsigned int is_artificial:1;
1642 
1643   /* * A stub method only has some fields valid (but they are enough
1644      to reconstruct the rest of the fields).  */
1645 
1646   unsigned int is_stub:1;
1647 
1648   /* * True if this function is a constructor, false otherwise.  */
1649 
1650   unsigned int is_constructor : 1;
1651 
1652   /* * True if this function is deleted, false otherwise.  */
1653 
1654   unsigned int is_deleted : 1;
1655 
1656   /* * DW_AT_defaulted attribute for this function.  The value is one
1657      of the DW_DEFAULTED constants.  */
1658 
1659   ENUM_BITFIELD (dwarf_defaulted_attribute) defaulted : 2;
1660 
1661   /* Accessibility of the field.  */
1662   enum accessibility accessibility;
1663 
1664   /* * Index into that baseclass's virtual function table, minus 2;
1665      else if static: VOFFSET_STATIC; else: 0.  */
1666 
1667   unsigned int voffset:16;
1668 
1669 #define VOFFSET_STATIC 1
1670 
1671 };
1672 
1673 struct decl_field
1674 {
1675   /* * Unqualified name to be prefixed by owning class qualified
1676      name.  */
1677 
1678   const char *name;
1679 
1680   /* * Type this typedef named NAME represents.  */
1681 
1682   struct type *type;
1683 
1684   /* Accessibility of the field.  */
1685   enum accessibility accessibility;
1686 };
1687 
1688 /* * C++ language-specific information for TYPE_CODE_STRUCT and
1689    TYPE_CODE_UNION nodes.  */
1690 
1691 struct cplus_struct_type
1692   {
1693     /* * Number of base classes this type derives from.  The
1694        baseclasses are stored in the first N_BASECLASSES fields
1695        (i.e. the `fields' field of the struct type).  The only fields
1696        of struct field that are used are: type, name, loc.bitpos.  */
1697 
1698     short n_baseclasses;
1699 
1700     /* * Field number of the virtual function table pointer in VPTR_BASETYPE.
1701        All access to this field must be through TYPE_VPTR_FIELDNO as one
1702        thing it does is check whether the field has been initialized.
1703        Initially TYPE_RAW_CPLUS_SPECIFIC has the value of cplus_struct_default,
1704        which for portability reasons doesn't initialize this field.
1705        TYPE_VPTR_FIELDNO returns -1 for this case.
1706 
1707        If -1, we were unable to find the virtual function table pointer in
1708        initial symbol reading, and get_vptr_fieldno should be called to find
1709        it if possible.  get_vptr_fieldno will update this field if possible.
1710        Otherwise the value is left at -1.
1711 
1712        Unused if this type does not have virtual functions.  */
1713 
1714     short vptr_fieldno;
1715 
1716     /* * Number of methods with unique names.  All overloaded methods
1717        with the same name count only once.  */
1718 
1719     short nfn_fields;
1720 
1721     /* * Number of template arguments.  */
1722 
1723     unsigned short n_template_arguments;
1724 
1725     /* * One if this struct is a dynamic class, as defined by the
1726        Itanium C++ ABI: if it requires a virtual table pointer,
1727        because it or any of its base classes have one or more virtual
1728        member functions or virtual base classes.  Minus one if not
1729        dynamic.  Zero if not yet computed.  */
1730 
1731     int is_dynamic : 2;
1732 
1733     /* * The calling convention for this type, fetched from the
1734        DW_AT_calling_convention attribute.  The value is one of the
1735        DW_CC constants.  */
1736 
1737     ENUM_BITFIELD (dwarf_calling_convention) calling_convention : 8;
1738 
1739     /* * The base class which defined the virtual function table pointer.  */
1740 
1741     struct type *vptr_basetype;
1742 
1743     /* * For classes, structures, and unions, a description of each
1744        field, which consists of an overloaded name, followed by the
1745        types of arguments that the method expects, and then the name
1746        after it has been renamed to make it distinct.
1747 
1748        fn_fieldlists points to an array of nfn_fields of these.  */
1749 
1750     struct fn_fieldlist *fn_fieldlists;
1751 
1752     /* * typedefs defined inside this class.  typedef_field points to
1753        an array of typedef_field_count elements.  */
1754 
1755     struct decl_field *typedef_field;
1756 
1757     unsigned typedef_field_count;
1758 
1759     /* * The nested types defined by this type.  nested_types points to
1760        an array of nested_types_count elements.  */
1761 
1762     struct decl_field *nested_types;
1763 
1764     unsigned nested_types_count;
1765 
1766     /* * The template arguments.  This is an array with
1767        N_TEMPLATE_ARGUMENTS elements.  This is NULL for non-template
1768        classes.  */
1769 
1770     struct symbol **template_arguments;
1771   };
1772 
1773 /* * Struct used to store conversion rankings.  */
1774 
1775 struct rank
1776   {
1777     short rank;
1778 
1779     /* * When two conversions are of the same type and therefore have
1780        the same rank, subrank is used to differentiate the two.
1781 
1782        Eg: Two derived-class-pointer to base-class-pointer conversions
1783        would both have base pointer conversion rank, but the
1784        conversion with the shorter distance to the ancestor is
1785        preferable.  'subrank' would be used to reflect that.  */
1786 
1787     short subrank;
1788   };
1789 
1790 /* * Used for ranking a function for overload resolution.  */
1791 
1792 typedef std::vector<rank> badness_vector;
1793 
1794 /* * GNAT Ada-specific information for various Ada types.  */
1795 
1796 struct gnat_aux_type
1797   {
1798     /* * Parallel type used to encode information about dynamic types
1799        used in Ada (such as variant records, variable-size array,
1800        etc).  */
1801     struct type* descriptive_type;
1802   };
1803 
1804 /* * For TYPE_CODE_FUNC and TYPE_CODE_METHOD types.  */
1805 
1806 struct func_type
1807   {
1808     /* * The calling convention for targets supporting multiple ABIs.
1809        Right now this is only fetched from the Dwarf-2
1810        DW_AT_calling_convention attribute.  The value is one of the
1811        DW_CC constants.  */
1812 
1813     ENUM_BITFIELD (dwarf_calling_convention) calling_convention : 8;
1814 
1815     /* * Whether this function normally returns to its caller.  It is
1816        set from the DW_AT_noreturn attribute if set on the
1817        DW_TAG_subprogram.  */
1818 
1819     unsigned int is_noreturn : 1;
1820 
1821     /* * Only those DW_TAG_call_site's in this function that have
1822        DW_AT_call_tail_call set are linked in this list.  Function
1823        without its tail call list complete
1824        (DW_AT_call_all_tail_calls or its superset
1825        DW_AT_call_all_calls) has TAIL_CALL_LIST NULL, even if some
1826        DW_TAG_call_site's exist in such function. */
1827 
1828     struct call_site *tail_call_list;
1829 
1830     /* * For method types (TYPE_CODE_METHOD), the aggregate type that
1831        contains the method.  */
1832 
1833     struct type *self_type;
1834   };
1835 
1836 /* The type-specific info for TYPE_CODE_FIXED_POINT types.  */
1837 
1838 struct fixed_point_type_info
1839 {
1840   /* The fixed point type's scaling factor.  */
1841   gdb_mpq scaling_factor;
1842 };
1843 
1844 /* * The default value of TYPE_CPLUS_SPECIFIC(T) points to this shared
1845    static structure.  */
1846 
1847 extern const struct cplus_struct_type cplus_struct_default;
1848 
1849 extern void allocate_cplus_struct_type (struct type *);
1850 
1851 #define INIT_CPLUS_SPECIFIC(type) \
1852   (TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_CPLUS_STUFF, \
1853    TYPE_RAW_CPLUS_SPECIFIC (type) = (struct cplus_struct_type*) \
1854    &cplus_struct_default)
1855 
1856 #define ALLOCATE_CPLUS_STRUCT_TYPE(type) allocate_cplus_struct_type (type)
1857 
1858 #define HAVE_CPLUS_STRUCT(type) \
1859   (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_CPLUS_STUFF \
1860    && TYPE_RAW_CPLUS_SPECIFIC (type) !=  &cplus_struct_default)
1861 
1862 #define INIT_NONE_SPECIFIC(type) \
1863   (TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_NONE, \
1864    TYPE_MAIN_TYPE (type)->type_specific = {})
1865 
1866 extern const struct gnat_aux_type gnat_aux_default;
1867 
1868 extern void allocate_gnat_aux_type (struct type *);
1869 
1870 #define INIT_GNAT_SPECIFIC(type) \
1871   (TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_GNAT_STUFF, \
1872    TYPE_GNAT_SPECIFIC (type) = (struct gnat_aux_type *) &gnat_aux_default)
1873 #define ALLOCATE_GNAT_AUX_TYPE(type) allocate_gnat_aux_type (type)
1874 /* * A macro that returns non-zero if the type-specific data should be
1875    read as "gnat-stuff".  */
1876 #define HAVE_GNAT_AUX_INFO(type) \
1877   (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_GNAT_STUFF)
1878 
1879 /* * True if TYPE is known to be an Ada type of some kind.  */
1880 #define ADA_TYPE_P(type)                                              \
1881   (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_GNAT_STUFF   \
1882     || (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_NONE    \
1883           && (type)->is_fixed_instance ()))
1884 
1885 #define INIT_FUNC_SPECIFIC(type)                                                       \
1886   (TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_FUNC,                                    \
1887    TYPE_MAIN_TYPE (type)->type_specific.func_stuff = (struct func_type *)      \
1888      TYPE_ZALLOC (type,                                                                          \
1889                       sizeof (*TYPE_MAIN_TYPE (type)->type_specific.func_stuff)))
1890 
1891 /* "struct fixed_point_type_info" has a field that has a destructor.
1892    See allocate_fixed_point_type_info to understand how this is
1893    handled.  */
1894 #define INIT_FIXED_POINT_SPECIFIC(type) \
1895   (TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_FIXED_POINT, \
1896    allocate_fixed_point_type_info (type))
1897 
1898 #define TYPE_MAIN_TYPE(thistype) (thistype)->main_type
1899 #define TYPE_POINTER_TYPE(thistype) (thistype)->pointer_type
1900 #define TYPE_REFERENCE_TYPE(thistype) (thistype)->reference_type
1901 #define TYPE_RVALUE_REFERENCE_TYPE(thistype) (thistype)->rvalue_reference_type
1902 #define TYPE_CHAIN(thistype) (thistype)->chain
1903 
1904 /* * Return the alignment of the type in target addressable memory
1905    units, or 0 if no alignment was specified.  */
1906 #define TYPE_RAW_ALIGN(thistype) type_raw_align (thistype)
1907 
1908 /* * Return the alignment of the type in target addressable memory
1909    units, or 0 if no alignment was specified.  */
1910 extern unsigned type_raw_align (struct type *);
1911 
1912 /* * Return the alignment of the type in target addressable memory
1913    units.  Return 0 if the alignment cannot be determined; but note
1914    that this makes an effort to compute the alignment even it it was
1915    not specified in the debug info.  */
1916 extern unsigned type_align (struct type *);
1917 
1918 /* * Set the alignment of the type.  The alignment must be a power of
1919    2.  Returns false if the given value does not fit in the available
1920    space in struct type.  */
1921 extern bool set_type_align (struct type *, ULONGEST);
1922 
1923 /* Property accessors for the type data location.  */
1924 #define TYPE_DATA_LOCATION(thistype) \
1925   ((thistype)->dyn_prop (DYN_PROP_DATA_LOCATION))
1926 #define TYPE_DATA_LOCATION_BATON(thistype) \
1927   TYPE_DATA_LOCATION (thistype)->data.baton
1928 #define TYPE_DATA_LOCATION_ADDR(thistype) \
1929   (TYPE_DATA_LOCATION (thistype)->const_val ())
1930 #define TYPE_DATA_LOCATION_KIND(thistype) \
1931   (TYPE_DATA_LOCATION (thistype)->kind ())
1932 #define TYPE_DYNAMIC_LENGTH(thistype) \
1933   ((thistype)->dyn_prop (DYN_PROP_BYTE_SIZE))
1934 
1935 /* Property accessors for the type allocated/associated.  */
1936 #define TYPE_ALLOCATED_PROP(thistype) \
1937   ((thistype)->dyn_prop (DYN_PROP_ALLOCATED))
1938 #define TYPE_ASSOCIATED_PROP(thistype) \
1939   ((thistype)->dyn_prop (DYN_PROP_ASSOCIATED))
1940 #define TYPE_RANK_PROP(thistype) \
1941   ((thistype)->dyn_prop (DYN_PROP_RANK))
1942 
1943 /* C++ */
1944 
1945 #define TYPE_SELF_TYPE(thistype) internal_type_self_type (thistype)
1946 /* Do not call this, use TYPE_SELF_TYPE.  */
1947 extern struct type *internal_type_self_type (struct type *);
1948 extern void set_type_self_type (struct type *, struct type *);
1949 
1950 extern int internal_type_vptr_fieldno (struct type *);
1951 extern void set_type_vptr_fieldno (struct type *, int);
1952 extern struct type *internal_type_vptr_basetype (struct type *);
1953 extern void set_type_vptr_basetype (struct type *, struct type *);
1954 #define TYPE_VPTR_FIELDNO(thistype) internal_type_vptr_fieldno (thistype)
1955 #define TYPE_VPTR_BASETYPE(thistype) internal_type_vptr_basetype (thistype)
1956 
1957 #define TYPE_NFN_FIELDS(thistype) TYPE_CPLUS_SPECIFIC(thistype)->nfn_fields
1958 #define TYPE_SPECIFIC_FIELD(thistype) \
1959   TYPE_MAIN_TYPE(thistype)->type_specific_field
1960 /* We need this tap-dance with the TYPE_RAW_SPECIFIC because of the case
1961    where we're trying to print an Ada array using the C language.
1962    In that case, there is no "cplus_stuff", but the C language assumes
1963    that there is.  What we do, in that case, is pretend that there is
1964    an implicit one which is the default cplus stuff.  */
1965 #define TYPE_CPLUS_SPECIFIC(thistype) \
1966    (!HAVE_CPLUS_STRUCT(thistype) \
1967     ? (struct cplus_struct_type*)&cplus_struct_default \
1968     : TYPE_RAW_CPLUS_SPECIFIC(thistype))
1969 #define TYPE_RAW_CPLUS_SPECIFIC(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.cplus_stuff
1970 #define TYPE_CPLUS_CALLING_CONVENTION(thistype) \
1971   TYPE_MAIN_TYPE(thistype)->type_specific.cplus_stuff->calling_convention
1972 #define TYPE_FLOATFORMAT(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.floatformat
1973 #define TYPE_GNAT_SPECIFIC(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.gnat_stuff
1974 #define TYPE_DESCRIPTIVE_TYPE(thistype) TYPE_GNAT_SPECIFIC(thistype)->descriptive_type
1975 #define TYPE_CALLING_CONVENTION(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.func_stuff->calling_convention
1976 #define TYPE_NO_RETURN(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.func_stuff->is_noreturn
1977 #define TYPE_TAIL_CALL_LIST(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.func_stuff->tail_call_list
1978 #define TYPE_BASECLASS(thistype,index) ((thistype)->field (index).type ())
1979 #define TYPE_N_BASECLASSES(thistype) TYPE_CPLUS_SPECIFIC(thistype)->n_baseclasses
1980 #define TYPE_BASECLASS_NAME(thistype,index) (thistype->field (index).name ())
1981 #define TYPE_BASECLASS_BITPOS(thistype,index) (thistype->field (index).loc_bitpos ())
1982 #define BASETYPE_VIA_PUBLIC(thistype, index) \
1983   ((thistype)->field (index).is_public ())
1984 #define TYPE_CPLUS_DYNAMIC(thistype) TYPE_CPLUS_SPECIFIC (thistype)->is_dynamic
1985 
1986 #define BASETYPE_VIA_VIRTUAL(thistype, index) \
1987   ((thistype)->field (index).is_virtual ())
1988 
1989 #define TYPE_FN_FIELDLISTS(thistype) TYPE_CPLUS_SPECIFIC(thistype)->fn_fieldlists
1990 #define TYPE_FN_FIELDLIST(thistype, n) TYPE_CPLUS_SPECIFIC(thistype)->fn_fieldlists[n]
1991 #define TYPE_FN_FIELDLIST1(thistype, n) TYPE_CPLUS_SPECIFIC(thistype)->fn_fieldlists[n].fn_fields
1992 #define TYPE_FN_FIELDLIST_NAME(thistype, n) TYPE_CPLUS_SPECIFIC(thistype)->fn_fieldlists[n].name
1993 #define TYPE_FN_FIELDLIST_LENGTH(thistype, n) TYPE_CPLUS_SPECIFIC(thistype)->fn_fieldlists[n].length
1994 
1995 #define TYPE_N_TEMPLATE_ARGUMENTS(thistype) \
1996   TYPE_CPLUS_SPECIFIC (thistype)->n_template_arguments
1997 #define TYPE_TEMPLATE_ARGUMENTS(thistype) \
1998   TYPE_CPLUS_SPECIFIC (thistype)->template_arguments
1999 #define TYPE_TEMPLATE_ARGUMENT(thistype, n) \
2000   TYPE_CPLUS_SPECIFIC (thistype)->template_arguments[n]
2001 
2002 #define TYPE_FN_FIELD(thisfn, n) (thisfn)[n]
2003 #define TYPE_FN_FIELD_PHYSNAME(thisfn, n) (thisfn)[n].physname
2004 #define TYPE_FN_FIELD_TYPE(thisfn, n) (thisfn)[n].type
2005 #define TYPE_FN_FIELD_ARGS(thisfn, n) (((thisfn)[n].type)->fields ())
2006 #define TYPE_FN_FIELD_CONST(thisfn, n) ((thisfn)[n].is_const)
2007 #define TYPE_FN_FIELD_VOLATILE(thisfn, n) ((thisfn)[n].is_volatile)
2008 #define TYPE_FN_FIELD_PRIVATE(thisfn, n) \
2009   ((thisfn)[n].accessibility == accessibility::PRIVATE)
2010 #define TYPE_FN_FIELD_PROTECTED(thisfn, n) \
2011   ((thisfn)[n].accessibility == accessibility::PROTECTED)
2012 #define TYPE_FN_FIELD_ARTIFICIAL(thisfn, n) ((thisfn)[n].is_artificial)
2013 #define TYPE_FN_FIELD_STUB(thisfn, n) ((thisfn)[n].is_stub)
2014 #define TYPE_FN_FIELD_CONSTRUCTOR(thisfn, n) ((thisfn)[n].is_constructor)
2015 #define TYPE_FN_FIELD_FCONTEXT(thisfn, n) ((thisfn)[n].fcontext)
2016 #define TYPE_FN_FIELD_VOFFSET(thisfn, n) ((thisfn)[n].voffset-2)
2017 #define TYPE_FN_FIELD_VIRTUAL_P(thisfn, n) ((thisfn)[n].voffset > 1)
2018 #define TYPE_FN_FIELD_STATIC_P(thisfn, n) ((thisfn)[n].voffset == VOFFSET_STATIC)
2019 #define TYPE_FN_FIELD_DEFAULTED(thisfn, n) ((thisfn)[n].defaulted)
2020 #define TYPE_FN_FIELD_DELETED(thisfn, n) ((thisfn)[n].is_deleted)
2021 
2022 /* Accessors for typedefs defined by a class.  */
2023 #define TYPE_TYPEDEF_FIELD_ARRAY(thistype) \
2024   TYPE_CPLUS_SPECIFIC (thistype)->typedef_field
2025 #define TYPE_TYPEDEF_FIELD(thistype, n) \
2026   TYPE_CPLUS_SPECIFIC (thistype)->typedef_field[n]
2027 #define TYPE_TYPEDEF_FIELD_NAME(thistype, n) \
2028   TYPE_TYPEDEF_FIELD (thistype, n).name
2029 #define TYPE_TYPEDEF_FIELD_TYPE(thistype, n) \
2030   TYPE_TYPEDEF_FIELD (thistype, n).type
2031 #define TYPE_TYPEDEF_FIELD_COUNT(thistype) \
2032   TYPE_CPLUS_SPECIFIC (thistype)->typedef_field_count
2033 #define TYPE_TYPEDEF_FIELD_PROTECTED(thistype, n) \
2034   (TYPE_TYPEDEF_FIELD (thistype, n).accessibility == accessibility::PROTECTED)
2035 #define TYPE_TYPEDEF_FIELD_PRIVATE(thistype, n)        \
2036   (TYPE_TYPEDEF_FIELD (thistype, n).accessibility == accessibility::PRIVATE)
2037 
2038 #define TYPE_NESTED_TYPES_ARRAY(thistype)         \
2039   TYPE_CPLUS_SPECIFIC (thistype)->nested_types
2040 #define TYPE_NESTED_TYPES_FIELD(thistype, n) \
2041   TYPE_CPLUS_SPECIFIC (thistype)->nested_types[n]
2042 #define TYPE_NESTED_TYPES_FIELD_NAME(thistype, n) \
2043   TYPE_NESTED_TYPES_FIELD (thistype, n).name
2044 #define TYPE_NESTED_TYPES_FIELD_TYPE(thistype, n) \
2045   TYPE_NESTED_TYPES_FIELD (thistype, n).type
2046 #define TYPE_NESTED_TYPES_COUNT(thistype) \
2047   TYPE_CPLUS_SPECIFIC (thistype)->nested_types_count
2048 #define TYPE_NESTED_TYPES_FIELD_PROTECTED(thistype, n) \
2049   (TYPE_NESTED_TYPES_FIELD (thistype, n).accessibility \
2050    == accessibility::PROTECTED)
2051 #define TYPE_NESTED_TYPES_FIELD_PRIVATE(thistype, n)        \
2052   (TYPE_NESTED_TYPES_FIELD (thistype, n).accessibility \
2053    == accessibility::PRIVATE)
2054 
2055 #define TYPE_IS_OPAQUE(thistype) \
2056   ((((thistype)->code () == TYPE_CODE_STRUCT) \
2057     || ((thistype)->code () == TYPE_CODE_UNION)) \
2058    && ((thistype)->num_fields () == 0) \
2059    && (!HAVE_CPLUS_STRUCT (thistype) \
2060        || TYPE_NFN_FIELDS (thistype) == 0) \
2061    && ((thistype)->is_stub () || !(thistype)->stub_is_supported ()))
2062 
2063 /* * A helper macro that returns the name of a type or "unnamed type"
2064    if the type has no name.  */
2065 
2066 #define TYPE_SAFE_NAME(type) \
2067   (type->name () != nullptr ? type->name () : _("<unnamed type>"))
2068 
2069 /* * A helper macro that returns the name of an error type.  If the
2070    type has a name, it is used; otherwise, a default is used.  */
2071 
2072 #define TYPE_ERROR_NAME(type) \
2073   (type->name () ? type->name () : _("<error type>"))
2074 
2075 /* Given TYPE, return its floatformat.  */
2076 const struct floatformat *floatformat_from_type (const struct type *type);
2077 
2078 struct builtin_type
2079 {
2080   /* Integral types.  */
2081 
2082   /* Implicit size/sign (based on the architecture's ABI).  */
2083   struct type *builtin_void = nullptr;
2084   struct type *builtin_char = nullptr;
2085   struct type *builtin_short = nullptr;
2086   struct type *builtin_int = nullptr;
2087   struct type *builtin_long = nullptr;
2088   struct type *builtin_signed_char = nullptr;
2089   struct type *builtin_unsigned_char = nullptr;
2090   struct type *builtin_unsigned_short = nullptr;
2091   struct type *builtin_unsigned_int = nullptr;
2092   struct type *builtin_unsigned_long = nullptr;
2093   struct type *builtin_bfloat16 = nullptr;
2094   struct type *builtin_half = nullptr;
2095   struct type *builtin_float = nullptr;
2096   struct type *builtin_double = nullptr;
2097   struct type *builtin_long_double = nullptr;
2098   struct type *builtin_complex = nullptr;
2099   struct type *builtin_double_complex = nullptr;
2100   struct type *builtin_string = nullptr;
2101   struct type *builtin_bool = nullptr;
2102   struct type *builtin_long_long = nullptr;
2103   struct type *builtin_unsigned_long_long = nullptr;
2104   struct type *builtin_decfloat = nullptr;
2105   struct type *builtin_decdouble = nullptr;
2106   struct type *builtin_declong = nullptr;
2107 
2108   /* "True" character types.
2109       We use these for the '/c' print format, because c_char is just a
2110       one-byte integral type, which languages less laid back than C
2111       will print as ... well, a one-byte integral type.  */
2112   struct type *builtin_true_char = nullptr;
2113   struct type *builtin_true_unsigned_char = nullptr;
2114 
2115   /* Explicit sizes - see C9X <intypes.h> for naming scheme.  The "int0"
2116      is for when an architecture needs to describe a register that has
2117      no size.  */
2118   struct type *builtin_int0 = nullptr;
2119   struct type *builtin_int8 = nullptr;
2120   struct type *builtin_uint8 = nullptr;
2121   struct type *builtin_int16 = nullptr;
2122   struct type *builtin_uint16 = nullptr;
2123   struct type *builtin_int24 = nullptr;
2124   struct type *builtin_uint24 = nullptr;
2125   struct type *builtin_int32 = nullptr;
2126   struct type *builtin_uint32 = nullptr;
2127   struct type *builtin_int64 = nullptr;
2128   struct type *builtin_uint64 = nullptr;
2129   struct type *builtin_int128 = nullptr;
2130   struct type *builtin_uint128 = nullptr;
2131 
2132   /* Wide character types.  */
2133   struct type *builtin_char16 = nullptr;
2134   struct type *builtin_char32 = nullptr;
2135   struct type *builtin_wchar = nullptr;
2136 
2137   /* Pointer types.  */
2138 
2139   /* * `pointer to data' type.  Some target platforms use an implicitly
2140      {sign,zero} -extended 32-bit ABI pointer on a 64-bit ISA.  */
2141   struct type *builtin_data_ptr = nullptr;
2142 
2143   /* * `pointer to function (returning void)' type.  Harvard
2144      architectures mean that ABI function and code pointers are not
2145      interconvertible.  Similarly, since ANSI, C standards have
2146      explicitly said that pointers to functions and pointers to data
2147      are not interconvertible --- that is, you can't cast a function
2148      pointer to void * and back, and expect to get the same value.
2149      However, all function pointer types are interconvertible, so void
2150      (*) () can server as a generic function pointer.  */
2151 
2152   struct type *builtin_func_ptr = nullptr;
2153 
2154   /* * `function returning pointer to function (returning void)' type.
2155      The final void return type is not significant for it.  */
2156 
2157   struct type *builtin_func_func = nullptr;
2158 
2159   /* Special-purpose types.  */
2160 
2161   /* * This type is used to represent a GDB internal function.  */
2162 
2163   struct type *internal_fn = nullptr;
2164 
2165   /* * This type is used to represent an xmethod.  */
2166   struct type *xmethod = nullptr;
2167 
2168   /* * This type is used to represent symbol addresses.  */
2169   struct type *builtin_core_addr = nullptr;
2170 
2171   /* * This type represents a type that was unrecognized in symbol
2172      read-in.  */
2173   struct type *builtin_error = nullptr;
2174 
2175   /* * Types used for symbols with no debug information.  */
2176   struct type *nodebug_text_symbol = nullptr;
2177   struct type *nodebug_text_gnu_ifunc_symbol = nullptr;
2178   struct type *nodebug_got_plt_symbol = nullptr;
2179   struct type *nodebug_data_symbol = nullptr;
2180   struct type *nodebug_unknown_symbol = nullptr;
2181   struct type *nodebug_tls_symbol = nullptr;
2182 };
2183 
2184 /* * Return the type table for the specified architecture.  */
2185 
2186 extern const struct builtin_type *builtin_type (struct gdbarch *gdbarch);
2187 
2188 /* * Return the type table for the specified objfile.  */
2189 
2190 extern const struct builtin_type *builtin_type (struct objfile *objfile);
2191 
2192 /* Explicit floating-point formats.  See "floatformat.h".  */
2193 extern const struct floatformat *floatformats_ieee_half[BFD_ENDIAN_UNKNOWN];
2194 extern const struct floatformat *floatformats_ieee_single[BFD_ENDIAN_UNKNOWN];
2195 extern const struct floatformat *floatformats_ieee_double[BFD_ENDIAN_UNKNOWN];
2196 extern const struct floatformat *floatformats_ieee_quad[BFD_ENDIAN_UNKNOWN];
2197 extern const struct floatformat *floatformats_ieee_double_littlebyte_bigword[BFD_ENDIAN_UNKNOWN];
2198 extern const struct floatformat *floatformats_i387_ext[BFD_ENDIAN_UNKNOWN];
2199 extern const struct floatformat *floatformats_m68881_ext[BFD_ENDIAN_UNKNOWN];
2200 extern const struct floatformat *floatformats_arm_ext[BFD_ENDIAN_UNKNOWN];
2201 extern const struct floatformat *floatformats_ia64_spill[BFD_ENDIAN_UNKNOWN];
2202 extern const struct floatformat *floatformats_vax_f[BFD_ENDIAN_UNKNOWN];
2203 extern const struct floatformat *floatformats_vax_d[BFD_ENDIAN_UNKNOWN];
2204 extern const struct floatformat *floatformats_ibm_long_double[BFD_ENDIAN_UNKNOWN];
2205 extern const struct floatformat *floatformats_bfloat16[BFD_ENDIAN_UNKNOWN];
2206 
2207 /* Allocate space for storing data associated with a particular
2208    type.  We ensure that the space is allocated using the same
2209    mechanism that was used to allocate the space for the type
2210    structure itself.  I.e.  if the type is on an objfile's
2211    objfile_obstack, then the space for data associated with that type
2212    will also be allocated on the objfile_obstack.  If the type is
2213    associated with a gdbarch, then the space for data associated with that
2214    type will also be allocated on the gdbarch_obstack.
2215 
2216    If a type is not associated with neither an objfile or a gdbarch then
2217    you should not use this macro to allocate space for data, instead you
2218    should call xmalloc directly, and ensure the memory is correctly freed
2219    when it is no longer needed.  */
2220 
2221 #define TYPE_ALLOC(t,size)                                              \
2222   (obstack_alloc (((t)->is_objfile_owned ()                             \
2223                        ? &((t)->objfile_owner ()->objfile_obstack)          \
2224                        : gdbarch_obstack ((t)->arch_owner ())),             \
2225                       size))
2226 
2227 
2228 /* See comment on TYPE_ALLOC.  */
2229 
2230 #define TYPE_ZALLOC(t,size) (memset (TYPE_ALLOC (t, size), 0, size))
2231 
2232 /* * This returns the target type (or NULL) of TYPE, also skipping
2233    past typedefs.  */
2234 
2235 extern struct type *get_target_type (struct type *type);
2236 
2237 /* Return the equivalent of TYPE_LENGTH, but in number of target
2238    addressable memory units of the associated gdbarch instead of bytes.  */
2239 
2240 extern unsigned int type_length_units (struct type *type);
2241 
2242 /* An object of this type is passed when allocating certain types.  It
2243    determines where the new type is allocated.  Ultimately a type is
2244    either allocated on a on an objfile obstack or on a gdbarch
2245    obstack.  However, it's also possible to request that a new type be
2246    allocated on the same obstack as some existing type, or that a
2247    "new" type instead overwrite a supplied type object.  */
2248 
2249 class type_allocator
2250 {
2251 public:
2252 
2253   /* Create new types on OBJFILE.  */
type_allocator(objfile * objfile,enum language lang)2254   type_allocator (objfile *objfile, enum language lang)
2255     : m_is_objfile (true),
2256       m_lang (lang)
2257   {
2258     m_data.objfile = objfile;
2259   }
2260 
2261   /* Create new types on GDBARCH.  */
type_allocator(gdbarch * gdbarch)2262   explicit type_allocator (gdbarch *gdbarch)
2263     : m_lang (language_minimal)
2264   {
2265     m_data.gdbarch = gdbarch;
2266   }
2267 
2268   /* This determines whether a passed-in type should be rewritten in
2269      place, or whether it should simply determine where the new type
2270      is created.  */
2271   enum type_allocator_kind
2272   {
2273     /* Allocate on same obstack as existing type.  */
2274     SAME = 0,
2275     /* Smash the existing type.  */
2276     SMASH = 1,
2277   };
2278 
2279   /* Create new types either on the same obstack as TYPE; or if SMASH
2280      is passed, overwrite TYPE.  */
2281   explicit type_allocator (struct type *type,
2282                                  type_allocator_kind kind = SAME)
2283     : m_lang (type->language ())
2284   {
2285     if (kind == SAME)
2286       {
2287           if (type->is_objfile_owned ())
2288             {
2289               m_data.objfile = type->objfile_owner ();
2290               m_is_objfile = true;
2291             }
2292           else
2293             m_data.gdbarch = type->arch_owner ();
2294       }
2295     else
2296       {
2297           m_smash = true;
2298           m_data.type = type;
2299       }
2300   }
2301 
2302   /* Create new types on the same obstack as TYPE.  */
type_allocator(const struct type * type)2303   explicit type_allocator (const struct type *type)
2304     : m_is_objfile (type->is_objfile_owned ()),
2305       m_lang (type->language ())
2306   {
2307     if (type->is_objfile_owned ())
2308       m_data.objfile = type->objfile_owner ();
2309     else
2310       m_data.gdbarch = type->arch_owner ();
2311   }
2312 
2313   /* Create a new type on the desired obstack.  Note that a "new" type
2314      is not created if type-smashing was selected at construction.  */
2315   type *new_type ();
2316 
2317   /* Create a new type on the desired obstack, and fill in its code,
2318      length, and name.  If NAME is non-null, it is copied to the
2319      destination obstack first.  Note that a "new" type is not created
2320      if type-smashing was selected at construction.  */
2321   type *new_type (enum type_code code, int bit, const char *name);
2322 
2323   /* Return the architecture associated with this allocator.  This
2324      comes from whatever object was supplied to the constructor.  */
2325   gdbarch *arch ();
2326 
2327 private:
2328 
2329   /* Where the type should wind up.  */
2330   union
2331   {
2332     struct objfile *objfile;
2333     struct gdbarch *gdbarch;
2334     struct type *type;
2335   } m_data {};
2336 
2337   /* True if this allocator uses the objfile field above.  */
2338   bool m_is_objfile = false;
2339   /* True if this allocator uses the type field above, indicating that
2340      the "allocation" should be done in-place.  */
2341   bool m_smash = false;
2342   /* The language for types created by this allocator.  */
2343   enum language m_lang;
2344 };
2345 
2346 /* Allocate a TYPE_CODE_INT type structure using ALLOC.  BIT is the
2347    type size in bits.  If UNSIGNED_P is non-zero, set the type's
2348    TYPE_UNSIGNED flag.  NAME is the type name.  */
2349 
2350 extern struct type *init_integer_type (type_allocator &alloc, int bit,
2351                                                int unsigned_p, const char *name);
2352 
2353 /* Allocate a TYPE_CODE_CHAR type structure using ALLOC.  BIT is the
2354    type size in bits.  If UNSIGNED_P is non-zero, set the type's
2355    TYPE_UNSIGNED flag.  NAME is the type name.  */
2356 
2357 extern struct type *init_character_type (type_allocator &alloc, int bit,
2358                                                    int unsigned_p, const char *name);
2359 
2360 /* Allocate a TYPE_CODE_BOOL type structure using ALLOC.  BIT is the
2361    type size in bits.  If UNSIGNED_P is non-zero, set the type's
2362    TYPE_UNSIGNED flag.  NAME is the type name.  */
2363 
2364 extern struct type *init_boolean_type (type_allocator &alloc, int bit,
2365                                                int unsigned_p, const char *name);
2366 
2367 /* Allocate a TYPE_CODE_FLT type structure using ALLOC.
2368    BIT is the type size in bits; if BIT equals -1, the size is
2369    determined by the floatformat.  NAME is the type name.  Set the
2370    TYPE_FLOATFORMAT from FLOATFORMATS.  BYTE_ORDER is the byte order
2371    to use.  If it is BFD_ENDIAN_UNKNOWN (the default), then the byte
2372    order of the objfile's architecture is used.  */
2373 
2374 extern struct type *init_float_type
2375      (type_allocator &alloc, int bit, const char *name,
2376       const struct floatformat **floatformats,
2377       enum bfd_endian byte_order = BFD_ENDIAN_UNKNOWN);
2378 
2379 /* Allocate a TYPE_CODE_DECFLOAT type structure using ALLOC.
2380    BIT is the type size in bits.  NAME is the type name.  */
2381 
2382 extern struct type *init_decfloat_type (type_allocator &alloc, int bit,
2383                                                   const char *name);
2384 
2385 extern bool can_create_complex_type (struct type *);
2386 extern struct type *init_complex_type (const char *, struct type *);
2387 
2388 /* Allocate a TYPE_CODE_PTR type structure using ALLOC.
2389    BIT is the pointer type size in bits.  NAME is the type name.
2390    TARGET_TYPE is the pointer target type.  Always sets the pointer type's
2391    TYPE_UNSIGNED flag.  */
2392 
2393 extern struct type *init_pointer_type (type_allocator &alloc, int bit,
2394                                                const char *name,
2395                                                struct type *target_type);
2396 
2397 extern struct type *init_fixed_point_type (type_allocator &, int, int,
2398                                                      const char *);
2399 
2400 /* Helper functions to construct a struct or record type.  An
2401    initially empty type is created using arch_composite_type().
2402    Fields are then added using append_composite_type_field*().  A union
2403    type has its size set to the largest field.  A struct type has each
2404    field packed against the previous.  */
2405 
2406 extern struct type *arch_composite_type (struct gdbarch *gdbarch,
2407                                                    const char *name, enum type_code code);
2408 extern void append_composite_type_field (struct type *t, const char *name,
2409                                                    struct type *field);
2410 extern void append_composite_type_field_aligned (struct type *t,
2411                                                              const char *name,
2412                                                              struct type *field,
2413                                                              int alignment);
2414 struct field *append_composite_type_field_raw (struct type *t, const char *name,
2415                                                          struct type *field);
2416 
2417 /* Helper functions to construct a bit flags type.  An initially empty
2418    type is created using arch_flag_type().  Flags are then added using
2419    append_flag_type_field() and append_flag_type_flag().  */
2420 extern struct type *arch_flags_type (struct gdbarch *gdbarch,
2421                                              const char *name, int bit);
2422 extern void append_flags_type_field (struct type *type,
2423                                              int start_bitpos, int nr_bits,
2424                                              struct type *field_type, const char *name);
2425 extern void append_flags_type_flag (struct type *type, int bitpos,
2426                                             const char *name);
2427 
2428 extern void make_vector_type (struct type *array_type);
2429 extern struct type *init_vector_type (struct type *elt_type, int n);
2430 
2431 extern struct type *lookup_reference_type (struct type *, enum type_code);
2432 extern struct type *lookup_lvalue_reference_type (struct type *);
2433 extern struct type *lookup_rvalue_reference_type (struct type *);
2434 
2435 
2436 extern struct type *make_reference_type (struct type *, struct type **,
2437                                                    enum type_code);
2438 
2439 extern struct type *make_cv_type (int, int, struct type *, struct type **);
2440 
2441 extern struct type *make_restrict_type (struct type *);
2442 
2443 extern struct type *make_unqualified_type (struct type *);
2444 
2445 extern struct type *make_atomic_type (struct type *);
2446 
2447 extern void replace_type (struct type *, struct type *);
2448 
2449 extern type_instance_flags address_space_name_to_type_instance_flags
2450   (struct gdbarch *, const char *);
2451 
2452 extern const char *address_space_type_instance_flags_to_name
2453   (struct gdbarch *, type_instance_flags);
2454 
2455 extern struct type *make_type_with_address_space
2456   (struct type *type, type_instance_flags space_identifier);
2457 
2458 extern struct type *lookup_memberptr_type (struct type *, struct type *);
2459 
2460 extern struct type *lookup_methodptr_type (struct type *);
2461 
2462 extern void smash_to_method_type (struct type *type, struct type *self_type,
2463                                           struct type *to_type, struct field *args,
2464                                           int nargs, int varargs);
2465 
2466 extern void smash_to_memberptr_type (struct type *, struct type *,
2467                                              struct type *);
2468 
2469 extern void smash_to_methodptr_type (struct type *, struct type *);
2470 
2471 extern const char *type_name_or_error (struct type *type);
2472 
2473 struct struct_elt
2474 {
2475   /* The field of the element, or NULL if no element was found.  */
2476   struct field *field;
2477 
2478   /* The bit offset of the element in the parent structure.  */
2479   LONGEST offset;
2480 };
2481 
2482 /* Given a type TYPE, lookup the field and offset of the component named
2483    NAME.
2484 
2485    TYPE can be either a struct or union, or a pointer or reference to
2486    a struct or union.  If it is a pointer or reference, its target
2487    type is automatically used.  Thus '.' and '->' are interchangeable,
2488    as specified for the definitions of the expression element types
2489    STRUCTOP_STRUCT and STRUCTOP_PTR.
2490 
2491    If NOERR is nonzero, the returned structure will have field set to
2492    NULL if there is no component named NAME.
2493 
2494    If the component NAME is a field in an anonymous substructure of
2495    TYPE, the returned offset is a "global" offset relative to TYPE
2496    rather than an offset within the substructure.  */
2497 
2498 extern struct_elt lookup_struct_elt (struct type *, const char *, int);
2499 
2500 /* Given a type TYPE, lookup the type of the component named NAME.
2501 
2502    TYPE can be either a struct or union, or a pointer or reference to
2503    a struct or union.  If it is a pointer or reference, its target
2504    type is automatically used.  Thus '.' and '->' are interchangeable,
2505    as specified for the definitions of the expression element types
2506    STRUCTOP_STRUCT and STRUCTOP_PTR.
2507 
2508    If NOERR is nonzero, return NULL if there is no component named
2509    NAME.  */
2510 
2511 extern struct type *lookup_struct_elt_type (struct type *, const char *, int);
2512 
2513 extern struct type *make_pointer_type (struct type *, struct type **);
2514 
2515 extern struct type *lookup_pointer_type (struct type *);
2516 
2517 extern struct type *make_function_type (struct type *, struct type **);
2518 
2519 extern struct type *lookup_function_type (struct type *);
2520 
2521 extern struct type *lookup_function_type_with_arguments (struct type *,
2522                                                                        int,
2523                                                                        struct type **);
2524 
2525 /* Create a range type using ALLOC.
2526 
2527    Indices will be of type INDEX_TYPE, and will range from LOW_BOUND
2528    to HIGH_BOUND, inclusive.  */
2529 
2530 extern struct type *create_static_range_type (type_allocator &alloc,
2531                                                         struct type *index_type,
2532                                                         LONGEST low_bound,
2533                                                         LONGEST high_bound);
2534 
2535 /* Create an array type using ALLOC.
2536 
2537    Elements will be of type ELEMENT_TYPE, the indices will be of type
2538    RANGE_TYPE.
2539 
2540    BYTE_STRIDE_PROP, when not NULL, provides the array's byte stride.
2541    This byte stride property is added to the resulting array type
2542    as a DYN_PROP_BYTE_STRIDE.  As a consequence, the BYTE_STRIDE_PROP
2543    argument can only be used to create types that are objfile-owned
2544    (see add_dyn_prop), meaning that either this function must be called
2545    with an objfile-owned RESULT_TYPE, or an objfile-owned RANGE_TYPE.
2546 
2547    BIT_STRIDE is taken into account only when BYTE_STRIDE_PROP is NULL.
2548    If BIT_STRIDE is not zero, build a packed array type whose element
2549    size is BIT_STRIDE.  Otherwise, ignore this parameter.  */
2550 
2551 extern struct type *create_array_type_with_stride
2552      (type_allocator &alloc, struct type *element_type,
2553       struct type *range_type, struct dynamic_prop *byte_stride_prop,
2554       unsigned int bit_stride);
2555 
2556 /* Create a range type using ALLOC with a dynamic range from LOW_BOUND
2557    to HIGH_BOUND, inclusive.  INDEX_TYPE is the underlying type.  BIAS
2558    is the bias to be applied when storing or retrieving values of this
2559    type.  */
2560 
2561 extern struct type *create_range_type (type_allocator &alloc,
2562                                                struct type *index_type,
2563                                                const struct dynamic_prop *low_bound,
2564                                                const struct dynamic_prop *high_bound,
2565                                                LONGEST bias);
2566 
2567 /* Like CREATE_RANGE_TYPE but also sets up a stride.  When BYTE_STRIDE_P
2568    is true the value in STRIDE is a byte stride, otherwise STRIDE is a bit
2569    stride.  */
2570 
2571 extern struct type *create_range_type_with_stride
2572   (type_allocator &alloc, struct type *index_type,
2573    const struct dynamic_prop *low_bound,
2574    const struct dynamic_prop *high_bound, LONGEST bias,
2575    const struct dynamic_prop *stride, bool byte_stride_p);
2576 
2577 /* Same as create_array_type_with_stride but with no bit_stride
2578    (BIT_STRIDE = 0), thus building an unpacked array.  */
2579 
2580 extern struct type *create_array_type (type_allocator &alloc,
2581                                                struct type *element_type,
2582                                                struct type *range_type);
2583 
2584 extern struct type *lookup_array_range_type (struct type *, LONGEST, LONGEST);
2585 
2586 /* Create a string type using ALLOC.  String types are similar enough
2587    to array of char types that we can use create_array_type to build
2588    the basic type and then bash it into a string type.
2589 
2590    For fixed length strings, the range type contains 0 as the lower
2591    bound and the length of the string minus one as the upper bound.  */
2592 
2593 extern struct type *create_string_type (type_allocator &alloc,
2594                                                   struct type *string_char_type,
2595                                                   struct type *range_type);
2596 
2597 extern struct type *lookup_string_range_type (struct type *, LONGEST, LONGEST);
2598 
2599 extern struct type *create_set_type (type_allocator &alloc,
2600                                              struct type *domain_type);
2601 
2602 extern struct type *lookup_unsigned_typename (const struct language_defn *,
2603                                                         const char *);
2604 
2605 extern struct type *lookup_signed_typename (const struct language_defn *,
2606                                                       const char *);
2607 
2608 extern ULONGEST get_unsigned_type_max (struct type *);
2609 
2610 extern void get_signed_type_minmax (struct type *, LONGEST *, LONGEST *);
2611 
2612 extern CORE_ADDR get_pointer_type_max (struct type *);
2613 
2614 /* * Resolve all dynamic values of a type e.g. array bounds to static values.
2615    ADDR specifies the location of the variable the type is bound to.
2616    If TYPE has no dynamic properties return TYPE; otherwise a new type with
2617    static properties is returned.
2618 
2619    If FRAME is given, it is used when evaluating dynamic properties.
2620    This can be important when a static link is seen.  If not given,
2621    the selected frame is used.
2622 
2623    For an array type, if the element type is dynamic, then that will
2624    not be resolved.  This is done because each individual element may
2625    have a different type when resolved (depending on the contents of
2626    memory).  In this situation, 'is_dynamic_type' will still return
2627    true for the return value of this function.  */
2628 extern struct type *resolve_dynamic_type
2629   (struct type *type, gdb::array_view<const gdb_byte> valaddr,
2630    CORE_ADDR addr, const frame_info_ptr *frame = nullptr);
2631 
2632 /* * Predicate if the type has dynamic values, which are not resolved yet.
2633    See the caveat in 'resolve_dynamic_type' to understand a scenario
2634    where an apparently-resolved type may still be considered
2635    "dynamic".  */
2636 extern bool is_dynamic_type (struct type *type);
2637 
2638 extern struct type *check_typedef (struct type *);
2639 
2640 extern void check_stub_method_group (struct type *, int);
2641 
2642 extern char *gdb_mangle_name (struct type *, int, int);
2643 
2644 /* Lookup a typedef or primitive type named NAME, visible in lexical block
2645    BLOCK.  If NOERR is nonzero, return zero if NAME is not suitably
2646    defined.
2647 
2648    If this function finds a suitable type then check_typedef is called on
2649    the type, this ensures that if the type being returned is a typedef
2650    then the length of the type will be correct.  The original typedef will
2651    still be returned, not the result of calling check_typedef.  */
2652 
2653 extern struct type *lookup_typename (const struct language_defn *language,
2654                                              const char *name,
2655                                              const struct block *block, int noerr);
2656 
2657 extern struct type *lookup_template_type (const char *, struct type *,
2658                                                     const struct block *);
2659 
2660 extern int get_vptr_fieldno (struct type *, struct type **);
2661 
2662 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type
2663    TYPE.
2664 
2665    Return true if the two bounds are available, false otherwise.  */
2666 
2667 extern bool get_discrete_bounds (struct type *type, LONGEST *lowp,
2668                                          LONGEST *highp);
2669 
2670 /* If TYPE's low bound is a known constant, return it, else return nullopt.  */
2671 
2672 extern std::optional<LONGEST> get_discrete_low_bound (struct type *type);
2673 
2674 /* If TYPE's high bound is a known constant, return it, else return nullopt.  */
2675 
2676 extern std::optional<LONGEST> get_discrete_high_bound (struct type *type);
2677 
2678 /* Assuming TYPE is a simple, non-empty array type, compute its upper
2679    and lower bound.  Save the low bound into LOW_BOUND if not NULL.
2680    Save the high bound into HIGH_BOUND if not NULL.
2681 
2682    Return true if the operation was successful.  Return false otherwise,
2683    in which case the values of LOW_BOUND and HIGH_BOUNDS are unmodified.  */
2684 
2685 extern bool get_array_bounds (struct type *type, LONGEST *low_bound,
2686                                     LONGEST *high_bound);
2687 
2688 extern std::optional<LONGEST> discrete_position (struct type *type,
2689                                                              LONGEST val);
2690 
2691 extern int class_types_same_p (const struct type *, const struct type *);
2692 
2693 extern int is_ancestor (struct type *, struct type *);
2694 
2695 extern int is_public_ancestor (struct type *, struct type *);
2696 
2697 extern int is_unique_ancestor (struct type *, struct value *);
2698 
2699 /* Overload resolution */
2700 
2701 /* * Badness if parameter list length doesn't match arg list length.  */
2702 extern const struct rank LENGTH_MISMATCH_BADNESS;
2703 
2704 /* * Dummy badness value for nonexistent parameter positions.  */
2705 extern const struct rank TOO_FEW_PARAMS_BADNESS;
2706 /* * Badness if no conversion among types.  */
2707 extern const struct rank INCOMPATIBLE_TYPE_BADNESS;
2708 
2709 /* * Badness of an exact match.  */
2710 extern const struct rank EXACT_MATCH_BADNESS;
2711 
2712 /* * Badness of integral promotion.  */
2713 extern const struct rank INTEGER_PROMOTION_BADNESS;
2714 /* * Badness of floating promotion.  */
2715 extern const struct rank FLOAT_PROMOTION_BADNESS;
2716 /* * Badness of converting a derived class pointer
2717    to a base class pointer.  */
2718 extern const struct rank BASE_PTR_CONVERSION_BADNESS;
2719 /* * Badness of integral conversion.  */
2720 extern const struct rank INTEGER_CONVERSION_BADNESS;
2721 /* * Badness of floating conversion.  */
2722 extern const struct rank FLOAT_CONVERSION_BADNESS;
2723 /* * Badness of integer<->floating conversions.  */
2724 extern const struct rank INT_FLOAT_CONVERSION_BADNESS;
2725 /* * Badness of conversion of pointer to void pointer.  */
2726 extern const struct rank VOID_PTR_CONVERSION_BADNESS;
2727 /* * Badness of conversion to boolean.  */
2728 extern const struct rank BOOL_CONVERSION_BADNESS;
2729 /* * Badness of converting derived to base class.  */
2730 extern const struct rank BASE_CONVERSION_BADNESS;
2731 /* * Badness of converting from non-reference to reference.  Subrank
2732    is the type of reference conversion being done.  */
2733 extern const struct rank REFERENCE_CONVERSION_BADNESS;
2734 extern const struct rank REFERENCE_SEE_THROUGH_BADNESS;
2735 /* * Conversion to rvalue reference.  */
2736 #define REFERENCE_CONVERSION_RVALUE 1
2737 /* * Conversion to const lvalue reference.  */
2738 #define REFERENCE_CONVERSION_CONST_LVALUE 2
2739 
2740 /* * Badness of converting integer 0 to NULL pointer.  */
2741 extern const struct rank NULL_POINTER_CONVERSION;
2742 /* * Badness of cv-conversion.  Subrank is a flag describing the conversions
2743    being done.  */
2744 extern const struct rank CV_CONVERSION_BADNESS;
2745 #define CV_CONVERSION_CONST 1
2746 #define CV_CONVERSION_VOLATILE 2
2747 
2748 /* Non-standard conversions allowed by the debugger */
2749 
2750 /* * Converting a pointer to an int is usually OK.  */
2751 extern const struct rank NS_POINTER_CONVERSION_BADNESS;
2752 
2753 /* * Badness of converting a (non-zero) integer constant
2754    to a pointer.  */
2755 extern const struct rank NS_INTEGER_POINTER_CONVERSION_BADNESS;
2756 
2757 extern struct rank sum_ranks (struct rank a, struct rank b);
2758 extern int compare_ranks (struct rank a, struct rank b);
2759 
2760 extern int compare_badness (const badness_vector &,
2761                                   const badness_vector &);
2762 
2763 extern badness_vector rank_function (gdb::array_view<type *> parms,
2764                                              gdb::array_view<value *> args,
2765                                              bool varargs = false);
2766 
2767 extern struct rank rank_one_type (struct type *, struct type *,
2768                                           struct value *);
2769 
2770 extern void recursive_dump_type (struct type *, int);
2771 
2772 /* printcmd.c */
2773 
2774 extern void print_scalar_formatted (const gdb_byte *, struct type *,
2775                                             const struct value_print_options *,
2776                                             int, struct ui_file *);
2777 
2778 extern int can_dereference (struct type *);
2779 
2780 extern int is_integral_type (struct type *);
2781 
2782 extern int is_floating_type (struct type *);
2783 
2784 extern int is_scalar_type (struct type *type);
2785 
2786 extern int is_scalar_type_recursive (struct type *);
2787 
2788 extern int class_or_union_p (const struct type *);
2789 
2790 extern void maintenance_print_type (const char *, int);
2791 
2792 extern htab_up create_copied_types_hash ();
2793 
2794 extern struct type *copy_type_recursive (struct type *type,
2795                                                    htab_t copied_types);
2796 
2797 extern struct type *copy_type (const struct type *type);
2798 
2799 extern bool types_equal (struct type *, struct type *);
2800 
2801 extern bool types_deeply_equal (struct type *, struct type *);
2802 
2803 extern int type_not_allocated (const struct type *type);
2804 
2805 extern int type_not_associated (const struct type *type);
2806 
2807 /* Return True if TYPE is a TYPE_CODE_FIXED_POINT or if TYPE is
2808    a range type whose base type is a TYPE_CODE_FIXED_POINT.  */
2809 extern bool is_fixed_point_type (struct type *type);
2810 
2811 /* Allocate a fixed-point type info for TYPE.  This should only be
2812    called by INIT_FIXED_POINT_SPECIFIC.  */
2813 extern void allocate_fixed_point_type_info (struct type *type);
2814 
2815 /* * When the type includes explicit byte ordering, return that.
2816    Otherwise, the byte ordering from gdbarch_byte_order for
2817    the type's arch is returned.  */
2818 
2819 extern enum bfd_endian type_byte_order (const struct type *type);
2820 
2821 /* A flag to enable printing of debugging information of C++
2822    overloading.  */
2823 
2824 extern unsigned int overload_debug;
2825 
2826 /* Return whether the function type represented by TYPE is marked as unsafe
2827    to call by the debugger.
2828 
2829    This usually indicates that the function does not follow the target's
2830    standard calling convention.  */
2831 
2832 extern bool is_nocall_function (const struct type *type);
2833 
2834 #endif /* GDBTYPES_H */
2835