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
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- E R R O U T --
-- --
-- B o d y --
-- --
-- $Revision: 1.163 $ --
-- --
-- Copyright (C) 1992-1997 Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT 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 COPYING. If not, write --
-- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
-- MA 02111-1307, USA. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
-- --
------------------------------------------------------------------------------
-- Warning! Error messages can be generated during Gigi processing by direct
-- calls to error message routines, so it is essential that the processing
-- in this body be consistent with the requirements for the Gigi processing
-- environment, and that in particular, no disallowed table expansion is
-- allowed to occur.
with Atree; use Atree;
with Casing; use Casing;
with Csets; use Csets;
with Debug; use Debug;
with Einfo; use Einfo;
with Expander; use Expander;
with Fname; use Fname;
with Hostparm;
with Lib; use Lib;
with Namet; use Namet;
with Opt; use Opt;
with Output; use Output;
with Scans; use Scans;
with Sem_Util; use Sem_Util;
with Sinput; use Sinput;
with Sinfo; use Sinfo;
with Snames; use Snames;
with Stand; use Stand;
with Uintp; use Uintp;
with Uname; use Uname;
package body Errout is
Max_Msg_Length : constant := 80 + 2 * Hostparm.Max_Line_Length;
-- Maximum length of error message. The addition of Max_Line_Length
-- ensures that two insertion tokens of maximum length can be accomodated.
Msg_Buffer : String (1 .. Max_Msg_Length);
-- Buffer used to prepare error messages
Msglen : Integer;
-- Number of characters currently stored in the message buffer
Flag_Source : Source_File_Index;
-- Source file index for source file where error is being posted
Is_Warning_Msg : Boolean;
-- Set by Set_Msg_Text to indicate if current message is warning message
Is_Unconditional_Msg : Boolean;
-- Set by Set_Msg_Text to indicate if current message is unconditional
Cur_Msg : Error_Msg_Id;
-- Id of most recently posted error message
Current_Error_Source_File : Source_File_Index;
-- Id of current messages. Used to post file name when unit changes. This
-- is initialized to Main_Source at the start of a compilation, which means
-- that no file names will be output unless there are errors in units
-- other than the main unit. However, if the main unit has a pragma
-- Source_Reference line, then this is initialized to No_Source_File,
-- to force an initial reference to the real source file name.
Manual_Quote_Mode : Boolean;
-- Set True in manual quotation mode
List_Pragmas_Index : Int;
-- Index into List_Pragmas table
List_Pragmas_Mode : Boolean;
-- Starts True, gets set False by pragma List (Off), True by List (On)
Suppress_Message : Boolean;
-- A flag used to suppress certain obviously redundant messages (i.e.
-- those referring to a node whose type is Any_Type). This suppression
-- is effective only if All_Errors_Mode is off.
Kill_Message : Boolean;
-- A flag used to kill weird messages (e.g. those containing uninterpreted
-- implicit type references) if we have already seen at least one message
-- already. The idea is that we hope the weird message is a junk cascaded
-- message that should be suppressed.
Suppress_Instance_Location : Boolean := False;
-- Normally, if a # location in a message references a location within
-- a generic template, then a note is added giving the location of the
-- instantiation. If this variable is set True, then this note is not
-- output. This is used for internal processing for the case of an
-- illegal instantiation. See Error_Msg routine for further details.
Continuation : Boolean;
-- Indicates if current message is a continuation. Intialized from the
-- Msg_Cont parameter in Error_Msg_Internal and then set True if a \
-- insertion character is encountered.
Last_Killed : Boolean := False;
-- Set True if the most recently posted non-continuation message was
-- killed. This is used to determine the processing of any continuation
-- messages that follow.
-----------------------------------
-- Error Message Data Structures --
-----------------------------------
-- The error messages are stored as a linked list of error message objects
-- sorted into ascending order by the source location (Sloc). Each object
-- records the text of the message and its source location.
-- The following record type and table are used to represent error
-- messages, with one entry in the table being allocated for each message.
type Error_Msg_Object is record
Text : String_Ptr;
-- Text of error message, fully expanded with all insertions
Next : Error_Msg_Id;
-- Pointer to next message in error chain
Sfile : Source_File_Index;
-- Source table index of source file. In the case of an error that
-- refers to a template, always references the original template
-- not an instantiation copy.
Sptr : Source_Ptr;
-- Flag pointer. In the case of an error that refers to a template,
-- always references the original template, not an instantiation copy.
Line : Logical_Line_Number;
-- Line number for error message. Used in some cases to suppress
-- errors appearing on the same line.
Col : Column_Number;
-- Column number for error message
Warn : Boolean;
-- True if warning message (i.e. insertion character ? appeared)
Uncond : Boolean;
-- True if unconditional message (i.e. insertion character ! appeared)
Msg_Cont : Boolean;
-- This is used for logical messages that are composed of multiple
-- individual messages. For messages that are not part of such a
-- group, or that are the first message in such a group. Msg_Cont
-- is set to False. For subsequent messages in a group, Msg_Cont
-- is set to True. This is used to make sure that such a group of
-- messages is either suppressed or retained as a group (e.g. in
-- the circuit that deletes identical messages).
end record;
package Errors is new Table.Table (
Table_Component_Type => Error_Msg_Object,
Table_Index_Type => Error_Msg_Id,
Table_Low_Bound => 1,
Table_Initial => 200,
Table_Increment => 200,
Table_Name => "Error");
Error_Msgs : Error_Msg_Id;
-- The list of error messages
--------------------------
-- Warning Mode Control --
--------------------------
-- Pragma Warnings allows warnings to be turned off for a specified
-- region of code, and the following tabl is the data structure used
-- to keep track of these regions.
-- It contains pairs of source locations, the first being the start
-- location for a warnings off region, and the second being the end
-- location. When a pragma Warnings (Off) is encountered, a new entry
-- is established extending from the location of the pragma to the
-- end of the current source file. A subsequent pragma Warnings (On)
-- adjusts the end point of this entry appropriately.
-- If all warnings are suppressed by comamnd switch, then there is a
-- dummy entry (put there by Errout.Initialize) at the start of the
-- table which covers all possible Source_Ptr values. Note that the
-- source pointer values in this table always reference the original
-- template, not an instantiation copy, in the generic case.
type Warnings_Entry is record
Start : Source_Ptr;
Stop : Source_Ptr;
end record;
package Warnings is new Table.Table (
Table_Component_Type => Warnings_Entry,
Table_Index_Type => Natural,
Table_Low_Bound => 1,
Table_Initial => 100,
Table_Increment => 200,
Table_Name => "Warnings");
-----------------------
-- Local Subprograms --
-----------------------
procedure Debug_Output (N : Node_Id);
-- Called from Error_Msg_N and Error_Msg_NE to generate line of debug
-- output giving node number (of node N) if the debug X switch is set.
function Duplicate_Messages (M1, M2 : Error_Msg_Id) return Boolean;
-- This function is passed the Id values of two error messages. A value
-- of true is returned only if M1 and M2 represent identical messages.
-- For this to be true, both M1 and M2 must represent non-continuation
-- messages with identical text, and must either have no following
-- continuation messages, or identical sequences of continuations.
procedure Error_Msg_Internal
(Msg : String;
Flag_Location : Source_Ptr;
Msg_Cont : Boolean);
-- This is like Error_Msg, except that Flag_Location is known not to be
-- a location within a instantiation of a generic template. The outer
-- level routine, Error_Msg, takes care of dealing with the generic case.
-- Msg_Cont is set True to indicate that the message is a continuation of
-- a previous message. This means that it must have the same Flag_Location
-- as the previous message.
function OK_Node (N : Node_Id) return Boolean;
-- Determines if a node is an OK node to place an error message on (return
-- True) or if the error message should be suppressed (return False). A
-- message is suppressed if the node already has an error posted on it,
-- or if it refers to an Etype that has an error posted on it, or if
-- it references an Entity that has an error posted on it.
procedure Output_Error_Msgs (E : in out Error_Msg_Id);
-- Output source line, error flag, and text of stored error message and
-- all subsequent messages for the same line and unit. On return E is
-- set to be one higher than the last message output.
procedure Output_Line_Number (L : Logical_Line_Number);
-- Output a line number as six digits (with leading zeroes suppressed),
-- followed by a period and a blank (note that this is 8 characters which
-- means that tabs in the source line will not get messed up). A line
-- number of zero is output as eight blanks (this is the way we list the
-- line number of a Source_Reference pragma at the start of the file).
procedure Output_Msg_Text (E : Error_Msg_Id);
-- Outputs characters of text in the text of the error message E, excluding
-- any final exclamation point. Note that no end of line is output, the
-- caller is responsible for adding the end of line.
procedure Output_Source_Line
(L : Logical_Line_Number;
Sfile : Source_File_Index;
Errs : Boolean);
-- Outputs text of source line L, in file S, together with preceding line
-- number, as described above for Output_Line_Number. The Errs parameter
-- indicates if there are errors attached to the line, which forces
-- listing on, even in the presence of pragma List (Off).
procedure Set_Msg_Blank;
-- Sets a single blank in the message if the preceding character is a
-- non-blank character other than a left parenthesis. Has no effect if
-- manual quote mode is turned on.
procedure Set_Msg_Blank_Conditional;
-- Sets a single blank in the message if the preceding character is a
-- non-blank character other than a left parenthesis or quote. Has no
-- effect if manual quote mode is turned on.
procedure Set_Msg_Char (C : Character);
-- Add a single character to the current message. This routine does not
-- check for special insertion characters (they are just treated as text
-- characters if they occur).
procedure Set_Msg_Insertion_Column;
-- Handle column number insertion (@ insertion character)
procedure Set_Msg_Insertion_Name;
-- Handle name insertion (% insertion character)
procedure Set_Msg_Insertion_Line_Number (Loc, Flag : Source_Ptr);
-- Handle line number insertion (# insertion character). Loc is the
-- location to be referenced, and Flag is the location at which the
-- flag is posted (used to determine whether to add "in file xxx")
procedure Set_Msg_Insertion_Node;
-- Handle node (name from node) insertion (& insertion character)
procedure Set_Msg_Insertion_Reserved_Name;
-- Handle insertion of reserved word name (* insertion character).
procedure Set_Msg_Insertion_Reserved_Word
(Text : String;
J : in out Integer);
-- Handle reserved word insertion (upper case letters). The Text argument
-- is the current error message input text, and J is an index which on
-- entry points to the first character of the reserved word, and on exit
-- points past the last character of the reserved word.
procedure Set_Msg_Insertion_Type_Reference (Flag : Source_Ptr);
-- Handle type reference (right brace insertion character). Flag is the
-- location of the flag, which is provided for the internal call to
-- Set_Msg_Insertion_Line_Number,
procedure Set_Msg_Insertion_Uint;
-- Handle Uint insertion (^ insertion character)
procedure Set_Msg_Insertion_Unit_Name;
-- Handle unit name insertion ($ insertion character)
procedure Set_Msg_Insertion_File_Name;
-- Handle file name insertion (left brace insertion character)
procedure Set_Msg_Int (Line : Int);
-- Set the decimal representation of the argument in the error message
-- buffer with no leading zeroes output.
procedure Set_Msg_Name_Buffer;
-- Output name from Name_Buffer, with surrounding quotes unless manual
-- quotation mode is in effect.
procedure Set_Msg_Node (Node : Node_Id);
-- Add the sequence of characters for the name associated with the
-- given node to the current message.
procedure Set_Msg_Quote;
-- Set quote if in normal quote mode, nothing if in manual quote mode
procedure Set_Msg_Str (Text : String);
-- Add a sequence of characters to the current message. This routine does
-- not check for special insertion characters (they are just treated as
-- text characters if they occur).
procedure Set_Msg_Text (Text : String; Flag : Source_Ptr);
-- Add a sequence of characters to the current message. The characters may
-- be one of the special insertion characters (see documentation in spec).
-- Flag is the location at which the error is to be posted, which is used
-- to determine whether or not the # insertion needs a file name. The
-- variables Msg_Buffer, Msglen, Is_Warning_Msg, and Is_Unconditional_Msg
-- are set on return.
procedure Set_Posted (N : Node_Id);
-- Sets the Error_Posted flag on the given node, and all its parents
-- that are subexpressions and then on the parent non-subexpression
-- construct that contains the original expression (this reduces the
-- number of cascaded messages)
procedure Set_Qualification (N : Nat; E : Entity_Id);
-- Outputs up to N levels of qualification for the given entity. For
-- example, the entity A.B.C.D will output B.C. if N = 2.
-----------------------
-- Change_Error_Text --
-----------------------
procedure Change_Error_Text (Error_Id : Error_Msg_Id; New_Msg : String) is
Save_Next : Error_Msg_Id;
Err_Id : Error_Msg_Id := Error_Id;
begin
Set_Msg_Text (New_Msg, Errors.Table (Error_Id).Sptr);
Errors.Table (Error_Id).Text := new String'(Msg_Buffer (1 .. Msglen));
-- If in immediate error message mode, output modified error message now
-- This is just a bit tricky, because we want to output just a single
-- message, and the messages we modified is already linked in. We solve
-- this by temporarily resetting its forward pointer to empty.
if Immediate_Errors then
Save_Next := Errors.Table (Error_Id).Next;
Errors.Table (Error_Id).Next := No_Error_Msg;
Write_Eol;
Output_Source_Line
(Errors.Table (Error_Id).Line, Errors.Table (Error_Id).Sfile, True);
Output_Error_Msgs (Err_Id);
Errors.Table (Error_Id).Next := Save_Next;
end if;
end Change_Error_Text;
------------------
-- Debug_Output --
------------------
procedure Debug_Output (N : Node_Id) is
begin
if Debug_Flag_1 then
Write_Str ("*** following error message posted on node id = #");
Write_Int (Int (N));
Write_Str (" ***");
Write_Eol;
end if;
end Debug_Output;
------------------------
-- Duplicate_Messages --
------------------------
function Duplicate_Messages (M1, M2 : Error_Msg_Id) return Boolean is
L1, L2 : Error_Msg_Id;
N1, N2 : Error_Msg_Id;
begin
-- Both messages must be non-continuation messages
if Errors.Table (M1).Msg_Cont or else Errors.Table (M2).Msg_Cont then
return False;
end if;
-- Definitely not equal if message text does not match
if Errors.Table (M1).Text.all /= Errors.Table (M2).Text.all then
return False;
end if;
-- Same text. See if all continuations are also identical
L1 := M1;
L2 := M2;
loop
N1 := Errors.Table (L1).Next;
N2 := Errors.Table (L2).Next;
-- If one of the message sequenes has run out, the other must too
if N1 = No_Error_Msg or else (not Errors.Table (N1).Msg_Cont) then
return
N2 = No_Error_Msg
or else
(not Errors.Table (N2).Msg_Cont);
end if;
-- Otherwise both message sequences are continued
if Errors.Table (N1).Text.all /= Errors.Table (N2).Text.all then
return False;
else
L1 := N1;
L2 := N2;
end if;
end loop;
end Duplicate_Messages;
---------------
-- Error_Msg --
---------------
-- Error_Msg posts a flag at the given location, except that if the
-- Flag_Location points within a generic template and corresponds
-- to an instantiation of this generic template, then the actual
-- message will be posted on the generic instantiation, along with
-- additional messages referencing the generic declaration.
procedure Error_Msg (Msg : String; Flag_Location : Source_Ptr) is
Is_Warning_Msg : Boolean := False;
Sindex : constant Source_File_Index :=
Get_Source_File_Index (Flag_Location);
Already_Flagged : Boolean := False;
-- Gets reset to true if a message has already been posted at
-- the given Flag_Location. Used to avoid bogus instantiation
-- messages as described below.
Orig_Loc : Source_Ptr;
-- Original location of Flag_Location (i.e. location in original
-- template in instantiation case, otherwise unchanged).
begin
for J in Msg'Range loop
if Msg (J) = '?' then
Is_Warning_Msg := True;
exit;
end if;
end loop;
-- It is a fatal error to issue an error message when scanning from
-- the internal source buffer (see Sinput for further documentation)
pragma Assert (Source /= Internal_Source_Ptr);
-- The idea at this stage is that we have two kinds of messages.
-- First, we have those that are to be placed as requested at
-- Flag_Location. This includes messages that have nothing to
-- do with generics, and also messages placed on generic templates
-- that reflect an error in the template itself. For such messages
-- we simply call Error_Msg_Internal to place the message in the
-- requested location.
if Instantiation (Sindex) = No_Location then
Error_Msg_Internal (Msg, Flag_Location, False);
return;
end if;
-- If we are trying to flag an error in an instantiation, we may have
-- a generic contract violation. What we generate in this case is:
-- instantiation error at ...
-- original error message
-- or
-- warning: in instantiation at
-- warning: original warning message
-- All these messages are posted at the location of the top level
-- instantiation. If there are nested instantiations, then the
-- instantiation error message can be repeated, pointing to each
-- of the relevant instantiations.
-- However, before we do this, we need to worry about the case where
-- indeed we are in an instantiation, but the message is a warning
-- message. In this case, it almost certainly a warning for the
-- template itself and so it is posted on the template. At least
-- this is the default mode, it can be cancelled (resulting the
-- warning being placed on the instance as in the error case) by
-- setting the global Warn_On_Instance True.
if (not Warn_On_Instance) and then Is_Warning_Msg then
Error_Msg_Internal (Msg, Flag_Location, False);
return;
end if;
-- Second, we need to worry about the case where there was a real error
-- in the template, and we are getting a repeat of this error in the
-- instantiation. We don't want to complain about the instantiation
-- in this case, since we have already flagged the template.
-- To deal with this case, just see if we have posted a non-warning
-- message at the template location. If so, assume that the current
-- message is redundant. There could be cases in which this is not
-- a correct assumption, but it is not terrible to lose a message,
-- about an incorrect instantiation, given that we have flagged an
-- illegality in the template itself.
Orig_Loc := Original_Location (Flag_Location);
for Err in Errors.First .. Errors.Last loop
if not Errors.Table (Err).Warn
and then Errors.Table (Err).Sptr = Orig_Loc
then
return;
end if;
end loop;
-- OK, this is the case where we have an instantiation error, and
-- we need to generate the error on the instantiation, rather than
-- on the template. First, see if we have posted this exact error
-- before, and if so suppress it. It is not so easy to use the main
-- list of errors for this, since they have already been split up
-- according to the processing below. Consequently we use an auxiliary
-- data structure that just records these types of messages (it will
-- never have very many entries).
declare
Actual_Error_Loc : Source_Ptr;
-- Location of outer level instantiation in instantiation case, or
-- just a copy of Flag_Location in the normal case. This is the
-- location where all error messages will actually be posted.
Save_Error_Msg_Sloc : constant Source_Ptr := Error_Msg_Sloc;
-- Save possible location set for caller's message. We need to
-- use Error_Msg_Sloc for the location of the instantiation error
-- but we have to preserve a possible original value.
X : Source_File_Index;
Msg_Cont_Status : Boolean;
-- Used to label continuation lines in instantiation case with
-- proper Msg_Cont status.
begin
X := Get_Source_File_Index (Flag_Location);
-- Loop to find highest level instantiation, where all error
-- messages will be placed.
while Instantiation (X) /= No_Location loop
Actual_Error_Loc := Instantiation (X);
X := Get_Source_File_Index (Actual_Error_Loc);
end loop;
-- Since we are generating the messages at the instantiation
-- point in any case, we do not want the references to the
-- bad lines in the instance to be annotated with the location
-- of the instantiation.
Suppress_Instance_Location := True;
Msg_Cont_Status := False;
-- Loop to generate instantiation messages
Error_Msg_Sloc := Flag_Location;
X := Get_Source_File_Index (Flag_Location);
while Instantiation (X) /= No_Location loop
-- Suppress instantiation message on continuation lines
if Msg (1) /= '\' then
if Is_Warning_Msg then
Error_Msg_Internal
("?in instantiation #",
Actual_Error_Loc, Msg_Cont_Status);
else
Error_Msg_Internal
("instantiation error #",
Actual_Error_Loc, Msg_Cont_Status);
end if;
end if;
Error_Msg_Sloc := Instantiation (X);
X := Get_Source_File_Index (Error_Msg_Sloc);
Msg_Cont_Status := True;
end loop;
Suppress_Instance_Location := False;
Error_Msg_Sloc := Save_Error_Msg_Sloc;
-- Here we output the original message on the outer instantiation
Error_Msg_Internal (Msg, Actual_Error_Loc, Msg_Cont_Status);
end;
end Error_Msg;
------------------------
-- Error_Msg_Internal --
------------------------
procedure Error_Msg_Internal
(Msg : String;
Flag_Location : Source_Ptr;
Msg_Cont : Boolean)
is
Next_Msg : Error_Msg_Id;
-- Pointer to next message at insertion point
Prev_Msg : Error_Msg_Id;
-- Pointer to previous message at insertion point
Temp_Msg : Error_Msg_Id;
Orig_Loc : constant Source_Ptr := Original_Location (Flag_Location);
begin
Continuation := Msg_Cont;
Suppress_Message := False;
Kill_Message := False;
Set_Msg_Text (Msg, Orig_Loc);
-- Kill continuation if parent message killed
if Continuation and Last_Killed then
return;
end if;
-- Return without doing anything if message is suppressed
if Suppress_Message
and not All_Errors_Mode
and not (Msg (Msg'Last) = '!')
then
if not Continuation then
Last_Killed := True;
end if;
return;
end if;
-- Return without doing anything if message is killed and this
-- is not the first error message. The philosophy is that if we
-- get a weird error message and we already have had a message,
-- then we hope the weird message is a junk cascaded message
if Kill_Message
and then not All_Errors_Mode
and then Errors_Detected /= 0
then
if not Continuation then
Last_Killed := True;
end if;
return;
end if;
-- Immediate return if warning message and warnings are suppressed
if Is_Warning_Msg then
for J in Warnings.First .. Warnings.Last loop
if Warnings.Table (J).Start <= Orig_Loc
and then Orig_Loc <= Warnings.Table (J).Stop
then
Cur_Msg := No_Error_Msg;
return;
end if;
end loop;
end if;
-- Otherwise build error message object for new message
Errors.Increment_Last;
Cur_Msg := Errors.Last;
Errors.Table (Cur_Msg).Text := new String'(Msg_Buffer (1 .. Msglen));
Errors.Table (Cur_Msg).Next := No_Error_Msg;
Errors.Table (Cur_Msg).Sptr := Orig_Loc;
Errors.Table (Cur_Msg).Sfile := Get_Source_File_Index (Orig_Loc);
Errors.Table (Cur_Msg).Line := Get_Line_Number (Orig_Loc);
Errors.Table (Cur_Msg).Col := Get_Column_Number (Orig_Loc);
Errors.Table (Cur_Msg).Warn := Is_Warning_Msg;
Errors.Table (Cur_Msg).Uncond := Is_Unconditional_Msg;
Errors.Table (Cur_Msg).Msg_Cont := Continuation;
-- If immediate errors mode set, output error message now. Also output
-- now if the -d1 debug flag is set (so node number message comes out
-- just before actual error message)
if Immediate_Errors or else Debug_Flag_1 then
Write_Eol;
Output_Source_Line (Errors.Table (Cur_Msg).Line,
Errors.Table (Cur_Msg).Sfile, True);
Temp_Msg := Cur_Msg;
Output_Error_Msgs (Temp_Msg);
-- If not in immediate errors mode, then we insert the message in the
-- error chain for later output by Finalize. The messages are sorted
-- first by unit (main unit comes first), and within a unit by source
-- location (earlier flag location first in the chain).
else
Prev_Msg := No_Error_Msg;
Next_Msg := Error_Msgs;
while Next_Msg /= No_Error_Msg loop
exit when
Errors.Table (Cur_Msg).Sfile < Errors.Table (Next_Msg).Sfile;
if Errors.Table (Cur_Msg).Sfile =
Errors.Table (Next_Msg).Sfile
then
exit when Orig_Loc < Errors.Table (Next_Msg).Sptr;
end if;
Prev_Msg := Next_Msg;
Next_Msg := Errors.Table (Next_Msg).Next;
end loop;
-- The possible insertion point for the new message is after Prev_Msg
-- and before Next_Msg. However, there are some cases in which we do
-- not insert the message on the grounds that it is redundant with
-- respect to the previous message. We only consider deleting the
-- message if it is for the same line and unit as the previous one.
if Prev_Msg /= No_Error_Msg
and then Errors.Table (Prev_Msg).Line =
Errors.Table (Cur_Msg).Line
and then Errors.Table (Prev_Msg).Sfile =
Errors.Table (Cur_Msg).Sfile
then
-- Delete a complete duplicate message (i.e. same error text
-- at same position). Such duplicate messages are typically
-- lexical messages from tokens that are rescanned. Note that
-- such complete duplicates are deleted even if All_Errors
-- mode is set on, since they can't possibly give any useful
-- information under any circumstances.
-- A special case of identity of error messages occurs when
-- the previous message is of the form "xxx, instance at yyy",
-- and the new message is simply "xxx". In this case we prefer
-- to retain only the instance message.
-- Note we actually do this in two places, once here, but that
-- catches only adjacent messages, and again in Finalize, where
-- we catch any remaining instances of duplicated messages.
-- Note: do not delete messages following an instantiation
-- error, because we need to keep those properly associated
-- with the instantiation error messages.
Check_Duplicate : declare
function Same_Error (Prv, Cur : String_Ptr) return Boolean;
-- See if current message is same error as previous, defined
-- as either an identical message, or the same message but
-- lacking an "instance at xxx" tag.
function Same_Error (Prv, Cur : String_Ptr) return Boolean is
Cur_Len : constant Integer := Cur'Length;
Prv_Len : constant Integer := Prv'Length;
begin
return
Prv.all = Cur.all
or else
(Prv_Len - 10 > Cur_Len
and then
Cur.all = Prv.all (1 .. Cur_Len)
and then
Prv (Cur_Len + 1 .. Cur_Len + 10) = ", instance");
end Same_Error;
-- Start of processing for Check_Duplicate
begin
if Errors.Table (Prev_Msg).Col = Errors.Table (Cur_Msg).Col
and then
Same_Error
(Errors.Table (Prev_Msg).Text,
Errors.Table (Cur_Msg).Text)
then
if not Continuation then
Last_Killed := True;
end if;
return;
end if;
end Check_Duplicate;
-- Remaining case is where we are parsing and we are not in
-- all errors mode (in semantics, don't delete any messages)
if not All_Errors_Mode and then Compiler_State = Parsing then
-- Don't delete unconditional messages and at this stage,
-- don't delete continuation lines (we attempted to delete
-- those earlier if the parent message was deleted.
if not Errors.Table (Cur_Msg).Uncond
and then not Continuation
then
-- Don't delete if prev msg is warning and new msg is
-- an error. This is because we don't want a real error
-- masked by a warning. In all other cases (that is parse
-- errors for the same line that are not unconditional)
-- we do delete the message. This helps to avoid
-- junk extra messages from cascaded parsing errors
if not Errors.Table (Prev_Msg).Warn
or else Errors.Table (Cur_Msg).Warn
then
-- All tests passed, delete the message by simply
-- returning without any further processing.
if not Continuation then
Last_Killed := True;
end if;
return;
end if;
end if;
end if;
end if;
-- Come here if message is to be inserted in the error chain
if not Continuation then
Last_Killed := False;
end if;
if Prev_Msg = No_Error_Msg then
Error_Msgs := Cur_Msg;
else
Errors.Table (Prev_Msg).Next := Cur_Msg;
end if;
Errors.Table (Cur_Msg).Next := Next_Msg;
end if;
-- Bump appropriate statistics count
if Errors.Table (Cur_Msg).Warn
and then Warning_Mode /= Treat_As_Error
then
Warnings_Detected := Warnings_Detected + 1;
else
Errors_Detected := Errors_Detected + 1;
-- Turn off code generation if not done already
if Operating_Mode = Generate_Code then
Operating_Mode := Check_Semantics;
Expander_Active := False;
end if;
-- Set the fatal error flag in the unit table unless we are
-- in Try_Semantics mode. This stops the semantics from being
-- performed if we find a parser error. This is skipped if we
-- are currently dealing with the configuration pragma file.
if not Try_Semantics
and then Current_Source_Unit /= No_Unit
then
Set_Fatal_Error (Get_Sloc_Unit_Number (Orig_Loc));
end if;
end if;
-- Terminate if max errors reached
if Errors_Detected + Warnings_Detected = Maximum_Errors then
raise Unrecoverable_Error;
end if;
end Error_Msg_Internal;
-----------------
-- Error_Msg_S --
-----------------
procedure Error_Msg_S (Msg : String) is
begin
Error_Msg (Msg, Scan_Ptr);
end Error_Msg_S;
------------------
-- Error_Msg_AP --
------------------
procedure Error_Msg_AP (Msg : String) is
S1 : Source_Ptr;
C : Character;
begin
-- If we had saved the Scan_Ptr value after scanning the previous
-- token, then we would have exactly the right place for putting
-- the flag immediately at hand. However, that would add at least
-- two instructions to a Scan call *just* to service the possibility
-- of an Error_Msg_AP call. So instead we reconstruct that value.
-- We have two possibilities, start with Prev_Token_Ptr and skip over
-- the current token, which is made harder by the possibility that this
-- token may be in error, or start with Token_Ptr and work backwards.
-- We used to take the second approach, but it's hard because of
-- comments, and harder still because things that look like comments
-- can appear inside strings. So now we take the first approach.
-- Note: in the case where there is no previous token, Prev_Token_Ptr
-- is set to Source_First, which is a reasonable position for the
-- error flag in this situation.
S1 := Prev_Token_Ptr;
C := Source (S1);
-- If the previous token is a string literal, we need a special approach
-- since there may be white space inside the literal and we don't want
-- to stop on that white space.
if Prev_Token = Tok_String_Literal then
loop
S1 := S1 + 1;
if Source (S1) = C then
S1 := S1 + 1;
exit when Source (S1) /= C;
elsif Source (S1) in Line_Terminator then
exit;
end if;
end loop;
-- Character literal also needs special handling
elsif Prev_Token = Tok_Char_Literal then
S1 := S1 + 3;
-- Otherwise we search forward for the end of the current token, marked
-- by a line terminator, white space, a comment symbol or if we bump
-- into the following token (i.e. the current token)
else
while Source (S1) not in Line_Terminator
and then Source (S1) /= ' '
and then Source (S1) /= Ascii.HT
and then (Source (S1) /= '-' or else Source (S1 + 1) /= '-')
and then S1 /= Token_Ptr
loop
S1 := S1 + 1;
end loop;
end if;
-- S1 is now set to the location for the flag
Error_Msg (Msg, S1);
end Error_Msg_AP;
------------------
-- Error_Msg_BC --
------------------
procedure Error_Msg_BC (Msg : String) is
begin
-- If we are at end of file, post the flag after the previous token
if Token = Tok_EOF then
Error_Msg_AP (Msg);
-- If we are at start of file, post the flag at the current token
elsif Token_Ptr = Source_First (Current_Source_File) then
Error_Msg_SC (Msg);
-- If the character before the current token is a space or a horizontal
-- tab, then we place the flag on this character (in the case of a tab
-- we would really like to place it in the "last" character of the tab
-- space, but that it too much trouble to worry about).
elsif Source (Token_Ptr - 1) = ' '
or else Source (Token_Ptr - 1) = Ascii.HT
then
Error_Msg (Msg, Token_Ptr - 1);
-- If there is no space or tab before the current token, then there is
-- no room to place the flag before the token, so we place it on the
-- token instead (this happens for example at the start of a line).
else
Error_Msg (Msg, Token_Ptr);
end if;
end Error_Msg_BC;
------------------
-- Error_Msg_SC --
------------------
procedure Error_Msg_SC (Msg : String) is
begin
-- If we are at end of file, post the flag after the previous token
if Token = Tok_EOF then
Error_Msg_AP (Msg);
-- For all other cases the message is posted at the current token
-- pointer position
else
Error_Msg (Msg, Token_Ptr);
end if;
end Error_Msg_SC;
------------------
-- Error_Msg_SP --
------------------
procedure Error_Msg_SP (Msg : String) is
begin
-- Note: in the case where there is no previous token, Prev_Token_Ptr
-- is set to Source_First, which is a reasonable position for the
-- error flag in this situation
Error_Msg (Msg, Prev_Token_Ptr);
end Error_Msg_SP;
-----------------
-- Error_Msg_N --
-----------------
procedure Error_Msg_N (Msg : String; N : Node_Id) is
begin
if All_Errors_Mode
or else Msg (Msg'Last) = '!'
or else OK_Node (N)
or else (Msg (1) = '\' and not Last_Killed)
then
Debug_Output (N);
Error_Msg_Node_1 := N;
Error_Msg (Msg, Sloc (N));
else
Last_Killed := True;
end if;
if not Is_Warning_Msg then
Set_Posted (N);
end if;
end Error_Msg_N;
------------------
-- Error_Msg_NE --
------------------
procedure Error_Msg_NE (Msg : String; N : Node_Id; E : Entity_Id) is
begin
if All_Errors_Mode
or else Msg (Msg'Last) = '!'
or else OK_Node (N)
or else (Msg (1) = '\' and not Last_Killed)
then
Debug_Output (N);
Error_Msg_Node_1 := E;
Error_Msg (Msg, Sloc (N));
else
Last_Killed := True;
end if;
if not Is_Warning_Msg then
Set_Posted (N);
end if;
end Error_Msg_NE;
--------------
-- Finalize --
--------------
procedure Finalize is
Cur : Error_Msg_Id;
Prv : Error_Msg_Id;
Nxt : Error_Msg_Id;
E, F : Error_Msg_Id;
Err_Flag : Boolean;
L : Logical_Line_Number;
Delete : Boolean;
begin
-- Reset current error source file if the main unit has a pragma
-- Source_Reference. This ensures outputting the proper name of
-- the source file in this situation.
if Line_Offset (Main_Source) /= 0 then
Current_Error_Source_File := No_Source_File;
end if;
-- Eliminate any duplicated error messages from the list. This is
-- done after the fact to avoid problems with Change_Error_Text.
Cur := Error_Msgs;
Prv := No_Error_Msg;
while Cur /= No_Error_Msg loop
Nxt := Errors.Table (Cur).Next;
-- Check for duplicate messages
Delete := False;
F := Nxt;
while F /= No_Error_Msg
and then Errors.Table (F).Sptr = Errors.Table (Cur).Sptr
loop
if Duplicate_Messages (Cur, F) then
Delete := True;
exit;
else
F := Errors.Table (F).Next;
end if;
end loop;
-- If deletion signalled, delete message and all its continuations
if Delete then
-- On entry to the loop, Cur points to a message to delete
loop
if Errors.Table (Cur).Warn then
Warnings_Detected := Warnings_Detected - 1;
else
Errors_Detected := Errors_Detected - 1;
end if;
Nxt := Errors.Table (Cur).Next;
if Prv = No_Error_Msg then
Error_Msgs := Nxt;
else
Errors.Table (Prv).Next := Nxt;
end if;
Cur := Nxt;
exit when Cur = No_Error_Msg
or else not Errors.Table (Cur).Msg_Cont;
end loop;
-- If no deletion, move Cur to next message
else
Prv := Cur;
Cur := Nxt;
end if;
end loop;
-- Brief Error mode
if Brief_Output or (not Full_List and not Verbose_Mode) then
E := Error_Msgs;
Set_Standard_Error;
while E /= No_Error_Msg loop
Write_Name (Reference_Name (Errors.Table (E).Sfile));
Write_Char (':');
Write_Int (Int (Errors.Table (E).Line));
Write_Char (':');
if Errors.Table (E).Col < 10 then
Write_Char ('0');
end if;
Write_Int (Int (Errors.Table (E).Col));
Write_Str (": ");
Output_Msg_Text (E);
Write_Eol;
E := Errors.Table (E).Next;
end loop;
Set_Standard_Output;
end if;
-- Full source listing case
if Full_List then
List_Pragmas_Index := 1;
List_Pragmas_Mode := True;
E := Error_Msgs;
Write_Eol;
-- First list initial main source file with its error messages
for N in 1 .. Num_Source_Lines (Main_Source) loop
L := Physical_To_Logical (N, Main_Source);
Err_Flag :=
E /= No_Error_Msg
and then Errors.Table (E).Line = L
and then Errors.Table (E).Sfile = Main_Source;
Output_Source_Line (L, Main_Source, Err_Flag);
if Err_Flag then
Output_Error_Msgs (E);
if not Debug_Flag_2 then
Write_Eol;
end if;
end if;
end loop;
-- Then output errors, if any, for subsidiary units
while E /= No_Error_Msg
and then Errors.Table (E).Sfile /= Main_Source
loop
Write_Eol;
Output_Source_Line
(Errors.Table (E).Line, Errors.Table (E).Sfile, True);
Output_Error_Msgs (E);
end loop;
end if;
-- Verbose mode (error lines only with error flags)
if Verbose_Mode and not Full_List then
E := Error_Msgs;
-- Loop through error lines
while E /= No_Error_Msg loop
Write_Eol;
Output_Source_Line
(Errors.Table (E).Line, Errors.Table (E).Sfile, True);
Output_Error_Msgs (E);
end loop;
end if;
-- Output error summary if verbose or full list mode
if Verbose_Mode or else Full_List then
-- Extra blank line if error messages or source listing were output
if Errors_Detected + Warnings_Detected > 0 or else Full_List then
Write_Eol;
end if;
-- Message giving total number of lines
Write_Str (" ");
Write_Int (Num_Source_Lines (Main_Source));
if Num_Source_Lines (Main_Source) = 1 then
Write_Str (" line: ");
else
Write_Str (" lines: ");
end if;
-- Message giving number of errors detected. This normally goes to
-- Standard_Output. The exception is when brief mode is not set,
-- verbose mode (or full list mode) is set, and there are errors.
-- In this case we send the message to standard error to make sure
-- that *something* appears on standard error in an error situation.
if Errors_Detected + Warnings_Detected /= 0
and then not Brief_Output
and then (Verbose_Mode or Full_List)
then
Set_Standard_Error;
end if;
if Errors_Detected = 0 then
Write_Str ("No errors");
elsif Errors_Detected = 1 then
Write_Str ("1 error");
else
Write_Int (Errors_Detected);
Write_Str (" errors");
end if;
if Warnings_Detected = 1 then
Write_Str (", 1 warning");
elsif Warnings_Detected > 1 then
Write_Str (", ");
Write_Int (Warnings_Detected);
Write_Str (" warnings");
end if;
Write_Eol;
Set_Standard_Output;
end if;
if Maximum_Errors /= 0
and then Errors_Detected + Warnings_Detected = Maximum_Errors
then
Set_Standard_Error;
Write_Str ("fatal error: maximum errors reached");
Write_Eol;
Set_Standard_Output;
end if;
end Finalize;
----------------
-- Get_Msg_Id --
----------------
function Get_Msg_Id return Error_Msg_Id is
begin
return Cur_Msg;
end Get_Msg_Id;
----------------
-- Initialize --
----------------
procedure Initialize is
begin
Errors.Init;
Error_Msgs := No_Error_Msg;
Errors_Detected := 0;
Warnings_Detected := 0;
Cur_Msg := No_Error_Msg;
Current_Error_Source_File := Main_Source;
List_Pragmas.Init;
-- Initialize warnings table, if all warnings are suppressed, supply
-- an initial dummy entry covering all possible source locations.
Warnings.Init;
if Warning_Mode = Suppress then
Warnings.Increment_Last;
Warnings.Table (Warnings.Last).Start := Source_Ptr'First;
Warnings.Table (Warnings.Last).Stop := Source_Ptr'Last;
end if;
end Initialize;
-------------
-- OK_Node --
-------------
function OK_Node (N : Node_Id) return Boolean is
K : constant Node_Kind := Nkind (N);
begin
if Error_Posted (N) then
return False;
elsif K in N_Has_Etype
and then Present (Etype (N))
and then Error_Posted (Etype (N))
then
return False;
elsif (K in N_Op
or else K = N_Attribute_Reference
or else K = N_Character_Literal
or else K = N_Expanded_Name
or else K = N_Identifier
or else K = N_Operator_Symbol)
and then Present (Entity (N))
and then Error_Posted (Entity (N))
then
return False;
else
return True;
end if;
end OK_Node;
-----------------------
-- Output_Error_Msgs --
-----------------------
procedure Output_Error_Msgs (E : in out Error_Msg_Id) is
P : Source_Ptr;
T : Error_Msg_Id;
Flag_Num : Pos;
Mult_Flags : Boolean := False;
begin
-- Figure out if we will place more than one error flag on this line
T := E;
while T /= No_Error_Msg
and then Errors.Table (T).Line = Errors.Table (E).Line
and then Errors.Table (T).Sfile = Errors.Table (E).Sfile
loop
if Errors.Table (T).Sptr > Errors.Table (E).Sptr then
Mult_Flags := True;
end if;
T := Errors.Table (T).Next;
end loop;
-- Output the error flags. The circuit here makes sure that the tab
-- characters in the original line are properly accounted for. The
-- eight blanks at the start are to match the line number.
if not Debug_Flag_2 then
Write_Str (" ");
P := Line_Start (Errors.Table (E).Sptr);
Flag_Num := 1;
-- Loop through error messages for this line to place flags
T := E;
while T /= No_Error_Msg
and then Errors.Table (T).Line = Errors.Table (E).Line
and then Errors.Table (T).Sfile = Errors.Table (E).Sfile
loop
-- Loop to output blanks till current flag position
while P < Errors.Table (T).Sptr loop
if Source_Text (Errors.Table (T).Sfile) (P) = Ascii.HT then
Write_Char (Ascii.HT);
else
Write_Char (' ');
end if;
P := P + 1;
end loop;
-- Output flag (unless already output, this happens if more
-- than one error message occurs at the same flag position).
if P = Errors.Table (T).Sptr then
if (Flag_Num = 1 and then not Mult_Flags)
or else Flag_Num > 9
then
Write_Char ('|');
else
Write_Char (Character'Val (Character'Pos ('0') + Flag_Num));
end if;
P := P + 1;
end if;
T := Errors.Table (T).Next;
Flag_Num := Flag_Num + 1;
end loop;
Write_Eol;
end if;
-- Now output the error messages
T := E;
while T /= No_Error_Msg
and then Errors.Table (T).Line = Errors.Table (E).Line
and then Errors.Table (T).Sfile = Errors.Table (E).Sfile
loop
Write_Str (" >>> ");
Output_Msg_Text (T);
if Debug_Flag_2 then
while Column < 74 loop
Write_Char (' ');
end loop;
Write_Str (" <<<");
end if;
Write_Eol;
T := Errors.Table (T).Next;
end loop;
E := T;
end Output_Error_Msgs;
------------------------
-- Output_Line_Number --
------------------------
procedure Output_Line_Number (L : Logical_Line_Number) is
D : Int; -- next digit
C : Character; -- next character
Z : Boolean; -- flag for zero suppress
N, M : Int; -- temporaries
begin
if L = 0 then
Write_Str (" ");
else
Z := False;
N := Int (L);
M := 100_000;
while M /= 0 loop
D := Int (N / M);
N := N rem M;
M := M / 10;
if D = 0 then
if Z then
C := '0';
else
C := ' ';
end if;
else
Z := True;
C := Character'Val (D + 48);
end if;
Write_Char (C);
end loop;
Write_Str (". ");
end if;
end Output_Line_Number;
---------------------
-- Output_Msg_Text --
---------------------
procedure Output_Msg_Text (E : Error_Msg_Id) is
begin
if Errors.Table (E).Warn then
Write_Str ("warning: ");
elsif Hostparm.Tag_Errors then
Write_Str ("error: ");
end if;
Write_Str (Errors.Table (E).Text.all);
end Output_Msg_Text;
------------------------
-- Output_Source_Line --
------------------------
procedure Output_Source_Line
(L : Logical_Line_Number;
Sfile : Source_File_Index;
Errs : Boolean)
is
S : Source_Ptr;
C : Character;
Line_Number_Output : Boolean := False;
-- Set True once line number is output
begin
if Sfile /= Current_Error_Source_File then
Write_Str ("==============Error messages for source file: ");
Write_Name (Full_File_Name (Sfile));
Write_Eol;
if Line_Offset (Sfile) /= 0 then
Write_Str ("--------------Line numbers from file: ");
Write_Name (Full_Ref_Name (Sfile));
Write_Str (" (starting at line ");
Write_Int (Line_Offset (Sfile) + 2);
Write_Char (')');
Write_Eol;
end if;
Current_Error_Source_File := Sfile;
end if;
if Errs or List_Pragmas_Mode then
Output_Line_Number (L);
Line_Number_Output := True;
end if;
S := Line_Start (L, Sfile);
loop
C := Source_Text (Sfile) (S);
exit when C = Ascii.LF or else C = Ascii.CR or else C = EOF;
-- Deal with matching entry in List_Pragmas table
if Full_List
and then List_Pragmas_Index <= List_Pragmas.Last
and then S = List_Pragmas.Table (List_Pragmas_Index).Ploc
then
case List_Pragmas.Table (List_Pragmas_Index).Ptyp is
when Page =>
Write_Char (C);
-- Ignore if on line with errors so that error flags
-- get properly listed with the error line .
if not Errs then
Write_Char (Ascii.FF);
end if;
when List_On =>
List_Pragmas_Mode := True;
if not Line_Number_Output then
Output_Line_Number (L);
Line_Number_Output := True;
end if;
Write_Char (C);
when List_Off =>
Write_Char (C);
List_Pragmas_Mode := False;
end case;
List_Pragmas_Index := List_Pragmas_Index + 1;
-- Normal case (no matching entry in List_Pragmas table)
else
if Errs or List_Pragmas_Mode then
Write_Char (C);
end if;
end if;
S := S + 1;
end loop;
if Line_Number_Output then
Write_Eol;
end if;
end Output_Source_Line;
-------------------
-- Set_Msg_Blank --
-------------------
procedure Set_Msg_Blank is
begin
if Msglen > 0
and then Msg_Buffer (Msglen) /= ' '
and then Msg_Buffer (Msglen) /= '('
and then not Manual_Quote_Mode
then
Set_Msg_Char (' ');
end if;
end Set_Msg_Blank;
-------------------------------
-- Set_Msg_Blank_Conditional --
-------------------------------
procedure Set_Msg_Blank_Conditional is
begin
if Msglen > 0
and then Msg_Buffer (Msglen) /= ' '
and then Msg_Buffer (Msglen) /= '('
and then Msg_Buffer (Msglen) /= '"'
and then not Manual_Quote_Mode
then
Set_Msg_Char (' ');
end if;
end Set_Msg_Blank_Conditional;
------------------
-- Set_Msg_Char --
------------------
procedure Set_Msg_Char (C : Character) is
begin
-- The check for message buffer overflow is needed to deal with cases
-- where insertions get too long (in particular a child unit name can
-- be very long).
if Msglen < Max_Msg_Length then
Msglen := Msglen + 1;
Msg_Buffer (Msglen) := C;
end if;
end Set_Msg_Char;
------------------------------
-- Set_Msg_Insertion_Column --
------------------------------
procedure Set_Msg_Insertion_Column is
begin
if RM_Column_Check then
Set_Msg_Str (" in column ");
Set_Msg_Int (Int (Error_Msg_Col) + 1);
end if;
end Set_Msg_Insertion_Column;
---------------------------------
-- Set_Msg_Insertion_File_Name --
---------------------------------
procedure Set_Msg_Insertion_File_Name is
begin
if Error_Msg_Name_1 = No_Name then
null;
elsif Error_Msg_Name_1 = Error_Name then
Set_Msg_Blank;
Set_Msg_Str ("<error>");
else
Set_Msg_Blank;
Get_Decoded_Name_String (Error_Msg_Name_1);
Set_Msg_Quote;
Set_Msg_Name_Buffer;
Set_Msg_Quote;
end if;
-- The following assignments ensure that the second and third percent
-- insertion characters will correspond to the Error_Msg_Name_2 and
-- Error_Msg_Name_3 as required.
Error_Msg_Name_1 := Error_Msg_Name_2;
Error_Msg_Name_2 := Error_Msg_Name_3;
end Set_Msg_Insertion_File_Name;
-----------------------------------
-- Set_Msg_Insertion_Line_Number --
-----------------------------------
procedure Set_Msg_Insertion_Line_Number (Loc, Flag : Source_Ptr) is
Sindex_Loc : Source_File_Index;
Sindex_Flag : Source_File_Index;
begin
Set_Msg_Blank;
if Loc = No_Location then
Set_Msg_Str ("at unknown location");
elsif Loc <= Standard_Location then
Set_Msg_Str ("in package Standard");
if Loc = Standard_Ascii_Location then
Set_Msg_Str (".Ascii");
end if;
else
-- Add "at file-name:" if reference is to other than the source
-- file in which the error message is placed. Note that we check
-- full file names, rather than just the source indexes, to
-- deal with generic instantiations from the current file.
Sindex_Loc := Get_Source_File_Index (Loc);
Sindex_Flag := Get_Source_File_Index (Flag);
if Full_File_Name (Sindex_Loc) /= Full_File_Name (Sindex_Flag) then
Set_Msg_Str ("at ");
Get_Decoded_Name_String
(Reference_Name (Get_Source_File_Index (Loc)));
Set_Msg_Name_Buffer;
Set_Msg_Char (':');
-- If in current file, add text "at line "
else
Set_Msg_Str ("at line ");
end if;
-- Output line number for reference
Set_Msg_Int (Int (Get_Line_Number (Loc)));
-- Deal with the instantiation case. We may have a reference to,
-- e.g. a type, that is declared within a generic template, and
-- what we are really referring to is the occurrence in an instance.
-- In this case, the line number of the instantiation is also of
-- interest, and we add a notation:
-- , instance at xxx
-- where xxx is a line number output using this same routine (and
-- the recursion can go further if the instantiation is itself in
-- a generic template).
-- The flag location passed to us in this situation is indeed the
-- line number within the template, but as described in Sinput.L
-- (file sinput-l.ads, section "Handling Generic Instantiations")
-- we can retrieve the location of the instantiation itself from
-- this flag location value.
-- Note: this processing is suppressed if Suppress_Instance_Location
-- is set True. This is used to prevent redundant annotations of the
-- location of the instantiation in the case where we are placing
-- the messages on the instantiation in any case.
if Instantiation (Sindex_Loc) /= No_Location
and then not Suppress_Instance_Location
then
Set_Msg_Str (", instance ");
Set_Msg_Insertion_Line_Number (Instantiation (Sindex_Loc), Flag);
end if;
end if;
end Set_Msg_Insertion_Line_Number;
----------------------------
-- Set_Msg_Insertion_Name --
----------------------------
procedure Set_Msg_Insertion_Name is
begin
if Error_Msg_Name_1 = No_Name then
null;
elsif Error_Msg_Name_1 = Error_Name then
Set_Msg_Blank;
Set_Msg_Str ("<error>");
else
Set_Msg_Blank_Conditional;
Get_Decoded_Name_String (Error_Msg_Name_1);
-- Remove %s or %b at end. These come from unit names. If the
-- caller wanted the (unit) or (body), then they would have used
-- the $ insertion character. Certainly no error message should
-- ever have %b or %s explicitly occurring.
if Name_Len > 2
and then Name_Buffer (Name_Len - 1) = '%'
then
Name_Len := Name_Len - 2;
end if;
-- Remove upper case letter at end, again, we should not be getting
-- such names, and what we hope is that the remainder makes sense.
if Name_Len > 1
and then Name_Buffer (Name_Len) in 'A' .. 'Z'
then
Name_Len := Name_Len - 1;
end if;
-- If operator name or character literal name, just print it as is
-- Also print as is if it ends in a right paren (case of x'val(nnn))
if Name_Buffer (1) = '"'
or else Name_Buffer (1) = '''
or else Name_Buffer (Name_Len) = ')'
then
Set_Msg_Name_Buffer;
-- Else output with surrounding quotes in proper casing mode
else
Set_Casing (Identifier_Casing (Flag_Source), Mixed_Case);
Set_Msg_Quote;
Set_Msg_Name_Buffer;
Set_Msg_Quote;
end if;
end if;
-- The following assignments ensure that the second and third percent
-- insertion characters will correspond to the Error_Msg_Name_2 and
-- Error_Msg_Name_3 as required.
Error_Msg_Name_1 := Error_Msg_Name_2;
Error_Msg_Name_2 := Error_Msg_Name_3;
end Set_Msg_Insertion_Name;
----------------------------
-- Set_Msg_Insertion_Node --
----------------------------
procedure Set_Msg_Insertion_Node is
begin
Suppress_Message :=
Error_Msg_Node_1 = Error
or else Error_Msg_Node_1 = Any_Type;
if Error_Msg_Node_1 = Empty then
Set_Msg_Blank_Conditional;
Set_Msg_Str ("<empty>");
elsif Error_Msg_Node_1 = Error then
Set_Msg_Blank;
Set_Msg_Str ("<error>");
elsif Error_Msg_Node_1 = Standard_Void_Type then
Set_Msg_Blank;
Set_Msg_Str ("procedure name");
else
Set_Msg_Blank_Conditional;
-- Skip quotes for operator case
if Nkind (Error_Msg_Node_1) in N_Op then
Set_Msg_Node (Error_Msg_Node_1);
else
Set_Msg_Quote;
Set_Qualification (Error_Msg_Qual_Level, Error_Msg_Node_1);
Set_Msg_Node (Error_Msg_Node_1);
Set_Msg_Quote;
end if;
end if;
-- The following assignment ensures that a second ampersand insertion
-- character will correspond to the Error_Msg_Node_2 parameter.
Error_Msg_Node_1 := Error_Msg_Node_2;
end Set_Msg_Insertion_Node;
-------------------------------------
-- Set_Msg_Insertion_Reserved_Name --
-------------------------------------
procedure Set_Msg_Insertion_Reserved_Name is
begin
Set_Msg_Blank_Conditional;
Get_Name_String (Error_Msg_Name_1);
Set_Msg_Quote;
Set_Casing (Keyword_Casing (Flag_Source), All_Lower_Case);
Set_Msg_Name_Buffer;
Set_Msg_Quote;
end Set_Msg_Insertion_Reserved_Name;
-------------------------------------
-- Set_Msg_Insertion_Reserved_Word --
-------------------------------------
procedure Set_Msg_Insertion_Reserved_Word
(Text : String;
J : in out Integer)
is
begin
Set_Msg_Blank_Conditional;
Name_Len := 0;
while J <= Text'Last and then Text (J) in 'A' .. 'Z' loop
Name_Len := Name_Len + 1;
Name_Buffer (Name_Len) := Text (J);
J := J + 1;
end loop;
Set_Casing (Keyword_Casing (Flag_Source), All_Lower_Case);
Set_Msg_Quote;
Set_Msg_Name_Buffer;
Set_Msg_Quote;
end Set_Msg_Insertion_Reserved_Word;
--------------------------------------
-- Set_Msg_Insertion_Type_Reference --
--------------------------------------
procedure Set_Msg_Insertion_Type_Reference (Flag : Source_Ptr) is
begin
Set_Msg_Blank;
if Error_Msg_Node_1 = Standard_Void_Type then
Set_Msg_Str ("package or procedure name");
return;
elsif Error_Msg_Node_1 = Standard_Exception_Type then
Set_Msg_Str ("exception name");
return;
elsif Error_Msg_Node_1 = Any_Access
or else Error_Msg_Node_1 = Any_Array
or else Error_Msg_Node_1 = Any_Boolean
or else Error_Msg_Node_1 = Any_Character
or else Error_Msg_Node_1 = Any_Composite
or else Error_Msg_Node_1 = Any_Discrete
or else Error_Msg_Node_1 = Any_Fixed
or else Error_Msg_Node_1 = Any_Integer
or else Error_Msg_Node_1 = Any_Modular
or else Error_Msg_Node_1 = Any_Numeric
or else Error_Msg_Node_1 = Any_Real
or else Error_Msg_Node_1 = Any_Scalar
or else Error_Msg_Node_1 = Any_String
then
Get_Decoded_Name_String (Chars (Error_Msg_Node_1));
Set_Msg_Name_Buffer;
return;
elsif Error_Msg_Node_1 = Universal_Real then
Set_Msg_Str ("type universal real");
return;
elsif Error_Msg_Node_1 = Universal_Integer then
Set_Msg_Str ("type universal integer");
return;
elsif Error_Msg_Node_1 = Universal_Fixed then
Set_Msg_Str ("type universal fixed");
return;
end if;
-- Special case of anonymous array
if Nkind (Error_Msg_Node_1) in N_Entity
and then Is_Array_Type (Error_Msg_Node_1)
and then Present (Related_Array_Object (Error_Msg_Node_1))
then
Set_Msg_Str ("type of ");
Set_Msg_Node (Related_Array_Object (Error_Msg_Node_1));
Set_Msg_Str (" declared");
Set_Msg_Insertion_Line_Number
(Sloc (Related_Array_Object (Error_Msg_Node_1)), Flag);
return;
end if;
-- If we fall through, it is not a special case, so first output
-- the name of the type, preceded by private for a private type
if Is_Private_Type (Error_Msg_Node_1) then
Set_Msg_Str ("private type ");
else
Set_Msg_Str ("type ");
end if;
-- Types in Standard are displayed as "Standard.name"
if Sloc (Error_Msg_Node_1) <= Standard_Location then
Set_Msg_Quote;
Set_Msg_Str ("Standard.");
Set_Msg_Node (Error_Msg_Node_1);
Set_Msg_Quote;
else
declare
Loc : constant Source_Ptr := Sloc (Error_Msg_Node_1);
Unit_Num : constant Unit_Number_Type := Get_Sloc_Unit_Number (Loc);
begin
-- Types in other language defined units are displayed as
-- "package-name.type-name"
if Is_Predefined_File_Name (Unit_File_Name (Unit_Num)) then
Get_Decoded_Name_String (Unit_Name (Unit_Num));
Name_Len := Name_Len - 2;
Set_Msg_Quote;
Set_Casing (Mixed_Case);
Set_Msg_Name_Buffer;
Set_Msg_Char ('.');
Set_Casing (Mixed_Case);
Set_Msg_Node (Error_Msg_Node_1);
Set_Msg_Quote;
-- If the type is the result of an instantiation, then
-- add the instantiation location
declare
Iloc : constant Source_Ptr := Instantiation_Location (Loc);
begin
if Iloc /= No_Location
and then not Suppress_Instance_Location
then
Set_Msg_Str (" from instance");
Set_Msg_Insertion_Line_Number (Iloc, Flag);
end if;
end;
-- All other types display as "type name" defined at line xxx
-- possibly qualified if qualification is requested.
else
Set_Msg_Quote;
Set_Qualification (Error_Msg_Qual_Level, Error_Msg_Node_1);
Set_Msg_Node (Error_Msg_Node_1);
Set_Msg_Quote;
Set_Msg_Str (" defined");
Set_Msg_Insertion_Line_Number (Loc, Flag);
end if;
end;
end if;
end Set_Msg_Insertion_Type_Reference;
----------------------------
-- Set_Msg_Insertion_Uint --
----------------------------
procedure Set_Msg_Insertion_Uint is
begin
Set_Msg_Blank;
UI_Image (Error_Msg_Uint_1);
for J in 1 .. UI_Image_Length loop
Set_Msg_Char (UI_Image_Buffer (J));
end loop;
-- The following assignment ensures that a second carret insertion
-- character will correspond to the Error_Msg_Uint_2 parameter.
Error_Msg_Uint_1 := Error_Msg_Uint_2;
end Set_Msg_Insertion_Uint;
---------------------------------
-- Set_Msg_Insertion_Unit_Name --
---------------------------------
procedure Set_Msg_Insertion_Unit_Name is
begin
if Error_Msg_Unit_1 = No_Name then
null;
elsif Error_Msg_Unit_1 = Error_Name then
Set_Msg_Blank;
Set_Msg_Str ("<error>");
else
Get_Unit_Name_String (Error_Msg_Unit_1);
Set_Msg_Blank;
Set_Msg_Quote;
Set_Msg_Name_Buffer;
Set_Msg_Quote;
end if;
-- The following assignment ensures that a second percent insertion
-- character will correspond to the Error_Msg_Unit_2 parameter.
Error_Msg_Unit_1 := Error_Msg_Unit_2;
end Set_Msg_Insertion_Unit_Name;
-----------------
-- Set_Msg_Int --
-----------------
procedure Set_Msg_Int (Line : Int) is
begin
if Line > 9 then
Set_Msg_Int (Line / 10);
end if;
Set_Msg_Char (Character'Val (Character'Pos ('0') + (Line rem 10)));
end Set_Msg_Int;
-------------------------
-- Set_Msg_Name_Buffer --
-------------------------
procedure Set_Msg_Name_Buffer is
begin
for J in 1 .. Name_Len loop
Set_Msg_Char (Name_Buffer (J));
end loop;
end Set_Msg_Name_Buffer;
------------------
-- Set_Msg_Node --
------------------
procedure Set_Msg_Node (Node : Node_Id) is
Ent : Entity_Id;
Old_Ent : Entity_Id;
Mchar : Character;
Derived : Boolean := False;
Class_Flag : Boolean := False;
Nam : Name_Id;
procedure Kill_Type;
-- If message buffer ends with " type ", then remove the last five
-- characters. This is used to avoid a duplication of "type" in the
-- text of the message with "type" generated by the special tests
-- below (e.g. we don't want "expected type type derived from ..")
procedure Kill_Type is
begin
if Msglen > 4
and then Msg_Buffer (Msglen - 4 .. Msglen) = "type "
and then (Msglen = 5 or else Msg_Buffer (Msglen - 5) = ' ')
then
Msglen := Msglen - 5;
end if;
end Kill_Type;
-- Start of processing for Set_Msg_Node
begin
if Nkind (Node) = N_Designator then
Set_Msg_Node (Name (Node));
Set_Msg_Char ('.');
Set_Msg_Node (Identifier (Node));
return;
elsif Nkind (Node) = N_Defining_Program_Unit_Name then
Set_Msg_Node (Name (Node));
Set_Msg_Char ('.');
Set_Msg_Node (Defining_Identifier (Node));
return;
elsif Nkind (Node) = N_Selected_Component then
Set_Msg_Node (Prefix (Node));
Set_Msg_Char ('.');
Set_Msg_Node (Selector_Name (Node));
return;
end if;
-- The only remaining possibilities are identifiers, defining
-- identifiers, pragmas, and pragma argument associations, i.e.
-- nodes that have a Chars field.
-- Internal names generally represent something gone wrong. An exception
-- is the case of internal type names, where we try to find a reasonable
-- external representation for the external name
if Is_Internal_Name (Chars (Node))
and then
((Is_Entity_Name (Node)
and then Present (Entity (Node))
and then Is_Type (Entity (Node)))
or else
(Nkind (Node) = N_Defining_Identifier and then Is_Type (Node)))
then
if Nkind (Node) = N_Identifier then
Ent := Entity (Node);
else
Ent := Node;
end if;
-- Undo placement of a quote, since we will put it back later
Mchar := Msg_Buffer (Msglen);
if Mchar = '"' then
Msglen := Msglen - 1;
end if;
-- The loop here deals with recursive types, we are trying to
-- find a related entity that is not an implicit type. Note
-- that the check with Old_Ent stops us from getting "stuck".
-- Also, we don't output the "type derived from" message more
-- than once in the case where we climb up multiple levels.
loop
Old_Ent := Ent;
-- Implicit access type, use directly designated type
if Is_Access_Type (Ent) then
Set_Msg_Str ("access to ");
Ent := Directly_Designated_Type (Ent);
-- Classwide type
elsif Is_Class_Wide_Type (Ent) then
Class_Flag := True;
Ent := Root_Type (Ent);
-- Use base type if this is a subtype
elsif Ent /= Base_Type (Ent) then
Kill_Type;
Set_Msg_Str ("subtype of ");
Ent := Base_Type (Ent);
-- If this is a base type with a first named subtype, use the
-- first named subtype instead. This is not quite accurate in
-- all cases, but it makes too much noise to be accurate and
-- add 'Base in all cases. Note that we only do this is the
-- first named subtype is not itself an internal name. This
-- avoids the obvious loop (subtype->basetype->subtype) which
-- would otherwise occur!)
elsif Present (Freeze_Node (Ent))
and then Present (First_Subtype_Link (Freeze_Node (Ent)))
and then
not Is_Internal_Name
(Chars (First_Subtype_Link (Freeze_Node (Ent))))
then
Ent := First_Subtype_Link (Freeze_Node (Ent));
-- Otherwise use root type
else
if not Derived then
Kill_Type;
Set_Msg_Str ("type derived from ");
Derived := True;
end if;
Ent := Etype (Ent);
end if;
-- If we are stuck in a loop, get out and settle for the
-- internal name after all.
exit when Ent = Old_Ent;
-- Get out if we finally found a non-internal name to use
exit when not Is_Internal_Name (Chars (Ent));
end loop;
if Mchar = '"' then
Set_Msg_Char ('"');
end if;
Nam := Chars (Ent);
else
Nam := Chars (Node);
end if;
-- If we still have an internal name, then set to kill the message
-- if it is not the first message (we really try hard not to show
-- the dirty laundry of the implementation to the compiler user!)
if Is_Internal_Name (Nam) then
Kill_Message := True;
end if;
-- At this stage, the name to output is in Nam
Get_Decoded_Name_String (Nam);
-- Remove trailing upper case letters from the name (useful for
-- dealing with some cases of internal names.
while Name_Len > 1 and then Name_Buffer (Name_Len) in 'A' .. 'Z' loop
Name_Len := Name_Len - 1;
end loop;
-- If we have any of the names from standard that start with the
-- characters "any " (e.g. Any_Type), then kill the message since
-- almost certainly it is a junk cascaded message.
if Name_Len > 4
and then Name_Buffer (1 .. 4) = "any "
then
Kill_Message := True;
end if;
-- Now we have to set the proper case. If we have a source location
-- then do a check to see if the name in the source is the same name
-- as the name in the Names table, except for possible differences
-- in case, which is the case when we can copy from the source.
declare
Src_Loc : constant Source_Ptr := Sloc (Error_Msg_Node_1);
Sbuffer : Source_Buffer_Ptr;
Ref_Ptr : Integer;
Src_Ptr : Source_Ptr;
begin
Ref_Ptr := 1;
Src_Ptr := Src_Loc;
-- Determine if the reference we are dealing with corresponds
-- to text at the point of the error reference. This will often
-- be the case for simple identifier references, and is the case
-- where we can copy the spelling from the source.
if Src_Loc /= No_Location
and then Src_Loc > Standard_Location
then
Sbuffer := Source_Text (Get_Source_File_Index (Src_Loc));
while Ref_Ptr <= Name_Len loop
exit when
Fold_Lower (Sbuffer (Src_Ptr)) /=
Fold_Lower (Name_Buffer (Ref_Ptr));
Ref_Ptr := Ref_Ptr + 1;
Src_Ptr := Src_Ptr + 1;
end loop;
end if;
-- If we get through the loop without a mismatch, then output
-- the name the way it is spelled in the source program
if Ref_Ptr > Name_Len then
Src_Ptr := Src_Loc;
for J in 1 .. Name_Len loop
Name_Buffer (J) := Sbuffer (Src_Ptr);
Src_Ptr := Src_Ptr + 1;
end loop;
-- Otherwise set the casing using the default identifier casing
else
Set_Casing (Identifier_Casing (Flag_Source), Mixed_Case);
end if;
end;
Set_Msg_Name_Buffer;
-- Add 'Class if class wide type
if Class_Flag then
Set_Msg_Char (''');
Get_Name_String (Name_Class);
Set_Casing (Identifier_Casing (Flag_Source), Mixed_Case);
Set_Msg_Name_Buffer;
end if;
end Set_Msg_Node;
-------------------
-- Set_Msg_Quote --
-------------------
procedure Set_Msg_Quote is
begin
if not Manual_Quote_Mode then
Set_Msg_Char ('"');
end if;
end Set_Msg_Quote;
-----------------
-- Set_Msg_Str --
-----------------
procedure Set_Msg_Str (Text : String) is
begin
for J in Text'Range loop
Set_Msg_Char (Text (J));
end loop;
end Set_Msg_Str;
------------------
-- Set_Msg_Text --
------------------
procedure Set_Msg_Text (Text : String; Flag : Source_Ptr) is
C : Character; -- Current character
P : Natural; -- Current index;
begin
Manual_Quote_Mode := False;
Is_Warning_Msg := False;
Is_Unconditional_Msg := False;
Msglen := 0;
Flag_Source := Get_Source_File_Index (Flag);
P := Text'First;
while P <= Text'Last loop
C := Text (P);
P := P + 1;
-- Check for insertion character
if C = '%' then
Set_Msg_Insertion_Name;
elsif C = '$' then
Set_Msg_Insertion_Unit_Name;
elsif C = '{' then
Set_Msg_Insertion_File_Name;
elsif C = '}' then
Set_Msg_Insertion_Type_Reference (Flag);
elsif C = '*' then
Set_Msg_Insertion_Reserved_Name;
elsif C = '&' then
Set_Msg_Insertion_Node;
elsif C = '#' then
Set_Msg_Insertion_Line_Number (Error_Msg_Sloc, Flag);
elsif C = '\' then
Continuation := True;
elsif C = '@' then
Set_Msg_Insertion_Column;
elsif C = '^' then
Set_Msg_Insertion_Uint;
elsif C = '`' then
Manual_Quote_Mode := not Manual_Quote_Mode;
Set_Msg_Char ('"');
elsif C = '!' then
Is_Unconditional_Msg := True;
elsif C = '?' then
Is_Warning_Msg := True;
elsif C = ''' then
Set_Msg_Char (Text (P));
P := P + 1;
-- Upper case letter (start of reserved word if 2 or more)
elsif C in 'A' .. 'Z'
and then P <= Text'Last
and then Text (P) in 'A' .. 'Z'
then
P := P - 1;
Set_Msg_Insertion_Reserved_Word (Text, P);
-- Normal character with no special treatment
else
Set_Msg_Char (C);
end if;
end loop;
end Set_Msg_Text;
----------------
-- Set_Posted --
----------------
procedure Set_Posted (N : Node_Id) is
P : Node_Id;
begin
-- We always set Error_Posted on the node itself
Set_Error_Posted (N);
-- If it is a subexpression, then set Error_Posted on parents
-- up to and including the first non-subexpression construct. This
-- helps avoid cascaded error messages within a single expression.
P := N;
loop
P := Parent (P);
Set_Error_Posted (P);
exit when Nkind (P) not in N_Subexpr;
end loop;
end Set_Posted;
-----------------------
-- Set_Qualification --
-----------------------
procedure Set_Qualification (N : Nat; E : Entity_Id) is
begin
if N /= 0 and then Scope (E) /= Standard_Standard then
Set_Qualification (N - 1, Scope (E));
Set_Msg_Node (Scope (E));
Set_Msg_Char ('.');
end if;
end Set_Qualification;
---------------------------
-- Set_Warnings_Mode_Off --
---------------------------
procedure Set_Warnings_Mode_Off (Loc : Source_Ptr) is
begin
-- Don't bother with entries from instantiation copies, since we
-- will already have a copy in the template, which is what matters
if Instantiation (Get_Source_File_Index (Loc)) /= No_Location then
return;
end if;
-- If last entry in table already covers us, this is a redundant
-- pragma Warnings (Off) and can be ignored. This also handles the
-- case where all warnings are suppressed by command line switch.
if Warnings.Last >= Warnings.First
and then Warnings.Table (Warnings.Last).Start <= Loc
and then Loc <= Warnings.Table (Warnings.Last).Stop
then
return;
-- Otherwise establish a new entry, extending from the location of
-- the pragma to the end of the current source file. This ending
-- point will be adjusted by a subsequent pragma Warnings (On).
else
Warnings.Increment_Last;
Warnings.Table (Warnings.Last).Start := Loc;
Warnings.Table (Warnings.Last).Stop :=
Source_Last (Current_Source_File);
end if;
end Set_Warnings_Mode_Off;
--------------------------
-- Set_Warnings_Mode_On --
--------------------------
procedure Set_Warnings_Mode_On (Loc : Source_Ptr) is
begin
-- Don't bother with entries from instantiation copies, since we
-- will already have a copy in the template, which is what matters
if Instantiation (Get_Source_File_Index (Loc)) /= No_Location then
return;
end if;
-- Nothing to do unless command line switch to suppress all warnings
-- is off, and the last entry in the warnings table covers this
-- pragma Warnings (On), in which case adjust the end point.
if (Warnings.Last >= Warnings.First
and then Warnings.Table (Warnings.Last).Start <= Loc
and then Loc <= Warnings.Table (Warnings.Last).Stop)
and then Warning_Mode /= Suppress
then
Warnings.Table (Warnings.Last).Stop := Loc;
end if;
end Set_Warnings_Mode_On;
end Errout;
|