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
|
------------------------------------------------------------------------------
-- --
-- GNATCHECK COMPONENTS --
-- --
-- A S I S _ U L . G L O B A L _ S T A T E . C G --
-- --
-- B o d y --
-- --
-- Copyright (C) 2007-2018, 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). --
-- --
------------------------------------------------------------------------------
with GNAT.Directory_Operations; use GNAT.Directory_Operations;
with GNAT.OS_Lib; use GNAT.OS_Lib;
with Asis; use Asis;
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.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.Set_Get; use Asis.Set_Get;
with ASIS_UL.Common;
with ASIS_UL.Global_State.CG.Conditions;
use ASIS_UL.Global_State.CG.Conditions;
with ASIS_UL.Options; use ASIS_UL.Options;
with ASIS_UL.Output; use ASIS_UL.Output;
with ASIS_UL.Utilities; use ASIS_UL.Utilities;
with ASIS_UL.Global_State.Utilities; use ASIS_UL.Global_State.Utilities;
with ASIS_UL.Global_State.Data; use ASIS_UL.Global_State.Data;
package body ASIS_UL.Global_State.CG is
----------------------------------------------------------------
-- Processing of dispatching operations and dispatching calls --
----------------------------------------------------------------
---------------------------------------------------------------------------
-- Existing approach is not 100% correct and does not work for the case --
-- of multiple inheritance: ??? --
---------------------------------------------------------------------------
-- For a dispatching call, the link to the corresponding dispatching
-- operation (RM05 3.9.2 (1/2)) is stored as an ordinary call.
--
-- For each dispatching operation, if the operation overrides some other
-- (dispatching) operation, a call from overriden operation to the
-- overriding one is stored. The call graph stores only explicetely (???)
-- declared entities, so if P(1) is an eplicitely declared dispatching
-- operation, P(2) is the corresponding implicetely declared inherited
-- operation, and P(3) is overriding dispatching operation that actually
-- overrides what could be inherited from P(2), then the link (the call)
-- from P(1) to P(3) will be stored.
-------------------------
-- To be implemented: --
-------------------------
-- ?????
-- Dispatching operations and dispatching calls make the following problem
-- for the call graph:
--
-- * At the place of a dispatching call, any of the operations that
-- overrides the given operation can be called, BUT:
--
-- * when processing a dispatching call, we do not have a full set of
-- operations to that the call can be dispatched
--
-- * when processing a dispatching operation that overrides some other
-- dispatching operation, we do not know if the overridden operation is
-- a root of some dispatching call. An implicit inherited operation is
-- not stored in the call graph if it is not a root of some dispatching
-- call (???);
--
-- The following way of representing dispatching operations in the call
-- graph is suggested
--
-- * all the dispatching operations are stored in the call graph (including
-- implicit inherited operations and abstract operations);
--
-- * for each dispatching operations, a list of corresponding operations
-- of the types directly derived from the type that "owns" this operation
-- is stored (corresponding operation here is either the inherited
-- operation corresponding to this operation, or an explicitly declared
-- operatation that overrides it. For this list we will be using the
-- term "operations implementing the given dispatching operation". Term
-- is not really good, but we try to express the following: if
-- implemented operation is a dispatching root, then implementing
-- operation can be called as the result of dispatching.
--
-- * for multiple inheritance,one operation can be implementing operation
-- for more than one "parent" implemented operations;
--
-- * dispatching calls are stored as separate lists. For each dispatching
-- call, the corresponding dispatching operation is stored in the list
-- of dispatching calls. If dispatching operation is not abstract
-- operation, the dispatching call is stored as an ordinary
-- non-dispatching call in the list of direct calls (that is, the result
-- of node representing the result of Corresponding_Element applied to
-- the dispatching operation is stored;
--
-- * call graph transitive closure is performed in two steps:
--
-- 1. for each dispatching operation, the list of all the operations that
-- implement the given dispatching operation, directly or indirectly,
-- is created;
--
-- 2. for each node N, for each node M from the list of dispatching calls
-- issued by N, the list of
-- operations implementing the corresponding dispatching operation M
-- (that is, the list of operations to that the call can be dispatched)
-- is added to the list of direct calls issued by N
--
-- 3. Normal transitive closure of the call graph is performed.
--
-- ???
-----------------------
-- Local subprograms --
-----------------------
procedure Process_Call
(Element : Asis.Element;
At_SLOC : String_Loc := Nil_String_Loc);
-- Analyzes a subprogram call. If the call cannot be statically analyzed,
-- ???????????????????????
-- generates the corresponding diagnostic message in case if ??? is ON.
-- IF At_SLOC is equal to Nil_String_Loc, the SLOC of the call is the SLOC
-- of the argument Element, otherwise At_SLOC is used as the SLOC of the
-- call (see the documentation for Add_CG_Info).
procedure Process_Callable_Entity (El : Asis.Element);
-- Stores (if needed) in the call graph the information about the
-- callable entity. In case of a single task declaration, this procedure
-- also stores the call link from the current scope to the task entity
procedure Process_Elaboration_Calls (Element : Asis.Element);
-- For the argument Element that should be
-- ASIS_UL.Utilities.May_Contain_Elaboration_Calls, tries to find implicit
-- calls that are made during the elaboration and for each of these calls
-- processes this call as a regular call.
procedure Process_Type_Default_Expressions
(Type_To_Analyze : Asis.Element;
Call_At_SLOC : String_Loc);
-- Implements a part of the functionality of Process_Elaboration_Calls
-- Recursively traverses the type structure of the type represented by
-- Type_To_Analyze argument (note that this type should not be private or
-- derived type!) and adds all the fucntion calls from the component
-- expressions in the call graph. At_SLOC parameter represents the location
-- of the calls to store (because these calls are issued as a part of
-- object declaration elaboration declaration or allocator evaluation).
procedure Process_Init_Expressions_In_Record_Components
(Component_List : Asis.Element_List;
Call_At_SLOC : String_Loc);
-- Implements a part of the functionality of
-- Process_Type_Default_Expressions. Traverses the argument list and do
-- the following:
--
-- - if a list element is a component definition and it contains an
-- initialization expression, traverses this expression to locate
-- function calls;
--
-- - if a list element is a component definition and it does not contain an
-- initialization expression, analyzes the component type to get
-- initialization expressions for suncomponents and to extract function
-- calls from them;
--
-- - if a list elemen is a variant part, recursively gets into the variant
-- part strcture to get and to analyze the variant components;
--
-- For errey compoenets, the component type is analyzed for possible
-- default initialization expressions.
procedure Process_Renaming_As_Body (El : Asis.Element);
-- If we have renaming-as-body, this means that we have the corresponding
-- subprigram declaration, so - the corresponding node in the call graph.
-- This subprogram detects (and creates, if needed) the corresponding node
-- in the call graph and sets for this node Is_Renaming ON. Then in tries
-- to unwind the renaming, and if the renamed entity can be statically
-- defined, stores the ID of this entity in the Calls_Chain for the node.
-- (That is, if we have a subprogram that has renaming-as-body as its
-- completion, we represent this in the call graph as if this subprogram
-- calls the renamed subprogram. The case of renaming a task entry as a
-- subprogram is not implemented yet.)
procedure Process_Task_Components
(Type_Decl : Asis.Element;
Call_At_SLOC : String_Loc;
Recursive_Call : Boolean := False);
-- Analyze the argument type declaration and defines the tasks that are
-- created when creating the value of this type. It is supposed that
-- Get_Type_Structure function has already been applied to the argument
-- type declaration. The actual for Call_At_SLOC should indicate the source
-- location of the construct that initiate task creations (e.g. SLOC of an
-- object declaration that contains task components).
--
-- The problem of this procedure is that it can get into cycles in case of
-- recursive record types. Two cases of recursion are possible:
--
-- type Rec_1 is record
-- ...
-- C : access Rec_1;
-- ...
-- end record
--
-- and
--
-- type Rec_2;
-- type Rec_3;
--
-- type Access_Rec_2 is access Rec_2
-- type Access_Rec_3 is access Rec_3
--
-- type Rec_2 is record
-- C : Access_Rec_3;
-- ....
-- end record;
--
-- type Rec_3 is record
-- C : Access_Rec_2;
-- ....
-- end record;
--
-- The break this cycling, Recursive_Call parameter is used. When this
-- parameter is False, the query starts from cleaning the set of processed
-- types, otherwise it does not do this. Before strarting processing a type
-- declaration, the qery checks if it already stored in the set of
-- processed types, and if it is, skips this type.
--
-- All the calls to this query from the code that builds the call graph
-- should be with Recursive_Call => False to avoid cycling
Processed_Types : Asis.Extensions.Element_Containers.Set;
procedure Process_Record_Task_Components
(Component_List : Asis.Element_List;
Call_At_SLOC : String_Loc);
-- Similar to the Process_Task_Components procedure, but works on a list of
-- record components (more exactly, on the list returned by the
-- Asis.Definitions.Record_Components query.
procedure Process_Task_Creation (El : Asis.Element);
-- Supposing that Can_Create_Tasks (El), recursively traverse the type
-- declaration of the object or value representing by El and stores the
-- information about all the tasks (if any) that are created when the
-- object/value is cretaed.
-- (Suppose we have:
--
-- task type T is ,.. end T;
-- type Rec is record
-- Comp_I : Integer;
-- Comp_T : T;
-- end record;
--
-- Var : Rec; -- here a task of type T is created,
--
-- This procedure should get from the declaration of Var the information
-- that a task of the type T is created as a result of elaboration this
-- declaration.
procedure Process_Stream_Attribute_Redefinition
(Element : Asis.Element;
At_SLOC : String_Loc);
-- Assuming that El is an attribute definition clause that redefines a
-- stream attribute, tries to define the procedure used for the
-- redefinition and if it is possible, creates a link that represents the
-- call to this procedure from the current scope. (The redefined attribute
-- can be used only within the current scope).
procedure Process_Reference_To_Subprogram
(Element : Asis.Element;
At_SLOC : String_Loc);
-- Assuming that El is a construct that can create a reference to a
-- subprogram that can be used for indirect subprogram call, tries to
-- define the refered subprogram and if it is indeed a subprogram, creates
-- a link that represents the call to this subprogram from its enclosing
-- scope.
--
-- !!! Note, that there are also references to tasks and to entries, and we
-- do not process these cases at the moment!
procedure Process_Discr_Init_Proc (El : Asis.Element);
-- Provided that Has_Discr_Init_Proc (El) is True, creates the
-- representation of the discriminant initialization procedure for this
-- type. This includes storing the information about all the (direct) calls
-- issuing by this initialization procedure.
procedure Process_Type_Init_Proc (El : Asis.Element);
-- Provided that Has_Type_Init_Proc (El) is True, creates the
-- representation of the component initialization procedure for this type.
-- This includes storing the information about all the (direct) calls
-- issuing by this initialization procedure.
procedure Process_Scope (El : Asis.Element);
-- Stores in the call graph the information about the scope (that is -
-- about the body of a callable entity) and updates Current_Scope and
-- the scope stack.
procedure Store_Dispatching_Operations (El : Asis.Element);
-- Provided that El is a type definition that may have dispatching
-- operations, stores all the dispatching operations in the call graph.
procedure Store_Arc
(Called_Entity : Asis.Element;
At_SLOC : String_Loc;
Calling_Entity : Asis.Element := Nil_Element);
-- Supposing that Called_Entity is an Element that can be stored as a node
-- of the Call Graph (that is, Corresponding_Element has already been
-- applied to it), stores the call arc from Calling_Entity (or from the
-- current scope if Calling_Entity is Nil_Element) to the node
-- corresponding to this element using At_SLOC as the SLOC of the place
-- where the call takes place. Only one (the first) call from the scope to
-- the given Element is stored.
procedure Set_Is_Renaming (N : GS_Node_Id; Val : Boolean := True);
-- Set the flag indicating if the callable entity is a renaming of another
-- callable entity (only renamings-as-bodies are represented in the call
-- graph),
function First_Direct_Call (N : GS_Node_Id) return GS_Node_Id;
-- Returns the first node from the direct call list of N. Returns
-- No_GS_Node if the list of direcr calls for N is empty
procedure Traverse_Construct_For_CG_Info is new Traverse_Element
(State_Information => String_Loc,
Pre_Operation => Add_CG_Info_Pre_Op,
Post_Operation => Complete_CG_Info_Post_Op);
-- Traverses the argument Element in ordrer to collect call graph
-- information. Usded as internal traversal routine for the implementation
procedure Unconditionally_Traverse_Construct_For_CG_Info is new
Traverse_Element (State_Information => String_Loc,
Pre_Operation => Unconditionally_Add_CG_Info_Pre_Op,
Post_Operation => Complete_CG_Info_Post_Op);
-- Traverses the argument Element in ordrer to collect call graph
-- information. Usded as internal traversal routine for the implementation
-- of Collect_CG_Info_From_Construct.
-- of Collect_CG_Info_From_Construct.
---------------------------------------------------
-- Dispatching calls and dispatching operations --
---------------------------------------------------
procedure Add_Possible_Calls
(Calling_Node : GS_Node_Id;
Disp_Operation : GS_Node_Id);
-- This procedure assumes that Calling_Node issues a dispatching call and
-- this call is dispatched to Disp_Operation. It adds all the subprograms
-- that can be called as the result of dispatching call to Disp_Operation
-- to the list of direct calls of Calling_Node (using placeholder SLOC
-- (0, 0))
------------------------------------------------------------
-- Data structures used for call graph transitive closure --
------------------------------------------------------------
-- The following variables are used by Close_Node procedure, we define them
-- as global to avoid elaboration expances for each call of Close_Node.
New_Set : Node_Lists.Set;
-- A set of nodes that are added to All_Call. For each of the nodes from
-- this set we should analyse its direct calls and then remove the node
-- fron this set. We stop the loop for the next node when this set is
-- empty,
Newer_Set : Node_Lists.Set;
-- Nodes that are added for All_Call at the last iteration of the
-- processing of New_Set for the given node. They should be added to
-- New_Set to process their direct calls.
Next_Direct_Call : Node_Lists.Cursor;
Next_Call : SLOC_Node_Lists.Cursor;
Next_All_Call : Node_Lists.Cursor;
Next_Ref : SLOC_Node_Lists.Cursor;
Link_Tmp : SLOC_Link;
Traverse_Renamings_Done_Flag : Boolean := False;
Transitive_Closure_Done_Flag : Boolean := False;
-- Flags that indicates that the corresponding operation has been done
-- !!!! Start of the junc patch code to be removed as soon as possible!
-- See I106-005
procedure Patch_For_Default_Parameter_Initialization
(Element : Asis.Element);
pragma Unreferenced (Patch_For_Default_Parameter_Initialization);
-- This is a temporary patch for the compiler problem described in
-- I106-005: if Element is a parameter specification from a subprogram
-- or an entry, then all the function called in the default initialization
-- expressions (if any) are unconditionally marked as used.
procedure Mark_Called_Function_Used
(Element : Asis.Element;
Control : in out Traverse_Control;
State : in out No_State);
-- If Element is a function call, tries to define the called function and
-- mark it as used.
procedure Mark_All_Called_Functions_Used is new Traverse_Element
(Pre_Operation => Mark_Called_Function_Used,
Post_Operation => No_Op,
State_Information => No_State);
-- !!!! End of the junc patch code to be removed as soon as possible!
-----------------
-- Add_CG_Info --
-----------------
procedure Add_CG_Info
(Element : Asis.Element;
At_SLOC : String_Loc := Nil_String_Loc)
is
begin
if Can_Have_Elaboration_Calls (Element) then
-- Is_Call and Can_Create_Tasks Elements can have elaboration calls,
-- so we have to process elaboration calls in a separate IF
-- statement.
Process_Elaboration_Calls (Element);
end if;
if Is_Scope (Element) then
Process_Scope (Element);
elsif Is_Declaration_Of_Callable_Entity (Element) then
Process_Callable_Entity (Element);
elsif Asis.Extensions.Is_Renaming_As_Body (Element) then
Process_Renaming_As_Body (Element);
-- At the moment, we just unwind renamings to the called subprogram
elsif Is_Call (Element) then
Process_Call (Element, At_SLOC => At_SLOC);
elsif Can_Create_Tasks (Element) then
Process_Task_Creation (Element);
elsif Is_Stream_Attribute_Redefinition (Element) then
Process_Stream_Attribute_Redefinition (Element, At_SLOC);
elsif Can_Create_Reference_To_Subprogram (Element) then
Process_Reference_To_Subprogram (Element, At_SLOC);
elsif Represent_Dispatching_Calls
and then
Can_Have_Dispatching_Operations (Element)
then
Store_Dispatching_Operations (Element);
end if;
if Has_Type_Init_Proc (Element) then
Process_Type_Init_Proc (Element);
end if;
if Has_Discr_Init_Proc (Element) then
Process_Discr_Init_Proc (Element);
end if;
end Add_CG_Info;
------------------------
-- Add_CG_Info_Pre_Op --
------------------------
Definition : Asis.Element;
Is_Global_Reference : Boolean;
Can_Be_Accessed_By_Local_Task : Boolean;
Reference_Kind : Reference_Kinds;
-- We define these variables as global for Pre_Operation because of
-- performance reasons (to awoind their allocation for each identifier
-- element being visited during traversal)
procedure Add_CG_Info_Pre_Op
(Element : Asis.Element;
Control : in out Traverse_Control;
State : in out String_Loc)
is
Expanded_Code : Asis.Element;
procedure Treat_Element (Element : Asis.Element);
procedure Treat_Element (Element : Asis.Element) is
begin
if (Flat_Element_Kind (Element) = A_Defining_Identifier and then
(Flat_Element_Kind (Enclosing_Element (Element)) =
A_Variable_Declaration or else
Flat_Element_Kind (Enclosing_Element (Element)) =
A_Formal_Object_Declaration))
-- Possible initialization in the declaration of a package-level
-- global variable, which counts as a write
or else
Flat_Element_Kind (Element) = An_Identifier
-- Possible read or write to a variable
then
Check_If_Global_Reference
(Element => Element,
Definition => Definition,
Is_Global_Reference => Is_Global_Reference,
Can_Be_Accessed_By_Local_Task =>
Can_Be_Accessed_By_Local_Task,
Reference_Kind => Reference_Kind,
Compute_Reference_Kind => True);
if Is_Global_Reference and then
Reference_Kind /= Not_A_Reference
then
Process_Global_Reference
(Element,
Definition,
Reference_Kind);
end if;
end if;
end Treat_Element;
begin
-- !!!! To be removed as soon as possible! See I106-005
-- Patch_For_Default_Parameter_Initialization (Element);
if not Compute_Global_Objects_Accessed and then
Is_Non_Executable_Construct (Element)
then
Control := Abandon_Children;
return;
end if;
Add_CG_Info (Element, State);
if Compute_Global_Objects_Accessed then
if Flat_Element_Kind (Element) = A_Parameter_Association then
Traverse_Construct_For_CG_Info
(Element => Actual_Parameter (Element),
Control => Control,
State => State);
-- Avoid traversing the formal parameter of an association
Control := Abandon_Children;
end if;
Treat_Element (Element);
end if;
if Declaration_Kind (Element) in
A_Package_Instantiation .. A_Function_Instantiation
then
Expanded_Code := Corresponding_Declaration (Element);
Traverse_Construct_For_CG_Info
(Element => Expanded_Code,
Control => Control,
State => State);
Expanded_Code := Corresponding_Body (Element);
if not Is_Nil (Expanded_Code) then
Traverse_Construct_For_CG_Info
(Element => Expanded_Code,
Control => Control,
State => State);
end if;
end if;
exception
when Ex : others =>
ASIS_UL.Common.Tool_Failures := ASIS_UL.Common.Tool_Failures + 1;
ASIS_UL.Output.Error ("call graph info collection failed");
ASIS_UL.Output.Error (Build_GNAT_Location (Element));
ASIS_UL.Output.Report_Unhandled_Exception (Ex);
end Add_CG_Info_Pre_Op;
------------------------
-- Add_Possible_Calls --
------------------------
procedure Add_Possible_Calls
(Calling_Node : GS_Node_Id;
Disp_Operation : GS_Node_Id)
is
Next_Impl_Subpr : Node_Lists.Cursor;
Next_Impl_Node : GS_Node_Id;
begin
Next_Impl_Subpr := Node_Lists.First (Table (Disp_Operation).Node_List_3);
while Node_Lists.Has_Element (Next_Impl_Subpr) loop
Next_Impl_Node := Node_Lists.Element (Next_Impl_Subpr);
Add_Link_To_SLOC_List
(To_Node => Calling_Node,
Link_To_Add => (Next_Impl_Node, Nil_String_Loc));
Next_Impl_Subpr := Node_Lists.Next (Next_Impl_Subpr);
end loop;
end Add_Possible_Calls;
-------------------
-- Body_Analyzed --
-------------------
function Body_Analyzed (N : GS_Node_Id) return Boolean is
begin
pragma Assert (GS_Node_Kind (N) in Callable_Nodes);
return Table (N).Bool_Flag_1;
end Body_Analyzed;
-----------------------------------
-- Check_Call_Graph_Completeness --
-----------------------------------
procedure Check_Call_Graph_Completeness is
begin
for Node in First_GS_Node .. Last_Node loop
if Is_Callable_Node (Node)
and then
not Is_Of_No_Interest (Node)
and then
not Body_Analyzed (Node)
and then
not Missing_Body_Reported (Node)
then
ASIS_UL.Output.Warning
("body is not analyzed for " &
GS_Node_Name (Node) & " (" &
Get_String (GS_Node_SLOC (Node)) & ")");
Set_Missing_Body_Reported (Node);
end if;
end loop;
end Check_Call_Graph_Completeness;
-------------------------
-- Check_For_Main_Unit --
-------------------------
Main_Unit_Already_Processed : Boolean := False;
-- As soon as the source file with the name coresponding to
-- ASIS_UL.Options.Main_Subprogram_Name is processed, we do not need to
-- check anything in Check_For_Main_Unit any more
procedure Check_For_Main_Unit
(SF : SF_Id;
CU : Asis.Compilation_Unit;
Unit : Asis.Element)
is
Main_Unit_Node : GS_Node_Id;
begin
if not Main_Unit_Already_Processed
and then
ASIS_UL.Options.Main_Subprogram_Name /= null
and then
Base_Name (ASIS_UL.Options.Main_Subprogram_Name.all) =
Base_Name (Source_Name (SF))
then
Main_Unit_Already_Processed := True;
if not Can_Be_Main_Program (CU) then
ASIS_UL.Output.Error
("file specified as main unit cannot be main subprogram");
ASIS_UL.Common.Tool_Failures := ASIS_UL.Common.Tool_Failures + 1;
return;
end if;
Main_Unit_Node := Corresponding_Node (Unit);
pragma Assert (Present (Main_Unit_Node));
Add_Link_To_SLOC_List
(To_Node => Environment_Task_Node,
Link_To_Add => (Main_Unit_Node, Build_GNAT_Location (Unit)));
end if;
end Check_For_Main_Unit;
-----------------------------
-- Check_Node_Completeness --
-----------------------------
procedure Check_Node_Completeness (N : GS_Node_Id) is
Next_Call : Node_Lists.Cursor;
Next_Call_N : GS_Node_Id;
begin
Next_Call := Node_Lists.First (All_Calls (N).all);
while Node_Lists.Has_Element (Next_Call) loop
Next_Call_N := Node_Lists.Element (Next_Call);
if not Body_Analyzed (Next_Call_N)
and then
not Missing_Body_Reported (Next_Call_N)
then
ASIS_UL.Output.Warning
("body is not analyzed for " &
GS_Node_Name (Next_Call_N) & " (" &
Get_String (GS_Node_SLOC (Next_Call_N)) & ")");
Set_Missing_Body_Reported (Next_Call_N);
end if;
Next_Call := Node_Lists.Next (Next_Call);
end loop;
end Check_Node_Completeness;
----------------
-- Close_Node --
----------------
procedure Close_Node (Node : GS_Node_Id) is
begin
-- SLOC_Node_List_1 <--> Direct calls
-- Node_List_1 <--> All calls
Node_Lists.Clear (New_Set);
Node_Lists.Clear (Newer_Set);
Add_SLOC_Node_List_To_Node_List
(Table (Node).Node_List_1,
Table (Node).SLOC_Node_List_1);
Add_SLOC_Node_List_To_Node_List
(New_Set,
Table (Node).SLOC_Node_List_1);
while not Node_Lists.Is_Empty (New_Set) loop
Next_Direct_Call := Node_Lists.First (New_Set);
Next_Call :=
SLOC_Node_Lists.First
(Table (Node_Lists.Element (Next_Direct_Call)).
SLOC_Node_List_1);
while SLOC_Node_Lists.Has_Element (Next_Call) loop
if not Node_Lists.Contains
(Table (Node).Node_List_1,
SLOC_Node_Lists.Element (Next_Call).Node)
then
Node_Lists.Insert
(Newer_Set, SLOC_Node_Lists.Element (Next_Call).Node);
end if;
Next_Call := SLOC_Node_Lists.Next (Next_Call);
end loop;
Node_Lists.Delete_First (New_Set);
if not Node_Lists.Is_Empty (Newer_Set) then
Node_Lists.Union (Table (Node).Node_List_1,
Newer_Set);
Node_Lists.Union (New_Set, Newer_Set);
Node_Lists.Clear (Newer_Set);
end if;
end loop;
-- SLOC_Node_List_2 <--> Direct reads
-- SLOC_Node_List_3 <--> Direct writes
-- Node_List_1 <--> All calls
if Compute_Global_Objects_Accessed then
for Node in First_GS_Node .. Last_Node loop
-- Output_Node (Node);
-- Traverse the set of all calls:
Next_All_Call :=
Node_Lists.First (Table (Node).Node_List_1);
while Node_Lists.Has_Element (Next_All_Call) loop
if not Is_Of_No_Interest
(Node_Lists.Element (Next_All_Call))
then
-- Read references
Next_Ref :=
SLOC_Node_Lists.First
(Table (Node_Lists.Element (Next_All_Call)).
SLOC_Node_List_2);
while SLOC_Node_Lists.Has_Element (Next_Ref) loop
if not SLOC_Node_Lists.Contains
(Table (Node).SLOC_Node_List_2,
SLOC_Node_Lists.Element (Next_Ref))
and then
Is_Global_For
(Node => SLOC_Node_Lists.Element (Next_Ref).Node,
Scope => Node)
-- or else
-- GS_Is_Local_Var_Accessed_By_Local_Tasks
-- (SLOC_Node_Lists.Element (Next_Ref).Node))
then
Link_Tmp := SLOC_Node_Lists.Element (Next_Ref);
Add_Link_To_SLOC_List
(To_Node => Node,
To_List => Indirect_Read_References,
Link_To_Add => Link_Tmp);
Add_Link_To_SLOC_List
(To_Node => Link_Tmp.Node,
To_List => Indirect_Read_References,
Link_To_Add => (Node => Node,
SLOC => Nil_String_Loc));
end if;
Next_Ref := SLOC_Node_Lists.Next (Next_Ref);
end loop;
-- Write references
Next_Ref :=
SLOC_Node_Lists.First
(Table (Node_Lists.Element (Next_All_Call)).
SLOC_Node_List_3);
while SLOC_Node_Lists.Has_Element (Next_Ref) loop
if not SLOC_Node_Lists.Contains
(Table (Node).SLOC_Node_List_3,
SLOC_Node_Lists.Element (Next_Ref))
and then
Is_Global_For
(Node => SLOC_Node_Lists.Element (Next_Ref).Node,
Scope => Node)
-- or else
-- GS_Is_Local_Var_Accessed_By_Local_Tasks
-- (SLOC_Node_Lists.Element (Next_Ref).Node))
then
Link_Tmp := SLOC_Node_Lists.Element (Next_Ref);
Add_Link_To_SLOC_List
(To_Node => Node,
To_List => Indirect_Write_References,
Link_To_Add => Link_Tmp);
Add_Link_To_SLOC_List
(To_Node => Link_Tmp.Node,
To_List => Indirect_Write_References,
Link_To_Add => (Node => Node,
SLOC => Nil_String_Loc));
end if;
Next_Ref := SLOC_Node_Lists.Next (Next_Ref);
end loop;
end if;
Next_All_Call := Node_Lists.Next (Next_All_Call);
end loop;
end loop;
end if;
end Close_Node;
------------------------------------
-- Collect_CG_Info_From_Construct --
------------------------------------
procedure Collect_CG_Info_From_Construct
(Element : Asis.Element;
At_SLOC : String_Loc := Nil_String_Loc)
is
State : String_Loc := At_SLOC;
Control : Traverse_Control := Continue;
begin
Traverse_Construct_For_CG_Info (Element, Control, State);
end Collect_CG_Info_From_Construct;
----------------------
-- Complete_CG_Info --
----------------------
procedure Complete_CG_Info (El : Asis.Element) is
begin
if Is_Scope (El)
and then
Should_Be_In_CG (El)
then
Remove_Current_Scope;
end if;
end Complete_CG_Info;
------------------------------
-- Complete_CG_Info_Post_Op --
------------------------------
procedure Complete_CG_Info_Post_Op
(Element : Asis.Element;
Control : in out Traverse_Control;
State : in out String_Loc)
is
pragma Unreferenced (Control, State);
begin
Complete_CG_Info (Element);
end Complete_CG_Info_Post_Op;
------------------------------
-- Expand_Dispatching_Calls --
------------------------------
procedure Expand_Dispatching_Calls is
Next_Disp_Call : Node_Lists.Cursor;
Next_Call_Node : GS_Node_Id;
begin
for Node in First_GS_Node .. Last_Node loop
Next_Disp_Call := Node_Lists.First (Table (Node).Node_List_2);
while Node_Lists.Has_Element (Next_Disp_Call) loop
Next_Call_Node := Node_Lists.Element (Next_Disp_Call);
Add_Possible_Calls
(Calling_Node => Node,
Disp_Operation => Next_Call_Node);
Next_Disp_Call := Node_Lists.Next (Next_Disp_Call);
end loop;
end loop;
end Expand_Dispatching_Calls;
-----------------------
-- First_Direct_Call --
-----------------------
function First_Direct_Call (N : GS_Node_Id) return GS_Node_Id is
Result : GS_Node_Id := No_GS_Node;
begin
pragma Assert (Is_Callable_Node (N));
if not SLOC_Node_Lists.Is_Empty (Table (N).SLOC_Node_List_1) then
Result :=
SLOC_Node_Lists.First_Element (Table (N).SLOC_Node_List_1).Node;
end if;
return Result;
end First_Direct_Call;
--------------------
-- GS_Is_Renaming --
--------------------
function GS_Is_Renaming (N : GS_Node_Id) return Boolean is
begin
pragma Assert (GS_Node_Kind (N) in Callable_Nodes);
return Table (N).Bool_Flag_2;
end GS_Is_Renaming;
---------------------
-- GS_Is_Task_Type --
---------------------
function GS_Is_Task_Type (N : GS_Node_Id) return Boolean is
begin
pragma Assert (GS_Node_Kind (N) in Callable_Nodes);
return GS_Node_Kind (N) = A_Task
and then
Table (N).Bool_Flag_3;
end GS_Is_Task_Type;
-----------------------------------
-- Is_Called_By_Environment_Task --
-----------------------------------
function Is_Called_By_Environment_Task (N : GS_Node_Id) return Boolean is
Result : Boolean := False;
begin
if Present (N) then
Result :=
Node_Lists.Contains
(Container => Table (Environment_Task_Node).Node_List_1,
Item => N);
end if;
return Result;
end Is_Called_By_Environment_Task;
---------------------------------
-- Is_Library_Level_Subprogram --
---------------------------------
function Is_Library_Level_Subprogram (N : GS_Node_Id) return Boolean is
Result : Boolean := False;
begin
if Present (N)
and then
GS_Node_Kind (N) in Subprogram_Nodes
and then
GS_Node_Enclosing_Scope (N) = Environment_Task_Node
then
-- The only possibility that we have at the moment is to compare
-- the name of the subprogram
Result := GS_Node_Name (N) = GS_Enclosed_CU_Name (N);
end if;
return Result;
end Is_Library_Level_Subprogram;
-----------------------
-- Is_Recursive_Node --
-----------------------
function Is_Recursive_Node (N : GS_Node_Id) return Boolean is
begin
return Node_Lists.Contains
(Container => Table (N).Node_List_1, -- all calls
Item => N);
end Is_Recursive_Node;
-------------------------------
-- Mark_Called_Function_Used --
-------------------------------
procedure Mark_Called_Function_Used
(Element : Asis.Element;
Control : in out Traverse_Control;
State : in out No_State)
is
pragma Unreferenced (Control, State);
Called_El : Asis.Element;
Called_Node : GS_Node_Id;
begin
if Expression_Kind (Element) = A_Function_Call then
Called_El := Get_Called_Element (Element);
if Declaration_Kind (Called_El) = An_Enumeration_Literal_Specification
or else
Is_Predefined_Operation_Renaming (Called_El)
then
return;
end if;
Called_El := Corresponding_Element (Called_El);
if Is_Nil (Called_El)
or else
Expression_Kind (Called_El) = An_Attribute_Reference
or else
Expression_Kind (Called_El) = An_Enumeration_Literal
then
return;
end if;
Called_Node := Corresponding_Node (Called_El);
if Present (Called_Node) then
Set_Application_Flag_1 (Called_Node, True);
end if;
end if;
end Mark_Called_Function_Used;
---------------------------
-- Missing_Body_Reported --
---------------------------
function Missing_Body_Reported (N : GS_Node_Id) return Boolean is
begin
pragma Assert (GS_Node_Kind (N) in Callable_Nodes);
return Table (N).Bool_Flag_7;
end Missing_Body_Reported;
------------------------------------------------
-- Patch_For_Default_Parameter_Initialization --
------------------------------------------------
procedure Patch_For_Default_Parameter_Initialization
(Element : Asis.Element)
is
Tmp : Asis.Element;
Control : Traverse_Control := Continue;
State : No_State := Not_Used;
begin
if Declaration_Kind (Element) = A_Parameter_Specification then
Tmp := Enclosing_Element (Element);
if Is_Declaration_Of_Callable_Entity (Tmp) or else
Declaration_Kind (Tmp) in
An_Entry_Declaration .. An_Entry_Body_Declaration
then
Tmp := Initialization_Expression (Element);
if not Is_Nil (Tmp) then
Mark_All_Called_Functions_Used (Tmp, Control, State);
end if;
end if;
end if;
end Patch_For_Default_Parameter_Initialization;
------------------
-- Process_Call --
------------------
procedure Process_Call
(Element : Asis.Element;
At_SLOC : String_Loc := Nil_String_Loc)
is
Called_El : Asis.Element := Get_Called_Element (Element);
Called_Node : GS_Node_Id;
Tmp_Cursor : Node_Lists.Cursor;
Tmp_Success : Boolean;
begin
if Is_Nil (Called_El) then
if Is_Call_To_Predefined_Operation (Element)
or else
Is_Call_To_Attribute_Subprogram (Element)
or else
Is_Call_To_Default_Null_Procedure (Element)
then
-- We do not consider such calls at all
return;
elsif Generate_Global_Structure_Warnings then
ASIS_UL.Output.Error (Build_GNAT_Location (Element) &
": call can not be resolved statically");
end if;
elsif Declaration_Kind (Called_El) =
An_Enumeration_Literal_Specification
then
-- This may happen in instantiation if an enumeration literal is
-- used as an actual for a formal function.
return;
else
if Is_Predefined_Operation_Renaming (Called_El) then
-- We do not consider such calls at all
return;
end if;
if Is_Renaming_Of_Null_Proc_Default (Called_El) then
-- May take place in nested generic when formal subprogram with
-- null default is used to instantiate another generic inside the
-- template code.
return;
end if;
Called_El := Corresponding_Element (Called_El);
if Is_Nil (Called_El) then
-- Subprogram renaming cannot be resolved statically. We do not
-- generate any diagnstic here, because the cubprogram to be
-- called here shall be marked as used anyway (if we have a
-- explicit dereference here, then the renamed subprogram is
-- marked as used when 'Access attribute is applied to it
return;
elsif Expression_Kind (Called_El) = An_Attribute_Reference
or else
Expression_Kind (Called_El) = An_Enumeration_Literal
then
-- These calls are of no interest
return;
end if;
if not Should_Be_In_CG (Called_El) then
return;
end if;
pragma Assert
(Is_Declaration_Of_Callable_Entity (Called_El)
or else
Is_Scope (Called_El));
if ASIS_UL.Options.Represent_Dispatching_Calls
and then
Is_Dispatching_Call (Element)
then
Called_Node := Corresponding_Node (Called_El);
Node_Lists.Insert
(Container => Table (Current_Scope).Node_List_2,
New_Item => Called_Node,
Position => Tmp_Cursor,
Inserted => Tmp_Success);
end if;
if Is_Part_Of_Inherited (Called_El) then
Called_El := Corresponding_Declaration (Called_El);
end if;
if At_SLOC = Nil_String_Loc then
Store_Arc
(Called_Entity => Called_El,
At_SLOC => Build_GNAT_Location (Element));
else
Store_Arc
(Called_Entity => Called_El,
At_SLOC => At_SLOC);
end if;
end if;
end Process_Call;
-----------------------------
-- Process_Callable_Entity --
-----------------------------
procedure Process_Callable_Entity (El : Asis.Element) is
Tmp : GS_Node_Id;
begin
Tmp := Corresponding_Node (El, Current_Scope);
if Present (Tmp)
and then
Declaration_Kind (El) = A_Single_Task_Declaration
then
Store_Arc (Called_Entity => El, At_SLOC => Build_GNAT_Location (El));
end if;
end Process_Callable_Entity;
-----------------------------
-- Process_Discr_Init_Proc --
-----------------------------
procedure Process_Discr_Init_Proc (El : Asis.Element) is
Proc_Node : constant GS_Node_Id :=
Corresponding_Node (El, Expected_Kind => A_Type_Discr_Init_Procedure);
pragma Unreferenced (Proc_Node);
begin
null;
end Process_Discr_Init_Proc;
-------------------------------
-- Process_Elaboration_Calls --
-------------------------------
procedure Process_Elaboration_Calls (Element : Asis.Element) is
Arg_Kind : constant Flat_Element_Kinds := Flat_Element_Kind (Element);
Call_AT_SLOC : constant String_Loc := Build_GNAT_Location (Element);
Type_To_Analyze : Asis.Element := Nil_Element;
-- To be set to point to the (full) type declaration of the type
-- for that we have to process default (sub)component initialization
-- expressions
Tmp_El : Asis.Element;
Process_Discriminants : Boolean := False;
-- In case if the discriminant constraint is present, we do not have to
-- process default expressions for discriminants
begin
case Arg_Kind is
when A_Variable_Declaration |
An_Allocation_From_Subtype =>
if Arg_Kind = A_Variable_Declaration then
Type_To_Analyze := Object_Declaration_View (Element);
else
Type_To_Analyze := Allocator_Subtype_Indication (Element);
end if;
if Type_Kind (Type_To_Analyze) in
An_Unconstrained_Array_Definition ..
A_Constrained_Array_Definition
then
Type_To_Analyze := Array_Component_Definition (Type_To_Analyze);
Type_To_Analyze :=
Component_Definition_View (Type_To_Analyze);
end if;
case Flat_Element_Kind (Type_To_Analyze) is
when A_Subtype_Indication =>
Tmp_El := Asis.Definitions.Subtype_Mark (Type_To_Analyze);
when An_Anonymous_Access_To_Procedure |
An_Anonymous_Access_To_Protected_Procedure |
An_Anonymous_Access_To_Function |
An_Anonymous_Access_To_Protected_Function =>
return;
when others =>
Tmp_El :=
Anonymous_Access_To_Object_Subtype_Mark (Type_To_Analyze);
end case;
if Expression_Kind (Tmp_El) /= An_Attribute_Reference then
-- In case of a attribute reference as a subtype mark the
-- only possible case is 'Base, so we have a scalar type
-- here, therefore it can be no default initialization
Process_Discriminants :=
Definition_Kind (Type_To_Analyze) = A_Subtype_Indication
and then
Is_Nil (Subtype_Constraint (Type_To_Analyze))
and then
Is_Indefinite_Subtype (Tmp_El);
else
Process_Discriminants := False;
end if;
Type_To_Analyze := Get_Subtype_Structure (Type_To_Analyze);
-- First, check discriminants:
if Process_Discriminants then
Add_Link_To_SLOC_List
(To_Node => Current_Scope,
To_List => Calls,
Link_To_Add =>
(Node => Corresponding_Node
(El => Type_To_Analyze,
Expected_Kind => A_Type_Discr_Init_Procedure),
SLOC => Build_GNAT_Location (Element)));
end if;
-- Now, check if we have record components with defaul
-- initialization expressions
if Has_Type_Init_Proc (Type_To_Analyze) then
Add_Link_To_SLOC_List
(To_Node => Current_Scope,
To_List => Calls,
Link_To_Add =>
(Node => Corresponding_Node
(El => Type_To_Analyze,
Expected_Kind => A_Type_Init_Procedure),
SLOC => Build_GNAT_Location (Element)));
end if;
when An_Entry_Call_Statement |
A_Procedure_Call_Statement |
A_Function_Call =>
declare
Call_Parameters : constant Asis.Element_List :=
Get_Call_Parameters (Element, Normalized => True);
-- Note that if Elemnent is a dispatching or dynamic call,
-- Call_Parameters are Nil_Element_List!
begin
for J in Call_Parameters'Range loop
if Is_Defaulted_Association (Call_Parameters (J)) then
Tmp_El := Actual_Parameter (Call_Parameters (J));
Unconditionally_Collect_CG_Info_From_Construct
(Element => Tmp_El,
At_SLOC => Call_AT_SLOC);
end if;
end loop;
end;
when A_Procedure_Instantiation |
A_Function_Instantiation =>
declare
Inst_Parameters : constant Asis.Element_List :=
Generic_Actual_Part (Element, Normalized => True);
begin
for J in Inst_Parameters'Range loop
if Is_Defaulted_Association (Inst_Parameters (J))
and then
Declaration_Kind (Enclosing_Element
(Formal_Parameter (Inst_Parameters (J)))) =
A_Formal_Object_Declaration
then
-- Note the condition expression: we check that we have
-- an association corresponding to formal object by
-- querying the kind of Enclosing_Element of a formal,
-- but not actual parameter of the association, because
-- the ASIS Standard does not define exactly the effect
-- of Enclosing_Element for an actual parameter from a
-- normalized association
Tmp_El := Actual_Parameter (Inst_Parameters (J));
Unconditionally_Collect_CG_Info_From_Construct
(Element => Tmp_El,
At_SLOC => Call_AT_SLOC);
end if;
end loop;
end;
when others =>
null;
-- Not implemented yet
end case;
end Process_Elaboration_Calls;
---------------------------------------------------
-- Process_Init_Expressions_In_Record_Components --
---------------------------------------------------
procedure Process_Init_Expressions_In_Record_Components
(Component_List : Asis.Element_List;
Call_At_SLOC : String_Loc)
is
Comp_Def : Asis.Element;
begin
for J in Component_List'Range loop
case Flat_Element_Kind (Component_List (J)) is
when Flat_Clause_Kinds |
A_Null_Component =>
null;
when A_Variant_Part =>
Process_Init_Expressions_In_Record_Components
(Component_List =>
Asis.Definitions.Variants (Component_List (J)),
Call_At_SLOC => Call_At_SLOC);
when A_Variant =>
Process_Init_Expressions_In_Record_Components
(Component_List =>
Asis.Definitions.Record_Components (Component_List (J)),
Call_At_SLOC => Call_At_SLOC);
when A_Component_Declaration =>
Comp_Def := Initialization_Expression (Component_List (J));
if Is_Nil (Comp_Def) then
-- No initialization here, but we have to go down the
-- component structure:
Comp_Def := Object_Declaration_View (Component_List (J));
Comp_Def := Component_Definition_View (Comp_Def);
if Definition_Kind (Comp_Def) = An_Access_Definition then
return;
end if;
Comp_Def := Get_Subtype_Structure (Comp_Def);
Process_Type_Default_Expressions
(Type_To_Analyze => Comp_Def,
Call_At_SLOC => Call_At_SLOC);
else
Collect_CG_Info_From_Construct
(Element => Comp_Def,
At_SLOC => Call_At_SLOC);
end if;
when others =>
-- Just in case...
pragma Assert (False);
null;
end case;
end loop;
end Process_Init_Expressions_In_Record_Components;
----------------------------
-- Process_Type_Init_Proc --
----------------------------
procedure Process_Type_Init_Proc (El : Asis.Element) is
Proc_Node : constant GS_Node_Id :=
Corresponding_Node (El, Expected_Kind => A_Type_Init_Procedure);
pragma Unreferenced (Proc_Node);
begin
null;
end Process_Type_Init_Proc;
------------------------------------
-- Process_Record_Task_Components --
------------------------------------
procedure Process_Record_Task_Components
(Component_List : Asis.Element_List;
Call_At_SLOC : String_Loc)
is
Comp_Def : Asis.Element;
begin
for J in Component_List'Range loop
case Flat_Element_Kind (Component_List (J)) is
when Flat_Clause_Kinds |
A_Null_Component =>
null;
when A_Variant_Part =>
Process_Record_Task_Components
(Component_List =>
Asis.Definitions.Variants (Component_List (J)),
Call_At_SLOC => Call_At_SLOC);
when A_Variant =>
Process_Record_Task_Components
(Component_List =>
Asis.Definitions.Record_Components (Component_List (J)),
Call_At_SLOC => Call_At_SLOC);
when A_Component_Declaration =>
Comp_Def := Object_Declaration_View (Component_List (J));
Comp_Def := Component_Definition_View (Comp_Def);
if Definition_Kind (Comp_Def) = A_Subtype_Indication
or else
Access_Definition_Kind (Comp_Def) in
An_Anonymous_Access_To_Variable ..
An_Anonymous_Access_To_Constant
then
Comp_Def := Get_Subtype_Structure (Comp_Def);
Process_Task_Components
(Type_Decl => Comp_Def,
Call_At_SLOC => Call_At_SLOC);
end if;
when others =>
-- Just in case...
pragma Assert (False);
null;
end case;
end loop;
end Process_Record_Task_Components;
-------------------------------------
-- Process_Reference_To_Subprogram --
-------------------------------------
procedure Process_Reference_To_Subprogram
(Element : Asis.Element;
At_SLOC : String_Loc)
is
Subpr : Asis.Element := Prefix (Element);
Call_Sloc : String_Loc := At_SLOC;
begin
Subpr := Normalize_Reference (Subpr);
if Expression_Kind (Subpr) not in
An_Identifier .. An_Operator_Symbol
then
-- No interest for call graph, so
return;
end if;
Subpr := Corresponding_Name_Declaration (Subpr);
case Declaration_Kind (Subpr) is
when A_Procedure_Instantiation |
A_Function_Instantiation |
A_Procedure_Declaration |
A_Function_Declaration |
A_Procedure_Body_Declaration |
A_Function_Body_Declaration =>
-- Continue processing...
null;
when A_Procedure_Body_Stub |
A_Function_Body_Stub =>
if Declaration_Kind (Corresponding_Declaration (Subpr)) in
A_Generic_Declaration
then
-- No interest for a call graph
return;
end if;
when others =>
-- Nothing interesting for a call graph
return;
end case;
if Should_Be_In_CG (Subpr) then
if Call_Sloc = Nil_String_Loc then
Call_Sloc := Build_GNAT_Location (Element);
end if;
Store_Arc
(Called_Entity => Subpr,
At_SLOC => At_SLOC,
Calling_Entity => Enclosing_Scope (Subpr));
end if;
end Process_Reference_To_Subprogram;
------------------------------
-- Process_Renaming_As_Body --
------------------------------
procedure Process_Renaming_As_Body (El : Asis.Element) is
Subprogram_Node : constant GS_Node_Id :=
Corresponding_Node (Corresponding_Declaration (El));
Renamed_Subprogram : Asis.Element := Get_Renamed_Subprogram (El);
Renamed_Subprogram_Node : GS_Node_Id;
Is_Of_No_Interest : Boolean := True;
begin
if not (Should_Be_In_CG (El)
and then
Should_Be_In_CG (Renamed_Subprogram))
then
return;
end if;
Set_Is_Renaming (Subprogram_Node);
case Declaration_Kind (Renamed_Subprogram) is
when A_Procedure_Declaration |
A_Function_Declaration |
A_Procedure_Body_Declaration |
A_Function_Body_Declaration |
A_Procedure_Body_Stub |
A_Function_Body_Stub |
A_Procedure_Instantiation |
A_Function_Instantiation =>
Is_Of_No_Interest := False;
when An_Entry_Declaration =>
-- Task entry is renamed as a subprogram - we cannot process
-- this case yet:
Set_Is_Of_No_Interest (Subprogram_Node);
raise ASIS_UL.Common.Non_Implemented_Error;
when others =>
-- Is_Of_No_Interest remains ON. Here we have all the cases of
-- attrubute subprogram renamings
null;
end case;
if Is_Of_No_Interest then
Set_Is_Of_No_Interest (Subprogram_Node);
else
if Is_Part_Of_Inherited (Renamed_Subprogram) then
Renamed_Subprogram :=
Corresponding_Declaration (Renamed_Subprogram);
end if;
Renamed_Subprogram_Node := Corresponding_Node (Renamed_Subprogram);
-- Add the "call" from a renaming to the renamed subprogram
Add_Link_To_SLOC_List
(To_Node => Subprogram_Node,
To_List => Calls,
Link_To_Add => (Node => Renamed_Subprogram_Node,
SLOC => Build_GNAT_Location (El)));
end if;
end Process_Renaming_As_Body;
-------------------
-- Process_Scope --
-------------------
procedure Process_Scope (El : Asis.Element) is
Tmp : GS_Node_Id;
Scope_El : Asis.Element;
begin
Scope_El := Corresponding_Element (El);
if not Should_Be_In_CG (Scope_El) then
-- Is it OK? What about the enclosing scope references?
return;
end if;
if Is_Subunit (El) then
Tmp := Corresponding_Node (Scope_El);
else
Tmp := Corresponding_Node (Scope_El, Current_Scope);
end if;
if Declaration_Kind (El) = A_Task_Body_Declaration
and then
Declaration_Kind (Corresponding_Declaration (Scope_El)) =
A_Task_Type_Declaration
then
-- Task type differs from a single anonymously typed task object in
-- respect of the scope node. For a task object, the front-end
-- creates an inplicit task type using the defining identifier node
-- from the task body as the defining identifier node for this type,
-- so the defining identifier from the body works as a top of the
-- scope for bodies corresponding to single task declarations. But
-- for a body that corresponds to a task type we have to go to the
-- task type declaration to get the scope node.
Scope_El := Corresponding_Declaration (Scope_El);
end if;
Scope_El := First_Name (Scope_El);
Set_Current_Scope (Tmp, Node (Scope_El));
Set_Body_Analyzed (Tmp);
if Represent_Dispatching_Calls
and then
Is_Dispatching_Operation (Scope_El)
and then
Is_Overriding_Operation (Scope_El)
then
Set_Implementing_Node (Implemented_Operations (Scope_El), Tmp);
end if;
-- If we have a body of a user-defined "=" operation that can be used
-- as a part of the implementation of some other predefined "="
-- according to RM 2012 4.5.2 (14/3 .. 15/3) and 3.4 (17/2), then we
-- mark it as used by creating the call link from environment task node
-- to the corresponding function declaration.
if Can_Be_Embedded_In_Equiality (Enclosing_Element (Scope_El)) then
Add_Link_To_SLOC_List
(To_Node => Environment_Task_Node,
Link_To_Add => (Tmp, Build_GNAT_Location (Scope_El)));
end if;
end Process_Scope;
-------------------------------------------
-- Process_Stream_Attribute_Redefinition --
-------------------------------------------
procedure Process_Stream_Attribute_Redefinition
(Element : Asis.Element;
At_SLOC : String_Loc)
is
Subpr : Asis.Element := Representation_Clause_Expression (Element);
begin
if Expression_Kind (Subpr) = An_Explicit_Dereference then
return;
else
Subpr := Normalize_Reference (Subpr);
end if;
Subpr := Corresponding_Name_Definition (Subpr);
Subpr := Enclosing_Element (Subpr);
pragma Assert
(Is_Declaration_Of_Callable_Entity (Subpr)
or else
Is_Scope (Subpr));
if Should_Be_In_CG (Subpr) then
if At_SLOC = Nil_String_Loc then
Store_Arc
(Called_Entity => Subpr,
At_SLOC => Build_GNAT_Location (Element));
else
Store_Arc
(Called_Entity => Subpr,
At_SLOC => At_SLOC);
end if;
end if;
end Process_Stream_Attribute_Redefinition;
-----------------------------
-- Process_Task_Components --
-----------------------------
procedure Process_Task_Components
(Type_Decl : Asis.Element;
Call_At_SLOC : String_Loc;
Recursive_Call : Boolean := False)
is
T_Def : Asis.Element;
Tmp : Asis.Element;
Unused_Cursor : Element_Containers.Cursor;
Inserted : Boolean;
begin
if Recursive_Call then
Element_Containers.Clear (Processed_Types);
end if;
Element_Containers.Insert
(Container => Processed_Types,
New_Item => Type_Decl,
Position => Unused_Cursor,
Inserted => Inserted);
if not Inserted then
-- To avoid recursion
return;
end if;
case Declaration_Kind (Type_Decl) is
when A_Task_Type_Declaration =>
if Should_Be_In_CG (Type_Decl) then
Store_Arc
(Called_Entity => Type_Decl,
At_SLOC => Call_At_SLOC);
end if;
when A_Protected_Type_Declaration |
A_Formal_Type_Declaration =>
null;
when An_Ordinary_Type_Declaration =>
T_Def := Type_Declaration_View (Type_Decl);
case Type_Kind (T_Def) is
when A_Derived_Record_Extension_Definition =>
Tmp := Asis.Definitions.Record_Definition (T_Def);
if Definition_Kind (Tmp) /= A_Null_Record_Definition then
Process_Record_Task_Components
(Component_List => Record_Components (Tmp),
Call_At_SLOC => Call_At_SLOC);
end if;
Tmp := Parent_Subtype_Indication (T_Def);
Tmp := Get_Subtype_Structure (Tmp);
Process_Task_Components (Tmp, Call_At_SLOC => Call_At_SLOC);
when An_Unconstrained_Array_Definition |
A_Constrained_Array_Definition =>
Tmp := Array_Component_Definition (T_Def);
Tmp := Component_Definition_View (Tmp);
if Definition_Kind (Tmp) = A_Subtype_Indication then
-- we are not interested in components that are defined
-- by An_Access_Definition
Tmp := Get_Subtype_Structure (Tmp);
Process_Task_Components
(Tmp,
Call_At_SLOC => Call_At_SLOC);
end if;
when A_Record_Type_Definition |
A_Tagged_Record_Type_Definition =>
-- Note: we do not process discriminant components!
Tmp := Asis.Definitions.Record_Definition (T_Def);
if Definition_Kind (Tmp) /= A_Null_Record_Definition then
Process_Record_Task_Components
(Component_List => Record_Components (Tmp),
Call_At_SLOC => Call_At_SLOC);
end if;
when A_Derived_Type_Definition =>
-- Just in case...
pragma Assert (False);
null;
when others =>
null;
end case;
when An_Incomplete_Type_Declaration |
A_Tagged_Incomplete_Type_Declaration =>
Process_Task_Components
(Type_Decl => Corresponding_Type_Declaration (Type_Decl),
Call_At_SLOC => Call_At_SLOC);
when others =>
pragma Assert (False);
null;
end case;
end Process_Task_Components;
---------------------------
-- Process_Task_Creation --
---------------------------
procedure Process_Task_Creation (El : Asis.Element) is
Type_To_Analyze : Asis.Element;
begin
case Flat_Element_Kind (El) is
when A_Variable_Declaration |
A_Constant_Declaration =>
Type_To_Analyze := Object_Declaration_View (El);
if Type_Kind (Type_To_Analyze) in
An_Unconstrained_Array_Definition ..
A_Constrained_Array_Definition
then
Type_To_Analyze := Array_Component_Definition (Type_To_Analyze);
Type_To_Analyze :=
Component_Definition_View (Type_To_Analyze);
end if;
when An_Allocation_From_Subtype =>
Type_To_Analyze := Allocator_Subtype_Indication (El);
when others =>
pragma Assert (False);
null;
end case;
if Definition_Kind (Type_To_Analyze) = An_Access_Definition
and then
Access_Definition_Kind (Type_To_Analyze) not in
An_Anonymous_Access_To_Variable .. An_Anonymous_Access_To_Constant
then
return;
end if;
Type_To_Analyze := Get_Subtype_Structure (Type_To_Analyze);
Process_Task_Components
(Type_To_Analyze,
Call_At_SLOC => Build_GNAT_Location (El),
Recursive_Call => True);
end Process_Task_Creation;
--------------------------------------
-- Process_Type_Default_Expressions --
--------------------------------------
procedure Process_Type_Default_Expressions
(Type_To_Analyze : Asis.Element;
Call_At_SLOC : String_Loc)
is
Type_Def : constant Asis.Element :=
Type_Declaration_View (Type_To_Analyze);
Tmp : Asis.Element;
begin
-- Note: we do not process discriminant components!
case Definition_Kind (Type_Def) is
when A_Protected_Definition =>
Process_Init_Expressions_In_Record_Components
(Component_List => Private_Part_Items (Type_Def),
Call_At_SLOC => Call_At_SLOC);
when A_Type_Definition =>
case Type_Kind (Type_Def) is
when A_Derived_Record_Extension_Definition =>
Tmp := Asis.Definitions.Record_Definition (Type_Def);
if Definition_Kind (Tmp) = A_Null_Record_Definition then
Process_Init_Expressions_In_Record_Components
(Component_List => Record_Components (Tmp),
Call_At_SLOC => Call_At_SLOC);
end if;
Tmp := Parent_Subtype_Indication (Type_Def);
Tmp := Get_Subtype_Structure (Tmp);
Process_Type_Default_Expressions
(Type_To_Analyze => Tmp,
Call_At_SLOC => Call_At_SLOC);
when An_Unconstrained_Array_Definition |
A_Constrained_Array_Definition =>
Tmp := Array_Component_Definition (Type_Def);
Tmp := Component_Definition_View (Tmp);
if Definition_Kind (Tmp) = A_Subtype_Indication then
-- we are not interested in components that are defined
-- by An_Access_Definition
Tmp := Get_Subtype_Structure (Tmp);
Process_Type_Default_Expressions
(Type_To_Analyze => Tmp,
Call_At_SLOC => Call_At_SLOC);
end if;
when A_Record_Type_Definition |
A_Tagged_Record_Type_Definition =>
Tmp := Asis.Definitions.Record_Definition (Type_Def);
if Definition_Kind (Tmp) /= A_Null_Record_Definition then
Process_Init_Expressions_In_Record_Components
(Component_List => Record_Components (Tmp),
Call_At_SLOC => Call_At_SLOC);
end if;
when others =>
-- No default initialization expression in this case!
null;
end case;
when others =>
-- No default initialization expression in this case!
null;
end case;
end Process_Type_Default_Expressions;
-----------------------
-- Set_Body_Analyzed --
-----------------------
procedure Set_Body_Analyzed (N : GS_Node_Id; Val : Boolean := True) is
begin
pragma Assert (GS_Node_Kind (N) in Callable_Nodes);
Set_Bool_Flag_1 (N, Val);
end Set_Body_Analyzed;
---------------------------
-- Set_Implementing_Node --
---------------------------
procedure Set_Implementing_Node
(Implementred_Operations : Asis.Element_List;
Implemeting_Node : GS_Node_Id)
is
Next_Implemented_Op : GS_Node_Id;
begin
for Op in Implementred_Operations'Range loop
Next_Implemented_Op :=
Corresponding_Node
(Corresponding_Element (Implementred_Operations (Op)),
Unconditionally => True);
Node_Lists.Insert
(Table (Next_Implemented_Op).Node_List_3,
Implemeting_Node);
end loop;
end Set_Implementing_Node;
---------------------
-- Set_Is_Renaming --
---------------------
procedure Set_Is_Renaming (N : GS_Node_Id; Val : Boolean := True) is
begin
pragma Assert (GS_Node_Kind (N) in Callable_Nodes);
Set_Bool_Flag_2 (N, Val);
end Set_Is_Renaming;
----------------------
-- Set_Is_Task_Type --
----------------------
procedure Set_Is_Task_Type (N : GS_Node_Id; Val : Boolean := True) is
begin
pragma Assert (GS_Node_Kind (N) = A_Task);
Set_Bool_Flag_3 (N, Val);
end Set_Is_Task_Type;
-------------------------------
-- Set_Missing_Body_Reported --
-------------------------------
procedure Set_Missing_Body_Reported
(N : GS_Node_Id;
Val : Boolean := True)
is
begin
pragma Assert (GS_Node_Kind (N) in Callable_Nodes);
Set_Bool_Flag_7 (N, Val);
end Set_Missing_Body_Reported;
---------------
-- Store_Arc --
---------------
procedure Store_Arc
(Called_Entity : Asis.Element;
At_SLOC : String_Loc;
Calling_Entity : Asis.Element := Nil_Element)
is
Called_Node : constant GS_Node_Id := Corresponding_Node (Called_Entity);
Calling_Node : GS_Node_Id := Current_Scope;
begin
if not Is_Nil (Calling_Entity) then
Calling_Node := Corresponding_Node
(Corresponding_Element (Calling_Entity), Unconditionally => True);
pragma Assert (Present (Calling_Node));
end if;
pragma Assert
(First_GS_Node < Called_Node
and then
Called_Node <= Last_Node);
Add_Link_To_SLOC_List
(To_Node => Calling_Node,
To_List => Calls,
Link_To_Add => (Node => Called_Node, SLOC => At_SLOC));
end Store_Arc;
----------------------------------
-- Store_Dispatching_Operations --
----------------------------------
procedure Store_Dispatching_Operations (El : Asis.Element) is
Disp_Ops : constant Asis.Element_List :=
Dispatching_Operations (El);
Tmp_Node : GS_Node_Id;
pragma Unreferenced (Tmp_Node);
begin
for Op in Disp_Ops'Range loop
if not Is_Predefined_Operation_Renaming (Disp_Ops (Op)) then
Tmp_Node := Corresponding_Node (Disp_Ops (Op));
end if;
end loop;
end Store_Dispatching_Operations;
------------------------
-- Transitive_Closure --
------------------------
procedure Transitive_Closure is
begin
if not Traverse_Renamings_Done then
Traverse_Renamings;
end if;
if Represent_Dispatching_Calls then
Expand_Dispatching_Calls;
end if;
Check_Call_Graph_Completeness;
for Node in First_GS_Node .. Last_Node loop
if Is_Callable_Node (Node)
and then
not Is_Of_No_Interest (Node)
then
Close_Node (Node);
end if;
end loop;
Transitive_Closure_Done_Flag := True;
end Transitive_Closure;
-----------------------------
-- Transitive_Closure_Done --
-----------------------------
function Transitive_Closure_Done return Boolean is
begin
return Transitive_Closure_Done_Flag;
end Transitive_Closure_Done;
------------------------
-- Traverse_Renamings --
------------------------
procedure Traverse_Renamings is
Already_Processed_Renamings : Node_Lists.Set;
procedure Process_Renaming (Node : GS_Node_Id);
-- Processes one renaming node and after that add node to
-- Already_Processed_Renamings set. This procedure recursively traverses
-- renaming chains (we suppose that these chains do not contain loops,
-- any loop definitely means an elaboration problem!).
procedure Process_Renaming (Node : GS_Node_Id) is
Renamed_Node : constant GS_Node_Id := First_Direct_Call (Node);
begin
Node_Lists.Insert (Already_Processed_Renamings, Node);
if Is_Of_No_Interest (Renamed_Node) then
Set_Is_Of_No_Interest (Node);
return;
end if;
if GS_Is_Renaming (Renamed_Node)
and then
not Node_Lists.Contains
(Already_Processed_Renamings, Renamed_Node)
then
Process_Renaming (Renamed_Node);
-- This may define that Renamed_Node is of no interest, so:
if Is_Of_No_Interest (Renamed_Node) then
Set_Is_Of_No_Interest (Node);
return;
end if;
end if;
Set_Body_Analyzed (Node, Body_Analyzed (Renamed_Node));
end Process_Renaming;
begin
Node_Lists.Clear (Already_Processed_Renamings);
for Node in First_GS_Node .. Last_Node loop
if Is_Callable_Node (Node)
and then
GS_Is_Renaming (Node)
and then
not Is_Of_No_Interest (Node)
and then
not Node_Lists.Contains (Already_Processed_Renamings, Node)
then
Process_Renaming (Node);
end if;
end loop;
Traverse_Renamings_Done_Flag := True;
end Traverse_Renamings;
-----------------------------
-- Traverse_Renamings_Done --
-----------------------------
function Traverse_Renamings_Done return Boolean is
begin
return Traverse_Renamings_Done_Flag;
end Traverse_Renamings_Done;
----------------------------------------
-- Unconditionally_Add_CG_Info_Pre_Op --
----------------------------------------
procedure Unconditionally_Add_CG_Info_Pre_Op
(Element : Asis.Element;
Control : in out Traverse_Control;
State : in out String_Loc)
is
Expanded_Code : Asis.Element;
begin
Add_CG_Info (Element, State);
if Declaration_Kind (Element) in
A_Package_Instantiation .. A_Function_Instantiation
then
Expanded_Code := Corresponding_Declaration (Element);
Traverse_Construct_For_CG_Info
(Element => Expanded_Code,
Control => Control,
State => State);
Expanded_Code := Corresponding_Body (Element);
if not Is_Nil (Expanded_Code) then
Traverse_Construct_For_CG_Info
(Element => Expanded_Code,
Control => Control,
State => State);
end if;
end if;
exception
when Ex : others =>
ASIS_UL.Common.Tool_Failures := ASIS_UL.Common.Tool_Failures + 1;
ASIS_UL.Output.Error ("call graph info collection failed");
ASIS_UL.Output.Error (Build_GNAT_Location (Element));
ASIS_UL.Output.Report_Unhandled_Exception (Ex);
end Unconditionally_Add_CG_Info_Pre_Op;
----------------------------------------------------
-- Unconditionally_Collect_CG_Info_From_Construct --
----------------------------------------------------
procedure Unconditionally_Collect_CG_Info_From_Construct
(Element : Asis.Element;
At_SLOC : String_Loc := Nil_String_Loc)
is
State : String_Loc := At_SLOC;
Control : Traverse_Control := Continue;
begin
Unconditionally_Traverse_Construct_For_CG_Info (Element, Control, State);
end Unconditionally_Collect_CG_Info_From_Construct;
end ASIS_UL.Global_State.CG;
|