summaryrefslogtreecommitdiff
path: root/gdb/gdbtypes.h
blob: 9254ec994e3e19805435fabf8325321bf7ef2ffd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763

/* Internal type definitions for GDB.

   Copyright (C) 1992-2023 Free Software Foundation, Inc.

   Contributed by Cygnus Support, using pieces from other GDB modules.

   This file is part of GDB.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

#if !defined (GDBTYPES_H)
#define GDBTYPES_H 1

/* * \page gdbtypes GDB Types

   GDB represents all the different kinds of types in programming
   languages using a common representation defined in gdbtypes.h.

   The main data structure is main_type; it consists of a code (such
   as #TYPE_CODE_ENUM for enumeration types), a number of
   generally-useful fields such as the printable name, and finally a
   field main_type::type_specific that is a union of info specific to
   particular languages or other special cases (such as calling
   convention).

   The available type codes are defined in enum #type_code.  The enum
   includes codes both for types that are common across a variety
   of languages, and for types that are language-specific.

   Most accesses to type fields go through macros such as
   #TYPE_CODE(thistype) and #TYPE_FN_FIELD_CONST(thisfn, n).  These are
   written such that they can be used as both rvalues and lvalues.
 */

#include "hashtab.h"
#include "gdbsupport/array-view.h"
#include "gdbsupport/gdb-hashtab.h"
#include "gdbsupport/gdb_optional.h"
#include "gdbsupport/offset-type.h"
#include "gdbsupport/enum-flags.h"
#include "gdbsupport/underlying.h"
#include "gdbsupport/print-utils.h"
#include "gdbsupport/function-view.h"
#include "dwarf2.h"
#include "gdbsupport/gdb_obstack.h"
#include "gmp-utils.h"

/* Forward declarations for prototypes.  */
struct field;
struct block;
struct value_print_options;
struct language_defn;
struct dwarf2_per_cu_data;
struct dwarf2_per_objfile;
struct dwarf2_property_baton;

/* Some macros for char-based bitfields.  */

#define B_SET(a,x)	((a)[(x)>>3] |= (1 << ((x)&7)))
#define B_CLR(a,x)	((a)[(x)>>3] &= ~(1 << ((x)&7)))
#define B_TST(a,x)	((a)[(x)>>3] & (1 << ((x)&7)))
#define B_TYPE		unsigned char
#define	B_BYTES(x)	( 1 + ((x)>>3) )
#define	B_CLRALL(a,x)	memset ((a), 0, B_BYTES(x))

/* * Different kinds of data types are distinguished by the `code'
   field.  */

enum type_code
  {
    TYPE_CODE_UNDEF = 0,	/**< Not used; catches errors */

#define OP(X) X,
#include "type-codes.def"
#undef OP

  };

/* * Some bits for the type's instance_flags word.  See the macros
   below for documentation on each bit.  */

enum type_instance_flag_value : unsigned
{
  TYPE_INSTANCE_FLAG_CONST = (1 << 0),
  TYPE_INSTANCE_FLAG_VOLATILE = (1 << 1),
  TYPE_INSTANCE_FLAG_CODE_SPACE = (1 << 2),
  TYPE_INSTANCE_FLAG_DATA_SPACE = (1 << 3),
  TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1 = (1 << 4),
  TYPE_INSTANCE_FLAG_ADDRESS_CLASS_2 = (1 << 5),
  TYPE_INSTANCE_FLAG_NOTTEXT = (1 << 6),
  TYPE_INSTANCE_FLAG_RESTRICT = (1 << 7),
  TYPE_INSTANCE_FLAG_ATOMIC = (1 << 8)
};

DEF_ENUM_FLAGS_TYPE (enum type_instance_flag_value, type_instance_flags);

/* * Not textual.  By default, GDB treats all single byte integers as
   characters (or elements of strings) unless this flag is set.  */

#define TYPE_NOTTEXT(t)	(((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_NOTTEXT)

/* * Constant type.  If this is set, the corresponding type has a
   const modifier.  */

#define TYPE_CONST(t) ((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_CONST) != 0)

/* * Volatile type.  If this is set, the corresponding type has a
   volatile modifier.  */

#define TYPE_VOLATILE(t) \
  ((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_VOLATILE) != 0)

/* * Restrict type.  If this is set, the corresponding type has a
   restrict modifier.  */

#define TYPE_RESTRICT(t) \
  ((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_RESTRICT) != 0)

/* * Atomic type.  If this is set, the corresponding type has an
   _Atomic modifier.  */

#define TYPE_ATOMIC(t) \
  ((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_ATOMIC) != 0)

/* * True if this type represents either an lvalue or lvalue reference type.  */

#define TYPE_IS_REFERENCE(t) \
  ((t)->code () == TYPE_CODE_REF || (t)->code () == TYPE_CODE_RVALUE_REF)

/* * True if this type is allocatable.  */
#define TYPE_IS_ALLOCATABLE(t) \
  ((t)->dyn_prop (DYN_PROP_ALLOCATED) != NULL)

/* * True if this type has variant parts.  */
#define TYPE_HAS_VARIANT_PARTS(t) \
  ((t)->dyn_prop (DYN_PROP_VARIANT_PARTS) != nullptr)

/* * True if this type has a dynamic length.  */
#define TYPE_HAS_DYNAMIC_LENGTH(t) \
  ((t)->dyn_prop (DYN_PROP_BYTE_SIZE) != nullptr)

/* * Instruction-space delimited type.  This is for Harvard architectures
   which have separate instruction and data address spaces (and perhaps
   others).

   GDB usually defines a flat address space that is a superset of the
   architecture's two (or more) address spaces, but this is an extension
   of the architecture's model.

   If TYPE_INSTANCE_FLAG_CODE_SPACE is set, an object of the corresponding type
   resides in instruction memory, even if its address (in the extended
   flat address space) does not reflect this.

   Similarly, if TYPE_INSTANCE_FLAG_DATA_SPACE is set, then an object of the
   corresponding type resides in the data memory space, even if
   this is not indicated by its (flat address space) address.

   If neither flag is set, the default space for functions / methods
   is instruction space, and for data objects is data memory.  */

#define TYPE_CODE_SPACE(t) \
  ((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_CODE_SPACE) != 0)

#define TYPE_DATA_SPACE(t) \
  ((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_DATA_SPACE) != 0)

/* * Address class flags.  Some environments provide for pointers
   whose size is different from that of a normal pointer or address
   types where the bits are interpreted differently than normal
   addresses.  The TYPE_INSTANCE_FLAG_ADDRESS_CLASS_n flags may be used in
   target specific ways to represent these different types of address
   classes.  */

#define TYPE_ADDRESS_CLASS_1(t) (((t)->instance_flags ()) \
				 & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1)
#define TYPE_ADDRESS_CLASS_2(t) (((t)->instance_flags ()) \
				 & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_2)
#define TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL \
  (TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1 | TYPE_INSTANCE_FLAG_ADDRESS_CLASS_2)
#define TYPE_ADDRESS_CLASS_ALL(t) (((t)->instance_flags ()) \
				   & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)

/* * Information about a single discriminant.  */

struct discriminant_range
{
  /* * The range of values for the variant.  This is an inclusive
     range.  */
  ULONGEST low, high;

  /* * Return true if VALUE is contained in this range.  IS_UNSIGNED
     is true if this should be an unsigned comparison; false for
     signed.  */
  bool contains (ULONGEST value, bool is_unsigned) const
  {
    if (is_unsigned)
      return value >= low && value <= high;
    LONGEST valuel = (LONGEST) value;
    return valuel >= (LONGEST) low && valuel <= (LONGEST) high;
  }
};

struct variant_part;

/* * A single variant.  A variant has a list of discriminant values.
   When the discriminator matches one of these, the variant is
   enabled.  Each variant controls zero or more fields; and may also
   control other variant parts as well.  This struct corresponds to
   DW_TAG_variant in DWARF.  */

struct variant : allocate_on_obstack
{
  /* * The discriminant ranges for this variant.  */
  gdb::array_view<discriminant_range> discriminants;

  /* * The fields controlled by this variant.  This is inclusive on
     the low end and exclusive on the high end.  A variant may not
     control any fields, in which case the two values will be equal.
     These are indexes into the type's array of fields.  */
  int first_field;
  int last_field;

  /* * Variant parts controlled by this variant.  */
  gdb::array_view<variant_part> parts;

  /* * Return true if this is the default variant.  The default
     variant can be recognized because it has no associated
     discriminants.  */
  bool is_default () const
  {
    return discriminants.empty ();
  }

  /* * Return true if this variant matches VALUE.  IS_UNSIGNED is true
     if this should be an unsigned comparison; false for signed.  */
  bool matches (ULONGEST value, bool is_unsigned) const;
};

/* * A variant part.  Each variant part has an optional discriminant
   and holds an array of variants.  This struct corresponds to
   DW_TAG_variant_part in DWARF.  */

struct variant_part : allocate_on_obstack
{
  /* * The index of the discriminant field in the outer type.  This is
     an index into the type's array of fields.  If this is -1, there
     is no discriminant, and only the default variant can be
     considered to be selected.  */
  int discriminant_index;

  /* * True if this discriminant is unsigned; false if signed.  This
     comes from the type of the discriminant.  */
  bool is_unsigned;

  /* * The variants that are controlled by this variant part.  Note
     that these will always be sorted by field number.  */
  gdb::array_view<variant> variants;
};


enum dynamic_prop_kind
{
  PROP_UNDEFINED, /* Not defined.  */
  PROP_CONST,     /* Constant.  */
  PROP_ADDR_OFFSET, /* Address offset.  */
  PROP_LOCEXPR,   /* Location expression.  */
  PROP_LOCLIST,    /* Location list.  */
  PROP_VARIANT_PARTS, /* Variant parts.  */
  PROP_TYPE,	   /* Type.  */
  PROP_VARIABLE_NAME, /* Variable name.  */
};

union dynamic_prop_data
{
  /* Storage for constant property.  */

  LONGEST const_val;

  /* Storage for dynamic property.  */

  const dwarf2_property_baton *baton;

  /* Storage of variant parts for a type.  A type with variant parts
     has all its fields "linearized" -- stored in a single field
     array, just as if they had all been declared that way.  The
     variant parts are attached via a dynamic property, and then are
     used to control which fields end up in the final type during
     dynamic type resolution.  */

  const gdb::array_view<variant_part> *variant_parts;

  /* Once a variant type is resolved, we may want to be able to go
     from the resolved type to the original type.  In this case we
     rewrite the property's kind and set this field.  */

  struct type *original_type;

  /* Name of a variable to look up; the variable holds the value of
     this property.  */

  const char *variable_name;
};

/* * Used to store a dynamic property.  */

struct dynamic_prop
{
  dynamic_prop_kind kind () const
  {
    return m_kind;
  }

  void set_undefined ()
  {
    m_kind = PROP_UNDEFINED;
  }

  LONGEST const_val () const
  {
    gdb_assert (m_kind == PROP_CONST);

    return m_data.const_val;
  }

  void set_const_val (LONGEST const_val)
  {
    m_kind = PROP_CONST;
    m_data.const_val = const_val;
  }

  const dwarf2_property_baton *baton () const
  {
    gdb_assert (m_kind == PROP_LOCEXPR
		|| m_kind == PROP_LOCLIST
		|| m_kind == PROP_ADDR_OFFSET);

    return m_data.baton;
  }

  void set_locexpr (const dwarf2_property_baton *baton)
  {
    m_kind = PROP_LOCEXPR;
    m_data.baton = baton;
  }

  void set_loclist (const dwarf2_property_baton *baton)
  {
    m_kind = PROP_LOCLIST;
    m_data.baton = baton;
  }

  void set_addr_offset (const dwarf2_property_baton *baton)
  {
    m_kind = PROP_ADDR_OFFSET;
    m_data.baton = baton;
  }

  const gdb::array_view<variant_part> *variant_parts () const
  {
    gdb_assert (m_kind == PROP_VARIANT_PARTS);

    return m_data.variant_parts;
  }

  void set_variant_parts (gdb::array_view<variant_part> *variant_parts)
  {
    m_kind = PROP_VARIANT_PARTS;
    m_data.variant_parts = variant_parts;
  }

  struct type *original_type () const
  {
    gdb_assert (m_kind == PROP_TYPE);

    return m_data.original_type;
  }

  void set_original_type (struct type *original_type)
  {
    m_kind = PROP_TYPE;
    m_data.original_type = original_type;
  }

  /* Return the name of the variable that holds this property's value.
     Only valid for PROP_VARIABLE_NAME.  */
  const char *variable_name () const
  {
    gdb_assert (m_kind == PROP_VARIABLE_NAME);
    return m_data.variable_name;
  }

  /* Set the name of the variable that holds this property's value,
     and set this property to be of kind PROP_VARIABLE_NAME.  */
  void set_variable_name (const char *name)
  {
    m_kind = PROP_VARIABLE_NAME;
    m_data.variable_name = name;
  }

  /* Determine which field of the union dynamic_prop.data is used.  */
  enum dynamic_prop_kind m_kind;

  /* Storage for dynamic or static value.  */
  union dynamic_prop_data m_data;
};

/* Compare two dynamic_prop objects for equality.  dynamic_prop
   instances are equal iff they have the same type and storage.  */
extern bool operator== (const dynamic_prop &l, const dynamic_prop &r);

/* Compare two dynamic_prop objects for inequality.  */
static inline bool operator!= (const dynamic_prop &l, const dynamic_prop &r)
{
  return !(l == r);
}

/* * Define a type's dynamic property node kind.  */
enum dynamic_prop_node_kind
{
  /* A property providing a type's data location.
     Evaluating this field yields to the location of an object's data.  */
  DYN_PROP_DATA_LOCATION,

  /* A property representing DW_AT_allocated.  The presence of this attribute
     indicates that the object of the type can be allocated/deallocated.  */
  DYN_PROP_ALLOCATED,

  /* A property representing DW_AT_associated.  The presence of this attribute
     indicated that the object of the type can be associated.  */
  DYN_PROP_ASSOCIATED,

  /* A property providing an array's byte stride.  */
  DYN_PROP_BYTE_STRIDE,

  /* A property holding variant parts.  */
  DYN_PROP_VARIANT_PARTS,

  /* A property representing DW_AT_rank. The presence of this attribute
     indicates that the object is of assumed rank array type.  */
  DYN_PROP_RANK,

  /* A property holding the size of the type.  */
  DYN_PROP_BYTE_SIZE,
};

/* * List for dynamic type attributes.  */
struct dynamic_prop_list
{
  /* The kind of dynamic prop in this node.  */
  enum dynamic_prop_node_kind prop_kind;

  /* The dynamic property itself.  */
  struct dynamic_prop prop;

  /* A pointer to the next dynamic property.  */
  struct dynamic_prop_list *next;
};

/* * Determine which field of the union main_type.fields[x].loc is
   used.  */

enum field_loc_kind
  {
    FIELD_LOC_KIND_BITPOS,	/**< bitpos */
    FIELD_LOC_KIND_ENUMVAL,	/**< enumval */
    FIELD_LOC_KIND_PHYSADDR,	/**< physaddr */
    FIELD_LOC_KIND_PHYSNAME,	/**< physname */
    FIELD_LOC_KIND_DWARF_BLOCK	/**< dwarf_block */
  };

/* * A discriminant to determine which field in the
   main_type.type_specific union is being used, if any.

   For types such as TYPE_CODE_FLT, the use of this
   discriminant is really redundant, as we know from the type code
   which field is going to be used.  As such, it would be possible to
   reduce the size of this enum in order to save a bit or two for
   other fields of struct main_type.  But, since we still have extra
   room , and for the sake of clarity and consistency, we treat all fields
   of the union the same way.  */

enum type_specific_kind
{
  TYPE_SPECIFIC_NONE,
  TYPE_SPECIFIC_CPLUS_STUFF,
  TYPE_SPECIFIC_GNAT_STUFF,
  TYPE_SPECIFIC_FLOATFORMAT,
  /* Note: This is used by TYPE_CODE_FUNC and TYPE_CODE_METHOD.  */
  TYPE_SPECIFIC_FUNC,
  TYPE_SPECIFIC_SELF_TYPE,
  TYPE_SPECIFIC_INT,
  TYPE_SPECIFIC_FIXED_POINT,
};

union type_owner
{
  struct objfile *objfile;
  struct gdbarch *gdbarch;
};

union field_location
{
  /* * Position of this field, counting in bits from start of
     containing structure.  For big-endian targets, it is the bit
     offset to the MSB.  For little-endian targets, it is the bit
     offset to the LSB.  */

  LONGEST bitpos;

  /* * Enum value.  */
  LONGEST enumval;

  /* * For a static field, if TYPE_FIELD_STATIC_HAS_ADDR then
     physaddr is the location (in the target) of the static
     field.  Otherwise, physname is the mangled label of the
     static field.  */

  CORE_ADDR physaddr;
  const char *physname;

  /* * The field location can be computed by evaluating the
     following DWARF block.  Its DATA is allocated on
     objfile_obstack - no CU load is needed to access it.  */

  struct dwarf2_locexpr_baton *dwarf_block;
};

struct field
{
  struct type *type () const
  {
    return this->m_type;
  }

  void set_type (struct type *type)
  {
    this->m_type = type;
  }

  const char *name () const
  {
    return m_name;
  }

  void set_name (const char *name)
  {
    m_name = name;
  }

  /* Return true if this field is static; false if not.  */
  bool is_static () const
  {
    /* "static" fields are the fields whose location is not relative
       to the address of the enclosing struct.  It would be nice to
       have a dedicated flag that would be set for static fields when
       the type is being created.  But in practice, checking the field
       loc_kind should give us an accurate answer.  */
    return (m_loc_kind == FIELD_LOC_KIND_PHYSNAME
	    || m_loc_kind == FIELD_LOC_KIND_PHYSADDR);
  }

  /* Location getters / setters.  */

  field_loc_kind loc_kind () const
  {
    return m_loc_kind;
  }

  LONGEST loc_bitpos () const
  {
    gdb_assert (m_loc_kind == FIELD_LOC_KIND_BITPOS);
    return m_loc.bitpos;
  }

  void set_loc_bitpos (LONGEST bitpos)
  {
    m_loc_kind = FIELD_LOC_KIND_BITPOS;
    m_loc.bitpos = bitpos;
  }

  LONGEST loc_enumval () const
  {
    gdb_assert (m_loc_kind == FIELD_LOC_KIND_ENUMVAL);
    return m_loc.enumval;
  }

  void set_loc_enumval (LONGEST enumval)
  {
    m_loc_kind = FIELD_LOC_KIND_ENUMVAL;
    m_loc.enumval = enumval;
  }

  CORE_ADDR loc_physaddr () const
  {
    gdb_assert (m_loc_kind == FIELD_LOC_KIND_PHYSADDR);
    return m_loc.physaddr;
  }

  void set_loc_physaddr (CORE_ADDR physaddr)
  {
    m_loc_kind = FIELD_LOC_KIND_PHYSADDR;
    m_loc.physaddr = physaddr;
  }

  const char *loc_physname () const
  {
    gdb_assert (m_loc_kind == FIELD_LOC_KIND_PHYSNAME);
    return m_loc.physname;
  }

  void set_loc_physname (const char *physname)
  {
    m_loc_kind = FIELD_LOC_KIND_PHYSNAME;
    m_loc.physname = physname;
  }

  dwarf2_locexpr_baton *loc_dwarf_block () const
  {
    gdb_assert (m_loc_kind == FIELD_LOC_KIND_DWARF_BLOCK);
    return m_loc.dwarf_block;
  }

  void set_loc_dwarf_block (dwarf2_locexpr_baton *dwarf_block)
  {
    m_loc_kind = FIELD_LOC_KIND_DWARF_BLOCK;
    m_loc.dwarf_block = dwarf_block;
  }

  union field_location m_loc;

  /* * For a function or member type, this is 1 if the argument is
     marked artificial.  Artificial arguments should not be shown
     to the user.  For TYPE_CODE_RANGE it is set if the specific
     bound is not defined.  */

  unsigned int artificial : 1;

  /* * Discriminant for union field_location.  */

  ENUM_BITFIELD(field_loc_kind) m_loc_kind : 3;

  /* * Size of this field, in bits, or zero if not packed.
     If non-zero in an array type, indicates the element size in
     bits (used only in Ada at the moment).
     For an unpacked field, the field's type's length
     says how many bytes the field occupies.  */

  unsigned int bitsize : 28;

  /* * In a struct or union type, type of this field.
     - In a function or member type, type of this argument.
     - In an array type, the domain-type of the array.  */

  struct type *m_type;

  /* * Name of field, value or argument.
     NULL for range bounds, array domains, and member function
     arguments.  */

  const char *m_name;
};

struct range_bounds
{
  ULONGEST bit_stride () const
  {
    if (this->flag_is_byte_stride)
      return this->stride.const_val () * 8;
    else
      return this->stride.const_val ();
  }

  /* * Low bound of range.  */

  struct dynamic_prop low;

  /* * High bound of range.  */

  struct dynamic_prop high;

  /* The stride value for this range.  This can be stored in bits or bytes
     based on the value of BYTE_STRIDE_P.  It is optional to have a stride
     value, if this range has no stride value defined then this will be set
     to the constant zero.  */

  struct dynamic_prop stride;

  /* * The bias.  Sometimes a range value is biased before storage.
     The bias is added to the stored bits to form the true value.  */

  LONGEST bias;

  /* True if HIGH range bound contains the number of elements in the
     subrange.  This affects how the final high bound is computed.  */

  unsigned int flag_upper_bound_is_count : 1;

  /* True if LOW or/and HIGH are resolved into a static bound from
     a dynamic one.  */

  unsigned int flag_bound_evaluated : 1;

  /* If this is true this STRIDE is in bytes, otherwise STRIDE is in bits.  */

  unsigned int flag_is_byte_stride : 1;
};

/* Compare two range_bounds objects for equality.  Simply does
   memberwise comparison.  */
extern bool operator== (const range_bounds &l, const range_bounds &r);

/* Compare two range_bounds objects for inequality.  */
static inline bool operator!= (const range_bounds &l, const range_bounds &r)
{
  return !(l == r);
}

union type_specific
{
  /* * CPLUS_STUFF is for TYPE_CODE_STRUCT.  It is initialized to
     point to cplus_struct_default, a default static instance of a
     struct cplus_struct_type.  */

  struct cplus_struct_type *cplus_stuff;

  /* * GNAT_STUFF is for types for which the GNAT Ada compiler
     provides additional information.  */

  struct gnat_aux_type *gnat_stuff;

  /* * FLOATFORMAT is for TYPE_CODE_FLT.  It is a pointer to a
     floatformat object that describes the floating-point value
     that resides within the type.  */

  const struct floatformat *floatformat;

  /* * For TYPE_CODE_FUNC and TYPE_CODE_METHOD types.  */

  struct func_type *func_stuff;

  /* * For types that are pointer to member types (TYPE_CODE_METHODPTR,
     TYPE_CODE_MEMBERPTR), SELF_TYPE is the type that this pointer
     is a member of.  */

  struct type *self_type;

  /* * For TYPE_CODE_FIXED_POINT types, the info necessary to decode
     values of that type.  */
  struct fixed_point_type_info *fixed_point_info;

  /* * An integer-like scalar type may be stored in just part of its
     enclosing storage bytes.  This structure describes this
     situation.  */
  struct
  {
    /* * The bit size of the integer.  This can be 0.  For integers
       that fill their storage (the ordinary case), this field holds
       the byte size times 8.  */
    unsigned short bit_size;
    /* * The bit offset of the integer.  This is ordinarily 0, and can
       only be non-zero if the bit size is less than the storage
       size.  */
    unsigned short bit_offset;
  } int_stuff;
};

/* * Main structure representing a type in GDB.

   This structure is space-critical.  Its layout has been tweaked to
   reduce the space used.  */

struct main_type
{
  /* * Code for kind of type.  */

  ENUM_BITFIELD(type_code) code : 8;

  /* * Flags about this type.  These fields appear at this location
     because they packs nicely here.  See the TYPE_* macros for
     documentation about these fields.  */

  unsigned int m_flag_unsigned : 1;
  unsigned int m_flag_nosign : 1;
  unsigned int m_flag_stub : 1;
  unsigned int m_flag_target_stub : 1;
  unsigned int m_flag_prototyped : 1;
  unsigned int m_flag_varargs : 1;
  unsigned int m_flag_vector : 1;
  unsigned int m_flag_stub_supported : 1;
  unsigned int m_flag_gnu_ifunc : 1;
  unsigned int m_flag_fixed_instance : 1;
  unsigned int m_flag_objfile_owned : 1;
  unsigned int m_flag_endianity_not_default : 1;

  /* * True if this type was declared with "class" rather than
     "struct".  */

  unsigned int m_flag_declared_class : 1;

  /* * True if this is an enum type with disjoint values.  This
     affects how the enum is printed.  */

  unsigned int m_flag_flag_enum : 1;

  /* * For TYPE_CODE_ARRAY, this is true if this type is part of a
     multi-dimensional array.  Multi-dimensional arrays are
     represented internally as arrays of arrays, and this flag lets
     gdb distinguish between multiple dimensions and an ordinary array
     of arrays.  The flag is set on each inner dimension, but not the
     outermost dimension.  */

  unsigned int m_multi_dimensional : 1;

  /* * A discriminant telling us which field of the type_specific
     union is being used for this type, if any.  */

  ENUM_BITFIELD(type_specific_kind) type_specific_field : 3;

  /* * Number of fields described for this type.  This field appears
     at this location because it packs nicely here.  */

  unsigned int m_nfields;

  /* * Name of this type, or NULL if none.

     This is used for printing only.  For looking up a name, look for
     a symbol in the VAR_DOMAIN.  This is generally allocated in the
     objfile's obstack.  However coffread.c uses malloc.  */

  const char *name;

  /* * Every type is now associated with a particular objfile, and the
     type is allocated on the objfile_obstack for that objfile.  One
     problem however, is that there are times when gdb allocates new
     types while it is not in the process of reading symbols from a
     particular objfile.  Fortunately, these happen when the type
     being created is a derived type of an existing type, such as in
     lookup_pointer_type().  So we can just allocate the new type
     using the same objfile as the existing type, but to do this we
     need a backpointer to the objfile from the existing type.  Yes
     this is somewhat ugly, but without major overhaul of the internal
     type system, it can't be avoided for now.  */

  union type_owner m_owner;

  /* * For a pointer type, describes the type of object pointed to.
     - For an array type, describes the type of the elements.
     - For a function or method type, describes the type of the return value.
     - For a range type, describes the type of the full range.
     - For a complex type, describes the type of each coordinate.
     - For a special record or union type encoding a dynamic-sized type
     in GNAT, a memoized pointer to a corresponding static version of
     the type.
     - Unused otherwise.  */

  struct type *m_target_type;

  /* * For structure and union types, a description of each field.
     For set and pascal array types, there is one "field",
     whose type is the domain type of the set or array.
     For range types, there are two "fields",
     the minimum and maximum values (both inclusive).
     For enum types, each possible value is described by one "field".
     For a function or method type, a "field" for each parameter.
     For C++ classes, there is one field for each base class (if it is
     a derived class) plus one field for each class data member.  Member
     functions are recorded elsewhere.

     Using a pointer to a separate array of fields
     allows all types to have the same size, which is useful
     because we can allocate the space for a type before
     we know what to put in it.  */

  union 
  {
    struct field *fields;

    /* * Union member used for range types.  */

    struct range_bounds *bounds;

    /* If this is a scalar type, then this is its corresponding
       complex type.  */
    struct type *complex_type;

  } flds_bnds;

  /* * Slot to point to additional language-specific fields of this
     type.  */

  union type_specific type_specific;

  /* * Contains all dynamic type properties.  */
  struct dynamic_prop_list *dyn_prop_list;
};

/* * Number of bits allocated for alignment.  */

#define TYPE_ALIGN_BITS 8

/* * A ``struct type'' describes a particular instance of a type, with
   some particular qualification.  */

struct type
{
  /* Get the type code of this type. 

     Note that the code can be TYPE_CODE_TYPEDEF, so if you want the real
     type, you need to do `check_typedef (type)->code ()`.  */
  type_code code () const
  {
    return this->main_type->code;
  }

  /* Set the type code of this type.  */
  void set_code (type_code code)
  {
    this->main_type->code = code;
  }

  /* Get the name of this type.  */
  const char *name () const
  {
    return this->main_type->name;
  }

  /* Set the name of this type.  */
  void set_name (const char *name)
  {
    this->main_type->name = name;
  }

  /* Note that if thistype is a TYPEDEF type, you have to call check_typedef.
     But check_typedef does set the TYPE_LENGTH of the TYPEDEF type,
     so you only have to call check_typedef once.  Since value::allocate
     calls check_typedef, X->type ()->length () is safe.  */
  ULONGEST length () const
  {
    return this->m_length;
  }

  void set_length (ULONGEST length)
  {
    this->m_length = length;
  }

  /* Get the number of fields of this type.  */
  unsigned int num_fields () const
  {
    return this->main_type->m_nfields;
  }

  /* Set the number of fields of this type.  */
  void set_num_fields (unsigned int num_fields)
  {
    this->main_type->m_nfields = num_fields;
  }

  /* Get the fields array of this type.  */
  struct field *fields () const
  {
    return this->main_type->flds_bnds.fields;
  }

  /* Get the field at index IDX.  */
  struct field &field (int idx) const
  {
    gdb_assert (idx >= 0 && idx < num_fields ());
    return this->fields ()[idx];
  }

  /* Set the fields array of this type.  */
  void set_fields (struct field *fields)
  {
    this->main_type->flds_bnds.fields = fields;
  }

  type *index_type () const
  {
    return this->field (0).type ();
  }

  struct type *target_type () const
  {
    return this->main_type->m_target_type;
  }

  void set_target_type (struct type *target_type)
  {
    this->main_type->m_target_type = target_type;
  }

  void set_index_type (type *index_type)
  {
    this->field (0).set_type (index_type);
  }

  /* Return the instance flags converted to the correct type.  */
  const type_instance_flags instance_flags () const
  {
    return (enum type_instance_flag_value) this->m_instance_flags;
  }

  /* Set the instance flags.  */
  void set_instance_flags (type_instance_flags flags)
  {
    this->m_instance_flags = flags;
  }

  /* Get the bounds bounds of this type.  The type must be a range type.  */
  range_bounds *bounds () const
  {
    switch (this->code ())
      {
      case TYPE_CODE_RANGE:
	return this->main_type->flds_bnds.bounds;

      case TYPE_CODE_ARRAY:
      case TYPE_CODE_STRING:
	return this->index_type ()->bounds ();

      default:
	gdb_assert_not_reached
	  ("type::bounds called on type with invalid code");
      }
  }

  /* Set the bounds of this type.  The type must be a range type.  */
  void set_bounds (range_bounds *bounds)
  {
    gdb_assert (this->code () == TYPE_CODE_RANGE);

    this->main_type->flds_bnds.bounds = bounds;
  }

  ULONGEST bit_stride () const
  {
    if (this->code () == TYPE_CODE_ARRAY && this->field (0).bitsize != 0)
      return this->field (0).bitsize;
    return this->bounds ()->bit_stride ();
  }

  /* Unsigned integer type.  If this is not set for a TYPE_CODE_INT,
     the type is signed (unless TYPE_NOSIGN is set).  */

  bool is_unsigned () const
  {
    return this->main_type->m_flag_unsigned;
  }

  void set_is_unsigned (bool is_unsigned)
  {
    this->main_type->m_flag_unsigned = is_unsigned;
  }

  /* No sign for this type.  In C++, "char", "signed char", and
     "unsigned char" are distinct types; so we need an extra flag to
     indicate the absence of a sign!  */

  bool has_no_signedness () const
  {
    return this->main_type->m_flag_nosign;
  }

  void set_has_no_signedness (bool has_no_signedness)
  {
    this->main_type->m_flag_nosign = has_no_signedness;
  }

  /* This appears in a type's flags word if it is a stub type (e.g.,
     if someone referenced a type that wasn't defined in a source file
     via (struct sir_not_appearing_in_this_film *)).  */

  bool is_stub () const
  {
    return this->main_type->m_flag_stub;
  }

  void set_is_stub (bool is_stub)
  {
    this->main_type->m_flag_stub = is_stub;
  }

  /* The target type of this type is a stub type, and this type needs
     to be updated if it gets un-stubbed in check_typedef.  Used for
     arrays and ranges, in which TYPE_LENGTH of the array/range gets set
     based on the TYPE_LENGTH of the target type.  Also, set for
     TYPE_CODE_TYPEDEF.  */

  bool target_is_stub () const
  {
    return this->main_type->m_flag_target_stub;
  }

  void set_target_is_stub (bool target_is_stub)
  {
    this->main_type->m_flag_target_stub = target_is_stub;
  }

  /* This is a function type which appears to have a prototype.  We
     need this for function calls in order to tell us if it's necessary
     to coerce the args, or to just do the standard conversions.  This
     is used with a short field.  */

  bool is_prototyped () const
  {
    return this->main_type->m_flag_prototyped;
  }

  void set_is_prototyped (bool is_prototyped)
  {
    this->main_type->m_flag_prototyped = is_prototyped;
  }

  /* FIXME drow/2002-06-03:  Only used for methods, but applies as well
     to functions.  */

  bool has_varargs () const
  {
    return this->main_type->m_flag_varargs;
  }

  void set_has_varargs (bool has_varargs)
  {
    this->main_type->m_flag_varargs = has_varargs;
  }

  /* Identify a vector type.  Gcc is handling this by adding an extra
     attribute to the array type.  We slurp that in as a new flag of a
     type.  This is used only in dwarf2read.c.  */

  bool is_vector () const
  {
    return this->main_type->m_flag_vector;
  }

  void set_is_vector (bool is_vector)
  {
    this->main_type->m_flag_vector = is_vector;
  }

  /* This debug target supports TYPE_STUB(t).  In the unsupported case
     we have to rely on NFIELDS to be zero etc., see TYPE_IS_OPAQUE().
     TYPE_STUB(t) with !TYPE_STUB_SUPPORTED(t) may exist if we only
     guessed the TYPE_STUB(t) value (see dwarfread.c).  */

  bool stub_is_supported () const
  {
    return this->main_type->m_flag_stub_supported;
  }

  void set_stub_is_supported (bool stub_is_supported)
  {
    this->main_type->m_flag_stub_supported = stub_is_supported;
  }

  /* Used only for TYPE_CODE_FUNC where it specifies the real function
     address is returned by this function call.  The target_type method
     determines the final returned function type to be presented to
     user.  */

  bool is_gnu_ifunc () const
  {
    return this->main_type->m_flag_gnu_ifunc;
  }

  void set_is_gnu_ifunc (bool is_gnu_ifunc)
  {
    this->main_type->m_flag_gnu_ifunc = is_gnu_ifunc;
  }

  /* The debugging formats (especially STABS) do not contain enough
     information to represent all Ada types---especially those whose
     size depends on dynamic quantities.  Therefore, the GNAT Ada
     compiler includes extra information in the form of additional type
     definitions connected by naming conventions.  This flag indicates
     that the type is an ordinary (unencoded) GDB type that has been
     created from the necessary run-time information, and does not need
     further interpretation.  Optionally marks ordinary, fixed-size GDB
     type.  */

  bool is_fixed_instance () const
  {
    return this->main_type->m_flag_fixed_instance;
  }

  void set_is_fixed_instance (bool is_fixed_instance)
  {
    this->main_type->m_flag_fixed_instance = is_fixed_instance;
  }

  /* A compiler may supply dwarf instrumentation that indicates the desired
     endian interpretation of the variable differs from the native endian
     representation. */

  bool endianity_is_not_default () const
  {
    return this->main_type->m_flag_endianity_not_default;
  }

  void set_endianity_is_not_default (bool endianity_is_not_default)
  {
    this->main_type->m_flag_endianity_not_default = endianity_is_not_default;
  }


  /* True if this type was declared using the "class" keyword.  This is
     only valid for C++ structure and enum types.  If false, a structure
     was declared as a "struct"; if true it was declared "class".  For
     enum types, this is true when "enum class" or "enum struct" was
     used to declare the type.  */

  bool is_declared_class () const
  {
    return this->main_type->m_flag_declared_class;
  }

  void set_is_declared_class (bool is_declared_class) const
  {
    this->main_type->m_flag_declared_class = is_declared_class;
  }

  /* True if this type is a "flag" enum.  A flag enum is one where all
     the values are pairwise disjoint when "and"ed together.  This
     affects how enum values are printed.  */

  bool is_flag_enum () const
  {
    return this->main_type->m_flag_flag_enum;
  }

  void set_is_flag_enum (bool is_flag_enum)
  {
    this->main_type->m_flag_flag_enum = is_flag_enum;
  }

  /* True if this array type is part of a multi-dimensional array.  */

  bool is_multi_dimensional () const
  {
    return this->main_type->m_multi_dimensional;
  }

  void set_is_multi_dimensional (bool value)
  {
    this->main_type->m_multi_dimensional = value;
  }

  /* * Assuming that THIS is a TYPE_CODE_FIXED_POINT, return a reference
     to this type's fixed_point_info.  */

  struct fixed_point_type_info &fixed_point_info () const
  {
    gdb_assert (this->code () == TYPE_CODE_FIXED_POINT);
    gdb_assert (this->main_type->type_specific.fixed_point_info != nullptr);

    return *this->main_type->type_specific.fixed_point_info;
  }

  /* * Assuming that THIS is a TYPE_CODE_FIXED_POINT, set this type's
     fixed_point_info to INFO.  */

  void set_fixed_point_info (struct fixed_point_type_info *info) const
  {
    gdb_assert (this->code () == TYPE_CODE_FIXED_POINT);

    this->main_type->type_specific.fixed_point_info = info;
  }

  /* * Assuming that THIS is a TYPE_CODE_FIXED_POINT, return its base type.

     In other words, this returns the type after having peeled all
     intermediate type layers (such as TYPE_CODE_RANGE, for instance).
     The TYPE_CODE of the type returned is guaranteed to be
     a TYPE_CODE_FIXED_POINT.  */

  struct type *fixed_point_type_base_type ();

  /* * Assuming that THIS is a TYPE_CODE_FIXED_POINT, return its scaling
     factor.  */

  const gdb_mpq &fixed_point_scaling_factor ();

  /* * Return the dynamic property of the requested KIND from this type's
     list of dynamic properties.  */
  dynamic_prop *dyn_prop (dynamic_prop_node_kind kind) const;

  /* * Given a dynamic property PROP of a given KIND, add this dynamic
     property to this type.

     This function assumes that this type is objfile-owned.  */
  void add_dyn_prop (dynamic_prop_node_kind kind, dynamic_prop prop);

  /* * Remove dynamic property of kind KIND from this type, if it exists.  */
  void remove_dyn_prop (dynamic_prop_node_kind kind);

  /* Return true if this type is owned by an objfile.  Return false if it is
     owned by an architecture.  */
  bool is_objfile_owned () const
  {
    return this->main_type->m_flag_objfile_owned;
  }

  /* Set the owner of the type to be OBJFILE.  */
  void set_owner (objfile *objfile)
  {
    gdb_assert (objfile != nullptr);

    this->main_type->m_owner.objfile = objfile;
    this->main_type->m_flag_objfile_owned = true;
  }

  /* Set the owner of the type to be ARCH.  */
  void set_owner (gdbarch *arch)
  {
    gdb_assert (arch != nullptr);

    this->main_type->m_owner.gdbarch = arch;
    this->main_type->m_flag_objfile_owned = false;
  }

  /* Return the objfile owner of this type.

     Return nullptr if this type is not objfile-owned.  */
  struct objfile *objfile_owner () const
  {
    if (!this->is_objfile_owned ())
      return nullptr;

    return this->main_type->m_owner.objfile;
  }

  /* Return the gdbarch owner of this type.

     Return nullptr if this type is not gdbarch-owned.  */
  gdbarch *arch_owner () const
  {
    if (this->is_objfile_owned ())
      return nullptr;

    return this->main_type->m_owner.gdbarch;
  }

  /* Return the type's architecture.  For types owned by an
     architecture, that architecture is returned.  For types owned by an
     objfile, that objfile's architecture is returned.

     The return value is always non-nullptr.  */
  gdbarch *arch () const;

  /* * Return true if this is an integer type whose logical (bit) size
     differs from its storage size; false otherwise.  Always return
     false for non-integer (i.e., non-TYPE_SPECIFIC_INT) types.  */
  bool bit_size_differs_p () const
  {
    return (main_type->type_specific_field == TYPE_SPECIFIC_INT
	    && main_type->type_specific.int_stuff.bit_size != 8 * length ());
  }

  /* * Return the logical (bit) size for this integer type.  Only
     valid for integer (TYPE_SPECIFIC_INT) types.  */
  unsigned short bit_size () const
  {
    gdb_assert (main_type->type_specific_field == TYPE_SPECIFIC_INT);
    return main_type->type_specific.int_stuff.bit_size;
  }

  /* * Return the bit offset for this integer type.  Only valid for
     integer (TYPE_SPECIFIC_INT) types.  */
  unsigned short bit_offset () const
  {
    gdb_assert (main_type->type_specific_field == TYPE_SPECIFIC_INT);
    return main_type->type_specific.int_stuff.bit_offset;
  }

  /* Return true if this is a pointer or reference type.  */
  bool is_pointer_or_reference () const
  {
    return this->code () == TYPE_CODE_PTR || TYPE_IS_REFERENCE (this);
  }

  /* * Type that is a pointer to this type.
     NULL if no such pointer-to type is known yet.
     The debugger may add the address of such a type
     if it has to construct one later.  */

  struct type *pointer_type;

  /* * C++: also need a reference type.  */

  struct type *reference_type;

  /* * A C++ rvalue reference type added in C++11. */

  struct type *rvalue_reference_type;

  /* * Variant chain.  This points to a type that differs from this
     one only in qualifiers and length.  Currently, the possible
     qualifiers are const, volatile, code-space, data-space, and
     address class.  The length may differ only when one of the
     address class flags are set.  The variants are linked in a
     circular ring and share MAIN_TYPE.  */

  struct type *chain;

  /* * The alignment for this type.  Zero means that the alignment was
     not specified in the debug info.  Note that this is stored in a
     funny way: as the log base 2 (plus 1) of the alignment; so a
     value of 1 means the alignment is 1, and a value of 9 means the
     alignment is 256.  */

  unsigned align_log2 : TYPE_ALIGN_BITS;

  /* * Flags specific to this instance of the type, indicating where
     on the ring we are.

     For TYPE_CODE_TYPEDEF the flags of the typedef type should be
     binary or-ed with the target type, with a special case for
     address class and space class.  For example if this typedef does
     not specify any new qualifiers, TYPE_INSTANCE_FLAGS is 0 and the
     instance flags are completely inherited from the target type.  No
     qualifiers can be cleared by the typedef.  See also
     check_typedef.  */
  unsigned m_instance_flags : 9;

  /* * Length of storage for a value of this type.  The value is the
     expression in host bytes of what sizeof(type) would return.  This
     size includes padding.  For example, an i386 extended-precision
     floating point value really only occupies ten bytes, but most
     ABI's declare its size to be 12 bytes, to preserve alignment.
     A `struct type' representing such a floating-point type would
     have a `length' value of 12, even though the last two bytes are
     unused.

     Since this field is expressed in host bytes, its value is appropriate
     to pass to memcpy and such (it is assumed that GDB itself always runs
     on an 8-bits addressable architecture).  However, when using it for
     target address arithmetic (e.g. adding it to a target address), the
     type_length_units function should be used in order to get the length
     expressed in target addressable memory units.  */

  ULONGEST m_length;

  /* * Core type, shared by a group of qualified types.  */

  struct main_type *main_type;
};

struct fn_fieldlist
{

  /* * The overloaded name.
     This is generally allocated in the objfile's obstack.
     However stabsread.c sometimes uses malloc.  */

  const char *name;

  /* * The number of methods with this name.  */

  int length;

  /* * The list of methods.  */

  struct fn_field *fn_fields;
};



struct fn_field
{
  /* * If is_stub is clear, this is the mangled name which we can look
     up to find the address of the method (FIXME: it would be cleaner
     to have a pointer to the struct symbol here instead).

     If is_stub is set, this is the portion of the mangled name which
     specifies the arguments.  For example, "ii", if there are two int
     arguments, or "" if there are no arguments.  See gdb_mangle_name
     for the conversion from this format to the one used if is_stub is
     clear.  */

  const char *physname;

  /* * The function type for the method.
	       
     (This comment used to say "The return value of the method", but
     that's wrong.  The function type is expected here, i.e. something
     with TYPE_CODE_METHOD, and *not* the return-value type).  */

  struct type *type;

  /* * For virtual functions.  First baseclass that defines this
     virtual function.  */

  struct type *fcontext;

  /* Attributes.  */

  unsigned int is_const:1;
  unsigned int is_volatile:1;
  unsigned int is_private:1;
  unsigned int is_protected:1;
  unsigned int is_artificial:1;

  /* * A stub method only has some fields valid (but they are enough
     to reconstruct the rest of the fields).  */

  unsigned int is_stub:1;

  /* * True if this function is a constructor, false otherwise.  */

  unsigned int is_constructor : 1;

  /* * True if this function is deleted, false otherwise.  */

  unsigned int is_deleted : 1;

  /* * DW_AT_defaulted attribute for this function.  The value is one
     of the DW_DEFAULTED constants.  */

  ENUM_BITFIELD (dwarf_defaulted_attribute) defaulted : 2;

  /* * Unused.  */

  unsigned int dummy:6;

  /* * Index into that baseclass's virtual function table, minus 2;
     else if static: VOFFSET_STATIC; else: 0.  */

  unsigned int voffset:16;

#define VOFFSET_STATIC 1

};

struct decl_field
{
  /* * Unqualified name to be prefixed by owning class qualified
     name.  */

  const char *name;

  /* * Type this typedef named NAME represents.  */

  struct type *type;

  /* * True if this field was declared protected, false otherwise.  */
  unsigned int is_protected : 1;

  /* * True if this field was declared private, false otherwise.  */
  unsigned int is_private : 1;
};

/* * C++ language-specific information for TYPE_CODE_STRUCT and
   TYPE_CODE_UNION nodes.  */

struct cplus_struct_type
  {
    /* * Number of base classes this type derives from.  The
       baseclasses are stored in the first N_BASECLASSES fields
       (i.e. the `fields' field of the struct type).  The only fields
       of struct field that are used are: type, name, loc.bitpos.  */

    short n_baseclasses;

    /* * Field number of the virtual function table pointer in VPTR_BASETYPE.
       All access to this field must be through TYPE_VPTR_FIELDNO as one
       thing it does is check whether the field has been initialized.
       Initially TYPE_RAW_CPLUS_SPECIFIC has the value of cplus_struct_default,
       which for portability reasons doesn't initialize this field.
       TYPE_VPTR_FIELDNO returns -1 for this case.

       If -1, we were unable to find the virtual function table pointer in
       initial symbol reading, and get_vptr_fieldno should be called to find
       it if possible.  get_vptr_fieldno will update this field if possible.
       Otherwise the value is left at -1.

       Unused if this type does not have virtual functions.  */

    short vptr_fieldno;

    /* * Number of methods with unique names.  All overloaded methods
       with the same name count only once.  */

    short nfn_fields;

    /* * Number of template arguments.  */

    unsigned short n_template_arguments;

    /* * One if this struct is a dynamic class, as defined by the
       Itanium C++ ABI: if it requires a virtual table pointer,
       because it or any of its base classes have one or more virtual
       member functions or virtual base classes.  Minus one if not
       dynamic.  Zero if not yet computed.  */

    int is_dynamic : 2;

    /* * The calling convention for this type, fetched from the
       DW_AT_calling_convention attribute.  The value is one of the
       DW_CC constants.  */

    ENUM_BITFIELD (dwarf_calling_convention) calling_convention : 8;

    /* * The base class which defined the virtual function table pointer.  */

    struct type *vptr_basetype;

    /* * For derived classes, the number of base classes is given by
       n_baseclasses and virtual_field_bits is a bit vector containing
       one bit per base class.  If the base class is virtual, the
       corresponding bit will be set.
       I.E, given:

       class A{};
       class B{};
       class C : public B, public virtual A {};

       B is a baseclass of C; A is a virtual baseclass for C.
       This is a C++ 2.0 language feature.  */

    B_TYPE *virtual_field_bits;

    /* * For classes with private fields, the number of fields is
       given by nfields and private_field_bits is a bit vector
       containing one bit per field.

       If the field is private, the corresponding bit will be set.  */

    B_TYPE *private_field_bits;

    /* * For classes with protected fields, the number of fields is
       given by nfields and protected_field_bits is a bit vector
       containing one bit per field.

       If the field is private, the corresponding bit will be set.  */

    B_TYPE *protected_field_bits;

    /* * For classes with fields to be ignored, either this is
       optimized out or this field has length 0.  */

    B_TYPE *ignore_field_bits;

    /* * For classes, structures, and unions, a description of each
       field, which consists of an overloaded name, followed by the
       types of arguments that the method expects, and then the name
       after it has been renamed to make it distinct.

       fn_fieldlists points to an array of nfn_fields of these.  */

    struct fn_fieldlist *fn_fieldlists;

    /* * typedefs defined inside this class.  typedef_field points to
       an array of typedef_field_count elements.  */

    struct decl_field *typedef_field;

    unsigned typedef_field_count;

    /* * The nested types defined by this type.  nested_types points to
       an array of nested_types_count elements.  */

    struct decl_field *nested_types;

    unsigned nested_types_count;

    /* * The template arguments.  This is an array with
       N_TEMPLATE_ARGUMENTS elements.  This is NULL for non-template
       classes.  */

    struct symbol **template_arguments;
  };

/* * Struct used to store conversion rankings.  */

struct rank
  {
    short rank;

    /* * When two conversions are of the same type and therefore have
       the same rank, subrank is used to differentiate the two.

       Eg: Two derived-class-pointer to base-class-pointer conversions
       would both have base pointer conversion rank, but the
       conversion with the shorter distance to the ancestor is
       preferable.  'subrank' would be used to reflect that.  */

    short subrank;
  };

/* * Used for ranking a function for overload resolution.  */

typedef std::vector<rank> badness_vector;

/* * GNAT Ada-specific information for various Ada types.  */

struct gnat_aux_type
  {
    /* * Parallel type used to encode information about dynamic types
       used in Ada (such as variant records, variable-size array,
       etc).  */
    struct type* descriptive_type;
  };

/* * For TYPE_CODE_FUNC and TYPE_CODE_METHOD types.  */

struct func_type
  {
    /* * The calling convention for targets supporting multiple ABIs.
       Right now this is only fetched from the Dwarf-2
       DW_AT_calling_convention attribute.  The value is one of the
       DW_CC constants.  */

    ENUM_BITFIELD (dwarf_calling_convention) calling_convention : 8;

    /* * Whether this function normally returns to its caller.  It is
       set from the DW_AT_noreturn attribute if set on the
       DW_TAG_subprogram.  */

    unsigned int is_noreturn : 1;

    /* * Only those DW_TAG_call_site's in this function that have
       DW_AT_call_tail_call set are linked in this list.  Function
       without its tail call list complete
       (DW_AT_call_all_tail_calls or its superset
       DW_AT_call_all_calls) has TAIL_CALL_LIST NULL, even if some
       DW_TAG_call_site's exist in such function. */

    struct call_site *tail_call_list;

    /* * For method types (TYPE_CODE_METHOD), the aggregate type that
       contains the method.  */

    struct type *self_type;
  };

/* The type-specific info for TYPE_CODE_FIXED_POINT types.  */

struct fixed_point_type_info
{
  /* The fixed point type's scaling factor.  */
  gdb_mpq scaling_factor;
};

/* * The default value of TYPE_CPLUS_SPECIFIC(T) points to this shared
   static structure.  */

extern const struct cplus_struct_type cplus_struct_default;

extern void allocate_cplus_struct_type (struct type *);

#define INIT_CPLUS_SPECIFIC(type) \
  (TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_CPLUS_STUFF, \
   TYPE_RAW_CPLUS_SPECIFIC (type) = (struct cplus_struct_type*) \
   &cplus_struct_default)

#define ALLOCATE_CPLUS_STRUCT_TYPE(type) allocate_cplus_struct_type (type)

#define HAVE_CPLUS_STRUCT(type) \
  (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_CPLUS_STUFF \
   && TYPE_RAW_CPLUS_SPECIFIC (type) !=  &cplus_struct_default)

#define INIT_NONE_SPECIFIC(type) \
  (TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_NONE, \
   TYPE_MAIN_TYPE (type)->type_specific = {})

extern const struct gnat_aux_type gnat_aux_default;

extern void allocate_gnat_aux_type (struct type *);

#define INIT_GNAT_SPECIFIC(type) \
  (TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_GNAT_STUFF, \
   TYPE_GNAT_SPECIFIC (type) = (struct gnat_aux_type *) &gnat_aux_default)
#define ALLOCATE_GNAT_AUX_TYPE(type) allocate_gnat_aux_type (type)
/* * A macro that returns non-zero if the type-specific data should be
   read as "gnat-stuff".  */
#define HAVE_GNAT_AUX_INFO(type) \
  (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_GNAT_STUFF)

/* * True if TYPE is known to be an Ada type of some kind.  */
#define ADA_TYPE_P(type)					\
  (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_GNAT_STUFF	\
    || (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_NONE	\
	&& (type)->is_fixed_instance ()))

#define INIT_FUNC_SPECIFIC(type)					       \
  (TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_FUNC,			       \
   TYPE_MAIN_TYPE (type)->type_specific.func_stuff = (struct func_type *)      \
     TYPE_ZALLOC (type,							       \
		  sizeof (*TYPE_MAIN_TYPE (type)->type_specific.func_stuff)))

/* "struct fixed_point_type_info" has a field that has a destructor.
   See allocate_fixed_point_type_info to understand how this is
   handled.  */
#define INIT_FIXED_POINT_SPECIFIC(type) \
  (TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_FIXED_POINT, \
   allocate_fixed_point_type_info (type))

#define TYPE_MAIN_TYPE(thistype) (thistype)->main_type
#define TYPE_POINTER_TYPE(thistype) (thistype)->pointer_type
#define TYPE_REFERENCE_TYPE(thistype) (thistype)->reference_type
#define TYPE_RVALUE_REFERENCE_TYPE(thistype) (thistype)->rvalue_reference_type
#define TYPE_CHAIN(thistype) (thistype)->chain

/* * Return the alignment of the type in target addressable memory
   units, or 0 if no alignment was specified.  */
#define TYPE_RAW_ALIGN(thistype) type_raw_align (thistype)

/* * Return the alignment of the type in target addressable memory
   units, or 0 if no alignment was specified.  */
extern unsigned type_raw_align (struct type *);

/* * Return the alignment of the type in target addressable memory
   units.  Return 0 if the alignment cannot be determined; but note
   that this makes an effort to compute the alignment even it it was
   not specified in the debug info.  */
extern unsigned type_align (struct type *);

/* * Set the alignment of the type.  The alignment must be a power of
   2.  Returns false if the given value does not fit in the available
   space in struct type.  */
extern bool set_type_align (struct type *, ULONGEST);

/* Property accessors for the type data location.  */
#define TYPE_DATA_LOCATION(thistype) \
  ((thistype)->dyn_prop (DYN_PROP_DATA_LOCATION))
#define TYPE_DATA_LOCATION_BATON(thistype) \
  TYPE_DATA_LOCATION (thistype)->data.baton
#define TYPE_DATA_LOCATION_ADDR(thistype) \
  (TYPE_DATA_LOCATION (thistype)->const_val ())
#define TYPE_DATA_LOCATION_KIND(thistype) \
  (TYPE_DATA_LOCATION (thistype)->kind ())
#define TYPE_DYNAMIC_LENGTH(thistype) \
  ((thistype)->dyn_prop (DYN_PROP_BYTE_SIZE))

/* Property accessors for the type allocated/associated.  */
#define TYPE_ALLOCATED_PROP(thistype) \
  ((thistype)->dyn_prop (DYN_PROP_ALLOCATED))
#define TYPE_ASSOCIATED_PROP(thistype) \
  ((thistype)->dyn_prop (DYN_PROP_ASSOCIATED))
#define TYPE_RANK_PROP(thistype) \
  ((thistype)->dyn_prop (DYN_PROP_RANK))

/* C++ */

#define TYPE_SELF_TYPE(thistype) internal_type_self_type (thistype)
/* Do not call this, use TYPE_SELF_TYPE.  */
extern struct type *internal_type_self_type (struct type *);
extern void set_type_self_type (struct type *, struct type *);

extern int internal_type_vptr_fieldno (struct type *);
extern void set_type_vptr_fieldno (struct type *, int);
extern struct type *internal_type_vptr_basetype (struct type *);
extern void set_type_vptr_basetype (struct type *, struct type *);
#define TYPE_VPTR_FIELDNO(thistype) internal_type_vptr_fieldno (thistype)
#define TYPE_VPTR_BASETYPE(thistype) internal_type_vptr_basetype (thistype)

#define TYPE_NFN_FIELDS(thistype) TYPE_CPLUS_SPECIFIC(thistype)->nfn_fields
#define TYPE_SPECIFIC_FIELD(thistype) \
  TYPE_MAIN_TYPE(thistype)->type_specific_field
/* We need this tap-dance with the TYPE_RAW_SPECIFIC because of the case
   where we're trying to print an Ada array using the C language.
   In that case, there is no "cplus_stuff", but the C language assumes
   that there is.  What we do, in that case, is pretend that there is
   an implicit one which is the default cplus stuff.  */
#define TYPE_CPLUS_SPECIFIC(thistype) \
   (!HAVE_CPLUS_STRUCT(thistype) \
    ? (struct cplus_struct_type*)&cplus_struct_default \
    : TYPE_RAW_CPLUS_SPECIFIC(thistype))
#define TYPE_RAW_CPLUS_SPECIFIC(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.cplus_stuff
#define TYPE_CPLUS_CALLING_CONVENTION(thistype) \
  TYPE_MAIN_TYPE(thistype)->type_specific.cplus_stuff->calling_convention
#define TYPE_FLOATFORMAT(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.floatformat
#define TYPE_GNAT_SPECIFIC(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.gnat_stuff
#define TYPE_DESCRIPTIVE_TYPE(thistype) TYPE_GNAT_SPECIFIC(thistype)->descriptive_type
#define TYPE_CALLING_CONVENTION(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.func_stuff->calling_convention
#define TYPE_NO_RETURN(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.func_stuff->is_noreturn
#define TYPE_TAIL_CALL_LIST(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.func_stuff->tail_call_list
#define TYPE_BASECLASS(thistype,index) ((thistype)->field (index).type ())
#define TYPE_N_BASECLASSES(thistype) TYPE_CPLUS_SPECIFIC(thistype)->n_baseclasses
#define TYPE_BASECLASS_NAME(thistype,index) (thistype->field (index).name ())
#define TYPE_BASECLASS_BITPOS(thistype,index) (thistype->field (index).loc_bitpos ())
#define BASETYPE_VIA_PUBLIC(thistype, index) \
  ((!TYPE_FIELD_PRIVATE(thistype, index)) && (!TYPE_FIELD_PROTECTED(thistype, index)))
#define TYPE_CPLUS_DYNAMIC(thistype) TYPE_CPLUS_SPECIFIC (thistype)->is_dynamic

#define BASETYPE_VIA_VIRTUAL(thistype, index) \
  (TYPE_CPLUS_SPECIFIC(thistype)->virtual_field_bits == NULL ? 0 \
    : B_TST(TYPE_CPLUS_SPECIFIC(thistype)->virtual_field_bits, (index)))

#define FIELD_ARTIFICIAL(thisfld) ((thisfld).artificial)
#define FIELD_BITSIZE(thisfld) ((thisfld).bitsize)

#define TYPE_FIELD_ARTIFICIAL(thistype, n) FIELD_ARTIFICIAL((thistype)->field (n))
#define TYPE_FIELD_BITSIZE(thistype, n) FIELD_BITSIZE((thistype)->field (n))
#define TYPE_FIELD_PACKED(thistype, n) (FIELD_BITSIZE((thistype)->field (n))!=0)

#define TYPE_FIELD_PRIVATE_BITS(thistype) \
  TYPE_CPLUS_SPECIFIC(thistype)->private_field_bits
#define TYPE_FIELD_PROTECTED_BITS(thistype) \
  TYPE_CPLUS_SPECIFIC(thistype)->protected_field_bits
#define TYPE_FIELD_IGNORE_BITS(thistype) \
  TYPE_CPLUS_SPECIFIC(thistype)->ignore_field_bits
#define TYPE_FIELD_VIRTUAL_BITS(thistype) \
  TYPE_CPLUS_SPECIFIC(thistype)->virtual_field_bits
#define SET_TYPE_FIELD_PRIVATE(thistype, n) \
  B_SET (TYPE_CPLUS_SPECIFIC(thistype)->private_field_bits, (n))
#define SET_TYPE_FIELD_PROTECTED(thistype, n) \
  B_SET (TYPE_CPLUS_SPECIFIC(thistype)->protected_field_bits, (n))
#define SET_TYPE_FIELD_IGNORE(thistype, n) \
  B_SET (TYPE_CPLUS_SPECIFIC(thistype)->ignore_field_bits, (n))
#define SET_TYPE_FIELD_VIRTUAL(thistype, n) \
  B_SET (TYPE_CPLUS_SPECIFIC(thistype)->virtual_field_bits, (n))
#define TYPE_FIELD_PRIVATE(thistype, n) \
  (TYPE_CPLUS_SPECIFIC(thistype)->private_field_bits == NULL ? 0 \
    : B_TST(TYPE_CPLUS_SPECIFIC(thistype)->private_field_bits, (n)))
#define TYPE_FIELD_PROTECTED(thistype, n) \
  (TYPE_CPLUS_SPECIFIC(thistype)->protected_field_bits == NULL ? 0 \
    : B_TST(TYPE_CPLUS_SPECIFIC(thistype)->protected_field_bits, (n)))
#define TYPE_FIELD_IGNORE(thistype, n) \
  (TYPE_CPLUS_SPECIFIC(thistype)->ignore_field_bits == NULL ? 0 \
    : B_TST(TYPE_CPLUS_SPECIFIC(thistype)->ignore_field_bits, (n)))
#define TYPE_FIELD_VIRTUAL(thistype, n) \
  (TYPE_CPLUS_SPECIFIC(thistype)->virtual_field_bits == NULL ? 0 \
    : B_TST(TYPE_CPLUS_SPECIFIC(thistype)->virtual_field_bits, (n)))

#define TYPE_FN_FIELDLISTS(thistype) TYPE_CPLUS_SPECIFIC(thistype)->fn_fieldlists
#define TYPE_FN_FIELDLIST(thistype, n) TYPE_CPLUS_SPECIFIC(thistype)->fn_fieldlists[n]
#define TYPE_FN_FIELDLIST1(thistype, n) TYPE_CPLUS_SPECIFIC(thistype)->fn_fieldlists[n].fn_fields
#define TYPE_FN_FIELDLIST_NAME(thistype, n) TYPE_CPLUS_SPECIFIC(thistype)->fn_fieldlists[n].name
#define TYPE_FN_FIELDLIST_LENGTH(thistype, n) TYPE_CPLUS_SPECIFIC(thistype)->fn_fieldlists[n].length

#define TYPE_N_TEMPLATE_ARGUMENTS(thistype) \
  TYPE_CPLUS_SPECIFIC (thistype)->n_template_arguments
#define TYPE_TEMPLATE_ARGUMENTS(thistype) \
  TYPE_CPLUS_SPECIFIC (thistype)->template_arguments
#define TYPE_TEMPLATE_ARGUMENT(thistype, n) \
  TYPE_CPLUS_SPECIFIC (thistype)->template_arguments[n]

#define TYPE_FN_FIELD(thisfn, n) (thisfn)[n]
#define TYPE_FN_FIELD_PHYSNAME(thisfn, n) (thisfn)[n].physname
#define TYPE_FN_FIELD_TYPE(thisfn, n) (thisfn)[n].type
#define TYPE_FN_FIELD_ARGS(thisfn, n) (((thisfn)[n].type)->fields ())
#define TYPE_FN_FIELD_CONST(thisfn, n) ((thisfn)[n].is_const)
#define TYPE_FN_FIELD_VOLATILE(thisfn, n) ((thisfn)[n].is_volatile)
#define TYPE_FN_FIELD_PRIVATE(thisfn, n) ((thisfn)[n].is_private)
#define TYPE_FN_FIELD_PROTECTED(thisfn, n) ((thisfn)[n].is_protected)
#define TYPE_FN_FIELD_ARTIFICIAL(thisfn, n) ((thisfn)[n].is_artificial)
#define TYPE_FN_FIELD_STUB(thisfn, n) ((thisfn)[n].is_stub)
#define TYPE_FN_FIELD_CONSTRUCTOR(thisfn, n) ((thisfn)[n].is_constructor)
#define TYPE_FN_FIELD_FCONTEXT(thisfn, n) ((thisfn)[n].fcontext)
#define TYPE_FN_FIELD_VOFFSET(thisfn, n) ((thisfn)[n].voffset-2)
#define TYPE_FN_FIELD_VIRTUAL_P(thisfn, n) ((thisfn)[n].voffset > 1)
#define TYPE_FN_FIELD_STATIC_P(thisfn, n) ((thisfn)[n].voffset == VOFFSET_STATIC)
#define TYPE_FN_FIELD_DEFAULTED(thisfn, n) ((thisfn)[n].defaulted)
#define TYPE_FN_FIELD_DELETED(thisfn, n) ((thisfn)[n].is_deleted)

/* Accessors for typedefs defined by a class.  */
#define TYPE_TYPEDEF_FIELD_ARRAY(thistype) \
  TYPE_CPLUS_SPECIFIC (thistype)->typedef_field
#define TYPE_TYPEDEF_FIELD(thistype, n) \
  TYPE_CPLUS_SPECIFIC (thistype)->typedef_field[n]
#define TYPE_TYPEDEF_FIELD_NAME(thistype, n) \
  TYPE_TYPEDEF_FIELD (thistype, n).name
#define TYPE_TYPEDEF_FIELD_TYPE(thistype, n) \
  TYPE_TYPEDEF_FIELD (thistype, n).type
#define TYPE_TYPEDEF_FIELD_COUNT(thistype) \
  TYPE_CPLUS_SPECIFIC (thistype)->typedef_field_count
#define TYPE_TYPEDEF_FIELD_PROTECTED(thistype, n) \
  TYPE_TYPEDEF_FIELD (thistype, n).is_protected
#define TYPE_TYPEDEF_FIELD_PRIVATE(thistype, n)        \
  TYPE_TYPEDEF_FIELD (thistype, n).is_private

#define TYPE_NESTED_TYPES_ARRAY(thistype)	\
  TYPE_CPLUS_SPECIFIC (thistype)->nested_types
#define TYPE_NESTED_TYPES_FIELD(thistype, n) \
  TYPE_CPLUS_SPECIFIC (thistype)->nested_types[n]
#define TYPE_NESTED_TYPES_FIELD_NAME(thistype, n) \
  TYPE_NESTED_TYPES_FIELD (thistype, n).name
#define TYPE_NESTED_TYPES_FIELD_TYPE(thistype, n) \
  TYPE_NESTED_TYPES_FIELD (thistype, n).type
#define TYPE_NESTED_TYPES_COUNT(thistype) \
  TYPE_CPLUS_SPECIFIC (thistype)->nested_types_count
#define TYPE_NESTED_TYPES_FIELD_PROTECTED(thistype, n) \
  TYPE_NESTED_TYPES_FIELD (thistype, n).is_protected
#define TYPE_NESTED_TYPES_FIELD_PRIVATE(thistype, n)	\
  TYPE_NESTED_TYPES_FIELD (thistype, n).is_private

#define TYPE_IS_OPAQUE(thistype) \
  ((((thistype)->code () == TYPE_CODE_STRUCT) \
    || ((thistype)->code () == TYPE_CODE_UNION)) \
   && ((thistype)->num_fields () == 0) \
   && (!HAVE_CPLUS_STRUCT (thistype) \
       || TYPE_NFN_FIELDS (thistype) == 0) \
   && ((thistype)->is_stub () || !(thistype)->stub_is_supported ()))

/* * A helper macro that returns the name of a type or "unnamed type"
   if the type has no name.  */

#define TYPE_SAFE_NAME(type) \
  (type->name () != nullptr ? type->name () : _("<unnamed type>"))

/* * A helper macro that returns the name of an error type.  If the
   type has a name, it is used; otherwise, a default is used.  */

#define TYPE_ERROR_NAME(type) \
  (type->name () ? type->name () : _("<error type>"))

/* Given TYPE, return its floatformat.  */
const struct floatformat *floatformat_from_type (const struct type *type);

struct builtin_type
{
  /* Integral types.  */

  /* Implicit size/sign (based on the architecture's ABI).  */
  struct type *builtin_void = nullptr;
  struct type *builtin_char = nullptr;
  struct type *builtin_short = nullptr;
  struct type *builtin_int = nullptr;
  struct type *builtin_long = nullptr;
  struct type *builtin_signed_char = nullptr;
  struct type *builtin_unsigned_char = nullptr;
  struct type *builtin_unsigned_short = nullptr;
  struct type *builtin_unsigned_int = nullptr;
  struct type *builtin_unsigned_long = nullptr;
  struct type *builtin_bfloat16 = nullptr;
  struct type *builtin_half = nullptr;
  struct type *builtin_float = nullptr;
  struct type *builtin_double = nullptr;
  struct type *builtin_long_double = nullptr;
  struct type *builtin_complex = nullptr;
  struct type *builtin_double_complex = nullptr;
  struct type *builtin_string = nullptr;
  struct type *builtin_bool = nullptr;
  struct type *builtin_long_long = nullptr;
  struct type *builtin_unsigned_long_long = nullptr;
  struct type *builtin_decfloat = nullptr;
  struct type *builtin_decdouble = nullptr;
  struct type *builtin_declong = nullptr;

  /* "True" character types.
      We use these for the '/c' print format, because c_char is just a
      one-byte integral type, which languages less laid back than C
      will print as ... well, a one-byte integral type.  */
  struct type *builtin_true_char = nullptr;
  struct type *builtin_true_unsigned_char = nullptr;

  /* Explicit sizes - see C9X <intypes.h> for naming scheme.  The "int0"
     is for when an architecture needs to describe a register that has
     no size.  */
  struct type *builtin_int0 = nullptr;
  struct type *builtin_int8 = nullptr;
  struct type *builtin_uint8 = nullptr;
  struct type *builtin_int16 = nullptr;
  struct type *builtin_uint16 = nullptr;
  struct type *builtin_int24 = nullptr;
  struct type *builtin_uint24 = nullptr;
  struct type *builtin_int32 = nullptr;
  struct type *builtin_uint32 = nullptr;
  struct type *builtin_int64 = nullptr;
  struct type *builtin_uint64 = nullptr;
  struct type *builtin_int128 = nullptr;
  struct type *builtin_uint128 = nullptr;

  /* Wide character types.  */
  struct type *builtin_char16 = nullptr;
  struct type *builtin_char32 = nullptr;
  struct type *builtin_wchar = nullptr;

  /* Pointer types.  */

  /* * `pointer to data' type.  Some target platforms use an implicitly
     {sign,zero} -extended 32-bit ABI pointer on a 64-bit ISA.  */
  struct type *builtin_data_ptr = nullptr;

  /* * `pointer to function (returning void)' type.  Harvard
     architectures mean that ABI function and code pointers are not
     interconvertible.  Similarly, since ANSI, C standards have
     explicitly said that pointers to functions and pointers to data
     are not interconvertible --- that is, you can't cast a function
     pointer to void * and back, and expect to get the same value.
     However, all function pointer types are interconvertible, so void
     (*) () can server as a generic function pointer.  */

  struct type *builtin_func_ptr = nullptr;

  /* * `function returning pointer to function (returning void)' type.
     The final void return type is not significant for it.  */

  struct type *builtin_func_func = nullptr;

  /* Special-purpose types.  */

  /* * This type is used to represent a GDB internal function.  */

  struct type *internal_fn = nullptr;

  /* * This type is used to represent an xmethod.  */
  struct type *xmethod = nullptr;

  /* * This type is used to represent symbol addresses.  */
  struct type *builtin_core_addr = nullptr;

  /* * This type represents a type that was unrecognized in symbol
     read-in.  */
  struct type *builtin_error = nullptr;

  /* * Types used for symbols with no debug information.  */
  struct type *nodebug_text_symbol = nullptr;
  struct type *nodebug_text_gnu_ifunc_symbol = nullptr;
  struct type *nodebug_got_plt_symbol = nullptr;
  struct type *nodebug_data_symbol = nullptr;
  struct type *nodebug_unknown_symbol = nullptr;
  struct type *nodebug_tls_symbol = nullptr;
};

/* * Return the type table for the specified architecture.  */

extern const struct builtin_type *builtin_type (struct gdbarch *gdbarch);

/* * Return the type table for the specified objfile.  */

extern const struct builtin_type *builtin_type (struct objfile *objfile);
 
/* Explicit floating-point formats.  See "floatformat.h".  */
extern const struct floatformat *floatformats_ieee_half[BFD_ENDIAN_UNKNOWN];
extern const struct floatformat *floatformats_ieee_single[BFD_ENDIAN_UNKNOWN];
extern const struct floatformat *floatformats_ieee_double[BFD_ENDIAN_UNKNOWN];
extern const struct floatformat *floatformats_ieee_quad[BFD_ENDIAN_UNKNOWN];
extern const struct floatformat *floatformats_ieee_double_littlebyte_bigword[BFD_ENDIAN_UNKNOWN];
extern const struct floatformat *floatformats_i387_ext[BFD_ENDIAN_UNKNOWN];
extern const struct floatformat *floatformats_m68881_ext[BFD_ENDIAN_UNKNOWN];
extern const struct floatformat *floatformats_arm_ext[BFD_ENDIAN_UNKNOWN];
extern const struct floatformat *floatformats_ia64_spill[BFD_ENDIAN_UNKNOWN];
extern const struct floatformat *floatformats_vax_f[BFD_ENDIAN_UNKNOWN];
extern const struct floatformat *floatformats_vax_d[BFD_ENDIAN_UNKNOWN];
extern const struct floatformat *floatformats_ibm_long_double[BFD_ENDIAN_UNKNOWN];
extern const struct floatformat *floatformats_bfloat16[BFD_ENDIAN_UNKNOWN];

/* Allocate space for storing data associated with a particular
   type.  We ensure that the space is allocated using the same
   mechanism that was used to allocate the space for the type
   structure itself.  I.e.  if the type is on an objfile's
   objfile_obstack, then the space for data associated with that type
   will also be allocated on the objfile_obstack.  If the type is
   associated with a gdbarch, then the space for data associated with that
   type will also be allocated on the gdbarch_obstack.

   If a type is not associated with neither an objfile or a gdbarch then
   you should not use this macro to allocate space for data, instead you
   should call xmalloc directly, and ensure the memory is correctly freed
   when it is no longer needed.  */

#define TYPE_ALLOC(t,size)                                              \
  (obstack_alloc (((t)->is_objfile_owned ()                             \
		   ? &((t)->objfile_owner ()->objfile_obstack)          \
		   : gdbarch_obstack ((t)->arch_owner ())),             \
		  size))


/* See comment on TYPE_ALLOC.  */

#define TYPE_ZALLOC(t,size) (memset (TYPE_ALLOC (t, size), 0, size))

/* * This returns the target type (or NULL) of TYPE, also skipping
   past typedefs.  */

extern struct type *get_target_type (struct type *type);

/* Return the equivalent of TYPE_LENGTH, but in number of target
   addressable memory units of the associated gdbarch instead of bytes.  */

extern unsigned int type_length_units (struct type *type);

/* An object of this type is passed when allocating certain types.  It
   determines where the new type is allocated.  Ultimately a type is
   either allocated on a on an objfile obstack or on a gdbarch
   obstack.  However, it's also possible to request that a new type be
   allocated on the same obstack as some existing type, or that a
   "new" type instead overwrite a supplied type object.  */

class type_allocator
{
public:

  /* Create new types on OBJFILE.  */
  explicit type_allocator (objfile *objfile)
    : m_is_objfile (true)
  {
    m_data.objfile = objfile;
  }

  /* Create new types on GDBARCH.  */
  explicit type_allocator (gdbarch *gdbarch)
  {
    m_data.gdbarch = gdbarch;
  }

  /* This determines whether a passed-in type should be rewritten in
     place, or whether it should simply determine where the new type
     is created.  */
  enum type_allocator_kind
  {
    /* Allocate on same obstack as existing type.  */
    SAME = 0,
    /* Smash the existing type.  */
    SMASH = 1,
  };

  /* Create new types either on the same obstack as TYPE; or if SMASH
     is passed, overwrite TYPE.  */
  explicit type_allocator (struct type *type,
			   type_allocator_kind kind = SAME)
  {
    if (kind == SAME)
      {
	if (type->is_objfile_owned ())
	  {
	    m_data.objfile = type->objfile_owner ();
	    m_is_objfile = true;
	  }
	else
	  m_data.gdbarch = type->arch_owner ();
      }
    else
      {
	m_smash = true;
	m_data.type = type;
      }
  }

  /* Create new types on the same obstack as TYPE.  */
  explicit type_allocator (const struct type *type)
    : m_is_objfile (type->is_objfile_owned ())
  {
    if (type->is_objfile_owned ())
      m_data.objfile = type->objfile_owner ();
    else
      m_data.gdbarch = type->arch_owner ();
  }

  /* Create a new type on the desired obstack.  Note that a "new" type
     is not created if type-smashing was selected at construction.  */
  type *new_type ();

  /* Create a new type on the desired obstack, and fill in its code,
     length, and name.  If NAME is non-null, it is copied to the
     destination obstack first.  Note that a "new" type is not created
     if type-smashing was selected at construction.  */
  type *new_type (enum type_code code, int bit, const char *name);

  /* Return the architecture associated with this allocator.  This
     comes from whatever object was supplied to the constructor.  */
  gdbarch *arch ();

private:

  /* Where the type should wind up.  */
  union
  {
    struct objfile *objfile;
    struct gdbarch *gdbarch;
    struct type *type;
  } m_data {};

  /* True if this allocator uses the objfile field above.  */
  bool m_is_objfile = false;
  /* True if this allocator uses the type field above, indicating that
     the "allocation" should be done in-place.  */
  bool m_smash = false;
};

/* Allocate a TYPE_CODE_INT type structure using ALLOC.  BIT is the
   type size in bits.  If UNSIGNED_P is non-zero, set the type's
   TYPE_UNSIGNED flag.  NAME is the type name.  */

extern struct type *init_integer_type (type_allocator &alloc, int bit,
				       int unsigned_p, const char *name);

/* Allocate a TYPE_CODE_CHAR type structure using ALLOC.  BIT is the
   type size in bits.  If UNSIGNED_P is non-zero, set the type's
   TYPE_UNSIGNED flag.  NAME is the type name.  */

extern struct type *init_character_type (type_allocator &alloc, int bit,
					 int unsigned_p, const char *name);

/* Allocate a TYPE_CODE_BOOL type structure using ALLOC.  BIT is the
   type size in bits.  If UNSIGNED_P is non-zero, set the type's
   TYPE_UNSIGNED flag.  NAME is the type name.  */

extern struct type *init_boolean_type (type_allocator &alloc, int bit,
				       int unsigned_p, const char *name);

/* Allocate a TYPE_CODE_FLT type structure using ALLOC.
   BIT is the type size in bits; if BIT equals -1, the size is
   determined by the floatformat.  NAME is the type name.  Set the
   TYPE_FLOATFORMAT from FLOATFORMATS.  BYTE_ORDER is the byte order
   to use.  If it is BFD_ENDIAN_UNKNOWN (the default), then the byte
   order of the objfile's architecture is used.  */

extern struct type *init_float_type
     (type_allocator &alloc, int bit, const char *name,
      const struct floatformat **floatformats,
      enum bfd_endian byte_order = BFD_ENDIAN_UNKNOWN);

/* Allocate a TYPE_CODE_DECFLOAT type structure using ALLOC.
   BIT is the type size in bits.  NAME is the type name.  */

extern struct type *init_decfloat_type (type_allocator &alloc, int bit,
					const char *name);

extern bool can_create_complex_type (struct type *);
extern struct type *init_complex_type (const char *, struct type *);

/* Allocate a TYPE_CODE_PTR type structure using ALLOC.
   BIT is the pointer type size in bits.  NAME is the type name.
   TARGET_TYPE is the pointer target type.  Always sets the pointer type's
   TYPE_UNSIGNED flag.  */

extern struct type *init_pointer_type (type_allocator &alloc, int bit,
				       const char *name,
				       struct type *target_type);

extern struct type *init_fixed_point_type (struct objfile *, int, int,
					   const char *);

/* Helper functions to construct a struct or record type.  An
   initially empty type is created using arch_composite_type().
   Fields are then added using append_composite_type_field*().  A union
   type has its size set to the largest field.  A struct type has each
   field packed against the previous.  */

extern struct type *arch_composite_type (struct gdbarch *gdbarch,
					 const char *name, enum type_code code);
extern void append_composite_type_field (struct type *t, const char *name,
					 struct type *field);
extern void append_composite_type_field_aligned (struct type *t,
						 const char *name,
						 struct type *field,
						 int alignment);
struct field *append_composite_type_field_raw (struct type *t, const char *name,
					       struct type *field);

/* Helper functions to construct a bit flags type.  An initially empty
   type is created using arch_flag_type().  Flags are then added using
   append_flag_type_field() and append_flag_type_flag().  */
extern struct type *arch_flags_type (struct gdbarch *gdbarch,
				     const char *name, int bit);
extern void append_flags_type_field (struct type *type,
				     int start_bitpos, int nr_bits,
				     struct type *field_type, const char *name);
extern void append_flags_type_flag (struct type *type, int bitpos,
				    const char *name);

extern void make_vector_type (struct type *array_type);
extern struct type *init_vector_type (struct type *elt_type, int n);

extern struct type *lookup_reference_type (struct type *, enum type_code);
extern struct type *lookup_lvalue_reference_type (struct type *);
extern struct type *lookup_rvalue_reference_type (struct type *);


extern struct type *make_reference_type (struct type *, struct type **,
					 enum type_code);

extern struct type *make_cv_type (int, int, struct type *, struct type **);

extern struct type *make_restrict_type (struct type *);

extern struct type *make_unqualified_type (struct type *);

extern struct type *make_atomic_type (struct type *);

extern void replace_type (struct type *, struct type *);

extern type_instance_flags address_space_name_to_type_instance_flags
  (struct gdbarch *, const char *);

extern const char *address_space_type_instance_flags_to_name
  (struct gdbarch *, type_instance_flags);

extern struct type *make_type_with_address_space
  (struct type *type, type_instance_flags space_identifier);

extern struct type *lookup_memberptr_type (struct type *, struct type *);

extern struct type *lookup_methodptr_type (struct type *);

extern void smash_to_method_type (struct type *type, struct type *self_type,
				  struct type *to_type, struct field *args,
				  int nargs, int varargs);

extern void smash_to_memberptr_type (struct type *, struct type *,
				     struct type *);

extern void smash_to_methodptr_type (struct type *, struct type *);

extern const char *type_name_or_error (struct type *type);

struct struct_elt
{
  /* The field of the element, or NULL if no element was found.  */
  struct field *field;

  /* The bit offset of the element in the parent structure.  */
  LONGEST offset;
};

/* Given a type TYPE, lookup the field and offset of the component named
   NAME.

   TYPE can be either a struct or union, or a pointer or reference to
   a struct or union.  If it is a pointer or reference, its target
   type is automatically used.  Thus '.' and '->' are interchangable,
   as specified for the definitions of the expression element types
   STRUCTOP_STRUCT and STRUCTOP_PTR.

   If NOERR is nonzero, the returned structure will have field set to
   NULL if there is no component named NAME.

   If the component NAME is a field in an anonymous substructure of
   TYPE, the returned offset is a "global" offset relative to TYPE
   rather than an offset within the substructure.  */

extern struct_elt lookup_struct_elt (struct type *, const char *, int);

/* Given a type TYPE, lookup the type of the component named NAME.

   TYPE can be either a struct or union, or a pointer or reference to
   a struct or union.  If it is a pointer or reference, its target
   type is automatically used.  Thus '.' and '->' are interchangable,
   as specified for the definitions of the expression element types
   STRUCTOP_STRUCT and STRUCTOP_PTR.

   If NOERR is nonzero, return NULL if there is no component named
   NAME.  */

extern struct type *lookup_struct_elt_type (struct type *, const char *, int);

extern struct type *make_pointer_type (struct type *, struct type **);

extern struct type *lookup_pointer_type (struct type *);

extern struct type *make_function_type (struct type *, struct type **);

extern struct type *lookup_function_type (struct type *);

extern struct type *lookup_function_type_with_arguments (struct type *,
							 int,
							 struct type **);

/* Create a range type using ALLOC.

   Indices will be of type INDEX_TYPE, and will range from LOW_BOUND
   to HIGH_BOUND, inclusive.  */

extern struct type *create_static_range_type (type_allocator &alloc,
					      struct type *index_type,
					      LONGEST low_bound,
					      LONGEST high_bound);

/* Create an array type using ALLOC.

   Elements will be of type ELEMENT_TYPE, the indices will be of type
   RANGE_TYPE.

   BYTE_STRIDE_PROP, when not NULL, provides the array's byte stride.
   This byte stride property is added to the resulting array type
   as a DYN_PROP_BYTE_STRIDE.  As a consequence, the BYTE_STRIDE_PROP
   argument can only be used to create types that are objfile-owned
   (see add_dyn_prop), meaning that either this function must be called
   with an objfile-owned RESULT_TYPE, or an objfile-owned RANGE_TYPE.

   BIT_STRIDE is taken into account only when BYTE_STRIDE_PROP is NULL.
   If BIT_STRIDE is not zero, build a packed array type whose element
   size is BIT_STRIDE.  Otherwise, ignore this parameter.  */

extern struct type *create_array_type_with_stride
     (type_allocator &alloc, struct type *element_type,
      struct type *range_type, struct dynamic_prop *byte_stride_prop,
      unsigned int bit_stride);

/* Create a range type using ALLOC with a dynamic range from LOW_BOUND
   to HIGH_BOUND, inclusive.  INDEX_TYPE is the underlying type.  BIAS
   is the bias to be applied when storing or retrieving values of this
   type.  */

extern struct type *create_range_type (type_allocator &alloc,
				       struct type *index_type,
				       const struct dynamic_prop *low_bound,
				       const struct dynamic_prop *high_bound,
				       LONGEST bias);

/* Like CREATE_RANGE_TYPE but also sets up a stride.  When BYTE_STRIDE_P
   is true the value in STRIDE is a byte stride, otherwise STRIDE is a bit
   stride.  */

extern struct type *create_range_type_with_stride
  (type_allocator &alloc, struct type *index_type,
   const struct dynamic_prop *low_bound,
   const struct dynamic_prop *high_bound, LONGEST bias,
   const struct dynamic_prop *stride, bool byte_stride_p);

/* Same as create_array_type_with_stride but with no bit_stride
   (BIT_STRIDE = 0), thus building an unpacked array.  */

extern struct type *create_array_type (type_allocator &alloc,
				       struct type *element_type,
				       struct type *range_type);

extern struct type *lookup_array_range_type (struct type *, LONGEST, LONGEST);

/* Create a string type using ALLOC.  String types are similar enough
   to array of char types that we can use create_array_type to build
   the basic type and then bash it into a string type.

   For fixed length strings, the range type contains 0 as the lower
   bound and the length of the string minus one as the upper bound.  */

extern struct type *create_string_type (type_allocator &alloc,
					struct type *string_char_type,
					struct type *range_type);

extern struct type *lookup_string_range_type (struct type *, LONGEST, LONGEST);

extern struct type *create_set_type (type_allocator &alloc,
				     struct type *domain_type);

extern struct type *lookup_unsigned_typename (const struct language_defn *,
					      const char *);

extern struct type *lookup_signed_typename (const struct language_defn *,
					    const char *);

extern ULONGEST get_unsigned_type_max (struct type *);

extern void get_signed_type_minmax (struct type *, LONGEST *, LONGEST *);

extern CORE_ADDR get_pointer_type_max (struct type *);

/* * Resolve all dynamic values of a type e.g. array bounds to static values.
   ADDR specifies the location of the variable the type is bound to.
   If TYPE has no dynamic properties return TYPE; otherwise a new type with
   static properties is returned.

   If FRAME is given, it is used when evaluating dynamic properties.
   This can be important when a static link is seen.  If not given,
   the selected frame is used.

   For an array type, if the element type is dynamic, then that will
   not be resolved.  This is done because each individual element may
   have a different type when resolved (depending on the contents of
   memory).  In this situation, 'is_dynamic_type' will still return
   true for the return value of this function.  */
extern struct type *resolve_dynamic_type
  (struct type *type, gdb::array_view<const gdb_byte> valaddr,
   CORE_ADDR addr, const frame_info_ptr *frame = nullptr);

/* * Predicate if the type has dynamic values, which are not resolved yet.
   See the caveat in 'resolve_dynamic_type' to understand a scenario
   where an apparently-resolved type may still be considered
   "dynamic".  */
extern int is_dynamic_type (struct type *type);

extern struct type *check_typedef (struct type *);

extern void check_stub_method_group (struct type *, int);

extern char *gdb_mangle_name (struct type *, int, int);

extern struct type *lookup_typename (const struct language_defn *,
				     const char *, const struct block *, int);

extern struct type *lookup_template_type (const char *, struct type *,
					  const struct block *);

extern int get_vptr_fieldno (struct type *, struct type **);

/* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type
   TYPE.

   Return true if the two bounds are available, false otherwise.  */

extern bool get_discrete_bounds (struct type *type, LONGEST *lowp,
				 LONGEST *highp);

/* If TYPE's low bound is a known constant, return it, else return nullopt.  */

extern gdb::optional<LONGEST> get_discrete_low_bound (struct type *type);

/* If TYPE's high bound is a known constant, return it, else return nullopt.  */

extern gdb::optional<LONGEST> get_discrete_high_bound (struct type *type);

/* Assuming TYPE is a simple, non-empty array type, compute its upper
   and lower bound.  Save the low bound into LOW_BOUND if not NULL.
   Save the high bound into HIGH_BOUND if not NULL.

   Return true if the operation was successful.  Return false otherwise,
   in which case the values of LOW_BOUND and HIGH_BOUNDS are unmodified.  */

extern bool get_array_bounds (struct type *type, LONGEST *low_bound,
			      LONGEST *high_bound);

extern gdb::optional<LONGEST> discrete_position (struct type *type,
						 LONGEST val);

extern int class_types_same_p (const struct type *, const struct type *);

extern int is_ancestor (struct type *, struct type *);

extern int is_public_ancestor (struct type *, struct type *);

extern int is_unique_ancestor (struct type *, struct value *);

/* Overload resolution */

/* * Badness if parameter list length doesn't match arg list length.  */
extern const struct rank LENGTH_MISMATCH_BADNESS;

/* * Dummy badness value for nonexistent parameter positions.  */
extern const struct rank TOO_FEW_PARAMS_BADNESS;
/* * Badness if no conversion among types.  */
extern const struct rank INCOMPATIBLE_TYPE_BADNESS;

/* * Badness of an exact match.  */
extern const struct rank EXACT_MATCH_BADNESS;

/* * Badness of integral promotion.  */
extern const struct rank INTEGER_PROMOTION_BADNESS;
/* * Badness of floating promotion.  */
extern const struct rank FLOAT_PROMOTION_BADNESS;
/* * Badness of converting a derived class pointer
   to a base class pointer.  */
extern const struct rank BASE_PTR_CONVERSION_BADNESS;
/* * Badness of integral conversion.  */
extern const struct rank INTEGER_CONVERSION_BADNESS;
/* * Badness of floating conversion.  */
extern const struct rank FLOAT_CONVERSION_BADNESS;
/* * Badness of integer<->floating conversions.  */
extern const struct rank INT_FLOAT_CONVERSION_BADNESS;
/* * Badness of conversion of pointer to void pointer.  */
extern const struct rank VOID_PTR_CONVERSION_BADNESS;
/* * Badness of conversion to boolean.  */
extern const struct rank BOOL_CONVERSION_BADNESS;
/* * Badness of converting derived to base class.  */
extern const struct rank BASE_CONVERSION_BADNESS;
/* * Badness of converting from non-reference to reference.  Subrank
   is the type of reference conversion being done.  */
extern const struct rank REFERENCE_CONVERSION_BADNESS;
extern const struct rank REFERENCE_SEE_THROUGH_BADNESS;
/* * Conversion to rvalue reference.  */
#define REFERENCE_CONVERSION_RVALUE 1
/* * Conversion to const lvalue reference.  */
#define REFERENCE_CONVERSION_CONST_LVALUE 2

/* * Badness of converting integer 0 to NULL pointer.  */
extern const struct rank NULL_POINTER_CONVERSION;
/* * Badness of cv-conversion.  Subrank is a flag describing the conversions
   being done.  */
extern const struct rank CV_CONVERSION_BADNESS;
#define CV_CONVERSION_CONST 1
#define CV_CONVERSION_VOLATILE 2

/* Non-standard conversions allowed by the debugger */

/* * Converting a pointer to an int is usually OK.  */
extern const struct rank NS_POINTER_CONVERSION_BADNESS;

/* * Badness of converting a (non-zero) integer constant
   to a pointer.  */
extern const struct rank NS_INTEGER_POINTER_CONVERSION_BADNESS;

extern struct rank sum_ranks (struct rank a, struct rank b);
extern int compare_ranks (struct rank a, struct rank b);

extern int compare_badness (const badness_vector &,
			    const badness_vector &);

extern badness_vector rank_function (gdb::array_view<type *> parms,
				     gdb::array_view<value *> args);

extern struct rank rank_one_type (struct type *, struct type *,
				  struct value *);

extern void recursive_dump_type (struct type *, int);

/* printcmd.c */

extern void print_scalar_formatted (const gdb_byte *, struct type *,
				    const struct value_print_options *,
				    int, struct ui_file *);

extern int can_dereference (struct type *);

extern int is_integral_type (struct type *);

extern int is_floating_type (struct type *);

extern int is_scalar_type (struct type *type);

extern int is_scalar_type_recursive (struct type *);

extern int class_or_union_p (const struct type *);

extern void maintenance_print_type (const char *, int);

extern htab_up create_copied_types_hash ();

extern struct type *copy_type_recursive (struct type *type,
					 htab_t copied_types);

extern struct type *copy_type (const struct type *type);

extern bool types_equal (struct type *, struct type *);

extern bool types_deeply_equal (struct type *, struct type *);

extern int type_not_allocated (const struct type *type);

extern int type_not_associated (const struct type *type);

/* Return True if TYPE is a TYPE_CODE_FIXED_POINT or if TYPE is
   a range type whose base type is a TYPE_CODE_FIXED_POINT.  */
extern bool is_fixed_point_type (struct type *type);

/* Allocate a fixed-point type info for TYPE.  This should only be
   called by INIT_FIXED_POINT_SPECIFIC.  */
extern void allocate_fixed_point_type_info (struct type *type);

/* * When the type includes explicit byte ordering, return that.
   Otherwise, the byte ordering from gdbarch_byte_order for
   the type's arch is returned.  */

extern enum bfd_endian type_byte_order (const struct type *type);

/* A flag to enable printing of debugging information of C++
   overloading.  */

extern unsigned int overload_debug;

/* Return whether the function type represented by TYPE is marked as unsafe
   to call by the debugger.

   This usually indicates that the function does not follow the target's
   standard calling convention.  */

extern bool is_nocall_function (const struct type *type);

#endif /* GDBTYPES_H */