This file is indexed.

/usr/share/ada/adainclude/asis/asis-expressions.adb is in libasis2017-dev 2017-2.

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

The actual contents of the file can be viewed below.

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
------------------------------------------------------------------------------
--                                                                          --
--                 ASIS-for-GNAT IMPLEMENTATION COMPONENTS                  --
--                                                                          --
--                      A S I S . E X P R E S S I O N S                     --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
--            Copyright (C) 1995-2017, Free Software Foundation, Inc.       --
--                                                                          --
-- ASIS-for-GNAT is free software; you can redistribute it and/or modify it --
-- under terms of the  GNU General Public License  as published by the Free --
-- Software  Foundation;  either version 3,  or (at your option)  any later --
-- version.  ASIS-for-GNAT  is  distributed  in  the  hope  that it will be --
-- useful,  but  WITHOUT ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
-- You should have  received  a copy of the  GNU General Public License and --
-- a copy of the  GCC Runtime Library Exception  distributed with GNAT; see --
-- the files COPYING3 and COPYING.RUNTIME respectively.  If not, see        --
-- <http://www.gnu.org/licenses/>.                                          --
--                                                                          --
-- ASIS-for-GNAT was originally developed  by the ASIS-for-GNAT team at the --
-- Software  Engineering  Laboratory  of  the Swiss  Federal  Institute  of --
-- Technology (LGL-EPFL) in Lausanne,  Switzerland, in cooperation with the --
-- Scientific  Research  Computer  Center of  Moscow State University (SRCC --
-- MSU), Russia,  with funding partially provided  by grants from the Swiss --
-- National  Science  Foundation  and  the  Swiss  Academy  of  Engineering --
-- Sciences.  ASIS-for-GNAT is now maintained by  AdaCore                   --
-- (http://www.adacore.com).                                                --
--                                                                          --
------------------------------------------------------------------------------

pragma Ada_2012;

with Ada.Characters.Handling; use Ada.Characters.Handling;

with Asis.Declarations;       use Asis.Declarations;
with Asis.Definitions;        use Asis.Definitions;
with Asis.Errors;             use Asis.Errors;
with Asis.Exceptions;         use Asis.Exceptions;
with Asis.Extensions;         use Asis.Extensions;
with Asis.Elements;           use Asis.Elements;
with Asis.Iterator;           use Asis.Iterator;
with Asis.Limited_Views;      use Asis.Limited_Views;
with Asis.Statements;         use Asis.Statements;

with Asis.Set_Get;            use  Asis.Set_Get;

with A4G.A_Debug;             use A4G.A_Debug;
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.Asis_Tables;         use A4G.Asis_Tables;
with A4G.Contt.UT;            use A4G.Contt.UT;
with A4G.EE_Cache;            use A4G.EE_Cache;
with A4G.Encl_El;             use A4G.Encl_El;
with A4G.Expr_Sem;            use A4G.Expr_Sem;
with A4G.Mapping;             use A4G.Mapping;
with A4G.Norm;                use A4G.Norm;
with A4G.Vcheck;              use A4G.Vcheck;

with Atree;                   use Atree;
with Einfo;                   use Einfo;
with Namet;                   use Namet;
with Nlists;                  use Nlists;
with Output;                  use Output;
with Sinfo;                   use Sinfo;
with Snames;                  use Snames;
with Stand;                   use Stand;
with Uintp;                   use Uintp;

package body Asis.Expressions is

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

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

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

   ----------------------------------------------
   -- Corresponding_Expression_Type_Definition --
   ----------------------------------------------

   function Corresponding_Expression_Type_Definition
     (Expression : Asis.Expression)
      return       Asis.Element
   is
      Arg_Kind  : constant Internal_Element_Kinds := Int_Kind (Expression);
      Result    :          Asis.Expression   := Asis.Nil_Element;
      Res_Unit  :          Asis.Compilation_Unit;
      Expr_Type :          Entity_Id         := Empty;
      Backup    :          Entity_Id;
      Tmp       :          Asis.Element;
   begin
      Check_Validity
        (Expression, Package_Name &
         "Corresponding_Expression_Type_Definition");

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

      --  Filter out cases that for sure result in Nil_Element

      case Arg_Kind is
         when --  attribute references
              An_Adjacent_Attribute          |
              A_Base_Attribute               |
              A_Ceiling_Attribute            |
              A_Class_Attribute              |
              A_Compose_Attribute            |
              A_Copy_Sign_Attribute          |
              An_Exponent_Attribute          |
              A_Floor_Attribute              |
              A_Fraction_Attribute           |
              An_Image_Attribute             |
              An_Input_Attribute             |
              A_Leading_Part_Attribute       |
              A_Machine_Attribute            |
              A_Max_Attribute                |
              A_Min_Attribute                |
              A_Model_Attribute              |
              An_Output_Attribute            |
              A_Pos_Attribute                |
              A_Pred_Attribute               |
              A_Range_Attribute              |
              A_Read_Attribute               |
              A_Remainder_Attribute          |
              A_Round_Attribute              |
              A_Rounding_Attribute           |
              A_Scaling_Attribute            |
              A_Succ_Attribute               |
              A_Truncation_Attribute         |
              An_Unbiased_Rounding_Attribute |
              A_Val_Attribute                |
              A_Value_Attribute              |
              A_Wide_Image_Attribute         |
              A_Wide_Value_Attribute         |
              A_Write_Attribute              |

              A_Box_Expression               |
              Internal_Operator_Symbol_Kinds =>
            return Nil_Element;
         when An_Identifier =>
            Tmp := Enclosing_Element (Expression);

            if (Expression_Kind (Tmp) = An_Attribute_Reference
               and then
                Is_Equal (Expression, Attribute_Designator_Identifier (Tmp)))
              or else
                (Association_Kind (Tmp) = A_Pragma_Argument_Association
               and then
                 Is_Equal (Expression, Formal_Parameter (Tmp)))
              or else
                (Definition_Kind (Tmp) = An_Aspect_Specification
               and then
                 Is_Equal (Expression, Aspect_Mark (Tmp)))
            then
               return Nil_Element;
            end if;

         when others => null;
      end case;

      Result := Corresponding_Expression_Type (Expression);

      if not Is_Nil (Result) then
         return Type_Declaration_View (Result);
      end if;

      begin
         Result := Corresponding_Name_Definition (Expression);

         if Nkind (Node (Result)) in
              N_Identifier | --  statement identifier
              N_Label        --  label
         then
            --  This is a label
            return Nil_Element;
         end if;

         --   A special case of character literals - we already
         --  have a needed node in the Result structure

         if Defining_Name_Kind (Result) = A_Defining_Character_Literal
           and then
            (Is_Part_Of_Inherited (Result)
            or else
             Special_Case (Result) = Stand_Char_Literal)
         then
            Expr_Type := Parent (Node (Result));
            goto Done;
         end if;

         if not Is_Nil (Result) then
            if Defining_Name_Kind (Result) = A_Defining_Expanded_Name then
               Result := Defining_Selector (Result);
            end if;

            Expr_Type := R_Node (Result);

            if Ekind (Expr_Type) not in
                 E_Variable                 |
                 E_Component                |
                 E_Constant                 |
                 E_Discriminant             |
                 E_Loop_Parameter           |
                 E_In_Out_Parameter         |
                 E_In_Parameter             |
                 E_Out_Parameter            |
                 E_Generic_In_Out_Parameter |
                 E_Generic_In_Parameter     |
                 E_Named_Integer            |
                 E_Named_Real               |
                 E_Enumeration_Literal      |
                 E_Entry_Index_Parameter    |
                 E_Protected_Object
            then
               return Nil_Element;
            end if;

            --  Special case of an object that has anonymous access type

            Tmp := Enclosing_Element (Result);

            if Int_Kind (Tmp) in
                 A_Variable_Declaration          |
                 A_Constant_Declaration          |
                 A_Deferred_Constant_Declaration |
                 A_Single_Protected_Declaration  |
                 A_Single_Task_Declaration       |
                 A_Component_Declaration         |
                 A_Discriminant_Specification    |
                 A_Parameter_Specification       |
                 A_Return_Variable_Specification |
                 A_Return_Constant_Specification |
                 A_Formal_Object_Declaration     |
                 An_Object_Renaming_Declaration
            then
               Tmp := Object_Declaration_View (Tmp);

               if Definition_Kind (Tmp) = An_Access_Definition then
                  --  We just cannot do better
                  return Tmp;
               end if;
            end if;

            Expr_Type := Etype (Expr_Type);
         end if;

      exception
         when ASIS_Inappropriate_Element =>
            null;
      end;

      if No (Expr_Type) then
--         if Is_Static (Expression) then
--            Expr_Type := Node (Expression);
--         else
         Expr_Type := R_Node (Expression);
--         end if;
      end if;

      if Nkind (Parent (Expr_Type)) = N_Expanded_Name
        and then
         Expr_Type = Selector_Name (Parent (Expr_Type))
      then
         Expr_Type := Parent (Expr_Type);
      end if;

      if Nkind (Expr_Type) = N_Selected_Component then
         Expr_Type := Selector_Name (Expr_Type);
      end if;

      if Nkind (Expr_Type) = N_Attribute_Definition_Clause then
         Expr_Type := Sinfo.Expression (Expr_Type);
      end if;

      if Nkind (Expr_Type) = N_Type_Conversion
        and then
         not Comes_From_Source (Expr_Type)
      then
         Expr_Type := Sinfo.Expression (Expr_Type);
      end if;

      if Nkind (Expr_Type) in N_Has_Entity
        and then
         Present (Entity (Expr_Type))
        and then
         Ekind (Entity (Expr_Type)) not in
           E_Variable                 |
           E_Component                |
           E_Constant                 |
           E_Discriminant             |
           E_Loop_Parameter           |
           E_In_Out_Parameter         |
           E_In_Parameter             |
           E_Out_Parameter            |
           E_Generic_In_Out_Parameter |
           E_Generic_In_Parameter     |
           E_Named_Integer            |
           E_Named_Real               |
           E_Enumeration_Literal      |
           E_Entry_Index_Parameter    |
           E_Protected_Object         |
           E_Operator --  may be a call to the operator function
      then
         --  This filters out cases when we have a name that is not an
         --  expression, but Corresponding_Name_Definition returns Nil_Element
         --  for it (such as reference to predefined operator)
         return Nil_Element;
      end if;

      if not (Type_Def_in_Standard (Expr_Type)
--            or else
--              Part_Of_Pass_Generic_Actual (Expr_Type)
            or else
              Is_Root_Standard_Type (Etype (Expr_Type)))
      then
         Expr_Type := Etype (Expr_Type);
      end if;

      if No (Expr_Type)
        or else
         Expr_Type = Standard_Void_Type
        or else
         (Ekind (Expr_Type) = E_Anonymous_Access_Type
         and then
          Nkind (Associated_Node_For_Itype (Expr_Type)) /=
          N_Object_Declaration)
        or else
         Ekind (Expr_Type) = E_Subprogram_Type
      then
         return Nil_Element;
      end if;

      while not (Type_Def_in_Standard (Expr_Type)
               or else
                 Part_Of_Pass_Generic_Actual (Expr_Type)
               or else
                 Etype (Expr_Type) = Expr_Type
            or else
                 Is_Root_Standard_Type (Etype (Expr_Type)))
      loop
         if Ekind (Expr_Type) = E_Anonymous_Access_Type then
            --  There is nothing in the source to represent the type
            return Nil_Element;
         end if;

         Expr_Type := Etype (Expr_Type);
      end loop;

      if Is_Itype (Expr_Type) then
         Backup    := Expr_Type;
         Expr_Type := Associated_Node_For_Itype (Expr_Type);

         if Nkind (Expr_Type) in
            N_Function_Specification | N_Procedure_Specification
         then
            --  Two cases are possible: this can be either the returned type
            --  of a function (anonymous access type) or an access parameter

            if Nkind (Original_Node (Parent (Backup))) = N_Access_Definition
              and then
               Nkind (Parent (Parent (Backup))) = N_Function_Specification
              and then
               Parent (Backup) =
                  Result_Definition (Parent (Parent (Backup)))
            then
               Expr_Type := Parent (Parent (Parent (Backup)));
               goto Done;
            end if;

            --  See documentation of Associated_Node_For_Itype in Einfo:
            --    ...For an access parameter it is the enclosing subprogram
            --       declaration.

            Expr_Type := First (Parameter_Specifications (Expr_Type));

            while Present (Expr_Type) loop
               if Etype (Defining_Identifier (Expr_Type)) = Backup then
                  exit;
               end if;

               Expr_Type := Next (Expr_Type);
            end loop;
         end if;
      else
         Expr_Type := Parent (Expr_Type);
      end if;

      <<Done>>
      Res_Unit := Enclosing_Unit (Encl_Cont_Id (Expression), Expr_Type);

      Result := Node_To_Element_New
        (Node    => Expr_Type,
         In_Unit => Res_Unit);

      case Int_Kind (Result) is
         when A_Variable_Declaration          |
              A_Constant_Declaration          |
              A_Deferred_Constant_Declaration |
              A_Single_Protected_Declaration  |
              A_Single_Task_Declaration       |
              A_Component_Declaration         |
              A_Discriminant_Specification    |
              A_Parameter_Specification       |
              A_Return_Variable_Specification |
              A_Return_Constant_Specification |
              A_Formal_Object_Declaration     |
              An_Object_Renaming_Declaration  =>

            Result := Object_Declaration_View (Result);

            if Definition_Kind (Result) = A_Component_Definition then
               Result := Component_Subtype_Indication (Result);
            end if;
         when An_Ordinary_Type_Declaration    |
              A_Task_Type_Declaration         |
              A_Protected_Type_Declaration    |
              A_Private_Type_Declaration      |
              A_Private_Extension_Declaration |
              A_Subtype_Declaration           |
              A_Formal_Type_Declaration       =>
            Result := Type_Declaration_View (Result);
         when A_Function_Declaration             |
              A_Function_Body_Declaration        |
              A_Function_Body_Stub               |
              A_Function_Renaming_Declaration    |
              A_Generic_Function_Declaration     |
              A_Formal_Function_Declaration      |
              An_Expression_Function_Declaration =>
            Result := Result_Profile (Result);
         when An_Unconstrained_Array_Definition       |
              A_Constrained_Array_Definition          |
              A_Formal_Unconstrained_Array_Definition |
              A_Formal_Constrained_Array_Definition   =>

            Result := Array_Component_Definition (Result);
            Result := Component_Definition_View (Result);
         when others =>
            Not_Implemented_Yet
              (Diagnosis => Package_Name &
                            "Corresponding_Expression_Type_Definition");
      end case;

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

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

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

------------------------------------------------------------------------------
--                       GENERAL DOCUMENTATION ITEMS                        --
------------------------------------------------------------------------------

   -----------------------------
   -- A_Function_Call Problem --
   -----------------------------

--  As for now, the following consideration can be applied to explicit
--  elements only!!!

--  The following situations should be distinguished:
--
--  - the called function is a predefined operation (it can also be its
--    renaming);
--  - the called function is a user-defined function, but it has an operation
--    symbol as its designator;
--  - the called function is a "usual" user-defined function;
--  - the called function is an attribute;
--
--  - the call is prefix;
--  - the call is infix;
--
--  As a result, in an AST we can have the following situations;
--
--  - prefix call to a predefined   operator:
--
--      Node is rewritten, the Original Node is of N_Function_Call kind
--      and its Name field points to the node of N_Operator_Symbol kind,
--      or of N_Expanded_Name kind, but anyway
--      the rewritten node is of N_Op_Xxxx kind and Original Node
--      contains the corresponding substructures only for naming
--      associations (if any). The rewritten node contains both parameters,
--      but in the form of positional association.
--
--      Compiler-time optimization for static expressions: the rewritten
--      node may be of N_Identifier kind (when optimizing calls to
--      boolean functions), N_Integer/Real_Literal king, when optimizing
--      function returning numeric results,
--
--  - infix  call to a predefined   operator:
--
--      Usually the node is unchanged, it is of N_Op_Xxx kind.
--      But the node may be rewritten into N_Integer_Literal or
--      N_Real_Literl, if the compiler optimizes an expression like
--      1 + 2! It also may be rewritten into N_Identifier node,
--      if the compiler optimizes an expression like "not True"
--      or "False and True". Finally, it may be rewritten into
--      N_String_Literal, if the compiler optimizes an expression like
--      "The " & "Beatles"
--
--      The  situation when a predefined operator is (re)defined by a renaming
--      declaration should be considered as a special case. The call is
--      rewritten into the node of the same N_Op_Xxx kind.
--
--  - prefix call to a user-defined operator:
--
--      node is unchanged, it is of N_Function_Call kind, but its Name
--      field points to the node of N_Operator_Symbol kind, if the prefix
--      consists on the operator symbol only, or to the node of N_Expanded_Name
--      kind.
--
--  - infix  call to a user-defined operator:
--
--      node is unchanged, it is of N_Function_Call kind, but its Name
--      field points to the node of N_Identifier kind.
--
--      !! THIS MEANS THAT AN ELEMENT OF An_Operator_Symbol KIND MAY BE
--         BASED ON THE NODE OF N_Identifier kind!!!
--
--  - prefix call to a "usual" user-defined function:
--
--      node is unchanged, it is of N_Function_Call kind, its Name
--      field points to the node of N_Identifier or N_Expanded_Name kind
--      (as it should).
--
--  - call to an attribute-function (only the prefix form is possible)
--
--       node may or may nor be rewritten, but the Node field of the
--       corresponding element definitely is of N_Attribute_Reference
--       kind, and its Expressions field should be used for obtaining the
--       list of the function call parameters.
--
--  This is important for the functions:
--
--       Prefix
--       Is_Prefix_Call
--       Corresponding_Called_Function (?)
--       Function_Call_Parameters
--
--  having A_Function_Call as their appropriate kind, and also for
--  Name_Image (in the case of getting the image of an operator symbol)
--
--  THE MAPPING.2 DOCUMENT ALSO REQUIRES CORRECTIONS!!!
------------------------------------------------------------------------------

   function Corresponding_Expression_Type
     (Expression : Asis.Expression)
      return       Asis.Declaration
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
   begin
      --  this is the result of the first attempt to implement this function
      --  the code is rather dirty, non-effective and not well-organized

      Check_Validity
        (Expression, Package_Name & "Corresponding_Expression_Type");

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

      --  first, we filter out cases for which Nil_Element should be
      --  returned (may be, the check below is too trivial???)

      if not Is_True_Expression (Expression)
        or else
         Has_Anonymous_Type (Expression)
      then
         return Nil_Element;
      end if;

      --  we incapsulate the real processing in the function
      --  A4G.Expr_Sem.Expr_Type:

      return Expr_Type (Expression);

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

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

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

   ----------------
   -- Name_Image --
   ----------------

   function Name_Image (Expression : Asis.Expression) return Wide_String is
      Arg_Kind    : constant Internal_Element_Kinds := Int_Kind (Expression);
      Arg_Node    : Node_Id;
      Arg_R_Node  : Node_Id;

      Def_Name    : Asis.Element;

      Tmp_Node    : Node_Id;

      Image_Start : Source_Ptr;
      Image_End   : Source_Ptr;
   begin
      Check_Validity (Expression, "Asis_Declarations.Name_Image");

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

      --  Let's first handle special cases:
      --
      --  = of fake Numeric_Error renaming (see B712-0050)
      --  = of a named number rewritten as a literal node (see BB10-002)

      case Special_Case (Expression) is
         when Numeric_Error_Renaming =>
            return "Constraint_Error";
         when Rewritten_Named_Number =>
            --  The problem here is that the references to the named numbers
            --  are rewritten as numeric literals, and in expanded generics the
            --  original tree structure for such references is lost. So in an
            --  expended generic we have to get the image from the defining
            --  occurrence of the name
            if Is_Part_Of_Instance (Expression) then
               return Defining_Name_Image
                        (Corresponding_Name_Definition (Expression));
            end if;
         when Dummy_Class_Attribute_Designator =>
            return "Class";
         when Dummy_Base_Attribute_Designator =>
            return "Base";
         when others =>
            null;
      end case;

      Arg_Node   := Node (Expression);
      Arg_R_Node := R_Node (Expression);

      if not Comes_From_Source (Arg_Node)
        and then
         Arg_Kind not in Internal_Operator_Symbol_Kinds
        and then
         Arg_Kind /= An_Enumeration_Literal
        and then
         Special_Case (Expression) not in Dummy_Attribute_Prefixes
        and then
         Nkind (Arg_Node) /= N_Attribute_Reference
        and then
         Part_Of_Pass_Generic_Actual (Arg_Node)
      then
         Arg_Node   := Entity (Arg_Node);
         Arg_R_Node := Arg_Node;
      end if;

      case Arg_Kind is
         when A_Character_Literal =>

            return ''' &
                   Wide_Character'Val
                     (Integer (UI_To_CC
                       (Char_Literal_Value (Arg_Node)))) &
                    ''';

         when Internal_Operator_Symbol_Kinds =>
         --  three alternatives can be possible:
         --
         --  the Element is based on N_Op_Xxx node
         --               -> an infix call of a predefined operator
         --
         --  the Element is based on N_Operator_Symbol node
         --               -> definitely a prefix call
         --
         --  the Element is based on N_Identifier node
         --               -> an infix call of a user-defined operator
         --
         --  But in any case the result should be enclosed in quoters
            if Nkind (Arg_Node) = N_Operator_Symbol then
               return Wide_String_Image (Arg_Node);
            else
               --  N_Identifier and N_Op_Xxx nodes are processed
               --  in the same way
               return To_Wide_String (Operator_Image (Arg_Node));
            end if;
         when others =>
            --  really only   An_Identifier | An_Enumeration_Literal
            --  are possible,
            --  see the condition for defining the appropriate
            --  argument

            --  The special case exists for names which are type marks
            --  in the parameter and result profiles in the implicit inherited
            --  subprograms

            Tmp_Node := Node_Field_1 (Expression);

            if Nkind (Arg_Node) /= N_Attribute_Reference
              and then
               Nkind (Arg_Node) in N_Has_Entity
              and then
               Entity_Present (Arg_Node)
              and then
               Ekind (Entity (Arg_Node)) in Einfo.Type_Kind
              and then
               Is_From_Inherited (Expression)
              and then
               (Ekind (Tmp_Node) = E_Procedure or else
                Ekind (Tmp_Node) = E_Function)
            then
               Arg_Node := Get_Derived_Type
                 (Type_Entity     => Entity (Arg_Node),
                  Inherited_Subpr => Tmp_Node);
            end if;

            if Sloc (Arg_Node) <= Standard_Location
              or else
               (Special_Case (Expression) = Is_From_Imp_Neq_Declaration
               and then
                Nkind (Parent (Arg_Node)) = N_Function_Specification
               and then
                Arg_Node = Result_Definition (Parent (Arg_Node)))
               --  This condition describes the return type of implicit
               --  "/=". It is always Boolean
              or else
                Normalization_Case (Expression) =
                Is_Normalized_Defaulted_For_Box
               --  This condition defines the "implicit naming expression"
               --  that should be returned as a part of normalized generic
               --  association if the formal contains the box default, and
               --  the actual subprogram is defined at place of instantiation.
               --  We do not really care about the name, but the problem
               --  is that the Sloc field for the corresponding node is not
               --  set properly whereas Chars is.
            then
               return To_Wide_String (Normalized_Namet_String (Arg_Node));

            elsif Is_Rewrite_Substitution (Arg_R_Node)
              and then
                  Nkind (Arg_R_Node) = N_Identifier
              and then
                  Nkind (Arg_Node) = N_Identifier
              and then
                  Is_From_Instance (Arg_R_Node)
              and then
                  Ekind (Entity (Arg_R_Node)) = E_Package
              and then
                  Renamed_Entity (Entity (Arg_Node)) =
                     Entity (Arg_R_Node)
            then
               --  This condition corresponds to the case when we have a name
               --  that is a reference to the generic unit name inside expanded
               --  generic (see F627-001)

               Def_Name := Corresponding_Name_Definition (Expression);

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

               return Defining_Name_Image (Def_Name);
            else

               if Special_Case (Expression) = Dummy_Class_Attribute_Prefix then
                  Arg_Node := Etype (Entity (Arg_Node));

               elsif Special_Case (Expression) =
                       Dummy_Base_Attribute_Prefix
               then
                  Arg_Node := Associated_Node (Arg_Node);

                  while Is_Itype (Arg_Node) loop
                     Arg_Node := Associated_Node_For_Itype (Arg_Node);
                     Arg_Node := Defining_Identifier (Arg_Node);
                  end loop;

               elsif Nkind (Arg_Node) = N_Identifier
                   and then
                     Nkind (Parent (Arg_Node)) = N_Parameter_Association
                   and then
                     Present (Entity (Arg_Node))
                   and then
                     Is_From_Instance (Arg_Node)
                   and then
                     Chars (Arg_Node) /= Chars (Entity (Arg_Node))
               then
                  --  This corresponds to the following situation:
                  --  * we have primitive operation for a type:
                  --
                  --      type Rec is tagger record ... end record;
                  --
                  --      procedure Proc (X : Rec, I : Integer := 1);
                  --
                  --  * we have a generic unit parametrized by the formal
                  --    derived type:
                  --
                  --      generic
                  --         type T_F is new Rec with private;
                  --      package P_G is ... end P_G;
                  --
                  --  * we have a call to proc in the body of P_G:
                  --
                  --      Proc (X => Var);
                  --
                  --  * we have a type derived from Rec, it redefines Proc and
                  --    uses a different signature for it:
                  --
                  --      type N_Rec is new Rec with record ... end record;
                  --
                  --      procedure Proc (Y : N_Rec, K : Integer);
                  --
                  --  * type N_Rec is used as a generic actual in the
                  --    instantiation of P_G:
                  --
                  --      package P_I is new P_G (N_Rec);
                  --
                  --  * we are processing the call to Proc in the expanded
                  --    instantiation. In the tree we have N_Identifier node
                  --    with Chars pointing to 'X', whereas the called
                  --    subprogram is Proc for N_Rec, and it has the first
                  --    formal named 'Y', not 'X'.

                  Arg_Node := Entity (Arg_Node);
               end if;

               Image_Start := Sloc (Arg_Node);

               --  special processing is needed for some cases:
               if Get_Character (Image_Start) = ''' then
                  --  special processing for an "ordinary" attribute
                  --  designator
                  Image_Start := Next_Identifier (Image_Start);
               elsif Get_Character (Image_Start) = '.' then
                  --  This is the case for a subtype mark in expanded
                  --  subprogram spec in case if in the template we have a
                  --  formal type, and the actual type is represented by
                  --  an expanded name
                  Image_Start := Image_Start + 1;
               elsif Nkind (Arg_Node) = N_Attribute_Definition_Clause then
                  --  special processing for an attribute designator being
                  --  a child element of a pseudo attribute reference from
                  --  an attribute definition clause
                  Image_Start := Search_Rightmost_Symbol (Image_Start, ''');
                  Image_Start := Next_Identifier (Image_Start);

                  if Nkind (Sinfo.Name (Arg_Node)) = N_Attribute_Reference then
                     --  See FA30-016
                     Image_Start := Search_Rightmost_Symbol (Image_Start, ''');
                     Image_Start := Next_Identifier (Image_Start);
                  end if;

               end if;

               Image_End   := Get_Word_End (P       => Image_Start,
                                            In_Word => In_Identifier'Access);

               return Get_Wide_Word (Image_Start, Image_End);

            end if;

      end case;

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

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

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

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

      Image_Start : Source_Ptr;
      Image_End   : Source_Ptr;
   begin
      Check_Validity (Expression, Package_Name & "Value_Image");

      if not (Arg_Kind = An_Integer_Literal or else
              Arg_Kind = A_Real_Literal     or else
              Arg_Kind = A_String_Literal)
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Value_Image",
            Wrong_Kind => Arg_Kind);
      end if;

      Arg_Node := Node (Expression);

      if Sloc (Arg_Node) <= Standard_Location then

         case Arg_Kind is
            when An_Integer_Literal =>
               UI_Image (Intval (Arg_Node));
               return To_Wide_String (UI_Image_Buffer (1 .. UI_Image_Length));
            when A_Real_Literal =>
               return To_Wide_String (Ureal_Image (Arg_Node));
            when others =>
               raise Internal_Implementation_Error;
         end case;

      else
         case Arg_Kind is
            when   An_Integer_Literal
                 | A_Real_Literal      =>

               Image_Start := Sloc (Arg_Node);
               Image_End   := Get_Num_Literal_End (P => Image_Start);
               return Get_Wide_Word (Image_Start, Image_End);

            when A_String_Literal =>
               return Wide_String_Image (Arg_Node);
            when others =>
               raise Internal_Implementation_Error;
               --  this choice can never been reached,
               --  see the condition for defining the appropriate argument
         end case;
      end if;
   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

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

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

------------------------------------------------------------------------------
--  OPEN PROBLEMS:
--
--  1. A_Defining_Expanded_Name: is the recursive construction of the result
--     of the String type a really good thing here? The performance can be poor
--     but, from the other hand, this can happen not very often.
--
--  2. The Asis_Declarations.Defining_Name_Image function contains the
--     (almost) exact
--     copy of the part of the code of this function (except the part for
--     processing A_Defining_Expanded_Name). May be, it should be better
--     to separate it on low-level function.
-------------------------------------------------------------------------------
--  PARTIALLY IMPLEMENTED, case Implicitly => True is not implemented

   function References
     (Name            : Asis.Element;
      Within_Element  : Asis.Element;
      Implicitly      : Boolean := False)
      return            Asis.Name_List
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Name);
      Arg_Name : Asis.Element;

      Search_Reference_Control : Traverse_Control := Continue;
      Search_Reference_State   : No_State         := Not_Used;

      procedure Check_Reference
        (Element :        Asis.Element;
         Control : in out Traverse_Control;
         State   : in out No_State);
      --  Actual for Pre_Operation: checks if Element is a reference to
      --  Name, and if it is, puts it into Element table

      procedure Collect_References is new Traverse_Element
        (State_Information => No_State,
         Pre_Operation     => Check_Reference,
         Post_Operation    => No_Op);

      procedure Check_Reference
        (Element :        Asis.Element;
         Control : in out Traverse_Control;
         State   : in out No_State)
      is
      begin

         pragma Unreferenced (Control);
         pragma Unreferenced (State);

         if Is_Reference (Arg_Name, Element) then
            Asis_Element_Table.Append (Element);
         end if;

      end Check_Reference;

   begin
      Check_Validity (Name, Package_Name & "References");

      if not (Arg_Kind in Internal_Defining_Name_Kinds) then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "References",
            Wrong_Kind => Arg_Kind);
      elsif Implicitly then
         Not_Implemented_Yet
           (Diagnosis => Package_Name & "References (Implicitly => True)");
      end if;

      Arg_Name := Enclosing_Element (Name);

      if Int_Kind (Arg_Name) /= A_Defining_Expanded_Name then
         Arg_Name := Name;
      end if;

      Asis_Element_Table.Init;

      Collect_References
        (Element => Within_Element,
         Control => Search_Reference_Control,
         State   => Search_Reference_State);

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

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

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

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name    => Package_Name & "References",
            Ex            => Ex,
            Arg_Element   => Name,
            Arg_Element_2 => Within_Element,
            Bool_Par_ON   => Implicitly);
   end References;
------------------------------------------------------------------------------
--  PARTIALLY IMPLEMENTED, case Implicitly => True is not implemented

   function Is_Referenced
     (Name            : Asis.Element;
      Within_Element  : Asis.Element;
      Implicitly      : Boolean := False)
      return            Boolean
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Name);
      Arg_Name : Asis.Element;

      Result   : Boolean := False;

      Search_Reference_Control : Traverse_Control := Continue;
      Search_Reference_State   : No_State         := Not_Used;

      procedure Search_Reference
        (Element :        Asis.Element;
         Control : in out Traverse_Control;
         State   : in out No_State);
      --  Actual for Pre_Operation: looks for (the first) reference to Name.
      --  Sets Result to True if such a reference is found

      procedure Check_Reference is new Traverse_Element
        (State_Information => No_State,
         Pre_Operation     => Search_Reference,
         Post_Operation    => No_Op);

      procedure Search_Reference
        (Element :        Asis.Element;
         Control : in out Traverse_Control;
         State   : in out No_State)
      is
      begin

         pragma Unreferenced (State);

         if Is_Reference (Arg_Name, Element) then
            Result  := True;
            Control := Terminate_Immediately;
         end if;

      end Search_Reference;

   begin --  Is_Referenced
      Check_Validity (Name, Package_Name & "Is_Referenced");

      if not (Arg_Kind in Internal_Defining_Name_Kinds) then
         return False;

      elsif Implicitly then
         Not_Implemented_Yet
           (Diagnosis => Package_Name & "Is_Referenced (Implicitly => True)");
      end if;

      Arg_Name := Enclosing_Element (Name);

      if Int_Kind (Arg_Name) /= A_Defining_Expanded_Name then
         Arg_Name := Name;
      end if;

      Check_Reference
        (Element => Within_Element,
         Control => Search_Reference_Control,
         State   => Search_Reference_State);

      return Result;

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

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

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name    => Package_Name & "Is_Referenced",
            Ex            => Ex,
            Arg_Element   => Name,
            Arg_Element_2 => Within_Element,
            Bool_Par_ON   => Implicitly);
   end Is_Referenced;

   -----------------------------------
   -- Corresponding_Name_Definition --
   -----------------------------------

   function Corresponding_Name_Definition
     (Reference : Asis.Expression)
      return      Asis.Defining_Name
   is
      Arg_Kind    : constant Internal_Element_Kinds := Int_Kind (Reference);
      Result      : Element;
      Parent_Node : Node_Id;
   begin
      Check_Validity
        (Reference, Package_Name & "Corresponding_Name_Definition");

      if not Is_Uniquely_Defined (Reference) then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Corresponding_Name_Definition",
            Wrong_Kind => Arg_Kind);
      end if;

      if Is_From_Limited_View (Reference) then
         return Nil_Element;
      end if;

      if Arg_Kind = An_Identifier or else
         Arg_Kind = An_Enumeration_Literal or else
         Arg_Kind in Internal_Operator_Symbol_Kinds
      then

         --  A special case of fake Numeric_Error renaming is handled
         --  separately (see B712-005)

         if Special_Case (Reference) = Numeric_Error_Renaming then

            Result :=
              Node_To_Element_New
                (Node             => Standard_Constraint_Error,
                 Starting_Element => Reference,
                 Internal_Kind    => A_Defining_Identifier,
                 Spec_Case        => Explicit_From_Standard);

         elsif Normalization_Case (Reference) =
                 Is_Normalized_Defaulted_Null_Procedure
         then
            Result := Reference;
            Set_Int_Kind           (Result, A_Defining_Identifier);
            Set_Normalization_Case (Result, Is_Not_Normalized);
         else

            if Is_Predefined_Operator (Reference) then
               Result := Nil_Element;
            else
               --  First, process a special case when  Reference is a label
               --  from goto statement that is rewritten into an infinite loop
               --  in the tree. The node of such Reference does not have the
               --  Entity field set

               Parent_Node := Parent (R_Node (Reference));

               if Nkind (Parent_Node) = N_Loop_Statement
                 and then
                  Is_Rewrite_Substitution (Parent_Node)
                 and then
                  Nkind (Original_Node (Parent_Node)) = N_Goto_Statement
               then
                  Result := Enclosing_Element (Reference);
                  Result := Corresponding_Destination_Statement (Result);
                  Result := Label_Names (Result) (1);
               else
                  Result := Identifier_Name_Definition (Reference);
               end if;
            end if;

            if Is_Nil (Result) then
               null;
            elsif Special_Case (Reference) = Rewritten_Named_Number then
               Correct_Result (Result, Reference);
            elsif Defining_Name_Kind (Result) /= A_Defining_Expanded_Name
               and then
                  Is_Implicit_Formal_Par (Result)
            then
               Correct_Impl_Form_Par (Result, Reference);
            end if;

         end if;

      else

         Result := Character_Literal_Name_Definition (Reference);

      end if;

      return Result;
   exception
      when ASIS_Failed =>

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

         raise;
   end Corresponding_Name_Definition;

   ----------------------------------------
   -- Corresponding_Name_Definition_List --
   ----------------------------------------

   function Corresponding_Name_Definition_List
     (Reference : Asis.Element)
      return      Asis.Defining_Name_List
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Reference);
   begin
      Check_Validity (Reference, Package_Name & "Name_Definition_List");

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

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

      Asis_Element_Table.Init;

      if Needs_List (Reference) then
         Collect_Overloaded_Entities (Reference);
      else
         Asis_Element_Table.Append (Corresponding_Name_Definition (Reference));
      end if;

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

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

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

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

------------------------------------------------------------------------------
   function Corresponding_Name_Declaration
     (Reference : Asis.Expression)
      return      Asis.Declaration
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Reference);
      Result   : Asis.Element;
   begin
      Check_Validity
        (Reference, Package_Name & "Corresponding_Name_Declaration");

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

      if Is_From_Limited_View (Reference) then
         return Nil_Element;
      end if;

      Result := Corresponding_Name_Definition (Reference);

      if not Is_Nil (Result) then
         Result := Enclosing_Element (Result);
      end if;

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

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

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

   function Prefix (Expression : Asis.Expression) return Asis.Expression is
      Arg_Kind      : constant Internal_Element_Kinds := Int_Kind (Expression);
      Arg_Node      : Node_Id;
      Returned_Kind : Internal_Element_Kinds := Not_An_Element;
      Res_Spec_Case : Special_Cases          := Not_A_Special_Case;
      Result_Node   : Node_Id;

      Result : Asis.Element := Nil_Element;
   begin

      Check_Validity (Expression, Package_Name & "Prefix");

      if not (Arg_Kind =  An_Explicit_Dereference            or else
               Arg_Kind in Internal_Attribute_Reference_Kinds or else
               Arg_Kind =  A_Function_Call                    or else
               Arg_Kind =  An_Indexed_Component               or else
               Arg_Kind =  A_Selected_Component               or else
               Arg_Kind =  A_Slice)
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Prefix",
            Wrong_Kind => Arg_Kind);
      end if;

      Arg_Node := Node (Expression);

      if ((Nkind (Arg_Node) = N_Identifier or else
           Nkind (Arg_Node) = N_Expanded_Name)
          and then
          --  Special case: F.A, where either F or A is a function call
          Nkind (R_Node (Expression)) = N_Function_Call)
        or else
          (Nkind (Arg_Node) = N_Function_Call
          and then
           Nkind (R_Node (Expression)) = N_Expanded_Name
          and then
           Comes_From_Source (R_Node (Expression))
          )
      then
         Arg_Node := R_Node (Expression);
      end if;

      --  We might implement this as shown below (the name following
      --  the arrow (->) is the name of the Sinfo-defined tree access
      --  function which should be used to obtain the result node,
      --  the infix form of A_Function_Call should be treated as a special
      --  case:

--    case Arg_Kind is
--
--    when An_Explicit_Dereference =>
--       -- N_Explicit_Dereference -> Prefix
--
--    when Internal_Attribute_Reference_Kinds =>
--       -- N_Attribute_Reference -> Prefix
--
--    when A_Function_Call         =>
--       -- N_Function_Call -- prefix call -> Name
--       -- N_Op_*          -- infix call  -> the result should be based
--       --                                    on the same node
--       -- N_Attribute_Reference          -> the result should be based
--                                            on the same node
--
--    when An_Indexed_Component    =>
--       -- N_Indexed_Component -> Prefix
--
--    when A_Selected_Component    =>
--       -- N_Selected_Component -> Prefix
--       -- N_Expanded_Name      -> Prefix
--
--    when A_Slice                 =>
--       -- N_Slice ->  Prefix
--
--    when others =>
--
--       return Nil_Element; -- to make the code formally correct,
--                           -- see the condition for determining the
--    end case;              -- appropriate element

      --  but it is more convenient to use the Node_Kind-driven
      --  case statement for implementing just the same processing:

      Result_Node := Arg_Node;
      --  for N_Op_* cases only; it may seem as being a bit tricky, but another
      --  variants are too long ;-)

      if Debug_Flag_1 then
         Write_Node (Arg_Node, "Prefix: Arg_Node -> ");
         Write_Eol;
      end if;

      case Nkind (Arg_Node) is

         when   N_Explicit_Dereference   -- Prefix node access function
              | N_Slice                  -- should be used for tree traversing
              | N_Indexed_Component      -- traversing
              | N_Selected_Component
              | N_Expanded_Name       =>

            --  !!The Node of N_Identifier kind cannot be processed by the
            --  !!general Node_To_Element function (involving the auto
            --  !!determination of the Element kind), because the subcomponents
            --  !!of the prefix of a defining_unit_name do not have the Entity
            --  !!attribute set.

            Result_Node := Prefix (Arg_Node);

            if Nkind (Result_Node) = N_Identifier and then
               not Is_Rewrite_Substitution (Result_Node)
            then

               Result :=
                 Node_To_Element_New (
                    Node                     => Result_Node,
                    Starting_Element         => Expression,
                    Internal_Kind            => An_Identifier,
                    Considering_Parent_Count => False);

            else

               Result :=
                 Node_To_Element_New (
                    Node                     => Result_Node,
                    Starting_Element         => Expression,
                    Considering_Parent_Count => False);
            end if;

         when N_Attribute_Definition_Clause =>
            --  special processing for pseudo-attribute being the child
            --  element of An_Attribute_Definition_Clause Element
            Result_Node := Sinfo.Name (Arg_Node);

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

         when N_Attribute_Reference =>
         --  two cases should be distinguished: when the function argument is
         --  of A_Function_Call kind and when it is in
         --  Internal_Attribute_Reference_Kinds

            if Debug_Flag_1 then
               Write_Str
                  (Package_Name & "Prefix: "
                 & "processing N_Attribute_Reference Node...");
               Write_Eol;
               Write_Node (Arg_Node, "Arg Node -> ");
               Write_Eol;
            end if;

            if Arg_Kind =  A_Function_Call then
               --  the result should be based on the same node, so the
               --  Result_Node setting should not be changed, but the kind
               --  of the result should be determined by hand

               Returned_Kind := Subprogram_Attribute_Kind (Result_Node);

               Result :=
                 Node_To_Element_New (
                    Node                     => R_Node (Expression),
                    Starting_Element         => Expression,
                    Internal_Kind            => Returned_Kind,
                    Considering_Parent_Count => False);

            else
               --  just the same processing as for the previous
               --  case alternative:
               Result_Node := Prefix (Arg_Node);

               if Debug_Flag_1 then
                  Write_Str (Package_Name & "Prefix: "
                     & "processing N_Attribute_Reference Prefix Node...");
                  Write_Eol;
                  Write_Node (Result_Node, "Result Node -> ");
                  Write_Eol;
               end if;

               Result :=
                 Node_To_Element_New (
                    Node                     => Result_Node,
                    Starting_Element         => Expression,
                    Considering_Parent_Count => False);

            end if;

      when   N_Function_Call |
             N_Procedure_Call_Statement =>

         --  N_Procedure_Call_Statement corresponds to the argument of pragma
         --  Debug which is treated as A_Function_Call
         --  Name node access function should be used for tree traversing

         if Debug_Flag_1 then
            Write_Str ("Prefix: processing N_Function_Call Node:");
            Write_Eol;
            Write_Str ("Node is rewritten more than once - ");
            Write_Eol;
            Write_Str (Boolean'Image (Is_Rewrite_Substitution (Arg_Node)));
            Write_Eol;
         end if;

         --  See comments under "A_Function_Call Problem" headline in the
         --  beginning of the package body - we shall distinguish the case
         --  of the infix call of the user - defined operator. The Name
         --  function gives the result of N_Identifier kind, but really it
         --  corresponds to the An_Operator_Symbol Element!

         Result_Node := Sinfo.Name (Arg_Node);

         if Is_Rewrite_Substitution (Result_Node)
           and then
            Nkind (Result_Node) = N_Explicit_Dereference
           and then
            Nkind (Prefix (Result_Node)) = N_Function_Call
         then
            --  Needed to process cases like F (1), where F - parameterless
            --  function that returns access-to-subprogram result.
            Result_Node := Prefix (Result_Node);
         end if;

         if Debug_Flag_1 then
            Write_Node (Result_Node, "Prefix: Result_Node -> ");
            Write_Eol;
         end if;

         if Nkind (Result_Node) = N_Identifier and then
            Chars (Result_Node) in Any_Operator_Name
         then
            --  really we have a infix call of a user-defined operator!
            Returned_Kind :=
               A4G.Mapping.N_Operator_Symbol_Mapping (Result_Node);
         else
            Result :=
              Node_To_Element_New (
                 Node                     => Result_Node,
                 Starting_Element         => Expression,
                 Considering_Parent_Count => False);
         end if;

--    when N_Op_* => --  N_Op_* cases corresponding to the infix function
                     --  call, the result should be based on the same node;
                     --  only the internal kind of the returned element is
                     --  determined in the case statement; the return
                     --  statement for N_Op_* alternatives is located
                     --  outside the case statement
      when N_Op_And       =>  -- "and"
         Returned_Kind := An_And_Operator;
      when N_Op_Or        =>  -- "or"
         Returned_Kind := An_Or_Operator;
      when N_Op_Xor       =>  -- "xor"
         Returned_Kind := An_Xor_Operator;
      when N_Op_Eq        =>  -- "="
         Returned_Kind := An_Equal_Operator;
      when N_Op_Ne        =>  -- "/="
         Returned_Kind := A_Not_Equal_Operator;
      when N_Op_Lt        =>  -- "<"
         Returned_Kind := A_Less_Than_Operator;
      when N_Op_Le        =>  -- "<="
         Returned_Kind := A_Less_Than_Or_Equal_Operator;
      when N_Op_Gt        =>  -- ">"
         Returned_Kind := A_Greater_Than_Operator;
      when N_Op_Ge        =>  -- ">="
         Returned_Kind := A_Greater_Than_Or_Equal_Operator;
      when N_Op_Add       =>  -- "+"  (binary)
         Returned_Kind := A_Plus_Operator;
      when N_Op_Subtract  =>  -- "-"  (binary)
         Returned_Kind := A_Minus_Operator;
      when N_Op_Concat    =>  -- "&"
         Returned_Kind := A_Concatenate_Operator;
      when N_Op_Plus      =>  -- "+"  (unary)
         Returned_Kind := A_Unary_Plus_Operator;
      when N_Op_Minus     =>  -- "-"  (unary)
         Returned_Kind := A_Unary_Minus_Operator;
      when N_Op_Multiply  =>  -- "*"
         Returned_Kind := A_Multiply_Operator;
      when N_Op_Divide    =>  -- "/"
         Returned_Kind := A_Divide_Operator;
      when N_Op_Mod       =>  -- "mod"
         Returned_Kind := A_Mod_Operator;
      when N_Op_Rem       =>  -- "rem"
         Returned_Kind := A_Rem_Operator;
      when N_Op_Expon     =>  -- "**"
         Returned_Kind := An_Exponentiate_Operator;
      when N_Op_Abs       =>  -- "abs"
         Returned_Kind := An_Abs_Operator;
      when N_Op_Not       =>  -- "not"
         Returned_Kind := A_Not_Operator;

      when N_Identifier =>
         --  See F410-011. The argument is the artificial 'Class attribute
         --  reference in the instance that corresponds to the actual
         --  class-wide type.

         if Is_Part_Of_Instance (Expression)
           and then
            (Represents_Class_Wide_Type_In_Instance (Arg_Node)
            or else
             Represents_Base_Type_In_Instance (Arg_Node))
         then
            Result_Node   := Arg_Node;
            Returned_Kind := An_Identifier;

            if Represents_Class_Wide_Type_In_Instance (Arg_Node) then
               Res_Spec_Case := Dummy_Class_Attribute_Prefix;
            else
               Res_Spec_Case := Dummy_Base_Attribute_Prefix;
            end if;

         elsif (Nkind (Arg_Node) = N_Identifier
               and then
                not Comes_From_Source (Arg_Node)
               and then
                Ekind (Entity (Arg_Node)) = E_Class_Wide_Type) --  See FA13-008
             or else
               Is_Aspect_Mark (Expression)
         then
            Result_Node   := Arg_Node;
            Returned_Kind := An_Identifier;
         else
            pragma Assert (False);
            null;
         end if;

      when N_Designator =>
         Result_Node := Sinfo.Name (Arg_Node);
      when others =>
         pragma Assert (False);
      end case;

      --  forming the result for N_Op_* cases and for the infix call of a
      --  user-defined operator:

      --  ??? !!! This is the ad hoc patch for Enclosing_Element needs:
      --  we should keep rewritten node for function calls rewritten as
      --  results of compiler-time optimisations

      if Is_Nil (Result) then
         if Returned_Kind in Internal_Operator_Symbol_Kinds
          and then
            Nkind (Node (Expression)) /= N_Function_Call
          and then
            Is_Rewrite_Substitution (R_Node (Expression))
         then
            Result_Node := R_Node (Expression);
         end if;

         Result := Node_To_Element_New (
                      Node                     => Result_Node,
                      Starting_Element         => Expression,
                      Internal_Kind            => Returned_Kind,
                      Spec_Case                => Res_Spec_Case,
                      Considering_Parent_Count => False);
      end if;

      Store_Enclosing_Element (Expression, Result);
      return Result;
   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

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

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

   function Index_Expressions
     (Expression : Asis.Expression)
      return       Asis.Expression_List
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
      Arg_Node : Node_Id;
   begin

      Check_Validity (Expression, Package_Name & "Index_Expressions");

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

      Arg_Node := Node (Expression);

      declare
         Result : constant Asis.Element_List :=
           N_To_E_List_New
             (List             => Sinfo.Expressions (Arg_Node),
              Starting_Element => Expression);
      begin
         Store_Enclosing_Element (Expression, Result);

         return Result;
      end;

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

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

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

   function Slice_Range
     (Expression : Asis.Expression)
      return       Asis.Discrete_Range
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
      Arg_Node : Node_Id;
      Result   : Asis.Element;
   begin

      Check_Validity (Expression, Package_Name & "Slice_Range");

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

      Arg_Node := Node (Expression);

      Result := Node_To_Element_New
                  (Node             => Sinfo.Discrete_Range (Arg_Node),
                   Starting_Element => Expression);

      Store_Enclosing_Element (Expression, Result);

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

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

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

   -----------------------------------------------
   -- local functions for the Selector function --
   -----------------------------------------------

   function Last_Selector (Node : Node_Id) return Boolean;
   --  Node should be of N_Identifier kind, obtained as a Selector_Name
   --  form N_Selected_Component or N_Expanded name node;
   --  a caller is responsible for this. This function checks if
   --  Node is the last selector in the corresponding selected component
   --  or expanded name. If the node is not a part of expanded name, True is
   --  returned.

   function Is_Enumeration_Literal (Node : Node_Id) return Boolean;
   --  Node should be of N_Identifier kind, obtained as a Selector_Name
   --  form N_Selected_Component or N_Expanded name node;
   --  moreover, this is the last selector in the enclosing construct
   --  a caller is responsible for this. This function checks if
   --  its argument should be classified as An_Enumeration_Literal
   --  by checking the Entity fields of the outermost "enclosing"
   --  node of N_Expanded_Name kind

   function Last_Selector (Node : Node_Id) return Boolean is
      Result : Boolean := True;
   begin
      if Nkind (Parent (Node)) in N_Expanded_Name | N_Selected_Component then
         if Nkind (Parent (Parent (Node))) in
              N_Expanded_Name | N_Selected_Component
         then
            Result := Node = Selector_Name (Parent (Parent (Node)));
         end if;
      end if;

      return Result;
   end Last_Selector;

   function Is_Enumeration_Literal (Node : Node_Id) return Boolean is
      Entity_Node : Node_Id := Empty;
   begin
      Entity_Node := Entity (Node);

      if No (Entity_Node) then

         Entity_Node := Original_Node (Parent (Node));

         if Nkind (Entity_Node) = N_Function_Call then
            --  this may be the case for an expanded name which is a reference
            --  to an overloaded enumeration literal
            Entity_Node := Sinfo.Name (Entity_Node);
         end if;

         if Nkind (Entity_Node) in N_Has_Entity then
            Entity_Node := Entity (Entity_Node);
         end if;

      end if;

      if Nkind (Entity_Node) in N_Entity and then
         Ekind (Entity_Node) = E_Enumeration_Literal
      then
         return True;
      else
         return False;
      end if;

   end Is_Enumeration_Literal;

   function Selector
     (Expression : Asis.Expression)
      return       Asis.Expression
   is
      Arg_Kind    : constant Internal_Element_Kinds := Int_Kind (Expression);
      Arg_Node    : Node_Id;
      Result_Node : Node_Id;
      Result_Kind : Internal_Element_Kinds;

      Result      : Asis.Element;
   begin

      Check_Validity (Expression, Package_Name & "Selector");

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

      Arg_Node := Node (Expression);

      if Nkind (Arg_Node) = N_Function_Call
          and then
           Nkind (R_Node (Expression)) = N_Expanded_Name
          and then
           Comes_From_Source (R_Node (Expression))
      then
         Arg_Node := R_Node (Expression);
      end if;

      if Nkind (Arg_Node) = N_Designator then
         Result_Node := Sinfo.Identifier (Arg_Node);
      else
         Result_Node := Selector_Name (Arg_Node);
      end if;

      if not (Nkind (Result_Node) = N_Identifier) then

         return Node_To_Element_New (Node             => Result_Node,
                                     Starting_Element => Expression);
      end if;

      if Last_Selector (Result_Node) and then
         Is_Enumeration_Literal (Result_Node)
      then
         Result_Kind := An_Enumeration_Literal;
      else
         Result_Kind := An_Identifier;
      end if;

      Result := Node_To_Element_New (Node             => Result_Node,
                                     Internal_Kind    => Result_Kind,
                                     Starting_Element => Expression);

      Store_Enclosing_Element (Expression, Result);

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

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

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

   function Attribute_Designator_Identifier
     (Expression : Asis.Expression)
      return       Asis.Expression
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
      Result   : Asis.Element                    := Nil_Element;

      P : constant Node_Id := Parent (R_Node (Expression));
   begin
      Check_Validity
        (Expression, Package_Name & "Attribute_Designator_Identifier");

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

      --  Attribute designator is based on the same node as the argument of
      --  the function, this is a special case of identifier handling!!!

      Result := Node_To_Element_New
        (Starting_Element         => Expression,
         Node                     => R_Node (Expression),
         Internal_Kind            => An_Identifier);

      if Represents_Class_Wide_Type_In_Instance (Node (Expression))
         --  See F410-011

        --  If Expression represents something like "Pre'Class" in "with
        --  Pre'Class => ...", then R_Node will be an N_Identifier (not an
        --  N_Attribute_Reference), and Class_Present will be True on the
        --  parent node.

        or else
          (Nkind (P) = N_Aspect_Specification and then
           Sinfo.Identifier (P) = R_Node (Expression) and then
           Class_Present (P))
      then

         Set_Special_Case (Result, Dummy_Class_Attribute_Designator);
      elsif Represents_Base_Type_In_Instance ((Node (Expression))) then
         Set_Special_Case (Result, Dummy_Base_Attribute_Designator);
      end if;

      Store_Enclosing_Element (Expression, Result);

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

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

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

   function Attribute_Designator_Expressions
     (Expression : Asis.Expression)
      return       Asis.Expression_List
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
      Arg_Node : Node_Id;
   begin

      Check_Validity
        (Expression, Package_Name & "Attribute_Designator_Expressions");

      if not (Arg_Kind = A_First_Attribute                   or else
              Arg_Kind = A_Last_Attribute                    or else
              Arg_Kind = A_Length_Attribute                  or else
              Arg_Kind = A_Range_Attribute                   or else
              Arg_Kind = An_Implementation_Defined_Attribute or else
              Arg_Kind = An_Unknown_Attribute)
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Attribute_Designator_Expressions",
            Wrong_Kind => Arg_Kind);
      end if;

      Arg_Node := Node (Expression);

      if Nkind (Arg_Node) = N_Attribute_Definition_Clause or else
         Is_GNAT_Attribute_Routine (Arg_Node)
      then
         return Nil_Element_List;
         --  just in case - for an implementation-defined attribute in an
         --  attribute definition clause
      end if;

      if Debug_Flag_1 then
         Write_Str ("Attribute_Designator_Expressions: Arg_Node:");
         Write_Eol;
         Write_Node (Arg_Node, "->");
         Write_Eol;
      end if;

      declare
         Result : constant Asis.Element_List :=
           N_To_E_List_New
             (List             => Sinfo.Expressions (Arg_Node),
              Starting_Element => Expression);
      begin
         if not Is_Nil (Result) then
            Store_Enclosing_Element (Expression, Result);
         end if;

         return Result;
      end;

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

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

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

      Returned_List_Length   : ASIS_Integer;
      Positional_List_Length : Int;
      Named_List_Length      : Int;
   begin

      Check_Validity
        (Expression, Package_Name & "Record_Component_Associations");

      if not (Arg_Kind =  A_Record_Aggregate or else
              Arg_Kind =  An_Extension_Aggregate)
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Record_Component_Associations",
            Wrong_Kind => Arg_Kind);
      end if;

      Arg_Node := Node (Expression);

      if Null_Record_Present (Arg_Node) then
         return Nil_Element_List;
      end if;

      if Normalized then
         return Normalized_Record_Component_Associations (Expression);
      end if;

      --  computing the returned list length:

      if Present (Sinfo.Expressions (Arg_Node)) then
         Positional_List_Length := List_Length (Sinfo.Expressions (Arg_Node));
      else
         Positional_List_Length := 0;
      end if;

      if Present (Component_Associations (Arg_Node)) then
         Named_List_Length := List_Length (Component_Associations (Arg_Node));
      else
         Named_List_Length := 0;
      end if;

      Returned_List_Length :=
         ASIS_Integer (Positional_List_Length + Named_List_Length);
      --  Returned_List_Length cannot be equal to 0 here!

      declare -- for proper exception handling
         Returned_List : Asis.Association_List (1 .. Returned_List_Length);
      begin
         --  obtaining the association list:

         if Debug_Flag_1 then
            Write_Str ("obtaining the association list");
            Write_Eol;
            Write_Str ("List length is ");
            Write_Int (Int (Returned_List_Length));
            Write_Eol;
         end if;

         Returned_List :=
            N_To_E_List_New
              (List             => Sinfo.Expressions (Arg_Node),
               Internal_Kind    => A_Record_Component_Association,
               Starting_Element => Expression)
          &
            N_To_E_List_New
              (List             => Component_Associations (Arg_Node),
               Internal_Kind    => A_Record_Component_Association,
               Starting_Element => Expression);

         Store_Enclosing_Element (Expression, Returned_List);

         return Returned_List;

      end;

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

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

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

   function Extension_Aggregate_Expression
     (Expression : Asis.Expression)
      return       Asis.Expression
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
      Arg_Node : Node_Id;
      Result   : Asis.Element;
   begin

      Check_Validity
        (Expression, Package_Name & "Extension_Aggregate_Expression");

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

      Arg_Node := Node (Expression);

      Result := Node_To_Element_New
                  (Node             => Ancestor_Part (Arg_Node),
                   Starting_Element => Expression);

      Store_Enclosing_Element (Expression, Result);

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

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

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

   function Array_Component_Associations
     (Expression : Asis.Expression)
      return       Asis.Association_List
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);

      Arg_Node           : Node_Id;
      Named_Associations : List_Id;
      Pos_Associations   : List_Id;
   begin

      Check_Validity
        (Expression, Package_Name & "Array_Component_Associations");

      if not (Arg_Kind = A_Positional_Array_Aggregate or else
              Arg_Kind = A_Named_Array_Aggregate)
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Array_Component_Associations",
            Wrong_Kind => Arg_Kind);
      end if;

      Arg_Node           := Node (Expression);
      Named_Associations := Component_Associations (Arg_Node);
      Pos_Associations   := Sinfo.Expressions (Arg_Node);

      declare
         Result : constant Asis.Element_List :=
           (if Arg_Kind = A_Named_Array_Aggregate then
               N_To_E_List_New
                 (List             => Named_Associations,
                  Internal_Kind    => An_Array_Component_Association,
                  Starting_Element => Expression)
            elsif No (Named_Associations) then
            --  that is, no "others" choice in a positional array aggregate
               N_To_E_List_New
                 (List             => Pos_Associations,
                  Internal_Kind    => An_Array_Component_Association,
                  Starting_Element => Expression)
            else
            --  a positional array aggregate with "others"
                N_To_E_List_New
                  (List          => Pos_Associations,
                   Internal_Kind => An_Array_Component_Association,
                   Starting_Element => Expression)
              &
                Node_To_Element_New
                  (Node             => First (Named_Associations),
                   Internal_Kind    => An_Array_Component_Association,
                   Starting_Element => Expression));
      begin
         Store_Enclosing_Element (Expression, Result);

         return Result;
      end;

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

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

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

   function Array_Component_Choices
     (Association : Asis.Association)
      return        Asis.Expression_List
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Association);
      Arg_Node : Node_Id;
   begin

      Check_Validity (Association, Package_Name & "Array_Component_Choices");

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

      Arg_Node := Node (Association);

      if Nkind (Arg_Node) = N_Component_Association  then
         --  named association
         declare
            Result : constant Asis.Element_List :=
              Discrete_Choice_Node_To_Element_List
                (Choice_List      => Choices (Arg_Node),
                 Starting_Element => Association);
         begin
            Store_Enclosing_Element (Association, Result);

            return Result;
         end;
      else
         --  positional association
         return Nil_Element_List;
      end if;
   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

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

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Array_Component_Choices",
            Ex          => Ex,
            Arg_Element => Association);
   end Array_Component_Choices;
-----------------------------------------------------------------------------
   function Record_Component_Choices
     (Association : Asis.Association)
      return        Asis.Expression_List
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Association);
      Arg_Node : Node_Id;

      Result_Node    : Node_Id;
      Temp_Node      : Node_Id;
      Result_Unit    : Asis.Compilation_Unit;
      Result_Element : Asis.Element;
      --  for handling the normalized A_Record_Component_Association only
   begin

      Check_Validity (Association, Package_Name & "Record_Component_Choices");

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

      Arg_Node := Node (Association);

      if Normalization_Case (Association) = Is_Normalized  then
         --  it is definitely A_Record_Component_Association
         --  based on the N_Component_Association Node
         --  and the returned list should definitely contain exactly one
         --  component of A_Defining_Name kind, which should not
         --  test as Is_Normalized
         --
         --  Note, that if the argument Is_Normalized, its Node and R_Node
         --  fields are the same

         Result_Node :=
            Original_Record_Component (Entity (First (Choices (Arg_Node))));

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

         Result_Element := Node_To_Element_New
                             (Starting_Element => Association,
                              Node             => Result_Node,
                              Internal_Kind    => A_Defining_Identifier,
                              In_Unit          => Result_Unit);

         --  And now we have to correct some fields in Result_Element.
         --  First, Association Is_Normalized, but its components are
         --  not Is_Normalized. Therefore

         Set_Special_Case (Result_Element, Not_A_Special_Case);

         --  Then, we should check whether or not Result_Element represents
         --  the implicit inherited component of some derived type
         --  The idea (based on the tree structure of 3.05) is to go from
         --  Result_Node up to the corresponding full type declaration,
         --  then one step down to the type defining identifier and then
         --  to check if it Is_Internal

         Temp_Node := Parent (Parent (Result_Node));
         --  this Parent (Parent) gives us either N_Component_List node
         --  (if  Result_Node corresponds to a record component) or
         --  N_Full_Type_Declaration node (if  Result_Node corresponds to a
         --  discriminant). In the former case we have to apply Parent
         --  twice more to go to a N_Full_Type_Declaration node

         if Nkind (Temp_Node) = N_Component_List then
            Temp_Node := Parent (Parent (Temp_Node));
         end if;

         --  and now - the test and the related corrections if the test
         --  is successful:
         if Nkind (Temp_Node) = N_Full_Type_Declaration then
            --  if Result_Node corresponds to a record component from a record
            --  extension part, we should be in N_Derived_Type_Definition
            --  node here, and we have nothing to correct in Result_Element
            --  in that case

            Temp_Node := Defining_Identifier (Temp_Node);
            if Is_Internal (Temp_Node) then
               Set_From_Implicit  (Result_Element);
               Set_From_Inherited (Result_Element);
            end if;
         end if;

         return (1 => Result_Element);

      end if;

      --  processing a non-normalized association:

      if Nkind (Arg_Node) = N_Component_Association then

         declare
            Result : constant Asis.Element_List :=
              N_To_E_List_New
                (List             => Choices (Arg_Node),
                 Starting_Element => Association);
         begin
            Store_Enclosing_Element (Association, Result);

            return Result;
         end;
      else
         return Nil_Element_List;
         --  what else can we get from a positional association?
      end if;

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

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

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Record_Component_Choices",
            Ex          => Ex,
            Arg_Element => Association);
   end Record_Component_Choices;
-----------------------------------------------------------------------------
   function Component_Expression
     (Association : Asis.Association)
      return        Asis.Expression
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Association);
      Arg_Node : Node_Id;

      Returned_Element : Element;
      Result_Node      : Node_Id;
      Result_Kind      : Internal_Element_Kinds := Not_An_Element;
      Temp_Node        : Node_Id;
      Norm_Expr_Sloc   : Source_Ptr;
   begin

      Check_Validity (Association, Package_Name & "Component_Expression");

      if not (Arg_Kind = A_Record_Component_Association or else
              Arg_Kind = An_Array_Component_Association)
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Component_Expression",
            Wrong_Kind => Arg_Kind);
      end if;

      Arg_Node := Node (Association);
      --  ??? May be, we have to use R_Node here???

      if Normalization_Case (Association) = Is_Normalized then
         --  In case when an aggregate contains a box, three cases are
         --  possible:
         --
         --  (1) the aggregate does not provide a value for a component and the
         --      record type does not define a default for it;
         --
         --  (2) the aggregate does not provide a value for a component and the
         --      record type defines a default for it;
         --
         --  (3) the aggregate provides a value for a component, the situation
         --      is the same as for an aggregate without a box;

         if Box_Present (Arg_Node) then
            --  Case (1): no value for this component - neither in aggregate
            --  nor default in record type declaration
            return Nil_Element;
         end if;

         pragma Assert (Atree.Present (Sinfo.Expression (Arg_Node)));

         if not Comes_From_Source
                  (Original_Node (Sinfo.Expression (Arg_Node)))
         then
            --  Case (2): the default value for a record component is used
            Result_Node := First (Choices (Arg_Node));
            Result_Node := Entity (Result_Node);
            Result_Node := Parent_No_Normalization (Result_Node);
            Result_Node := Sinfo.Expression (Result_Node);
            goto Find;
         end if;

         -------------------------------------------------------
         --  (3) an aggregate defines a value for a component --
         -------------------------------------------------------

         --  the idea of the implementation is: to go up to the
         --  (rewritten!) N_Aggregate node, then to go to the corresponding
         --  expression in the corresponding non-normalized association
         --  through the original aggregate node. The corresponding
         --  expression is the expression having the same Sloc value
         --  (we are traversing the same tree all the time, so we do not
         --  need relative Slocs.
         --
         --  It may look a bit crazy - why do not we use the expression
         --  subtree from the rewritten aggregate. At least one reason is
         --  that some details of the original expression structure are
         --  lost in the rewritten aggregate as a result of compile-time
         --  optimization of static expressions

         Result_Node := Parent (Arg_Node);
         --  here we are in the rewritten aggregate node. Now coming to its
         --  original node:
         Result_Node := Original_Node (Result_Node);

         --  and now - trying to find the corresponding expression:

         Norm_Expr_Sloc := Sloc (Sinfo.Expression (Arg_Node));

         if Present (Sinfo.Expressions (Result_Node)) then
            --  starting from positional associations, if any:
            Temp_Node := First (Sinfo.Expressions (Result_Node));

            while Present (Temp_Node) loop

               if Sloc (Temp_Node) = Norm_Expr_Sloc then
                  Result_Node := Temp_Node;
                  goto Find;
               end if;

               Temp_Node := Next (Temp_Node);
            end loop;

         end if;

         if Present (Component_Associations (Result_Node)) then

            Temp_Node := First (Component_Associations (Result_Node));

            while Present (Temp_Node) loop

               if Sloc (Sinfo.Expression (Temp_Node)) = Norm_Expr_Sloc then
                  Result_Node := (Sinfo.Expression (Temp_Node));
                  goto Find;
               end if;

               Temp_Node := Next (Temp_Node);
            end loop;

         end if;

         <<Find>>
         Returned_Element := Node_To_Element_New
                               (Starting_Element => Association,
                                Node             => Result_Node);

         --  And now we have to correct the Result_Element before returning
         --  it. Association Is_Normalized, but its components are
         --  not Is_Normalized. Therefore

         Set_Special_Case (Returned_Element, Not_A_Special_Case);

      else
         --  processing non-normalized A_Record_Component_Association or
         --  An_Array_Component_Association

         if Nkind (Arg_Node) in N_Component_Association | N_Generic_Association
           and then
            Box_Present (Arg_Node)
         then
            Returned_Element := Association;
            Set_Int_Kind (Returned_Element, A_Box_Expression);
            return Returned_Element;
         end if;

         if Nkind (Arg_Node) = N_Component_Association then
            Result_Node := Sinfo.Expression (Arg_Node);
         else
            Result_Node := R_Node (Association);
         end if;

         if Special_Case (Association) = Rewritten_Named_Number then
            Result_Kind := An_Identifier;
         end if;

         Returned_Element :=
           Node_To_Element_New (Node             => Result_Node,
                                Internal_Kind    => Result_Kind,
                                Starting_Element => Association);

      end if;

      if Normalization_Case (Association) /= Is_Normalized then
         Store_Enclosing_Element (Association, Returned_Element);
      end if;

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

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

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

   function Formal_Parameter
     (Association : Asis.Association)
      return        Asis.Element
   is
      Arg_Kind    : constant Internal_Element_Kinds := Int_Kind (Association);
      Arg_Node    : Node_Id;
      Result_Node : Node_Id;
      Tmp         : Node_Id;
      Result_Unit : Compilation_Unit;
      Result_Kind : Internal_Element_Kinds := An_Identifier;

      Is_Inherited      : Boolean := False;
      Subprogram_Entity : Entity_Id := Empty;

      Nil_To_Be_Returned  : Boolean := False;
      Result              : Asis.Element;

      Spec_Case           : Special_Cases := Not_A_Special_Case;

   begin
      Check_Validity (Association, Package_Name & "Formal_Parameter");

      if not (Arg_Kind = A_Parameter_Association or else
              Arg_Kind = A_Generic_Association   or else
              Arg_Kind = A_Pragma_Argument_Association)
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Formal_Parameter",
            Wrong_Kind => Arg_Kind);
      end if;

      Arg_Node := Node (Association);

      if Normalization_Case (Association) in Normalized_Association then

         if Arg_Kind = A_Generic_Association
          or else
            Arg_Kind = A_Parameter_Association
         then
            --  see the documentation for the body of
            --  Norm.Normalized_Generic_Associations:
            Result_Node := Arg_Node;

            if Nkind (Result_Node) = N_Defining_Identifier then
               Result_Kind := A_Defining_Identifier;
            else
               Result_Kind := Not_An_Element;
               --  In this case Result_Kind should be detected
               --  automatically
            end if;

            Subprogram_Entity := Node_Field_1 (Association);
            Is_Inherited      := Present (Subprogram_Entity);

            if Arg_Kind = A_Parameter_Association
             and then
               Is_Inherited
            then
               Result_Unit :=
                  Enclosing_Unit (Encl_Cont_Id (Association),
                                  Subprogram_Entity);
            else
               Result_Unit :=
                  Enclosing_Unit (Encl_Cont_Id (Association),
                                  Result_Node);
            end if;

            --  Check if we have a parameter from implicit "/=" operation

            Tmp := Parent (Parent (Result_Node));

            if Nkind (Tmp) = N_Function_Specification then
               Tmp := Defining_Unit_Name (Tmp);

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

               if Chars (Tmp) = Name_Op_Ne
                 and then
                  Present (Corresponding_Equality (Tmp))
               then
                  Spec_Case := Is_From_Imp_Neq_Declaration;
               end if;
            end if;

            return Node_To_Element_New (Node          => Result_Node,
                                        Internal_Kind => Result_Kind,
                                        Node_Field_1  => Subprogram_Entity,
                                        Inherited     => Is_Inherited,
                                        In_Unit       => Result_Unit,
                                        Spec_Case     => Spec_Case);
         else
            Not_Implemented_Yet (Diagnosis =>
                Package_Name & "Formal_Parameter: "
              &  ASIS_Line_Terminator
              & "     Cannot handle the NORMALIZED parameter association");
         end if;

      else
         if Arg_Kind = A_Parameter_Association then

            if not (Nkind (Arg_Node) = N_Parameter_Association) then
               --  positional (non-normalized) association
               Nil_To_Be_Returned := True;
            else
               Result_Node := Selector_Name (Arg_Node);
            end if;

         elsif Arg_Kind = A_Generic_Association then

            if Nkind (Arg_Node) = N_Others_Choice then
               Result_Kind := An_Others_Choice;
               Result_Node := Arg_Node;

               --  For the rest of IF paths
               --  Arg_Node_Kind = N_Generic_Association
               --  is always True
            elsif No (Selector_Name (Arg_Node)) then
               --  positional (non-normalized) association
               Nil_To_Be_Returned := True;
            else
               Result_Node := Selector_Name (Arg_Node);

               if Nkind (Result_Node) = N_Operator_Symbol then
                  Result_Kind := Not_An_Element;
                  --  In this case Result_Kind should be detected
                  --  automatically
               end if;

            end if;

         else -- Arg_Kind = A_Pragma_Argument_Association

            --  special treatment by an identifier in the tree

            if Chars (Arg_Node) = No_Name then
               --  no pragma argument identifier
               Nil_To_Be_Returned := True;
            else
               Result_Node := Arg_Node;
            end if;

         end if;

         if Nil_To_Be_Returned then
            return Nil_Element;

         else
            Result :=
              Node_To_Element_New (Node             => Result_Node,
                                   Internal_Kind    => Result_Kind,
                                   Starting_Element => Association);

            Store_Enclosing_Element (Association, Result);

            return Result;
         end if;

      end if;

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

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

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

   function Actual_Parameter
     (Association : Asis.Association)
      return        Asis.Expression
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Association);

      Arg_Node         : Node_Id;
      Result_Node      : Node_Id;
      Result_Kind      : Internal_Element_Kinds := Not_An_Element;
      Result_Norm_Case : Normalization_Cases    := Is_Not_Normalized;
      Result_Spec_Case : Special_Cases          := Not_A_Special_Case;
      Result_Unit      : Compilation_Unit;
      Pragma_Chars     : Name_Id;

      Is_Inherited       : Boolean := False;
      Subprogram_Entity  : Entity_Id := Empty;

      Result : Asis.Element;

   begin
      Check_Validity (Association, Package_Name & "Actual_Parameter");

      if not (Arg_Kind = A_Parameter_Association or else
              Arg_Kind = A_Generic_Association   or else
              Arg_Kind = A_Pragma_Argument_Association)
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Actual_Parameter",
            Wrong_Kind => Arg_Kind);
      end if;

      Arg_Node := Node (Association);

      if Normalization_Case (Association) in Normalized_Association then
         Result_Spec_Case := Special_Case (Association);

         if Arg_Kind = A_Generic_Association
           or else
            Arg_Kind = A_Parameter_Association
         then
            --  see the documentation for the body of
            --  Norm.Normalized_Generic_Associations:
            Result_Node := Node_Field_2 (Association);

            if Nkind (Result_Node) = N_Unchecked_Type_Conversion then

               --  Sometimes the front-end creates a "wrapper"
               --  N_Unchecked_Type_Conversion structures for calls from
               --  RTL, see E622-015 and the corresponding note in
               --  Function_Call_Parameters
               Result_Node := Sinfo.Expression (Result_Node);
            end if;

            if Normalization_Case (Association) = Is_Normalized_Defaulted then
               --  the actual parameter is taken by default from the
               --  declaration of the corresponding formal, it may be
               --  in another Compilation Unit
               Result_Unit :=
                  Enclosing_Unit (Encl_Cont_Id (Association), Result_Node);
            else
               Result_Unit := Encl_Unit (Association);
            end if;

            --  in case of the default defined at the place of
            --  an instantiation for A_Box_Default; we will keep
            --  Special_Case equal to Is_Normalized_Defaulted_For_Box
            --  (just in case).
            if Normalization_Case (Association) =
                  Is_Normalized_Defaulted_For_Box
            then
               Result_Norm_Case := Is_Normalized_Defaulted_For_Box;
            end if;

            if Result_Spec_Case = Not_A_Special_Case
              and then
               Normalization_Case (Association) = Is_Normalized
              and then
               Arg_Kind = A_Generic_Association
            then
               Result_Spec_Case := Is_From_Gen_Association;
            end if;

            if Is_Defaulted_Association (Association) then
               Subprogram_Entity := Node_Field_1 (Association);
               Is_Inherited      := Present (Subprogram_Entity);
            end if;

            --  See FB27-003 - we need a special processing for the
            --  case when we have an attribute passed as an actual for a
            --  formal subprogram

            if Arg_Kind = A_Generic_Association
              and then
               Nkind (Result_Node) = N_Attribute_Reference
              and then
               Nkind (Original_Node (Parent (Result_Node))) in
                 N_Subprogram_Renaming_Declaration |
                 N_Formal_Subprogram_Declaration
            then
               Result_Kind := Subprogram_Attribute_Kind (Result_Node);
            end if;

            if Arg_Kind = A_Generic_Association
             and then
               Nkind (Result_Node) = N_Others_Choice
            then
               Result_Kind := A_Box_Expression;
            end if;

            Result := Node_To_Element_New (Node          => Result_Node,
                                           Norm_Case     => Result_Norm_Case,
                                           Spec_Case     => Result_Spec_Case,
                                           Node_Field_1  => Subprogram_Entity,
                                           Inherited     => Is_Inherited,
                                           Internal_Kind => Result_Kind,
                                           In_Unit       => Result_Unit);

            --  If we have an actual corresponding to
            --  Is_Normalized_Defaulted_For_Box, we may have to correct
            --  Is_Part_Of_Instance of the result. The corresponding naming
            --  expression is taken from the artificial renaming, so
            --  it in any case is classified as being from instance. But
            --  for this particular case of getting actual from normalized
            --  association we should check that not the result node, but the
            --  corresponding instantiation is from instance, that is, that the
            --  instantiation chain has at least three elements. Another
            --  possibility to check this is to check if the corresponding
            --  instantiation is from instance

            if (Result_Norm_Case = Is_Normalized_Defaulted_For_Box
              or else
                Result_Spec_Case = Is_From_Gen_Association)
              and then
               not Is_From_Instance (Enclosing_Element (Association))
            then
               Set_From_Instance (Result, False);
            end if;

            if Normalization_Case (Association) =
               Is_Normalized_Defaulted_Null_Procedure
            then
               Set_Int_Kind (Result, An_Identifier);
               Set_Normalization_Case
                 (Result, Is_Normalized_Defaulted_Null_Procedure);
               Set_Node_Field_2 (Result, Node (Association));
               --  This is needed for computing Enclosing_Element that should
               --  point to the corresponding generic formal parameter
            end if;

         else
            Not_Implemented_Yet (Diagnosis =>
                Package_Name & "Actual_Parameter: "
              &  ASIS_Line_Terminator
              & "     Cannot handle the NORMALIZED parameter association");
         end if;
      else

         if Arg_Kind = A_Parameter_Association then

            if not (Nkind (Arg_Node) = N_Parameter_Association) then
               --  positional (non-normalized) association
               Result_Node := R_Node (Association);

               if Nkind (Result_Node) = N_Unchecked_Type_Conversion then

                  --  Sometimes the front-end creates a "wrapper"
                  --  N_Unchecked_Type_Conversion structures for calls from
                  --  RTL, see E622-015 and the corresponding note in
                  --  Function_Call_Parameters
                  Result_Node := Sinfo.Expression (Result_Node);
               end if;

               if Nkind (Result_Node) = N_Explicit_Dereference
                 and then
                  not Comes_From_Source ((Result_Node))
                 and then
                  Nkind (Original_Node (Result_Node)) = N_Explicit_Dereference
               then
                  Result_Node := Prefix (Result_Node);
               end if;

            else
               Result_Node := Explicit_Actual_Parameter (Arg_Node);
            end if;

         elsif Arg_Kind = A_Generic_Association then

            if Nkind (Arg_Node) = N_Others_Choice
              or else
               Box_Present (Arg_Node)
            then
               Result := Association;
               Set_Int_Kind     (Result, A_Box_Expression);
               Set_Special_Case (Result, Is_From_Gen_Association);
               return Result;
            else
               --  NKind (Arg_Node)  = N_Generic_Association is always True
               Result_Spec_Case := Is_From_Gen_Association;
               Result_Node := Explicit_Generic_Actual_Parameter (Arg_Node);

               --  See FB27-003 - we need a special processing for the
               --  case when we have an attribute passed as an actual for a
               --  formal subprogram

               if Nkind (Result_Node) = N_Attribute_Reference
                 and then
                  Nkind (Original_Node (Parent (Result_Node))) =
                    N_Subprogram_Renaming_Declaration
               then
                  Result_Kind := Subprogram_Attribute_Kind (Result_Node);
               end if;

            end if;

         else
            --  Arg_Kind = A_Pragma_Argument_Association
            --  Special processing is needed for a Debug pragma:
            Pragma_Chars := Pragma_Name (Original_Node (Parent (Arg_Node)));

            if Pragma_Chars = Name_Debug
              and then
               Nkind (Parent (Arg_Node)) /= N_Null_Statement
              and then
               No (Next (Arg_Node))
            then

               --  We have to use the rewritten tree structures here, because
               --  in the original structures the procedure call in pragma
               --  Debug is not decorated. The problem with the rewritten
               --  structure is that it is an IF statement with block statement
               --  with procedure call from the Debug pragma as its statement
               --  sequence.
               --
               --  Note the second condition in "and then'. In case when a
               --  pragma
               --
               --     pragma Debug_Policy (Disable);
               --
               --  is applied to a compilation unit, then all the Debug pragmas
               --  in this unit are rewritten as null statements, and there is
               --  no check that the name that is the argument of a Debug
               --  pragma and is supposed to denote some procedure is actually
               --  defined.
               --
               --  The third condition in "and then" ensures that this special
               --  processing is applied only to the procedure call argument
               --  of pragma Debug. In case when the pragma has two parameters
               --  the first parameter (boolean guard expression) should be
               --  processed in a usual way

               Result_Node := Parent (Arg_Node);
               Result_Node := First (Then_Statements (Result_Node));
               Result_Node :=
                 First (Sinfo.Statements
                        (Handled_Statement_Sequence (Result_Node)));

               while Nkind (Original_Node (Result_Node)) /=
                       N_Procedure_Call_Statement
               loop
                  Result_Node := Next (Result_Node);
               end loop;

               Result_Kind := A_Function_Call;
            else
               Result_Node := Sinfo.Expression (Arg_Node);
            end if;

         end if;

         Result := Node_To_Element_New (Node             => Result_Node,
                                        Starting_Element => Association,
                                        Spec_Case        => Result_Spec_Case,
                                        Internal_Kind    => Result_Kind);
      end if;

      if Special_Case (Result) = Configuration_File_Pragma
        and then
         Expression_Kind (Result) = An_Operator_Symbol
      then
         Set_Int_Kind (Result, A_String_Literal);
      end if;

      if Normalization_Case (Association) not in Normalized_Association then
         Store_Enclosing_Element (Association, Result);
      end if;

      return Result;

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

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

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Actual_Parameter",
            Ex          => Ex,
            Arg_Element => Association);
   end Actual_Parameter;
------------------------------------------------------------------------------
--  PARTIALLY IMPLEMENTED, CANNOT HANDLE THE NORMALIZED ARGUMENT

   function Discriminant_Selector_Names
     (Association : Asis.Discriminant_Association)
      return        Asis.Expression_List
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Association);
      Arg_Node : Node_Id;
   begin

      Check_Validity
        (Association, Package_Name & "Discriminant_Selector_Names");

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

      Arg_Node := Node (Association);

      if Normalization_Case (Association) = Is_Normalized then

         return (1 => Discr_Def_Name (Association));
      else

         if not (Nkind (Arg_Node) = N_Discriminant_Association) then
            --  positional association
            return Nil_Element_List;
         else
            declare
               Result : constant Asis.Expression_List :=
                 N_To_E_List_New
                   (List             => Selector_Names (Arg_Node),
                    Internal_Kind    => An_Identifier,
                    Starting_Element => Association);

            begin
               Store_Enclosing_Element (Association, Result);

               return Result;
            end;
         end if;

      end if;

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

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

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

   -----------------------------
   -- Discriminant_Expression --
   -----------------------------

   function Discriminant_Expression
     (Association : Asis.Discriminant_Association)
      return        Asis.Expression
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Association);
      Arg_Node : Node_Id;
      Result   : Asis.Element;
   begin

      Check_Validity (Association, Package_Name & "Discriminant_Expression");

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

      Arg_Node := R_Node (Association);

      if Nkind (Arg_Node) = N_Discriminant_Association then
         --  named association
         Result :=
           Node_To_Element_New
             (Node             => Sinfo.Expression (Arg_Node),
              Starting_Element => Association);
      else
         --  positional or normalized association
         Result :=
           Node_To_Element_New (Node             => Arg_Node,
                                Starting_Element => Association);
      end if;

      if Normalization_Case (Association) /= Is_Normalized then
         Store_Enclosing_Element (Association, Result);
      end if;

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

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

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

   function Is_Normalized (Association : Asis.Association) return Boolean is
      Arg_Kind  : constant Internal_Element_Kinds := Int_Kind (Association);
      Norm_Case : Normalization_Cases;
   begin
      Check_Validity (Association, Package_Name & "Is_Normalized");

      if not (Arg_Kind = A_Discriminant_Association     or else
              Arg_Kind = A_Record_Component_Association or else
              Arg_Kind = A_Parameter_Association        or else
              Arg_Kind = A_Generic_Association)
      then
         return False;
      else
         Norm_Case := Normalization_Case (Association);

         return Norm_Case in Normalized_Association;
      end if;
   end Is_Normalized;
-----------------------------------------------------------------------------
   function Is_Defaulted_Association
     (Association : Asis.Element)
      return        Boolean
   is
      Arg_Kind  : constant Internal_Element_Kinds := Int_Kind (Association);
      Norm_Case : Normalization_Cases;
   begin
      Check_Validity (Association, Package_Name & "Is_Defaulted_Association");

      if not (Arg_Kind = A_Parameter_Association or else
              Arg_Kind = A_Generic_Association)
      then
         return False;
      else
         Norm_Case := Normalization_Case (Association);

         return Norm_Case in Defaulted_Association;
      end if;
   end Is_Defaulted_Association;
------------------------------------------------------------------------------
   function Expression_Parenthesized
     (Expression : Asis.Expression)
      return       Asis.Expression
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);

      Res_Parenth_Count : Nat;
      Result            : Asis.Expression;

   begin

      Check_Validity (Expression, Package_Name & "Expression_Parenthesized");

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

      Res_Parenth_Count := Parenth_Count (Expression) - 1;

      if Res_Parenth_Count = 0 then
         --  Returning unparenthesized expression
         Result := Node_To_Element_New
                     (Node                     => R_Node (Expression),
                      Considering_Parent_Count => False,
                      Starting_Element         => Expression);
      else
         --  Cut away one level of parentheses
         Result := Expression;
         Set_Parenth_Count (Result, Res_Parenth_Count);
      end if;

      Store_Enclosing_Element (Expression, Result);

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

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

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

   function Is_Prefix_Call (Expression : Asis.Expression) return Boolean is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
      Arg_Node : Node_Id;
   begin

      Check_Validity (Expression, Package_Name & "Is_Prefix_Call");

      if Arg_Kind /= A_Function_Call then
         return False;
      end if;

      Arg_Node := Node (Expression);

      if (Nkind (Arg_Node) = N_Identifier or else
          Nkind (Arg_Node) = N_Expanded_Name)
        and then
         --  Special case: F.A, where either F or A is a function call
         Nkind (R_Node (Expression)) = N_Function_Call
      then
         Arg_Node := R_Node (Expression);
      end if;

      if Nkind (Arg_Node) = N_Attribute_Reference or else
         Nkind (Arg_Node) = N_Procedure_Call_Statement
      then
         --  N_Procedure_Call_Statement corresponds to the argument of
         --  Debug pragma
         return True;
      elsif Nkind (Arg_Node) = N_Identifier then
         --  Special case: F.A , where F - parameterless function returning
         --  a record type
         return True;
      elsif not (Nkind (Arg_Node) = N_Function_Call) then
         return False;
      else
         return Nkind (Sinfo.Name (Arg_Node)) /= N_Identifier
                or else
                Chars (Sinfo.Name (Arg_Node)) not in Any_Operator_Name;
      end if;
   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

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

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

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

      if not (Arg_Kind = A_Function_Call
            or else
              (Arg_Kind = An_Indexed_Component
              and then
               Is_Generalized_Indexing (Expression)))
      then
         Raise_ASIS_Inappropriate_Element
            (Diagnosis  => Package_Name & "Corresponding_Called_Function",
             Wrong_Kind => Arg_Kind);
      end if;

      return Get_Corr_Called_Entity (Expression);

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

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

         raise;
      when Ex : others =>
         Report_ASIS_Bug
           (Query_Name  => Package_Name & "Corresponding_Called_Function",
            Ex          => Ex,
            Arg_Element => Expression);
   end Corresponding_Called_Function;
------------------------------------------------------------------------------
   function Function_Call_Parameters
     (Expression : Asis.Expression;
      Normalized : Boolean := False)
      return       Asis.Association_List
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
      Arg_Node : Node_Id;
      Tmp_El   : Asis.Element;

      Function_Call_Node      : Node_Id;
      Func_Call_Or_Node       : Node_Id;
      Function_Call_Node_Kind : Node_Kind;

      Association_Node_List   : List_Id;

      Infix_Operands          : Asis.Association_List (1 .. 2);
   begin
      --  !!! In case if Normalized is set ON, we return non-nil result only if
      --  Corresponding_Called_Function (Expression) is not nil!

      Check_Validity (Expression, Package_Name & "Function_Call_Parameters");

      Arg_Node := Node (Expression);

      if not (Arg_Kind = A_Function_Call) or else
         (Normalized and then Nkind (Arg_Node) = N_Attribute_Reference)
      then
         Raise_ASIS_Inappropriate_Element
            (Diagnosis  => Package_Name & "Function_Call_Parameters",
             Wrong_Kind => Arg_Kind);
      end if;

      --  There is a number of different situations when the frontend
      --  rewrites or changes in some other way the node heading
      --  the subtree representing a function call. So we have to start
      --  from computing the node to represent a function call.

      if Nkind (R_Node (Expression)) in
           N_Raise_Constraint_Error | N_Raise_Program_Error | N_If_Expression
      then
         Function_Call_Node := Node (Expression);
      elsif Nkind (Arg_Node) = N_Attribute_Reference then
         Function_Call_Node := Arg_Node;
      elsif Nkind (R_Node (Expression)) = N_Unchecked_Type_Conversion then
         --  Sometimes the front-end creates a "wrapper"
         --  N_Unchecked_Type_Conversion structures for calls from RTL, see
         --  E622-015 and the corresponding note in Actual_Parameter
         Function_Call_Node := Sinfo.Expression (R_Node (Expression));
      else
         Function_Call_Node := R_Node (Expression);

         --  Special cases when we need not the rewritten, but the original
         --  node (or something else.

         if Nkind (Function_Call_Node) in
              N_Integer_Literal |
              N_Real_Literal    |
              N_Identifier      |
              N_String_Literal
          or else
            --  this means, that the compiler has optimized a call like
            --  1 + 2, and we have to go back to the original node!

            Nkind (Function_Call_Node) = N_Explicit_Dereference
            --  this happens, but I do not know why...
          or else
            (Nkind (Function_Call_Node) = N_Aggregate
            and then
             Is_Rewrite_Substitution (Function_Call_Node)
            and then
             Is_From_SPARK_Aspect (Expression))
         then
            Function_Call_Node := Arg_Node;
         end if;

         if Nkind (Function_Call_Node) = N_Op_Not        and then
            Is_Rewrite_Substitution (Function_Call_Node) and then
            Nkind (Original_Node (Function_Call_Node)) = N_Op_Ne
         then
            --  '/=' is rewritten as 'not (  =  )'
            Function_Call_Node := Arg_Node;
         end if;

         if Nkind (Function_Call_Node) = N_Type_Conversion and then
            Is_Rewrite_Substitution (Function_Call_Node)   and then
            Nkind (Original_Node (Function_Call_Node)) =
            Nkind (Original_Node (Sinfo.Expression (Function_Call_Node)))
         then
            Function_Call_Node := Sinfo.Expression (Function_Call_Node);
         end if;

      end if;

      --  See the general comment under the "A_Function_Call Problem"
      --  headline in the beginning of the package body!! The prefix call
      --  of the predefined operations should be processed on the base of
      --  the rewritten node, in all the other cases, except
      --  N_Attribute_Reference (which corresponds to the call to an
      --  attribute-function and is handled separately: the node for such
      --  a call may or may not be rewritten, but the processing is based on
      --  the original node) the node is not rewritten.

      --  --  temporary fix for "+"(1, 2) problem ??? 3.11w
      --
      --  if Nkind (Node (Expression)) = N_Function_Call and then
      --     (Nkind (R_Node (Expression)) in N_Op_Add .. N_Op_Xor or else
      --      Nkind (R_Node (Expression)) in N_Op_Abs .. N_Op_Plus)
      --  then
      --      Function_Call_Node := R_Node (Expression);
      --  end if;
      --
      --  to activate this fix, one should decomment this if statement
      --  and to comment out the fragment between
      --   --  temporary fix for "+"(1, 2) problem - start and
      --   --  temporary fix for "+"(1, 2) problem - end sentinels

      if Normalized then

         Tmp_El := Corresponding_Called_Function (Expression);

         if Declaration_Kind (Tmp_El) in
           A_Procedure_Instantiation .. A_Function_Instantiation
         then
            Tmp_El := Corresponding_Declaration (Tmp_El);
         end if;

         if (not (Is_Call_Through_Access_To_Subprogram (Expression)
                 or else
                  Is_Dispatching_Call (Expression))
           and then
             Is_Nil (Tmp_El))
           or else
            (not Is_Nil (Tmp_El)
            and then
             Is_Nil (Parameter_Profile (Tmp_El)))
         then
            return Nil_Element_List;
         else
            return Normalized_Param_Associations (Call_Elem => Expression);
         end if;

      else

         Function_Call_Node_Kind := Nkind (Function_Call_Node);

         case Function_Call_Node_Kind is
            when N_Binary_Op =>

               --  here we have infix or prefix call of a binary predefined
               --  operation

               --  first, we construct the non-normalized association list

               Infix_Operands (1) :=
                 Node_To_Element_New
                   (Node             => Left_Opnd (Function_Call_Node),
                    Internal_Kind    => A_Parameter_Association,
                    Starting_Element => Expression);

               Infix_Operands (2) :=
                 Node_To_Element_New
                   (Node             => Right_Opnd (Function_Call_Node),
                    Internal_Kind    => A_Parameter_Association,
                    Starting_Element => Expression);

      --  temporary fix for "+"(1, 2) problem - start

               if Is_Prefix_Call (Expression) then
                  --  It is a real pity, but we have to worry about the crazy
                  --  situation like "+" (Right => X, Left => Y). For a prefix
                  --  call to a predefined operation an argument node is
                  --  rewritten to N_Op_Xxx node, and the original node of
                  --  N_Function_Call kind contains references to named
                  --  parameter associations, if any

                  --  So, we have to check if this situation takes place

                  --  If not Is_Prefix_Call (Expression), we have nothing
                  --  to do!
                  Func_Call_Or_Node := Node (Expression);

                  if Func_Call_Or_Node /= Function_Call_Node and then
                     --  Func_Call_Or_Node can be of N_Function_Call kind only!
                     --  and we have the prefix call here!
                     --
                     --  Present (Parameter_Associations (Func_Call_Or_Node))
                     --
                     --  cannot be used to complete the check, because we have
                     --  empty list, but not No_List if there is positional
                     --  associations. Therefore -
                    List_Length (Parameter_Associations (Func_Call_Or_Node))
                      > 0
                  then
                     --  we have named associations, and we have to correct the
                     --  result
                     Association_Node_List :=
                        Parameter_Associations (Func_Call_Or_Node);

                     if List_Length (Association_Node_List) = 2 then
                        --  we have two named associations, so we cannot return
                        --  Infix_Operands. We will not correct it, we will
                        --  recreate the returned list:

                        return N_To_E_List_New
                          (List             => Association_Node_List,
                           Include_Pragmas  => False,  --  ???
                           Starting_Element => Expression,
                           Internal_Kind    => A_Parameter_Association);

                     else
                        --  if we are here, the only possibility is that
                        --  List_Length (Association_Node_List) = 1 and we are
                        --  processing the call like "+"(13, Right => Y).
                        --  So the first component of Infix_Operands is OK,
                        --  but the second should be re-created from the
                        --  positional association pointed by the original
                        --  node:

                        Infix_Operands (2) :=
                          Node_To_Element_New
                            (Node             => First (Association_Node_List),
                             Internal_Kind    => A_Parameter_Association,
                             Starting_Element => Expression);
                     end if;
                  end if;
               end if;

      --  temporary fix for "+"(1, 2) problem - end

               Store_Enclosing_Element (Expression, Infix_Operands);

               return Infix_Operands;

            when N_Unary_Op =>
               --  unary operation, Sinfo.ads rev. 1.251
               --  infix_call, here we have infix or prefix call of an unary
               --  predefined  operation

               --  the situation is more simple, then for binary predefined
               --  operation - we have only one component in the returned list

               --  we start from checking if we have the crazy case with
               --  named association (something like "+"(Right => X)

               Func_Call_Or_Node := Node (Expression);

               if Func_Call_Or_Node /= Function_Call_Node     and then
                  Nkind (Func_Call_Or_Node) = N_Function_Call and then
                  List_Length (Parameter_Associations (Func_Call_Or_Node)) > 0
               then
                  --  we have named association
                  Association_Node_List :=
                     Parameter_Associations (Func_Call_Or_Node);

                  Infix_Operands (1) :=
                     Node_To_Element_New
                       (Node             => First (Association_Node_List),
                        Internal_Kind    => A_Parameter_Association,
                        Starting_Element => Expression);
               else
                  Infix_Operands (1) :=
                     Node_To_Element_New
                       (Node             => Right_Opnd (Function_Call_Node),
                        Internal_Kind    => A_Parameter_Association,
                        Starting_Element => Expression);
               end if;

               Store_Enclosing_Element (Expression, Infix_Operands (1 .. 1));

               return Infix_Operands (1 .. 1);

            when N_Attribute_Reference      |
                 N_Function_Call            |
                 N_Procedure_Call_Statement |
                 N_Entry_Call_Statement     =>

               declare
                  Result : constant Asis.Element_List :=
                    (if Function_Call_Node_Kind = N_Attribute_Reference then
                        N_To_E_List_New
                          (List             =>
                             Sinfo.Expressions (Function_Call_Node),
                           Starting_Element => Expression,
                           Internal_Kind    => A_Parameter_Association)
                     elsif No (Parameter_Associations (Function_Call_Node))
                     then
                        Nil_Element_List
                     else
                        N_To_E_List_New
                          (List             => Parameter_Associations
                             (Function_Call_Node),
                           Starting_Element => Expression,
                           Internal_Kind    => A_Parameter_Association));
               begin
                  if not Is_Nil (Result) then
                     Store_Enclosing_Element (Expression, Result);
                  end if;

                  return Result;
               end;
            when others =>
               --  really nothing else could be possible, this alternative
               --  could be chosen only as the result of some bug in the
               --  implementation
               raise Internal_Implementation_Error;
         end case;

      end if;

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

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

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

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

   function Short_Circuit_Operation_Left_Expression
     (Expression : Asis.Expression)
      return       Asis.Expression
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
      Arg_Node : Node_Id;
      Result   : Asis.Element;
   begin

      Check_Validity
        (Expression, Package_Name & "Short_Circuit_Operation_Left_Expression");

      if not (Arg_Kind = An_And_Then_Short_Circuit or else
              Arg_Kind = An_Or_Else_Short_Circuit)
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis =>
              Package_Name & "Short_Circuit_Operation_Left_Expression",
            Wrong_Kind => Arg_Kind);
      end if;

      Arg_Node := Node (Expression);

      Result := Node_To_Element_New (Node             => Left_Opnd (Arg_Node),
                                     Starting_Element => Expression);

      Store_Enclosing_Element (Expression, Result);

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

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

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

   function Short_Circuit_Operation_Right_Expression
      (Expression : Asis.Expression)
       return       Asis.Expression
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
      Arg_Node : Node_Id;
      Result   : Asis.Element;
   begin

      Check_Validity
        (Expression,
         Package_Name & "Short_Circuit_Operation_Right_Expression");

      if not (Arg_Kind = An_And_Then_Short_Circuit or else
              Arg_Kind = An_Or_Else_Short_Circuit)
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis =>
              Package_Name & "Short_Circuit_Operation_Right_Expression",
            Wrong_Kind => Arg_Kind);
      end if;

      Arg_Node := Node (Expression);

      Result := Node_To_Element_New (Node             => Right_Opnd (Arg_Node),
                                     Starting_Element => Expression);
      Store_Enclosing_Element (Expression, Result);

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

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

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

   function Membership_Test_Expression
     (Expression : Asis.Expression)
      return       Asis.Expression
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
      Arg_Node : Node_Id;
      Result   : Asis.Element;
   begin

      Check_Validity (Expression, Package_Name & "Membership_Test_Expression");

      if Arg_Kind not in
         An_In_Membership_Test .. A_Not_In_Membership_Test
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Membership_Test_Expression",
            Wrong_Kind => Arg_Kind);
      end if;

      Arg_Node := Node (Expression);

      Result := Node_To_Element_New (Node             => Left_Opnd (Arg_Node),
                                     Starting_Element => Expression);

      Store_Enclosing_Element (Expression, Result);

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

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

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

   function Membership_Test_Range
     (Expression : Asis.Expression)
      return       Asis.Range_Constraint
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
      Arg_Node : Node_Id;

      Result_Node    : Node_Id;
      Result_Or_Node : Node_Id;
      Result_Kind    : Internal_Element_Kinds;
      Result         : Asis.Element;
   begin

      Check_Validity (Expression, Package_Name & "Membership_Test_Range");

      if not (Arg_Kind in An_In_Membership_Test .. A_Not_In_Membership_Test
            and then
              Is_Range_Memberchip_Test (Expression))
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Membership_Test_Range",
            Wrong_Kind => Arg_Kind);
      end if;

      Arg_Node := Node (Expression);

      --  we cannot use the auto determination of the result kind
      --  because of the possible rewriting of A'Range as
      --  A'First .. A'Last.

      Result_Node    := Right_Opnd (Arg_Node);
      Result_Or_Node := Original_Node (Result_Node);

      if Nkind (Result_Or_Node) = N_Attribute_Reference then
         Result_Kind := A_Range_Attribute_Reference;
      else
         Result_Kind := A_Simple_Expression_Range;
      end if;

      Result := Node_To_Element_New (Node             => Result_Node,
                                     Internal_Kind    => Result_Kind,
                                     Starting_Element => Expression);

      Store_Enclosing_Element (Expression, Result);

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

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

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

   function Membership_Test_Subtype_Mark
     (Expression : Asis.Expression)
      return       Asis.Expression
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
      Arg_Node : Node_Id;
      Result   : Asis.Element;
   begin

      Check_Validity
        (Expression, Package_Name & "Membership_Test_Subtype_Mark");

      if not (Arg_Kind in An_In_Membership_Test .. A_Not_In_Membership_Test
            and then
              Is_Type_Memberchip_Test (Expression))
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Membership_Test_Expression",
            Wrong_Kind => Arg_Kind);
      end if;

      Arg_Node := Node (Expression);

      Result := Node_To_Element_New (Node             => Right_Opnd (Arg_Node),
                                     Starting_Element => Expression);

      Store_Enclosing_Element (Expression, Result);

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

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

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

   function Converted_Or_Qualified_Subtype_Mark
      (Expression : Asis.Expression)
       return       Asis.Expression
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
      Arg_Node : Node_Id;
      Result   : Asis.Element;
   begin

      Check_Validity
        (Expression, Package_Name & "Converted_Or_Qualified_Subtype_Mark");

      if not (Arg_Kind = A_Type_Conversion or else
              Arg_Kind = A_Qualified_Expression)
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Converted_Or_Qualified_Subtype_Mark",
            Wrong_Kind => Arg_Kind);
      end if;

      Arg_Node := Node (Expression);

      --  if Special_Case (Expression) = Type_Conversion_With_Attribute then
      --
      --     return Node_To_Element (
      --              Node    => Arg_Node,
      --              --  that is, the node of N_Attribute_Reference kind!
      --              Check_If_Type_Conversion => False,
      --              --  and it is treated as the base for
      --              --  An_Attribute_Reference Element
      --              In_Unit => Encl_Unit (Expression));
      --  else
      --     return Node_To_Element (
      --              Node    => Sinfo.Subtype_Mark (Arg_Node),
      --              In_Unit => Encl_Unit (Expression));
      --  end if;
      --
      --   ??? It looks like Type_Conversion_With_Attribute is not needed
      --   ??? any more as a Special_Cases value. We'll keep the old code
      --   ??? (commented out) till the next application of the massive
      --   ??? testing procedure

      Result := Node_To_Element_New
                  (Node             => Sinfo.Subtype_Mark (Arg_Node),
                   Starting_Element => Expression);

      Store_Enclosing_Element (Expression, Result);

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

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

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

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

      if not (Arg_Kind = A_Type_Conversion or else
              Arg_Kind = A_Qualified_Expression)
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Converted_Or_Qualified_Expression",
            Wrong_Kind => Arg_Kind);
      end if;

      Arg_Node := Node (Expression);

      Result := Node_To_Element_New
                  (Node             => Sinfo.Expression (Arg_Node),
                   Starting_Element => Expression);

      Store_Enclosing_Element (Expression, Result);

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

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

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

   function Allocator_Subtype_Indication
     (Expression : Asis.Expression)
      return       Asis.Subtype_Indication
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
      Arg_Node : Node_Id;
      Result   : Asis.Element;
   begin

      Check_Validity
        (Expression, Package_Name & "Allocator_Subtype_Indication");

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

      Arg_Node := Node (Expression);

      Result := Node_To_Element_New
                  (Node             => Sinfo.Expression (Arg_Node),
                   Internal_Kind    => A_Subtype_Indication,
                   Starting_Element => Expression);

      Store_Enclosing_Element (Expression, Result);

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

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

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

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

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

      Arg_Node := Node (Expression);

      Result := Node_To_Element_New
                  (Node             => Sinfo.Expression (Arg_Node),
                   Starting_Element => Expression);

      Store_Enclosing_Element (Expression, Result);

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

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

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

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

-----------------------------
-- Conditional Expressions --
-----------------------------

   ----------------------
   -- Expression_Paths --
   ----------------------

   function Expression_Paths
     (Expression : Asis.Expression)
      return       Asis.Element_List
   is
      Res_Node            : Node_Id;
      First_Path_Kind     : Internal_Element_Kinds := An_If_Expression_Path;
      Next_Cond_Expr_Node : Node_Id                := Node (Expression);

      procedure Get_If_Paths;
      --  Get expression paths from the Expressions list of
      --  N_If_Expression node that is the current value of
      --  Next_Cond_Expr_Node. It uses the value of First_Path_Kind to set
      --  the kind of the first path element.
      --
      --  For IF expression, The Expressions list may have the following
      --  structure:
      --
      --  (1) expr1 -> expr2 -> True, where True is not Comes_From_Source, this
      --                      corresponds to
      --                      IF expr1 THEN expr2
      --                      no ELSE or ELSIF paths
      --
      --  (2) expr1 -> expr2 -> expr3, this corresponds to
      --                      IF expr1 THEN expr2 ELSE expr3
      --                      no ELSIF paths
      --
      --  (3) expr1 -> expr2 -> cond_expr, this corresponds to a conditional
      --                      expression with ELSIF path
      --
      --  This procedure creates and appends to Asis_Element_Table.Table
      --  elements corresponding to expr1, expr2 and expr3, and in case (3)
      --  sets Next_Cond_Expr_Node to cond_expr. In cases (1) and (2)
      --  Next_Cond_Expr_Node is set to Empty

      procedure Get_If_Paths is

         --  The front end performs two normalizations that we need to undo
         --  here. It turns elsif's into nested if's, so for example
         --  (if A then X elsif B then Y else Z) becomes
         --  (if A then X else (if B then Y else Z)).
         --  We can detect this by noticing that the third list element is an
         --  If_Expression and has the Is_Elsif flag set. This is case (3)
         --  above.
         --
         --  It inserts an implicit True, so for example (if A then X) becomes
         --  (if A then X else True). We can detect this by noticing an
         --  expression that denotes Standard_True and has Comes_From_Source =
         --  False.

         function Is_Implicit_True (N : Node_Id) return Boolean;
         --  N is the third element of the list. True if it is an implicit
         --  compiler-generated True.

         function Is_Implicit_True (N : Node_Id) return Boolean is
         begin
            return Nkind (N) = N_Identifier
              and then Entity (N) = Standard_True
              and then not Comes_From_Source (N);
         end Is_Implicit_True;

      --  Start of processing for Get_If_Paths

      begin
         Res_Node := First (Sinfo.Expressions (Next_Cond_Expr_Node));
         --  This Element represents the condition from IF/ELSIF path, so
         Res_Node  := Next (Res_Node);

         Asis_Element_Table.Append
           (Node_To_Element_New
              (Node => Res_Node,
               Starting_Element => Expression,
               Internal_Kind    => First_Path_Kind));

         Res_Node := Next (Res_Node);

         if Present (Res_Node)
           and then
            not Is_Implicit_True (Res_Node)
         then
            if Nkind (Res_Node) = N_If_Expression
              and then Is_Elsif (Res_Node)
            then
               Next_Cond_Expr_Node := Res_Node;
            else
               Asis_Element_Table.Append
                 (Node_To_Element_New
                    (Node => Res_Node,
                     Starting_Element => Expression,
                     Internal_Kind    => An_Else_Expression_Path));

               Next_Cond_Expr_Node := Empty;
            end if;

         else
            Next_Cond_Expr_Node := Empty;
         end if;

      end Get_If_Paths;

   --  Start of processing for Expression_Paths

   begin
      Check_Validity (Expression, Package_Name & "Expression_Paths");

      if Expression_Kind (Expression) not in
         A_Case_Expression .. An_If_Expression
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Expression_Paths",
            Wrong_Kind => Int_Kind (Expression));
      end if;

      Asis_Element_Table.Init;

      if Expression_Kind (Expression) = An_If_Expression then
         Next_Cond_Expr_Node := Node (Expression);
         Get_If_Paths;
         First_Path_Kind := An_Elsif_Expression_Path;

         while Present (Next_Cond_Expr_Node) loop
            Get_If_Paths;
         end loop;
      else
         Res_Node := First (Alternatives (Node (Expression)));

         while Present (Res_Node) loop
            Asis_Element_Table.Append
              (Node_To_Element_New
                 (Node => Res_Node,
                  Starting_Element => Expression,
                  Internal_Kind    => A_Case_Expression_Path));

            Res_Node := Next (Res_Node);
         end loop;
      end if;

      Store_Enclosing_Element
        (Expression,
         Asis.Element_List
           (Asis_Element_Table.Table (1 .. Asis_Element_Table.Last)));

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

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

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

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

   -------------------------------
   -- Path_Condition_Expression --
   -------------------------------

--   function Path_Condition_Expression
--     (Path : Asis.Element)
--      return Asis.Expression
--   is
--      Res_Node : Node_Id;
--   begin
--      Check_Validity (Path, Package_Name & "Path_Condition_Expression");

--      if Expression_Path_Kind (Path) not in
--        An_If_Expression_Path .. An_Elsif_Expression_Path
--      then
--         Raise_ASIS_Inappropriate_Element
--           (Diagnosis  => Package_Name & "Path_Condition_Expression",
--            Wrong_Kind => Int_Kind (Path));
--      end if;

--      Res_Node := R_Node (Path);
--      pragma Assert (Is_List_Member (Res_Node));
--      Res_Node := Prev (Res_Node);

--      return Node_To_Element_New
--               (Node => Res_Node,
--                Starting_Element => Path);
--   exception
--      when ASIS_Inappropriate_Element =>
--         raise;
--      when ASIS_Failed =>

--         if Status_Indicator = Unhandled_Exception_Error then
--            Add_Call_Information
--              (Argument   => Path,
--               Outer_Call => Package_Name & "Path_Condition_Expression");
--         end if;

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

   --------------------------
   -- Dependent_Expression --
   --------------------------

   function Dependent_Expression
     (Path : Asis.Element)
      return Asis.Expression
   is
      Arg_Kind    : constant Path_Kinds := Path_Kind (Path);
      Result_Node :          Node_Id;
      Result      :          Asis.Element;
   begin
      Check_Validity (Path, Package_Name & "Dependent_Expression");

      if Arg_Kind not in
           A_Case_Expression_Path .. An_Else_Expression_Path
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Dependent_Expression",
            Wrong_Kind => Int_Kind (Path));
      end if;

      Result_Node := R_Node (Path);

      if Arg_Kind = A_Case_Expression_Path then
         Result_Node := Sinfo.Expression (Result_Node);
      end if;

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

      Store_Enclosing_Element (Path, Result);

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

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

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

----------------------------------
-- Generalized Membership Tests --
----------------------------------

   function Membership_Test_Choices
     (Expression : Asis.Expression)
      return Asis.Element_List
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
      Arg_Node : Node_Id;
      Res_Node : Node_Id;
   begin
      if Arg_Kind not in An_In_Membership_Test .. A_Not_In_Membership_Test then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Membership_Test_Choices",
            Wrong_Kind => Arg_Kind);
      end if;

      Asis_Element_Table.Init;
      Arg_Node := Node (Expression);

      if No (Alternatives (Arg_Node)) then
         Asis_Element_Table.Append
           (Node_To_Element_New
              (Node => Right_Opnd (Arg_Node),
               Starting_Element => Expression));
      else
         Res_Node := First (Alternatives (Arg_Node));

         while Present (Res_Node) loop
            Asis_Element_Table.Append
              (Node_To_Element_New
                 (Node => Res_Node,
                  Starting_Element => Expression));

            Res_Node := Next (Res_Node);
         end loop;
      end if;

      Store_Enclosing_Element
        (Expression,
         Asis.Element_List
           (Asis_Element_Table.Table (1 .. Asis_Element_Table.Last)));

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

   exception
      when ASIS_Inappropriate_Element =>
         raise;
      when ASIS_Failed =>

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

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

-----------------------------------------------------
-- User-Defined Indexing (or generalized indexing) --
-----------------------------------------------------

   -----------------------------
   -- Is_Generalized_Indexing --
   -----------------------------

   function Is_Generalized_Indexing
     (Expression : Asis.Expression)
      return       Boolean
   is
      Result : Boolean := False;
   begin
      Check_Validity (Expression, Package_Name & "Is_Generalized_Indexing");

      if Expression_Kind (Expression) = An_Indexed_Component then
         Result := Present (Generalized_Indexing (Node (Expression)));
      end if;

      return Result;
   end Is_Generalized_Indexing;

   ------------------------------
   -- Is_Generalized_Reference --
   ------------------------------

   function Is_Generalized_Reference
     (Expression : Asis.Expression)
      return       Boolean
   is
      Result : Boolean := False;
      Tmp    : Node_Id;
   begin
      Check_Validity (Expression, Package_Name & "Is_Generalized_Reference");

      if Expression_Kind (Expression) = A_Function_Call then
         Tmp := R_Node (Expression);

         if Nkind (Tmp) = N_Function_Call
           and then
            Comes_From_Source (Tmp)
           and then
            Is_Rewrite_Substitution (Tmp)
           and then
            Nkind (Original_Node (Tmp)) = N_Indexed_Component
           and then
            Nkind (Parent (Tmp)) = N_Selected_Component
           and then
            not Comes_From_Source (Parent (Tmp))
         then
            Tmp := Parent (Parent (Tmp));

            if Nkind (Tmp) = N_Explicit_Dereference
              and then
               not Comes_From_Source (Tmp)
              and then
               Is_Rewrite_Substitution (Tmp)
              and then
               Nkind (Original_Node (Tmp)) = N_Indexed_Component
            then
               Result := True;
            end if;
         end if;

      end if;

      return Result;
   end Is_Generalized_Reference;

----------------------------
-- Quantified Expressions --
----------------------------

   ----------------------------
   -- Iterator_Specification --
   ----------------------------

   function Iterator_Specification
     (Expression : Asis.Expression)
      return      Asis.Declaration
   is
      Arg_Kind    : constant Internal_Element_Kinds := Int_Kind (Expression);
      Result_Node :          Node_Id;
      Result      :          Asis.Element;

   begin
      Check_Validity (Expression, Package_Name & "Iterator_Specification");

      if Arg_Kind not in
           A_For_All_Quantified_Expression .. A_For_Some_Quantified_Expression
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Iterator_Specification",
            Wrong_Kind => Arg_Kind);
      end if;

      Result_Node := Loop_Parameter_Specification (Node (Expression));

      if No (Result_Node) then
         Result_Node := Iterator_Specification (Node (Expression));
      end if;

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

      Store_Enclosing_Element (Expression, Result);

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

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

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

   ---------------
   -- Predicate --
   ---------------

   function Predicate
     (Expression : Asis.Expression)
      return      Asis.Expression
   is
      Arg_Kind    : constant Internal_Element_Kinds := Int_Kind (Expression);
      Result      :          Asis.Element;
   begin
      Check_Validity (Expression, Package_Name & "Predicate");

      if Arg_Kind not in
           A_For_All_Quantified_Expression .. A_For_Some_Quantified_Expression
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Predicate",
            Wrong_Kind => Arg_Kind);
      end if;

      Result := Node_To_Element_New
                  (Node             => Condition (Node (Expression)),
                   Starting_Element => Expression);

      Store_Enclosing_Element (Expression, Result);

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

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

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

   -------------------
   --  Subpool_Name --
   -------------------

   function Subpool_Name
     (Expression : Asis.Expression)
      return      Asis.Expression
   is
      Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Expression);
      Result   :          Asis.Element;
   begin
      Check_Validity (Expression, Package_Name & "Subpool_Name");

      if Arg_Kind not in An_Allocation_From_Subtype ..
                         An_Allocation_From_Qualified_Expression
      then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis  => Package_Name & "Subpool_Name",
            Wrong_Kind => Arg_Kind);
      end if;

      Result := Node_To_Element_New
                  (Node             => Subpool_Handle_Name (Node (Expression)),
                   Starting_Element => Expression);

      Store_Enclosing_Element (Expression, Result);

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

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

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

end Asis.Expressions;