This file is indexed.

/usr/share/ada/adainclude/asis/asis-declarations.adb is in libasis2014-dev 2014-4.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   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
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
------------------------------------------------------------------------------
--                                                                          --
--                 ASIS-for-GNAT IMPLEMENTATION COMPONENTS                  --
--                                                                          --
--                                                                          --
--                    A S I S . D E C L A R A T I O N S                     --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
--            Copyright (C) 1995-2014, Free Software Foundation, Inc.       --
--                                                                          --
-- ASIS-for-GNAT is free software; you can redistribute it and/or modify it --
-- under terms of the  GNU General Public License  as published by the Free --
-- Software  Foundation;  either version 3,  or (at your option)  any later --
-- version.  ASIS-for-GNAT  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.                     --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
-- You should have  received  a copy of the  GNU General Public License and --
-- a copy of the  GCC Runtime Library Exception  distributed with GNAT; see --
-- the files COPYING3 and COPYING.RUNTIME respectively.  If not, see        --
-- <http://www.gnu.org/licenses/>.                                          --
--                                                                          --
-- ASIS-for-GNAT was originally developed  by the ASIS-for-GNAT team at the --
-- Software  Engineering  Laboratory  of  the Swiss  Federal  Institute  of --
-- Technology (LGL-EPFL) in Lausanne,  Switzerland, in cooperation with the --
-- Scientific  Research  Computer  Center of  Moscow State University (SRCC --
-- MSU), Russia,  with funding partially provided  by grants from the Swiss --
-- National  Science  Foundation  and  the  Swiss  Academy  of  Engineering --
-- Sciences.  ASIS-for-GNAT is now maintained by  AdaCore                   --
-- (http://www.adacore.com).                                                --
--                                                                          --
------------------------------------------------------------------------------

pragma Ada_2012;

with Ada.Characters.Handling; use Ada.Characters.Handling;
with Ada.Strings;             use Ada.Strings;
with Ada.Strings.Fixed;       use Ada.Strings.Fixed;

with Asis.Compilation_Units;  use Asis.Compilation_Units;
with Asis.Elements;           use Asis.Elements;
with Asis.Errors;             use Asis.Errors;
with Asis.Exceptions;         use Asis.Exceptions;
with Asis.Expressions;
with Asis.Extensions;         use Asis.Extensions;
with Asis.Limited_Views;      use Asis.Limited_Views;

with Asis.Set_Get;            use  Asis.Set_Get;

with A4G.A_Sem;               use A4G.A_Sem;
with A4G.A_Sinput;            use A4G.A_Sinput;
with A4G.Asis_Tables;         use A4G.Asis_Tables;
with A4G.Contt.TT;            use A4G.Contt.TT;
with A4G.Contt.UT;            use A4G.Contt.UT; use A4G.Contt;
with A4G.Decl_Sem;            use A4G.Decl_Sem;
with A4G.Mapping;             use A4G.Mapping;
with A4G.Norm;                use A4G.Norm;
with A4G.Span_End;            use A4G.Span_End;
with A4G.Stand;               use A4G.Stand;
with A4G.Vcheck;              use A4G.Vcheck;

with Aspects;                 use Aspects;
with Atree;                   use Atree;
with Einfo;                   use Einfo;
with Namet;                   use Namet;
with Nlists;                  use Nlists;
with Sem_Aux;                 use Sem_Aux;
with Sinfo;                   use Sinfo;
with Snames;                  use Snames;
with Stand;                   use Stand;
with Uintp;                   use Uintp;

package body Asis.Declarations is

   Package_Name : constant String := "Asis.Declarations.";

   -----------------------
   -- ASIS 2012 queries --
   -----------------------

   ---------------------------
   -- Aspect_Specifications --
   ---------------------------

   function Aspect_Specifications
     (Declaration : Asis.Element)
      return        Asis.Element_List
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Declaration);
      Arg_Node :          Node_Id;
      Result   :          List_Id;
   begin
      Check_Validity
        (Declaration, Package_Name & "Aspect_Specifications");

      if Arg_Kind not in Internal_Declaration_Kinds then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Aspect_Specifications",
            Wrong_Kind => Arg_Kind);
      end if;

      Arg_Node := Node (Declaration);

      --  In some cases, the Arg_Node has no aspects, but the R_Node does

      if Has_Aspects (Arg_Node) then
         Result := Aspect_Specifications (Arg_Node);
      else
         Arg_Node := R_Node (Declaration);

         if Has_Aspects (Arg_Node) then
            Result := Aspect_Specifications (Arg_Node);
         else
            return Nil_Element_List;
         end if;
      end if;

      return N_To_E_List_New
        (List             => Result,
         Internal_Kind    => An_Aspect_Specification,
         Starting_Element => Declaration);
   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information
              (Argument   => Declaration,
               Outer_Call => Package_Name & "Aspect_Specifications");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Aspect_Specifications",
            Ex          => Ex,
            Arg_Element => Declaration);
   end Aspect_Specifications;

   -----------------------
   -- Result_Expression --
   -----------------------

   function Result_Expression
     (Declaration :  Asis.Declaration)
      return        Asis.Expression
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Declaration);
      Res_Node :          Node_Id;
   begin
      Check_Validity
        (Declaration, Package_Name & "Result_Expression");

      if Arg_Kind /= An_Expression_Function_Declaration  then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Result_Expression",
            Wrong_Kind => Arg_Kind);
      end if;

      Res_Node := R_Node (Declaration);

      if Nkind (Res_Node) = N_Subprogram_Declaration then
         Res_Node := Parent (Parent (Corresponding_Body (Res_Node)));
      end if;

      Res_Node := First (Statements (Handled_Statement_Sequence (Res_Node)));

      while Nkind (Res_Node) /= N_Simple_Return_Statement loop
         Res_Node := Next (Res_Node);
      end loop;

      Res_Node := Sinfo.Expression (Res_Node);

      return Node_To_Element_New
               (Node             => Res_Node,
                Starting_Element => Declaration);

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information
              (Argument   => Declaration,
               Outer_Call => Package_Name & "Result_Expression");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Result_Expression",
            Ex          => Ex,
            Arg_Element => Declaration);
   end Result_Expression;

   -----------------------
   -- ASIS 2005 queries --
   -----------------------

   --------------------------------
   -- Declaration_Interface_List --
   --------------------------------

   function Declaration_Interface_List
     (Declaration : Asis.Definition)
      return        Asis.Expression_List
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Declaration);
      Arg_Node :          Node_Id;
   begin

      Check_Validity
        (Declaration, Package_Name & "Declaration_Interface_List");

      if not (Arg_Kind = A_Task_Type_Declaration         or else
              Arg_Kind = A_Protected_Type_Declaration    or else
              Arg_Kind = A_Single_Task_Declaration       or else
              Arg_Kind = A_Single_Protected_Declaration)
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Declaration_Interface_List",
            Wrong_Kind => Arg_Kind);
      end if;

      Arg_Node := Node (Declaration);

      return N_To_E_List_New (List             => Interface_List (Arg_Node),
                              Starting_Element => Declaration);
   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information
              (Argument   => Declaration,
               Outer_Call => Package_Name & "Declaration_Interface_List");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Declaration_Interface_List",
            Ex          => Ex,
            Arg_Element => Declaration);
   end Declaration_Interface_List;

   -------------------------------
   -- Is_Overriding_Declaration --
   -------------------------------

   function Is_Overriding_Declaration
    (Declaration : Asis.Declaration)
     return        Boolean
   is
      Arg_Kind   : constant Internal_Element_Kinds := Int_Kind (Declaration);
      Check_Node : Node_Id;
      Result     :          Boolean                := False;
   begin

      Check_Validity (Declaration, Package_Name & "Is_Overriding_Declaration");

      if Arg_Kind = A_Procedure_Declaration            or else
         Arg_Kind = A_Function_Declaration             or else
         Arg_Kind = An_Expression_Function_Declaration or else
         Arg_Kind = A_Procedure_Body_Declaration       or else
         Arg_Kind = A_Function_Body_Declaration        or else
         Arg_Kind = A_Null_Procedure_Declaration       or else
         Arg_Kind = A_Procedure_Renaming_Declaration   or else
         Arg_Kind = A_Function_Renaming_Declaration    or else
         Arg_Kind = An_Entry_Declaration               or else
         Arg_Kind = A_Procedure_Body_Stub              or else
         Arg_Kind = A_Function_Body_Stub               or else
         Arg_Kind = A_Procedure_Instantiation          or else
         Arg_Kind = A_Function_Instantiation
      then
         Check_Node := Node (Declaration);

         case Arg_Kind is
            when A_Procedure_Declaration            |
                 A_Function_Declaration             |
                 An_Expression_Function_Declaration |
                 A_Procedure_Body_Declaration       |
                 A_Function_Body_Declaration        |
                 A_Procedure_Body_Stub              |
                 A_Function_Body_Stub               |
                 A_Procedure_Renaming_Declaration   |
                 A_Function_Renaming_Declaration    |
                 A_Null_Procedure_Declaration     =>
               Check_Node := Specification (Check_Node);
            when others =>
               null;
         end case;

         Result := Must_Override (Check_Node);
      end if;

      return Result;
   end Is_Overriding_Declaration;

   -----------------------------------
   -- Is_Not_Overriding_Declaration --
   -----------------------------------

   function Is_Not_Overriding_Declaration
     (Declaration : Asis.Declaration)
      return        Boolean
   is
      Arg_Kind   : constant Internal_Element_Kinds := Int_Kind (Declaration);
      Check_Node : Node_Id;
      Result     : Boolean                         := False;
   begin

      Check_Validity
        (Declaration, Package_Name & "Is_Not_Overriding_Declaration");

      if Arg_Kind = A_Procedure_Declaration            or else
         Arg_Kind = A_Function_Declaration             or else
         Arg_Kind = An_Expression_Function_Declaration or else
         Arg_Kind = A_Procedure_Body_Declaration       or else
         Arg_Kind = A_Function_Body_Declaration        or else
         Arg_Kind = A_Null_Procedure_Declaration       or else
         Arg_Kind = A_Procedure_Renaming_Declaration   or else
         Arg_Kind = A_Function_Renaming_Declaration    or else
         Arg_Kind = An_Entry_Declaration               or else
         Arg_Kind = A_Procedure_Body_Stub              or else
         Arg_Kind = A_Function_Body_Stub               or else
         Arg_Kind = A_Procedure_Instantiation          or else
         Arg_Kind = A_Function_Instantiation
      then

         Check_Node := Node (Declaration);

         case Arg_Kind is
            when A_Procedure_Declaration            |
                 A_Function_Declaration             |
                 An_Expression_Function_Declaration |
                 A_Procedure_Body_Declaration       |
                 A_Function_Body_Declaration        |
                 A_Procedure_Body_Stub              |
                 A_Function_Body_Stub               |
                 A_Procedure_Renaming_Declaration   |
                 A_Function_Renaming_Declaration    |
                 A_Null_Procedure_Declaration     =>
               Check_Node := Specification (Check_Node);
            when others =>
               null;
         end case;

         Result := Must_Not_Override (Check_Node);
      end if;

      return Result;
   end Is_Not_Overriding_Declaration;

------------------------------------------------------------------------------

   ------------------------------------
   -- Corresponding_Type_Declaration --
   ------------------------------------

   function Corresponding_Type_Declaration
     (Declaration : Asis.Declaration)
      return        Asis.Declaration
   is
      Arg_Kind    : constant Internal_Element_Kinds := Int_Kind (Declaration);
      Arg_Node    : Node_Id;
      Arg_Unit    : Asis.Compilation_Unit;
      Entity_Node : Node_Id;
      Result_Node : Node_Id;
      Result_Unit : Asis.Compilation_Unit := Nil_Compilation_Unit;
      Arg_Element : Asis.Declaration;
   begin
      Check_Validity
       (Declaration,
        Package_Name & "Corresponding_Type_Declaration");

      if not (Arg_Kind = An_Ordinary_Type_Declaration         or else
              Arg_Kind = A_Task_Type_Declaration              or else
              Arg_Kind = A_Protected_Type_Declaration         or else
              Arg_Kind = An_Incomplete_Type_Declaration       or else
--  |A2005 start
              Arg_Kind = A_Tagged_Incomplete_Type_Declaration or else
--  |A2005 end
              Arg_Kind = A_Private_Type_Declaration           or else
              Arg_Kind = A_Private_Extension_Declaration)
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Corresponding_Type_Declaration",
            Wrong_Kind => Arg_Kind);
      end if;

      if Arg_Kind in A_Private_Type_Declaration ..
                     A_Private_Extension_Declaration
        and then
         not Is_Nil (Corresponding_Type_Completion (Declaration))
        and then
         not Is_Nil (Corresponding_Type_Partial_View (Declaration))
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name &
            "Corresponding_Type_Declaration - obsolescent for Ada 2012",
            Wrong_Kind => Arg_Kind);
      end if;

      --  this query can cross compilation unit boundaries for an
      --  incomplete type defined in the private part of a library
      --  package spec and completed in the package body.

      Arg_Node := R_Node (Declaration);

      if Sloc (Arg_Node) <= Standard_Location then
         --  No private/incomplete declaration in Standard!
         return Nil_Element;
      end if;

      Entity_Node := Defining_Identifier (Arg_Node);
      Arg_Unit := Get_Comp_Unit
        (Encl_Unit_Id (Declaration), Encl_Cont_Id (Declaration));

      if Arg_Kind = An_Incomplete_Type_Declaration       or else
         Arg_Kind = A_Private_Type_Declaration           or else
--  |A2005 start
         Arg_Kind = A_Tagged_Incomplete_Type_Declaration or else
--  |A2005 end
         Arg_Kind = A_Private_Extension_Declaration
      then
         --  finding the full view for incomplete/private type
         Result_Node := Full_View (Entity_Node);

         if No (Result_Node) then
            --  for a legal Ada unit it is possible only for
            --  An_Incomplete_Type_Declaration in the private part of a
            --  package, provided that enclosing unit is a library package or
            --  a library generic package.

            Result_Unit := Corresponding_Body (Arg_Unit);

            if not Exists (Result_Unit) then
               return Nil_Element;
            else
               Arg_Element := Declaration;
               Reset_For_Body (Arg_Element, Result_Unit);
               Arg_Node := R_Node (Arg_Element);
               Entity_Node := Defining_Identifier (Arg_Node);
               Result_Node := Full_View (Entity_Node);
            end if;
         end if;
      else
         --  trying to find the private/incomplete view, if any

         Result_Node := Search_First_View (Entity_Node);

         if Result_Node = Entity_Node then
            --  no private/incomplete view, therefore:
            return Nil_Element;
         end if;

      end if;

      --  and, finally, one step up from the defining name to the
      --  corresponding type declaration
      Result_Node := Parent (Result_Node);

      --  if we are here, Result_Node is not Empty!
      pragma Assert (Present (Result_Node));

      if not Exists (Result_Unit) then
         Result_Unit :=
            Enclosing_Unit (Encl_Cont_Id (Declaration), Result_Node);
      end if;

      return Node_To_Element_New (Node    => Result_Node,
                                  In_Unit => Result_Unit);
   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Declaration,
               Outer_Call => Package_Name & "Corresponding_Type_Declaration");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Corresponding_Type_Declaration",
            Ex          => Ex,
            Arg_Element => Declaration);
   end Corresponding_Type_Declaration;

--  --|A2010 start

   -----------------------------------
   -- Corresponding_Type_Completion --
   -----------------------------------

   function Corresponding_Type_Completion
     (Declaration : Asis.Declaration)
      return        Asis.Declaration
   is
      Arg_Kind    : constant Internal_Element_Kinds := Int_Kind (Declaration);
      Arg_Node    : Node_Id;
      Arg_Unit    : Asis.Compilation_Unit;
      Entity_Node : Node_Id;
      Result_Node : Node_Id;
      Result_Unit : Asis.Compilation_Unit := Nil_Compilation_Unit;
      Arg_Element : Asis.Declaration;
   begin
      Check_Validity
       (Declaration,
        Package_Name & "Corresponding_Type_Completion");

      if not (Arg_Kind = An_Incomplete_Type_Declaration       or else
              Arg_Kind = A_Tagged_Incomplete_Type_Declaration or else
              Arg_Kind = A_Private_Type_Declaration           or else
              Arg_Kind = A_Private_Extension_Declaration)
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Corresponding_Type_Completion",
            Wrong_Kind => Arg_Kind);
      end if;

      --  this query can cross compilation unit boundaries for an
      --  incomplete type defined in the private part of a library
      --  package spec and completed in the package body.

      Arg_Node := R_Node (Declaration);

      if Sloc (Arg_Node) <= Standard_Location then
         --  No private/incomplete declaration in Standard!
         return Nil_Element;
      end if;

      Entity_Node := Defining_Identifier (Arg_Node);
      Arg_Unit := Get_Comp_Unit
        (Encl_Unit_Id (Declaration), Encl_Cont_Id (Declaration));

      Result_Node := Full_View (Entity_Node);

      if No (Result_Node) then
         --  for a legal Ada unit it is possible only for
         --  An_Incomplete_Type_Declaration in the private part of a
         --  package, provided that enclosing unit is a library package or
         --  a library generic package.

         Result_Unit := Corresponding_Body (Arg_Unit);

         if not Exists (Result_Unit) then
            return Nil_Element;
         else
            Arg_Element := Declaration;
            Reset_For_Body (Arg_Element, Result_Unit);
            Arg_Node := R_Node (Arg_Element);
            Entity_Node := Defining_Identifier (Arg_Node);
            Result_Node := Full_View (Entity_Node);
         end if;
      end if;

      --  one step up from the defining name to the corresponding type
      --  declaration
      Result_Node := Parent (Result_Node);

      --  if we are here, Result_Node is not Empty!
      pragma Assert (Present (Result_Node));

      if not Exists (Result_Unit) then
         Result_Unit :=
            Enclosing_Unit (Encl_Cont_Id (Declaration), Result_Node);
      end if;

      return Node_To_Element_New (Node    => Result_Node,
                                  In_Unit => Result_Unit);
   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Declaration,
               Outer_Call => Package_Name & "Corresponding_Type_Completion");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Corresponding_Type_Completion",
            Ex          => Ex,
            Arg_Element => Declaration);
   end Corresponding_Type_Completion;

   -------------------------------------
   -- Corresponding_Type_Partial_View --
   -------------------------------------

   function Corresponding_Type_Partial_View
     (Declaration : Asis.Declaration)
      return        Asis.Declaration
   is
      Arg_Kind    : constant Internal_Element_Kinds := Int_Kind (Declaration);
      Arg_Node    : Node_Id;
      Arg_Unit    : Asis.Compilation_Unit;
      pragma Unreferenced (Arg_Unit);
      Entity_Node : Node_Id;
      Result_Node : Node_Id;
      Result_Unit : Asis.Compilation_Unit := Nil_Compilation_Unit;
   begin
      Check_Validity
       (Declaration,
        Package_Name & "Corresponding_Type_Partial_View");

      if not (Arg_Kind = An_Ordinary_Type_Declaration         or else
              Arg_Kind = A_Task_Type_Declaration              or else
              Arg_Kind = A_Protected_Type_Declaration         or else
              Arg_Kind = A_Private_Type_Declaration           or else
              Arg_Kind = A_Private_Extension_Declaration)
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Corresponding_Type_Partial_View",
            Wrong_Kind => Arg_Kind);
      end if;

      Arg_Node := R_Node (Declaration);

      if Sloc (Arg_Node) <= Standard_Location then
         --  No private/incomplete declaration in Standard!
         return Nil_Element;
      end if;

      Entity_Node := Defining_Identifier (Arg_Node);
      Arg_Unit := Get_Comp_Unit
        (Encl_Unit_Id (Declaration), Encl_Cont_Id (Declaration));

      Result_Node := Search_First_View (Entity_Node);

      if Result_Node = Entity_Node then
         --  no private/incomplete view, therefore:
         return Nil_Element;
      end if;

      --  one step up from the defining name to the corresponding type
      --  declaration
      Result_Node := Parent (Result_Node);

      --  if we are here, Result_Node is not Empty!
      pragma Assert (Present (Result_Node));

      if not Exists (Result_Unit) then
         Result_Unit :=
            Enclosing_Unit (Encl_Cont_Id (Declaration), Result_Node);
      end if;

      return Node_To_Element_New (Node    => Result_Node,
                                  In_Unit => Result_Unit);
   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Declaration,
               Outer_Call => Package_Name & "Corresponding_Type_Partial_View");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Corresponding_Type_Partial_View",
            Ex          => Ex,
            Arg_Element => Declaration);
   end Corresponding_Type_Partial_View;

--  --|A2010 end

   -----------------------
   -- Discriminant_Part --
   -----------------------

   function Discriminant_Part
     (Declaration : Asis.Declaration)
      return        Asis.Definition
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Declaration);
      Arg_Node : Node_Id;

      Result   : Element := Nil_Element;
   begin
      Check_Validity (Declaration, Package_Name & "Discriminant_Part");

      if not (Arg_Kind = An_Ordinary_Type_Declaration          or else
              Arg_Kind = A_Task_Type_Declaration               or else
              Arg_Kind = A_Protected_Type_Declaration          or else
              Arg_Kind = An_Incomplete_Type_Declaration        or else
--  |A2005 start
              Arg_Kind = A_Tagged_Incomplete_Type_Declaration  or else
--  |A2005 end
             Arg_Kind = A_Private_Type_Declaration             or else
             Arg_Kind = A_Private_Extension_Declaration        or else
             Arg_Kind = A_Formal_Type_Declaration              or else
--  |A2012 start
              Arg_Kind = A_Formal_Incomplete_Type_Declaration)
--  |A2012 end
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Discriminant_Part",
            Wrong_Kind => Arg_Kind);
      end if;

      if Special_Case (Declaration) = From_Limited_View then
         --  See Ada2012-B108
         return Nil_Element;
      end if;

      --  There is no appropriate Node in the tree to map the Asis Element
      --  of the An_Unknown_Discriminant_Part or A_Known_Discriminant_Part
      --  Definition_Kinds values. So the (non-nil) result of this function
      --  contains just the same value in the field Node as the argument,
      --  but it differs in the value of the Internal_Kind fields.

      Arg_Node := Node (Declaration);

      if Present (Arg_Node) then

         if Present (Discriminant_Specifications (Arg_Node)) then
            Result := Declaration;
            Set_Int_Kind (Result, A_Known_Discriminant_Part);

         elsif not (Arg_Kind = An_Ordinary_Type_Declaration or else
                    Arg_Kind = A_Task_Type_Declaration      or else
                    Arg_Kind = A_Protected_Type_Declaration)
            and then
               Unknown_Discriminants_Present (Arg_Node)
         then
            Result := Declaration;
            Set_Int_Kind (Result, An_Unknown_Discriminant_Part);
         end if;

      end if;

      return Result;
   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Declaration,
               Outer_Call => Package_Name & "Discriminant_Part");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Discriminant_Part",
            Ex          => Ex,
            Arg_Element => Declaration);
   end Discriminant_Part;

   -----------
   -- Names --
   -----------

   function Names
     (Declaration : Asis.Declaration)
      return        Asis.Defining_Name_List
   is
      Arg_Node    : Node_Id;
      Decl_Kind   : constant Internal_Element_Kinds := Int_Kind (Declaration);
      Result_Node : Node_Id;
      Result_Kind : Internal_Element_Kinds := Not_An_Element;

      Result_Elem : Element;
   begin
      Check_Validity (Declaration, Package_Name & "Names");

      if not (Decl_Kind in Internal_Declaration_Kinds) then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Names",
            Wrong_Kind => Decl_Kind);
      end if;

      Arg_Node := Node (Declaration);

      case Internal_Declaration_Kinds (Decl_Kind) is

         when An_Ordinary_Type_Declaration =>

            Result_Node := R_Node (Declaration);

            if No (Result_Node) then
               --  The declaration of a root or universal numeric type,
               --  the type is anonymous, so the result should be nil
               return Nil_Element_List;
            end if;

            Result_Node := Defining_Identifier (Result_Node);
            Result_Kind := A_Defining_Identifier;

         when A_Variable_Declaration          |
              A_Constant_Declaration          |
              A_Deferred_Constant_Declaration |
              An_Integer_Number_Declaration   |
              A_Real_Number_Declaration       |
              A_Discriminant_Specification    |
              A_Component_Declaration         |
              An_Exception_Declaration        |
              A_Formal_Object_Declaration     =>

            if Is_From_Inherited (Declaration) then
               Result_Elem := Node_To_Element_New
                 (Starting_Element => Declaration,
                  Node             => Node_Field_2 (Declaration));

               return (1 => Result_Elem);
            else
               return Defining_Id_List_From_Normalized
                        (N                => Arg_Node,
                         From_Declaration => Declaration);
            end if;

         when A_Parameter_Specification =>

            return Defining_Id_List_From_Normalized
                     (N                => Arg_Node,
                      From_Declaration => Declaration);

         when A_Task_Type_Declaration                |
              A_Protected_Type_Declaration           |
              An_Incomplete_Type_Declaration         |
--  --|A2005 start
              A_Tagged_Incomplete_Type_Declaration   |
              A_Return_Variable_Specification        |
              A_Return_Constant_Specification        |
--  --|A2005 end
              A_Private_Type_Declaration             |
              A_Private_Extension_Declaration        |
              A_Subtype_Declaration                  |
              A_Single_Task_Declaration              |
              A_Single_Protected_Declaration         |
              A_Loop_Parameter_Specification         |
              A_Generalized_Iterator_Specification   |
              An_Element_Iterator_Specification      |
              An_Object_Renaming_Declaration         |
              A_Task_Body_Declaration                |
              A_Protected_Body_Declaration           |
              An_Entry_Declaration                   |
              An_Entry_Body_Declaration              |
              An_Entry_Index_Specification           |
              A_Package_Body_Stub                    |
              A_Task_Body_Stub                       |
              A_Protected_Body_Stub                  |
              A_Formal_Type_Declaration              |
              A_Formal_Incomplete_Type_Declaration   |
              A_Formal_Package_Declaration           |
              A_Formal_Package_Declaration_With_Box  =>

            Result_Node := Defining_Identifier (Arg_Node);
            Result_Kind := A_Defining_Identifier;
            --  See "Open problems" below

         when An_Exception_Renaming_Declaration =>

            if Special_Case (Declaration) = Numeric_Error_Renaming then
               Result_Elem := Declaration;
               Set_Int_Kind (Result_Elem, A_Defining_Identifier);

               return (1 => Result_Elem);
            else
               Result_Node := Defining_Identifier (Arg_Node);
               Result_Kind := A_Defining_Identifier;
            end if;

         when An_Enumeration_Literal_Specification =>

            Result_Node := Arg_Node;

            if Special_Case (Declaration) = Stand_Char_Literal    or else
               Nkind (Result_Node) = N_Defining_Character_Literal or else
               Character_Code (Declaration) /= 0
            then
               Result_Kind := A_Defining_Character_Literal;
            else
               Result_Kind := A_Defining_Enumeration_Literal;
            end if;

         when   A_Procedure_Body_Declaration
              | A_Function_Body_Declaration
              | A_Package_Declaration
              | A_Procedure_Renaming_Declaration
              | A_Function_Renaming_Declaration
              | A_Procedure_Body_Stub
              | A_Function_Body_Stub
              | A_Generic_Procedure_Declaration
              | A_Generic_Function_Declaration
              | A_Generic_Package_Declaration
              | A_Formal_Procedure_Declaration
              | A_Formal_Function_Declaration  =>

            if Decl_Kind = A_Package_Declaration
              and then
               Nkind (Arg_Node) = N_Formal_Package_Declaration
            then
               --  A special case of expanded  package corresponding
               --  to a formal generic package
               Arg_Node := R_Node (Declaration);
            end if;

            if Nkind (Arg_Node) /= N_Package_Body then
               --  We may have N_Package_Body in case of an expanded spec
               --  to the library-level instantiation corresponding
               Arg_Node := Specification (Arg_Node);
            end if;

            Result_Node := Defining_Unit_Name (Arg_Node);

            if Nkind (Result_Node) = N_Defining_Program_Unit_Name then
               Result_Kind := A_Defining_Expanded_Name;
            else
               Result_Kind := Not_An_Element;
            end if;

         when A_Package_Body_Declaration =>

            Result_Node := Defining_Unit_Name (Arg_Node);

            if Nkind (Result_Node) = N_Defining_Program_Unit_Name then
               Result_Kind := A_Defining_Expanded_Name;
            else
               Result_Kind := A_Defining_Identifier;
            end if;

         when   A_Procedure_Declaration
--  --|A2005 start
              | A_Null_Procedure_Declaration
--  --|A2005 end
              | A_Function_Declaration
              | A_Package_Renaming_Declaration
              | A_Generic_Package_Renaming_Declaration
              | A_Generic_Procedure_Renaming_Declaration
              | A_Generic_Function_Renaming_Declaration
              | A_Package_Instantiation
              | A_Procedure_Instantiation
              | A_Function_Instantiation   =>

            if Decl_Kind in A_Procedure_Declaration .. A_Function_Declaration
--  --|A2005 start
              or else
               Decl_Kind = A_Null_Procedure_Declaration
--  --|A2005 end
            then
               Result_Node := Defining_Unit_Name (Specification (Arg_Node));
            else
               Result_Node := Defining_Unit_Name (Arg_Node);
            end if;

            if Nkind (Result_Node) = N_Defining_Program_Unit_Name then
               Result_Kind := A_Defining_Expanded_Name;
            elsif Special_Case (Declaration) = Is_From_Imp_Neq_Declaration then
               Result_Kind := A_Defining_Not_Equal_Operator;
            else
               Result_Kind := Not_An_Element;
            end if;

--  --|A2012 start
         when An_Expression_Function_Declaration =>
            --  This may be changed again...
            Arg_Node    := R_Node (Declaration);
            Result_Node := Defining_Unit_Name (Specification (Arg_Node));
--  --|A2012 end

         when A_Choice_Parameter_Specification =>
            Result_Node := Arg_Node;
            Result_Kind := A_Defining_Identifier;

      end case;

      return (1 => Node_To_Element_New (Starting_Element => Declaration,
                                        Node             => Result_Node,
                                        Internal_Kind    => Result_Kind));
   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information
              (Argument   => Declaration,
               Outer_Call => Package_Name & "Names");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Names",
            Ex          => Ex,
            Arg_Element => Declaration);
   end Names;
   --  OPEN PROBLEMS: 1. May be, we should use R_Node (Declaration) instead
   --  of Node for all possible argument kinds, not only for
   --  An_Ordinary_Type_Declaration to handle properly all the rewritings

   function Defining_Name_Image
     (Defining_Name : Asis.Defining_Name)
      return          Wide_String
   is
      Arg_Node    : Node_Id;
      Def_N_Kind  : Internal_Element_Kinds;
      Ch_Code     : Char_Code;
      Image_Start : Source_Ptr;
      Image_End   : Source_Ptr;

      Name_Prefix : Asis.Expression;
      --  for recursive construction of A_Defining_Expanded_Name image

      function Prefix_Image (Name_Prefix : Asis.Name) return Program_Text;
      --   Returns the string image for the prefix A_Defining_Expanded_Name.

      function Prefix_Image (Name_Prefix : Asis.Name) return Program_Text is
      begin
         if Int_Kind (Name_Prefix) = An_Identifier then
            return Asis.Expressions.Name_Image (Name_Prefix);
         else
            return
              Prefix_Image (Asis.Expressions.Prefix (Name_Prefix))
              & "."
              & Asis.Expressions.Name_Image
                  (Asis.Expressions.Selector (Name_Prefix));
         end if;
      end Prefix_Image;

   begin

      Check_Validity (Defining_Name, Package_Name & "Defining_Name_Image");
      Def_N_Kind := Int_Kind (Defining_Name);

      if Def_N_Kind not in Internal_Defining_Name_Kinds then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Defining_Name_Image",
            Wrong_Kind => Def_N_Kind);
      end if;

      --  Let's first handle special cases:

      case Special_Case (Defining_Name) is
         when Numeric_Error_Renaming =>
            --  (see B712-0050)
            return "Numeric_Error";
         when Is_From_Imp_Neq_Declaration =>

            if Ekind (Node (Defining_Name)) = E_Function then
               return """/=""";
            end if;

         when others =>
            null;
      end case;

      --  we should make the difference between entities defined in the
      --  package Standard and all the other entities. Entities from the
      --  package Standard are processed on the basis of Name Table, all the
      --  other ones - on the basis of the Source Buffer.

      Arg_Node := Node (Defining_Name);

      if Nkind (Arg_Node) in N_Entity and then
         Ekind (Arg_Node) = E_Enumeration_Literal
      then
         while Present (Alias (Arg_Node)) loop
            --  Traversing the chain of inherited literals to get the
            --  original name (we need the correct casing!)
            Arg_Node := Alias (Arg_Node);
         end loop;
      end if;

      case Def_N_Kind is

         when A_Defining_Character_Literal =>

            if Sloc (Arg_Node) <= Standard_Location then

               if Nkind (Arg_Node) = N_Character_Literal then
                  Ch_Code := UI_To_CC (Char_Literal_Value (Arg_Node));
               else
                  Ch_Code := Character_Code (Defining_Name);
               end if;

               --  For control characters, the image is implementation
               --  defined. For all characters, we simply return the character
               --  surrounded by single quotes.

               return ''' & Wide_Character'Val (Ch_Code) & ''';

            elsif Is_From_Inherited (Defining_Name)
              and then
                  Character_Code (Defining_Name) /= 0
            then

               return To_Wide_String (
                      '''
                    & Get_Character (Character_Code (Defining_Name))
                    & ''');

            else
               return ''' & Get_Wide_Ch (Sloc (Arg_Node) + 1) & ''';
            end if;

         when   A_Defining_Identifier |
                A_Defining_Enumeration_Literal =>

            --  the situation is the same for them

            if Sloc (Arg_Node) <= Standard_Location then
               return To_Program_Text (Normalized_Namet_String (Arg_Node));
            else

               Image_Start := Sloc (Arg_Node);

               --  Sloc points to << so we have to go right to the
               --  first letter of the identifier

               if Nkind (Arg_Node) = N_Label then
                  Image_Start := Next_Identifier (Image_Start);
               end if;

               Image_End   := Get_Word_End (P       => Image_Start,
                                            In_Word => In_Identifier'Access);
               return Get_Wide_Word (Image_Start, Image_End);
            end if;
         when Internal_Defining_Operator_Kinds =>

            if Sloc (Arg_Node) <= Standard_Location then
               Not_Implemented_Yet (Package_Name & "Defining_Name_Image: "
                 & "An operator symbol defined in Standard");
            else
               return Wide_String_Image (Arg_Node);
            end if;
         when A_Defining_Expanded_Name =>

            --  there is nothing of this kind in Standard

            Name_Prefix := Defining_Prefix (Defining_Name);
            return  Prefix_Image (Name_Prefix) & "."
              & Defining_Name_Image (Defining_Selector (Defining_Name));
         when others =>

            --  this choice can never been reached, see the condition for
            --  defining the appropriate argument
            raise Internal_Implementation_Error;
      end case;

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Defining_Name,
               Outer_Call => Package_Name & "Defining_Name_Image");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Defining_Name_Image",
            Ex          => Ex,
            Arg_Element => Defining_Name);
   end Defining_Name_Image;
   ----------------------------------------------------------------------------
   --  OPEN PROBLEMS:
   --
   --  1. A_Defining_Expanded_Name: is the recursive construction of the result
   --     of the String type a really good thing here? The performance can be
   --     poor but, from the other hand, this can happen not very often.
   --
   --  2. The Asis.Expressions.Name_Image function contains the (almost) exact
   --     copy of the part of the code of this function (except the part for
   --     processing A_Defining_Expanded_Name). May be, it should be better
   --     to separate it on low-level function.
   ----------------------------------------------------------------------------

   function Position_Number_Image
     (Defining_Name : Asis.Defining_Name)
      return          Wide_String
   is
      Arg_Kind  : constant Internal_Element_Kinds := Int_Kind (Defining_Name);
      Arg_Node  : Node_Id;
      Arg_Nkind : Node_Kind;
      Result    : Uint;
   begin
      Check_Validity (Defining_Name,
        Package_Name & "Position_Number_Image");

      if not (Arg_Kind = A_Defining_Character_Literal  or else
              Arg_Kind = A_Defining_Enumeration_Literal)
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Position_Number_Image",
            Wrong_Kind => Arg_Kind);
      end if;

      Arg_Node := Node (Defining_Name);
      Arg_Nkind := Nkind (Arg_Node);

      if Arg_Nkind = N_Defining_Identifier or else
         Arg_Nkind = N_Defining_Character_Literal
      then
         Result := Enumeration_Pos (Arg_Node);
         UI_Image (Result, Format => Decimal);

         return To_Wide_String (UI_Image_Buffer (1 .. UI_Image_Length));

      else
         --  Here we have literals of Standard.Character and
         --  Standard.Wide_Cherecter

         return To_Wide_String --  ??? Wide_Character ???
                  (Trim (Character_Code (Defining_Name)'Img, Left));

      end if;

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Defining_Name,
               Outer_Call => Package_Name & "Position_Number_Image");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Position_Number_Image",
            Ex          => Ex,
            Arg_Element => Defining_Name);
   end Position_Number_Image;
   -------------------------------------------------------------------------

   function Representation_Value_Image
     (Defining_Name : Asis.Defining_Name)
      return          Wide_String
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Defining_Name);
      Arg_Node : Node_Id;
      Arg_Nkind : Node_Kind;
      Result    : Uint;
   begin
      Check_Validity (Defining_Name,
        Package_Name & "Representation_Value_Image");

      if not (Arg_Kind = A_Defining_Character_Literal  or else
              Arg_Kind = A_Defining_Enumeration_Literal)
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Representation_Value_Image",
            Wrong_Kind => Arg_Kind);
      end if;

      Arg_Node := Node (Defining_Name);
      Arg_Nkind := Nkind (Arg_Node);

      if Arg_Nkind = N_Defining_Identifier or else
         Arg_Nkind = N_Defining_Character_Literal
      then
         Result := Enumeration_Rep (Arg_Node);
         UI_Image (Result, Format => Decimal);

         return To_Wide_String (UI_Image_Buffer (1 .. UI_Image_Length));

      else
         --  Here we have literals of Standard.Character and
         --  Standard.Wide_Cherecter

         return To_Wide_String  --  ??? Wide_Character ???
                  (Trim (Character_Code (Defining_Name)'Img, Left));

      end if;

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Defining_Name,
               Outer_Call => Package_Name & "Representation_Value_Image");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Representation_Value_Image",
            Ex          => Ex,
            Arg_Element => Defining_Name);
   end Representation_Value_Image;
   --------------------------------------------------------------------------

   function Defining_Prefix
     (Defining_Name : Asis.Defining_Name)
      return          Asis.Expression
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Defining_Name);
      Arg_Node : Node_Id;
      Result_Node : Node_Id;
      Result_Kind : Internal_Element_Kinds;
   begin
      Check_Validity (Defining_Name, Package_Name & "Defining_Prefix");

      if not (Arg_Kind = A_Defining_Expanded_Name) then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Defining_Prefix",
            Wrong_Kind => Arg_Kind);
      end if;

      Arg_Node := Node (Defining_Name);
      Result_Node := Sinfo.Name (Arg_Node);

      if Nkind (Result_Node) = N_Identifier then
         Result_Kind := An_Identifier;
      else
         Result_Kind := A_Selected_Component;
      end if;

      return Node_To_Element_New (
        Node             => Result_Node,
        Starting_Element => Defining_Name,
        Internal_Kind    => Result_Kind);
   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Defining_Name,
               Outer_Call => Package_Name & "Defining_Prefix");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Defining_Prefix",
            Ex          => Ex,
            Arg_Element => Defining_Name);
   end Defining_Prefix;
   -------------------------------------------------------------------------

   function Defining_Selector
     (Defining_Name : Asis.Defining_Name)
      return          Asis.Defining_Name
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Defining_Name);
      Arg_Node : Node_Id;
   begin
      Check_Validity (Defining_Name, Package_Name & "Defining_Selector");

      if not (Arg_Kind = A_Defining_Expanded_Name) then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Defining_Selector",
            Wrong_Kind => Arg_Kind);
      end if;

      Arg_Node := Node (Defining_Name);

      return Node_To_Element_New (
        Node          => Defining_Identifier (Arg_Node),
        Starting_Element => Defining_Name,
        Internal_Kind => A_Defining_Identifier);
   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Defining_Name,
               Outer_Call => Package_Name & "Defining_Selector");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Defining_Selector",
            Ex          => Ex,
            Arg_Element => Defining_Name);
   end Defining_Selector;
   -------------------------------------------------------------------------

   -----------------------------------------------------------------------

   function Type_Declaration_View
     (Declaration : Asis.Declaration)
      return        Asis.Type_Definition
   is
      Arg_Node             : Node_Id;
      Decl_Kind            : Internal_Element_Kinds;
      Result_Node          : Node_Id;
      Result_Internal_Kind : Internal_Element_Kinds;
   begin
      Check_Validity (Declaration, Package_Name & "Type_Declaration_View");
      Decl_Kind := Int_Kind (Declaration);

      if not (Decl_Kind = An_Ordinary_Type_Declaration    or else
        Decl_Kind = A_Task_Type_Declaration         or else
        Decl_Kind = A_Protected_Type_Declaration    or else
        Decl_Kind = A_Private_Type_Declaration      or else
        Decl_Kind = A_Private_Extension_Declaration or else
        Decl_Kind = A_Subtype_Declaration           or else
        Decl_Kind = A_Formal_Type_Declaration)
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Type_Declaration_View",
            Wrong_Kind => Decl_Kind);
      end if;

      --  tree traversing:

      --  first, we have to detect whether we have the declaration of a
      --  root or universal numeric type, and if we have, we should
      --  process it in a special way:

      if Is_Root_Num_Type (Declaration) then
         return Asis.Set_Get.Root_Type_Definition (Declaration);
      end if;

      --  forming the result for incomplete and private types:

      Arg_Node := Node (Declaration);

      case Decl_Kind is
         when A_Private_Type_Declaration |
           A_Private_Extension_Declaration
           =>
            --  There is no appropriate Node in the tree to map the Asis
            --  Element of the
            --
            --    A_Private_Type_Definition,
            --    A_Tagged_Private_Type_Definition,
            --    A_Private_Extension_Definition,
            --
            --  Definition_Kind values. So the result of this function
            --  for the A_Private_Type_Declaration or
            --  A_Private_Extension_Declaration passed as the argument
            --  contains just the same value in the field Node as the , but
            --  argument it differs in the values of the Kind and
            --  Internal_Kind fields.

            if Decl_Kind = A_Private_Extension_Declaration then
               Result_Internal_Kind := A_Private_Extension_Definition;
            elsif Tagged_Present (Arg_Node) then
               Result_Internal_Kind := A_Tagged_Private_Type_Definition;
            else
               Result_Internal_Kind := A_Private_Type_Definition;
            end if;

            return Node_To_Element_New
              (Node          => Arg_Node,
              Starting_Element => Declaration,
              Internal_Kind => Result_Internal_Kind);

         when An_Ordinary_Type_Declaration =>
            Result_Node := Sinfo.Type_Definition (Arg_Node);

         when A_Task_Type_Declaration =>
            Result_Node := Task_Definition (Arg_Node);

            if No (Result_Node) then
               return Nil_Element;
            end if;

         when A_Protected_Type_Declaration =>
            Result_Node := Protected_Definition (Arg_Node);

         when A_Subtype_Declaration =>
            Result_Node := Sinfo.Subtype_Indication (Arg_Node);
            return Node_To_Element_New
              (Node          => Result_Node,
              Starting_Element => Declaration,
              Internal_Kind => A_Subtype_Indication);
            --  Automatic Element Kind determination is also possible
            --  here, but it seems unnecessary

         when A_Formal_Type_Declaration =>
            Result_Node := Sinfo.Formal_Type_Definition (Arg_Node);

         when others =>
            null;
      end case;

      --  forming the result for other kinds of types:

      return Node_To_Element_New
        (Node    => Result_Node,
        Starting_Element => Declaration);
   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Declaration,
               Outer_Call => Package_Name & "Type_Declaration_View");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Type_Declaration_View",
            Ex          => Ex,
            Arg_Element => Declaration);
   end Type_Declaration_View;

   -----------------------------
   -- Object_Declaration_View --
   -----------------------------

   function Object_Declaration_View
     (Declaration : Asis.Declaration)
      return        Asis.Type_Definition
   is
      Arg_Node : Node_Id;
      Decl_Kind            : Internal_Element_Kinds;
      Result_Node          : Node_Id;
      Result_Internal_Kind : Internal_Element_Kinds := Not_An_Element;
      --  We keep using Result_Internal_Kind from old ASIS 95 code, but it is
      --  not used for new Ada 2005 features (access definitions) as well as
      --  for extending the functionality of this query to all forms of
      --  object definitions
   begin
      Check_Validity (Declaration,
        Package_Name & "Object_Declaration_View");
      Decl_Kind := Int_Kind (Declaration);

      if not (Decl_Kind = A_Variable_Declaration          or else
              Decl_Kind = A_Constant_Declaration          or else
              Decl_Kind = A_Deferred_Constant_Declaration or else
              Decl_Kind = A_Single_Protected_Declaration  or else
              Decl_Kind = A_Single_Task_Declaration       or else
              Decl_Kind = A_Component_Declaration         or else
--  |A2005 start
              Decl_Kind = A_Discriminant_Specification    or else
              Decl_Kind = A_Parameter_Specification       or else
              Decl_Kind = A_Return_Variable_Specification or else
              Decl_Kind = A_Return_Constant_Specification or else
              Decl_Kind = A_Formal_Object_Declaration     or else
              Decl_Kind = An_Object_Renaming_Declaration)
--  |A2005 end
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Object_Declaration_View",
            Wrong_Kind => Decl_Kind);
      end if;

      Arg_Node := Node (Declaration);

      case Decl_Kind is

         when A_Variable_Declaration          |
              A_Constant_Declaration          |
              A_Deferred_Constant_Declaration |
              A_Return_Variable_Specification |
              A_Return_Constant_Specification =>

            Result_Node := Object_Definition (Arg_Node);

            case Nkind (Original_Node (Result_Node)) is
               when N_Constrained_Array_Definition =>
                  Result_Internal_Kind := A_Constrained_Array_Definition;

               when N_Unconstrained_Array_Definition =>
                  Result_Internal_Kind := An_Unconstrained_Array_Definition;

--  --|A2005 start
               when N_Access_Definition =>
                  null;
--  --|A2005 end
               when others =>
                  Result_Internal_Kind := A_Subtype_Indication;
            end case;

         when A_Component_Declaration =>
            Result_Node          := Sinfo.Component_Definition (Arg_Node);
            Result_Internal_Kind := A_Component_Definition;

         when A_Single_Protected_Declaration =>
            Result_Node          := Protected_Definition (Arg_Node);
            Result_Internal_Kind := A_Protected_Definition;

         when A_Single_Task_Declaration =>
            Result_Node          := Task_Definition (Arg_Node);
            Result_Internal_Kind := A_Task_Definition;

            if No (Result_Node) then
               return Nil_Element;
            end if;

--  --|A2005 start
         when A_Discriminant_Specification =>
            Result_Node := Discriminant_Type (Arg_Node);
         when A_Parameter_Specification =>
            Result_Node := Parameter_Type (Arg_Node);
         when An_Object_Renaming_Declaration |
              A_Formal_Object_Declaration    =>

            if Present (Access_Definition (Arg_Node)) then
               Result_Node := Access_Definition (Arg_Node);
            else
               Result_Node := Sinfo.Subtype_Mark (Arg_Node);
            end if;

         when others =>
            Not_Implemented_Yet
              (Diagnosis => Package_Name & "Object_Declaration_View");
--  --|A2005 end
      end case;

      return Node_To_Element_New
        (Node             => Result_Node,
         Starting_Element => Declaration,
         Internal_Kind    => Result_Internal_Kind);

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Declaration,
               Outer_Call => Package_Name & "Object_Declaration_View");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Object_Declaration_View",
            Ex          => Ex,
            Arg_Element => Declaration);
   end Object_Declaration_View;
   --------------------------------------------------------------------------
   function Initialization_Expression
     (Declaration : Asis.Declaration)
      return        Asis.Expression
   is
      Arg_Kind    : constant Internal_Element_Kinds := Int_Kind (Declaration);
      Arg_Node    : Node_Id;
      Result_Node : Node_Id;
   begin
      Check_Validity
        (Declaration, Package_Name & "Initialization_Expression");
      if not (Arg_Kind = A_Variable_Declaration          or else
              Arg_Kind = A_Constant_Declaration          or else
              Arg_Kind = An_Integer_Number_Declaration   or else
              Arg_Kind = A_Real_Number_Declaration       or else
              Arg_Kind = A_Discriminant_Specification    or else
              Arg_Kind = A_Component_Declaration         or else
              Arg_Kind = A_Parameter_Specification       or else
--  |A2005 start
              Arg_Kind = A_Return_Variable_Specification or else
              Arg_Kind = A_Return_Constant_Specification or else
--  |A2005 end
              Arg_Kind = A_Formal_Object_Declaration)
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Initialization_Expression",
            Wrong_Kind => Arg_Kind);
      end if;

      Arg_Node := Node (Declaration);

      if Nkind (Arg_Node) = N_Formal_Object_Declaration then
         Result_Node := Sinfo.Default_Expression (Arg_Node);
      else
         Result_Node := Sinfo.Expression (Arg_Node);
      end if;

      if No (Result_Node)
          or else
        (Is_Rewrite_Substitution (Result_Node)
        and then
         not (Comes_From_Source (Original_Node (Result_Node))))
      then
         return Nil_Element;
      else

         return Node_To_Element_New
           (Node             => Result_Node,
           Starting_Element => Declaration);
      end if;
   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Declaration,
               Outer_Call => Package_Name & "Initialization_Expression");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Initialization_Expression",
            Ex          => Ex,
            Arg_Element => Declaration);
   end Initialization_Expression;
   -----------------------------------------------------------------------
   function Corresponding_Constant_Declaration
     (Name : Asis.Defining_Name)
      return Asis.Declaration
   is
      Arg_Kind      : constant Internal_Element_Kinds := Int_Kind (Name);
      Arg_Node      : Node_Id;
      Arg_Decl_Node : Node_Id;
      Result_Node   : Node_Id;
   begin
      Check_Validity (Name,
        Package_Name & "Corresponding_Constant_Declaration");

      Arg_Node := Node (Name);
      Arg_Decl_Node := Parent (Arg_Node);

      if not (Arg_Kind              = A_Defining_Identifier and then
              Nkind (Arg_Decl_Node) = N_Object_Declaration  and then
              Constant_Present (Arg_Decl_Node))
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Corresponding_Constant_Declaration",
            Wrong_Kind => Arg_Kind);
      end if;

      --  first, we should find out, where we are - in a constant
      --  declaration or in a deferred constant declaration:

      if Present (Sinfo.Expression (Parent (Arg_Node))) then
         --  we are in a full constant declaration.
         --  Here we have to traverse the tree to find the corresponding
         --  deferred constant declaration, if any. To optimize the search,
         --  we first check if we are in the private part of a package.
         --
         --  Unfortunately, in 3.10a Is_Private is set on for entities
         --  declared immediately within package bodies, so we have
         --  to do the corresponding check "by hands"::

         if not (Nkind (Parent (Arg_Decl_Node)) =
                 N_Package_Specification
           and then
              List_Containing (Arg_Decl_Node) =
              Private_Declarations (Parent (Arg_Decl_Node)))
         then
            --  it cannot be a completion of a deferred constant,
            --  see RM95 7.4(4)
            return Nil_Element;
         end if;

         --  and here we have to go into the visible part of the same
         --  package and to look for the same defining name in it:

         Result_Node := First_Non_Pragma (Visible_Declarations (Parent (
           Parent (Arg_Node))));

         while Present (Result_Node) loop
            if Nkind (Result_Node) = N_Object_Declaration and then
              Constant_Present (Result_Node)              and then
              No (Sinfo.Expression (Result_Node))         and then
              Full_View (Defining_Identifier (Result_Node)) = Arg_Node
            then
               return Node_To_Element_New
                 (Node             => Result_Node,
                  Internal_Kind    => A_Deferred_Constant_Declaration,
                  Starting_Element => Name);
            end if;

            Result_Node := Next_Non_Pragma (Result_Node);
         end loop;

         --  here we are only if there is no declaration of a deferred
         --  constant corresponding to the given full constant declaration,
         --  so:
         return Nil_Element;
      else
         --  we are in deferred constant declaration

         if Is_Imported (Arg_Node) then
            --  a deferred constant completed by a pragma Import
            return Nil_Element;
         end if;

         Result_Node := Parent (Full_View (Arg_Node));

         return Node_To_Element_New
           (Node             => Result_Node,
           Starting_Element => Name,
           Internal_Kind => A_Constant_Declaration);
      end if;

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information
              (Argument   => Name,
               Outer_Call => Package_Name &
                             "Corresponding_Constant_Declaration");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Corresponding_Constant_Declaration",
            Ex          => Ex,
            Arg_Element => Name);
   end Corresponding_Constant_Declaration;
   --------------------------------------------------------------------------

   function Declaration_Subtype_Mark
     (Declaration : Asis.Declaration)
      return        Asis.Expression
   is
      Arg_Kind    : constant Internal_Element_Kinds := Int_Kind (Declaration);
      Arg_Node    : Node_Id;
      Result_Node : Node_Id;
      Result_Kind : Internal_Element_Kinds := Not_An_Element;
   begin
      Check_Validity (Declaration,
        Package_Name & "Declaration_Subtype_Mark");

      if not (Arg_Kind = A_Discriminant_Specification or else
        Arg_Kind = A_Parameter_Specification    or else
        Arg_Kind = A_Formal_Object_Declaration  or else
        Arg_Kind = An_Object_Renaming_Declaration)
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Declaration_Subtype_Mark",
            Wrong_Kind => Arg_Kind);
      end if;

      Arg_Node := Node (Declaration);

      if Arg_Kind = A_Formal_Object_Declaration or else
         Arg_Kind = An_Object_Renaming_Declaration
      then
         Result_Node := Sinfo.Subtype_Mark (Arg_Node);

      elsif Arg_Kind = A_Discriminant_Specification then
         Result_Node := Discriminant_Type (Arg_Node);
      else -- Arg_Kind = A_Parameter_Specification
         Result_Node := Parameter_Type (Arg_Node);
      end if;

      if Nkind (Result_Node) = N_Access_Definition then
         Result_Node := Sinfo.Subtype_Mark (Result_Node);
      end if;

      --  if the result node is of N_Attribute_Reference kind, we should
      --  define the kind of this attribute, so general Node_To_Element
      --  function is used, otherwise we set An_Identifier or
      --  A_Selected_Component result kind "by hand"

      --  starting from GNAT 3.09, the compiler rewrite the node corresponding
      --  to the attribute reference in the a context like this:
      --  function "**" (Left: Precision_Float; Right: Integer'Base)
      --                                        ^^^^^^^^^^^^^^^^^^^^

      if Nkind (Result_Node) = N_Attribute_Reference
        or else
         (Is_Rewrite_Substitution (Result_Node)
         and then
          Nkind (Original_Node (Result_Node)) = N_Attribute_Reference)
        or else
         --  See FA13-008.
         (Nkind (Result_Node) = N_Identifier
         and then
          not Comes_From_Source (Result_Node)
         and then
          Ekind (Entity (Result_Node)) = E_Class_Wide_Type)

      then
         null;
         --  not a very elegant solution, but the idea is to keep
         --  Result_Kind set to Not_An_Element and not to disturb the old
         --  workable code
      elsif Nkind (Original_Node (Result_Node)) = N_Identifier then
         Result_Kind := An_Identifier;
      else
         Result_Kind := A_Selected_Component;
      end if;

      return Node_To_Element_New
        (Node            => Result_Node,
        Starting_Element => Declaration,
        Internal_Kind    => Result_Kind);
   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Declaration,
               Outer_Call => Package_Name & "Declaration_Subtype_Mark");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Declaration_Subtype_Mark",
            Ex          => Ex,
            Arg_Element => Declaration);
   end Declaration_Subtype_Mark;
   ----------------------------------------------------------------------

   ------------------------------------------------------------------------
   --  NOT IMPLEMENTED

   function Corresponding_Type_Declaration
     (Declaration : Asis.Declaration;
      The_Context : Asis.Context)
      return        Asis.Declaration
   is
   begin
      Check_Validity (Declaration,
        Package_Name & "Corresponding_Type_Declaration");
      Check_Validity (The_Context,
        Package_Name & "Corresponding_Type_Declaration");

      Not_Implemented_Yet (Diagnosis =>
        Package_Name & "Corresponding_Type_Declaration");
      --  ASIS_Failed is raised, Not_Implemented_Error status is set

      return Nil_Element; -- to make the code syntactically correct

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information
              (Argument   => Declaration,
               Outer_Call => Package_Name & "Corresponding_Type_Declaration");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Corresponding_Type_Declaration",
            Ex          => Ex,
            Arg_Element => Declaration);
   end Corresponding_Type_Declaration;
   ----------------------------------------------------------------

   function Corresponding_First_Subtype
     (Declaration : Asis.Declaration)
      return        Asis.Declaration
   is
      Arg_Kind    : constant Internal_Element_Kinds := Int_Kind (Declaration);
      Arg_Node    : Node_Id;
      Result_Node : Node_Id;

      Result_Unit : Asis.Compilation_Unit;

   begin
      Check_Validity (Declaration,
        Package_Name & "Corresponding_First_Subtype");

      if not (Arg_Kind = An_Ordinary_Type_Declaration    or else
              Arg_Kind = A_Task_Type_Declaration         or else
              Arg_Kind = A_Protected_Type_Declaration    or else
              Arg_Kind = A_Private_Type_Declaration      or else
              Arg_Kind = A_Private_Extension_Declaration or else
              Arg_Kind = A_Subtype_Declaration           or else
              Arg_Kind = A_Formal_Type_Declaration)
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Corresponding_First_Subtype",
            Wrong_Kind => Arg_Kind);
      end if;

      if Arg_Kind = An_Ordinary_Type_Declaration    or else
         Arg_Kind = A_Task_Type_Declaration         or else
         Arg_Kind = A_Protected_Type_Declaration    or else
         Arg_Kind = A_Private_Type_Declaration      or else
         Arg_Kind = A_Private_Extension_Declaration or else
         Arg_Kind = A_Formal_Type_Declaration
      then
         return Declaration;
      end if;

      Arg_Node := Node (Declaration);
      --  now we are processing a subtype declaration, therefore Arg_Node
      --  is of N_Subtype_Declaration kind

      pragma Assert (Nkind (Arg_Node) = N_Subtype_Declaration);
      Result_Node := Sem_Aux.First_Subtype (Defining_Identifier (Arg_Node));

      --  We are in the subtype declaration now, so we can detect this
      --  situation like this:
      if Result_Node = Defining_Identifier (Arg_Node) then
         Result_Node := Sinfo.Subtype_Indication (Arg_Node);

         if Nkind (Result_Node) = N_Subtype_Indication then
            Result_Node := Sinfo.Subtype_Mark (Result_Node);
         end if;

         Result_Node := Entity (Result_Node);

         while Nkind (Parent (Result_Node)) = N_Subtype_Declaration loop
            Result_Node := Sinfo.Subtype_Indication (Parent (Result_Node));

            if Nkind (Result_Node) = N_Subtype_Indication then
               Result_Node := Sinfo.Subtype_Mark (Result_Node);
            end if;

            Result_Node := Entity (Result_Node);
         end loop;
      end if;

      --  and now - from defining name to the corresponding type declaration:
      if No (Parent (Result_Node)) then

         if Is_Itype (Result_Node) then
            --  for now, the only discovered case is the subtyping
            --  from a formal array type.
            Result_Node := Associated_Node_For_Itype (Result_Node);
         else
            --  for now, the only truly discovered case when
            --  Parent (Result_Node) is Empty and Is_Itype is NOT set on
            --  is when Result_Node points
            --  to the implicit entity created by the compiler for
            --  a formal integer type. In this case the following approach
            --  should work:
            Result_Node := Next_Entity (Result_Node);
         end if;
      end if;

      if Nkind (Result_Node) = N_Defining_Identifier then
         --  we should not do this step up when Associated_Node_For_Itype
         --  has been applied!
         Result_Node := Parent (Result_Node);
      end if;

      Result_Unit := Enclosing_Unit (Encl_Cont_Id (Declaration), Result_Node);

      return Node_To_Element_New (Node    => Result_Node,
                                  In_Unit => Result_Unit);

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Declaration,
               Outer_Call =>
              Package_Name & "Corresponding_First_Subtype");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Corresponding_First_Subtype",
            Ex          => Ex,
            Arg_Element => Declaration);
   end Corresponding_First_Subtype;
   ----------------------------------------------------------------
   function Corresponding_Last_Constraint
     (Declaration : Asis.Declaration)
      return        Asis.Declaration
   is
      Arg_Kind    : constant Internal_Element_Kinds := Int_Kind (Declaration);
      Arg_Node    : Node_Id;
      Result_Node : Node_Id;
      Result_Unit : Asis.Compilation_Unit;
   begin
      Check_Validity (Declaration,
        Package_Name & "Corresponding_Last_Constraint");

      if not (Arg_Kind = An_Ordinary_Type_Declaration    or else
              Arg_Kind = A_Task_Type_Declaration         or else
              Arg_Kind = A_Protected_Type_Declaration    or else
              Arg_Kind = A_Private_Type_Declaration      or else
              Arg_Kind = A_Private_Extension_Declaration or else
              Arg_Kind = A_Subtype_Declaration           or else
              Arg_Kind = A_Formal_Type_Declaration)
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Corresponding_Last_Constraint",
            Wrong_Kind => Arg_Kind);
      end if;

      if Arg_Kind = An_Ordinary_Type_Declaration    or else
         Arg_Kind = A_Task_Type_Declaration         or else
         Arg_Kind = A_Protected_Type_Declaration    or else
         Arg_Kind = A_Private_Type_Declaration      or else
         Arg_Kind = A_Private_Extension_Declaration or else
         Arg_Kind = A_Formal_Type_Declaration
      then
         return Declaration;
      end if;

      Arg_Node := Node (Declaration);
      --  now we are processing a subtype declaration, therefore Arg_Node
      --  is of N_Subtype_Declaration kind

      Result_Node := Sinfo.Subtype_Indication (Arg_Node);

      if Nkind (Result_Node) = N_Subtype_Indication then
         Result_Node := Sinfo.Subtype_Mark (Result_Node);
      end if;

      if Is_Rewrite_Substitution (Result_Node)
        and then
         Nkind (Original_Node (Result_Node)) = N_Attribute_Reference
      then
         Result_Node := Sinfo.Prefix (Original_Node (Result_Node));
      end if;

      Result_Node := Parent (Entity (Result_Node));

      while Nkind (Result_Node) = N_Subtype_Declaration and then
            Nkind (Sinfo.Subtype_Indication (Result_Node)) /=
               N_Subtype_Indication
      loop
         Result_Node := Sinfo.Subtype_Indication (Result_Node);

         if Nkind (Result_Node) = N_Subtype_Indication then
            Result_Node := Sinfo.Subtype_Mark (Result_Node);
         end if;

         if Is_Rewrite_Substitution (Result_Node)
           and then
            Nkind (Original_Node (Result_Node)) = N_Attribute_Reference
         then
            Result_Node := Sinfo.Prefix (Original_Node (Result_Node));
         end if;

         Result_Node := Parent (Entity (Result_Node));

      end loop;

      Result_Unit := Enclosing_Unit (Encl_Cont_Id (Declaration), Result_Node);

      return Node_To_Element_New (Node    => Result_Node,
                                  In_Unit => Result_Unit);

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Declaration,
               Outer_Call =>
              Package_Name & "Corresponding_Last_Constraint");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Corresponding_Last_Constraint",
            Ex          => Ex,
            Arg_Element => Declaration);
   end Corresponding_Last_Constraint;
   ----------------------------------------------------------------
   function Corresponding_Last_Subtype
     (Declaration : Asis.Declaration)
      return        Asis.Declaration
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Declaration);
      Arg_Node : Node_Id;
      Result_Node : Node_Id;
      Result_Unit : Asis.Compilation_Unit;
   begin
      Check_Validity (Declaration,
        Package_Name & "Corresponding_Last_Subtype");

      if not (Arg_Kind = An_Ordinary_Type_Declaration    or else
              Arg_Kind = A_Task_Type_Declaration         or else
              Arg_Kind = A_Protected_Type_Declaration    or else
              Arg_Kind = A_Private_Type_Declaration      or else
              Arg_Kind = A_Private_Extension_Declaration or else
              Arg_Kind = A_Subtype_Declaration           or else
              Arg_Kind = A_Formal_Type_Declaration)
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Corresponding_Last_Subtype",
            Wrong_Kind => Arg_Kind);
      end if;

      if Arg_Kind = An_Ordinary_Type_Declaration    or else
         Arg_Kind = A_Task_Type_Declaration         or else
         Arg_Kind = A_Protected_Type_Declaration    or else
         Arg_Kind = A_Private_Type_Declaration      or else
         Arg_Kind = A_Private_Extension_Declaration or else
         Arg_Kind = A_Formal_Type_Declaration
      then
         return Declaration;
      end if;

      Arg_Node := Node (Declaration);
      --  now we are processing a subtype declaration, therefore Arg_Node
      --  is of N_Subtype_Declaration kind

      Result_Node := Original_Node (Sinfo.Subtype_Indication (Arg_Node));

      if Nkind (Result_Node) = N_Subtype_Indication then
         Result_Node := Original_Node (Sinfo.Subtype_Mark (Result_Node));
      end if;

      while Nkind (Result_Node) = N_Attribute_Reference loop
         --  We need this loop (as well as using Original_Node in case if the
         --  subtype mark is an attribute reference
         Result_Node := Original_Node (Prefix (Result_Node));
      end loop;

      Result_Node := Parent (Entity (Result_Node));

      Result_Unit := Enclosing_Unit (Encl_Cont_Id (Declaration), Result_Node);

      return Node_To_Element_New (Node    => Result_Node,
                                  In_Unit => Result_Unit);

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Declaration,
               Outer_Call => Package_Name & "Corresponding_Last_Subtype");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Corresponding_Last_Subtype",
            Ex          => Ex,
            Arg_Element => Declaration);
   end Corresponding_Last_Subtype;
   ------------------------------------------------------------------
   function Corresponding_Representation_Clauses
     (Declaration : Asis.Declaration)
      return        Asis.Representation_Clause_List
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Declaration);
      Arg_Node : constant Node_Id                := Node (Declaration);

      Arg_Node_Kind       : constant Node_Kind := Nkind (Arg_Node);
      Entity_Node         : Node_Id;
      First_Rep_Item_Node : Node_Id;
      Next_Rep_Item_Node  : Node_Id;
      Rep_Node_Kind       : Node_Kind;
      Result_Unit         : Asis.Compilation_Unit := Nil_Compilation_Unit;

      Actual_Repr_Cl : array (N_Representation_Clause)
        of Boolean := (others => True);
      Actual_Rep_Attr : array (First_Attribute_Name .. Last_Attribute_Name)
        of Boolean := (others => True);
      --  The first flag array Is used to select only first representation
      --  item from the chain, in case if representation clauses are duplicated
      --  in the tree for derived types. For attribute definition clauses we
      --  use second flag array, because we can have more than one attribute
      --  definition clauses, so we have to take the first clause for a given
      --  representation attribute

   begin
      Check_Validity (Declaration,
        Package_Name & "Corresponding_Representation_Clauses");

      if not (Arg_Kind in Internal_Declaration_Kinds) then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis =>
              Package_Name & "Corresponding_Representation_Clauses",
            Wrong_Kind => Arg_Kind);
      end if;

      --  first, we have to get entity from the declaration:
      if Arg_Node_Kind  = N_Subprogram_Declaration          or else
         Arg_Node_Kind  = N_Abstract_Subprogram_Declaration or else
         Arg_Node_Kind  = N_Subprogram_Body                 or else
         Arg_Node_Kind  = N_Subprogram_Body_Stub            or else
         Arg_Node_Kind  = N_Package_Declaration             or else
         Arg_Node_Kind  = N_Package_Declaration             or else
         Arg_Node_Kind  = N_Subprogram_Renaming_Declaration or else
         Arg_Node_Kind  = N_Generic_Package_Declaration     or else
         Arg_Node_Kind  = N_Generic_Subprogram_Declaration  or else
         Arg_Node_Kind in N_Formal_Subprogram_Declaration
      then
         Entity_Node := Defining_Unit_Name (Specification (Arg_Node));
      elsif
        Arg_Node_Kind = N_Package_Body                           or else
        Arg_Node_Kind = N_Package_Renaming_Declaration           or else
        Arg_Node_Kind = N_Generic_Package_Renaming_Declaration   or else
        Arg_Node_Kind = N_Generic_Procedure_Renaming_Declaration or else
        Arg_Node_Kind = N_Generic_Function_Renaming_Declaration  or else
        Arg_Node_Kind = N_Package_Instantiation                  or else
        Arg_Node_Kind = N_Procedure_Instantiation                or else
        Arg_Node_Kind = N_Function_Instantiation
      then
         Entity_Node := Defining_Unit_Name (Arg_Node);
      elsif
        Arg_Node_Kind = N_Defining_Identifier        or else
        Arg_Node_Kind = N_Defining_Character_Literal
      then
         Entity_Node := Arg_Node;
      else
         Entity_Node := Defining_Identifier (Arg_Node);
      end if;

      if Nkind (Entity_Node) = N_Defining_Program_Unit_Name then
         Entity_Node := Defining_Identifier (Entity_Node);
      end if;

      Asis_Element_Table.Init;

      First_Rep_Item_Node := First_Rep_Item (Entity_Node);
      Next_Rep_Item_Node  := First_Rep_Item_Node;

      while Present (Next_Rep_Item_Node) loop

         Rep_Node_Kind := Nkind (Next_Rep_Item_Node);

         Result_Unit :=
           Enclosing_Unit (Encl_Cont_Id (Declaration), Next_Rep_Item_Node);

         case Rep_Node_Kind is

            when N_Attribute_Definition_Clause =>

               if not From_At_Mod (Next_Rep_Item_Node) and then
                  Actual_Rep_Attr (Chars (Next_Rep_Item_Node))
               then
                  Asis_Element_Table.Append
                    (Node_To_Element_New
                      (In_Unit => Result_Unit,
                       Node    => Next_Rep_Item_Node));

                  Actual_Rep_Attr (Chars (Next_Rep_Item_Node)) := False;
               end if;

            when N_At_Clause                         |
                 N_Component_Clause                  |
                 N_Enumeration_Representation_Clause |
                 N_Mod_Clause                        |
                 N_Record_Representation_Clause      =>

               if Actual_Repr_Cl (Rep_Node_Kind) then
                  Asis_Element_Table.Append
                    (Node_To_Element_New
                      (In_Unit => Result_Unit,
                       Node    => Next_Rep_Item_Node));

                  Actual_Repr_Cl (Rep_Node_Kind) := False;
               end if;

            when others =>
               --  This query is only about representation clauses, not pragmas
               null;
         end case;

         Next_Rep_Item_Node := Next_Rep_Item (Next_Rep_Item_Node);
      end loop;

      return Asis.Declaration_List
               (Asis_Element_Table.Table (1 .. Asis_Element_Table.Last));

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Declaration,
               Outer_Call =>
              Package_Name & "Corresponding_Representation_Clauses");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name &
                           "Corresponding_Representation_Clauses",
            Ex          => Ex,
            Arg_Element => Declaration);
   end Corresponding_Representation_Clauses;
   -----------------------------------------------------------------------
   function Specification_Subtype_Definition
     (Specification : Asis.Declaration)
      return          Asis.Discrete_Subtype_Definition
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Specification);
      Arg_Node : Node_Id;

      Result_Node      : Node_Id;
      Result_Kind      : Internal_Element_Kinds;
      Result_Node_Kind : Node_Kind;
   begin
      Check_Validity (Specification,
        Package_Name & "Specification_Subtype_Definition");
      if not (Arg_Kind = A_Loop_Parameter_Specification or else
        Arg_Kind = An_Entry_Index_Specification)
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Specification_Subtype_Definition",
            Wrong_Kind => Arg_Kind);
      end if;

      Arg_Node := Node (Specification);
      Result_Node := Sinfo.Discrete_Subtype_Definition (Arg_Node);

      Result_Node_Kind := Nkind (Original_Node (Result_Node));

      case Result_Node_Kind is
         when N_Subtype_Indication |
              N_Identifier         |
              N_Expanded_Name      =>
            Result_Kind := A_Discrete_Subtype_Indication_As_Subtype_Definition;

         when N_Attribute_Reference =>
            Result_Kind :=
              A_Discrete_Range_Attribute_Reference_As_Subtype_Definition;

         when N_Range =>
            Result_Kind :=
              A_Discrete_Simple_Expression_Range_As_Subtype_Definition;
         when others =>
            --  unexpected Node Kind for DISCRETE_SUBTYPE_DEFINITION!!!
            pragma Assert (False);
            null;
      end case;

      return Node_To_Element_New
               (Node          => Result_Node,
                Starting_Element => Specification,
                Internal_Kind => Result_Kind);
   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Specification,
               Outer_Call =>
              Package_Name & "Specification_Subtype_Definition");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Specification_Subtype_Definition",
            Ex          => Ex,
            Arg_Element => Specification);
   end Specification_Subtype_Definition;
   -------------------------------------------------------------------

   ---------------------------
   -- Iteration_Scheme_Name --
   ---------------------------

   function Iteration_Scheme_Name
     (Iterator_Specification : Asis.Element)
      return                   Asis.Element
   is
      Arg_Kind : constant Internal_Element_Kinds :=
        Int_Kind (Iterator_Specification);
      Result_Node : Node_Id;
   begin
      Check_Validity
        (Iterator_Specification, Package_Name & "Iteration_Scheme_Name");

      if Arg_Kind not in
           A_Generalized_Iterator_Specification ..
           An_Element_Iterator_Specification
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Iteration_Scheme_Name",
            Wrong_Kind => Arg_Kind);
      end if;

      Result_Node := Node (Iterator_Specification);
      Result_Node := Sinfo.Name (Result_Node);

      return Node_To_Element_New
               (Node             => Result_Node,
                Starting_Element => Iterator_Specification);
   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Iterator_Specification,
               Outer_Call =>
              Package_Name & "Iteration_Scheme_Name");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Iteration_Scheme_Name",
            Ex          => Ex,
            Arg_Element => Iterator_Specification);
   end Iteration_Scheme_Name;

   ------------------------
   -- Subtype_Indication --
   ------------------------

   function Subtype_Indication
     (Iterator_Specification : Asis.Element)
      return                   Asis.Element
   is
      Arg_Kind : constant Internal_Element_Kinds :=
        Int_Kind (Iterator_Specification);
      Result_Node : Node_Id;
   begin
      Check_Validity (Iterator_Specification,
        Package_Name & "Subtype_Indication");

      if Arg_Kind /= An_Element_Iterator_Specification then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Subtype_Indication",
            Wrong_Kind => Arg_Kind);
      end if;

      Result_Node := Node (Iterator_Specification);
      Result_Node := Sinfo.Subtype_Indication (Result_Node);

      if Present (Result_Node) then
         return Node_To_Element_New
                  (Node             => Result_Node,
                   Starting_Element => Iterator_Specification,
                   Internal_Kind    => A_Subtype_Indication);
      else
         return Nil_Element;
      end if;

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Iterator_Specification,
               Outer_Call =>
              Package_Name & "Subtype_Indication");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Subtype_Indication",
            Ex          => Ex,
            Arg_Element => Iterator_Specification);
   end Subtype_Indication;
   -------------------------------------------------------------------
   function Parameter_Profile
     (Declaration : Asis.Declaration)
      return        Asis.Parameter_Specification_List
   is
      Arg_Element      : constant Element := Declaration;
      Arg_Node         : Node_Id;
      Decl_Kind        : Internal_Element_Kinds;
      Result_List      : List_Id;
   begin
      Check_Validity (Declaration, Package_Name & "Parameter_Profile");

      Decl_Kind := Int_Kind (Declaration);

      if not (Decl_Kind = A_Procedure_Declaration            or else
--  |A2005 start
              Decl_Kind = A_Null_Procedure_Declaration       or else
--  |A2005 end
--  |A2012 start
              Decl_Kind = An_Expression_Function_Declaration or else
--  |A2012 end
              Decl_Kind = A_Function_Declaration             or else
              Decl_Kind = A_Procedure_Body_Declaration       or else
              Decl_Kind = A_Function_Body_Declaration        or else
              Decl_Kind = A_Procedure_Renaming_Declaration   or else
              Decl_Kind = A_Function_Renaming_Declaration    or else
              Decl_Kind = An_Entry_Declaration               or else
              Decl_Kind = An_Entry_Body_Declaration          or else
              Decl_Kind = A_Procedure_Body_Stub              or else
              Decl_Kind = A_Function_Body_Stub               or else
              Decl_Kind = A_Generic_Procedure_Declaration    or else
              Decl_Kind = A_Generic_Function_Declaration     or else
              Decl_Kind = A_Formal_Procedure_Declaration     or else
              Decl_Kind = A_Formal_Function_Declaration)
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Parameter_Profile",
            Wrong_Kind => Decl_Kind);
      end if;

      Arg_Node := Node (Arg_Element);

      if Decl_Kind = A_Procedure_Declaration            or else
         Decl_Kind = A_Null_Procedure_Declaration       or else
         Decl_Kind = An_Expression_Function_Declaration or else
         Decl_Kind = A_Function_Declaration             or else
         Decl_Kind = A_Procedure_Body_Declaration       or else
         Decl_Kind = A_Function_Body_Declaration        or else
         Decl_Kind = A_Procedure_Renaming_Declaration   or else
         Decl_Kind = A_Function_Renaming_Declaration    or else
         Decl_Kind = A_Procedure_Body_Stub              or else
         Decl_Kind = A_Function_Body_Stub               or else
         Decl_Kind = A_Generic_Procedure_Declaration    or else
         Decl_Kind = A_Generic_Function_Declaration     or else
         Decl_Kind = A_Formal_Procedure_Declaration     or else
         Decl_Kind = A_Formal_Function_Declaration
      then

         Result_List := Parameter_Specifications (Specification (Arg_Node));

      elsif Decl_Kind = An_Entry_Declaration then
         Result_List := Parameter_Specifications (Arg_Node);

      else
         Result_List :=
            Parameter_Specifications (Entry_Body_Formal_Part (Arg_Node));
      end if;

      if No (Result_List) then
         return Nil_Element_List;

      else

         return N_To_E_List_New
                  (List              => Result_List,
                   Starting_Element  => Declaration,
                   Internal_Kind     => A_Parameter_Specification);
      end if;

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Declaration,
               Outer_Call => Package_Name & "Parameter_Profile");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Parameter_Profile",
            Ex          => Ex,
            Arg_Element => Declaration);
   end Parameter_Profile;
   -----------------------------------------------------------------------

   function Result_Profile
     (Declaration : Asis.Declaration)
      return        Asis.Expression
   is
      Arg_Node    : Node_Id;
      Decl_Kind   : Internal_Element_Kinds;
      Result_Node : Node_Id;
      Result_Kind : Internal_Element_Kinds := Not_An_Element;
   begin

      Check_Validity (Declaration, Package_Name & "Result_Profile");

      Decl_Kind := Int_Kind (Declaration);

      if not (Decl_Kind = A_Function_Declaration       or else
        Decl_Kind = A_Function_Body_Declaration        or else
        Decl_Kind = An_Expression_Function_Declaration or else
        Decl_Kind = A_Function_Renaming_Declaration    or else
        Decl_Kind = A_Function_Body_Stub               or else
        Decl_Kind = A_Generic_Function_Declaration     or else
        Decl_Kind = A_Formal_Function_Declaration)
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Result_Profile",
            Wrong_Kind => Decl_Kind);
      end if;

      Arg_Node    := Node (Declaration);
      Result_Node := Sinfo.Result_Definition (Specification (Arg_Node));

      if Nkind (Original_Node (Result_Node)) = N_Attribute_Reference
--  --|A2005 start
        or else
         Nkind (Original_Node (Result_Node)) = N_Access_Definition
--  --|A2005 end
      then
         null;
      elsif Nkind (Original_Node (Result_Node)) = N_Identifier then
         Result_Kind := An_Identifier;
      else
         Result_Kind := A_Selected_Component;
      end if;

      return Node_To_Element_New (
        Node             => Result_Node,
        Starting_Element => Declaration,
        Internal_Kind    => Result_Kind);
   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Declaration,
               Outer_Call => Package_Name & "Result_Profile");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Result_Profile",
            Ex          => Ex,
            Arg_Element => Declaration);
   end Result_Profile;
   ----------------------------------------------------------------------
   function Body_Declarative_Items
     (Declaration     : Asis.Declaration;
      Include_Pragmas : Boolean := False)
      return            Asis.Declarative_Item_List
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Declaration);
      Arg_Node : Node_Id;

   begin
      Check_Validity (Declaration,
        Package_Name & "Body_Declarative_Items");

      if not (Arg_Kind = A_Function_Body_Declaration  or else
        Arg_Kind = A_Procedure_Body_Declaration or else
        Arg_Kind = A_Package_Body_Declaration   or else
        Arg_Kind = A_Task_Body_Declaration      or else
        Arg_Kind = An_Entry_Body_Declaration)
      then
         Raise_ASIS_Inappropriate_Element
           (Package_Name & "Body_Declarative_Items",
            Wrong_Kind => Arg_Kind);
      end if;

      Arg_Node := Node (Declaration);

      return N_To_E_List_New
               (List             => Sinfo.Declarations (Arg_Node),
                Include_Pragmas  => Include_Pragmas,
                Starting_Element => Declaration);

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Declaration,
               Outer_Call => Package_Name & "Body_Declarative_Items",
            Bool_Par   => Include_Pragmas);
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Body_Declarative_Items",
            Ex          => Ex,
            Arg_Element => Declaration,
            Bool_Par_ON => Include_Pragmas);
   end Body_Declarative_Items;
   ----------------------------------------------------------------------

   function Body_Statements
     (Declaration     : Asis.Declaration;
      Include_Pragmas : Boolean := False)
      return            Asis.Statement_List
   is
      Arg_Kind    : constant Internal_Element_Kinds := Int_Kind (Declaration);
      Arg_Node    : Node_Id;

      Resilt_List : List_Id := No_List;
   begin
      Check_Validity (Declaration, Package_Name & "Body_Statements");
      if not (Arg_Kind = A_Function_Body_Declaration  or else
              Arg_Kind = A_Procedure_Body_Declaration or else
              Arg_Kind = A_Package_Body_Declaration   or else
              Arg_Kind = A_Task_Body_Declaration      or else
              Arg_Kind = An_Entry_Body_Declaration)
      then
         Raise_ASIS_Inappropriate_Element
           (Package_Name & "Body_Statements",
            Wrong_Kind => Arg_Kind);
      end if;

      Arg_Node := Node (Declaration);

      if Present (Handled_Statement_Sequence (Arg_Node)) then
         Resilt_List := Statements (Handled_Statement_Sequence (Arg_Node));
      end if;

      return N_To_E_List_New
               (List             => Resilt_List,
                Include_Pragmas  => Include_Pragmas,
                Starting_Element => Declaration);

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Declaration,
               Outer_Call => Package_Name & "Body_Statements",
            Bool_Par   => Include_Pragmas);
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Body_Statements",
            Ex          => Ex,
            Arg_Element => Declaration,
            Bool_Par_ON => Include_Pragmas);
   end Body_Statements;
   ---------------------------------------------------------------------
   function Body_Exception_Handlers
     (Declaration     : Asis.Declaration;
      Include_Pragmas : Boolean := False)
      return            Asis.Exception_Handler_List
   is
      Arg_Kind    : constant Internal_Element_Kinds := Int_Kind (Declaration);
      Arg_Node    : Node_Id;

      Resilt_List : List_Id := No_List;

   begin
      Check_Validity (Declaration,
        Package_Name & "Body_Exception_Handlers");

      if not (Arg_Kind = A_Function_Body_Declaration  or else
              Arg_Kind = A_Procedure_Body_Declaration or else
              Arg_Kind = A_Package_Body_Declaration   or else
              Arg_Kind = A_Task_Body_Declaration      or else
              Arg_Kind = An_Entry_Body_Declaration)
      then
         Raise_ASIS_Inappropriate_Element
           (Package_Name & "Body_Exception_Handlers",
            Wrong_Kind => Arg_Kind);
      end if;

      Arg_Node := Node (Declaration);

      if Present (Handled_Statement_Sequence (Arg_Node)) then
         Resilt_List :=
            Exception_Handlers (Handled_Statement_Sequence (Arg_Node));
      end if;

      return N_To_E_List_New
               (List             => Resilt_List,
                Include_Pragmas  => Include_Pragmas,
                Starting_Element => Declaration);

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Declaration,
               Outer_Call => Package_Name & "Body_Exception_Handlers",
            Bool_Par   => Include_Pragmas);
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Body_Exception_Handlers",
            Ex          => Ex,
            Arg_Element => Declaration,
            Bool_Par_ON => Include_Pragmas);
   end Body_Exception_Handlers;

   ------------------------------------------------------------------------
   --  |GNAT-ASIS: If the body passed as the actual have no declarative items
   --  |GNAT-ASIS  on its own, the result of the function will not test
   --  |GNAT-ASIS  Statements.Is_Declare_Block

   function Body_Block_Statement
     (Declaration : Asis.Declaration)
      return        Asis.Statement
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Declaration);
      Arg_Node : Node_Id;
   begin
      Check_Validity (Declaration,
        Package_Name & "Body_Block_Statement");
      if not (Arg_Kind = A_Function_Body_Declaration  or else
        Arg_Kind = A_Procedure_Body_Declaration or else
        Arg_Kind = A_Package_Body_Declaration   or else
        Arg_Kind = A_Task_Body_Declaration      or else
        Arg_Kind = An_Entry_Body_Declaration)
      then
         Raise_ASIS_Inappropriate_Element
           (Package_Name & "Body_Block_Statement",
            Wrong_Kind => Arg_Kind);
      end if;

      Arg_Node := Node (Declaration);

      --  the dummy block statement is created on the base on the
      --  argument's node; it requires the special processing to be
      --  performed by the block-related functions from Asis_Statements.

      return Node_To_Element_New (
        Node             => Arg_Node,
        Starting_Element => Declaration,
        Internal_Kind    => A_Block_Statement,
        Spec_Case        => A_Dummy_Block_Statement);
   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Declaration,
               Outer_Call => Package_Name & "Body_Block_Statement");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Body_Block_Statement",
            Ex          => Ex,
            Arg_Element => Declaration);
   end Body_Block_Statement;
------------------------------------------------------------------------------
   function Is_Name_Repeated
     (Declaration : Asis.Declaration)
      return       Boolean
   is
      Arg       : Asis.Element                    := Declaration;
      Arg_Kind  : constant Internal_Element_Kinds := Int_Kind (Arg);
      Last_Comp : Asis.Element;
      S         : Source_Ptr;
      Result    : Boolean;

   begin
      Check_Validity (Arg, Package_Name & "Is_Name_Repeated");

      if not (Arg_Kind = A_Package_Declaration          or else
              Arg_Kind = A_Package_Body_Declaration     or else
              Arg_Kind = A_Procedure_Body_Declaration   or else
              Arg_Kind = A_Function_Body_Declaration    or else
              Arg_Kind = A_Generic_Package_Declaration  or else
              Arg_Kind = A_Task_Type_Declaration        or else
              Arg_Kind = A_Single_Task_Declaration      or else
              Arg_Kind = A_Task_Body_Declaration        or else
              Arg_Kind = A_Protected_Type_Declaration   or else
              Arg_Kind = A_Single_Protected_Declaration or else
              Arg_Kind = A_Protected_Body_Declaration   or else
              Arg_Kind = An_Entry_Body_Declaration)
      then
         return False;
      end if;

      --  For expanded spec and bodies we do the check for the original
      --  generics.
      if Special_Case (Arg) in Expanded_Spec then
         Arg := Enclosing_Element (Arg);
         Arg := Generic_Unit_Name (Arg);
         Arg := Normalize_Reference (Arg);
         Arg := Asis.Expressions.Corresponding_Name_Declaration (Arg);

         if Arg_Kind in
              A_Package_Body_Declaration   |
              A_Procedure_Body_Declaration |
              A_Function_Body_Declaration
         then
            Arg := Corresponding_Body (Arg);
            pragma Assert (not (Is_Nil (Arg)));
         end if;
      end if;

      Reset_Tree_For_Element (Arg);

      if Arg_Kind = A_Task_Type_Declaration        or else
         Arg_Kind = A_Single_Task_Declaration      or else
         Arg_Kind = A_Protected_Type_Declaration   or else
         Arg_Kind = A_Single_Protected_Declaration
      then
         --  this situation differs from the rest of the appropriate element
         --  kinds, because here we have to analyze type or object declaration
         --  view as the last component, and the potentially repeated name is
         --  a part of this component:
         if Arg_Kind = A_Task_Type_Declaration        or else
            Arg_Kind = A_Protected_Type_Declaration
         then
            Last_Comp := Type_Declaration_View (Arg);
         else
            Last_Comp := Object_Declaration_View (Arg);
         end if;

         if Is_Nil (Last_Comp) then
            --  this is the case for a single task or task type declaration
            --  without any entry declaration. such a declaration does not
            --  contain a "is ... end" part in its structure, therefore there
            --  is no "end" for a name to repeat after:
            Result := False;
         else
            --  here we have the end after which the name may be repeated in
            --  the very end of Last_Comp:
            S := Set_Image_End (Last_Comp);

            if not (Get_Character (S) = 'd' or else
                    Get_Character (S) = 'D')
            then
               Result := True;
            elsif not (Get_Character (S - 1) = 'n' or else
                       Get_Character (S - 1) = 'N')
            then
               Result := True;
            elsif not (Get_Character (S - 2) = 'e' or else
                       Get_Character (S - 2) = 'E')
            then
               Result := True;
            elsif not (Get_Character (S - 3) = ' ') then
               Result := True;
            else
               Result := False;
            end if;

         end if;
      else
         --  here we are in the situation when the "end" to repeat the name
         --  after is not a part of any subcomponent of Declaration
         Last_Comp := Get_Last_Component (Arg);
         S := Set_Image_End (Last_Comp);
         S := S + 1;
         S := Rightmost_Non_Blank (S);

         --  there may be a pathological case of a package or protected spec
         --  with no declaration inside, moreover, in such a case a protected
         --  type declaration may or may not contain a discriminant part

         if Get_Character (S) = 'i' or else Get_Character (S) = 'I' then
            --  the reserved word IS is the only possibility here, therefore:
            S := S + 2;
            S := Rightmost_Non_Blank (S);
         end if;

         --  here we have two possibilities S can put on the beginning of
         --  "end" or "private"

         if Get_Character (S) = 'P' or else Get_Character (S) = 'p' then
            --  skipping "private"
            S := S + 7;
            S := Rightmost_Non_Blank (S);
         end if;

         S := S + 3;
         --  the first character after "end"
         S := Rightmost_Non_Blank (S);
         --  and the final check - what follows the final "end"

         if Get_Character (S) = ';' then
            Result := False;
         else
            Result := True;
         end if;

      end if;

      return Result;

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Declaration,
               Outer_Call =>
              Package_Name & "Is_Name_Repeated");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Is_Name_Repeated",
            Ex          => Ex,
            Arg_Element => Declaration);
   end Is_Name_Repeated;
------------------------------------------------------------------------------
   function Corresponding_Declaration
     (Declaration : Asis.Declaration)
      return        Asis.Declaration
   is
      Arg_Kind  : constant Internal_Element_Kinds := Int_Kind (Declaration);
      Inherited : constant Boolean := Is_From_Inherited (Declaration);

      Arg_Node         : Node_Id;
      Result_Node      : Node_Id;
      Result_Kind      : Internal_Element_Kinds := Not_An_Element;
      Result_Spec_Case : Special_Cases := Not_A_Special_Case;
      Argument_Unit    : Asis.Compilation_Unit;
      Result_Unit      : Asis.Compilation_Unit;

      Result_Element   : Asis.Element := Nil_Element;
   begin
      Check_Validity (Declaration,
        Package_Name & "Corresponding_Declaration");

      case Arg_Kind is
         --  Appropriate Declaration_Kinds returning the argument Declaration:
         when  A_Generic_Function_Declaration           |
               A_Generic_Package_Declaration            |
               A_Generic_Procedure_Declaration          |
               A_Package_Declaration                    |
               A_Package_Renaming_Declaration           |
               A_Single_Task_Declaration                |
               A_Task_Type_Declaration                  |
               A_Protected_Type_Declaration             |
               A_Single_Protected_Declaration           |
               A_Generic_Package_Renaming_Declaration   |
               A_Generic_Procedure_Renaming_Declaration |
               A_Generic_Function_Renaming_Declaration  =>

            Result_Element := Declaration;

         --  Appropriate Declaration_Kinds returning a specification:
         when  A_Function_Body_Declaration              |
               An_Expression_Function_Declaration       |
               A_Function_Body_Stub                     |
               A_Function_Instantiation                 |
               A_Package_Body_Declaration               |
               A_Package_Body_Stub                      |
               A_Package_Instantiation                  |
               A_Procedure_Body_Declaration             |
               A_Procedure_Body_Stub                    |
               A_Procedure_Instantiation                |
               A_Task_Body_Declaration                  |
               A_Task_Body_Stub                         |
               A_Protected_Body_Declaration             |
               A_Protected_Body_Stub                    |
               A_Formal_Package_Declaration             |
               A_Formal_Package_Declaration_With_Box    |
               An_Entry_Body_Declaration                =>

            --  Some specific processing is needed, so we do not change
            --  Result_Element from its null value
            null;

         when  A_Function_Renaming_Declaration  |
               A_Procedure_Renaming_Declaration =>

            --  Here we have to make the difference between renaming-as-body
            --  and renaming-as-declaration

            if not Is_Renaming_As_Body (Declaration) then
               --  The argument declaration should be returned for
               --   renaming-as-declaration
               Result_Element := Declaration;
            end if;

         when A_Function_Declaration        |
               A_Procedure_Declaration      |
               A_Null_Procedure_Declaration |
               An_Entry_Declaration         =>
            --  Here we have to make the difference between inherited and
            --  non-inherited subprograms

            if not Inherited then
               Result_Element := Declaration;
            end if;

         when others =>
            --  Definitely non-appropriate argument
            Raise_ASIS_Inappropriate_Element
              (Package_Name & "Corresponding_Declaration",
               Wrong_Kind => Arg_Kind);
      end case;

      --  and here we have to (try to) return the corresponding spec:
      --
      --  There are the following cases:
      --
      --  1. A body which is the library_item of some compilation
      --     unit;
      --
      --  2. Bodies declared immediately within a library package/library
      --     generic package, but it does not make any problem for this
      --     query, because the tree containing a package body also
      --     contains the package spec;
      --
      --  3. Generic instantiations;
      --
      --  3.1 Formal package declarations (this is ASIS-for-GNAT-specific and
      --      we believe, that in fact this is a fix of the hole in the
      --      ASIS definition
      --  3.2 Library-level instantiation that is not the main unit in the
      --      tree. The instantiation may be rewritten twice - first as a
      --      body (top of expanded body), and then the body node is rewritten
      --      as a package declaration node (top of expanded spec)
      --
      --  4. making the difference between renaming-as-declaration and
      --     renaming-as-body (the problem does not exist together with
      --     the case No.1);
      --
      --  5. body stubs
      --
      --  7. declarations of implicit inherited subprograms
      --
      --  6. The "common" case;
      --
      --  8. ???

      if Is_Nil (Result_Element) and then
         not Acts_As_Spec (Declaration)
      then

         if Arg_Kind = A_Function_Instantiation  then
            Result_Kind      := A_Function_Declaration;
            Result_Spec_Case := Expanded_Subprogram_Instantiation;
         elsif Arg_Kind = A_Procedure_Instantiation then
            Result_Kind      := A_Procedure_Declaration;
            Result_Spec_Case := Expanded_Subprogram_Instantiation;
         elsif Arg_Kind = A_Package_Instantiation      or else
               Arg_Kind = A_Formal_Package_Declaration or else
               Arg_Kind = A_Formal_Package_Declaration_With_Box
         then
            Result_Kind      := A_Package_Declaration;
            Result_Spec_Case := Expanded_Package_Instantiation;
         end if;

         --  first, we compute the result enclosing unit, and we return
         --  Nil_Element if it is Nil_Compilation_Unit or if it is
         --  of Nonexistent kind:

         Argument_Unit := Get_Comp_Unit
           (Encl_Unit_Id (Declaration), Encl_Cont_Id (Declaration));

         if Is_Identical (Declaration, Unit_Declaration (Argument_Unit)) then

            --  A body which is the library_item of some compilation unit
            if Class (Argument_Unit) = A_Public_Declaration_And_Body or else
              Kind (Argument_Unit) in A_Subunit
            then
               Result_Element := Nil_Element;
               --  This assignment does not change anything, we use it just to
               --  simplify the revising of the old code of the function
            elsif not (Arg_Kind = A_Function_Instantiation      or else
                       Arg_Kind = A_Package_Instantiation       or else
                       Arg_Kind = A_Procedure_Instantiation     or else
                       Arg_Kind = A_Formal_Package_Declaration  or else
                       Arg_Kind = A_Formal_Package_Declaration_With_Box)
            then
               Result_Unit := Corresponding_Declaration (Argument_Unit);

               if Exists (Result_Unit) then
                  Result_Element := Unit_Declaration (Result_Unit);
               end if;

            else
               --  here we have to return the expanded generic specification:
               Result_Node := Unit (Top (Argument_Unit));
               --  note, that in case of a library-level generic instantiation,
               --  this is a rewritten node!

               if Arg_Kind = A_Function_Instantiation or else
                  Arg_Kind = A_Procedure_Instantiation
               then
                  --  the difference between the library-level package
                  --  instantiation and the library-level function or procedure
                  --  instantiation is that in the latter case the compiler
                  --  creates the artificial enclosing package:
                  --  Note, that this path may not work correctly because of
                  --  the bug in the tree structure for library-level
                  --  subprogram  instantiations

                  if Nkind (Result_Node) = N_Package_Body then
                     --  the tree created for a compilation unit which is a
                     --  library-level subprogram instantiation
                     Result_Node := Last (Sinfo.Declarations (Result_Node));

                     --  This gave us the expanded body, so
                     Result_Node :=
                        Parent (Parent (Corresponding_Spec (Result_Node)));

                  else
                     Result_Node := Last
                        (Visible_Declarations (Specification (Result_Node)));
                  end if;

               else
                  Reset_Instance_Tree (Argument_Unit, Result_Node);

                  --  In case of a package instantiations, the node is
                  --  rewritten in package body node in case if the generic
                  --  unit has a body
                  if Nkind (Result_Node) = N_Package_Body then
                     Result_Node := Corresponding_Spec (Result_Node);
                     Result_Node := Parent (Result_Node);

                     if Nkind (Result_Node) = N_Defining_Program_Unit_Name then
                        Result_Node := Parent (Result_Node);
                     end if;

                     Result_Node := Parent (Result_Node);
                  end if;

               end if;

               Result_Element :=
                 Node_To_Element_New
                   (Node               => Result_Node,
                   Internal_Kind       => Result_Kind,
                   Spec_Case           => Result_Spec_Case,
                   Using_Original_Node => False,
                   Starting_Element    => Declaration);
            end if;

         else

            --  and now - processing the general case, in which we separate the
            --  following situations:
            --  - generic instantiations - the expanded template should be
            --    returned
            --  - a declaration of an implicit inherited subprogram (including
            --    protected operations or entry - the corresponding explicit
            --    user-defined subprogram or entry should be returned;
            --  - all the rest

            Arg_Node := R_Node (Declaration);
            --  this resets the tree if needed!

            if Arg_Kind = A_Function_Instantiation     or else
               Arg_Kind = A_Procedure_Instantiation    or else
               Arg_Kind = A_Package_Instantiation      or else
               Arg_Kind = A_Formal_Package_Declaration or else
               Arg_Kind = A_Formal_Package_Declaration_With_Box
            then
               Result_Node := Get_Expanded_Spec (Arg_Node);
               Result_Unit := Argument_Unit;
            elsif Inherited then
               --  coming from the declaration of implicit inherited subprogram
               --  to the corresponding explicit declaration of user-defined
               --  subprogram, from which it was ultimately inherited
               Result_Node := Arg_Node;

               Result_Unit :=
                  Enclosing_Unit (Encl_Cont_Id (Declaration), Result_Node);
            else
               --  and, finally, the general case
               Result_Node := Corresponding_Decl_Node (Arg_Node);
               --  Note, that when called here, Corresponding_Decl_Node should
               --  return some non-Empty node.
               --  and here we should check the situation when the
               --  corresponding declaration is located in another
               --  Compilation Unit.

               if Is_From_Instance (Declaration) then
                  Result_Unit := Argument_Unit;
               else
                  Result_Unit :=
                     Enclosing_Unit (Encl_Cont_Id (Declaration), Result_Node);
               end if;

            end if;

            if Special_Case (Declaration) in Expanded_Spec then
               Result_Spec_Case := Special_Case (Declaration);
            end if;

            Result_Element :=
              Node_To_Element_New
                (Node          => Result_Node,
                 Internal_Kind => Result_Kind,
                 Spec_Case     => Result_Spec_Case,
                 In_Unit       => Result_Unit);

            if Is_From_Implicit (Result_Element) then
               --  See FA01-004. This patch is for the situation when a parent
               --  subprogram is defined by a subprogram instantiation. This is
               --  the only case when for Result_Node we have Comes_From_Source
               --  set to False. So we just fix Result_Element:

               Set_From_Implicit (Result_Element, False);
               Set_Special_Case
                 (Result_Element, Expanded_Subprogram_Instantiation);
            end if;

            --  Special processing for the case 3.2 above
            if Arg_Kind = A_Package_Body_Declaration
              and then
               Special_Case (Result_Element) = Expanded_Package_Instantiation
              and then
               Int_Kind (Result_Element) = A_Package_Instantiation
            then
               Set_Int_Kind (Result_Element, A_Package_Declaration);
               Set_Node
                 (Result_Element, Original_Node (R_Node (Result_Element)));
            end if;
         end if;

      end if;

      return Result_Element;
   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Declaration,
               Outer_Call => Package_Name & "Corresponding_Declaration");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Corresponding_Declaration",
            Ex          => Ex,
            Arg_Element => Declaration);
   end Corresponding_Declaration;
-----------------------------------------------------------------------------
   --  NOT IMPLEMENTED

   function Corresponding_Declaration
     (Declaration : Asis.Declaration;
      The_Context : Asis.Context)
      return        Asis.Declaration
   is
   begin
      Check_Validity (Declaration,
        Package_Name & "Corresponding_Declaration");
      Check_Validity (The_Context,
        Package_Name & "Corresponding_Declaration");

      Not_Implemented_Yet (Diagnosis =>
        Package_Name & "Corresponding_Declaration");
      --  ASIS_Failed is raised, Not_Implemented_Error status is set

      return Nil_Element; -- to make the code syntactically correct

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Declaration,
               Outer_Call => Package_Name & "Corresponding_Declaration");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Corresponding_Declaration",
            Ex          => Ex,
            Arg_Element => Declaration);
   end Corresponding_Declaration;
------------------------------------------------------------------------------
   function Corresponding_Body
     (Declaration : Asis.Declaration)
      return        Asis.Declaration
   is
      Arg_Kind          : Internal_Element_Kinds := Int_Kind (Declaration);
      Arg_Node          : Node_Id;
      Arg_Element       : Asis.Declaration := Declaration;
      Result_Node       : Node_Id := Empty;
      Result_Kind       : Internal_Element_Kinds := Not_An_Element;
      Result_Spec_Case  : Special_Cases := Not_A_Special_Case;
      Argument_Unit     : Asis.Compilation_Unit;
      Result_Unit       : Asis.Compilation_Unit;

      Use_Original_Node : Boolean := True;
   begin

      Check_Validity (Declaration, Package_Name & "Corresponding_Body");

      case Arg_Kind is
         --  Appropriate Declaration_Kinds returning the argument Declaration:
         when A_Function_Body_Declaration              |
              A_Function_Body_Stub                     |
              An_Expression_Function_Declaration       |
              A_Function_Renaming_Declaration          |
              A_Package_Body_Declaration               |
              A_Package_Body_Stub                      |
              A_Package_Renaming_Declaration           |
              A_Procedure_Body_Declaration             |
              A_Procedure_Renaming_Declaration         |
              A_Procedure_Body_Stub                    |
              A_Task_Body_Declaration                  |
              A_Task_Body_Stub                         |
              A_Protected_Body_Declaration             |
              A_Protected_Body_Stub                    |
              A_Generic_Package_Renaming_Declaration   |
              A_Generic_Procedure_Renaming_Declaration |
              A_Generic_Function_Renaming_Declaration  |
              An_Entry_Body_Declaration                =>

            return Declaration;

         --  Appropriate Declaration_Kinds returning a body:
         when A_Function_Declaration                |
              A_Function_Instantiation              |
              A_Generic_Package_Declaration         |
              A_Generic_Procedure_Declaration       |
              A_Generic_Function_Declaration        |
              A_Package_Declaration                 |
              A_Package_Instantiation               |
              A_Procedure_Declaration               |
              A_Procedure_Instantiation             |
              A_Single_Task_Declaration             |
              A_Task_Type_Declaration               |
              A_Protected_Type_Declaration          |
              A_Single_Protected_Declaration        |
              A_Formal_Package_Declaration          |
              A_Formal_Package_Declaration_With_Box =>

            null;

         when An_Entry_Declaration =>
            --  This query can work on protected entries only

            if Int_Kind (Enclosing_Element (Declaration)) /=
               A_Protected_Definition
            then
               Raise_ASIS_Inappropriate_Element
                 (Package_Name & "Corresponding_Body",
                  Wrong_Kind => Arg_Kind);
            end if;

         when others =>
            Raise_ASIS_Inappropriate_Element
              (Package_Name & "Corresponding_Body",
               Wrong_Kind => Arg_Kind);
      end case;

      if Trait_Kind (Declaration) = An_Abstract_Trait
        or else
         Is_Implicit_Neq_Declaration (Declaration)
      then
         return Nil_Element;
      end if;

      if (Arg_Kind = A_Function_Declaration or else
          Arg_Kind = A_Procedure_Declaration)
         and then
          Is_From_Inherited (Declaration)
      then
         --  for an implicit inherited subprogram ASIS Corresponding_Body is
         --  a body of an explicit subprogram from which it is inherited
         --  (possibly indirectly)
         Arg_Element := Corresponding_Declaration (Declaration);

         case Declaration_Kind (Arg_Element) is
            when A_Procedure_Body_Declaration     |
                 A_Function_Body_Declaration      |
                 A_Procedure_Renaming_Declaration |
                 A_Function_Renaming_Declaration  =>
               return Arg_Element;
            when A_Procedure_Declaration |
                 A_Function_Declaration  =>
               null;
            when others =>
               return Nil_Element;
         end case;

      elsif Arg_Kind in An_Internal_Generic_Instantiation
         or else
            Arg_Kind in A_Formal_Package_Declaration ..
            A_Formal_Package_Declaration_With_Box
      then
         --  for an implicit inherited subprogram ASIS Corresponding_Body is
         --  a body of an explicit subprogram from which it is inherited
         --  (possibly indirectly)
         Arg_Element := Corresponding_Declaration (Declaration);

         if Is_Nil (Arg_Element) or else
            Int_Kind (Arg_Element) in A_Procedure_Renaming_Declaration ..
                                      A_Function_Renaming_Declaration
         then
            --  This stands here because implicit constructs are supported
            --  only partially by ASIS (???)
            --  The second condition is needed for subprograms inherited
            --  from explicit renamings, see 8728-A23
            return Nil_Element;
         end if;

      else
         Arg_Element := Declaration;
         --  in case if Declaration is in a library package spec and the
         --  package body is not in the enclosing element's tree, Arg_Element
         --  should be reset to Is_Equial Element obtained from the tree
         --  for the package body, but we are trying to do this expensive
         --  operation only when it is really necessary.
      end if;

      Arg_Kind := Int_Kind (Arg_Element);

      --  and for these cases we return the corresponding body, if any:
      --
      --    A_Function_Declaration
      --    A_Generic_Package_Declaration
      --    A_Generic_Procedure_Declaration
      --    A_Generic_Function_Declaration
      --    A_Package_Declaration
      --    A_Procedure_Declaration
      --    A_Single_Task_Declaration
      --    A_Task_Type_Declaration
      --    A_Protected_Type_Declaration
      --    A_Single_Protected_Declaration
      --    A_Function_Instantiation
      --    A_Package_Instantiation
      --    A_Procedure_Instantiation
      --
      --  There are following cases which require special processing:
      --  1. Program units declared within a library package or a library
      --     generic package (directly or within a nested package)- we have
      --     to use the tree containing the corresponding library unit body,
      --     if any, otherwise Corresponding_Body will be Nil_Element;
      --  2. renaming-as-body: in this case in the tree the Corresponding_Body
      --     field set for nodes representing declarations which can (must)
      --     have bodies as completions points not to the corresponding
      --     renaming declaration, but to the body implicitly created by the
      --     compiler;
      --  3. Library-level program units
      --  4. Expanded generic bodies
      --  5. Pragma Import as a subprogram completion

      --  First, deal with the case of pragma Import:

      if (Int_Kind (Declaration) in
           A_Procedure_Declaration .. A_Function_Declaration
         or else
          Int_Kind (Declaration) in
           A_Generic_Procedure_Declaration .. A_Generic_Function_Declaration)
        and then
          not Is_Part_Of_Inherited (Declaration)
      then
         Arg_Node := R_Node (Declaration);
         Arg_Node := Defining_Unit_Name (Specification (Arg_Node));

         if Nkind (Arg_Node) = N_Defining_Program_Unit_Name then
            Arg_Node := Defining_Identifier (Arg_Node);
         end if;

         if Is_Imported (Arg_Node) then

            Result_Node := Get_Importing_Pragma (Arg_Node);

            pragma Assert (Present (Result_Node));

            return Node_To_Element_New
              (Node             => Result_Node,
               Starting_Element => Arg_Element);

         end if;

      end if;

      Argument_Unit := Get_Comp_Unit
        (Encl_Unit_Id (Arg_Element), Encl_Cont_Id (Arg_Element));

      if Is_From_Instance (Arg_Element) then
         Result_Unit := Argument_Unit;
      else
         Result_Unit := Corresponding_Body (Argument_Unit);

         --  Note, that this is not a correct enclosing unit for a result
         --  in case for a subprogram declared in a local package for which
         --  the package body is presented by the stub. So we'll have to
         --  recompute Result_Unit before forming a result.

         if Is_Identical (Arg_Element, Unit_Declaration (Argument_Unit)) then

            if not Exists (Result_Unit) then
               return Nil_Element;
               --  what else could we do?
            else
               return Unit_Declaration (Result_Unit);
            end if;

         end if;

      end if;

      Arg_Node    := R_Node (Arg_Element);
      --  this resets the tree!
      --  we use R_Node, because a single task declaration is rewritten
      --  in a task type declaration, and the Corresponding_Body field
      --  is not set for the original node

      --  if we are here, we have Arg_Element as some declaration inside the
      --  spec of a library package or library generic package (may be, nested
      --  in a local subpackage). There are two possibilities for a
      --  corresponding body (which is to be a completion of Arg_Element):
      --  renaming as a body in the library (generic) package spec or
      --  some construct in the corresponding library package body.

      --  For the second possibility, we have to be in the tree created for
      --  a package body (if any) to be able to compute the corresponding
      --  body for Arg_Element. But if Arg_Element is obtained from the tree
      --  containing only spec for this package, we have to recompute
      --  Arg_Element from the tree for the package body. It is expansive,
      --  and we would like to avoid this if possible.

      if Arg_Kind = A_Function_Declaration or else
         Arg_Kind = A_Procedure_Declaration
      then
         Result_Node := Get_Renaming_As_Body (Node      => Arg_Node,
                                              Spec_Only => True);
         if Present (Result_Node) then
            --  this means, that the subprogram declaration is completed
            --  by renaming-as-body already in the package spec, and we can
            --  return the non-nil result without dealing with the body
            --  of this package
            if Arg_Kind = A_Function_Declaration then
               Result_Kind := A_Function_Renaming_Declaration;
            else
               Result_Kind := A_Procedure_Renaming_Declaration;
            end if;

            return Node_To_Element_New
              (Node             => Result_Node,
               Internal_Kind    => Result_Kind,
               Starting_Element => Arg_Element);

         end if;
      end if;

      --  if we are here, Arg_Element is not completed in the spec of the
      --  library (generic) package.

      if not Exists (Result_Unit) then
         return Nil_Element;
      end if;

      Result_Node := Corresponding_Body_Node (Arg_Node);

      if No (Result_Node) then
         --  There are two possibilities when the corresponding body may
         --  exist:
         --
         --  1. A subprogram completed by pragma Import
         --
         --  2. Arg_Element represent a declaration which is located
         --     in a library (generic) package spec (and Arg_Element
         --     is not from expanded generic!). The corresponding body
         --     may be located in a library package body, which may not
         --     be presented in the tree which is currently accessed
         --  3. Arg_Element represent a declaration which is from expanded
         --     generic spec corresponding to a library-level instantiation.
         --     in this case, if the construct is completed in an expanded
         --     body, we need the tree for expanded body, and this tree
         --     is presented only in the tree created for such a library-level
         --     instantiation.

         if Arg_Kind in A_Procedure_Declaration .. A_Function_Declaration
           and then
            Special_Case (Arg_Element) not in Expanded_Spec
         then
            Result_Node := Defining_Unit_Name (Specification (Arg_Node));

            Result_Node := First_Rep_Item (Result_Node);

            while Present (Result_Node) loop
               if Nkind (Result_Node) = N_Pragma
                and then
                  Chars (Pragma_Identifier (Result_Node)) = Name_Import
               then
                  exit;
               end if;

               Result_Node := Next_Rep_Item (Result_Node);
            end loop;

            if Nkind (Result_Node) = N_Pragma
             and then
               Chars (Pragma_Identifier (Result_Node)) = Name_Import
            then
               Result_Kind := An_Import_Pragma;
            else
               Result_Node := Empty;
            end if;

         end if;

         if No (Result_Node) then

            case Kind (Argument_Unit) is

               when A_Package |
                    A_Generic_Package =>

                  --  ??? This case statement should definitely be simplified
                  --  ??? by unifying the actions needed to reset the tree in a
                  --  ??? way to get the tree containing the body in question

                  if not Is_From_Instance (Arg_Element) then
                     Reset_For_Body (Arg_Element, Result_Unit);
                     --  ??? Should be replaced by less expensive
                     --  GNAT tree traversing
                     Arg_Node := R_Node (Arg_Element);
                  else
                     Reset_Instance_Tree (Argument_Unit, Arg_Node);
                     --  Should we check here if Arg_Node is already in some
                     --  package body? There is a check in Reset_Instance_Tree,
                     --  but is it enough?
                  end if;

               when A_Generic_Unit_Instance |
                    A_Library_Unit_Body =>
                  --  Here we are sure, that we are working not with the
                  --  instantiation itself, but with some spec from expanded
                  --  generic. This expanded generic spec may be in some body
                  --  unit, and if this body unit is not compiled on its own,
                  --  the needed spec -> body link is missed for the expanded
                  --  generics, so we have to go to the main tree for the body
                  --   (see 9327-007)

                  if Is_From_Instance (Arg_Node)
                    or else
                     Arg_Kind in An_Internal_Generic_Instantiation
                    or else
                     Special_Case (Arg_Element) in Expanded_Spec
                  then
                     Reset_Instance_Tree (Argument_Unit, Arg_Node);
                  end if;

               when others =>
                  null;
            end case;

            Result_Node := Corresponding_Body_Node (Arg_Node);
         end if;
      end if;

      if Special_Case (Arg_Element) in Expanded_Spec then
         Result_Spec_Case := Special_Case (Arg_Element);
         Use_Original_Node := False;
      end if;

      if Present (Result_Node) then
         Result_Unit :=
           Enclosing_Unit (Encl_Cont_Id (Declaration), Result_Node);

         return Node_To_Element_New
           (Node                => Result_Node,
            Internal_Kind       => Result_Kind,
            Spec_Case           => Result_Spec_Case,
            Using_Original_Node => Use_Original_Node,
            In_Unit             => Result_Unit);

      else
         return Nil_Element;
      end if;

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Declaration,
               Outer_Call => Package_Name & "Corresponding_Body");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Corresponding_Body",
            Ex          => Ex,
            Arg_Element => Declaration);
   end Corresponding_Body;
------------------------------------------------------------------------------
   --  NOT IMPLEMENTED

   function Corresponding_Body
     (Declaration : Asis.Declaration;
      The_Context : Asis.Context)
      return        Asis.Declaration
   is
   begin
      Check_Validity (Declaration, Package_Name & "Corresponding_Body");
      Check_Validity (The_Context,     Package_Name & "Corresponding_Body");

      Not_Implemented_Yet (Diagnosis =>
        Package_Name & "Corresponding_Body");
      --  ASIS_Failed is raised, Not_Implemented_Error status is set

      return Nil_Element; -- to make the code syntactically correct

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Declaration,
               Outer_Call => Package_Name & "Corresponding_Body");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Corresponding_Body",
            Ex          => Ex,
            Arg_Element => Declaration);
   end Corresponding_Body;
------------------------------------------------------------------------------
   function Corresponding_Subprogram_Derivation
     (Declaration : Asis.Declaration)
      return        Asis.Declaration
   is
      Arg_Kind    : constant Internal_Element_Kinds := Int_Kind (Declaration);
      Result_Unit : Asis.Compilation_Unit;
      Result_Node : Node_Id;
      Subpr_Node  : Node_Id                := Empty;
      Result_Kind : Internal_Element_Kinds := Not_An_Element;
      Inherited   : Boolean := False;
      Spec_Case   : Special_Cases          := Not_A_Special_Case;
   begin
      Check_Validity (Declaration,
        Package_Name & "Corresponding_Subprogram_Derivation");

      if not ((Arg_Kind = A_Function_Declaration or else
               Arg_Kind = A_Procedure_Declaration)
        and then
               Is_From_Inherited (Declaration))
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Corresponding_Subprogram_Derivation",
            Wrong_Kind => Arg_Kind);
      end if;

      Result_Node := Alias (Node_Field_1 (Declaration));

      --  and now - up the tree to the declaration node if needed
      if No (Alias (Result_Node)) then
         Result_Node := Parent (Result_Node);

         if Nkind (Result_Node) = N_Procedure_Specification or else
           Nkind (Result_Node) = N_Function_Specification
         then
            Result_Node := Parent (Result_Node);
         end if;

      else
         if Is_Generic_Instance (Result_Node) then
            Spec_Case := Expanded_Subprogram_Instantiation;
         else
            Inherited  := True;
            Subpr_Node := Result_Node;
         end if;
         Result_Node := Node (Declaration);

         if Arg_Kind = A_Function_Declaration then
            Result_Kind := A_Function_Declaration;
         else
            Result_Kind := A_Procedure_Declaration;
         end if;

      end if;

      Result_Unit := Enclosing_Unit (Encl_Cont_Id (Declaration), Result_Node);

      return Node_To_Element_New
        (Node          => Result_Node,
         Node_Field_1  => Subpr_Node,
         Internal_Kind => Result_Kind,
         Inherited     => Inherited,
         Spec_Case     => Spec_Case,
         In_Unit       => Result_Unit);

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Declaration,
               Outer_Call =>
              Package_Name & "Corresponding_Subprogram_Derivation");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name &
                           "Corresponding_Subprogram_Derivation",
            Ex          => Ex,
            Arg_Element => Declaration);
   end Corresponding_Subprogram_Derivation;

   ------------------------
   -- Corresponding_Type --
   ------------------------

   function Corresponding_Type
     (Declaration : Asis.Declaration)
      return        Asis.Type_Definition
   is
      Arg_Kind    : constant Internal_Element_Kinds := Int_Kind (Declaration);
      Result_Node : Node_Id;
      Result_Unit : Asis.Compilation_Unit;
      Result_Kind : Internal_Element_Kinds := Not_An_Element;
   begin
      Check_Validity (Declaration, Package_Name & "Corresponding_Type");

      if not (Arg_Kind in A_Function_Declaration  |
                          A_Procedure_Declaration
            and then
               Is_From_Implicit (Declaration))
      then
         Raise_ASIS_Inappropriate_Element
           (Package_Name & "Corresponding_Type",
            Wrong_Kind => Arg_Kind);
      end if;

      Result_Node := Parent (Node_Field_1 (Declaration));

      if Nkind (Original_Node (Result_Node)) =
         N_Private_Extension_Declaration
      then
         Result_Kind := A_Private_Extension_Definition;
      else
         Result_Node := Sinfo.Type_Definition (Original_Node (Result_Node));
      end if;

      Result_Unit := Enclosing_Unit (Encl_Cont_Id (Declaration), Result_Node);

      return Node_To_Element_New (Node          => Result_Node,
                                  Internal_Kind => Result_Kind,
                                  In_Unit       => Result_Unit);

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Declaration,
               Outer_Call => Package_Name & "Corresponding_Type");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Corresponding_Type",
            Ex          => Ex,
            Arg_Element => Declaration);
   end Corresponding_Type;
------------------------------------------------------------------------------

   function Corresponding_Equality_Operator
     (Declaration : Asis.Declaration)
      return        Asis.Declaration
   is
      Arg_Kind     : constant Internal_Element_Kinds := Int_Kind (Declaration);
      Result       :          Asis.Declaration       := Nil_Element;
      Res_Node     : Node_Id;
      Res_NF_1     : Node_Id := Empty;
      Is_Exp_Spb   : Boolean := False;
      Is_Inherited : Boolean := False;
      Is_From_Inst : Boolean := False;
   begin
      Check_Validity (Declaration,
        Package_Name & "Corresponding_Equality_Operator");

      if not (Arg_Kind = A_Function_Declaration      or else
              Arg_Kind = A_Function_Body_Declaration or else
              Arg_Kind = A_Function_Renaming_Declaration)
      then
         Raise_ASIS_Inappropriate_Element
           (Package_Name & "Corresponding_Equality_Operator",
            Wrong_Kind => Arg_Kind);
      end if;

      if Is_Bool_Eq_Declaration (Declaration) then

         if Is_Tagged_Type_Eq (Declaration) then
            Result := Declaration;
            Set_Special_Case (Result, Is_From_Imp_Neq_Declaration);
         else
            if Is_Part_Of_Inherited (Declaration) then
               Res_Node := Node_Field_1 (Declaration);
            else
               Res_Node :=
                 Defining_Unit_Name (Specification (Node (Declaration)));
            end if;

            if Is_Generic_Instance (Res_Node) then
               --  If "=" is defined by a generic instantiation, we have to go
               --  to the enclosing scope - where the instantiation itself
               --  takes place
               Res_Node := Defining_Unit_Name (Parent (Node (Declaration)));
            end if;

            while not (Nkind (Res_Node) = N_Defining_Operator_Symbol
                    and then
                       Chars (Res_Node) = Name_Op_Ne)
            loop
               Res_Node := Next_Entity (Res_Node);
            end loop;

            Res_Node := Parent (Parent (Res_Node));

            Result := Node_To_Element_New
                           (Node             => Res_Node,
                            Spec_Case        => Is_From_Imp_Neq_Declaration,
                            In_Unit          => Encl_Unit (Declaration));

         end if;

         Set_From_Implicit (Result, True);

         --  In no case the result can be inherited:
         Set_From_Inherited (Result, False);

      elsif Is_Implicit_Neq_Declaration (Declaration) then

         if Is_Tagged_Type_Eq (Declaration) then
            Res_Node := R_Node (Declaration);
            Res_Node := Defining_Unit_Name (Specification (Res_Node));
         else
            Res_Node :=
              Defining_Unit_Name (Specification (Node (Declaration)));
            Res_Node := Corresponding_Equality (Res_Node);
         end if;

         if Nkind (Original_Node (Parent (Res_Node))) in
              N_Formal_Type_Declaration       |
              N_Full_Type_Declaration         |
              N_Incomplete_Type_Declaration   |
              N_Iterator_Specification        |
              N_Loop_Parameter_Specification  |
              N_Object_Declaration            |
              N_Protected_Type_Declaration    |
              N_Private_Extension_Declaration |
              N_Private_Type_Declaration
         then
            Res_NF_1 := Res_Node;

            Res_Node := Alias (Res_Node);

            while Present (Alias (Res_Node))
                and then
                  not Comes_From_Source (Res_Node)
            loop
               Res_Node := Alias (Res_Node);
            end loop;

            Is_Inherited := True;
            Is_From_Inst := Is_From_Instance (Res_NF_1);
         end if;

         if Is_Generic_Instance (Res_Node) then
            Is_Exp_Spb := True;
         end if;

         if Is_Tagged_Type_Eq (Declaration) then
            Result := Declaration;
            Set_Special_Case (Result, Not_A_Special_Case);
         else
            Res_Node := Parent (Parent (Res_Node));

            Result := Node_To_Element_New
                           (Node             => Res_Node,
                            Node_Field_1     => Res_NF_1,
                            In_Unit          => Encl_Unit (Declaration));
         end if;

         if not (Is_From_Inherited (Declaration)) then
            Set_From_Implicit (Result, False);
         end if;

         if Is_Exp_Spb then
            Set_From_Instance (Result, True);
            Set_Special_Case   (Result, Expanded_Subprogram_Instantiation);
         else
            Set_Special_Case (Result, Not_A_Special_Case);
         end if;

         if Is_Inherited then
            Set_From_Implicit  (Result, True);
            Set_From_Inherited (Result, True);
            Set_From_Instance  (Result, Is_From_Inst);
         end if;

      end if;

      return Result;

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Declaration,
               Outer_Call => Package_Name & "Corresponding_Equality_Operator");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Corresponding_Equality_Operator",
            Ex          => Ex,
            Arg_Element => Declaration);
   end Corresponding_Equality_Operator;
-----------------------------------------------------------------------------

   function Visible_Part_Declarative_Items
     (Declaration     : Asis.Declaration;
      Include_Pragmas : Boolean := False)
      return            Asis.Declarative_Item_List
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Declaration);
      Arg_Node : Node_Id;
   begin
      Check_Validity (Declaration,
        Package_Name & "Visible_Part_Declarative_Items");
      if not (Arg_Kind = A_Package_Declaration or else
        Arg_Kind = A_Generic_Package_Declaration)
      then
         Raise_ASIS_Inappropriate_Element
           (Package_Name & "Visible_Part_Declarative_Items",
            Wrong_Kind => Arg_Kind);
      end if;

      Arg_Node := R_Node (Declaration);

      if Arg_Node = Standard_Package_Node then
         return
           N_To_E_List_New
              (List             =>
                 Visible_Declarations (Specification (Arg_Node)),
               Include_Pragmas  => Include_Pragmas,
               Starting_Element => Declaration)
            &
               Get_Numeric_Error_Renaming;

      else

         if Nkind (Arg_Node) = N_Package_Body then
            --  We may have N_Package_Body in case of an expanded spec
            --  to the library-level instantiation corresponding
            Arg_Node := Corresponding_Spec (Arg_Node);

            while Nkind (Arg_Node) /= N_Package_Specification loop
               Arg_Node := Parent (Arg_Node);
            end loop;

            Arg_Node := Parent (Arg_Node);

         end if;

         declare
            Result : constant Element_List :=
              N_To_E_List_New
                (List             =>
                   Visible_Declarations (Specification (Arg_Node)),
                 Include_Pragmas  => Include_Pragmas,
                 Starting_Element => Declaration);
            First_Idx         : constant List_Index   := Result'First;
            Last_Idx          : constant ASIS_Integer := Result'Last;
            Last_Limited_View :          ASIS_Integer := First_Idx - 1;

            Limited_Views : Element_List (First_Idx .. Last_Idx);
         begin
            if Is_From_Limited_View (Declaration) then
               for J in Result'Range loop
                  if Belongs_To_Limited_View (Result (J)) then
                     Last_Limited_View := Last_Limited_View + 1;
                     Limited_Views (Last_Limited_View) := Result (J);
                     Convert_To_Limited_View
                       (Limited_Views (Last_Limited_View));
                  end if;
               end loop;

               return Limited_Views (First_Idx .. Last_Limited_View);
            else
               return Result;
            end if;
         end;
      end if;

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Declaration,
               Outer_Call => Package_Name & "Visible_Part_Declarative_Items",
               Bool_Par   => Include_Pragmas);
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Visible_Part_Declarative_Items",
            Ex          => Ex,
            Arg_Element => Declaration,
            Bool_Par_ON => Include_Pragmas);
   end Visible_Part_Declarative_Items;
------------------------------------------------------------------------------

   function Is_Private_Present
     (Declaration : Asis.Declaration)
      return        Boolean
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Declaration);
      Arg_Node : Node_Id;
   begin
      Check_Validity (Declaration, Package_Name & "Is_Private_Present");

      if not (Arg_Kind = A_Package_Declaration or else
              Arg_Kind = A_Generic_Package_Declaration)
        or else
         Is_From_Limited_View (Declaration)
      then
         return False;
      end if;

      Arg_Node := Node (Declaration);

      return Present (Private_Declarations (Specification (Arg_Node)));
   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Declaration,
               Outer_Call => Package_Name & "Is_Private_Present");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Is_Private_Present",
            Ex          => Ex,
            Arg_Element => Declaration);
   end Is_Private_Present;
------------------------------------------------------------------------------

   function Private_Part_Declarative_Items
     (Declaration     : Asis.Declaration;
      Include_Pragmas : Boolean := False)
      return            Asis.Declarative_Item_List
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Declaration);
      Arg_Node : Node_Id;
   begin
      Check_Validity (Declaration,
        Package_Name & "Private_Part_Declarative_Items");

      if not (Arg_Kind = A_Package_Declaration or else
        Arg_Kind = A_Generic_Package_Declaration)
      then
         Raise_ASIS_Inappropriate_Element
           ("Private_Part_Declarative_Items",
            Wrong_Kind => Arg_Kind);
      end if;

      if Is_From_Limited_View (Declaration) then
         return Nil_Element_List;
      end if;

      Arg_Node := R_Node (Declaration);

      if Nkind (Arg_Node) = N_Package_Body then
         --  We may have N_Package_Body in case of an expanded spec
         --  to the library-level instantiation corresponding
         Arg_Node := Corresponding_Spec (Arg_Node);

         while Nkind (Arg_Node) /= N_Package_Specification loop
            Arg_Node := Parent (Arg_Node);
         end loop;

         Arg_Node := Parent (Arg_Node);

      end if;

      return N_To_E_List_New
        (List             => Private_Declarations (Specification (Arg_Node)),
        Include_Pragmas  => Include_Pragmas,
        Starting_Element => Declaration);
   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Declaration,
               Outer_Call => Package_Name & "Private_Part_Declarative_Items",
               Bool_Par   => Include_Pragmas);
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Private_Part_Declarative_Items",
            Ex          => Ex,
            Arg_Element => Declaration,
            Bool_Par_ON => Include_Pragmas);
   end Private_Part_Declarative_Items;
------------------------------------------------------------------------------
   function Renamed_Entity
     (Declaration : Asis.Declaration)
      return        Asis.Expression
   is
      Arg_Kind    : constant Internal_Element_Kinds := Int_Kind (Declaration);
      Arg_Node    : Node_Id;
      Result_Node : Node_Id;

      Result : Asis.Expression;
   begin
      Check_Validity (Declaration, Package_Name & "Renamed_Entity");
      if not (Arg_Kind = An_Object_Renaming_Declaration           or else
        Arg_Kind = An_Exception_Renaming_Declaration        or else
        Arg_Kind = A_Package_Renaming_Declaration           or else
        Arg_Kind = A_Procedure_Renaming_Declaration         or else
        Arg_Kind = A_Function_Renaming_Declaration          or else
        Arg_Kind = A_Generic_Package_Renaming_Declaration   or else
        Arg_Kind = A_Generic_Procedure_Renaming_Declaration or else
        Arg_Kind = A_Generic_Function_Renaming_Declaration)
      then
         Raise_ASIS_Inappropriate_Element
           (Package_Name & "Renamed_Entity",
            Wrong_Kind => Arg_Kind);
      end if;

      if Special_Case (Declaration) = Numeric_Error_Renaming then
         Result := Declaration;
         Set_Int_Kind (Result, An_Identifier);
      else
         Arg_Node := Node (Declaration);
         Result_Node := Sinfo.Name (Arg_Node);

         Result := Node_To_Element_New
                     (Node             => Result_Node,
                      Starting_Element => Declaration);

      end if;

      --  In case if we have a subprogram renaming, and the renamed entity is
      --  an attribute reference, we have to correct the result kind, see
      --  FA26-004

      if Arg_Kind in
           A_Procedure_Renaming_Declaration .. A_Function_Renaming_Declaration
       and then
         (Int_Kind (Result) = A_Function_Call
         or else
           Int_Kind (Result) = A_Procedure_Call_Statement)
      then
         Set_Int_Kind (Result, Subprogram_Attribute_Kind (Result_Node));
      end if;

      return Result;

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Declaration,
               Outer_Call => Package_Name & "Renamed_Entity");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Renamed_Entity",
            Ex          => Ex,
            Arg_Element => Declaration);
   end Renamed_Entity;
------------------------------------------------------------------------------
   function Corresponding_Base_Entity
     (Declaration : Asis.Declaration)
      return        Asis.Expression
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Declaration);

      Arg_Node      : Node_Id;
      Result_Node   : Node_Id                := Empty;
      Res_Kind      : Node_Kind;
      Res_Elem_Kind : Internal_Element_Kinds := Not_An_Element;
      Result_Unit   : Asis.Compilation_Unit;
   begin
      Check_Validity (Declaration,
        Package_Name & "Corresponding_Base_Entity");

      if not (Arg_Kind = An_Object_Renaming_Declaration           or else
              Arg_Kind = An_Exception_Renaming_Declaration        or else
              Arg_Kind = A_Procedure_Renaming_Declaration         or else
              Arg_Kind = A_Function_Renaming_Declaration          or else
              Arg_Kind = A_Package_Renaming_Declaration           or else
              Arg_Kind = A_Generic_Package_Renaming_Declaration   or else
              Arg_Kind = A_Generic_Procedure_Renaming_Declaration or else
              Arg_Kind = A_Generic_Function_Renaming_Declaration)
      then
         Raise_ASIS_Inappropriate_Element
           (Package_Name & "Corresponding_Base_Entity",
            Wrong_Kind => Arg_Kind);
      end if;

      --  Let's first handle a special case of fake Numeric_Error renaming
      --  (see B712-0050

      if Special_Case (Declaration) = Numeric_Error_Renaming then
         --  Nothing to unwind:
         return Renamed_Entity (Declaration);
      end if;

      Arg_Node := Node (Declaration);
      --  the first renaming declaration in the renaming chain

      Result_Node := Sinfo.Name (Arg_Node);
      Arg_Node := R_Node (Declaration);
      --  to be able to deal with renamings of task entries in a uniform way

      while Present (Arg_Node) loop

         if Is_Rewrite_Substitution (Arg_Node) and then
            Nkind (Arg_Node) = N_Subprogram_Declaration
         then
            exit;
            --  renaming a task entry as a subprogram, no renaming chain
            --  any more
         end if;

         Res_Kind := Nkind (Result_Node);

         if Res_Kind = N_Selected_Component   or else
            Res_Kind = N_Indexed_Component    or else
            Res_Kind = N_Explicit_Dereference or else
            Res_Kind = N_Slice                or else
            Res_Kind = N_Function_Call        or else
            Res_Kind = N_Type_Conversion
         then

            --  The name after 'renames' has no chance to be defined by a
            --  renamed declaration
            exit;

         elsif Entity_Present (Result_Node) then
            Arg_Node := Entity (Result_Node);

         elsif Res_Kind = N_Attribute_Reference then

            if Arg_Kind in A_Procedure_Renaming_Declaration ..
                           A_Function_Renaming_Declaration
            then
               --  Renaming of an attribute-subprogram as a "normal" subprogram
               Res_Elem_Kind := Subprogram_Attribute_Kind  (Result_Node);
               exit;
            end if;

         else
            null;
            pragma Assert (False);
         end if;

         Arg_Node := Parent (Arg_Node);

         if Nkind (Arg_Node) in N_Subprogram_Specification then
            Arg_Node := Parent (Arg_Node);
         end if;

         if Nkind (Arg_Node) not in N_Renaming_Declaration then
            --  we have achieved the end of the renaming chain
            exit;
         else
            --  we are still in the chain
            Result_Node := Sinfo.Name (Arg_Node);
         end if;

      end loop;

      --  and now we have to compute the Result_Unit and to make the
      --  consistency check:

      Result_Unit := Enclosing_Unit
        (Encl_Cont_Id (Declaration), Result_Node);

      return Node_To_Element_New (Node          => Result_Node,
                                  Internal_Kind => Res_Elem_Kind,
                                  In_Unit       => Result_Unit);

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Declaration,
               Outer_Call => Package_Name & "Corresponding_Base_Entity");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Corresponding_Base_Entity",
            Ex          => Ex,
            Arg_Element => Declaration);
   end Corresponding_Base_Entity;
------------------------------------------------------------------------------

   function Protected_Operation_Items
     (Declaration     : Asis.Declaration;
      Include_Pragmas : Boolean := False)
      return            Asis.Declarative_Item_List
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Declaration);
      Arg_Node : Node_Id;
   begin

      Check_Validity (Declaration,
        Package_Name & "Protected_Operation_Items");

      if not (Arg_Kind = A_Protected_Body_Declaration) then
         Raise_ASIS_Inappropriate_Element
           (Package_Name & "Protected_Operation_Items",
            Wrong_Kind => Arg_Kind);
      end if;

      Arg_Node := Node (Declaration);

      return N_To_E_List_New
               (List             => Sinfo.Declarations (Arg_Node),
                Include_Pragmas  => Include_Pragmas,
                Starting_Element => Declaration);

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Declaration,
               Outer_Call => Package_Name & "Protected_Operation_Items",
               Bool_Par   => Include_Pragmas);
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Protected_Operation_Items",
            Ex          => Ex,
            Arg_Element => Declaration,
            Bool_Par_ON => Include_Pragmas);
   end Protected_Operation_Items;
------------------------------------------------------------------------------

   function Entry_Family_Definition
     (Declaration : Asis.Declaration)
      return        Asis.Discrete_Subtype_Definition
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Declaration);
      Arg_Node : Node_Id;
      Result_Node : Node_Id;
   begin
      Check_Validity (Declaration,
        Package_Name & "Entry_Family_Definition");
      if not (Arg_Kind = An_Entry_Declaration) then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Entry_Family_Definition",
            Wrong_Kind => Arg_Kind);
      end if;

      Arg_Node := Node (Declaration);
      Result_Node := Sinfo.Discrete_Subtype_Definition (Arg_Node);

      if Present (Result_Node) then
         return Node_To_Element_New
           (Node             => Result_Node,
           Starting_Element => Declaration);
      else
         return Nil_Element;
      end if;
   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Declaration,
               Outer_Call => Package_Name & "Entry_Family_Definition");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Entry_Family_Definition",
            Ex          => Ex,
            Arg_Element => Declaration);
   end Entry_Family_Definition;
------------------------------------------------------------------------------
   function Entry_Index_Specification
     (Declaration : Asis.Declaration)
      return        Asis.Declaration
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Declaration);
      Arg_Node : Node_Id;
      Result_Node : Node_Id;
   begin
      Check_Validity (Declaration,
        Package_Name & "Entry_Index_Specification");
      if not (Arg_Kind = An_Entry_Body_Declaration) then
         Raise_ASIS_Inappropriate_Element (Diagnosis =>
           Package_Name & "Entry_Index_Specification",
           Wrong_Kind => Arg_Kind);
      end if;

      Arg_Node := Node (Declaration);

      Result_Node := Entry_Index_Specification
        (Entry_Body_Formal_Part (Arg_Node));

      if Present (Result_Node) then
         return Node_To_Element_New
           (Node             => Result_Node,
           Starting_Element => Declaration,
           Internal_Kind => An_Entry_Index_Specification);
      else
         return Nil_Element;
      end if;

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Declaration,
               Outer_Call => Package_Name & "Entry_Index_Specification");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Entry_Index_Specification",
            Ex          => Ex,
            Arg_Element => Declaration);
   end Entry_Index_Specification;
------------------------------------------------------------------------------
   function Entry_Barrier
     (Declaration : Asis.Declaration)
      return        Asis.Expression
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Declaration);
      Arg_Node : Node_Id;
   begin
      Check_Validity (Declaration, Package_Name & "Entry_Barrier");
      if not (Arg_Kind = An_Entry_Body_Declaration) then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Entry_Barrier",
            Wrong_Kind => Arg_Kind);
      end if;

      Arg_Node := Node (Declaration);

      return Node_To_Element_New
        (Node             => Condition (Entry_Body_Formal_Part (Arg_Node)),
        Starting_Element => Declaration);
   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Declaration,
               Outer_Call => Package_Name & "Entry_Barrier");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Entry_Barrier",
            Ex          => Ex,
            Arg_Element => Declaration);
   end Entry_Barrier;
------------------------------------------------------------------------------
   function Corresponding_Subunit
     (Body_Stub : Asis.Declaration)
      return      Asis.Declaration
   is
      Arg_Node       : Node_Id;
      Arg_Kind       : constant Internal_Element_Kinds := Int_Kind (Body_Stub);
      Arg_Unit       : Asis.Compilation_Unit;
      Result_Subunit : Asis.Compilation_Unit;
   begin
      Check_Validity (Body_Stub, Package_Name & "Corresponding_Subunit");

      if not (Arg_Kind = A_Function_Body_Stub  or else
              Arg_Kind = A_Package_Body_Stub   or else
              Arg_Kind = A_Procedure_Body_Stub or else
              Arg_Kind = A_Task_Body_Stub      or else
              Arg_Kind = A_Protected_Body_Stub)
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Corresponding_Subunit",
            Wrong_Kind => Arg_Kind);
      end if;

      Arg_Node := Node (Body_Stub);

      Arg_Unit := Encl_Unit (Body_Stub);

      Result_Subunit := Get_Subunit (Parent_Body => Arg_Unit,
                                     Stub_Node   => Arg_Node);

      if Exists (Result_Subunit) then
         return Unit_Declaration (Result_Subunit);
      else
         return Nil_Element;
      end if;

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Body_Stub,
               Outer_Call => Package_Name & "Corresponding_Subunit");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Corresponding_Subunit",
            Ex          => Ex,
            Arg_Element => Body_Stub);
   end Corresponding_Subunit;
------------------------------------------------------------------------------
   --  NOT IMPLEMENTED

   function Corresponding_Subunit
     (Body_Stub   : Asis.Declaration;
      The_Context : Asis.Context)
      return        Asis.Declaration
   is
   begin
      Check_Validity (Body_Stub, Package_Name & "Corresponding_Subunit");
      Check_Validity (The_Context, Package_Name & "Corresponding_Subunit");

      Not_Implemented_Yet (Diagnosis =>
        Package_Name & "Corresponding_Subunit");
      --  ASIS_Failed is raised, Not_Implemented_Error status is set

      return Nil_Element; -- to make the code syntactically correct

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Body_Stub,
               Outer_Call => Package_Name & "Corresponding_Subunit");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Corresponding_Subunit",
            Ex          => Ex,
            Arg_Element => Body_Stub);
   end Corresponding_Subunit;
------------------------------------------------------------------------------

   function Is_Subunit (Declaration : Asis.Declaration) return Boolean is
      Arg_Kind   : constant Internal_Element_Kinds := Int_Kind (Declaration);
      Arg_R_Node : Node_Id;
   begin
      Check_Validity (Declaration, Package_Name & "Is_Subunit");

      if not (Arg_Kind in Internal_Declaration_Kinds) then
         return False;
      else
         Arg_R_Node := R_Node (Declaration);
         return Nkind (Parent (Arg_R_Node)) = N_Subunit;
      end if;

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Declaration,
               Outer_Call => Package_Name & "Is_Subunit");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Is_Subunit",
            Ex          => Ex,
            Arg_Element => Declaration);
   end Is_Subunit;
------------------------------------------------------------------------------
   function Corresponding_Body_Stub
     (Subunit : Asis.Declaration)
      return    Asis.Declaration
   is
      Arg_Node    : Node_Id;
      Result_Node : Node_Id;
      Result_Unit : Asis.Compilation_Unit;
   begin
      Check_Validity (Subunit, Package_Name & "Corresponding_Body_Stub");

      if not Is_Subunit (Subunit) then
         Raise_ASIS_Inappropriate_Element
           (Package_Name & "Corresponding_Body_Stub",
            Wrong_Kind => Int_Kind (Subunit));
      end if;

      Arg_Node := Node (Subunit);
      Result_Node := Corresponding_Stub (Parent (Arg_Node));
      Result_Unit := Enclosing_Unit
        (Encl_Cont_Id (Subunit), Result_Node);

      return Node_To_Element_New (Node    => Result_Node,
                                  In_Unit => Result_Unit);

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Subunit,
               Outer_Call => Package_Name & "Corresponding_Body_Stub");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Corresponding_Body_Stub",
            Ex          => Ex,
            Arg_Element => Subunit);
   end Corresponding_Body_Stub;
-----------------------------------------------------------------------------
   --  NOT IMPLEMENTED

   function Corresponding_Body_Stub
     (Subunit     : Asis.Declaration;
      The_Context : Asis.Context)
      return        Asis.Declaration
   is
   begin
      Check_Validity (Subunit, Package_Name & "Corresponding_Body_Stub");
      Check_Validity (
        The_Context, Package_Name & "Corresponding_Body_Stub");

      Not_Implemented_Yet (Diagnosis =>
        Package_Name & "Corresponding_Body_Stub");
      --  ASIS_Failed is raised, Not_Implemented_Error status is set

      return Nil_Element; -- to make the code syntactically correct

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Subunit,
               Outer_Call => Package_Name & "Corresponding_Body_Stub");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Corresponding_Body_Stub",
            Ex          => Ex,
            Arg_Element => Subunit);
   end Corresponding_Body_Stub;
------------------------------------------------------------------------------
   function Generic_Formal_Part
     (Declaration     : Asis.Declaration;
      Include_Pragmas : Boolean := False)
      return            Asis.Generic_Formal_Parameter_List
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Declaration);
      Arg_Node : Node_Id;
      Result_Node_List : List_Id;
   begin
      Check_Validity (Declaration, Package_Name & "Generic_Formal_Part");

      if not (Arg_Kind = A_Generic_Package_Declaration   or else
        Arg_Kind = A_Generic_Procedure_Declaration or else
        Arg_Kind = A_Generic_Function_Declaration)
      then
         Raise_ASIS_Inappropriate_Element
           (Package_Name & "Generic_Formal_Part",
            Wrong_Kind => Arg_Kind);
      end if;

      Arg_Node         := Node (Declaration);
      Result_Node_List := Generic_Formal_Declarations (Arg_Node);

      return N_To_E_List_New
        (List             => Result_Node_List,
        Include_Pragmas  => Include_Pragmas,
        Starting_Element => Declaration);
   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Declaration,
               Outer_Call => Package_Name & "Generic_Formal_Part",
               Bool_Par   => Include_Pragmas);
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Generic_Formal_Part",
            Ex          => Ex,
            Arg_Element => Declaration,
            Bool_Par_ON => Include_Pragmas);
   end Generic_Formal_Part;
-----------------------------------------------------------------------------

   function Generic_Unit_Name
     (Declaration : Asis.Declaration)
      return        Asis.Expression
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Declaration);
      Arg_Node : Node_Id;
   begin
      Check_Validity (Declaration, Package_Name & "Generic_Unit_Name");
      if not (Arg_Kind = A_Function_Instantiation    or else
        Arg_Kind = A_Package_Instantiation      or else
        Arg_Kind = A_Procedure_Instantiation    or else
        Arg_Kind = A_Formal_Package_Declaration or else
        Arg_Kind = A_Formal_Package_Declaration_With_Box)
      then
         Raise_ASIS_Inappropriate_Element
           (Package_Name & "Generic_Unit_Name",
            Wrong_Kind => Arg_Kind);
      end if;

      Arg_Node := Node (Declaration);

      return Node_To_Element_New
        (Node             => Sinfo.Name (Arg_Node),
        Starting_Element => Declaration);
   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Declaration,
               Outer_Call => Package_Name & "Generic_Unit_Name");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Generic_Unit_Name",
            Ex          => Ex,
            Arg_Element => Declaration);
   end Generic_Unit_Name;
------------------------------------------------------------------------------
   function Generic_Actual_Part
     (Declaration : Asis.Declaration;
      Normalized  : Boolean := False)
      return        Asis.Association_List
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Declaration);

      Arg_Node           : Node_Id;
      Template_Node      : Node_Id;
   begin

      Check_Validity (Declaration, Package_Name & "Generic_Actual_Part");

      if not (Arg_Kind = A_Function_Instantiation  or else
        Arg_Kind = A_Package_Instantiation   or else
        Arg_Kind = A_Procedure_Instantiation or else
        Arg_Kind = A_Formal_Package_Declaration)
      then
         Raise_ASIS_Inappropriate_Element
           (Package_Name & "Generic_Actual_Part",
            Wrong_Kind => Arg_Kind);
      end if;

      Arg_Node := Node (Declaration);

      if Normalized then
         --  the only things we do here are calculating the node of the
         --  template and the number of the normalized associations in the
         --  result list. Then we call Normalized_Generic_Associations,
         --  which does the actual job.
         Template_Node := Entity (Sinfo.Name (Arg_Node));

         if Nkind (Parent (Template_Node)) = N_Defining_Program_Unit_Name then
            Template_Node := Parent (Template_Node);
         end if;

         Template_Node := Parent (Template_Node);

         while Nkind (Template_Node) in N_Generic_Renaming_Declaration loop
            Template_Node := Entity (Sinfo.Name (Template_Node));

            if Nkind (Parent (Template_Node)) =
               N_Defining_Program_Unit_Name
            then
               Template_Node := Parent (Template_Node);
            end if;

            Template_Node := Parent (Template_Node);
         end loop;

         Template_Node := Parent (Template_Node);

         if Is_Non_Empty_List (
              Generic_Formal_Declarations (Template_Node))
         then

            return Normalized_Generic_Associations
              (Inst_Elem          => Declaration,
               Templ_Node         => Template_Node);
         else
            return Nil_Element_List;
         end if;

      else

         declare
            Result : Asis.Association_List :=
               N_To_E_List_New
                  (List             => Generic_Associations (Arg_Node),
                   Internal_Kind    => A_Generic_Association,
                   Starting_Element => Declaration);

            Tmp_El         : Asis.Element;
            More_Inversion : Boolean := True;
         begin

            --  We have to reorder Result to follow the situation in, because
            while More_Inversion loop

               More_Inversion := False;

               for J in 1 .. Result'Last - 1 loop

                  if Sloc (Node (Result (J))) >
                     Sloc (Node (Result (J + 1)))
                  then
                     Tmp_El         := Result (J + 1);
                     Result (J + 1) := Result (J);
                     Result (J)     := Tmp_El;
                     More_Inversion := True;
                  end if;

               end loop;

            end loop;

            return Result;
         end;

      end if;

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Declaration,
               Outer_Call => Package_Name & "Generic_Actual_Part",
               Bool_Par   => Normalized);
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Generic_Actual_Part",
            Ex          => Ex,
            Arg_Element => Declaration,
            Bool_Par_ON => Normalized);
   end Generic_Actual_Part;
------------------------------------------------------------------------------

   function Formal_Subprogram_Default
     (Declaration : Asis.Generic_Formal_Parameter)
      return        Asis.Expression
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Declaration);
      Arg_Node : Node_Id;
      Res_Node : Node_Id;
      Result   : Asis.Element;
   begin
      Arg_Node := Node (Declaration);
      Check_Validity (Declaration,
        Package_Name & "Formal_Subprogram_Default");
      if not ((Arg_Kind = A_Formal_Procedure_Declaration
               or else
                 Arg_Kind = A_Formal_Function_Declaration)
              and then
                Present (Default_Name (Arg_Node)))
      then
         Raise_ASIS_Inappropriate_Element
           (Package_Name & "Formal_Subprogram_Default",
            Wrong_Kind => Arg_Kind);
      end if;

      Res_Node := Default_Name (Arg_Node);

      Result := Node_To_Element_New
                  (Node             => Res_Node,
                   Starting_Element => Declaration);

      if Int_Kind (Result) = A_Function_Call
        or else
         Int_Kind (Result) = A_Procedure_Call_Statement
      then
         Set_Int_Kind (Result, Subprogram_Attribute_Kind (Res_Node));
      end if;

      return Result;

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Argument   => Declaration,
               Outer_Call => Package_Name & "Formal_Subprogram_Default");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Formal_Subprogram_Default",
            Ex          => Ex,
            Arg_Element => Declaration);
   end Formal_Subprogram_Default;

   -----------------------------------
   -- Corresponding_Generic_Element --
   -----------------------------------

   function Corresponding_Generic_Element
     (Reference : Asis.Element)
      return      Asis.Defining_Name
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Reference);

      Arg_Def_Name     : Asis.Element;
      Gen_Unit_Elem    : Asis.Element;
      Decl_In_Instanse : Asis.Element;
      Is_Instance_Name : Boolean := False;
      Is_From_Body     : Boolean := False;
      Tmp_Elem         : Element;

      Result_Element   : Asis.Element;
   begin
      Check_Validity (Reference,
        Package_Name & "Corresponding_Generic_Element");

      if not (Arg_Kind in Internal_Defining_Name_Kinds   or else
              Arg_Kind = An_Identifier                   or else
              Arg_Kind in Internal_Operator_Symbol_Kinds or else
              Arg_Kind = A_Character_Literal             or else
              Arg_Kind = An_Enumeration_Literal)
      then
         Raise_ASIS_Inappropriate_Element
           (Package_Name & "Corresponding_Generic_Element",
            Wrong_Kind => Arg_Kind);
      end if;

      --  first, we heed the defining name in case if an argument is of
      --  An_Expression kind

      if Arg_Kind in Internal_Defining_Name_Kinds then
         Arg_Def_Name := Reference;
      else
         begin
            Arg_Def_Name :=
              Asis.Expressions.Corresponding_Name_Definition (Reference);
         exception
            when ASIS_Inappropriate_Element =>
               --  As an argument we have an entity that either is not a
               --  reference having a declaration or it is an ambiguous
               --  reference to more than one entity, so
               return Nil_Element;
         end;
      end if;

      --  then, checking if there is a corresponding generic element
      if Is_Nil (Arg_Def_Name) or else
        not (Is_From_Instance (Arg_Def_Name))
      then
         return Nil_Element;
      end if;

      --  !!! NOTE: references to formal parameters cannot be processed
      --            for now ??? But why?

      --  Now - computing Gen_Unit_Elem as the declaration of generic
      --  unit in which the corresponding generic element in question is
      --  supposed to be
      Decl_In_Instanse := Enclosing_Element (Arg_Def_Name);
      Gen_Unit_Elem    := Decl_In_Instanse;

      --  A defining name of (nested) instance is a special case -
      --  we have to skip such an instance

      if Int_Kind (Gen_Unit_Elem) in An_Internal_Generic_Instantiation
       and then
         Is_Equal (Arg_Def_Name, Names (Gen_Unit_Elem) (1))
      then
         Gen_Unit_Elem := Enclosing_Element (Gen_Unit_Elem);
      end if;

      while Int_Kind (Gen_Unit_Elem) not in
            An_Internal_Generic_Instantiation
         and then
            (Int_Kind (Gen_Unit_Elem) not in
             A_Formal_Package_Declaration ..
             A_Formal_Package_Declaration_With_Box
            or else
             Is_Equal (Reference, Names (Gen_Unit_Elem) (1)))
      loop
         Tmp_Elem      := Gen_Unit_Elem;
         Gen_Unit_Elem := Enclosing_Element (Gen_Unit_Elem);
      end loop;

      if (Int_Kind (Tmp_Elem) = A_Procedure_Body_Declaration or else
          Int_Kind (Tmp_Elem) = A_Function_Body_Declaration  or else
          Int_Kind (Tmp_Elem) = A_Package_Body_Declaration)
         and then
         --  We should not treat artificial declarations created to pass
         --  actuals as being from body!
          not (Pass_Generic_Actual (Node (Decl_In_Instanse)))
      then
         Is_From_Body := True;
      end if;

      Gen_Unit_Elem := Generic_Unit_Name (Gen_Unit_Elem);

      if Int_Kind (Gen_Unit_Elem) = A_Selected_Component then
         Gen_Unit_Elem := Asis.Expressions.Selector (Gen_Unit_Elem);
      end if;

      Gen_Unit_Elem :=
         Asis.Expressions.Corresponding_Name_Declaration (Gen_Unit_Elem);

      if Int_Kind (Gen_Unit_Elem) in An_Internal_Renaming_Declaration then
         Gen_Unit_Elem := Corresponding_Base_Entity (Gen_Unit_Elem);

         if Int_Kind (Gen_Unit_Elem) = A_Selected_Component then
            Gen_Unit_Elem := Asis.Expressions.Selector (Gen_Unit_Elem);
         end if;

         Gen_Unit_Elem :=
            Asis.Expressions.Corresponding_Name_Declaration (Gen_Unit_Elem);

      end if;

      Tmp_Elem := Enclosing_Element (Arg_Def_Name);

      if Int_Kind (Tmp_Elem) = A_Defining_Expanded_Name then
         Tmp_Elem := Enclosing_Element (Tmp_Elem);
      end if;

      Tmp_Elem := Enclosing_Element (Tmp_Elem);

      if Int_Kind (Tmp_Elem) in An_Internal_Generic_Instantiation
       or else
         Int_Kind (Tmp_Elem) in A_Formal_Package_Declaration ..
         A_Formal_Package_Declaration_With_Box
      then
         Is_Instance_Name := True;
      end if;

      if Is_Instance_Name then
         Result_Element := Names (Gen_Unit_Elem) (1);
      else

         if Is_From_Body then
            Gen_Unit_Elem := Corresponding_Body (Gen_Unit_Elem);
         end if;

         Result_Element := Get_Corresponding_Generic_Element (
                              Gen_Unit => Gen_Unit_Elem,
                              Def_Name => Arg_Def_Name);
      end if;

      return Result_Element;

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (
               Outer_Call => Package_Name & "Corresponding_Generic_Element",
               Argument   => Reference);
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Corresponding_Generic_Element",
            Ex          => Ex,
            Arg_Element => Reference);
   end Corresponding_Generic_Element;

   ------------------------------
   -- Is_Dispatching_Operation --
   ------------------------------

   function Is_Dispatching_Operation
     (Declaration : Asis.Element)
      return        Boolean
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Declaration);
      Arg_Node : Node_Id;
   begin

      Check_Validity (Declaration, Package_Name & "Is_Dispatching_Operation");

      if not (Arg_Kind = A_Procedure_Declaration            or else
              Arg_Kind = A_Null_Procedure_Declaration       or else
              Arg_Kind = A_Function_Declaration             or else
              Arg_Kind = An_Expression_Function_Declaration or else
              Arg_Kind = A_Procedure_Body_Declaration       or else
              Arg_Kind = A_Function_Body_Declaration        or else
              Arg_Kind = A_Procedure_Renaming_Declaration   or else
              Arg_Kind = A_Function_Renaming_Declaration    or else
              Arg_Kind = A_Procedure_Body_Stub              or else
              Arg_Kind = A_Function_Body_Stub)
      then
         return False;
      end if;

      Arg_Node := Defining_Unit_Name (Specification (Node (Declaration)));

      if Nkind (Arg_Node) = N_Defining_Program_Unit_Name then
         return False;
      else
         return Is_Dispatching_Operation (Arg_Node);
      end if;
   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information
              (Outer_Call => Package_Name & "Is_Dispatching_Operation",
               Argument   => Declaration);
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "",
            Ex          => Ex,
            Arg_Element => Declaration);
   end Is_Dispatching_Operation;

end Asis.Declarations;