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
|
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* 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, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributor(s): Blender Foundation (2008).
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file blender/makesrna/intern/makesrna.c
* \ingroup RNA
*/
#include <float.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "MEM_guardedalloc.h"
#include "BLI_utildefines.h"
#include "RNA_define.h"
#include "RNA_types.h"
#include "rna_internal.h"
#ifdef _WIN32
# ifndef snprintf
# define snprintf _snprintf
# endif
#endif
/**
* Variable to control debug output of makesrna.
* debugSRNA:
* - 0 = no output, except errors
* - 1 = detail actions
*/
static int debugSRNA = 0;
/* stub for BLI_abort() */
#ifndef NDEBUG
void BLI_system_backtrace(FILE *fp)
{
(void)fp;
}
#endif
/* Replace if different */
#define TMP_EXT ".tmp"
/* copied from BLI_file_older */
#include <sys/stat.h>
static int file_older(const char *file1, const char *file2)
{
struct stat st1, st2;
if (debugSRNA > 0) {
printf("compare: %s %s\n", file1, file2);
}
if (stat(file1, &st1)) return 0;
if (stat(file2, &st2)) return 0;
return (st1.st_mtime < st2.st_mtime);
}
static const char *makesrna_path = NULL;
/* forward declarations */
static void rna_generate_static_parameter_prototypes(FILE *f, StructRNA *srna, FunctionDefRNA *dfunc,
const char *name_override, int close_prototype);
/* helpers */
#define WRITE_COMMA \
{ \
if (!first) \
fprintf(f, ", "); \
first = 0; \
} (void)0
#define WRITE_PARAM(param) \
{ \
WRITE_COMMA; \
fprintf(f, param); \
} (void)0
static int replace_if_different(const char *tmpfile, const char *dep_files[])
{
/* return 0; *//* use for testing had edited rna */
#define REN_IF_DIFF \
{ \
FILE *file_test = fopen(orgfile, "rb"); \
if (file_test) { \
fclose(file_test); \
if (fp_org) fclose(fp_org); \
if (fp_new) fclose(fp_new); \
if (remove(orgfile) != 0) { \
fprintf(stderr, "%s:%d, Remove Error (%s): \"%s\"\n", \
__FILE__, __LINE__, strerror(errno), orgfile); \
return -1; \
} \
} \
} \
if (rename(tmpfile, orgfile) != 0) { \
fprintf(stderr, "%s:%d, Rename Error (%s): \"%s\" -> \"%s\"\n", \
__FILE__, __LINE__, strerror(errno), tmpfile, orgfile); \
return -1; \
} \
remove(tmpfile); \
return 1 \
/* end REN_IF_DIFF */
FILE *fp_new = NULL, *fp_org = NULL;
int len_new, len_org;
char *arr_new, *arr_org;
int cmp;
char orgfile[4096];
strcpy(orgfile, tmpfile);
orgfile[strlen(orgfile) - strlen(TMP_EXT)] = '\0'; /* strip '.tmp' */
fp_org = fopen(orgfile, "rb");
if (fp_org == NULL) {
REN_IF_DIFF;
}
/* XXX, trick to work around dependency problem
* assumes dep_files is in the same dir as makesrna.c, which is true for now. */
if (1) {
/* first check if makesrna.c is newer then generated files
* for development on makesrna.c you may want to disable this */
if (file_older(orgfile, __FILE__)) {
REN_IF_DIFF;
}
if (file_older(orgfile, makesrna_path)) {
REN_IF_DIFF;
}
/* now check if any files we depend on are newer then any generated files */
if (dep_files) {
int pass;
for (pass = 0; dep_files[pass]; pass++) {
char from_path[4096] = __FILE__;
char *p1, *p2;
/* dir only */
p1 = strrchr(from_path, '/');
p2 = strrchr(from_path, '\\');
strcpy((p1 > p2 ? p1 : p2) + 1, dep_files[pass]);
/* account for build deps, if makesrna.c (this file) is newer */
if (file_older(orgfile, from_path)) {
REN_IF_DIFF;
}
}
}
}
/* XXX end dep trick */
fp_new = fopen(tmpfile, "rb");
if (fp_new == NULL) {
/* shouldn't happen, just to be safe */
fprintf(stderr, "%s:%d, open error: \"%s\"\n", __FILE__, __LINE__, tmpfile);
fclose(fp_org);
return -1;
}
fseek(fp_new, 0L, SEEK_END); len_new = ftell(fp_new); fseek(fp_new, 0L, SEEK_SET);
fseek(fp_org, 0L, SEEK_END); len_org = ftell(fp_org); fseek(fp_org, 0L, SEEK_SET);
if (len_new != len_org) {
fclose(fp_new); fp_new = NULL;
fclose(fp_org); fp_org = NULL;
REN_IF_DIFF;
}
/* now compare the files... */
arr_new = MEM_mallocN(sizeof(char) * len_new, "rna_cmp_file_new");
arr_org = MEM_mallocN(sizeof(char) * len_org, "rna_cmp_file_org");
if (fread(arr_new, sizeof(char), len_new, fp_new) != len_new)
fprintf(stderr, "%s:%d, error reading file %s for comparison.\n", __FILE__, __LINE__, tmpfile);
if (fread(arr_org, sizeof(char), len_org, fp_org) != len_org)
fprintf(stderr, "%s:%d, error reading file %s for comparison.\n", __FILE__, __LINE__, orgfile);
fclose(fp_new); fp_new = NULL;
fclose(fp_org); fp_org = NULL;
cmp = memcmp(arr_new, arr_org, len_new);
MEM_freeN(arr_new);
MEM_freeN(arr_org);
if (cmp) {
REN_IF_DIFF;
}
else {
remove(tmpfile);
return 0;
}
#undef REN_IF_DIFF
}
/* Helper to solve keyword problems with C/C++ */
static const char *rna_safe_id(const char *id)
{
if (STREQ(id, "default"))
return "default_value";
else if (STREQ(id, "operator"))
return "operator_value";
else if (STREQ(id, "new"))
return "create";
else if (STREQ(id, "co_return")) {
/* MSVC2015, C++ uses for coroutines */
return "coord_return";
}
return id;
}
/* Sorting */
static int cmp_struct(const void *a, const void *b)
{
const StructRNA *structa = *(const StructRNA **)a;
const StructRNA *structb = *(const StructRNA **)b;
return strcmp(structa->identifier, structb->identifier);
}
static int cmp_property(const void *a, const void *b)
{
const PropertyRNA *propa = *(const PropertyRNA **)a;
const PropertyRNA *propb = *(const PropertyRNA **)b;
if (STREQ(propa->identifier, "rna_type")) return -1;
else if (STREQ(propb->identifier, "rna_type")) return 1;
if (STREQ(propa->identifier, "name")) return -1;
else if (STREQ(propb->identifier, "name")) return 1;
return strcmp(propa->name, propb->name);
}
static int cmp_def_struct(const void *a, const void *b)
{
const StructDefRNA *dsa = *(const StructDefRNA **)a;
const StructDefRNA *dsb = *(const StructDefRNA **)b;
return cmp_struct(&dsa->srna, &dsb->srna);
}
static int cmp_def_property(const void *a, const void *b)
{
const PropertyDefRNA *dpa = *(const PropertyDefRNA **)a;
const PropertyDefRNA *dpb = *(const PropertyDefRNA **)b;
return cmp_property(&dpa->prop, &dpb->prop);
}
static void rna_sortlist(ListBase *listbase, int (*cmp)(const void *, const void *))
{
Link *link;
void **array;
int a, size;
if (listbase->first == listbase->last)
return;
for (size = 0, link = listbase->first; link; link = link->next)
size++;
array = MEM_mallocN(sizeof(void *) * size, "rna_sortlist");
for (a = 0, link = listbase->first; link; link = link->next, a++)
array[a] = link;
qsort(array, size, sizeof(void *), cmp);
listbase->first = listbase->last = NULL;
for (a = 0; a < size; a++) {
link = array[a];
link->next = link->prev = NULL;
rna_addtail(listbase, link);
}
MEM_freeN(array);
}
/* Preprocessing */
static void rna_print_c_string(FILE *f, const char *str)
{
static const char *escape[] = {"\''", "\"\"", "\??", "\\\\", "\aa", "\bb", "\ff", "\nn", "\rr", "\tt", "\vv", NULL};
int i, j;
if (!str) {
fprintf(f, "NULL");
return;
}
fprintf(f, "\"");
for (i = 0; str[i]; i++) {
for (j = 0; escape[j]; j++)
if (str[i] == escape[j][0])
break;
if (escape[j]) fprintf(f, "\\%c", escape[j][1]);
else fprintf(f, "%c", str[i]);
}
fprintf(f, "\"");
}
static void rna_print_data_get(FILE *f, PropertyDefRNA *dp)
{
if (dp->dnastructfromname && dp->dnastructfromprop)
fprintf(f, " %s *data = (%s *)(((%s *)ptr->data)->%s);\n", dp->dnastructname, dp->dnastructname,
dp->dnastructfromname, dp->dnastructfromprop);
else
fprintf(f, " %s *data = (%s *)(ptr->data);\n", dp->dnastructname, dp->dnastructname);
}
static void rna_print_id_get(FILE *f, PropertyDefRNA *UNUSED(dp))
{
fprintf(f, " ID *id = ptr->id.data;\n");
}
static void rna_construct_function_name(char *buffer, int size, const char *structname, const char *propname, const char *type)
{
snprintf(buffer, size, "%s_%s_%s", structname, propname, type);
}
static void rna_construct_wrapper_function_name(char *buffer, int size, const char *structname, const char *propname, const char *type)
{
if (type == NULL || type[0] == '\0')
snprintf(buffer, size, "%s_%s", structname, propname);
else
snprintf(buffer, size, "%s_%s_%s", structname, propname, type);
}
static char *rna_alloc_function_name(const char *structname, const char *propname, const char *type)
{
AllocDefRNA *alloc;
char buffer[2048];
char *result;
rna_construct_function_name(buffer, sizeof(buffer), structname, propname, type);
result = MEM_callocN(sizeof(char) * strlen(buffer) + 1, "rna_alloc_function_name");
strcpy(result, buffer);
alloc = MEM_callocN(sizeof(AllocDefRNA), "AllocDefRNA");
alloc->mem = result;
rna_addtail(&DefRNA.allocs, alloc);
return result;
}
static StructRNA *rna_find_struct(const char *identifier)
{
StructDefRNA *ds;
for (ds = DefRNA.structs.first; ds; ds = ds->cont.next)
if (STREQ(ds->srna->identifier, identifier))
return ds->srna;
return NULL;
}
static const char *rna_find_type(const char *type)
{
StructDefRNA *ds;
for (ds = DefRNA.structs.first; ds; ds = ds->cont.next)
if (ds->dnaname && STREQ(ds->dnaname, type))
return ds->srna->identifier;
return NULL;
}
static const char *rna_find_dna_type(const char *type)
{
StructDefRNA *ds;
for (ds = DefRNA.structs.first; ds; ds = ds->cont.next)
if (STREQ(ds->srna->identifier, type))
return ds->dnaname;
return NULL;
}
static const char *rna_type_type_name(PropertyRNA *prop)
{
switch (prop->type) {
case PROP_BOOLEAN:
return "bool";
case PROP_INT:
case PROP_ENUM:
return "int";
case PROP_FLOAT:
return "float";
case PROP_STRING:
if (prop->flag & PROP_THICK_WRAP) {
return "char *";
}
else {
return "const char *";
}
default:
return NULL;
}
}
static const char *rna_type_type(PropertyRNA *prop)
{
const char *type;
type = rna_type_type_name(prop);
if (type)
return type;
return "PointerRNA";
}
static const char *rna_type_struct(PropertyRNA *prop)
{
const char *type;
type = rna_type_type_name(prop);
if (type)
return "";
return "struct ";
}
static const char *rna_parameter_type_name(PropertyRNA *parm)
{
const char *type;
type = rna_type_type_name(parm);
if (type)
return type;
switch (parm->type) {
case PROP_POINTER:
{
PointerPropertyRNA *pparm = (PointerPropertyRNA *)parm;
if (parm->flag_parameter & PARM_RNAPTR)
return "PointerRNA";
else
return rna_find_dna_type((const char *)pparm->type);
}
case PROP_COLLECTION:
{
return "CollectionListBase";
}
default:
return "<error, no type specified>";
}
}
static int rna_enum_bitmask(PropertyRNA *prop)
{
EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
int a, mask = 0;
if (eprop->item) {
for (a = 0; a < eprop->totitem; a++)
if (eprop->item[a].identifier[0])
mask |= eprop->item[a].value;
}
return mask;
}
static int rna_color_quantize(PropertyRNA *prop, PropertyDefRNA *dp)
{
return ( (prop->type == PROP_FLOAT) &&
(prop->subtype == PROP_COLOR || prop->subtype == PROP_COLOR_GAMMA) &&
(IS_DNATYPE_FLOAT_COMPAT(dp->dnatype) == 0) );
}
static const char *rna_function_string(void *func)
{
return (func) ? (const char *)func : "NULL";
}
static void rna_float_print(FILE *f, float num)
{
if (num == -FLT_MAX) fprintf(f, "-FLT_MAX");
else if (num == FLT_MAX) fprintf(f, "FLT_MAX");
else if ((ABS(num) < INT64_MAX) && ((int64_t)num == num)) fprintf(f, "%.1ff", num);
else fprintf(f, "%.10ff", num);
}
static void rna_int_print(FILE *f, int num)
{
if (num == INT_MIN) fprintf(f, "INT_MIN");
else if (num == INT_MAX) fprintf(f, "INT_MAX");
else fprintf(f, "%d", num);
}
static char *rna_def_property_get_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp,
const char *manualfunc)
{
char *func;
if (prop->flag & PROP_IDPROPERTY && manualfunc == NULL)
return NULL;
if (!manualfunc) {
if (!dp->dnastructname || !dp->dnaname) {
fprintf(stderr, "%s (0): %s.%s has no valid dna info.\n",
__func__, srna->identifier, prop->identifier);
DefRNA.error = 1;
return NULL;
}
/* typecheck, */
if (dp->dnatype && *dp->dnatype) {
if (prop->type == PROP_FLOAT) {
if (IS_DNATYPE_FLOAT_COMPAT(dp->dnatype) == 0) {
if (prop->subtype != PROP_COLOR_GAMMA) { /* colors are an exception. these get translated */
fprintf(stderr, "%s (1): %s.%s is a '%s' but wrapped as type '%s'.\n",
__func__, srna->identifier, prop->identifier, dp->dnatype,
RNA_property_typename(prop->type));
DefRNA.error = 1;
return NULL;
}
}
}
else if (prop->type == PROP_INT || prop->type == PROP_BOOLEAN || prop->type == PROP_ENUM) {
if (IS_DNATYPE_INT_COMPAT(dp->dnatype) == 0) {
fprintf(stderr, "%s (2): %s.%s is a '%s' but wrapped as type '%s'.\n",
__func__, srna->identifier, prop->identifier, dp->dnatype,
RNA_property_typename(prop->type));
DefRNA.error = 1;
return NULL;
}
}
}
}
func = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "get");
switch (prop->type) {
case PROP_STRING:
{
StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
fprintf(f, "void %s(PointerRNA *ptr, char *value)\n", func);
fprintf(f, "{\n");
if (manualfunc) {
fprintf(f, " %s(ptr, value);\n", manualfunc);
}
else {
const PropertySubType subtype = prop->subtype;
const char *string_copy_func = (subtype == PROP_FILEPATH ||
subtype == PROP_DIRPATH ||
subtype == PROP_FILENAME ||
subtype == PROP_BYTESTRING) ?
"BLI_strncpy" : "BLI_strncpy_utf8";
rna_print_data_get(f, dp);
if (!(prop->flag & PROP_NEVER_NULL)) {
fprintf(f, " if (data->%s == NULL) {\n", dp->dnaname);
fprintf(f, " *value = '\\0';\n");
fprintf(f, " return;\n");
fprintf(f, " }\n");
}
if (sprop->maxlength)
fprintf(f, " %s(value, data->%s, %d);\n", string_copy_func, dp->dnaname, sprop->maxlength);
else
fprintf(f, " %s(value, data->%s, sizeof(data->%s));\n", string_copy_func,
dp->dnaname, dp->dnaname);
}
fprintf(f, "}\n\n");
break;
}
case PROP_POINTER:
{
fprintf(f, "PointerRNA %s(PointerRNA *ptr)\n", func);
fprintf(f, "{\n");
if (manualfunc) {
fprintf(f, " return %s(ptr);\n", manualfunc);
}
else {
PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop;
rna_print_data_get(f, dp);
if (dp->dnapointerlevel == 0)
fprintf(f, " return rna_pointer_inherit_refine(ptr, &RNA_%s, &data->%s);\n",
(const char *)pprop->type, dp->dnaname);
else
fprintf(f, " return rna_pointer_inherit_refine(ptr, &RNA_%s, data->%s);\n",
(const char *)pprop->type, dp->dnaname);
}
fprintf(f, "}\n\n");
break;
}
case PROP_COLLECTION:
{
CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop;
fprintf(f, "static PointerRNA %s(CollectionPropertyIterator *iter)\n", func);
fprintf(f, "{\n");
if (manualfunc) {
if (STREQ(manualfunc, "rna_iterator_listbase_get") ||
STREQ(manualfunc, "rna_iterator_array_get") ||
STREQ(manualfunc, "rna_iterator_array_dereference_get"))
{
fprintf(f, " return rna_pointer_inherit_refine(&iter->parent, &RNA_%s, %s(iter));\n",
(cprop->item_type) ? (const char *)cprop->item_type : "UnknownType", manualfunc);
}
else {
fprintf(f, " return %s(iter);\n", manualfunc);
}
}
fprintf(f, "}\n\n");
break;
}
default:
if (prop->arraydimension) {
if (prop->flag & PROP_DYNAMIC)
fprintf(f, "void %s(PointerRNA *ptr, %s values[])\n", func, rna_type_type(prop));
else
fprintf(f, "void %s(PointerRNA *ptr, %s values[%u])\n", func, rna_type_type(prop),
prop->totarraylength);
fprintf(f, "{\n");
if (manualfunc) {
fprintf(f, " %s(ptr, values);\n", manualfunc);
}
else {
rna_print_data_get(f, dp);
if (prop->flag & PROP_DYNAMIC) {
char *lenfunc = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier),
"get_length");
fprintf(f, " unsigned int arraylen[RNA_MAX_ARRAY_DIMENSION];\n");
fprintf(f, " unsigned int i;\n");
fprintf(f, " unsigned int len = %s(ptr, arraylen);\n\n", lenfunc);
fprintf(f, " for (i = 0; i < len; i++) {\n");
MEM_freeN(lenfunc);
}
else {
fprintf(f, " unsigned int i;\n\n");
fprintf(f, " for (i = 0; i < %u; i++) {\n", prop->totarraylength);
}
if (dp->dnaarraylength == 1) {
if (prop->type == PROP_BOOLEAN && dp->booleanbit) {
fprintf(f, " values[i] = %s((data->%s & (%du << i)) != 0);\n",
(dp->booleannegative) ? "!" : "", dp->dnaname, dp->booleanbit);
}
else {
fprintf(f, " values[i] = (%s)%s((&data->%s)[i]);\n",
rna_type_type(prop), (dp->booleannegative) ? "!" : "", dp->dnaname);
}
}
else {
if (prop->type == PROP_BOOLEAN && dp->booleanbit) {
fprintf(f, " values[i] = %s((data->%s[i] & ", (dp->booleannegative) ? "!" : "",
dp->dnaname);
rna_int_print(f, dp->booleanbit);
fprintf(f, ") != 0);\n");
}
else if (rna_color_quantize(prop, dp)) {
fprintf(f, " values[i] = (%s)(data->%s[i] * (1.0f / 255.0f));\n",
rna_type_type(prop), dp->dnaname);
}
else if (dp->dnatype) {
fprintf(f, " values[i] = (%s)%s(((%s *)data->%s)[i]);\n",
rna_type_type(prop), (dp->booleannegative) ? "!" : "", dp->dnatype, dp->dnaname);
}
else {
fprintf(f, " values[i] = (%s)%s((data->%s)[i]);\n",
rna_type_type(prop), (dp->booleannegative) ? "!" : "", dp->dnaname);
}
}
fprintf(f, " }\n");
}
fprintf(f, "}\n\n");
}
else {
fprintf(f, "%s %s(PointerRNA *ptr)\n", rna_type_type(prop), func);
fprintf(f, "{\n");
if (manualfunc) {
fprintf(f, " return %s(ptr);\n", manualfunc);
}
else {
rna_print_data_get(f, dp);
if (prop->type == PROP_BOOLEAN && dp->booleanbit) {
fprintf(f, " return %s(((data->%s) & ", (dp->booleannegative) ? "!" : "", dp->dnaname);
rna_int_print(f, dp->booleanbit);
fprintf(f, ") != 0);\n");
}
else if (prop->type == PROP_ENUM && dp->enumbitflags) {
fprintf(f, " return ((data->%s) & ", dp->dnaname);
rna_int_print(f, rna_enum_bitmask(prop));
fprintf(f, ");\n");
}
else
fprintf(f, " return (%s)%s(data->%s);\n", rna_type_type(prop),
(dp->booleannegative) ? "!" : "", dp->dnaname);
}
fprintf(f, "}\n\n");
}
break;
}
return func;
}
/* defined min/max variables to be used by rna_clamp_value() */
static void rna_clamp_value_range(FILE *f, PropertyRNA *prop)
{
if (prop->type == PROP_FLOAT) {
FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
if (fprop->range) {
fprintf(f,
" float prop_clamp_min = -FLT_MAX, prop_clamp_max = FLT_MAX, prop_soft_min, prop_soft_max;\n");
fprintf(f, " %s(ptr, &prop_clamp_min, &prop_clamp_max, &prop_soft_min, &prop_soft_max);\n",
rna_function_string(fprop->range));
}
}
else if (prop->type == PROP_INT) {
IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
if (iprop->range) {
fprintf(f, " int prop_clamp_min = INT_MIN, prop_clamp_max = INT_MAX, prop_soft_min, prop_soft_max;\n");
fprintf(f, " %s(ptr, &prop_clamp_min, &prop_clamp_max, &prop_soft_min, &prop_soft_max);\n",
rna_function_string(iprop->range));
}
}
}
#ifdef USE_RNA_RANGE_CHECK
static void rna_clamp_value_range_check(
FILE *f, PropertyRNA *prop,
const char *dnaname_prefix, const char *dnaname)
{
if (prop->type == PROP_INT) {
IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
fprintf(f,
" { BLI_STATIC_ASSERT("
"(TYPEOF_MAX(%s%s) >= %d) && "
"(TYPEOF_MIN(%s%s) <= %d), "
"\"invalid limits\"); }\n",
dnaname_prefix, dnaname, iprop->hardmax,
dnaname_prefix, dnaname, iprop->hardmin);
}
}
#endif /* USE_RNA_RANGE_CHECK */
static void rna_clamp_value(FILE *f, PropertyRNA *prop, int array)
{
if (prop->type == PROP_INT) {
IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
if (iprop->hardmin != INT_MIN || iprop->hardmax != INT_MAX || iprop->range) {
if (array) fprintf(f, "CLAMPIS(values[i], ");
else fprintf(f, "CLAMPIS(value, ");
if (iprop->range) {
fprintf(f, "prop_clamp_min, prop_clamp_max);");
}
else {
rna_int_print(f, iprop->hardmin); fprintf(f, ", ");
rna_int_print(f, iprop->hardmax); fprintf(f, ");\n");
}
return;
}
}
else if (prop->type == PROP_FLOAT) {
FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
if (fprop->hardmin != -FLT_MAX || fprop->hardmax != FLT_MAX || fprop->range) {
if (array) fprintf(f, "CLAMPIS(values[i], ");
else fprintf(f, "CLAMPIS(value, ");
if (fprop->range) {
fprintf(f, "prop_clamp_min, prop_clamp_max);");
}
else {
rna_float_print(f, fprop->hardmin); fprintf(f, ", ");
rna_float_print(f, fprop->hardmax); fprintf(f, ");\n");
}
return;
}
}
if (array)
fprintf(f, "values[i];\n");
else
fprintf(f, "value;\n");
}
static char *rna_def_property_set_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp,
const char *manualfunc)
{
char *func;
if (!(prop->flag & PROP_EDITABLE))
return NULL;
if (prop->flag & PROP_IDPROPERTY && manualfunc == NULL)
return NULL;
if (!manualfunc) {
if (!dp->dnastructname || !dp->dnaname) {
if (prop->flag & PROP_EDITABLE) {
fprintf(stderr, "%s: %s.%s has no valid dna info.\n",
__func__, srna->identifier, prop->identifier);
DefRNA.error = 1;
}
return NULL;
}
}
func = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "set");
switch (prop->type) {
case PROP_STRING:
{
StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
fprintf(f, "void %s(PointerRNA *ptr, const char *value)\n", func);
fprintf(f, "{\n");
if (manualfunc) {
fprintf(f, " %s(ptr, value);\n", manualfunc);
}
else {
const PropertySubType subtype = prop->subtype;
const char *string_copy_func = (subtype == PROP_FILEPATH ||
subtype == PROP_DIRPATH ||
subtype == PROP_FILENAME ||
subtype == PROP_BYTESTRING) ?
"BLI_strncpy" : "BLI_strncpy_utf8";
rna_print_data_get(f, dp);
if (!(prop->flag & PROP_NEVER_NULL)) {
fprintf(f, " if (data->%s == NULL) {\n", dp->dnaname);
fprintf(f, " return;\n");
fprintf(f, " }\n");
}
if (sprop->maxlength)
fprintf(f, " %s(data->%s, value, %d);\n", string_copy_func, dp->dnaname, sprop->maxlength);
else
fprintf(f, " %s(data->%s, value, sizeof(data->%s));\n", string_copy_func,
dp->dnaname, dp->dnaname);
}
fprintf(f, "}\n\n");
break;
}
case PROP_POINTER:
{
fprintf(f, "void %s(PointerRNA *ptr, PointerRNA value)\n", func);
fprintf(f, "{\n");
if (manualfunc) {
fprintf(f, " %s(ptr, value);\n", manualfunc);
}
else {
rna_print_data_get(f, dp);
if (prop->flag & PROP_ID_SELF_CHECK) {
rna_print_id_get(f, dp);
fprintf(f, " if (id == value.data) return;\n\n");
}
if (prop->flag & PROP_ID_REFCOUNT) {
fprintf(f, "\n if (data->%s)\n", dp->dnaname);
fprintf(f, " id_us_min((ID *)data->%s);\n", dp->dnaname);
fprintf(f, " if (value.data)\n");
fprintf(f, " id_us_plus((ID *)value.data);\n\n");
}
else {
PointerPropertyRNA *pprop = (PointerPropertyRNA *)dp->prop;
StructRNA *type = rna_find_struct((const char *)pprop->type);
if (type && (type->flag & STRUCT_ID)) {
fprintf(f, " if (value.data)\n");
fprintf(f, " id_lib_extern((ID *)value.data);\n\n");
}
}
fprintf(f, " data->%s = value.data;\n", dp->dnaname);
}
fprintf(f, "}\n\n");
break;
}
default:
if (prop->arraydimension) {
if (prop->flag & PROP_DYNAMIC)
fprintf(f, "void %s(PointerRNA *ptr, const %s values[])\n", func, rna_type_type(prop));
else
fprintf(f, "void %s(PointerRNA *ptr, const %s values[%u])\n", func,
rna_type_type(prop), prop->totarraylength);
fprintf(f, "{\n");
if (manualfunc) {
fprintf(f, " %s(ptr, values);\n", manualfunc);
}
else {
rna_print_data_get(f, dp);
if (prop->flag & PROP_DYNAMIC) {
char *lenfunc = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier),
"set_length");
fprintf(f, " unsigned int i, arraylen[RNA_MAX_ARRAY_DIMENSION];\n");
fprintf(f, " unsigned int len = %s(ptr, arraylen);\n\n", lenfunc);
rna_clamp_value_range(f, prop);
fprintf(f, " for (i = 0; i < len; i++) {\n");
MEM_freeN(lenfunc);
}
else {
fprintf(f, " unsigned int i;\n\n");
rna_clamp_value_range(f, prop);
fprintf(f, " for (i = 0; i < %u; i++) {\n", prop->totarraylength);
}
if (dp->dnaarraylength == 1) {
if (prop->type == PROP_BOOLEAN && dp->booleanbit) {
fprintf(f, " if (%svalues[i]) data->%s |= (%du << i);\n",
(dp->booleannegative) ? "!" : "", dp->dnaname, dp->booleanbit);
fprintf(f, " else data->%s &= ~(%du << i);\n", dp->dnaname, dp->booleanbit);
}
else {
fprintf(f, " (&data->%s)[i] = %s", dp->dnaname, (dp->booleannegative) ? "!" : "");
rna_clamp_value(f, prop, 1);
}
}
else {
if (prop->type == PROP_BOOLEAN && dp->booleanbit) {
fprintf(f, " if (%svalues[i]) data->%s[i] |= ", (dp->booleannegative) ? "!" : "",
dp->dnaname);
rna_int_print(f, dp->booleanbit);
fprintf(f, ";\n");
fprintf(f, " else data->%s[i] &= ~", dp->dnaname);
rna_int_print(f, dp->booleanbit);
fprintf(f, ";\n");
}
else if (rna_color_quantize(prop, dp)) {
fprintf(f, " data->%s[i] = unit_float_to_uchar_clamp(values[i]);\n", dp->dnaname);
}
else {
if (dp->dnatype)
fprintf(f, " ((%s *)data->%s)[i] = %s", dp->dnatype, dp->dnaname,
(dp->booleannegative) ? "!" : "");
else
fprintf(f, " (data->%s)[i] = %s", dp->dnaname, (dp->booleannegative) ? "!" : "");
rna_clamp_value(f, prop, 1);
}
}
fprintf(f, " }\n");
}
#ifdef USE_RNA_RANGE_CHECK
if (dp->dnaname && manualfunc == NULL) {
if (dp->dnaarraylength == 1) {
rna_clamp_value_range_check(f, prop, "data->", dp->dnaname);
}
else {
rna_clamp_value_range_check(f, prop, "*data->", dp->dnaname);
}
}
#endif
fprintf(f, "}\n\n");
}
else {
fprintf(f, "void %s(PointerRNA *ptr, %s value)\n", func, rna_type_type(prop));
fprintf(f, "{\n");
if (manualfunc) {
fprintf(f, " %s(ptr, value);\n", manualfunc);
}
else {
rna_print_data_get(f, dp);
if (prop->type == PROP_BOOLEAN && dp->booleanbit) {
fprintf(f, " if (%svalue) data->%s |= ", (dp->booleannegative) ? "!" : "", dp->dnaname);
rna_int_print(f, dp->booleanbit);
fprintf(f, ";\n");
fprintf(f, " else data->%s &= ~", dp->dnaname);
rna_int_print(f, dp->booleanbit);
fprintf(f, ";\n");
}
else if (prop->type == PROP_ENUM && dp->enumbitflags) {
fprintf(f, " data->%s &= ~", dp->dnaname);
rna_int_print(f, rna_enum_bitmask(prop));
fprintf(f, ";\n");
fprintf(f, " data->%s |= value;\n", dp->dnaname);
}
else {
rna_clamp_value_range(f, prop);
fprintf(f, " data->%s = %s", dp->dnaname, (dp->booleannegative) ? "!" : "");
rna_clamp_value(f, prop, 0);
}
}
#ifdef USE_RNA_RANGE_CHECK
if (dp->dnaname && manualfunc == NULL) {
rna_clamp_value_range_check(f, prop, "data->", dp->dnaname);
}
#endif
fprintf(f, "}\n\n");
}
break;
}
return func;
}
static char *rna_def_property_length_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp,
const char *manualfunc)
{
char *func = NULL;
if (prop->flag & PROP_IDPROPERTY && manualfunc == NULL)
return NULL;
if (prop->type == PROP_STRING) {
if (!manualfunc) {
if (!dp->dnastructname || !dp->dnaname) {
fprintf(stderr, "%s: %s.%s has no valid dna info.\n",
__func__, srna->identifier, prop->identifier);
DefRNA.error = 1;
return NULL;
}
}
func = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "length");
fprintf(f, "int %s(PointerRNA *ptr)\n", func);
fprintf(f, "{\n");
if (manualfunc) {
fprintf(f, " return %s(ptr);\n", manualfunc);
}
else {
rna_print_data_get(f, dp);
if (!(prop->flag & PROP_NEVER_NULL)) {
fprintf(f, " if (data->%s == NULL) return 0;\n", dp->dnaname);
}
fprintf(f, " return strlen(data->%s);\n", dp->dnaname);
}
fprintf(f, "}\n\n");
}
else if (prop->type == PROP_COLLECTION) {
if (!manualfunc) {
if (prop->type == PROP_COLLECTION && (!(dp->dnalengthname || dp->dnalengthfixed) || !dp->dnaname)) {
fprintf(stderr, "%s: %s.%s has no valid dna info.\n",
__func__, srna->identifier, prop->identifier);
DefRNA.error = 1;
return NULL;
}
}
func = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "length");
fprintf(f, "int %s(PointerRNA *ptr)\n", func);
fprintf(f, "{\n");
if (manualfunc) {
fprintf(f, " return %s(ptr);\n", manualfunc);
}
else {
if (dp->dnaarraylength <= 1 || dp->dnalengthname)
rna_print_data_get(f, dp);
if (dp->dnaarraylength > 1)
fprintf(f, " return ");
else
fprintf(f, " return (data->%s == NULL) ? 0 : ", dp->dnaname);
if (dp->dnalengthname)
fprintf(f, "data->%s;\n", dp->dnalengthname);
else
fprintf(f, "%d;\n", dp->dnalengthfixed);
}
fprintf(f, "}\n\n");
}
return func;
}
static char *rna_def_property_begin_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp,
const char *manualfunc)
{
char *func, *getfunc;
if (prop->flag & PROP_IDPROPERTY && manualfunc == NULL)
return NULL;
if (!manualfunc) {
if (!dp->dnastructname || !dp->dnaname) {
fprintf(stderr, "%s: %s.%s has no valid dna info.\n",
__func__, srna->identifier, prop->identifier);
DefRNA.error = 1;
return NULL;
}
}
func = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "begin");
fprintf(f, "void %s(CollectionPropertyIterator *iter, PointerRNA *ptr)\n", func);
fprintf(f, "{\n");
if (!manualfunc)
rna_print_data_get(f, dp);
fprintf(f, "\n memset(iter, 0, sizeof(*iter));\n");
fprintf(f, " iter->parent = *ptr;\n");
fprintf(f, " iter->prop = (PropertyRNA *)&rna_%s_%s;\n", srna->identifier, prop->identifier);
if (dp->dnalengthname || dp->dnalengthfixed) {
if (manualfunc) {
fprintf(f, "\n %s(iter, ptr);\n", manualfunc);
}
else {
if (dp->dnalengthname)
fprintf(f, "\n rna_iterator_array_begin(iter, data->%s, sizeof(data->%s[0]), data->%s, 0, NULL);\n",
dp->dnaname, dp->dnaname, dp->dnalengthname);
else
fprintf(f, "\n rna_iterator_array_begin(iter, data->%s, sizeof(data->%s[0]), %d, 0, NULL);\n",
dp->dnaname, dp->dnaname, dp->dnalengthfixed);
}
}
else {
if (manualfunc)
fprintf(f, "\n %s(iter, ptr);\n", manualfunc);
else if (dp->dnapointerlevel == 0)
fprintf(f, "\n rna_iterator_listbase_begin(iter, &data->%s, NULL);\n", dp->dnaname);
else
fprintf(f, "\n rna_iterator_listbase_begin(iter, data->%s, NULL);\n", dp->dnaname);
}
getfunc = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "get");
fprintf(f, "\n if (iter->valid)\n");
fprintf(f, " iter->ptr = %s(iter);\n", getfunc);
fprintf(f, "}\n\n");
return func;
}
static char *rna_def_property_lookup_int_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp,
const char *manualfunc, const char *nextfunc)
{
/* note on indices, this is for external functions and ignores skipped values.
* so the index can only be checked against the length when there is no 'skip' function. */
char *func;
if (prop->flag & PROP_IDPROPERTY && manualfunc == NULL)
return NULL;
if (!manualfunc) {
if (!dp->dnastructname || !dp->dnaname)
return NULL;
/* only supported in case of standard next functions */
if (STREQ(nextfunc, "rna_iterator_array_next")) {}
else if (STREQ(nextfunc, "rna_iterator_listbase_next")) {}
else return NULL;
}
func = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "lookup_int");
fprintf(f, "int %s(PointerRNA *ptr, int index, PointerRNA *r_ptr)\n", func);
fprintf(f, "{\n");
if (manualfunc) {
fprintf(f, "\n return %s(ptr, index, r_ptr);\n", manualfunc);
fprintf(f, "}\n\n");
return func;
}
fprintf(f, " int found = 0;\n");
fprintf(f, " CollectionPropertyIterator iter;\n\n");
fprintf(f, " %s_%s_begin(&iter, ptr);\n\n", srna->identifier, rna_safe_id(prop->identifier));
fprintf(f, " if (iter.valid) {\n");
if (STREQ(nextfunc, "rna_iterator_array_next")) {
fprintf(f, " ArrayIterator *internal = &iter.internal.array;\n");
fprintf(f, " if (index < 0 || index >= internal->length) {\n");
fprintf(f, "#ifdef __GNUC__\n");
fprintf(f, " printf(\"Array iterator out of range: %%s (index %%d)\\n\", __func__, index);\n");
fprintf(f, "#else\n");
fprintf(f, " printf(\"Array iterator out of range: (index %%d)\\n\", index);\n");
fprintf(f, "#endif\n");
fprintf(f, " }\n");
fprintf(f, " else if (internal->skip) {\n");
fprintf(f, " while (index-- > 0 && iter.valid) {\n");
fprintf(f, " rna_iterator_array_next(&iter);\n");
fprintf(f, " }\n");
fprintf(f, " found = (index == -1 && iter.valid);\n");
fprintf(f, " }\n");
fprintf(f, " else {\n");
fprintf(f, " internal->ptr += internal->itemsize * index;\n");
fprintf(f, " found = 1;\n");
fprintf(f, " }\n");
}
else if (STREQ(nextfunc, "rna_iterator_listbase_next")) {
fprintf(f, " ListBaseIterator *internal = &iter.internal.listbase;\n");
fprintf(f, " if (internal->skip) {\n");
fprintf(f, " while (index-- > 0 && iter.valid) {\n");
fprintf(f, " rna_iterator_listbase_next(&iter);\n");
fprintf(f, " }\n");
fprintf(f, " found = (index == -1 && iter.valid);\n");
fprintf(f, " }\n");
fprintf(f, " else {\n");
fprintf(f, " while (index-- > 0 && internal->link)\n");
fprintf(f, " internal->link = internal->link->next;\n");
fprintf(f, " found = (index == -1 && internal->link);\n");
fprintf(f, " }\n");
}
fprintf(f, " if (found) *r_ptr = %s_%s_get(&iter);\n", srna->identifier, rna_safe_id(prop->identifier));
fprintf(f, " }\n\n");
fprintf(f, " %s_%s_end(&iter);\n\n", srna->identifier, rna_safe_id(prop->identifier));
fprintf(f, " return found;\n");
#if 0
rna_print_data_get(f, dp);
item_type = (cprop->item_type) ? (const char *)cprop->item_type : "UnknownType";
if (dp->dnalengthname || dp->dnalengthfixed) {
if (dp->dnalengthname)
fprintf(f, "\n rna_array_lookup_int(ptr, &RNA_%s, data->%s, sizeof(data->%s[0]), data->%s, index);\n",
item_type, dp->dnaname, dp->dnaname, dp->dnalengthname);
else
fprintf(f, "\n rna_array_lookup_int(ptr, &RNA_%s, data->%s, sizeof(data->%s[0]), %d, index);\n",
item_type, dp->dnaname, dp->dnaname, dp->dnalengthfixed);
}
else {
if (dp->dnapointerlevel == 0)
fprintf(f, "\n return rna_listbase_lookup_int(ptr, &RNA_%s, &data->%s, index);\n",
item_type, dp->dnaname);
else
fprintf(f, "\n return rna_listbase_lookup_int(ptr, &RNA_%s, data->%s, index);\n", item_type, dp->dnaname);
}
#endif
fprintf(f, "}\n\n");
return func;
}
static char *rna_def_property_lookup_string_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp,
const char *manualfunc, const char *item_type)
{
char *func;
StructRNA *item_srna, *item_name_base;
PropertyRNA *item_name_prop;
const int namebuflen = 1024;
if (prop->flag & PROP_IDPROPERTY && manualfunc == NULL)
return NULL;
if (!manualfunc) {
if (!dp->dnastructname || !dp->dnaname)
return NULL;
/* only supported for collection items with name properties */
item_srna = rna_find_struct(item_type);
if (item_srna && item_srna->nameproperty) {
item_name_prop = item_srna->nameproperty;
item_name_base = item_srna;
while (item_name_base->base && item_name_base->base->nameproperty == item_name_prop)
item_name_base = item_name_base->base;
}
else
return NULL;
}
func = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "lookup_string");
fprintf(f, "int %s(PointerRNA *ptr, const char *key, PointerRNA *r_ptr)\n", func);
fprintf(f, "{\n");
if (manualfunc) {
fprintf(f, " return %s(ptr, key, r_ptr);\n", manualfunc);
fprintf(f, "}\n\n");
return func;
}
/* XXX extern declaration could be avoid by including RNA_blender.h, but this has lots of unknown
* DNA types in functions, leading to conflicting function signatures.
*/
fprintf(f, " extern int %s_%s_length(PointerRNA *);\n", item_name_base->identifier, rna_safe_id(item_name_prop->identifier));
fprintf(f, " extern void %s_%s_get(PointerRNA *, char *);\n\n", item_name_base->identifier, rna_safe_id(item_name_prop->identifier));
fprintf(f, " bool found = false;\n");
fprintf(f, " CollectionPropertyIterator iter;\n");
fprintf(f, " char namebuf[%d];\n", namebuflen);
fprintf(f, " char *name;\n\n");
fprintf(f, " %s_%s_begin(&iter, ptr);\n\n", srna->identifier, rna_safe_id(prop->identifier));
fprintf(f, " while (iter.valid) {\n");
fprintf(f, " if (iter.ptr.data) {\n");
fprintf(f, " int namelen = %s_%s_length(&iter.ptr);\n", item_name_base->identifier, rna_safe_id(item_name_prop->identifier));
fprintf(f, " if (namelen < %d) {\n", namebuflen);
fprintf(f, " %s_%s_get(&iter.ptr, namebuf);\n", item_name_base->identifier, rna_safe_id(item_name_prop->identifier));
fprintf(f, " if (strcmp(namebuf, key) == 0) {\n");
fprintf(f, " found = true;\n");
fprintf(f, " *r_ptr = iter.ptr;\n");
fprintf(f, " break;\n");
fprintf(f, " }\n");
fprintf(f, " }\n");
fprintf(f, " else {\n");
fprintf(f, " name = MEM_mallocN(namelen+1, \"name string\");\n");
fprintf(f, " %s_%s_get(&iter.ptr, name);\n", item_name_base->identifier, rna_safe_id(item_name_prop->identifier));
fprintf(f, " if (strcmp(name, key) == 0) {\n");
fprintf(f, " MEM_freeN(name);\n\n");
fprintf(f, " found = true;\n");
fprintf(f, " *r_ptr = iter.ptr;\n");
fprintf(f, " break;\n");
fprintf(f, " }\n");
fprintf(f, " else {\n");
fprintf(f, " MEM_freeN(name);\n");
fprintf(f, " }\n");
fprintf(f, " }\n");
fprintf(f, " }\n");
fprintf(f, " %s_%s_next(&iter);\n", srna->identifier, rna_safe_id(prop->identifier));
fprintf(f, " }\n");
fprintf(f, " %s_%s_end(&iter);\n\n", srna->identifier, rna_safe_id(prop->identifier));
fprintf(f, " return found;\n");
fprintf(f, "}\n\n");
return func;
}
static char *rna_def_property_next_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *UNUSED(dp),
const char *manualfunc)
{
char *func, *getfunc;
if (prop->flag & PROP_IDPROPERTY && manualfunc == NULL)
return NULL;
if (!manualfunc)
return NULL;
func = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "next");
fprintf(f, "void %s(CollectionPropertyIterator *iter)\n", func);
fprintf(f, "{\n");
fprintf(f, " %s(iter);\n", manualfunc);
getfunc = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "get");
fprintf(f, "\n if (iter->valid)\n");
fprintf(f, " iter->ptr = %s(iter);\n", getfunc);
fprintf(f, "}\n\n");
return func;
}
static char *rna_def_property_end_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *UNUSED(dp),
const char *manualfunc)
{
char *func;
if (prop->flag & PROP_IDPROPERTY && manualfunc == NULL)
return NULL;
func = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "end");
fprintf(f, "void %s(CollectionPropertyIterator *iter)\n", func);
fprintf(f, "{\n");
if (manualfunc)
fprintf(f, " %s(iter);\n", manualfunc);
fprintf(f, "}\n\n");
return func;
}
static void rna_set_raw_property(PropertyDefRNA *dp, PropertyRNA *prop)
{
if (dp->dnapointerlevel != 0)
return;
if (!dp->dnatype || !dp->dnaname || !dp->dnastructname)
return;
if (STREQ(dp->dnatype, "char")) {
prop->rawtype = PROP_RAW_CHAR;
prop->flag_internal |= PROP_INTERN_RAW_ACCESS;
}
else if (STREQ(dp->dnatype, "short")) {
prop->rawtype = PROP_RAW_SHORT;
prop->flag_internal |= PROP_INTERN_RAW_ACCESS;
}
else if (STREQ(dp->dnatype, "int")) {
prop->rawtype = PROP_RAW_INT;
prop->flag_internal |= PROP_INTERN_RAW_ACCESS;
}
else if (STREQ(dp->dnatype, "float")) {
prop->rawtype = PROP_RAW_FLOAT;
prop->flag_internal |= PROP_INTERN_RAW_ACCESS;
}
else if (STREQ(dp->dnatype, "double")) {
prop->rawtype = PROP_RAW_DOUBLE;
prop->flag_internal |= PROP_INTERN_RAW_ACCESS;
}
}
static void rna_set_raw_offset(FILE *f, StructRNA *srna, PropertyRNA *prop)
{
PropertyDefRNA *dp = rna_find_struct_property_def(srna, prop);
fprintf(f, "\toffsetof(%s, %s), %d", dp->dnastructname, dp->dnaname, prop->rawtype);
}
static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
{
PropertyRNA *prop;
prop = dp->prop;
switch (prop->type) {
case PROP_BOOLEAN:
{
BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
if (!prop->arraydimension) {
if (!bprop->get && !bprop->set && !dp->booleanbit)
rna_set_raw_property(dp, prop);
bprop->get = (void *)rna_def_property_get_func(f, srna, prop, dp, (const char *)bprop->get);
bprop->set = (void *)rna_def_property_set_func(f, srna, prop, dp, (const char *)bprop->set);
}
else {
bprop->getarray = (void *)rna_def_property_get_func(f, srna, prop, dp, (const char *)bprop->getarray);
bprop->setarray = (void *)rna_def_property_set_func(f, srna, prop, dp, (const char *)bprop->setarray);
}
break;
}
case PROP_INT:
{
IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
if (!prop->arraydimension) {
if (!iprop->get && !iprop->set)
rna_set_raw_property(dp, prop);
iprop->get = (void *)rna_def_property_get_func(f, srna, prop, dp, (const char *)iprop->get);
iprop->set = (void *)rna_def_property_set_func(f, srna, prop, dp, (const char *)iprop->set);
}
else {
if (!iprop->getarray && !iprop->setarray)
rna_set_raw_property(dp, prop);
iprop->getarray = (void *)rna_def_property_get_func(f, srna, prop, dp, (const char *)iprop->getarray);
iprop->setarray = (void *)rna_def_property_set_func(f, srna, prop, dp, (const char *)iprop->setarray);
}
break;
}
case PROP_FLOAT:
{
FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
if (!prop->arraydimension) {
if (!fprop->get && !fprop->set)
rna_set_raw_property(dp, prop);
fprop->get = (void *)rna_def_property_get_func(f, srna, prop, dp, (const char *)fprop->get);
fprop->set = (void *)rna_def_property_set_func(f, srna, prop, dp, (const char *)fprop->set);
}
else {
if (!fprop->getarray && !fprop->setarray)
rna_set_raw_property(dp, prop);
fprop->getarray = (void *)rna_def_property_get_func(f, srna, prop, dp, (const char *)fprop->getarray);
fprop->setarray = (void *)rna_def_property_set_func(f, srna, prop, dp, (const char *)fprop->setarray);
}
break;
}
case PROP_ENUM:
{
EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
eprop->get = (void *)rna_def_property_get_func(f, srna, prop, dp, (const char *)eprop->get);
eprop->set = (void *)rna_def_property_set_func(f, srna, prop, dp, (const char *)eprop->set);
break;
}
case PROP_STRING:
{
StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
sprop->get = (void *)rna_def_property_get_func(f, srna, prop, dp, (const char *)sprop->get);
sprop->length = (void *)rna_def_property_length_func(f, srna, prop, dp, (const char *)sprop->length);
sprop->set = (void *)rna_def_property_set_func(f, srna, prop, dp, (const char *)sprop->set);
break;
}
case PROP_POINTER:
{
PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop;
pprop->get = (void *)rna_def_property_get_func(f, srna, prop, dp, (const char *)pprop->get);
pprop->set = (void *)rna_def_property_set_func(f, srna, prop, dp, (const char *)pprop->set);
if (!pprop->type) {
fprintf(stderr, "%s: %s.%s, pointer must have a struct type.\n",
__func__, srna->identifier, prop->identifier);
DefRNA.error = 1;
}
break;
}
case PROP_COLLECTION:
{
CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop;
const char *nextfunc = (const char *)cprop->next;
const char *item_type = (const char *)cprop->item_type;
if (cprop->length) {
/* always generate if we have a manual implementation */
cprop->length = (void *)rna_def_property_length_func(f, srna, prop, dp, (const char *)cprop->length);
}
else if (dp->dnatype && STREQ(dp->dnatype, "ListBase")) {
/* pass */
}
else if (dp->dnalengthname || dp->dnalengthfixed) {
cprop->length = (void *)rna_def_property_length_func(f, srna, prop, dp, (const char *)cprop->length);
}
/* test if we can allow raw array access, if it is using our standard
* array get/next function, we can be sure it is an actual array */
if (cprop->next && cprop->get)
if (STREQ((const char *)cprop->next, "rna_iterator_array_next") &&
STREQ((const char *)cprop->get, "rna_iterator_array_get"))
{
prop->flag_internal |= PROP_INTERN_RAW_ARRAY;
}
cprop->get = (void *)rna_def_property_get_func(f, srna, prop, dp, (const char *)cprop->get);
cprop->begin = (void *)rna_def_property_begin_func(f, srna, prop, dp, (const char *)cprop->begin);
cprop->next = (void *)rna_def_property_next_func(f, srna, prop, dp, (const char *)cprop->next);
cprop->end = (void *)rna_def_property_end_func(f, srna, prop, dp, (const char *)cprop->end);
cprop->lookupint = (void *)rna_def_property_lookup_int_func(f, srna, prop, dp,
(const char *)cprop->lookupint, nextfunc);
cprop->lookupstring = (void *)rna_def_property_lookup_string_func(f, srna, prop, dp,
(const char *)cprop->lookupstring, item_type);
if (!(prop->flag & PROP_IDPROPERTY)) {
if (!cprop->begin) {
fprintf(stderr, "%s: %s.%s, collection must have a begin function.\n",
__func__, srna->identifier, prop->identifier);
DefRNA.error = 1;
}
if (!cprop->next) {
fprintf(stderr, "%s: %s.%s, collection must have a next function.\n",
__func__, srna->identifier, prop->identifier);
DefRNA.error = 1;
}
if (!cprop->get) {
fprintf(stderr, "%s: %s.%s, collection must have a get function.\n",
__func__, srna->identifier, prop->identifier);
DefRNA.error = 1;
}
}
if (!cprop->item_type) {
fprintf(stderr, "%s: %s.%s, collection must have a struct type.\n",
__func__, srna->identifier, prop->identifier);
DefRNA.error = 1;
}
break;
}
}
}
static void rna_def_property_funcs_header(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
{
PropertyRNA *prop;
const char *func;
prop = dp->prop;
if (prop->flag & PROP_IDPROPERTY || prop->flag_internal & PROP_INTERN_BUILTIN) {
return;
}
func = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "");
switch (prop->type) {
case PROP_BOOLEAN:
{
if (!prop->arraydimension) {
fprintf(f, "bool %sget(PointerRNA *ptr);\n", func);
fprintf(f, "void %sset(PointerRNA *ptr, bool value);\n", func);
}
else if (prop->arraydimension && prop->totarraylength) {
fprintf(f, "void %sget(PointerRNA *ptr, bool values[%u]);\n", func, prop->totarraylength);
fprintf(f, "void %sset(PointerRNA *ptr, const bool values[%u]);\n", func, prop->totarraylength);
}
else {
fprintf(f, "void %sget(PointerRNA *ptr, bool values[]);\n", func);
fprintf(f, "void %sset(PointerRNA *ptr, const bool values[]);\n", func);
}
break;
}
case PROP_INT:
{
if (!prop->arraydimension) {
fprintf(f, "int %sget(PointerRNA *ptr);\n", func);
fprintf(f, "void %sset(PointerRNA *ptr, int value);\n", func);
}
else if (prop->arraydimension && prop->totarraylength) {
fprintf(f, "void %sget(PointerRNA *ptr, int values[%u]);\n", func, prop->totarraylength);
fprintf(f, "void %sset(PointerRNA *ptr, const int values[%u]);\n", func, prop->totarraylength);
}
else {
fprintf(f, "void %sget(PointerRNA *ptr, int values[]);\n", func);
fprintf(f, "void %sset(PointerRNA *ptr, const int values[]);\n", func);
}
break;
}
case PROP_FLOAT:
{
if (!prop->arraydimension) {
fprintf(f, "float %sget(PointerRNA *ptr);\n", func);
fprintf(f, "void %sset(PointerRNA *ptr, float value);\n", func);
}
else if (prop->arraydimension && prop->totarraylength) {
fprintf(f, "void %sget(PointerRNA *ptr, float values[%u]);\n", func, prop->totarraylength);
fprintf(f, "void %sset(PointerRNA *ptr, const float values[%u]);\n", func, prop->totarraylength);
}
else {
fprintf(f, "void %sget(PointerRNA *ptr, float values[]);\n", func);
fprintf(f, "void %sset(PointerRNA *ptr, const float values[]);", func);
}
break;
}
case PROP_ENUM:
{
EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
int i;
if (eprop->item && eprop->totitem) {
fprintf(f, "enum {\n");
for (i = 0; i < eprop->totitem; i++)
if (eprop->item[i].identifier[0])
fprintf(f, "\t%s_%s_%s = %d,\n", srna->identifier, prop->identifier,
eprop->item[i].identifier, eprop->item[i].value);
fprintf(f, "};\n\n");
}
fprintf(f, "int %sget(PointerRNA *ptr);\n", func);
fprintf(f, "void %sset(PointerRNA *ptr, int value);\n", func);
break;
}
case PROP_STRING:
{
StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
if (sprop->maxlength) {
fprintf(f, "#define %s_%s_MAX %d\n\n", srna->identifier, prop->identifier, sprop->maxlength);
}
fprintf(f, "void %sget(PointerRNA *ptr, char *value);\n", func);
fprintf(f, "int %slength(PointerRNA *ptr);\n", func);
fprintf(f, "void %sset(PointerRNA *ptr, const char *value);\n", func);
break;
}
case PROP_POINTER:
{
fprintf(f, "PointerRNA %sget(PointerRNA *ptr);\n", func);
/*fprintf(f, "void %sset(PointerRNA *ptr, PointerRNA value);\n", func); */
break;
}
case PROP_COLLECTION:
{
CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop;
fprintf(f, "void %sbegin(CollectionPropertyIterator *iter, PointerRNA *ptr);\n", func);
fprintf(f, "void %snext(CollectionPropertyIterator *iter);\n", func);
fprintf(f, "void %send(CollectionPropertyIterator *iter);\n", func);
if (cprop->length)
fprintf(f, "int %slength(PointerRNA *ptr);\n", func);
if (cprop->lookupint)
fprintf(f, "int %slookup_int(PointerRNA *ptr, int key, PointerRNA *r_ptr);\n", func);
if (cprop->lookupstring)
fprintf(f, "int %slookup_string(PointerRNA *ptr, const char *key, PointerRNA *r_ptr);\n", func);
break;
}
}
if (prop->getlength) {
char funcname[2048];
rna_construct_wrapper_function_name(funcname, sizeof(funcname), srna->identifier, prop->identifier, "get_length");
fprintf(f, "int %s(PointerRNA *ptr, int *arraylen);\n", funcname);
}
fprintf(f, "\n");
}
static void rna_def_function_funcs_header(FILE *f, StructRNA *srna, FunctionDefRNA *dfunc)
{
FunctionRNA *func = dfunc->func;
char funcname[2048];
rna_construct_wrapper_function_name(funcname, sizeof(funcname), srna->identifier, func->identifier, NULL);
rna_generate_static_parameter_prototypes(f, srna, dfunc, funcname, 1);
}
static void rna_def_property_funcs_header_cpp(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
{
PropertyRNA *prop;
prop = dp->prop;
if (prop->flag & PROP_IDPROPERTY || prop->flag_internal & PROP_INTERN_BUILTIN) {
return;
}
/* disabled for now to avoid msvc compiler error due to large file size */
#if 0
if (prop->name && prop->description && prop->description[0] != '\0')
fprintf(f, "\t/* %s: %s */\n", prop->name, prop->description);
else if (prop->name)
fprintf(f, "\t/* %s */\n", prop->name);
else
fprintf(f, "\t/* */\n");
#endif
switch (prop->type) {
case PROP_BOOLEAN:
{
if (!prop->arraydimension) {
fprintf(f, "\tinline bool %s(void);\n", rna_safe_id(prop->identifier));
fprintf(f, "\tinline void %s(bool value);", rna_safe_id(prop->identifier));
}
else if (prop->totarraylength) {
fprintf(f, "\tinline Array<bool, %u> %s(void);\n", prop->totarraylength, rna_safe_id(prop->identifier));
fprintf(f, "\tinline void %s(bool values[%u]);", rna_safe_id(prop->identifier), prop->totarraylength);
}
else if (prop->getlength) {
fprintf(f, "\tinline DynamicArray<bool> %s(void);\n", rna_safe_id(prop->identifier));
fprintf(f, "\tinline void %s(bool values[]);", rna_safe_id(prop->identifier));
}
break;
}
case PROP_INT:
{
if (!prop->arraydimension) {
fprintf(f, "\tinline int %s(void);\n", rna_safe_id(prop->identifier));
fprintf(f, "\tinline void %s(int value);", rna_safe_id(prop->identifier));
}
else if (prop->totarraylength) {
fprintf(f, "\tinline Array<int, %u> %s(void);\n", prop->totarraylength, rna_safe_id(prop->identifier));
fprintf(f, "\tinline void %s(int values[%u]);", rna_safe_id(prop->identifier), prop->totarraylength);
}
else if (prop->getlength) {
fprintf(f, "\tinline DynamicArray<int> %s(void);\n", rna_safe_id(prop->identifier));
fprintf(f, "\tinline void %s(int values[]);", rna_safe_id(prop->identifier));
}
break;
}
case PROP_FLOAT:
{
if (!prop->arraydimension) {
fprintf(f, "\tinline float %s(void);\n", rna_safe_id(prop->identifier));
fprintf(f, "\tinline void %s(float value);", rna_safe_id(prop->identifier));
}
else if (prop->totarraylength) {
fprintf(f, "\tinline Array<float, %u> %s(void);\n", prop->totarraylength, rna_safe_id(prop->identifier));
fprintf(f, "\tinline void %s(float values[%u]);", rna_safe_id(prop->identifier), prop->totarraylength);
}
else if (prop->getlength) {
fprintf(f, "\tinline DynamicArray<float> %s(void);\n", rna_safe_id(prop->identifier));
fprintf(f, "\tinline void %s(float values[]);", rna_safe_id(prop->identifier));
}
break;
}
case PROP_ENUM:
{
EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
int i;
if (eprop->item) {
fprintf(f, "\tenum %s_enum {\n", rna_safe_id(prop->identifier));
for (i = 0; i < eprop->totitem; i++)
if (eprop->item[i].identifier[0])
fprintf(f, "\t\t%s_%s = %d,\n", rna_safe_id(prop->identifier), eprop->item[i].identifier,
eprop->item[i].value);
fprintf(f, "\t};\n");
}
fprintf(f, "\tinline %s_enum %s(void);\n", rna_safe_id(prop->identifier), rna_safe_id(prop->identifier));
fprintf(f, "\tinline void %s(%s_enum value);", rna_safe_id(prop->identifier), rna_safe_id(prop->identifier));
break;
}
case PROP_STRING:
{
fprintf(f, "\tinline std::string %s(void);\n", rna_safe_id(prop->identifier));
fprintf(f, "\tinline void %s(const std::string& value);", rna_safe_id(prop->identifier));
break;
}
case PROP_POINTER:
{
PointerPropertyRNA *pprop = (PointerPropertyRNA *)dp->prop;
if (pprop->type)
fprintf(f, "\tinline %s %s(void);", (const char *)pprop->type, rna_safe_id(prop->identifier));
else
fprintf(f, "\tinline %s %s(void);", "UnknownType", rna_safe_id(prop->identifier));
break;
}
case PROP_COLLECTION:
{
CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)dp->prop;
const char *collection_funcs = "DefaultCollectionFunctions";
if (!(dp->prop->flag & PROP_IDPROPERTY || dp->prop->flag_internal & PROP_INTERN_BUILTIN) && cprop->property.srna) {
collection_funcs = (char *)cprop->property.srna;
}
if (cprop->item_type)
fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s, %s, %s, %s, %s)", collection_funcs, (const char *)cprop->item_type, srna->identifier,
rna_safe_id(prop->identifier), (cprop->length ? "true" : "false"),
(cprop->lookupint ? "true" : "false"), (cprop->lookupstring ? "true" : "false"));
else
fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s, %s, %s, %s, %s)", collection_funcs, "UnknownType", srna->identifier,
rna_safe_id(prop->identifier), (cprop->length ? "true" : "false"),
(cprop->lookupint ? "true" : "false"), (cprop->lookupstring ? "true" : "false"));
break;
}
}
fprintf(f, "\n");
}
static const char *rna_parameter_type_cpp_name(PropertyRNA *prop)
{
if (prop->type == PROP_POINTER) {
/* for cpp api we need to use RNA structures names for pointers */
PointerPropertyRNA *pprop = (PointerPropertyRNA *) prop;
return (const char *) pprop->type;
}
else {
return rna_parameter_type_name(prop);
}
}
static void rna_def_struct_function_prototype_cpp(FILE *f, StructRNA *UNUSED(srna), FunctionDefRNA *dfunc,
const char *namespace, int close_prototype)
{
PropertyDefRNA *dp;
FunctionRNA *func = dfunc->func;
int first = 1;
const char *retval_type = "void";
if (func->c_ret) {
dp = rna_find_parameter_def(func->c_ret);
retval_type = rna_parameter_type_cpp_name(dp->prop);
}
if (namespace && namespace[0])
fprintf(f, "\tinline %s %s::%s(", retval_type, namespace, rna_safe_id(func->identifier));
else
fprintf(f, "\tinline %s %s(", retval_type, rna_safe_id(func->identifier));
if (func->flag & FUNC_USE_MAIN)
WRITE_PARAM("void *main");
if (func->flag & FUNC_USE_CONTEXT)
WRITE_PARAM("Context C");
for (dp = dfunc->cont.properties.first; dp; dp = dp->next) {
int type, flag, flag_parameter, pout;
const char *ptrstr;
if (dp->prop == func->c_ret)
continue;
type = dp->prop->type;
flag = dp->prop->flag;
flag_parameter = dp->prop->flag_parameter;
pout = (flag_parameter & PARM_OUTPUT);
if (flag & PROP_DYNAMIC)
ptrstr = pout ? "**" : "*";
else if (type == PROP_POINTER)
ptrstr = pout ? "*" : "";
else if (dp->prop->arraydimension)
ptrstr = "*";
else if (type == PROP_STRING && (flag & PROP_THICK_WRAP))
ptrstr = "";
else
ptrstr = pout ? "*" : "";
WRITE_COMMA;
if (flag & PROP_DYNAMIC)
fprintf(f, "int %s%s_len, ", (flag_parameter & PARM_OUTPUT) ? "*" : "", dp->prop->identifier);
if (!(flag & PROP_DYNAMIC) && dp->prop->arraydimension)
fprintf(f, "%s %s[%u]", rna_parameter_type_cpp_name(dp->prop),
rna_safe_id(dp->prop->identifier), dp->prop->totarraylength);
else {
fprintf(f, "%s%s%s%s",
rna_parameter_type_cpp_name(dp->prop),
(dp->prop->type == PROP_POINTER && ptrstr[0] == '\0') ? "& " : " ",
ptrstr,
rna_safe_id(dp->prop->identifier));
}
}
fprintf(f, ")");
if (close_prototype)
fprintf(f, ";\n");
}
static void rna_def_struct_function_header_cpp(FILE *f, StructRNA *srna, FunctionDefRNA *dfunc)
{
if (dfunc->call) {
/* disabled for now to avoid msvc compiler error due to large file size */
#if 0
FunctionRNA *func = dfunc->func;
fprintf(f, "\n\t/* %s */\n", func->description);
#endif
rna_def_struct_function_prototype_cpp(f, srna, dfunc, NULL, 1);
}
}
static void rna_def_property_funcs_impl_cpp(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
{
PropertyRNA *prop;
prop = dp->prop;
if (prop->flag & PROP_IDPROPERTY || prop->flag_internal & PROP_INTERN_BUILTIN) {
return;
}
switch (prop->type) {
case PROP_BOOLEAN:
{
if (!prop->arraydimension)
fprintf(f, "\tBOOLEAN_PROPERTY(%s, %s)", srna->identifier, rna_safe_id(prop->identifier));
else if (prop->totarraylength)
fprintf(f, "\tBOOLEAN_ARRAY_PROPERTY(%s, %u, %s)", srna->identifier, prop->totarraylength,
rna_safe_id(prop->identifier));
else if (prop->getlength)
fprintf(f, "\tBOOLEAN_DYNAMIC_ARRAY_PROPERTY(%s, %s)", srna->identifier,
rna_safe_id(prop->identifier));
break;
}
case PROP_INT:
{
if (!prop->arraydimension)
fprintf(f, "\tINT_PROPERTY(%s, %s)", srna->identifier, rna_safe_id(prop->identifier));
else if (prop->totarraylength)
fprintf(f, "\tINT_ARRAY_PROPERTY(%s, %u, %s)", srna->identifier, prop->totarraylength,
rna_safe_id(prop->identifier));
else if (prop->getlength)
fprintf(f, "\tINT_DYNAMIC_ARRAY_PROPERTY(%s, %s)", srna->identifier,
rna_safe_id(prop->identifier));
break;
}
case PROP_FLOAT:
{
if (!prop->arraydimension)
fprintf(f, "\tFLOAT_PROPERTY(%s, %s)", srna->identifier, rna_safe_id(prop->identifier));
else if (prop->totarraylength)
fprintf(f, "\tFLOAT_ARRAY_PROPERTY(%s, %u, %s)", srna->identifier, prop->totarraylength,
rna_safe_id(prop->identifier));
else if (prop->getlength)
fprintf(f, "\tFLOAT_DYNAMIC_ARRAY_PROPERTY(%s, %s)", srna->identifier,
rna_safe_id(prop->identifier));
break;
}
case PROP_ENUM:
{
fprintf(f, "\tENUM_PROPERTY(%s_enum, %s, %s)", rna_safe_id(prop->identifier), srna->identifier,
rna_safe_id(prop->identifier));
break;
}
case PROP_STRING:
{
fprintf(f, "\tSTRING_PROPERTY(%s, %s)", srna->identifier, rna_safe_id(prop->identifier));
break;
}
case PROP_POINTER:
{
PointerPropertyRNA *pprop = (PointerPropertyRNA *)dp->prop;
if (pprop->type)
fprintf(f, "\tPOINTER_PROPERTY(%s, %s, %s)", (const char *)pprop->type, srna->identifier,
rna_safe_id(prop->identifier));
else
fprintf(f, "\tPOINTER_PROPERTY(%s, %s, %s)", "UnknownType", srna->identifier,
rna_safe_id(prop->identifier));
break;
}
case PROP_COLLECTION:
{
#if 0
CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)dp->prop;
if (cprop->type)
fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s, %s, %s, %s)", (const char *)cprop->type, srna->identifier,
prop->identifier, (cprop->length ? "true" : "false"),
(cprop->lookupint ? "true" : "false"), (cprop->lookupstring ? "true" : "false"));
else
fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s, %s, %s, %s)", "UnknownType", srna->identifier,
prop->identifier, (cprop->length ? "true" : "false"),
(cprop->lookupint ? "true" : "false"), (cprop->lookupstring ? "true" : "false"));
#endif
break;
}
}
fprintf(f, "\n");
}
static void rna_def_struct_function_call_impl_cpp(FILE *f, StructRNA *srna, FunctionDefRNA *dfunc)
{
PropertyDefRNA *dp;
StructDefRNA *dsrna;
FunctionRNA *func = dfunc->func;
char funcname[2048];
int first = 1;
rna_construct_wrapper_function_name(funcname, sizeof(funcname), srna->identifier, func->identifier, NULL);
fprintf(f, "%s(", funcname);
dsrna = rna_find_struct_def(srna);
if (func->flag & FUNC_USE_SELF_ID)
WRITE_PARAM("(::ID *) ptr.id.data");
if ((func->flag & FUNC_NO_SELF) == 0) {
WRITE_COMMA;
if (dsrna->dnafromprop) fprintf(f, "(::%s *) this->ptr.data", dsrna->dnafromname);
else if (dsrna->dnaname) fprintf(f, "(::%s *) this->ptr.data", dsrna->dnaname);
else fprintf(f, "(::%s *) this->ptr.data", srna->identifier);
}
else if (func->flag & FUNC_USE_SELF_TYPE) {
WRITE_COMMA;
fprintf(f, "this->ptr.type");
}
if (func->flag & FUNC_USE_MAIN)
WRITE_PARAM("(::Main *) main");
if (func->flag & FUNC_USE_CONTEXT)
WRITE_PARAM("(::bContext *) C.ptr.data");
if (func->flag & FUNC_USE_REPORTS)
WRITE_PARAM("NULL");
dp = dfunc->cont.properties.first;
for (; dp; dp = dp->next) {
if (dp->prop == func->c_ret)
continue;
WRITE_COMMA;
if (dp->prop->flag & PROP_DYNAMIC)
fprintf(f, "%s_len, ", dp->prop->identifier);
if (dp->prop->type == PROP_POINTER)
if ((dp->prop->flag_parameter & PARM_RNAPTR) && !(dp->prop->flag & PROP_THICK_WRAP))
fprintf(f, "(::%s *) &%s.ptr", rna_parameter_type_name(dp->prop), rna_safe_id(dp->prop->identifier));
else if (dp->prop->flag_parameter & PARM_OUTPUT) {
if (dp->prop->flag_parameter & PARM_RNAPTR) {
fprintf(f, "&%s->ptr",
rna_safe_id(dp->prop->identifier));
}
else {
fprintf(f, "(::%s **) &%s->ptr.data",
rna_parameter_type_name(dp->prop), rna_safe_id(dp->prop->identifier));
}
}
else
fprintf(f, "(::%s *) %s.ptr.data", rna_parameter_type_name(dp->prop), rna_safe_id(dp->prop->identifier));
else
fprintf(f, "%s", rna_safe_id(dp->prop->identifier));
}
fprintf(f, ");\n");
}
static void rna_def_struct_function_impl_cpp(FILE *f, StructRNA *srna, FunctionDefRNA *dfunc)
{
PropertyDefRNA *dp;
PointerPropertyRNA *pprop;
FunctionRNA *func = dfunc->func;
if (!dfunc->call)
return;
rna_def_struct_function_prototype_cpp(f, srna, dfunc, srna->identifier, 0);
fprintf(f, " {\n");
if (func->c_ret) {
dp = rna_find_parameter_def(func->c_ret);
if (dp->prop->type == PROP_POINTER) {
pprop = (PointerPropertyRNA *) dp->prop;
fprintf(f, "\t\tPointerRNA result;\n");
if ((dp->prop->flag_parameter & PARM_RNAPTR) == 0) {
StructRNA *ret_srna = rna_find_struct((const char *) pprop->type);
fprintf(f, "\t\t::%s *retdata = ", rna_parameter_type_name(dp->prop));
rna_def_struct_function_call_impl_cpp(f, srna, dfunc);
if (ret_srna->flag & STRUCT_ID)
fprintf(f, "\t\tRNA_id_pointer_create((::ID *) retdata, &result);\n");
else
fprintf(f, "\t\tRNA_pointer_create((::ID *) ptr.id.data, &RNA_%s, retdata, &result);\n", (const char *) pprop->type);
}
else {
fprintf(f, "\t\tresult = ");
rna_def_struct_function_call_impl_cpp(f, srna, dfunc);
}
fprintf(f, "\t\treturn %s(result);\n", (const char *) pprop->type);
}
else {
fprintf(f, "\t\treturn ");
rna_def_struct_function_call_impl_cpp(f, srna, dfunc);
}
}
else {
fprintf(f, "\t\t");
rna_def_struct_function_call_impl_cpp(f, srna, dfunc);
}
fprintf(f, "\t}\n\n");
}
static void rna_def_property_wrapper_funcs(FILE *f, StructDefRNA *dsrna, PropertyDefRNA *dp)
{
if (dp->prop->getlength) {
char funcname[2048];
rna_construct_wrapper_function_name(funcname, sizeof(funcname), dsrna->srna->identifier, dp->prop->identifier, "get_length");
fprintf(f, "int %s(PointerRNA *ptr, int *arraylen)\n", funcname);
fprintf(f, "{\n");
fprintf(f, "\treturn %s(ptr, arraylen);\n", rna_function_string(dp->prop->getlength));
fprintf(f, "}\n\n");
}
}
static void rna_def_function_wrapper_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA *dfunc)
{
StructRNA *srna = dsrna->srna;
FunctionRNA *func = dfunc->func;
PropertyDefRNA *dparm;
int first;
char funcname[2048];
if (!dfunc->call)
return;
rna_construct_wrapper_function_name(funcname, sizeof(funcname), srna->identifier, func->identifier, NULL);
rna_generate_static_parameter_prototypes(f, srna, dfunc, funcname, 0);
fprintf(f, "\n{\n");
if (func->c_ret)
fprintf(f, "\treturn %s(", dfunc->call);
else
fprintf(f, "\t%s(", dfunc->call);
first = 1;
if (func->flag & FUNC_USE_SELF_ID)
WRITE_PARAM("_selfid");
if ((func->flag & FUNC_NO_SELF) == 0) {
WRITE_PARAM("_self");
}
else if (func->flag & FUNC_USE_SELF_TYPE) {
WRITE_PARAM("_type");
}
if (func->flag & FUNC_USE_MAIN)
WRITE_PARAM("bmain");
if (func->flag & FUNC_USE_CONTEXT)
WRITE_PARAM("C");
if (func->flag & FUNC_USE_REPORTS)
WRITE_PARAM("reports");
dparm = dfunc->cont.properties.first;
for (; dparm; dparm = dparm->next) {
if (dparm->prop == func->c_ret)
continue;
WRITE_COMMA;
if (dparm->prop->flag & PROP_DYNAMIC)
fprintf(f, "%s_len, %s", dparm->prop->identifier, dparm->prop->identifier);
else
fprintf(f, "%s", rna_safe_id(dparm->prop->identifier));
}
fprintf(f, ");\n");
fprintf(f, "}\n\n");
}
static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA *dfunc)
{
StructRNA *srna;
FunctionRNA *func;
PropertyDefRNA *dparm;
PropertyType type;
const char *funcname, *valstr;
const char *ptrstr;
const bool has_data = (dfunc->cont.properties.first != NULL);
int flag, flag_parameter, pout, cptr, first;
srna = dsrna->srna;
func = dfunc->func;
if (!dfunc->call)
return;
funcname = rna_alloc_function_name(srna->identifier, func->identifier, "call");
/* function definition */
fprintf(f, "void %s(bContext *C, ReportList *reports, PointerRNA *_ptr, ParameterList *_parms)", funcname);
fprintf(f, "\n{\n");
/* variable definitions */
if (func->flag & FUNC_USE_SELF_ID) {
fprintf(f, "\tstruct ID *_selfid;\n");
}
if ((func->flag & FUNC_NO_SELF) == 0) {
if (dsrna->dnafromprop) fprintf(f, "\tstruct %s *_self;\n", dsrna->dnafromname);
else if (dsrna->dnaname) fprintf(f, "\tstruct %s *_self;\n", dsrna->dnaname);
else fprintf(f, "\tstruct %s *_self;\n", srna->identifier);
}
else if (func->flag & FUNC_USE_SELF_TYPE) {
fprintf(f, "\tstruct StructRNA *_type;\n");
}
dparm = dfunc->cont.properties.first;
for (; dparm; dparm = dparm->next) {
type = dparm->prop->type;
flag = dparm->prop->flag;
flag_parameter = dparm->prop->flag_parameter;
pout = (flag_parameter & PARM_OUTPUT);
cptr = ((type == PROP_POINTER) && !(flag_parameter & PARM_RNAPTR));
if (dparm->prop == func->c_ret)
ptrstr = cptr || dparm->prop->arraydimension ? "*" : "";
/* XXX only arrays and strings are allowed to be dynamic, is this checked anywhere? */
else if (cptr || (flag & PROP_DYNAMIC))
ptrstr = pout ? "**" : "*";
/* fixed size arrays and RNA pointers are pre-allocated on the ParameterList stack, pass a pointer to it */
else if (type == PROP_POINTER || dparm->prop->arraydimension)
ptrstr = "*";
else if ((type == PROP_POINTER) && (flag_parameter & PARM_RNAPTR) && !(flag & PROP_THICK_WRAP))
ptrstr = "*";
/* PROP_THICK_WRAP strings are pre-allocated on the ParameterList stack,
* but type name for string props is already (char *), so leave empty */
else if (type == PROP_STRING && (flag & PROP_THICK_WRAP))
ptrstr = "";
else
ptrstr = pout ? "*" : "";
/* for dynamic parameters we pass an additional int for the length of the parameter */
if (flag & PROP_DYNAMIC)
fprintf(f, "\tint %s%s_len;\n", pout ? "*" : "", dparm->prop->identifier);
fprintf(f, "\t%s%s %s%s;\n", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop),
ptrstr, dparm->prop->identifier);
}
if (has_data) {
fprintf(f, "\tchar *_data");
if (func->c_ret) fprintf(f, ", *_retdata");
fprintf(f, ";\n");
fprintf(f, "\t\n");
}
/* assign self */
if (func->flag & FUNC_USE_SELF_ID) {
fprintf(f, "\t_selfid = (struct ID *)_ptr->id.data;\n");
}
if ((func->flag & FUNC_NO_SELF) == 0) {
if (dsrna->dnafromprop) fprintf(f, "\t_self = (struct %s *)_ptr->data;\n", dsrna->dnafromname);
else if (dsrna->dnaname) fprintf(f, "\t_self = (struct %s *)_ptr->data;\n", dsrna->dnaname);
else fprintf(f, "\t_self = (struct %s *)_ptr->data;\n", srna->identifier);
}
else if (func->flag & FUNC_USE_SELF_TYPE) {
fprintf(f, "\t_type = _ptr->type;\n");
}
if (has_data) {
fprintf(f, "\t_data = (char *)_parms->data;\n");
}
dparm = dfunc->cont.properties.first;
for (; dparm; dparm = dparm->next) {
type = dparm->prop->type;
flag = dparm->prop->flag;
flag_parameter = dparm->prop->flag_parameter;
pout = (flag_parameter & PARM_OUTPUT);
cptr = ((type == PROP_POINTER) && !(flag_parameter & PARM_RNAPTR));
if (dparm->prop == func->c_ret)
fprintf(f, "\t_retdata = _data;\n");
else {
const char *data_str;
if (cptr || (flag & PROP_DYNAMIC)) {
ptrstr = "**";
valstr = "*";
}
else if ((type == PROP_POINTER) && !(flag & PROP_THICK_WRAP)) {
ptrstr = "**";
valstr = "*";
}
else if (type == PROP_POINTER || dparm->prop->arraydimension) {
ptrstr = "*";
valstr = "";
}
else if (type == PROP_STRING && (flag & PROP_THICK_WRAP)) {
ptrstr = "";
valstr = "";
}
else {
ptrstr = "*";
valstr = "*";
}
/* this must be kept in sync with RNA_parameter_dynamic_length_get_data and RNA_parameter_get,
* we could just call the function directly, but this is faster */
if (flag & PROP_DYNAMIC) {
fprintf(f, "\t%s_len = %s((ParameterDynAlloc *)_data)->array_tot;\n", dparm->prop->identifier,
pout ? "(int *)&" : "(int)");
data_str = "(&(((ParameterDynAlloc *)_data)->array))";
}
else {
data_str = "_data";
}
fprintf(f, "\t%s = ", dparm->prop->identifier);
if (!pout)
fprintf(f, "%s", valstr);
fprintf(f, "((%s%s %s)%s);\n", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop),
ptrstr, data_str);
}
if (dparm->next)
fprintf(f, "\t_data += %d;\n", rna_parameter_size(dparm->prop));
}
if (dfunc->call) {
fprintf(f, "\t\n");
fprintf(f, "\t");
if (func->c_ret) fprintf(f, "%s = ", func->c_ret->identifier);
fprintf(f, "%s(", dfunc->call);
first = 1;
if (func->flag & FUNC_USE_SELF_ID) {
fprintf(f, "_selfid");
first = 0;
}
if ((func->flag & FUNC_NO_SELF) == 0) {
if (!first) fprintf(f, ", ");
fprintf(f, "_self");
first = 0;
}
else if (func->flag & FUNC_USE_SELF_TYPE) {
if (!first) fprintf(f, ", ");
fprintf(f, "_type");
first = 0;
}
if (func->flag & FUNC_USE_MAIN) {
if (!first) fprintf(f, ", ");
first = 0;
fprintf(f, "CTX_data_main(C)"); /* may have direct access later */
}
if (func->flag & FUNC_USE_CONTEXT) {
if (!first) fprintf(f, ", ");
first = 0;
fprintf(f, "C");
}
if (func->flag & FUNC_USE_REPORTS) {
if (!first) fprintf(f, ", ");
first = 0;
fprintf(f, "reports");
}
dparm = dfunc->cont.properties.first;
for (; dparm; dparm = dparm->next) {
if (dparm->prop == func->c_ret)
continue;
if (!first) fprintf(f, ", ");
first = 0;
if (dparm->prop->flag & PROP_DYNAMIC)
fprintf(f, "%s_len, %s", dparm->prop->identifier, dparm->prop->identifier);
else
fprintf(f, "%s", dparm->prop->identifier);
}
fprintf(f, ");\n");
if (func->c_ret) {
dparm = rna_find_parameter_def(func->c_ret);
ptrstr = (((dparm->prop->type == PROP_POINTER) && !(dparm->prop->flag_parameter & PARM_RNAPTR)) ||
(dparm->prop->arraydimension)) ? "*" : "";
fprintf(f, "\t*((%s%s %s*)_retdata) = %s;\n", rna_type_struct(dparm->prop),
rna_parameter_type_name(dparm->prop), ptrstr, func->c_ret->identifier);
}
}
fprintf(f, "}\n\n");
dfunc->gencall = funcname;
}
static void rna_auto_types(void)
{
StructDefRNA *ds;
PropertyDefRNA *dp;
for (ds = DefRNA.structs.first; ds; ds = ds->cont.next) {
/* DNA name for Screen is patched in 2.5, we do the reverse here .. */
if (ds->dnaname && STREQ(ds->dnaname, "Screen"))
ds->dnaname = "bScreen";
for (dp = ds->cont.properties.first; dp; dp = dp->next) {
if (dp->dnastructname && STREQ(dp->dnastructname, "Screen"))
dp->dnastructname = "bScreen";
if (dp->dnatype) {
if (dp->prop->type == PROP_POINTER) {
PointerPropertyRNA *pprop = (PointerPropertyRNA *)dp->prop;
StructRNA *type;
if (!pprop->type && !pprop->get)
pprop->type = (StructRNA *)rna_find_type(dp->dnatype);
if (pprop->type) {
type = rna_find_struct((const char *)pprop->type);
if (type && (type->flag & STRUCT_ID_REFCOUNT))
pprop->property.flag |= PROP_ID_REFCOUNT;
}
}
else if (dp->prop->type == PROP_COLLECTION) {
CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)dp->prop;
if (!cprop->item_type && !cprop->get && STREQ(dp->dnatype, "ListBase"))
cprop->item_type = (StructRNA *)rna_find_type(dp->dnatype);
}
}
}
}
}
static void rna_sort(BlenderRNA *brna)
{
StructDefRNA *ds;
StructRNA *srna;
rna_sortlist(&brna->structs, cmp_struct);
rna_sortlist(&DefRNA.structs, cmp_def_struct);
for (srna = brna->structs.first; srna; srna = srna->cont.next)
rna_sortlist(&srna->cont.properties, cmp_property);
for (ds = DefRNA.structs.first; ds; ds = ds->cont.next)
rna_sortlist(&ds->cont.properties, cmp_def_property);
}
static const char *rna_property_structname(PropertyType type)
{
switch (type) {
case PROP_BOOLEAN: return "BoolPropertyRNA";
case PROP_INT: return "IntPropertyRNA";
case PROP_FLOAT: return "FloatPropertyRNA";
case PROP_STRING: return "StringPropertyRNA";
case PROP_ENUM: return "EnumPropertyRNA";
case PROP_POINTER: return "PointerPropertyRNA";
case PROP_COLLECTION: return "CollectionPropertyRNA";
default: return "UnknownPropertyRNA";
}
}
static const char *rna_property_subtypename(PropertySubType type)
{
switch (type) {
case PROP_NONE: return "PROP_NONE";
case PROP_FILEPATH: return "PROP_FILEPATH";
case PROP_FILENAME: return "PROP_FILENAME";
case PROP_DIRPATH: return "PROP_DIRPATH";
case PROP_PIXEL: return "PROP_PIXEL";
case PROP_BYTESTRING: return "PROP_BYTESTRING";
case PROP_UNSIGNED: return "PROP_UNSIGNED";
case PROP_PERCENTAGE: return "PROP_PERCENTAGE";
case PROP_FACTOR: return "PROP_FACTOR";
case PROP_ANGLE: return "PROP_ANGLE";
case PROP_TIME: return "PROP_TIME";
case PROP_DISTANCE: return "PROP_DISTANCE";
case PROP_DISTANCE_CAMERA: return "PROP_DISTANCE_CAMERA";
case PROP_COLOR: return "PROP_COLOR";
case PROP_TRANSLATION: return "PROP_TRANSLATION";
case PROP_DIRECTION: return "PROP_DIRECTION";
case PROP_MATRIX: return "PROP_MATRIX";
case PROP_EULER: return "PROP_EULER";
case PROP_QUATERNION: return "PROP_QUATERNION";
case PROP_AXISANGLE: return "PROP_AXISANGLE";
case PROP_VELOCITY: return "PROP_VELOCITY";
case PROP_ACCELERATION: return "PROP_ACCELERATION";
case PROP_XYZ: return "PROP_XYZ";
case PROP_COLOR_GAMMA: return "PROP_COLOR_GAMMA";
case PROP_COORDS: return "PROP_COORDS";
case PROP_LAYER: return "PROP_LAYER";
case PROP_LAYER_MEMBER: return "PROP_LAYER_MEMBER";
case PROP_PASSWORD: return "PROP_PASSWORD";
default:
{
/* in case we don't have a type preset that includes the subtype */
if (RNA_SUBTYPE_UNIT(type)) {
return rna_property_subtypename(type & ~RNA_SUBTYPE_UNIT(type));
}
else {
return "PROP_SUBTYPE_UNKNOWN";
}
}
}
}
static const char *rna_property_subtype_unit(PropertySubType type)
{
switch (RNA_SUBTYPE_UNIT(type)) {
case PROP_UNIT_NONE: return "PROP_UNIT_NONE";
case PROP_UNIT_LENGTH: return "PROP_UNIT_LENGTH";
case PROP_UNIT_AREA: return "PROP_UNIT_AREA";
case PROP_UNIT_VOLUME: return "PROP_UNIT_VOLUME";
case PROP_UNIT_MASS: return "PROP_UNIT_MASS";
case PROP_UNIT_ROTATION: return "PROP_UNIT_ROTATION";
case PROP_UNIT_TIME: return "PROP_UNIT_TIME";
case PROP_UNIT_VELOCITY: return "PROP_UNIT_VELOCITY";
case PROP_UNIT_ACCELERATION: return "PROP_UNIT_ACCELERATION";
case PROP_UNIT_CAMERA: return "PROP_UNIT_CAMERA";
default: return "PROP_UNIT_UNKNOWN";
}
}
static void rna_generate_prototypes(BlenderRNA *brna, FILE *f)
{
StructRNA *srna;
for (srna = brna->structs.first; srna; srna = srna->cont.next)
fprintf(f, "extern StructRNA RNA_%s;\n", srna->identifier);
fprintf(f, "\n");
}
static void rna_generate_blender(BlenderRNA *brna, FILE *f)
{
StructRNA *srna;
fprintf(f,
"BlenderRNA BLENDER_RNA = {\n"
"\t.structs = {"
);
srna = brna->structs.first;
if (srna) fprintf(f, "&RNA_%s, ", srna->identifier);
else fprintf(f, "NULL, ");
srna = brna->structs.last;
if (srna) fprintf(f, "&RNA_%s},\n", srna->identifier);
else fprintf(f, "NULL},\n");
fprintf(f,
"\t.structs_map = NULL,\n"
"\t.structs_len = 0,\n"
"};\n\n"
);
}
static void rna_generate_property_prototypes(BlenderRNA *UNUSED(brna), StructRNA *srna, FILE *f)
{
PropertyRNA *prop;
StructRNA *base;
base = srna->base;
while (base) {
fprintf(f, "\n");
for (prop = base->cont.properties.first; prop; prop = prop->next)
fprintf(f, "%s%s rna_%s_%s;\n", "extern ", rna_property_structname(prop->type),
base->identifier, prop->identifier);
base = base->base;
}
if (srna->cont.properties.first)
fprintf(f, "\n");
for (prop = srna->cont.properties.first; prop; prop = prop->next)
fprintf(f, "%s%s rna_%s_%s;\n", (prop->flag & PROP_EXPORT) ? "" : "", rna_property_structname(prop->type),
srna->identifier, prop->identifier);
fprintf(f, "\n");
}
static void rna_generate_parameter_prototypes(BlenderRNA *UNUSED(brna), StructRNA *srna, FunctionRNA *func, FILE *f)
{
PropertyRNA *parm;
for (parm = func->cont.properties.first; parm; parm = parm->next)
fprintf(f, "%s%s rna_%s_%s_%s;\n", "extern ", rna_property_structname(parm->type), srna->identifier,
func->identifier, parm->identifier);
if (func->cont.properties.first)
fprintf(f, "\n");
}
static void rna_generate_function_prototypes(BlenderRNA *brna, StructRNA *srna, FILE *f)
{
FunctionRNA *func;
StructRNA *base;
base = srna->base;
while (base) {
for (func = base->functions.first; func; func = func->cont.next) {
fprintf(f, "%s%s rna_%s_%s_func;\n", "extern ", "FunctionRNA", base->identifier, func->identifier);
rna_generate_parameter_prototypes(brna, base, func, f);
}
if (base->functions.first)
fprintf(f, "\n");
base = base->base;
}
for (func = srna->functions.first; func; func = func->cont.next) {
fprintf(f, "%s%s rna_%s_%s_func;\n", "extern ", "FunctionRNA", srna->identifier, func->identifier);
rna_generate_parameter_prototypes(brna, srna, func, f);
}
if (srna->functions.first)
fprintf(f, "\n");
}
static void rna_generate_static_parameter_prototypes(FILE *f, StructRNA *srna, FunctionDefRNA *dfunc, const char *name_override, int close_prototype)
{
FunctionRNA *func;
PropertyDefRNA *dparm;
StructDefRNA *dsrna;
PropertyType type;
int flag, flag_parameter, pout, cptr, first;
const char *ptrstr;
dsrna = rna_find_struct_def(srna);
func = dfunc->func;
/* return type */
for (dparm = dfunc->cont.properties.first; dparm; dparm = dparm->next) {
if (dparm->prop == func->c_ret) {
if (dparm->prop->arraydimension)
fprintf(f, "XXX no array return types yet"); /* XXX not supported */
else if (dparm->prop->type == PROP_POINTER && !(dparm->prop->flag_parameter & PARM_RNAPTR))
fprintf(f, "%s%s *", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop));
else
fprintf(f, "%s%s ", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop));
break;
}
}
/* void if nothing to return */
if (!dparm)
fprintf(f, "void ");
/* function name */
if (name_override == NULL || name_override[0] == '\0')
fprintf(f, "%s(", dfunc->call);
else
fprintf(f, "%s(", name_override);
first = 1;
/* self, context and reports parameters */
if (func->flag & FUNC_USE_SELF_ID) {
fprintf(f, "struct ID *_selfid");
first = 0;
}
if ((func->flag & FUNC_NO_SELF) == 0) {
if (!first) fprintf(f, ", ");
if (dsrna->dnafromprop) fprintf(f, "struct %s *_self", dsrna->dnafromname);
else if (dsrna->dnaname) fprintf(f, "struct %s *_self", dsrna->dnaname);
else fprintf(f, "struct %s *_self", srna->identifier);
first = 0;
}
else if (func->flag & FUNC_USE_SELF_TYPE) {
if (!first) fprintf(f, ", ");
fprintf(f, "struct StructRNA *_type");
first = 0;
}
if (func->flag & FUNC_USE_MAIN) {
if (!first) fprintf(f, ", ");
first = 0;
fprintf(f, "Main *bmain");
}
if (func->flag & FUNC_USE_CONTEXT) {
if (!first) fprintf(f, ", ");
first = 0;
fprintf(f, "bContext *C");
}
if (func->flag & FUNC_USE_REPORTS) {
if (!first) fprintf(f, ", ");
first = 0;
fprintf(f, "ReportList *reports");
}
/* defined parameters */
for (dparm = dfunc->cont.properties.first; dparm; dparm = dparm->next) {
type = dparm->prop->type;
flag = dparm->prop->flag;
flag_parameter = dparm->prop->flag_parameter;
pout = (flag_parameter & PARM_OUTPUT);
cptr = ((type == PROP_POINTER) && !(flag_parameter & PARM_RNAPTR));
if (dparm->prop == func->c_ret)
continue;
if (cptr || (flag & PROP_DYNAMIC))
ptrstr = pout ? "**" : "*";
else if (type == PROP_POINTER || dparm->prop->arraydimension)
ptrstr = "*";
else if (type == PROP_STRING && (flag & PROP_THICK_WRAP))
ptrstr = "";
else
ptrstr = pout ? "*" : "";
if (!first) fprintf(f, ", ");
first = 0;
if (flag & PROP_DYNAMIC)
fprintf(f, "int %s%s_len, ", pout ? "*" : "", dparm->prop->identifier);
if (!(flag & PROP_DYNAMIC) && dparm->prop->arraydimension)
fprintf(f, "%s%s %s[%u]", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop),
rna_safe_id(dparm->prop->identifier), dparm->prop->totarraylength);
else
fprintf(f, "%s%s %s%s", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop),
ptrstr, rna_safe_id(dparm->prop->identifier));
}
/* ensure func(void) if there are no args */
if (first) fprintf(f, "void");
fprintf(f, ")");
if (close_prototype)
fprintf(f, ";\n");
}
static void rna_generate_static_function_prototypes(BlenderRNA *UNUSED(brna), StructRNA *srna, FILE *f)
{
FunctionRNA *func;
FunctionDefRNA *dfunc;
int first = 1;
for (func = srna->functions.first; func; func = func->cont.next) {
dfunc = rna_find_function_def(func);
if (dfunc->call) {
if (first) {
fprintf(f, "/* Repeated prototypes to detect errors */\n\n");
first = 0;
}
rna_generate_static_parameter_prototypes(f, srna, dfunc, NULL, 1);
}
}
fprintf(f, "\n");
}
static void rna_generate_struct_prototypes(FILE *f)
{
StructDefRNA *ds;
PropertyDefRNA *dp;
FunctionDefRNA *dfunc;
const char *structures[2048];
int all_structures = 0;
/* structures definitions */
for (ds = DefRNA.structs.first; ds; ds = ds->cont.next) {
for (dfunc = ds->functions.first; dfunc; dfunc = dfunc->cont.next) {
if (dfunc->call) {
for (dp = dfunc->cont.properties.first; dp; dp = dp->next) {
if (dp->prop->type == PROP_POINTER) {
int a, found = 0;
const char *struct_name = rna_parameter_type_name(dp->prop);
if (struct_name == NULL) {
printf("No struct found for property '%s'\n", dp->prop->identifier);
exit(1);
}
for (a = 0; a < all_structures; a++) {
if (STREQ(struct_name, structures[a])) {
found = 1;
break;
}
}
if (found == 0) {
fprintf(f, "struct %s;\n", struct_name);
if (all_structures >= sizeof(structures) / sizeof(structures[0])) {
printf("Array size to store all structures names is too small\n");
exit(1);
}
structures[all_structures++] = struct_name;
}
}
}
}
}
}
fprintf(f, "\n");
}
static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, PropertyRNA *prop)
{
char *strnest = (char *)"", *errnest = (char *)"";
int len, freenest = 0;
if (nest != NULL) {
len = strlen(nest);
strnest = MEM_mallocN(sizeof(char) * (len + 2), "rna_generate_property -> strnest");
errnest = MEM_mallocN(sizeof(char) * (len + 2), "rna_generate_property -> errnest");
strcpy(strnest, "_"); strcat(strnest, nest);
strcpy(errnest, "."); strcat(errnest, nest);
freenest = 1;
}
switch (prop->type) {
case PROP_ENUM:
{
EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
int i, defaultfound = 0, totflag = 0;
if (eprop->item) {
fprintf(f, "static const EnumPropertyItem rna_%s%s_%s_items[%d] = {\n\t", srna->identifier,
strnest, prop->identifier, eprop->totitem + 1);
for (i = 0; i < eprop->totitem; i++) {
fprintf(f, "{%d, ", eprop->item[i].value);
rna_print_c_string(f, eprop->item[i].identifier); fprintf(f, ", ");
fprintf(f, "%d, ", eprop->item[i].icon);
rna_print_c_string(f, eprop->item[i].name); fprintf(f, ", ");
rna_print_c_string(f, eprop->item[i].description); fprintf(f, "},\n\t");
if (eprop->item[i].identifier[0]) {
if (prop->flag & PROP_ENUM_FLAG) {
totflag |= eprop->item[i].value;
}
else {
if (eprop->defaultvalue == eprop->item[i].value) {
defaultfound = 1;
}
}
}
}
fprintf(f, "{0, NULL, 0, NULL, NULL}\n};\n\n");
if (prop->flag & PROP_ENUM_FLAG) {
if (eprop->defaultvalue & ~totflag) {
fprintf(stderr, "%s: %s%s.%s, enum default includes unused bits (%d).\n",
__func__, srna->identifier, errnest, prop->identifier,
eprop->defaultvalue & ~totflag);
DefRNA.error = 1;
}
}
else {
if (!defaultfound) {
fprintf(stderr, "%s: %s%s.%s, enum default is not in items.\n",
__func__, srna->identifier, errnest, prop->identifier);
DefRNA.error = 1;
}
}
}
else {
fprintf(stderr, "%s: %s%s.%s, enum must have items defined.\n",
__func__, srna->identifier, errnest, prop->identifier);
DefRNA.error = 1;
}
break;
}
case PROP_BOOLEAN:
{
BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
unsigned int i;
if (prop->arraydimension && prop->totarraylength) {
fprintf(f, "static bool rna_%s%s_%s_default[%u] = {\n\t", srna->identifier, strnest,
prop->identifier, prop->totarraylength);
for (i = 0; i < prop->totarraylength; i++) {
if (bprop->defaultarray)
fprintf(f, "%d", bprop->defaultarray[i]);
else
fprintf(f, "%d", bprop->defaultvalue);
if (i != prop->totarraylength - 1)
fprintf(f, ",\n\t");
}
fprintf(f, "\n};\n\n");
}
break;
}
case PROP_INT:
{
IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
unsigned int i;
if (prop->arraydimension && prop->totarraylength) {
fprintf(f, "static int rna_%s%s_%s_default[%u] = {\n\t", srna->identifier, strnest,
prop->identifier, prop->totarraylength);
for (i = 0; i < prop->totarraylength; i++) {
if (iprop->defaultarray)
fprintf(f, "%d", iprop->defaultarray[i]);
else
fprintf(f, "%d", iprop->defaultvalue);
if (i != prop->totarraylength - 1)
fprintf(f, ",\n\t");
}
fprintf(f, "\n};\n\n");
}
break;
}
case PROP_FLOAT:
{
FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
unsigned int i;
if (prop->arraydimension && prop->totarraylength) {
fprintf(f, "static float rna_%s%s_%s_default[%u] = {\n\t", srna->identifier, strnest,
prop->identifier, prop->totarraylength);
for (i = 0; i < prop->totarraylength; i++) {
if (fprop->defaultarray)
rna_float_print(f, fprop->defaultarray[i]);
else
rna_float_print(f, fprop->defaultvalue);
if (i != prop->totarraylength - 1)
fprintf(f, ",\n\t");
}
fprintf(f, "\n};\n\n");
}
break;
}
default:
break;
}
fprintf(f, "%s%s rna_%s%s_%s = {\n",
(prop->flag & PROP_EXPORT) ? "" : "",
rna_property_structname(prop->type),
srna->identifier, strnest, prop->identifier);
if (prop->next) fprintf(f, "\t{(PropertyRNA *)&rna_%s%s_%s, ", srna->identifier, strnest, prop->next->identifier);
else fprintf(f, "\t{NULL, ");
if (prop->prev) fprintf(f, "(PropertyRNA *)&rna_%s%s_%s,\n", srna->identifier, strnest, prop->prev->identifier);
else fprintf(f, "NULL,\n");
fprintf(f, "\t%d, ", prop->magic);
rna_print_c_string(f, prop->identifier);
fprintf(f, ", %d, %d, %d, %d, ", prop->flag, prop->flag_parameter, prop->flag_internal, prop->tags);
rna_print_c_string(f, prop->name); fprintf(f, ",\n\t");
rna_print_c_string(f, prop->description); fprintf(f, ",\n\t");
fprintf(f, "%d, ", prop->icon);
rna_print_c_string(f, prop->translation_context); fprintf(f, ",\n");
fprintf(f, "\t%s, %s | %s, %s, %u, {%u, %u, %u}, %u,\n",
RNA_property_typename(prop->type),
rna_property_subtypename(prop->subtype),
rna_property_subtype_unit(prop->subtype),
rna_function_string(prop->getlength),
prop->arraydimension,
prop->arraylength[0],
prop->arraylength[1],
prop->arraylength[2],
prop->totarraylength);
fprintf(f, "\t%s%s, %d, %s, %s,\n",
(prop->flag & PROP_CONTEXT_UPDATE) ? "(UpdateFunc)" : "",
rna_function_string(prop->update),
prop->noteflag,
rna_function_string(prop->editable),
rna_function_string(prop->itemeditable));
if (prop->flag_internal & PROP_INTERN_RAW_ACCESS) rna_set_raw_offset(f, srna, prop);
else fprintf(f, "\t0, -1");
/* our own type - collections/arrays only */
if (prop->srna) fprintf(f, ", &RNA_%s", (const char *)prop->srna);
else fprintf(f, ", NULL");
fprintf(f, "},\n");
switch (prop->type) {
case PROP_BOOLEAN:
{
BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
fprintf(f, "\t%s, %s, %s, %s, %s, %s, %s, %s, %d, ",
rna_function_string(bprop->get),
rna_function_string(bprop->set),
rna_function_string(bprop->getarray),
rna_function_string(bprop->setarray),
rna_function_string(bprop->get_ex),
rna_function_string(bprop->set_ex),
rna_function_string(bprop->getarray_ex),
rna_function_string(bprop->setarray_ex),
bprop->defaultvalue);
if (prop->arraydimension && prop->totarraylength)
fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier);
else fprintf(f, "NULL\n");
break;
}
case PROP_INT:
{
IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
fprintf(f, "\t%s, %s, %s, %s, %s, %s, %s, %s, %s, %s,\n\t",
rna_function_string(iprop->get),
rna_function_string(iprop->set),
rna_function_string(iprop->getarray),
rna_function_string(iprop->setarray),
rna_function_string(iprop->range),
rna_function_string(iprop->get_ex),
rna_function_string(iprop->set_ex),
rna_function_string(iprop->getarray_ex),
rna_function_string(iprop->setarray_ex),
rna_function_string(iprop->range_ex));
rna_int_print(f, iprop->softmin); fprintf(f, ", ");
rna_int_print(f, iprop->softmax); fprintf(f, ", ");
rna_int_print(f, iprop->hardmin); fprintf(f, ", ");
rna_int_print(f, iprop->hardmax); fprintf(f, ", ");
rna_int_print(f, iprop->step); fprintf(f, ", ");
rna_int_print(f, iprop->defaultvalue); fprintf(f, ", ");
if (prop->arraydimension && prop->totarraylength)
fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier);
else fprintf(f, "NULL\n");
break;
}
case PROP_FLOAT:
{
FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
fprintf(f, "\t%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, ",
rna_function_string(fprop->get),
rna_function_string(fprop->set),
rna_function_string(fprop->getarray),
rna_function_string(fprop->setarray),
rna_function_string(fprop->range),
rna_function_string(fprop->get_ex),
rna_function_string(fprop->set_ex),
rna_function_string(fprop->getarray_ex),
rna_function_string(fprop->setarray_ex),
rna_function_string(fprop->range_ex));
rna_float_print(f, fprop->softmin); fprintf(f, ", ");
rna_float_print(f, fprop->softmax); fprintf(f, ", ");
rna_float_print(f, fprop->hardmin); fprintf(f, ", ");
rna_float_print(f, fprop->hardmax); fprintf(f, ", ");
rna_float_print(f, fprop->step); fprintf(f, ", ");
rna_int_print(f, (int)fprop->precision); fprintf(f, ", ");
rna_float_print(f, fprop->defaultvalue); fprintf(f, ", ");
if (prop->arraydimension && prop->totarraylength)
fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier);
else fprintf(f, "NULL\n");
break;
}
case PROP_STRING:
{
StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
fprintf(f, "\t%s, %s, %s, %s, %s, %s, %d, ",
rna_function_string(sprop->get),
rna_function_string(sprop->length),
rna_function_string(sprop->set),
rna_function_string(sprop->get_ex),
rna_function_string(sprop->length_ex),
rna_function_string(sprop->set_ex),
sprop->maxlength);
rna_print_c_string(f, sprop->defaultvalue); fprintf(f, "\n");
break;
}
case PROP_ENUM:
{
EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
fprintf(f, "\t%s, %s, %s, %s, %s, NULL, ",
rna_function_string(eprop->get),
rna_function_string(eprop->set),
rna_function_string(eprop->itemf),
rna_function_string(eprop->get_ex),
rna_function_string(eprop->set_ex));
if (eprop->item)
fprintf(f, "rna_%s%s_%s_items, ", srna->identifier, strnest, prop->identifier);
else
fprintf(f, "NULL, ");
fprintf(f, "%d, %d\n", eprop->totitem, eprop->defaultvalue);
break;
}
case PROP_POINTER:
{
PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop;
fprintf(f, "\t%s, %s, %s, %s,", rna_function_string(pprop->get),
rna_function_string(pprop->set),
rna_function_string(pprop->typef),
rna_function_string(pprop->poll));
if (pprop->type) fprintf(f, "&RNA_%s\n", (const char *)pprop->type);
else fprintf(f, "NULL\n");
break;
}
case PROP_COLLECTION:
{
CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop;
fprintf(f, "\t%s, %s, %s, %s, %s, %s, %s, %s, ",
rna_function_string(cprop->begin),
rna_function_string(cprop->next),
rna_function_string(cprop->end),
rna_function_string(cprop->get),
rna_function_string(cprop->length),
rna_function_string(cprop->lookupint),
rna_function_string(cprop->lookupstring),
rna_function_string(cprop->assignint));
if (cprop->item_type) fprintf(f, "&RNA_%s\n", (const char *)cprop->item_type);
else fprintf(f, "NULL\n");
break;
}
}
fprintf(f, "};\n\n");
if (freenest) {
MEM_freeN(strnest);
MEM_freeN(errnest);
}
}
static void rna_generate_struct(BlenderRNA *UNUSED(brna), StructRNA *srna, FILE *f)
{
FunctionRNA *func;
FunctionDefRNA *dfunc;
PropertyRNA *prop, *parm;
StructRNA *base;
fprintf(f, "/* %s */\n", srna->name);
for (prop = srna->cont.properties.first; prop; prop = prop->next)
rna_generate_property(f, srna, NULL, prop);
for (func = srna->functions.first; func; func = func->cont.next) {
for (parm = func->cont.properties.first; parm; parm = parm->next)
rna_generate_property(f, srna, func->identifier, parm);
fprintf(f, "%s%s rna_%s_%s_func = {\n", "", "FunctionRNA", srna->identifier, func->identifier);
if (func->cont.next)
fprintf(f, "\t{(FunctionRNA *)&rna_%s_%s_func, ", srna->identifier,
((FunctionRNA *)func->cont.next)->identifier);
else
fprintf(f, "\t{NULL, ");
if (func->cont.prev)
fprintf(f, "(FunctionRNA *)&rna_%s_%s_func,\n", srna->identifier,
((FunctionRNA *)func->cont.prev)->identifier);
else
fprintf(f, "NULL,\n");
fprintf(f, "\tNULL,\n");
parm = func->cont.properties.first;
if (parm) fprintf(f, "\t{(PropertyRNA *)&rna_%s_%s_%s, ", srna->identifier, func->identifier, parm->identifier);
else fprintf(f, "\t{NULL, ");
parm = func->cont.properties.last;
if (parm) fprintf(f, "(PropertyRNA *)&rna_%s_%s_%s}},\n", srna->identifier, func->identifier, parm->identifier);
else fprintf(f, "NULL}},\n");
fprintf(f, "\t");
rna_print_c_string(f, func->identifier);
fprintf(f, ", %d, ", func->flag);
rna_print_c_string(f, func->description); fprintf(f, ",\n");
dfunc = rna_find_function_def(func);
if (dfunc->gencall) fprintf(f, "\t%s,\n", dfunc->gencall);
else fprintf(f, "\tNULL,\n");
if (func->c_ret)
fprintf(f, "\t(PropertyRNA *)&rna_%s_%s_%s\n", srna->identifier, func->identifier, func->c_ret->identifier);
else
fprintf(f, "\tNULL\n");
fprintf(f, "};\n");
fprintf(f, "\n");
}
fprintf(f, "StructRNA RNA_%s = {\n", srna->identifier);
if (srna->cont.next) fprintf(f, "\t{(ContainerRNA *)&RNA_%s, ", ((StructRNA *)srna->cont.next)->identifier);
else fprintf(f, "\t{NULL, ");
if (srna->cont.prev) fprintf(f, "(ContainerRNA *)&RNA_%s,\n", ((StructRNA *)srna->cont.prev)->identifier);
else fprintf(f, "NULL,\n");
fprintf(f, "\tNULL,\n");
prop = srna->cont.properties.first;
if (prop) fprintf(f, "\t{(PropertyRNA *)&rna_%s_%s, ", srna->identifier, prop->identifier);
else fprintf(f, "\t{NULL, ");
prop = srna->cont.properties.last;
if (prop) fprintf(f, "(PropertyRNA *)&rna_%s_%s}},\n", srna->identifier, prop->identifier);
else fprintf(f, "NULL}},\n");
fprintf(f, "\t");
rna_print_c_string(f, srna->identifier);
fprintf(f, ", NULL, NULL"); /* PyType - Cant initialize here */
fprintf(f, ", %d, NULL, ", srna->flag);
rna_print_c_string(f, srna->name);
fprintf(f, ",\n\t");
rna_print_c_string(f, srna->description);
fprintf(f, ",\n\t");
rna_print_c_string(f, srna->translation_context);
fprintf(f, ", %d,\n", srna->icon);
prop = srna->nameproperty;
if (prop) {
base = srna;
while (base->base && base->base->nameproperty == prop)
base = base->base;
fprintf(f, "\t(PropertyRNA *)&rna_%s_%s, ", base->identifier, prop->identifier);
}
else {
fprintf(f, "\tNULL, ");
}
prop = srna->iteratorproperty;
base = srna;
while (base->base && base->base->iteratorproperty == prop)
base = base->base;
fprintf(f, "(PropertyRNA *)&rna_%s_rna_properties,\n", base->identifier);
if (srna->base) fprintf(f, "\t&RNA_%s,\n", srna->base->identifier);
else fprintf(f, "\tNULL,\n");
if (srna->nested) fprintf(f, "\t&RNA_%s,\n", srna->nested->identifier);
else fprintf(f, "\tNULL,\n");
fprintf(f, "\t%s,\n", rna_function_string(srna->refine));
fprintf(f, "\t%s,\n", rna_function_string(srna->path));
fprintf(f, "\t%s,\n", rna_function_string(srna->reg));
fprintf(f, "\t%s,\n", rna_function_string(srna->unreg));
fprintf(f, "\t%s,\n", rna_function_string(srna->instance));
fprintf(f, "\t%s,\n", rna_function_string(srna->idproperties));
if (srna->reg && !srna->refine) {
fprintf(stderr, "%s: %s has a register function, must also have refine function.\n",
__func__, srna->identifier);
DefRNA.error = 1;
}
func = srna->functions.first;
if (func) fprintf(f, "\t{(FunctionRNA *)&rna_%s_%s_func, ", srna->identifier, func->identifier);
else fprintf(f, "\t{NULL, ");
func = srna->functions.last;
if (func) fprintf(f, "(FunctionRNA *)&rna_%s_%s_func}\n", srna->identifier, func->identifier);
else fprintf(f, "NULL}\n");
fprintf(f, "};\n");
fprintf(f, "\n");
}
typedef struct RNAProcessItem {
const char *filename;
const char *api_filename;
void (*define)(BlenderRNA *brna);
} RNAProcessItem;
static RNAProcessItem PROCESS_ITEMS[] = {
{"rna_rna.c", NULL, RNA_def_rna},
{"rna_ID.c", NULL, RNA_def_ID},
{"rna_texture.c", "rna_texture_api.c", RNA_def_texture},
{"rna_action.c", "rna_action_api.c", RNA_def_action},
{"rna_animation.c", "rna_animation_api.c", RNA_def_animation},
{"rna_animviz.c", NULL, RNA_def_animviz},
{"rna_actuator.c", "rna_actuator_api.c", RNA_def_actuator},
{"rna_armature.c", "rna_armature_api.c", RNA_def_armature},
{"rna_boid.c", NULL, RNA_def_boid},
{"rna_brush.c", NULL, RNA_def_brush},
{"rna_cachefile.c", NULL, RNA_def_cachefile},
{"rna_camera.c", "rna_camera_api.c", RNA_def_camera},
{"rna_cloth.c", NULL, RNA_def_cloth},
{"rna_color.c", NULL, RNA_def_color},
{"rna_constraint.c", NULL, RNA_def_constraint},
{"rna_context.c", NULL, RNA_def_context},
{"rna_controller.c", "rna_controller_api.c", RNA_def_controller},
{"rna_curve.c", "rna_curve_api.c", RNA_def_curve},
{"rna_depsgraph.c", NULL, RNA_def_depsgraph},
{"rna_dynamicpaint.c", NULL, RNA_def_dynamic_paint},
{"rna_fcurve.c", "rna_fcurve_api.c", RNA_def_fcurve},
{"rna_fluidsim.c", NULL, RNA_def_fluidsim},
{"rna_gpencil.c", NULL, RNA_def_gpencil},
{"rna_group.c", NULL, RNA_def_group},
{"rna_image.c", "rna_image_api.c", RNA_def_image},
{"rna_key.c", NULL, RNA_def_key},
{"rna_lamp.c", NULL, RNA_def_lamp},
{"rna_lattice.c", "rna_lattice_api.c", RNA_def_lattice},
{"rna_linestyle.c", NULL, RNA_def_linestyle},
{"rna_main.c", "rna_main_api.c", RNA_def_main},
{"rna_material.c", "rna_material_api.c", RNA_def_material},
{"rna_mesh.c", "rna_mesh_api.c", RNA_def_mesh},
{"rna_meta.c", "rna_meta_api.c", RNA_def_meta},
{"rna_modifier.c", NULL, RNA_def_modifier},
{"rna_nla.c", NULL, RNA_def_nla},
{"rna_nodetree.c", NULL, RNA_def_nodetree},
{"rna_object.c", "rna_object_api.c", RNA_def_object},
{"rna_object_force.c", NULL, RNA_def_object_force},
{"rna_packedfile.c", NULL, RNA_def_packedfile},
{"rna_palette.c", NULL, RNA_def_palette},
{"rna_particle.c", NULL, RNA_def_particle},
{"rna_pose.c", "rna_pose_api.c", RNA_def_pose},
{"rna_property.c", NULL, RNA_def_gameproperty},
{"rna_render.c", NULL, RNA_def_render},
{"rna_rigidbody.c", NULL, RNA_def_rigidbody},
{"rna_scene.c", "rna_scene_api.c", RNA_def_scene},
{"rna_screen.c", NULL, RNA_def_screen},
{"rna_sculpt_paint.c", NULL, RNA_def_sculpt_paint},
{"rna_sensor.c", "rna_sensor_api.c", RNA_def_sensor},
{"rna_sequencer.c", "rna_sequencer_api.c", RNA_def_sequencer},
{"rna_smoke.c", NULL, RNA_def_smoke},
{"rna_space.c", "rna_space_api.c", RNA_def_space},
{"rna_speaker.c", NULL, RNA_def_speaker},
{"rna_test.c", NULL, RNA_def_test},
{"rna_text.c", "rna_text_api.c", RNA_def_text},
{"rna_timeline.c", NULL, RNA_def_timeline_marker},
{"rna_sound.c", "rna_sound_api.c", RNA_def_sound},
{"rna_ui.c", "rna_ui_api.c", RNA_def_ui},
{"rna_userdef.c", NULL, RNA_def_userdef},
{"rna_vfont.c", "rna_vfont_api.c", RNA_def_vfont},
{"rna_wm.c", "rna_wm_api.c", RNA_def_wm},
{"rna_world.c", NULL, RNA_def_world},
{"rna_movieclip.c", NULL, RNA_def_movieclip},
{"rna_tracking.c", NULL, RNA_def_tracking},
{"rna_mask.c", NULL, RNA_def_mask},
{NULL, NULL}
};
static void rna_generate(BlenderRNA *brna, FILE *f, const char *filename, const char *api_filename)
{
StructDefRNA *ds;
PropertyDefRNA *dp;
FunctionDefRNA *dfunc;
fprintf(f,
"\n"
"/* Automatically generated struct definitions for the Data API.\n"
" * Do not edit manually, changes will be overwritten. */\n\n"
"#define RNA_RUNTIME\n\n");
fprintf(f, "#include <float.h>\n");
fprintf(f, "#include <stdio.h>\n");
fprintf(f, "#include <limits.h>\n");
fprintf(f, "#include <string.h>\n\n");
fprintf(f, "#include <stddef.h>\n\n");
fprintf(f, "#include \"MEM_guardedalloc.h\"\n\n");
fprintf(f, "#include \"DNA_ID.h\"\n");
fprintf(f, "#include \"DNA_scene_types.h\"\n");
fprintf(f, "#include \"BLI_blenlib.h\"\n\n");
fprintf(f, "#include \"BLI_utildefines.h\"\n\n");
fprintf(f, "#include \"BKE_context.h\"\n");
fprintf(f, "#include \"BKE_library.h\"\n");
fprintf(f, "#include \"BKE_main.h\"\n");
fprintf(f, "#include \"BKE_report.h\"\n");
fprintf(f, "#include \"RNA_define.h\"\n");
fprintf(f, "#include \"RNA_types.h\"\n");
fprintf(f, "#include \"rna_internal.h\"\n\n");
/* include the generated prototypes header */
fprintf(f, "#include \"rna_prototypes_gen.h\"\n\n");
fprintf(f, "#include \"%s\"\n", filename);
if (api_filename)
fprintf(f, "#include \"%s\"\n", api_filename);
fprintf(f, "\n");
/* we want the included C files to have warnings enabled but for the generated code
* ignore unused-parameter warnings which are hard to prevent */
#if defined( __GNUC__) || defined(__clang__)
fprintf(f, "#pragma GCC diagnostic ignored \"-Wunused-parameter\"\n\n");
#endif
fprintf(f, "/* Autogenerated Functions */\n\n");
for (ds = DefRNA.structs.first; ds; ds = ds->cont.next) {
if (!filename || ds->filename == filename) {
rna_generate_property_prototypes(brna, ds->srna, f);
rna_generate_function_prototypes(brna, ds->srna, f);
}
}
for (ds = DefRNA.structs.first; ds; ds = ds->cont.next)
if (!filename || ds->filename == filename)
for (dp = ds->cont.properties.first; dp; dp = dp->next)
rna_def_property_funcs(f, ds->srna, dp);
for (ds = DefRNA.structs.first; ds; ds = ds->cont.next) {
if (!filename || ds->filename == filename) {
for (dp = ds->cont.properties.first; dp; dp = dp->next)
rna_def_property_wrapper_funcs(f, ds, dp);
for (dfunc = ds->functions.first; dfunc; dfunc = dfunc->cont.next) {
rna_def_function_wrapper_funcs(f, ds, dfunc);
rna_def_function_funcs(f, ds, dfunc);
}
rna_generate_static_function_prototypes(brna, ds->srna, f);
}
}
for (ds = DefRNA.structs.first; ds; ds = ds->cont.next)
if (!filename || ds->filename == filename)
rna_generate_struct(brna, ds->srna, f);
if (STREQ(filename, "rna_ID.c")) {
/* this is ugly, but we cannot have c files compiled for both
* makesrna and blender with some build systems at the moment */
fprintf(f, "#include \"rna_define.c\"\n\n");
rna_generate_blender(brna, f);
}
}
static void rna_generate_header(BlenderRNA *UNUSED(brna), FILE *f)
{
StructDefRNA *ds;
PropertyDefRNA *dp;
StructRNA *srna;
FunctionDefRNA *dfunc;
fprintf(f, "\n#ifndef __RNA_BLENDER_H__\n");
fprintf(f, "#define __RNA_BLENDER_H__\n\n");
fprintf(f,
"/* Automatically generated function declarations for the Data API.\n"
" * Do not edit manually, changes will be overwritten. */\n\n");
fprintf(f, "#include \"RNA_types.h\"\n\n");
fprintf(f, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n");
fprintf(f, "#define FOREACH_BEGIN(property, sptr, itemptr) \\\n");
fprintf(f, " { \\\n");
fprintf(f, " CollectionPropertyIterator rna_macro_iter; \\\n");
fprintf(f, " for (property##_begin(&rna_macro_iter, sptr); rna_macro_iter.valid; "
"property##_next(&rna_macro_iter)) { \\\n");
fprintf(f, " itemptr = rna_macro_iter.ptr;\n\n");
fprintf(f, "#define FOREACH_END(property) \\\n");
fprintf(f, " } \\\n");
fprintf(f, " property##_end(&rna_macro_iter); \\\n");
fprintf(f, " }\n\n");
for (ds = DefRNA.structs.first; ds; ds = ds->cont.next) {
srna = ds->srna;
fprintf(f, "/**************** %s ****************/\n\n", srna->name);
while (srna) {
fprintf(f, "extern StructRNA RNA_%s;\n", srna->identifier);
srna = srna->base;
}
fprintf(f, "\n");
for (dp = ds->cont.properties.first; dp; dp = dp->next)
rna_def_property_funcs_header(f, ds->srna, dp);
for (dfunc = ds->functions.first; dfunc; dfunc = dfunc->cont.next)
rna_def_function_funcs_header(f, ds->srna, dfunc);
}
fprintf(f, "#ifdef __cplusplus\n}\n#endif\n\n");
fprintf(f, "#endif /* __RNA_BLENDER_H__ */\n\n");
}
static const char *cpp_classes = ""
"\n"
"#include <string>\n"
"#include <string.h> /* for memcpy */\n"
"\n"
"namespace BL {\n"
"\n"
"#define BOOLEAN_PROPERTY(sname, identifier) \\\n"
" inline bool sname::identifier(void) { return sname##_##identifier##_get(&ptr) ? true: false; } \\\n"
" inline void sname::identifier(bool value) { sname##_##identifier##_set(&ptr, value); }\n"
"\n"
"#define BOOLEAN_ARRAY_PROPERTY(sname, size, identifier) \\\n"
" inline Array<bool, size> sname::identifier(void) \\\n"
" { Array<bool, size> ar; sname##_##identifier##_get(&ptr, ar.data); return ar; } \\\n"
" inline void sname::identifier(bool values[size]) \\\n"
" { sname##_##identifier##_set(&ptr, values); } \\\n"
"\n"
"#define BOOLEAN_DYNAMIC_ARRAY_PROPERTY(sname, identifier) \\\n"
" inline DynamicArray<bool> sname::identifier(void) { \\\n"
" int arraylen[3]; \\\n"
" int len = sname##_##identifier##_get_length(&ptr, arraylen); \\\n"
" DynamicArray<bool> ar(len); \\\n"
" sname##_##identifier##_get(&ptr, ar.data); \\\n"
" return ar; } \\\n"
" inline void sname::identifier(bool values[]) \\\n"
" { sname##_##identifier##_set(&ptr, values); } \\\n"
"\n"
"#define INT_PROPERTY(sname, identifier) \\\n"
" inline int sname::identifier(void) { return sname##_##identifier##_get(&ptr); } \\\n"
" inline void sname::identifier(int value) { sname##_##identifier##_set(&ptr, value); }\n"
"\n"
"#define INT_ARRAY_PROPERTY(sname, size, identifier) \\\n"
" inline Array<int, size> sname::identifier(void) \\\n"
" { Array<int, size> ar; sname##_##identifier##_get(&ptr, ar.data); return ar; } \\\n"
" inline void sname::identifier(int values[size]) \\\n"
" { sname##_##identifier##_set(&ptr, values); } \\\n"
"\n"
"#define INT_DYNAMIC_ARRAY_PROPERTY(sname, identifier) \\\n"
" inline DynamicArray<int> sname::identifier(void) { \\\n"
" int arraylen[3]; \\\n"
" int len = sname##_##identifier##_get_length(&ptr, arraylen); \\\n"
" DynamicArray<int> ar(len); \\\n"
" sname##_##identifier##_get(&ptr, ar.data); \\\n"
" return ar; } \\\n"
" inline void sname::identifier(int values[]) \\\n"
" { sname##_##identifier##_set(&ptr, values); } \\\n"
"\n"
"#define FLOAT_PROPERTY(sname, identifier) \\\n"
" inline float sname::identifier(void) { return sname##_##identifier##_get(&ptr); } \\\n"
" inline void sname::identifier(float value) { sname##_##identifier##_set(&ptr, value); }\n"
"\n"
"#define FLOAT_ARRAY_PROPERTY(sname, size, identifier) \\\n"
" inline Array<float, size> sname::identifier(void) \\\n"
" { Array<float, size> ar; sname##_##identifier##_get(&ptr, ar.data); return ar; } \\\n"
" inline void sname::identifier(float values[size]) \\\n"
" { sname##_##identifier##_set(&ptr, values); } \\\n"
"\n"
"#define FLOAT_DYNAMIC_ARRAY_PROPERTY(sname, identifier) \\\n"
" inline DynamicArray<float> sname::identifier(void) { \\\n"
" int arraylen[3]; \\\n"
" int len = sname##_##identifier##_get_length(&ptr, arraylen); \\\n"
" DynamicArray<float> ar(len); \\\n"
" sname##_##identifier##_get(&ptr, ar.data); \\\n"
" return ar; } \\\n"
" inline void sname::identifier(float values[]) \\\n"
" { sname##_##identifier##_set(&ptr, values); } \\\n"
"\n"
"#define ENUM_PROPERTY(type, sname, identifier) \\\n"
" inline sname::type sname::identifier(void) { return (type)sname##_##identifier##_get(&ptr); } \\\n"
" inline void sname::identifier(sname::type value) { sname##_##identifier##_set(&ptr, value); }\n"
"\n"
"#define STRING_PROPERTY(sname, identifier) \\\n"
" inline std::string sname::identifier(void) { \\\n"
" int len = sname##_##identifier##_length(&ptr); \\\n"
" std::string str; str.resize(len); \\\n"
" sname##_##identifier##_get(&ptr, &str[0]); return str; } \\\n"
" inline void sname::identifier(const std::string& value) { \\\n"
" sname##_##identifier##_set(&ptr, value.c_str()); } \\\n"
"\n"
"#define POINTER_PROPERTY(type, sname, identifier) \\\n"
" inline type sname::identifier(void) { return type(sname##_##identifier##_get(&ptr)); }\n"
"\n"
"#define COLLECTION_PROPERTY_LENGTH_false(sname, identifier) \\\n"
" inline static int sname##_##identifier##_length_wrap(PointerRNA *ptr) \\\n"
" { \\\n"
" CollectionPropertyIterator iter; \\\n"
" int length = 0; \\\n"
" sname##_##identifier##_begin(&iter, ptr); \\\n"
" while (iter.valid) { \\\n"
" sname##_##identifier##_next(&iter); \\\n"
" ++length; \\\n"
" } \\\n"
" sname##_##identifier##_end(&iter); \\\n"
" return length; \\\n"
" } \n"
"#define COLLECTION_PROPERTY_LENGTH_true(sname, identifier) \\\n"
" inline static int sname##_##identifier##_length_wrap(PointerRNA *ptr) \\\n"
" { return sname##_##identifier##_length(ptr); } \n"
"\n"
"#define COLLECTION_PROPERTY_LOOKUP_INT_false(sname, identifier) \\\n"
" inline static int sname##_##identifier##_lookup_int_wrap(PointerRNA *ptr, int key, PointerRNA *r_ptr) \\\n"
" { \\\n"
" CollectionPropertyIterator iter; \\\n"
" int i = 0, found = 0; \\\n"
" sname##_##identifier##_begin(&iter, ptr); \\\n"
" while (iter.valid) { \\\n"
" if (i == key) { \\\n"
" *r_ptr = iter.ptr; \\\n"
" found = 1; \\\n"
" break; \\\n"
" } \\\n"
" sname##_##identifier##_next(&iter); \\\n"
" ++i; \\\n"
" } \\\n"
" sname##_##identifier##_end(&iter); \\\n"
" if (!found) \\\n"
" memset(r_ptr, 0, sizeof(*r_ptr)); \\\n"
" return found; \\\n"
" } \n"
"#define COLLECTION_PROPERTY_LOOKUP_INT_true(sname, identifier) \\\n"
" inline static int sname##_##identifier##_lookup_int_wrap(PointerRNA *ptr, int key, PointerRNA *r_ptr) \\\n"
" { \\\n"
" int found = sname##_##identifier##_lookup_int(ptr, key, r_ptr); \\\n"
" if (!found) \\\n"
" memset(r_ptr, 0, sizeof(*r_ptr)); \\\n"
" return found; \\\n"
" } \n"
"#define COLLECTION_PROPERTY_LOOKUP_STRING_false(sname, identifier) \\\n"
" inline static int sname##_##identifier##_lookup_string_wrap(PointerRNA *ptr, const char *key, PointerRNA *r_ptr) \\\n"
" { \\\n"
" CollectionPropertyIterator iter; \\\n"
" int found = 0; \\\n"
" PropertyRNA *item_name_prop = RNA_struct_name_property(ptr->type); \\\n"
" sname##_##identifier##_begin(&iter, ptr); \\\n"
" while (iter.valid && !found) { \\\n"
" char name_fixed[32]; \\\n"
" const char *name; \\\n"
" int name_length; \\\n"
" name = RNA_property_string_get_alloc(&iter.ptr, item_name_prop, name_fixed, sizeof(name_fixed), &name_length); \\\n"
" if (!strncmp(name, key, name_length)) { \\\n"
" *r_ptr = iter.ptr; \\\n"
" found = 1; \\\n"
" } \\\n"
" if (name_fixed != name) \\\n"
" MEM_freeN((void *) name); \\\n"
" sname##_##identifier##_next(&iter); \\\n"
" } \\\n"
" sname##_##identifier##_end(&iter); \\\n"
" if (!found) \\\n"
" memset(r_ptr, 0, sizeof(*r_ptr)); \\\n"
" return found; \\\n"
" } \n"
"#define COLLECTION_PROPERTY_LOOKUP_STRING_true(sname, identifier) \\\n"
" inline static int sname##_##identifier##_lookup_string_wrap(PointerRNA *ptr, const char *key, PointerRNA *r_ptr) \\\n"
" { \\\n"
" int found = sname##_##identifier##_lookup_string(ptr, key, r_ptr); \\\n"
" if (!found) \\\n"
" memset(r_ptr, 0, sizeof(*r_ptr)); \\\n"
" return found; \\\n"
" } \n"
"#define COLLECTION_PROPERTY(collection_funcs, type, sname, identifier, has_length, has_lookup_int, has_lookup_string) \\\n"
" typedef CollectionIterator<type, sname##_##identifier##_begin, \\\n"
" sname##_##identifier##_next, sname##_##identifier##_end> identifier##_iterator; \\\n"
" COLLECTION_PROPERTY_LENGTH_##has_length(sname, identifier) \\\n"
" COLLECTION_PROPERTY_LOOKUP_INT_##has_lookup_int(sname, identifier) \\\n"
" COLLECTION_PROPERTY_LOOKUP_STRING_##has_lookup_string(sname, identifier) \\\n"
" Collection<sname, type, sname##_##identifier##_begin, \\\n"
" sname##_##identifier##_next, sname##_##identifier##_end, \\\n"
" sname##_##identifier##_length_wrap, \\\n"
" sname##_##identifier##_lookup_int_wrap, sname##_##identifier##_lookup_string_wrap, collection_funcs> identifier;\n"
"\n"
"class Pointer {\n"
"public:\n"
" Pointer(const PointerRNA &p) : ptr(p) { }\n"
" operator const PointerRNA&() { return ptr; }\n"
" bool is_a(StructRNA *type) { return RNA_struct_is_a(ptr.type, type) ? true: false; }\n"
" operator void*() { return ptr.data; }\n"
" operator bool() { return ptr.data != NULL; }\n"
"\n"
" PointerRNA ptr;\n"
"};\n"
"\n"
"\n"
"template<typename T, int Tsize>\n"
"class Array {\n"
"public:\n"
" T data[Tsize];\n"
"\n"
" Array() {}\n"
" Array(const Array<T, Tsize>& other) { memcpy(data, other.data, sizeof(T) * Tsize); }\n"
" const Array<T, Tsize>& operator = (const Array<T, Tsize>& other) { memcpy(data, other.data, sizeof(T) * Tsize); "
"return *this; }\n"
"\n"
" operator T*() { return data; }\n"
" operator const T*() const { return data; }\n"
"};\n"
"\n"
"template<typename T>\n"
"class DynamicArray {\n"
"public:\n"
" T *data;\n"
" int length;\n"
"\n"
" DynamicArray() : data(NULL), length(0) {}\n"
" DynamicArray(int new_length) : data(NULL), length(new_length) { data = (T *)malloc(sizeof(T) * new_length); }\n"
" DynamicArray(const DynamicArray<T>& other) { copy_from(other); }\n"
" const DynamicArray<T>& operator = (const DynamicArray<T>& other) { copy_from(other); return *this; }\n"
"\n"
" ~DynamicArray() { if (data) free(data); }\n"
"\n"
" operator T*() { return data; }\n"
"\n"
"protected:\n"
" void copy_from(const DynamicArray<T>& other) {\n"
" if (data) free(data);\n"
" data = (T *)malloc(sizeof(T) * other.length);\n"
" memcpy(data, other.data, sizeof(T) * other.length);\n"
" length = other.length;\n"
" }\n"
"};\n"
"\n"
"typedef void (*TBeginFunc)(CollectionPropertyIterator *iter, PointerRNA *ptr);\n"
"typedef void (*TNextFunc)(CollectionPropertyIterator *iter);\n"
"typedef void (*TEndFunc)(CollectionPropertyIterator *iter);\n"
"typedef int (*TLengthFunc)(PointerRNA *ptr);\n"
"typedef int (*TLookupIntFunc)(PointerRNA *ptr, int key, PointerRNA *r_ptr);\n"
"typedef int (*TLookupStringFunc)(PointerRNA *ptr, const char *key, PointerRNA *r_ptr);\n"
"\n"
"template<typename T, TBeginFunc Tbegin, TNextFunc Tnext, TEndFunc Tend>\n"
"class CollectionIterator {\n"
"public:\n"
" CollectionIterator() : iter(), t(iter.ptr), init(false) { iter.valid = false; }\n"
" ~CollectionIterator(void) { if (init) Tend(&iter); };\n"
"\n"
" operator bool(void)\n"
" { return iter.valid != 0; }\n"
" const CollectionIterator<T, Tbegin, Tnext, Tend>& operator++() { Tnext(&iter); t = T(iter.ptr); return *this; }\n"
"\n"
" T& operator*(void) { return t; }\n"
" T* operator->(void) { return &t; }\n"
" bool operator == (const CollectionIterator<T, Tbegin, Tnext, Tend>& other) "
"{ return iter.valid == other.iter.valid; }\n"
" bool operator!=(const CollectionIterator<T, Tbegin, Tnext, Tend>& other) "
"{ return iter.valid != other.iter.valid; }\n"
"\n"
" void begin(const Pointer &ptr)\n"
" { if (init) Tend(&iter); Tbegin(&iter, (PointerRNA *)&ptr.ptr); t = T(iter.ptr); init = true; }\n"
"\n"
"private:\n"
" const CollectionIterator<T, Tbegin, Tnext, Tend>& operator = "
"(const CollectionIterator<T, Tbegin, Tnext, Tend>& /*copy*/) {}\n"
""
" CollectionPropertyIterator iter;\n"
" T t;\n"
" bool init;\n"
"};\n"
"\n"
"template<typename Tp, typename T, TBeginFunc Tbegin, TNextFunc Tnext, TEndFunc Tend,\n"
" TLengthFunc Tlength, TLookupIntFunc Tlookup_int, TLookupStringFunc Tlookup_string,\n"
" typename Tcollection_funcs>\n"
"class Collection : public Tcollection_funcs {\n"
"public:\n"
" Collection(const PointerRNA &p) : Tcollection_funcs(p), ptr(p) {}\n"
"\n"
" void begin(CollectionIterator<T, Tbegin, Tnext, Tend>& iter)\n"
" { iter.begin(ptr); }\n"
" CollectionIterator<T, Tbegin, Tnext, Tend> end()\n"
" { return CollectionIterator<T, Tbegin, Tnext, Tend>(); } /* test */ \n"
""
" int length()\n"
" { return Tlength(&ptr); }\n"
" T operator[](int key)\n"
" { PointerRNA r_ptr; Tlookup_int(&ptr, key, &r_ptr); return T(r_ptr); }\n"
" T operator[](const std::string &key)\n"
" { PointerRNA r_ptr; Tlookup_string(&ptr, key.c_str(), &r_ptr); return T(r_ptr); }\n"
"\n"
"private:\n"
" PointerRNA ptr;\n"
"};\n"
"\n"
"class DefaultCollectionFunctions {\n"
"public:\n"
" DefaultCollectionFunctions(const PointerRNA & /*p*/) {}\n"
"};\n"
"\n"
"\n";
static int rna_is_collection_prop(PropertyRNA *prop)
{
if (!(prop->flag & PROP_IDPROPERTY || prop->flag_internal & PROP_INTERN_BUILTIN)) {
if (prop->type == PROP_COLLECTION) {
return 1;
}
}
return 0;
}
static int rna_is_collection_functions_struct(const char **collection_structs, const char *struct_name)
{
int a = 0, found = 0;
while (collection_structs[a]) {
if (STREQ(collection_structs[a], struct_name)) {
found = 1;
break;
}
a++;
}
return found;
}
static void rna_generate_header_class_cpp(StructDefRNA *ds, FILE *f)
{
StructRNA *srna = ds->srna;
PropertyDefRNA *dp;
FunctionDefRNA *dfunc;
fprintf(f, "/**************** %s ****************/\n\n", srna->name);
fprintf(f, "class %s : public %s {\n", srna->identifier, (srna->base) ? srna->base->identifier : "Pointer");
fprintf(f, "public:\n");
fprintf(f, "\t%s(const PointerRNA &ptr_arg) :\n\t\t%s(ptr_arg)", srna->identifier,
(srna->base) ? srna->base->identifier : "Pointer");
for (dp = ds->cont.properties.first; dp; dp = dp->next)
if (rna_is_collection_prop(dp->prop))
fprintf(f, ",\n\t\t%s(ptr_arg)", dp->prop->identifier);
fprintf(f, "\n\t\t{}\n\n");
for (dp = ds->cont.properties.first; dp; dp = dp->next)
rna_def_property_funcs_header_cpp(f, ds->srna, dp);
fprintf(f, "\n");
for (dfunc = ds->functions.first; dfunc; dfunc = dfunc->cont.next)
rna_def_struct_function_header_cpp(f, srna, dfunc);
fprintf(f, "};\n\n");
}
static void rna_generate_header_cpp(BlenderRNA *UNUSED(brna), FILE *f)
{
StructDefRNA *ds;
PropertyDefRNA *dp;
StructRNA *srna;
FunctionDefRNA *dfunc;
const char *first_collection_func_struct = NULL;
const char *collection_func_structs[256] = {NULL};
int all_collection_func_structs = 0;
int max_collection_func_structs = sizeof(collection_func_structs) / sizeof(collection_func_structs[0]) - 1;
fprintf(f, "\n#ifndef __RNA_BLENDER_CPP_H__\n");
fprintf(f, "#define __RNA_BLENDER_CPP_H__\n\n");
fprintf(f,
"/* Automatically generated classes for the Data API.\n"
" * Do not edit manually, changes will be overwritten. */\n\n");
fprintf(f, "#include \"RNA_blender.h\"\n");
fprintf(f, "#include \"RNA_types.h\"\n");
fprintf(f, "#include \"RNA_access.h\"\n");
fprintf(f, "%s", cpp_classes);
fprintf(f, "/**************** Declarations ****************/\n\n");
for (ds = DefRNA.structs.first; ds; ds = ds->cont.next) {
fprintf(f, "class %s;\n", ds->srna->identifier);
}
fprintf(f, "\n");
/* first get list of all structures used as collection functions, so they'll be declared first */
for (ds = DefRNA.structs.first; ds; ds = ds->cont.next) {
for (dp = ds->cont.properties.first; dp; dp = dp->next) {
if (rna_is_collection_prop(dp->prop)) {
PropertyRNA *prop = dp->prop;
if (prop->srna) {
/* store name of structure which first uses custom functions for collections */
if (first_collection_func_struct == NULL)
first_collection_func_struct = ds->srna->identifier;
if (!rna_is_collection_functions_struct(collection_func_structs, (char *)prop->srna)) {
if (all_collection_func_structs >= max_collection_func_structs) {
printf("Array size to store all collection structures names is too small\n");
exit(1);
}
collection_func_structs[all_collection_func_structs++] = (char *)prop->srna;
}
}
}
}
}
/* declare all structures in such order:
* - first N structures which doesn't use custom functions for collections
* - all structures used for custom functions in collections
* - all the rest structures
* such an order prevents usage of non-declared classes
*/
for (ds = DefRNA.structs.first; ds; ds = ds->cont.next) {
srna = ds->srna;
if (STREQ(srna->identifier, first_collection_func_struct)) {
StructDefRNA *ds2;
StructRNA *srna2;
for (ds2 = DefRNA.structs.first; ds2; ds2 = ds2->cont.next) {
srna2 = ds2->srna;
if (rna_is_collection_functions_struct(collection_func_structs, srna2->identifier)) {
rna_generate_header_class_cpp(ds2, f);
}
}
}
if (!rna_is_collection_functions_struct(collection_func_structs, srna->identifier))
rna_generate_header_class_cpp(ds, f);
}
fprintf(f, "} /* namespace BL */\n");
fprintf(f, "\n");
fprintf(f, "/**************** Implementation ****************/\n");
fprintf(f, "\n");
fprintf(f, "/* Structure prototypes */\n\n");
fprintf(f, "extern \"C\" {\n");
rna_generate_struct_prototypes(f);
fprintf(f, "}\n\n");
fprintf(f, "namespace BL {\n");
for (ds = DefRNA.structs.first; ds; ds = ds->cont.next) {
srna = ds->srna;
for (dp = ds->cont.properties.first; dp; dp = dp->next)
rna_def_property_funcs_impl_cpp(f, ds->srna, dp);
fprintf(f, "\n");
for (dfunc = ds->functions.first; dfunc; dfunc = dfunc->cont.next)
rna_def_struct_function_impl_cpp(f, srna, dfunc);
fprintf(f, "\n");
}
fprintf(f, "}\n\n#endif /* __RNA_BLENDER_CPP_H__ */\n\n");
}
static void make_bad_file(const char *file, int line)
{
FILE *fp = fopen(file, "w");
fprintf(fp,
"#error \"Error! can't make correct RNA file from %s:%d, "
"check DNA properties.\"\n",
__FILE__, line);
fclose(fp);
}
static int rna_preprocess(const char *outfile)
{
BlenderRNA *brna;
StructDefRNA *ds;
FILE *file;
char deffile[4096];
int i, status;
const char *deps[3]; /* expand as needed */
/* define rna */
brna = RNA_create();
for (i = 0; PROCESS_ITEMS[i].filename; i++) {
if (PROCESS_ITEMS[i].define) {
PROCESS_ITEMS[i].define(brna);
/* sanity check */
if (!DefRNA.animate) {
fprintf(stderr,
"Error: DefRNA.animate left disabled in %s\n",
PROCESS_ITEMS[i].filename);
}
for (ds = DefRNA.structs.first; ds; ds = ds->cont.next)
if (!ds->filename)
ds->filename = PROCESS_ITEMS[i].filename;
}
}
rna_auto_types();
status = (DefRNA.error != 0);
/* create rna prototype header file */
strcpy(deffile, outfile);
strcat(deffile, "rna_prototypes_gen.h");
if (status) {
make_bad_file(deffile, __LINE__);
}
file = fopen(deffile, "w");
if (!file) {
fprintf(stderr, "Unable to open file: %s\n", deffile);
status = 1;
}
else {
fprintf(file,
"/* Automatically generated function declarations for the Data API.\n"
" * Do not edit manually, changes will be overwritten. */\n\n");
rna_generate_prototypes(brna, file);
fclose(file);
status = (DefRNA.error != 0);
}
/* create rna_gen_*.c files */
for (i = 0; PROCESS_ITEMS[i].filename; i++) {
strcpy(deffile, outfile);
strcat(deffile, PROCESS_ITEMS[i].filename);
deffile[strlen(deffile) - 2] = '\0';
strcat(deffile, "_gen.c" TMP_EXT);
if (status) {
make_bad_file(deffile, __LINE__);
}
else {
file = fopen(deffile, "w");
if (!file) {
fprintf(stderr, "Unable to open file: %s\n", deffile);
status = 1;
}
else {
rna_generate(brna, file, PROCESS_ITEMS[i].filename, PROCESS_ITEMS[i].api_filename);
fclose(file);
status = (DefRNA.error != 0);
}
}
/* avoid unneeded rebuilds */
deps[0] = PROCESS_ITEMS[i].filename;
deps[1] = PROCESS_ITEMS[i].api_filename;
deps[2] = NULL;
replace_if_different(deffile, deps);
}
/* create RNA_blender_cpp.h */
strcpy(deffile, outfile);
strcat(deffile, "RNA_blender_cpp.h" TMP_EXT);
if (status) {
make_bad_file(deffile, __LINE__);
}
else {
file = fopen(deffile, "w");
if (!file) {
fprintf(stderr, "Unable to open file: %s\n", deffile);
status = 1;
}
else {
rna_generate_header_cpp(brna, file);
fclose(file);
status = (DefRNA.error != 0);
}
}
replace_if_different(deffile, NULL);
rna_sort(brna);
/* create RNA_blender.h */
strcpy(deffile, outfile);
strcat(deffile, "RNA_blender.h" TMP_EXT);
if (status) {
make_bad_file(deffile, __LINE__);
}
else {
file = fopen(deffile, "w");
if (!file) {
fprintf(stderr, "Unable to open file: %s\n", deffile);
status = 1;
}
else {
rna_generate_header(brna, file);
fclose(file);
status = (DefRNA.error != 0);
}
}
replace_if_different(deffile, NULL);
/* free RNA */
RNA_define_free(brna);
RNA_free(brna);
return status;
}
static void mem_error_cb(const char *errorStr)
{
fprintf(stderr, "%s", errorStr);
fflush(stderr);
}
int main(int argc, char **argv)
{
int totblock, return_status = 0;
if (argc < 2) {
fprintf(stderr, "Usage: %s outdirectory/\n", argv[0]);
return_status = 1;
}
else {
if (debugSRNA > 0) {
fprintf(stderr, "Running makesrna\n");
}
makesrna_path = argv[0];
return_status = rna_preprocess(argv[1]);
}
totblock = MEM_get_memory_blocks_in_use();
if (totblock != 0) {
fprintf(stderr, "Error Totblock: %d\n", totblock);
MEM_set_error_callback(mem_error_cb);
MEM_printmemlist();
}
return return_status;
}
|