This file is indexed.

/usr/share/ada/adainclude/asis/asis-elements.adb is in libasis2010-dev 2010-3.

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
------------------------------------------------------------------------------
--                                                                          --
--                 ASIS-for-GNAT IMPLEMENTATION COMPONENTS                  --
--                                                                          --
--                        A S I S . E L E M E N T S                         --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
--            Copyright (C) 1995-2010, 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 2,  or  (at your option)  any later --
-- version. ASIS-for-GNAT is distributed  in the hope  that it will be use- --
-- ful, but WITHOUT ANY WARRANTY; without even the implied warranty of MER- --
-- CHANTABILITY or  FITNESS FOR A  PARTICULAR PURPOSE.  See the GNU General --
-- Public License for more details.  You should have received a copy of the --
-- GNU  General  Public  License  distributed with  ASIS-for-GNAT; see file --
-- COPYING.  If not,  write  to the  Free Software Foundation,  51 Franklin --
-- Street, Fifth Floor, Boston, MA 02110-1301, USA.                         --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
-- 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).                                                --
--                                                                          --
------------------------------------------------------------------------------

with Ada.Characters.Handling; use Ada.Characters.Handling;
with Ada.Unchecked_Conversion;
with Interfaces;              use Interfaces;
with GNAT.HTable;

with Asis.Clauses;
with Asis.Compilation_Units;
with Asis.Declarations;       use Asis.Declarations;
with Asis.Definitions;
with Asis.Errors;             use Asis.Errors;
with Asis.Exceptions;         use Asis.Exceptions;
with Asis.Extensions;
with Asis.Statements;

with Asis.Set_Get;            use  Asis.Set_Get;

with A4G.A_Opt;
with A4G.A_Output;            use A4G.A_Output;
with A4G.A_Sem;               use A4G.A_Sem;
with A4G.A_Sinput;            use A4G.A_Sinput;
with A4G.A_Types;
with A4G.Asis_Tables;         use A4G.Asis_Tables;
with A4G.Contt;               use A4G.Contt;
with A4G.Contt.UT;            use A4G.Contt.UT;
with A4G.Encl_El;             use A4G.Encl_El;
with A4G.Knd_Conv;            use A4G.Knd_Conv;
with A4G.Mapping;             use A4G.Mapping;
with A4G.Vcheck;              use A4G.Vcheck;

with Atree;                   use Atree;
with Einfo;                   use Einfo;
with Nlists;                  use Nlists;
with Sinfo;                   use Sinfo;
with Sinput;                  use Sinput;
with Snames;                  use Snames;
with Stand;                   use Stand;

package body Asis.Elements is
   --  !!!??? This file is '-gnatg-compilable', but both its content and its
   --  !!!???  documentation need revising

   function "=" (Left, Right : Element) return Boolean
      renames Asis.Set_Get."=";

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

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

   ---------------------------
   -- ASIS 2005 Draft stuff --
   ---------------------------

   ----------------------------
   -- Access_Definition_Kind --
   ----------------------------

   function Access_Definition_Kind
     (Definition : Asis.Definition)
      return       Asis.Access_Definition_Kinds
   is
   begin
      Check_Validity (Definition, Package_Name & "Access_Definition_Kind");

      if not A4G.A_Opt.ASIS_2005_Mode then

         Set_Error_Status
            (Status    => Asis.Errors.Use_Error,
             Diagnosis => "ASIS 2005 queries require initialization with " &
                            "-asis05");

         raise ASIS_Failed;
      end if;

      return Access_Definition_Kind_From_Internal (Int_Kind (Definition));
   end Access_Definition_Kind;

   --------------------
   -- Interface_Kind --
   --------------------

   function Interface_Kind
     (Definition : Asis.Definition)
      return       Asis.Interface_Kinds
   is
   begin
      Check_Validity (Definition, Package_Name & "Interface_Kind");

      if not A4G.A_Opt.ASIS_2005_Mode then

         Set_Error_Status
            (Status    => Asis.Errors.Use_Error,
             Diagnosis => "ASIS 2005 queries require initialization with " &
                            "-asis05");

         raise ASIS_Failed;
      end if;

      return Interface_Kind_From_Internal (Int_Kind (Definition));
   end Interface_Kind;

   ------------------------
   -- Is_Not_Null_Return --
   ------------------------

   function Is_Not_Null_Return
     (Element : Asis.Element)
      return    Boolean
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Element);
      Arg_Node : Node_Id                         := Node (Element);
      Result   :          Boolean                := False;
   begin
      Check_Validity (Element, Package_Name & "Is_Not_Null_Return");

      if not A4G.A_Opt.ASIS_2005_Mode then

         Set_Error_Status
            (Status    => Asis.Errors.Use_Error,
             Diagnosis => "ASIS 2005 queries require initialization with " &
                            "-asis05");

         raise ASIS_Failed;
      end if;

      case Arg_Kind is
         when A_Function_Declaration          |
              A_Function_Body_Declaration     |
              A_Function_Renaming_Declaration |
              A_Function_Body_Stub            |
              A_Generic_Function_Declaration  |
              A_Formal_Function_Declaration   =>

            Arg_Node := Specification (Arg_Node);
            Result   := Null_Exclusion_Present (Arg_Node);

         when An_Access_To_Function                     |
              An_Access_To_Protected_Function           |
              An_Anonymous_Access_To_Function           |
              An_Anonymous_Access_To_Protected_Function =>

            Result   := Null_Exclusion_Present (Arg_Node);

         when others =>
            null;
      end case;

      return Result;
   end Is_Not_Null_Return;

   ------------------------
   -- Is_Prefix_Notation --
   ------------------------

   function Is_Prefix_Notation (Call : Asis.Element) return Boolean is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Call);
      Arg_Node : constant Node_Id                := R_Node (Call);
      Result   :          Boolean                := False;
   begin
      Check_Validity (Call, Package_Name & "Is_Prefix_Notation");

      if not A4G.A_Opt.ASIS_2005_Mode then

         Set_Error_Status
            (Status    => Asis.Errors.Use_Error,
             Diagnosis => "ASIS 2005 queries require initialization with " &
                            "-asis05");

         raise ASIS_Failed;
      end if;

      if Arg_Kind = A_Procedure_Call_Statement then

         if Is_Rewrite_Substitution (Arg_Node)
           and then
            Nkind (Original_Node (Arg_Node)) = Nkind (Arg_Node)
           and then
            Nkind (Sinfo.Name (Arg_Node)) = N_Identifier
           and then
             Nkind (Sinfo.Name (Original_Node (Arg_Node))) =
               N_Selected_Component
         then
            Result := True;
         end if;

      elsif Arg_Kind = A_Function_Call
           and then
            Is_Rewrite_Substitution (Arg_Node)
      then
         --  If prefix notation is used for a function call, the corresponding
         --  A_Function_Call element is based on the rewritten node and the
         --  original node is not used at all
         if Node (Call) = Arg_Node then
            Result := Is_Rewritten_Function_Prefix_Notation (Arg_Node);
         elsif Nkind (Arg_Node) = N_Explicit_Dereference then
            --  This is a case of *implicit* dereference :(
            Result :=
              Is_Rewritten_Impl_Deref_Function_Prefix_Notation (Node (Call));
         end if;

      end if;

      return Result;
   end Is_Prefix_Notation;

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

   function Unit_Declaration
     (Compilation_Unit : Asis.Compilation_Unit)
      return             Asis.Declaration
   is
      Unit_Kind             : Asis.Unit_Kinds;
      Unit_Declaration_Node : Node_Id;
      Special_Case          : Special_Cases := Not_A_Special_Case;
   begin
      Check_Validity (Compilation_Unit, Package_Name & "Unit_Declaration");

      Reset_Context (Encl_Cont_Id (Compilation_Unit));
      Unit_Kind := Kind (Compilation_Unit);

      if Unit_Kind = Not_A_Unit then
         Raise_ASIS_Inappropriate_Compilation_Unit
           (Package_Name & "Unit_Declaration");
      end if;

      if Unit_Kind = A_Nonexistent_Declaration or else
         Unit_Kind = A_Nonexistent_Body        or else
         Unit_Kind = An_Unknown_Unit           or else
         Unit_Kind = A_Configuration_Compilation
      then
         return Nil_Element;
      end if;

      if Is_Standard (Compilation_Unit) then
         Special_Case          := Explicit_From_Standard;
         Unit_Declaration_Node := Standard_Package_Node;
      else
         Unit_Declaration_Node := Unit (Top (Compilation_Unit));
      end if;

      if  Unit_Kind = A_Procedure_Body_Subunit or else
          Unit_Kind = A_Function_Body_Subunit  or else
          Unit_Kind = A_Package_Body_Subunit   or else
          Unit_Kind = A_Task_Body_Subunit      or else
          Unit_Kind = A_Protected_Body_Subunit
      then
         --  one step down the tree is required.
         --  No Asis Element can correspond to
         --  the N_Subunit Node
         Unit_Declaration_Node := Proper_Body (Unit_Declaration_Node);
      end if;

      return Node_To_Element_New (Node      => Unit_Declaration_Node,
                                  Spec_Case => Special_Case,
                                  In_Unit   => Compilation_Unit);
   exception
      when ASIS_Inappropriate_Compilation_Unit =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information
              (Outer_Call => Package_Name & "Unit_Declaration");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name => Package_Name & "Unit_Declaration",
            Ex         => Ex,
            Arg_CU     => Compilation_Unit);
   end Unit_Declaration;
-----------------------------------------------------------------------------

   function Enclosing_Compilation_Unit
     (Element : Asis.Element)
      return    Asis.Compilation_Unit
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Element);
   begin

      Check_Validity (Element, Package_Name & "Enclosing_Compilation_Unit");

      if Arg_Kind = Not_An_Element then
         Raise_ASIS_Inappropriate_Element
           (Package_Name & "Enclosing_Compilation_Unit",
            Wrong_Kind => Arg_Kind);
      end if;

      return Encl_Unit (Element);

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

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

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

   function Context_Clause_Elements
     (Compilation_Unit : Asis.Compilation_Unit;
      Include_Pragmas  : Boolean := False)
      return             Asis.Context_Clause_List
   is
      Unit_Kind   : Asis.Unit_Kinds; -- Compilation_Unit kind
      List_Before : List_Id;
   begin
      Check_Validity
        (Compilation_Unit, Package_Name & "Context_Clause_Elements");

      Unit_Kind := Kind (Compilation_Unit);

      if Unit_Kind = Not_A_Unit then
         Raise_ASIS_Inappropriate_Compilation_Unit
           (Package_Name & "Context_Clause_Elements");
      end if;

      if Is_Standard (Compilation_Unit)        or else
         Unit_Kind = A_Nonexistent_Declaration or else
         Unit_Kind = A_Nonexistent_Body        or else
         Unit_Kind = An_Unknown_Unit           or else
         Unit_Kind = A_Configuration_Compilation
      then
         --  The last part of the condition comes from the GNAT compilation
         --  model. But it seems that it should be in the definition of
         --  this query in the ASIS Standard
         return Nil_Element_List;
      end if;

      List_Before := Context_Items (Top (Compilation_Unit));

      return N_To_E_List_New
        (List             => List_Before,
         Include_Pragmas  => Include_Pragmas,
         In_Unit          => Compilation_Unit);
   exception
      when ASIS_Inappropriate_Compilation_Unit =>
         raise;
      when ASIS_Failed =>

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

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Context_Clause_Elements",
            Ex          => Ex,
            Arg_CU      => Compilation_Unit,
            Bool_Par_ON => Include_Pragmas);
   end Context_Clause_Elements;
------------------------------------------------------------------------------

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

      --  In the GNAT environment, "a list of pragmas that apply to all future
      --  compilation_unit elements compiled into The_Context" is defined by
      --  the -gnatA and -gnatec options used when calling the compiler and
      --  by the content of configuration file(s) at the moment of the compiler
      --  call. These things cannot be detected from the set of tree files
      --  making up the Context, so the only thing we can do is to return
      --  Nil_Element_List

      return Nil_Element_List;

   exception

      when ASIS_Inappropriate_Context =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information
              (Outer_Call => Package_Name & "Configuration_Pragmas");
         end if;

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

   function Compilation_Pragmas
     (Compilation_Unit : Asis.Compilation_Unit)
      return             Asis.Pragma_Element_List
   is
      Unit_Kind      : Asis.Unit_Kinds;

      Config_Prgms : List_Id := No_List;
      List_Before  : List_Id;
      Next_Pragma  : Node_Id;
      List_After   : List_Id;
   begin

      Check_Validity (Compilation_Unit,
                      Package_Name & "Compilation_Pragmas");

      Unit_Kind := Kind (Compilation_Unit);

      if Unit_Kind = Not_A_Unit then
         Raise_ASIS_Inappropriate_Compilation_Unit
           (Package_Name & "Compilation_Pragmas");
      end if;

      if Is_Standard (Compilation_Unit)        or else
         Unit_Kind = A_Nonexistent_Declaration or else
         Unit_Kind = A_Nonexistent_Body        or else
         Unit_Kind = An_Unknown_Unit           or else
         Unit_Kind = A_Configuration_Compilation
      then
         --  The last part of the condition is GNAT-specific
         return Nil_Element_List;
      end if;

      Reset_Context (Encl_Cont_Id (Compilation_Unit));

      --  For the GNAT compilation model, we consider that configuration
      --  pragmas from the configuration file(s) are applied to the main unit
      --  of the compilation only. So if some unit belonging to the Context
      --  is compiled only as a supporter of some other units, but not on
      --  their own, the result of Compilation_Pragmas applied to this unit
      --  does not include any configuration pragmas from the configuration
      --  file(s).

      if Asis.Extensions.Is_Main_Unit_In_Tree (Compilation_Unit) then
         Reset_Main_Tree (Compilation_Unit);

         Config_Prgms :=
           Config_Pragmas (Aux_Decls_Node (Top (Compilation_Unit)));
      end if;

      List_Before := Context_Items (Top (Compilation_Unit));

      List_After  := Pragmas_After (Aux_Decls_Node (Top (Compilation_Unit)));

      Set_Element_List
        (List             => Config_Prgms,
         Include_Pragmas  => True,
         Node_Knd         => N_Pragma,
         Special_Case     => Configuration_File_Pragma,
         In_Unit          => Compilation_Unit,
         Append           => False);

      --  The middle part - pragmas from the context clause - we have to
      --  compose by hands, because we can add to the result only the
      --  configuration pragmas

      if Present (List_Before) then

         Next_Pragma := First (List_Before);

         Next_Pragma := Get_Next_Configuration_Pragma (Next_Pragma);

         while Present (Next_Pragma) loop

            Internal_Asis_Element_Table.Append
              (Node_To_Element_New
                 (Node    => Next_Pragma,
                  In_Unit => Compilation_Unit));

            Next_Pragma := Get_Next_Configuration_Pragma (Next (Next_Pragma));

         end loop;

      end if;

      Set_Element_List
        (List             => List_After,
         Include_Pragmas  => True,
         Node_Knd         => N_Pragma,
         In_Unit          => Compilation_Unit,
         Append           => True);

      return Asis.Pragma_Element_List
               (Internal_Asis_Element_Table.Table
                  (1 .. Internal_Asis_Element_Table.Last));

   exception
      when ASIS_Inappropriate_Compilation_Unit =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information
              (Outer_Call => Package_Name & "Compilation_Pragmas");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name => Package_Name & "Compilation_Pragmas",
            Ex         => Ex,
            Arg_CU     => Compilation_Unit);
   end Compilation_Pragmas;
------------------------------------------------------------------------------

   function Element_Kind
     (Element : Asis.Element)
      return    Asis.Element_Kinds
   is
   begin
      Check_Validity (Element, Package_Name & "Element_Kind");

      return Kind (Element);
   end Element_Kind;
-----------------------------------------------------------------------------

   function Pragma_Kind
     (Pragma_Element : Asis.Pragma_Element)
      return           Asis.Pragma_Kinds
   is
   begin
      Check_Validity (Pragma_Element, Package_Name & "Pragma_Kind");

      return Pragma_Kind_From_Internal (Int_Kind (Pragma_Element));
   end Pragma_Kind;
-----------------------------------------------------------------------------

   function Defining_Name_Kind
     (Defining_Name : Asis.Defining_Name)
      return          Asis.Defining_Name_Kinds
   is
   begin
      Check_Validity (Defining_Name, Package_Name & "Defining_Name_Kind");

      return Defining_Name_Kind_From_Internal (Int_Kind (Defining_Name));
   end Defining_Name_Kind;
-----------------------------------------------------------------------------

   function Declaration_Kind
     (Declaration : Asis.Declaration)
      return        Asis.Declaration_Kinds
   is
   begin
      Check_Validity (Declaration, Package_Name & "Declaration_Kind");

      return Declaration_Kind_From_Internal (Int_Kind (Declaration));
   end Declaration_Kind;

   ----------------
   -- Trait_Kind --
   ----------------

   function Trait_Kind (Element : Asis.Element) return Asis.Trait_Kinds is

   --  Trait-related flag values:

      Is_Abstract : Boolean;
      Is_Limited  : Boolean;
      Is_Aliased  : Boolean;
      Is_Private  : Boolean;

      Arg_Node            : Node_Id;
      Trait_Defining_Node : Node_Id;
      --  if the Node (Element) is not enough for defining the result,
      --  Trait_Defining_Node is used for the tree traversing

      Result : Asis.Trait_Kinds := An_Ordinary_Trait;

   begin

      Check_Validity (Element, Package_Name & "Trait_Kind");

--  ASIS_Element_Kinds.Trait_Kinds literals and GNAT tree flags mapping:
--
--  (This nice piece of documentation is for ASIS/Ada 95 only, we have not
--  extended it for Ada 2005)
--
--  type Trait_Kinds is (
--
--    Not_A_Trait,     --> Unexpected element, its node always has no
--                     --  corresponding flags and its kind does not belong
--                     --  to the Node Kinds for which A_Private_Trait could
--                     --  be determined
--
--    An_Ordinary_Trait, -->  all flags are set off, and the node kind
--                            does not belong to the Node Kinds for which
--                            A_Private_Trait could be determined
--
--    An_Aliased_Trait,  -->  Aliased_Present set ON
--
--    An_Access_Definition_Trait, --> no special flag, could be defined
--                                --  on the base of the presence of
--                                --  the N_Access_Definition node as the
--                                --  child node of the argument node
--
--    A_Reverse_Trait,  --> Reverse_Present set ON
--
--    A_Private_Trait,  --> except the case of
--                          A_Formal_Derived_Type_Definition,
--                      --  no special flag is presented in the corresponding
--                      --  node, the A_Private_Trait could be defined
--                      --  on the base of Node Kinds and setting other
--                      --  flags OFF;
--                      --  for A_Formal_Derived_Type_Definition -
--                      --  Private_Present set ON
--
--    A_Limited_Trait,  --> Limited_Present set ON and corresponding node
--                      --  does not belong to the Node Kinds for which
--                      --  A_Private_Trait could be defined
--
--    A_Limited_Private_Trait, --> Limited_Present set ON and corresponding
--                             -- node belongs to the Node Kinds for which
--                             -- A_Private_Trait could be defined
--
--    An_Abstract_Trait, --> For types: Abstract_Present set ON and
--                       --  corresponding node does not belong to the
--                       --  Node Kinds for which A_Private_Trait could be
--                       --  defined;
--                       --  For subprograms: no special flag, could be
--                       --  defined on the base of the Node Kind of the
--                       --  argument node
--
--    An_Abstract_Private_Trait, --> except the case of
--                               --  A_Formal_Derived_Type_Definition,
--                               --  Abstract_Present set ON and corresponding
--                               --  node belongs to the Node Kinds for which
--                               --  A_Private_Trait could be defined;
--                               --  for A_Formal_Derived_Type_Definition -
--                               --  Abstract_Present set ON and
--                               --  Private_Present set ON
--
--    An_Abstract_Limited_Trait, --> Abstract_Present set ON,
--                               --  Limited_Present set ON
--                               --  and corresponding node does not belong
--                               --  to the Node Kinds for which
--                               --  A_Private_Trait could be defined
--
--    An_Abstract_Limited_Private_Trait); --> Abstract_Present set ON,
--                                        --  Limited_Present set ON and
--                                        --  corresponding node belongs
--                                        --  to Node Kinds for which
--                                        --  A_Private_Trait could be defined
--
----------------------------------------------------------------------------
--  Expected Argument_Kinds:     ->       Corresponding tree Nodes:
--   Possible Trait values:     -->         Provided trait-related flags and
--                                          combination of their values
--                                          corresponding to the Trait value
----------------------------------------------------------------------------
--
--  Expected Declaration_Kinds:
--  ==========================
--
--     A_Private_Type_Declaration      -> N_Private_Type_Declaration (*1*)
--      A_Private_Trait                   --> Abstract_Present = OFF
--                                            Limited_Present  = OFF
--
--      A_Limited_Private_Trait           --> Abstract_Present = OFF
--                                            Limited_Present  = ON
--
--      An_Abstract_Private_Trait         --> Abstract_Present = ON
--                                            Limited_Present  = OFF
--
--      An_Abstract_Limited_Private_Trait --> Abstract_Present = ON
--                                            Limited_Present  = ON
-----------------------------------------------
--     A_Private_Extension_Declaration -> N_Private_Extension_Declaration (*2*)
--      A_Private_Trait                   --> Abstract_Present = OFF
--
--      An_Abstract_Private_Trait         --> Abstract_Present = ON
-----------------------------------------------
--     A_Variable_Declaration          -> N_Object_Declaration      (*3*)
--      An_Ordinary_Trait                 --> Aliased_Present = OFF
--
--      An_Aliased_Trait                  --> Aliased_Present = ON
-----------------------------------------------
--     A_Constant_Declaration          -> N_Object_Declaration      (*3*)
--      An_Ordinary_Trait                 --> Aliased_Present = OFF
--
--      An_Aliased_Trait                  --> Aliased_Present = ON
-----------------------------------------------
--     A_Deferred_Constant_Declaration -> N_Object_Declaration      (*3*)
--      An_Ordinary_Trait                 --> Aliased_Present = OFF
--
--      An_Aliased_Trait                  --> Aliased_Present = ON
-----------------------------------------------
--     A_Discriminant_Specification    -> N_Discriminant_Specification  (*4*)
--                                            Has no trait-related flags
--
--      An_Ordinary_Trait --> Nkind(Discriminant_Type(Definition.Node))
--                                   /=  N_Access_Definition
--      An_Access_Definition_Trait--> Nkind(Discriminant_Type(Definition.Node))
--                                   =   N_Access_Definition
-----------------------------------------------
--     A_Loop_Parameter_Specification  -> N_Loop_Parameter_Specification (*5*)
--      An_Ordinary_Trait                 --> Reverse_Present = OFF
--
--      A_Reverse_Trait                   --> Reverse_Present = ON
-----------------------------------------------
--     A_Procedure_Declaration         -> N_Subprogram_Declaration (*6*)
--      An_Ordinary_Trait  --> No flag needed to determine the trait
--                                     -> N_Abstract_Subprogram_Declaration
--      An_Abstract_Trait  --> No flag needed to determine the trait
-----------------------------------------------
--     A_Function_Declaration          -> N_Subprogram_Declaration  (*6*)
--      An_Ordinary_Trait  --> No flag needed to determine the trait
--                                     -> N_Abstract_Subprogram_Declaration
--      An_Abstract_Trait  --> No flag needed to determine the trait
-----------------------------------------------
--     A_Parameter_Specification       -> N_Parameter_Specification  (*4*)
--                                            Has no trait-related flags
--
--      An_Ordinary_Trait --> Nkind(Parameter_Type(Definition.Node))
--                                   /=  N_Access_Definition
--      An_Access_Definition_Trait --> Nkind(Parameter_Type(Definition.Node))
--                                   =   N_Access_Definition
-----------------------------------------------
--
--  Expected Definition_Kinds:
--  =========================
--
--     A_Component_Definition          -> N_Subtype_Indication    (*10*)
--                                        N_Identifier
--                                        N_Expanded_Name
--      An_Ordinary_Trait --> Aliased_Present set OFF in the PARENT node
--      An_Aliased_Trait  --> Aliased_Present set  ON in the PARENT nod
--
--     A_Private_Type_Definition       -> N_Private_Type_Declaration  (*1*)
--      The situation is just the same as for A_Private_Type_Declaration
-----------------------------------------------
--     A_Tagged_Private_Type_Definition-> N_Private_Type_Declaration  (*1*)
--      The situation is just the same as for A_Private_Type_Declaration
-----------------------------------------------
--     A_Private_Extension_Definition  -> N_Private_Extension_Declaration (*2*)
--      The situation is just the same as for N_Private_Extension_Declaration
-----------------------------------------------
--
--  Expected Type_Kinds:
--  ===================
--
-----------------------------------------------
--     A_Derived_Type_Definition             -> N_Derived_Type_Definition (*7*)
--      An_Ordinary_Trait                       --> Abstract_Present = OFF
--
--      An_Abstract_Trait                       --> Abstract_Present = ON
-----------------------------------------------
--     A_Derived_Record_Extension_Definition -> N_Derived_Type_Definition (*7*)
--      An_Ordinary_Trait                       --> Abstract_Present = OFF
--
--      An_Abstract_Trait                       --> Abstract_Present = ON
-----------------------------------------------
--     A_Record_Type_Definition              -> N_Record_Definition      (*8*)
--      An_Ordinary_Trait                       --> Abstract_Present = OFF
--                                                  Limited_Present  = OFF
--
--      An_Abstract_Trait                       --> Abstract_Present = ON
--                                                  Limited_Present  = OFF
--
--      A_Limited_Trait                         --> Abstract_Present = OFF
--                                                  Limited_Present  = ON
--
--      An_Abstract_Limited_Trait               --> Abstract_Present = ON
--                                                  Limited_Present  = ON
-----------------------------------------------
--     A_Tagged_Record_Type_Definition       -> N_Record_Definition      (*8*)
--      An_Ordinary_Trait                       --> Abstract_Present = OFF
--                                                  Limited_Present  = OFF
--
--      An_Abstract_Trait                       --> Abstract_Present = ON
--                                                  Limited_Present  = OFF
--
--      A_Limited_Trait                         --> Abstract_Present = OFF
--                                                  Limited_Present  = ON
--
--      An_Abstract_Limited_Trait               --> Abstract_Present = ON
--                                                  Limited_Present  = ON
-----------------------------------------------
--
--  Expected Formal_Type_Kinds:
--  ==========================
--
--     A_Formal_Private_Type_Definition -> N_Formal_Private_Type_Definition
--        (*1*)
--      The situation is just the same as for A_Private_Type_Declaration
-----------------------------------------------
--     A_Formal_Tagged_Private_Type_Definition ->
--        N_Formal_Private_Type_Definition (*1*)

--
--      The situation is just the same as for A_Private_Type_Declaration
-----------------------------------------------
--    A_Formal_Derived_Type_Definition -> N_Formal_Derived_Type_Definition(*9*)
--     An_Ordinary_Trait                       --> Abstract_Present = OFF
--                                                 Private_Present  = OFF
--
--     An_Abstract_Trait                       --> Abstract_Present = ON
--                                                 Private_Present  = OFF
--
--     A_Private_Trait                         --> Abstract_Present = OFF
--                                                 Private_Present  = ON
--
--     An_Abstract_Private_Trait               --> Abstract_Present = ON
--                                                 Private_Present  = ON
------------------------------------------------------------------------------

      Arg_Node := Node (Element);

      case Int_Kind (Element) is

      --  expected argument:

      when -- (*1*)
            A_Private_Type_Declaration
          | A_Private_Type_Definition
          | A_Tagged_Private_Type_Definition
          | A_Formal_Private_Type_Definition
          | A_Formal_Tagged_Private_Type_Definition =>

            Is_Abstract := Abstract_Present (Arg_Node);
            Is_Limited  := Limited_Present  (Arg_Node);

            if Is_Abstract and Is_Limited then
               Result := An_Abstract_Limited_Private_Trait;
            elsif Is_Abstract then
               Result := An_Abstract_Private_Trait;
            elsif Is_Limited then
               Result := A_Limited_Private_Trait;
            else
               Result := A_Private_Trait;
            end if;

      when -- (*2*)
            A_Private_Extension_Declaration
          | A_Private_Extension_Definition =>

            Is_Abstract := Abstract_Present (Arg_Node);

            if Is_Abstract then
               Result := An_Abstract_Private_Trait;
            else
               Result := A_Private_Trait;
            end if;

      when -- (*3*)
            A_Variable_Declaration
          | A_Constant_Declaration
          | A_Deferred_Constant_Declaration  =>

            Is_Aliased := Aliased_Present (Arg_Node);

            if Is_Aliased then
               Result := An_Aliased_Trait;
            end if;

      when -- (*4*)
            A_Discriminant_Specification
          | A_Parameter_Specification =>

--  --|A2005 start

            if A4G.A_Opt.ASIS_2005_Mode then
               --  Ada/ASIS 2005 approach: we have to define
               --  A_Null_Exclusion_Trait, and we can not define
               --  An_Access_Definition_Trait in any reasonable way - now it
               --  corresponds to An_Access_Definition Elements, and in case if
               --  an access discriminant also contains null_exclusion, we
               --  would need something like A_Null_Exclusion_Access_Trait,
               --  that looks completely meaningless for ASIS 2005

               if Null_Exclusion_Present (Arg_Node) then
                  Result := A_Null_Exclusion_Trait;
               end if;

            else
               --  Old Ada/ASIS 95 approach: we may have
               --  An_Access_Definition_Trait, but we do not have
               --  A_Null_Exclusion_Trait

               if Int_Kind (Element) = A_Discriminant_Specification then
                  Trait_Defining_Node := Discriminant_Type (Arg_Node);
               else
                  Trait_Defining_Node := Parameter_Type (Arg_Node);
               end if;

               if Nkind (Trait_Defining_Node) = N_Access_Definition then
                  Result := An_Access_Definition_Trait;
               end if;

            end if;
--  --|A2005 end

      when -- (*5*)
            A_Loop_Parameter_Specification =>

            if Reverse_Present (Arg_Node) then
               Result := A_Reverse_Trait;
            end if;

      when -- (*6*)
            A_Procedure_Declaration
          | A_Function_Declaration =>

            if Nkind (Arg_Node) = N_Abstract_Subprogram_Declaration then
               Result := An_Abstract_Trait;
            end if;
--  --|A2005 start
      when
            A_Formal_Procedure_Declaration
          | A_Formal_Function_Declaration =>

            if Nkind (Arg_Node) = N_Formal_Abstract_Subprogram_Declaration then
               Result := An_Abstract_Trait;
            end if;
--  --|A2005 end

      when -- (*7*)
            A_Derived_Type_Definition
          | A_Derived_Record_Extension_Definition =>

            if Abstract_Present (Arg_Node) then
               Result := An_Abstract_Trait;
            end if;

      when -- (*8*)
            A_Record_Type_Definition
          | A_Tagged_Record_Type_Definition =>

            Is_Abstract := Abstract_Present (Arg_Node);
            Is_Limited  := Limited_Present  (Arg_Node);

            if Is_Abstract and Is_Limited then
               Result := An_Abstract_Limited_Trait;
            elsif Is_Abstract then
               Result := An_Abstract_Trait;
            elsif Is_Limited then
               Result := A_Limited_Trait;
            end if;

      when -- (*9*)
            A_Formal_Derived_Type_Definition =>

            Is_Abstract := Abstract_Present (Arg_Node);
            Is_Limited  := Limited_Present  (Arg_Node);
            Is_Private  := Private_Present  (Arg_Node);

            if Is_Abstract and Is_Limited and Is_Private then
               Result := An_Abstract_Limited_Private_Trait;
            elsif Is_Abstract and Is_Limited then
               Result := An_Abstract_Limited_Trait;
            elsif Is_Abstract and Is_Private then
               Result := An_Abstract_Private_Trait;
            elsif Is_Limited and Is_Private then
               Result := A_Limited_Private_Trait;
            elsif Is_Abstract then
               Result := An_Abstract_Trait;
            elsif Is_Limited then
               Result := A_Limited_Trait;
            elsif Is_Private then
               Result := A_Private_Trait;
            end if;

      when -- (*10*)
            A_Component_Definition =>

            if Aliased_Present (R_Node (Element)) then
               Result := An_Aliased_Trait;
            end if;

--  --|A2005 start
      when A_With_Clause =>
            Is_Limited := Limited_Present  (Arg_Node);
            Is_Private := Private_Present (Arg_Node);

            if Is_Limited then
               if Is_Private then
                  Result := A_Limited_Private_Trait;
               else
                  Result := A_Limited_Trait;
               end if;
            elsif Is_Private then
               Result := A_Private_Trait;
            end if;
      when Internal_Access_Type_Kinds =>

            if Null_Exclusion_Present (Arg_Node) then
               Result := A_Null_Exclusion_Trait;
            end if;

      when Internal_Access_Definition_Kinds =>

            if Present (Sinfo.Access_To_Subprogram_Definition (Arg_Node)) then
               Arg_Node := Sinfo.Access_To_Subprogram_Definition (Arg_Node);
            end if;

            if Null_Exclusion_Present (Arg_Node) then
               Result := A_Null_Exclusion_Trait;
            end if;

      when A_Subtype_Indication =>
            Arg_Node := Parent (Arg_Node);

            if Null_Exclusion_Present (Arg_Node) then
               Result := A_Null_Exclusion_Trait;
            end if;

--  --|A2005 end

      when others =>
         --  unexpected argument:
         Result := Not_A_Trait;
      end case;

      return Result;

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

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

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

   function Declaration_Origin
     (Declaration : Asis.Declaration)
      return        Asis.Declaration_Origins
   is
   begin
      --  The implementation may require revising when the semantic queries
      --  and implicit elements are implemented.
      Check_Validity (Declaration, Package_Name & "Declaration_Origin");

      if Int_Kind (Declaration) not in Internal_Declaration_Kinds then
         return Not_A_Declaration_Origin;
      elsif not Is_From_Implicit (Declaration) then
         return An_Explicit_Declaration;
      elsif Is_From_Inherited (Declaration) then
         return An_Implicit_Inherited_Declaration;
      else
         return An_Implicit_Predefined_Declaration;
      end if;

   end Declaration_Origin;
-----------------------------------------------------------------------------

   function Mode_Kind
     (Declaration : Asis.Declaration)
      return        Asis.Mode_Kinds
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Declaration);
      Arg_Node : Node_Id;
   begin

      Check_Validity (Declaration, Package_Name & "Mode_Kind");

      if not (Arg_Kind = A_Parameter_Specification or else
              Arg_Kind = A_Formal_Object_Declaration)
      then
         return Not_A_Mode;
      end if;

      Arg_Node := Node (Declaration);

      if In_Present (Arg_Node) and then Out_Present (Arg_Node) then
         return An_In_Out_Mode;
      elsif In_Present (Arg_Node) then
         return An_In_Mode;
      elsif Out_Present (Arg_Node) then
         return An_Out_Mode;
      else
         return A_Default_In_Mode;
      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 & "Mode_Kind");
         end if;

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

   function Default_Kind
     (Declaration : Asis.Generic_Formal_Parameter)
      return        Asis.Subprogram_Default_Kinds
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Declaration);
      Arg_Node : Node_Id;
   begin

      Check_Validity (Declaration, Package_Name & "Default_Kind");

      Arg_Node := Node (Declaration);

      if not (Arg_Kind = A_Formal_Procedure_Declaration or else
              Arg_Kind = A_Formal_Function_Declaration)
      then
         return Not_A_Default;
      elsif Box_Present (Arg_Node) then
         return A_Box_Default;
      elsif Present (Default_Name (Arg_Node)) then
         return A_Name_Default;
      elsif Nkind (Specification (Arg_Node)) = N_Procedure_Specification
          and then
            Null_Present (Specification (Arg_Node))
      then
         return A_Null_Default;
      else
         return A_Nil_Default;
      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 & "Default_Kind");
         end if;

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

   function Definition_Kind
     (Definition : Asis.Definition)
      return       Asis.Definition_Kinds
   is
   begin
      Check_Validity (Definition, Package_Name & "Definition_Kind");

      return Definition_Kind_From_Internal (Int_Kind (Definition));
   end Definition_Kind;
-----------------------------------------------------------------------------

   function Type_Kind
     (Definition : Asis.Type_Definition)
      return       Asis.Type_Kinds
   is
   begin
      Check_Validity (Definition, Package_Name & "Type_Kind");

      return Type_Kind_From_Internal (Int_Kind (Definition));
   end Type_Kind;
-----------------------------------------------------------------------------

   function Formal_Type_Kind
     (Definition : Asis.Type_Definition)
      return       Asis.Formal_Type_Kinds
   is
   begin
      Check_Validity (Definition, Package_Name & "Formal_Type_Kind");

      return Formal_Type_Kind_From_Internal (Int_Kind (Definition));
   end Formal_Type_Kind;
-----------------------------------------------------------------------------

   function Access_Type_Kind
     (Definition : Asis.Type_Definition)
      return       Asis.Access_Type_Kinds
   is
   begin
      Check_Validity (Definition, Package_Name & "Access_Type_Kind");

      return Access_Type_Kind_From_Internal (Int_Kind (Definition));
   end Access_Type_Kind;
-----------------------------------------------------------------------------

   function Root_Type_Kind
     (Definition : Asis.Type_Definition)
      return       Asis.Root_Type_Kinds
   is
   begin
      Check_Validity (Definition, Package_Name & "Root_Type_Kind");

      return Root_Type_Kind_From_Internal (Int_Kind (Definition));
   end Root_Type_Kind;
-----------------------------------------------------------------------------

   function Constraint_Kind
     (Definition : Asis.Definition)
      return       Asis.Constraint_Kinds
   is
   begin
      Check_Validity (Definition, Package_Name & "Constraint_Kind");

      return Constraint_Kind_From_Internal (Int_Kind (Definition));
   end Constraint_Kind;
-----------------------------------------------------------------------------

   function Discrete_Range_Kind
     (Definition : Asis.Definition)
      return       Asis.Discrete_Range_Kinds
   is
   begin
      Check_Validity (Definition, "Discrete_Range_Kind.Expression_Kind");

      return Discrete_Range_Kind_From_Internal (Int_Kind (Definition));
   end Discrete_Range_Kind;

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

   function Expression_Kind
     (Expression : Asis.Expression)
      return       Asis.Expression_Kinds
   is
   begin
      Check_Validity (Expression, Package_Name & "Expression_Kind");

      return Expression_Kind_From_Internal (Int_Kind (Expression));
   end Expression_Kind;
-----------------------------------------------------------------------------

   function Operator_Kind
     (Element : Asis.Element)
      return    Asis.Operator_Kinds
   is
   begin
      Check_Validity (Element, Package_Name & "Operator_Kind");

      return Operator_Kind_From_Internal (Int_Kind (Element));
   end Operator_Kind;
-----------------------------------------------------------------------------

   function Attribute_Kind
     (Expression : Asis.Expression)
      return       Asis.Attribute_Kinds
   is
   begin
      Check_Validity (Expression, Package_Name & "Attribute_Kind");

      return Attribute_Kind_From_Internal (Int_Kind (Expression));
   end Attribute_Kind;
-----------------------------------------------------------------------------

   function Association_Kind
     (Association : Asis.Association)
      return        Asis.Association_Kinds
   is
   begin
      Check_Validity (Association, Package_Name & "Association_Kind");

      return Association_Kind_From_Internal (Int_Kind (Association));
   end Association_Kind;
-----------------------------------------------------------------------------

   function Statement_Kind
     (Statement : Asis.Statement)
      return      Asis.Statement_Kinds
   is
   begin
      Check_Validity (Statement, Package_Name & "Statement_Kind");

      return Statement_Kind_From_Internal (Int_Kind (Statement));
   end Statement_Kind;
-----------------------------------------------------------------------------

   function Path_Kind (Path : Asis.Path) return Asis.Path_Kinds is
   begin
      Check_Validity (Path, Package_Name & "Clause_Kind");

      return Path_Kind_From_Internal (Int_Kind (Path));
   end Path_Kind;
-----------------------------------------------------------------------------

   function Clause_Kind (Clause : Asis.Clause) return Asis.Clause_Kinds is
   begin
      Check_Validity (Clause, Package_Name & "Clause_Kind");

      return Clause_Kind_From_Internal (Int_Kind (Clause));
   end Clause_Kind;
-----------------------------------------------------------------------------

   function Representation_Clause_Kind
     (Clause : Asis.Clause)
      return   Asis.Representation_Clause_Kinds
   is
   begin
      Check_Validity (Clause, Package_Name & "Representation_Clause_Kind");

      return Representation_Clause_Kind_From_Internal (Int_Kind (Clause));
   end Representation_Clause_Kind;
-----------------------------------------------------------------------------

   function Is_Nil (Right : Asis.Element) return Boolean is
   begin
      return Right = Asis.Nil_Element;
   end Is_Nil;
-----------------------------------------------------------------------------

   function Is_Nil (Right : Asis.Element_List) return Boolean is
   begin
      return Right'Length = 0;
   end Is_Nil;
-----------------------------------------------------------------------------

   function Is_Equal
     (Left  : Asis.Element;
      Right : Asis.Element)
      return  Boolean
   is
      C_Left   : Context_Id;
      C_Right  : Context_Id;

      U_Left   : Unit_Id;
      U_Right  : Unit_Id;

      CU_Left  : Compilation_Unit;
      CU_Right : Compilation_Unit;

      N_Left   : Node_Id;
      N_Right  : Node_Id;

      Result   : Boolean := False;

   begin
      Check_Validity (Left,  Package_Name & "Is_Equal");
      Check_Validity (Right, Package_Name & "Is_Equal");

      --  To minimize the performance penalties, we are trying to filter
      --  out simple cases first. These are (more or less) simple cases
      --  when the function should return False

      --  First, checking the case when one of the arguments is Nil_Element

      if Int_Kind (Left)  = Not_An_Element or else
         Int_Kind (Right) = Not_An_Element
      then
         return (Int_Kind (Left) = Int_Kind (Right));
      end if;

      --  Then, we are checking if the basic properties of the argument are
      --  the same

      if not (Special_Case       (Left) = Special_Case       (Right) and then
              Int_Kind           (Left) = Int_Kind           (Right) and then
              Character_Code     (Left) = Character_Code     (Right) and then
              Is_From_Implicit   (Left) = Is_From_Implicit   (Right) and then
              Is_From_Inherited  (Left) = Is_From_Inherited  (Right) and then
              Is_From_Instance   (Left) = Is_From_Instance   (Right) and then
              Normalization_Case (Left) = Normalization_Case (Right) and then
              Parenth_Count (Left)      = Parenth_Count      (Right))
      then
         return False;
      end if;

      --  Now, checking that arguments are from the same Ada unit

      C_Left  := Encl_Cont_Id (Left);
      U_Left  := Encl_Unit_Id (Left);

      C_Right := Encl_Cont_Id (Right);
      U_Right := Encl_Unit_Id (Right);

      if C_Left = C_Right then

         if U_Left /= U_Right then
            return False;
         end if;

      else
         --  This case is a bit more complicated: we have to compare names
         --  and time stamps of enclosed units
         if U_Left = Standard_Id or else U_Right = Standard_Id then

            if U_Left /= U_Right then
               return False;
            end if;

         else

            if Time_Stamp (C_Left, U_Left) /=
               Time_Stamp (C_Right, U_Right)
            then
               return False;
            end if;

            --  Here we have to compare unit names. Let's check unit kind
            --  and class first

            CU_Left  := Encl_Unit (Left);
            CU_Right := Encl_Unit (Right);

            if not (Kind  (CU_Left) = Kind  (CU_Right) and then
                    Class (CU_Left) = Class (CU_Right))
            then
               return False;
            end if;

            --  And now - unit names. This case does not seem to be
            --  encountered very often, so we simply use Unit_Full_Name
            --  query to avoid manual Context switching:

            if Asis.Compilation_Units.Unit_Full_Name (CU_Left) /=
               Asis.Compilation_Units.Unit_Full_Name (CU_Right)
            then
               return False;
            end if;

         end if;

      end if;

      --  And if we are here, we are in the following situation: both Left
      --  and Right are non-nil Elements, they have all their properties
      --  the same and they are from the same Compilation_Unit.
      --  And now we have to check if they represents the same construct.

      if U_Left = Standard_Id or else
         (C_Left = C_Right
         and then
          Encl_Tree (Left) = Encl_Tree (Right))
      then
         --  In Standard, we may just compare the node values.
         --  In the same tree we may do the same
         return R_Node (Left) = R_Node (Right);
      end if;

      --  In case of configuration pragmas and components thereof we are very
      --  conservative - two elements can be equal only if there are from
      --  the same tree. The reason for this is that in ASIS we have no
      --  means to control that the content of the configuration files
      --  is the same in different trees.

      if Special_Case (Left) = Configuration_File_Pragma then

         return Encl_Tree (Left) = Encl_Tree (Right) and then
                R_Node (Left) = R_Node (Right);

      end if;

      --  And if we are here, we have to compare Elements obtained from
      --  different trees

      if not Is_From_Instance (Left) then
         --  May be, we have to use source-trace-based approach for
         --  all cases....????
         return Rel_Sloc (Left) = Rel_Sloc (Right);
      end if;

      --  If we are here, we have to compare node traces.

      Reset_Context (C_Left);

      N_Left := R_Node (Left);
      Create_Node_Trace (N_Left);

      Reset_Context (C_Right);

      N_Right := R_Node (Right);
      Result  := True;

      for J in Node_Trace.First .. Node_Trace.Last loop

         if No (N_Right) or else
            not Is_Equal (N_Right, Node_Trace.Table (J))
         then
            Result := False;
            exit;
         end if;

         N_Right := A4G.Asis_Tables.Enclosing_Scope (N_Right);

      end loop;

      return Result;

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information (Outer_Call => Package_Name & "Is_Equal");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name    => Package_Name & "Is_Equal",
            Ex            => Ex,
            Arg_Element   => Left,
            Arg_Element_2 => Right);
   end Is_Equal;

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

   function Is_Identical
     (Left  : Asis.Element;
      Right : Asis.Element)
      return  Boolean
   is
      C_Left  : Context_Id;
      C_Right : Context_Id;
   begin
      Check_Validity (Left,  Package_Name & "Is_Identical");
      Check_Validity (Right, Package_Name & "Is_Identical");

      C_Left  := Encl_Cont_Id (Left);
      C_Right := Encl_Cont_Id (Right);

      if C_Left /= C_Right then
         return False;
      else
         return Is_Equal (Left, Right);
      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_Identical");
         end if;

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name    => Package_Name & "Is_Identical",
            Ex            => Ex,
            Arg_Element   => Left,
            Arg_Element_2 => Right);
   end Is_Identical;
------------------------------------------------------------------------------
--          The general principle of the implementation
--          of the Is_Part_Of_... functions:
--
--  These functions simply returns the corresponding flag value from the
--  Element passed as their argument. All necessary work should be done
--  during the creation of the Element when these flags are set
--
--  All of them (as well as the function Declaration_Origin above) will
--  require revisiting during semantic queries implementation
------------------------------------------------------------------------------

   function Is_Part_Of_Implicit (Element : Asis.Element) return Boolean is
   begin
      Check_Validity (Element, Package_Name & "Is_Part_Of_Implicit");

      return Is_From_Implicit (Element) or else
             Normalization_Case (Element) in Normalized_Association;
      --  for normalized associations Is_Part_Of_Implicit is not set ON   ???
      --  unless the association is from some enclosing implicit construct. ???
   end Is_Part_Of_Implicit;
-----------------------------------------------------------------------------

   function Is_Part_Of_Inherited (Element : Asis.Element) return Boolean is
   begin
      Check_Validity (Element, Package_Name & "Is_Part_Of_Inherited");

      return Is_From_Inherited (Element);
   end Is_Part_Of_Inherited;
-----------------------------------------------------------------------------

   function Is_Part_Of_Instance (Element : Asis.Element) return Boolean is
   begin
      Check_Validity (Element, Package_Name & "Is_Part_Of_Instance");

      return Is_From_Instance (Element);
   end Is_Part_Of_Instance;
-----------------------------------------------------------------------------
   function Enclosing_Element
     (Element : Asis.Element)
      return    Asis.Element
   is
      Argument_Kind : constant Internal_Element_Kinds := Int_Kind (Element);
      Arg_Spec_Case : constant Special_Cases := Special_Case (Element);
   begin
      Check_Validity (Element, Package_Name & "Enclosing_Element");

      if Argument_Kind = Not_An_Element then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Enclosing_Element",
            Wrong_Kind => Argument_Kind);
      end if;

      --  if the argument is an expanded generic declaration we have
      --  to return the corresponding instantiation:
      if Arg_Spec_Case in Expanded_Spec then
         return Corresponding_Instantiation (Element);
      end if;

      --  if the argument is from an expanded generic declaration,
      --  we have to be careful when coming from some top-level component
      --  of the expanded declaration to the declaration itself - we
      --  need to set the Special_Case field properly

      if Is_From_Instance (Element) and then
         not Is_From_Implicit (Element)
      then

         if Arg_Spec_Case in
            Dummy_Base_Attribute_Designator .. Dummy_Class_Attribute_Prefix
         then

            declare
               Result : Asis.Element := Element;
            begin
               Set_Special_Case (Result, Not_A_Special_Case);

               if Arg_Spec_Case = Dummy_Class_Attribute_Designator
                 or else
                  Arg_Spec_Case = Dummy_Class_Attribute_Prefix
               then
                  Set_Int_Kind (Result, A_Class_Attribute);
               elsif Arg_Spec_Case = Dummy_Base_Attribute_Designator
                    or else
                     Arg_Spec_Case = Dummy_Base_Attribute_Prefix
               then
                  Set_Int_Kind (Result, A_Base_Attribute);
               end if;

               return Result;
            end;
         else
            return Enclosing_For_Explicit_Instance_Component (Element);
         end if;

      end if;

      if not (Is_From_Implicit (Element) or else
              Is_From_Inherited (Element))  --  ???
      then
         return Enclosing_Element_For_Explicit (Element);
      else
         return Enclosing_Element_For_Implicit (Element);
      end if;

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

         if Status_Indicator = Unhandled_Exception_Error then
            Add_Call_Information
              (Argument   => Element,
               Outer_Call => Package_Name & "Enclosing_Element");

         end if;

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

   function Enclosing_Element
     (Element                    : Asis.Element;
      Expected_Enclosing_Element : Asis.Element)
      return                       Asis.Element
   is
   begin
      Check_Validity
        (Element,
         Package_Name & "Enclosing_Element (the Element parameter)");

      Check_Validity
        (Expected_Enclosing_Element,
         Package_Name &
         "Enclosing_Element (the Expected_Enclosing_Element parameter)");

      return Enclosing_Element (Element);
   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

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

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name    => Package_Name & "Enclosing_Element",
            Ex            => Ex,
            Arg_Element   => Element,
            Arg_Element_2 => Expected_Enclosing_Element);
   end Enclosing_Element;
-----------------------------------------------------------------------------
   function Pragmas
     (The_Element : Asis.Element)
      return        Asis.Pragma_Element_List
   is

--  This implementation is based on the following statement in the function
--  documentation:
--
--  This interface returns exactly those pragmas that would be returned by the
--  various interfaces, that accept these same argument kinds, and that
--  return Declaration_Lists and Statement_Lists, where the inclusion of
--  Pragmas is controlled by an Include_Pragmas parameter.
--
--  The general idea of the implementation is straightforward - to get
--  the "full" Element_List by the call of the corresponding interface
--  with Include_Pragmas => True, and then select only A_Pragma elements
--  from this intermediate result.
--
--  Some loss of effectiveness could be considered as the disadvantage of
--  this approach, but its advantages are:
--
--   - it saves implementation efforts;
--   - it allows to check whether the documentation fragment cited above
--     is really correct;
--   - it saves the debugging efforts on the first prototyping stage
--     (there is no need for the special debugging of this function
--     if other ASIS interfaces used for its implementation work correctly);
--   - it is more convenient for incremental development
--   - it yields the vendor-independent implementation of this function

      Context_Internal_Kind : Internal_Element_Kinds;

      function Extract_Pragmas
        (List : Asis.Element_List)
         return Asis.Pragma_Element_List;
      --  function extracts Elements of A_Pragma kind from its
      --  List parameter and returns the new List constructed from these
      --  Pragma Elements (in their order of appearance) as its result

      function Extract_Pragmas
        (List : Asis.Element_List)
         return Asis.Pragma_Element_List
      is
         Pragma_List               : Asis.Pragma_Element_List (List'Range);
         Pragma_List_Actual_Lenght : Asis.ASIS_Integer := 0;

      begin

         for I in List'Range loop

            if Element_Kind (List (I)) = A_Pragma then
               Pragma_List_Actual_Lenght := Pragma_List_Actual_Lenght + 1;
               Pragma_List (Pragma_List_Actual_Lenght) := List (I);
            end if;

         end loop;

         return Pragma_List (1 .. Pragma_List_Actual_Lenght);

      end Extract_Pragmas;

   begin -- Pragmas

      Check_Validity (The_Element, Package_Name & "Pragmas");

      Context_Internal_Kind := Int_Kind (The_Element);

      if not -- Appropriate Element_Kinds:

             (Context_Internal_Kind in Internal_Path_Kinds
            or else Context_Internal_Kind =  An_Exception_Handler

            --  Appropriate Declaration_Kinds:

            or else Context_Internal_Kind =  A_Procedure_Body_Declaration
            or else Context_Internal_Kind =  A_Function_Body_Declaration
            or else Context_Internal_Kind =  A_Package_Declaration
            or else Context_Internal_Kind =  A_Package_Body_Declaration
            or else Context_Internal_Kind =  A_Task_Body_Declaration
            or else Context_Internal_Kind =  A_Protected_Body_Declaration
            or else Context_Internal_Kind =  An_Entry_Body_Declaration
            or else Context_Internal_Kind =  A_Generic_Procedure_Declaration
            or else Context_Internal_Kind =  A_Generic_Function_Declaration
            or else Context_Internal_Kind =  A_Generic_Package_Declaration

            --  Appropriate Definition_Kinds:

            or else Context_Internal_Kind =  A_Record_Definition
            or else Context_Internal_Kind =  A_Variant_Part
            or else Context_Internal_Kind =  A_Variant
            or else Context_Internal_Kind =  A_Task_Definition
            or else Context_Internal_Kind =  A_Protected_Definition

            --  Appropriate Statement_Kinds:

            or else Context_Internal_Kind =  A_Loop_Statement
            or else Context_Internal_Kind =  A_While_Loop_Statement
            or else Context_Internal_Kind =  A_For_Loop_Statement
            or else Context_Internal_Kind =  A_Block_Statement
            or else Context_Internal_Kind =  An_Accept_Statement
            --  Representation_Clause_Kinds:
            or else Context_Internal_Kind = A_Record_Representation_Clause)
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Pragmas",
            Wrong_Kind => Context_Internal_Kind);
      end if;

      case Context_Internal_Kind is

         --  Appropriate Element_Kinds:

         when Internal_Path_Kinds =>
            --  A_Path: (pragmas from the statement list)

            return Extract_Pragmas (
                   Asis.Statements.Sequence_Of_Statements (
                       Path            => The_Element,
                       Include_Pragmas => True));

         when An_Exception_Handler =>
            --  (pragmas from the statement list)

            return Extract_Pragmas (
                   Asis.Statements.Handler_Statements (
                       Handler         => The_Element,
                       Include_Pragmas => True));

--  Appropriate Declaration_Kinds:

         when A_Procedure_Body_Declaration  -- (pragmas from decl region
            | A_Function_Body_Declaration   --  + statements)
            | A_Package_Body_Declaration    -- !! SEE OPEN_PROBLEMS.1 BELOW
            | A_Task_Body_Declaration
            | An_Entry_Body_Declaration =>

            return (Extract_Pragmas (
                        Asis.Declarations.Body_Declarative_Items (
                            Declaration     => The_Element,
                            Include_Pragmas => True))
                   &
                      Extract_Pragmas (
                         Asis.Declarations.Body_Statements (
                            Declaration     => The_Element,
                            Include_Pragmas => True)));

         when A_Package_Declaration =>
            --  (pragmas from visible + private decl regions)
            return (Extract_Pragmas (
                        Asis.Declarations.Visible_Part_Declarative_Items (
                            Declaration     => The_Element,
                            Include_Pragmas => True))
                   &
                      Extract_Pragmas (
                        Asis.Declarations.Private_Part_Declarative_Items (
                            Declaration     => The_Element,
                            Include_Pragmas => True)));

         when A_Protected_Body_Declaration =>
            --  (pragmas from decl region)

            return Extract_Pragmas (
                      Asis.Declarations.Protected_Operation_Items (
                          Declaration     => The_Element,
                          Include_Pragmas => True));

         when A_Generic_Procedure_Declaration
            | A_Generic_Function_Declaration =>

            --  (pragmas from formal decl region
            return Extract_Pragmas (
                      Asis.Declarations.Generic_Formal_Part (
                          Declaration     => The_Element,
                          Include_Pragmas => True));

         when A_Generic_Package_Declaration =>
            --  (pragmas from formal + visible + private decl regions)
            return (Extract_Pragmas (
                        Asis.Declarations.Generic_Formal_Part (
                            Declaration     => The_Element,
                            Include_Pragmas => True))
                   &
                      Extract_Pragmas (
                        Asis.Declarations.Visible_Part_Declarative_Items (
                            Declaration     => The_Element,
                            Include_Pragmas => True))
                   &
                      Extract_Pragmas (
                        Asis.Declarations.Private_Part_Declarative_Items (
                            Declaration     => The_Element,
                            Include_Pragmas => True)));

--  Appropriate Definition_Kinds:

         when   A_Record_Definition
              | A_Variant           =>

            --  (pragmas from the component list)

            return Extract_Pragmas (
                      Asis.Definitions.Record_Components (
                          Definition        => The_Element,
                          Include_Pragmas   => True));

         when A_Variant_Part =>
            --  (pragmas from between variants)

            return Extract_Pragmas (
                      Asis.Definitions.Variants (
                          Variant_Part    => The_Element,
                          Include_Pragmas => True));

         when A_Task_Definition
            | A_Protected_Definition =>

            --  (pragmas from visible + private decl regions)
            return (Extract_Pragmas (
                        Asis.Definitions.Visible_Part_Items (
                            Definition      => The_Element,
                            Include_Pragmas => True))
                   &
                      Extract_Pragmas (
                        Asis.Definitions.Private_Part_Items (
                            Definition      => The_Element,
                            Include_Pragmas => True)));

--  Appropriate Statement_Kinds:

         when A_Loop_Statement
            | A_While_Loop_Statement
            | A_For_Loop_Statement =>

            --  (pragmas from statement list)

            return Extract_Pragmas (
                     Asis.Statements.Loop_Statements (
                         Statement       => The_Element,
                         Include_Pragmas => True));

         when A_Block_Statement =>
         --  (pragmas from decl region + statements)

            return (Extract_Pragmas (
                        Asis.Statements.Block_Declarative_Items (
                            Statement       => The_Element,
                            Include_Pragmas => True))
                   &
                      Extract_Pragmas (
                         Asis.Statements.Block_Statements (
                            Statement       => The_Element,
                            Include_Pragmas => True)));

         when An_Accept_Statement =>
            --  (pragmas from statement list+ pragma immediately preceding
            --  the first  exception handler, if any)
            --  !! SEE OPEN_PROBLEMS.2 BELOW
            return (Extract_Pragmas (
                        Asis.Statements.Accept_Body_Statements (
                            Statement       => The_Element,
                            Include_Pragmas => True))
                   &
                      Extract_Pragmas (
                         Asis.Statements.Accept_Body_Exception_Handlers (
                            Statement       => The_Element,
                            Include_Pragmas => True)));

--  Appropriate Representation_Clause_Kinds:

         when A_Record_Representation_Clause =>
            --  (pragmas from component specifications)

            return Extract_Pragmas (
                     Asis.Clauses.Component_Clauses (
                         Clause          => The_Element,
                         Include_Pragmas => True));

         when others =>
            --  Should never been reached !!!
            raise Internal_Implementation_Error;
      end case;

   exception
      when ASIS_Inappropriate_Element =>
         Add_Call_Information (Outer_Call => Package_Name & "Pragmas");
         raise;
      when ASIS_Failed =>

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

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Pragmas",
            Ex          => Ex,
            Arg_Element => The_Element);
   end Pragmas;
------------------------------------------------------------------------------
--  PARTIALLY IMPLEMENTED

   ---------------------------
   -- Corresponding_Pragmas --
   ---------------------------

   function Corresponding_Pragmas
     (Element : Asis.Element)
      return    Asis.Pragma_Element_List
   is
      Next_Rep_Node    : Node_Id;
      Next_Pragma_Node : Node_Id := Empty;
      Arg_Node         : Node_Id;
   begin
      Check_Validity (Element, Package_Name & "Corresponding_Pragmas");

      if not (Element_Kind (Element) = A_Declaration
           or else
              Element_Kind (Element) = A_Statement)
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Corresponding_Pragmas",
            Wrong_Kind => Int_Kind (Element));
      end if;

      --  At the moment, this is a partial implementation:
      --  - for A_Statement argument  Nil_Element_List is always returned;
      --  - for A_Declaration argument that represents
      --  - for A_Declaration argument that corresponds to a unit declaration
      --    from the compilation unit or to the proper body of subunit, nothing
      --    is returned.
      --  - implicit inherited declarations are not properly processed
      --  - the result list contains representation pragmas only

      if Element_Kind (Element) = A_Statement then
         return Nil_Element_List;
      else
         Asis_Element_Table.Init;

         case Declaration_Kind (Element) is
            when A_Procedure_Declaration          |
                 A_Function_Declaration           |
                 A_Procedure_Body_Declaration     |
                 A_Function_Body_Declaration      |
                 A_Procedure_Renaming_Declaration |
                 A_Function_Renaming_Declaration  |
                 An_Entry_Declaration             |
                 A_Procedure_Body_Stub            |
                 A_Function_Body_Stub             |
                 A_Procedure_Instantiation        |
                 A_Function_Instantiation         =>

            --  Overloadable entities, pragmas are not chained.
            --  At the moment we can process only explicit stuff.

            --  First, collect Pre- and Postcondition pragmas, if any.
            Arg_Node := R_Node (Element);

            case Declaration_Kind (Element) is
               when A_Procedure_Declaration |
                    A_Function_Declaration  =>

                  if Is_List_Member (Arg_Node) then
                     Next_Pragma_Node := Next (Arg_Node);
                  else
                     --  Spec of a library-level subprogram
                     Next_Pragma_Node := Aux_Decls_Node (Parent (Arg_Node));

                     if Present (Pragmas_After (Next_Pragma_Node)) then
                        Next_Pragma_Node :=
                          First (Pragmas_After (Next_Pragma_Node));
                     else
                        Next_Pragma_Node := Empty;
                     end if;

                  end if;

               when A_Procedure_Body_Declaration |
                    A_Function_Body_Declaration  =>
                  Next_Pragma_Node := First (Sinfo.Declarations (Arg_Node));

                  while Present (Next_Pragma_Node)
                     and then
                        not Comes_From_Source
                             (Original_Node (Next_Pragma_Node))
                  loop
                     Next_Pragma_Node := Next (Next_Pragma_Node);
                  end loop;

               when others => null;
            end case;

            while Present (Next_Pragma_Node)
                and then
                 Nkind (Next_Pragma_Node) = N_Pragma
            loop

               if Pragma_Name (Original_Node (Next_Pragma_Node)) in
                   Name_Postcondition .. Name_Precondition
               then
                  Asis_Element_Table.Append
                    (Node_To_Element_New
                      (Starting_Element => Element,
                       Node             => Next_Pragma_Node));
               end if;

               Next_Pragma_Node := Next (Next_Pragma_Node);

               while Present (Next_Pragma_Node)
                  and then
                     not Comes_From_Source (Original_Node (Next_Pragma_Node))
               loop
                  Next_Pragma_Node := Next (Next_Pragma_Node);
               end loop;

            end loop;

            --  Now - general processing of all the other pragmas that can be
            --  semantically associated with the argument
            if not Is_Part_Of_Implicit (Element)
              and then
               Enclosing_Element (Element) /= Nil_Element
            then

               case Nkind (Arg_Node) is
                  when N_Subprogram_Declaration          |
                       N_Abstract_Subprogram_Declaration |
                       N_Subprogram_Body                 |
                       N_Subprogram_Renaming_Declaration |
                       N_Subprogram_Body_Stub            =>
                     Arg_Node := Defining_Unit_Name (Specification (Arg_Node));
                  when N_Entry_Declaration =>
                     Arg_Node := Defining_Identifier (Arg_Node);

                  when N_Procedure_Instantiation |
                       N_Function_Instantiation  =>
                     Arg_Node := Defining_Unit_Name (Arg_Node);

                  when others =>
                     pragma Assert (False);
                     null;
               end case;

               Next_Rep_Node := R_Node (Element);
               Next_Rep_Node := Next (Next_Rep_Node);

               while Present (Next_Rep_Node) loop

                  if Nkind (Next_Rep_Node) = N_Pragma
                   and then
                     Is_Applied_To (Next_Rep_Node, Arg_Node)
                  then
                     Asis_Element_Table.Append
                       (Node_To_Element_New
                         (Starting_Element => Element,
                          Node             => Next_Rep_Node));
                  end if;

                  Next_Rep_Node := Next (Next_Rep_Node);

               end loop;

               --  In case if the ergument declaration is in the visible part
               --  of the package spec, traverse the private part:
               Next_Rep_Node := Parent (R_Node (Element));

               if Nkind (Next_Rep_Node) = N_Package_Specification
                 and then
                  List_Containing (R_Node (Element)) =
                  Visible_Declarations (Next_Rep_Node)
               then
                  Next_Rep_Node :=
                    First (Private_Declarations (Next_Rep_Node));

                  while Present (Next_Rep_Node) loop

                     if Nkind (Next_Rep_Node) = N_Pragma
                      and then
                        Is_Applied_To (Next_Rep_Node, Arg_Node)
                     then
                        Asis_Element_Table.Append
                          (Node_To_Element_New
                            (Starting_Element => Element,
                             Node             => Next_Rep_Node));
                     end if;

                     Next_Rep_Node := Next (Next_Rep_Node);

                  end loop;

               end if;

            end if;

         when others =>

            --  Non-overloadable entity. This implementation is not good,
            --  but we have to deal with an error in query definition -
            --  the query should actually be applied to an entity, but not
            --  to a declaration that can define more then one entity.
            declare
               Decl_Names    : constant Element_List := Names (Element);
               Next_Name     : Asis.Element;
            begin

               for J in Decl_Names'Range loop
                  Next_Name := Decl_Names (J);

                  if Defining_Name_Kind (Next_Name) =
                     A_Defining_Expanded_Name
                  then
                     Next_Name := Defining_Selector (Next_Name);
                  end if;

                  Next_Rep_Node := First_Rep_Item (R_Node (Next_Name));

                  while Present (Next_Rep_Node) loop

                     if Nkind (Next_Rep_Node) = N_Pragma then
                        Asis_Element_Table.Append
                          (Node_To_Element_New
                            (Starting_Element => Element,
                             Node             => Next_Rep_Node));
                     end if;

                     Next_Rep_Node := Next_Rep_Item (Next_Rep_Node);

                  end loop;

               end loop;

            end;
         end case;

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

      end if;

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

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

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

   function Pragma_Name_Image
     (Pragma_Element : Asis.Pragma_Element)
      return           Wide_String
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Pragma_Element);
      Arg_Node : Node_Id;

      Image_Start : Source_Ptr;
      Image_End   : Source_Ptr;
   begin
      Check_Validity (Pragma_Element, Package_Name & "Pragma_Name_Image");

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

      Arg_Node := Node (Pragma_Element);
      Image_Start := Next_Identifier (Sloc (Arg_Node) + 5);
      Image_End   := Get_Word_End (P       => Image_Start,
                                   In_Word => In_Identifier'Access);

      return Get_Wide_Word (Image_Start, Image_End);
   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

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

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

   function Pragma_Argument_Associations
     (Pragma_Element : Asis.Pragma_Element)
      return           Asis.Association_List
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Pragma_Element);
      Arg_Node : Node_Id;
   begin

      Check_Validity
        (Pragma_Element, Package_Name & "Pragma_Argument_Associations");

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

      Arg_Node     := Node (Pragma_Element);

      return N_To_E_List_New
               (List             => Pragma_Argument_Associations (Arg_Node),
                Internal_Kind    => A_Pragma_Argument_Association,
                Starting_Element => Pragma_Element);

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

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

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

   function Debug_Image (Element : Asis.Element) return Wide_String is
      LT : String renames A4G.A_Types.ASIS_Line_Terminator;
   begin
      Check_Validity (Element, Package_Name & "Debug_Image");

      Debug_String (Element);

      return To_Wide_String (
         LT & "Element Debug_Image: " & LT &
         Debug_Buffer (1 .. Debug_Buffer_Len));
   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

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

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

   --  The following constants are used in the computation of hash values for
   --  Elements which are not from Standard:

   Line_Pos  : constant Natural := 6;
   Bit_Pos   : constant Natural := 1;
   Impl_Pos  : Natural renames Bit_Pos;
   Inh_Pos   : Natural renames Bit_Pos;
   Inst_Pos  : Natural renames Bit_Pos;
   Kind_Pos  : constant Natural := 8;
   Col_Pos   : constant Natural := 4;
   Name_Pos  : constant Natural := 9;
   Spec_Pos  : constant Natural := 2;

   Max_Names : constant Unsigned_32 := 2 ** Name_Pos;
   Max_Cols  : constant Unsigned_32 := 2 ** Col_Pos;
   Max_Kinds : constant Unsigned_32 := 2 ** Kind_Pos;
   Max_Lines : constant Unsigned_32 := 2 ** Line_Pos;
   Max_Specs : constant Unsigned_32 := 2 ** Spec_Pos;

   subtype Unit_Name_Hash_Range is Integer range 0 .. Integer (Max_Names) - 1;

   function Ada_Name_Hash is new GNAT.HTable.Hash (Unit_Name_Hash_Range);

   function Hash (Element : Asis.Element) return Asis.ASIS_Integer is
      N : Node_Id;
      S : Source_Ptr;

      L : Physical_Line_Number;
      C : Column_Number;

      Result : Unsigned_32 := 0;

      function Get_Ada_Name return String;
      --  Returns Ada name of the Element's enclosing unit appended with 'S' if
      --  the unit is a spec unit and with 'B' if it is a body unit. Returns
      --  null string for Nil_Element

      function Get_Ada_Name return String is
         CU           : Asis.Compilation_Unit;
         Spec_Or_Body : Character := 'B';
      begin

         if Is_Nil (Element) then
            return "";
         else
            CU := Enclosing_Compilation_Unit (Element);

            if Asis.Compilation_Units.Unit_Kind (CU) in
              A_Procedure .. A_Generic_Package_Renaming
            then
               Spec_Or_Body := 'S';
            end if;

            return To_String
              (Asis.Compilation_Units.Unit_Full_Name (CU)) & Spec_Or_Body;
         end if;

      end Get_Ada_Name;

      function To_ASIS_Integer is new
         Ada.Unchecked_Conversion
           (Source => Unsigned_32,
            Target => Asis.ASIS_Integer);

   begin
      Check_Validity (Element, Package_Name & "Hash");

      --  The hash value for Elements is first created as 32-bit unsigned
      --  integer and then converted into ASIS_Integer
      --
      --  Different approaches are used to create this 32-bit unsigned
      --  integer value for Elements which are and which are not from the
      --  predefined Standard package.
      --
      --  For Elements from Standard:
      --  -  If Element represents the An_Enumeration_Literal_Specification
      --     or A_Defining_Character_Literal from types Character or
      --     Standard_Character, the corresponding character code is used
      --     as hash value
      --  -  otherwise the Node Id of the Element is used as hash value;
      --
      --  For Elements which are not from Standard the 32 bits are first
      --  filled in by the following information:
      --
      --   0 ..  8 - the hash value computed from the Ada name of enclosing
      --             unit
      --         9 - Is_Part_Of_Implicit
      --  10 .. 13 - column in the source file computed from the Sloc of
      --             Element's Node reference
      --        14 - Is_Part_Of_Inherited
      --  15 .. 22 - Internal kind (converted to 'Pos value)
      --        23 - Is_Part_Of_Instance
      --  24 .. 29 - line in the source file computed from the Sloc of
      --             Element's Node reference
      --  30 .. 31 - Special_Case (converted to 'Pos value)
      --
      --  All the values are reduced modulo the corresponding values to fit
      --  the corresponding range. In case of extended generic code, line
      --  and column are computed as the sum of all the lines and columns
      --  in the chain of the source references corresponding to the
      --  instantiation
      --
      --  After creating such a value, it is rotated right by the number of
      --  the lines computed from Sloc of Element's Node reference

      if Encl_Unit_Id (Element) = Standard_Id then

         if Character_Code (Element) /= 0 then
            Result := Result + (Unsigned_32 (Character_Code (Element)));
         else
            N := Node_Value (Element);
            Result := Unsigned_32 (N);
         end if;

      elsif not Is_Nil (Element) then

         N := Node (Element);
         S := Sloc (N);

         L := Get_Physical_Line_Number (Sloc (N));
         C := Get_Column_Number        (Sloc (N));
         S := Instantiation_Location   (S);

         while S /= No_Location loop
            L := L + Get_Physical_Line_Number (Sloc (N));
            C := C + Get_Column_Number        (Sloc (N));
            S := Instantiation_Location       (S);
         end loop;

         --  Special Case:
         Result := Result +
            (Unsigned_32 (
               Special_Cases'Pos (Special_Case (Element))) mod Max_Specs);

         Result := Shift_Left (Result, Line_Pos);

         --  Line:
         Result := Result + (Unsigned_32 (L) mod Max_Lines);
         Result := Shift_Left (Result, Inst_Pos);

         --  Is_Part_Of_Instance
         if Is_From_Instance (Element) then
            Result := Result + 1;
         end if;
         Result := Shift_Left (Result, Kind_Pos);

         --  Internal kind:
         Result := Result +
           (Internal_Element_Kinds'Pos (Int_Kind (Element)) mod Max_Kinds);
         Result := Shift_Left (Result, Inh_Pos);

         --  Is_Part_Of_Inherited
         if Is_From_Inherited (Element) then
            Result := Result + 1;
         end if;
         Result := Shift_Left (Result, Col_Pos);

         --  Column:
         Result := Result + (Unsigned_32 (C) mod Max_Cols);
         Result := Shift_Left (Result, Impl_Pos);

         --  Is_Part_Of_Implicit:
         if Is_From_Implicit (Element) then
            Result := Result + 1;
         end if;
         Result := Shift_Left (Result, Name_Pos);

         --  Hash value computed from the name of enclosed unit:
         Result := Result + Unsigned_32 (Ada_Name_Hash (Get_Ada_Name));

         --  And now, rotating Result

         Result := Rotate_Right (Result, Natural (L));
      end if;

      return To_ASIS_Integer (Result);

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

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

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

------------------------------------------------------------------------------
--  Processing of the Ada extensions that most likely will be included in   --
--  Ada 2015 and that are already implemented in GNAT                       --
------------------------------------------------------------------------------

   --------------------------
   -- Expression_Path_Kind --
   --------------------------

   function Expression_Path_Kind
     (Path  : Asis.Element)
      return  Asis.Expression_Path_Kinds
   is
   begin
      Check_Validity (Path, Package_Name & "Expression_Path_Kind");

      return Expression_Path_Kind_From_Internal (Int_Kind (Path));
   end Expression_Path_Kind;

end Asis.Elements;