libgpr2_24.0.0_eda3c693/src/lib/gpr2-project-parser.adb

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
--
--  Copyright (C) 2019-2023, AdaCore
--
--  SPDX-License-Identifier: Apache-2.0 WITH LLVM-Exception
--

with Ada.Characters.Conversions;
with Ada.Characters.Handling;
with Ada.Containers;
with Ada.Containers.Vectors;
with Ada.Exceptions;
with Ada.Strings.Fixed;
with Ada.Strings.Maps.Constants;
with Ada.Strings.Wide_Wide_Unbounded;

with GNAT.Regpat;

with Gpr_Parser_Support.Diagnostics;
with Gpr_Parser_Support.Slocs;
with Gpr_Parser_Support.Text;
with Gpr_Parser.Common;

with GPR2.Builtin;
with GPR2.KB;
with GPR2.Message;
with GPR2.Project.Attribute.Set;
with GPR2.Project.Attribute_Index;
with GPR2.Project.Definition;
with GPR2.Project.Pack;
with GPR2.Project.Parser.Registry;
with GPR2.Project.Registry.Attribute;
with GPR2.Project.Registry.Pack;
with GPR2.Project.Tree;
with GPR2.Project.Variable.Set;
with GPR2.Source_Reference.Attribute;
with GPR2.Source_Reference.Identifier;
with GPR2.Source_Reference.Pack;
with GPR2.Source_Reference.Value;

package body GPR2.Project.Parser is

   use Ada.Exceptions;

   use Gpr_Parser.Common;
   use Gpr_Parser_Support.Text;

   package PA renames GPR2.Project.Attribute;
   package PRA renames GPR2.Project.Registry.Attribute;
   package PRP renames GPR2.Project.Registry.Pack;
   package PAI renames GPR2.Project.Attribute_Index;
   package ASU renames Ada.Strings.Unbounded;

   function Is_Builtin_Project_Name (Name : Name_Type) return Boolean is
     (To_Lower (Name) in "project" | "config" | "runtime");

   --  Some helpers routines for the parser

   function Get_Value_Type
     (Node : Single_Tok_Node'Class) return Value_Type;
   --  Returns the Value_Type for the given node

   function Get_Name_Type
     (Node : Single_Tok_Node'Class) return Name_Type
   is
     (Name_Type (Get_Value_Type (Node)));
   --  Returns the Name for the given node

   function Get_Name_Type
     (Node  : Gpr_Node'Class;
      First : Positive := 1;
      Last  : Positive;
      Sep   : String := ".") return Name_Type
       with Pre => Last >= First and then Children_Count (Node) >= Last;
   --  Returns the Name for the given children of given node

   function Get_Filename
     (Node : Single_Tok_Node'Class) return Filename_Type
   is
     (Filename_Type (Get_Value_Type (Node)));
   --  Returns the Name for the given node

   function Present (Node : Gpr_Node'Class) return Boolean is
     (not Node.Is_Null);
   --  Returns True if the Node is present (not null)

   function Get_Source_Reference
     (Path_Name : GPR2.Path_Name.Object;
      Slr       : Gpr_Parser_Support.Slocs.Source_Location_Range)
      return Source_Reference.Object
   is
     (Source_Reference.Object
        (Source_Reference.Create
             (Path_Name.Value,
              Positive (Slr.Start_Line),
              Positive (Slr.Start_Column))));

   function Get_Source_Reference
     (Path_Name : GPR2.Path_Name.Object;
      Node      : Gpr_Node'Class) return Source_Reference.Object
   is
     (Get_Source_Reference (Path_Name, Sloc_Range (Node)));

   function Get_Value_Reference
     (Path_Name : GPR2.Path_Name.Object;
      Slr       : Gpr_Parser_Support.Slocs.Source_Location_Range;
      Value     : Value_Type;
      At_Pos    : Unit_Index := No_Index) return Source_Reference.Value.Object
   is
     (Source_Reference.Value.Object
        (Source_Reference.Value.Create
             (Get_Source_Reference (Path_Name, Slr), Value, At_Pos)));

   function Get_Value_Reference
     (Value        : Value_Type;
      Sloc         : Source_Reference.Object;
      At_Pos       : Unit_Index := No_Index;
      From_Default : Boolean := False) return Source_Reference.Value.Object
   is
     (Source_Reference.Value.Object
        (Source_Reference.Value.Create (Sloc, Value, At_Pos, From_Default)));

   function Get_Identifier_Reference
     (Path_Name  : GPR2.Path_Name.Object;
      Slr        : Gpr_Parser_Support.Slocs.Source_Location_Range;
      Identifier : Name_Type)
      return Source_Reference.Identifier.Object
   is
     (Source_Reference.Identifier.Object
        (Source_Reference.Identifier.Create
             (Get_Source_Reference (Path_Name, Slr), Identifier)));

   function Get_Attribute_Reference
     (Path_Name  : GPR2.Path_Name.Object;
      Slr        : Gpr_Parser_Support.Slocs.Source_Location_Range;
      Identifier : Q_Attribute_Id)
      return Source_Reference.Attribute.Object
   is
     (Source_Reference.Attribute.Object
        (Source_Reference.Attribute.Create
             (Get_Source_Reference (Path_Name, Slr), Identifier)));

   function Get_Raw_Path
     (Node : Single_Tok_Node'Class) return GPR2.Path_Name.Object
   is
     (GPR2.Path_Name.Create_File
        (GPR2.Project.Ensure_Extension (Get_Filename (Node)),
         GPR2.Path_Name.No_Resolution));
   --  Creates project Path_Name.Object not checked for location

   function Get_String_Literal
     (N     : Gpr_Node'Class;
      Error : out Boolean) return Value_Type;
   --  Returns the first string literal found under this node. This is an
   --  helper routine to get strings out of built-in parameters for example.
   --  Set Error to True if the node was not a simple string-literal.

   function Parse_Stage_1
     (Unit          : Analysis_Unit;
      Filename      : GPR2.Path_Name.Object;
      Implicit_With : GPR2.Path_Name.Set.Object;
      Messages      : in out Log.Object) return Object;
   --  Analyzes the project, recording all external references and imports

   -----------------
   -- Clear_Cache --
   -----------------

   procedure Clear_Cache is
   begin
      GPR2.Project.Parser.Registry.Clear_Cache;
   end Clear_Cache;

   --------------
   -- Extended --
   --------------

   function Extended (Self : Object) return GPR2.Project.Import.Object is
   begin
      return Self.Extended;
   end Extended;

   ---------------
   -- Externals --
   ---------------

   function Externals (Self : Object) return Containers.Name_Set is
   begin
      return Self.Externals;
   end Externals;

   -------------------
   -- Get_Name_Type --
   -------------------

   function Get_Name_Type
     (Node  : Gpr_Node'Class;
      First : Positive := 1;
      Last  : Positive;
      Sep   : String := ".") return Name_Type
   is
      Name : ASU.Unbounded_String :=
               ASU.To_Unbounded_String
                 (Ada.Characters.Conversions.To_String
                    (Text (Child (Node, First))));
   begin
      for C in First + 1 .. Last loop
         ASU.Append (Name, Sep);
         ASU.Append
           (Name,
            Ada.Characters.Conversions.To_String (Text (Child (Node, C))));
      end loop;
      return Name_Type (ASU.To_String (Name));
   end Get_Name_Type;

   ------------------------
   -- Get_String_Literal --
   ------------------------

   function Get_String_Literal
     (N     : Gpr_Node'Class;
      Error : out Boolean) return Value_Type
   is
      function Parser (Node : Gpr_Node'Class) return Visit_Status;
      --  Parser for the string-literal tree

      Result : Unbounded_String;

      ------------
      -- Parser --
      ------------

      function Parser (Node : Gpr_Node'Class) return Visit_Status is

         Status : Visit_Status := Into;

         procedure Handle_String (Node : String_Literal)
           with Pre  => Present (Node), Inline;
         --  A simple static string

         -------------------
         -- Handle_String --
         -------------------

         procedure Handle_String (Node : String_Literal) is
         begin
            Result := To_Unbounded_String
              (Unquote (Value_Type (To_UTF8 (Node.Text))));
         end Handle_String;

      begin
         case Kind (Node) is
            when Gpr_String_Literal =>
               Handle_String (Node.As_String_Literal);

            when Gpr_String_Literal_At | Gpr_Base_List =>
               null;

            when others =>
               --  Everything else is an error
               Error := True;
               Status := Over;
         end case;

         return Status;
      end Parser;

   begin
      Error := False;
      Traverse (N, Parser'Access);

      return Value_Type (To_String (Result));
   end Get_String_Literal;

   --------------------
   -- Get_Value_Type --
   --------------------

   function Get_Value_Type
     (Node : Single_Tok_Node'Class) return Value_Type
   is
      use Ada.Characters.Conversions;
      V      : constant Wide_Wide_String := Text (Node);
      Offset : Natural := 0;
   begin
      if V (V'First) = '"' and then V (V'Last) = '"' then
         Offset := 1;
      end if;
      return To_String (V (V'First + Offset .. V'Last - Offset));
   end Get_Value_Type;

   ------------------
   -- Has_Extended --
   ------------------

   function Has_Extended (Self : Object) return Boolean is
   begin
      return Self.Extended.Is_Defined;
   end Has_Extended;

   -------------------
   -- Has_Externals --
   -------------------

   function Has_Externals (Self : Object) return Boolean is
   begin
      return not Self.Externals.Is_Empty;
   end Has_Externals;

   -----------------
   -- Has_Imports --
   -----------------

   function Has_Imports (Self : Object) return Boolean is
   begin
      return not Self.Imports.Is_Empty;
   end Has_Imports;

   -------------
   -- Imports --
   -------------

   function Imports (Self : Object) return GPR2.Project.Import.Set.Object is
   begin
      return Self.Imports;
   end Imports;

   ----------------------
   -- Is_Extending_All --
   ----------------------

   function Is_Extending_All (Self : Object) return Boolean is
   begin
      return Self.Is_All;
   end Is_Extending_All;

   ----------
   -- Name --
   ----------

   function Name (Self : Object) return Name_Type is
   begin
      return Name_Type (To_String (Self.Name));
   end Name;

   -----------
   -- Parse --
   -----------

   function Parse
     (Contents        : Unbounded_String;
      Messages        : in out Log.Object;
      Pseudo_Filename : GPR2.Path_Name.Object := GPR2.Path_Name.Undefined)
      return Object
   is
      use Ada.Characters.Conversions;
      use Ada.Strings.Wide_Wide_Unbounded;

      Filename : constant GPR2.Path_Name.Object :=
                   (if Pseudo_Filename.Is_Defined
                    then Pseudo_Filename
                    else GPR2.Path_Name.Create_File
                           ("/string_input/default.gpr"));
      Context  : constant Analysis_Context := Create_Context ("UTF-8");
      Unit     : Analysis_Unit;
      Project  : Object;
   begin
      if Contents = Null_Unbounded_String then
         Messages.Append
           (GPR2.Message.Create
              (Level   => Message.Error,
               Message => "project string is empty",
               Sloc    => Source_Reference.Create (Filename.Value, 0, 0)));

         return Undefined;
      end if;

      Unit := Get_From_Buffer
        (Context, Filename.Value, Buffer => To_String (Contents));

      if Root (Unit).Is_Null or else Has_Diagnostics (Unit) then
         if Has_Diagnostics (Unit) then
            for D of Diagnostics (Unit) loop
               declare
                  Sloc : constant Source_Reference.Object'Class :=
                           Source_Reference.Create
                             (Filename => Filename.Value,
                              Line     =>
                                Natural (D.Sloc_Range.Start_Line),
                              Column   =>
                                Natural (D.Sloc_Range.Start_Column));
               begin
                  Messages.Append
                    (GPR2.Message.Create
                       (Level   => Message.Error,
                        Sloc    => Sloc,
                        Message =>
                          To_String (To_Wide_Wide_String (D.Message))));
               end;
            end loop;
         end if;

         return Undefined;
      end if;

      --  Do the first stage parsing. We just need the external references
      --  and the project dependencies. This is the minimum to be able to
      --  create the project tree and setup the project context.

      Project := Parse_Stage_1
        (Unit, Filename, GPR2.Path_Name.Set.Empty_Set, Messages);

      --  Then record langkit tree data with project. Those data will be
      --  used for later parsing when creating view of projects with a
      --  full context.

      Project.File    := Filename;
      Project.Unit    := Unit;
      Project.Context := Context;

      --  If this is a configuration project, then we register it under the
      --  "config" name as this is what is expected on this implementation.
      --  That is, referencing the configuration is done using
      --  Config'Archive_Suffix for example.

      if Project.Qualifier = K_Configuration then
         Project.Name := To_Unbounded_String ("Config");
      end if;

      return Project;
   end Parse;

   -----------
   -- Parse --
   -----------

   function Parse
     (Filename      : GPR2.Path_Name.Object;
      Implicit_With : GPR2.Path_Name.Set.Object;
      Messages      : in out Log.Object;
      File_Reader   : Gpr_Parser_Support.File_Readers.File_Reader_Reference :=
                        Gpr_Parser_Support.File_Readers.
                          No_File_Reader_Reference)
      return Object
   is
      use Ada.Characters.Conversions;
      use Ada.Strings.Wide_Wide_Unbounded;

      Context : Analysis_Context :=
                  Create_Context (Charset     => "UTF-8",
                                  File_Reader => File_Reader);
      Unit    : Analysis_Unit;
      Project : Object;

   begin
      if Registry.Check_Project (Filename, Project) then
         return Project;

      else
         if not Filename.Exists then
            Messages.Append
              (GPR2.Message.Create
                 (Level   => Message.Error,
                  Message => "project file """ & Filename.Value &
                             """ not found",
                  Sloc    => Source_Reference.Create (Filename.Value, 0, 0)));
            return Undefined;
         end if;

         Unit := Get_From_File (Context, Filename.Value);

         if Root (Unit).Is_Null or else Has_Diagnostics (Unit) then
            declare
               use Gpr_Parser_Support.Diagnostics;

               Diags_UTF8 : constant Diagnostics_Array := Diagnostics (Unit);
            begin

               --  if UTF-8 encoding issue let's try Windows-1252, a ISO 8859-1
               --  (Latin-1) superset.

               Context := Create_Context (Charset     => "Windows-1252",

                                          File_Reader => File_Reader);
               Unit := Get_From_File (Context, Filename.Value);

               if Root (Unit).Is_Null or else Has_Diagnostics (Unit) then
                  declare
                     Diags : constant Diagnostics_Array :=
                               (if Diags_UTF8'Length > 0
                                then Diags_UTF8
                                else Diagnostics (Unit));
                  begin
                     for D of Diags loop
                        declare
                           Sloc : constant Source_Reference.Object'Class :=
                                    Source_Reference.Create
                                      (Filename => Filename.Value,
                                       Line     =>
                                         Natural (D.Sloc_Range.Start_Line),
                                       Column   =>
                                         Natural (D.Sloc_Range.Start_Column));
                        begin
                           Messages.Append
                             (GPR2.Message.Create
                                (Level   => Message.Error,
                                 Sloc    => Sloc,
                                 Message =>
                                   To_String
                                     (To_Wide_Wide_String (D.Message))));
                        end;
                     end loop;

                     return Undefined;
                  end;
               end if;
            end;
         end if;

         --  Do the first stage parsing. We just need the external references
         --  and the project dependencies. This is the minimum to be able to
         --  create the project tree and setup the project context.

         Project := Parse_Stage_1 (Unit, Filename, Implicit_With, Messages);

         --  Then record langkit tree data with project. Those data will be
         --  used for later parsing when creating view of projects with a
         --  full context.

         Project.File    := Filename;
         Project.Unit    := Unit;
         Project.Context := Context;

         --  If this is a configuration project, then we register it under the
         --  "config" name as this is what is expected on this implementation.
         --  That is, referencing the configuration is done using
         --  Config'Archive_Suffix for example.

         if Project.Qualifier = K_Configuration then
            Project.Name := To_Unbounded_String ("Config");
         end if;

         --  Finally register this project into the registry

         if not Messages.Has_Error then
            Registry.Register (Filename, Project);
         end if;

         return Project;
      end if;
   end Parse;

   -------------------
   -- Parse_Stage_1 --
   -------------------

   function Parse_Stage_1
     (Unit          : Analysis_Unit;
      Filename      : GPR2.Path_Name.Object;
      Implicit_With : GPR2.Path_Name.Set.Object;
      Messages      : in out Log.Object) return Object
   is
      use type GPR2.Path_Name.Object;

      Project : Object;
      --  The project being constructed

      function Parser (Node : Gpr_Node'Class) return Visit_Status;
      --  Actual parser callback for the project

      ------------
      -- Parser --
      ------------

      function Parser (Node : Gpr_Node'Class) return Visit_Status is

         Status : Visit_Status := Into;

         procedure Parse_Project_Declaration (N : Project_Declaration);
         --  Parse a project declaration and set the qualifier if present

         procedure Parse_Builtin (N : Builtin_Function_Call);
         --  Put the name of the external into the Externals list

         procedure Parse_With_Decl (N : With_Decl);
         --  Add the name of the withed project into the Imports list

         procedure Parse_Typed_String_Decl (N : Typed_String_Decl);
         --  A typed string declaration

         -------------------
         -- Parse_Builtin --
         -------------------

         procedure Parse_Builtin (N : Builtin_Function_Call) is

            procedure Parse_External_Reference (N : Builtin_Function_Call);
            --  Put the name of the external into the Externals list

            procedure Parse_External_As_List_Reference
              (N : Builtin_Function_Call);
            --  Put the name of the external into the Externals list

            procedure Parse_Split_Reference (N : Builtin_Function_Call);
            --  Check that split parameters has the proper type

            procedure Parse_Match_Reference (N : Builtin_Function_Call);
            --  Check that split parameters has the proper type

            procedure Parse_One_Parameter_Reference
              (N    : Builtin_Function_Call;
               Name : Name_Type);
            --  Check that lower/upper parameters has the proper type

            procedure Parse_Two_Parameter_Reference
              (N    : Builtin_Function_Call;
               Name : Name_Type);
            --  Check that default/alternative parameters has the proper type

            --------------------------------------
            -- Parse_External_As_List_Reference --
            --------------------------------------

            procedure Parse_External_As_List_Reference
              (N : Builtin_Function_Call)
            is
               Exprs : constant Term_List_List := F_Terms (F_Parameters (N));
            begin
               --  Note that this routine is only validating the syntax
               --  of the external_as_list built-in. It does not add the
               --  variable referenced by the built-in as dependencies
               --  as an external_as_list result cannot be used in a
               --  case statement.

               if Exprs.Is_Null or else Exprs.Children_Count = 0 then
                  Messages.Append
                    (GPR2.Message.Create
                       (Level   => Message.Error,
                        Sloc    => Get_Source_Reference (Filename, N),
                        Message =>
                          "missing parameters for external_as_list"
                        & " built-in"));

               elsif Exprs.Children_Count < 2 then
                     Messages.Append
                       (GPR2.Message.Create
                          (Level   => Message.Error,
                           Sloc    =>
                             Get_Source_Reference (Filename, Exprs),
                           Message =>
                             "external_as_list requires two "
                           & "parameters"));

               elsif Exprs.Children_Count > 2 then
                  Messages.Append
                    (GPR2.Message.Create
                       (Level   => Message.Error,
                        Sloc    =>
                          Get_Source_Reference
                            (Filename, Exprs),
                        Message =>
                          "external_as_list accepts only two parameters"));

               else
                  --  We have External_As_List ("VAR", "SEP"), check the
                  --  variable name.

                  declare
                     Var_Node : constant Term_List :=
                                  Exprs.Child (1).As_Term_List;
                     Error    : Boolean;
                     Var      : constant Value_Type :=
                                  Get_String_Literal (Var_Node, Error);
                  begin
                     if Error then
                        Messages.Append
                          (GPR2.Message.Create
                             (Level   => Message.Error,
                              Sloc    =>
                                Get_Source_Reference (Filename, Var_Node),
                              Message =>
                                "external_as_list first parameter must be "
                              & "a simple string"));

                     elsif Var = "" then
                        Messages.Append
                          (GPR2.Message.Create
                             (Level   => Message.Error,
                              Sloc    =>
                                Get_Source_Reference (Filename, Var_Node),
                              Message =>
                                "external_as_list variable name must not "
                              & "be empty"));
                     end if;
                  end;

                  --  Check that the second parameter exists and is a string

                  declare
                     Sep_Node : constant Term_List :=
                                  Child (Exprs, 2).As_Term_List;
                     Error    : Boolean;
                     Sep      : constant Value_Type :=
                                  Get_String_Literal (Sep_Node, Error);
                  begin
                     if Error then
                        Messages.Append
                          (GPR2.Message.Create
                             (Level   => Message.Error,
                              Sloc    =>
                                Get_Source_Reference
                                  (Filename, Sep_Node),
                              Message =>
                                "external_as_list second parameter must "
                                & "be a simple string"));

                     elsif Sep = "" then
                        Messages.Append
                          (GPR2.Message.Create
                             (Level   => Message.Error,
                              Sloc    =>
                                Get_Source_Reference
                                  (Filename, Sep_Node),
                              Message =>
                                "external_as_list separator must not "
                              & "be empty"));
                     end if;
                  end;
               end if;
            end Parse_External_As_List_Reference;

            ------------------------------
            -- Parse_External_Reference --
            ------------------------------

            procedure Parse_External_Reference (N : Builtin_Function_Call) is
               Exprs : constant Term_List_List := F_Terms (F_Parameters (N));
            begin
               if Exprs.Is_Null or else Exprs.Children_Count = 0 then
                  Messages.Append
                    (GPR2.Message.Create
                       (Level   => Message.Error,
                        Sloc    => Get_Source_Reference (Filename, N),
                        Message =>
                          "missing parameter for external built-in"));

               elsif Exprs.Children_Count > 2 then
                     Messages.Append
                       (GPR2.Message.Create
                          (Level   => Message.Error,
                           Sloc    =>
                             Get_Source_Reference (Filename, Exprs),
                           Message =>
                             "external built-in accepts at most two "
                             & "parameters."));

               else
                  --  We have External ("VAR" [, "VALUE"]), get the
                  --  variable name.

                  declare
                     Var_Node : constant Term_List :=
                                  Child (Exprs, 1).As_Term_List;
                     Error    : Boolean;
                     Var      : constant Value_Type :=
                                  Get_String_Literal (Var_Node, Error);
                  begin
                     if Error then
                        Messages.Append
                          (GPR2.Message.Create
                             (Level   => Message.Error,
                              Sloc    =>
                                Get_Source_Reference (Filename, Var_Node),
                              Message =>
                                "external first parameter must be a "
                              & "simple string"));

                     elsif Var = "" then
                        Messages.Append
                          (GPR2.Message.Create
                             (Level   => Message.Error,
                              Sloc    =>
                                Get_Source_Reference (Filename, Var_Node),
                              Message =>
                                "external variable name must not be "
                              & "empty"));

                     else
                        Project.Externals.Include (Optional_Name_Type (Var));

                        declare
                           Node : Gpr_Node := Exprs.Child (2);
                        begin
                           if not Node.Is_Null then
                              Node := Node.Child (1);

                              if not Node.Is_Null
                                and then Node.Kind = Gpr_Builtin_Function_Call
                              then
                                 Parse_Builtin (Node.As_Builtin_Function_Call);
                              end if;
                           end if;
                        end;
                     end if;
                  end;
               end if;
            end Parse_External_Reference;

            ---------------------------
            -- Parse_Match_Reference --
            ---------------------------

            procedure Parse_Match_Reference (N : Builtin_Function_Call) is
               Exprs : constant Term_List_List := F_Terms (F_Parameters (N));
            begin
               --  Note that this routine is only validating the syntax
               --  of the split built-in.

               if Exprs.Is_Null or else Exprs.Children_Count = 0 then
                  Messages.Append
                    (GPR2.Message.Create
                       (Level   => Message.Error,
                        Sloc    => Get_Source_Reference (Filename, N),
                        Message => "missing parameters for match built-in"));

               --  Check that the second parameter exists

               elsif Exprs.Children_Count < 2 then
                  Messages.Append
                    (GPR2.Message.Create
                       (Level   => Message.Error,
                        Sloc    => Get_Source_Reference (Filename, Exprs),
                        Message => "match requires a second parameter"));

               --  Check that we don't have more than two parameters

               elsif Exprs.Children_Count > 3 then
                  Messages.Append
                    (GPR2.Message.Create
                       (Level   => Message.Error,
                        Sloc    =>
                          Get_Source_Reference (Filename, Exprs),
                        Message =>
                          "match accepts a maximum of three parameters"));
               end if;
            end Parse_Match_Reference;

            -----------------------------------
            -- Parse_One_Parameter_Reference --
            -----------------------------------

            procedure Parse_One_Parameter_Reference
              (N    : Builtin_Function_Call;
               Name : Name_Type)
            is
               Exprs : constant Term_List_List := F_Terms (F_Parameters (N));
            begin
               --  Note that this routine is only validating the syntax
               --  of the split built-in.

               if Exprs.Is_Null or else Exprs.Children_Count = 0 then
                  Messages.Append
                    (GPR2.Message.Create
                       (Level   => Message.Error,
                        Sloc    => Get_Source_Reference (Filename, N),
                        Message => "missing parameters for "
                                    & String (Name) & "  built-in"));

               --  Check that we don't have more than two parameters

               elsif Exprs.Children_Count > 1 then
                  Messages.Append
                    (GPR2.Message.Create
                       (Level   => Message.Error,
                        Sloc    =>
                          Get_Source_Reference (Filename, Exprs),
                        Message =>
                          String (Name) & " accepts only one parameter"));
               end if;
            end Parse_One_Parameter_Reference;

            ---------------------------
            -- Parse_Split_Reference --
            ---------------------------

            procedure Parse_Split_Reference (N : Builtin_Function_Call) is
               Exprs : constant Term_List_List := F_Terms (F_Parameters (N));
            begin
               --  Note that this routine is only validating the syntax
               --  of the split built-in.

               if Exprs.Is_Null or else Exprs.Children_Count = 0 then
                  Messages.Append
                    (GPR2.Message.Create
                       (Level   => Message.Error,
                        Sloc    => Get_Source_Reference (Filename, N),
                        Message => "missing parameters for split built-in"));

               --  Check that the second parameter exists

               elsif Exprs.Children_Count = 1 then
                  Messages.Append
                    (GPR2.Message.Create
                       (Level   => Message.Error,
                        Sloc    => Get_Source_Reference (Filename, Exprs),
                        Message => "split requires a second parameter"));

               --  Check that we don't have more than two parameters

               elsif Exprs.Children_Count > 2 then
                  Messages.Append
                    (GPR2.Message.Create
                       (Level   => Message.Error,
                        Sloc    =>
                          Get_Source_Reference (Filename, Exprs),
                        Message =>
                          "split accepts only two parameters"));
               end if;
            end Parse_Split_Reference;

            -----------------------------------
            -- Parse_Two_Parameter_Reference --
            -----------------------------------

            procedure Parse_Two_Parameter_Reference
              (N    : Builtin_Function_Call;
               Name : Name_Type)
            is
               Exprs : constant Term_List_List := F_Terms (F_Parameters (N));
            begin
               --  Note that this routine is only validating the syntax
               --  of the split built-in.

               if Exprs.Is_Null or else Exprs.Children_Count < 2 then
                  Messages.Append
                    (GPR2.Message.Create
                       (Level   => Message.Error,
                        Sloc    => Get_Source_Reference (Filename, N),
                        Message => "missing parameters for "
                                    & String (Name) & "  built-in"));

               --  Check that we don't have more than two parameters

               elsif Exprs.Children_Count > 2 then
                  Messages.Append
                    (GPR2.Message.Create
                       (Level   => Message.Error,
                        Sloc    =>
                          Get_Source_Reference (Filename, Exprs),
                        Message =>
                          String (Name) & " accepts only two parameters"));
               end if;
            end Parse_Two_Parameter_Reference;

            Function_Name : constant Name_Type :=
                              Get_Name_Type (F_Function_Name (N));
         begin
            if Function_Name = "external" then
               Parse_External_Reference (N);

            elsif Function_Name = "external_as_list" then
               Parse_External_As_List_Reference (N);

            elsif Function_Name = "split" then
               Parse_Split_Reference (N);

            elsif Function_Name = "lower" then
               Parse_One_Parameter_Reference (N, "lower");

            elsif Function_Name = "upper" then
               Parse_One_Parameter_Reference (N, "upper");

            elsif Function_Name = "match" then
               Parse_Match_Reference (N);

            elsif Function_Name = "default" then
               Parse_Two_Parameter_Reference (N, "default");

            elsif Function_Name = "alternative" then
               Parse_Two_Parameter_Reference (N, "alternative");

            elsif Function_Name = "item_at" then
               Parse_Two_Parameter_Reference (N, "item_at");

            elsif Function_Name = "filter_out" then
               Parse_Two_Parameter_Reference (N, "filter_out");

            elsif Function_Name = "remove_prefix" then
               Parse_Two_Parameter_Reference (N, "remove_prefix");

            elsif Function_Name = "remove_suffix" then
               Parse_Two_Parameter_Reference (N, "remove_suffix");

            else
               Messages.Append
                 (GPR2.Message.Create
                    (Level   => Message.Error,
                     Sloc    => Get_Source_Reference (Filename, N),
                     Message =>
                       "unknown built-in """
                     & String (Function_Name) & '"'));
            end if;
         end Parse_Builtin;

         -------------------------------
         -- Parse_Project_Declaration --
         -------------------------------

         procedure Parse_Project_Declaration (N : Project_Declaration) is
            Qual : constant Project_Qualifier := F_Qualifier (N);
            Ext  : constant Project_Extension := F_Extension (N);
         begin
            Project.Name := To_Unbounded_String
              (To_UTF8 (F_Project_Name (N).Text));

            --  Check that project name is consistent with the end declaration

            if Name (Project) /= Name_Type (To_UTF8 (F_End_Name (N).Text)) then
               Messages.Append
                 (GPR2.Message.Create
                    (Level   => Message.Error,
                     Sloc    =>
                       Get_Source_Reference (Filename, F_End_Name (N)),
                     Message =>
                       "'end " & String (Name (Project)) & "' expected"));
            end if;

            --  If we have an explicit qualifier parse it now. If not the
            --  kind of project will be determined later during a second
            --  pass.

            if Present (Qual) then
               Project.Expl_Qual := True;
               Project.Qualifier :=
                 (case Kind (Qual) is
                     when Gpr_Project_Qualifier_Abstract
                       => K_Abstract,
                     when Gpr_Project_Qualifier_Standard
                       => K_Standard,
                     when Gpr_Project_Qualifier_Library
                       => K_Library,
                     when Gpr_Project_Qualifier_Aggregate
                       => K_Aggregate,
                     when Gpr_Project_Qualifier_Aggregate_Library
                       => K_Aggregate_Library,
                     when Gpr_Project_Qualifier_Configuration
                       => K_Configuration,
                     when others
                       => raise Program_Error with "Unreachable");
            end if;

            --  Check if we have an extends declaration

            if Present (Ext) then
               Project.Extended :=
                 GPR2.Project.Import.Create
                   (Get_Raw_Path (F_Path_Name (Ext)),
                    Get_Source_Reference (Filename, Ext),
                    Is_Limited => False);
               Project.Is_All := F_Is_All (Ext);
            end if;
         end Parse_Project_Declaration;

         -----------------------------
         -- Parse_Typed_String_Decl --
         -----------------------------

         procedure Parse_Typed_String_Decl (N : Typed_String_Decl) is
            Name       : constant Name_Type :=
                           Get_Name_Type (F_Type_Id (N));
            Values     : constant String_Literal_List :=
                           F_String_Literals (N);
            Num_Childs : constant Natural := Children_Count (Values);
            Cur_Child  : Gpr_Node;
            Set        : Containers.Value_Set;
            List       : Containers.Source_Value_List;
         begin
            if Project.Types.Contains (Name) then
               Messages.Append
                 (GPR2.Message.Create
                    (Level   => Message.Error,
                     Sloc    =>
                       Get_Source_Reference (Filename, F_Type_Id (N)),
                     Message =>
                       "type """ & String (Name) & """ already defined"));

            else
               for J in 1 .. Num_Childs loop
                  Cur_Child := Child (Gpr_Node (Values), J);

                  if not Cur_Child.Is_Null then
                     declare
                        Value : constant Value_Type :=
                                  Get_Value_Type
                                    (Cur_Child.As_String_Literal);
                     begin
                        if Set.Contains (Value) then
                           Messages.Append
                             (GPR2.Message.Create
                                (Level   => Message.Error,
                                 Sloc    =>
                                   Get_Source_Reference
                                     (Filename, Cur_Child),
                                 Message =>
                                   '"' & String (Name)
                                 & """ has duplicate value """
                                 & String (Value) & '"'));
                        else
                           Set.Insert (Value);
                           List.Append
                             (Get_Value_Reference
                                (Filename, Sloc_Range (Cur_Child), Value));
                        end if;
                     end;
                  end if;
               end loop;

               Project.Types.Insert
                 (Name,
                  GPR2.Project.Typ.Create
                    (Get_Identifier_Reference
                         (Filename, Sloc_Range (F_Type_Id (N)), Name), List));
            end if;
         end Parse_Typed_String_Decl;

         ---------------------
         -- Parse_With_Decl --
         ---------------------

         procedure Parse_With_Decl (N : With_Decl) is
            Path_Names : constant String_Literal_List :=
                           F_Path_Names (N);
            Num_Childs : constant Natural := Children_Count (Path_Names);
            Cur_Child  : Gpr_Node;
         begin
            for J in 1 .. Num_Childs loop
               Cur_Child := Child (Gpr_Node (Path_Names), J);

               declare
                  Path : constant GPR2.Path_Name.Object :=
                           Get_Raw_Path (Cur_Child.As_String_Literal);
                  CI   : constant GPR2.Project.Import.Set.Cursor :=
                           Project.Imports.Find (Path);
               begin
                  if GPR2.Project.Import.Set.Has_Element (CI) then
                     declare
                        Prev : constant GPR2.Project.Import.Object :=
                                 GPR2.Project.Import.Set.Element (CI);
                     begin
                        if Prev.Path_Name = Path then
                           Messages.Append
                             (GPR2.Message.Create
                                (Level   => Message.Warning,
                                 Message => "duplicate with clause """
                                 & String (Path.Base_Name) & '"',
                                 Sloc    => Get_Source_Reference
                                   (Filename, Cur_Child)));

                        else
                           Messages.Append
                             (GPR2.Message.Create
                                (Level   => Message.Warning,
                                 Message => "duplicate project name """
                                 & String (Path.Base_Name) & '"',
                                 Sloc    => Get_Source_Reference
                                   (Filename, Cur_Child)));
                           Messages.Append
                             (GPR2.Message.Create
                                (Level   => Message.Warning,
                                 Message => "already in """
                                 & String (Prev.Path_Name.Name)
                                 & '"',
                                 Sloc    => Get_Source_Reference
                                   (Filename, Cur_Child)));
                        end if;
                     end;

                  else
                     Project.Imports.Insert
                       (GPR2.Project.Import.Create
                          (Path,
                           Get_Source_Reference (Filename, Cur_Child),
                           F_Is_Limited (N)));
                  end if;
               end;
            end loop;
         end Parse_With_Decl;

      begin
         case Kind (Node) is
            when Gpr_Project_Declaration =>
               Parse_Project_Declaration (Node.As_Project_Declaration);

            when Gpr_Builtin_Function_Call =>
               Parse_Builtin (Node.As_Builtin_Function_Call);
               Status := Over;

            when Gpr_With_Decl =>
               Parse_With_Decl (Node.As_With_Decl);
               Status := Over;

            when Gpr_Typed_String_Decl =>
               Parse_Typed_String_Decl (Node.As_Typed_String_Decl);
               Status := Over;

            when others =>
               null;
         end case;

         return Status;
      end Parser;

   begin
      Traverse (Root (Unit), Parser'Access);

      --  Import --implicit-with options

      for PN of Implicit_With loop
         if PN /= Filename
           and then not Project.Imports.Contains (PN)
         then
            Project.Imports.Insert
              (GPR2.Project.Import.Create
                 (PN,
                  Source_Reference.Object
                    (Source_Reference.Create (Filename.Value, 0, 0)),
                  Is_Limited => True));
         end if;
      end loop;

      return Project;
   end Parse_Stage_1;

   ---------------
   -- Path_Name --
   ---------------

   function Path_Name (Self : Object) return GPR2.Path_Name.Object is
   begin
      return Self.File;
   end Path_Name;

   -------------
   -- Process --
   -------------

   procedure Process
     (Self          : in out Object;
      Tree          : in out GPR2.Project.Tree.Object;
      Context       : GPR2.Context.Object;
      View          : GPR2.Project.View.Object;
      Pre_Conf_Mode : Boolean := False;
      Ext_Conf_Mode : Boolean := False)
   is

      type Indexed_Values is record
         Index  : GPR2.Project.Attribute_Index.Object;
         Values : Containers.Source_Value_List;
         Single : Boolean := False;
      end record
        with Dynamic_Predicate =>
          not PAI."=" (Indexed_Values.Index, PAI.Undefined)
            and then (if Indexed_Values.Single
                        then Indexed_Values.Values.Length = 1);

      package Indexed_Item_Values_Vectors is new Ada.Containers.Vectors
        (Index_Type => Positive, Element_Type => Indexed_Values);

      type Indexed_Item_Values is record
         Filled         : Boolean := False;
         Attribute_Name : Q_Optional_Attribute_Id := No_Attribute_Id;
         Values         : Indexed_Item_Values_Vectors.Vector;
      end record;

      type Item_Values is record
         Values         : Containers.Source_Value_List;
         Single         : Boolean := False;
         Indexed_Values : Indexed_Item_Values;
      end record
        with Dynamic_Predicate =>
          (if Item_Values.Single then Item_Values.Values.Length <= 1);
      --  Indexed_Values is filled only in Get_Attribute_Ref when attribute
      --  allows index and index is not provided in the reference.

      function To_Set
        (Values : Containers.Source_Value_List) return Containers.Value_Set;
      --  Creates a set for fast searching from a list of values

      Unfilled_Indexed_Values : constant Indexed_Item_Values := (others => <>);

      Empty_Item_Values : constant Item_Values := (others => <>);
      No_Values         : constant Item_Values := (Single => True,
                                                   others => <>);

      function Missing_Project_Error_Level return Message.Level_Value is
        (if Pre_Conf_Mode then Message.Warning else Message.Error);
      --  Returns expected level for missing import messages

      function Ensure_Source_Loc
        (Values : Containers.Source_Value_List;
         Sloc   : Source_Reference.Object)
         return Containers.Source_Value_List;
      --  Ensures the values have the proper Source_Loc

      function Parser (Node : Gpr_Node'Class) return Visit_Status;
      --  Actual parser callback for the project

      function Get_Variable_Values
        (Node : Variable_Reference) return Item_Values;
      --  Parses and returns the values for the given variable/attribute
      --  reference.

      function Get_Attribute_Index
        (Node : Attribute_Reference;
         Pack : Package_Id := Project_Level_Scope) return PAI.Object;
      --  Gets the attribute index, if any, or PAI.Undefined

      function Get_Attribute_Ref
        (Project : Name_Type;
         Node    : Attribute_Reference;
         Pack    : Package_Id := Project_Level_Scope) return Item_Values;
      --  Returns the value for an attribute reference in the given project
      --  and possibly the given package.

      function Get_Variable_Ref
        (Variable   : Name_Type;
         Source_Ref : Source_Reference.Object;
         Project    : Optional_Name_Type := No_Name;
         Pack       : Package_Id := Project_Level_Scope;
         From_View  : GPR2.Project.View.Object := GPR2.Project.View.Undefined)
         return Item_Values;
      --  Returns the value for a variable reference in the given project
      --
      --  Variable:   the variable name to retrieve
      --  Source_Ref: the location of the variable reference
      --  Project:    the project name in which to look for the variable
      --              if No_Name it lookup is done in From_View
      --  Pack:       the package in which which to look for the variable. If
      --              No_Name it assumes the variable is declared at top-level
      --  From_View:  the reference view from where to start the search. If
      --              set to Undefined search starts from the currently
      --              processed view.

      function Is_Limited_Import
        (Self : Object; Project : Name_Type) return Boolean;
      --  Returns True if the given project exists and is made visible through
      --  a limited import clause.

      function Get_Term_List (Node : Term_List) return Item_Values;
      --  Parses a list of value or a single value as found in an attribute.
      --  Single is set to True if we have a single value. It is false if we
      --  have parsed an expression list. In this later case it does not mean
      --  that we are retuning multiple values, just that the expression is a
      --  list surrounded by parentheses.

      procedure Record_Attribute
        (Set : in out PA.Set.Object;
         A   : PA.Object);
      --  Records an attribute into the given set. At the same time we
      --  increment the Empty_Attribute_Count if this attribute has an empty
      --  value. This is used to check whether we need to reparse the tree.

      function Has_Error return Boolean is
        (Tree.Log_Messages.Has_Error);

      View_Def    : GPR2.Project.Definition.Ref renames
                      Definition.Get (View);
      Attrs       : GPR2.Project.Attribute.Set.Object renames View_Def.Attrs;
      Vars        : GPR2.Project.Variable.Set.Object  renames View_Def.Vars;
      Packs       : GPR2.Project.Pack.Set.Map         renames View_Def.Packs;
      Types       : GPR2.Project.Typ.Set.Object       renames View_Def.Types;
      --  Easy access to the view's attributes, variables, packs and type
      --  definitions.
      --  Side note: unfortunately, for convenience we need to have View as
      --  an "in" parameter, while we obviously need to modify it. Working
      --  with "in out" would prevent usage of this function with return
      --  values (such as calling
      --  Parser.Process (Configuration.Corresponding_View)).
      --  View being just a ref, we can copy the ref and then use it to get
      --  the rw definition.

      Actual      : Containers.Filename_Set;
      --  Naming exception source filenames from active case alternatives

      Case_Values : Containers.Value_List;
      --  The case-values to match against the case-item. Each time a case
      --  statement is entered the value for the case is prepended into this
      --  vector. The first value is then removed when exiting from the case
      --  statement. This is to support nested case statements.
      --  First character in each element mean is the case-item is open or
      --  closed. Other characters contain case value.

      In_Pack     : Boolean := False;
      Pack_Name   : Package_Id := Project_Level_Scope;
      Pack_Ref    : access GPR2.Project.Pack.Object;
      --  Package-oriented state, when parsing is in a package In_Pack is
      --  set and Pack_Name contains the name of the package and Pack_Ref
      --  will point to the view's package object.

      Non_Fatal_Error : GPR2.Log.Object;
      --  Store non fatal errors that we record while parsing. This avoids
      --  stopping the parsing at the first error.

      function Is_Open return Boolean is
        (Case_Values.Is_Empty
         or else (for all CV of Case_Values => CV (1) = '+'));
      --  Is_Open is a parsing barrier, it is True when whole parsing can be
      --  conducted and False otherwise. When it is False the naming exceptions
      --  source filenames collected into Object.Skip_Src container to ignore
      --  at the Update_Sources stage. When it is True, the entire parsing
      --  processes and naming exception source filenames collected into Actual
      --  to remove it from Object.Skip_Src at the end of parsing.

      -----------------------
      -- Ensure_Source_Loc --
      -----------------------

      function Ensure_Source_Loc
        (Values : Containers.Source_Value_List;
         Sloc   : Source_Reference.Object) return Containers.Source_Value_List
      is
         New_List : Containers.Source_Value_List;
      begin
         for V of Values loop
            New_List.Append
              (Source_Reference.Value.Object
                 (Source_Reference.Value.Create
                    (Sloc         => Sloc,
                     Text         => V.Text,
                     At_Pos       => (if V.Has_At_Pos then V.At_Pos else 0),
                     From_Default => V.Is_From_Default)));
         end loop;

         return New_List;
      end Ensure_Source_Loc;

      -------------------------
      -- Get_Attribute_Index --
      -------------------------

      function Get_Attribute_Index
        (Node : Attribute_Reference;
         Pack : Package_Id := Project_Level_Scope) return PAI.Object
      is
         Name   : constant Attribute_Id :=
                    +Get_Name_Type (Single_Tok_Node (F_Attribute_Name (Node)));
         I_Node : constant Gpr_Node := F_Attribute_Index (Node);
         Q_Name : constant Q_Attribute_Id := (Pack, Name);
      begin
         if not Present (I_Node) then
            return PAI.Undefined;
         end if;

         if I_Node.Kind in Gpr_Others_Designator_Range then
            return PAI.I_Others;
         end if;

         declare
            Index : constant Value_Type :=
                      Get_Value_Type (I_Node.As_Single_Tok_Node);
         begin
            return
              PAI.Create
                 (Index,
                  Case_Sensitive =>
                    (if PRA.Exists (Q_Name)
                     then PRA.Is_Case_Sensitive (Index,
                                                 PRA.Get (Q_Name).Index_Type)
                     else True));
         end;
      end Get_Attribute_Index;

      -----------------------
      -- Get_Attribute_Ref --
      -----------------------

      function Get_Attribute_Ref
        (Project : Name_Type;
         Node    : Attribute_Reference;
         Pack    : Package_Id := Project_Level_Scope) return Item_Values
      is
         use type GPR2.Project.View.Object;
         use type PRA.Index_Value_Type;
         use type PRA.Value_Kind;
         use PAI;

         Sloc         : constant Source_Reference.Object :=
                          Get_Source_Reference (Self.File, Node);
         Name         : constant Attribute_Id :=
                          +Get_Name_Type
                            (Single_Tok_Node (F_Attribute_Name (Node)));
         Q_Name       : constant Q_Attribute_Id := (Pack, Name);
         Def          : constant PRA.Def := (if PRA.Exists (Q_Name)
                                             then PRA.Get (Q_Name)
                                             else PRA.Def'(others => <>));

         Index        : constant PAI.Object :=
                          Get_Attribute_Index (Node, Pack);
         Project_View : constant GPR2.Project.View.Object :=
                          (if Project = "Project" or else Project = View.Name
                           then View
                           else Process.View.View_For (Project));

         Attr         : PA.Object;

         Indexed_Values : Indexed_Item_Values := Unfilled_Indexed_Values;

         procedure Fill_Indexed_Values
           (View : GPR2.Project.View.Object;
            Pack : Package_Id);
         --  fill Indexed_Values if Index is undefined and Q_Name allows Index

         -------------------------
         -- Fill_Indexed_Values --
         -------------------------

         procedure Fill_Indexed_Values
           (View : GPR2.Project.View.Object;
            Pack : Package_Id)
         is
            Q_Name : constant Q_Attribute_Id := (Pack, Name);

            use Indexed_Item_Values_Vectors;
            use PRA;
         begin
            if Index = PAI.Undefined
              and then  Def.Index_Type /= PRA.No_Index
            then
               Indexed_Values.Filled := True;
               Indexed_Values.Attribute_Name := Q_Name;

               if View.Is_Defined then
                  for Attribute of View.Attributes (Q_Name) loop
                     Indexed_Values.Values.Append
                       ((Index  => Attribute.Index,
                         Values => Attribute.Values,
                         Single => Attribute.Kind = PRA.Single), 1);
                  end loop;
               end if;
            end if;
         end Fill_Indexed_Values;

      begin
         --  We do not want to have a reference to a limited import, we do not
         --  check when a special project reference is found Project'Name or
         --  Config'Name.

         if not Is_Builtin_Project_Name (Project)
           and then Is_Limited_Import (Self, Project)
         then
            Tree.Log_Messages.Append
              (Message.Create
                 (Message.Error,
                  "cannot have a reference to a limited project",
                  Get_Source_Reference (Self.File, Node)));

            return No_Values;
         end if;

         --  For a project/attribute reference we need to check the attribute
         --  definition to know whether the result is multi-valued or not.

         if not PRA.Exists (Q_Name) then
            if not In_Pack
              or else PRP.Exists (Pack_Name)
            then
               --  Ignore case where we know nothing about the currently parsed
               --  package.

               --  Unknown package name
               if not PRP.Exists (Q_Name.Pack) then
                  Tree.Log_Messages.Append
                    (Message.Create
                       (Message.Error,
                        "unknown package or project """ &
                          Image (Q_Name.Pack) & '"',
                        Get_Source_Reference (Self.File, Node)));

               else
                  Tree.Log_Messages.Append
                    (Message.Create
                       (Message.Error,
                        "undefined attribute """ & Image (Q_Name) &
                          '"',
                        Get_Source_Reference (Self.File, Node)));
               end if;
            end if;

            return No_Values;
         end if;

         if Index.Is_Defined and then Def.Index_Type = PRA.No_Index then
            Tree.Log_Messages.Append
              (Message.Create
                 (Message.Error,
                  "attribute """ & Image (Q_Name) & """ cannot have index",
                  Get_Source_Reference (Self.File, Node)));

            return No_Values;
         end if;

         --  If the attribute is not found or not yet resolved we need
         --  to ensure that the Values list respect the post
         --  condition. That is, a Single result must contain a single
         --  element.

         if Project_View.Is_Defined then
            Attr := Project_View.Attribute
                      (Name  => (Pack, Name), Index => Index);
            Fill_Indexed_Values (Project_View, Pack);

            --  Some top-level attribute specific processing
            if Pack = Project_Level_Scope then
               if Attr.Is_Defined then
                  if Project_View = View
                    and then Def.Is_Toolchain_Config
                    and then not Attr.Is_Frozen
                  then
                     Attr.Freeze;
                     Attrs.Include (Attr);
                  end if;

               elsif Indexed_Values.Filled
                 and then not Indexed_Values.Values.Is_Empty
               then
                  --  Full associative array values filled, no default to
                  --  create.
                  null;

                  --  Special case for built-in Canonical_Target and for
                  --  Runtime, that is at the minimum empty
               elsif Name = PRA.Canonical_Target.Attr then
                  --  Project'Target case
                  Attr := PA.Create
                    (Get_Attribute_Reference
                       (Self.Path_Name, Sloc_Range (Node),
                        (Project_Level_Scope, Name)),
                     Value   => Get_Value_Reference
                       (Value_Not_Empty (Tree.Target (Canonical => True)),
                        Sloc),
                     Default => True,
                     Frozen  => True);

               elsif Name = PRA.Runtime.Attr then
                  if Index /= PAI.Undefined then
                     --  Project'Runtime (<lang>)
                     Attr := PA.Create
                       (Get_Attribute_Reference
                          (Self.Path_Name,
                           Sloc_Range (Node),
                           (Project_Level_Scope, Name)),
                        Index   => Index,
                        Value   => Get_Value_Reference ("", Sloc),
                        Default => True,
                        Frozen  => True);
                  else
                     Indexed_Values.Attribute_Name :=
                       (Project_Level_Scope, Name);
                     Indexed_Values.Filled         := True;
                  end if;
               end if;
            end if;

            if not Attr.Is_Defined
              and then not Indexed_Values.Filled
              and then Def.Value /= PRA.Single
            then
               --  When no default is defined, lists are created empty.
               --  This allows the common pattern:
               --  My_List := ("new", "values") & Project'My_List

               Attr := GPR2.Project.Attribute.Create
                         (Source_Reference.Attribute.Object
                            (Source_Reference.Attribute.Create
                                 (Source_Reference.Builtin,
                                  (Project_Level_Scope, Name))),
                          Index   => Index,
                          Values  =>
                            Containers.Source_Value_Type_List.Empty_Vector,
                          Default => True);
            end if;

            if not Attr.Is_Defined then
               if Pack /= Project_Level_Scope
                 and then not Project_View.Has_Package (Pack)
               then
                  Tree.Log_Messages.Append
                    (Message.Create
                       (Message.Error,
                        "package """ & Image (Pack)
                        & """ not declared in project """
                        & String (Project) & '"',
                        Get_Source_Reference (Self.File, Node)));

               elsif not Indexed_Values.Filled
                 or else Indexed_Values.Values.Is_Empty
               then
                  Tree.Log_Messages.Append
                    (Message.Create
                       (Message.Error,
                        "undefined attribute """ &
                        (if Pack = Project_Level_Scope then ""
                         else Image (Pack) & "'") &
                          Image (Name) &
                          (if Index /= PAI.Undefined
                           then " (""" & Index.Text & """)"
                           else "") &
                          '"',
                        Get_Source_Reference (Self.File, Node)));
               end if;
            end if;

         elsif Project /= "Config" then
            --  Config project can be undefined at this stage

            Tree.Log_Messages.Append
              (Message.Create
                 (Missing_Project_Error_Level,
                  "undefined project or package """ & String (Project) &
                    '"',
                  Get_Source_Reference (Self.File, Node)));
         end if;

         return Result : Item_Values do
            Result.Indexed_Values := Indexed_Values;

            if Attr.Is_Defined then
               Result.Values := Ensure_Source_Loc (Attr.Values, Sloc);
               Result.Single := Attr.Kind = PRA.Single;

            else
               Result.Single := PRA.Get (Q_Name).Value = PRA.Single;

               if Result.Single then
                  Result.Values :=
                    GPR2.Containers.Source_Value_Type_List.To_Vector
                      (New_Item => GPR2.Source_Reference.Value.Object
                         (GPR2.Source_Reference.Value.Create
                            (Sloc, GPR2.No_Value)),
                       Length   => 1);
               end if;
            end if;
         end return;
      end Get_Attribute_Ref;

      -------------------
      -- Get_Term_List --
      -------------------

      function Get_Term_List (Node : Term_List) return Item_Values is

         Result : Item_Values;
         --  The list of values returned by Get_Term_List

         New_Item : Boolean := True;

         Force_Append : Boolean := False;
         --  When True new value are always added to list

         function Parser (Node : Gpr_Node'Class) return Visit_Status;

         procedure Record_Value (Value : Source_Reference.Value.Object)
           with Post => Result.Values.Length'Old <= Result.Values.Length;
         --  Record Value into Result, either add it as a new value in the list
         --  (Single = False) or append the value to the current one.

         procedure Record_Values (Values : Item_Values);
         --  Same as above but for multiple values

         ------------
         -- Parser --
         ------------

         function Parser (Node : Gpr_Node'Class) return Visit_Status is
            Status : Visit_Status := Into;

            procedure Handle_String (Node : String_Literal)
              with Pre => Present (Node);
            --  A simple static string

            procedure Handle_String_At (Node : String_Literal_At)
              with Pre => Present (Node);
            --  A simple static string with "at" number.
            --  The number is retrieved and used later in Parse_Attribute_Decl.

            procedure Handle_Variable (Node : Variable_Reference)
              with Pre => Present (Node);
            --  A variable

            procedure Handle_Builtin (Node : Builtin_Function_Call)
              with Pre => Present (Node);
            --  A built-in

            function Terms_Parser (Node : Gpr_Node'Class) return Visit_Status;
            --  Parser for the terms tree

            --------------------
            -- Handle_Builtin --
            --------------------

            procedure Handle_Builtin (Node : Builtin_Function_Call) is

               procedure Handle_External_Variable
                 (Node : Builtin_Function_Call);
               --  An external variable : External ("VAR"[, "VALUE"])

               procedure Handle_External_As_List_Variable
                 (Node : Builtin_Function_Call);
               --  An external_as_list variable :
               --    External_As_List ("VAR", "SEP")

               procedure Handle_Split (Node : Builtin_Function_Call);
               --  Handle the Split built-in : Split ("STR1", "SEP")

               procedure Handle_Item_At (Node : Builtin_Function_Call);
               --  Handle the Item_At build-in : Item_At (List, Index)

               procedure Handle_Filter_Out (Node : Builtin_Function_Call);
               --  Handle the Filter_Out build-in : Filter_Out (List, "REGEX")

               generic
                  with function Transform
                    (Value : Value_Type) return Value_Type;
               procedure Handle_Generic1 (Node : Builtin_Function_Call);
               --  A generic procedure call Transform for the single value or
               --  for each values in a list.

               generic
                  Name : String;
                  with function Transform_V
                    (Value1, Value2 : Value_Type) return Value_Type;
                  with function Transform_L
                    (List1, List2 : Containers.Source_Value_List)
                     return Containers.Source_Value_List;
               procedure Handle_Generic2 (Node : Builtin_Function_Call);
               --  A generic procedure call Transform for the single value or
               --  a list.

               generic
                  Name : String;
                  with function Transform
                    (Value1, Pattern : Value_Type) return Value_Type;
               procedure Handle_Generic2_LV (Node : Builtin_Function_Call);
               --  A generic procedure call Transform for the single value or
               --  for each values in a list.

               procedure Handle_Match (Node : Builtin_Function_Call);
               --  Handle the Match built-in :
               --    Match ("STR", "PATTERN"[, "REPL"])

               --------------------------------------
               -- Handle_External_As_List_Variable --
               --------------------------------------

               procedure Handle_External_As_List_Variable
                 (Node : Builtin_Function_Call)
               is
                  function Get_Parameter (Index : Positive) return Value_Type;
                  --  Returns parameter by Index

                  Parameters : constant Term_List_List :=
                                 F_Terms (F_Parameters (Node));

                  -------------------
                  -- Get_Parameter --
                  -------------------

                  function Get_Parameter
                    (Index : Positive) return Value_Type
                  is
                     Ignore : Boolean;
                  begin
                     return Get_String_Literal
                       (Child (Parameters, Index), Error => Ignore);
                  end Get_Parameter;

                  Var : constant Name_Type  := Name_Type (Get_Parameter (1));
                  Sep : constant Value_Type := Get_Parameter (2);

               begin
                  Result.Single := False;

                  for V of Builtin.External_As_List (Context, Var, Sep) loop
                     New_Item := True;
                     Record_Value
                       (Get_Value_Reference
                          (V, Get_Source_Reference (Self.File, Parameters)));
                  end loop;

                  --  Skip all child nodes, we do not want to parse a second
                  --  time the string_literal.

                  Status := Over;
               end Handle_External_As_List_Variable;

               ------------------------------
               -- Handle_External_Variable --
               ------------------------------

               procedure Handle_External_Variable
                 (Node : Builtin_Function_Call)
               is
                  Parameters : constant Term_List_List :=
                                 F_Terms (F_Parameters (Node));
                  Error      : Boolean;
                  Var        : constant Name_Type :=
                                 Name_Type
                                   (Get_String_Literal
                                      (Child (Parameters, 1), Error));
                  Value_Node : constant Term_List :=
                                 Child (Parameters, 2).As_Term_List;
               begin
                  if Present (Value_Node) then
                     --  External not in the context but has a default value
                     declare
                        Values : constant Item_Values :=
                                   Get_Term_List (Value_Node);
                     begin
                        if Values.Single then
                           Record_Value
                             (Builtin.External
                                (Context,
                                 Var, Values.Values.First_Element));

                        else
                           Tree.Log_Messages.Append
                             (GPR2.Message.Create
                                (Level   => Message.Error,
                                 Sloc    =>
                                   Get_Source_Reference
                                     (Self.File, Parameters),
                                 Message =>
                                   "external default parameter must be a "
                                   & "simple string"));
                        end if;
                     end;

                  else
                     Record_Value
                       (Builtin.External
                          (Context, Var,
                           Sloc => Get_Source_Reference
                                     (Self.File, Parameters)));
                  end if;

                  --  Skip all child nodes, we do not want to parse a second
                  --  time the string_literal.

                  Status := Over;

               exception
                  when E : Project_Error =>
                     if not Ext_Conf_Mode then
                        Tree.Log_Messages.Append
                          (GPR2.Message.Create
                             (Level   => Message.Error,
                              Sloc    =>
                                Get_Source_Reference (Self.File, Parameters),
                              Message => Exception_Message (E)));
                     end if;

                     Record_Value
                       (Get_Value_Reference
                          ("", Get_Source_Reference (Self.File, Parameters)));
                     Status := Over;
               end Handle_External_Variable;

               -----------------------
               -- Handle_Filter_Out --
               -----------------------

               procedure Handle_Filter_Out (Node : Builtin_Function_Call) is
                  Parameters : constant Term_List_List :=
                                 F_Terms (F_Parameters (Node));
                  P1_Node    : constant Term_List :=
                                 Child (Parameters, 1).As_Term_List;
                  P2_Node    : constant Term_List :=
                                 Child (Parameters, 2).As_Term_List;
               begin
                  declare
                     P1 : constant Item_Values := Get_Term_List (P1_Node);
                     P2 : constant Item_Values := Get_Term_List (P2_Node);
                  begin
                     if P1.Single then
                        Non_Fatal_Error.Append
                          (GPR2.Message.Create
                             (Level   => Message.Error,
                              Sloc    =>
                                Get_Source_Reference (Self.File, Node),
                              Message =>
                                "first parameter of Filter_Out"
                                & " built-in must be a list"));
                     end if;

                     --  Check that 2nd parameter is a simple value

                     if not P2.Single then
                        Non_Fatal_Error.Append
                          (GPR2.Message.Create
                             (Level   => Message.Error,
                              Sloc    =>
                                Get_Source_Reference (Self.File, Node),
                              Message =>
                                "second parameter of Filter_Out"
                                & " built-in must be a value"));

                     else
                        declare
                           use GNAT;

                           Pattern : constant Value_Type :=
                                       P2.Values.First_Element.Text;

                           Regex   : constant Regexp.Regexp :=
                                       Regexp.Compile (Pattern);

                           L       : constant Containers.Source_Value_List :=
                                       Builtin.Filter_Out (P1.Values, Regex);
                        begin
                           for V of L loop
                              New_Item := True;

                              Record_Value
                                (Get_Value_Reference
                                   (V.Text,
                                 Get_Source_Reference
                                   (Self.File, Parameters)));
                           end loop;

                           Result.Single := False;
                        end;
                     end if;
                  end;

                  Status := Over;
               end Handle_Filter_Out;

               ---------------------
               -- Handle_Generic1 --
               ---------------------

               procedure Handle_Generic1 (Node : Builtin_Function_Call) is
                  Parameters : constant Term_List_List :=
                                 F_Terms (F_Parameters (Node));
                  Value_Node : constant Term_List :=
                                 Child (Parameters, 1).As_Term_List;
               begin
                  declare
                     Values : constant Item_Values :=
                                Get_Term_List (Value_Node);
                  begin
                     if Values.Single then
                        Record_Value
                          (Get_Value_Reference
                             (Transform (Values.Values.First_Element.Text),
                              Get_Source_Reference
                                (Self.File, Parameters)));

                     else
                        for V of Values.Values loop
                           New_Item := True;

                           Record_Value
                             (Get_Value_Reference
                                (Transform (V.Text),
                                 Get_Source_Reference
                                   (Self.File, Parameters)));
                        end loop;

                        Result.Single := False;
                     end if;
                  end;

                  --  Skip all child nodes, we do not want to parse a second
                  --  time the string_literal.

                  Status := Over;
               end Handle_Generic1;

               ---------------------
               -- Handle_Generic2 --
               ---------------------

               procedure Handle_Generic2 (Node : Builtin_Function_Call) is
                  Parameters : constant Term_List_List :=
                                 F_Terms (F_Parameters (Node));
                  P1_Node    : constant Term_List :=
                                 Child (Parameters, 1).As_Term_List;
                  P2_Node    : constant Term_List :=
                                 Child (Parameters, 2).As_Term_List;
               begin
                  declare
                     P1 : constant Item_Values := Get_Term_List (P1_Node);
                     P2 : constant Item_Values := Get_Term_List (P2_Node);
                  begin
                     if P1.Single xor P2.Single then
                        Non_Fatal_Error.Append
                          (GPR2.Message.Create
                             (Level   => Message.Error,
                              Sloc    =>
                                Get_Source_Reference (Self.File, Node),
                              Message =>
                                "parameters of " & Name
                                & " built-in must be of the same type"));
                     end if;

                     if P1.Single then
                        Record_Value
                          (Get_Value_Reference
                             (Transform_V
                                  (P1.Values.First_Element.Text,
                                   P2.Values.First_Element.Text),
                              Get_Source_Reference
                                (Self.File, Parameters)));

                     else
                        declare
                           L : constant Containers.Source_Value_List :=
                                 Transform_L (P1.Values, P2.Values);
                        begin
                           for V of L loop
                              New_Item := True;

                              Record_Value
                                (Get_Value_Reference
                                   (V.Text,
                                 Get_Source_Reference
                                   (Self.File, Parameters)));
                           end loop;
                        end;

                        Result.Single := False;
                     end if;
                  end;

                  --  Skip all child nodes, we do not want to parse a second
                  --  time the string_literal.

                  Status := Over;
               end Handle_Generic2;

               ------------------------
               -- Handle_Generic2_LV --
               ------------------------

               procedure Handle_Generic2_LV (Node : Builtin_Function_Call) is
                  Parameters : constant Term_List_List :=
                                 F_Terms (F_Parameters (Node));
                  P1_Node    : constant Term_List :=
                                 Child (Parameters, 1).As_Term_List;
                  P2_Node    : constant Term_List :=
                                 Child (Parameters, 2).As_Term_List;
               begin
                  declare
                     P1 : constant Item_Values := Get_Term_List (P1_Node);
                     P2 : constant Item_Values := Get_Term_List (P2_Node);
                  begin
                     if not P2.Single then
                        Non_Fatal_Error.Append
                          (GPR2.Message.Create
                             (Level   => Message.Error,
                              Sloc    =>
                                Get_Source_Reference (Self.File, Node),
                              Message =>
                                "second parameters of " & Name
                                & " built-in must be a simple value"));
                     end if;

                     if P1.Single then
                        Record_Value
                          (Get_Value_Reference
                             (Transform
                                  (P1.Values.First_Element.Text,
                                   P2.Values.First_Element.Text),
                              Get_Source_Reference
                                (Self.File, Parameters)));

                     else
                        for V of P1.Values loop
                           declare
                              R : constant String :=
                                    Transform
                                      (V.Text, P2.Values.First_Element.Text);
                           begin
                              New_Item := True;

                              --  The result is empty, remove from the list

                              if R /= "" then
                                 Record_Value
                                   (Get_Value_Reference
                                      (Transform
                                           (V.Text,
                                            P2.Values.First_Element.Text),
                                       Get_Source_Reference
                                         (Self.File, Parameters)));
                              end if;
                           end;
                        end loop;

                        Result.Single := False;
                     end if;
                  end;

                  --  Skip all child nodes, we do not want to parse a second
                  --  time the string_literal.

                  Status := Over;
               end Handle_Generic2_LV;

               --------------------
               -- Handle_Item_At --
               --------------------

               procedure Handle_Item_At (Node : Builtin_Function_Call) is
                  use type Strings.Maps.Character_Set;

                  Parameters : constant Term_List_List :=
                                 F_Terms (F_Parameters (Node));
                  P1_Node    : constant Term_List :=
                                 Child (Parameters, 1).As_Term_List;
                  P2_Node    : constant Term_List :=
                                 Child (Parameters, 2).As_Term_List;
               begin
                  declare
                     P1 : constant Item_Values := Get_Term_List (P1_Node);
                     P2 : constant Item_Values := Get_Term_List (P2_Node);
                  begin
                     if P1.Single then
                        Non_Fatal_Error.Append
                          (GPR2.Message.Create
                             (Level   => Message.Error,
                              Sloc    =>
                                Get_Source_Reference (Self.File, Node),
                              Message =>
                                "first parameter of Index_At"
                                & " built-in must be a list"));
                     end if;

                     --  Check that 2nd parameter is a simple number

                     if not P2.Single
                       or else
                         Strings.Fixed.Index
                           (P2.Values.First_Element.Text,
                            Strings.Maps.Constants.Decimal_Digit_Set
                              or Strings.Maps.To_Set ("-"),
                            Strings.Outside) /= 0
                     then
                        Non_Fatal_Error.Append
                          (GPR2.Message.Create
                             (Level   => Message.Error,
                              Sloc    =>
                                Get_Source_Reference (Self.File, Node),
                              Message =>
                                "second parameter of Index_At"
                                & " built-in must be a number"));

                     else
                        declare
                           Index : constant Integer :=
                                     Integer'Value
                                       (P2.Values.First_Element.Text);
                        begin
                           if abs (Index) > Positive (P1.Values.Length)
                             or else Index = 0
                           then
                              Non_Fatal_Error.Append
                                (GPR2.Message.Create
                                   (Level   => Message.Error,
                                    Sloc    =>
                                      Get_Source_Reference (Self.File, Node),
                                    Message =>
                                      "second parameter of Index_At"
                                      & " built-in out of bound"));
                           else
                              Record_Value
                                (Get_Value_Reference
                                   (Builtin.Item_At (P1.Values, Index),
                                    Source_Reference.Object
                                      (P1.Values.First_Element)));
                           end if;
                        end;
                     end if;
                  end;

                  Status := Over;
               end Handle_Item_At;

               ------------------
               -- Handle_Match --
               ------------------

               procedure Handle_Match (Node : Builtin_Function_Call) is
                  Parameters : constant Term_List_List :=
                                 F_Terms (F_Parameters (Node));

                  Str : constant Item_Values :=
                          Get_Term_List (Child (Parameters, 1).As_Term_List);
                  Pat : constant Item_Values :=
                          Get_Term_List (Child (Parameters, 2).As_Term_List);
                  Rep : constant Item_Values :=
                          (if Parameters.Children_Count = 3
                           then Get_Term_List
                                  (Child (Parameters, 3).As_Term_List)
                           else Empty_Item_Values);
               begin
                  if not Pat.Single then
                     Tree.Log_Messages.Append
                       (Message.Create
                          (Level => Message.Error,
                           Sloc  => Get_Source_Reference
                                      (Self.File, Child (Parameters, 2)),
                           Message => "Match pattern parameter must be a"
                                    & " string"));

                  elsif Rep /= Empty_Item_Values and then not Rep.Single then
                     Tree.Log_Messages.Append
                       (Message.Create
                          (Level => Message.Error,
                           Sloc  => Get_Source_Reference
                                      (Self.File, Child (Parameters, 2)),
                           Message => "Match replacement parameter must be a"
                                    & " string"));

                  else
                     declare
                        use GNAT;

                        Pattern : constant Value_Type :=
                                    Pat.Values.First_Element.Text;

                        Regex   : constant Regpat.Pattern_Matcher :=
                                    Regpat.Compile (Pattern);

                        Repl    : constant Value_Type :=
                                    (if Rep = Empty_Item_Values
                                     then ""
                                     else Rep.Values.First_Element.Text);
                     begin
                        if Str.Single then
                           declare
                              R : constant String :=
                                    Builtin.Match
                                      (Str.Values.First_Element.Text,
                                       Pattern, Regex, Repl);
                           begin
                              if R = "" then
                                 --  No match, result is an empty value
                                 Record_Value
                                   (Get_Value_Reference
                                      ("",
                                       Get_Source_Reference
                                         (Self.File, Parameters)));
                              else
                                 Record_Value
                                   (Get_Value_Reference
                                      (R,
                                       Source_Reference.Object
                                         (Str.Values.First_Element)));
                              end if;
                           end;

                        else
                           --  First parameter is a list, do the match on all
                           --  list items, if no match remove from the list.

                           for V of Str.Values loop
                              declare
                                 R : constant String :=
                                       Builtin.Match
                                         (V.Text, Pattern, Regex, Repl);
                              begin
                                 New_Item := True;

                                 if R /= "" then
                                    Record_Value
                                      (Get_Value_Reference
                                         (R,
                                          Source_Reference.Object
                                            (Str.Values.First_Element)));
                                 end if;
                              end;
                           end loop;

                           Result.Single := False;
                        end if;
                     end;
                  end if;

                  Status := Over;

               exception
                  when E : GNAT.Regpat.Expression_Error =>
                     if not Ext_Conf_Mode then
                        Tree.Log_Messages.Append
                          (GPR2.Message.Create
                             (Level   => Message.Error,
                              Sloc    =>
                                Get_Source_Reference (Self.File, Parameters),
                              Message => Exception_Message (E)));
                     end if;

                     Record_Value
                       (Get_Value_Reference
                          ("", Get_Source_Reference (Self.File, Parameters)));
                     Status := Over;
               end Handle_Match;

               ------------------
               -- Handle_Split --
               ------------------

               procedure Handle_Split (Node : Builtin_Function_Call) is
                  Parameters : constant Term_List_List :=
                                 F_Terms (F_Parameters (Node));

                  Str : constant Item_Values :=
                          Get_Term_List (Child (Parameters, 1).As_Term_List);
                  Sep : constant Item_Values :=
                          Get_Term_List (Child (Parameters, 2).As_Term_List);
               begin
                  if not Str.Single then
                     Tree.Log_Messages.Append
                       (Message.Create
                          (Level => Message.Error,
                           Sloc  => Get_Source_Reference
                                      (Self.File, Child (Parameters, 1)),
                           Message => "Split first parameter must be a"
                                    & " string"));

                  elsif not Sep.Single then
                     Tree.Log_Messages.Append
                       (Message.Create
                          (Level => Message.Error,
                           Sloc  => Get_Source_Reference
                                      (Self.File, Child (Parameters, 2)),
                           Message => "Split separator parameter must be a"
                                    & " string"));

                  else
                     declare
                        Item  : constant Value_Type :=
                                  Str.Values.First_Element.Text;
                        Delim : constant Value_Type :=
                                  Sep.Values.First_Element.Text;
                     begin
                        if Delim = "" then
                           Tree.Log_Messages.Append
                             (Message.Create
                                (Level => Message.Error,
                                 Sloc  => Source_Reference.Object
                                            (Sep.Values.First_Element),
                                 Message => "Split separator parameter must"
                                          & " not be empty"));

                        elsif Item /= "" then
                           for V of Builtin.Split (Item, Delim) loop
                              New_Item := True;
                              Record_Value
                                (Get_Value_Reference
                                   (V,
                                    Source_Reference.Object
                                      (Str.Values.First_Element)));
                           end loop;
                        end if;
                     end;
                  end if;

                  --  Skip all child nodes, we do not want to parse a second
                  --  time the string_literal.

                  Status := Over;
               end Handle_Split;

               procedure Handle_Upper is
                 new Handle_Generic1 (Transform => Builtin.Upper);
               --  Handle the Upper built-in : Upper ("STR") or Upper (VAR)

               procedure Handle_Lower is
                 new Handle_Generic1 (Transform => Builtin.Lower);
               --  Handle the Lower built-in : Lower ("STR") or Lower (VAR)

               procedure Handle_Default is new Handle_Generic2
                 ("Default",
                  Transform_V => Builtin.Default,
                  Transform_L => Builtin.Default);
               --  Handle the Default built-in : Default ("STR", "def")

               procedure Handle_Alternative is new Handle_Generic2
                 ("Alternative",
                  Transform_V => Builtin.Alternative,
                  Transform_L => Builtin.Alternative);
               --  Handle the Alternative built-in :
               --    Alternative ("STR", "def")

               procedure Handle_Remove_Prefix is new Handle_Generic2_LV
                 ("Remove_Prefix",
                  Transform => Builtin.Remove_Prefix);
               --  Handle the Remove_Prefix built-in :
               --    Remove_Prefix ("STR", "def")

               procedure Handle_Remove_Suffix is new Handle_Generic2_LV
                 ("Remove_Suffix",
                  Transform => Builtin.Remove_Suffix);
               --  Handle the Remove_Prefix built-in :
               --    Remove_Suffix ("STR", "def")

               Function_Name : constant Name_Type :=
                                 Get_Name_Type (F_Function_Name (Node));
            begin
               if Function_Name = "external" then
                  Handle_External_Variable (Node);

               elsif Function_Name = "external_as_list" then
                  Result.Single := False;
                  Handle_External_As_List_Variable (Node);

               elsif Function_Name = "split" then
                  Result.Single := False;
                  Handle_Split (Node);

               elsif Function_Name = "lower" then
                  Handle_Lower (Node);

               elsif Function_Name = "upper" then
                  Handle_Upper (Node);

               elsif Function_Name = "match" then
                  Handle_Match (Node);

               elsif Function_Name = "default" then
                  Handle_Default (Node);

               elsif Function_Name = "alternative" then
                  Handle_Alternative (Node);

               elsif Function_Name = "item_at" then
                  Handle_Item_At (Node);

               elsif Function_Name = "filter_out" then
                  Handle_Filter_Out (Node);

               elsif Function_Name = "remove_prefix" then
                  Handle_Remove_Prefix (Node);

               elsif Function_Name = "remove_suffix" then
                  Handle_Remove_Suffix (Node);
               end if;
            end Handle_Builtin;

            -------------------
            -- Handle_String --
            -------------------

            procedure Handle_String (Node : String_Literal) is
            begin
               Record_Value
                 (Get_Value_Reference
                    (Unquote (Value_Type (To_UTF8 (Node.Text))),
                     Get_Source_Reference (Self.File, Node)));
            end Handle_String;

            ----------------------
            -- Handle_String_At --
            ----------------------

            procedure Handle_String_At (Node : String_Literal_At) is
               At_Lit : constant Num_Literal := Node.F_At_Lit;
            begin
               Record_Value
                 (Get_Value_Reference
                    (Unquote (Value_Type (To_UTF8 (Node.F_Str_Lit.Text))),
                     Get_Source_Reference (Self.File, Sloc_Range (Node)),
                     At_Pos =>
                       (if At_Lit = No_Gpr_Node then 0
                        else Unit_Index'Wide_Wide_Value (At_Lit.Text))));
               Status := Over;
               --  Stop here to avoid parsing into the String_Literal child
            end Handle_String_At;

            ---------------------
            -- Handle_Variable --
            ---------------------

            procedure Handle_Variable (Node : Variable_Reference) is
               Values : constant Item_Values := Get_Variable_Values (Node);
            begin
               Record_Values (Values);
               Status := Over;
            end Handle_Variable;

            ------------------
            -- Terms_Parser --
            ------------------

            function Terms_Parser
              (Node : Gpr_Node'Class) return Visit_Status is
            begin
               case Kind (Node) is
                  when Gpr_Terms =>
                     null;

                  when others =>
                     return Parser (Node);
               end case;

               return Into;
            end Terms_Parser;

         begin
            case Kind (Node) is
               when Gpr_Terms =>
                  if Result.Values.Length /= 0 and then Result.Single then
                     Tree.Log_Messages.Append
                       (Message.Create
                          (Message.Error,
                           "literal string list cannot appear in a string",
                           Get_Source_Reference (Self.File, Node)));
                  end if;

                  --  We are opening not a single element but an expression
                  --  list.

                  Result.Single := False;

                  --  Handle '&' found in ("A" & "B", "C") as value extension

                  Force_Append := False;

                  --  Parse Terms tree

                  Traverse (Gpr_Node (Node), Terms_Parser'Access);

                  --  Handle '&' found in () & "A as values list append

                  Force_Append := True;

                  Status := Over;

               when Gpr_Term_List =>
                  --  A new value parsing is starting
                  New_Item := True;

               when Gpr_String_Literal =>
                  Handle_String (Node.As_String_Literal);

               when Gpr_String_Literal_At =>
                  Handle_String_At (Node.As_String_Literal_At);

               when Gpr_Variable_Reference =>
                  Handle_Variable (Node.As_Variable_Reference);

               when Gpr_Builtin_Function_Call =>
                  Handle_Builtin (Node.As_Builtin_Function_Call);

               when others =>
                  null;
            end case;

            return Status;
         end Parser;

         ------------------
         -- Record_Value --
         ------------------

         procedure Record_Value (Value : Source_Reference.Value.Object) is
         begin
            if New_Item or else Force_Append then
               Result.Values.Append (Value);
               New_Item := False;

            else
               declare
                  Last      : constant Containers.Extended_Index :=
                                Result.Values.Last_Index;
                  Old_Value : constant Source_Reference.Value.Object :=
                                Result.Values (Last);
                  New_Value : constant Value_Type :=
                                Old_Value.Text & Value.Text;
               begin
                  Result.Values.Replace_Element
                    (Last,
                     Get_Value_Reference
                       (New_Value,
                        Source_Reference.Object (Value)));
               end;
            end if;
         end Record_Value;

         -------------------
         -- Record_Values --
         -------------------

         procedure Record_Values (Values : Item_Values) is
            use type Project.Attribute_Index.Object;

            function Has_Index (Index : Attribute_Index.Object) return Boolean
              is (for some V of Result.Indexed_Values.Values
                    => V.Index = Index);

         begin
            --  If we already have a list of indexed values, or If we already
            --  have one indexed values and we have new indexed values and if
            --  those are having different index then we want to append to the
            --  list.
            --
            --  It covers the following case:
            --
            --  for Attr use Pck'Attr & Pck'Attr;
            --

            if Result.Indexed_Values.Values.Length > 1
              or else
                (Result.Indexed_Values.Values.Length > 0
                 and then Values.Indexed_Values.Values.Length > 0
                 and then Values.Indexed_Values.Values.First_Element.Index
                           /= Result.Indexed_Values.Values.First_Element.Index)
            then
               for V of Values.Indexed_Values.Values loop
                  --  Issue a lint-level message if we are going to overwrite
                  --  an already existing value for the given index.

                  if Has_Index (V.Index) then
                     Tree.Log_Messages.Append
                       (Message.Create
                          (Message.Lint,
                           "duplicate indexed attribute found for "
                           & V.Index.Text,
                           Source_Reference.Object (V.Index)));
                  end if;

                  Result.Indexed_Values.Values.Append (V);
               end loop;
            else
               Result.Indexed_Values := Values.Indexed_Values;
            end if;

            for V of Values.Values loop
               New_Item := New_Item or else not Values.Single;
               Record_Value (V);
            end loop;

            --  If we add a list, then the final value must be a list

            if not Values.Single and then Result.Single then
               Result.Single := False;

               --  When parsing a list '&' should be used as append to list
               --  ("a") & "b" => ("a", "b")

               Force_Append := True;
            end if;
         end Record_Values;

      begin
         Result.Single := True;

         Traverse (Gpr_Node (Node), Parser'Access);

         return Result;
      end Get_Term_List;

      ----------------------
      -- Get_Variable_Ref --
      ----------------------

      function Get_Variable_Ref
        (Variable   : Name_Type;
         Source_Ref : Source_Reference.Object;
         Project    : Optional_Name_Type := No_Name;
         Pack       : Package_Id := Project_Level_Scope;
         From_View  : GPR2.Project.View.Object := GPR2.Project.View.Undefined)
         return Item_Values
      is
         use type PRA.Value_Kind;

         procedure Error (Msg : String := "") with Inline;
         --  Emit an error message that starts with
         --  "variable VARIABLE undefined". If Msg is not the empty string then
         --  append "(MSG)".

         function Get_Pack_Var
           (View : GPR2.Project.View.Object;
            Pack : Package_Id;
            Name : Name_Type) return Item_Values with Inline;
         --  Returns the variable value Pack.Name. If not found an error added

         function Try_Visible_In
           (View : GPR2.Project.View.Object) return Item_Values;
         --  Try to find variable either in extended view or in parent one

         -----------
         -- Error --
         -----------

         procedure Error (Msg : String := "") is
         begin
            Tree.Log_Messages.Append
              (Message.Create
                 (Message.Error,
                  (if Msg /= "" then Msg
                   else "undefined variable """ &
                        (if Project = No_Name then ""
                         else String (Project) & ".") &
                        (if Pack = Project_Level_Scope then ""
                         else Image (Pack) & ".") &
                        String (Variable) & '"'),
                  Source_Ref));
         end Error;

         ------------------
         -- Get_Pack_Var --
         ------------------

         function Get_Pack_Var
           (View : GPR2.Project.View.Object;
            Pack : Package_Id;
            Name : Name_Type) return Item_Values is
         begin
            if View.Has_Variables (Pack, Name) then
               declare
                  V : constant GPR2.Project.Variable.Object :=
                        View.Variable (Pack, Name);
               begin
                  return (Values => Ensure_Source_Loc (V.Values, Source_Ref),
                          Single => V.Kind = PRA.Single,
                          others => <>);
               end;
            else
               Error;
               return No_Values;
            end if;
         end Get_Pack_Var;

         --------------------
         -- Try_Visible_In --
         --------------------

         function Try_Visible_In
           (View : GPR2.Project.View.Object) return Item_Values
         is
            Result : Item_Values;
            Parent : GPR2.Project.View.Object;
         begin
            if View.Is_Extending then
               Result := Get_Variable_Ref
                 (Variable   => Variable,
                  From_View  => View.Extended_Root,
                  Source_Ref => Source_Ref);

               if Result /= No_Values then
                  return Result;
               end if;
            end if;

            if View.Check_Parent (Parent) then
               Result := Get_Variable_Ref
                 (Variable   => Variable,
                  From_View  => Parent,
                  Source_Ref => Source_Ref);

               if Result /= No_Values then
                  return Result;
               end if;
            end if;

            Error;

            return No_Values;
         end Try_Visible_In;

      begin
         if Project /= No_Name then
            --  We have a reference to subproject, resolve it and recurse

            declare
               Var_View : constant GPR2.Project.View.Object :=
                            (if From_View.Is_Defined
                             then From_View.View_For (Project)
                             else View.View_For (Project));
            begin
               if Var_View.Is_Defined then
                  return Get_Variable_Ref
                           (Variable   => Variable,
                            Pack       => Pack,
                            From_View  => Var_View,
                            Source_Ref => Source_Ref);

               elsif To_Lower (Project) = "project" then
                  --  If no project called project is defined then assume
                  --  project is the current project.

                  return Get_Variable_Ref
                           (Variable   => Variable,
                            Pack       => Pack,
                            From_View  => From_View,
                            Source_Ref => Source_Ref);
               else
                  Tree.Log_Messages.Append
                    (Message.Create
                       (Missing_Project_Error_Level,
                        "undefined project " & String (Project) & '"',
                        Source_Ref));
               end if;
            end;

         elsif not From_View.Is_Defined then
            --  Working from the current view that is processed. In that case
            --  use Packs and Vars variables as the view has not been updated
            --  yet.

            if Pack = Project_Level_Scope then
               --  Look first if the variable is declared explicitly in the
               --  project itself otherwise iterate on the extended project
               --  chain.

               if Vars.Contains (Variable) then
                  return (Values =>
                            Ensure_Source_Loc
                              (Vars (Variable).Values, Source_Ref),
                          Single => Vars (Variable).Kind = PRA.Single,
                          others => <>);

               else
                  return Try_Visible_In (View);
               end if;

            else
               if In_Pack and then Pack = Pack_Name  then
                  --  If in the package currently processed use Pack_Vars to
                  --  find the value.

                  if Pack_Ref.Vars.Contains (Variable) then
                     return
                       (Values =>
                          Ensure_Source_Loc
                            (Pack_Ref.Vars (Variable).Values, Source_Ref),
                        Single => Pack_Ref.Vars (Variable).Kind = PRA.Single,
                        others => <>);
                  else
                     Error;
                  end if;

               else
                  --  Otherwise search into the already parsed packages

                  if View.Has_Package (Pack) then
                     return Get_Pack_Var (View, Pack, Variable);
                  else
                     Error
                       ("undefined project or package """ & Image (Pack)
                        & '"');
                  end if;
               end if;
            end if;

         else
            --  From_View contains the variable we are looking at

            if Pack = Project_Level_Scope then
               if From_View.Has_Variables (Variable) then
                  declare
                     V : constant GPR2.Project.Variable.Object :=
                           From_View.Variable (Variable);
                  begin
                     return (Values =>
                               Ensure_Source_Loc (V.Values, Source_Ref),
                             Single => V.Kind = PRA.Single,
                             others => <>);
                  end;

               else
                  return Try_Visible_In (From_View);
               end if;

            elsif From_View.Has_Package (Pack) then
               return Get_Pack_Var (From_View, Pack, Variable);
            else
               Error ("undefined package """ & Image (Pack) & '"');
            end if;
         end if;

         return No_Values;
      end Get_Variable_Ref;

      -------------------------
      -- Get_Variable_Values --
      -------------------------

      function Get_Variable_Values
        (Node : Variable_Reference) return Item_Values
      is
         --  A reference to variable/attribute values has the following format:
         --  prj_name[.pack_name[.var_name]]['Attribute]

         Var_Name   : constant Identifier_List := F_Variable_Name (Node);
         Att_Ref    : constant Attribute_Reference := F_Attribute_Ref (Node);
         Source_Ref : constant Source_Reference.Object :=
                        Get_Source_Reference (Self.File, Node);

         function Project_Name_Length
           (List : Identifier_List) return Natural;
         --  Returns the last Index in list of the project name part. can be
         --  0 if List not starting with a project name

         -------------------------
         -- Project_Name_Length --
         -------------------------

         function Project_Name_Length
           (List : Identifier_List) return Natural
         is
            Last : constant Natural :=
                     Children_Count (List) -
                     (if Present (Att_Ref) then 0 else 1);
            --  if not attribute reference last segment is variable name

            function Is_Valid_Project_Name (Name : Name_Type) return Boolean is
              (Process.View.View_For (Name).Is_Defined
               or else Self.Imports.Contains (Name)
               or else (Self.Extended.Is_Defined
                        and then Self.Extended.Path_Name.Base_Name = Name)
               or else Is_Builtin_Project_Name (Name)
               or else Name_Type (To_String (Self.Name)) = Name);

         begin
            if Last >= 1
              and then Is_Valid_Project_Name (Get_Name_Type (List, 1, Last))
            then
               return Last;

            elsif Last >= 2
              and then Is_Valid_Project_Name
                         (Get_Name_Type (List, 1, Last - 1))
            then
               return Last - 1;
            end if;

            return 0;
         end Project_Name_Length;

         Var_Name_Length : constant Positive :=  Children_Count (Var_Name);
         --  Number of segment of variable name. cannot be 0 as var_name list
         --  empty are not allowed in gpr_parser language.

         Prj_Name_Length : constant Natural := Project_Name_Length (Var_Name);
         --  Number of segment of project name part

      begin
         if Present (Att_Ref) then
            --  This is a reference to an attribute
            --  supported formats are prj'attr, pack'attr or prj.pack'attr
            --  prj can be a child project (root.child)

            return Get_Attribute_Ref
              (Project => (if Prj_Name_Length = 0
                           then (if Var_Name_Length = 1
                                 then Name_Type (To_String (Self.Name))
                                 else Get_Name_Type
                                        (Var_Name, 1, Var_Name_Length - 1))
                           else Get_Name_Type (Var_Name, 1, Prj_Name_Length)),
               Pack    => (if Prj_Name_Length = Var_Name_Length
                           then Project_Level_Scope
                           else +Get_Name_Type
                             (Var_Name, Var_Name_Length, Var_Name_Length)),
               Node    => Att_Ref);
         else
            --  This is a reference to a variable

            declare
               Variable : constant Name_Type :=
                            Get_Name_Type
                               (Var_Name, Var_Name_Length, Var_Name_Length);
            begin
               if Var_Name_Length < 2 then
                  --  A 1 word variable can only refer to a variable declared
                  --  implicitly (in case of extends or child) or explicitly
                  --  in the current project itself.

                  if In_Pack and then Pack_Ref.Vars.Contains (Variable) then
                     --  If we are in the context of a package we don't need
                     --  the package prefix to refer to variables explicitly
                     --  declared in the package.

                     return Get_Variable_Ref
                       (Pack       => Pack_Name,
                        Variable   => Variable,
                        Source_Ref => Source_Ref);

                  else
                     --  This is a reference to a variable in the current
                     --  project scope

                     return Get_Variable_Ref
                              (Variable => Variable, Source_Ref => Source_Ref);
                  end if;

               elsif Prj_Name_Length > 0
                 and then Prj_Name_Length + 1 = Var_Name_Length
               then
                  --  it is a <project_name>.<variable_name>

                  return Get_Variable_Ref
                    (Project    =>
                       Get_Name_Type (Var_Name, 1, Var_Name_Length - 1),
                     Variable   => Variable,
                     Source_Ref => Source_Ref);

               elsif Prj_Name_Length = 0 and then Var_Name_Length = 2 then
                  --  it is a <package_name>.<variable_name>

                  return Get_Variable_Ref
                    (Pack       =>
                       +Get_Name_Type (Var_Name, 1, Var_Name_Length - 1),
                     Variable   => Variable,
                     Source_Ref => Source_Ref);

               else
                  --  it is a <project_name>.<package_name>.<variable_name>

                  return Get_Variable_Ref
                    (Project    =>
                       Get_Name_Type (Var_Name, 1, Var_Name_Length - 2),
                     Pack       =>
                       +Get_Name_Type
                         (Var_Name, Var_Name_Length - 1, Var_Name_Length - 1),
                     Variable   => Variable,
                     Source_Ref => Source_Ref);
               end if;
            end;
         end if;
      end Get_Variable_Values;

      -----------------------
      -- Is_Limited_Import --
      -----------------------

      function Is_Limited_Import
        (Self : Object; Project : Name_Type) return Boolean
      is
         package PIS renames GPR2.Project.Import.Set;
         Position : constant PIS.Cursor := Self.Imports.Find (Project);
      begin
         return PIS.Has_Element (Position)
           and then PIS.Element (Position).Is_Limited;
      end Is_Limited_Import;

      ------------
      -- Parser --
      ------------

      function Parser (Node : Gpr_Node'Class) return Visit_Status is
         Status : Visit_Status := Into;

         procedure Parse_Attribute_Decl (Node : Attribute_Decl);
         --  Parse attribute declaration and append it into Attrs set

         procedure Parse_Variable_Decl (Node : Variable_Decl)
           with Pre => Is_Open;
         --  Parse variable declaration and append it into the Vars set

         procedure Parse_Package_Decl (Node : Package_Decl)
           with Pre => Is_Open;
         --  Parse variable declaration and append it into the Vars set

         procedure Parse_Package_Renaming (Node : Package_Renaming)
           with Pre => Is_Open;
         --  Parse a package renaming

         procedure Parse_Package_Extension (Node : Package_Extension)
           with Pre => Is_Open;
         --  Parse a package extension

         procedure Parse_Project_Declaration (N : Project_Declaration)
           with Pre => Is_Open;
         --  Parse the project declaration

         procedure Parse_Case_Construction (Node : Case_Construction)
           with Post => Case_Values.Length'Old = Case_Values.Length;
         --  Parse a case construction, during a case construction parsing the
         --  Is_Open flag may be set to False and True. Set Is_Open comments.

         procedure Parse_Case_Item (Node : Case_Item)
           with Pre => not Case_Values.Is_Empty;
         --  Set Is_Open to True or False depending on the item

         procedure Visit_Child (Child : Gpr_Node);
         --  Recursive call to the Parser if the Child is not null

         --------------------------
         -- Parse_Attribute_Decl --
         --------------------------

         procedure Parse_Attribute_Decl (Node : Attribute_Decl) is

            Name  : constant Identifier := F_Attr_Name (Node);
            Index : constant Gpr_Node := F_Attr_Index (Node);
            Expr  : constant Term_List := F_Expr (Node);
            N_Str : constant Name_Type :=
                      Get_Name_Type (Name.As_Single_Tok_Node);
            N_Id  : constant Attribute_Id := +N_Str;

            function Create_Index return PAI.Object;
            --  Create index with "at" part if exists

            procedure Create_And_Register_Attribute
              (Index  : PAI.Object;
               Values : Containers.Source_Value_List;
               Single : Boolean);
            --  Create attribute and register it if needed

            Q_Name : constant Q_Attribute_Id := (Pack_Name, N_Id);

            Values : constant Item_Values := Get_Term_List (Expr);
            A      : PA.Object;
            --  Set to False if the attribute definition is invalid

            Id     : constant Source_Reference.Attribute.Object :=
                       Get_Attribute_Reference
                         (Self.Path_Name, Sloc_Range (Name), Q_Name);

            --  The attribute name & sloc

            Sloc   : constant Source_Reference.Object :=
                       Get_Source_Reference (Self.File, Node);

            use PAI;
            use PRA;

            Is_Name_Exception : constant Boolean :=
                                  N_Id in
                                    Naming.Spec.Attr
                                    | Naming.Specification.Attr
                                    | Naming.Body_N.Attr
                                    | Naming.Implementation.Attr;

            -----------------------------------
            -- Create_And_Register_Attribute --
            -----------------------------------

            procedure Create_And_Register_Attribute
              (Index  : PAI.Object;
               Values : Containers.Source_Value_List;
               Single : Boolean)
            is
               Position : Containers.Filename_Source_Reference_Package.Cursor;
               Inserted : Boolean;
            begin
               if Single then
                  pragma Assert (Expr.Children_Count >= 1);

                  A := PA.Create
                    (Name  => Id,
                     Index => Index,
                     Value => Values.First_Element);

               else
                  A := PA.Create
                         (Name   => Id,
                          Index  => Index,
                          Values => Values);
               end if;

               --  Record attribute with proper casing definition if found

               if PRA.Exists (Q_Name) then
                  declare
                     Def : constant PRA.Def := PRA.Get (Q_Name);

                  begin
                     if Def.Builtin then
                        Tree.Log_Messages.Append
                          (Message.Create
                             (Level   => Message.Error,
                              Sloc    => Sloc,
                              Message => "builtin attribute """
                                          & Image (Q_Name)
                                          & """ is read-only"));
                     end if;

                     A.Set_Case
                       (Value_Is_Case_Sensitive => Def.Value_Case_Sensitive);
                  end;
               end if;

               if Is_Open then
                  if View_Def.Is_Root
                    and then View_Def.Kind /= K_Configuration
                    and then A.Name.Id = PRA.Target
                    and then Tree.Has_Configuration
                    and then A.Value.Text /= "all"
                  then
                     --  Check if defined target in the project is the
                     --  same as configuration. Else issue a warning.

                     declare
                        C_View : Project.View.Object renames
                                   Tree.Configuration.Corresponding_View;
                        T_Conf : constant Name_Type :=
                                   Name_Type
                                     (C_View.Attribute
                                        (PRA.Target).Value.Text);
                        T_Attr : constant Name_Type :=
                                   Name_Type (A.Value.Text);
                        Base   : GPR2.KB.Object := Tree.Get_KB;

                     begin
                        if not Base.Is_Defined then
                           Base := GPR2.KB.Create_Default
                             (GPR2.KB.Targetset_Only_Flags,
                              Tree.Environment);
                        end if;

                        if Base.Normalized_Target (T_Conf) /=
                          Base.Normalized_Target (T_Attr)
                        then
                           Tree.Log_Messages.Append
                             (Message.Create
                                (Level   => Message.Warning,
                                 Sloc    => Sloc,
                                 Message => "target attribute '"
                                            & String (T_Attr)
                                            & "' not used, overridden by the "
                                            & "configuration's target: "
                                            & String (T_Conf)));
                        end if;
                     end;
                  end if;

                  declare
                     Alias : constant Q_Optional_Attribute_Id :=
                               PRA.Alias (Q_Name);
                     A2    : constant GPR2.Project.Attribute.Object :=
                               (if Alias.Attr /= No_Attribute
                                then A.Get_Alias (Alias)
                                else Project.Attribute.Undefined);
                  begin
                     if In_Pack then
                        Record_Attribute (Pack_Ref.Attrs, A);

                        if A2.Is_Defined
                          and then Pack_Ref.Attrs.Contains (A2)
                        then
                           --  Need to update the value
                           Record_Attribute (Pack_Ref.Attrs, A2);
                        end if;

                        if Is_Name_Exception then
                           Actual.Include (Filename_Type (A.Value.Text));
                        end if;

                     else
                        Record_Attribute (Attrs, A);

                        if A2.Is_Defined and then Attrs.Contains (A2) then
                           --  Need to update the value
                           Record_Attribute (Attrs, A2);
                        end if;
                     end if;
                  end;

               elsif Is_Name_Exception then
                  Self.Skip_Src.Insert
                    (Filename_Type (A.Value.Text), A.Value,
                     Position, Inserted);
               end if;
            end Create_And_Register_Attribute;

            ------------------
            -- Create_Index --
            ------------------

            function Create_Index return PAI.Object is
               Str_Lit : String_Literal_At;
               At_Lit  : Num_Literal;
            begin
               if Index.Kind = Gpr_Others_Designator then
                  return PAI.Create
                    (Get_Value_Reference
                       (Self.Path_Name, Sloc_Range (Index), "others"),
                     Is_Others      => True,
                     Case_Sensitive => False);

               else
                  Str_Lit := Index.As_String_Literal_At;
                  At_Lit  := Str_Lit.F_At_Lit;

                  return PAI.Create
                    (Get_Value_Reference
                       (Self.Path_Name, Sloc_Range (Index),
                        Get_Value_Type (Str_Lit.F_Str_Lit),
                        At_Pos =>
                          (if At_Lit = No_Gpr_Node
                           then 0
                           else Unit_Index'Wide_Wide_Value (At_Lit.Text))),
                     Is_Others      => False,
                     Case_Sensitive => False);
               end if;
            end Create_Index;

            I_Sloc : PAI.Object :=
                       (if Present (Index)
                        then Create_Index
                        else PAI.Undefined);

         begin
            if not I_Sloc.Is_Defined
             and then PRA.Exists (Q_Name)
             and then PRA.Get (Q_Name).Index_Type /= PRA.No_Index
            then
               if not Values.Indexed_Values.Filled then
                  Tree.Log_Messages.Append
                   (Message.Create
                      (Level   => Message.Error,
                       Sloc    => Sloc,
                       Message => "full associative array expression " &
                         "requires simple attribute reference"));

               elsif
                 Values.Indexed_Values.Attribute_Name.Pack /= Pack_Name
               then
                  Tree.Log_Messages.Append
                   (Message.Create
                      (Level   => Message.Error,
                       Sloc    => Sloc,
                       Message => "not the same package as " &
                         Image (Pack_Name)));

               elsif Values.Indexed_Values.Attribute_Name.Attr /= N_Id then
                  Tree.Log_Messages.Append
                   (Message.Create
                      (Level   => Message.Error,
                       Sloc    => Sloc,
                       Message => "full associative array expression " &
                         "must reference the same attribute """ &
                         Image (N_Id) & '"'));

               else
                  for V of Values.Indexed_Values.Values loop
                     Create_And_Register_Attribute
                      (Index  => V.Index,
                       Values => V.Values,
                       Single => V.Single);
                  end loop;
               end if;

            elsif Values /= No_Values then
               if I_Sloc.Is_Defined and then PRA.Exists (Q_Name) then
                  I_Sloc.Set_Case
                    (PRA.Is_Case_Sensitive
                       (I_Sloc.Value, PRA.Get (Q_Name).Index_Type));
               end if;

               Create_And_Register_Attribute
                (Index  => I_Sloc,
                 Values => Values.Values,
                 Single => Values.Single);
            end if;
         end Parse_Attribute_Decl;

         -----------------------------
         -- Parse_Case_Construction --
         -----------------------------

         procedure Parse_Case_Construction (Node : Case_Construction) is
            Var     : constant Variable_Reference := F_Var_Ref (Node);
            Value   : constant Containers.Source_Value_List :=
                        Get_Variable_Values (Var).Values;
            Att_Ref : constant Attribute_Reference := F_Attribute_Ref (Var);

         begin
            if Present (Att_Ref) then
               --  Can't have attribute references as value in case statements
               Tree.Log_Messages.Append
                 (Message.Create
                    (Level   => Message.Error,
                     Sloc    => Get_Source_Reference (Self.File, Att_Ref),
                     Message => "attribute reference not allowed here"));

            elsif Value.Length = 1 then
               Case_Values.Append ('-' & Value.First_Element.Text);

               --  Set status to close for now, this will be open when a
               --  when_clause will match the value pushed just above on
               --  the vector.

               declare
                  Childs : constant Case_Item_List := F_Items (Node);
               begin
                  for C in 1 .. Children_Count (Childs) loop
                     Visit_Child (Child (Childs, C));
                  end loop;
               end;

               --  Then remove the case value

               Case_Values.Delete_Last;

               --  Skip all nodes for this construct

               Status := Over;

            elsif not Has_Error then
               Tree.Log_Messages.Append
                 (Message.Create
                    (Level   => Missing_Project_Error_Level,
                     Sloc    => Get_Source_Reference (Self.File, Node),
                     Message => "variable """
                     & String (Get_Name_Type (F_Variable_Name (Var), 1, 1))
                     & """ must be a simple value"));
               if Pre_Conf_Mode then
                  Status := Over;
               end if;
            end if;
         end Parse_Case_Construction;

         ---------------------
         -- Parse_Case_Item --
         ---------------------

         procedure Parse_Case_Item (Node : Case_Item) is

            function Parser (Node : Gpr_Node'Class) return Visit_Status;

            Case_Value   : constant String := Case_Values.Last_Element;
            Is_That_Case : Boolean := False;

            ------------
            -- Parser --
            ------------

            function Parser (Node : Gpr_Node'Class) return Visit_Status is
            begin
               case Kind (Node) is
                  when Gpr_String_Literal =>
                     Is_That_Case :=
                       Unquote (To_UTF8 (Node.Text))
                         = Case_Value (2 .. Case_Value'Last);

                  when Gpr_Others_Designator =>
                     Is_That_Case := True;

                  when others =>
                     return Into;
               end case;

               return (if Is_That_Case then Stop else Over);
            end Parser;

         begin
            case Case_Value (1) is
               when '-' =>
                  Traverse (F_Choice (Node), Parser'Access);

                  if Is_That_Case then
                     Case_Values (Case_Values.Last) (1) := '+';
                  end if;

               when '+' =>
                  Case_Values (Case_Values.Last) (1) := '^';

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

         ------------------------
         -- Parse_Package_Decl --
         ------------------------

         procedure Parse_Package_Decl (Node : Package_Decl) is
            Name   : constant Identifier := F_Pkg_Name (Node);
            P_Name : constant Package_Id :=
                       +Get_Name_Type (Name.As_Single_Tok_Node);

         begin
            --  Entering a package, set the state and parse the corresponding
            --  children.

            In_Pack := True;
            Pack_Name := P_Name;

            --  Make sure the package exists in view, and make Pack_Ref point
            --  to it.
            Packs.Include
              (P_Name,
               GPR2.Project.Pack.Object'
                 (Source_Reference.Pack.Object
                    (Source_Reference.Pack.Create
                       (Get_Source_Reference (Self.File, Node), P_Name)) with
                  PA.Set.Empty_Set, Project.Variable.Set.Empty_Set));
            Pack_Ref := Packs.Reference (P_Name).Element;

            Visit_Child (F_Pkg_Spec (Node));

            In_Pack   := False;
            Pack_Name := Project_Level_Scope;
            Pack_Ref  := null;

            --  Skip all nodes for this construct

            Status := Over;
         end Parse_Package_Decl;

         -----------------------------
         -- Parse_Package_Extension --
         -----------------------------

         procedure Parse_Package_Extension (Node : Package_Extension) is
            Sloc       : constant Source_Reference.Object :=
                           Get_Source_Reference (Self.File, Node);
            Values     : constant Identifier_List := F_Extended_Name (Node);
            Num_Childs : constant Positive := Children_Count (Values);
            Project    : constant Name_Type :=
                           (if Num_Childs > 1
                            then Get_Name_Type
                              (Values, Last => Num_Childs - 1)
                            else "?");
            P_Name     : constant Package_Id :=
                           +Get_Name_Type (Values, Num_Childs, Num_Childs);

            View       : constant GPR2.Project.View.Object :=
                           (if Num_Childs > 1
                            then Process.View.View_For (Project)
                            else GPR2.Project.View.Undefined);
         begin
            --  Clear any previous value. This node is parsed as a child
            --  process of Parse_Package_Decl routine above.

            Pack_Ref.Attrs.Clear;
            Pack_Ref.Vars.Clear;

            --  Check if the Project.Package reference exists

            if Num_Childs = 1 then
               Tree.Log_Messages.Append
                 (Message.Create
                    (Level   => Message.Error,
                     Sloc    => Sloc,
                     Message =>
                       "project_name.package_name reference is required"));
            elsif Is_Limited_Import (Self, Project) then
               Tree.Log_Messages.Append
                 (Message.Create
                    (Level   => Message.Error,
                     Sloc    => Sloc,
                     Message =>
                       "cannot have a reference to a limited project"));

            elsif not View.Is_Defined then
               Tree.Log_Messages.Append
                 (Message.Create
                    (Level   => Missing_Project_Error_Level,
                     Sloc    => Sloc,
                     Message =>
                       "undefined project """ & String (Project) & '"'));

            elsif not View.Has_Package (P_Name) then
               Tree.Log_Messages.Append
                 (Message.Create
                    (Level   => Message.Error,
                     Sloc    => Sloc,
                     Message =>
                       "undefined package """ &
                       String (Project) & '.' & Image (P_Name)
                       & '"'));

            else
               --  Then just copy the attributes into the current package

               Pack_Ref.Attrs := View.Raw_Attributes (P_Name);
               Pack_Ref.Vars  := View.Variables (Pack => P_Name);
            end if;

            Status := Over;
         end Parse_Package_Extension;

         ----------------------------
         -- Parse_Package_Renaming --
         ----------------------------

         procedure Parse_Package_Renaming (Node : Package_Renaming) is
            Sloc       : constant Source_Reference.Object :=
                           Get_Source_Reference (Self.File, Node);
            Values     : constant Identifier_List := F_Renamed_Name (Node);
            Num_Childs : constant Positive := Children_Count (Values);
            Project    : constant Name_Type :=
                           (if Num_Childs > 1
                            then Get_Name_Type
                              (Values, Last => Num_Childs - 1)
                            else "?");
            P_Name     : constant Package_Id :=
                           +Get_Name_Type (Values, Num_Childs, Num_Childs);

            View       : constant GPR2.Project.View.Object :=
                           (if Num_Childs > 1
                            then Process.View.View_For (Project)
                            else GPR2.Project.View.Undefined);
         begin
            --  Clear any previous value. This node is parsed as a child
            --  process of Parse_Package_Decl routine above.

            Pack_Ref.Attrs.Clear;
            Pack_Ref.Vars.Clear;

            --  Check if the Project.Package reference exists

            if Num_Childs = 1 then
               Tree.Log_Messages.Append
                 (Message.Create
                    (Level   => Message.Error,
                     Sloc    => Sloc,
                     Message =>
                       "project_name.package_name reference is required"));

            elsif Is_Limited_Import (Self, Project) then
               Tree.Log_Messages.Append
                 (Message.Create
                    (Level   => Message.Error,
                     Sloc    => Sloc,
                     Message =>
                       "cannot have a reference to a limited project"));

            elsif not View.Is_Defined then
               Tree.Log_Messages.Append
                 (Message.Create
                    (Level   => Missing_Project_Error_Level,
                     Sloc    => Sloc,
                     Message =>
                       "undefined project """ & String (Project) & '"'));

            elsif not View.Has_Package (P_Name) then
               Tree.Log_Messages.Append
                 (Message.Create
                    (Level   => Message.Warning,
                     Sloc    => Sloc,
                     Message =>
                       "undefined package """ &
                       String (Project) & '.' & Image (P_Name) & '"'));

            else
               --  Then just copy the attributes into the current package

               Pack_Ref.Attrs := View.Raw_Attributes (P_Name);
               Pack_Ref.Vars  := View.Variables (Pack => P_Name);
            end if;

            Status := Over;
         end Parse_Package_Renaming;

         -------------------------------
         -- Parse_Project_Declaration --
         -------------------------------

         procedure Parse_Project_Declaration (N : Project_Declaration) is
            Dot_Map  : constant Strings.Maps.Character_Mapping :=
                         Strings.Maps.To_Mapping ("-", ".");
           --  A dash on a project's file name is translated as a dot in the
           --  actual project name.

            Prj_Name : constant Name_Type :=
                         Name_Type
                           (Strings.Fixed.Translate
                              (String (Self.File.Base_Name),
                               Mapping => Dot_Map));
         begin
            --  Check that project name is consistent with the filename, we
            --  skip autoconf which is using the Default project name.

            if Self.Qualifier /= K_Configuration
              and then Name_Type (To_String (Self.Name)) /= Prj_Name
            then
               Tree.Log_Messages.Append
                 (GPR2.Message.Create
                    (Level   => Message.Warning,
                     Sloc    =>
                       Get_Source_Reference (Self.File, F_Project_Name (N)),
                     Message =>
                       "project name '" & String (Prj_Name) & "' expected"));
            end if;
         end Parse_Project_Declaration;

         -------------------------
         -- Parse_Variable_Decl --
         -------------------------

         procedure Parse_Variable_Decl (Node : Variable_Decl) is

            function Search_Paths return GPR2.Path_Name.Set.Object is
              (GPR2.Project.Search_Paths
                 (Self.File, Tree.Project_Search_Paths));

            function Sloc return Source_Reference.Object is
               (Get_Source_Reference (Self.File, Node));
            --  Use function instead of constant because Sloc need only in case
            --  of error logging and no more than once.

            Name     : constant Identifier := F_Var_Name (Node);
            Expr     : constant Term_List := F_Expr (Node);
            Values   : constant Item_Values := Get_Term_List (Expr);
            V_Type   : constant Type_Reference := F_Var_Type (Node);
            V        : GPR2.Project.Variable.Object;
            Type_Def : GPR2.Project.Typ.Object;
         begin
            if not V_Type.Is_Null then
               declare
                  package PTS renames GPR2.Project.Typ.Set.Set;

                  CT : PTS.Cursor;

                  Type_N     : constant Identifier_List :=
                                 F_Var_Type_Name (V_Type);
                  Num_Childs : constant Positive := Children_Count (Type_N);
                  T_Name     : constant Name_Type :=
                                 Get_Name_Type
                                   (Type_N, Num_Childs, Num_Childs);

                  procedure Get_Type_Def_From
                    (Imp : GPR2.Project.Import.Object);
                  --  Try to find type definition from Imp by name T_Name and
                  --  store it to Type_Def if found.

                  -----------------------
                  -- Get_Type_Def_From --
                  -----------------------

                  procedure Get_Type_Def_From
                    (Imp : GPR2.Project.Import.Object)
                  is
                     Path : constant GPR2.Path_Name.Object :=
                              GPR2.Project.Create
                                (Imp.Path_Name.Name, Search_Paths);
                     Types : GPR2.Project.Typ.Set.Object;
                  begin
                     if Path.Exists then
                        Types := Registry.Get (Path).Types;
                        CT := Types.Find (T_Name);

                        if PTS.Has_Element (CT) then
                           Type_Def := PTS.Element (CT);
                        end if;
                     end if;
                  end Get_Type_Def_From;

               begin
                  if Num_Childs > 1 then
                     --  We have a project prefix for the type name

                     declare
                        package PIS renames GPR2.Project.Import.Set;
                        Position : constant PIS.Cursor :=
                                     Self.Imports.Find
                                       (Get_Name_Type
                                          (Type_N, 1, Num_Childs - 1, "-"));
                     begin
                        if PIS.Has_Element (Position) then
                           Get_Type_Def_From (PIS.Element (Position));
                        end if;
                     end;
                  end if;

                  if not Type_Def.Is_Defined
                    or else Type_Def.Count_Values = 0
                  then
                     CT := Self.Types.Find (T_Name);

                     if PTS.Has_Element (CT) then
                        Type_Def := PTS.Element (CT);

                     elsif Self.Has_Extended then
                        Get_Type_Def_From (Self.Extended);
                     end if;

                     --  Type definition from "parent" project

                     if not Type_Def.Is_Defined
                       and then Self.Has_Imports
                       and then Count (Self.Name, ".") > 0
                     then
                        declare
                           Prj_Id       : constant String := -Self.Name;
                           Dot_Position : Natural := Prj_Id'First;
                           I_Cursor     : GPR2.Project.Import.Set.Cursor;
                        begin
                           loop
                              for J in Dot_Position .. Prj_Id'Last loop
                                 Dot_Position := J;
                                 exit when Prj_Id (J) = '.';
                              end loop;

                              exit when Dot_Position = Prj_Id'Last;

                              I_Cursor := Self.Imports.Find
                                (Name_Type (Prj_Id (1 .. Dot_Position - 1)));
                              if GPR2.Project.Import.Set.Has_Element
                                                          (I_Cursor)
                              then
                                 Get_Type_Def_From
                                   (GPR2.Project.Import.Set.Element
                                      (I_Cursor));
                              end if;

                              exit when Type_Def.Is_Defined;
                           end loop;
                        end;
                     end if;
                  end if;

                  --  Check that the type has been defined

                  if Type_Def.Is_Defined
                    and then Type_Def.Count_Values /= 0
                  then
                     --  Check that we have a single value

                     if Values.Single then
                        --  Check that the value is part of the type

                        declare
                           Value : constant Value_Type :=
                                     Values.Values.First_Element.Text;
                        begin
                           if Value /= ""
                             and then
                               not To_Set (Type_Def.Values).Contains (Value)
                           then
                              Tree.Log_Messages.Append
                                (Message.Create
                                   (Level   => Message.Error,
                                    Sloc    => Sloc,
                                    Message => "value """ & Value
                                    & """ is illegal for typed string """
                                    & Get_Value_Type (Single_Tok_Node (Name))
                                    & '"'));
                           end if;
                        end;

                     else
                        Tree.Log_Messages.Append
                          (Message.Create
                             (Level   => Message.Error,
                              Sloc    => Sloc,
                              Message =>
                                "expression for """
                                & Get_Value_Type (Single_Tok_Node (Name))
                                & """ must be a single string"));
                     end if;

                  else
                     Tree.Log_Messages.Append
                       (Message.Create
                          (Level   => Message.Error,
                           Sloc    => Get_Source_Reference (Self.File, V_Type),
                           Message =>
                             "unknown string type """ & String (T_Name) &
                             '"'));
                  end if;
               end;
            end if;

            if Values = No_Values then
               --  Do not report failure of evaluating the left-hand side if
               --  errors have already been reported: failure to get the actual
               --  value(s) is most certainly a direct consequence of the
               --  previous error.
               --
               --  Detecting such error without other explicit error is not
               --  expected, so this is just a safe guard, not expected to be
               --  covered by tests.

               if not Tree.Log_Messages.Has_Error
                 and then Non_Fatal_Error.Is_Empty
               then
                  Tree.Log_Messages.Append
                    (Message.Create
                       (Level   => Message.Error,
                        Sloc    => Get_Source_Reference (Self.File, Name),
                        Message =>
                          "internal error evaluating the value for """ &
                          Get_Value_Type (Single_Tok_Node (Name)) &
                          '"'));
               end if;

               return;

            elsif Values.Single then
               V := GPR2.Project.Variable.Create
                 (Name  =>
                    Get_Identifier_Reference
                      (Self.File,
                       Sloc_Range (Name),
                       Get_Name_Type (Single_Tok_Node (Name))),
                  Value => Values.Values.First_Element,
                  Typ   => Type_Def);
            else
               V := GPR2.Project.Variable.Create
                 (Name   =>
                    Get_Identifier_Reference
                      (Self.File,
                       Sloc_Range (Name),
                       Get_Name_Type (Single_Tok_Node (Name))),
                  Values => Values.Values,
                  Typ    => Type_Def);
            end if;

            if In_Pack then
               Pack_Ref.Vars.Include (V.Name.Text, V);
            else
               Vars.Include (V.Name.Text, V);
            end if;
         end Parse_Variable_Decl;

         -----------------
         -- Visit_Child --
         -----------------

         procedure Visit_Child (Child : Gpr_Node) is
         begin
            if Present (Child) then
               Status := Traverse (Node => Child, Visit => Parser'Access);
            end if;
         end Visit_Child;

      begin
         if Is_Open then
            --  Handle all kind of nodes when the parsing is open

            case Kind (Node) is
               when Gpr_Project_Declaration =>
                  Parse_Project_Declaration (Node.As_Project_Declaration);

               when Gpr_Attribute_Decl =>
                  Parse_Attribute_Decl (Node.As_Attribute_Decl);

               when Gpr_Variable_Decl =>
                  Parse_Variable_Decl (Node.As_Variable_Decl);

               when Gpr_Package_Decl =>
                  Parse_Package_Decl (Node.As_Package_Decl);

               when Gpr_Package_Renaming =>
                  Parse_Package_Renaming (Node.As_Package_Renaming);

               when Gpr_Package_Extension =>
                  Parse_Package_Extension (Node.As_Package_Extension);

               when Gpr_Case_Construction =>
                  Parse_Case_Construction (Node.As_Case_Construction);

               when Gpr_Case_Item =>
                  Parse_Case_Item (Node.As_Case_Item);

               when others =>
                  null;
            end case;

         else
            --  We are on a closed parsing mode, only handle case alternatives
            --  and Spec and Body attributes

            case Kind (Node) is
               when Gpr_Case_Construction =>
                  Parse_Case_Construction (Node.As_Case_Construction);

               when Gpr_Case_Item =>
                  Parse_Case_Item (Node.As_Case_Item);

               when Gpr_Attribute_Decl =>
                  Parse_Attribute_Decl (Node.As_Attribute_Decl);

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

         if Has_Error then
            Status := Stop;
         end if;

         return Status;
      end Parser;

      ----------------------
      -- Record_Attribute --
      ----------------------

      procedure Record_Attribute
        (Set : in out PA.Set.Object;
         A   : PA.Object)
      is
         use type PRA.Value_Kind;
         use type PRA.Empty_Value_Status;

         Include : Boolean := True;
         Q_Name  : constant Q_Attribute_Id := A.Name.Id;
         Def     : PRA.Def;

      begin
         --  Check that a definition exists

         if not PRA.Exists (Q_Name) then
            if Q_Name.Pack = Project_Level_Scope
              or else PRP.Attributes_Are_Checked (Q_Name.Pack)
            then
               Tree.Log_Messages.Append
                 (Message.Create
                    (Level => Message.Error,
                     Sloc  => Source_Reference.Object (A),
                     Message => "unrecognized attribute """ &
                                Image (Q_Name) & """"));
            end if;

            Include := False;

         --  Malformed attribute values can be side-effects of another
         --  error (such as missing variable). So only perform the next
         --  checks if there's no critical error.

         elsif not Tree.Log_Messages.Has_Error then
            --  Check value kind

            Def := PRA.Get (Q_Name);

            if Def.Value /= A.Kind then
               if Def.Value = PRA.Single then
                  Tree.Log_Messages.Append
                    (Message.Create
                       (Level => Message.Error,
                        Sloc  => Source_Reference.Object (A),
                        Message => "attribute """ & Image (Q_Name) &
                                   """ expects a single value"));
               else
                  Tree.Log_Messages.Append
                    (Message.Create
                       (Level => Message.Error,
                        Sloc  => Source_Reference.Object (A),
                        Message => "attribute """ & Image (Q_Name) &
                                   """ expects a list of values"));
               end if;

               Include := False;

            elsif Def.Value = PRA.Single
              and then Def.Empty_Value in PRA.Error | PRA.Ignore
              and then Length (A.Value.Unchecked_Text) = 0
            then
               if Def.Empty_Value = PRA.Error then
                  Tree.Log_Messages.Append
                    (Message.Create
                       (Level   => Message.Error,
                        Sloc    => Source_Reference.Object (A.Value),
                        Message => "attribute """ & Image (Q_Name)
                                   & """ cannot be empty"));
               else
                  Tree.Log_Messages.Append
                    (Message.Create
                       (Level   => Message.Warning,
                        Sloc    => Source_Reference.Object (A.Value),
                        Message => "empty attribute """ & Image (Q_Name)
                                   & """ ignored"));
               end if;

               Include := False;

            elsif Q_Name = PRA.Main then
               --  A main attrbute must contain only basename and must reject
               --  full names. We ensure here that we don't have directory
               --  separators in the list of mains.
               for V of A.Values loop
                  declare
                     M : constant String := V.Text;
                  begin
                     --  Check for bath Unix & Windows directory separators
                     if Strings.Fixed.Index
                       (M, Strings.Maps.To_Set ("/\")) > 0
                     then
                        Tree.Log_Messages.Append
                          (Message.Create
                             (Level   => Message.Error,
                              Sloc    => Source_Reference.Object (A),
                              Message => "attribute """ & Image (Q_Name)
                                         & """ accepts only simple names"));
                     end if;
                  end;
               end loop;
            end if;

            --  Check the attribute index

            case Def.Index_Type is
               when PRA.No_Index =>
                  if A.Has_Index then
                     Tree.Log_Messages.Append
                       (Message.Create
                          (Level => Message.Error,
                           Sloc  => Source_Reference.Object (A.Index),
                           Message => "attribute """ & Image (Q_Name) &
                                      """ does not expect an index"));
                     Include := False;
                  end if;

               when others =>
                  if not A.Has_Index then
                     Tree.Log_Messages.Append
                       (Message.Create
                          (Level => Message.Error,
                           Sloc  => Source_Reference.Object (A),
                           Message => "attribute """ & Image (Q_Name) &
                                      """ expects an index"));
                     Include := False;

                  elsif A.Index.Is_Others
                    and then not Def.Index_Optional
                  then
                     Tree.Log_Messages.Append
                       (Message.Create
                          (Level => Message.Error,
                           Sloc  => Source_Reference.Object (A),
                           Message => "'others' index not allowed with """ &
                                      Image (Q_Name) & """"));
                     Include := False;
                  end if;
            end case;
         end if;

         if Set.Contains (A) then
            declare
               Old : constant PA.Object :=
                       Set.Element (A.Name.Id.Attr, A.Index);
            begin
               if Old.Is_Frozen then
                  Tree.Log_Messages.Append
                    (Message.Create
                       (Level => Message.Error,
                        Sloc  => Source_Reference.Object (A),
                        Message => "cannot set configuration attribute """ &
                          Image (A.Name.Id) &
                          """ after it was referenced"));
                  Include := False;
               end if;
            end;
         end if;

         if Include then
            Set.Include (A);
         end if;
      end Record_Attribute;

      ------------
      -- To_Set --
      ------------

      function To_Set
        (Values : Containers.Source_Value_List) return Containers.Value_Set is
      begin
         return Set : Containers.Value_Set do
            for V of Values loop
               Set.Insert (V.Text);
            end loop;
         end return;
      end To_Set;

      Is_Parsed_Project : constant Boolean := Self.Unit /= No_Analysis_Unit;

   begin
      if Is_Parsed_Project then
         Attrs.Clear;
         Vars.Clear;
         Packs.Clear;
      end if;

      --  Insert intrinsic attributes Name and Project_Dir

      declare
         use Characters.Handling;

         Sloc : constant Source_Reference.Object :=
                  Source_Reference.Object
                    (Source_Reference.Create (Self.File.Value, 0, 0));

         function Create_Attr
           (Name : Q_Attribute_Id) return Source_Reference.Attribute.Object
         is
           (Source_Reference.Attribute.Object
              (Source_Reference.Attribute.Create (Sloc, Name)));

      begin
         Attrs.Insert
           (PA.Create
              (Name    => Create_Attr (PRA.Name),
               Value   => Get_Value_Reference
                            (To_Lower (To_String (Self.Name)), Sloc),
               Default => True));

         Attrs.Insert
           (PA.Create
              (Name    => Create_Attr (PRA.Project_Dir),
               Value   => Get_Value_Reference (Self.File.Dir_Name, Sloc),
               Default => True));
      end;

      Types := Self.Types;

      if Is_Parsed_Project then
         Definition.Get (View).Disable_Cache;
         Traverse (Root (Self.Unit), Parser'Access);
         Definition.Get (View).Enable_Cache;
      end if;

      --  Fill possible non-fatal errors into the tree now

      for M of Non_Fatal_Error loop
         Tree.Log_Messages.Append (M);
      end loop;

      for F of Actual loop
         Self.Skip_Src.Exclude (F);
      end loop;
   end Process;

   ---------------
   -- Qualifier --
   ---------------

   function Qualifier (Self : Object) return Project_Kind is
   begin
      return Self.Qualifier;
   end Qualifier;

   ----------
   -- Unit --
   ----------

   function Unit (Self : Object) return Analysis_Unit is
   begin
      return Self.Unit;
   end Unit;

end GPR2.Project.Parser;