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
|
------------------------------------------------------------------------------
-- --
-- GNATCHECK COMPONENTS --
-- --
-- A S I S _ U L . U T I L I T I E S --
-- --
-- B o d y --
-- --
-- Copyright (C) 2007-2019, AdaCore --
-- --
-- Asis Utility Library (ASIS UL) is free software; you can redistribute it --
-- and/or modify it under terms of the GNU General Public License as --
-- published by the Free Software Foundation; either version 3, or (at your --
-- option) any later version. ASIS UL 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. --
-- --
-- ASIS UL is maintained by AdaCore (http://www.adacore.com). --
-- --
------------------------------------------------------------------------------
pragma Ada_2012;
with Ada.Characters.Handling; use Ada.Characters.Handling;
with Ada.Strings; use Ada.Strings;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Asis.Compilation_Units; use Asis.Compilation_Units;
with Asis.Declarations; use Asis.Declarations;
with Asis.Definitions; use Asis.Definitions;
with Asis.Elements; use Asis.Elements;
with Asis.Expressions; use Asis.Expressions;
with Asis.Extensions; use Asis.Extensions;
with Asis.Iterator; use Asis.Iterator;
with Asis.Statements; use Asis.Statements;
with Asis.Set_Get; use Asis.Set_Get;
with A4G.A_Sem; use A4G.A_Sem;
with A4G.A_Types; use A4G.A_Types;
with A4G.Asis_Tables; use A4G.Asis_Tables;
with A4G.Contt.UT; use A4G.Contt.UT;
with A4G.Int_Knds; use A4G.Int_Knds;
with A4G.Mapping; use A4G.Mapping;
with A4G.Vcheck; use A4G.Vcheck;
with Atree; use Atree;
with Einfo; use Einfo;
with Elists; use Elists;
with Fname; use Fname;
with Lib; use Lib;
with Namet;
with Nlists; use Nlists;
with Sem_Aux; use Sem_Aux;
with Sinfo; use Sinfo;
with Sinput; use Sinput;
with Types; use Types;
with ASIS_UL.Common; use ASIS_UL.Common;
with ASIS_UL.Misc;
with ASIS_UL.Output; use ASIS_UL.Output;
package body ASIS_UL.Utilities is
Package_Name : constant String := "ASIS_UL.Utilities.";
-----------------------
-- Local subprograms --
-----------------------
function Contains
(Outer : Element;
Inner : Element)
return Boolean;
-- Checks if Outer contains Inner. At the moment this function is
-- implemented for explicit elements only, or, more precisely, for the
-- situation when for both arguments Is_Text_Available. If at least one of
-- the parameters does not have a text properties available, False is
-- returned.
--
-- Note, that the current implementation assumes that both arguments are
-- from the same Compilation_Unit!
function Internal_Full_Image (E : Asis.Element) return Program_Text;
-- Part of the Full_Expanded_Name_Image implementation, makes the main
-- recursive step. Goes up the ASIS tree until the first namable scope is
-- found and returns either the image of the name of the scope (and empty
-- string in case of nameless block statement) prepended by a dot and the
-- result of the call to Internal_Full_Image applied to the enclosing
-- element of the scope. In case if this is the last namable scope on the
-- way to program unit top, returns its name and does not do any recursive
-- step. In case of a subunit, goes to the parent unit.
function Is_Namable_Scope (E : Element) return Boolean;
-- Checks if the argument is a program unit definition is a scope that may
-- contain a type or variable declaration
function Is_Static_Subtype (E : Element) return Boolean;
-- Checks if the argument is a static subtype indication or a static
-- A_Discrete_Subtype_Definition. This function is supposed to be applied
-- to discrete subtype indications (and definitions) of the form
-- subtype_mark [constraint].
procedure Capitalize (S : in out String);
-- Assuming that S has a syntax of an Ada identifier, changes the casing
-- of S to proper case.
------------------------------
-- Ada_Attribute_Designator --
------------------------------
function Ada_Attribute_Designator
(Attr : Asis.Attribute_Kinds)
return String
is
Result : String := Attr'Img;
First_Idx : Positive;
Last_Idx : Positive;
begin
case Attr is
when Not_An_Attribute |
An_Implementation_Defined_Attribute |
An_Unknown_Attribute =>
raise Constraint_Error;
when others =>
First_Idx := Index (Result, "_", Forward) + 1;
Last_Idx := Index (Result, "_", Backward) - 1;
end case;
Capitalize (Result (First_Idx .. Last_Idx));
return Result (First_Idx .. Last_Idx);
end Ada_Attribute_Designator;
---------------------------
-- Ada_Pragma_Identifier --
---------------------------
function Ada_Pragma_Identifier
(Attr : Asis.Pragma_Kinds)
return String
is
Result : String := Attr'Img;
First_Idx : Positive;
Last_Idx : Positive;
begin
case Attr is
when Not_A_Pragma |
An_Implementation_Defined_Pragma |
An_Unknown_Pragma =>
raise Constraint_Error;
when others =>
First_Idx := Index (Result, "_", Forward) + 1;
Last_Idx := Index (Result, "_", Backward) - 1;
end case;
Capitalize (Result (First_Idx .. Last_Idx));
return Result (First_Idx .. Last_Idx);
end Ada_Pragma_Identifier;
------------------------------
-- Full_Expanded_Name_Image --
------------------------------
function Full_Expanded_Name_Image
(Name : Asis.Element)
return Program_Text
is
EE : constant Asis.Element := Enclosing_Element (Name);
begin
if Defining_Name_Kind (Name) = A_Defining_Expanded_Name or else
Is_Nil (Enclosing_Element (EE))
then
return Defining_Name_Image (Name);
else
return Internal_Full_Image (Enclosing_Element (EE)) & '.' &
Defining_Name_Image (Name);
end if;
end Full_Expanded_Name_Image;
-------------------------
-- Internal_Full_Image --
-------------------------
function Internal_Full_Image (E : Asis.Element) return Program_Text is
Next_Scope : Asis.Element := E;
Tmp : Asis.Element;
begin
while not Is_Namable_Scope (Next_Scope) loop
Next_Scope := Enclosing_Element (Next_Scope);
pragma Assert (not (Is_Nil (Next_Scope)));
end loop;
if Is_Part_Of_Instance (Next_Scope) then
Tmp := Enclosing_Element (Next_Scope);
if Declaration_Kind (Tmp) in A_Generic_Instantiation
and then
Is_Nil (Enclosing_Element (Tmp))
then
return Defining_Name_Image (First_Name (Tmp));
end if;
end if;
if Is_Nil (Enclosing_Element (Next_Scope)) then
return Defining_Name_Image (First_Name (Next_Scope));
end if;
case Flat_Element_Kind (Next_Scope) is
when A_Procedure_Body_Declaration |
A_Function_Body_Declaration |
A_Package_Body_Declaration |
A_Task_Body_Declaration |
A_Protected_Body_Declaration =>
-- It can be a subunit here
if Is_Subunit (Next_Scope) then
Next_Scope := Corresponding_Body_Stub (Next_Scope);
Next_Scope := First_Name (Next_Scope);
return Full_Expanded_Name_Image (Next_Scope);
end if;
when A_Block_Statement =>
if Is_Nil (Statement_Identifier (Next_Scope)) then
return Internal_Full_Image (Enclosing_Element (Next_Scope)) &
".";
else
return Internal_Full_Image (Enclosing_Element (Next_Scope)) &
"." & Defining_Name_Image
(Statement_Identifier (Next_Scope));
end if;
when others =>
null;
end case;
return Internal_Full_Image (Enclosing_Element (Next_Scope)) & '.' &
Defining_Name_Image (First_Name (Next_Scope));
end Internal_Full_Image;
----------------------
-- Is_Namable_Scope --
----------------------
function Is_Namable_Scope (E : Element) return Boolean is
begin
case Flat_Element_Kind (E) is
when A_Block_Statement |
A_Task_Type_Declaration |
A_Protected_Type_Declaration |
A_Single_Task_Declaration |
A_Single_Protected_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_Generic_Procedure_Declaration | -- ???
A_Generic_Function_Declaration | -- ???
A_Formal_Package_Declaration | -- ???
A_Formal_Package_Declaration_With_Box -- ???
=>
return True;
when others =>
return False;
end case;
end Is_Namable_Scope;
---------------------------------------
-- Is_Recursive_Component_Definition --
---------------------------------------
function Is_Recursive_Component_Definition
(Def : Asis.Element)
return Boolean
is
Result : Boolean := False;
Tmp : Asis.Element;
Type_Decl : Asis.Element;
begin
if Access_Definition_Kind (Def) in
An_Anonymous_Access_To_Variable .. An_Anonymous_Access_To_Constant
then
-- First, check if we are in component definition:
Tmp := Enclosing_Element (Enclosing_Element (Def));
if Declaration_Kind (Tmp) = A_Component_Declaration then
-- Compute the defining name of enclosing type
Type_Decl := Enclosing_Element (Tmp);
while Element_Kind (Type_Decl) /= A_Declaration loop
Type_Decl := Enclosing_Element (Type_Decl);
end loop;
Tmp := Anonymous_Access_To_Object_Subtype_Mark (Def);
Tmp := Normalize_Reference (Tmp);
Tmp := Corresponding_Name_Declaration (Tmp);
Result := Is_Equal (Tmp, Type_Decl);
end if;
end if;
return Result;
end Is_Recursive_Component_Definition;
---------------
-- Is_Tagged --
---------------
function Is_Tagged (Dcl : Asis.Element) return Boolean is
Result : Boolean := False;
begin
case Declaration_Kind (Dcl) is
when A_Tagged_Incomplete_Type_Declaration |
A_Private_Extension_Declaration =>
Result := True;
when A_Private_Type_Declaration =>
Result :=
Definition_Kind (Type_Declaration_View (Dcl)) =
A_Tagged_Private_Type_Definition;
when An_Ordinary_Type_Declaration =>
Result :=
Asis.Elements.Type_Kind (Type_Declaration_View (Dcl)) in
A_Derived_Record_Extension_Definition |
A_Tagged_Record_Type_Definition |
An_Interface_Type_Definition;
when others =>
null;
end case;
return Result;
end Is_Tagged;
-----------------
-- Is_Volatile --
-----------------
function Is_Volatile (Def_Name : Asis.Element) return Boolean is
E : constant Entity_Id := R_Node (Def_Name);
Result : Boolean := False;
begin
if Defining_Name_Kind (Def_Name) = A_Defining_Identifier then
Result := Treat_As_Volatile (E);
end if;
return Result;
end Is_Volatile;
----------------------
-- Is_Volatile_Type --
----------------------
function Is_Volatile_Type (Subtype_Ref : Asis.Element) return Boolean is
Tmp : Asis.Element;
Pragma_Arg : Asis.Element;
Result : Boolean := False;
begin
if Attribute_Kind (Subtype_Ref) /= A_Class_Attribute then
Tmp := Normalize_Reference (Subtype_Ref);
Tmp := Corresponding_Name_Declaration (Tmp);
Tmp := Corresponding_First_Subtype (Tmp);
if Declaration_Kind (Tmp) = An_Ordinary_Type_Declaration then
declare
Corr_Pragmas : constant Asis.Element_List :=
Corresponding_Pragmas (Tmp);
begin
for J in Corr_Pragmas'Range loop
if Pragma_Kind (Corr_Pragmas (J)) = A_Volatile_Pragma then
Pragma_Arg :=
Pragma_Argument_Associations (Corr_Pragmas (J)) (1);
Pragma_Arg := Actual_Parameter (Pragma_Arg);
if Expression_Kind (Pragma_Arg) = An_Identifier then
Pragma_Arg :=
Corresponding_Name_Definition (Pragma_Arg);
if Is_Equal (Pragma_Arg, Names (Tmp) (1)) then
Result := True;
exit;
end if;
end if;
end if;
end loop;
if not Result then
Tmp := Type_Declaration_View (Tmp);
if Asis.Elements.Type_Kind (Tmp) =
A_Derived_Type_Definition
then
-- Here we have to traverse the derivation chain looking
-- for the Volatile pragma applied to some of the parent
-- types
Tmp := Parent_Subtype_Indication (Tmp);
Tmp := Asis.Definitions.Subtype_Mark (Tmp);
Result := Is_Volatile_Type (Tmp);
end if;
end if;
end;
end if;
end if;
return Result;
end Is_Volatile_Type;
------------------
-- Is_Component --
------------------
function Is_Component (El : Asis.Element) return Boolean is
Result : Boolean := False;
begin
if Expression_Kind (El) = A_Selected_Component then
Result := Nkind (R_Node (El)) /= N_Expanded_Name;
end if;
return Result;
end Is_Component;
----------------------------
-- Adds_New_Nesting_Level --
----------------------------
function Adds_New_Nesting_Level
(El_Kind : Flat_Element_Kinds)
return Boolean
is
Result : Boolean := False;
begin
case El_Kind is
when A_Procedure_Body_Declaration |
A_Function_Body_Declaration |
A_Package_Declaration |
A_Package_Body_Declaration |
A_Task_Body_Declaration |
A_Protected_Body_Declaration |
An_Entry_Body_Declaration |
A_Generic_Package_Declaration |
An_If_Statement |
A_Case_Statement |
A_Loop_Statement |
A_While_Loop_Statement |
A_For_Loop_Statement |
A_Block_Statement |
An_Accept_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 Adds_New_Nesting_Level;
------------
-- Before --
------------
function Before (First : Span; Second : Span) return Boolean is
Result : Boolean := True;
begin
if Is_Nil (First) or else Is_Nil (Second) then
Result := False;
end if;
if Result
and then
(First.First_Line > Second.First_Line
or else
(First.First_Line = Second.First_Line
and then
First.First_Column >= Second.First_Column))
then
Result := False;
end if;
if Result
and then
(First.Last_Line > Second.Last_Line
or else
(First.Last_Line = Second.Last_Line
and then
First.Last_Column >= Second.Last_Column))
then
Result := False;
end if;
return Result;
end Before;
function Before
(First : Asis.Element;
Second : Asis.Element)
return Boolean
is
Result : Boolean := False;
begin
if Is_Text_Available (First)
and then
Is_Text_Available (Second)
and then
Is_Equal (Enclosing_Compilation_Unit (First),
Enclosing_Compilation_Unit (Second))
then
Result :=
Before (First => Element_Span (First),
Second => Element_Span (Second));
end if;
return Result;
end Before;
-------------------------------------
-- Belongs_To_Multiple_Inheritance --
-------------------------------------
function Belongs_To_Multiple_Inheritance (Decl : Element) return Boolean is
Parent_Type : Asis.Element;
Result : Boolean := False;
begin
Parent_Type := Primitive_Owner (Decl);
while Asis.Elements.Type_Kind (Parent_Type) =
A_Derived_Record_Extension_Definition
loop
if not Is_Nil (Definition_Interface_List (Parent_Type)) then
Result := True;
exit;
end if;
Parent_Type := Corresponding_Parent_Subtype (Parent_Type);
if Declaration_Kind (Parent_Type) = A_Subtype_Declaration then
Parent_Type := Corresponding_First_Subtype (Parent_Type);
end if;
if Declaration_Kind (Parent_Type) = A_Private_Type_Declaration then
exit;
end if;
if Declaration_Kind (Parent_Type) =
A_Private_Extension_Declaration
then
Parent_Type := Corresponding_Type_Declaration (Parent_Type);
end if;
Parent_Type := Type_Declaration_View (Parent_Type);
end loop;
return Result;
end Belongs_To_Multiple_Inheritance;
------------------------------
-- Can_Create_Return_Object --
------------------------------
function Can_Create_Return_Object (SM : Asis.Element) return Boolean is
SM_Entity : constant Entity_Id := Entity (R_Node (SM));
SM_Type : Entity_Id;
Result : Boolean := False;
begin
if Present (SM_Entity) then
SM_Type := Etype (SM_Entity);
if not (Is_Abstract_Type (SM_Type)
or else
Is_Limited_Record (SM_Type)
or else
Is_Limited_Composite (SM_Type))
then
Result :=
not ((Has_Discriminants (SM_Type) or else
Is_Array_Type (SM_Type))
and then
not Is_Constrained (SM_Entity));
end if;
end if;
return Result;
end Can_Create_Return_Object;
-------------------------------------
-- Can_Have_Dispatching_Operations --
-------------------------------------
function Can_Have_Dispatching_Operations
(El : Asis.Element)
return Boolean
is
Result : Boolean := False;
begin
case Definition_Kind (El) is
when A_Type_Definition =>
case Asis.Elements.Type_Kind (El) is
when A_Derived_Record_Extension_Definition |
A_Tagged_Record_Type_Definition =>
Result :=
Is_Nil (Corresponding_Type_Declaration
(Enclosing_Element (El)));
when An_Interface_Type_Definition =>
Result := True;
when others =>
null;
end case;
when A_Tagged_Private_Type_Definition |
A_Private_Extension_Definition =>
Result := True;
when others =>
null;
end case;
return Result;
end Can_Have_Dispatching_Operations;
--------------------------------
-- Can_Have_Elaboration_Calls --
--------------------------------
function Can_Have_Elaboration_Calls (El : Asis.Element) return Boolean is
Arg_Kind : constant Flat_Element_Kinds := Flat_Element_Kind (El);
Tmp_El : Asis.Element := Nil_Element;
Result : Boolean := False;
begin
-- Note that we do not have to care about evaluating default parameters
-- for IN formal objects for package instantiations- the corresponding
-- default expression will be processed as a part of processing the
-- expanded generic. But we have to care about subprogram
-- instantiations
case Arg_Kind is
when A_Variable_Declaration =>
Result := Is_Nil (Initialization_Expression (El));
when A_Function_Call |
A_Procedure_Call_Statement =>
-- Calls to operator functions and to attribute subprograms cannot
-- evaluate any default expressions:
if Arg_Kind = A_Procedure_Call_Statement then
Tmp_El := Called_Name (El);
elsif Arg_Kind = A_Function_Call then
Tmp_El := Prefix (El);
else
Tmp_El := Nil_Element;
end if;
if Expression_Kind (Tmp_El) = A_Selected_Component then
Tmp_El := Selector (Tmp_El);
end if;
Result := not (Expression_Kind (Tmp_El) = An_Attribute_Reference
or else
Expression_Kind (Tmp_El) = An_Operator_Symbol);
when A_Procedure_Instantiation |
A_Function_Instantiation |
An_Allocation_From_Subtype |
An_Entry_Call_Statement =>
Result := True;
when others =>
null;
end case;
return Result;
end Can_Have_Elaboration_Calls;
----------------
-- Capitalize --
----------------
procedure Capitalize (S : in out String) is
Next_Char_Uppercase : Boolean := True;
begin
for J in S'Range loop
if Next_Char_Uppercase then
S (J) := To_Upper (S (J));
else
S (J) := To_Lower (S (J));
end if;
if S (J) = '_' then
Next_Char_Uppercase := True;
else
Next_Char_Uppercase := False;
end if;
end loop;
end Capitalize;
--------------
-- Contains --
--------------
function Contains
(Outer : Element;
Inner : Element)
return Boolean
is
Outer_Span : Span;
Inner_Span : Span;
Result : Boolean := False;
begin
if Is_Text_Available (Outer) and then
Is_Text_Available (Inner)
then
Outer_Span := Element_Span (Outer);
Inner_Span := Element_Span (Inner);
if (Outer_Span.First_Line < Inner_Span.First_Line
or else
(Outer_Span.First_Line = Inner_Span.First_Line and then
Outer_Span.First_Column <= Inner_Span.First_Column))
and then
(Outer_Span.Last_Line > Inner_Span.Last_Line
or else
(Outer_Span.Last_Line = Inner_Span.Last_Line and then
Outer_Span.Last_Column >= Inner_Span.Last_Column))
then
Result := True;
end if;
end if;
return Result;
end Contains;
-------------------------
-- Contains_Raise_Stmt --
-------------------------
function Contains_Raise_Stmt (C : Asis.Element) return Boolean is
Result : Boolean := False;
Control : Traverse_Control := Continue;
procedure Check_For_Raise
(Element : Asis.Element;
Control : in out Traverse_Control;
State : in out Boolean);
-- If Element is a raise statement, sets State to True and Control to
-- terminate_Immediatelly. Otherwise does nothing
procedure No_Op
(Element : Asis.Element;
Control : in out Traverse_Control;
State : in out Boolean);
-- Does nothing
procedure Look_For_Raise is new
Traverse_Element (Boolean, Check_For_Raise, No_Op);
procedure Check_For_Raise
(Element : Asis.Element;
Control : in out Traverse_Control;
State : in out Boolean)
is
begin
if Statement_Kind (Element) = A_Raise_Statement then
State := True;
Control := Terminate_Immediately;
end if;
end Check_For_Raise;
procedure No_Op
(Element : Asis.Element;
Control : in out Traverse_Control;
State : in out Boolean)
is
begin
null;
end No_Op;
begin
Look_For_Raise (C, Control, Result);
return Result;
end Contains_Raise_Stmt;
-----------------------
-- Defines_Predicate --
-----------------------
function Defines_Predicate (A : Asis.Element) return Boolean is
Result : Boolean := False;
Aspect_M : Asis.Element;
Aspect_Name : Program_Text_Access;
begin
if Definition_Kind (A) = An_Aspect_Specification then
Aspect_M := Aspect_Mark (A);
if Expression_Kind (Aspect_M) = An_Attribute_Reference then
Aspect_M := Prefix (Aspect_M);
end if;
Aspect_Name :=
new Program_Text'
(ASIS_UL.Misc.To_Lower_Case (Name_Image (Aspect_M)));
Result := Aspect_Name.all = "static_predicate"
or else
Aspect_Name.all = "dynamic_predicate"
or else
Aspect_Name.all = "type_invariant"
or else
Aspect_Name.all = "pre"
or else
Aspect_Name.all = "post";
Free (Aspect_Name);
end if;
return Result;
end Defines_Predicate;
----------------------------
-- Dispatching_Operations --
----------------------------
function Dispatching_Operations
(Type_Def : Asis.Element)
return Asis.Element_List
is
Type_Node : Node_Id;
Prim_Ops : Elist_Id;
Next_Pr_El : Elmt_Id;
Next_Primitive : Node_Id;
Res_Node : Node_Id;
Res_NF_1 : Node_Id;
Res_Kind : Internal_Element_Kinds;
Inherited : Boolean;
Res_Element : Asis.Element;
begin
-- See ASIS_UL.Global_State.Utilities.Implemented_Operations. Is any
-- factorization possible here?
if not Can_Have_Dispatching_Operations (Type_Def) then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Dispatching_Operations",
Wrong_Kind => Int_Kind (Type_Def));
end if;
Type_Node := Node (Enclosing_Element (Type_Def));
Type_Node := Defining_Identifier (Type_Node);
if not Has_Primitive_Operations (Type_Node) then
return Nil_Element_List;
end if;
Asis_Element_Table.Init;
Prim_Ops := Primitive_Operations (Type_Node);
Next_Pr_El := First_Elmt (Prim_Ops);
while Present (Next_Pr_El) loop
Next_Primitive := Node (Next_Pr_El);
if No (Interface_Alias (Next_Primitive)) then
if Comes_From_Source (Next_Primitive) then
Inherited := False;
Res_Node := Parent (Parent (Next_Primitive));
Res_NF_1 := Empty;
Res_Kind := Not_An_Element;
else
-- See implementation of
-- Asis.Definitions.Implicit_Inherited_Subprograms:
Inherited := True;
Res_NF_1 := Next_Primitive;
Res_Node := Explicit_Parent_Subprogram (Next_Primitive);
Res_Node := Parent (Res_Node);
if Ekind (Next_Primitive) = E_Function then
Res_Kind := A_Function_Declaration;
elsif Null_Present (Res_Node) then
Res_Kind := A_Null_Procedure_Declaration;
else
Res_Kind := A_Procedure_Declaration;
end if;
Res_Node := Parent (Res_Node);
end if;
Res_Element :=
Node_To_Element_New
(Node => Res_Node,
Node_Field_1 => Res_NF_1,
Internal_Kind => Res_Kind,
Inherited => Inherited,
In_Unit => Enclosing_Unit
(Encl_Cont_Id (Type_Def),
Next_Primitive));
if Is_From_Instance (Type_Def) then
Set_From_Instance (Res_Element, True);
else
Set_From_Instance (Res_Element, False);
end if;
Asis_Element_Table.Append (Res_Element);
end if;
Next_Pr_El := Next_Elmt (Next_Pr_El);
end loop;
return Asis.Element_List
(Asis_Element_Table.Table (1 .. Asis_Element_Table.Last));
end Dispatching_Operations;
---------------------------------
-- Does_Not_Add_New_Components --
---------------------------------
function Does_Not_Add_New_Components (El : Asis.Element) return Boolean is
Result : Boolean := False;
Tmp : Asis.Element;
begin
if Asis.Elements.Type_Kind (El) =
A_Derived_Record_Extension_Definition
then
Tmp := Asis.Definitions.Record_Definition (El);
if Definition_Kind (Tmp) = A_Null_Record_Definition then
Result := True;
elsif Record_Components (Tmp)'Length = 1
and then
Definition_Kind (Record_Components (Tmp) (1)) = A_Null_Component
then
Result := True;
end if;
end if;
return Result;
end Does_Not_Add_New_Components;
---------------------
-- Call_Parameters --
---------------------
function Call_Parameters (Call : Asis.Element) return Asis.Element_List is
begin
case Flat_Element_Kind (Call) is
when A_Procedure_Call_Statement |
An_Entry_Call_Statement =>
return Call_Statement_Parameters (Call);
when A_Function_Call =>
return Function_Call_Parameters (Call);
when others =>
pragma Assert (False);
return Nil_Element_List;
end case;
end Call_Parameters;
--------------------------------------
-- Unwind_Derivations_And_Subtyping --
--------------------------------------
function Unwind_Derivations_And_Subtyping
(Decl : Asis.Element)
return Asis.Element
is
Result : Asis.Element := Decl;
Def : Asis.Element := Type_Declaration_View (Result);
begin
if Definition_Kind (Def) = A_Subtype_Indication then
Result := Corresponding_First_Subtype (Def);
Def := Type_Declaration_View (Result);
end if;
if Asis.Elements.Type_Kind (Def) in A_Derived_Type_Definition ..
A_Derived_Record_Extension_Definition
then
Result := Corresponding_Root_Type (Def);
end if;
return Result;
end Unwind_Derivations_And_Subtyping;
--------------------
-- Get_Called_Ref --
--------------------
function Get_Called_Ref (Call : Asis.Element) return Asis.Element is
begin
if Expression_Kind (Call) = A_Function_Call then
return Prefix (Call);
else
return Called_Name (Call);
end if;
end Get_Called_Ref;
--------------------
-- Called_Profile --
--------------------
function Called_Profile (Call : Asis.Element) return Asis.Element_List is
Get_Profile_From : Asis.Element;
Tmp : Asis.Element;
begin
-- Filter out the case of a call to a predefined operator
if Expression_Kind (Call) = A_Function_Call then
Tmp := Prefix (Call);
Tmp := Normalize_Reference (Tmp);
if Is_Predefined_Operator (Tmp) then
return Nil_Element_List;
end if;
end if;
-- Filter out the case of a call to attribute subprogram:
if Is_Call_To_Attribute_Subprogram (Call) then
return Nil_Element_List;
end if;
case Flat_Element_Kind (Call) is
when A_Procedure_Call_Statement |
An_Entry_Call_Statement =>
Get_Profile_From := Corresponding_Called_Entity (Call);
when A_Function_Call =>
Get_Profile_From := Corresponding_Called_Function (Call);
when others =>
pragma Assert (False);
return Nil_Element_List;
end case;
if Is_Nil (Get_Profile_From) then
-- two possibilities: either a dispatching call or a dynamic call
-- through access-to-subprogram value
if Is_Dispatching_Call (Call) then
Tmp := Get_Called_Ref (Call);
Tmp := Normalize_Reference (Tmp);
Get_Profile_From := Corresponding_Name_Declaration (Tmp);
else
-- Call through access-to-subprogram value
Get_Profile_From := Get_Called_Ref (Call);
if Expression_Kind (Get_Profile_From) =
An_Explicit_Dereference
then
Get_Profile_From := Prefix (Get_Profile_From);
end if;
Tmp := Get_Profile_From;
Get_Profile_From :=
Corresponding_Expression_Type (Get_Profile_From);
if not Is_Nil (Get_Profile_From) then
Get_Profile_From :=
Unwind_Derivations_And_Subtyping (Get_Profile_From);
else
-- Here we have the dynamic call to a subprogram through
-- anonymous access-to-subprogram type.
Get_Profile_From := Normalize_Reference (Tmp);
case Expression_Kind (Get_Profile_From) is
when An_Identifier =>
Get_Profile_From :=
Corresponding_Name_Declaration (Get_Profile_From);
when An_Indexed_Component =>
-- No need to check for Corresponding_Expression_Type -
-- we have already tried this out, and the result is
-- Nil_Element. Here we have an indexed component that
-- has an anonymous array type.
Get_Profile_From := Prefix (Get_Profile_From);
Get_Profile_From :=
Corresponding_Expression_Type (Get_Profile_From);
if Is_Nil (Get_Profile_From) then
-- Anonymous access types - endless nightmare :(
raise Non_Implemented_Error;
end if;
Get_Profile_From := Unwind_Derivations_And_Subtyping
(Get_Profile_From);
when others =>
raise Non_Implemented_Error;
end case;
end if;
end if;
end if;
if Declaration_Kind (Get_Profile_From) in
A_Procedure_Instantiation .. A_Function_Instantiation
then
Get_Profile_From := Corresponding_Declaration (Get_Profile_From);
end if;
case Declaration_Kind (Get_Profile_From) is
when A_Procedure_Declaration |
A_Function_Declaration |
A_Procedure_Body_Declaration |
A_Function_Body_Declaration |
A_Procedure_Renaming_Declaration |
A_Function_Renaming_Declaration |
An_Entry_Declaration |
An_Entry_Body_Declaration |
A_Procedure_Body_Stub |
A_Function_Body_Stub |
A_Generic_Procedure_Declaration |
A_Generic_Function_Declaration |
A_Formal_Procedure_Declaration |
A_Formal_Function_Declaration =>
return Parameter_Profile (Get_Profile_From);
when An_Ordinary_Type_Declaration =>
Get_Profile_From := Type_Declaration_View (Get_Profile_From);
case Asis.Elements.Type_Kind (Get_Profile_From) is
when An_Access_Type_Definition =>
pragma Assert (Access_Type_Kind (Get_Profile_From) in
Asis.Access_To_Subprogram_Definition);
return
Access_To_Subprogram_Parameter_Profile (Get_Profile_From);
when An_Unconstrained_Array_Definition |
A_Constrained_Array_Definition =>
Get_Profile_From :=
Array_Component_Definition (Get_Profile_From);
Get_Profile_From :=
Component_Definition_View (Get_Profile_From);
return
Access_To_Subprogram_Parameter_Profile (Get_Profile_From);
when others =>
raise Non_Implemented_Error;
end case;
when A_Parameter_Specification |
A_Variable_Declaration |
A_Constant_Declaration |
A_Discriminant_Specification |
An_Object_Renaming_Declaration =>
-- Use of anonymous Access-to-subprogram type
Get_Profile_From := Object_Declaration_View (Get_Profile_From);
return Access_To_Subprogram_Parameter_Profile (Get_Profile_From);
when A_Component_Declaration =>
-- Use of anonymous Access-to-subprogram type
Get_Profile_From := Object_Declaration_View (Get_Profile_From);
Get_Profile_From := Component_Definition_View (Get_Profile_From);
return Access_To_Subprogram_Parameter_Profile (Get_Profile_From);
when others =>
raise Non_Implemented_Error;
end case;
end Called_Profile;
-------------------------------
-- Get_Parameter_Declaration --
-------------------------------
function Get_Parameter_Declaration (El : Asis.Element) return Asis.Element
is
Formal_Par : constant Asis.Element := Formal_Parameter (El);
Actual_Par : constant Asis.Element := Actual_Parameter (El);
Result : Asis.Element;
begin
if Is_Nil (Formal_Par) then
declare
Call : constant Asis.Element := Enclosing_Element (El);
Norm_Pars : constant Asis.Element_List :=
(if Expression_Kind (Call) = A_Function_Call then
Function_Call_Parameters (Call, Normalized => True)
else
Call_Statement_Parameters (Call, Normalized => True));
begin
for J in Norm_Pars'Range loop
if Is_Equal (Actual_Parameter (Norm_Pars (J)), Actual_Par) then
Result :=
Enclosing_Element (Formal_Parameter (Norm_Pars (J)));
exit;
end if;
end loop;
end;
else
Result := Corresponding_Name_Declaration (Formal_Par);
end if;
pragma Assert (not Is_Nil (Result));
return Result;
end Get_Parameter_Declaration;
------------------------
-- Get_Called_Element --
------------------------
function Get_Called_Element (Call : Asis.Element) return Asis.Element is
Result : Asis.Element := Nil_Element;
Tmp : Asis.Element;
begin
if Expression_Kind (Call) in A_Function_Call | An_Indexed_Component then
-- An_Indexed_Component can be Is_Generalized_Indexing only here!
Result := Corresponding_Called_Function (Call);
else
Result := Corresponding_Called_Entity (Call);
end if;
if Is_Nil (Result)
and then
Is_Dispatching_Call (Call)
then
if Expression_Kind (Call) = A_Function_Call then
Tmp := Prefix (Call);
else
Tmp := Called_Name (Call);
end if;
Result := Corresponding_Name_Declaration (Normalize_Reference (Tmp));
end if;
return Result;
end Get_Called_Element;
--------------------
-- Get_Statements --
--------------------
function Get_Statements (El : Asis.Element) return Asis.Element_List is
begin
case Int_Kind (El) is
when A_Procedure_Body_Declaration |
A_Function_Body_Declaration |
A_Package_Body_Declaration |
A_Task_Body_Declaration |
An_Entry_Body_Declaration =>
return Body_Statements (El);
when A_Loop_Statement |
A_While_Loop_Statement |
A_For_Loop_Statement =>
return Loop_Statements (El);
when An_If_Path .. A_Then_Abort_Path =>
return Sequence_Of_Statements (El);
when A_Block_Statement =>
return Block_Statements (El);
when An_Extended_Return_Statement =>
return Extended_Return_Statements (El);
when An_Accept_Statement =>
return Accept_Body_Statements (El);
when others =>
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Get_Statements",
Wrong_Kind => Int_Kind (El));
return Nil_Element_List;
end case;
end Get_Statements;
---------------------------
-- Get_Subtype_Structure --
---------------------------
function Get_Subtype_Structure (Def : Asis.Element) return Asis.Element is
Result : Asis.Element := Def;
begin
if Definition_Kind (Def) = A_Subtype_Indication then
Result := Asis.Definitions.Subtype_Mark (Result);
else
Result := Anonymous_Access_To_Object_Subtype_Mark (Result);
end if;
Result := Normalize_Reference (Result);
Result := Corresponding_Name_Declaration (Result);
Result := Get_Type_Structure (Result);
return Result;
end Get_Subtype_Structure;
------------------------
-- Get_Type_Structure --
------------------------
function Get_Type_Structure (Decl : Asis.Element) return Asis.Element is
Arg_Kind : constant Declaration_Kinds := Declaration_Kind (Decl);
Result : Asis.Element := Decl;
Tmp : Asis.Element;
begin
-- Should be replaced with regular kind check!
pragma Assert
(Arg_Kind in
An_Ordinary_Type_Declaration .. A_Subtype_Declaration
or else
Arg_Kind = A_Formal_Type_Declaration);
-- We cannot use Asis,Definitions queries Corresponding_Root_Type or
-- Corresponding_Type_Structure - they unwind derivations, so we can
-- miss extension components
case Arg_Kind is
when A_Task_Type_Declaration |
A_Protected_Type_Declaration |
An_Incomplete_Type_Declaration |
A_Tagged_Incomplete_Type_Declaration |
A_Formal_Type_Declaration =>
null;
when An_Ordinary_Type_Declaration =>
Tmp := Type_Declaration_View (Result);
if Asis.Elements.Type_Kind (Tmp) = A_Derived_Type_Definition
or else
(Asis.Elements.Type_Kind (Tmp) =
A_Derived_Record_Extension_Definition
and then
Does_Not_Add_New_Components (Tmp))
then
Result := Parent_Subtype_Indication (Tmp);
Result := Get_Subtype_Structure (Result);
end if;
when A_Private_Type_Declaration |
A_Private_Extension_Declaration =>
Result :=
Get_Type_Structure (Corresponding_Type_Completion (Result));
when A_Subtype_Declaration =>
Result := Type_Declaration_View (Result);
Result := Get_Subtype_Structure (Result);
when others =>
pragma Assert (False);
null;
end case;
return Result;
end Get_Type_Structure;
-------------------------------
-- GNAT_Attribute_Designator --
-------------------------------
function GNAT_Attribute_Designator
(Attr : Snames.Attribute_Id)
return String
is
Result : String := Attr'Img;
First_Idx : constant Positive := Index (Result, "_", Forward) + 1;
Last_Idx : constant Positive := Result'Last;
begin
Capitalize (Result (First_Idx .. Last_Idx));
return Result (First_Idx .. Last_Idx);
end GNAT_Attribute_Designator;
----------------------------
-- GNAT_Pragma_Identifier --
----------------------------
function GNAT_Pragma_Identifier
(Attr : Snames.Pragma_Id)
return String
is
Result : String := Attr'Img;
First_Idx : constant Positive := Index (Result, "_", Forward) + 1;
Last_Idx : constant Positive := Result'Last;
begin
Capitalize (Result (First_Idx .. Last_Idx));
return Result (First_Idx .. Last_Idx);
end GNAT_Pragma_Identifier;
-----------------------
-- Has_Pragma_Inline --
-----------------------
function Has_Pragma_Inline (Subpr : Element) return Boolean is
Arg : Asis.Element := Subpr;
Subpr_Entity : Entity_Id;
Result : Boolean := False;
begin
-- In case of a generic instantiation (or expanded subprogram) there can
-- be two sources of pragma Inline:
--
-- - Inline is applied to the instantiation itself,in this case
-- Has_Pragma_Inline flag is set for the entity of expanded spec;
--
-- - Inline is applied to the generic subprogram, in this case
-- Has_Pragma_Inline is set for generic subprogram entity.
--
-- This makes the logic of this check a bit twisty :(
-- First, get rid of unexpected elements:
case Declaration_Kind (Arg) is
when A_Procedure_Declaration |
A_Function_Declaration |
A_Procedure_Body_Declaration |
A_Function_Body_Declaration |
An_Expression_Function_Declaration |
A_Generic_Procedure_Declaration |
A_Generic_Function_Declaration |
A_Procedure_Instantiation |
A_Function_Instantiation =>
-- ???WHAT ABOUT SUBPROGRAM RENAMINGS???
null; -- Just to continue...
when others =>
return False;
end case;
-- If we have an instantiation or an expanded subprogram, check if we
-- have Inline for generic:
if Special_Case (Arg) = Expanded_Subprogram_Instantiation then
Arg := Enclosing_Element (Arg);
end if;
if Declaration_Kind (Arg) in
A_Procedure_Instantiation .. A_Function_Instantiation
then
Arg := Generic_Unit_Name (Arg);
Arg := Normalize_Reference (Arg);
Arg := Corresponding_Name_Declaration (Arg);
if Declaration_Kind (Arg) in
A_Generic_Procedure_Renaming_Declaration ..
A_Generic_Function_Renaming_Declaration
then
Arg := Corresponding_Base_Entity (Arg);
Arg := Normalize_Reference (Arg);
Arg := Corresponding_Name_Declaration (Arg);
end if;
Subpr_Entity := R_Node (Arg);
Subpr_Entity := Defining_Unit_Name (Specification (Subpr_Entity));
-- Looks like a corner case, but still:
if Nkind (Subpr_Entity) = N_Defining_Program_Unit_Name then
Subpr_Entity := Defining_Identifier (Subpr_Entity);
end if;
Result := Has_Pragma_Inline (Subpr_Entity);
end if;
if Result then
return True;
end if;
-- If we have an instantiation (and we are here - that is, generic
-- does not have Inline!), we have to check expanded spec:
Arg := Subpr;
if Declaration_Kind (Arg) in
A_Procedure_Instantiation .. A_Function_Instantiation
then
Arg := Corresponding_Declaration (Arg);
end if;
-- Arg cannot be an instantiation any more
Subpr_Entity := R_Node (Arg);
Subpr_Entity := Defining_Unit_Name (Specification (Subpr_Entity));
-- Looks like a corner case, but still:
if Nkind (Subpr_Entity) = N_Defining_Program_Unit_Name then
Subpr_Entity := Defining_Identifier (Subpr_Entity);
end if;
Result := Has_Pragma_Inline (Subpr_Entity);
if not Result
and then
Declaration_Kind (Arg) in
A_Procedure_Body_Declaration |
A_Function_Body_Declaration |
An_Expression_Function_Declaration
then
Result := Has_Pragma_Inline (Corresponding_Declaration (Arg));
end if;
return Result;
end Has_Pragma_Inline;
---------------------
-- In_Private_Part --
---------------------
function In_Private_Part
(Pack : Asis.Element;
Element : Asis.Element)
return Boolean
is
Result : Boolean := False;
begin
if Is_Text_Available (Pack)
and then
Is_Text_Available (Element)
and then
Is_Equal (Enclosing_Compilation_Unit (Pack),
Enclosing_Compilation_Unit (Element))
and then
(Declaration_Kind (Pack) = A_Package_Declaration
or else
Declaration_Kind (Pack) = A_Generic_Package_Declaration)
then
declare
Private_Dcls : constant Element_List :=
Private_Part_Declarative_Items (Pack, Include_Pragmas => True);
Private_Span : Span;
Arg_Span : Span;
begin
if not Is_Nil (Private_Dcls) then
Arg_Span := Element_Span (Private_Dcls (Private_Dcls'First));
Private_Span.First_Line := Arg_Span.First_Line;
Private_Span.First_Column := Arg_Span.First_Column;
Arg_Span := Element_Span (Private_Dcls (Private_Dcls'Last));
Private_Span.Last_Line := Arg_Span.Last_Line;
Private_Span.Last_Column := Arg_Span.Last_Column;
Arg_Span := Element_Span (Element);
Result := Inclides (Whole => Private_Span, Part => Arg_Span);
end if;
end;
end if;
return Result;
end In_Private_Part;
--------------
-- Inclides --
--------------
function Inclides (Whole : Span; Part : Span) return Boolean is
Result : Boolean := True;
begin
if Is_Nil (Whole) or else Is_Nil (Part) then
Result := False;
end if;
if Result
and then
(Whole.First_Line > Part.First_Line
or else
(Whole.First_Line = Part.First_Line
and then
Whole.First_Column > Part.First_Column))
then
Result := False;
end if;
if Result
and then
(Whole.Last_Line < Part.Last_Line
or else
(Whole.Last_Line = Part.Last_Line
and then
Whole.Last_Column < Part.Last_Column))
then
Result := False;
end if;
return Result;
end Inclides;
function Inclides
(Whole : Asis.Element;
Part : Asis.Element)
return Boolean
is
Result : Boolean := False;
begin
if Is_Text_Available (Whole)
and then
Is_Text_Available (Part)
and then
Is_Equal (Enclosing_Compilation_Unit (Whole),
Enclosing_Compilation_Unit (Part))
then
Result :=
Inclides (Whole => Element_Span (Whole),
Part => Element_Span (Part));
end if;
return Result;
end Inclides;
-----------------------
-- Inheritance_Depth --
-----------------------
function Inheritance_Depth (Type_Def : Asis.Element) return Natural is
Result : Natural := 0;
Parent_Type_Def : Asis.Element := Nil_Element;
begin
if Asis.Elements.Type_Kind (Type_Def) =
A_Derived_Record_Extension_Definition
then
Parent_Type_Def := Parent_Subtype_Indication (Type_Def);
Parent_Type_Def := Asis.Definitions.Subtype_Mark (Parent_Type_Def);
elsif Formal_Type_Kind (Type_Def) = A_Formal_Derived_Type_Definition then
Parent_Type_Def := Asis.Definitions.Subtype_Mark (Type_Def);
elsif Definition_Kind (Type_Def) = A_Private_Extension_Definition then
Parent_Type_Def := Ancestor_Subtype_Indication (Type_Def);
Parent_Type_Def := Asis.Definitions.Subtype_Mark (Parent_Type_Def);
end if;
if not Is_Nil (Parent_Type_Def) then
Parent_Type_Def := Normalize_Reference (Parent_Type_Def);
Parent_Type_Def := Corresponding_Name_Declaration (Parent_Type_Def);
Parent_Type_Def := Corresponding_First_Subtype (Parent_Type_Def);
Parent_Type_Def := Type_Declaration_View (Parent_Type_Def);
Result := 1 + Inheritance_Depth (Parent_Type_Def);
end if;
if Asis.Elements.Type_Kind (Type_Def) =
A_Derived_Record_Extension_Definition
or else
Asis.Elements.Type_Kind (Type_Def) = An_Interface_Type_Definition
or else
Definition_Kind (Type_Def) = A_Private_Extension_Definition
or else
Formal_Type_Kind (Type_Def) = A_Formal_Derived_Type_Definition
or else
Formal_Type_Kind (Type_Def) = A_Formal_Interface_Type_Definition
then
declare
Interface_List : constant Asis.Element_List :=
Definition_Interface_List (Type_Def);
begin
if Is_Nil (Interface_List)
and then
Formal_Type_Kind (Type_Def) = A_Formal_Derived_Type_Definition
then
return Result - 1;
elsif Interface_List'Length = 1
and then
Formal_Type_Kind (Type_Def) =
A_Formal_Interface_Type_Definition
then
return
Inheritance_Depth (Interface_List (Interface_List'First));
end if;
for J in Interface_List'Range loop
Parent_Type_Def := Normalize_Reference (Interface_List (J));
Parent_Type_Def :=
Corresponding_Name_Declaration (Parent_Type_Def);
Parent_Type_Def :=
Corresponding_First_Subtype (Parent_Type_Def);
Parent_Type_Def := Type_Declaration_View (Parent_Type_Def);
Result :=
Natural'Max (Result, 1 + Inheritance_Depth (Parent_Type_Def));
end loop;
end;
end if;
return Result;
end Inheritance_Depth;
--------------------
-- Interface_List --
--------------------
function Interface_List (Decl : Asis.Element) return Asis.Element_List is
begin
if not May_Have_Interface_List (Decl) then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Interface_List",
Wrong_Kind => Int_Kind (Decl));
end if;
case Declaration_Kind (Decl) is
when A_Task_Type_Declaration |
A_Protected_Type_Declaration |
A_Single_Task_Declaration |
A_Single_Protected_Declaration =>
return Declaration_Interface_List (Decl);
when others =>
return Definition_Interface_List (Type_Declaration_View (Decl));
end case;
end Interface_List;
-------------------------
-- Is_Access_Attribute --
-------------------------
function Is_Access_Attribute (Attr : Asis.Element) return Boolean is
Result : Boolean := False;
begin
case Attribute_Kind (Attr) is
when An_Access_Attribute |
An_Unchecked_Access_Attribute =>
Result := True;
when An_Implementation_Defined_Attribute =>
if To_Lower (To_String (Name_Image
(Attribute_Designator_Identifier (Attr)))) =
"unrestricted_access"
then
Result := True;
end if;
when others =>
null;
end case;
return Result;
end Is_Access_Attribute;
-------------------------------------
-- Is_Call_To_Attribute_Subprogram --
-------------------------------------
function Is_Call_To_Attribute_Subprogram
(El : Asis.Element)
return Boolean
is
Result : Boolean := False;
Call_Prefix : Asis.Element := Nil_Element;
begin
case Flat_Element_Kind (El) is
when A_Procedure_Call_Statement =>
Call_Prefix := Called_Name (El);
when A_Function_Call =>
if Is_Prefix_Call (El) then
Call_Prefix := Prefix (El);
end if;
when others =>
null;
end case;
if Expression_Kind (Call_Prefix) = An_Attribute_Reference then
Result := True;
end if;
return Result;
end Is_Call_To_Attribute_Subprogram;
-----------------------------
-- Is_Constructor_Function --
-----------------------------
function Is_Constructor_Function (El : Asis.Element) return Boolean is
Tmp : Asis.Element;
F_Node : Node_Id;
P_Node : Node_Id;
Arg : Asis.Element := El;
Result : Boolean := False;
begin
case Declaration_Kind (El) is
when A_Function_Declaration |
A_Function_Body_Declaration |
An_Expression_Function_Declaration |
A_Function_Renaming_Declaration |
A_Function_Instantiation =>
if Is_Dispatching_Operation (El) then
Tmp := First_Name (El);
if Defining_Name_Kind (Tmp) /= A_Defining_Expanded_Name then
F_Node := R_Node (Tmp);
if Has_Controlling_Result (F_Node) then
if Declaration_Kind (Arg) = A_Function_Instantiation then
Arg := Corresponding_Declaration (Arg);
end if;
P_Node := R_Node (Arg);
P_Node := Specification (P_Node);
Result := True;
if Is_Non_Empty_List
(Parameter_Specifications (P_Node))
then
P_Node :=
First_Non_Pragma (Parameter_Specifications (P_Node));
while Present (P_Node) loop
if Is_Controlling_Formal
(Defining_Identifier (P_Node))
then
Result := False;
exit;
end if;
P_Node := Next_Non_Pragma (P_Node);
end loop;
end if;
end if;
end if;
end if;
when others => null;
end case;
return Result;
end Is_Constructor_Function;
-------------------
-- Is_Controlled --
-------------------
function Is_Controlled (Type_Name : Asis.Element) return Boolean is
Result : Boolean := False;
begin
if Defining_Name_Kind (Type_Name) = A_Defining_Identifier then
if Is_Controlled (R_Node (Type_Name)) then
Result := True;
end if;
end if;
return Result;
end Is_Controlled;
-----------------------------------
-- Is_Controlling_Type_Operation --
-----------------------------------
function Is_Controlling_Type_Operation (El : Asis.Element) return Boolean is
Type_Decl : Asis.Element;
Result : Boolean := False;
begin
if not Is_Part_Of_Inherited (El)
and then
Is_Dispatching_Operation (El)
then
Type_Decl := Primitive_Owner (El);
Type_Decl := First_Name (Enclosing_Element (Type_Decl));
if Is_Controlled (Type_Decl)
and then
Parameter_Profile (El)'Length = 1
and then
Mode_Kind (Parameter_Profile (El) (1)) = An_In_Out_Mode
then
declare
El_Name : constant String :=
To_Lower (To_String (Defining_Name_Image (First_Name (El))));
begin
if El_Name = "initialize"
or else
El_Name = "finalize"
then
Result := True;
elsif El_Name = "adjust"
and then
not Is_Limited_Type (R_Node (Type_Decl))
then
Result := True;
end if;
end;
end if;
end if;
return Result;
end Is_Controlling_Type_Operation;
---------------------
-- Is_Derived_From --
---------------------
function Is_Derived_From
(Descendant : Element;
Ancestor : Element)
return Boolean
is
Result : Boolean := False;
Ancestor_Arg : Asis.Element;
Descendant_Arg : Asis.Element;
Def : Asis.Element;
begin
if Declaration_Kind (Ancestor) in
A_Private_Type_Declaration .. A_Private_Extension_Declaration
then
Ancestor_Arg := Corresponding_Type_Declaration (Ancestor);
else
Ancestor_Arg := Ancestor;
end if;
if Declaration_Kind (Descendant) in
A_Private_Type_Declaration .. A_Private_Extension_Declaration
then
Descendant_Arg := Corresponding_Type_Declaration (Descendant);
else
Descendant_Arg := Descendant;
end if;
if Declaration_Kind (Ancestor_Arg) in
An_Ordinary_Type_Declaration .. A_Protected_Type_Declaration
and then
Declaration_Kind (Descendant_Arg) = An_Ordinary_Type_Declaration
then
Def := Type_Declaration_View (Descendant_Arg);
while Asis.Elements.Type_Kind (Def) in A_Derived_Type_Definition ..
A_Derived_Record_Extension_Definition
loop
Def := Corresponding_Parent_Subtype (Def);
if Is_Nil (Def) then
-- case of
-- type NT is new T'Base;
Def := Parent_Subtype_Indication (Def);
Def := Asis.Definitions.Subtype_Mark (Def);
Def := Normalize_Reference (Def);
Def := Corresponding_Name_Declaration (Def);
end if;
Def := Corresponding_First_Subtype (Def);
if Declaration_Kind (Def) in
A_Private_Type_Declaration .. A_Private_Extension_Declaration
then
Def := Corresponding_Type_Declaration (Def);
end if;
if Is_Equal (Def, Ancestor_Arg) then
Result := True;
exit;
end if;
Def := Type_Declaration_View (Def);
end loop;
end if;
return Result;
end Is_Derived_From;
------------------------
-- Is_Executable_Body --
------------------------
function Is_Executable_Body (El : Element) return Boolean is
El_Kind : constant Flat_Element_Kinds := Flat_Element_Kind (El);
Result : Boolean := False;
begin
case El_Kind is
when An_Expression_Function_Declaration |
A_Procedure_Body_Declaration |
A_Function_Body_Declaration |
A_Task_Body_Declaration |
An_Entry_Body_Declaration =>
Result := True;
when A_Package_Body_Declaration =>
Result := Body_Statements (El)'Length > 0;
when others =>
null;
end case;
return Result;
end Is_Executable_Body;
----------------
-- Is_Handled --
----------------
function Is_Handled
(Exc : Asis.Element;
H : Asis.Element)
return Boolean
is
Choices : constant Asis.Element_List := Exception_Choices (H);
Handled_Exc : Asis.Element;
Result : Boolean := False;
begin
if Definition_Kind (Choices (Choices'First)) = An_Others_Choice then
Result := not Contains_Raise_Stmt (H);
else
for J in Choices'Range loop
Handled_Exc := Normalize_Reference (Choices (J));
Handled_Exc := Corresponding_Name_Definition (Handled_Exc);
Handled_Exc := Unwind_Exception_Renamings (Handled_Exc);
if Is_Equal (Handled_Exc, Exc) then
Result := not Contains_Raise_Stmt (H);
exit;
end if;
end loop;
end if;
return Result;
end Is_Handled;
----------------------------
-- Is_Imported_Subprogram --
----------------------------
function Is_Imported_Subprogram (El : Asis.Element) return Boolean is
Argument : Asis.Element := El;
Result : Boolean := False;
begin
if Declaration_Kind (Argument) in
A_Procedure_Instantiation .. A_Function_Instantiation
then
Argument := Normalize_Reference (Generic_Unit_Name (Argument));
Argument := Corresponding_Name_Declaration (Argument);
end if;
if Declaration_Kind (Argument) in
A_Procedure_Declaration .. A_Function_Declaration
or else
Declaration_Kind (Argument) in
A_Generic_Procedure_Declaration .. A_Generic_Function_Declaration
then
Argument := Corresponding_Body (Argument);
case Pragma_Kind (Argument) is
when An_Import_Pragma =>
Result := True;
when An_Implementation_Defined_Pragma =>
Result :=
ASIS_UL.Misc.To_Lower_Case (Pragma_Name_Image (Argument)) =
"interface";
when others =>
null;
end case;
end if;
return Result;
end Is_Imported_Subprogram;
------------------------
-- Is_In_Private_Part --
------------------------
function Is_In_Private_Part
(Decl : Element;
Scope : Element)
return Boolean
is
Result : Boolean := False;
begin
if Element_Kind (Decl) = A_Declaration
and then
(Declaration_Kind (Scope) = A_Package_Declaration
or else
Declaration_Kind (Scope) = A_Generic_Package_Declaration)
then
declare
Private_Dls : constant Asis.Element_List :=
Private_Part_Declarative_Items (Scope);
First_Private_Line : Asis.Text.Line_Number_Positive;
Last_Private_Line : Asis.Text.Line_Number_Positive;
begin
if not Is_Nil (Private_Dls) then
First_Private_Line :=
Element_Span (Private_Dls (Private_Dls'First)).First_Line;
Last_Private_Line :=
Element_Span (Private_Dls (Private_Dls'Last)).Last_Line;
Result := Element_Span (Decl).First_Line in
First_Private_Line .. Last_Private_Line;
end if;
end;
end if;
return Result;
end Is_In_Private_Part;
------------------------
-- Is_In_Visible_Part --
------------------------
function Is_In_Visible_Part
(Decl : Element;
Scope : Element)
return Boolean
is
Result : Boolean := False;
begin
if Element_Kind (Decl) = A_Declaration
and then
(Declaration_Kind (Scope) = A_Package_Declaration
or else
Declaration_Kind (Scope) = A_Generic_Package_Declaration)
then
declare
Visible_Dls : constant Asis.Element_List :=
Visible_Part_Declarative_Items (Scope);
First_Public_Line : Asis.Text.Line_Number_Positive;
Last_Public_Line : Asis.Text.Line_Number_Positive;
begin
if not Is_Nil (Visible_Dls) then
First_Public_Line :=
Element_Span (Visible_Dls (Visible_Dls'First)).First_Line;
Last_Public_Line :=
Element_Span (Visible_Dls (Visible_Dls'Last)).Last_Line;
Result := Element_Span (Decl).First_Line in
First_Public_Line .. Last_Public_Line;
end if;
end;
end if;
return Result;
end Is_In_Visible_Part;
---------------------------
-- Is_Indefinite_Subtype --
---------------------------
function Is_Indefinite_Subtype (SM : Asis.Element) return Boolean is
Result : Boolean := False;
SM_Entity : Entity_Id;
begin
if Expression_Kind (SM) = A_Selected_Component
or else
Expression_Kind (SM) = An_Identifier
then
SM_Entity := Entity (R_Node (SM));
pragma Assert (Ekind (SM_Entity) in Einfo.Type_Kind);
Result :=
Has_Discriminants (SM_Entity) and then
not Is_Constrained (SM_Entity);
end if;
return Result;
end Is_Indefinite_Subtype;
---------------------
-- Is_Modular_Type --
---------------------
function Is_Modular_Type (Subtype_Ref : Asis.Element) return Boolean is
Ent : Entity_Id;
begin
Ent := Entity (R_Node (Subtype_Ref));
return Is_Modular_Integer_Type (Ent);
end Is_Modular_Type;
---------------------------------
-- Is_Non_Structural_Statement --
---------------------------------
function Is_Non_Structural_Statement
(Stmt : Element;
Exit_Is_Goto : Boolean := True)
return Boolean
is
Arg_Kind : constant Flat_Element_Kinds := Flat_Element_Kind (Stmt);
Result : Boolean := False;
Control : Traverse_Control := Continue;
Target_Stmt : Element;
procedure Pre_Operation
(Element : Asis.Element;
Control : in out Traverse_Control;
State : in out Boolean);
-- This procedure does most of the job. It checks if the element being
-- visited does transfer the control outside Stmt. If this is really so
-- it sets Result to True and terminates the traversal
procedure Post_Operation
(Element : Asis.Element;
Control : in out Traverse_Control;
State : in out Boolean);
procedure Check_Statement is new
Traverse_Element (Boolean, Pre_Operation, Post_Operation);
procedure Pre_Operation
(Element : Asis.Element;
Control : in out Traverse_Control;
State : in out Boolean)
is
Arg_Kind : constant Flat_Element_Kinds := Flat_Element_Kind (Element);
begin
case Arg_Kind is
when Flat_Path_Kinds |
An_If_Statement |
A_Case_Statement |
A_Loop_Statement |
A_While_Loop_Statement |
A_For_Loop_Statement |
A_Block_Statement |
A_Selective_Accept_Statement |
A_Timed_Entry_Call_Statement |
A_Conditional_Entry_Call_Statement |
An_Asynchronous_Select_Statement =>
-- We may control transfer inside such a construct. So just
-- continue...
null;
when A_Return_Statement |
A_Raise_Statement |
A_Terminate_Alternative_Statement =>
State := True;
Control := Terminate_Immediately;
when An_Exit_Statement =>
if Exit_Is_Goto then
Target_Stmt := Corresponding_Loop_Exited (Element);
if not Contains (Outer => Stmt, Inner => Target_Stmt) or else
Is_Equal (Stmt, Target_Stmt)
then
State := True;
Control := Terminate_Immediately;
end if;
end if;
when A_Goto_Statement =>
Target_Stmt := Corresponding_Destination_Statement (Element);
if not Contains (Outer => Stmt, Inner => Target_Stmt) or else
Is_Equal (Stmt, Target_Stmt)
then
State := True;
Control := Terminate_Immediately;
end if;
when others =>
-- Nothing interesting inside...
Control := Abandon_Children;
end case;
end Pre_Operation;
procedure Post_Operation
(Element : Asis.Element;
Control : in out Traverse_Control;
State : in out Boolean)
is
begin
pragma Unreferenced (Element);
pragma Unreferenced (Control);
pragma Unreferenced (State);
null;
end Post_Operation;
begin
if Arg_Kind = An_If_Statement or else
Arg_Kind = A_Case_Statement or else
Arg_Kind = A_Loop_Statement or else
Arg_Kind = A_While_Loop_Statement or else
Arg_Kind = A_For_Loop_Statement or else
Arg_Kind = A_Selective_Accept_Statement or else
Arg_Kind = A_Timed_Entry_Call_Statement or else
Arg_Kind = A_Conditional_Entry_Call_Statement or else
Arg_Kind = An_Asynchronous_Select_Statement
then
Check_Statement (Stmt, Control, Result);
end if;
return Result;
end Is_Non_Structural_Statement;
---------------------
-- Is_Program_Unit --
---------------------
function Is_Program_Unit (El : Element) return Boolean is
El_Kind : constant Flat_Element_Kinds := Flat_Element_Kind (El);
Result : Boolean := False;
begin
Result := False
or else El_Kind = A_Task_Type_Declaration
or else El_Kind = A_Protected_Type_Declaration
or else El_Kind = A_Single_Task_Declaration
or else El_Kind = A_Single_Protected_Declaration
or else El_Kind = A_Package_Declaration
or else El_Kind = A_Generic_Package_Declaration
or else El_Kind = A_Package_Body_Declaration
or else El_Kind = A_Procedure_Body_Declaration
or else El_Kind = A_Function_Body_Declaration
or else El_Kind = A_Task_Body_Declaration
or else El_Kind = A_Protected_Body_Declaration
or else El_Kind = An_Entry_Body_Declaration
or else El_Kind = An_Expression_Function_Declaration;
if not Result then
Result := False
or else El_Kind = A_Procedure_Declaration
or else El_Kind = A_Function_Declaration
or else El_Kind = A_Generic_Procedure_Declaration
or else El_Kind = A_Generic_Function_Declaration
or else El_Kind = A_Package_Instantiation
or else El_Kind = A_Procedure_Instantiation
or else El_Kind = A_Function_Instantiation
or else El_Kind = A_Package_Renaming_Declaration
or else El_Kind = A_Procedure_Renaming_Declaration
or else El_Kind = A_Function_Renaming_Declaration
or else El_Kind = A_Generic_Package_Renaming_Declaration
or else El_Kind = A_Generic_Procedure_Renaming_Declaration
or else El_Kind = A_Generic_Function_Renaming_Declaration;
Result :=
Result and then
Is_Equal (El, Unit_Declaration (Enclosing_Compilation_Unit (El)));
end if;
return Result;
end Is_Program_Unit;
------------------------
-- Is_RM_Program_Unit --
------------------------
function Is_RM_Program_Unit (El : Element) return Boolean is
Result : Boolean := False;
El_Kind : constant Flat_Element_Kinds := Flat_Element_Kind (El);
begin
Result := False
or else El_Kind = A_Task_Type_Declaration
or else El_Kind = A_Protected_Type_Declaration
or else El_Kind = A_Single_Task_Declaration
or else El_Kind = A_Single_Protected_Declaration
or else El_Kind = A_Procedure_Declaration
or else El_Kind = A_Function_Declaration
or else El_Kind = A_Procedure_Body_Declaration
or else El_Kind = A_Function_Body_Declaration
or else El_Kind = A_Package_Declaration
or else El_Kind = A_Package_Body_Declaration
or else El_Kind = A_Task_Body_Declaration
or else El_Kind = A_Protected_Body_Declaration
or else El_Kind = An_Entry_Body_Declaration
or else El_Kind = A_Procedure_Body_Stub
or else El_Kind = A_Function_Body_Stub
or else El_Kind = A_Package_Body_Stub
or else El_Kind = A_Task_Body_Stub
or else El_Kind = A_Protected_Body_Stub
or else El_Kind = A_Generic_Procedure_Declaration
or else El_Kind = A_Generic_Function_Declaration
or else El_Kind = A_Generic_Package_Declaration;
if El_Kind = An_Entry_Declaration then
Result :=
Definition_Kind (Enclosing_Element (El)) = A_Protected_Definition;
end if;
return Result;
end Is_RM_Program_Unit;
------------------------------
-- Is_Publically_Accessible --
------------------------------
function Is_Publically_Accessible (Decl : Element) return Boolean is
Enclosing_CU : constant Asis.Compilation_Unit :=
Enclosing_Compilation_Unit (Decl);
Enclosing_Unit : Asis.Element;
Local_Pkg : Asis.Element;
Result : Boolean := False;
begin
if Element_Kind (Decl) = A_Declaration
and then
(Unit_Kind (Enclosing_CU) = A_Package
or else
Unit_Kind (Enclosing_CU) = A_Generic_Package)
and then
Unit_Class (Enclosing_CU) = A_Public_Declaration
then
Enclosing_Unit := Unit_Declaration (Enclosing_CU);
Result := Is_In_Visible_Part (Decl, Enclosing_Unit);
if Result then
-- Decl could be in the private part of some local package
Local_Pkg := Enclosing_Element (Decl);
while not Is_Equal (Local_Pkg, Enclosing_Unit) loop
if Is_In_Private_Part (Decl, Local_Pkg) then
Result := False;
exit;
end if;
Local_Pkg := Enclosing_Element (Local_Pkg);
end loop;
end if;
end if;
return Result;
end Is_Publically_Accessible;
--------------------
-- Is_Static_Loop --
--------------------
function Is_Static_Loop (Loop_Stmt : Element) return Boolean
is
Param_Definition : Element;
Result : Boolean := False;
begin
if Flat_Element_Kind (Loop_Stmt) = A_For_Loop_Statement then
Param_Definition :=
Specification_Subtype_Definition
(For_Loop_Parameter_Specification (Loop_Stmt));
case Flat_Element_Kind (Param_Definition) is
when A_Discrete_Subtype_Indication_As_Subtype_Definition =>
Result := Is_Static_Subtype (Param_Definition);
-- Is_Static_Subtype (Subtype_Constraint (Param_Definition));
when A_Discrete_Range_Attribute_Reference_As_Subtype_Definition =>
Result := Is_Static (Param_Definition);
when A_Discrete_Simple_Expression_Range_As_Subtype_Definition =>
Result := Is_Static (Lower_Bound (Param_Definition)) and then
Is_Static (Upper_Bound (Param_Definition));
when others =>
null;
end case;
end if;
return Result;
end Is_Static_Loop;
-----------------------
-- Is_Static_Subtype --
-----------------------
function Is_Static_Subtype (E : Element) return Boolean is
Result : Boolean := False;
Arg_Kind : constant Flat_Element_Kinds := Flat_Element_Kind (E);
Def_Name : Element;
Type_Entity : Entity_Id;
Tmp : Element;
begin
-- Note, that this NOT an ASIS secondary query, some routines from
-- Einfo are used.
-- First, return False for any non-expected or definitely non-static
-- result
if not (Arg_Kind = A_Subtype_Indication or else
Arg_Kind = A_Discrete_Subtype_Indication or else
Arg_Kind = A_Discrete_Subtype_Indication_As_Subtype_Definition)
then
return False;
end if;
Tmp := Asis.Definitions.Subtype_Mark (E);
Tmp := Normalize_Reference (Tmp);
Def_Name := Corresponding_Name_Definition (Tmp);
Type_Entity := Node (Def_Name);
if Is_Non_Static_Subtype (Type_Entity) or else
Ekind (Type_Entity) not in Discrete_Kind
then
return False;
end if;
-- If we are here, we are sure that we are processing some discrete
-- subtype indication
Tmp := Subtype_Constraint (E);
if not Is_Nil (Tmp) then
if Flat_Element_Kind (Tmp) = A_Range_Attribute_Reference then
Result := Is_Static (Tmp);
else
Result := Is_Static (Lower_Bound (Tmp)) and then
Is_Static (Upper_Bound (Tmp));
end if;
if not Result then
-- The constraint is not static. No chance to be a static
-- subtype...
return False;
end if;
end if;
-- If we are here, the constraint is either absent or static. So,
-- checking the subtype mark
Tmp := Type_Declaration_View (Enclosing_Element (Def_Name));
if Flat_Element_Kind (Tmp) = A_Subtype_Indication then
Result := Is_Static_Subtype (Tmp);
else
-- that is, here we have a type definition
case Flat_Element_Kind (Tmp) is
when A_Derived_Type_Definition =>
Result := Is_Static_Subtype (Parent_Subtype_Indication (Tmp));
when An_Enumeration_Type_Definition |
A_Signed_Integer_Type_Definition |
A_Modular_Type_Definition =>
Result := True;
when others =>
Result := False;
end case;
end if;
return Result;
end Is_Static_Subtype;
--------------------------------------
-- Is_Unchecked_Convertion_Instance --
--------------------------------------
function Is_Unchecked_Convertion_Instance (Decl : Element) return Boolean is
Result : Boolean := False;
Arg : Element;
Arg_Unit : Compilation_Unit;
begin
if Declaration_Kind (Decl) = A_Function_Instantiation then
Arg := Generic_Unit_Name (Decl);
Arg := Normalize_Reference (Arg);
Arg := Corresponding_Name_Declaration (Arg);
if Declaration_Kind (Arg) =
A_Generic_Function_Renaming_Declaration
then
Arg := Corresponding_Base_Entity (Arg);
Arg := Corresponding_Name_Declaration (Arg);
end if;
Arg_Unit := Enclosing_Compilation_Unit (Arg);
if Unit_Origin (Arg_Unit) = A_Predefined_Unit
and then
Unit_Full_Name (Arg_Unit) = "Ada.Unchecked_Conversion"
then
Result := True;
end if;
end if;
return Result;
end Is_Unchecked_Convertion_Instance;
-----------------------------
-- May_Have_Interface_List --
-----------------------------
function May_Have_Interface_List (Decl : Element) return Boolean is
Result : Boolean := False;
begin
case Declaration_Kind (Decl) is
when An_Ordinary_Type_Declaration =>
Result :=
Asis.Elements.Type_Kind (Type_Declaration_View (Decl)) =
A_Derived_Record_Extension_Definition
or else
Asis.Elements.Type_Kind (Type_Declaration_View (Decl)) =
An_Interface_Type_Definition;
when A_Formal_Type_Declaration =>
Result :=
Formal_Type_Kind (Type_Declaration_View (Decl)) =
A_Formal_Derived_Type_Definition
or else
Formal_Type_Kind (Type_Declaration_View (Decl)) =
A_Formal_Interface_Type_Definition;
when A_Private_Extension_Declaration |
A_Task_Type_Declaration |
A_Protected_Type_Declaration |
A_Single_Task_Declaration |
A_Single_Protected_Declaration =>
Result := True;
when others =>
null;
end case;
return Result;
end May_Have_Interface_List;
------------------------
-- Print_Tree_Sources --
------------------------
procedure Print_Tree_Sources is
begin
for U in Main_Unit .. Last_Unit loop
begin
if not Is_Internal_File_Name
(File_Name (Source_Index (U)))
then
Namet.Get_Name_String (Full_File_Name (Source_Index (U)));
Info (Namet.Name_Buffer (1 .. Namet.Name_Len));
end if;
-- In case of any non-expected problem:
exception
when others =>
Info ("list may be incomplete");
exit;
end;
end loop;
end Print_Tree_Sources;
-----------------------
-- Primitive_Of_Type --
-----------------------
function Primitive_Of_Type (Op : Asis.Element) return Asis.Element is
Result : Asis.Element;
begin
if Is_Part_Of_Inherited (Op) then
Result := Enclosing_Element (Enclosing_Element (Op));
else
Result := Enclosing_Element (Primitive_Owner (Op));
end if;
return Result;
end Primitive_Of_Type;
--------------------------------
-- Unwind_Exception_Renamings --
--------------------------------
function Unwind_Exception_Renamings
(Exc : Asis.Element)
return Asis.Element
is
Result : Asis.Element := Exc;
Renamed_Exc : Asis.Element;
begin
Renamed_Exc := Enclosing_Element (Exc);
if Declaration_Kind (Renamed_Exc) =
An_Exception_Renaming_Declaration
then
Renamed_Exc := Renamed_Entity (Renamed_Exc);
Renamed_Exc := Normalize_Reference (Renamed_Exc);
Renamed_Exc := Corresponding_Name_Definition (Renamed_Exc);
Result := Unwind_Exception_Renamings (Renamed_Exc);
end if;
return Result;
end Unwind_Exception_Renamings;
end ASIS_UL.Utilities;
|