asis_2019.0.0_3ca32fa2/tools/gnatcheck/gnatcheck-asis_utilities.adb

   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
------------------------------------------------------------------------------
--                                                                          --
--                          GNATCHECK COMPONENTS                            --
--                                                                          --
--             G N A T C H E C K . A S I S _ U T I L I T I E S              --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
--                     Copyright (C) 2004-2019, AdaCore                     --
--                                                                          --
-- GNATCHECK  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.  GNATCHECK  is  distributed in the hope that it will be useful, --
-- but  WITHOUT  ANY  WARRANTY;   without  even  the  implied  warranty  of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General --
-- Public License for more details.  You should have received a copy of the --
-- GNU General Public License distributed with GNAT; see file  COPYING3. If --
-- not,  go  to  http://www.gnu.org/licenses  for  a  complete  copy of the --
-- license.                                                                 --
--                                                                          --
-- GNATCHECK is maintained by AdaCore (http://www.adacore.com).             --
--                                                                          --
------------------------------------------------------------------------------

pragma Ada_2012;

with Ada.Characters.Conversions; use Ada.Characters.Conversions;
with Ada.Wide_Text_IO;           use Ada.Wide_Text_IO;

with Asis.Clauses;               use Asis.Clauses;
with Asis.Compilation_Units;     use Asis.Compilation_Units;
with Asis.Declarations;          use Asis.Declarations;
with Asis.Definitions;           use Asis.Definitions;
with Asis.Elements;              use Asis.Elements;
with Asis.Exceptions;
with Asis.Expressions;           use Asis.Expressions;
with Asis.Extensions;            use Asis.Extensions;
with Asis.Extensions.Flat_Kinds; use Asis.Extensions.Flat_Kinds;
with Asis.Iterator;              use Asis.Iterator;
with Asis.Statements;            use Asis.Statements;
with Asis.Text;                  use Asis.Text;

with ASIS_UL.Debug;
with ASIS_UL.Misc;               use ASIS_UL.Misc;
with ASIS_UL.Utilities;          use ASIS_UL.Utilities;

with GNAT.Table;

with Atree;                      use Atree;
with Einfo;                      use Einfo;
with Elists;                     use Elists;
with Namet;                      use Namet;
with Nlists;                     use Nlists;
with Sem_Aux;                    use Sem_Aux;
with Sinfo;                      use Sinfo;
with Snames;                     use Snames;
with Stand;                      use Stand;
with Types;                      use Types;

with Asis.Set_Get;               use Asis.Set_Get;

with A4G.A_Sem;                  use A4G.A_Sem;
with A4G.Int_Knds;               use A4G.Int_Knds;
with A4G.Vcheck;                 use A4G.Vcheck;

with Gnatcheck.Traversal_Stack;  use Gnatcheck.Traversal_Stack;

package body Gnatcheck.ASIS_Utilities is
   Package_Name : constant String := "Gnatcheck.ASIS_Utilities";

   -------------------------
   -- ASIS Elements Table --
   -------------------------

   --  Here we define the same structure as A4G.Asis_Tables.Asis_Element_Table.
   --  We need it to create the results of the functions returning
   --  Element_List, but we can not reuse A4G.Asis_Tables.Asis_Element_Table
   --  because it may be used by the standard ASIS queries we may need for our
   --  gnatcheck ASIS utilities.

   package Gnatcheck_Element_Table is new GNAT.Table (
     Table_Component_Type => Asis.Element,
     Table_Index_Type     => Natural,
     Table_Low_Bound      => 1,
     Table_Initial        => 100,
     Table_Increment      => 100,
     Table_Name           => "GNATCHECK Element List");

   -----------------------
   -- Local subprograms --
   -----------------------

   function Has_Predicate (Type_E : Entity_Id) return Boolean with
      Pre => Is_Type (Type_E);
   --  Checks if the argument denotes a subtype with dynamic predicate. Assumes
   --  the Type_E denotes a (sub)type.

   function Is_Constr_Error_Declaration (Decl : Asis.Element) return Boolean;
   function Is_Num_Error_Declaration (Decl : Asis.Element) return Boolean;
   --  Checks if the argument represents the declaration of the predefined
   --  exception Constraint_Error/Numeric_Error

   function Is_Task_Object_Declaration (Expr : Asis.Element) return Boolean;
   --  Check if the element if a declaration of (one or more) task object(s)
   --  Returns False for any unexpected object
   --
   --  Expected Declaration_Kinds:
   --       A_Variable_Declaration
   --       A_Constant_Declaration

   function Get_Called_Task (Call : Asis.Element) return Asis.Element;
   pragma Unreferenced (Get_Called_Task);
   --  Provided that Is_Task_Entry_Call (Call) computes the called
   --  task.
   --  What is "the called task" for different ways of defining a task
   --  object ???

   procedure Look_For_Loop_Pre_Op
     (Element :        Asis.Element;
      Control : in out Traverse_Control;
      State   : in out Boolean);
   --  Actual for Traverse_Element instantiation.
   --  Terminates the traversal and sets State ON when visiting a loop
   --  statement. Skips traversal of declarations, expressions and simple
   --  statements

   procedure Look_For_Modular_Component_Pre_Op
     (Element :        Asis.Element;
      Control : in out Traverse_Control;
      State   : in out Boolean);
   --  Actual for Traverse_Element instantiation.
   --  Terminates the traversal and sets State ON when visiting a component
   --  declaration that defines a component of a modular type

   procedure Empty_Bool_Post_Op
     (Element :        Asis.Element;
      Control : in out Traverse_Control;
      State   : in out Boolean);
   --  Actual for Traverse_Element instantiation.
   --  Does nothing.

   procedure Look_For_Loop is new Traverse_Element
     (State_Information => Boolean,
      Pre_Operation     => Look_For_Loop_Pre_Op,
      Post_Operation    => Empty_Bool_Post_Op);
   --  Looks for a loop statement enclosed by its Element argument and sets
   --  the result of the search to its State parameter. Declarations are not
   --  searched.

   procedure Look_For_Modular_Component is new Traverse_Element
     (State_Information => Boolean,
      Pre_Operation     => Look_For_Modular_Component_Pre_Op,
      Post_Operation    => Empty_Bool_Post_Op);
   --  Looks for a component declaration that defines a component of a modular
   --  type. If such a component declaration is foubd sets State ON, otherwise
   --  State is set OFF.

   procedure Check_For_Discr_Reference
     (Element :        Asis.Element;
      Control : in out Traverse_Control;
      State   : in out Boolean);
   --  If Element is An_Identifier, checks if it is reference to discriminant;
   --  and if it is - sets State ON and terminates traversing

   procedure Check_For_Discriminant_Reference is new Traverse_Element
     (State_Information => Boolean,
      Pre_Operation     => Check_For_Discr_Reference,
      Post_Operation    => Empty_Bool_Post_Op);
   --  Checks if Element has a reference to a discriminant

   function Is_Ancestor
     (Ancestor : Entity_Id;
      Source   : Entity_Id)
      return     Boolean;
   --  Assumes that both arguments are interface type entities. Check if
   --  Ancestor is indeed an ancestor of Source

   --  The folowing stuff is needed for No_Inherited_Classwide_Pre rule. The
   --  implementation of the rule is far from being good, so this definitely
   --  needs revision at some point. At least to eliminate code duplications.

   type List_Of_Nodes is array (Natural range <>) of Node_Id;
   function Get_Overridden_Ops (Op : Asis.Element) return List_Of_Nodes;
   function Get_Overridden_Ops (Op : Entity_Id) return List_Of_Nodes;
   --  Assuming that Op is a declaration of an overridding operation, gets a
   --  full list of operations (their entity nodes) that are overridden or
   --  implemented by this declaration.
   --
   --  The Get_Overridden_Ops function that works directly on operation entity
   --  node does NOT include in the result the operation pointed by the
   --  Overridden_Operation (Op) link

   function Primitive_Owner (Op : Entity_Id) return Entity_Id;
   --  Assuming that Op is a discpatching operation, returns the type for that
   --  this operation is defined. In case of private types/extensions a private
   --  view is returned.

   function Overridden_Interface_Ops
     (Type_Entity : Entity_Id;
      Op_Entity   : Entity_Id)
      return   List_Of_Nodes;
   --  Assuming that Type_Entity is a tagged type entity node, and Op_Entity
   --  is an entity node of a primitive of this type, returns the list of
   --  interface primitibes that are implemented by Op_Entity.

   function Has_Class_Wide_Pre (Op : Entity_Id) return Boolean;
   --  Checks if Op has an explicitly defined or inherited Pre'Class attribute
   --  specified for it.

   function Contract_Contains_Pre_Class (C : Node_Id) return Boolean;
   --  Assuming that C is of N_Contract kind checks if it defines class-wide
   --  Precondition

   function Add_Scope_Name (El : Asis.Element) return String;
   --  Assumes that El is an Element where
   --  Gnatcheck.Rules.Traversing.All_Rules_Pre_Op stands now (needed to apply
   --  fast Get_Enclosing_Element instead of standard Enclosing_Element query).
   --  returns the full Ada name of the inermost scope that encloses El.
   --  Returns an empty string if there is no such scope (library-level
   --  renaming or instantiation, compilation pragmas etc.)

   function Is_Named_Scope (E : Asis.Element) return Boolean;
   --  Checks if E is a named scope (in a sense needed to add the scope name
   --  in the diagnostic message if -dJ is specified).

   function Encl_Scope_Full_Name (El : Asis.Element) return String;
   --  Returns the full expanded Ada name of a scope that encloses El (not
   --  counting El itself if El is also a scope) with a dot character appended.
   --  Return an empty string if El is a library-level declaration

   function Overloading_Index (El : Asis.Element) return String;
   --  Assuming that Is_Named_Scope (El), and that El is a subprogram body,
   --  checks if there are other subprograms in the same declarative region
   --  that overloads this subprogram and precedes this one. If there are some,
   --  returns string of the forms "#n" where 'n' is a positional number of
   --  this subprogram in sequence of overloaded subprograms, otherwise an
   --  empty string is returned. Note, that when computing this chain and
   --  detecting this number, we do not consider subprogram body/stub/renaming
   --  declarations that are completions of other declarations, that is we are
   --  trying to follow the compiler's way of computing this suffix if -gnatdJ
   --  is set.

   --------------------
   -- Add_Scope_Name --
   --------------------

   function Add_Scope_Name (El : Asis.Element) return String is
      Step_Up         : Elmt_Idx     := 0;
      Enclosing_Scope : Asis.Element := Nil_Element;
      EE              : Asis.Element := El;
   begin
      while not Is_Nil (EE) loop
         if Is_Named_Scope (EE) then
            Enclosing_Scope := EE;
            exit;
         end if;

         EE      := Get_Enclosing_Element (Step_Up);
         Step_Up := Step_Up + 1;
      end loop;

      if Is_Nil (Enclosing_Scope) then
         return "";
      else
         return Encl_Scope_Full_Name (Enclosing_Scope)                 &
                To_String
                  (Defining_Name_Image (First_Name (Enclosing_Scope))) &
                Overloading_Index (Enclosing_Scope)                    &
                ":" & Build_GNAT_Location (Enclosing_Scope, 0, 0);
      end if;

   end Add_Scope_Name;

   ---------------------------
   -- Can_Cause_Side_Effect --
   ---------------------------

   function Can_Cause_Side_Effect (El : Asis.Element) return Boolean is
      Arg_Kind : constant Flat_Element_Kinds := Flat_Element_Kind (El);
      Result   :          Boolean := False;
   begin
      --  !!! Only partial implementation for now!!!

      case Arg_Kind is
         when An_Assignment_Statement    |
              A_Procedure_Call_Statement |
              A_Function_Call            =>
            --  What about entry calls???
            Result := True;
--         when =>
         when others =>
            null;
      end case;

      return Result;
   end Can_Cause_Side_Effect;

   ----------------------------------------------
   -- Call_To_Complicated_Cuncurrent_Structure --
   ----------------------------------------------

   function Call_To_Complicated_Cuncurrent_Structure
     (Call : Asis.Element)
      return Boolean
   is
      Arg_Kind    : constant Flat_Element_Kinds := Flat_Element_Kind (Call);
      Result      : Boolean                     := True;
      Called_Pref : Asis.Element                := Nil_Element;
      Called_Obj  : Asis.Element                := Nil_Element;
      Tmp_El      : Asis.Element;
   begin

      case Arg_Kind is
         when An_Entry_Call_Statement    |
             A_Procedure_Call_Statement =>
            Called_Pref := Called_Name (Call);

            if Arg_Kind = An_Entry_Call_Statement
             and then
               Flat_Element_Kind (Called_Pref) = An_Indexed_Component
            then
               --  Call to an entry from an entry family
               Called_Pref := Prefix (Called_Pref);
            end if;

         when A_Function_Call =>
            Called_Pref := Prefix (Call);
         when others =>
            null;
      end case;

      --  Called_Pref should be of A_Selected_Component kind. We are interested
      --  in task or protected object now

      if Flat_Element_Kind (Called_Pref) = A_Selected_Component then
         Called_Pref := Prefix (Called_Pref);

         if Flat_Element_Kind (Called_Pref) = A_Selected_Component then
            Called_Pref := Selector (Called_Pref);
         end if;

      end if;

      if Expression_Kind (Called_Pref) = An_Identifier then

         begin
            Called_Obj := Corresponding_Name_Definition (Called_Pref);
         exception
            when others =>
               Called_Obj := Nil_Element;
         end;

      end if;

      if not Is_Nil (Called_Obj) then
         Tmp_El := Enclosing_Element (Called_Obj);

         case Declaration_Kind (Tmp_El) is
            when A_Single_Task_Declaration .. A_Single_Protected_Declaration =>
               Result := False;

            when A_Variable_Declaration | A_Constant_Declaration =>
               Tmp_El := Object_Declaration_View (Tmp_El);

               Tmp_El := Asis.Definitions.Subtype_Mark (Tmp_El);

               if Expression_Kind (Tmp_El) = A_Selected_Component then
                  Tmp_El := Selector (Tmp_El);
               end if;

               Tmp_El := Corresponding_Name_Declaration (Tmp_El);

               --  Now we check that the type of the object is a task or
               --  protected type

               Tmp_El := Corresponding_First_Subtype (Tmp_El);

               --  We can n0t have a private type here.

               if Declaration_Kind (Tmp_El) in
                 A_Task_Type_Declaration .. A_Protected_Type_Declaration
               then
                  Result := False;
               else
                  Tmp_El := Type_Declaration_View (Tmp_El);

                  if Asis.Elements.Type_Kind (Tmp_El) =
                    A_Derived_Type_Definition
                  then
                     Tmp_El := Corresponding_Root_Type (Tmp_El);

                     if Declaration_Kind (Tmp_El) in
                       A_Task_Type_Declaration .. A_Protected_Type_Declaration
                     then
                        Result := False;
                     end if;

                  end if;
               end if;

            when others =>
               null;
         end case;

      end if;

      return Result;
   end Call_To_Complicated_Cuncurrent_Structure;

   -----------------------------------
   -- Can_Be_Replaced_With_Function --
   -----------------------------------

   function Can_Be_Replaced_With_Function
     (Decl : Asis.Element)
      return Boolean
   is
      Out_Par : Asis.Element := Nil_Element;
      Result  : Boolean := False;
   begin

      case Declaration_Kind (Decl) is
         when A_Procedure_Declaration         |
              A_Procedure_Body_Declaration    |
              A_Procedure_Body_Stub           |
              A_Generic_Procedure_Declaration |
              A_Formal_Procedure_Declaration  =>

            declare
               Params : constant Asis.Element_List := Parameter_Profile (Decl);
            begin

               for J in Params'Range loop

                  case Mode_Kind (Params (J)) is
                     when An_Out_Mode =>

                        if Names (Params (J))'Length > 1 then
                           Result := False;
                           exit;
                        end if;

                        if Is_Nil (Out_Par) then
                           Out_Par := Object_Declaration_View (Params (J));

                           if Definition_Kind (Out_Par) =
                                 An_Access_Definition
                           then
                              Result := True;
                           else
                              --  If we are here, Out_Par represents a subtype
                              --  mark
                              Result := not Is_Limited (Out_Par);

                              exit when not Result;

                           end if;

                        else
                           Result := False;
                           exit;
                        end if;

                     when An_In_Out_Mode =>
                        Result := False;
                        exit;
                     when others =>
                        null;
                  end case;

               end loop;

            end;

         when others =>
            null;
      end case;

      return Result;
   end Can_Be_Replaced_With_Function;

   ---------------------
   -- Changed_Element --
   ---------------------

   function Changed_Element (El : Asis.Element) return Asis.Element is
      Arg_Elem :          Asis.Element       := El;
      Arg_Kind : constant Flat_Element_Kinds := Flat_Element_Kind (El);
      Result   :          Asis.Element       := Nil_Element;
   begin

      --  Problem with access types!!!???

      case Arg_Kind is
         when An_Identifier =>
            --  Nothing to do:
            null;
         when A_Selected_Component =>
            Arg_Elem := Get_Whole_Object (Arg_Elem);

         when An_Indexed_Component    |
              A_Slice                 |
              An_Explicit_Dereference =>

            while not (Expression_Kind (Arg_Elem) = A_Selected_Component
                   or else
                       Expression_Kind (Arg_Elem) = An_Identifier)
            loop
               Arg_Elem := Prefix (Arg_Elem);
            end loop;

            if Expression_Kind (Arg_Elem) = A_Selected_Component then
               Arg_Elem := Get_Whole_Object (Arg_Elem);
            end if;

         when A_Type_Conversion =>
            return Changed_Element (Converted_Or_Qualified_Expression (El));

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

      if Expression_Kind (Arg_Elem) = An_Identifier then
         Result := Corresponding_Name_Definition (Arg_Elem);
      else
         Result := Arg_Elem;
      end if;

      return Result;
   end Changed_Element;

   -----------------------------------
   -- Check_Classwide_Pre_Vioaltion --
   -----------------------------------

   procedure Check_Classwide_Pre_Vioaltion
     (Op       : Asis.Element;
      Detected : out Boolean;
      At_SLOC  : out String_Loc)
   is
      Overridden_Ops : constant List_Of_Nodes := Get_Overridden_Ops (Op);
      Template_El    : Asis.Element := Nil_Element;
   begin
      Detected := False;
      At_SLOC := Nil_String_Loc;

      for J in Overridden_Ops'Range loop
         if not Has_Class_Wide_Pre (Overridden_Ops (J)) then
            Detected := True;
            Set_Encl_Unit_Id (Template_El, Encl_Unit_Id (Op));
            Set_Node (Template_El, Overridden_Ops (J));
            At_SLOC :=
              Enter_String ("%1%" & Build_GNAT_Location (Template_El));
            exit;
         end if;
      end loop;

   end Check_Classwide_Pre_Vioaltion;

   -------------------------------
   -- Check_For_Discr_Reference --
   -------------------------------

   procedure Check_For_Discr_Reference
     (Element :        Asis.Element;
      Control : in out Traverse_Control;
      State   : in out Boolean)
   is
   begin

      case Expression_Kind (Element) is
         when An_Identifier =>

            begin
               if Declaration_Kind (Corresponding_Name_Declaration (Element)) =
                    A_Discriminant_Specification
               then
                  State   := True;
                  Control := Terminate_Immediately;
               end if;
            exception
               when Asis.Exceptions.ASIS_Inappropriate_Element =>
                  null;
            end;

         when Not_An_Expression =>
            null;
         when others =>
            Control := Abandon_Children;
      end case;

   end Check_For_Discr_Reference;

   ----------------------------------------
   -- Constraint_Depends_On_Discriminant --
   ----------------------------------------

   function Constraint_Depends_On_Discriminant
     (Constr : Asis.Element)
      return   Boolean
   is
      Control : Traverse_Control := Continue;
      Result  : Boolean          := False;
   begin

      if Constraint_Kind (Constr) in
           An_Index_Constraint | A_Discriminant_Constraint
      then
         Check_For_Discriminant_Reference
           (Element => Constr, Control => Control, State => Result);
      end if;

      return Result;
   end Constraint_Depends_On_Discriminant;

   -------------------
   -- Contains_Loop --
   -------------------

   function Contains_Loop (El : Asis.Element) return Boolean is
      Control : Traverse_Control := Continue;
      Result  : Boolean          := False;

      Comps : constant Asis.Element_List := Components (El);
   begin

      --  We can not just apply Look_For_Loop tp El - if El itself is a loop
      --  statement, then Result will alvays be True:
      for J in Comps'Range loop
         Look_For_Loop (Comps (J), Control, Result);
         exit when Result;
      end loop;

      return Result;

   end Contains_Loop;

   --------------------------------
   -- Contains_Modular_Component --
   --------------------------------

   function Contains_Modular_Component
     (Type_Decl : Asis.Element)
      return      Boolean
   is
      Result  : Boolean := False;
      Tmp     : Asis.Element;
      Control : Traverse_Control := Continue;
   begin
      if Declaration_Kind (Type_Decl) /= An_Ordinary_Type_Declaration then
         return False;
      end if;

      Tmp := Discriminant_Part (Type_Decl);

      if Definition_Kind (Tmp) = A_Known_Discriminant_Part then
         declare
            Discrs : constant Asis.Element_List := Discriminants (Tmp);
         begin
            for J in Discrs'Range loop
               Tmp := Object_Declaration_View (Discrs (J));

               if Flat_Element_Kind (Tmp) not in Flat_Access_Definition_Kinds
                 and then
                  Is_Modular_Type (Tmp)
               then
                  Result := True;
                  exit;
               end if;
            end loop;
         end;
      end if;

      if not Result then
         Tmp := Type_Declaration_View (Type_Decl);

         Look_For_Modular_Component
           (Element => Tmp,
           Control  => Control,
           State    => Result);
      end if;

      return Result;
   end Contains_Modular_Component;

   ---------------------------------
   -- Contract_Contains_Pre_Class --
   ---------------------------------

   function Contract_Contains_Pre_Class (C : Node_Id) return Boolean is
      Result   : Boolean := False;
      N_Pragma : Node_Id;
   begin
      pragma Assert (Nkind (C) = N_Contract);

      N_Pragma := Pre_Post_Conditions (C);

      while Present (N_Pragma) loop

         if Chars (Pragma_Identifier (N_Pragma)) = Name_Precondition
          and then
            Class_Present (N_Pragma)
         then
            Result := True;
            exit;
         end if;

         N_Pragma := Next_Pragma (N_Pragma);
      end loop;

      return Result;
   end Contract_Contains_Pre_Class;

   ------------------------------------
   -- Corresponding_Protected_Object --
   ------------------------------------

   function Corresponding_Protected_Object
     (Pref : Asis.Element)
      return Asis.Element
   is
      Tmp    : Asis.Element := Pref;
      Result : Asis.Element := Nil_Element;
   begin

      if Expression_Kind (Tmp) = A_Function_Call then
         Tmp := Prefix (Tmp);
      else
         Tmp := Called_Name (Tmp);
      end if;

      --  At the moment the simplest case only is implemented: we can process
      --  only the argument Element of the form P_Obj_Name.P_Op_Name

      if Expression_Kind (Tmp) = A_Selected_Component then
         Tmp := Prefix (Tmp);

         if Expression_Kind (Tmp) = A_Selected_Component then
            Tmp := Selector (Tmp);
         end if;

         pragma Assert (Expression_Kind (Tmp) = An_Identifier);

         Result := Corresponding_Name_Definition (Tmp);

         if Declaration_Kind (Enclosing_Element (Result)) =
            A_Single_Protected_Declaration
         then
            Result := Enclosing_Element (Result);
         end if;

      end if;

      pragma Assert (not Is_Nil (Result));

      return Result;

   end Corresponding_Protected_Object;

   -----------------------------------
   -- Declaration_Of_Renamed_Entity --
   -----------------------------------

   function Declaration_Of_Renamed_Entity
     (R    : Asis.Element)
      return Asis.Element
   is
      Arg_Element : Asis.Element := Renamed_Entity (R);
      Result      : Asis.Element := Nil_Element;
   begin

      if Expression_Kind (Arg_Element) = A_Selected_Component then
         Arg_Element := Selector (Arg_Element);
      end if;

      case Expression_Kind (Arg_Element) is
         when An_Identifier          |
              An_Operator_Symbol     |
              A_Character_Literal    |
              An_Enumeration_Literal =>
            Result := Corresponding_Name_Declaration (Arg_Element);
         when others =>
            null;
      end case;

      return Result;
   exception
      when others =>
         return Nil_Element;
   end Declaration_Of_Renamed_Entity;

   ------------------------
   -- Defines_Components --
   ------------------------

   function Defines_Components (Decl : Asis.Element) return Boolean is
      Type_Def : Asis.Element;
      Result   : Boolean := False;
   begin

      if Declaration_Kind (Decl) = An_Ordinary_Type_Declaration then

         Type_Def := Type_Declaration_View (Decl);

         case Asis.Elements.Type_Kind (Type_Def) is
            when A_Derived_Record_Extension_Definition |
                 A_Record_Type_Definition              |
                 A_Tagged_Record_Type_Definition       =>
               Result := True;
            when others =>
               null;
         end case;

      end if;

      return Result;

   end Defines_Components;

   ----------------------------
   -- Denotes_Access_Subtype --
   ----------------------------

   function Denotes_Access_Subtype (N : Asis.Element) return Boolean is
   begin
      return Ekind (Node (N)) in Access_Kind;
   end Denotes_Access_Subtype;

   --------------------------------
   -- Denotes_Class_Wide_Subtype --
   --------------------------------

   function Denotes_Class_Wide_Subtype (N : Asis.Element) return Boolean is
      E      : Entity_Id;
      Result : Boolean := False;
   begin

      E := R_Node (N);

      if Nkind (E) in  N_Expanded_Name | N_Identifier then
         E := Entity (E);

         if Present (E) then
            Result := Ekind (E) = E_Class_Wide_Subtype;
         end if;
      end if;

      return Result;
   end Denotes_Class_Wide_Subtype;

   ------------------------------------
   -- Denotes_Subtype_With_Predicate --
   ------------------------------------

   function Denotes_Subtype_With_Predicate
     (E    : Asis.Element)
      return Boolean
   is
      Result : Boolean := False;
      N      : Node_Id;
      E_Id   : Entity_Id;
   begin
      if Expression_Kind (E) not in An_Identifier | A_Selected_Component then
         return False;
      end if;

      N := R_Node (E);

      if Nkind (N) in N_Has_Entity then
         E_Id := Entity (N);

         Result := Present (E_Id)
                 and then
                   Is_Type (E_Id)
                 and then
                   Has_Predicate (E_Id);
      end if;

      return Result;
   end Denotes_Subtype_With_Predicate;

   ---------------------------
   -- Empty_Bool_Post_Op --
   ---------------------------

   procedure Empty_Bool_Post_Op
     (Element :        Asis.Element;
      Control : in out Traverse_Control;
      State   : in out Boolean)
   is
      pragma Unreferenced (Element, Control, State);
   begin
      null;
   end Empty_Bool_Post_Op;

   --------------------------
   -- Encl_Scope_Full_Name --
   --------------------------

   function Encl_Scope_Full_Name (El : Asis.Element) return String is
      Encl_Scope : Asis.Element := Enclosing_Element (El);
   begin
      while not Is_Nil (Encl_Scope)
          and then
            not Is_Named_Scope (Encl_Scope)
      loop
         Encl_Scope := Enclosing_Element (Encl_Scope);
      end loop;

      if Is_Nil (Encl_Scope) then
         return "";
      else
         return Encl_Scope_Full_Name (Encl_Scope)                         &
                To_String (Defining_Name_Image (First_Name (Encl_Scope))) &
                '.';
      end if;

   end Encl_Scope_Full_Name;

   --------------------
   -- Enclosing_List --
   --------------------

   function Enclosing_List return Asis.Element_List is
      EE : constant Asis.Element := Get_Enclosing_Element;
   begin

      if Is_Nil (EE) then
         return Nil_Element_List;
      else
         return Components (EE);
      end if;

   end Enclosing_List;

   --------------------------
   -- Entity_From_Rep_Item --
   --------------------------

   function Entity_From_Rep_Item
     (Rep_Item : Asis.Element)
      return     Asis.Element
   is
      Ent_Name : Asis.Element;
   begin
      if not Is_Representation_Item (Rep_Item) then
         Raise_ASIS_Inappropriate_Element
           (Diagnosis =>
              "Gnatcheck.ASIS_Utilities.Is_Representation_Item",
            Wrong_Kind => Int_Kind (Rep_Item));
      end if;

      if Clause_Kind (Rep_Item) = A_Representation_Clause then
         Ent_Name := Representation_Clause_Name (Rep_Item);
      else
         declare
            Params : constant Asis.Element_List :=
              Pragma_Argument_Associations (Rep_Item);
         begin
            Ent_Name := Params (Params'First);
            Ent_Name := Actual_Parameter (Ent_Name);
         end;

      end if;

      Ent_Name := Normalize_Reference (Ent_Name);

      return Corresponding_Name_Declaration (Ent_Name);
   end Entity_From_Rep_Item;

   ---------------------------------
   -- From_Subtype_With_Predicate --
   ---------------------------------

   function From_Subtype_With_Predicate
     (E    : Asis.Element)
      return Boolean
   is
      Result : Boolean := False;
      N      : Node_Id;
      E_Id   : Entity_Id;
   begin
      N := R_Node (E);

      if Nkind (N) in N_Has_Etype then
         E_Id := Etype (N);

         Result := Present (E_Id)
                 and then
                   Is_Type (E_Id)
                 and then
                   Has_Predicate (E_Id);
      end if;

      return Result;
   end From_Subtype_With_Predicate;

   -----------------------
   -- Full_View_Visible --
   -----------------------

   function Full_View_Visible
     (Type_Decl : Asis.Declaration;
      At_Place  : Asis.Element)
      return      Boolean
   is
      Result              : Boolean := False;
      Full_View           : Asis.Declaration;
      Enclosing_Pack_Spec : Asis.Declaration;
      Enclosing_Pack_Body : Asis.Declaration;

      Type_Spec_CU     : Asis.Compilation_Unit;
      Type_Body_CU     : Asis.Compilation_Unit := Nil_Compilation_Unit;
      Location_CU      : Asis.Compilation_Unit;
      Next_Parent      : Asis.Compilation_Unit;

      Stub_El          : Asis.Element;
   begin
      --  First, check if we have expected elements and return False if we
      --  do not.

      if Declaration_Kind (Type_Decl) not in
           A_Private_Type_Declaration .. A_Private_Extension_Declaration
        or else
         Is_Part_Of_Implicit (Type_Decl)
        or else
         Is_Part_Of_Implicit (At_Place)
        or else
         Is_Part_Of_Instance (Type_Decl)
        or else
         Is_Part_Of_Instance (At_Place)
      then
         return False;
      end if;

      Full_View           := Corresponding_Type_Declaration (Type_Decl);
      Enclosing_Pack_Spec := Enclosing_Element (Type_Decl);
      Enclosing_Pack_Body := Corresponding_Body (Enclosing_Pack_Spec);

      if Declaration_Kind (Enclosing_Pack_Body) = A_Package_Body_Stub then
         Enclosing_Pack_Body := Corresponding_Subunit (Enclosing_Pack_Body);
      end if;

      Type_Spec_CU := Enclosing_Compilation_Unit (Enclosing_Pack_Spec);
      Location_CU  := Enclosing_Compilation_Unit (At_Place);

      if not Is_Nil (Enclosing_Pack_Body) then
         Type_Body_CU := Enclosing_Compilation_Unit (Enclosing_Pack_Body);
      end if;

      --  Type declaration and location to check are in the same CU:

      if Is_Equal (Type_Spec_CU, Location_CU) then
         if In_Private_Part (Enclosing_Pack_Spec, At_Place) then
            Result := Before (Full_View, At_Place);
         elsif Is_Equal (Type_Body_CU, Location_CU) then
            Result :=
              Inclides (Whole => Enclosing_Pack_Body, Part => At_Place);
         end if;

         return Result;
      end if;

      --  If we are here, then type declaration and location to check are
      --  in different compilation units. First, check if location is in
      --  the body of the package that defines the type. (Subunits are a
      --  pain in this case)

      if not Is_Nil (Type_Body_CU) then

         if not Is_Equal (Type_Body_CU, Location_CU) then

            if Unit_Kind (Location_CU) in A_Subunit then
               Stub_El := Unit_Declaration (Location_CU);
               Stub_El := Corresponding_Body_Stub (Stub_El);
            end if;

            while Unit_Kind (Location_CU) in A_Subunit loop
               exit when Is_Equal (Type_Body_CU, Location_CU);

               Stub_El     := Unit_Declaration (Location_CU);
               Stub_El     := Corresponding_Body_Stub (Stub_El);
               Location_CU := Corresponding_Subunit_Parent_Body (Location_CU);

            end loop;

         else
            Stub_El := At_Place;
         end if;

         if Is_Equal (Type_Body_CU, Location_CU) then
            Result := Inclides (Whole => Enclosing_Pack_Body, Part => Stub_El);
            return Result;
         end if;

      end if;

      --  If we are here, the only possibility when the full view is visible
      --  at a given place is:
      --
      --  - Type_Decl is declared in a visible part of a library package
      --
      --  - At_Place is either in the child unit of this package - either in
      --    the body, or in the private part of the public child, or in the
      --    spec of a private child.

      if (Unit_Kind (Type_Spec_CU) = A_Package
         or else
          Unit_Kind (Type_Spec_CU) = A_Generic_Package)
        and then
          Is_Equal (Enclosing_Element (Type_Decl),
                    Unit_Declaration (Type_Spec_CU))
      then

         while Unit_Kind (Location_CU) in A_Subunit loop
            Location_CU := Corresponding_Subunit_Parent_Body (Location_CU);
         end loop;

         Next_Parent := Location_CU;

         while not Is_Nil (Next_Parent) loop
            exit when Is_Equal (Next_Parent, Type_Spec_CU);
            Next_Parent := Corresponding_Parent_Declaration (Next_Parent);
         end loop;

         if not Is_Equal (Next_Parent, Type_Spec_CU) then
            return False;
         elsif Unit_Kind (Location_CU) in A_Library_Unit_Body then
            return True;
         elsif Unit_Kind (Location_CU) in
                 A_Procedure          |
                 A_Function           |
                 A_Generic_Procedure  |
                 A_Generic_Function   |
                 A_Procedure_Instance |
                 A_Function_Instance  |
                 A_Package_Instance   |
                 A_Procedure_Renaming |
                 A_Function_Renaming
         then
            return False;

         elsif Unit_Kind (Location_CU) = A_Package
             or else
                Unit_Kind (Location_CU) = A_Generic_Package
         then
            if Unit_Class (Location_CU) = A_Private_Declaration
              and then
               Is_Equal (Corresponding_Parent_Declaration (Location_CU),
                         Type_Spec_CU)
            then
               return True;
            else
               Result :=
                 In_Private_Part (Pack    => Unit_Declaration (Location_CU),
                                  Element => At_Place);
               return Result;
            end if;
         end if;

         pragma Assert (False);
         return False;
      end if;

      return False;
   end Full_View_Visible;

   ----------------------
   -- Get_Associations --
   ----------------------

   function Get_Associations (El : Asis.Element) return Asis.Element_List is
   begin

      case Flat_Element_Kind (El) is
         when A_Record_Aggregate     |
              An_Extension_Aggregate =>
            return Record_Component_Associations (El);
         when A_Positional_Array_Aggregate |
              A_Named_Array_Aggregate      =>
            return Array_Component_Associations (El);
--         when  =>
--            return  (El);
         when others =>
            return Nil_Element_List;
      end case;

   end Get_Associations;

   ----------------------
   -- Get_Call_Element --
   ----------------------

   function Get_Call_Element return Asis.Element is
      Steps_Up     : Elmt_Idx := 0;
      Result       : Asis.Element := Get_Enclosing_Element (Steps_Up);
   begin
      loop
         exit when
            Expression_Kind (Result) = A_Function_Call
           or else
            Element_Kind (Result) /= An_Expression;

         Steps_Up := Steps_Up + 1;
         Result   := Get_Enclosing_Element (Steps_Up);
      end loop;

      return Result;
   end Get_Call_Element;

   ---------------------
   -- Get_Called_Task --
   ---------------------

   function Get_Called_Task (Call : Asis.Element) return Asis.Element is
      Result : Asis.Element := Nil_Element;
      Tmp    : Asis.Element;
      Tmp1   : Asis.Element;
   begin
      --  For now - the simplest case. We consider that the prefix has
      --  the form of Task_Name.Entry_Name

      Tmp := Called_Name (Call);

      if Expression_Kind (Tmp) = An_Indexed_Component then
         --  A call to an entry from an entry family
         Tmp := Prefix (Tmp);
      end if;

      if Expression_Kind (Tmp) = A_Selected_Component then
         Tmp := Prefix (Tmp);

         if Expression_Kind (Tmp) = A_Selected_Component then
            Tmp := Asis.Expressions.Selector (Tmp);
         end if;

         Tmp := Corresponding_Name_Definition (Tmp);

         if not Is_Nil (Tmp) then
            --  For a task declared by a single task declaration we return this
            --  single task declaration, otherwise we return a task defining
            --  identifier
            Tmp1 := Enclosing_Element (Tmp);

            if Declaration_Kind (Tmp1) = A_Single_Task_Declaration then
               Tmp := Tmp1;
            end if;

            Result := Tmp;
         end if;

      end if;

      pragma Assert (not Is_Nil (Result));
      --  A null result requires a special processing, so for the development
      --  period we just blow up

      return Result;
   end Get_Called_Task;

   -----------------
   -- Get_Choices --
   -----------------

   function Get_Choices (El : Asis.Element) return Asis.Element_List is
   begin

      case Association_Kind (El) is
         when An_Array_Component_Association =>
            return Array_Component_Choices (El);
         when A_Record_Component_Association =>
            return Record_Component_Choices (El);
         when others =>
            return Nil_Element_List;
      end case;

   end Get_Choices;

   ----------------------------------
   -- Get_Corresponding_Definition --
   ----------------------------------

   function Get_Corresponding_Definition
     (El   : Asis.Element)
      return Asis.Element
   is
      Arg_Kind : constant Expression_Kinds := Expression_Kind (El);
      Result   : Asis.Element;
   begin

      if not (Arg_Kind = An_Identifier
             or else
              Arg_Kind = An_Operator_Symbol
             or else
              Arg_Kind = A_Character_Literal
             or else
              Arg_Kind = An_Enumeration_Literal)
      then
         --  To avoid junk use of this query
         Raise_ASIS_Inappropriate_Element
           (Diagnosis =>
              "Gnatcheck.ASIS_Utilities.Get_Corresponding_Definition",
            Wrong_Kind => Int_Kind (El));
      end if;

      begin
         Result := Corresponding_Name_Definition (El);
      exception
         when Asis.Exceptions.ASIS_Inappropriate_Element =>
            Result := Nil_Element;
      end;

      return Result;
   end Get_Corresponding_Definition;

   -----------------------------
   -- Get_Encl_Protected_Body --
   -----------------------------

   function Get_Encl_Protected_Body return Asis.Element is
      Result  : Asis.Element := Nil_Element;
      Step_Up : Elmt_Idx     := 0;
      Tmp     : Asis.Element := Get_Enclosing_Element (Step_Up);
   begin

      while not Is_Nil (Tmp) loop

         if Declaration_Kind (Tmp) = A_Protected_Body_Declaration then
            Result := Tmp;
            exit;
         end if;

         Step_Up := Step_Up + 1;
         Tmp := Get_Enclosing_Element (Step_Up);

      end loop;

      return Result;
   end Get_Encl_Protected_Body;

   ------------------
   -- Get_Handlers --
   ------------------

   function Get_Handlers
     (El              : Asis.Element;
      Include_Pragmas : Boolean := False)
      return            Asis.Element_List
   is
   begin

      case Flat_Element_Kind (El) is
         when A_Procedure_Body_Declaration |
              A_Function_Body_Declaration  |
              A_Package_Body_Declaration   |
              An_Entry_Body_Declaration    |
              A_Task_Body_Declaration      =>
            return Body_Exception_Handlers (El, Include_Pragmas);

         when A_Block_Statement =>
            return Block_Exception_Handlers (El, Include_Pragmas);

         when An_Extended_Return_Statement =>
            return Extended_Return_Exception_Handlers (El, Include_Pragmas);

         when An_Accept_Statement =>
            return Accept_Body_Exception_Handlers (El, Include_Pragmas);

         when others =>
            return Nil_Element_List;
      end case;

   end Get_Handlers;

   -------------------------
   -- Get_Name_Definition --
   -------------------------

   function Get_Name_Definition (Ref : Asis.Element) return Asis.Element is
      Result : Asis.Element := Normalize_Reference (Ref);
   begin

      Result := Corresponding_Name_Definition (Result);

      if Declaration_Kind (Enclosing_Element (Result)) in
           A_Renaming_Declaration
      then
         Result := Corresponding_Base_Entity (Enclosing_Element (Result));
         Result := Normalize_Reference (Result);
         Result := Corresponding_Name_Definition (Result);
      end if;

      return Result;
   end Get_Name_Definition;

   -----------------
   -- Get_Obj_Dcl --
   -----------------

   function Get_Obj_Dcl (El : Asis.Element) return Asis.Element is
      Result : Asis.Element := Nil_Element;
   begin
      case Flat_Element_Kind (El) is
         when A_Function_Call =>
            null;
         when An_Identifier =>
            Result := Corresponding_Name_Declaration (El);
         when An_Explicit_Dereference |
              An_Indexed_Component    |
              A_Slice                 =>
            Result := Get_Obj_Dcl (Prefix (El));
         when A_Selected_Component =>
            --  The hard case: A.B may be the reference to the variable B
            --  declared in package A, or it may be the reference to the
            --  component B of a record object A

            Result := Corresponding_Name_Declaration (Selector (El));

            if Declaration_Kind (Result) = A_Component_Declaration then
               Result := Get_Obj_Dcl (Prefix (El));
            end if;

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

      if Declaration_Kind (Result) = An_Object_Renaming_Declaration then
         Result := Get_Obj_Dcl (Renamed_Entity (Result));
      end if;

      return Result;
   end Get_Obj_Dcl;

   ------------------------
   -- Get_Overridden_Ops --
   ------------------------

   function Get_Overridden_Ops (Op : Entity_Id) return List_Of_Nodes is
      Type_Entity : Entity_Id := Primitive_Owner (Op);
   begin
      if Ekind (Type_Entity) in E_Private_Type         |
                                E_Limited_Private_Type
      then
         Type_Entity := Full_View (Type_Entity);
      end if;

      return Overridden_Interface_Ops (Type_Entity, Op);
   end Get_Overridden_Ops;

   function Get_Overridden_Ops (Op : Asis.Element) return List_Of_Nodes is
      Result : List_Of_Nodes (1 .. 6000);
      --  6000 looks as infinity here
      Res_Last : Natural := 0;

      Op_Entity           : constant Entity_Id := R_Node (First_Name (Op));
      Directly_Overridded :          Entity_Id;
      Type_Entity         :          Entity_Id;

      Type_Def : Asis.Element;

   begin
      if not Is_Overriding_Operation (Op) then
         return Result (1 .. 0);
      end if;

      if Present (Overridden_Operation (Op_Entity)) then
         Directly_Overridded := Overridden_Operation (Op_Entity);
         Res_Last            := Res_Last + 1;
         Result (Res_Last)   := Directly_Overridded;
      end if;

      --  Check if we may have multiple inheritance:
      Type_Def := Primitive_Owner (Op);

      if Definition_Kind (Type_Def) in
           A_Private_Type_Definition |
           A_Private_Extension_Definition
      then
         Type_Def := Enclosing_Element (Type_Def);
         Type_Def := Corresponding_Type_Completion (Type_Def);
         Type_Def := Type_Declaration_View (Type_Def);
      end if;

      if Int_Kind (Type_Def) not in
           A_Derived_Record_Extension_Definition |
           A_Private_Extension_Definition        |
           Internal_Interface_Kinds              |
           A_Formal_Derived_Type_Definition      |
           Internal_Formal_Interface_Kinds
        or else
         Is_Nil (Definition_Interface_List (Type_Def))
      then
         --  Nothing else to do!
         return Result (1 .. Res_Last);
      end if;

      Type_Def    := First_Name (Enclosing_Element (Type_Def));
      Type_Entity := R_Node (Type_Def);

      return Result (1 .. Res_Last) &
             Overridden_Interface_Ops (Type_Entity, Op_Entity);
   end Get_Overridden_Ops;

   -------------------
   -- Get_Root_Type --
   -------------------

   function Get_Root_Type (Decl : Asis.Element) return Asis.Element is
      Arg_Kind : constant Flat_Element_Kinds := Flat_Element_Kind (Decl);
      Type_Def :          Asis.Element;
      Result   :          Asis.Element;
   begin

      case Arg_Kind is
         when A_Variable_Declaration |
              A_Constant_Declaration =>
            null;
         when others =>
            Raise_ASIS_Inappropriate_Element
              (Package_Name & "Get_Root_Type",
               Wrong_Kind => Int_Kind (Decl));
      end case;

      Result := Object_Declaration_View (Decl);
      Result := Asis.Definitions.Subtype_Mark (Result);

      if Expression_Kind (Result) = A_Selected_Component then
         Result := Selector (Result);
      end if;

      Result := Corresponding_Name_Declaration (Result);

      if Declaration_Kind (Result) = A_Subtype_Declaration then
         Result := Corresponding_First_Subtype (Result);
      end if;

      if Declaration_Kind (Result) = An_Ordinary_Type_Declaration then
         Type_Def := Type_Declaration_View (Result);

         if Asis.Elements.Type_Kind (Type_Def) in
            A_Derived_Type_Definition .. A_Derived_Record_Extension_Definition
         then
            Result := Corresponding_Root_Type (Type_Def);
         end if;

      end if;

      return Result;

   end Get_Root_Type;

   -------------------------
   -- Get_Type_Components --
   -------------------------

   function Get_Type_Components
     (El                    : Asis.Element;
      Include_Discriminants : Boolean)
      return                  Asis.Element_List
   is
      Type_Def : Asis.Element;

      procedure Add_Components (Comps : Asis.Element_List);
      --  Adds record components to the result, recursively going down into
      --  variant part(s)

      procedure Add_Components (Comps : Asis.Element_List) is
      begin

         for J in Comps'Range loop

            if Declaration_Kind (Comps (J)) = A_Component_Declaration then
               Gnatcheck_Element_Table.Append (Comps (J));
            elsif Definition_Kind (Comps (J)) = A_Variant_Part then

               declare
                  Vars : constant Asis.Element_List := Variants (Comps (J));
               begin
                  for K in Vars'Range loop
                     Add_Components (Record_Components (Vars (K)));
                  end loop;
               end;

            end if;

         end loop;

      end Add_Components;

   begin
      Gnatcheck_Element_Table.Init;

      if Include_Discriminants then

         Type_Def :=  Discriminant_Part (El);

         if Definition_Kind (Type_Def) = A_Known_Discriminant_Part then

            declare
               Discr_List : constant Asis.Element_List :=
                  Discriminants (Type_Def);
            begin

               for J in Discr_List'Range loop
                  Gnatcheck_Element_Table.Append (Discr_List (J));
               end loop;

            end;

         end if;

      end if;

      Type_Def := Type_Declaration_View (El);

      case Flat_Element_Kind (Type_Def) is
         when A_Protected_Definition =>

            declare
               Items : constant Asis.Element_List :=
                 Private_Part_Items (Type_Def);
            begin

               for J in Items'Range loop

                  if Declaration_Kind (Items (J)) =
                     A_Component_Declaration
                  then
                     Gnatcheck_Element_Table.Append (Items (J));
                  end if;

               end loop;

            end;

         when A_Derived_Type_Definition ..
              A_Derived_Record_Extension_Definition =>

            declare
               Items : constant Asis.Element_List :=
                 Implicit_Inherited_Declarations (Type_Def);
            begin

               for J in Items'Range loop

                  if Declaration_Kind (Items (J)) =
                     A_Component_Declaration
                  then
                     Gnatcheck_Element_Table.Append (Items (J));
                  end if;

               end loop;

            end;

         when others =>
            null;
      end case;

      --  Now add explicit record components, if any

      if Asis.Elements.Type_Kind (Type_Def) =
         A_Derived_Record_Extension_Definition
        or else
         Asis.Elements.Type_Kind (Type_Def) = A_Record_Type_Definition
        or else
         Asis.Elements.Type_Kind (Type_Def) = A_Tagged_Record_Type_Definition
      then
         Type_Def := Asis.Definitions.Record_Definition (Type_Def);

         if Definition_Kind (Type_Def) /= A_Null_Record_Definition then

            declare
               Comps : constant Asis.Element_List :=
                 Record_Components (Type_Def);
            begin
               Add_Components (Comps);
            end;

         end if;

      end if;

      return Asis.Element_List
        (Gnatcheck_Element_Table.Table (1 .. Gnatcheck_Element_Table.Last));
   end Get_Type_Components;

   -------------------------------------
   -- Get_Type_Decl_From_Subtype_Mark --
   -------------------------------------

   function Get_Type_Decl_From_Subtype_Mark
     (SM   : Asis.Element)
      return Asis.Element
   is
      Result : Asis.Element := SM;
   begin

      if Expression_Kind (Result) = A_Selected_Component then
         Result := Selector (Result);
      end if;

      Result := Corresponding_Name_Declaration (Result);

      if Declaration_Kind (Result) = A_Subtype_Declaration then
         Result := Corresponding_First_Subtype (Result);
      end if;

      if Declaration_Kind (Result) in
           A_Private_Type_Declaration .. A_Private_Extension_Declaration
      then
         Result := Corresponding_Type_Declaration (Result);
      end if;

      return Result;
   end Get_Type_Decl_From_Subtype_Mark;

   -------------------------
   -- Get_Underlying_Type --
   -------------------------

   function Get_Underlying_Type
     (SM              : Asis.Element;
      Stop_At_Private : Boolean := False)
      return            Asis.Element
   is
      Result : Asis.Element := Nil_Element;
      Tmp    : Asis.Element := SM;

   begin
      while Attribute_Kind (Tmp) = A_Base_Attribute loop
         Tmp := Prefix (Tmp);
      end loop;

      if Expression_Kind (Tmp) = A_Selected_Component then
         Tmp := Selector (Tmp);
      end if;

      if Expression_Kind (Tmp) = An_Identifier then
         begin
            Tmp := Corresponding_Name_Declaration (Tmp);
         exception
            when Asis.Exceptions.ASIS_Inappropriate_Element =>
               Tmp := Nil_Element;
         end;
      else
         Tmp := Nil_Element;
      end if;

      if Declaration_Kind (Tmp) in
           An_Ordinary_Type_Declaration         |
           A_Task_Type_Declaration              |
           A_Protected_Type_Declaration         |
           An_Incomplete_Type_Declaration       |
           A_Tagged_Incomplete_Type_Declaration |
           A_Private_Type_Declaration           |
           A_Private_Extension_Declaration      |
           A_Subtype_Declaration                |
           A_Formal_Type_Declaration            |
           A_Formal_Incomplete_Type_Declaration
      then
         Result := Unwind_Type (Tmp, Stop_At_Private);
      end if;

      return Result;
   end Get_Underlying_Type;

   ----------------------
   -- Get_Whole_Object --
   ----------------------

   function Get_Whole_Object (El : Asis.Element) return Asis.Element is
      Pref   : Asis.Element := El;
      --  Pref represents the (left) part of the argument name that has not
      --  been traversed yet

      Result : Asis.Element := Selector (El);
      --  The selector part of the current Pref

      procedure Step_To_The_Left;
      --  Resets the values of Pref and Result, moving them to the beginning
      --  (that is - to the left end) of the name represented by El: as a
      --  result of calling this procedure we should always have Result to be
      --  Selector (Prefix) except we are in the very beginning of El

      procedure Step_To_The_Left is
      begin
         case Expression_Kind (Pref) is
            when Not_An_Expression =>
               --  That is, Pref just is Nil_Element, and we have traversed the
               --  whole name represented by El

               Result := Nil_Element;

            when An_Identifier =>
               --  Approaching the left part of El
               Result := Pref;
               Pref   := Nil_Element;
            when A_Selected_Component =>
               Pref   := Prefix (Pref);

               if Expression_Kind (Pref) = An_Identifier then
                  Result := Pref;
                  Pref := Nil_Element;
               elsif Expression_Kind (Pref) = A_Selected_Component then
                  Result := Selector (Pref);
               else
                  pragma Warnings (Off);
                  Step_To_The_Left;
                  pragma Warnings (On);
               end if;

            when A_Slice                 |
                 An_Explicit_Dereference |
                 An_Indexed_Component    =>
               Pref := Prefix (Pref);

               pragma Warnings (Off);
               Step_To_The_Left;
               pragma Warnings (ON);

            when A_Function_Call =>
               --  A rather exotic case - a function call (or a component
               --  therteof) as a changen element...
               Result := Corresponding_Called_Function (Pref);

            when A_Type_Conversion =>

               Pref := Converted_Or_Qualified_Expression (Pref);

               pragma Warnings (Off);
               Step_To_The_Left;
               pragma Warnings (ON);

            when others =>
               Put_Line (Standard_Error, Debug_Image (Pref));

               if Is_Text_Available (Pref) then
                  Put_Line (Standard_Error, Element_Image (Pref));
               end if;

               pragma Assert (False);
         end case;

      end Step_To_The_Left;

   begin

      while not Is_Nil (Result) loop

         if Is_Function_Declaration (Result) then
            --  Actually, a more detailed analyzis is possible for this case
            exit;
         elsif No (Entity (R_Node (Result)))
           and then
            not Is_Nil (Pref)
         then
            --  We have a case of an expaded name - the Entity field is not
            --  set for a selector, but it is set for a whole expanded name.
            --  So what we now have in Result is what we are looking for:
            exit;

         elsif Is_Nil (Pref) then
            --  That means that we get to the beginning (rightmost identifier)
            --  in the expanded name. It can not be a subcomponent, so:
            exit;
         end if;

         Step_To_The_Left;

      end loop;

      return Result;
   end Get_Whole_Object;

   ------------------------
   -- Has_Address_Clause --
   ------------------------

   function Has_Address_Clause (Def_Name : Asis.Element) return Boolean is
      Object_Decl : constant Asis.Element := Enclosing_Element (Def_Name);

      Corr_Rep_Clauses : constant Asis.Element_List :=
        Corresponding_Representation_Clauses (Object_Decl);

      Result : Boolean := False;
   begin

      for J in Corr_Rep_Clauses'Range loop

         if Representation_Clause_Kind (Corr_Rep_Clauses (J)) =
            An_Attribute_Definition_Clause
           and then
             Attribute_Kind
               (Representation_Clause_Name (Corr_Rep_Clauses (J))) =
            An_Address_Attribute
           and then
             Is_Equal
               (Corresponding_Name_Definition
                 (Prefix (Representation_Clause_Name
                   (Corr_Rep_Clauses (J)))),
                Def_Name)
         then
            Result := True;
            exit;
         end if;

      end loop;

      return Result;
   end Has_Address_Clause;

   ------------------------
   -- Has_Class_Wide_Pre --
   ------------------------

   function Has_Class_Wide_Pre (Op : Entity_Id) return Boolean is
      Result : Boolean := False;
      Directly_Overridden_Op : Entity_Id := Empty;
   begin
      if Present (Contract (Op)) then
         Result := Contract_Contains_Pre_Class (Contract (Op));
      end if;

      if not Result then
         Directly_Overridden_Op := Overridden_Operation (Op);

         if Present (Directly_Overridden_Op) then
            Result := Has_Class_Wide_Pre (Directly_Overridden_Op);
         end if;

      end if;

      if not Result then

         declare
            Overridden_Ops : constant List_Of_Nodes := Get_Overridden_Ops (Op);
         begin
            for J in Overridden_Ops'Range loop
               if Overridden_Ops (J) /= Directly_Overridden_Op then
                  Result := Has_Class_Wide_Pre (Overridden_Ops (J));
               end if;

               exit when Result;
            end loop;
         end;

      end if;

      return Result;
   end Has_Class_Wide_Pre;

   -----------------------
   -- Has_One_Parameter --
   -----------------------

   function Has_One_Parameter (El : Asis.Element) return Boolean is
      Template_El : Asis.Element;
      Call_Node   : Node_Id;
      Result      : Boolean := False;
   begin

      if Expression_Kind (El) = A_Function_Call
        or else
         Statement_Kind (El) = A_Procedure_Call_Statement
        or else
         Statement_Kind (El) = An_Entry_Call_Statement
      then
         Call_Node := Node (El);

         if Nkind (Call_Node) = N_Attribute_Reference then

            if Sinfo.Expressions (Call_Node) /= No_List
              and then
               List_Length (Sinfo.Expressions (Call_Node)) = 1
            then
               Result := True;
            end if;

         else

            if Parameter_Associations (Call_Node) /= No_List
              and then
               List_Length (Parameter_Associations (Call_Node)) = 1
            then
               Result := True;
            end if;

         end if;

      elsif Declaration_Kind (El) in A_Generic_Instantiation then
         Template_El := Normalize_Reference (Generic_Unit_Name (El));
         Template_El := Corresponding_Name_Declaration (Template_El);

         if Declaration_Kind (Template_El) in
              A_Generic_Package_Renaming_Declaration ..
              A_Generic_Function_Renaming_Declaration
         then
            Template_El := Corresponding_Base_Entity (Template_El);
            Template_El := Normalize_Reference (Template_El);
            Template_El := Corresponding_Name_Declaration (Template_El);
         end if;

         Result := Generic_Formal_Part (Template_El)'Length = 1;
      end if;

      return Result;
   end Has_One_Parameter;

   --------------------------------
   -- Has_Positional_Association --
   --------------------------------

   function Has_Positional_Association (El : Asis.Element) return Boolean is
      Result : Boolean := False;
   begin

      if Expression_Kind (El) in
           A_Record_Aggregate .. An_Extension_Aggregate
         --  The condition can be extended
      then

         declare
            Associations : constant Asis.Element_List := Get_Associations (El);
         begin
            if Associations'Length > 0 then
               Result := Is_Positional (Associations (Associations'First));
            end if;
         end;

      end if;

      return Result;
   end Has_Positional_Association;

   -------------------
   -- Has_Predicate --
   -------------------

   function Has_Predicate (Type_E : Entity_Id) return Boolean is
      N      : Node_Id;
      Result : Boolean := False;
   begin
      if Has_Dynamic_Predicate_Aspect (Type_E) then
         Result := True;
      elsif Present (First_Rep_Item (Type_E)) then
         N := First_Rep_Item (Type_E);

         while Present (N) loop
            if Nkind (N) = N_Aspect_Specification
              and then
               Chars (Sinfo.Identifier (N)) in
                 Name_Dynamic_Predicate | Name_Static_Predicate
            then
               Result := True;
               exit;
            end if;

            N := Next_Rep_Item (N);
         end loop;
      end if;

      return Result;
   end Has_Predicate;

   -----------------------------
   -- Has_Range_Specification --
   -----------------------------

   function Has_Range_Specification (El : Asis.Element) return Boolean is
      Result : Boolean;
      Tmp    : Asis.Element := Type_Declaration_View (El);
      Constr : Asis.Element;
   begin
      --  The hardest case is a derived type declaration - we have to check
      --  all the chain of derivation and subtyping up to ansestor to see if
      --  there is a range constraint somewhere. So, if we use the recursion,
      --  we may have three kinds of arguments:
      --
      --   * a floating point type or a decimal fixed point type declaration;
      --   * a derived type declaration
      --   * a subtype declaration

      case Flat_Element_Kind (Tmp) is
         when A_Floating_Point_Definition      |
              A_Decimal_Fixed_Point_Definition =>
            Result := not Is_Nil (Real_Range_Constraint (Tmp));

         when A_Subtype_Indication =>
            Constr := Subtype_Constraint (Tmp);

            if Constraint_Kind (Constr) = A_Simple_Expression_Range then
               Result := True;
            else
               Tmp    := Corresponding_First_Subtype (El);
               Result := Has_Range_Specification (Tmp);
            end if;

         when A_Derived_Type_Definition =>
            Constr := Parent_Subtype_Indication (Tmp);
            Constr := Subtype_Constraint (Constr);

            if Constraint_Kind (Constr) = A_Simple_Expression_Range then
               Result := True;
            else
               Tmp    := Corresponding_Parent_Subtype (Tmp);
               Result := Has_Range_Specification (Tmp);
            end if;

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

      return Result;
   end Has_Range_Specification;

   ------------------------------
   -- Has_Statements_And_Decls --
   ------------------------------

   function Has_Statements_And_Decls (Decl : Asis.Element) return Boolean is
      Result    : Boolean := False;
   begin

      Result := not Is_Nil (Body_Statements (Decl))
              and then
                not Is_Nil (Body_Declarative_Items (Decl));

      return Result;
   end Has_Statements_And_Decls;

   ------------------------------
   -- Is_Address_Specification --
   ------------------------------

   function Is_Address_Specification (El : Asis.Element) return Boolean is
      Result : Boolean := False;
      Tmp    : Asis.Element;
   begin
      case Flat_Element_Kind (El) is
         when An_Attribute_Definition_Clause =>
            Tmp    := Representation_Clause_Name (El);
            Result := Attribute_Kind (Tmp) = An_Address_Attribute;

         when An_At_Clause =>
            Result := True;

         when An_Aspect_Specification =>
            Tmp := Aspect_Mark (El);

            if Expression_Kind (Tmp) = An_Identifier then
               Result := To_Lower_Case (Asis.Expressions.Name_Image (Tmp)) =
                           "address";
            end if;

         when others =>
            null;
      end case;

      return Result;
   end Is_Address_Specification;

   -----------------
   -- Is_Ancestor --
   -----------------

   function Is_Ancestor
     (Ancestor : Entity_Id;
      Source   : Entity_Id)
      return     Boolean
   is
      Result   : Boolean := False;
      Type_Def : Node_Id;
      Next_T   : Entity_Id;
   begin
      Result := Source = Ancestor;

      if not Result then
         --  Starting from source, go to its definition (and it should be an
         --  interface type definition!) and check Is_Ancestor for all the
         --  interfaces listed in this definition
         Next_T := Parent (Source);

         if Nkind (Next_T) = N_Private_Type_Declaration then
            --  nothing to analyze!
            return False;
         end if;

         pragma Assert (Nkind (Next_T) = N_Full_Type_Declaration);

         Type_Def := Sinfo.Type_Definition (Next_T);

         if Nkind (Type_Def) = N_Derived_Type_Definition then
            --  First element from the interface list can be reached by the
            --  Subtype_Indication (Type_Def) link, the other (if any) are
            --  the members of Interface_List (Type_Def) list

            Next_T := Sinfo.Subtype_Indication (Type_Def);
            Next_T := Entity (Next_T);

            while Present (Next_T)
                and then
                  Nkind (Parent (Next_T)) /= N_Full_Type_Declaration
                and then
                  Etype (Next_T) /= Next_T
            loop
               Next_T := Etype (Next_T);
            end loop;

            pragma Assert (Nkind (Parent (Next_T)) = N_Full_Type_Declaration);

            Result := Is_Ancestor (Ancestor, Next_T);

            if not Result
              and then
               not Is_Empty_List (Interface_List (Type_Def))
            then
               Next_T := First (Interface_List (Type_Def));

               while Present (Next_T) loop

                  Next_T := Entity (Next_T);

                  while Present (Next_T)
                      and then
                        Nkind (Parent (Next_T)) /= N_Full_Type_Declaration
                      and then
                        Etype (Next_T) /= Next_T
                  loop
                     Next_T := Etype (Next_T);
                  end loop;

                  pragma Assert (Nkind (Parent (Next_T)) =
                                 N_Full_Type_Declaration);

                  Result := Is_Ancestor (Ancestor, Next_T);

                  exit when Result;

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

         end if;

      end if;

      return Result;
   end Is_Ancestor;

   -------------
   -- Is_Body --
   -------------

   function Is_Body (El : Asis.Element) return Boolean is
      Result : Boolean := False;
   begin

      case Flat_Element_Kind (El) is
         when A_Procedure_Body_Declaration |
              A_Function_Body_Declaration  |
              A_Package_Body_Declaration   |
              A_Task_Body_Declaration      |
              An_Entry_Body_Declaration    =>
            Result := True;
         when  others =>
            null;
      end case;

      return Result;

   end Is_Body;

   ---------------------------
   -- Is_Boolean_Logical_Op --
   ---------------------------

   function Is_Boolean_Logical_Op (Op : Asis.Element) return Boolean is
      Entity_N : Entity_Id;
      Call     : Asis.Element;
      Arg_Node : Node_Id := Node (Op);
      Result   : Boolean := False;
   begin

      if Operator_Kind (Op) in An_And_Operator .. An_Xor_Operator then

         Call := Enclosing_Element (Op);

         if Is_Prefix_Call (Call) then
            Arg_Node := R_Node (Call);
         end if;

         if Nkind (Arg_Node) in N_Type_Conversion | N_Qualified_Expression
           and then
            not Comes_From_Source (Arg_Node)
         then
            --  Implicit conversion/qyulification added by front-end
            Arg_Node := Sinfo.Expression (Arg_Node);
         end if;

         if Nkind (Arg_Node) = N_Op_And
           or else
            Nkind (Arg_Node) = N_Op_Or
           or else
            Nkind (Arg_Node) = N_Op_Xor
         then
            Entity_N := Entity (Arg_Node);

            if Present (Entity_N)
              and then
               Sloc (Entity_N) <= Standard_Location
              and then
               Ekind (Etype (Arg_Node)) = E_Enumeration_Type
            then
               Result := True;
            end if;
         end if;

      end if;

      return Result;
   end Is_Boolean_Logical_Op;

   ----------------------------------
   -- Is_Call_To_Operator_Function --
   ----------------------------------

   function Is_Call_To_Operator_Function (El : Asis.Element) return Boolean is
      Pref   : Asis.Element;
      Result : Boolean := False;
   begin

      if Expression_Kind (El) = A_Function_Call then

         if not Is_Prefix_Call (El) then
            Result := True;
         else
            Pref := Prefix (El);

            if Expression_Kind (Pref) = A_Selected_Component then
               Pref := Selector (Pref);
            end if;

            Result := Expression_Kind (Pref) = An_Operator_Symbol;

         end if;

      end if;

      return Result;
   end Is_Call_To_Operator_Function;

   ---------------
   -- Is_Caller --
   ---------------

--   function Is_Caller (El : Asis.Element) return Boolean is
--      Spec_El : Asis.Element;
--      Result  : Boolean := False;
--   begin
--      --  Implementation is incomplete!!! ???
--      --  Protected operations is a huge hole!!!

--      case Flat_Element_Kind (El) is
--         when A_Procedure_Declaration |
--              A_Function_Declaration  =>

--            Result := Trait_Kind (El) /= An_Abstract_Trait;

--         when An_Entry_Body_Declaration =>

--            Result := True;

--         when A_Procedure_Body_Declaration |
--              A_Function_Body_Declaration  |
--              A_Procedure_Body_Stub        |
--              A_Function_Body_Stub         =>

--            Spec_El := El;

--            if Is_Subunit (El) then
--               Spec_El := Corresponding_Body_Stub (El);
--            end if;

--            Spec_El := Corresponding_Declaration (El);

--            Result :=
--              Declaration_Kind (Spec_El) not in
--                A_Generic_Procedure_Declaration ..
--                A_Generic_Function_Declaration;

--         when An_Entry_Declaration =>

--            if Definition_Kind (Get_Enclosing_Element) =
--               A_Protected_Definition
--            then
--               Result := True;
--            end if;

--         when others =>
--            null;
--      end case;

--      return Result;
--   end Is_Caller;

   -----------------
   -- Is_Constant --
   -----------------

   function Is_Constant (E : Asis.Element) return Boolean is
      Result : Boolean := False;
   begin
      if Defining_Name_Kind (E) = A_Defining_Identifier then
         Result := Ekind (Node (E)) = E_Constant;
      end if;

      return Result;
   end Is_Constant;

   ---------------------------------
   -- Is_Constr_Error_Declaration --
   ---------------------------------

   function Is_Constr_Error_Declaration (Decl : Asis.Element) return Boolean is
      Result : Boolean := False;
   begin

      if Declaration_Kind (Decl) = An_Exception_Declaration
        and then
         Is_Standard (Enclosing_Compilation_Unit (Decl))
        and then
         Defining_Name_Image (First_Name (Decl)) = "Constraint_Error"
      then
         Result := True;
      end if;

      return Result;
   end Is_Constr_Error_Declaration;

   -------------------------
   -- Is_Constraint_Error --
   -------------------------

   function Is_Constraint_Error (Ref : Asis.Element) return Boolean is
      Next_Exception_Decl : Asis.Element;

      Result : Boolean := False;
   begin
      Next_Exception_Decl := Corresponding_Name_Declaration (Ref);

      while not Is_Nil (Next_Exception_Decl) loop

         if Is_Constr_Error_Declaration (Next_Exception_Decl) then
            Result := True;
            exit;
         elsif Is_Num_Error_Declaration (Next_Exception_Decl) then
            exit;
         elsif Declaration_Kind (Next_Exception_Decl) =
               An_Exception_Renaming_Declaration
         then
            Next_Exception_Decl := Renamed_Entity (Next_Exception_Decl);
            Next_Exception_Decl := Normalize_Reference (Next_Exception_Decl);
            Next_Exception_Decl :=
              Corresponding_Name_Declaration (Next_Exception_Decl);
         else
            exit;
         end if;

      end loop;

      return Result;
   end Is_Constraint_Error;

   --------------------
   -- Is_Constructor --
   --------------------

   function Is_Constructor (Element : Asis.Element) return Boolean is
      Name     : Asis.Element;
      N        : Node_Id;
      Result   : Boolean := False;

   begin

      if Declaration_Kind (Element) in
            A_Function_Declaration             |
            An_Expression_Function_Declaration |
            A_Function_Body_Declaration        |
            A_Function_Renaming_Declaration    |
            A_Function_Body_Stub
        and then
         Is_Dispatching_Operation (Element)
      then
         Name := First_Name (Element);
         N    := Node (Name);

         if Has_Controlling_Result (N) then
            --  The last thing to check is that we do not have any controlling
            --  parameter
            Result := True;

            declare
               Pars : constant Asis.Element_List :=
                 Parameter_Profile (Element);
            begin
               if Pars'Length > 0 then
                  --  All we have to check in a legal code is if we have at
                  --  least one parameter of a tagged type, and this type is
                  --  not a class-wide type.

                  for J in Pars'Range loop
                     Name := First_Name (Pars (J));
                     N    := Node (Name);
                     N    := Etype (N);

                     if Ekind (N) in
                          E_Access_Type          |
                          E_Access_Subtype       |
                          E_Anonymous_Access_Type
                     then
                        N := Directly_Designated_Type (N);
                     end if;

                     if Is_Tagged_Type (N)
                       and then
                        Ekind (N) not in
                          E_Class_Wide_Type | E_Class_Wide_Subtype
                     then
                        --  We already have a controlling result, so in a legal
                        --  code this type should be the same as the result
                        --  type. Therefore:
                        Result := False;
                        exit;
                     end if;
                  end loop;
               end if;
            end;
         end if;
      end if;

      return Result;
   end Is_Constructor;

   --------------------------
   -- Is_Control_Structure --
   --------------------------

   function Is_Control_Structure (Stmt : Asis.Element) return Boolean is
      Result : Boolean := False;
   begin

      case Statement_Kind (Stmt) is
         when An_If_Statement                    |
              A_Case_Statement                   |
              A_Loop_Statement                   |
              A_While_Loop_Statement             |
              A_For_Loop_Statement               |
              A_Selective_Accept_Statement       |
              A_Timed_Entry_Call_Statement       |
              A_Conditional_Entry_Call_Statement |
              An_Asynchronous_Select_Statement   =>
            Result := True;
         when others =>
            null;
      end case;

      return Result;
   end Is_Control_Structure;

   ---------------------------------
   -- Is_Downward_View_Conversion --
   ---------------------------------

   function Is_Downward_View_Conversion
     (Element : Asis.Element)
      return    Boolean
   is
      Result : Boolean := False;
      Source : Asis.Element;
      Target : Asis.Element;

      Source_T : Entity_Id;
      Target_T : Entity_Id;
   begin
      if Expression_Kind (Element) /= A_Type_Conversion then
         return False;
      end if;

      Source   := Converted_Or_Qualified_Expression (Element);
      Source_T := R_Node (Source);
      Source_T := Etype (Source_T);

      while Ekind (Source_T) in
              E_Class_Wide_Subtype          |
              E_Record_Subtype              |
              E_Record_Subtype_With_Private |
              E_Private_Subtype             |
              E_Limited_Private_Subtype
      loop
         Source_T := Etype (Source_T);
      end loop;

      --  We are interested in view conversions in the context of
      --  Downward_View_Conversions gnatcheck rule, so both source and target
      --  types should be tagged

      if not Is_Tagged_Type (Source_T) then
         return False;
      end if;

      Target   := Converted_Or_Qualified_Subtype_Mark (Element);
      Target_T := R_Node (Target);
      Target_T := Etype (Target_T);

      while Ekind (Target_T) in
              E_Class_Wide_Subtype          |
              E_Record_Subtype              |
              E_Record_Subtype_With_Private |
              E_Private_Subtype             |
              E_Limited_Private_Subtype
      loop
         Target_T := Etype (Target_T);
      end loop;

      if Ekind (Source_T) = E_Class_Wide_Type then
         Source_T := Etype (Source_T);
      end if;

      if Ekind (Target_T) = E_Class_Wide_Type then
         Target_T := Etype (Target_T);
      end if;

      --  Conversion of non-interface type into interface type is always OK

      if Is_Interface (Target_T) and then not Is_Interface (Source_T) then
         return False;
      end if;

      --  Simple case - both source and target are not interfaces

      if not Is_Interface (Target_T) and then not Is_Interface (Source_T) then

         Result := True;

         loop

            if Source_T = Target_T then
               Result := False;
               exit;
            end if;

            exit when Etype (Source_T) = Source_T;

            Source_T := Etype (Source_T);
         end loop;

      end if;

      if Is_Interface (Target_T) and then Is_Interface (Source_T) then
         --  The hardest case - both source and target are interfaces.
         Result := not Is_Ancestor (Target_T, Source_T);
      end if;

      return Result;
   end Is_Downward_View_Conversion;

   --------------
   -- Is_Frame --
   --------------

   function Is_Frame (El : Asis.Element) return Boolean is
      Result : Boolean := False;
   begin

      case Flat_Element_Kind (El) is
         when A_Procedure_Body_Declaration |
              A_Function_Body_Declaration  |
              A_Package_Body_Declaration   |
              An_Entry_Body_Declaration    |
              A_Task_Body_Declaration      |
              A_Block_Statement            |
              An_Extended_Return_Statement |
              An_Accept_Statement          =>

            Result := True;
         when others =>
            null;
      end case;

      return Result;
   end Is_Frame;

   ----------------------
   -- Is_From_Standard --
   ----------------------

   function Is_From_Standard (El : Asis.Element) return Boolean is
      Result : Boolean := False;
   begin

      if not Is_Nil (El) then
         Result := Sloc (Node (El)) <= Standard_Location;
      end if;

      return Result;
   end Is_From_Standard;

   -----------------------------
   -- Is_Function_Declaration --
   -----------------------------

   function Is_Function_Declaration (El : Asis.Element) return Boolean is
      Result : Boolean := False;
   begin

      case Declaration_Kind (El) is
         when A_Function_Declaration          |
              A_Function_Body_Declaration     |
              A_Function_Body_Stub            |
              A_Function_Renaming_Declaration |
              A_Function_Instantiation        |
              A_Formal_Function_Declaration   |
              A_Generic_Function_Declaration  =>

            Result := True;

         when others =>
            null;
      end case;

      return Result;
   end Is_Function_Declaration;

   ---------------------
   -- Is_Dynamic_Call --
   ---------------------

   function Is_Dynamic_Call (Call : Asis.Element) return Boolean is
      Tmp    : Asis.Element;
      Result : Boolean := False;
   begin

      if Expression_Kind (Call) = A_Function_Call then
         Tmp := Prefix (Call);
      else
         Tmp := Called_Name (Call);
      end if;

      if Expression_Kind (Tmp) = An_Explicit_Dereference
        or else
         Is_True_Expression (Tmp)
      then
         --  If the prefix of a (procedure or function) call is a true
         --  expression that is, if it has a type, the only possibility for
         --  this prefix is to be of an access to procedure/function type, so
         Result := True;
      end if;

      return Result;
   end Is_Dynamic_Call;

   ------------------------------
   -- Is_Enum_Literal_Renaming --
   ------------------------------

   function Is_Enum_Literal_Renaming (El : Asis.Element) return Boolean is
      Result         : Boolean := False;
      Renamed_Entity : Entity_Id;
   begin
      if Declaration_Kind (El) = A_Function_Renaming_Declaration then

         Renamed_Entity := Sinfo.Name (Node (El));
         Renamed_Entity := Entity (Renamed_Entity);

         if Present (Renamed_Entity)
           and then
            Ekind (Renamed_Entity) = E_Enumeration_Literal
         then
            Result := True;
         end if;

      end if;

      return Result;
   end Is_Enum_Literal_Renaming;

   --------------
   -- Is_Fixed --
   --------------

   function Is_Fixed (Expr : Asis.Element) return Boolean is
      Result      : Boolean := False;
      Type_Entity : Entity_Id;
   begin

      if Asis.Extensions.Is_True_Expression (Expr) then
         Type_Entity := Etype (R_Node (Expr));
         Result      := Ekind (Type_Entity) in Fixed_Point_Kind;
      end if;

      return Result;

   end Is_Fixed;

   --------------
   -- Is_Float --
   --------------

   function Is_Float (Expr : Asis.Element) return Boolean is
      Result      : Boolean := False;
      Type_Entity : Entity_Id;
   begin

      if Asis.Extensions.Is_True_Expression (Expr) then
         Type_Entity := Etype (R_Node (Expr));

         while Present (Type_Entity)
             and then
               Ekind (Type_Entity) in E_Private_Type | E_Private_Subtype
         loop
            Type_Entity := Full_View (Type_Entity);
         end loop;

         Result := Present (Type_Entity)
                  and then
                   Ekind (Type_Entity) in Float_Kind;
      end if;

      return Result;

   end Is_Float;

   ----------------
   -- Is_Handled --
   ----------------

   function Is_Handled
     (Exc  : Asis.Element;
      By   : Asis.Element_List)
      return Boolean
   is
      Exc_To_Catch : Asis.Element := Exc;
      Result       : Boolean  := False;
      Last_Handler : Boolean := True;
   begin

      if By'Length > 0 then

         if Declaration_Kind (Enclosing_Element (Exc_To_Catch)) =
            An_Exception_Renaming_Declaration
         then
            Exc_To_Catch :=
              Get_Name_Definition
                (Renamed_Entity (Enclosing_Element (Exc_To_Catch)));
         end if;

         Traverse_Handlers : for J in reverse By'Range loop

            declare
               Handled_Excs : constant Asis.Element_List :=
                 Exception_Choices (By (J));
            begin

               if Last_Handler
                 and then
                  Definition_Kind (Handled_Excs (Handled_Excs'Last)) =
                  An_Others_Choice
               then
                  Result := True;
                  exit Traverse_Handlers;
               end if;

               Last_Handler := False;

               for K in Handled_Excs'Range loop

                  if Is_Equal
                       (Get_Name_Definition (Handled_Excs (K)),
                        Exc_To_Catch)
                  then
                     Result := True;
                     exit Traverse_Handlers;
                  end if;

               end loop;

            end;

         end loop Traverse_Handlers;

      end if;

      return Result;
   end Is_Handled;

   --------------------------
   -- Is_Interrupt_Handler --
   --------------------------

   function Is_Interrupt_Handler (Proc : Asis.Element) return Boolean is
      Result : Boolean := False;
      Tmp    : Asis.Element;
   begin
      if Declaration_Kind (Proc) = A_Procedure_Declaration
        and then
         Definition_Kind (Enclosing_Element (Proc)) = A_Protected_Definition
        and then
         Parameter_Profile (Proc)'Length = 0
      then

         --  Check for aspects Attach_Handler or Interrupt_Handler first
         declare
            Asps : constant Asis.Element_List := Aspect_Specifications (Proc);
         begin
            for J in Asps'Range loop
               Tmp := Aspect_Mark (Asps (J));

               if To_Lower_Case (Asis.Expressions.Name_Image (Tmp)) in
                    "attach_handler" | "interrupt_handler"
               then
                  Result := True;
                  exit;
               end if;
            end loop;
         end;

         if not Result then
            --  Check for pragmas Attach_Handler or Interrupt_Handler
            declare
               Dcls : constant Asis.Element_List :=
                 Pragmas (Enclosing_Element (Proc));
            begin
               for J in Dcls'Range loop
                  if To_Lower_Case (Pragma_Name_Image (Dcls (J))) in
                       "attach_handler" | "interrupt_handler"
                  then
                     declare
                        Pars : constant Asis.Element_List :=
                          Pragma_Argument_Associations (Dcls (J));
                     begin
                        Tmp := Actual_Parameter (Pars (Pars'First));

                        if To_Lower_Case (Asis.Expressions.Name_Image (Tmp)) =
                           To_Lower_Case
                             (Defining_Name_Image (First_Name (Proc)))
                        then
                           Result := True;
                           exit;
                        end if;
                     end;
                  end if;
               end loop;
            end;
         end if;

      end if;

      return Result;
   end Is_Interrupt_Handler;

   ----------------
   -- Is_Limited --
   ----------------

   function Is_Limited (SM : Asis.Element) return Boolean is
      Type_Entity : Entity_Id;
      Result      : Boolean := False;
   begin

      case Expression_Kind (SM) is
         when An_Identifier          |
              A_Selected_Component   |
              An_Attribute_Reference =>

            Type_Entity := Etype (R_Node (SM));

            Result :=
              Is_Limited_Type (Type_Entity)
             or else
              (Is_Interface (Type_Entity)
              and then
               Is_Limited_Interface (Type_Entity));

         when others =>
            null;
      end case;

      return Result;
   end Is_Limited;

   --------------------
   -- Is_Local --
   --------------------

   function Is_Local
     (Dcl            : Asis.Element;
      Protected_Body : Asis.Element)
      return Boolean
   is
      Result         :          Boolean      := False;
      Encl_El        :          Asis.Element := Enclosing_Element (Dcl);
      Protected_Spec : constant Asis.Element :=
        Corresponding_Declaration (Protected_Body);
   begin
      while not Is_Nil (Encl_El) loop
         if Is_Equal (Encl_El, Protected_Body)
           or else
            Is_Equal (Encl_El, Protected_Spec)
         then
            Result := True;
            exit;
         end if;

         Encl_El := Enclosing_Element (Encl_El);
      end loop;

      return Result;
   end Is_Local;

   --------------------
   -- Is_Named_Scope --
   --------------------

   function Is_Named_Scope (E : Asis.Element) return Boolean is
   begin

      return Declaration_Kind (E) in
               A_Task_Type_Declaration                  |
               A_Protected_Type_Declaration             |
               A_Procedure_Body_Declaration             |
               A_Function_Body_Declaration              |
               A_Package_Declaration                    |
               A_Package_Body_Declaration               |
               A_Task_Body_Declaration                  |
               A_Protected_Body_Declaration             |
               A_Generic_Package_Declaration            |
               A_Procedure_Declaration                  |
               An_Expression_Function_Declaration       |
               A_Function_Declaration                   |
               A_Package_Renaming_Declaration           |
               A_Procedure_Renaming_Declaration         |
               A_Function_Renaming_Declaration          |
               A_Generic_Package_Renaming_Declaration   |
               A_Generic_Procedure_Renaming_Declaration |
               A_Generic_Function_Renaming_Declaration  |
               A_Generic_Procedure_Declaration          |
               A_Generic_Function_Declaration;

   end Is_Named_Scope;

   ------------------------------
   -- Is_Num_Error_Declaration --
   ------------------------------

   function Is_Num_Error_Declaration (Decl : Asis.Element) return Boolean is
      Result : Boolean := False;
   begin

      if Declaration_Kind (Decl) = An_Exception_Renaming_Declaration
        and then
         Is_Standard (Enclosing_Compilation_Unit (Decl))
        and then
         Defining_Name_Image (First_Name (Decl)) = "Numeric_Error"
      then
         Result := True;
      end if;

      return Result;
   end Is_Num_Error_Declaration;

   ----------------------
   -- Is_Numeric_Error --
   ----------------------

   function Is_Numeric_Error (Ref : Asis.Element) return Boolean is
      Next_Exception_Decl : Asis.Element;

      Result : Boolean := False;
   begin
      Next_Exception_Decl := Corresponding_Name_Declaration (Ref);

      while not Is_Nil (Next_Exception_Decl) loop

         if Is_Num_Error_Declaration (Next_Exception_Decl) then
            Result := True;
            exit;
         elsif Declaration_Kind (Next_Exception_Decl) =
               An_Exception_Renaming_Declaration
         then
            Next_Exception_Decl := Renamed_Entity (Next_Exception_Decl);
            Next_Exception_Decl := Normalize_Reference (Next_Exception_Decl);
            Next_Exception_Decl :=
              Corresponding_Name_Declaration (Next_Exception_Decl);
         else
            exit;
         end if;

      end loop;

      return Result;
   end Is_Numeric_Error;

   -------------------------------------
   -- Is_Object_Address_Specification --
   -------------------------------------

   function Is_Object_Address_Specification
     (El   : Asis.Element)
      return Boolean
   is
      Result : Boolean := False;
      Tmp    : Asis.Element;
   begin

      if Is_Address_Specification (El) then

         if Definition_Kind (El) = An_Aspect_Specification then
            Tmp := Enclosing_Element (El);
         else
            --  an 'Address definition clause
            Tmp := Entity_From_Rep_Item (El);
         end if;

         Result := Declaration_Kind (Tmp) in
                     A_Variable_Declaration |
                     A_Constant_Declaration |
                     A_Deferred_Constant_Declaration;
      end if;

      return Result;
   end Is_Object_Address_Specification;

   -------------------
   -- Is_Positional --
   -------------------

   function Is_Positional (El : Asis.Element) return Boolean is
      Result : Boolean := False;
   begin

      if not Is_Normalized (El) then

         case Association_Kind (El) is
            when A_Pragma_Argument_Association |
                 A_Parameter_Association       |
                 A_Generic_Association         =>
               Result := Is_Nil (Formal_Parameter (El));
            when A_Discriminant_Association =>
               Result := Is_Nil (Discriminant_Selector_Names (El));
            when A_Record_Component_Association =>
               Result := Is_Nil (Record_Component_Choices (El));
            when An_Array_Component_Association =>
               Result := Is_Nil (Array_Component_Choices (El));
            when others =>
               null;
         end case;

      end if;

      return Result;
   end Is_Positional;

   -------------------
   -- Is_Predefined --
   -------------------

   function Is_Predefined (Operation : Asis.Element) return Boolean is
      Tmp_Element : Asis.Element;
      Op_Entity   : Entity_Id := Empty;
      Result      : Boolean := False;
   begin

      if Expression_Kind (Operation) = An_Operator_Symbol
        and then
         Is_Uniquely_Defined (Operation)
      then

         Tmp_Element := Corresponding_Name_Definition (Operation);

         if Is_Nil (Tmp_Element) then
            --  This also includes the case of "/=" implicitly declared by
            --  an explicit declaration of "="

            Tmp_Element := Enclosing_Element (Operation);

            if Expression_Kind (Tmp_Element) = A_Selected_Component then
               Op_Entity := R_Node (Tmp_Element);
            else
               Op_Entity := R_Node (Operation);
            end if;

            if Nkind (Op_Entity) = N_Raise_Constraint_Error then
               Op_Entity := Node (Operation);
            end if;

            case Nkind (Op_Entity) is
               when N_Function_Call =>
                  Op_Entity := Sinfo.Name (Op_Entity);
               when N_Type_Conversion =>
                  Op_Entity := Sinfo.Expression (Op_Entity);
               when others =>
                  null;
            end case;

            Op_Entity := Entity (Op_Entity);

            Result := Sloc (Op_Entity) = Standard_Location;

         end if;
      end if;

      return Result;

   end Is_Predefined;

   --------------------------
   -- Is_Predefined_String --
   --------------------------

   function Is_Predefined_String (Type_Decl : Asis.Element) return Boolean is
      Type_Entity : Entity_Id;
      Result      : Boolean := False;
   begin

      if Declaration_Kind (Type_Decl) = An_Ordinary_Type_Declaration
        or else
         Declaration_Kind (Type_Decl) = A_Subtype_Declaration
      then
         Type_Entity := R_Node (Names (Type_Decl) (1));

         while Etype (Type_Entity) /= Type_Entity loop
            Type_Entity := Etype (Type_Entity);
         end loop;

         Result := Type_Entity = Stand.Standard_String;

      end if;

      return Result;

   end Is_Predefined_String;

   ----------------------------------
   -- Is_Prefix_Notation_Exception --
   ----------------------------------

   function Is_Prefix_Notation_Exception
     (El                 : Asis.Element;
      Exclude_Second_Par : Boolean)
      return Boolean
   is
      Call_Node      : Node_Id;
      Par_Node       : Node_Id;
      Firts_Par_Node : Node_Id;

      Result    : Boolean := False;
   begin
      Call_Node := Parent (R_Node (El));

      --  We can be sure, that El is a subprogram call that has at least one
      --  parameter, so Parameter_Associations (Call_Node) definitely presents.
      if List_Length (Parameter_Associations (Call_Node)) = 1 then
         Result := True;
      else
         Par_Node       := R_Node (El);
         Firts_Par_Node := First (Parameter_Associations (Call_Node));

         if Par_Node = Firts_Par_Node then
            Result := True;
         elsif List_Length (Parameter_Associations (Call_Node)) = 2
            and then
             Exclude_Second_Par
         then
            Result := Par_Node = Next (Firts_Par_Node);
         end if;

      end if;

      return Result;
   end Is_Prefix_Notation_Exception;

   ---------------------------------
   -- Is_Protected_Operation_Call --
   ---------------------------------

   function Is_Protected_Operation_Call (Call : Asis.Element) return Boolean is
      Tmp_Node : Node_Id;
      Result   : Boolean := False;
   begin
      Tmp_Node := R_Node (Call);

      if Nkind (Tmp_Node) = N_Entry_Call_Statement then
         Tmp_Node := Prefix (Sinfo.Name (Tmp_Node));
         Tmp_Node := Etype (Tmp_Node);

         if Ekind (Tmp_Node) in Private_Kind then
            Tmp_Node := Full_View (Tmp_Node);
         end if;

         Result := Ekind (Tmp_Node) in Protected_Kind;
      end if;

      return Result;
   end Is_Protected_Operation_Call;

   ------------------------------------
   -- Is_Ref_To_Standard_Num_Subtype --
   ------------------------------------

   function Is_Ref_To_Standard_Num_Subtype
     (Ref  : Asis.Element)
      return Boolean
   is
      Result     : Boolean := False;
      Arg_Entity : Entity_Id;
   begin
      Arg_Entity := Node (Ref);

      if Nkind (Arg_Entity) in N_Has_Entity then

         if No (Entity (Arg_Entity))
           and then
            Nkind (Parent (Arg_Entity)) = N_Expanded_Name
           and then
            Arg_Entity = Selector_Name (Parent (Arg_Entity))
         then
            Arg_Entity := Parent (Arg_Entity);
         end if;

         Arg_Entity := Entity (Arg_Entity);

         if Present (Arg_Entity)
           and then
            Sloc (Arg_Entity) = Standard_Location
           and then
            Ekind (Arg_Entity) in Numeric_Kind
         then
            Result := True;
         end if;

      end if;

      return Result;

   end Is_Ref_To_Standard_Num_Subtype;

   ---------------
   -- Is_Public --
   ---------------

   function Is_Public (Def_Name : Asis.Element) return Boolean is
      Result : Boolean := False;
   begin

      case Defining_Name_Kind (Def_Name) is
         when A_Defining_Identifier .. A_Defining_Operator_Symbol =>
            Result := not Is_Hidden (Node (Def_Name));
         when A_Defining_Expanded_Name =>
            Result := not Is_Hidden (Node (Defining_Selector (Def_Name)));
         when others =>
            null;
      end case;

      return Result;
   end Is_Public;

   -----------------
   -- Is_Renaming --
   -----------------

   function Is_Renaming (El : Asis.Element) return Boolean is
      Result : Boolean := False;
   begin
      --  A very simple test at the moment

      case Flat_Element_Kind (El) is
         when A_Procedure_Renaming_Declaration |
              A_Function_Renaming_Declaration  =>
            Result := True;
         when others =>
            null;
      end case;

      return Result;
   end Is_Renaming;

   ----------------------------
   -- Is_Representation_Item --
   ----------------------------

   function Is_Representation_Item (El : Asis.Element) return Boolean is
   begin
      return Clause_Kind (El) = A_Representation_Clause
           or else
             (Element_Kind (El) = A_Pragma
             and then
              To_Lower_Case (Pragma_Name_Image (El)) in
                "atomic"                 |
                "atomic_components"      |
                "independent"            |
                "independent_components" |
                "pack"                   |
                "unchecked_union"        |
                "volatile)"              |
                "volatile_components");
   end Is_Representation_Item;

   -------------------------
   -- Is_Standard_Boolean --
   -------------------------

   function Is_Standard_Boolean (Expr : Asis.Element) return Boolean is
      Result      : Boolean := False;
      Type_Entity : Entity_Id;
   begin

      if Asis.Extensions.Is_True_Expression (Expr) then
         Type_Entity := Etype (R_Node (Expr));

         while Present (Type_Entity)
            and then
               Type_Entity /= Etype (Type_Entity)
            and then
               Ekind (Type_Entity) /= E_Enumeration_Type
         loop
            Type_Entity := Etype (Type_Entity);
         end loop;

         Result      := Type_Entity = Standard_Boolean;
      end if;

      return Result;

   end Is_Standard_Boolean;

   ----------------------
   -- Is_Task_Creation --
   ----------------------

   function Is_Task_Creation (El : Asis.Element) return Boolean is
      Arg_Kind : constant Flat_Element_Kinds := Flat_Element_Kind (El);
      Result   :          Boolean := False;
   begin

      case Arg_Kind is
         when A_Variable_Declaration |
              A_Constant_Declaration =>
            Result := Is_Task_Object_Declaration (El);
         when A_Single_Task_Declaration =>
            Result := True;
         when others =>
            null;
      end case;

      return Result;
   end Is_Task_Creation;

   ------------------------
   -- Is_Task_Entry_Call --
   ------------------------

   function Is_Task_Entry_Call (Call : Asis.Element) return Boolean is
      Pref_Node      : Node_Id;
      Pref_Type_Node : Entity_Id;
      Result         : Boolean   := False;
   begin

      if Statement_Kind (Call) = An_Entry_Call_Statement then
         Pref_Node      := Node (Called_Name (Call));

         if Nkind (Pref_Node) = N_Indexed_Component then
            --  Call to an entry from an entrty family
            Pref_Node := Prefix (Pref_Node);
         end if;

         Pref_Type_Node := Etype (Pref_Node);

         if (No (Pref_Type_Node)
            or else
             Ekind (Pref_Type_Node) = E_Void)
           and then
             Nkind (Pref_Node) = N_Selected_Component
         then
            Pref_Node      := Sinfo.Prefix (Pref_Node);
            Pref_Type_Node := Etype (Pref_Node);
         end if;

         if Present (Pref_Type_Node)
           and then
            Ekind (Pref_Type_Node) in
              E_Private_Type         |
              E_Private_Subtype      |
              E_Limited_Private_Type |
              E_Limited_Private_Subtype
         then
            Pref_Type_Node := Full_View (Pref_Type_Node);
         end if;

         Result := Ekind (Pref_Type_Node) in Task_Kind;
      end if;

      return Result;
   end Is_Task_Entry_Call;

   --------------------------------
   -- Is_Task_Object_Declaration --
   --------------------------------

   function Is_Task_Object_Declaration (Expr : Asis.Element) return Boolean is
      N      : Node_Id;
      Result : Boolean := False;
   begin

      case Flat_Element_Kind (Expr) is
         when A_Variable_Declaration |
              A_Constant_Declaration =>

            N := Defining_Identifier (R_Node (Expr));
            N := Etype (N);

            Result := Ekind (N) in Task_Kind;
         when others =>
            null;
      end case;

      return Result;
   end Is_Task_Object_Declaration;

   ------------------------
   -- Is_Template_Caller --
   ------------------------

   function Is_Template_Caller (El : Asis.Element) return Boolean is
      Result : Boolean := False;
   begin
      case Flat_Element_Kind (El) is
         when A_Task_Type_Declaration =>
            Result := True;
         when others =>
            null;
      end case;

      return Result;
   end Is_Template_Caller;

   ----------------------------
   -- Is_Unconstrained_Array --
   ----------------------------

   function Is_Unconstrained_Array (Type_Decl : Asis.Element) return Boolean is
      Type_Entity : Entity_Id;
      Result      : Boolean := False;
   begin

      if Declaration_Kind (Type_Decl) = An_Ordinary_Type_Declaration
        or else
         Declaration_Kind (Type_Decl) = A_Subtype_Declaration
      then
         Type_Entity := R_Node (Names (Type_Decl) (1));

         if Is_Array_Type (Type_Entity)
           and then
            not Is_Constrained (Type_Entity)
         then
            Result := True;
         end if;

      end if;

      return Result;

   end Is_Unconstrained_Array;

   --------------------------
   -- Look_For_Loop_Pre_Op --
   --------------------------

   procedure Look_For_Loop_Pre_Op
     (Element :        Asis.Element;
      Control : in out Traverse_Control;
      State   : in out Boolean)
   is
   begin

      case Element_Kind (Element) is
         when A_Statement =>

            case Statement_Kind (Element) is
               when An_If_Statement                    |
                    A_Case_Statement                   |
                    A_Block_Statement                  |
                    An_Extended_Return_Statement       |
                    An_Accept_Statement                |
                    A_Selective_Accept_Statement       |
                    A_Timed_Entry_Call_Statement       |
                    A_Conditional_Entry_Call_Statement |
                    An_Asynchronous_Select_Statement   =>
                  null;
               when A_Loop_Statement       |
                    A_While_Loop_Statement |
                    A_For_Loop_Statement   =>

                  State   := True;
                  Control := Terminate_Immediately;

               when others =>
                  Control := Abandon_Children;
            end case;

         when A_Path =>
            null;
         when others =>
            Control := Abandon_Children;
      end case;

   end Look_For_Loop_Pre_Op;

   ---------------------------------------
   -- Look_For_Modular_Component_Pre_Op --
   ---------------------------------------

   procedure Look_For_Modular_Component_Pre_Op
     (Element :        Asis.Element;
      Control : in out Traverse_Control;
      State   : in out Boolean)
   is
      S_Mark : Asis.Element;
   begin

      case Declaration_Kind (Element) is
         when A_Component_Declaration =>
            S_Mark := Object_Declaration_View (Element);
            S_Mark := Component_Definition_View (S_Mark);

            if Definition_Kind (S_Mark) = A_Subtype_Indication then
               S_Mark := Asis.Definitions.Subtype_Mark (S_Mark);

               if Is_Modular_Type (S_Mark) then
                  State   := True;
                  Control := Terminate_Immediately;
               else
                  Control := Abandon_Children;
               end if;
            else
               --  Anonymous access definition
               Control := Abandon_Children;
            end if;

         when others =>
            null;
      end case;

   end Look_For_Modular_Component_Pre_Op;

   ----------------------
   -- Needs_Completion --
   ----------------------

   function Needs_Completion (El : Asis.Element) return Boolean is
      Arg_Kind : constant Flat_Element_Kinds := Flat_Element_Kind (El);
      Result   : Boolean                     := False;
      Entity_N : Entity_Id;
   begin

      case Arg_Kind is
         when A_Task_Type_Declaration        |
              A_Protected_Type_Declaration   |
              A_Single_Task_Declaration      |
              A_Single_Protected_Declaration |
              A_Procedure_Body_Stub          |
              A_Function_Body_Stub           |
              A_Package_Body_Stub            |
              A_Task_Body_Stub               |
              A_Protected_Body_Stub          =>
            Result := True;

         when A_Package_Declaration         |
              A_Generic_Package_Declaration =>

            --  Now we make the check for library packages only!

            if Is_Nil (Enclosing_Element (El)) then
               Result :=
                 Asis.Compilation_Units.Is_Body_Required
                   (Enclosing_Compilation_Unit (El));
            end if;

         when A_Generic_Procedure_Declaration |
              A_Generic_Function_Declaration  |
              A_Procedure_Declaration         |
              A_Function_Declaration          =>

            Entity_N := Defining_Unit_Name (Specification (Node (El)));

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

            if not (Is_Intrinsic_Subprogram (Entity_N)
                 or else
                    Is_Imported (Entity_N))
            then
               Result := True;
            end if;

         when others =>
            null;
      end case;

      return Result;
   end Needs_Completion;

   ---------------------------------
   -- Needs_Real_Range_Definition --
   ---------------------------------

   function Needs_Real_Range_Definition (El : Asis.Element) return Boolean is
      Result : Boolean := False;
      Tmp    : Asis.Element;
      Ent    : Entity_Id;
   begin
      if Declaration_Kind (El) = An_Ordinary_Type_Declaration then
         Tmp := First_Name (El);
         Ent := R_Node (Tmp);

         Result := Ekind (Ent) in Digits_Kind;
      end if;

      return Result;
   end Needs_Real_Range_Definition;

   -----------------------
   -- Overloading_Index --
   -----------------------

   function Overloading_Index (El : Asis.Element) return String is
      Dcl      : Asis.Element;
      Dcl_N    : Asis.Element;
      Dcl_Name : Program_Text_Access;

      Res : Positive := 1;

      Scope     : Asis.Element := Nil_Element;
      Dcl_Scope : Asis.Element := Nil_Element;

      Detected : Boolean := False;

      procedure Get_Overloding_Index (Dcls : Asis.Element_List);
      --  Parses its argument and counts in Res declarations that overloads El.
      --  If founds the declaration that Is_Equal to El, sets Detected ON and
      --  returns (without increasing Res).
      procedure Get_Overloding_Index (Dcls : Asis.Element_List) is
      begin
         for J in Dcls'Range loop
            if Is_Equal (Dcls (J), Dcl) then
               Detected := True;
               exit;
            end if;

            if Declaration_Kind (Dcls (J)) in
                  A_Procedure_Declaration            |
                  An_Entry_Declaration               |
                  A_Procedure_Instantiation          |
                  A_Function_Declaration             |
                  A_Function_Instantiation
               or else
                (Declaration_Kind (Dcls (J)) in
                   A_Procedure_Body_Declaration       |
                   A_Null_Procedure_Declaration       |
                   A_Procedure_Body_Stub              |
                   A_Function_Body_Declaration        |
                   A_Function_Body_Stub               |
                   An_Expression_Function_Declaration
                 and then
                Acts_As_Spec (Dcls (J)))
               or else
                (Declaration_Kind (Dcls (J)) in
                  A_Procedure_Renaming_Declaration   |
                  A_Function_Renaming_Declaration
                 and then
                not Is_Renaming_As_Body (Dcls (J)))
            then
               if To_Lower_Case (Defining_Name_Image (First_Name (Dcls (J)))) =
                    Dcl_Name.all
               then
                  Res := Res + 1;
               end if;
            end if;

         end loop;
      end Get_Overloding_Index;

   begin
      if Declaration_Kind (El) in
           A_Procedure_Body_Declaration |
           A_Function_Body_Declaration
      then
         Dcl := Corresponding_Declaration (El);

         if Is_Nil (Dcl) then
            if Acts_As_Spec (El) then
               Dcl := El;
            elsif Is_Subunit (El) then
               Dcl := Corresponding_Body_Stub (El);

               if not Acts_As_Spec (Dcl) then
                  Dcl := Corresponding_Declaration (Dcl);
               end if;
            else
               pragma Assert (False);
            end if;
         end if;
      else
         return "";
      end if;

      if Declaration_Kind (Dcl) in
           A_Generic_Procedure_Declaration |
           A_Generic_Function_Declaration
      then
         return "";
      end if;

      Dcl_N := First_Name (Dcl);

      if Defining_Name_Kind (Dcl_N) = A_Defining_Expanded_Name
        or else
         not Has_Homonym (R_Node (Dcl_N))
      then
         return "";
      end if;

      Scope    := Enclosing_Element (Dcl);

      Dcl_Name := new Program_Text'(To_Lower_Case
                        (Defining_Name_Image (Dcl_N)));

      if Is_Nil (Scope) then
         --  We are at the library level
         return "";
      end if;

      if Declaration_Kind (Scope) in
           A_Package_Body_Declaration |
           A_Protected_Body_Declaration
      then
         Dcl_Scope := Corresponding_Declaration (Scope);
      end if;

      if Declaration_Kind (Dcl_Scope) in
           A_Protected_Type_Declaration |
           A_Single_Protected_Declaration
      then
         Get_Overloding_Index
          (Visible_Part_Items (
             (if Declaration_Kind (Dcl_Scope) =
                   A_Protected_Type_Declaration
              then
                 Type_Declaration_View (Dcl_Scope)
              else
                 Object_Declaration_View (Dcl_Scope))));
         if not Detected then
            Get_Overloding_Index
             (Private_Part_Items (
                (if Declaration_Kind (Dcl_Scope) =
                      A_Protected_Type_Declaration
                 then
                    Type_Declaration_View (Dcl_Scope)
                 else
                    Object_Declaration_View (Dcl_Scope))));
         end if;
      elsif Declaration_Kind (Dcl_Scope) in
              A_Package_Declaration |
              A_Generic_Package_Declaration
      then
         Get_Overloding_Index (Visible_Part_Declarative_Items (Dcl_Scope));

         if not Detected then
            Get_Overloding_Index (Private_Part_Declarative_Items (Dcl_Scope));
         end if;
      end if;

      if not Detected then

         if Declaration_Kind (Scope) = A_Protected_Body_Declaration then
            Get_Overloding_Index (Protected_Operation_Items (Scope));

         elsif Declaration_Kind (Scope) in
                 A_Package_Declaration |
                 A_Generic_Package_Declaration
         then
            Get_Overloding_Index (Visible_Part_Declarative_Items (Scope));

         elsif Declaration_Kind (Scope) in
                 A_Procedure_Body_Declaration |
                 A_Function_Body_Declaration  |
                 A_Package_Body_Declaration   |
                 A_Task_Body_Declaration
         then
            Get_Overloding_Index (Body_Declarative_Items (Scope));

         elsif Definition_Kind (Scope) = A_Protected_Definition then
            Get_Overloding_Index (Visible_Part_Items (Scope));

         elsif Statement_Kind (Scope) = A_Block_Statement then
            Get_Overloding_Index (Block_Declarative_Items (Scope));
         else
            pragma Assert (False);
         end if;

         if not Detected then
            if Declaration_Kind (Scope) in
                 A_Package_Declaration |
                 A_Generic_Package_Declaration
            then
               Get_Overloding_Index (Private_Part_Declarative_Items (Scope));
            elsif Definition_Kind (Scope) = A_Protected_Definition then
               Get_Overloding_Index (Private_Part_Items (Scope));
            end if;
         end if;
      end if;

      Free (Dcl_Name);

      if Res = 1 then
         return "";
      else
         return '#' & Image (Res);
      end if;
   end Overloading_Index;

   ------------------------------
   -- Overridden_Interface_Ops --
   ------------------------------

   function Overridden_Interface_Ops
     (Type_Entity : Entity_Id;
      Op_Entity   : Entity_Id)
      return   List_Of_Nodes
   is
      Result : List_Of_Nodes (1 .. 6000);
      --  6000 looks as infinity here
      Res_Last : Natural := 0;

      Next_El             :          Elmt_Id;
      Next_Overridden     :          Entity_Id;
   begin
      Next_El := First_Elmt (Direct_Primitive_Operations (Type_Entity));

      while Present (Next_El) loop
         Next_Overridden := Node (Next_El);

         if Present (Interface_Alias (Next_Overridden))
           and then
            Alias (Next_Overridden) = Op_Entity
         then
            Res_Last            := Res_Last + 1;
            Result (Res_Last)   := Interface_Alias (Next_Overridden);
         end if;

         Next_El := Next_Elmt (Next_El);
      end loop;

      return Result (1 .. Res_Last);

   end Overridden_Interface_Ops;

   ---------------------
   -- Primitive_Owner --
   ---------------------

   function Primitive_Owner (Op : Entity_Id) return Entity_Id is
      Res_Node : Entity_Id := Empty;
      Op_Def   : Node_Id;
      Par_Node : Node_Id;
   begin
      --  Two cases should be processed separately - explicit and implicit
      --  primitives

      if Comes_From_Source (Op) then
         Op_Def := Parent (Op);
         pragma Assert (Nkind (Op_Def) in
                        N_Procedure_Specification | N_Function_Specification);

         if Nkind (Op_Def) = N_Function_Specification
           and then
            Has_Controlling_Result (Op)
         then
            Res_Node := Sinfo.Result_Definition (Op_Def);

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

            Res_Node := Entity (Res_Node);
         end if;

         if No (Res_Node) then
            --  This means that we do not have a function with controlling
            --  result, so we have to go through the formal parameter list,
            --  and it can not be No_List or empty

            Par_Node := First (Parameter_Specifications (Op_Def));

            while Present (Par_Node) loop

               if Is_Controlling_Formal
                    (Defining_Identifier (Par_Node))
               then

                  if Nkind (Parameter_Type (Par_Node)) =
                     N_Access_Definition
                  then
                     Res_Node :=
                        Sinfo.Subtype_Mark (Parameter_Type (Par_Node));
                  else
                     Res_Node := Defining_Identifier (Par_Node);
                  end if;

                  Res_Node := Etype (Res_Node);

                  exit;
               end if;

               Par_Node := Next (Par_Node);
            end loop;

         end if;

         pragma Assert (Present (Res_Node));

         if Nkind (Original_Node (Parent (Res_Node))) =
              N_Subtype_Declaration
         then
            Res_Node := Etype (Res_Node);
         end if;

         if Ekind (Res_Node) = E_Incomplete_Type
           and then
            Present (Full_View (Res_Node))
         then
            Res_Node := Full_View (Res_Node);
         end if;

      else
         Res_Node := Parent (Op);

         pragma Assert (Nkind (Res_Node) in
                          N_Private_Extension_Declaration |
                          N_Private_Type_Declaration      |
                          N_Full_Type_Declaration);

         Res_Node := Defining_Identifier (Res_Node);
      end if;

      return Res_Node;
   end Primitive_Owner;

   ----------------------
   -- Raises_Exception --
   ----------------------

   function Raises_Exception (El : Asis.Element) return Boolean is
      Result          : Boolean := False;
      First_Handler   : Boolean := Element_Kind (El) = An_Exception_Handler;
      First_Body_Decl : Boolean :=
        Declaration_Kind (El) in
          A_Procedure_Body_Declaration .. A_Function_Body_Declaration;

      procedure Check_Construct
        (Element :        Asis.Element;
         Control : in out Traverse_Control;
         State   : in out Boolean);
      --  Checks if we have a raise statement or a construct that should be
      --  skipped in the analysis;
      procedure No_Op
        (Element :        Asis.Element;
         Control : in out Traverse_Control;
         State   : in out Boolean);

      procedure Check_For_Raise_Statement is new Traverse_Element
        (Pre_Operation     => Check_Construct,
         Post_Operation    => No_Op,
         State_Information => Boolean);

      Control : Traverse_Control := Continue;

      procedure Check_Construct
        (Element :        Asis.Element;
         Control : in out Traverse_Control;
         State   : in out Boolean)
      is
      begin
         case Element_Kind (Element) is
            when A_Declaration =>

               case Declaration_Kind (Element) is
                  when A_Procedure_Body_Declaration |
                       A_Function_Body_Declaration  =>

                     if First_Body_Decl then
                        First_Body_Decl := False;
                     else
                        Control := Abandon_Children;
                     end if;

                  when others =>
                     Control := Abandon_Children;
               end case;

            when A_Statement =>
               if Statement_Kind (Element) = A_Raise_Statement then
                  State   := True;
                  Control := Terminate_Immediately;
               end if;
            when A_Path =>
               null;
            when An_Exception_Handler =>
               if First_Handler then
                  First_Handler := False;
               else
                  Control := Abandon_Children;
               end if;

            when others =>
               Control := Abandon_Children;
         end case;
      end Check_Construct;

      procedure No_Op
        (Element :        Asis.Element;
         Control : in out Traverse_Control;
         State   : in out Boolean)
      is
      begin
         null;
      end No_Op;

   begin
      Check_For_Raise_Statement (El, Control, Result);

      return Result;
   end Raises_Exception;

   ----------------
   -- Scope_Name --
   ----------------

   function Scope_Name (El : Asis.Element) return String is
   begin
      if not ASIS_UL.Debug.Debug_Flag_JJ
        or else Is_Nil (El)
      then
         return "";
      else
         declare
            Result : constant String := Add_Scope_Name (El);
         begin
            if Result = "" then
               return "";
            else
               return Result & ": ";
            end if;
         end;
      end if;

   end Scope_Name;

   -------------------------------
   -- Self_Ref_Discr_Constraint --
   -------------------------------

   function Self_Ref_Discr_Constraint
     (Constr : Asis.Element)
      return   Boolean
   is
      Result    : Boolean := False;
      Type_Name : Asis.Element;
   begin

      if Constraint_Kind (Constr) /= A_Discriminant_Constraint then
         return False;
      end if;

      Type_Name :=
        Enclosing_Element (Enclosing_Element (Enclosing_Element (Constr)));

      if Declaration_Kind (Type_Name) /= A_Component_Declaration then
         return False;
      end if;

      while Declaration_Kind (Type_Name) /= An_Ordinary_Type_Declaration loop
         Type_Name := Enclosing_Element (Type_Name);
      end loop;

      Type_Name := First_Name (Type_Name);

      declare
         D_Associations : constant Asis.Element_List :=
           Discriminant_Associations (Constr);
         D_Value : Asis.Element;
         Pref    : Asis.Element;
      begin
         for J in D_Associations'Range loop
            D_Value := Discriminant_Expression (D_Associations (J));

            if Is_Access_Attribute (D_Value) then
               Pref := Prefix (D_Value);

               if Expression_Kind (Pref) = An_Identifier then
                  Pref := Corresponding_Name_Declaration (Pref);

                  while Declaration_Kind (Pref) in
                          An_Incomplete_Type_Declaration       |
                          A_Tagged_Incomplete_Type_Declaration |
                          A_Private_Type_Declaration            |
                          A_Private_Extension_Declaration
                  loop
                     Pref := Corresponding_Type_Completion (Pref);
                  end loop;

                  if Declaration_Kind (Pref) =
                       An_Ordinary_Type_Declaration
                  then
                     Pref := First_Name (Pref);

                     if Is_Equal (Pref, Type_Name) then
                        Result := True;
                        exit;
                     end if;
                  end if;

               end if;
            end if;

         end loop;
      end;

      return Result;
   end Self_Ref_Discr_Constraint;

   -------------------------------------
   -- Storage_Order_Defined_By_Pragma --
   -------------------------------------

   function Storage_Order_Defined_By_Pragma
     (E    : Asis.Element)
      return Boolean
   is
      Type_Entity : Entity_Id;
      Next_Pragma : Node_Id;
      Pragma_Arg  : Node_Id;
      Result      : Boolean := False;
   begin
      Type_Entity := R_Node (E);
      Next_Pragma := Next (Type_Entity);
      Type_Entity := Defining_Identifier (Type_Entity);

      while Present (Next_Pragma) loop
         if Nkind (Next_Pragma) = N_Attribute_Definition_Clause
          and then
            Is_Rewrite_Substitution (Next_Pragma)
          and then
            Nkind (Original_Node (Next_Pragma)) = N_Pragma
          and then
            Chars (Next_Pragma) = Name_Scalar_Storage_Order
         then
            Pragma_Arg := Sinfo.Name (Next_Pragma);

            if Nkind (Pragma_Arg) = N_Identifier
              and then
               Entity (Pragma_Arg) = Type_Entity
            then
               Result := True;
               exit;
            end if;
         end if;

         Next_Pragma := Next (Next_Pragma);
      end loop;

      return Result;
   end Storage_Order_Defined_By_Pragma;

   -----------------
   -- Unwind_Type --
   -----------------

   function Unwind_Type
     (D               : Asis.Element;
      Stop_At_Private : Boolean := False)
      return            Asis.Element
   is
      Result : Asis.Element := D;
      T_Def  : Asis.Element;
   begin
      case Declaration_Kind (Result) is
         when A_Task_Type_Declaration              |
              A_Protected_Type_Declaration         |
              An_Incomplete_Type_Declaration       |
              A_Tagged_Incomplete_Type_Declaration |
              A_Formal_Type_Declaration            |
              A_Formal_Incomplete_Type_Declaration =>
            null;

         when An_Ordinary_Type_Declaration =>
            T_Def := Type_Declaration_View (Result);

            if Asis.Elements.Type_Kind (T_Def) in
                 A_Derived_Type_Definition             |
                 A_Derived_Record_Extension_Definition
            then
               Result := Unwind_Type (Corresponding_Root_Type (T_Def));
            end if;

         when A_Private_Type_Declaration      |
              A_Private_Extension_Declaration =>
            if not Stop_At_Private then
               Result := Unwind_Type (Corresponding_Type_Completion (Result));
            end if;

         when A_Subtype_Declaration =>
            Result := Unwind_Type (Corresponding_First_Subtype (Result));

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

      return Result;
   end Unwind_Type;

   -------------------------------
   -- Used_To_Pass_Actual_Subpr --
   -------------------------------

   function Used_To_Pass_Actual_Subpr (El : Asis.Element) return Boolean is
      Result : Boolean := False;
   begin

      if Declaration_Kind (El) in A_Procedure_Renaming_Declaration ..
        A_Function_Renaming_Declaration
      then
         Result := Pass_Generic_Actual (Node (El));
      end if;

      return Result;
   end Used_To_Pass_Actual_Subpr;

end Gnatcheck.ASIS_Utilities;
------------------------------------------------