1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
|
-- Semantic analysis.
-- Copyright (C) 2002, 2003, 2004, 2005 Tristan Gingold
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 2 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <gnu.org/licenses>.
with Flags; use Flags;
with Name_Table;
with Libraries;
with Vhdl.Evaluation; use Vhdl.Evaluation;
with Vhdl.Utils; use Vhdl.Utils;
with Errorout; use Errorout;
with Vhdl.Errors; use Vhdl.Errors;
with Vhdl.Std_Package; use Vhdl.Std_Package;
with Types; use Types;
with Vhdl.Nodes_Utils; use Vhdl.Nodes_Utils;
with Std_Names;
with Vhdl.Sem;
with Vhdl.Sem_Lib; use Vhdl.Sem_Lib;
with Vhdl.Sem_Scopes; use Vhdl.Sem_Scopes;
with Vhdl.Sem_Expr; use Vhdl.Sem_Expr;
with Vhdl.Sem_Stmts; use Vhdl.Sem_Stmts;
with Vhdl.Sem_Decls; use Vhdl.Sem_Decls;
with Vhdl.Sem_Assocs; use Vhdl.Sem_Assocs;
with Vhdl.Sem_Specs;
with Vhdl.Sem_Types;
with Vhdl.Sem_Psl;
with Vhdl.Xrefs; use Vhdl.Xrefs;
package body Vhdl.Sem_Names is
-- Finish the analyze of NAME using RES as named entity.
-- This is called when the analyze is finished and an uniq
-- interpretation has been determined (RES).
--
-- Error messages are emitted here.
function Finish_Sem_Name (Name : Iir; Res : Iir) return Iir;
-- Return the fully analyzed name of NAME.
function Name_To_Analyzed_Name (Name : Iir) return Iir;
procedure Error_Overload (Expr: Iir) is
begin
if Is_Error (Expr) then
-- Avoid error storm.
return;
end if;
Error_Msg_Sem (+Expr, "can't resolve overload for %n", +Expr);
end Error_Overload;
procedure Disp_Overload_List (List : Iir_List; Loc : Iir)
is
El : Iir;
It : List_Iterator;
begin
Error_Msg_Sem (+Loc, "possible interpretations are:");
It := List_Iterate (List);
while Is_Valid (It) loop
El := Get_Element (It);
case Get_Kind (El) is
when Iir_Kind_Function_Declaration
| Iir_Kind_Procedure_Declaration =>
Error_Msg_Sem (+El, Disp_Subprg (El));
when Iir_Kind_Function_Call =>
El := Get_Implementation (El);
Error_Msg_Sem (+El, Disp_Subprg (El));
when others =>
Error_Msg_Sem (+El, "%n", +El);
end case;
Next (It);
end loop;
end Disp_Overload_List;
-- Create an overload list.
-- must be destroyed with free_iir.
function Get_Overload_List return Iir_Overload_List
is
Res : Iir;
begin
Res := Create_Iir (Iir_Kind_Overload_List);
return Res;
end Get_Overload_List;
function Create_Overload_List (List : Iir_List) return Iir_Overload_List
is
Res : Iir_Overload_List;
begin
Res := Get_Overload_List;
Set_Overload_List (Res, List);
return Res;
end Create_Overload_List;
procedure Free_Overload_List (N : in out Iir_Overload_List)
is
List : Iir_List;
begin
List := Get_Overload_List (N);
Destroy_Iir_List (List);
Free_Iir (N);
N := Null_Iir;
end Free_Overload_List;
function Simplify_Overload_List (List : Iir_List) return Iir
is
Res : Iir;
L1 : Iir_List;
begin
case Get_Nbr_Elements (List) is
when 0 =>
L1 := List;
Destroy_Iir_List (L1);
return Null_Iir;
when 1 =>
L1 := List;
Res := Get_First_Element (List);
Destroy_Iir_List (L1);
return Res;
when others =>
return Create_Overload_List (List);
end case;
end Simplify_Overload_List;
-- Return true if AN_IIR is an overload list.
function Is_Overload_List (An_Iir: Iir) return Boolean is
begin
return Get_Kind (An_Iir) = Iir_Kind_Overload_List;
end Is_Overload_List;
function Is_Defined_Type (Atype : Iir) return Boolean is
begin
return Atype /= Null_Iir
and then not Kind_In (Get_Kind (Atype),
Iir_Kind_Overload_List,
Iir_Kind_Wildcard_Type_Definition);
end Is_Defined_Type;
-- From the list LIST of function or enumeration literal, extract the
-- list of (return) types.
-- If there is only one type, return it.
-- If there is no types, return NULL.
-- Otherwise, return the list as an overload list.
function Create_List_Of_Types (List : Iir_List)
return Iir
is
Res_List : Iir_List;
Decl : Iir;
It : List_Iterator;
begin
-- Create the list of possible return types.
Res_List := Create_Iir_List;
It := List_Iterate (List);
while Is_Valid (It) loop
Decl := Get_Element (It);
case Get_Kind (Decl) is
when Iir_Kind_Function_Declaration =>
Add_Element (Res_List, Get_Return_Type (Decl));
when Iir_Kind_Enumeration_Literal
| Iir_Kind_Function_Call
| Iir_Kind_Indexed_Name
| Iir_Kind_Slice_Name
| Iir_Kind_Selected_Element
| Iir_Kind_Dereference =>
Add_Element (Res_List, Get_Type (Decl));
when others =>
Error_Kind ("create_list_of_types", Decl);
end case;
Next (It);
end loop;
return Simplify_Overload_List (Res_List);
end Create_List_Of_Types;
procedure Add_Result (Res : in out Iir; Decl : Iir)
is
Nres : Iir;
Nres_List : Iir_List;
begin
if Decl = Null_Iir then
return;
end if;
if Res = Null_Iir then
Res := Decl;
elsif Is_Overload_List (Res) then
Append_Element (Get_Overload_List (Res), Decl);
else
Nres_List := Create_Iir_List;
Nres := Create_Overload_List (Nres_List);
Append_Element (Nres_List, Res);
Append_Element (Nres_List, Decl);
Res := Nres;
end if;
end Add_Result;
-- Extract from overload list RES the function call without implicit
-- conversion. Return Null_Iir if there is no function call, or if there
-- is an expressions that isn't a function call, or if there is more than
-- one function call without implicit conversion.
-- Cf Sem_Expr.Get_Non_Implicit_Subprogram
function Extract_Call_Without_Implicit_Conversion (Res : Iir) return Iir
is
pragma Assert (Is_Overload_List (Res));
List : constant Iir_List := Get_Overload_List (Res);
It : List_Iterator;
Call : Iir;
El : Iir;
Imp : Iir;
Inter : Iir;
begin
Call := Null_Iir;
It := List_Iterate (List);
while Is_Valid (It) loop
El := Get_Element (It);
if Get_Kind (El) = Iir_Kind_Function_Call then
Imp := Get_Implementation (El);
Inter := Get_Interface_Declaration_Chain (Imp);
if Get_Type (Inter) = Universal_Integer_Type_Definition
or else Get_Type (Inter) = Universal_Real_Type_Definition
then
-- The type of the first interface is a universal type. So,
-- there were no implicit conversions. Once there is an
-- implicit conversion, the only way to 'convert' to a
-- universal type is through T'Pos, which has to be resolved.
-- Note: there are no interface of convertible types.
-- GHDL: this is not proven...
if Call /= Null_Iir then
-- More than one call without implicit conversion.
return Null_Iir;
else
Call := El;
end if;
end if;
else
return Null_Iir;
end if;
Next (It);
end loop;
return Call;
end Extract_Call_Without_Implicit_Conversion;
-- Move elements of result list LIST to result list RES.
-- Destroy LIST if necessary.
procedure Add_Result_List (Res : in out Iir; List : Iir);
pragma Unreferenced (Add_Result_List);
procedure Add_Result_List (Res : in out Iir; List : Iir)
is
El : Iir;
List_List : Iir_List;
Res_List : Iir_List;
It : List_Iterator;
begin
if Res = Null_Iir then
Res := List;
elsif List = Null_Iir then
null;
elsif not Is_Overload_List (List) then
Add_Result (Res, List);
else
if not Is_Overload_List (Res) then
El := Res;
Res := Get_Overload_List;
Append_Element (Get_Overload_List (Res), El);
end if;
List_List := Get_Overload_List (List);
Res_List := Get_Overload_List (Res);
It := List_Iterate (List_List);
while Is_Valid (It) loop
Append_Element (Res_List, Get_Element (It));
Next (It);
end loop;
Free_Iir (List);
end if;
end Add_Result_List;
-- Free interpretations of LIST except KEEP (which can be Null_Iir to free
-- the whole list).
procedure Sem_Name_Free_Result (List : Iir; Keep : Iir)
is
procedure Sem_Name_Free (El : Iir) is
begin
case Get_Kind (El) is
when Iir_Kind_Function_Call
| Iir_Kind_Indexed_Name
| Iir_Kind_Selected_Element =>
Sem_Name_Free (Get_Prefix (El));
Free_Iir (El);
when Iir_Kind_Attribute_Name =>
Free_Iir (El);
when Iir_Kind_Function_Declaration
| Iir_Kind_Procedure_Declaration
| Iir_Kind_Enumeration_Literal =>
null;
when Iir_Kind_Interface_Function_Declaration
| Iir_Kind_Interface_Procedure_Declaration =>
null;
when Iir_Kinds_Denoting_Name =>
null;
when others =>
Error_Kind ("sem_name_free", El);
end case;
end Sem_Name_Free;
El : Iir;
List_List : Iir_List;
It : List_Iterator;
begin
if List = Null_Iir then
return;
elsif not Is_Overload_List (List) then
if List /= Keep then
Sem_Name_Free (List);
end if;
else
List_List := Get_Overload_List (List);
It := List_Iterate (List_List);
while Is_Valid (It) loop
El := Get_Element (It);
if El /= Keep then
Sem_Name_Free (El);
end if;
Next (It);
end loop;
Free_Iir (List);
end if;
end Sem_Name_Free_Result;
procedure Free_Parenthesis_Name (Name : Iir; Res : Iir)
is
Chain, Next_Chain : Iir;
begin
pragma Assert (Get_Kind (Res) /= Iir_Kind_Function_Call);
Chain := Get_Association_Chain (Name);
while Chain /= Null_Iir loop
Next_Chain := Get_Chain (Chain);
Free_Iir (Chain);
Chain := Next_Chain;
end loop;
Free_Iir (Name);
end Free_Parenthesis_Name;
-- Find all named declaration whose identifier is ID in DECL_LIST and
-- return it.
-- The result can be NULL (if no such declaration exist),
-- a declaration, or an overload_list containing all declarations.
function Find_Declarations_In_List
(Decl: Iir; Name : Iir_Selected_Name; Keep_Alias : Boolean)
return Iir
is
Res: Iir := Null_Iir;
-- If indentifier of DECL is ID, then add DECL in the result.
procedure Handle_Decl (Decl : Iir; Id : Name_Id) is
begin
-- Use_clauses may appear in a declaration list.
case Get_Kind (Decl) is
when Iir_Kind_Use_Clause
| Iir_Kind_Anonymous_Type_Declaration =>
return;
when Iir_Kind_Non_Object_Alias_Declaration =>
if Get_Identifier (Decl) = Id then
if Keep_Alias then
Add_Result (Res, Decl);
else
Add_Result (Res, Get_Named_Entity (Get_Name (Decl)));
end if;
end if;
when others =>
-- Consider only visible declarations (case of an implicit
-- declaration that is overriden by explicit one).
if Get_Identifier (Decl) = Id and Get_Visible_Flag (Decl) then
Add_Result (Res, Decl);
end if;
end case;
end Handle_Decl;
procedure Iterator_Decl is new Sem_Scopes.Iterator_Decl
(Arg_Type => Name_Id, Handle_Decl => Handle_Decl);
--procedure Iterator_Decl_List is new Sem_Scopes.Iterator_Decl_List
-- (Arg_Type => Name_Id, Handle_Decl => Iterator_Decl);
procedure Iterator_Decl_Chain is new Sem_Scopes.Iterator_Decl_Chain
(Arg_Type => Name_Id, Handle_Decl => Iterator_Decl);
Id : constant Name_Id := Get_Identifier (Name);
begin
case Get_Kind (Decl) is
when Iir_Kind_Function_Declaration
| Iir_Kind_Procedure_Declaration =>
Iterator_Decl_Chain (Get_Interface_Declaration_Chain (Decl), Id);
when Iir_Kind_Entity_Declaration =>
Iterator_Decl_Chain (Get_Generic_Chain (Decl), Id);
Iterator_Decl_Chain (Get_Port_Chain (Decl), Id);
when Iir_Kind_Architecture_Body =>
null;
when Iir_Kind_If_Generate_Statement
| Iir_Kind_For_Generate_Statement =>
null;
when Iir_Kind_Package_Declaration =>
declare
Header : constant Iir := Get_Package_Header (Decl);
begin
if Is_Valid (Header)
and then Get_Is_Within_Flag (Decl)
then
Iterator_Decl_Chain (Get_Generic_Chain (Header), Id);
end if;
end;
when Iir_Kind_Package_Instantiation_Declaration
| Iir_Kind_Interface_Package_Declaration =>
-- Generics are not visible in selected name.
null;
-- Iterator_Decl_Chain (Get_Generic_Chain (Decl), Id);
when Iir_Kind_Block_Statement =>
declare
Header : constant Iir := Get_Block_Header (Decl);
begin
if Header /= Null_Iir then
Iterator_Decl_Chain (Get_Generic_Chain (Header), Id);
Iterator_Decl_Chain (Get_Port_Chain (Header), Id);
end if;
end;
when Iir_Kind_For_Loop_Statement =>
Handle_Decl (Get_Parameter_Specification (Decl), Id);
when Iir_Kind_Process_Statement
| Iir_Kind_Sensitized_Process_Statement =>
null;
when others =>
Error_Kind ("find_declarations_in_list", Decl);
end case;
case Get_Kind (Decl) is
when Iir_Kind_Function_Declaration
| Iir_Kind_Procedure_Declaration =>
declare
Decl_Body : constant Iir := Get_Subprogram_Body (Decl);
begin
Iterator_Decl_Chain
(Get_Declaration_Chain (Decl_Body), Id);
Iterator_Decl_Chain
(Get_Sequential_Statement_Chain (Decl_Body), Id);
end;
when Iir_Kind_Architecture_Body
| Iir_Kind_Entity_Declaration
| Iir_Kind_Block_Statement =>
Iterator_Decl_Chain (Get_Declaration_Chain (Decl), Id);
Iterator_Decl_Chain (Get_Concurrent_Statement_Chain (Decl), Id);
when Iir_Kind_For_Generate_Statement =>
declare
Bod : constant Iir := Get_Generate_Statement_Body (Decl);
begin
Iterator_Decl_Chain (Get_Declaration_Chain (Bod), Id);
Iterator_Decl_Chain (Get_Concurrent_Statement_Chain (Bod), Id);
end;
when Iir_Kind_If_Generate_Statement =>
declare
Clause : Iir;
Bod : Iir;
begin
-- Look only in the current generate_statement_body
Clause := Decl;
while Clause /= Null_Iir loop
Bod := Get_Generate_Statement_Body (Clause);
if Get_Is_Within_Flag (Bod) then
Iterator_Decl_Chain
(Get_Declaration_Chain (Bod), Id);
Iterator_Decl_Chain
(Get_Concurrent_Statement_Chain (Bod), Id);
exit;
end if;
Clause := Get_Generate_Else_Clause (Clause);
end loop;
end;
when Iir_Kind_Package_Declaration
| Iir_Kind_Package_Instantiation_Declaration
| Iir_Kind_Interface_Package_Declaration =>
Iterator_Decl_Chain (Get_Declaration_Chain (Decl), Id);
when Iir_Kind_Process_Statement
| Iir_Kind_Sensitized_Process_Statement =>
Iterator_Decl_Chain (Get_Declaration_Chain (Decl), Id);
Iterator_Decl_Chain (Get_Sequential_Statement_Chain (Decl), Id);
when Iir_Kind_For_Loop_Statement =>
null;
when others =>
Error_Kind ("find_declarations_in_list", Decl);
end case;
--if Res = Null_Iir then
-- Error_Msg_Sem ("""" & Name_Table.Image (Id) & """ not defined in "
-- & Disp_Node (Decl), Name);
--end if;
return Res;
end Find_Declarations_In_List;
-- Create an implicit_dereference node if PREFIX is of type access.
-- Return PREFIX otherwise.
-- PARENT is used if an implicit dereference node is created, to copy
-- location from.
function Insert_Implicit_Dereference (Prefix : Iir; Parent : Iir)
return Iir
is
Prefix_Type : Iir;
Res : Iir_Implicit_Dereference;
begin
Prefix_Type := Get_Type (Prefix);
case Get_Kind (Prefix_Type) is
when Iir_Kind_Access_Type_Definition
| Iir_Kind_Access_Subtype_Definition =>
null;
when others =>
return Prefix;
end case;
Check_Read (Prefix);
Res := Create_Iir (Iir_Kind_Implicit_Dereference);
Location_Copy (Res, Parent);
Set_Type (Res, Get_Designated_Type (Prefix_Type));
Set_Prefix (Res, Prefix);
Set_Base_Name (Res, Res);
Set_Expr_Staticness (Res, None);
return Res;
end Insert_Implicit_Dereference;
-- If PREFIX is a function specification that cannot be converted to a
-- function call (because of lack of association), return FALSE.
function Maybe_Function_Call (Prefix : Iir) return Boolean
is
Inter : Iir;
begin
if Get_Kind (Prefix) /= Iir_Kind_Function_Declaration then
return True;
end if;
Inter := Get_Interface_Declaration_Chain (Prefix);
while Inter /= Null_Iir loop
if Get_Default_Value (Inter) = Null_Iir then
return False;
end if;
Inter := Get_Chain (Inter);
end loop;
return True;
end Maybe_Function_Call;
procedure Name_To_Method_Object (Call : Iir; Name : Iir)
is
Prefix : Iir;
Obj : Iir;
Obj_Alias : Iir;
Obj_Type : Iir;
begin
if Get_Kind (Name) /= Iir_Kind_Selected_Name then
return;
end if;
Prefix := Get_Prefix (Name);
Obj := Get_Named_Entity (Prefix);
if Obj = Null_Iir then
return;
end if;
if Get_Kind (Obj) = Iir_Kind_Object_Alias_Declaration then
Obj_Alias := Get_Named_Entity (Get_Name (Obj));
else
Obj_Alias := Obj;
end if;
if Kind_In (Obj_Alias, Iir_Kind_Variable_Declaration,
Iir_Kind_Interface_Variable_Declaration)
then
Obj_Type := Get_Type (Obj_Alias);
if Obj_Type = Null_Iir then
return;
end if;
if Get_Kind (Obj_Type) /= Iir_Kind_Protected_Type_Declaration
then
Error_Msg_Sem
(+Prefix, "type of the prefix should be a protected type");
return;
end if;
Set_Method_Object (Call, Obj_Alias);
Set_Use_Flag (Obj, True);
end if;
end Name_To_Method_Object;
-- NAME is the name of the function (and not the parenthesis name)
function Sem_As_Function_Call (Name : Iir; Spec : Iir; Assoc_Chain : Iir)
return Iir_Function_Call
is
Call : Iir_Function_Call;
begin
-- Check.
pragma Assert (Get_Kind (Name) in Iir_Kinds_Denoting_Name);
Call := Create_Iir (Iir_Kind_Function_Call);
Location_Copy (Call, Name);
if Get_Kind (Name) = Iir_Kind_Parenthesis_Name then
Set_Prefix (Call, Get_Prefix (Name));
else
Set_Prefix (Call, Name);
end if;
Name_To_Method_Object (Call, Name);
Set_Implementation (Call, Spec);
Set_Parameter_Association_Chain (Call, Assoc_Chain);
Set_Type (Call, Get_Return_Type (Spec));
Set_Base_Name (Call, Call);
return Call;
end Sem_As_Function_Call;
-- If SPEC is a function specification, then return a function call,
-- else return SPEC.
function Maybe_Insert_Function_Call (Name : Iir; Spec : Iir) return Iir
is
begin
if Get_Kind (Spec) = Iir_Kind_Function_Declaration then
return Sem_As_Function_Call (Name, Spec, Null_Iir);
else
return Spec;
end if;
end Maybe_Insert_Function_Call;
-- If PTR_TYPE is not NULL_IIR, then return an implciti dereference to
-- PREFIX, else return PREFIX.
function Maybe_Insert_Dereference (Prefix : Iir; Ptr_Type : Iir) return Iir
is
Id : Iir;
begin
if Ptr_Type /= Null_Iir then
Id := Create_Iir (Iir_Kind_Implicit_Dereference);
Location_Copy (Id, Prefix);
Set_Type (Id, Get_Designated_Type (Ptr_Type));
Set_Prefix (Id, Prefix);
Set_Base_Name (Id, Id);
return Id;
else
return Prefix;
end if;
end Maybe_Insert_Dereference;
procedure Finish_Sem_Indexed_Name (Expr : Iir)
is
Prefix : constant Iir := Get_Prefix (Expr);
Prefix_Type : constant Iir := Get_Type (Prefix);
Index_List : constant Iir_Flist := Get_Index_List (Expr);
Index_Subtype : Iir;
Index : Iir;
Expr_Staticness : Iir_Staticness;
begin
Expr_Staticness := Locally;
-- LRM93 6.4: there must be one such expression for each index
-- position of the array and each expression must be of the
-- type of the corresponding index.
-- Loop on the indexes.
for I in Flist_First .. Flist_Last (Index_List) loop
Index := Get_Nth_Element (Index_List, I);
Index_Subtype := Get_Index_Type (Prefix_Type, I);
-- The index_subtype can be an unconstrained index type.
Index := Check_Is_Expression (Index, Index);
if Index /= Null_Iir then
Index := Sem_Expression (Index, Get_Base_Type (Index_Subtype));
end if;
if Index /= Null_Iir then
Check_Read (Index);
if Get_Expr_Staticness (Index) = Locally
and then Get_Type_Staticness (Index_Subtype) = Locally
then
Index := Eval_Expr_Check (Index, Index_Subtype);
end if;
Set_Nth_Element (Index_List, I, Index);
Expr_Staticness := Min (Expr_Staticness,
Get_Expr_Staticness (Index));
else
Expr_Staticness := None;
end if;
end loop;
Set_Type (Expr, Get_Element_Subtype (Prefix_Type));
-- LRM93 6.1
-- a name is said to be a static name iff:
-- The name is an indexed name whose prefix is a static name
-- and every expression that appears as part of the name is a
-- static expression.
--
-- a name is said to be a locally static name iif:
-- The name is an indexed name whose prefix is a locally
-- static name and every expression that appears as part
-- of the name is a locally static expression.
Set_Name_Staticness
(Expr, Min (Expr_Staticness, Get_Name_Staticness (Prefix)));
-- An indexed name cannot be locally static.
if Flags.Vhdl_Std < Vhdl_08 then
Expr_Staticness := Min (Globally, Expr_Staticness);
end if;
Set_Expr_Staticness
(Expr, Min (Expr_Staticness, Get_Expr_Staticness (Prefix)));
Set_Base_Name (Expr, Get_Base_Name (Prefix));
end Finish_Sem_Indexed_Name;
procedure Finish_Sem_Dereference (Res : Iir) is
begin
Set_Base_Name (Res, Res);
Check_Read (Get_Prefix (Res));
Set_Expr_Staticness (Res, None);
Set_Name_Staticness (Res, None);
end Finish_Sem_Dereference;
procedure Finish_Sem_Slice_Name (Name : Iir_Slice_Name)
is
-- The prefix of the slice
Prefix : constant Iir := Get_Prefix (Name);
Prefix_Type : constant Iir := Get_Type (Prefix);
Prefix_Base_Type : Iir;
Prefix_Bt : constant Iir := Get_Base_Type (Prefix_Type);
Index_List: Iir_Flist;
Index_Type: Iir;
Suffix: Iir;
Slice_Type : Iir;
Expr_Type : Iir;
Staticness : Iir_Staticness;
Prefix_Rng : Iir;
Suffix_Rng : Iir;
begin
Set_Base_Name (Name, Get_Base_Name (Prefix));
-- LRM93 6.5: the prefix of an indexed name must be appropriate
-- for an array type.
if Get_Kind (Prefix_Bt) /= Iir_Kind_Array_Type_Definition then
Error_Msg_Sem (+Name, "slice can only be applied to an array");
return;
end if;
-- LRM93 6.5:
-- The prefix of a slice must be appropriate for a
-- one-dimensionnal array object.
Index_List := Get_Index_Subtype_List (Prefix_Type);
if Get_Nbr_Elements (Index_List) /= 1 then
Error_Msg_Sem
(+Name, "slice prefix must be an one-dimensional array");
return;
end if;
Index_Type := Get_Index_Type (Index_List, 0);
Prefix_Rng := Eval_Static_Range (Index_Type);
-- LRM93 6.5
-- It is an error if either the bounds of the discrete range does not
-- belong to the index range of the prefixing array, *unless* the slice
-- is a null slice.
--
-- LRM93 6.5
-- The slice is a null slice if the discrete range is a null range.
-- LRM93 6.5:
-- The bounds of the discrete range [...] must be of the
-- type of the index of the array.
Suffix := Get_Suffix (Name);
Suffix := Sem_Discrete_Range (Suffix, Index_Type, False);
if Suffix = Null_Iir then
return;
end if;
case Get_Kind (Suffix) is
when Iir_Kind_Simple_Name
| Iir_Kind_Selected_Name =>
Staticness := Get_Type_Staticness (Get_Type (Suffix));
Suffix_Rng := Get_Range_Constraint (Get_Type (Suffix));
when Iir_Kinds_Scalar_Subtype_Definition =>
Staticness := Get_Type_Staticness (Suffix);
Suffix_Rng := Get_Range_Constraint (Suffix);
when Iir_Kind_Range_Expression
| Iir_Kind_Range_Array_Attribute
| Iir_Kind_Reverse_Range_Array_Attribute =>
Suffix := Eval_Range_If_Static (Suffix);
Suffix_Rng := Suffix;
Staticness := Get_Expr_Staticness (Suffix);
when others =>
Error_Kind ("finish_sem_slice_name", Suffix);
end case;
Set_Suffix (Name, Suffix);
-- LRM93 6.5:
-- It is an error if the direction of the discrete range is not
-- the same as that of the index range of the array denoted
-- by the prefix of the slice name.
-- Check this only if the type is a constrained type.
if Get_Kind (Prefix_Type) = Iir_Kind_Array_Subtype_Definition
and then Get_Index_Constraint_Flag (Prefix_Type)
and then Staticness = Locally
and then Prefix_Rng /= Null_Iir
and then Get_Direction (Suffix_Rng) /= Get_Direction (Prefix_Rng)
then
if False and then Flags.Vhdl_Std = Vhdl_87 then
-- emit a warning for a null slice.
Warning_Msg_Sem (Warnid_Runtime_Error, +Name,
"direction mismatch results in a null slice");
end if;
Error_Msg_Sem (+Name, "direction of the range mismatch");
end if;
-- LRM93 7.4.1
-- A slice is never a locally static expression.
Set_Expr_Staticness
(Name, Min (Min (Staticness, Get_Expr_Staticness (Prefix)), Globally));
Set_Name_Staticness
(Name, Min (Staticness, Get_Name_Staticness (Prefix)));
Expr_Type := Create_Iir (Iir_Kind_Array_Subtype_Definition);
Set_Location (Expr_Type, Get_Location (Suffix));
-- The type of the slice is a subtype of the base type whose
-- range contraint is the slice itself.
case Get_Kind (Suffix) is
when Iir_Kinds_Denoting_Name =>
Slice_Type := Get_Type (Suffix);
when Iir_Kinds_Scalar_Subtype_Definition =>
Slice_Type := Suffix;
when others =>
case Get_Kind (Get_Base_Type (Index_Type)) is
when Iir_Kind_Integer_Type_Definition =>
Slice_Type :=
Create_Iir (Iir_Kind_Integer_Subtype_Definition);
when Iir_Kind_Enumeration_Type_Definition =>
Slice_Type :=
Create_Iir (Iir_Kind_Enumeration_Subtype_Definition);
when others =>
Error_Kind
("sem_expr: slice_name", Get_Base_Type (Index_Type));
end case;
Set_Range_Constraint (Slice_Type, Suffix_Rng);
Set_Is_Ref (Slice_Type, True);
Set_Type_Staticness (Slice_Type, Staticness);
Set_Parent_Type (Slice_Type, Get_Base_Type (Index_Type));
Set_Location (Slice_Type, Get_Location (Suffix));
-- Attach the new index subtype to the array subtype.
Index_List := Create_Iir_Flist (1);
Set_Index_Constraint_List (Expr_Type, Index_List);
Set_Nth_Element (Index_List, 0, Slice_Type);
end case;
Index_List := Create_Iir_Flist (1);
Set_Index_Subtype_List (Expr_Type, Index_List);
Set_Nth_Element (Index_List, 0, Slice_Type);
Prefix_Base_Type := Get_Base_Type (Prefix_Type);
Set_Parent_Type (Expr_Type, Prefix_Base_Type);
Set_Signal_Type_Flag (Expr_Type,
Get_Signal_Type_Flag (Prefix_Base_Type));
Set_Element_Subtype (Expr_Type, Get_Element_Subtype (Prefix_Type));
if Get_Kind (Prefix_Type) = Iir_Kind_Array_Subtype_Definition then
Set_Resolution_Indication
(Expr_Type, Sem_Types.Copy_Resolution_Indication (Prefix_Type));
else
Set_Resolution_Indication (Expr_Type, Null_Iir);
end if;
Set_Type_Staticness
(Expr_Type, Min (Get_Type_Staticness (Prefix_Type),
Get_Type_Staticness (Slice_Type)));
Set_Type (Name, Expr_Type);
Set_Slice_Subtype (Name, Expr_Type);
Set_Index_Constraint_Flag (Expr_Type, True);
Set_Constraint_State (Expr_Type, Fully_Constrained);
if Is_Signal_Object (Prefix) then
Sem_Types.Set_Type_Has_Signal (Expr_Type);
end if;
end Finish_Sem_Slice_Name;
-- PREFIX is the name denoting the function declaration, and its analysis
-- is already finished.
procedure Finish_Sem_Function_Call (Call : Iir; Prefix : Iir)
is
Rtype : Iir;
begin
Set_Prefix (Call, Prefix);
Set_Implementation (Call, Get_Named_Entity (Prefix));
-- LRM08 8.1 Names
-- The name is a simple name or selected name that does NOT denote a
-- function call [...]
--
-- GHDL: so function calls are never static names.
Set_Name_Staticness (Call, None);
-- FIXME: modify sem_subprogram_call to avoid such a type swap.
Rtype := Get_Type (Call);
Set_Type (Call, Null_Iir);
if Sem_Subprogram_Call (Call, Null_Iir) = Null_Iir then
Set_Type (Call, Rtype);
end if;
end Finish_Sem_Function_Call;
function Function_Declaration_To_Call (Name : Iir) return Iir
is
Expr : Iir;
begin
Expr := Get_Named_Entity (Name);
if Maybe_Function_Call (Expr) then
Expr := Sem_As_Function_Call (Name, Expr, Null_Iir);
pragma Assert (Get_Kind (Expr) = Iir_Kind_Function_Call);
Finish_Sem_Function_Call (Expr, Name);
return Expr;
else
Error_Msg_Sem (+Name, "%n requires parameters", +Expr);
Set_Type (Name, Get_Type (Expr));
Set_Expr_Staticness (Name, None);
Set_Named_Entity (Name, Create_Error_Expr (Expr, Get_Type (Expr)));
return Name;
end if;
end Function_Declaration_To_Call;
function Sem_Type_Mark (Name : Iir; Incomplete : Boolean := False)
return Iir
is
Atype : Iir;
Res : Iir;
begin
-- The name must not have been analyzed.
pragma Assert (Get_Type (Name) = Null_Iir);
if Is_Error (Name) then
Set_Type (Name, Name);
return Name;
end if;
-- Analyze the name (if not already done).
Res := Get_Named_Entity (Name);
if Res = Null_Iir then
Sem_Name (Name);
Res := Get_Named_Entity (Name);
end if;
if Res /= Null_Iir and then Is_Overload_List (Res) then
Error_Msg_Sem (+Name, "name does not denote a type mark");
return Create_Error_Type (Name);
end if;
Res := Finish_Sem_Name (Name);
-- LRM87 14.1 Predefined attributes
if Get_Kind (Res) = Iir_Kind_Base_Attribute then
Error_Msg_Sem
(+Name, "'Base attribute cannot be used as a type mark");
end if;
Atype := Name_To_Type_Definition (Res);
if Is_Error (Atype) then
if Get_Kind (Res) in Iir_Kinds_Denoting_Name then
Set_Named_Entity (Res, Atype);
else
return Create_Error_Type (Name);
end if;
elsif not Incomplete then
if Get_Kind (Atype) = Iir_Kind_Incomplete_Type_Definition then
Error_Msg_Sem
(+Name, "invalid use of an incomplete type definition");
Atype := Create_Error_Type (Name);
Set_Named_Entity (Res, Atype);
end if;
end if;
Set_Type (Res, Atype);
return Res;
end Sem_Type_Mark;
-- Return Globally if the prefix of NAME is a globally static name.
function Get_Object_Type_Staticness (Name : Iir) return Iir_Staticness
is
Base : constant Iir := Get_Base_Name (Name);
Parent : Iir;
begin
if Get_Kind (Base) in Iir_Kinds_Dereference then
-- A dereferenced object is never static.
return None;
end if;
Parent := Get_Parent (Base);
loop
case Get_Kind (Parent) is
when Iir_Kind_Entity_Declaration
| Iir_Kind_Architecture_Body
| Iir_Kind_Block_Statement
| Iir_Kind_Block_Header
| Iir_Kind_Component_Declaration
| Iir_Kinds_Process_Statement
| Iir_Kind_Generate_Statement_Body
| Iir_Kind_Design_Unit =>
-- Globally static.
return Globally;
when Iir_Kind_Package_Declaration
| Iir_Kind_Package_Body
| Iir_Kind_Package_Instantiation_Declaration
| Iir_Kind_Protected_Type_Body =>
-- Possibly nested construct.
Parent := Get_Parent (Parent);
when Iir_Kinds_Subprogram_Declaration
| Iir_Kinds_Subprogram_Body
| Iir_Kinds_Interface_Subprogram_Declaration =>
-- Not globally static.
return None;
when others =>
Error_Kind ("get_object_type_staticness", Parent);
end case;
end loop;
end Get_Object_Type_Staticness;
procedure Finish_Sem_Array_Attribute
(Attr_Name : Iir; Attr : Iir; Param : Iir)
is
Parameter : Iir;
Prefix_Type : Iir;
Index_Type : Iir;
Prefix : Iir;
Prefix_Name : Iir;
Staticness : Iir_Staticness;
begin
-- LRM93 14.1
-- Parameter: A locally static expression of type universal_integer, the
-- value of which must not exceed the dimensionality of A. If omitted,
-- it defaults to 1.
if Param = Null_Iir then
Parameter := Null_Iir;
else
Parameter := Sem_Expression
(Param, Universal_Integer_Type_Definition);
if Parameter /= Null_Iir then
if Get_Expr_Staticness (Parameter) /= Locally then
Error_Msg_Sem (+Parameter, "parameter must be locally static");
end if;
else
-- Don't forget there is a parameter, so the attribute cannot
-- be reanalyzed with a default parameter.
Parameter := Error_Mark;
end if;
end if;
-- See Sem_Array_Attribute_Name for comments about the prefix.
Prefix_Name := Get_Prefix (Attr_Name);
if Is_Type_Name (Prefix_Name) /= Null_Iir then
Prefix := Sem_Type_Mark (Prefix_Name);
else
Prefix := Finish_Sem_Name (Prefix_Name, Get_Prefix (Attr));
-- Convert function declaration to call.
if Get_Kind (Prefix) in Iir_Kinds_Denoting_Name
and then
(Get_Kind (Get_Named_Entity (Prefix))
= Iir_Kind_Function_Declaration)
then
Prefix := Function_Declaration_To_Call (Prefix);
end if;
if not Is_Object_Name (Prefix) then
Error_Msg_Sem_Relaxed
(Attr, Warnid_Attribute,
"prefix of array attribute must be an object name");
end if;
end if;
Set_Prefix (Attr, Prefix);
Prefix_Type := Get_Type (Prefix);
if Is_Error (Prefix_Type) then
return;
end if;
declare
Dim : Int64;
Indexes_List : constant Iir_Flist :=
Get_Index_Subtype_List (Prefix_Type);
begin
if Is_Null (Parameter)
or else Get_Expr_Staticness (Parameter) /= Locally
then
Dim := 1;
else
Dim := Get_Value (Parameter);
end if;
if Dim < 1 or else Dim > Int64 (Get_Nbr_Elements (Indexes_List))
then
Error_Msg_Sem (+Attr, "parameter value out of bound");
Dim := 1;
end if;
Index_Type := Get_Index_Type (Indexes_List, Natural (Dim - 1));
end;
case Get_Kind (Attr) is
when Iir_Kind_Left_Array_Attribute
| Iir_Kind_Right_Array_Attribute
| Iir_Kind_High_Array_Attribute
| Iir_Kind_Low_Array_Attribute =>
Set_Type (Attr, Index_Type);
when Iir_Kind_Range_Array_Attribute
| Iir_Kind_Reverse_Range_Array_Attribute =>
Set_Type (Attr, Index_Type);
when Iir_Kind_Length_Array_Attribute =>
Set_Type (Attr, Convertible_Integer_Type_Definition);
when Iir_Kind_Ascending_Array_Attribute =>
Set_Type (Attr, Boolean_Type_Definition);
when others =>
raise Internal_Error;
end case;
pragma Assert (Get_Parameter (Attr) = Null_Iir);
Set_Parameter (Attr, Parameter);
-- If the corresponding type is known, save it so that it is not
-- necessary to extract it from the object.
if Get_Kind (Prefix_Type) = Iir_Kind_Array_Subtype_Definition
and then Get_Constraint_State (Prefix_Type) = Fully_Constrained
then
Set_Index_Subtype (Attr, Index_Type);
end if;
-- LRM08 9.4.2 Locally static primaries
-- g) A predefined attribute that is a function, [other than ... and
-- other than ...], whose prefix is either a locally static subtype
-- or is an object that is of a locally static subtype, and whose
-- actual parameter (if any) is a locally static expression.
--
-- LRM08 9.4.3 Globally static primaries
-- l) A predefined attribute that is a function, [other than ... and
-- other than ...], whose prefix is appropriate for a globally
-- static attribute, and whose actual parameter (if any) is a
-- globally static expression.
--
-- A prefix is appropriate for a globally static attribute if it denotes
-- a signal, a constant, a type or subtype, a globally static function
-- call, a variable that is not of an access type, or a variable of an
-- access type whose designated subtype is fully constrained.
-- LRM93 7.4.1
-- A locally static range is either [...], or a range of the first form
-- whose prefix denotes either a locally static subtype or an object
-- that is of a locally static subtype.
-- LRM93 7.4.2
-- A globally static range is either [...], or a range of the first form
-- whose prefix denotes either a globally static subtype or an object
-- that is of a globally static subtype.
--
-- A globally static subtype is either a globally static scalar subtype,
-- a globally static array subtype, [...]
--
-- A globally static array subtype is a constrained array subtype
-- formed by imposing on an unconstrained array type a globally static
-- index constraint.
Staticness := Get_Type_Staticness (Prefix_Type);
if Is_Object_Name (Prefix) then
Staticness := Iir_Staticness'Max
(Staticness, Get_Object_Type_Staticness (Prefix));
end if;
Set_Expr_Staticness (Attr, Staticness);
end Finish_Sem_Array_Attribute;
procedure Finish_Sem_Scalar_Type_Attribute
(Attr_Name : Iir; Attr : Iir; Param : Iir)
is
Prefix : Iir;
Prefix_Type : Iir;
Prefix_Bt : Iir;
Parameter : Iir;
Param_Type : Iir;
begin
if Param = Null_Iir then
Error_Msg_Sem (+Attr, "%n requires a parameter", +Attr);
return;
end if;
Prefix := Finish_Sem_Name (Get_Prefix (Attr));
Free_Iir (Attr_Name);
Set_Prefix (Attr, Prefix);
Prefix_Type := Get_Type (Prefix);
Prefix_Bt := Get_Base_Type (Prefix_Type);
case Get_Kind (Attr) is
when Iir_Kind_Pos_Attribute =>
-- LRM93 14.1
-- Parameter: An expression whose type is the base type of T.
Parameter := Sem_Expression (Param, Prefix_Bt);
when Iir_Kind_Val_Attribute =>
-- LRM93 14.1
-- Parameter: An expression of any integer type.
Param_Type := Get_Type (Param);
if Is_Overload_List (Param_Type) then
Parameter := Sem_Expression
(Param, Universal_Integer_Type_Definition);
else
if Get_Kind (Get_Base_Type (Param_Type))
/= Iir_Kind_Integer_Type_Definition
then
Error_Msg_Sem (+Attr, "parameter must be an integer");
return;
end if;
Parameter := Param;
end if;
when Iir_Kind_Succ_Attribute
| Iir_Kind_Pred_Attribute
| Iir_Kind_Leftof_Attribute
| Iir_Kind_Rightof_Attribute =>
-- LRM93 14.1
-- Parameter: An expression whose type is the base type of T.
Parameter := Sem_Expression (Param, Prefix_Bt);
when Iir_Kind_Image_Attribute =>
-- LRM93 14.1
-- Parameter: An expression whose type is the base type of T.
Parameter := Sem_Expression (Param, Prefix_Bt);
when Iir_Kind_Value_Attribute =>
-- Parameter: An expression of type string.
Parameter := Sem_Expression (Param, String_Type_Definition);
when others =>
raise Internal_Error;
end case;
pragma Assert (Get_Parameter (Attr) = Null_Iir);
if Parameter = Null_Iir then
Set_Parameter (Attr, Param);
Set_Expr_Staticness (Attr, None);
return;
end if;
Set_Parameter (Attr, Parameter);
Set_Expr_Staticness (Attr, Min (Get_Type_Staticness (Prefix_Type),
Get_Expr_Staticness (Parameter)));
Set_Name_Staticness (Attr, Get_Expr_Staticness (Attr));
end Finish_Sem_Scalar_Type_Attribute;
-- Finish analysis of attributes for signals.
procedure Finish_Sem_Signal_Attribute (Attr : Iir)
is
Prefix : constant Iir := Get_Prefix (Attr);
begin
-- According to LRM 7.4, signal attributes are not static expressions
-- since the prefix (a signal) is not a static expression.
Set_Expr_Staticness (Attr, None);
-- For all signal attributes:
--
-- LRM93 14.1 Predefined attributes
-- Prefix: any signal denoted by the static signal name S.
if Get_Name_Staticness (Prefix) < Globally then
Error_Msg_Sem
(+Attr, "prefix of %n must be a static name", +Attr);
end if;
-- LRM02 6.1 / LRM08 8.1
-- A name is said to be a static name if and only if at least one of
-- the following conditions holds:
-- [...]
-- - The name is a attribute name whose prefix is a static signal name
-- and whose suffix is one of the predefined attributes 'DELAYED,
-- 'STABLE, 'QUIET or 'TRANSACTION.
-- According to LRM 6.1, attributes are not static names.
if Flag_Relaxed_Rules or Flags.Vhdl_Std >= Vhdl_02 then
case Get_Kind (Attr) is
when Iir_Kind_Stable_Attribute
| Iir_Kind_Quiet_Attribute
| Iir_Kind_Delayed_Attribute
| Iir_Kind_Transaction_Attribute =>
Set_Name_Staticness (Attr, Get_Name_Staticness (Prefix));
when others =>
Set_Name_Staticness (Attr, None);
end case;
else
Set_Name_Staticness (Attr, None);
end if;
end Finish_Sem_Signal_Attribute;
-- Finish analysis of attributes that are signals for signals
procedure Finish_Sem_Signal_Attribute_Signal (Attr : Iir; Parameter : Iir)
is
pragma Assert (Parameter /= Null_Iir);
Param : Iir;
begin
if Get_Kind (Attr) = Iir_Kind_Transaction_Attribute then
Error_Msg_Sem (+Attr, "'transaction does not allow a parameter");
return;
end if;
Param := Sem_Expression (Parameter, Time_Subtype_Definition);
if Param /= Null_Iir then
-- LRM93 14.1
-- Parameter: A static expression of type TIME [that evaluate
-- to a nonnegative value.]
if Get_Expr_Staticness (Param) = None then
Error_Msg_Sem
(+Param, "parameter of signal attribute must be static");
end if;
Set_Parameter (Attr, Param);
end if;
end Finish_Sem_Signal_Attribute_Signal;
procedure Sem_Quantity_Attribute_Parameters
(Attr : Iir; Params : Iir_Array; Params_Type : Iir_Array; Min : Natural)
is
Param : Iir;
begin
pragma Assert (Params'First = 1);
pragma Assert (Params_Type'First = 1);
pragma Assert (Params_Type'Last = Params'Last);
for I in Params'Range loop
Param := Params (I);
if Param = Null_Iir then
if I <= Min then
Error_Msg_Sem
(+Attr, "not enough parameters for the attribute");
end if;
return;
end if;
if Params_Type (I) = Null_Iir then
Error_Msg_Sem (+Attr, "too many parameters for the attribute");
return;
end if;
Param := Sem_Expression (Param, Params_Type (I));
if Param /= Null_Iir then
if Get_Expr_Staticness (Param) < Globally then
Error_Msg_Sem
(+Param, "parameter must be a static expression");
end if;
Set_Attribute_Parameter (Attr, I, Param);
end if;
end loop;
end Sem_Quantity_Attribute_Parameters;
procedure Finish_Sem_Quantity_Attribute
(Attr_Name : Iir; Attr : Iir; Params : Iir_Array)
is
Prefix : Iir;
Param : Iir;
begin
Prefix := Get_Prefix (Attr_Name);
Set_Prefix (Attr, Prefix);
Free_Iir (Attr_Name);
case Get_Kind (Attr) is
when Iir_Kind_Quantity_Delayed_Attribute =>
-- AMS-LRM17 16.2.6
-- Q'DELAYED[(T)]
-- Parameter:
-- T: A static expression of type REAL that evaluates to a
-- non-negative number. If omitted, defaults to 0.0.
Sem_Quantity_Attribute_Parameters
(Attr, Params, (1 => Real_Type_Definition,
2 .. 4 => Null_Iir), 0);
when Iir_Kind_Above_Attribute =>
pragma Assert (Params'First = 1 and Params'Last = 1);
if Params (1) = Null_Iir then
Error_Msg_Sem (+Attr, "'above requires a parameter");
else
-- FIXME: AMS-LRM17 16.2.6
-- Any quantity appearing in the expression shall be denoted by
-- a static name.
Param := Sem_Expression (Params (1), Get_Type (Prefix));
if Param /= Null_Iir then
Set_Parameter (Attr, Param);
end if;
end if;
when Iir_Kind_Ramp_Attribute
| Iir_Kind_Signal_Slew_Attribute
| Iir_Kind_Quantity_Slew_Attribute =>
pragma Assert (Params'First = 1 and Params'Last = 4);
-- AMS-LRM17 16.2.6
-- S'RAMP [(TRISE [, TFALL])]
-- Parameters:
-- TRISE: a static expression of a floating-point type that
-- evaluates to a nonnegative value. If omitted, it
-- defaults to 0.
-- TFALL: a static expression of a floating-point type that
-- evaluates to a nonnegative value. If omitted, it
-- defaults to the value of TRISE.
--
-- S'SLEW [(RISING_SLOP [, FALLING_SLOPE])]
-- Parameters:
-- RISING_SLOPE: a static expression of type REAL that
-- evaluates to a positive value. If omitted, it defaults
-- to REAL'HIGH, which is interpreted as an infinite slope.
-- FALLING_SLOPE: a static expression of type REAL that
-- evaluates to a negative value. If omitted, it defaults
-- to the negative of RISING_SLOPE. The value REAL'LOW is
-- interpreted as a negative infinite slope.
--
-- Q'SLEW [(MAX_RISING_SLOPE [, MAX_FALLING_SLOPE])]
-- Parameters:
-- MAX_RISING_SLOPE: a static expression of type REAL that
-- evaluates to a positive value. If omitted, it defaults
-- to REAL'HIGH, which is interpreted as an infinite slope.
-- MAX_FALLING_SLOPE: a static expression of type REAL that
-- evaluates to a negative value. If omitted, it defaults
-- to the negative of MAX_RISING_SLOPE. The value REAL'LOW
-- is interpreted as a negative infinite slope.
Sem_Quantity_Attribute_Parameters
(Attr, Params, (1 => Real_Type_Definition,
2 => Real_Type_Definition,
3 | 4 => Null_Iir), 1);
when Iir_Kind_Zoh_Attribute =>
-- AMS-LRM17 16.2.6
-- Q'LTF(T [, INITIAL_DELAY)
-- Parameters:
-- T: A static expression of type REAL that evaluates to a
-- positive value. This is the sampling period.
-- INITIAL_DELAY: A static expression of type REAL that
-- evaluates to a non-negative value. The first sampling will
-- occur after INITIAL_DELAY seconds. If omitted, it defaults
-- to 0.0.
Sem_Quantity_Attribute_Parameters
(Attr, Params, (1 => Real_Type_Definition,
2 => Real_Type_Definition,
3 | 4 => Null_Iir), 1);
when Iir_Kind_Ltf_Attribute =>
-- AMS-LRM17 16.2.6
-- Q'LTF(NUM, DEN)
-- Parameters:
-- NUM: a static expression of type REAL_VECTOR that contains
-- the numerator coefficients.
-- DEN: a static expression of type REAL_VECTOR that contains
-- the denominator coefficients.
Sem_Quantity_Attribute_Parameters
(Attr, Params, (1 => Real_Vector_Type_Definition,
2 => Real_Vector_Type_Definition,
3 | 4 => Null_Iir), 2);
when Iir_Kind_Ztf_Attribute =>
-- AMS-LRM17 16.2.6
-- Q'ZTF(NUM, DEN, T, [, INITIAL_DELAY])
-- Parameters:
-- NUM: A static expression of type REAL_VECTOR with the
-- numerator coefficients.
-- DEN: A static expression of type REAL_VECTOR with the
-- denominator coefficients.
-- T: A static expression of type REAL that evaluates to a
-- positive value, which is the sampling period.
-- INITIAL_DELAY: A static expression of type REAL that
-- evaluates to a non-negative value, which is the time of the
-- first sampling. If omitted, it defaults to 0.0
Sem_Quantity_Attribute_Parameters
(Attr, Params, (1 => Real_Vector_Type_Definition,
2 => Real_Vector_Type_Definition,
3 => Real_Type_Definition,
4 => Real_Type_Definition), 3);
when others =>
Error_Kind ("finish_sem_quantity_attribute", Attr);
end case;
end Finish_Sem_Quantity_Attribute;
function Is_Type_Abstract_Numeric (Atype : Iir) return Boolean is
begin
case Get_Kind (Atype) is
when Iir_Kind_Integer_Subtype_Definition
| Iir_Kind_Integer_Type_Definition
| Iir_Kind_Floating_Subtype_Definition
| Iir_Kind_Floating_Type_Definition =>
return True;
when others =>
return False;
end case;
end Is_Type_Abstract_Numeric;
function Are_Types_Closely_Related (Type1, Type2 : Iir) return Boolean
is
Base_Type1 : constant Iir := Get_Base_Type (Type1);
Base_Type2 : constant Iir := Get_Base_Type (Type2);
Ant1, Ant2 : Boolean;
Index_List1, Index_List2 : Iir_Flist;
El1, El2 : Iir;
begin
-- LRM 7.3.5
-- In particular, a type is closely related to itself.
if Base_Type1 = Base_Type2 then
return True;
end if;
-- LRM 7.3.5
-- a) Abstract Numeric Types: Any abstract numeric type is closely
-- related to any other abstract numeric type.
Ant1 := Is_Type_Abstract_Numeric (Type1);
Ant2 := Is_Type_Abstract_Numeric (Type2);
if Ant1 and Ant2 then
return True;
end if;
if Ant1 or Ant2 then
return False;
end if;
-- LRM 7.3.5
-- b) Array Types: Two array types are closely related if and only if
-- The types have the same dimensionality; For each index position,
-- the index types are either the same or are closely related; and
-- The element types are the same.
--
-- No other types are closely related.
if not (Get_Kind (Base_Type1) = Iir_Kind_Array_Type_Definition
and then Get_Kind (Base_Type2) = Iir_Kind_Array_Type_Definition)
then
return False;
end if;
Index_List1 := Get_Index_Subtype_List (Base_Type1);
Index_List2 := Get_Index_Subtype_List (Base_Type2);
if Get_Nbr_Elements (Index_List1) /= Get_Nbr_Elements (Index_List2) then
return False;
end if;
if Get_Base_Type (Get_Element_Subtype (Base_Type1))
/= Get_Base_Type (Get_Element_Subtype (Base_Type2))
then
return False;
end if;
for I in Flist_First .. Flist_Last (Index_List1) loop
El1 := Get_Index_Type (Index_List1, I);
El2 := Get_Index_Type (Index_List2, I);
if not Are_Types_Closely_Related (El1, El2) then
return False;
end if;
end loop;
return True;
end Are_Types_Closely_Related;
function Sem_Type_Conversion
(Name : Iir; Type_Mark : Iir; Actual : Iir; In_Formal : Boolean)
return Iir
is
Conv_Type : constant Iir := Get_Type (Type_Mark);
Conv : Iir_Type_Conversion;
Expr : Iir;
Staticness : Iir_Staticness;
begin
Conv := Create_Iir (Iir_Kind_Type_Conversion);
Location_Copy (Conv, Name);
Set_Type_Mark (Conv, Type_Mark);
Set_Type (Conv, Conv_Type);
Set_Expression (Conv, Actual);
-- Default staticness in case of error.
Set_Expr_Staticness (Conv, None);
-- Bail out if no actual (or invalid one).
if Actual = Null_Iir then
return Conv;
end if;
-- LRM93 7.3.5
-- Furthermore, the operand of a type conversion is not allowed to be
-- the literal null, an allocator, an aggregate, or a string literal.
case Get_Kind (Actual) is
when Iir_Kind_Null_Literal
| Iir_Kind_Aggregate
| Iir_Kind_String_Literal8
| Iir_Kinds_Allocator =>
Error_Msg_Sem
(+Actual, "%n cannot be a type conversion operand", +Actual);
return Conv;
when Iir_Kind_Range_Expression =>
-- Try to nicely handle expression like NAME (A to B).
Error_Msg_Sem
(+Actual, "subtype indication not allowed in an expression");
return Conv;
when Iir_Kind_Error =>
return Conv;
when others =>
null;
end case;
-- LRM93 7.3.5
-- The type of the operand of a type conversion must be
-- determinable independent of the context (in particular,
-- independent of the target type).
Expr := Sem_Expression_Universal (Actual);
if Expr = Null_Iir then
return Conv;
end if;
Set_Expression (Conv, Expr);
-- LRM93 7.4.1 Locally Static Primaries.
-- 9. a type conversion whose expression is a locally static expression.
-- LRM93 7.4.2 Globally Static Primaries.
-- 14. a type conversion whose expression is a globally static
-- expression.
Staticness := Get_Expr_Staticness (Expr);
-- If the type mark is not locally static, the expression cannot
-- be locally static. This was clarified in VHDL 08, but a type
-- mark that denotes an unconstrained array type, does not prevent
-- the expression from being static.
if Get_Kind (Conv_Type) not in Iir_Kinds_Array_Type_Definition
or else Get_Constraint_State (Conv_Type) = Fully_Constrained
then
Staticness := Min (Staticness, Get_Type_Staticness (Conv_Type));
end if;
-- LRM87 7.4 Static Expressions
-- A type conversion is not a locally static expression.
if Flags.Vhdl_Std = Vhdl_87 then
Staticness := Min (Globally, Staticness);
end if;
Set_Expr_Staticness (Conv, Staticness);
if not Are_Types_Closely_Related (Conv_Type, Get_Type (Expr)) then
-- FIXME: should explain why the types are not closely related.
Error_Msg_Sem
(+Conv, "conversion allowed only between closely related types");
-- Avoid error storm in evaluation.
Set_Expr_Staticness (Conv, None);
else
-- Unless the type conversion appears in the formal part of an
-- association, the expression must be readable.
if not In_Formal then
Check_Read (Expr);
end if;
end if;
return Conv;
end Sem_Type_Conversion;
-- OBJ is an 'impure' object (variable, signal or file) referenced at
-- location LOC.
-- Check the pure rules (LRM08 4 Subprograms and packages,
-- LRM08 4.3 Subprograms bodies).
procedure Sem_Check_Pure (Loc : Iir; Obj : Iir)
is
procedure Update_Impure_Depth (Subprg_Spec : Iir; Depth : Iir_Int32)
is
Bod : constant Iir := Get_Subprogram_Body (Subprg_Spec);
begin
if Bod = Null_Iir then
return;
end if;
if Depth < Get_Impure_Depth (Bod) then
Set_Impure_Depth (Bod, Depth);
end if;
end Update_Impure_Depth;
procedure Error_Pure (Subprg : Iir; Obj : Iir)
is
begin
Error_Msg_Sem_Relaxed
(Loc, Warnid_Pure,
"reference to %n violate pure rule for %n", (+Obj, +Subprg));
end Error_Pure;
Subprg : constant Iir := Sem_Stmts.Get_Current_Subprogram;
Subprg_Body : Iir;
Parent : Iir;
Decl : Iir;
begin
-- Apply only in subprograms.
if Subprg = Null_Iir then
return;
end if;
case Get_Kind (Subprg) is
when Iir_Kinds_Process_Statement
| Iir_Kind_Simultaneous_Procedural_Statement =>
return;
when Iir_Kind_Procedure_Declaration =>
-- Exit now if already known as impure.
if Get_Purity_State (Subprg) = Impure then
return;
end if;
when Iir_Kind_Function_Declaration =>
-- Exit now if impure.
if Get_Pure_Flag (Subprg) = False then
return;
end if;
when others =>
Error_Kind ("sem_check_pure", Subprg);
end case;
-- Follow aliases.
if Get_Kind (Obj) = Iir_Kind_Object_Alias_Declaration then
Decl := Get_Object_Prefix (Get_Name (Obj));
else
Decl := Obj;
end if;
-- Not all objects are impure.
case Get_Kind (Decl) is
when Iir_Kind_Object_Alias_Declaration =>
raise Program_Error;
when Iir_Kind_Guard_Signal_Declaration
| Iir_Kind_Signal_Declaration
| Iir_Kind_Variable_Declaration
| Iir_Kind_Interface_File_Declaration =>
null;
when Iir_Kind_Interface_Variable_Declaration
| Iir_Kind_Interface_Signal_Declaration =>
-- When referenced as a formal name (FIXME: this is an
-- approximation), the rules don't apply.
if not Get_Is_Within_Flag (Get_Parent (Decl)) then
return;
end if;
when Iir_Kind_File_Declaration =>
-- LRM 93 2.2
-- If a pure function is the parent of a given procedure, then
-- that procedure must not contain a reference to an explicitly
-- declared file object [...]
--
-- A pure function must not contain a reference to an explicitly
-- declared file.
if Get_Kind (Subprg) = Iir_Kind_Function_Declaration then
Error_Pure (Subprg, Obj);
else
Set_Purity_State (Subprg, Impure);
Set_Impure_Depth (Get_Subprogram_Body (Subprg),
Iir_Depth_Impure);
end if;
return;
when others =>
return;
end case;
-- DECL is declared in the immediate declarative part of the subprogram.
Parent := Get_Parent (Decl);
Subprg_Body := Get_Subprogram_Body (Subprg);
if Parent = Subprg or else Parent = Subprg_Body then
return;
end if;
-- Function.
if Get_Kind (Subprg) = Iir_Kind_Function_Declaration then
Error_Pure (Subprg, Obj);
return;
end if;
case Get_Kind (Parent) is
when Iir_Kind_Entity_Declaration
| Iir_Kind_Architecture_Body
| Iir_Kind_Package_Declaration
| Iir_Kind_Package_Body
| Iir_Kind_Block_Statement
| Iir_Kind_If_Generate_Statement
| Iir_Kind_For_Generate_Statement
| Iir_Kind_Generate_Statement_Body
| Iir_Kinds_Process_Statement
| Iir_Kind_Protected_Type_Body =>
-- The procedure is impure.
Set_Purity_State (Subprg, Impure);
Set_Impure_Depth (Subprg_Body, Iir_Depth_Impure);
return;
when Iir_Kind_Function_Body
| Iir_Kind_Procedure_Body =>
Update_Impure_Depth
(Subprg,
Get_Subprogram_Depth (Get_Subprogram_Specification (Parent)));
when Iir_Kind_Function_Declaration
| Iir_Kind_Procedure_Declaration =>
Update_Impure_Depth (Subprg, Get_Subprogram_Depth (Parent));
when others =>
Error_Kind ("sem_check_pure(2)", Parent);
end case;
end Sem_Check_Pure;
-- Set All_Sensitized_State to False iff OBJ is a signal declaration
-- and the current subprogram is in a package body.
procedure Sem_Check_All_Sensitized (Obj : Iir)
is
Subprg : Iir;
begin
-- We cares only of signals.
if Get_Kind (Obj) /= Iir_Kind_Signal_Declaration then
return;
end if;
-- We cares only of subprograms. Give up if we are in a process.
Subprg := Sem_Stmts.Get_Current_Subprogram;
if Subprg = Null_Iir
or else Get_Kind (Subprg) not in Iir_Kinds_Subprogram_Declaration
then
return;
end if;
if Get_Kind (Get_Library_Unit (Sem.Get_Current_Design_Unit))
= Iir_Kind_Package_Body
then
Set_All_Sensitized_State (Subprg, Invalid_Signal);
else
Set_All_Sensitized_State (Subprg, Read_Signal);
end if;
end Sem_Check_All_Sensitized;
-- Free overload list of NAME but keep RES interpretation.
procedure Free_Old_Entity_Name (Name : Iir; Res : Iir)
is
Old_Res : constant Iir := Get_Named_Entity (Name);
begin
if Old_Res /= Null_Iir and then Old_Res /= Res then
pragma Assert (Is_Overload_List (Old_Res));
Sem_Name_Free_Result (Old_Res, Res);
end if;
Set_Named_Entity (Name, Res);
end Free_Old_Entity_Name;
function Finish_Sem_Denoting_Name (Name : Iir; Res : Iir) return Iir is
begin
case Iir_Kinds_Denoting_Name (Get_Kind (Name)) is
when Iir_Kind_Simple_Name
| Iir_Kind_Character_Literal
| Iir_Kind_Operator_Symbol =>
Set_Base_Name (Name, Res);
Xref_Ref (Name, Res);
return Name;
when Iir_Kind_Selected_Name =>
declare
Prefix, Res_Prefix : Iir;
Old_Res : Iir;
begin
Xref_Ref (Name, Res);
Prefix := Name;
Res_Prefix := Res;
loop
Prefix := Get_Prefix (Prefix);
Res_Prefix := Get_Parent (Res_Prefix);
-- Get the parent for expanded_name, may skip some parents.
case Get_Kind (Res_Prefix) is
when Iir_Kind_Design_Unit =>
Res_Prefix :=
Get_Library (Get_Design_File (Res_Prefix));
when others =>
null;
end case;
pragma Assert (Get_Kind (Prefix) in Iir_Kinds_Denoting_Name);
Xref_Ref (Prefix, Res_Prefix);
-- Cannot use Free_Old_Entity_Name as a prefix may not be
-- the parent (for protected subprogram calls).
Old_Res := Get_Named_Entity (Prefix);
if Is_Overload_List (Old_Res) then
Free_Iir (Old_Res);
Set_Named_Entity (Prefix, Res_Prefix);
end if;
exit when Get_Kind (Prefix) /= Iir_Kind_Selected_Name;
end loop;
end;
return Name;
when Iir_Kind_Reference_Name =>
-- Not in the sources.
raise Internal_Error;
end case;
end Finish_Sem_Denoting_Name;
function Finish_Sem_Name_1 (Name : Iir; Res : Iir) return Iir
is
Prefix : Iir;
Name_Prefix : Iir;
Name_Res : Iir;
begin
case Get_Kind (Res) is
when Iir_Kinds_Library_Unit =>
return Finish_Sem_Denoting_Name (Name, Res);
when Iir_Kinds_Sequential_Statement
| Iir_Kinds_Concurrent_Statement =>
-- Label or part of an expanded name (for process, block
-- and generate).
return Finish_Sem_Denoting_Name (Name, Res);
when Iir_Kinds_Object_Declaration
| Iir_Kind_Enumeration_Literal
| Iir_Kind_Unit_Declaration
| Iir_Kind_Psl_Endpoint_Declaration =>
Name_Res := Finish_Sem_Denoting_Name (Name, Res);
Set_Base_Name (Name_Res, Res);
Set_Name_Staticness (Name_Res, Get_Name_Staticness (Res));
Set_Expr_Staticness (Name_Res, Get_Expr_Staticness (Res));
Sem_Check_Pure (Name_Res, Res);
Sem_Check_All_Sensitized (Res);
Set_Type (Name_Res, Get_Type (Res));
return Name_Res;
when Iir_Kind_Terminal_Declaration
| Iir_Kind_Interface_Terminal_Declaration =>
Name_Res := Finish_Sem_Denoting_Name (Name, Res);
Set_Base_Name (Name_Res, Res);
Set_Name_Staticness (Name_Res, Get_Name_Staticness (Res));
Sem_Check_Pure (Name_Res, Res);
return Name_Res;
when Iir_Kind_Attribute_Value =>
pragma Assert (Get_Kind (Name) = Iir_Kind_Attribute_Name);
Prefix := Finish_Sem_Name (Get_Prefix (Name));
Set_Prefix (Name, Prefix);
if Get_Is_Forward_Ref (Prefix) then
Set_Base_Name (Prefix, Null_Iir);
end if;
Set_Base_Name (Name, Res);
Set_Type (Name, Get_Type (Res));
Set_Name_Staticness (Name, Get_Name_Staticness (Res));
Set_Expr_Staticness (Name, Get_Expr_Staticness (Res));
return Name;
when Iir_Kind_Type_Declaration
| Iir_Kind_Subtype_Declaration
| Iir_Kind_Nature_Declaration
| Iir_Kind_Subnature_Declaration
| Iir_Kind_Component_Declaration
| Iir_Kind_Group_Template_Declaration
| Iir_Kind_Group_Declaration
| Iir_Kind_Attribute_Declaration
| Iir_Kind_Non_Object_Alias_Declaration
| Iir_Kind_Library_Declaration
| Iir_Kind_Interface_Package_Declaration
| Iir_Kind_Interface_Type_Declaration =>
Name_Res := Finish_Sem_Denoting_Name (Name, Res);
Set_Base_Name (Name_Res, Res);
return Name_Res;
when Iir_Kind_Function_Declaration
| Iir_Kind_Interface_Function_Declaration =>
Name_Res := Finish_Sem_Denoting_Name (Name, Res);
Set_Type (Name_Res, Get_Return_Type (Res));
return Name_Res;
when Iir_Kind_Procedure_Declaration
| Iir_Kind_Interface_Procedure_Declaration =>
return Finish_Sem_Denoting_Name (Name, Res);
when Iir_Kind_Type_Conversion =>
pragma Assert (Get_Kind (Name) = Iir_Kind_Parenthesis_Name);
Set_Type_Mark (Res, Sem_Type_Mark (Get_Prefix (Name)));
Free_Parenthesis_Name (Name, Res);
return Res;
when Iir_Kind_Indexed_Name
| Iir_Kind_Selected_Element
| Iir_Kind_Slice_Name
| Iir_Kind_Dereference =>
-- Fall through.
null;
when Iir_Kind_Implicit_Dereference =>
-- The name may not have a prefix.
Prefix := Finish_Sem_Name_1 (Name, Get_Prefix (Res));
Set_Prefix (Res, Prefix);
Finish_Sem_Dereference (Res);
return Res;
when Iir_Kind_Function_Call =>
case Get_Kind (Name) is
when Iir_Kind_Parenthesis_Name =>
-- Usual case.
Prefix := Finish_Sem_Name
(Get_Prefix (Name), Get_Implementation (Res));
Finish_Sem_Function_Call (Res, Prefix);
Free_Iir (Name);
when Iir_Kinds_Denoting_Name =>
-- Call without association list.
Prefix := Finish_Sem_Name (Name, Get_Implementation (Res));
Finish_Sem_Function_Call (Res, Prefix);
when others =>
Error_Kind ("Finish_Sem_Name(function call)", Name);
end case;
return Res;
when Iir_Kinds_Array_Attribute =>
if Get_Parameter (Res) = Null_Iir then
Finish_Sem_Array_Attribute (Name, Res, Null_Iir);
end if;
if Get_Kind (Name) = Iir_Kind_Attribute_Name then
Free_Iir (Name);
else
Free_Iir (Get_Prefix (Name));
Free_Parenthesis_Name (Name, Res);
end if;
return Res;
when Iir_Kinds_Scalar_Type_Attribute
| Iir_Kind_Image_Attribute
| Iir_Kind_Value_Attribute =>
if Get_Parameter (Res) = Null_Iir then
Finish_Sem_Scalar_Type_Attribute (Name, Res, Null_Iir);
else
Free_Parenthesis_Name (Name, Res);
end if;
return Res;
when Iir_Kind_Across_Attribute
| Iir_Kind_Through_Attribute
| Iir_Kind_Nature_Reference_Attribute =>
null;
when Iir_Kinds_Signal_Value_Attribute =>
null;
when Iir_Kinds_Signal_Attribute =>
-- Cannot use the common code below for the prefix, because
-- the parenthesis_name is absorbed as a parameter.
Prefix := Get_Prefix (Res);
Name_Prefix := Get_Prefix (Name);
if Get_Kind (Name) = Iir_Kind_Parenthesis_Name then
-- Skip the parenthesis name.
Prefix := Finish_Sem_Name_1 (Get_Prefix (Name_Prefix), Prefix);
Set_Prefix (Res, Prefix);
-- But free it.
Free_Parenthesis_Name (Name, Res);
else
pragma Assert (Get_Parameter (Res) = Null_Iir);
Prefix := Finish_Sem_Name (Name_Prefix, Prefix);
Set_Prefix (Res, Prefix);
Free_Iir (Name);
end if;
Finish_Sem_Signal_Attribute (Res);
return Res;
when Iir_Kind_Above_Attribute
| Iir_Kind_Ramp_Attribute
| Iir_Kind_Quantity_Slew_Attribute
| Iir_Kind_Signal_Slew_Attribute
| Iir_Kind_Zoh_Attribute
| Iir_Kind_Ltf_Attribute
| Iir_Kind_Ztf_Attribute
| Iir_Kind_Quantity_Delayed_Attribute =>
if Get_Parameter (Res) = Null_Iir then
-- Not finished. Need to emit an error message.
Finish_Sem_Quantity_Attribute (Name, Res, (1 => Null_Iir));
else
Free_Parenthesis_Name (Name, Res);
end if;
return Res;
when Iir_Kind_Dot_Attribute
| Iir_Kind_Integ_Attribute =>
-- Already finished.
return Res;
when Iir_Kinds_Type_Attribute
| Iir_Kind_Subtype_Attribute
| Iir_Kind_Element_Attribute
| Iir_Kind_Base_Attribute =>
pragma Assert (Get_Kind (Name) = Iir_Kind_Attribute_Name);
Free_Iir (Name);
return Res;
when Iir_Kind_Simple_Name_Attribute
| Iir_Kind_Path_Name_Attribute
| Iir_Kind_Instance_Name_Attribute =>
Free_Iir (Name);
return Res;
when Iir_Kinds_External_Name =>
pragma Assert (Name = Res);
return Res;
when Iir_Kind_Psl_Expression =>
return Res;
when Iir_Kind_Psl_Declaration =>
return Name;
when Iir_Kind_Element_Declaration =>
-- Certainly an error!
return Name;
when Iir_Kind_Error =>
return Name;
when others =>
Error_Kind ("finish_sem_name_1", Res);
end case;
-- The name has a prefix, finish it.
Prefix := Get_Prefix (Res);
Name_Prefix := Get_Prefix (Name);
Prefix := Finish_Sem_Name_1 (Name_Prefix, Prefix);
Set_Prefix (Res, Prefix);
case Get_Kind (Res) is
when Iir_Kind_Indexed_Name =>
Finish_Sem_Indexed_Name (Res);
Free_Parenthesis_Name (Name, Res);
when Iir_Kind_Slice_Name =>
Finish_Sem_Slice_Name (Res);
Free_Parenthesis_Name (Name, Res);
when Iir_Kind_Selected_Element =>
pragma Assert (Get_Kind (Name) = Iir_Kind_Selected_Name);
Xref_Ref (Res, Get_Named_Entity (Res));
Set_Name_Staticness (Res, Get_Name_Staticness (Prefix));
Set_Expr_Staticness (Res, Get_Expr_Staticness (Prefix));
Set_Base_Name (Res, Get_Base_Name (Prefix));
Free_Iir (Name);
when Iir_Kind_Dereference =>
pragma Assert (Get_Kind (Name) = Iir_Kind_Selected_By_All_Name);
Finish_Sem_Dereference (Res);
Free_Iir (Name);
when Iir_Kind_Subtype_Attribute
| Iir_Kind_Through_Attribute
| Iir_Kind_Across_Attribute
| Iir_Kind_Nature_Reference_Attribute =>
Sem_Name_Free_Result (Name, Res);
when Iir_Kinds_Signal_Value_Attribute =>
Sem_Name_Free_Result (Name, Res);
Finish_Sem_Signal_Attribute (Res);
when others =>
Error_Kind ("finish_sem_name_1(2)", Res);
end case;
return Res;
end Finish_Sem_Name_1;
function Finish_Sem_Name (Name : Iir; Res : Iir) return Iir is
begin
if Get_Kind (Res) /= Iir_Kind_Implicit_Dereference then
-- There is no corresponding name for implicit_dereference (because
-- it is implicit).
-- Free overload list (but keep RES interpretation) for other cases.
Free_Old_Entity_Name (Name, Res);
end if;
return Finish_Sem_Name_1 (Name, Res);
end Finish_Sem_Name;
function Finish_Sem_Name (Name : Iir) return Iir is
begin
return Finish_Sem_Name_1 (Name, Get_Named_Entity (Name));
end Finish_Sem_Name;
-- LRM93 6.2
-- The evaluation of a simple name has no other effect than to determine
-- the named entity denoted by the name.
--
-- NAME may be a simple name, a strig literal or a character literal.
-- GHDL: set interpretation of NAME (possibly an overload list) or
-- error_mark for unknown names.
-- If SOFT is TRUE, then no error message is reported in case of failure.
procedure Sem_Simple_Name (Name : Iir; Keep_Alias : Boolean; Soft : Boolean)
is
Id : constant Name_Id := Get_Identifier (Name);
Interpretation: Name_Interpretation_Type;
Res: Iir;
Res_List : Iir_List;
Res_It : List_Iterator;
N : Natural;
begin
Interpretation := Get_Interpretation (Id);
if not Valid_Interpretation (Interpretation) then
-- Unknown name.
if not Soft then
Interpretation := Get_Interpretation_Raw (Id);
if Valid_Interpretation (Interpretation)
and then Is_Conflict_Declaration (Interpretation)
then
Error_Msg_Sem
(+Name, "no declaration for %i (due to conflicts)", +Name);
else
Error_Msg_Sem (+Name, "no declaration for %i", +Name);
end if;
end if;
Res := Error_Mark;
elsif not Valid_Interpretation (Get_Next_Interpretation (Interpretation))
then
-- One simple interpretation.
Res := Get_Declaration (Interpretation);
-- For a design unit, return the library unit
if Get_Kind (Res) = Iir_Kind_Design_Unit then
-- FIXME: should replace interpretation ?
Load_Design_Unit (Res, Name);
Sem.Add_Dependence (Res);
Res := Get_Library_Unit (Res);
end if;
-- Check visibility.
if not Get_Visible_Flag (Res) then
if Flag_Relaxed_Rules
and then Get_Kind (Res) in Iir_Kinds_Object_Declaration
and then Valid_Interpretation (Get_Under_Interpretation (Id))
then
Res := Get_Declaration (Get_Under_Interpretation (Id));
else
if not Soft then
Error_Msg_Sem (+Name, "%n is not visible here", +Res);
end if;
-- Even if a named entity was found, return an error_mark.
-- Indeed, the named entity found is certainly the one being
-- analyzed, and the analyze may be uncomplete.
Res := Error_Mark;
end if;
end if;
if not Keep_Alias
and then Get_Kind (Res) = Iir_Kind_Non_Object_Alias_Declaration
then
Set_Alias_Declaration (Name, Res);
Res := Get_Named_Entity (Get_Name (Res));
end if;
else
-- Name is overloaded.
Res_List := Create_Iir_List;
N := 0;
-- The SEEN_FLAG is used to get only one meaning which can be reached
-- through several paths (such as aliases).
while Valid_Interpretation (Interpretation) loop
if Keep_Alias then
Res := Get_Declaration (Interpretation);
else
Res := Get_Non_Alias_Declaration (Interpretation);
end if;
if not Get_Seen_Flag (Res) then
Set_Seen_Flag (Res, True);
N := N + 1;
Append_Element (Res_List, Res);
end if;
Interpretation := Get_Next_Interpretation (Interpretation);
end loop;
-- FIXME: there can be only one element (a function and its alias!).
-- Clear SEEN_FLAG.
Res_It := List_Iterate (Res_List);
while Is_Valid (Res_It) loop
Set_Seen_Flag (Get_Element (Res_It), False);
Next (Res_It);
end loop;
Res := Create_Overload_List (Res_List);
end if;
Set_Named_Entity (Name, Res);
end Sem_Simple_Name;
-- LRM93 6.3
-- Selected Names.
procedure Sem_Selected_Name
(Name: Iir; Keep_Alias : Boolean := False; Soft : Boolean := False)
is
Suffix : constant Name_Id := Get_Identifier (Name);
Prefix_Name : constant Iir := Get_Prefix (Name);
Prefix_Loc : constant Location_Type := Get_Location (Prefix_Name);
Prefix: Iir;
Res : Iir;
-- Analyze SUB_NAME.NAME as an expanded name (ie, NAME is declared
-- within SUB_NAME). This is possible only if the expanded name is
-- analyzed within the context of SUB_NAME.
procedure Sem_As_Expanded_Name (Sub_Name : Iir)
is
Sub_Res : Iir;
begin
if Get_Is_Within_Flag (Sub_Name) then
Sub_Res := Find_Declarations_In_List (Sub_Name, Name, Keep_Alias);
if Sub_Res /= Null_Iir then
Add_Result (Res, Sub_Res);
end if;
end if;
end Sem_As_Expanded_Name;
-- LRM93 6.3
-- For a selected name that is used to denote a record element,
-- the suffix must be a simple name denoting an element of a
-- record object or value. The prefix must be appropriate for the
-- type of this object or value.
--
-- Analyze SUB_NAME.NAME as a selected element.
procedure Sem_As_Selected_Element (Sub_Name : Iir)
is
Name_Type : Iir;
Ptr_Type : Iir;
Rec_El : Iir;
R : Iir;
Se : Iir;
begin
Name_Type := Get_Type (Sub_Name);
if Kind_In (Name_Type, Iir_Kind_Access_Type_Definition,
Iir_Kind_Access_Subtype_Definition)
then
Ptr_Type := Name_Type;
Name_Type := Get_Designated_Type (Name_Type);
else
Ptr_Type := Null_Iir;
end if;
-- Only records have elements.
if not Kind_In (Name_Type, Iir_Kind_Record_Type_Definition,
Iir_Kind_Record_Subtype_Definition)
then
return;
end if;
Rec_El := Find_Name_In_Flist
(Get_Elements_Declaration_List (Name_Type), Suffix);
if Rec_El = Null_Iir then
-- No such element in the record type.
return;
end if;
if not Maybe_Function_Call (Sub_Name) then
return;
end if;
R := Maybe_Insert_Function_Call (Prefix_Name, Sub_Name);
R := Maybe_Insert_Dereference (R, Ptr_Type);
Se := Create_Iir (Iir_Kind_Selected_Element);
Location_Copy (Se, Name);
Set_Prefix (Se, R);
Set_Type (Se, Get_Type (Rec_El));
Set_Identifier (Se, Suffix);
Set_Named_Entity (Se, Rec_El);
Set_Base_Name (Se, Get_Object_Prefix (R, False));
Add_Result (Res, Se);
end Sem_As_Selected_Element;
procedure Error_Selected_Element (Prefix_Type : Iir)
is
Base_Type : Iir;
begin
Base_Type := Get_Base_Type (Prefix_Type);
if Get_Kind (Base_Type) = Iir_Kind_Access_Type_Definition then
Base_Type := Get_Base_Type (Get_Designated_Type (Base_Type));
end if;
if Get_Kind (Base_Type) /= Iir_Kind_Record_Type_Definition then
Error_Msg_Sem
(+Name, "%n does not designate a record", +Prefix);
else
Error_Msg_Sem
(+Name, "no element %i in %n", (+Suffix, +Base_Type));
end if;
end Error_Selected_Element;
procedure Sem_As_Protected_Item (Sub_Name : Iir)
is
Prot_Type : constant Iir := Get_Type (Sub_Name);
Method : Iir;
begin
-- LRM98 12.3 Visibility
-- s) For a subprogram declared immediately within a given protected
-- type declaration: at the place of the suffix in a selected
-- name whose prefix denotes an object of the protected type.
Method := Get_Declaration_Chain (Prot_Type);
while Method /= Null_Iir loop
case Get_Kind (Method) is
when Iir_Kind_Function_Declaration |
Iir_Kind_Procedure_Declaration =>
if Get_Identifier (Method) = Suffix then
Add_Result (Res, Method);
end if;
when Iir_Kind_Attribute_Specification
| Iir_Kind_Use_Clause =>
null;
when others =>
-- Declarations not allowed in protected types.
-- Just ignore them.
null;
end case;
Method := Get_Chain (Method);
end loop;
end Sem_As_Protected_Item;
procedure Error_Protected_Item (Prot_Type : Iir) is
begin
Error_Msg_Sem (+Name, "no method %i in %n", (+Suffix, +Prot_Type));
end Error_Protected_Item;
-- Check if a synopsys package can be imported.
procedure Check_Synopsys_Package (Lib : Iir)
is
use Std_Names;
begin
if Get_Identifier (Lib) /= Name_Ieee then
return;
end if;
case Suffix is
when Name_Std_Logic_Arith
| Name_Std_Logic_Signed
| Name_Std_Logic_Unsigned =>
-- Synopsys package.
null;
when Name_Std_Logic_Textio =>
if Vhdl_Std >= Vhdl_08 then
-- Standard ieee package in vhdl-08
return;
end if;
when others =>
-- Not a synopsys package.
return;
end case;
if Get_Identifier
(Get_Library (Get_Design_File (Sem.Get_Current_Design_Unit)))
= Name_Ieee
then
-- No error when referenced from an ieee package. That could
-- happen only for synopsys packages, so an error will be
-- emitted when the user references the first synopsys package.
return;
end if;
Error_Msg_Sem
(+Name, "use of synopsys package %i needs the -fsynopsys option",
+Suffix);
end Check_Synopsys_Package;
begin
-- Analyze prefix.
if Soft then
Sem_Name_Soft (Prefix_Name);
else
Sem_Name (Prefix_Name);
end if;
Prefix := Get_Named_Entity (Prefix_Name);
if Is_Error (Prefix) then
Set_Named_Entity (Name, Prefix);
return;
end if;
Res := Null_Iir;
case Get_Kind (Prefix) is
when Iir_Kind_Overload_List =>
-- LRM93 6.3
-- If, according to the visibility rules, there is at
-- least one possible interpretation of the prefix of a
-- selected name as the name of an enclosing entity
-- interface, architecture, subprogram, block statement,
-- process statement, generate statement, or loop
-- statement, then the only interpretations considered are
-- those of the immediately preceding paragraph.
--
-- In this case, the selected name is always interpreted
-- as an expanded name. In particular, no interpretations
-- of the prefix as a function call are considered.
declare
Prefix_List : Iir_List;
It : List_Iterator;
El : Iir;
begin
-- So, first try as expanded name.
Prefix_List := Get_Overload_List (Prefix);
It := List_Iterate (Prefix_List);
while Is_Valid (It) loop
El := Get_Element (It);
case Get_Kind (El) is
when Iir_Kind_Function_Call
| Iir_Kind_Selected_Element =>
-- Not an expanded name.
null;
when others =>
Sem_As_Expanded_Name (El);
end case;
Next (It);
end loop;
-- If no expanded name are found, try as selected element.
if Res = Null_Iir then
It := List_Iterate (Prefix_List);
while Is_Valid (It) loop
El := Get_Element (It);
case Get_Kind (El) is
when Iir_Kind_Procedure_Declaration =>
-- A procedure cannot be the prefix of a selected
-- element.
null;
when others =>
Sem_As_Selected_Element (El);
end case;
Next (It);
end loop;
end if;
end;
if Res = Null_Iir and then not Soft then
Error_Msg_Sem
(+Name, "no suffix %i for overloaded selected name", +Suffix);
end if;
when Iir_Kind_Library_Declaration =>
-- LRM93 6.3
-- An expanded name denotes a primary unit constained in a design
-- library if the prefix denotes the library and the suffix is the
-- simple name if a primary unit whose declaration is contained
-- in that library.
-- An expanded name is not allowed for a secondary unit,
-- particularly for an architecture body.
-- GHDL: FIXME: error message more explicit
Res := Load_Primary_Unit (Prefix, Suffix, Name);
if Res /= Null_Iir then
if not Soft and then not Flag_Synopsys then
Check_Synopsys_Package (Prefix);
end if;
Sem.Add_Dependence (Res);
Res := Get_Library_Unit (Res);
elsif not Soft then
Error_Msg_Sem
(+Name, "unit %i not found in %n", (+Suffix, +Prefix));
end if;
when Iir_Kind_Process_Statement
| Iir_Kind_Procedure_Declaration
| Iir_Kind_Sensitized_Process_Statement
| Iir_Kind_Architecture_Body
| Iir_Kind_Entity_Declaration
| Iir_Kind_Package_Declaration
| Iir_Kind_Package_Instantiation_Declaration
| Iir_Kind_Interface_Package_Declaration
| Iir_Kind_If_Generate_Statement
| Iir_Kind_For_Generate_Statement
| Iir_Kind_Block_Statement
| Iir_Kind_For_Loop_Statement =>
-- LRM93 6.3
-- An expanded name denotes a named entity declared immediatly
-- within a named construct if the prefix that is an entity
-- interface, an architecture, a subprogram, a block statement,
-- a process statement, a generate statement, or a loop
-- statement, and the suffix is the simple name, character
-- literal, or operator symbol of an named entity whose
-- declaration occurs immediatly within that construct.
if Get_Kind (Prefix) = Iir_Kind_Design_Unit then
Load_Design_Unit (Prefix, Name);
Sem.Add_Dependence (Prefix);
Prefix := Get_Library_Unit (Prefix);
-- Modified only for xrefs, since a design_unit points to
-- the first context clause, while a library unit points to
-- the identifier.
Set_Named_Entity (Get_Prefix (Name), Prefix);
end if;
Res := Find_Declarations_In_List (Prefix, Name, Keep_Alias);
if Res = Null_Iir then
if not Soft then
Error_Msg_Sem
(+Name, "no declaration for %i in %n", (+Suffix, +Prefix));
end if;
else
-- LRM93 6.3
-- This form of expanded name is only allowed within the
-- construct itself.
-- FIXME: LRM08 12.3 Visibility h)
if not Kind_In (Prefix,
Iir_Kind_Package_Declaration,
Iir_Kind_Package_Instantiation_Declaration)
and then not Get_Is_Within_Flag (Prefix)
then
if not Soft then
Error_Msg_Sem
(+Prefix_Loc,
"an expanded name is only allowed "
& "within the construct");
end if;
-- Hum, keep res.
elsif Get_Kind (Prefix) = Iir_Kind_Package_Declaration
and then not Get_Is_Within_Flag (Prefix)
and then Is_Uninstantiated_Package (Prefix)
then
-- LRM08 12.3 f) Visibility
-- For a declaration given in a package declaration, other
-- than in a package declaration that defines an
-- uninstantiated package: [...]
if not Soft then
Error_Msg_Sem
(+Prefix_Loc,
"cannot refer a declaration in an "
& "uninstantiated package");
end if;
end if;
end if;
when Iir_Kind_Function_Declaration =>
Sem_As_Expanded_Name (Prefix);
if Res = Null_Iir then
Sem_As_Selected_Element (Prefix);
end if;
if Res = Null_Iir and then not Soft then
Error_Selected_Element (Get_Return_Type (Prefix));
end if;
when Iir_Kinds_Object_Declaration
| Iir_Kind_Indexed_Name
| Iir_Kind_Selected_Element
| Iir_Kind_Dereference
| Iir_Kind_Implicit_Dereference
| Iir_Kind_Attribute_Value
| Iir_Kind_Function_Call =>
if Get_Kind (Get_Type (Prefix))
= Iir_Kind_Protected_Type_Declaration
then
Sem_As_Protected_Item (Prefix);
if Res = Null_Iir and then not Soft then
Error_Protected_Item (Prefix);
end if;
else
Sem_As_Selected_Element (Prefix);
if Res = Null_Iir and then not Soft then
Error_Selected_Element (Get_Type (Prefix));
end if;
end if;
when Iir_Kind_Type_Declaration
| Iir_Kind_Subtype_Declaration
| Iir_Kind_Concurrent_Procedure_Call_Statement
| Iir_Kind_Component_Instantiation_Statement
| Iir_Kind_Slice_Name
| Iir_Kind_Procedure_Call_Statement
| Iir_Kind_Attribute_Declaration
| Iir_Kind_Type_Conversion =>
if not Soft then
Error_Msg_Sem
(+Prefix_Loc, "%n cannot be selected by name", +Prefix);
end if;
when Iir_Kind_Error =>
-- Let's propagate the error.
null;
when others =>
Error_Kind ("sem_selected_name(2)", Prefix);
end case;
if Res = Null_Iir then
Res := Error_Mark;
end if;
Set_Named_Entity (Name, Res);
end Sem_Selected_Name;
-- Extract actuals from ASSOC_CHAIN. Report errors.
procedure Extract_Attribute_Parameters
(Assoc_Chain : Iir; Actuals : out Iir_Array)
is
Assoc : Iir;
begin
pragma Assert (Assoc_Chain /= Null_Iir);
Assoc := Assoc_Chain;
for I in Actuals'Range loop
if Assoc = Null_Iir then
Actuals (I) := Null_Iir;
else
-- Not 'open' association element ?
if Get_Kind (Assoc) /= Iir_Kind_Association_Element_By_Expression
then
Error_Msg_Sem (+Assoc, "'open' is not an attribute parameter");
Actuals (Actuals'First) := Null_Iir;
return;
end if;
-- Not an association (ie no formal) ?
if Get_Formal (Assoc) /= Null_Iir then
Error_Msg_Sem
(+Assoc, "formal not allowed for attribute parameter");
Actuals (Actuals'First) := Null_Iir;
return;
end if;
Actuals (I) := Get_Actual (Assoc);
Assoc := Get_Chain (Assoc);
end if;
end loop;
if Assoc /= Null_Iir then
Error_Msg_Sem (+Assoc, "too many parameters for the attribute");
end if;
end Extract_Attribute_Parameters;
-- If ASSOC_ASSOC has one element, which is an expression without formal,
-- return the actual, else return NULL_IIR.
function Get_One_Actual (Assoc_Chain : Iir) return Iir
is
Assoc : Iir;
begin
-- Only one actual ?
if Assoc_Chain = Null_Iir or else Get_Chain (Assoc_Chain) /= Null_Iir
then
return Null_Iir;
end if;
-- Not 'open' association element ?
Assoc := Assoc_Chain;
if Get_Kind (Assoc) /= Iir_Kind_Association_Element_By_Expression then
return Null_Iir;
end if;
-- Not an association (ie no formal) ?
if Get_Formal (Assoc) /= Null_Iir then
return Null_Iir;
end if;
return Get_Actual (Assoc);
end Get_One_Actual;
function Slice_Or_Index (Actual : Iir) return Iir_Kind is
begin
-- But it may be a slice name.
case Get_Kind (Actual) is
when Iir_Kind_Range_Array_Attribute
| Iir_Kind_Reverse_Range_Array_Attribute
| Iir_Kind_Subtype_Declaration
| Iir_Kind_Type_Declaration
| Iir_Kind_Range_Expression =>
return Iir_Kind_Slice_Name;
when others =>
if Is_Range_Attribute_Name (Actual) then
return Iir_Kind_Slice_Name;
end if;
end case;
-- By default, this is an indexed name.
return Iir_Kind_Indexed_Name;
end Slice_Or_Index;
-- Check whether association chain ASSOCS may be interpreted as indexes.
function Index_Or_Not (Assocs : Iir) return Iir_Kind
is
El : Iir;
begin
El := Assocs;
while El /= Null_Iir loop
case Get_Kind (El) is
when Iir_Kind_Association_Element_By_Expression =>
if Get_Formal (El) /= Null_Iir then
return Iir_Kind_Error;
end if;
when others =>
-- Only expression are allowed.
return Iir_Kind_Error;
end case;
El := Get_Chain (El);
end loop;
return Iir_Kind_Indexed_Name;
end Index_Or_Not;
function Sem_Index_Specification (Name : Iir_Parenthesis_Name; Itype : Iir)
return Iir
is
Actual : Iir;
Kind : Iir_Kind;
Res : Iir;
begin
-- FIXME: reuse Sem_Name for the whole analysis ?
Actual := Get_One_Actual (Get_Association_Chain (Name));
if Actual = Null_Iir then
Error_Msg_Sem (+Name, "only one index specification is allowed");
return Null_Iir;
end if;
case Get_Kind (Actual) is
when Iir_Kind_Simple_Name
| Iir_Kind_Selected_Name =>
Sem_Name (Actual);
Kind := Slice_Or_Index (Get_Named_Entity (Actual));
-- FIXME: analyze to be finished.
--Maybe_Finish_Sem_Name (Actual);
when Iir_Kind_Subtype_Definition
| Iir_Kind_Range_Expression =>
Kind := Iir_Kind_Slice_Name;
when others =>
Kind := Slice_Or_Index (Actual);
end case;
Res := Create_Iir (Kind);
Location_Copy (Res, Name);
case Kind is
when Iir_Kind_Indexed_Name =>
Actual := Sem_Expression (Actual, Itype);
if Actual = Null_Iir then
return Null_Iir;
end if;
Check_Read (Actual);
if Get_Expr_Staticness (Actual) < Globally then
Error_Msg_Sem (+Name, "index must be a static expression");
end if;
Set_Index_List (Res, Create_Iir_Flist (1));
Set_Nth_Element (Get_Index_List (Res), 0, Actual);
when Iir_Kind_Slice_Name =>
Actual := Sem_Discrete_Range (Actual, Itype, False);
if Actual = Null_Iir then
return Null_Iir;
end if;
Set_Suffix (Res, Actual);
Actual := Get_Range_From_Discrete_Range (Actual);
if Get_Expr_Staticness (Actual) < Globally then
Error_Msg_Sem (+Name, "index must be a static expression");
end if;
when others =>
raise Internal_Error;
end case;
Free_Parenthesis_Name (Name, Res);
return Res;
end Sem_Index_Specification;
procedure Sem_Parenthesis_Name (Name : Iir_Parenthesis_Name)
is
Prefix_Name : constant Iir := Get_Prefix (Name);
Prefix: Iir;
Res : Iir;
Res_Prefix : Iir;
Assoc_Chain : Iir;
Slice_Index_Kind : Iir_Kind;
-- If FINISH is TRUE, then display error message in case of error.
function Sem_As_Indexed_Or_Slice_Name (Sub_Name : Iir; Finish : Boolean)
return Iir
is
Arr_Type : Iir;
Ptr_Type : Iir;
P : Iir;
R : Iir;
begin
if Slice_Index_Kind = Iir_Kind_Error then
if Finish then
Error_Msg_Sem (+Name, "prefix is not a function name");
end if;
-- No way.
return Null_Iir;
end if;
-- Only values can be indexed or sliced.
-- Catch errors such as slice of a type conversion.
if Name_To_Value (Sub_Name) = Null_Iir
and then not Is_Function_Declaration (Sub_Name)
then
if Finish then
Error_Msg_Sem
(+Name, "prefix is not an array value (found %n)", +Sub_Name);
end if;
return Null_Iir;
end if;
-- Extract type of prefix, handle possible implicit deference.
Arr_Type := Get_Type (Sub_Name);
if Kind_In (Arr_Type, Iir_Kind_Access_Type_Definition,
Iir_Kind_Access_Subtype_Definition)
then
-- FIXME: use base type until full support of access subtypes.
Ptr_Type := Get_Base_Type (Arr_Type);
Arr_Type := Get_Designated_Type (Arr_Type);
else
Ptr_Type := Null_Iir;
end if;
if not Kind_In (Arr_Type, Iir_Kind_Array_Type_Definition,
Iir_Kind_Array_Subtype_Definition)
then
if Finish and then not Is_Error (Arr_Type) then
Error_Msg_Sem (+Name, "type of prefix is not an array");
end if;
return Null_Iir;
end if;
if Get_Nbr_Elements (Get_Index_Subtype_List (Arr_Type)) /=
Get_Chain_Length (Assoc_Chain)
then
if Finish then
Error_Msg_Sem
(+Name, "number of indexes mismatches array dimension");
end if;
return Null_Iir;
end if;
-- For indexed names, discard type incompatibilities between indexes
-- and array type indexes.
-- The FINISH = True case will be handled by Finish_Sem_Indexed_Name.
if Slice_Index_Kind = Iir_Kind_Indexed_Name and then not Finish then
declare
Type_Index_List : constant Iir_Flist :=
Get_Index_Subtype_List (Arr_Type);
Type_Index : Iir;
Assoc : Iir;
begin
Assoc := Assoc_Chain;
for I in Natural loop
-- Assoc and Type_Index_List have the same length as this
-- was checked just above.
exit when Assoc = Null_Iir;
if Get_Kind (Assoc)
/= Iir_Kind_Association_Element_By_Expression
then
return Null_Iir;
end if;
Type_Index := Get_Index_Type (Type_Index_List, I);
if Is_Expr_Compatible (Type_Index, Get_Actual (Assoc))
= Not_Compatible
then
return Null_Iir;
end if;
Assoc := Get_Chain (Assoc);
end loop;
end;
end if;
if not Maybe_Function_Call (Sub_Name) then
if Finish then
Error_Msg_Sem (+Name, "missing parameters for function call");
end if;
return Null_Iir;
end if;
P := Maybe_Insert_Function_Call (Prefix_Name, Sub_Name);
P := Maybe_Insert_Dereference (P, Ptr_Type);
R := Create_Iir (Slice_Index_Kind);
Location_Copy (R, Name);
Set_Prefix (R, P);
Set_Base_Name (R, Get_Object_Prefix (P));
case Slice_Index_Kind is
when Iir_Kind_Slice_Name =>
Set_Suffix (R, Get_Actual (Assoc_Chain));
Set_Type (R, Get_Base_Type (Get_Type (P)));
when Iir_Kind_Indexed_Name =>
declare
Idx_El : Iir;
Idx_List : Iir_List;
begin
Idx_List := Create_Iir_List;
Idx_El := Assoc_Chain;
while Idx_El /= Null_Iir loop
Append_Element (Idx_List, Get_Actual (Idx_El));
Idx_El := Get_Chain (Idx_El);
end loop;
Set_Index_List (R, List_To_Flist (Idx_List));
end;
Set_Type (R, Get_Element_Subtype (Arr_Type));
when others =>
raise Internal_Error;
end case;
return R;
end Sem_As_Indexed_Or_Slice_Name;
-- Sem parenthesis name when the prefix is a function declaration.
-- Can be either a function call (and the expression is the actual) or
-- a slice/index of the result of a call without actual.
procedure Sem_Parenthesis_Function (Sub_Name : Iir)
is
Used : Boolean;
R : Iir;
Match : Compatibility_Level;
Call : Iir;
begin
Used := False;
-- A function call.
if Is_Function_Declaration (Sub_Name) then
Sem_Association_Chain
(Get_Interface_Declaration_Chain (Sub_Name),
Assoc_Chain, False, Missing_Parameter, Name, Match);
if Match /= Not_Compatible then
Call := Sem_As_Function_Call
(Prefix_Name, Sub_Name, Assoc_Chain);
Add_Result (Res, Call);
Add_Result (Res_Prefix, Sub_Name);
Used := True;
end if;
end if;
-- A slice/index of a call (without parameters).
if not Is_Procedure_Declaration (Sub_Name) then
R := Sem_As_Indexed_Or_Slice_Name (Sub_Name, False);
if R /= Null_Iir then
Add_Result (Res, R);
Add_Result (Res_Prefix, Sub_Name);
Used := True;
end if;
end if;
if not Used then
Sem_Name_Free_Result (Sub_Name, Null_Iir);
end if;
end Sem_Parenthesis_Function;
procedure Error_Parenthesis_Function (Spec : Iir)
is
Match : Compatibility_Level;
begin
Error_Msg_Sem (+Name, "cannot match %n with actuals", +Prefix);
-- Display error message.
Sem_Association_Chain
(Get_Interface_Declaration_Chain (Spec),
Assoc_Chain, True, Missing_Parameter, Name, Match);
end Error_Parenthesis_Function;
Actual : Iir;
Actual_Expr : Iir;
begin
-- The prefix is a function name, a type mark or an array.
Sem_Name (Prefix_Name);
Prefix := Get_Named_Entity (Prefix_Name);
if Prefix = Error_Mark then
Set_Named_Entity (Name, Error_Mark);
return;
end if;
Res := Null_Iir;
Assoc_Chain := Get_Association_Chain (Name);
Actual := Get_One_Actual (Assoc_Chain);
if Kind_In (Prefix,
Iir_Kind_Type_Declaration, Iir_Kind_Subtype_Declaration)
then
-- A type conversion. The prefix is a type mark.
declare
In_Formal : Boolean;
begin
if Actual = Null_Iir then
-- More than one actual. Keep only the first.
Error_Msg_Sem
(+Name, "type conversion allows only one expression");
In_Formal := False;
else
In_Formal := Get_In_Formal_Flag (Assoc_Chain);
end if;
-- This is certainly the easiest case: the prefix is not
-- overloaded, so the result can be computed.
Set_Named_Entity
(Name, Sem_Type_Conversion (Name, Prefix, Actual, In_Formal));
end;
return;
end if;
-- Select between slice or indexed name.
Actual_Expr := Null_Iir;
if Actual /= Null_Iir then
-- Only one actual: can be a slice or an index
case Get_Kind (Actual) is
when Iir_Kinds_Name
| Iir_Kind_Attribute_Name =>
-- Maybe a discrete range name.
Sem_Name (Actual);
Actual_Expr := Get_Named_Entity (Actual);
if Actual_Expr = Error_Mark then
Set_Named_Entity (Name, Actual_Expr);
return;
end if;
-- Decides between sliced or indexed name to actual.
Slice_Index_Kind := Slice_Or_Index (Actual_Expr);
when Iir_Kind_Range_Expression
| Iir_Kind_Subtype_Definition =>
-- This can only be a slice.
Slice_Index_Kind := Iir_Kind_Slice_Name;
when others =>
-- Any other expression: an indexed name.
Slice_Index_Kind := Iir_Kind_Indexed_Name;
end case;
else
-- More than one actual: an indexed name.
-- FIXME: improve error message for multi-dim slice ?
Slice_Index_Kind := Index_Or_Not (Assoc_Chain);
end if;
-- Analyze actuals if not already done (done for slices).
if Slice_Index_Kind /= Iir_Kind_Slice_Name then
if Sem_Actual_Of_Association_Chain (Assoc_Chain) = False then
Actual := Null_Iir;
else
Actual := Get_One_Actual (Assoc_Chain);
end if;
end if;
Res_Prefix := Null_Iir;
case Get_Kind (Prefix) is
when Iir_Kind_Overload_List =>
declare
El : Iir;
Prefix_List : Iir_List;
It : List_Iterator;
begin
Prefix_List := Get_Overload_List (Prefix);
It := List_Iterate (Prefix_List);
while Is_Valid (It) loop
El := Get_Element (It);
Sem_Parenthesis_Function (El);
Next (It);
end loop;
-- Some prefixes may have been removed, replace with the
-- rebuilt prefix list.
Free_Overload_List (Prefix);
Set_Named_Entity (Prefix_Name, Res_Prefix);
end;
if Res = Null_Iir then
Error_Msg_Sem
(+Name, "no overloaded function found matching %n",
+Prefix_Name);
end if;
when Iir_Kind_Function_Declaration
| Iir_Kind_Interface_Function_Declaration =>
Sem_Parenthesis_Function (Prefix);
Set_Named_Entity (Prefix_Name, Res_Prefix);
if Res = Null_Iir then
Error_Parenthesis_Function (Prefix);
end if;
when Iir_Kinds_Object_Declaration
| Iir_Kind_Indexed_Name
| Iir_Kind_Slice_Name
| Iir_Kind_Dereference
| Iir_Kind_Implicit_Dereference
| Iir_Kind_Selected_Element
| Iir_Kind_Attribute_Value
| Iir_Kind_Simple_Name_Attribute
| Iir_Kind_Function_Call =>
Add_Result (Res, Sem_As_Indexed_Or_Slice_Name (Prefix, True));
when Iir_Kinds_Array_Attribute =>
if Actual /= Null_Iir then
Finish_Sem_Array_Attribute (Prefix_Name, Prefix, Actual);
Set_Named_Entity (Name, Prefix);
else
Error_Msg_Sem (+Name, "bad attribute parameter");
Set_Named_Entity (Name, Error_Mark);
end if;
return;
when Iir_Kinds_Scalar_Type_Attribute
| Iir_Kind_Image_Attribute
| Iir_Kind_Value_Attribute =>
if Get_Parameter (Prefix) /= Null_Iir then
-- Attribute already has a parameter, the expression
-- is either a slice or an index.
Add_Result
(Res, Sem_As_Indexed_Or_Slice_Name (Prefix, True));
elsif Actual /= Null_Iir then
Finish_Sem_Scalar_Type_Attribute (Prefix_Name, Prefix, Actual);
Set_Named_Entity (Name, Prefix);
return;
else
Error_Msg_Sem (+Name, "bad attribute parameter");
Set_Named_Entity (Name, Error_Mark);
return;
end if;
when Iir_Kind_Type_Declaration
| Iir_Kind_Subtype_Declaration =>
Error_Msg_Sem
(+Name, "subprogram name is a type mark (missing apostrophe)");
when Iir_Kind_Stable_Attribute
| Iir_Kind_Quiet_Attribute
| Iir_Kind_Delayed_Attribute =>
if Actual /= Null_Iir then
Finish_Sem_Signal_Attribute_Signal (Prefix, Actual);
Set_Named_Entity (Name, Prefix);
else
Error_Msg_Sem (+Name, "bad attribute parameter");
Set_Named_Entity (Name, Error_Mark);
end if;
return;
when Iir_Kind_Ramp_Attribute
| Iir_Kind_Quantity_Slew_Attribute
| Iir_Kind_Signal_Slew_Attribute
| Iir_Kind_Zoh_Attribute
| Iir_Kind_Ltf_Attribute
| Iir_Kind_Ztf_Attribute
| Iir_Kind_Quantity_Delayed_Attribute =>
declare
Params : Iir_Array (1 .. 4);
begin
-- Try to extract 2 actuals from the name association list.
-- Emit a message in case of error.
Extract_Attribute_Parameters (Assoc_Chain, Params);
if Params (1) /= Null_Iir then
-- If ok, finish analysis.
Finish_Sem_Quantity_Attribute (Prefix_Name, Prefix, Params);
else
Prefix := Error_Mark;
end if;
-- The meaning of the parenthesis name is the attribute (as
-- the actuals have been moved to the attribute node).
Set_Named_Entity (Name, Prefix);
return;
end;
when Iir_Kind_Above_Attribute =>
if Actual /= Null_Iir then
Finish_Sem_Quantity_Attribute
(Prefix_Name, Prefix, (1 => Actual));
else
Error_Msg_Sem (+Name, "bad attribute parameter");
Prefix := Error_Mark;
end if;
Set_Named_Entity (Name, Prefix);
return;
when Iir_Kind_Procedure_Declaration
| Iir_Kind_Interface_Procedure_Declaration =>
Error_Msg_Sem (+Name, "cannot call %n in an expression",
+Prefix);
when Iir_Kinds_Sequential_Statement
| Iir_Kinds_Concurrent_Statement
| Iir_Kind_Component_Declaration
| Iir_Kind_Type_Conversion
| Iir_Kind_Unit_Declaration
| Iir_Kind_Enumeration_Literal
| Iir_Kind_Attribute_Declaration
| Iir_Kinds_Library_Unit
| Iir_Kind_Library_Declaration
| Iir_Kinds_Type_Attribute
| Iir_Kind_Nature_Declaration
| Iir_Kind_Subnature_Declaration
| Iir_Kind_Group_Declaration
| Iir_Kind_Group_Template_Declaration =>
Error_Msg_Sem (+Name, "%n cannot be indexed or sliced", +Prefix);
Res := Null_Iir;
when Iir_Kind_Psl_Declaration
| Iir_Kind_Psl_Endpoint_Declaration =>
Res := Sem_Psl.Sem_Psl_Name (Name);
when Iir_Kind_Error =>
-- Continue with the error.
Res := Prefix;
when others =>
Error_Kind ("sem_parenthesis_name", Prefix);
end case;
if Res = Null_Iir then
Res := Error_Mark;
end if;
Set_Named_Entity (Name, Res);
end Sem_Parenthesis_Name;
procedure Sem_Selected_By_All_Name (Name : Iir_Selected_By_All_Name)
is
Prefix : Iir;
Prefix_Name : Iir;
Res : Iir;
procedure Sem_As_Selected_By_All_Name (Sub_Name : Iir)
is
Base_Type : Iir;
R, R1 : Iir;
begin
-- Only accept prefix of access type.
Base_Type := Get_Base_Type (Get_Type (Sub_Name));
if Get_Kind (Base_Type) /= Iir_Kind_Access_Type_Definition then
return;
end if;
if not Maybe_Function_Call (Sub_Name) then
return;
end if;
R1 := Maybe_Insert_Function_Call (Get_Prefix (Name), Sub_Name);
R := Create_Iir (Iir_Kind_Dereference);
Location_Copy (R, Name);
Set_Prefix (R, R1);
-- FIXME: access subtype.
Set_Type (R, Get_Designated_Type (Base_Type));
Add_Result (Res, R);
end Sem_As_Selected_By_All_Name;
begin
Prefix := Get_Prefix (Name);
Sem_Name (Prefix);
Prefix_Name := Prefix;
Prefix := Get_Named_Entity (Prefix);
if Prefix = Null_Iir then
return;
end if;
Res := Null_Iir;
case Get_Kind (Prefix) is
when Iir_Kind_Overload_List =>
declare
Prefix_List : constant Iir_List := Get_Overload_List (Prefix);
It : List_Iterator;
begin
It := List_Iterate (Prefix_List);
while Is_Valid (It) loop
Sem_As_Selected_By_All_Name (Get_Element (It));
Next (It);
end loop;
end;
when Iir_Kinds_Object_Declaration
| Iir_Kind_Selected_Element
| Iir_Kind_Dereference
| Iir_Kind_Indexed_Name
| Iir_Kind_Function_Call =>
Sem_As_Selected_By_All_Name (Prefix);
when Iir_Kind_Function_Declaration =>
Prefix := Sem_As_Function_Call (Name => Prefix_Name,
Spec => Prefix,
Assoc_Chain => Null_Iir);
Sem_As_Selected_By_All_Name (Prefix);
when Iir_Kind_Error =>
Set_Named_Entity (Name, Error_Mark);
return;
when others =>
Error_Kind ("sem_selected_by_all_name", Prefix);
end case;
if Res = Null_Iir then
Error_Msg_Sem (+Name, "prefix type is not an access type");
Res := Error_Mark;
end if;
Set_Named_Entity (Name, Res);
end Sem_Selected_By_All_Name;
function Sem_Base_Attribute (Attr : Iir_Attribute_Name) return Iir
is
Prefix_Name : Iir;
Prefix_Type : Iir;
Res : Iir;
Base_Type : Iir;
Type_Decl : Iir;
begin
Prefix_Name := Finish_Sem_Name (Get_Prefix (Attr));
Prefix_Type := Name_To_Type_Definition (Prefix_Name);
if not Is_Error (Prefix_Type) then
Base_Type := Get_Base_Type (Prefix_Type);
-- Get the first subtype. FIXME: ref?
Type_Decl := Get_Type_Declarator (Base_Type);
if Get_Kind (Type_Decl) = Iir_Kind_Anonymous_Type_Declaration then
Base_Type := Get_Subtype_Definition (Type_Decl);
end if;
else
Base_Type := Prefix_Type;
end if;
Res := Create_Iir (Iir_Kind_Base_Attribute);
Location_Copy (Res, Attr);
Set_Prefix (Res, Prefix_Name);
Set_Type (Res, Base_Type);
return Res;
end Sem_Base_Attribute;
function Sem_User_Attribute (Attr : Iir_Attribute_Name) return Iir
is
Prefix_Name : constant Iir := Get_Prefix (Attr);
Prefix : Iir;
Value : Iir;
Attr_Id : Name_Id;
begin
Prefix := Get_Named_Entity (Prefix_Name);
-- LRM93 6.6
-- If the attribute name denotes an alias, then the attribute name
-- denotes an attribute of the aliased name and not the alias itself,
-- except when the attribute designator denotes any of the predefined
-- attributes 'simple_name, 'path_name, or 'instance_name.
if Get_Kind (Prefix) = Iir_Kind_Object_Alias_Declaration then
-- GHDL: according to 4.3.3, the name cannot be an alias.
Prefix := Strip_Denoting_Name (Get_Name (Prefix));
end if;
-- LRM93 6.6
-- If the attribute designator denotes a user-defined attribute, the
-- prefix cannot denote a subelement or a slice of an object.
case Get_Kind (Prefix) is
when Iir_Kind_Selected_By_All_Name
| Iir_Kind_Selected_Name
| Iir_Kind_Indexed_Name
| Iir_Kind_Slice_Name
| Iir_Kind_Selected_Element =>
Error_Msg_Sem (+Attr, "prefix of user defined attribute cannot be "
& "an object subelement");
return Error_Mark;
when Iir_Kind_Dereference =>
Error_Msg_Sem (+Attr, "prefix of user defined attribute cannot be "
& "an anonymous object");
return Error_Mark;
when Iir_Kind_Attribute_Declaration =>
Error_Msg_Sem (+Attr, "prefix of user defined attribute cannot be "
& "an attribute");
return Error_Mark;
when Iir_Kind_Function_Call
| Iir_Kind_Type_Conversion =>
Error_Msg_Sem (+Attr, "invalid prefix for user defined attribute");
return Error_Mark;
when Iir_Kinds_Object_Declaration
| Iir_Kind_Type_Declaration
| Iir_Kind_Subtype_Declaration
| Iir_Kind_Nature_Declaration
| Iir_Kind_Subnature_Declaration
| Iir_Kind_Function_Declaration
| Iir_Kind_Procedure_Declaration
| Iir_Kind_Enumeration_Literal
| Iir_Kind_Unit_Declaration
| Iir_Kind_Component_Declaration
| Iir_Kinds_Library_Unit =>
-- FIXME: complete
null;
when Iir_Kinds_Sequential_Statement
| Iir_Kinds_Concurrent_Statement =>
-- May appear textually before the statement.
Set_Is_Forward_Ref (Prefix_Name, True);
when others =>
Error_Kind ("sem_user_attribute", Prefix);
end case;
Attr_Id := Get_Identifier (Attr);
Value := Sem_Specs.Find_Attribute_Value (Prefix, Attr_Id);
if Value = Null_Iir then
Error_Msg_Sem (+Attr, "%n was not annotated with attribute %i",
(+Prefix, +Attr_Id));
if Attr_Id = Std_Names.Name_First or Attr_Id = Std_Names.Name_Last
then
-- Nice (?) message for Ada users.
Error_Msg_Sem
(+Attr, "(you may use 'high, 'low, 'left or 'right attribute)");
end if;
return Error_Mark;
end if;
Xref_Ref (Attr, Value);
if Get_Static_Attribute_Flag (Get_Attribute_Specification (Value))
and then not Get_Is_Within_Flag (Prefix)
and then Get_Expr_Staticness (Value) /= Locally
then
Error_Msg_Sem
(+Attr, "non-locally static attribute cannot be referenced here");
return Error_Mark;
end if;
return Value;
end Sem_User_Attribute;
-- The prefix of scalar type attributes is a type name (or 'base), and
-- therefore isn't overloadable. So at the end of the function, the
-- analyze is finished.
function Sem_Scalar_Type_Attribute (Attr : Iir_Attribute_Name)
return Iir
is
use Std_Names;
Prefix_Name : constant Iir := Get_Prefix (Attr);
Id : constant Name_Id := Get_Identifier (Attr);
Prefix_Type : Iir;
Res : Iir;
begin
-- LRM93 14.1
-- Prefix: Any discrete or physical type of subtype T.
Prefix_Type :=
Name_To_Type_Definition (Name_To_Analyzed_Name (Prefix_Name));
Set_Type (Prefix_Name, Prefix_Type);
if Is_Error (Prefix_Type) then
--Error_Msg_Sem
--(+Attr, "prefix of %i attribute must be a type", +Id);
return Error_Mark;
end if;
case Id is
when Name_Image
| Name_Value =>
if Get_Kind (Prefix_Type)
not in Iir_Kinds_Scalar_Type_And_Subtype_Definition
then
Report_Start_Group;
Error_Msg_Sem
(+Attr, "prefix of %i attribute must be a scalar type", +Id);
Error_Msg_Sem
(+Attr, "found %n defined at %l",
(+Prefix_Type, +Prefix_Type));
Report_End_Group;
return Error_Mark;
end if;
when others =>
case Get_Kind (Prefix_Type) is
when Iir_Kinds_Discrete_Type_Definition
| Iir_Kind_Physical_Subtype_Definition
| Iir_Kind_Physical_Type_Definition =>
null;
when others =>
Report_Start_Group;
Error_Msg_Sem
(+Attr, "prefix of %i"
& " attribute must be discrete or physical type", +Id);
Error_Msg_Sem
(+Attr, "found %n defined at %l",
(+Prefix_Type, +Prefix_Type));
Report_End_Group;
return Error_Mark;
end case;
end case;
-- Create the resulting node.
case Get_Identifier (Attr) is
when Name_Pos =>
Res := Create_Iir (Iir_Kind_Pos_Attribute);
when Name_Val =>
Res := Create_Iir (Iir_Kind_Val_Attribute);
when Name_Succ =>
Res := Create_Iir (Iir_Kind_Succ_Attribute);
when Name_Pred =>
Res := Create_Iir (Iir_Kind_Pred_Attribute);
when Name_Leftof =>
Res := Create_Iir (Iir_Kind_Leftof_Attribute);
when Name_Rightof =>
Res := Create_Iir (Iir_Kind_Rightof_Attribute);
when Name_Image =>
Res := Create_Iir (Iir_Kind_Image_Attribute);
when Name_Value =>
Res := Create_Iir (Iir_Kind_Value_Attribute);
when others =>
raise Internal_Error;
end case;
Location_Copy (Res, Attr);
Set_Prefix (Res, Prefix_Name);
Set_Base_Name (Res, Res);
case Get_Identifier (Attr) is
when Name_Pos =>
-- LRM93 14.1
-- Result type: universal_integer.
Set_Type (Res, Convertible_Integer_Type_Definition);
when Name_Val =>
-- LRM93 14.1
-- Result type: the base type of T
Set_Type (Res, Get_Base_Type (Prefix_Type));
when Name_Succ
| Name_Pred
| Name_Leftof
| Name_Rightof =>
-- LRM93 14.1
-- Result type: the base type of T.
Set_Type (Res, Get_Base_Type (Prefix_Type));
when Name_Image =>
-- LRM93 14.1
-- Result type: type string
Set_Type (Res, String_Type_Definition);
when Name_Value =>
-- LRM93 14.1
-- Result type: the base type of T.
Set_Type (Res, Get_Base_Type (Prefix_Type));
when others =>
raise Internal_Error;
end case;
return Res;
end Sem_Scalar_Type_Attribute;
-- Analyze attributes whose prefix is a type or a subtype and result is
-- a value (not a function).
function Sem_Predefined_Type_Attribute (Attr : Iir_Attribute_Name)
return Iir
is
use Std_Names;
Prefix_Name : constant Iir := Get_Prefix (Attr);
Id : constant Name_Id := Get_Identifier (Attr);
Res : Iir;
Prefix : Iir;
Prefix_Type : Iir;
begin
case Id is
when Name_Left =>
Res := Create_Iir (Iir_Kind_Left_Type_Attribute);
when Name_Right =>
Res := Create_Iir (Iir_Kind_Right_Type_Attribute);
when Name_High =>
Res := Create_Iir (Iir_Kind_High_Type_Attribute);
when Name_Low =>
Res := Create_Iir (Iir_Kind_Low_Type_Attribute);
when Name_Ascending =>
Res := Create_Iir (Iir_Kind_Ascending_Type_Attribute);
when Name_Range
| Name_Reverse_Range =>
Error_Msg_Sem
(+Attr,
"prefix of range attribute must be an array type or object");
return Error_Mark;
when others =>
Error_Msg_Sem (+Attr, "attribute %i not valid on this type", +Id);
return Error_Mark;
end case;
Location_Copy (Res, Attr);
Set_Base_Name (Res, Res);
Prefix := Get_Named_Entity (Prefix_Name);
case Get_Kind (Prefix) is
when Iir_Kind_Range_Array_Attribute
| Iir_Kind_Reverse_Range_Array_Attribute =>
Prefix := Finish_Sem_Name (Prefix_Name, Prefix);
Prefix_Type := Get_Type (Prefix);
Set_Expr_Staticness (Res, Get_Expr_Staticness (Prefix));
when Iir_Kind_Base_Attribute =>
-- Base_Attribute is already finished.
pragma Assert (Get_Kind (Prefix_Name) = Iir_Kind_Attribute_Name);
Free_Iir (Prefix_Name);
Prefix_Type := Get_Type (Prefix);
Set_Expr_Staticness (Res, Get_Type_Staticness (Prefix_Type));
when others =>
Prefix := Sem_Type_Mark (Prefix_Name);
Prefix_Type := Get_Type (Prefix);
Set_Expr_Staticness (Res, Get_Type_Staticness (Prefix_Type));
end case;
Set_Prefix (Res, Prefix);
case Get_Identifier (Attr) is
when Name_Ascending =>
-- LRM93 14.1
-- Result Type: type boolean.
Set_Type (Res, Boolean_Type_Definition);
when others =>
-- LRM 14.1
-- Result Type: Same type as T.
Set_Type (Res, Prefix_Type);
end case;
return Res;
end Sem_Predefined_Type_Attribute;
-- Called for attributes Length, Left, Right, High, Low, Range,
-- Reverse_Range, Ascending.
-- FIXME: handle overload
function Sem_Array_Attribute_Name (Attr : Iir_Attribute_Name) return Iir
is
use Std_Names;
Prefix_Name : constant Iir := Get_Prefix (Attr);
Prefix_Type : Iir;
Prefix : Iir;
Res : Iir;
Res_Type : Iir;
begin
Prefix := Get_Named_Entity (Prefix_Name);
-- LRM93 14.1
-- Prefix: Any prefix A that is appropriate for an array object, or an
-- alias thereof, or that denotes a constrained array subtype.
--
-- LRM08 16.2 Predefined attributes.
-- Prefix of A'Left[(N)], A'Right[(N)]... :
-- Any prefix A that is appropriate for an array object, or an alias
-- thereof, or that denotes a constrained an array subtype whose index
-- ranges are defined by a constraint.
--
-- GHDL: the prefix cannot be a function call, as the result is not
-- an object and it doesn't denote a subtype. References are:
--
-- LRM08 6.4 Objects:
-- An object is a named entity [...]
-- In addition the following are objects, but are not named
-- entities[...]
--
-- LRM08 6 Declarations
-- the name is said to denote the associated entity.
case Get_Kind (Prefix) is
when Iir_Kind_Dereference
| Iir_Kinds_Object_Declaration
| Iir_Kind_Function_Call
| Iir_Kind_Function_Declaration
| Iir_Kind_Selected_Element
| Iir_Kind_Indexed_Name
| Iir_Kind_Slice_Name
| Iir_Kind_Attribute_Value
| Iir_Kind_Image_Attribute =>
-- FIXME: list of expr.
Prefix_Type := Get_Type (Prefix);
case Get_Kind (Prefix_Type) is
when Iir_Kind_Access_Type_Definition
| Iir_Kind_Access_Subtype_Definition =>
declare
Designated_Type : Iir;
begin
Designated_Type :=
Get_Designated_Type (Get_Base_Type (Prefix_Type));
Prefix := Insert_Implicit_Dereference (Prefix, Attr);
Prefix_Type := Designated_Type;
end;
when Iir_Kinds_Array_Type_Definition =>
null;
when others =>
Error_Msg_Sem (+Attr, "object prefix must be an array");
return Error_Mark;
end case;
when Iir_Kind_Subtype_Declaration
| Iir_Kind_Type_Declaration
| Iir_Kind_Base_Attribute
| Iir_Kind_Subtype_Attribute
| Iir_Kind_Element_Attribute =>
Prefix_Type := Get_Type (Prefix);
if not Is_Fully_Constrained_Type (Prefix_Type) then
Error_Msg_Sem (+Attr, "prefix type is not constrained");
-- We continue using the unconstrained array type.
-- At least, this type is valid; and even if the array was
-- constrained, the base type would be the same.
end if;
when Iir_Kind_Range_Array_Attribute
| Iir_Kind_Reverse_Range_Array_Attribute =>
-- For names such as pfx'Range'Left.
-- Finish_Sem_Array_Attribute (Prefix_Name, Prefix, Null_Iir);
Prefix_Type := Get_Type (Prefix);
when Iir_Kind_Process_Statement =>
Error_Msg_Sem
(+Attr, "%n is not an appropriate prefix for %i attribute",
(+Prefix, +Attr));
return Error_Mark;
when others =>
Error_Msg_Sem
(+Attr, "prefix must denote an array object or type");
return Error_Mark;
end case;
case Get_Kind (Prefix_Type) is
when Iir_Kinds_Scalar_Type_And_Subtype_Definition =>
-- Note: prefix is a scalar type or subtype.
return Sem_Predefined_Type_Attribute (Attr);
when Iir_Kinds_Array_Type_Definition =>
null;
when others =>
Error_Msg_Sem (+Attr, "prefix of %i attribute must denote a "
& "constrained array subtype", +Attr);
return Error_Mark;
end case;
-- Type of the attribute. This is correct unless there is a parameter,
-- and furthermore 'range and 'reverse_range has to be handled
-- specially because the result is a range and not a value.
Res_Type := Get_Index_Type (Get_Index_Subtype_List (Prefix_Type), 0);
-- Create the node for the attribute.
case Get_Identifier (Attr) is
when Name_Left =>
Res := Create_Iir (Iir_Kind_Left_Array_Attribute);
when Name_Right =>
Res := Create_Iir (Iir_Kind_Right_Array_Attribute);
when Name_High =>
Res := Create_Iir (Iir_Kind_High_Array_Attribute);
when Name_Low =>
Res := Create_Iir (Iir_Kind_Low_Array_Attribute);
when Name_Range =>
Res := Create_Iir (Iir_Kind_Range_Array_Attribute);
when Name_Reverse_Range =>
Res := Create_Iir (Iir_Kind_Reverse_Range_Array_Attribute);
when Name_Length =>
Res := Create_Iir (Iir_Kind_Length_Array_Attribute);
-- FIXME: Error if ambiguous
Res_Type := Convertible_Integer_Type_Definition;
when Name_Ascending =>
Res := Create_Iir (Iir_Kind_Ascending_Array_Attribute);
-- FIXME: Error if ambiguous
Res_Type := Boolean_Type_Definition;
when others =>
raise Internal_Error;
end case;
Location_Copy (Res, Attr);
Set_Prefix (Res, Prefix);
Set_Type (Res, Res_Type);
return Res;
end Sem_Array_Attribute_Name;
-- For 'Subtype
function Sem_Subtype_Attribute (Attr : Iir_Attribute_Name) return Iir
is
Prefix_Name : Iir;
Attr_Type : Iir;
Res : Iir;
begin
Prefix_Name := Get_Prefix (Attr);
Prefix_Name := Finish_Sem_Name (Prefix_Name);
Set_Prefix (Attr, Prefix_Name);
-- LRM08 16.2 Predefined attributes
-- Prefix: Any prefix O that is appropriate for an object, or an alias
-- thereof
if (Get_Kind (Get_Base_Name (Prefix_Name))
not in Iir_Kinds_Object_Declaration)
then
Error_Msg_Sem (+Attr, "prefix must denote an object");
return Error_Mark;
end if;
-- The type defined by 'subtype is always constrained. Create
-- a subtype if it is not.
Attr_Type := Get_Type (Prefix_Name);
if False and not Is_Fully_Constrained_Type (Attr_Type) then
Attr_Type := Sem_Types.Build_Constrained_Subtype (Attr_Type, Attr);
end if;
Res := Create_Iir (Iir_Kind_Subtype_Attribute);
Location_Copy (Res, Attr);
Set_Prefix (Res, Prefix_Name);
Set_Type (Res, Attr_Type);
Set_Base_Name (Res, Res);
Set_Name_Staticness (Res, Get_Name_Staticness (Prefix_Name));
Set_Type_Staticness (Res, Get_Type_Staticness (Attr_Type));
return Res;
end Sem_Subtype_Attribute;
-- For 'Element
function Sem_Element_Attribute (Attr : Iir_Attribute_Name) return Iir
is
Prefix_Name : Iir;
Attr_Type : Iir;
Attr_Subtype : Iir;
Res : Iir;
begin
Prefix_Name := Get_Prefix (Attr);
Prefix_Name := Finish_Sem_Name (Prefix_Name);
Set_Prefix (Attr, Prefix_Name);
-- LRM08 16.2 Predefined attributes
-- Prefix: Any prefix A that is appropriate for an array object, or an
-- alias thereof, or that denotes an array subtype
if (Get_Kind (Get_Base_Name (Prefix_Name))
in Iir_Kinds_Object_Declaration)
then
Attr_Type := Get_Type (Prefix_Name);
elsif (Get_Kind (Get_Base_Name (Prefix_Name))
in Iir_Kinds_Type_Declaration)
then
Attr_Type := Get_Type (Get_Base_Name (Prefix_Name));
else
Error_Msg_Sem (+Attr, "prefix must denote an object or a type");
end if;
if False and not Is_Array_Type (Attr_Type) then
Error_Msg_Sem (+Attr, "prefix must denote an array");
end if;
-- The type defined by 'element is always constrained. Create
-- a subtype if it is not.
Attr_Subtype := Get_Element_Subtype (Attr_Type);
if False and not Is_Fully_Constrained_Type (Attr_Subtype) then
Attr_Subtype :=
Sem_Types.Build_Constrained_Subtype (Attr_Subtype, Attr);
end if;
Res := Create_Iir (Iir_Kind_Element_Attribute);
Location_Copy (Res, Attr);
Set_Prefix (Res, Prefix_Name);
Set_Type (Res, Attr_Subtype);
Set_Base_Name (Res, Res);
Set_Name_Staticness (Res, Get_Name_Staticness (Prefix_Name));
Set_Type_Staticness (Res, Get_Type_Staticness (Attr_Subtype));
return Res;
end Sem_Element_Attribute;
-- For 'Across or 'Through
function Sem_Nature_Type_Attribute (Attr : Iir_Attribute_Name) return Iir
is
Prefix_Name : constant Iir := Get_Prefix (Attr);
Prefix : Iir;
Prefix_Nature : Iir;
Res : Iir;
Attr_Type : Iir;
begin
Prefix := Get_Named_Entity (Prefix_Name);
-- LRM08 16.2 Predefined attributes
-- Prefix: Any nature or subnature N.
case Get_Kind (Prefix) is
when Iir_Kind_Nature_Declaration
| Iir_Kind_Subnature_Declaration =>
null;
when others =>
Error_Msg_Sem (+Attr, "prefix must denote a nature");
return Error_Mark;
end case;
Prefix_Nature := Get_Nature (Prefix);
case Get_Identifier (Attr) is
when Std_Names.Name_Across =>
Res := Create_Iir (Iir_Kind_Across_Attribute);
Attr_Type := Get_Across_Type (Prefix_Nature);
when Std_Names.Name_Through =>
Res := Create_Iir (Iir_Kind_Through_Attribute);
Attr_Type := Get_Across_Type (Prefix_Nature);
when others =>
raise Internal_Error;
end case;
pragma Assert (Attr_Type /= Null_Iir);
Location_Copy (Res, Attr);
Set_Prefix (Res, Prefix);
Set_Type (Res, Attr_Type);
Set_Base_Name (Res, Get_Base_Name (Prefix_Name));
Set_Name_Staticness (Res, Get_Name_Staticness (Prefix_Name));
Set_Type_Staticness (Res, Get_Type_Staticness (Attr_Type));
return Res;
end Sem_Nature_Type_Attribute;
-- For 'Reference
function Sem_Nature_Reference_Attribute (Attr : Iir_Attribute_Name)
return Iir
is
Prefix_Name : constant Iir := Get_Prefix (Attr);
Prefix : Iir;
Res : Iir;
begin
Prefix := Get_Named_Entity (Prefix_Name);
-- AMS-LRM17 16.2.6 Predefined analog attributes
-- Prefix: Any nature of subnature N.
case Get_Kind (Prefix) is
when Iir_Kind_Nature_Declaration
| Iir_Kind_Subnature_Declaration =>
null;
when others =>
Error_Msg_Sem (+Attr, "prefix must denote a nature");
return Error_Mark;
end case;
Res := Create_Iir (Iir_Kind_Nature_Reference_Attribute);
Location_Copy (Res, Attr);
Set_Prefix (Res, Prefix);
Set_Nature (Res, Get_Nature (Prefix));
Set_Base_Name (Res, Get_Base_Name (Prefix_Name));
Set_Name_Staticness (Res, Get_Name_Staticness (Prefix_Name));
return Res;
end Sem_Nature_Reference_Attribute;
function Sem_Quantity_Attribute (Attr : Iir_Attribute_Name) return Iir
is
use Std_Names;
Name_Prefix : constant Iir := Get_Prefix (Attr);
Prefix: Iir;
Res : Iir;
Res_Type : Iir;
begin
Prefix := Get_Named_Entity (Name_Prefix);
Prefix := Finish_Sem_Name_1 (Name_Prefix, Prefix);
if not Is_Quantity_Name (Prefix) then
Error_Msg_Sem
(+Attr, "prefix of %i attribute must denote a quantity", +Attr);
end if;
Res_Type := Get_Type (Prefix);
case Get_Identifier (Attr) is
when Name_Above =>
Res := Create_Iir (Iir_Kind_Above_Attribute);
Res_Type := Boolean_Type_Definition;
when Name_Dot =>
Res := Create_Iir (Iir_Kind_Dot_Attribute);
when Name_Integ =>
Res := Create_Iir (Iir_Kind_Integ_Attribute);
when Name_Zoh =>
Res := Create_Iir (Iir_Kind_Zoh_Attribute);
when Name_Ltf =>
Res := Create_Iir (Iir_Kind_Ltf_Attribute);
when Name_Ztf =>
Res := Create_Iir (Iir_Kind_Ztf_Attribute);
when Name_Delayed =>
Res := Create_Iir (Iir_Kind_Quantity_Delayed_Attribute);
when others =>
-- Not yet implemented attribute, or really an internal error.
raise Internal_Error;
end case;
Location_Copy (Res, Attr);
Set_Prefix (Res, Prefix);
Set_Type (Res, Res_Type);
-- AMS-LRM17 16.2.6 Predefined analog an mixed-signal attributes
-- Prefix: Any quantity denoted by the static name Q.
if Get_Name_Staticness (Prefix) < Globally then
Error_Msg_Sem
(+Res, "prefix of %i attribute must be a static name", +Res);
end if;
-- According to LRM 7.4, signal attributes are not static expressions
-- since the prefix (a signal) is not a static expression.
Set_Expr_Staticness (Res, None);
-- AMS-LRM17 8.1 Names
-- A name is said to be a static name if and only if one of the
-- following conditions holds:
-- [...]
-- - The name is an attribute whose prefix is a static quantity name
-- and whose suffix is one of the predefined attributes 'ABOVE, 'DOT,
-- 'INTEG, 'DELAYED, 'SLEW, 'LTF, 'ZOH, or 'ZTF.
Set_Name_Staticness (Res, Globally);
return Res;
end Sem_Quantity_Attribute;
function Sem_Slew_Attribute (Attr : Iir_Attribute_Name) return Iir
is
Prefix_Name : constant Iir := Get_Prefix (Attr);
Prefix: Iir;
Res : Iir;
Res_Type : Iir;
begin
Prefix := Get_Named_Entity (Prefix_Name);
if Is_Quantity_Name (Prefix) then
Res := Create_Iir (Iir_Kind_Quantity_Slew_Attribute);
elsif Is_Signal_Name (Prefix) then
Res := Create_Iir (Iir_Kind_Signal_Slew_Attribute);
else
Error_Msg_Sem
(+Attr,
"prefix of 'slew must denote a quantity or a signal", +Attr);
return Error_Mark;
end if;
-- AMS-VHDL17 16.2.6
-- Prefix: Any signal denoted by the static name S whose scalar
-- subelements are of a floating-point type.
--
-- GHDL: not necessary when the prefix is a quantity.
Res_Type := Get_Type (Prefix);
if not Sem_Types.Is_Nature_Type (Res_Type) then
Error_Msg_Sem (+Attr, "prefix of 'slew must be of nature type");
end if;
if Get_Name_Staticness (Prefix) < Globally then
Error_Msg_Sem (+Attr, "prefix of 'slew must be a static name");
end if;
Set_Type (Res, Res_Type);
Location_Copy (Res, Attr);
Set_Prefix (Res, Prefix);
Set_Expr_Staticness (Res, None);
-- AMS-LRM17 8.1 Names
-- A name is said to be a static name if and only if one of the
-- following conditions holds:
-- [...]
-- - The name is an attribute whose prefix is a static quantity name
-- and whose suffix is one of the predefined attributes 'ABOVE, 'DOT,
-- 'INTEG, 'DELAYED, 'SLEW, 'LTF, 'ZOH, or 'ZTF.
Set_Name_Staticness (Res, Globally);
return Res;
end Sem_Slew_Attribute;
function Sem_Signal_Signal_Attribute
(Attr : Iir_Attribute_Name; Kind : Iir_Kind)
return Iir
is
Res : Iir;
Prefix : Iir;
begin
Prefix := Get_Named_Entity (Get_Prefix (Attr));
-- Create the proper signal attribute node.
Res := Create_Iir (Kind);
Location_Copy (Res, Attr);
if Kind = Iir_Kind_Delayed_Attribute then
Set_Type (Res, Get_Type (Prefix));
elsif Kind = Iir_Kind_Transaction_Attribute then
Set_Type (Res, Bit_Type_Definition);
else
Set_Type (Res, Boolean_Type_Definition);
end if;
Set_Base_Name (Res, Res);
if Get_Kind (Prefix) = Iir_Kind_Interface_Signal_Declaration then
-- LRM93 2.1.1.2 / LRM08 4.2.2.3
--
-- It is an error if signal-valued attributes 'STABLE , 'QUIET,
-- 'TRANSACTION, and 'DELAYED of formal signal paramaters of any
-- mode are read within a subprogram.
case Get_Kind (Get_Parent (Prefix)) is
when Iir_Kind_Function_Declaration
| Iir_Kind_Procedure_Declaration =>
Error_Msg_Sem
(+Attr, "%i is not allowed for a signal parameter", +Attr);
when others =>
null;
end case;
end if;
-- Add a declaration for it.
Sem_Decls.Add_Declaration_For_Implicit_Signal (Res);
return Res;
end Sem_Signal_Signal_Attribute;
function Sem_Signal_Attribute (Attr : Iir_Attribute_Name) return Iir
is
use Std_Names;
Id : constant Name_Id := Get_Identifier (Attr);
Prefix: Iir;
Res : Iir;
Base : Iir;
begin
Prefix := Get_Named_Entity (Get_Prefix (Attr));
Base := Get_Object_Prefix (Prefix);
if AMS_Vhdl
and then Id = Name_Delayed
and then Is_Quantity_Name (Base)
then
return Sem_Quantity_Attribute (Attr);
end if;
case Get_Kind (Base) is
when Iir_Kind_Signal_Declaration
| Iir_Kind_Interface_Signal_Declaration
| Iir_Kind_Guard_Signal_Declaration
| Iir_Kinds_Signal_Attribute =>
null;
when others =>
Error_Msg_Sem
(+Attr, "prefix of %i attribute must denote a signal", +Attr);
return Error_Mark;
end case;
case Id is
when Name_Stable =>
Res := Sem_Signal_Signal_Attribute
(Attr, Iir_Kind_Stable_Attribute);
when Name_Quiet =>
Res := Sem_Signal_Signal_Attribute
(Attr, Iir_Kind_Quiet_Attribute);
when Name_Delayed =>
Res := Sem_Signal_Signal_Attribute
(Attr, Iir_Kind_Delayed_Attribute);
when Name_Transaction =>
Res := Sem_Signal_Signal_Attribute
(Attr, Iir_Kind_Transaction_Attribute);
when Name_Event =>
Res := Create_Iir (Iir_Kind_Event_Attribute);
Set_Type (Res, Boolean_Type_Definition);
when Name_Active =>
Res := Create_Iir (Iir_Kind_Active_Attribute);
Set_Type (Res, Boolean_Type_Definition);
when Name_Last_Value =>
Res := Create_Iir (Iir_Kind_Last_Value_Attribute);
Set_Type (Res, Get_Type (Prefix));
when Name_Last_Event =>
Res := Create_Iir (Iir_Kind_Last_Event_Attribute);
Set_Type (Res, Time_Type_Definition);
when Name_Last_Active =>
Res := Create_Iir (Iir_Kind_Last_Active_Attribute);
Set_Type (Res, Time_Type_Definition);
when Name_Driving_Value =>
Res := Create_Iir (Iir_Kind_Driving_Value_Attribute);
Set_Type (Res, Get_Type (Prefix));
-- FIXME: check restrictions.
when Name_Driving =>
Res := Create_Iir (Iir_Kind_Driving_Attribute);
Set_Type (Res, Boolean_Type_Definition);
-- FIXME: check restrictions.
when Name_Ramp =>
Res := Create_Iir (Iir_Kind_Ramp_Attribute);
Set_Type (Res, Get_Type (Prefix));
when others =>
-- Not yet implemented attribute, or really an internal error.
raise Internal_Error;
end case;
Location_Copy (Res, Attr);
-- LRM 4.3.2
-- The value of an object is said to be read when one of the following
-- conditions is satisfied:
-- [...]
-- * When the object is a signal and the value of any of its predefined
-- attributes 'STABLE, 'QUIET, 'DELAYED, 'TRANSACTION, 'EVENT,
-- 'ACTIVE, 'LAST_EVENT, 'LAST_ACTIVE, or 'LAST_VALUE is read.
-- LRM 14.1
-- S'Driving Restrictions:
-- S'Driving_Value Restrictions:
-- This attribute is available only from within a process, a
-- concurrent statement with an equivalent process, or a subprogram.
-- If the prefix denotes a port, it is an error if the port does not
-- have a mode of INOUT, OUT or BUFFER. It is also an error if the
-- attribute name appears in a subprogram body that is not a declarative
-- item contained within a process statement and the prefix is not a
-- formal parameter of the given subprogram or of a parent of that
-- subprogram. Finally, it is an error if the prefix denotes a
-- subprogram formal parameter whose mode is not INOUT or OUT, or if
-- S'Driving is False at the time of the evaluation of S'Driving_Value.
case Get_Kind (Res) is
when Iir_Kind_Stable_Attribute
| Iir_Kind_Quiet_Attribute
| Iir_Kind_Delayed_Attribute
| Iir_Kind_Transaction_Attribute
| Iir_Kind_Event_Attribute
| Iir_Kind_Active_Attribute
| Iir_Kind_Last_Event_Attribute
| Iir_Kind_Last_Active_Attribute
| Iir_Kind_Last_Value_Attribute =>
Check_Read (Prefix);
when Iir_Kind_Driving_Attribute
| Iir_Kind_Driving_Value_Attribute =>
-- FIXME: complete checks.
if Get_Current_Concurrent_Statement = Null_Iir then
Error_Msg_Sem
(+Attr, "'driving or 'driving_value is available only "
& "within a concurrent statement");
else
case Get_Kind (Get_Current_Concurrent_Statement) is
when Iir_Kinds_Process_Statement
| Iir_Kind_Concurrent_Conditional_Signal_Assignment
| Iir_Kind_Concurrent_Selected_Signal_Assignment
| Iir_Kind_Concurrent_Procedure_Call_Statement =>
null;
when others =>
Error_Msg_Sem
(+Attr, "'driving or 'driving_value not available "
& "within this concurrent statement");
end case;
end if;
case Get_Kind (Base) is
when Iir_Kind_Signal_Declaration =>
null;
when Iir_Kind_Interface_Signal_Declaration =>
case Get_Mode (Base) is
when Iir_Buffer_Mode
| Iir_Inout_Mode
| Iir_Out_Mode =>
null;
when others =>
Error_Msg_Sem
(+Attr, "mode of 'driving or 'driving_value prefix "
& "must be out, inout or buffer");
end case;
when others =>
Error_Msg_Sem
(+Attr, "bad prefix for 'driving or 'driving_value");
end case;
when Iir_Kind_Ramp_Attribute =>
null;
when others =>
null;
end case;
Set_Prefix (Res, Prefix);
-- Set has_active_flag when activity is read.
case Get_Kind (Res) is
when Iir_Kind_Quiet_Attribute
| Iir_Kind_Transaction_Attribute
| Iir_Kind_Active_Attribute
| Iir_Kind_Last_Active_Attribute =>
Set_Has_Active_Flag (Base, True);
when others =>
null;
end case;
return Res;
end Sem_Signal_Attribute;
-- 'Simple_name, 'instance_name and 'path_name.
function Sem_Name_Attribute (Attr : Iir_Attribute_Name) return Iir
is
use Std_Names;
Prefix_Name : constant Iir := Get_Prefix (Attr);
Prefix: Iir;
Res : Iir;
Attr_Type : Iir;
begin
Prefix := Get_Named_Entity (Prefix_Name);
Set_Prefix (Attr, Finish_Sem_Name (Prefix_Name, Prefix));
-- LRM 14.1 Predefined attributes
-- E'SIMPLE_NAME
-- Prefix: Any named entity as defined in 5.1
-- E'INSTANCE_NAME
-- Prefix: Any named entity other than the local ports and generics
-- of a component declaration.
-- E'PATH_NAME
-- Prefix: Any named entity other than the local ports and generics
-- of a component declaration.
case Get_Kind (Prefix) is
when Iir_Kind_Procedure_Declaration
| Iir_Kind_Function_Declaration
| Iir_Kind_Type_Declaration
| Iir_Kind_Subtype_Declaration
| Iir_Kind_Constant_Declaration
| Iir_Kind_Signal_Declaration
| Iir_Kind_Variable_Declaration
| Iir_Kind_Interface_Variable_Declaration
| Iir_Kind_Iterator_Declaration
| Iir_Kind_Component_Declaration
| Iir_Kinds_Concurrent_Statement
| Iir_Kinds_Sequential_Statement
| Iir_Kind_Enumeration_Literal
| Iir_Kind_Group_Declaration
| Iir_Kind_Group_Template_Declaration
| Iir_Kind_File_Declaration
| Iir_Kinds_Library_Unit
| Iir_Kind_Non_Object_Alias_Declaration =>
null;
when Iir_Kind_Interface_Signal_Declaration
| Iir_Kind_Interface_Constant_Declaration =>
if Get_Identifier (Attr) /= Name_Simple_Name
and then Get_Kind (Get_Parent (Prefix))
= Iir_Kind_Component_Declaration
then
Error_Msg_Sem
(+Attr,
"local ports or generics of a component cannot be a prefix");
end if;
when Iir_Kind_Subtype_Attribute
| Iir_Kind_Base_Attribute =>
declare
Atype : constant Iir := Get_Type (Prefix);
begin
if Is_Anonymous_Type_Definition (Atype) then
Error_Msg_Sem (+Attr, "%n is not a named entity", +Prefix);
return Create_Error_Expr (Attr, String_Type_Definition);
end if;
Prefix := Get_Type_Declarator (Atype);
end;
when others =>
Error_Msg_Sem (+Attr, "%n is not a named entity", +Prefix);
return Create_Error_Expr (Attr, String_Type_Definition);
end case;
case Get_Identifier (Attr) is
when Name_Simple_Name =>
declare
Id : constant Name_Id := Name_Table.Get_Identifier
(Eval_Simple_Name (Get_Identifier (Prefix)));
begin
Res := Create_Iir (Iir_Kind_Simple_Name_Attribute);
Set_Simple_Name_Identifier (Res, Id);
Attr_Type := Create_Unidim_Array_By_Length
(String_Type_Definition,
Int64 (Name_Table.Get_Name_Length (Id)),
Attr);
Set_Simple_Name_Subtype (Res, Attr_Type);
Set_Expr_Staticness (Res, Locally);
end;
when Name_Path_Name =>
Res := Create_Iir (Iir_Kind_Path_Name_Attribute);
Set_Expr_Staticness (Res, Globally);
Attr_Type := String_Type_Definition;
when Name_Instance_Name =>
Res := Create_Iir (Iir_Kind_Instance_Name_Attribute);
Set_Expr_Staticness (Res, Globally);
Attr_Type := String_Type_Definition;
when others =>
raise Internal_Error;
end case;
Location_Copy (Res, Attr);
Set_Prefix (Res, Prefix_Name);
Set_Type (Res, Attr_Type);
return Res;
end Sem_Name_Attribute;
procedure Sem_Attribute_Name (Attr : Iir_Attribute_Name)
is
use Std_Names;
Prefix : Iir;
Res : Iir;
Sig : Iir_Signature;
begin
-- LRM93 6.6 Attribute names
-- The meaning of the prefix of an attribute name must be determinable
-- independently of the attribute designator and independently of the
-- fact that it is the prefix of an attribute.
Prefix := Get_Prefix (Attr);
-- LRM93 6.6
-- If the prefix of an attribute name denotes an alias, then the
-- attribute name denotes an attribute of the aliased name and not the
-- alias itself, except when the attribute designator denotes any of
-- the predefined attributes 'Simple_Name, 'Path_Name or 'Instance_Name.
-- If the prefix of an attribute name denotes an alias and the
-- attribute designator denotes any of the predefined attributes
-- 'Simple_Name, 'Path_Name or 'Instance_Name, then the attribute name
-- denotes the attribute of the alias and not of the aliased name.
if Flags.Vhdl_Std > Vhdl_87
and then Get_Identifier (Attr) in Name_Id_Name_Attributes
then
Sem_Name (Prefix, True);
else
Sem_Name (Prefix, False);
end if;
Prefix := Get_Named_Entity (Prefix);
if Prefix = Error_Mark then
Set_Named_Entity (Attr, Prefix);
return;
end if;
-- LRM93 6.6
-- A signature may follow the prefix if and only if the prefix denotes
-- a subprogram or enumeration literal, or an alias thereof.
-- In this case, the signature is required to match (see Section 2.3.2)
-- the parameter and result type profile of exactly one visible
-- subprogram or enumeration literal, as is appropriate to the prefix.
-- GHDL: this is done by Sem_Signature.
Sig := Get_Attribute_Signature (Attr);
if Sig /= Null_Iir then
Prefix := Sem_Signature (Prefix, Sig);
if Prefix = Null_Iir then
Set_Named_Entity (Attr, Error_Mark);
return;
end if;
Set_Named_Entity (Get_Prefix (Attr), Prefix);
end if;
if Get_Kind (Prefix) = Iir_Kind_Overload_List then
-- FIXME: this should be allowed.
Error_Msg_Sem (+Attr, "prefix of attribute is overloaded");
Set_Named_Entity (Attr, Error_Mark);
return;
end if;
-- Set_Prefix (Attr, Finish_Sem_Name (Get_Prefix (Attr), Prefix));
case Get_Identifier (Attr) is
when Name_Base =>
Res := Sem_Base_Attribute (Attr);
when Name_Image
| Name_Value =>
if Flags.Vhdl_Std > Vhdl_87 then
Res := Sem_Scalar_Type_Attribute (Attr);
else
Res := Sem_User_Attribute (Attr);
end if;
when Name_Pos
| Name_Val
| Name_Succ
| Name_Pred
| Name_Rightof
| Name_Leftof =>
Res := Sem_Scalar_Type_Attribute (Attr);
when Name_Length
| Name_Left
| Name_Right
| Name_High
| Name_Low
| Name_Range
| Name_Reverse_Range =>
Res := Sem_Array_Attribute_Name (Attr);
when Name_Ascending =>
if Flags.Vhdl_Std > Vhdl_87 then
Res := Sem_Array_Attribute_Name (Attr);
else
Res := Sem_User_Attribute (Attr);
end if;
when Name_Stable
| Name_Event
| Name_Last_Value
| Name_Delayed
| Name_Quiet
| Name_Transaction
| Name_Active
| Name_Last_Active
| Name_Last_Event =>
Res := Sem_Signal_Attribute (Attr);
when Name_Driving
| Name_Driving_Value =>
if Flags.Vhdl_Std > Vhdl_87 then
Res := Sem_Signal_Attribute (Attr);
else
Res := Sem_User_Attribute (Attr);
end if;
when Name_Simple_Name
| Name_Path_Name
| Name_Instance_Name =>
if Flags.Vhdl_Std > Vhdl_87 then
Res := Sem_Name_Attribute (Attr);
else
Res := Sem_User_Attribute (Attr);
end if;
when Name_Subtype =>
if Flags.Vhdl_Std >= Vhdl_08 then
Res := Sem_Subtype_Attribute (Attr);
else
Res := Sem_User_Attribute (Attr);
end if;
when Name_Element =>
if Flags.Vhdl_Std >= Vhdl_08 then
Res := Sem_Element_Attribute (Attr);
else
Res := Sem_User_Attribute (Attr);
end if;
when Name_Across
| Name_Through =>
if Flags.AMS_Vhdl then
Res := Sem_Nature_Type_Attribute (Attr);
else
Res := Sem_User_Attribute (Attr);
end if;
when Name_Reference =>
if Flags.AMS_Vhdl then
Res := Sem_Nature_Reference_Attribute (Attr);
else
Res := Sem_User_Attribute (Attr);
end if;
when Name_Above
| Name_Dot
| Name_Integ
| Name_Zoh
| Name_Ltf
| Name_Ztf =>
if Flags.AMS_Vhdl then
Res := Sem_Quantity_Attribute (Attr);
else
Res := Sem_User_Attribute (Attr);
end if;
when Name_Ramp =>
if Flags.AMS_Vhdl then
Res := Sem_Signal_Attribute (Attr);
else
Res := Sem_User_Attribute (Attr);
end if;
when Name_Slew =>
if Flags.AMS_Vhdl then
Res := Sem_Slew_Attribute (Attr);
else
Res := Sem_User_Attribute (Attr);
end if;
when others =>
Res := Sem_User_Attribute (Attr);
end case;
if Res = Null_Iir then
Error_Kind ("sem_attribute_name", Attr);
end if;
Set_Named_Entity (Attr, Res);
end Sem_Attribute_Name;
-- LRM93 6
procedure Sem_Name (Name : Iir; Keep_Alias : Boolean := False) is
begin
-- Exit now if NAME was already analyzed.
if Get_Named_Entity (Name) /= Null_Iir then
return;
end if;
case Get_Kind (Name) is
when Iir_Kind_Simple_Name
| Iir_Kind_Character_Literal
| Iir_Kind_Operator_Symbol =>
-- String_Literal may be a operator_symbol.
Sem_Simple_Name (Name, Keep_Alias, Soft => False);
when Iir_Kind_Selected_Name =>
Sem_Selected_Name (Name, Keep_Alias);
when Iir_Kind_Parenthesis_Name =>
Sem_Parenthesis_Name (Name);
when Iir_Kind_Selected_By_All_Name =>
Sem_Selected_By_All_Name (Name);
when Iir_Kind_Attribute_Name =>
Sem_Attribute_Name (Name);
when Iir_Kinds_External_Name =>
Sem_External_Name (Name);
when others =>
Error_Kind ("sem_name", Name);
end case;
end Sem_Name;
procedure Sem_Name_Soft (Name : Iir)
is
begin
-- Exit now if NAME was already analyzed.
if Get_Named_Entity (Name) /= Null_Iir then
return;
end if;
case Get_Kind (Name) is
when Iir_Kind_Simple_Name
| Iir_Kind_Operator_Symbol =>
-- String_Literal may be a operator_symbol.
Sem_Simple_Name (Name, False, Soft => True);
when Iir_Kind_Selected_Name =>
Sem_Selected_Name (Name, Keep_Alias => False, Soft => True);
when Iir_Kind_Parenthesis_Name =>
-- FIXME: SOFT!!
Sem_Parenthesis_Name (Name);
when others =>
Error_Kind ("sem_name_soft", Name);
end case;
end Sem_Name_Soft;
procedure Sem_Name_Clean_1 (Name : Iir)
is
Named_Entity : Iir;
Atype : Iir;
begin
if Name = Null_Iir then
return;
end if;
-- Clear and free overload lists of Named_entity and type.
Named_Entity := Get_Named_Entity (Name);
Set_Named_Entity (Name, Null_Iir);
if Named_Entity /= Null_Iir
and then Is_Overload_List (Named_Entity)
then
Free_Iir (Named_Entity);
end if;
Atype := Get_Type (Name);
Set_Type (Name, Null_Iir);
if Atype /= Null_Iir
and then Is_Overload_List (Atype)
then
Free_Iir (Atype);
end if;
end Sem_Name_Clean_1;
procedure Sem_Name_Clean (Name : Iir) is
begin
case Get_Kind (Name) is
when Iir_Kind_Simple_Name
| Iir_Kind_Operator_Symbol =>
Sem_Name_Clean_1 (Name);
when Iir_Kind_Parenthesis_Name
| Iir_Kind_Selected_Name =>
Sem_Name_Clean_1 (Get_Prefix (Name));
Sem_Name_Clean_1 (Name);
when others =>
Error_Kind ("sem_name_clean", Name);
end case;
end Sem_Name_Clean;
-- Remove procedure specification from LIST.
function Remove_Procedures_From_List (Expr : Iir) return Iir
is
El : Iir;
List : Iir_List;
It : List_Iterator;
New_List : Iir_List;
begin
if not Is_Overload_List (Expr) then
return Expr;
end if;
List := Get_Overload_List (Expr);
New_List := Create_Iir_List;
It := List_Iterate (List);
while Is_Valid (It) loop
El := Get_Element (It);
case Get_Kind (El) is
when Iir_Kind_Procedure_Declaration =>
null;
when Iir_Kind_Function_Declaration =>
if Maybe_Function_Call (El) then
Append_Element (New_List, El);
end if;
when others =>
Append_Element (New_List, El);
end case;
Next (It);
end loop;
case Get_Nbr_Elements (New_List) is
when 0 =>
Free_Iir (Expr);
Destroy_Iir_List (New_List);
return Null_Iir;
when 1 =>
Free_Iir (Expr);
El := Get_First_Element (New_List);
Destroy_Iir_List (New_List);
return El;
when others =>
Set_Overload_List (Expr, New_List);
Destroy_Iir_List (List);
return Expr;
end case;
end Remove_Procedures_From_List;
-- Return the fully analyzed name of NAME.
function Name_To_Analyzed_Name (Name : Iir) return Iir is
begin
case Get_Kind (Name) is
when Iir_Kind_Attribute_Name
| Iir_Kind_Parenthesis_Name =>
return Get_Named_Entity (Name);
when others =>
return Name;
end case;
end Name_To_Analyzed_Name;
-- Return True iff the current design unit is package body textio.
function Is_Current_Design_Unit_Textio_Body return Boolean
is
Unit : constant Iir := Sem.Get_Current_Design_Unit;
Cur_Lib : constant Iir := Get_Library_Unit (Unit);
begin
if Get_Kind (Cur_Lib) /= Iir_Kind_Package_Body then
return False;
end if;
if Get_Library (Get_Design_File (Unit)) /= Libraries.Std_Library then
return False;
end if;
return Get_Identifier (Cur_Lib) = Std_Names.Name_Textio;
end Is_Current_Design_Unit_Textio_Body;
-- Convert name EXPR to an expression (ie, create function call).
-- A_TYPE is the expected type of the expression.
-- Returns an Error node in case of error.
function Name_To_Expression (Name : Iir; A_Type : Iir) return Iir
is
Ret_Type : Iir;
Res_Type : Iir;
Expr : Iir;
Expr_List : Iir_List;
Expr_It : List_Iterator;
Res : Iir;
Res1 : Iir;
El : Iir;
begin
Expr := Get_Named_Entity (Name);
if Get_Kind (Expr) = Iir_Kind_Error then
return Expr;
end if;
if Check_Is_Expression (Expr, Name) = Null_Iir then
return Create_Error_Expr (Name, A_Type);
end if;
-- Note: EXPR may contain procedure names...
Expr := Remove_Procedures_From_List (Expr);
Set_Named_Entity (Name, Expr);
if Expr = Null_Iir then
Error_Msg_Sem (+Name, "%n cannot be used as expression", +Name);
-- Note: this creates a loop.
Res := Create_Error_Expr (Name, A_Type);
Set_Named_Entity (Name, Res);
return Res;
end if;
if not Is_Overload_List (Expr) then
Res := Finish_Sem_Name (Name);
pragma Assert (Res /= Null_Iir);
if A_Type /= Null_Iir then
Res_Type := Get_Type (Res);
if Res_Type = Null_Iir then
return Create_Error_Expr (Res, A_Type);
end if;
if Are_Basetypes_Compatible (Get_Base_Type (Res_Type), A_Type)
= Not_Compatible
then
Error_Not_Match (Res, A_Type);
return Create_Error_Expr (Res, A_Type);
end if;
-- Fall through.
end if;
else
-- EXPR is an overloaded name.
Expr_List := Get_Overload_List (Expr);
if A_Type /= Null_Iir then
-- Find the name returning A_TYPE.
Res := Null_Iir;
Expr_It := List_Iterate (Expr_List);
while Is_Valid (Expr_It) loop
El := Get_Element (Expr_It);
if Are_Basetypes_Compatible (Get_Base_Type (Get_Type (El)),
A_Type)
/= Not_Compatible
then
Add_Result (Res, El);
end if;
Next (Expr_It);
end loop;
if Res = Null_Iir then
-- Specific error message for a non-visible enumeration
-- literal.
if (Get_Kind (Get_Base_Type (A_Type))
= Iir_Kind_Enumeration_Type_Definition)
and then Kind_In (Name, Iir_Kind_Simple_Name,
Iir_Kind_Character_Literal)
then
Res := Find_Name_In_Flist (Get_Enumeration_Literal_List
(Get_Base_Type (A_Type)),
Get_Identifier (Name));
if Res /= Null_Iir then
Error_Msg_Sem
(+Name, "enumeration literal %i is not visible "
& "(add a use clause)", +Name);
-- Keep the literal as result.
end if;
end if;
end if;
if Res = Null_Iir then
Error_Not_Match (Name, A_Type);
return Create_Error_Expr (Name, A_Type);
elsif Is_Overload_List (Res) then
Res1 := Extract_Call_Without_Implicit_Conversion (Res);
if Res1 /= Null_Iir then
Free_Iir (Res);
Res := Res1;
else
Report_Start_Group;
Error_Overload (Name);
Disp_Overload_List (Get_Overload_List (Res), Name);
Report_End_Group;
Free_Iir (Res);
return Create_Error_Expr (Name, A_Type);
end if;
end if;
-- Free results
Sem_Name_Free_Result (Expr, Res);
Ret_Type := Get_Type (Name);
if Ret_Type /= Null_Iir then
pragma Assert (Is_Overload_List (Ret_Type));
Free_Overload_List (Ret_Type);
end if;
-- Fall through.
else
-- Create a list of type.
Ret_Type := Create_List_Of_Types (Expr_List);
if Ret_Type = Null_Iir or else not Is_Overload_List (Ret_Type) then
Res1 := Extract_Call_Without_Implicit_Conversion (Expr);
if Res1 /= Null_Iir then
-- Found it.
Res := Res1;
-- Fall through
else
-- There is either no types or one type for
-- several meanings.
Report_Start_Group;
Error_Overload (Name);
Disp_Overload_List (Expr_List, Name);
Report_End_Group;
--Free_Iir (Ret_Type);
return Create_Error_Expr (Name, A_Type);
end if;
else
Set_Type (Name, Ret_Type);
return Name;
end if;
end if;
Set_Named_Entity (Name, Res);
Res := Finish_Sem_Name (Name);
end if;
-- NAME has only one meaning, which is RES.
case Get_Kind (Res) is
when Iir_Kind_Simple_Name
| Iir_Kind_Character_Literal
| Iir_Kind_Selected_Name =>
Expr := Get_Named_Entity (Res);
if Get_Kind (Expr) = Iir_Kind_Function_Declaration then
return Function_Declaration_To_Call (Res);
else
Set_Type (Res, Get_Type (Expr));
Set_Expr_Staticness (Res, Get_Expr_Staticness (Expr));
--Set_Name_Staticness (Name, Get_Name_Staticness (Expr));
--Set_Base_Name (Name, Get_Base_Name (Expr));
-- For time physical literal (without a literal), check for
-- resolution and mark the literal used.
-- Don't check for textio body, as it uses all units and
-- user code shouldn't be affected by it.
if Get_Type (Expr) = Time_Type_Definition
and then not Is_Current_Design_Unit_Textio_Body
then
pragma Assert (Get_Kind (Expr) = Iir_Kind_Unit_Declaration);
Set_Use_Flag (Expr, True);
-- See Sem_Physical_Literal.
if Get_Value (Get_Physical_Literal (Expr)) = 0 then
Error_Msg_Sem
(+Res, "physical unit %i is below the "
& "time resolution", +Expr);
end if;
end if;
return Res;
end if;
when Iir_Kind_Function_Call
| Iir_Kind_Selected_Element
| Iir_Kind_Indexed_Name
| Iir_Kind_Slice_Name
| Iir_Kind_Type_Conversion
| Iir_Kind_Attribute_Name =>
return Eval_Expr_If_Static (Res);
when Iir_Kind_Dereference =>
-- Never static.
return Res;
when Iir_Kinds_Array_Attribute =>
-- FIXME: exclude range and reverse_range.
return Eval_Expr_If_Static (Res);
when Iir_Kinds_Signal_Attribute
| Iir_Kinds_Signal_Value_Attribute
| Iir_Kind_Above_Attribute
| Iir_Kind_Dot_Attribute
| Iir_Kind_Integ_Attribute
| Iir_Kind_Ramp_Attribute
| Iir_Kind_Zoh_Attribute
| Iir_Kind_Ltf_Attribute
| Iir_Kind_Ztf_Attribute
| Iir_Kind_Signal_Slew_Attribute
| Iir_Kind_Quantity_Slew_Attribute
| Iir_Kind_Quantity_Delayed_Attribute =>
-- Never static
return Res;
when Iir_Kinds_Type_Attribute
| Iir_Kinds_Scalar_Type_Attribute
| Iir_Kind_Image_Attribute
| Iir_Kind_Value_Attribute
| Iir_Kind_Simple_Name_Attribute
| Iir_Kind_Path_Name_Attribute
| Iir_Kind_Instance_Name_Attribute =>
return Eval_Expr_If_Static (Res);
when Iir_Kind_Parenthesis_Name
| Iir_Kind_Selected_By_All_Name =>
raise Internal_Error;
when others =>
Error_Kind ("name_to_expression", Res);
end case;
end Name_To_Expression;
function Name_To_Range (Name : Iir) return Iir
is
Expr : Iir;
begin
Expr := Get_Named_Entity (Name);
if Get_Kind (Expr) = Iir_Kind_Error then
return Error_Mark;
end if;
case Get_Kind (Expr) is
when Iir_Kind_Subtype_Declaration
| Iir_Kind_Type_Declaration =>
Expr := Sem_Type_Mark (Name);
Set_Expr_Staticness
(Expr, Get_Type_Staticness (Get_Type (Expr)));
return Expr;
when Iir_Kind_Range_Array_Attribute
| Iir_Kind_Reverse_Range_Array_Attribute =>
if Get_Parameter (Expr) = Null_Iir then
Finish_Sem_Array_Attribute (Name, Expr, Null_Iir);
end if;
if Get_Kind (Name) = Iir_Kind_Attribute_Name then
Free_Iir (Name);
else
Free_Iir (Get_Prefix (Name));
Free_Parenthesis_Name (Name, Expr);
end if;
return Expr;
when others =>
Error_Msg_Sem (+Name, "%n doesn't denote a range", +Name);
return Error_Mark;
end case;
end Name_To_Range;
function Name_To_Type_Definition (Name : Iir) return Iir
is
Atype : Iir;
begin
case Get_Kind (Name) is
when Iir_Kinds_Denoting_Name =>
-- Common correct case.
Atype := Get_Named_Entity (Name);
case Get_Kind (Atype) is
when Iir_Kind_Type_Declaration =>
return Get_Type_Definition (Atype);
when Iir_Kind_Subtype_Declaration
| Iir_Kind_Interface_Type_Declaration =>
return Get_Type (Atype);
when Iir_Kind_Error =>
return Atype;
when others =>
Report_Start_Group;
Error_Msg_Sem
(+Name, "a type mark must denote a type or a subtype");
Error_Msg_Sem
(+Name, "(type mark denotes %n)", +Atype);
Report_End_Group;
return Create_Error_Type (Atype);
end case;
when Iir_Kind_Subtype_Attribute
| Iir_Kind_Element_Attribute
| Iir_Kind_Base_Attribute
| Iir_Kind_Across_Attribute
| Iir_Kind_Through_Attribute =>
return Get_Type (Name);
when Iir_Kinds_Expression_Attribute =>
Error_Msg_Sem (+Name, "%n is not a valid type mark", +Name);
return Create_Error_Type (Name);
when others =>
if not Is_Error (Name) then
Error_Msg_Sem
(+Name, "a type mark must be a simple or expanded name");
end if;
return Create_Error_Type (Name);
end case;
end Name_To_Type_Definition;
function Sem_Denoting_Name (Name: Iir) return Iir
is
Res: Iir;
begin
pragma Assert (Get_Kind (Name) in Iir_Kinds_Denoting_Name);
Sem_Name (Name);
Res := Get_Named_Entity (Name);
case Get_Kind (Res) is
when Iir_Kind_Error =>
-- A message must have been displayed.
return Name;
when Iir_Kind_Overload_List =>
Error_Overload (Name);
Set_Named_Entity (Name, Create_Error_Name (Name));
return Name;
when Iir_Kinds_Concurrent_Statement
| Iir_Kinds_Sequential_Statement
| Iir_Kind_Type_Declaration
| Iir_Kind_Subtype_Declaration
| Iir_Kind_Nature_Declaration
| Iir_Kind_Subnature_Declaration
| Iir_Kind_Enumeration_Literal
| Iir_Kind_Unit_Declaration
| Iir_Kind_Group_Template_Declaration
| Iir_Kind_Group_Declaration
| Iir_Kind_Attribute_Declaration
| Iir_Kinds_Object_Declaration
| Iir_Kind_Terminal_Declaration
| Iir_Kind_Entity_Declaration
| Iir_Kind_Configuration_Declaration
| Iir_Kind_Package_Declaration
| Iir_Kind_Context_Declaration
| Iir_Kind_Package_Instantiation_Declaration
| Iir_Kind_Interface_Package_Declaration
| Iir_Kind_Library_Declaration
| Iir_Kinds_Subprogram_Declaration
| Iir_Kind_Component_Declaration =>
Res := Finish_Sem_Name (Name, Res);
pragma Assert (Get_Kind (Res) in Iir_Kinds_Denoting_Name);
return Res;
when Iir_Kind_Selected_Element =>
-- An error (to be diagnosticed by the caller).
return Name;
when others =>
Error_Kind ("sem_denoting_name", Res);
end case;
end Sem_Denoting_Name;
procedure Sem_External_Name (Name : Iir)
is
Atype : Iir;
begin
pragma Assert (Get_Type (Name) = Null_Iir);
Atype := Get_Subtype_Indication (Name);
Atype := Sem_Types.Sem_Subtype_Indication (Atype);
Set_Subtype_Indication (Name, Atype);
Atype := Get_Type_Of_Subtype_Indication (Atype);
if Atype = Null_Iir then
Atype := Create_Error_Type (Null_Iir);
end if;
Set_Type (Name, Atype);
-- LRM08 8.1 Names
-- A name is said to be a static name if and only if one of the
-- following condition holds:
-- - The name is an external name.
Set_Name_Staticness (Name, Globally);
Set_Expr_Staticness (Name, None);
-- Consider the node as analyzed.
Set_Named_Entity (Name, Name);
end Sem_External_Name;
function Sem_Terminal_Name (Name : Iir) return Iir
is
Res : Iir;
begin
Sem_Name (Name);
Res := Get_Named_Entity (Name);
case Get_Kind (Res) is
when Iir_Kind_Error =>
-- A message must have been displayed.
return Name;
when Iir_Kind_Overload_List =>
Error_Overload (Res);
Set_Named_Entity (Name, Create_Error_Name (Name));
return Name;
when Iir_Kind_Terminal_Declaration
| Iir_Kind_Interface_Terminal_Declaration
| Iir_Kind_Nature_Reference_Attribute =>
Res := Finish_Sem_Name (Name, Res);
return Res;
when others =>
Error_Class_Match (Name, "terminal");
Set_Named_Entity (Name, Create_Error_Name (Name));
return Name;
end case;
end Sem_Terminal_Name;
procedure Error_Class_Match (Name : Iir; Class_Name : String)
is
Ent : constant Iir := Get_Named_Entity (Name);
begin
if Is_Error (Ent) then
Error_Msg_Sem (+Name, Class_Name & " name expected");
else
Error_Msg_Sem (+Name, Class_Name & " name expected, found %n",
+Get_Named_Entity (Name));
end if;
end Error_Class_Match;
end Vhdl.Sem_Names;
|