1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- E R R O U T --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2024, 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 3, 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 COPYING3. If not, go to --
-- http://www.gnu.org/licenses for a complete copy of the license. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- 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 Einfo.Entities; use Einfo.Entities;
with Einfo.Utils; use Einfo.Utils;
with Erroutc; use Erroutc;
with Gnatvsn; use Gnatvsn;
with Lib; use Lib;
with Opt; use Opt;
with Nlists; use Nlists;
with Output; use Output;
with Scans; use Scans;
with Sem_Aux; use Sem_Aux;
with Sinput; use Sinput;
with Sinfo; use Sinfo;
with Sinfo.Nodes; use Sinfo.Nodes;
with Sinfo.Utils; use Sinfo.Utils;
with Snames; use Snames;
with Stand; use Stand;
with Stringt; use Stringt;
with Stylesw; use Stylesw;
with System.OS_Lib;
with Uname; use Uname;
with Warnsw;
package body Errout is
Errors_Must_Be_Ignored : Boolean := False;
-- Set to True by procedure Set_Ignore_Errors (True), when calls to error
-- message procedures should be ignored (when parsing irrelevant text in
-- sources being preprocessed).
Finalize_Called : Boolean := False;
-- Set True if the Finalize routine has been called
Warn_On_Instance : Boolean;
-- Flag set true for warning message to be posted on instance
------------------------------------
-- Table of Non-Instance Messages --
------------------------------------
-- This table contains an entry for every error message processed by the
-- Error_Msg routine that is not posted on generic (or inlined) instance.
-- As explained in further detail in the Error_Msg procedure body, this
-- table is used to avoid posting redundant messages on instances.
type NIM_Record is record
Msg : String_Ptr;
Loc : Source_Ptr;
end record;
-- Type used to store text and location of one message
package Non_Instance_Msgs is new Table.Table (
Table_Component_Type => NIM_Record,
Table_Index_Type => Int,
Table_Low_Bound => 1,
Table_Initial => 100,
Table_Increment => 100,
Table_Name => "Non_Instance_Msgs");
-----------------------
-- Local Subprograms --
-----------------------
procedure Error_Msg_Internal
(Msg : String;
Span : Source_Span;
Opan : Source_Span;
Msg_Cont : Boolean;
Node : Node_Id);
-- This is the low-level routine used to post messages after dealing with
-- the issue of messages placed on instantiations (which get broken up
-- into separate calls in Error_Msg). Span is the location on which the
-- flag will be placed in the output. In the case where the flag is on
-- the template, this points directly to the template, not to one of the
-- instantiation copies of the template. Opan is the original location
-- used to flag the error, and this may indeed point to an instantiation
-- copy. So typically we can see Opan pointing to the template location
-- in an instantiation copy when Span points to the source location of
-- the actual instantiation (i.e the line with the new). Msg_Cont is
-- set true if this is a continuation message. Node is the relevant
-- Node_Id for this message, to be used to compute the enclosing entity if
-- Opt.Include_Subprogram_In_Messages is set.
function No_Warnings (N : Node_Or_Entity_Id) return Boolean;
-- Determines if warnings should be suppressed for the given node
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_JSON_Message (Error_Id : Error_Msg_Id);
-- Output error message Error_Id and any subsequent continuation message
-- using a JSON format similar to the one GCC uses when passed
-- -fdiagnostics-format=json.
procedure Output_Source_Line
(L : Physical_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).
function Paren_Required (N : Node_Id) return Boolean;
-- Subsidiary to First_Sloc and Last_Sloc. Returns True iff parentheses
-- around node N are required by the Ada syntax, e.g. when N is an
-- expression of a qualified expression.
procedure Set_Msg_Insertion_Column;
-- Handle column number insertion (@ insertion character)
procedure Set_Msg_Insertion_Node;
-- Handle node (name from node) insertion (& insertion character)
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_Unit_Name (Suffix : Boolean := True);
-- Handle unit name insertion ($ insertion character). Depending on Boolean
-- parameter Suffix, (spec) or (body) is appended after the unit name.
procedure Set_Msg_Node (Node : Node_Id);
-- Add the sequence of characters for the name associated with the given
-- node to the current message. For N_Designator, N_Selected_Component,
-- N_Defining_Program_Unit_Name, and N_Expanded_Name, the Prefix is
-- included as well.
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 are set on return Msglen.
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. If that parent is a named
-- association, the flag is further propagated to its parent. This is done
-- in order to guard against cascaded errors. Note that this call has an
-- effect for a serious error only.
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.
function Should_Ignore_Pragma_SPARK_Mode return Boolean;
-- Return whether pragma Ignore_Pragma (SPARK_Mode) was specified. This is
-- similar to Sem_Util.Should_Ignore_Pragma_Par but located here to avoid
-- problematic dependency on Sem_Util.
function Special_Msg_Delete
(Msg : String;
N : Node_Or_Entity_Id;
E : Node_Or_Entity_Id) return Boolean;
-- This function is called from Error_Msg_NEL, passing the message Msg,
-- node N on which the error is to be posted, and the entity or node E
-- to be used for an & insertion in the message if any. The job of this
-- procedure is to test for certain cascaded messages that we would like
-- to suppress. If the message is to be suppressed then we return True.
-- If the message should be generated (the normal case) False is returned.
procedure Unwind_Internal_Type (Ent : in out Entity_Id);
-- This procedure is given an entity id for an internal type, i.e. a type
-- with an internal name. It unwinds the type to try to get to something
-- reasonably printable, generating prefixes like "subtype of", "access
-- to", etc along the way in the buffer. The value in Ent on return is the
-- final name to be printed. Hopefully this is not an internal name, but in
-- some internal name cases, it is an internal name, and has to be printed
-- anyway (although in this case the message has been killed if possible).
-- The global variable Class_Flag is set to True if the resulting entity
-- should have 'Class appended to its name (see Add_Class procedure), and
-- is otherwise unchanged.
function Warn_Insertion return String;
-- This is called for warning messages only (so Warning_Msg_Char is set)
-- and returns a corresponding string to use at the beginning of generated
-- auxiliary messages, such as "in instantiation at ...".
-- "?" returns "??"
-- " " returns "?"
-- other trimmed, prefixed and suffixed with "?".
-----------------------
-- 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.Ptr);
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 Debug_Flag_OO 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;
------------------------
-- Compilation_Errors --
------------------------
function Compilation_Errors return Boolean is
begin
if not Finalize_Called then
raise Program_Error;
else
return Erroutc.Compilation_Errors;
end if;
end Compilation_Errors;
--------------------------------------
-- Delete_Warning_And_Continuations --
--------------------------------------
procedure Delete_Warning_And_Continuations (Msg : Error_Msg_Id) is
Id : Error_Msg_Id;
begin
pragma Assert (not Errors.Table (Msg).Msg_Cont);
Id := Msg;
loop
declare
M : Error_Msg_Object renames Errors.Table (Id);
begin
if not M.Deleted then
M.Deleted := True;
Warnings_Detected := Warnings_Detected - 1;
if M.Info then
Warning_Info_Messages := Warning_Info_Messages - 1;
end if;
if M.Warn_Err then
Warnings_Treated_As_Errors := Warnings_Treated_As_Errors - 1;
end if;
end if;
Id := M.Next;
exit when Id = No_Error_Msg;
exit when not Errors.Table (Id).Msg_Cont;
end;
end loop;
end Delete_Warning_And_Continuations;
---------------
-- Error_Msg --
---------------
-- Error_Msg posts a flag at the given location, except that if the
-- Flag_Location/Flag_Span 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
begin
Error_Msg (Msg, To_Span (Flag_Location), Current_Node);
end Error_Msg;
procedure Error_Msg (Msg : String; Flag_Span : Source_Span) is
begin
Error_Msg (Msg, Flag_Span, Current_Node);
end Error_Msg;
procedure Error_Msg
(Msg : String;
Flag_Location : Source_Ptr;
Is_Compile_Time_Pragma : Boolean)
is
Save_Is_Compile_Time_Msg : constant Boolean := Is_Compile_Time_Msg;
begin
Is_Compile_Time_Msg := Is_Compile_Time_Pragma;
Error_Msg (Msg, To_Span (Flag_Location), Current_Node);
Is_Compile_Time_Msg := Save_Is_Compile_Time_Msg;
end Error_Msg;
procedure Error_Msg
(Msg : String;
Flag_Location : Source_Ptr;
N : Node_Id)
is
begin
Error_Msg (Msg, To_Span (Flag_Location), N);
end Error_Msg;
procedure Error_Msg
(Msg : String;
Flag_Span : Source_Span;
N : Node_Id)
is
Flag_Location : constant Source_Ptr := Flag_Span.Ptr;
Sindex : Source_File_Index;
-- Source index for flag location
Orig_Loc : Source_Ptr;
-- Original location of Flag_Location (i.e. location in original
-- template in instantiation case, otherwise unchanged).
begin
-- Return if all errors are to be ignored
if Get_Ignore_Errors then
return;
end if;
-- If we already have messages, and we are trying to place a message at
-- No_Location, then just ignore the attempt since we assume that what
-- is happening is some cascaded junk. Note that this is safe in the
-- sense that proceeding will surely bomb. We will also bomb if the flag
-- location is No_Location and we don't have any messages so far, but
-- that is a real bug and a legitimate bomb, so we go ahead.
if Flag_Location = No_Location
and then Total_Errors_Detected > 0
then
return;
end if;
-- Start of processing for new message
Sindex := Get_Source_File_Index (Flag_Location);
Prescan_Message (Msg);
Orig_Loc := Original_Location (Flag_Location);
-- If the current location is in an instantiation, the issue arises of
-- whether to post the message on the template or the instantiation.
-- The way we decide is to see if we have posted the same message on
-- the template when we compiled the template (the template is always
-- compiled before any instantiations). For this purpose, we use a
-- separate table of messages. The reason we do this is twofold:
-- First, the messages can get changed by various processing
-- including the insertion of tokens etc, making it hard to
-- do the comparison.
-- Second, we will suppress a warning on a template if it is not in
-- the current extended source unit. That's reasonable and means we
-- don't want the warning on the instantiation here either, but it
-- does mean that the main error table would not in any case include
-- the message.
if Flag_Location = Orig_Loc then
Non_Instance_Msgs.Append ((new String'(Msg), Flag_Location));
Warn_On_Instance := False;
-- Here we have an instance message
else
-- Delete if debug flag off, and this message duplicates a message
-- already posted on the corresponding template
if not Debug_Flag_GG then
for J in Non_Instance_Msgs.First .. Non_Instance_Msgs.Last loop
if Msg = Non_Instance_Msgs.Table (J).Msg.all
and then Non_Instance_Msgs.Table (J).Loc = Orig_Loc
then
return;
end if;
end loop;
end if;
-- No duplicate, so error/warning will be posted on instance
Warn_On_Instance := Is_Warning_Msg;
end if;
-- Ignore warning message that is suppressed for this location. Note
-- that style checks are not considered warning messages for this
-- purpose.
if Is_Warning_Msg and then Warnings_Suppressed (Orig_Loc) /= No_String
then
return;
-- For style messages, check too many messages so far
elsif Is_Style_Msg
and then Maximum_Messages /= 0
and then Warnings_Detected >= Maximum_Messages
then
return;
-- Suppress warnings inside a loop that is known to be null or is
-- probably null (i.e. when loop executes only if invalid values
-- present). In either case warnings in the loop are likely to be junk.
elsif Is_Warning_Msg and then Present (N) then
declare
P : Node_Id;
begin
P := Parent (N);
while Present (P) loop
if Nkind (P) = N_Loop_Statement
and then Suppress_Loop_Warnings (P)
then
return;
end if;
P := Parent (P);
end loop;
end;
end if;
-- The idea at this stage is that we have two kinds of messages
-- First, we have those messages 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_Span, Flag_Span, False, N);
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
-- or
-- info: in instantiation at ...
-- info: original info 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.
-- Note: the instantiation mechanism is also shared for inlining of
-- subprogram bodies when front end inlining is done. In this case the
-- messages have the form:
-- in inlined body at ...
-- original error message
-- or
-- warning: in inlined body at ...
-- warning: original warning message
-- or
-- info: in inlined body at ...
-- info: original info message
-- OK, here we have an instantiation error, and we need to generate the
-- error on the instantiation, rather than on the template.
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
-- Loop to find highest level instantiation, where all error
-- messages will be placed.
X := Sindex;
loop
Actual_Error_Loc := Instantiation (X);
X := Get_Source_File_Index (Actual_Error_Loc);
exit when Instantiation (X) = No_Location;
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 (Msg'First) /= '\' then
-- Case of inlined body
if Inlined_Body (X) then
if Is_Info_Msg then
Error_Msg_Internal
(Msg => "info: in inlined body #",
Span => To_Span (Actual_Error_Loc),
Opan => Flag_Span,
Msg_Cont => Msg_Cont_Status,
Node => N);
elsif Is_Warning_Msg then
Error_Msg_Internal
(Msg => Warn_Insertion & "in inlined body #",
Span => To_Span (Actual_Error_Loc),
Opan => Flag_Span,
Msg_Cont => Msg_Cont_Status,
Node => N);
elsif Is_Style_Msg then
Error_Msg_Internal
(Msg => "style: in inlined body #",
Span => To_Span (Actual_Error_Loc),
Opan => Flag_Span,
Msg_Cont => Msg_Cont_Status,
Node => N);
else
Error_Msg_Internal
(Msg => "error in inlined body #",
Span => To_Span (Actual_Error_Loc),
Opan => Flag_Span,
Msg_Cont => Msg_Cont_Status,
Node => N);
end if;
-- Case of generic instantiation
else
if Is_Info_Msg then
Error_Msg_Internal
(Msg => "info: in instantiation #",
Span => To_Span (Actual_Error_Loc),
Opan => Flag_Span,
Msg_Cont => Msg_Cont_Status,
Node => N);
elsif Is_Warning_Msg then
Error_Msg_Internal
(Msg => Warn_Insertion & "in instantiation #",
Span => To_Span (Actual_Error_Loc),
Opan => Flag_Span,
Msg_Cont => Msg_Cont_Status,
Node => N);
elsif Is_Style_Msg then
Error_Msg_Internal
(Msg => "style: in instantiation #",
Span => To_Span (Actual_Error_Loc),
Opan => Flag_Span,
Msg_Cont => Msg_Cont_Status,
Node => N);
else
Error_Msg_Internal
(Msg => "instantiation error #",
Span => To_Span (Actual_Error_Loc),
Opan => Flag_Span,
Msg_Cont => Msg_Cont_Status,
Node => N);
end if;
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 => Msg,
Span => To_Span (Actual_Error_Loc),
Opan => Flag_Span,
Msg_Cont => Msg_Cont_Status,
Node => N);
end;
end Error_Msg;
----------------------------------
-- Error_Msg_Ada_2005_Extension --
----------------------------------
procedure Error_Msg_Ada_2005_Extension (Extension : String) is
Loc : constant Source_Ptr := Token_Ptr;
begin
if Ada_Version < Ada_2005 then
Error_Msg (Extension & " is an Ada 2005 extension", Loc);
if No (Ada_Version_Pragma) then
Error_Msg ("\unit must be compiled with -gnat05 switch", Loc);
else
Error_Msg_Sloc := Sloc (Ada_Version_Pragma);
Error_Msg ("\incompatible with Ada version set#", Loc);
end if;
end if;
end Error_Msg_Ada_2005_Extension;
--------------------------------
-- Error_Msg_Ada_2012_Feature --
--------------------------------
procedure Error_Msg_Ada_2012_Feature (Feature : String; Loc : Source_Ptr) is
begin
if Ada_Version < Ada_2012 then
Error_Msg (Feature & " is an Ada 2012 feature", Loc);
if No (Ada_Version_Pragma) then
Error_Msg ("\unit must be compiled with -gnat2012 switch", Loc);
else
Error_Msg_Sloc := Sloc (Ada_Version_Pragma);
Error_Msg ("\incompatible with Ada version set#", Loc);
end if;
end if;
end Error_Msg_Ada_2012_Feature;
--------------------------------
-- Error_Msg_Ada_2022_Feature --
--------------------------------
procedure Error_Msg_Ada_2022_Feature (Feature : String; Loc : Source_Ptr) is
begin
if Ada_Version < Ada_2022 then
Error_Msg (Feature & " is an Ada 2022 feature", Loc);
if No (Ada_Version_Pragma) then
Error_Msg ("\unit must be compiled with -gnat2022 switch", Loc);
else
Error_Msg_Sloc := Sloc (Ada_Version_Pragma);
Error_Msg ("\incompatible with Ada version set#", Loc);
end if;
end if;
end Error_Msg_Ada_2022_Feature;
------------------
-- 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.
-- Note: since this is an error recovery issue anyway, it is not worth
-- worrying about special UTF_32 line terminator characters here.
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).
-- Again, it is not worth worrying about UTF_32 special line terminator
-- characters in this context, since this is only for error recovery.
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_CRT --
-------------------
procedure Error_Msg_CRT (Feature : String; N : Node_Id) is
begin
if No_Run_Time_Mode then
Error_Msg_N ('|' & Feature & " not allowed in no run time mode", N);
else pragma Assert (Configurable_Run_Time_Mode);
Error_Msg_N ('|' & Feature & " not supported by configuration>", N);
end if;
Configurable_Run_Time_Violations := Configurable_Run_Time_Violations + 1;
end Error_Msg_CRT;
------------------
-- Error_Msg_PT --
------------------
procedure Error_Msg_PT (E : Entity_Id; Iface_Prim : Entity_Id) is
begin
Error_Msg_N
("illegal overriding of subprogram inherited from interface", E);
Error_Msg_Sloc := Sloc (Iface_Prim);
if Ekind (E) = E_Function then
Error_Msg_N
("\first formal of & declared # must be of mode `IN` "
& "or access-to-constant", E);
else
Error_Msg_N
("\first formal of & declared # must be of mode `OUT`, `IN OUT` "
& "or access-to-variable", E);
end if;
end Error_Msg_PT;
-----------------
-- Error_Msg_F --
-----------------
procedure Error_Msg_F (Msg : String; N : Node_Id) is
Fst, Lst : Node_Id;
begin
First_And_Last_Nodes (N, Fst, Lst);
Error_Msg_NEL (Msg, N, N,
To_Span (Ptr => Sloc (Fst),
First => First_Sloc (Fst),
Last => Last_Sloc (Lst)));
end Error_Msg_F;
------------------
-- Error_Msg_FE --
------------------
procedure Error_Msg_FE
(Msg : String;
N : Node_Id;
E : Node_Or_Entity_Id)
is
Fst, Lst : Node_Id;
begin
First_And_Last_Nodes (N, Fst, Lst);
Error_Msg_NEL (Msg, N, E,
To_Span (Ptr => Sloc (Fst),
First => First_Sloc (Fst),
Last => Last_Sloc (Lst)));
end Error_Msg_FE;
------------------------------
-- Error_Msg_GNAT_Extension --
------------------------------
procedure Error_Msg_GNAT_Extension
(Extension : String;
Loc : Source_Ptr;
Is_Core_Extension : Boolean := False)
is
begin
if (if Is_Core_Extension
then Core_Extensions_Allowed
else All_Extensions_Allowed)
then
return;
end if;
Error_Msg (Extension & " is a 'G'N'A'T-specific extension", Loc);
if No (Ada_Version_Pragma) then
if Is_Core_Extension then
Error_Msg
("\unit must be compiled with -gnatX '[or -gnatX0'] " &
"or use pragma Extensions_Allowed (On) '[or All']", Loc);
else
Error_Msg
("\unit must be compiled with -gnatX0 " &
"or use pragma Extensions_Allowed (All)", Loc);
end if;
else
Error_Msg_Sloc := Sloc (Ada_Version_Pragma);
Error_Msg ("\incompatible with Ada version set#", Loc);
if Is_Core_Extension then
Error_Msg
("\must use pragma Extensions_Allowed (On) '[or All']", Loc);
else
Error_Msg
("\must use pragma Extensions_Allowed (All)", Loc);
end if;
end if;
end Error_Msg_GNAT_Extension;
------------------------
-- Error_Msg_Internal --
------------------------
procedure Error_Msg_Internal
(Msg : String;
Span : Source_Span;
Opan : Source_Span;
Msg_Cont : Boolean;
Node : Node_Id)
is
Sptr : constant Source_Ptr := Span.Ptr;
Optr : constant Source_Ptr := Opan.Ptr;
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;
Warn_Err : Boolean;
-- Set if warning to be treated as error
procedure Handle_Serious_Error;
-- Internal procedure to do all error message handling for a serious
-- error message, other than bumping the error counts and arranging
-- for the message to be output.
--------------------------
-- Handle_Serious_Error --
--------------------------
procedure Handle_Serious_Error is
begin
-- 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 (in which case we set ignored mode if not
-- currently set. This stops the semantics from being performed
-- if we find a serious error. This is skipped if we are currently
-- dealing with the configuration pragma file.
if Current_Source_Unit /= No_Unit then
declare
U : constant Unit_Number_Type := Get_Source_Unit (Sptr);
begin
if Try_Semantics then
if Fatal_Error (U) = None then
Set_Fatal_Error (U, Error_Ignored);
end if;
else
Set_Fatal_Error (U, Error_Detected);
end if;
end;
end if;
-- Disable warnings on unused use clauses and the like. Otherwise, an
-- error might hide a reference to an entity in a used package, so
-- after fixing the error, the use clause no longer looks like it was
-- unused.
Warnsw.Check_Unreferenced := False;
Warnsw.Check_Unreferenced_Formals := False;
end Handle_Serious_Error;
-- Start of processing for Error_Msg_Internal
begin
-- Detect common mistake of prefixing or suffixing the message with a
-- space character.
pragma Assert (Msg (Msg'First) /= ' ' and then Msg (Msg'Last) /= ' ');
if Raise_Exception_On_Error /= 0 then
raise Error_Msg_Exception;
end if;
Continuation := Msg_Cont;
Continuation_New_Line := False;
Suppress_Message := False;
Kill_Message := False;
Set_Msg_Text (Msg, Sptr);
-- 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 then not All_Errors_Mode
and then not Is_Warning_Msg
and then not Is_Unconditional_Msg
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 Total_Errors_Detected /= 0
then
if not Continuation then
Last_Killed := True;
end if;
return;
end if;
-- Special check for warning message to see if it should be output
if Is_Warning_Msg then
-- Immediate return if warning message and warnings are suppressed
if Warnings_Suppressed (Optr) /= No_String
or else
Warnings_Suppressed (Sptr) /= No_String
then
Cur_Msg := No_Error_Msg;
return;
end if;
-- If the flag location is in the main extended source unit then for
-- sure we want the warning since it definitely belongs
if In_Extended_Main_Source_Unit (Sptr) then
null;
-- If the main unit has not been read yet. The warning must be on
-- a configuration file: gnat.adc or user-defined. This means we
-- are not parsing the main unit yet, so skip following checks.
elsif No (Cunit (Main_Unit)) then
null;
-- If the flag location is not in the extended main source unit, then
-- we want to eliminate the warning, unless it is in the extended
-- main code unit and we want warnings on the instance.
elsif In_Extended_Main_Code_Unit (Sptr) and then Warn_On_Instance then
null;
-- Keep warning if debug flag G set
elsif Debug_Flag_GG then
null;
-- Keep warning if message text contains !!
elsif Has_Double_Exclam then
null;
-- Here is where we delete a warning from a with'ed unit
else
Cur_Msg := No_Error_Msg;
if not Continuation then
Last_Killed := True;
end if;
return;
end if;
end if;
-- If message is to be ignored in special ignore message mode, this is
-- where we do this special processing, bypassing message output.
if Ignore_Errors_Enable > 0 then
if Is_Serious_Error then
Handle_Serious_Error;
end if;
return;
end if;
-- If error message line length set, and this is a continuation message
-- then all we do is to append the text to the text of the last message
-- with a comma space separator (eliminating a possible (style) or
-- info prefix).
if Error_Msg_Line_Length /= 0 and then Continuation then
Cur_Msg := Errors.Last;
declare
Oldm : String_Ptr := Errors.Table (Cur_Msg).Text;
Newm : String (1 .. Oldm'Last + 2 + Msglen);
Newl : Natural;
M : Natural;
begin
-- First copy old message to new one and free it
Newm (Oldm'Range) := Oldm.all;
Newl := Oldm'Length;
Free (Oldm);
-- Remove (style) or info: at start of message
if Msglen > 8 and then Msg_Buffer (1 .. 8) = "(style) " then
M := 9;
elsif Msglen > 6 and then Msg_Buffer (1 .. 6) = "info: " then
M := 7;
else
M := 1;
end if;
-- Now deal with separation between messages. Normally this is
-- simply comma space, but there are some special cases.
-- If continuation new line, then put actual NL character in msg
if Continuation_New_Line then
Newl := Newl + 1;
Newm (Newl) := ASCII.LF;
-- If continuation message is enclosed in parentheses, then
-- special treatment (don't need a comma, and we want to combine
-- successive parenthetical remarks into a single one with
-- separating commas).
elsif Msg_Buffer (M) = '(' and then Msg_Buffer (Msglen) = ')' then
-- Case where existing message ends in right paren, remove
-- and separate parenthetical remarks with a comma.
if Newm (Newl) = ')' then
Newm (Newl) := ',';
Msg_Buffer (M) := ' ';
-- Case where we are adding new parenthetical comment
else
Newl := Newl + 1;
Newm (Newl) := ' ';
end if;
-- Case where continuation not in parens and no new line
else
Newm (Newl + 1 .. Newl + 2) := ", ";
Newl := Newl + 2;
end if;
-- Append new message
Newm (Newl + 1 .. Newl + Msglen - M + 1) :=
Msg_Buffer (M .. Msglen);
Newl := Newl + Msglen - M + 1;
Errors.Table (Cur_Msg).Text := new String'(Newm (1 .. Newl));
-- Update warning msg flag and message doc char if needed
if Is_Warning_Msg then
if not Errors.Table (Cur_Msg).Warn then
Errors.Table (Cur_Msg).Warn := True;
Errors.Table (Cur_Msg).Warn_Chr := Warning_Msg_Char;
elsif Warning_Msg_Char /= " " then
Errors.Table (Cur_Msg).Warn_Chr := Warning_Msg_Char;
end if;
end if;
end;
return;
end if;
-- Here we build a new error object
Errors.Append
((Text => new String'(Msg_Buffer (1 .. Msglen)),
Next => No_Error_Msg,
Prev => No_Error_Msg,
Sptr => Span,
Optr => Opan,
Insertion_Sloc => (if Has_Insertion_Line then Error_Msg_Sloc
else No_Location),
Sfile => Get_Source_File_Index (Sptr),
Line => Get_Physical_Line_Number (Sptr),
Col => Get_Column_Number (Sptr),
Compile_Time_Pragma => Is_Compile_Time_Msg,
Warn => Is_Warning_Msg,
Info => Is_Info_Msg,
Check => Is_Check_Msg,
Warn_Err => False, -- reset below
Warn_Chr => Warning_Msg_Char,
Warn_Runtime_Raise => Is_Runtime_Raise,
Style => Is_Style_Msg,
Serious => Is_Serious_Error,
Uncond => Is_Unconditional_Msg,
Msg_Cont => Continuation,
Deleted => False,
Node => Node));
Cur_Msg := Errors.Last;
-- Test if warning to be treated as error
Warn_Err :=
(Is_Warning_Msg or Is_Style_Msg)
and then (Warning_Treated_As_Error (Msg_Buffer (1 .. Msglen))
or else
Warning_Treated_As_Error (Get_Warning_Tag (Cur_Msg)));
-- Propagate Warn_Err to this message and preceding continuations.
-- Likewise, propagate Is_Warning_Msg and Is_Runtime_Raise, because the
-- current continued message could have been escalated from warning to
-- error.
for J in reverse 1 .. Errors.Last loop
Errors.Table (J).Warn_Err := Warn_Err;
Errors.Table (J).Warn := Is_Warning_Msg;
Errors.Table (J).Warn_Runtime_Raise := Is_Runtime_Raise;
exit when not Errors.Table (J).Msg_Cont;
end loop;
-- 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 Debug_Flag_OO 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
-- First a quick check, does this belong at the very end of the chain
-- of error messages. This saves a lot of time in the normal case if
-- there are lots of messages.
if Last_Error_Msg /= No_Error_Msg
and then Errors.Table (Cur_Msg).Sfile =
Errors.Table (Last_Error_Msg).Sfile
and then (Sptr > Errors.Table (Last_Error_Msg).Sptr.Ptr
or else
(Sptr = Errors.Table (Last_Error_Msg).Sptr.Ptr
and then
Optr > Errors.Table (Last_Error_Msg).Optr.Ptr))
then
Prev_Msg := Last_Error_Msg;
Next_Msg := No_Error_Msg;
-- Otherwise do a full sequential search for the insertion point
else
Prev_Msg := No_Error_Msg;
Next_Msg := First_Error_Msg;
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 Sptr < Errors.Table (Next_Msg).Sptr.Ptr
or else (Sptr = Errors.Table (Next_Msg).Sptr.Ptr
and then
Optr < Errors.Table (Next_Msg).Optr.Ptr);
end if;
Prev_Msg := Next_Msg;
Next_Msg := Errors.Table (Next_Msg).Next;
end loop;
end if;
-- Now we insert the new message in the error chain.
-- The possible insertion point for the new message is after Prev_Msg
-- and before Next_Msg. However, this is where we do a special check
-- for redundant parsing messages, defined as messages posted on the
-- same line. The idea here is that probably such messages are junk
-- from the parser recovering. In full errors mode, we don't do this
-- deletion, but otherwise such messages are discarded at this stage.
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
and then Compiler_State = Parsing
and then not All_Errors_Mode
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 (Prev_Msg).Style)
or else
(Errors.Table (Cur_Msg).Warn
or else
Errors.Table (Cur_Msg).Style)
then
-- All tests passed, delete the message by simply returning
-- without any further processing.
pragma Assert (not Continuation);
Last_Killed := True;
return;
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
First_Error_Msg := Cur_Msg;
else
Errors.Table (Prev_Msg).Next := Cur_Msg;
end if;
Errors.Table (Cur_Msg).Next := Next_Msg;
if Next_Msg = No_Error_Msg then
Last_Error_Msg := Cur_Msg;
end if;
end if;
-- Bump appropriate statistics counts
if Errors.Table (Cur_Msg).Info then
-- Could be (usually is) both "info" and "warning"
if Errors.Table (Cur_Msg).Warn then
Warning_Info_Messages := Warning_Info_Messages + 1;
Warnings_Detected := Warnings_Detected + 1;
else
Report_Info_Messages := Report_Info_Messages + 1;
end if;
elsif Errors.Table (Cur_Msg).Warn
or else Errors.Table (Cur_Msg).Style
then
Warnings_Detected := Warnings_Detected + 1;
elsif Errors.Table (Cur_Msg).Check then
Check_Messages := Check_Messages + 1;
else
Total_Errors_Detected := Total_Errors_Detected + 1;
if Errors.Table (Cur_Msg).Serious then
Serious_Errors_Detected := Serious_Errors_Detected + 1;
Handle_Serious_Error;
-- If not serious error, set Fatal_Error to indicate ignored error
else
declare
U : constant Unit_Number_Type := Get_Source_Unit (Sptr);
begin
if Fatal_Error (U) = None then
Set_Fatal_Error (U, Error_Ignored);
end if;
end;
end if;
end if;
-- Record warning message issued
if Errors.Table (Cur_Msg).Warn
and then not Errors.Table (Cur_Msg).Msg_Cont
then
Warning_Msg := Cur_Msg;
end if;
-- If too many warnings turn off warnings
if Maximum_Messages /= 0 then
if Warnings_Detected = Maximum_Messages then
Warning_Mode := Suppress;
end if;
-- If too many errors abandon compilation
if Total_Errors_Detected = Maximum_Messages then
raise Unrecoverable_Error;
end if;
end if;
if Has_Error_Code then
declare
Msg : constant String :=
"\launch ""gnatprove --explain=[]"" for more information";
begin
Has_Double_Exclam := False;
Has_Error_Code := False;
Has_Insertion_Line := False;
Error_Msg_Internal
(Msg => Msg,
Span => Span,
Opan => Opan,
Msg_Cont => True,
Node => Node);
end;
end if;
end Error_Msg_Internal;
-----------------
-- Error_Msg_N --
-----------------
procedure Error_Msg_N (Msg : String; N : Node_Or_Entity_Id) is
Fst, Lst : Node_Id;
begin
First_And_Last_Nodes (N, Fst, Lst);
Error_Msg_NEL (Msg, N, N,
To_Span (Ptr => Sloc (N),
First => First_Sloc (Fst),
Last => Last_Sloc (Lst)));
end Error_Msg_N;
------------------
-- Error_Msg_NE --
------------------
procedure Error_Msg_NE
(Msg : String;
N : Node_Or_Entity_Id;
E : Node_Or_Entity_Id)
is
Fst, Lst : Node_Id;
begin
First_And_Last_Nodes (N, Fst, Lst);
Error_Msg_NEL (Msg, N, E,
To_Span (Ptr => Sloc (N),
First => First_Sloc (Fst),
Last => Last_Sloc (Lst)));
end Error_Msg_NE;
-------------------
-- Error_Msg_NEL --
-------------------
procedure Error_Msg_NEL
(Msg : String;
N : Node_Or_Entity_Id;
E : Node_Or_Entity_Id;
Flag_Location : Source_Ptr)
is
Fst, Lst : Node_Id;
begin
First_And_Last_Nodes (N, Fst, Lst);
Error_Msg_NEL
(Msg, N, E,
To_Span (Ptr => Flag_Location,
First => Source_Ptr'Min (Flag_Location, First_Sloc (Fst)),
Last => Source_Ptr'Max (Flag_Location, Last_Sloc (Lst))));
end Error_Msg_NEL;
procedure Error_Msg_NEL
(Msg : String;
N : Node_Or_Entity_Id;
E : Node_Or_Entity_Id;
Flag_Span : Source_Span)
is
begin
if Special_Msg_Delete (Msg, N, E) then
return;
end if;
Prescan_Message (Msg);
-- Special handling for warning messages
if Is_Warning_Msg then
-- Suppress if no warnings set for either entity or node
if No_Warnings (N) or else No_Warnings (E) then
-- Disable any continuation messages as well
Last_Killed := True;
return;
end if;
end if;
-- Test for message to be output
if All_Errors_Mode
or else Is_Unconditional_Msg
or else Is_Warning_Msg
or else OK_Node (N)
or else (Msg (Msg'First) = '\' and then not Last_Killed)
then
Debug_Output (N);
Error_Msg_Node_1 := E;
Error_Msg (Msg, Flag_Span, N);
else
Last_Killed := True;
end if;
if not Get_Ignore_Errors then
Set_Posted (N);
end if;
end Error_Msg_NEL;
------------------
-- Error_Msg_NW --
------------------
procedure Error_Msg_NW
(Eflag : Boolean;
Msg : String;
N : Node_Or_Entity_Id)
is
Fst, Lst : Node_Id;
begin
if Eflag
and then In_Extended_Main_Source_Unit (N)
and then Comes_From_Source (N)
then
First_And_Last_Nodes (N, Fst, Lst);
Error_Msg_NEL (Msg, N, N,
To_Span (Ptr => Sloc (N),
First => First_Sloc (Fst),
Last => Last_Sloc (Lst)));
end if;
end Error_Msg_NW;
-----------------
-- Error_Msg_S --
-----------------
procedure Error_Msg_S (Msg : String) is
begin
Error_Msg (Msg, Scan_Ptr);
end Error_Msg_S;
------------------
-- 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;
--------------
-- Finalize --
--------------
procedure Finalize (Last_Call : Boolean) is
Cur : Error_Msg_Id;
Nxt : Error_Msg_Id;
F : Error_Msg_Id;
procedure Delete_Warning (E : Error_Msg_Id);
-- Delete a warning msg if not already deleted and adjust warning count
--------------------
-- Delete_Warning --
--------------------
procedure Delete_Warning (E : Error_Msg_Id) is
begin
if not Errors.Table (E).Deleted then
Errors.Table (E).Deleted := True;
Warnings_Detected := Warnings_Detected - 1;
if Errors.Table (E).Info then
Warning_Info_Messages := Warning_Info_Messages - 1;
end if;
end if;
end Delete_Warning;
-- Start of processing for Finalize
begin
-- Set Prev pointers
Cur := First_Error_Msg;
while Cur /= No_Error_Msg loop
Nxt := Errors.Table (Cur).Next;
exit when Nxt = No_Error_Msg;
Errors.Table (Nxt).Prev := Cur;
Cur := Nxt;
end loop;
-- Eliminate any duplicated error messages from the list. This is
-- done after the fact to avoid problems with Change_Error_Text.
Cur := First_Error_Msg;
while Cur /= No_Error_Msg loop
Nxt := Errors.Table (Cur).Next;
F := Nxt;
while F /= No_Error_Msg
and then Errors.Table (F).Sptr.Ptr = Errors.Table (Cur).Sptr.Ptr
loop
Check_Duplicate_Message (Cur, F);
F := Errors.Table (F).Next;
end loop;
Cur := Nxt;
end loop;
-- Mark any messages suppressed by specific warnings as Deleted
Cur := First_Error_Msg;
while Cur /= No_Error_Msg loop
declare
CE : Error_Msg_Object renames Errors.Table (Cur);
Tag : constant String := Get_Warning_Tag (Cur);
begin
if (CE.Warn and not CE.Deleted)
and then
(Warning_Specifically_Suppressed (CE.Sptr.Ptr, CE.Text, Tag)
/= No_String
or else
Warning_Specifically_Suppressed (CE.Optr.Ptr, CE.Text, Tag)
/= No_String)
then
Delete_Warning (Cur);
-- If this is a continuation, delete previous parts of message
F := Cur;
while Errors.Table (F).Msg_Cont loop
F := Errors.Table (F).Prev;
exit when F = No_Error_Msg;
Delete_Warning (F);
end loop;
-- Delete any following continuations
F := Cur;
loop
F := Errors.Table (F).Next;
exit when F = No_Error_Msg;
exit when not Errors.Table (F).Msg_Cont;
Delete_Warning (F);
end loop;
end if;
end;
Cur := Errors.Table (Cur).Next;
end loop;
Finalize_Called := True;
-- Check consistency of specific warnings (may add warnings). We only
-- do this on the last call, after all possible warnings are posted.
if Last_Call then
Validate_Specific_Warnings (Error_Msg'Access);
end if;
end Finalize;
----------------
-- First_Node --
----------------
function First_Node (C : Node_Id) return Node_Id is
Fst, Lst : Node_Id;
begin
First_And_Last_Nodes (C, Fst, Lst);
return Fst;
end First_Node;
--------------------------
-- First_And_Last_Nodes --
--------------------------
procedure First_And_Last_Nodes
(C : Node_Id;
First_Node, Last_Node : out Node_Id)
is
Orig : constant Node_Id := Original_Node (C);
Loc : constant Source_Ptr := Sloc (Orig);
Sfile : constant Source_File_Index := Get_Source_File_Index (Loc);
Earliest : Node_Id;
Latest : Node_Id;
Eloc : Source_Ptr;
Lloc : Source_Ptr;
function Test_First_And_Last (N : Node_Id) return Traverse_Result;
-- Function applied to every node in the construct
procedure Search_Tree_First_And_Last is new
Traverse_Proc (Test_First_And_Last);
-- Create traversal procedure
-------------------------
-- Test_First_And_Last --
-------------------------
function Test_First_And_Last (N : Node_Id) return Traverse_Result is
Norig : constant Node_Id := Original_Node (N);
Loc : constant Source_Ptr := Sloc (Norig);
begin
-- ??? For assignments that require accessiblity checks, e.g.:
--
-- Y := Func (123);
--
-- the function call gets an extra actual parameter association with
-- Sloc of the assigned name "Y":
--
-- Y := Func (123, A8b => 2);
--
-- We can simply ignore those extra actual parameters when
-- determining the Sloc range of the "Func (123)" expression.
if Nkind (N) = N_Parameter_Association
and then Is_Accessibility_Actual (N)
then
return Skip;
end if;
-- Check for earlier
if Loc < Eloc
-- Ignore nodes with no useful location information
and then Loc /= Standard_Location
and then Loc /= No_Location
-- Ignore nodes from a different file. This ensures against cases
-- of strange foreign code somehow being present. We don't want
-- wild placement of messages if that happens.
and then Get_Source_File_Index (Loc) = Sfile
then
Earliest := Norig;
Eloc := Loc;
end if;
-- Check for later
if Loc > Lloc
-- Ignore nodes with no useful location information
and then Loc /= Standard_Location
and then Loc /= No_Location
-- Ignore nodes from a different file. This ensures against cases
-- of strange foreign code somehow being present. We don't want
-- wild placement of messages if that happens.
and then Get_Source_File_Index (Loc) = Sfile
then
Latest := Norig;
Lloc := Loc;
end if;
return OK_Orig;
end Test_First_And_Last;
-- Start of processing for First_And_Last_Nodes
begin
if Nkind (Orig) in N_Subexpr
| N_Declaration
| N_Access_To_Subprogram_Definition
| N_Generic_Instantiation
| N_Later_Decl_Item
| N_Use_Package_Clause
| N_Array_Type_Definition
| N_Renaming_Declaration
| N_Generic_Renaming_Declaration
| N_Assignment_Statement
| N_Raise_Statement
| N_Simple_Return_Statement
| N_Exit_Statement
| N_Pragma
| N_Use_Type_Clause
| N_With_Clause
| N_Attribute_Definition_Clause
| N_Subtype_Indication
then
Earliest := Orig;
Eloc := Loc;
Latest := Orig;
Lloc := Loc;
Search_Tree_First_And_Last (Orig);
First_Node := Earliest;
Last_Node := Latest;
else
First_Node := Orig;
Last_Node := Orig;
end if;
end First_And_Last_Nodes;
----------------
-- First_Sloc --
----------------
function First_Sloc (N : Node_Id) return Source_Ptr is
SI : constant Source_File_Index := Get_Source_File_Index (Sloc (N));
SF : constant Source_Ptr := Source_First (SI);
SL : constant Source_Ptr := Source_Last (SI);
Src : constant Source_Buffer_Ptr := Source_Text (SI);
F : Node_Id;
S : Source_Ptr;
begin
F := First_Node (N);
S := Sloc (F);
if S not in SF .. SL then
return S;
end if;
-- The following circuit is a bit subtle. When we have parenthesized
-- expressions, then the Sloc will not record the location of the paren,
-- but we would like to post the flag on the paren. So what we do is to
-- crawl up the tree from the First_Node, adjusting the Sloc value for
-- any parentheses we know are present. Yes, we know this circuit is not
-- 100% reliable (e.g. because we don't record all possible paren level
-- values), but this is only for an error message so it is good enough.
Node_Loop : loop
-- Include parentheses around the top node, except when they are
-- required by the syntax of the parent node.
exit Node_Loop when F = N
and then Paren_Required (N);
Paren_Loop : for J in 1 .. Paren_Count (F) loop
-- We don't look more than 12 characters behind the current
-- location, and in any case not past the front of the source.
Search_Loop : for K in 1 .. 12 loop
exit Search_Loop when S = SF;
if Src (S - 1) = '(' then
S := S - 1;
exit Search_Loop;
elsif Src (S - 1) <= ' ' then
S := S - 1;
else
exit Search_Loop;
end if;
end loop Search_Loop;
end loop Paren_Loop;
exit Node_Loop when F = N;
F := Parent (F);
exit Node_Loop when Nkind (F) not in N_Subexpr;
end loop Node_Loop;
return S;
end First_Sloc;
-----------------------
-- Get_Ignore_Errors --
-----------------------
function Get_Ignore_Errors return Boolean is
begin
return Errors_Must_Be_Ignored;
end Get_Ignore_Errors;
----------------
-- Initialize --
----------------
procedure Initialize is
begin
Errors.Init;
First_Error_Msg := No_Error_Msg;
Last_Error_Msg := No_Error_Msg;
Serious_Errors_Detected := 0;
Total_Errors_Detected := 0;
Cur_Msg := No_Error_Msg;
List_Pragmas.Init;
-- Reset counts for warnings
Warnings_Treated_As_Errors := 0;
Warnings_Detected := 0;
Warning_Info_Messages := 0;
Warnings_As_Errors_Count := 0;
-- Initialize warnings tables
Warnings.Init;
Specific_Warnings.Init;
end Initialize;
-------------------------------
-- Is_Size_Too_Small_Message --
-------------------------------
function Is_Size_Too_Small_Message (S : String) return Boolean is
Size_For : constant String := "size for";
pragma Assert (Size_Too_Small_Message (1 .. Size_For'Last) = Size_For);
-- Assert that Size_Too_Small_Message starts with Size_For
begin
return S'Length >= Size_For'Length
and then S (S'First .. S'First + Size_For'Length - 1) = Size_For;
-- True if S starts with Size_For
end Is_Size_Too_Small_Message;
---------------
-- Last_Node --
---------------
function Last_Node (C : Node_Id) return Node_Id is
Fst, Lst : Node_Id;
begin
First_And_Last_Nodes (C, Fst, Lst);
return Lst;
end Last_Node;
---------------
-- Last_Sloc --
---------------
function Last_Sloc (N : Node_Id) return Source_Ptr is
procedure Skip_Char (S : in out Source_Ptr);
-- Skip one character of the source buffer at location S
---------------
-- Skip_Char --
---------------
procedure Skip_Char (S : in out Source_Ptr) is
begin
S := S + 1;
end Skip_Char;
-- Local variables
SI : constant Source_File_Index := Get_Source_File_Index (Sloc (N));
SF : constant Source_Ptr := Source_First (SI);
SL : constant Source_Ptr := Source_Last (SI);
Src : constant Source_Buffer_Ptr := Source_Text (SI);
F : Node_Id;
S : Source_Ptr;
-- Start of processing for Last_Sloc
begin
F := Last_Node (N);
S := Sloc (F);
if S not in SF .. SL then
return S;
end if;
-- For string and character literals simply forward the sloc by their
-- length including the closing quotes. Perhaps we should do something
-- special for multibyte characters, but this code is only used to emit
-- error messages, so it is not worth the effort.
case Nkind (F) is
when N_String_Literal =>
return S + Source_Ptr (String_Length (Strval (F))) + 1;
when N_Character_Literal =>
return S + 2;
-- Skip past integer literals, both decimal and based, integer and
-- real. We can't greedily accept all allowed character, because
-- we would consme too many of them in expressions like "123+ABC"
-- or "123..456", so we follow quite precisely the Ada grammar and
-- consume different characters depending on the context.
when N_Integer_Literal =>
-- Skip past the initial numeral, which either leads the decimal
-- literal or is the base of a based literal.
while S < SL
and then Src (S + 1) in '0' .. '9' | '_'
loop
Skip_Char (S);
end loop;
-- Skip past #based_numeral#, if present
if S < SL
and then Src (S + 1) = '#'
then
Skip_Char (S);
while S < SL
and then
Src (S + 1) in '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' | '_'
loop
Skip_Char (S);
end loop;
if S < SL
and then Src (S + 1) = '#'
then
Skip_Char (S);
end if;
end if;
-- Skip past exponent, if present
if S < SL
and then Src (S + 1) in 'e' | 'E'
then
Skip_Char (S);
-- For positive exponents the plus sign is optional, but we
-- can simply skip past both plus and minus.
if S < SL
and then Src (S + 1) in '+' | '-'
then
Skip_Char (S);
end if;
-- Skip past the numeral part
while S < SL
and then Src (S + 1) in '0' .. '9' | '_'
loop
Skip_Char (S);
end loop;
end if;
when N_Real_Literal =>
-- Skip past the initial numeral, which either leads the decimal
-- literal or is the base of a based literal.
while S < SL
and then Src (S + 1) in '0' .. '9' | '_'
loop
Skip_Char (S);
end loop;
if S < SL then
-- Skip the dot and continue with a decimal literal
if Src (S + 1) = '.' then
Skip_Char (S);
while S < SL
and then Src (S + 1) in '0' .. '9' | '_'
loop
Skip_Char (S);
end loop;
-- Skip the hash and continue with a based literal
elsif Src (S + 1) = '#' then
Skip_Char (S);
while S < SL
and then
Src (S + 1) in '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' | '_'
loop
Skip_Char (S);
end loop;
if S < SL
and then Src (S + 1) = '.'
then
Skip_Char (S);
end if;
while S < SL
and then
Src (S + 1) in '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' | '_'
loop
Skip_Char (S);
end loop;
if S < SL
and then Src (S + 1) = '#'
then
Skip_Char (S);
end if;
end if;
end if;
-- Skip past exponent, if present
if S < SL
and then Src (S + 1) in 'e' | 'E'
then
Skip_Char (S);
-- For positive exponents the plus sign is optional, but we
-- can simply skip past both plus and minus.
if Src (S + 1) in '+' | '-' then
Skip_Char (S);
end if;
-- Skip past the numeral part
while S < SL
and then Src (S + 1) in '0' .. '9' | '_'
loop
Skip_Char (S);
end loop;
end if;
-- For other nodes simply skip past a keyword/identifier
when others =>
while S in SF .. SL - 1
and then Src (S + 1)
in
'0' .. '9' | 'a' .. 'z' | 'A' .. 'Z' | '_'
loop
Skip_Char (S);
end loop;
end case;
-- The following circuit attempts at crawling up the tree from the
-- Last_Node, adjusting the Sloc value for any parentheses we know
-- are present, similarly to what is done in First_Sloc.
Node_Loop : loop
-- Include parentheses around the top node, except when they are
-- required by the syntax of the parent node.
exit Node_Loop when F = N
and then Paren_Required (N);
Paren_Loop : for J in 1 .. Paren_Count (F) loop
-- We don't look more than 12 characters after the current
-- location
Search_Loop : for K in 1 .. 12 loop
exit Node_Loop when S = SL;
if Src (S + 1) = ')' then
S := S + 1;
exit Search_Loop;
elsif Src (S + 1) <= ' ' then
S := S + 1;
else
exit Search_Loop;
end if;
end loop Search_Loop;
end loop Paren_Loop;
exit Node_Loop when F = N;
F := Parent (F);
exit Node_Loop when Nkind (F) not in N_Subexpr;
end loop Node_Loop;
-- Remove any trailing space
while S in SF + 1 .. SL
and then Src (S) = ' '
loop
S := S - 1;
end loop;
return S;
end Last_Sloc;
-----------------
-- No_Warnings --
-----------------
function No_Warnings (N : Node_Or_Entity_Id) return Boolean is
begin
if Error_Posted (N) then
return True;
elsif Nkind (N) in N_Entity and then Has_Warnings_Off (N) then
return True;
elsif Is_Entity_Name (N)
and then Present (Entity (N))
and then Has_Warnings_Off (Entity (N))
then
return True;
else
return False;
end if;
end No_Warnings;
-------------
-- 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_JSON_Message --
-------------------------
procedure Output_JSON_Message (Error_Id : Error_Msg_Id) is
function Is_Continuation (E : Error_Msg_Id) return Boolean;
-- Return True if E is a continuation message.
procedure Write_JSON_Escaped_String (Str : String_Ptr);
procedure Write_JSON_Escaped_String (Str : String);
-- Write each character of Str, taking care of preceding each quote and
-- backslash with a backslash. Note that this escaping differs from what
-- GCC does.
--
-- Indeed, the JSON specification mandates encoding wide characters
-- either as their direct UTF-8 representation or as their escaped
-- UTF-16 surrogate pairs representation. GCC seems to prefer escaping -
-- we choose to use the UTF-8 representation instead.
procedure Write_JSON_Location (Sptr : Source_Ptr);
-- Write Sptr as a JSON location, an object containing a file attribute,
-- a line number and a column number.
procedure Write_JSON_Span (Error : Error_Msg_Object);
-- Write Error as a JSON span, an object containing a "caret" attribute
-- whose value is the JSON location of Error.Sptr.Ptr. If Sptr.First and
-- Sptr.Last are different from Sptr.Ptr, they will be printed as JSON
-- locations under the names "start" and "finish".
-- When Include_Subprogram_In_Messages is true (-gnatdJ) an additional,
-- non-standard, attribute named "subprogram" will be added, allowing
-- precisely identifying the subprogram surrounding the span.
-----------------------
-- Is_Continuation --
-----------------------
function Is_Continuation (E : Error_Msg_Id) return Boolean is
begin
return E <= Last_Error_Msg and then Errors.Table (E).Msg_Cont;
end Is_Continuation;
-------------------------------
-- Write_JSON_Escaped_String --
-------------------------------
procedure Write_JSON_Escaped_String (Str : String) is
begin
for C of Str loop
if C = '"' or else C = '\' then
Write_Char ('\');
end if;
Write_Char (C);
end loop;
end Write_JSON_Escaped_String;
-------------------------------
-- Write_JSON_Escaped_String --
-------------------------------
procedure Write_JSON_Escaped_String (Str : String_Ptr) is
begin
Write_JSON_Escaped_String (Str.all);
end Write_JSON_Escaped_String;
-------------------------
-- Write_JSON_Location --
-------------------------
procedure Write_JSON_Location (Sptr : Source_Ptr) is
Name : constant File_Name_Type :=
Full_Ref_Name (Get_Source_File_Index (Sptr));
begin
Write_Str ("{""file"":""");
if Full_Path_Name_For_Brief_Errors then
Write_JSON_Escaped_String
(System.OS_Lib.Normalize_Pathname (Get_Name_String (Name)));
else
Write_Name (Name);
end if;
Write_Str (""",""line"":");
Write_Int (Pos (Get_Physical_Line_Number (Sptr)));
Write_Str (", ""column"":");
Write_Int (Nat (Get_Column_Number (Sptr)));
Write_Str ("}");
end Write_JSON_Location;
---------------------
-- Write_JSON_Span --
---------------------
procedure Write_JSON_Span (Error : Error_Msg_Object) is
Span : constant Source_Span := Error.Sptr;
begin
Write_Str ("{""caret"":");
Write_JSON_Location (Span.Ptr);
if Span.Ptr /= Span.First then
Write_Str (",""start"":");
Write_JSON_Location (Span.First);
end if;
if Span.Ptr /= Span.Last then
Write_Str (",""finish"":");
Write_JSON_Location (Span.Last);
end if;
if Include_Subprogram_In_Messages then
Write_Str (",""subprogram"":""");
Write_JSON_Escaped_String (Subprogram_Name_Ptr (Error.Node));
Write_Str ("""");
end if;
Write_Str ("}");
end Write_JSON_Span;
-- Local Variables
E : Error_Msg_Id := Error_Id;
Print_Continuations : constant Boolean := not Is_Continuation (E);
-- Do not print continuations messages as children of the current
-- message if the current message is a continuation message.
Option : constant String := Get_Warning_Option (E);
-- The option that triggered this message.
-- Start of processing for Output_JSON_Message
begin
-- Print message kind
Write_Str ("{""kind"":");
if Errors.Table (E).Warn and then not Errors.Table (E).Warn_Err then
Write_Str ("""warning""");
elsif Errors.Table (E).Info or else Errors.Table (E).Check then
Write_Str ("""note""");
else
Write_Str ("""error""");
end if;
-- Print message location
Write_Str (",""locations"":[");
Write_JSON_Span (Errors.Table (E));
if Errors.Table (E).Optr.Ptr /= Errors.Table (E).Sptr.Ptr then
Write_Str (",{""caret"":");
Write_JSON_Location (Errors.Table (E).Optr.Ptr);
Write_Str ("}");
end if;
Write_Str ("]");
-- Print message option, if there is one
if Option /= "" then
Write_Str (",""option"":""" & Option & """");
end if;
-- Print message content
Write_Str (",""message"":""");
Write_JSON_Escaped_String (Errors.Table (E).Text);
Write_Str ("""");
E := E + 1;
if Print_Continuations and then Is_Continuation (E) then
Write_Str (",""children"": [");
Output_JSON_Message (E);
E := E + 1;
while Is_Continuation (E) loop
Write_Str (", ");
Output_JSON_Message (E);
E := E + 1;
end loop;
Write_Str ("]");
end if;
Write_Str ("}");
end Output_JSON_Message;
---------------------
-- Output_Messages --
---------------------
procedure Output_Messages is
-- Local subprograms
procedure Write_Error_Summary;
-- Write error summary
procedure Write_Header (Sfile : Source_File_Index);
-- Write header line (compiling or checking given file)
procedure Write_Max_Errors;
-- Write message if max errors reached
procedure Write_Source_Code_Lines
(Span : Source_Span;
SGR_Span : String);
-- Write the source code line corresponding to Span, as follows when
-- Span in on one line:
--
-- line | actual code line here with Span somewhere
-- | ~~~~~^~~~
--
-- where the caret on the line points to location Span.Ptr, and the
-- range Span.First..Span.Last is underlined.
--
-- or when the span is over multiple lines:
--
-- line | beginning of the Span on this line
-- ... | ...
-- line>| actual code line here with Span.Ptr somewhere
-- ... | ...
-- line | end of the Span on this line
--
-- or when the span is a simple location, as follows:
--
-- line | actual code line here with Span somewhere
-- | ^ here
--
-- where the caret on the line points to location Span.Ptr
--
-- SGR_Span is the SGR string to start the section of code in the span,
-- that should be closed with SGR_Reset.
-------------------------
-- Write_Error_Summary --
-------------------------
procedure Write_Error_Summary is
begin
-- Extra blank line if error messages or source listing were output
if Total_Errors_Detected + Warnings_Detected > 0 or else Full_List
then
Write_Eol;
end if;
-- Message giving number of lines read and 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 Total_Errors_Detected + Warnings_Detected /= 0
and then not Brief_Output
and then (Verbose_Mode or Full_List)
then
Set_Standard_Error;
end if;
-- Message giving total number of lines. Don't give this message if
-- the Main_Source line is unknown (this happens in error situations,
-- e.g. when integrated preprocessing fails).
if Main_Source_File > No_Source_File then
Write_Str (" ");
Write_Int (Num_Source_Lines (Main_Source_File));
if Num_Source_Lines (Main_Source_File) = 1 then
Write_Str (" line: ");
else
Write_Str (" lines: ");
end if;
end if;
if Total_Errors_Detected = 0 then
Write_Str ("No errors");
elsif Total_Errors_Detected = 1 then
Write_Str ("1 error");
else
Write_Int (Total_Errors_Detected);
Write_Str (" errors");
end if;
-- We now need to output warnings. When using -gnatwe, all warnings
-- should be treated as errors, except for warnings originating from
-- the use of the Compile_Time_Warning pragma. Another situation
-- where a warning might be treated as an error is when the source
-- code contains a Warning_As_Error pragma.
-- When warnings are treated as errors, we still log them as
-- warnings, but we add a message denoting how many of these warnings
-- are also errors.
declare
Warnings_Count : constant Int :=
Warnings_Detected - Warning_Info_Messages;
Compile_Time_Warnings : Int;
-- Number of warnings that come from a Compile_Time_Warning
-- pragma.
Non_Compile_Time_Warnings : Int;
-- Number of warnings that do not come from a Compile_Time_Warning
-- pragmas.
begin
if Warnings_Count > 0 then
Write_Str (", ");
Write_Int (Warnings_Count);
Write_Str (" warning");
if Warnings_Count > 1 then
Write_Char ('s');
end if;
Compile_Time_Warnings := Count_Compile_Time_Pragma_Warnings;
Non_Compile_Time_Warnings :=
Warnings_Count - Compile_Time_Warnings;
if Warning_Mode = Treat_As_Error
and then Non_Compile_Time_Warnings > 0
then
Write_Str (" (");
if Compile_Time_Warnings > 0 then
Write_Int (Non_Compile_Time_Warnings);
Write_Str (" ");
end if;
Write_Str ("treated as error");
if Non_Compile_Time_Warnings > 1 then
Write_Char ('s');
end if;
Write_Char (')');
elsif Warnings_Treated_As_Errors > 0 then
Write_Str (" (");
if Warnings_Treated_As_Errors /= Warnings_Count then
Write_Int (Warnings_Treated_As_Errors);
Write_Str (" ");
end if;
Write_Str ("treated as error");
if Warnings_Treated_As_Errors > 1 then
Write_Str ("s");
end if;
Write_Str (")");
end if;
end if;
end;
if Warning_Info_Messages + Report_Info_Messages /= 0 then
Write_Str (", ");
Write_Int (Warning_Info_Messages + Report_Info_Messages);
Write_Str (" info message");
if Warning_Info_Messages + Report_Info_Messages > 1 then
Write_Char ('s');
end if;
end if;
Write_Eol;
Set_Standard_Output;
end Write_Error_Summary;
------------------
-- Write_Header --
------------------
procedure Write_Header (Sfile : Source_File_Index) is
begin
if Verbose_Mode or Full_List then
if Original_Operating_Mode = Generate_Code then
Write_Str ("Compiling: ");
else
Write_Str ("Checking: ");
end if;
Write_Name (Full_File_Name (Sfile));
if not Debug_Flag_7 then
Write_Eol;
Write_Str ("Source file time stamp: ");
Write_Time_Stamp (Sfile);
Write_Eol;
Write_Str ("Compiled at: " & Compilation_Time);
end if;
Write_Eol;
end if;
end Write_Header;
----------------------
-- Write_Max_Errors --
----------------------
procedure Write_Max_Errors is
begin
if Maximum_Messages /= 0 then
if Warnings_Detected >= Maximum_Messages then
Set_Standard_Error;
Write_Line ("maximum number of warnings output");
Write_Line ("any further warnings suppressed");
Set_Standard_Output;
end if;
-- If too many errors print message
if Total_Errors_Detected >= Maximum_Messages then
Set_Standard_Error;
Write_Line ("fatal error: maximum number of errors detected");
Set_Standard_Output;
end if;
end if;
end Write_Max_Errors;
-----------------------------
-- Write_Source_Code_Lines --
-----------------------------
procedure Write_Source_Code_Lines
(Span : Source_Span;
SGR_Span : String)
is
function Get_Line_End
(Buf : Source_Buffer_Ptr;
Loc : Source_Ptr) return Source_Ptr;
-- Get the source location for the end of the line in Buf for Loc. If
-- Loc is past the end of Buf already, return Buf'Last.
function Get_Line_Start
(Buf : Source_Buffer_Ptr;
Loc : Source_Ptr) return Source_Ptr;
-- Get the source location for the start of the line in Buf for Loc
function Image (X : Positive; Width : Positive) return String;
-- Output number X over Width characters, with whitespace padding.
-- Only output the low-order Width digits of X, if X is larger than
-- Width digits.
procedure Write_Buffer
(Buf : Source_Buffer_Ptr;
First : Source_Ptr;
Last : Source_Ptr);
-- Output the characters from First to Last position in Buf, using
-- Write_Buffer_Char.
procedure Write_Buffer_Char
(Buf : Source_Buffer_Ptr;
Loc : Source_Ptr);
-- Output the characters at position Loc in Buf, translating ASCII.HT
-- in a suitable number of spaces so that the output is not modified
-- by starting in a different column that 1.
procedure Write_Line_Marker
(Num : Pos;
Mark : Boolean;
Width : Positive);
-- Output the line number Num over Width characters, with possibly
-- a Mark to denote the line with the main location when reporting
-- a span over multiple lines.
------------------
-- Get_Line_End --
------------------
function Get_Line_End
(Buf : Source_Buffer_Ptr;
Loc : Source_Ptr) return Source_Ptr
is
Cur_Loc : Source_Ptr := Source_Ptr'Min (Loc, Buf'Last);
begin
while Cur_Loc < Buf'Last
and then Buf (Cur_Loc) /= ASCII.LF
loop
Cur_Loc := Cur_Loc + 1;
end loop;
return Cur_Loc;
end Get_Line_End;
--------------------
-- Get_Line_Start --
--------------------
function Get_Line_Start
(Buf : Source_Buffer_Ptr;
Loc : Source_Ptr) return Source_Ptr
is
Cur_Loc : Source_Ptr := Loc;
begin
while Cur_Loc > Buf'First
and then Buf (Cur_Loc - 1) /= ASCII.LF
loop
Cur_Loc := Cur_Loc - 1;
end loop;
return Cur_Loc;
end Get_Line_Start;
-----------
-- Image --
-----------
function Image (X : Positive; Width : Positive) return String is
Str : String (1 .. Width);
Curr : Natural := X;
begin
for J in reverse 1 .. Width loop
if Curr > 0 then
Str (J) := Character'Val (Character'Pos ('0') + Curr mod 10);
Curr := Curr / 10;
else
Str (J) := ' ';
end if;
end loop;
return Str;
end Image;
------------------
-- Write_Buffer --
------------------
procedure Write_Buffer
(Buf : Source_Buffer_Ptr;
First : Source_Ptr;
Last : Source_Ptr)
is
begin
for Loc in First .. Last loop
Write_Buffer_Char (Buf, Loc);
end loop;
end Write_Buffer;
-----------------------
-- Write_Buffer_Char --
-----------------------
procedure Write_Buffer_Char
(Buf : Source_Buffer_Ptr;
Loc : Source_Ptr)
is
begin
-- If the character ASCII.HT is not the last one in the file,
-- output as many spaces as the character represents in the
-- original source file.
if Buf (Loc) = ASCII.HT
and then Loc < Buf'Last
then
for X in Get_Column_Number (Loc) ..
Get_Column_Number (Loc + 1) - 1
loop
Write_Char (' ');
end loop;
-- Otherwise output the character itself
else
Write_Char (Buf (Loc));
end if;
end Write_Buffer_Char;
-----------------------
-- Write_Line_Marker --
-----------------------
procedure Write_Line_Marker
(Num : Pos;
Mark : Boolean;
Width : Positive)
is
begin
Write_Str (Image (Positive (Num), Width => Width));
Write_Str ((if Mark then ">" else " ") & "|");
end Write_Line_Marker;
-- Local variables
Loc : constant Source_Ptr := Span.Ptr;
Line : constant Pos := Pos (Get_Physical_Line_Number (Loc));
Col : constant Natural := Natural (Get_Column_Number (Loc));
Fst : constant Source_Ptr := Span.First;
Line_Fst : constant Pos :=
Pos (Get_Physical_Line_Number (Fst));
Col_Fst : constant Natural :=
Natural (Get_Column_Number (Fst));
Lst : constant Source_Ptr := Span.Last;
Line_Lst : constant Pos :=
Pos (Get_Physical_Line_Number (Lst));
Col_Lst : constant Natural :=
Natural (Get_Column_Number (Lst));
Width : constant := 5;
Buf : Source_Buffer_Ptr;
Cur_Loc : Source_Ptr := Fst;
Cur_Line : Pos := Line_Fst;
-- Start of processing for Write_Source_Code_Lines
begin
if Loc >= First_Source_Ptr then
Buf := Source_Text (Get_Source_File_Index (Loc));
-- First line of the span with actual source code. We retrieve
-- the beginning of the line instead of relying on Col_Fst, as
-- ASCII.HT characters change column numbers by possibly more
-- than one.
Write_Line_Marker
(Cur_Line,
Line_Fst /= Line_Lst and then Cur_Line = Line,
Width);
Write_Buffer (Buf, Get_Line_Start (Buf, Cur_Loc), Cur_Loc - 1);
-- Output the first/caret/last lines of the span, as well as
-- lines that are directly above/below the caret if they complete
-- the gap with first/last lines, otherwise use ... to denote
-- intermediate lines.
-- If the span is on one line and not a simple source location,
-- color it appropriately.
if Line_Fst = Line_Lst
and then Col_Fst /= Col_Lst
then
Write_Str (SGR_Span);
end if;
declare
function Do_Write_Line (Cur_Line : Pos) return Boolean is
(Cur_Line in Line_Fst | Line | Line_Lst
or else
(Cur_Line = Line_Fst + 1 and then Cur_Line = Line - 1)
or else
(Cur_Line = Line + 1 and then Cur_Line = Line_Lst - 1));
begin
while Cur_Loc <= Buf'Last
and then Cur_Loc <= Lst
loop
if Do_Write_Line (Cur_Line) then
Write_Buffer_Char (Buf, Cur_Loc);
end if;
if Buf (Cur_Loc) = ASCII.LF then
Cur_Line := Cur_Line + 1;
-- Output ... for skipped lines
if (Cur_Line = Line
and then not Do_Write_Line (Cur_Line - 1))
or else
(Cur_Line = Line + 1
and then not Do_Write_Line (Cur_Line))
then
Write_Str ((1 .. Width - 3 => ' ') & "... | ...");
Write_Eol;
end if;
-- Display the line marker if the line should be
-- displayed.
if Do_Write_Line (Cur_Line) then
Write_Line_Marker
(Cur_Line,
Line_Fst /= Line_Lst and then Cur_Line = Line,
Width);
end if;
end if;
Cur_Loc := Cur_Loc + 1;
end loop;
end;
if Line_Fst = Line_Lst
and then Col_Fst /= Col_Lst
then
Write_Str (SGR_Reset);
end if;
-- Output the rest of the last line of the span
Write_Buffer (Buf, Cur_Loc, Get_Line_End (Buf, Cur_Loc));
-- If the span is on one line, output a second line with caret
-- sign pointing to location Loc
if Line_Fst = Line_Lst then
Write_Str (String'(1 .. Width => ' '));
Write_Str (" |");
Write_Str (String'(1 .. Col_Fst - 1 => ' '));
Write_Str (SGR_Span);
Write_Str (String'(Col_Fst .. Col - 1 => '~'));
Write_Str ("^");
Write_Str (String'(Col + 1 .. Col_Lst => '~'));
-- If the span is really just a location, add the word "here"
-- to clarify this is the location for the message.
if Col_Fst = Col_Lst then
Write_Str (" here");
end if;
Write_Str (SGR_Reset);
Write_Eol;
end if;
end if;
end Write_Source_Code_Lines;
-- Local variables
E : Error_Msg_Id;
Err_Flag : Boolean;
Use_Prefix : Boolean;
-- Start of processing for Output_Messages
begin
-- Error if Finalize has not been called
if not Finalize_Called then
raise Program_Error;
end if;
-- 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 Main_Source_File <= No_Source_File
or else Num_SRef_Pragmas (Main_Source_File) /= 0
then
Current_Error_Source_File := No_Source_File;
end if;
if Opt.JSON_Output then
Set_Standard_Error;
E := First_Error_Msg;
-- Find first printable message
while E /= No_Error_Msg and then Errors.Table (E).Deleted loop
E := Errors.Table (E).Next;
end loop;
Write_Char ('[');
if E /= No_Error_Msg then
Output_JSON_Message (E);
E := Errors.Table (E).Next;
while E /= No_Error_Msg loop
-- Skip deleted messages.
-- Also skip continuation messages, as they have already been
-- printed along the message they're attached to.
if not Errors.Table (E).Deleted
and then not Errors.Table (E).Msg_Cont
then
Write_Char (',');
Output_JSON_Message (E);
end if;
E := Errors.Table (E).Next;
end loop;
end if;
Write_Char (']');
Set_Standard_Output;
-- Brief Error mode
elsif Brief_Output or (not Full_List and not Verbose_Mode) then
Set_Standard_Error;
E := First_Error_Msg;
while E /= No_Error_Msg loop
-- If -gnatdF is used, separate main messages from previous
-- messages with a newline (unless it is an info message) and
-- make continuation messages follow the main message with only
-- an indentation of two space characters, without repeating
-- file:line:col: prefix.
Use_Prefix :=
not (Debug_Flag_FF and then Errors.Table (E).Msg_Cont);
if not Errors.Table (E).Deleted and then not Debug_Flag_KK then
if Debug_Flag_FF then
if Errors.Table (E).Msg_Cont then
Write_Str (" ");
elsif not Errors.Table (E).Info then
Write_Eol;
end if;
end if;
if Use_Prefix then
Write_Str (SGR_Locus);
if Full_Path_Name_For_Brief_Errors then
Write_Name (Full_Ref_Name (Errors.Table (E).Sfile));
else
Write_Name (Reference_Name (Errors.Table (E).Sfile));
end if;
Write_Char (':');
Write_Int (Int (Physical_To_Logical
(Errors.Table (E).Line,
Errors.Table (E).Sfile)));
Write_Char (':');
if Errors.Table (E).Col < 10 then
Write_Char ('0');
end if;
Write_Int (Int (Errors.Table (E).Col));
Write_Str (": ");
Write_Str (SGR_Reset);
end if;
Output_Msg_Text (E);
Write_Eol;
-- If -gnatdF is used, write the source code line corresponding
-- to the location of the main message (unless it is an info
-- message). Also write the source code line corresponding to
-- an insertion location inside continuation messages.
if Debug_Flag_FF
and then not Errors.Table (E).Info
then
if Errors.Table (E).Msg_Cont then
declare
Loc : constant Source_Ptr :=
Errors.Table (E).Insertion_Sloc;
begin
if Loc /= No_Location then
Write_Source_Code_Lines
(To_Span (Loc), SGR_Span => SGR_Note);
end if;
end;
else
declare
SGR_Span : constant String :=
(if Errors.Table (E).Info then SGR_Note
elsif Errors.Table (E).Warn
and then not Errors.Table (E).Warn_Err
then SGR_Warning
else SGR_Error);
begin
Write_Source_Code_Lines
(Errors.Table (E).Optr, SGR_Span);
end;
end if;
end if;
end if;
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 := First_Error_Msg;
-- Normal case, to stdout (copyright notice already output)
if Full_List_File_Name = null then
if not Debug_Flag_7 then
Write_Eol;
end if;
-- Output to file
else
Create_List_File_Access.all (Full_List_File_Name.all);
Set_Special_Output (Write_List_Info_Access.all'Access);
-- Write copyright notice to file
if not Debug_Flag_7 then
Write_Str ("GNAT ");
Write_Str (Gnat_Version_String);
Write_Eol;
Write_Str ("Copyright 1992-" &
Current_Year &
", Free Software Foundation, Inc.");
Write_Eol;
end if;
end if;
-- First list extended main source file units with errors
for U in Main_Unit .. Last_Unit loop
if In_Extended_Main_Source_Unit (Cunit_Entity (U))
-- If debug flag d.m is set, only the main source is listed
and then (U = Main_Unit or else not Debug_Flag_Dot_M)
-- If the unit of the entity does not come from source, it is
-- an implicit subprogram declaration for a child subprogram.
-- Do not emit errors for it, they are listed with the body.
and then
(No (Cunit_Entity (U))
or else Comes_From_Source (Cunit_Entity (U))
or else not Is_Subprogram (Cunit_Entity (U)))
-- If the compilation unit associated with this unit does not
-- come from source, it means it is an instantiation that should
-- not be included in the source listing.
and then Comes_From_Source (Cunit (U))
then
declare
Sfile : constant Source_File_Index := Source_Index (U);
begin
Write_Eol;
-- Only write the header if Sfile is known
if Sfile > No_Source_File then
Write_Header (Sfile);
Write_Eol;
end if;
-- Normally, we don't want an "error messages from file"
-- message when listing the entire file, so we set the
-- current source file as the current error source file.
-- However, the old style of doing things was to list this
-- message if pragma Source_Reference is present, even for
-- the main unit. Since the purpose of the -gnatd.m switch
-- is to duplicate the old behavior, we skip the reset if
-- this debug flag is set.
if not Debug_Flag_Dot_M then
Current_Error_Source_File := Sfile;
end if;
-- Only output the listing if Sfile is known, to avoid
-- crashing the compiler.
if Sfile > No_Source_File then
for N in 1 .. Last_Source_Line (Sfile) loop
while E /= No_Error_Msg
and then Errors.Table (E).Deleted
loop
E := Errors.Table (E).Next;
end loop;
Err_Flag :=
E /= No_Error_Msg
and then Errors.Table (E).Line = N
and then Errors.Table (E).Sfile = Sfile;
Output_Source_Line (N, Sfile, Err_Flag);
if Err_Flag then
Output_Error_Msgs (E);
if not Debug_Flag_2 then
Write_Eol;
end if;
end if;
end loop;
end if;
end;
end if;
end loop;
-- Then output errors, if any, for subsidiary units not in the
-- main extended unit.
-- Note: if debug flag d.m set, include errors for any units other
-- than the main unit in the extended source unit (e.g. spec and
-- subunits for a body).
while E /= No_Error_Msg
and then (not In_Extended_Main_Source_Unit
(Errors.Table (E).Sptr.Ptr)
or else
(Debug_Flag_Dot_M
and then Get_Source_Unit
(Errors.Table (E).Sptr.Ptr) /= Main_Unit))
loop
if Errors.Table (E).Deleted then
E := Errors.Table (E).Next;
else
Write_Eol;
Output_Source_Line
(Errors.Table (E).Line, Errors.Table (E).Sfile, True);
Output_Error_Msgs (E);
end if;
end loop;
-- If output to file, write extra copy of error summary to the
-- output file, and then close it.
if Full_List_File_Name /= null then
Write_Error_Summary;
Write_Max_Errors;
Close_List_File_Access.all;
Cancel_Special_Output;
end if;
end if;
-- Verbose mode (error lines only with error flags). Normally this is
-- ignored in full list mode, unless we are listing to a file, in which
-- case we still generate -gnatv output to standard output.
if Verbose_Mode
and then (not Full_List or else Full_List_File_Name /= null)
then
Write_Eol;
-- Output the header only when Main_Source_File is known
if Main_Source_File > No_Source_File then
Write_Header (Main_Source_File);
end if;
E := First_Error_Msg;
-- Loop through error lines
while E /= No_Error_Msg loop
if Errors.Table (E).Deleted then
E := Errors.Table (E).Next;
else
Write_Eol;
Output_Source_Line
(Errors.Table (E).Line, Errors.Table (E).Sfile, True);
Output_Error_Msgs (E);
end if;
end loop;
end if;
-- Output error summary if verbose or full list mode
if Verbose_Mode or else Full_List then
Write_Error_Summary;
end if;
if not Opt.JSON_Output then
Write_Max_Errors;
end if;
-- Even though Warning_Info_Messages are a subclass of warnings, they
-- must not be treated as errors when -gnatwe is in effect.
if Warning_Mode = Treat_As_Error then
declare
Compile_Time_Pragma_Warnings : constant Int :=
Count_Compile_Time_Pragma_Warnings;
begin
Total_Errors_Detected := Total_Errors_Detected + Warnings_Detected
- Warning_Info_Messages - Compile_Time_Pragma_Warnings;
Warnings_Detected :=
Warning_Info_Messages + Compile_Time_Pragma_Warnings;
end;
end if;
end Output_Messages;
------------------------
-- Output_Source_Line --
------------------------
procedure Output_Source_Line
(L : Physical_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
Empty_Line : Boolean := True;
-- Set False if line includes at least one character
begin
if Sfile /= Current_Error_Source_File then
Write_Str ("==============Error messages for ");
case Sinput.File_Type (Sfile) is
when Sinput.Src =>
Write_Str ("source");
when Sinput.Config =>
Write_Str ("configuration pragmas");
when Sinput.Def =>
Write_Str ("symbol definition");
when Sinput.Preproc =>
Write_Str ("preprocessing data");
end case;
Write_Str (" file: ");
Write_Name (Full_File_Name (Sfile));
Write_Eol;
if Num_SRef_Pragmas (Sfile) > 0 then
Write_Str ("--------------Line numbers from file: ");
Write_Name (Full_Ref_Name (Sfile));
Write_Str (" (starting at line ");
Write_Int (Int (First_Mapped_Line (Sfile)));
Write_Char (')');
Write_Eol;
end if;
Current_Error_Source_File := Sfile;
end if;
if Errs or List_Pragmas_Mode then
Output_Line_Number (Physical_To_Logical (L, Sfile));
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 (Physical_To_Logical (L, Sfile));
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;
Empty_Line := False;
S := S + 1;
end loop;
-- If we have output a source line, then add the line terminator, with
-- training spaces preserved (so we output the line exactly as input).
if Line_Number_Output then
if Empty_Line then
Write_Eol;
else
Write_Eol_Keep_Blanks;
end if;
end if;
end Output_Source_Line;
--------------------
-- Paren_Required --
--------------------
function Paren_Required (N : Node_Id) return Boolean is
begin
-- In a qualifed_expression the expression part needs to be enclosed in
-- parentheses.
if Nkind (Parent (N)) = N_Qualified_Expression then
return N = Expression (Parent (N));
else
return False;
end if;
end Paren_Required;
-----------------------------
-- Remove_Warning_Messages --
-----------------------------
procedure Remove_Warning_Messages (N : Node_Id) is
function Check_For_Warning (N : Node_Id) return Traverse_Result;
-- This function checks one node for a possible warning message
procedure Check_All_Warnings is new Traverse_Proc (Check_For_Warning);
-- This defines the traversal operation
-----------------------
-- Check_For_Warning --
-----------------------
function Check_For_Warning (N : Node_Id) return Traverse_Result is
Loc : constant Source_Ptr := Sloc (N);
E : Error_Msg_Id;
function To_Be_Removed (E : Error_Msg_Id) return Boolean;
-- Returns True for a message that is to be removed. Also adjusts
-- warning count appropriately.
-------------------
-- To_Be_Removed --
-------------------
function To_Be_Removed (E : Error_Msg_Id) return Boolean is
begin
if E /= No_Error_Msg
-- Don't remove if location does not match
and then Errors.Table (E).Optr.Ptr = Loc
-- Don't remove if not warning/info message. Note that we do
-- not remove style messages here. They are warning messages
-- but not ones we want removed in this context.
and then (Errors.Table (E).Warn
or else
Errors.Table (E).Warn_Runtime_Raise)
-- Don't remove unconditional messages
and then not Errors.Table (E).Uncond
then
if Errors.Table (E).Warn then
Warnings_Detected := Warnings_Detected - 1;
end if;
if Errors.Table (E).Info then
Warning_Info_Messages := Warning_Info_Messages - 1;
end if;
-- When warning about a runtime exception has been escalated
-- into error, the starting message has increased the total
-- errors counter, so here we decrease this counter.
if Errors.Table (E).Warn_Runtime_Raise
and then not Errors.Table (E).Msg_Cont
and then Warning_Mode = Treat_Run_Time_Warnings_As_Errors
then
Total_Errors_Detected := Total_Errors_Detected - 1;
end if;
return True;
-- No removal required
else
return False;
end if;
end To_Be_Removed;
-- Start of processing for Check_For_Warnings
begin
while To_Be_Removed (First_Error_Msg) loop
First_Error_Msg := Errors.Table (First_Error_Msg).Next;
end loop;
if First_Error_Msg = No_Error_Msg then
Last_Error_Msg := No_Error_Msg;
end if;
E := First_Error_Msg;
while E /= No_Error_Msg loop
while To_Be_Removed (Errors.Table (E).Next) loop
Errors.Table (E).Next :=
Errors.Table (Errors.Table (E).Next).Next;
if Errors.Table (E).Next = No_Error_Msg then
Last_Error_Msg := E;
end if;
end loop;
E := Errors.Table (E).Next;
end loop;
-- Warnings may have been posted on subexpressions of original tree
if Nkind (N) = N_Raise_Constraint_Error
and then Is_Rewrite_Substitution (N)
and then No (Condition (N))
then
Check_All_Warnings (Original_Node (N));
end if;
return OK;
end Check_For_Warning;
-- Start of processing for Remove_Warning_Messages
begin
if Warnings_Detected /= 0 then
Check_All_Warnings (N);
end if;
end Remove_Warning_Messages;
procedure Remove_Warning_Messages (L : List_Id) is
Stat : Node_Id;
begin
Stat := First (L);
while Present (Stat) loop
Remove_Warning_Messages (Stat);
Next (Stat);
end loop;
end Remove_Warning_Messages;
----------------------
-- Adjust_Name_Case --
----------------------
procedure Adjust_Name_Case
(Buf : in out Bounded_String;
Loc : Source_Ptr)
is
Src_Ind : constant Source_File_Index := Get_Source_File_Index (Loc);
Sbuffer : Source_Buffer_Ptr;
Ref_Ptr : Integer;
Src_Ptr : Source_Ptr;
begin
-- We have an all lower case name from Namet, and now we want to set
-- the appropriate case. If possible we copy the actual casing from
-- the source. If not we use standard identifier casing.
Ref_Ptr := 1;
Src_Ptr := Loc;
-- For standard locations, always use mixed case
if Loc <= No_Location then
Set_Casing (Buf, Mixed_Case);
else
-- 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 casing from the source.
Sbuffer := Source_Text (Src_Ind);
while Ref_Ptr <= Buf.Length loop
exit when
Fold_Lower (Sbuffer (Src_Ptr)) /=
Fold_Lower (Buf.Chars (Ref_Ptr));
Ref_Ptr := Ref_Ptr + 1;
Src_Ptr := Src_Ptr + 1;
end loop;
-- If we get through the loop without a mismatch, then output the
-- name the way it is cased in the source program.
if Ref_Ptr > Buf.Length then
Src_Ptr := Loc;
for J in 1 .. Buf.Length loop
Buf.Chars (J) := Sbuffer (Src_Ptr);
Src_Ptr := Src_Ptr + 1;
end loop;
-- Otherwise set the casing using the default identifier casing
else
Set_Casing (Buf, Identifier_Casing (Src_Ind));
end if;
end if;
end Adjust_Name_Case;
---------------------------
-- Set_Identifier_Casing --
---------------------------
procedure Set_Identifier_Casing
(Identifier_Name : System.Address;
File_Name : System.Address)
is
Ident : constant Big_String_Ptr := To_Big_String_Ptr (Identifier_Name);
File : constant Big_String_Ptr := To_Big_String_Ptr (File_Name);
Flen : Natural;
Desired_Case : Casing_Type := Mixed_Case;
-- Casing required for result. Default value of Mixed_Case is used if
-- for some reason we cannot find the right file name in the table.
begin
-- Get length of file name
Flen := 0;
while File (Flen + 1) /= ASCII.NUL loop
Flen := Flen + 1;
end loop;
-- Loop through file names to find matching one. This is a bit slow, but
-- we only do it in error situations so it is not so terrible. Note that
-- if the loop does not exit, then the desired case will be left set to
-- Mixed_Case, this can happen if the name was not in canonical form.
for J in 1 .. Last_Source_File loop
Get_Name_String (Full_Debug_Name (J));
if Name_Len = Flen
and then Name_Buffer (1 .. Name_Len) = String (File (1 .. Flen))
then
Desired_Case := Identifier_Casing (J);
exit;
end if;
end loop;
-- Copy identifier as given to Name_Buffer
for J in Name_Buffer'Range loop
Name_Buffer (J) := Ident (J);
if Name_Buffer (J) = ASCII.NUL then
Name_Len := J - 1;
exit;
end if;
end loop;
Set_Casing (Desired_Case);
end Set_Identifier_Casing;
-----------------------
-- Set_Ignore_Errors --
-----------------------
procedure Set_Ignore_Errors (To : Boolean) is
begin
Errors_Must_Be_Ignored := To;
end Set_Ignore_Errors;
------------------------------
-- 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_Node --
----------------------------
procedure Set_Msg_Insertion_Node is
K : Node_Kind;
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");
elsif Nkind (Error_Msg_Node_1) in N_Entity
and then Ekind (Error_Msg_Node_1) = E_Anonymous_Access_Subprogram_Type
then
Set_Msg_Blank;
Set_Msg_Str ("access to subprogram");
else
Set_Msg_Blank_Conditional;
-- Output name
K := Nkind (Error_Msg_Node_1);
-- If we have operator case, skip quotes since name of operator
-- itself will supply the required quotations. An operator can be an
-- applied use in an expression or an explicit operator symbol, or an
-- identifier whose name indicates it is an operator.
if K in N_Op
or else K = N_Operator_Symbol
or else K = N_Defining_Operator_Symbol
or else ((K = N_Identifier or else K = N_Defining_Identifier)
and then Is_Operator_Name (Chars (Error_Msg_Node_1)))
then
Set_Msg_Node (Error_Msg_Node_1);
-- Normal case, not an operator, surround with quotes
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 further ampersand insertion
-- characters will correspond to the Error_Msg_Node_# parameter.
Error_Msg_Node_1 := Error_Msg_Node_2;
Error_Msg_Node_2 := Error_Msg_Node_3;
Error_Msg_Node_3 := Error_Msg_Node_4;
Error_Msg_Node_4 := Error_Msg_Node_5;
Error_Msg_Node_5 := Error_Msg_Node_6;
end Set_Msg_Insertion_Node;
--------------------------------------
-- Set_Msg_Insertion_Type_Reference --
--------------------------------------
procedure Set_Msg_Insertion_Type_Reference (Flag : Source_Ptr) is
Ent : Entity_Id;
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_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_Unqualified_Decoded_Name_String (Chars (Error_Msg_Node_1));
Set_Msg_Name_Buffer;
return;
elsif Error_Msg_Node_1 = Universal_Integer then
Set_Msg_Str ("type universal integer");
return;
elsif Error_Msg_Node_1 = Universal_Real then
Set_Msg_Str ("type universal real");
return;
elsif Error_Msg_Node_1 = Universal_Fixed then
Set_Msg_Str ("type universal fixed");
return;
elsif Error_Msg_Node_1 = Universal_Access then
Set_Msg_Str ("type universal access");
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;
Ent := Error_Msg_Node_1;
if Is_Internal_Name (Chars (Ent)) then
Unwind_Internal_Type (Ent);
end if;
-- Types in Standard are displayed as "Standard.name"
if Sloc (Ent) <= Standard_Location then
Set_Msg_Quote;
Set_Msg_Str ("Standard.");
Set_Msg_Node (Ent);
Add_Class;
Set_Msg_Quote;
-- Types in other language defined units are displayed as
-- "package-name.type-name"
elsif Is_Predefined_Unit (Get_Source_Unit (Ent)) then
Get_Unqualified_Decoded_Name_String
(Unit_Name (Get_Source_Unit (Ent)));
Name_Len := Name_Len - 2;
Set_Msg_Blank_Conditional;
Set_Msg_Quote;
Set_Casing (Mixed_Case);
Set_Msg_Name_Buffer;
Set_Msg_Char ('.');
Set_Casing (Mixed_Case);
Set_Msg_Node (Ent);
Add_Class;
Set_Msg_Quote;
-- 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, Ent);
Set_Msg_Node (Ent);
Add_Class;
-- If we did not print a name (e.g. in the case of an anonymous
-- subprogram type), there is no name to print, so remove quotes.
if Buffer_Ends_With ('"') then
Buffer_Remove ('"');
else
Set_Msg_Quote;
end if;
end if;
-- If the original type did not come from a predefined file, add the
-- location where the type was defined.
if Sloc (Error_Msg_Node_1) > Standard_Location
and then
not Is_Predefined_Unit (Get_Source_Unit (Error_Msg_Node_1))
then
Get_Name_String (Unit_File_Name (Get_Source_Unit (Error_Msg_Node_1)));
Set_Msg_Str (" defined");
Set_Msg_Insertion_Line_Number (Sloc (Error_Msg_Node_1), Flag);
-- If it did come from a predefined file, deal with the case where
-- this was a file with a generic instantiation from elsewhere.
else
if Sloc (Error_Msg_Node_1) > Standard_Location then
declare
Iloc : constant Source_Ptr :=
Instantiation_Location (Sloc (Error_Msg_Node_1));
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;
end if;
end if;
end Set_Msg_Insertion_Type_Reference;
---------------------------------
-- Set_Msg_Insertion_Unit_Name --
---------------------------------
procedure Set_Msg_Insertion_Unit_Name (Suffix : Boolean := True) is
begin
if Error_Msg_Unit_1 = No_Unit_Name then
null;
elsif Error_Msg_Unit_1 = Error_Unit_Name then
Set_Msg_Blank;
Set_Msg_Str ("<error>");
else
Get_Unit_Name_String (Global_Name_Buffer, Error_Msg_Unit_1, Suffix);
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_Node --
------------------
procedure Set_Msg_Node (Node : Node_Id) is
Loc : Source_Ptr;
Ent : Entity_Id;
Nam : Name_Id;
begin
case Nkind (Node) is
when N_Designator =>
Set_Msg_Node (Name (Node));
Set_Msg_Char ('.');
Set_Msg_Node (Identifier (Node));
return;
when N_Defining_Program_Unit_Name =>
Set_Msg_Node (Name (Node));
Set_Msg_Char ('.');
Set_Msg_Node (Defining_Identifier (Node));
return;
when N_Expanded_Name
| N_Selected_Component
=>
Set_Msg_Node (Prefix (Node));
Set_Msg_Char ('.');
Set_Msg_Node (Selector_Name (Node));
return;
when others =>
null;
end case;
-- The only remaining possibilities are identifiers, defining
-- identifiers, pragmas, and pragma argument associations.
if Nkind (Node) = N_Pragma then
Nam := Pragma_Name (Node);
Loc := Sloc (Node);
-- The other cases have Chars fields
-- First deal with internal names, which generally represent something
-- gone wrong. First attempt: if this is a rewritten node that rewrites
-- something with a Chars field that is not an internal name, use that.
elsif Is_Internal_Name (Chars (Node))
and then Nkind (Original_Node (Node)) in N_Has_Chars
and then not Is_Internal_Name (Chars (Original_Node (Node)))
then
Nam := Chars (Original_Node (Node));
Loc := Sloc (Original_Node (Node));
-- Another shot for internal names, in the case of internal type names,
-- we try to find a reasonable representation for the external name.
elsif 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;
Loc := Sloc (Ent);
-- If the type is the designated type of an access_to_subprogram,
-- then there is no name to provide in the call.
if Ekind (Ent) = E_Subprogram_Type then
return;
-- Otherwise, we will be able to find some kind of name to output
else
Unwind_Internal_Type (Ent);
Nam := Chars (Ent);
end if;
-- If not internal name, or if we could not find a reasonable possible
-- substitution for the internal name, just use name in Chars field.
else
Nam := Chars (Node);
Loc := Sloc (Node);
end if;
-- At this stage, the name to output is in Nam
Get_Unqualified_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;
-- If we still have an internal name, kill the message (will only
-- work if we already had errors!)
if Is_Internal_Name then
Kill_Message := True;
end if;
-- Remaining step is to adjust casing and possibly add 'Class
Adjust_Name_Case (Global_Name_Buffer, Loc);
Set_Msg_Name_Buffer;
Add_Class;
end Set_Msg_Node;
------------------
-- Set_Msg_Text --
------------------
procedure Set_Msg_Text (Text : String; Flag : Source_Ptr) is
C : Character; -- Current character
P : Natural; -- Current index;
procedure Skip_Msg_Insertion_Warning (C : Character);
-- Skip the ? ?? ?x? ?*? ?$? insertion sequences (and the same
-- sequences using < instead of ?). The caller has already bumped
-- the pointer past the initial ? or < and C is set to this initial
-- character (? or <). This procedure skips past the rest of the
-- sequence. We do not need to set Msg_Insertion_Char, since this
-- was already done during the message prescan.
-- No validity check is performed as the insertion sequence is
-- supposed to be sane. See Prescan_Message.Parse_Message_Class in
-- erroutc.adb for the validity checks.
--------------------------------
-- Skip_Msg_Insertion_Warning --
--------------------------------
procedure Skip_Msg_Insertion_Warning (C : Character) is
begin
if P <= Text'Last and then Text (P) = C then
P := P + 1;
elsif P < Text'Last and then Text (P + 1) = C
and then Text (P) in 'a' .. 'z' | 'A' .. 'Z' |
'0' .. '9' | '*' | '$'
then
P := P + 2;
elsif P + 1 < Text'Last and then Text (P + 2) = C
and then Text (P) in '.' | '_'
and then Text (P + 1) in 'a' .. 'z'
then
P := P + 3;
end if;
end Skip_Msg_Insertion_Warning;
-- Start of processing for Set_Msg_Text
begin
Manual_Quote_Mode := False;
Msglen := 0;
Flag_Source := Get_Source_File_Index (Flag);
-- Skip info: at start, we have recorded this in Is_Info_Msg, and this
-- will be used (Info field in error message object) to put back the
-- string when it is printed. We need to do this, or we get confused
-- with instantiation continuations.
if Text'Length > 6
and then Text (Text'First .. Text'First + 5) = "info: "
then
P := Text'First + 6;
else
P := Text'First;
end if;
-- Loop through characters of message
while P <= Text'Last loop
C := Text (P);
P := P + 1;
-- Check for insertion character or sequence
case C is
when '%' =>
if P <= Text'Last and then Text (P) = '%' then
P := P + 1;
Set_Msg_Insertion_Name_Literal;
else
Set_Msg_Insertion_Name;
end if;
when '$' =>
if P <= Text'Last and then Text (P) = '$' then
P := P + 1;
Set_Msg_Insertion_Unit_Name (Suffix => False);
else
Set_Msg_Insertion_Unit_Name;
end if;
when '{' =>
Set_Msg_Insertion_File_Name;
when '}' =>
Set_Msg_Insertion_Type_Reference (Flag);
when '*' =>
Set_Msg_Insertion_Reserved_Name;
when '&' =>
Set_Msg_Insertion_Node;
when '#' =>
Set_Msg_Insertion_Line_Number (Error_Msg_Sloc, Flag);
when '\' =>
Continuation := True;
if P <= Text'Last and then Text (P) = '\' then
Continuation_New_Line := True;
P := P + 1;
end if;
when '@' =>
Set_Msg_Insertion_Column;
when '>' =>
Set_Msg_Insertion_Run_Time_Name;
when '^' =>
Set_Msg_Insertion_Uint;
when '`' =>
Manual_Quote_Mode := not Manual_Quote_Mode;
Set_Msg_Char ('"');
when '!' =>
null; -- already dealt with
when '?' =>
Skip_Msg_Insertion_Warning ('?');
when '<' =>
Skip_Msg_Insertion_Warning ('<');
when '|' =>
null; -- already dealt with
when ''' =>
Set_Msg_Char (Text (P));
P := P + 1;
when '~' =>
Set_Msg_Str (Error_Msg_String (1 .. Error_Msg_Strlen));
-- Upper case letter
when 'A' .. 'Z' =>
-- Start of reserved word if two or more
if P <= Text'Last and then Text (P) in 'A' .. 'Z' then
P := P - 1;
Set_Msg_Insertion_Reserved_Word (Text, P);
-- Single upper case letter is just inserted
else
Set_Msg_Char (C);
end if;
-- '[' (will be/would have been raised at run time)
when '[' =>
-- "[]" (insertion of error code)
if P <= Text'Last and then Text (P) = ']' then
P := P + 1;
Set_Msg_Insertion_Code;
else
-- Switch the message from a warning to an error if the flag
-- -gnatwE is specified to treat run-time exception warnings
-- as errors.
if Is_Warning_Msg
and then Warning_Mode = Treat_Run_Time_Warnings_As_Errors
then
Is_Warning_Msg := False;
Is_Runtime_Raise := True;
end if;
if Is_Warning_Msg then
Set_Msg_Str ("will be raised at run time");
else
Set_Msg_Str ("would have been raised at run time");
end if;
end if;
-- ']' (may be/might have been raised at run time)
when ']' =>
if Is_Warning_Msg then
Set_Msg_Str ("may be raised at run time");
else
Set_Msg_Str ("might have been raised at run time");
end if;
-- Normal character with no special treatment
when others =>
Set_Msg_Char (C);
end case;
end loop;
end Set_Msg_Text;
----------------
-- Set_Posted --
----------------
procedure Set_Posted (N : Node_Id) is
P : Node_Id;
begin
if Is_Serious_Error then
-- 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);
exit when No (P);
Set_Error_Posted (P);
exit when Nkind (P) not in N_Subexpr;
end loop;
if Nkind (P) in N_Pragma_Argument_Association
| N_Component_Association
| N_Discriminant_Association
| N_Generic_Association
| N_Parameter_Association
then
Set_Error_Posted (Parent (P));
end if;
-- A special check, if we just posted an error on an attribute
-- definition clause, then also set the entity involved as posted.
-- For example, this stops complaining about the alignment after
-- complaining about the size, which is likely to be useless.
if Nkind (P) = N_Attribute_Definition_Clause then
if Is_Entity_Name (Name (P)) then
Set_Error_Posted (Entity (Name (P)));
end if;
end if;
end if;
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;
-------------------------------------
-- Should_Ignore_Pragma_SPARK_Mode --
-------------------------------------
function Should_Ignore_Pragma_SPARK_Mode return Boolean is
begin
return Get_Name_Table_Boolean3 (Name_SPARK_Mode);
end Should_Ignore_Pragma_SPARK_Mode;
------------------------
-- Special_Msg_Delete --
------------------------
-- Is it really right to have all this specialized knowledge in errout?
function Special_Msg_Delete
(Msg : String;
N : Node_Or_Entity_Id;
E : Node_Or_Entity_Id) return Boolean
is
begin
-- Never delete messages in -gnatdO mode
if Debug_Flag_OO then
return False;
-- Processing for "Size too small" messages
elsif Is_Size_Too_Small_Message (Msg) then
-- Suppress "size too small" errors in CodePeer mode, since code may
-- be analyzed in a different configuration than the one used for
-- compilation. Even when the configurations match, this message
-- may be issued on correct code, because pragma Pack is ignored
-- in CodePeer mode.
if CodePeer_Mode then
return True;
-- When a size is wrong for a frozen type there is no explicit size
-- clause, and other errors have occurred, suppress the message,
-- since it is likely that this size error is a cascaded result of
-- other errors. The reason we eliminate unfrozen types is that
-- messages issued before the freeze type are for sure OK.
elsif Nkind (N) in N_Entity
and then Is_Frozen (E)
and then Serious_Errors_Detected > 0
and then Nkind (N) /= N_Component_Clause
and then Nkind (Parent (N)) /= N_Component_Clause
and then
No (Get_Attribute_Definition_Clause (E, Attribute_Size))
and then
No (Get_Attribute_Definition_Clause (E, Attribute_Object_Size))
and then
No (Get_Attribute_Definition_Clause (E, Attribute_Value_Size))
then
return True;
end if;
end if;
-- All special tests complete, so go ahead with message
return False;
end Special_Msg_Delete;
-----------------
-- SPARK_Msg_N --
-----------------
procedure SPARK_Msg_N (Msg : String; N : Node_Or_Entity_Id) is
begin
-- If SPARK_Mode is Off, we do not report SPARK legality errors to give
-- the flexibility to opt out of SPARK checking completely. We do the
-- same if pragma Ignore_Pragma (SPARK_Mode) was specified, as a way
-- for tools to ignore SPARK checking even on SPARK code.
if SPARK_Mode /= Off
and then not Should_Ignore_Pragma_SPARK_Mode
then
Error_Msg_N (Msg, N);
end if;
end SPARK_Msg_N;
------------------
-- SPARK_Msg_NE --
------------------
procedure SPARK_Msg_NE
(Msg : String;
N : Node_Or_Entity_Id;
E : Node_Or_Entity_Id)
is
begin
if SPARK_Mode /= Off
and then not Should_Ignore_Pragma_SPARK_Mode
then
Error_Msg_NE (Msg, N, E);
end if;
end SPARK_Msg_NE;
--------------------------
-- Unwind_Internal_Type --
--------------------------
procedure Unwind_Internal_Type (Ent : in out Entity_Id) is
Derived : Boolean := False;
Mchar : Character;
Old_Ent : Entity_Id;
begin
-- 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.
Find : loop
Old_Ent := Ent;
-- Implicit access type, use directly designated type In Ada 2005,
-- the designated type may be an anonymous access to subprogram, in
-- which case we can only point to its definition.
if Is_Access_Type (Ent) then
if Ekind (Ent) = E_Access_Subprogram_Type
or else Ekind (Ent) = E_Anonymous_Access_Subprogram_Type
or else Is_Access_Protected_Subprogram_Type (Ent)
then
Ent := Directly_Designated_Type (Ent);
if not Comes_From_Source (Ent) then
if Buffer_Ends_With ("type ") then
Buffer_Remove ("type ");
end if;
end if;
if Ekind (Ent) = E_Function then
Set_Msg_Str ("access to function ");
elsif Ekind (Ent) = E_Procedure then
Set_Msg_Str ("access to procedure ");
else
Set_Msg_Str ("access to subprogram");
end if;
exit Find;
-- Type is access to object, named or anonymous
else
Set_Msg_Str ("access to ");
Ent := Directly_Designated_Type (Ent);
end if;
-- 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
Buffer_Remove ("type ");
-- Avoid duplication "subtype of subtype of", and also replace
-- "derived from subtype of" simply by "derived from"
if not Buffer_Ends_With ("subtype of ")
and then not Buffer_Ends_With ("derived from ")
then
Set_Msg_Str ("subtype of ");
end if;
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).
else
declare
FST : constant Entity_Id := First_Subtype (Ent);
begin
if not Is_Internal_Name (Chars (FST)) then
Ent := FST;
exit Find;
-- Otherwise use root type
else
if not Derived then
Buffer_Remove ("type ");
-- Test for "subtype of type derived from" which seems
-- excessive and is replaced by "type derived from".
Buffer_Remove ("subtype of");
-- Avoid duplicated "type derived from type derived from"
if not Buffer_Ends_With ("type derived from ") then
Set_Msg_Str ("type derived from ");
end if;
Derived := True;
end if;
end if;
end;
Ent := Etype (Ent);
end if;
-- If we are stuck in a loop, get out and settle for the internal
-- name after all. In this case we set to kill the message if it is
-- not the first error message (we really try hard not to show the
-- dirty laundry of the implementation to the poor user).
if Ent = Old_Ent then
Kill_Message := True;
exit Find;
end if;
-- Get out if we finally found a non-internal name to use
exit Find when not Is_Internal_Name (Chars (Ent));
end loop Find;
if Mchar = '"' then
Set_Msg_Char ('"');
end if;
end Unwind_Internal_Type;
--------------------
-- Warn_Insertion --
--------------------
function Warn_Insertion return String is
begin
if Warning_Msg_Char = "? " then
return "??";
elsif Warning_Msg_Char = " " then
return "?";
elsif Warning_Msg_Char (2) = ' ' then
return '?' & Warning_Msg_Char (1) & '?';
else
return '?' & Warning_Msg_Char & '?';
end if;
end Warn_Insertion;
end Errout;
|