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