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