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