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
|
{
This file is part of the Free Component Library
Pascal parse tree classes
Copyright (c) 2000-2005 by
Areca Systems GmbH / Sebastian Guenther, sg@freepascal.org
See the file COPYING.FPC, included in this distribution,
for details about the copyright.
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.
**********************************************************************}
{$mode objfpc}
{$h+}
unit PasTree;
interface
uses Classes;
resourcestring
// Parse tree node type names
SPasTreeElement = 'generic element';
SPasTreeSection = 'unit section';
SPasTreeModule = 'module';
SPasTreePackage = 'package';
SPasTreeResString = 'resource string';
SPasTreeType = 'generic type';
SPasTreePointerType = 'pointer type';
SPasTreeAliasType = 'alias type';
SPasTreeTypeAliasType = '"type" alias type';
SPasTreeClassOfType = '"class of" type';
SPasTreeRangeType = 'range type';
SPasTreeArrayType = 'array type';
SPasTreeFileType = 'file type';
SPasTreeEnumValue = 'enumeration value';
SPasTreeEnumType = 'enumeration type';
SPasTreeSetType = 'set type';
SPasTreeRecordType = 'record type';
SPasTreeObjectType = 'object';
SPasTreeClassType = 'class';
SPasTreeInterfaceType = 'interface';
SPasTreeArgument = 'argument';
SPasTreeProcedureType = 'procedure type';
SPasTreeResultElement = 'function result';
SPasTreeConstructorType = 'constructor type';
SPasTreeDestructorType = 'destructor type';
SPasTreeFunctionType = 'function type';
SPasTreeUnresolvedTypeRef = 'unresolved type reference';
SPasTreeVariable = 'variable';
SPasTreeConst = 'constant';
SPasTreeProperty = 'property';
SPasTreeOverloadedProcedure = 'overloaded procedure';
SPasTreeProcedure = 'procedure';
SPasTreeFunction = 'function';
SPasTreeClassProcedure = 'class procedure';
SPasTreeClassFunction = 'class function';
SPasTreeConstructor = 'constructor';
SPasTreeDestructor = 'destructor';
SPasTreeProcedureImpl = 'procedure/function implementation';
SPasTreeConstructorImpl = 'constructor implementation';
SPasTreeDestructorImpl = 'destructor implementation';
type
// Visitor pattern.
TPassTreeVisitor = class;
TPasElementBase = class
procedure Accept(Visitor: TPassTreeVisitor); virtual; abstract;
end;
TPasModule = class;
TPasMemberVisibility = (visDefault, visPrivate, visProtected, visPublic,
visPublished, visAutomated,
visStrictPrivate, visStrictProtected);
TCallingConvention = (ccDefault,ccRegister,ccPascal,ccCDecl,ccStdCall,ccOldFPCCall,ccSafeCall);
TPasMemberVisibilities = set of TPasMemberVisibility;
TPasMemberHint = (hDeprecated,hLibrary,hPlatform,hExperimental,hUnimplemented);
TPasMemberHints = set of TPasMemberHint;
TPTreeElement = class of TPasElement;
{ TPasElement }
TPasElement = class(TPasElementBase)
private
FRefCount: LongWord;
FName: string;
FParent: TPasElement;
FHints : TPasMemberHints;
protected
procedure ProcessHints(const ASemiColonPrefix: boolean; var AResult: string); virtual;
public
SourceFilename: string;
SourceLinenumber: Integer;
Visibility: TPasMemberVisibility;
public
constructor Create(const AName: string; AParent: TPasElement); virtual;
procedure AddRef;
procedure Release;
function FullName: string; // Name including parent's names
function PathName: string; // = Module.Name + FullName
function GetModule: TPasModule;
function ElementTypeName: string; virtual;
function GetDeclaration(full : Boolean) : string; virtual;
procedure Accept(Visitor: TPassTreeVisitor); override;
property RefCount: LongWord read FRefCount;
property Name: string read FName write FName;
property Parent: TPasElement read FParent;
Property Hints : TPasMemberHints Read FHints Write FHints;
end;
TPasExprKind = (pekIdent, pekNumber, pekString, pekSet, pekNil, pekBoolConst, pekRange,
pekUnary, pekBinary, pekFuncParams, pekArrayParams, pekListOfExp, pekInherited, pekSelf);
TExprOpCode = (eopNone,
eopAdd,eopSubtract,eopMultiply,eopDivide, eopDiv,eopMod, eopPower,// arithmetic
eopShr,eopSHl, // bit operations
eopNot,eopAnd,eopOr,eopXor, // logical/bit
eopEqual, eopNotEqual, // Logical
eopLessThan,eopGreaterThan, eopLessthanEqual,eopGreaterThanEqual, // ordering
eopIn,eopIs,eopAs, eopSymmetricaldifference, // Specials
eopAddress, eopDeref, // Pointers
eopSubIdent); // SomeRec.A, A is subIdent of SomeRec
{ TPasExpr }
TPasExpr = class(TPasElement)
Kind : TPasExprKind;
OpCode : TexprOpcode;
constructor Create(AParent : TPasElement; AKind: TPasExprKind; AOpCode: TexprOpcode); virtual; overload;
end;
TUnaryExpr = class(TPasExpr)
Operand : TPasExpr;
constructor Create(AParent : TPasElement; AOperand: TPasExpr; AOpCode: TExprOpCode); overload;
function GetDeclaration(full : Boolean) : string; override;
destructor Destroy; override;
end;
{ TBinaryExpr }
TBinaryExpr = class(TPasExpr)
left : TPasExpr;
right : TPasExpr;
constructor Create(AParent : TPasElement; xleft, xright: TPasExpr; AOpCode: TExprOpCode); overload;
constructor CreateRange(AParent : TPasElement; xleft, xright: TPasExpr); overload;
function GetDeclaration(full : Boolean) : string; override;
destructor Destroy; override;
end;
TPrimitiveExpr = class(TPasExpr)
Value : AnsiString;
constructor Create(AParent : TPasElement; AKind: TPasExprKind; const AValue : Ansistring); overload;
function GetDeclaration(full : Boolean) : string; override;
end;
TBoolConstExpr = class(TPasExpr)
Value : Boolean;
constructor Create(AParent : TPasElement; AKind: TPasExprKind; const ABoolValue : Boolean); overload;
function GetDeclaration(full : Boolean) : string; override;
end;
{ TNilExpr }
TNilExpr = class(TPasExpr)
constructor Create(AParent : TPasElement); overload;
function GetDeclaration(full : Boolean) : string; override;
end;
{ TInheritedExpr }
TInheritedExpr = class(TPasExpr)
constructor Create(AParent : TPasElement); overload;
function GetDeclaration(full : Boolean) : string; override;
end;
{ TSelfExpr }
TSelfExpr = class(TPasExpr)
constructor Create(AParent : TPasElement); overload;
function GetDeclaration(full : Boolean) : string; override;
end;
{ TParamsExpr }
TParamsExpr = class(TPasExpr)
Value : TPasExpr;
Params : array of TPasExpr;
{pekArray, pekFuncCall, pekSet}
constructor Create(AParent : TPasElement; AKind: TPasExprKind); overload;
function GetDeclaration(full : Boolean) : string; override;
destructor Destroy; override;
procedure AddParam(xp: TPasExpr);
end;
{ TRecordValues }
TRecordValuesItem = record
Name : AnsiString;
ValueExp : TPasExpr;
end;
TRecordValues = class(TPasExpr)
Fields : array of TRecordValuesItem;
constructor Create(AParent : TPasElement); overload;
destructor Destroy; override;
procedure AddField(const AName: AnsiString; Value: TPasExpr);
function GetDeclaration(full : Boolean) : string; override;
end;
{ TArrayValues }
TArrayValues = class(TPasExpr)
Values : array of TPasExpr;
constructor Create(AParent : TPasElement); overload;
destructor Destroy; override;
procedure AddValues(AValue: TPasExpr);
function GetDeclaration(full : Boolean) : string; override;
end;
{ TPasDeclarations }
TPasDeclarations = class(TPasElement)
public
constructor Create(const AName: string; AParent: TPasElement); override;
destructor Destroy; override;
function ElementTypeName: string; override;
public
Declarations, ResStrings, Types, Consts, Classes,
Functions, Variables, Properties: TList;
end;
{ TPasSection }
TPasSection = class(TPasDeclarations)
public
constructor Create(const AName: string; AParent: TPasElement); override;
destructor Destroy; override;
procedure AddUnitToUsesList(const AUnitName: string);
public
UsesList: TList; // TPasUnresolvedTypeRef or TPasModule elements
end;
{ TInterfaceSection }
TInterfaceSection = class(TPasSection)
end;
{ TImplementationSection }
TImplementationSection = class(TPasSection)
end;
TProgramSection = class(TPasSection)
end;
TInitializationSection = class;
TFinalizationSection = class;
{ TPasModule }
TPasModule = class(TPasElement)
public
destructor Destroy; override;
function ElementTypeName: string; override;
function GetDeclaration(full : boolean) : string; override;
public
InterfaceSection: TInterfaceSection;
ImplementationSection: TImplementationSection;
InitializationSection: TInitializationSection;
FinalizationSection: TFinalizationSection;
PackageName: string;
Filename : String; // the IN filename, only written when not empty.
end;
{ TPasProgram }
TPasProgram = class(TPasModule);
{ TPasPackage }
TPasPackage = class(TPasElement)
public
constructor Create(const AName: string; AParent: TPasElement); override;
destructor Destroy; override;
function ElementTypeName: string; override;
public
Modules: TList; // List of TPasModule objects
end;
{ TPasResString }
TPasResString = class(TPasElement)
public
function ElementTypeName: string; override;
function GetDeclaration(full : Boolean) : string; Override;
public
Value: string;
end;
{ TPasType }
TPasType = class(TPasElement)
public
function ElementTypeName: string; override;
end;
{ TPasPointerType }
TPasPointerType = class(TPasType)
public
destructor Destroy; override;
function ElementTypeName: string; override;
function GetDeclaration(full : Boolean): string; override;
public
DestType: TPasType;
end;
{ TPasAliasType }
TPasAliasType = class(TPasType)
public
destructor Destroy; override;
function ElementTypeName: string; override;
function GetDeclaration(full : Boolean): string; override;
public
DestType: TPasType;
end;
{ TPasTypeAliasType }
TPasTypeAliasType = class(TPasAliasType)
public
function ElementTypeName: string; override;
end;
{ TPasClassOfType }
TPasClassOfType = class(TPasAliasType)
public
function ElementTypeName: string; override;
function GetDeclaration(full: boolean) : string; override;
end;
{ TPasRangeType }
TPasRangeType = class(TPasType)
public
function ElementTypeName: string; override;
function GetDeclaration(full : boolean) : string; override;
public
RangeStart, RangeEnd: string;
end;
{ TPasArrayType }
TPasArrayType = class(TPasType)
public
destructor Destroy; override;
function ElementTypeName: string; override;
function GetDeclaration(full : boolean) : string; override;
public
IndexRange : string;
IsPacked : Boolean; // 12/04/04 - Dave - Added
ElType: TPasType;
end;
{ TPasFileType }
TPasFileType = class(TPasType)
public
destructor Destroy; override;
function ElementTypeName: string; override;
function GetDeclaration(full : boolean) : string; override;
public
ElType: TPasType;
end;
{ TPasEnumValue }
TPasEnumValue = class(TPasElement)
public
function ElementTypeName: string; override;
public
IsValueUsed: Boolean;
Value: Integer;
AssignedValue : string;
end;
{ TPasEnumType }
TPasEnumType = class(TPasType)
public
constructor Create(const AName: string; AParent: TPasElement); override;
destructor Destroy; override;
function ElementTypeName: string; override;
function GetDeclaration(full : boolean) : string; override;
Procedure GetEnumNames(Names : TStrings);
public
Values: TList; // List of TPasEnumValue objects
end;
{ TPasSetType }
TPasSetType = class(TPasType)
public
destructor Destroy; override;
function ElementTypeName: string; override;
function GetDeclaration(full : boolean) : string; override;
public
EnumType: TPasType;
end;
TPasRecordType = class;
{ TPasVariant }
TPasVariant = class(TPasElement)
public
constructor Create(const AName: string; AParent: TPasElement); override;
destructor Destroy; override;
public
Values: TStringList;
Members: TPasRecordType;
end;
{ TPasRecordType }
TPasRecordType = class(TPasType)
public
constructor Create(const AName: string; AParent: TPasElement); override;
destructor Destroy; override;
function ElementTypeName: string; override;
function GetDeclaration(full : boolean) : string; override;
public
IsPacked: Boolean;
IsBitPacked : Boolean;
Members: TList; // array of TPasVariable elements
VariantName: string;
VariantType: TPasType;
Variants: TList; // array of TPasVariant elements, may be nil!
end;
TPasObjKind = (okObject, okClass, okInterface);
{ TPasClassType }
TPasClassType = class(TPasType)
public
constructor Create(const AName: string; AParent: TPasElement); override;
destructor Destroy; override;
function ElementTypeName: string; override;
public
ObjKind: TPasObjKind;
AncestorType: TPasType; // TPasClassType or TPasUnresolvedTypeRef
IsPacked: Boolean; // 12/04/04 - Dave - Added
IsForward : Boolean;
IsShortDefinition: Boolean;//class(anchestor); without end
Members: TList; // array of TPasElement objects
InterfaceGUID : string; // 15/06/07 - Inoussa
ClassVars: TList; // class vars
Modifiers: TStringList;
Interfaces : TList;
end;
TArgumentAccess = (argDefault, argConst, argVar, argOut);
{ TPasArgument }
TPasArgument = class(TPasElement)
public
destructor Destroy; override;
function ElementTypeName: string; override;
function GetDeclaration(full : boolean) : string; override;
public
Access: TArgumentAccess;
ArgType: TPasType;
Value: string;
end;
{ TPasProcedureType }
TPasProcedureType = class(TPasType)
public
constructor Create(const AName: string; AParent: TPasElement); override;
destructor Destroy; override;
class function TypeName: string; virtual;
function ElementTypeName: string; override;
function GetDeclaration(full : boolean) : string; override;
procedure GetArguments(List : TStrings);
function CreateArgument(const AName, AUnresolvedTypeName: string):TPasArgument;
public
IsOfObject: Boolean;
Args: TList; // List of TPasArgument objects
end;
{ TPasResultElement }
TPasResultElement = class(TPasElement)
public
destructor Destroy; override;
function ElementTypeName : string; override;
public
ResultType: TPasType;
end;
{ TPasFunctionType }
TPasFunctionType = class(TPasProcedureType)
public
destructor Destroy; override;
class function TypeName: string; override;
function ElementTypeName: string; override;
function GetDeclaration(Full : boolean) : string; override;
public
ResultEl: TPasResultElement;
end;
TPasUnresolvedTypeRef = class(TPasType)
public
// Typerefs cannot be parented! -> AParent _must_ be NIL
constructor Create(const AName: string; AParent: TPasElement); override;
function ElementTypeName: string; override;
end;
{ TPasTypeRef }
TPasTypeRef = class(TPasUnresolvedTypeRef)
public
public
// function GetDeclaration(full : Boolean): string; override;
RefType: TPasType;
end;
{ TPasVariable }
TPasVariable = class(TPasElement)
public
destructor Destroy; override;
function ElementTypeName: string; override;
function GetDeclaration(full : boolean) : string; override;
public
VarType: TPasType;
Value: string;
Modifiers : string;
AbsoluteLocation : String;
Expr: TPasExpr;
end;
{ TPasConst }
TPasConst = class(TPasVariable)
public
public
function ElementTypeName: string; override;
end;
{ TPasProperty }
TPasProperty = class(TPasVariable)
public
constructor Create(const AName: string; AParent: TPasElement); override;
destructor Destroy; override;
function ElementTypeName: string; override;
function GetDeclaration(full : boolean) : string; override;
public
Args: TList; // List of TPasArgument objects
IndexValue, ReadAccessorName, WriteAccessorName,ImplementsName,
StoredAccessorName, DefaultValue: string;
IsDefault, IsNodefault: Boolean;
end;
{ TPasProcedureBase }
TPasProcedureBase = class(TPasElement)
public
function TypeName: string; virtual; abstract;
end;
{ TPasOverloadedProc }
TPasOverloadedProc = class(TPasProcedureBase)
public
constructor Create(const AName: string; AParent: TPasElement); override;
destructor Destroy; override;
function ElementTypeName: string; override;
function TypeName: string; override;
public
Overloads: TList; // List of TPasProcedure nodes
end;
TProcedureModifier = (pmVirtual, pmDynamic, pmAbstract, pmOverride,
pmExported, pmOverload, pmMessage, pmReintroduce,
pmStatic,pmInline,pmAssembler,pmVarargs,
pmCompilerProc,pmExternal,pmExtdecl,pmForward);
TProcedureModifiers = Set of TProcedureModifier;
TProcedureMessageType = (pmtInteger,pmtString);
TProcedureBody = class;
TPasProcedure = class(TPasProcedureBase)
Private
FCallingConvention : TCallingConvention;
FModifiers : TProcedureModifiers;
FMessageName : String;
FMessageType : TProcedureMessageType;
public
destructor Destroy; override;
function ElementTypeName: string; override;
function TypeName: string; override;
function GetDeclaration(full: Boolean): string; override;
procedure GetModifiers(List: TStrings);
public
ProcType : TPasProcedureType;
Body : TProcedureBody;
Procedure AddModifier(AModifier : TProcedureModifier);
Function IsVirtual : Boolean;
Function IsDynamic : Boolean;
Function IsAbstract : Boolean;
Function IsOverride : Boolean;
Function IsExported : Boolean;
Function IsExternal : Boolean;
Function IsOverload : Boolean;
Function IsMessage: Boolean;
Function IsReintroduced : Boolean;
Function IsStatic : Boolean;
Function IsForward: Boolean;
Property Modifiers : TProcedureModifiers Read FModifiers Write FModifiers;
Property CallingConvention : TCallingConvention Read FCallingConvention Write FCallingConvention;
Property MessageName : String Read FMessageName Write FMessageName;
property MessageType : TProcedureMessageType Read FMessageType Write FMessageType;
end;
TPasFunction = class(TPasProcedure)
public
function ElementTypeName: string; override;
function TypeName: string; override;
function GetDeclaration (full : boolean) : string; override;
end;
{ TPasOperator }
TPasOperator = class(TPasProcedure)
public
function ElementTypeName: string; override;
function TypeName: string; override;
function GetDeclaration (full : boolean) : string; override;
end;
{ TPasConstructor }
TPasConstructor = class(TPasProcedure)
public
function ElementTypeName: string; override;
function TypeName: string; override;
end;
{ TPasDestructor }
TPasDestructor = class(TPasProcedure)
public
function ElementTypeName: string; override;
function TypeName: string; override;
end;
{ TPasClassProcedure }
TPasClassProcedure = class(TPasProcedure)
public
function ElementTypeName: string; override;
function TypeName: string; override;
end;
{ TPasClassFunction }
TPasClassFunction = class(TPasProcedure)
public
function ElementTypeName: string; override;
function TypeName: string; override;
end;
TPasImplBlock = class;
{ TProcedureBody - the var+type+const+begin, without the header, child of TPasProcedure }
TProcedureBody = class(TPasDeclarations)
public
constructor Create(const AName: string; AParent: TPasElement); override;
destructor Destroy; override;
public
Labels: TList;
Body: TPasImplBlock;
end;
{ TPasProcedureImpl - used by mkxmlrpc, not by pparser }
TPasProcedureImpl = class(TPasElement)
public
constructor Create(const AName: string; AParent: TPasElement); override;
destructor Destroy; override;
function ElementTypeName: string; override;
function TypeName: string; virtual;
public
ProcType: TPasProcedureType;
Locals: TList;
Body: TPasImplBlock;
end;
{ TPasConstructorImpl - used by mkxmlrpc, not by pparser }
TPasConstructorImpl = class(TPasProcedureImpl)
public
function ElementTypeName: string; override;
function TypeName: string; override;
end;
{ TPasDestructorImpl - used by mkxmlrpc, not by pparser }
TPasDestructorImpl = class(TPasProcedureImpl)
public
function ElementTypeName: string; override;
function TypeName: string; override;
end;
{ TPasImplElement - implementation element }
TPasImplElement = class(TPasElement)
end;
{ TPasImplCommand }
TPasImplCommand = class(TPasImplElement)
public
Command: string;
end;
{ TPasImplCommands - used by mkxmlrpc, not used by pparser }
TPasImplCommands = class(TPasImplElement)
public
constructor Create(const AName: string; AParent: TPasElement); override;
destructor Destroy; override;
public
Commands: TStrings;
end;
{ TPasLabels }
TPasLabels = class(TPasImplElement)
public
Labels : TStrings;
constructor Create(const AName: string; AParent: TPasElement); override;
destructor Destroy; override;
end;
TPasImplBeginBlock = class;
TPasImplRepeatUntil = class;
TPasImplIfElse = class;
TPasImplWhileDo = class;
TPasImplWithDo = class;
TPasImplCaseOf = class;
TPasImplForLoop = class;
TPasImplTry = class;
TPasImplExceptOn = class;
TPasImplRaise = class;
TPasImplAssign = class;
TPasImplSimple = class;
TPasImplLabelMark = class;
{ TPasImplBlock }
TPasImplBlock = class(TPasImplElement)
public
constructor Create(const AName: string; AParent: TPasElement); override;
destructor Destroy; override;
procedure AddElement(Element: TPasImplElement); virtual;
function AddCommand(const ACommand: string): TPasImplCommand;
function AddCommands: TPasImplCommands; // used by mkxmlrpc, not by pparser
function AddBeginBlock: TPasImplBeginBlock;
function AddRepeatUntil: TPasImplRepeatUntil;
function AddIfElse(const ACondition: string): TPasImplIfElse;
function AddWhileDo(const ACondition: string): TPasImplWhileDo;
function AddWithDo(const Expression: string): TPasImplWithDo;
function AddCaseOf(const Expression: string): TPasImplCaseOf;
function AddForLoop(AVar: TPasVariable;
const AStartValue, AEndValue: string): TPasImplForLoop;
function AddForLoop(const AVarName, AStartValue, AEndValue: string;
ADownTo: Boolean = false): TPasImplForLoop;
function AddTry: TPasImplTry;
function AddExceptOn(const VarName, TypeName: string): TPasImplExceptOn;
function AddRaise: TPasImplRaise;
function AddLabelMark(const Id: string): TPasImplLabelMark;
function AddAssign(left, right: TPasExpr): TPasImplAssign;
function AddSimple(exp: TPasExpr): TPasImplSimple;
function CloseOnSemicolon: boolean; virtual;
public
Elements: TList; // TPasImplElement objects
end;
{ TPasImplStatement }
TPasImplStatement = class(TPasImplBlock)
public
function CloseOnSemicolon: boolean; override;
end;
{ TPasImplBeginBlock }
TPasImplBeginBlock = class(TPasImplBlock)
end;
{ TInitializationSection }
TInitializationSection = class(TPasImplBlock)
end;
{ TFinalizationSection }
TFinalizationSection = class(TPasImplBlock)
end;
{ TPasImplRepeatUntil }
TPasImplRepeatUntil = class(TPasImplBlock)
public
Condition: string;
end;
{ TPasImplIfElse }
TPasImplIfElse = class(TPasImplBlock)
public
destructor Destroy; override;
procedure AddElement(Element: TPasImplElement); override;
function CloseOnSemicolon: boolean; override;
public
Condition: string;
IfBranch: TPasImplElement;
ElseBranch: TPasImplElement; // can be nil
end;
{ TPasImplWhileDo }
TPasImplWhileDo = class(TPasImplStatement)
public
destructor Destroy; override;
procedure AddElement(Element: TPasImplElement); override;
public
Condition: string;
Body: TPasImplElement;
end;
{ TPasImplWithDo }
TPasImplWithDo = class(TPasImplStatement)
public
constructor Create(const AName: string; AParent: TPasElement); override;
destructor Destroy; override;
procedure AddElement(Element: TPasImplElement); override;
procedure AddExpression(const Expression: string);
public
Expressions: TStrings;
Body: TPasImplElement;
end;
TPasImplCaseStatement = class;
TPasImplCaseElse = class;
{ TPasImplCaseOf }
TPasImplCaseOf = class(TPasImplBlock)
public
destructor Destroy; override;
procedure AddElement(Element: TPasImplElement); override;
function AddCase(const Expression: string): TPasImplCaseStatement;
function AddElse: TPasImplCaseElse;
public
Expression: string;
ElseBranch: TPasImplCaseElse;
end;
{ TPasImplCaseStatement }
TPasImplCaseStatement = class(TPasImplStatement)
public
constructor Create(const AName: string; AParent: TPasElement); override;
destructor Destroy; override;
procedure AddElement(Element: TPasImplElement); override;
procedure AddExpression(const Expr: string);
public
Expressions: TStrings;
Body: TPasImplElement;
end;
{ TPasImplCaseElse }
TPasImplCaseElse = class(TPasImplBlock)
end;
{ TPasImplForLoop }
TPasImplForLoop = class(TPasImplStatement)
public
destructor Destroy; override;
procedure AddElement(Element: TPasImplElement); override;
public
Variable: TPasVariable;
VariableName, StartValue, EndValue: string;
Down: boolean; // downto
Body: TPasImplElement;
end;
{ TPasImplAssign }
TPasImplAssign = class (TPasImplStatement)
public
left : TPasExpr;
right : TPasExpr;
end;
{ TPasImplSimple }
TPasImplSimple = class (TPasImplStatement)
public
expr : TPasExpr;
end;
TPasImplTryHandler = class;
TPasImplTryFinally = class;
TPasImplTryExcept = class;
TPasImplTryExceptElse = class;
{ TPasImplTry }
TPasImplTry = class(TPasImplBlock)
public
destructor Destroy; override;
function AddFinally: TPasImplTryFinally;
function AddExcept: TPasImplTryExcept;
function AddExceptElse: TPasImplTryExceptElse;
public
FinallyExcept: TPasImplTryHandler;
ElseBranch: TPasImplTryExceptElse;
end;
TPasImplTryHandler = class(TPasImplBlock)
end;
{ TPasImplTryFinally }
TPasImplTryFinally = class(TPasImplTryHandler)
end;
{ TPasImplTryExcept }
TPasImplTryExcept = class(TPasImplTryHandler)
end;
{ TPasImplTryExceptElse }
TPasImplTryExceptElse = class(TPasImplTryHandler)
end;
{ TPasImplExceptOn }
TPasImplExceptOn = class(TPasImplStatement)
public
destructor Destroy; override;
procedure AddElement(Element: TPasImplElement); override;
public
VariableName, TypeName: string;
Body: TPasImplElement;
end;
{ TPasImplRaise }
TPasImplRaise = class(TPasImplStatement)
end;
{ TPassTreeVisitor }
TPassTreeVisitor = class
procedure Visit(obj: TPasElement); virtual;
end;
TPasImplLabelMark = class(TPasImplElement)
public
LabelId: AnsiString;
end;
const
AccessNames: array[TArgumentAccess] of string[6] = ('', 'const ', 'var ', 'out ');
AllVisibilities: TPasMemberVisibilities =
[visDefault, visPrivate, visProtected, visPublic,
visPublished, visAutomated];
VisibilityNames: array[TPasMemberVisibility] of string = (
'default', 'private', 'protected', 'public', 'published', 'automated','strict private', 'strict protected');
ObjKindNames: array[TPasObjKind] of string = (
'object', 'class', 'interface');
OpcodeStrings : Array[TExprOpCode] of string =
('','+','-','*','/','div','mod','**',
'shr','shl',
'not','and','or','xor',
'=','<>',
'<','>','<=','>=',
'in','is','as','><',
'@','^',
'.');
cPasMemberHint : array[TPasMemberHint] of string =
( 'deprecated', 'library', 'platform', 'experimental', 'unimplemented' );
implementation
uses SysUtils;
{$IFNDEF FPC}
const
LineEnding = sLineBreak;
{$ENDIF}
{ Parse tree element type name functions }
function TPasElement.ElementTypeName: string; begin Result := SPasTreeElement end;
function TPasDeclarations.ElementTypeName: string; begin Result := SPasTreeSection end;
function TPasModule.ElementTypeName: string; begin Result := SPasTreeModule end;
function TPasPackage.ElementTypeName: string; begin Result := SPasTreePackage end;
function TPasResString.ElementTypeName: string; begin Result := SPasTreeResString end;
function TPasType.ElementTypeName: string; begin Result := SPasTreeType end;
function TPasPointerType.ElementTypeName: string; begin Result := SPasTreePointerType end;
function TPasAliasType.ElementTypeName: string; begin Result := SPasTreeAliasType end;
function TPasTypeAliasType.ElementTypeName: string; begin Result := SPasTreeTypeAliasType end;
function TPasClassOfType.ElementTypeName: string; begin Result := SPasTreeClassOfType end;
function TPasRangeType.ElementTypeName: string; begin Result := SPasTreeRangeType end;
function TPasArrayType.ElementTypeName: string; begin Result := SPasTreeArrayType end;
function TPasFileType.ElementTypeName: string; begin Result := SPasTreeFileType end;
function TPasEnumValue.ElementTypeName: string; begin Result := SPasTreeEnumValue end;
function TPasEnumType.ElementTypeName: string; begin Result := SPasTreeEnumType end;
function TPasSetType.ElementTypeName: string; begin Result := SPasTreeSetType end;
function TPasRecordType.ElementTypeName: string; begin Result := SPasTreeRecordType end;
function TPasArgument.ElementTypeName: string; begin Result := SPasTreeArgument end;
function TPasProcedureType.ElementTypeName: string; begin Result := SPasTreeProcedureType end;
function TPasResultElement.ElementTypeName: string; begin Result := SPasTreeResultElement end;
function TPasFunctionType.ElementTypeName: string; begin Result := SPasTreeFunctionType end;
function TPasUnresolvedTypeRef.ElementTypeName: string; begin Result := SPasTreeUnresolvedTypeRef end;
function TPasVariable.ElementTypeName: string; begin Result := SPasTreeVariable end;
function TPasConst.ElementTypeName: string; begin Result := SPasTreeConst end;
function TPasProperty.ElementTypeName: string; begin Result := SPasTreeProperty end;
function TPasOverloadedProc.ElementTypeName: string; begin Result := SPasTreeOverloadedProcedure end;
function TPasProcedure.ElementTypeName: string; begin Result := SPasTreeProcedure end;
function TPasFunction.ElementTypeName: string; begin Result := SPasTreeFunction end;
function TPasClassProcedure.ElementTypeName: string; begin Result := SPasTreeClassProcedure; end;
function TPasClassFunction.ElementTypeName: string; begin Result := SPasTreeClassFunction; end;
function TPasOperator.ElementTypeName: string; begin Result := SPasTreeFunction end;
function TPasConstructor.ElementTypeName: string; begin Result := SPasTreeConstructor end;
function TPasDestructor.ElementTypeName: string; begin Result := SPasTreeDestructor end;
function TPasProcedureImpl.ElementTypeName: string; begin Result := SPasTreeProcedureImpl end;
function TPasConstructorImpl.ElementTypeName: string; begin Result := SPasTreeConstructorImpl end;
function TPasDestructorImpl.ElementTypeName: string; begin Result := SPasTreeDestructorImpl end;
function TPasClassType.ElementTypeName: string;
begin
case ObjKind of
okObject: Result := SPasTreeObjectType;
okClass: Result := SPasTreeClassType;
okInterface: Result := SPasTreeInterfaceType;
end;
end;
{ All other stuff: }
procedure TPasElement.ProcessHints(const ASemiColonPrefix: boolean; var AResult: string);
var
h: TPasMemberHint;
begin
if Hints <> [] then
begin
if ASemiColonPrefix then
AResult := AResult + ';';
for h := Low(TPasMemberHint) to High(TPasMemberHint) do
begin
if h in Hints then
AResult := AResult + ' ' + cPasMemberHint[h] + ';'
end;
end;
end;
constructor TPasElement.Create(const AName: string; AParent: TPasElement);
begin
inherited Create;
FName := AName;
FParent := AParent;
end;
procedure TPasElement.AddRef;
begin
Inc(FRefCount);
end;
procedure TPasElement.Release;
begin
if FRefCount = 0 then
Free
else
Dec(FRefCount);
end;
function TPasElement.FullName: string;
var
p: TPasElement;
begin
Result := Name;
p := Parent;
while Assigned(p) and not p.InheritsFrom(TPasDeclarations) do
begin
if (p.ClassType <> TPasOverloadedProc) and (Length(p.Name) > 0) then
if Length(Result) > 0 then
Result := p.Name + '.' + Result
else
Result := p.Name;
p := p.Parent;
end;
end;
function TPasElement.PathName: string;
var
p: TPasElement;
begin
Result := Name;
p := Parent;
while Assigned(p) do
begin
if (p.ClassType <> TPasOverloadedProc) and (Length(p.Name) > 0) then
if Length(Result) > 0 then
Result := p.Name + '.' + Result
else
Result := p.Name;
p := p.Parent;
end;
end;
function TPasElement.GetModule: TPasModule;
begin
if ClassType = TPasPackage then
Result := nil
else
begin
Result := TPasModule(Self);
while Assigned(Result) and not (Result.ClassType = TPasModule) do
Result := TPasModule(Result.Parent);
end;
end;
function TPasElement.GetDeclaration (full : boolean): string;
begin
if Full then
Result := Name
else
Result := '';
end;
procedure TPasElement.Accept(Visitor: TPassTreeVisitor);
begin
Visitor.Visit(Self);
end;
constructor TPasDeclarations.Create(const AName: string; AParent: TPasElement);
begin
inherited Create(AName, AParent);
Declarations := TList.Create;
ResStrings := TList.Create;
Types := TList.Create;
Consts := TList.Create;
Classes := TList.Create;
Functions := TList.Create;
Variables := TList.Create;
Properties := TList.Create;
end;
destructor TPasDeclarations.Destroy;
var
i: Integer;
begin
Variables.Free;
Functions.Free;
Classes.Free;
Consts.Free;
Types.Free;
ResStrings.Free;
Properties.Free;
for i := 0 to Declarations.Count - 1 do
TPasElement(Declarations[i]).Release;
Declarations.Free;
inherited Destroy;
end;
destructor TPasModule.Destroy;
begin
if Assigned(InterfaceSection) then
InterfaceSection.Release;
if Assigned(ImplementationSection) then
ImplementationSection.Release;
inherited Destroy;
end;
constructor TPasPackage.Create(const AName: string; AParent: TPasElement);
begin
if (Length(AName) > 0) and (AName[1] <> '#') then
inherited Create('#' + AName, AParent)
else
inherited Create(AName, AParent);
Modules := TList.Create;
end;
destructor TPasPackage.Destroy;
var
i: Integer;
begin
for i := 0 to Modules.Count - 1 do
TPasModule(Modules[i]).Release;
Modules.Free;
inherited Destroy;
end;
destructor TPasPointerType.Destroy;
begin
if Assigned(DestType) then
DestType.Release;
inherited Destroy;
end;
destructor TPasAliasType.Destroy;
begin
if Assigned(DestType) then
DestType.Release;
inherited Destroy;
end;
destructor TPasArrayType.Destroy;
begin
if Assigned(ElType) then
ElType.Release;
inherited Destroy;
end;
destructor TPasFileType.Destroy;
begin
if Assigned(ElType) then
ElType.Release;
inherited Destroy;
end;
constructor TPasEnumType.Create(const AName: string; AParent: TPasElement);
begin
inherited Create(AName, AParent);
Values := TList.Create;
end;
destructor TPasEnumType.Destroy;
var
i: Integer;
begin
for i := 0 to Values.Count - 1 do
TPasEnumValue(Values[i]).Release;
Values.Free;
inherited Destroy;
end;
procedure TPasEnumType.GetEnumNames(Names: TStrings);
var
i: Integer;
begin
with Values do
begin
for i := 0 to Count - 2 do
Names.Add(TPasEnumValue(Items[i]).Name + ',');
if Count > 0 then
Names.Add(TPasEnumValue(Items[Count - 1]).Name);
end;
end;
destructor TPasSetType.Destroy;
begin
if Assigned(EnumType) then
EnumType.Release;
inherited Destroy;
end;
constructor TPasVariant.Create(const AName: string; AParent: TPasElement);
begin
inherited Create(AName, AParent);
Values := TStringList.Create;
end;
destructor TPasVariant.Destroy;
begin
Values.Free;
if Assigned(Members) then
Members.Release;
inherited Destroy;
end;
constructor TPasRecordType.Create(const AName: string; AParent: TPasElement);
begin
inherited Create(AName, AParent);
Members := TList.Create;
end;
destructor TPasRecordType.Destroy;
var
i: Integer;
begin
for i := 0 to Members.Count - 1 do
TPasVariable(Members[i]).Release;
Members.Free;
if Assigned(VariantType) then
VariantType.Release;
if Assigned(Variants) then
begin
for i := 0 to Variants.Count - 1 do
TPasVariant(Variants[i]).Release;
Variants.Free;
end;
inherited Destroy;
end;
constructor TPasClassType.Create(const AName: string; AParent: TPasElement);
begin
inherited Create(AName, AParent);
IsPacked := False; // 12/04/04 - Dave - Added
IsShortDefinition := False;
Members := TList.Create;
Modifiers := TStringList.Create;
ClassVars := TList.Create;
Interfaces:= TList.Create;
end;
destructor TPasClassType.Destroy;
var
i: Integer;
begin
for i := 0 to Members.Count - 1 do
TPasElement(Members[i]).Release;
Members.Free;
if Assigned(AncestorType) then
AncestorType.Release;
Modifiers.Free;
ClassVars.Free;
Interfaces.Free;
inherited Destroy;
end;
destructor TPasArgument.Destroy;
begin
if Assigned(ArgType) then
ArgType.Release;
inherited Destroy;
end;
constructor TPasProcedureType.Create(const AName: string; AParent: TPasElement);
begin
inherited Create(AName, AParent);
Args := TList.Create;
end;
destructor TPasProcedureType.Destroy;
var
i: Integer;
begin
for i := 0 to Args.Count - 1 do
TPasArgument(Args[i]).Release;
FreeAndNil(Args);
inherited Destroy;
end;
class function TPasProcedureType.TypeName: string;
begin
Result := 'procedure';
end;
function TPasProcedureType.CreateArgument(const AName,
AUnresolvedTypeName: string): TPasArgument;
begin
Result := TPasArgument.Create(AName, Self);
Args.Add(Result);
Result.ArgType := TPasUnresolvedTypeRef.Create(AUnresolvedTypeName, Result);
end;
destructor TPasResultElement.Destroy;
begin
if Assigned(ResultType) then
ResultType.Release;
inherited Destroy;
end;
destructor TPasFunctionType.Destroy;
begin
if Assigned(ResultEl) then
ResultEl.Release;
inherited Destroy;
end;
class function TPasFunctionType.TypeName: string;
begin
Result := 'function';
end;
constructor TPasUnresolvedTypeRef.Create(const AName: string; AParent: TPasElement);
begin
inherited Create(AName, nil);
end;
destructor TPasVariable.Destroy;
begin
{ Attention, in derived classes, VarType isn't necessarily set!
(e.g. in Constants) }
if Assigned(VarType) then
VarType.Release;
if Assigned(Expr) then
Expr.Release;
inherited Destroy;
end;
constructor TPasProperty.Create(const AName: string; AParent: TPasElement);
begin
inherited Create(AName, AParent);
Args := TList.Create;
end;
destructor TPasProperty.Destroy;
var
i: Integer;
begin
for i := 0 to Args.Count - 1 do
TPasArgument(Args[i]).Release;
Args.Free;
inherited Destroy;
end;
constructor TPasOverloadedProc.Create(const AName: string; AParent: TPasElement);
begin
inherited Create(AName, AParent);
Overloads := TList.Create;
end;
destructor TPasOverloadedProc.Destroy;
var
i: Integer;
begin
for i := 0 to Overloads.Count - 1 do
TPasProcedure(Overloads[i]).Release;
Overloads.Free;
inherited Destroy;
end;
function TPasOverloadedProc.TypeName: string;
begin
if Assigned(TPasProcedure(Overloads[0]).ProcType) then
Result := TPasProcedure(Overloads[0]).ProcType.TypeName
else
SetLength(Result, 0);
end;
destructor TPasProcedure.Destroy;
begin
if Assigned(ProcType) then
ProcType.Release;
if Assigned(Body) then
Body.Release;
inherited Destroy;
end;
function TPasProcedure.TypeName: string;
begin
Result := 'procedure';
end;
constructor TPasProcedureImpl.Create(const AName: string; AParent: TPasElement);
begin
inherited Create(AName, AParent);
Locals := TList.Create;
end;
destructor TPasProcedureImpl.Destroy;
var
i: Integer;
begin
if Assigned(Body) then
Body.Release;
for i := 0 to Locals.Count - 1 do
TPasElement(Locals[i]).Release;
Locals.Free;
if Assigned(ProcType) then
ProcType.Release;
inherited Destroy;
end;
function TPasProcedureImpl.TypeName: string;
begin
Result := ProcType.TypeName;
end;
function TPasConstructorImpl.TypeName: string;
begin
Result := 'constructor';
end;
function TPasDestructorImpl.TypeName: string;
begin
Result := 'destructor';
end;
constructor TPasImplCommands.Create(const AName: string; AParent: TPasElement);
begin
inherited Create(AName, AParent);
Commands := TStringList.Create;
end;
destructor TPasImplCommands.Destroy;
begin
Commands.Free;
inherited Destroy;
end;
destructor TPasImplIfElse.Destroy;
begin
if Assigned(IfBranch) then
IfBranch.Release;
if Assigned(ElseBranch) then
ElseBranch.Release;
inherited Destroy;
end;
procedure TPasImplIfElse.AddElement(Element: TPasImplElement);
begin
inherited AddElement(Element);
if IfBranch=nil then
IfBranch:=Element
else if ElseBranch=nil then
ElseBranch:=Element
else
raise Exception.Create('TPasImplIfElse.AddElement if and else already set - please report this bug');
end;
function TPasImplIfElse.CloseOnSemicolon: boolean;
begin
Result:=ElseBranch<>nil;
end;
destructor TPasImplForLoop.Destroy;
begin
if Assigned(Variable) then
Variable.Release;
if Assigned(Body) then
Body.Release;
inherited Destroy;
end;
procedure TPasImplForLoop.AddElement(Element: TPasImplElement);
begin
inherited AddElement(Element);
if Body=nil then
Body:=Element
else
raise Exception.Create('TPasImplForLoop.AddElement body already set - please report this bug');
end;
constructor TPasImplBlock.Create(const AName: string; AParent: TPasElement);
begin
inherited Create(AName, AParent);
Elements := TList.Create;
end;
destructor TPasImplBlock.Destroy;
var
i: Integer;
begin
for i := 0 to Elements.Count - 1 do
TPasImplElement(Elements[i]).Release;
Elements.Free;
inherited Destroy;
end;
procedure TPasImplBlock.AddElement(Element: TPasImplElement);
begin
Elements.Add(Element);
end;
function TPasImplBlock.AddCommand(const ACommand: string): TPasImplCommand;
begin
Result := TPasImplCommand.Create('', Self);
Result.Command := ACommand;
AddElement(Result);
end;
function TPasImplBlock.AddCommands: TPasImplCommands;
begin
Result := TPasImplCommands.Create('', Self);
AddElement(Result);
end;
function TPasImplBlock.AddBeginBlock: TPasImplBeginBlock;
begin
Result := TPasImplBeginBlock.Create('', Self);
AddElement(Result);
end;
function TPasImplBlock.AddRepeatUntil: TPasImplRepeatUntil;
begin
Result := TPasImplRepeatUntil.Create('', Self);
AddElement(Result);
end;
function TPasImplBlock.AddIfElse(const ACondition: string): TPasImplIfElse;
begin
Result := TPasImplIfElse.Create('', Self);
Result.Condition := ACondition;
AddElement(Result);
end;
function TPasImplBlock.AddWhileDo(const ACondition: string): TPasImplWhileDo;
begin
Result := TPasImplWhileDo.Create('', Self);
Result.Condition := ACondition;
AddElement(Result);
end;
function TPasImplBlock.AddWithDo(const Expression: string): TPasImplWithDo;
begin
Result := TPasImplWithDo.Create('', Self);
Result.AddExpression(Expression);
AddElement(Result);
end;
function TPasImplBlock.AddCaseOf(const Expression: string): TPasImplCaseOf;
begin
Result := TPasImplCaseOf.Create('', Self);
Result.Expression := Expression;
AddElement(Result);
end;
function TPasImplBlock.AddForLoop(AVar: TPasVariable; const AStartValue,
AEndValue: string): TPasImplForLoop;
begin
Result := TPasImplForLoop.Create('', Self);
Result.Variable := AVar;
Result.StartValue := AStartValue;
Result.EndValue := AEndValue;
AddElement(Result);
end;
function TPasImplBlock.AddForLoop(const AVarName, AStartValue,
AEndValue: string; ADownTo: Boolean): TPasImplForLoop;
begin
Result := TPasImplForLoop.Create('', Self);
Result.VariableName := AVarName;
Result.StartValue := AStartValue;
Result.EndValue := AEndValue;
Result.Down := ADownTo;
AddElement(Result);
end;
function TPasImplBlock.AddTry: TPasImplTry;
begin
Result := TPasImplTry.Create('', Self);
AddElement(Result);
end;
function TPasImplBlock.AddExceptOn(const VarName, TypeName: string
): TPasImplExceptOn;
begin
Result:=TPasImplExceptOn.Create('',Self);
Result.VariableName:=VarName;
Result.TypeName:=TypeName;
AddElement(Result);
end;
function TPasImplBlock.AddRaise: TPasImplRaise;
begin
Result:=TPasImplRaise.Create('',Self);
AddElement(Result);
end;
function TPasImplBlock.AddLabelMark(const Id: string): TPasImplLabelMark;
begin
Result:=TPasImplLabelMark.Create('', Self);
Result.LabelId:=Id;
AddElement(Result);
end;
function TPasImplBlock.AddAssign(left,right:TPasExpr):TPasImplAssign;
begin
Result:=TPasImplAssign.Create('', Self);
Result.left:=left;
Result.right:=right;
AddElement(Result);
end;
function TPasImplBlock.AddSimple(exp:TPasExpr):TPasImplSimple;
begin
Result:=TPasImplSimple.Create('', Self);
Result.expr:=exp;
AddElement(Result);
end;
function TPasImplBlock.CloseOnSemicolon: boolean;
begin
Result:=false;
end;
{ ---------------------------------------------------------------------
---------------------------------------------------------------------}
function TPasModule.GetDeclaration(full : boolean): string;
begin
Result := 'Unit ' + Name;
end;
{
function TPas.GetDeclaration : string;
begin
Result:=Name;
end;
}
function TPasResString.GetDeclaration (full : boolean) : string;
begin
Result:=Value;
If Full Then
Result:=Name+' = '+Result;
end;
function TPasPointerType.GetDeclaration (full : boolean) : string;
begin
Result:='^'+DestType.Name;
If Full then
Result:=Name+' = '+Result;
end;
function TPasAliasType.GetDeclaration (full : boolean) : string;
begin
Result:=DestType.Name;
If Full then
Result:=Name+' = '+Result;
end;
function TPasClassOfType.GetDeclaration (full : boolean) : string;
begin
Result:='Class of '+DestType.Name;
If Full then
Result:=Name+' = '+Result;
end;
function TPasRangeType.GetDeclaration (full : boolean) : string;
begin
Result:=RangeStart+'..'+RangeEnd;
If Full then
Result:=Name+' = '+Result;
end;
function TPasArrayType.GetDeclaration (full : boolean) : string;
begin
Result:='Array';
If (IndexRange<>'') then
Result:=Result+'['+IndexRange+']';
Result:=Result+' of ';
If IsPacked then
Result := 'packed '+Result; // 12/04/04 Dave - Added
If Assigned(Eltype) then
Result:=Result+ElType.Name
else
Result:=Result+'const';
If Full Then
Result:=Name+' = '+Result;
end;
function TPasFileType.GetDeclaration (full : boolean) : string;
begin
Result:='File';
If Assigned(Eltype) then
Result:=Result+' of '+ElType.Name;
If Full Then
Result:=Name+' = '+Result;
end;
Function IndentStrings(S : TStrings; indent : Integer) : string;
Var
I,CurrLen,CurrPos : Integer;
begin
Result:='';
CurrLen:=0;
CurrPos:=0;
For I:=0 to S.Count-1 do
begin
CurrLen:=Length(S[i]);
If (CurrLen+CurrPos)>72 then
begin
Result:=Result+LineEnding+StringOfChar(' ',Indent);
CurrPos:=Indent;
end;
Result:=Result+S[i];
CurrPos:=CurrPos+CurrLen;
end;
end;
function TPasEnumType.GetDeclaration (full : boolean) : string;
Var
S : TStringList;
begin
S:=TStringList.Create;
Try
If Full then
S.Add(Name+' = (')
else
S.Add('(');
GetEnumNames(S);
S[S.Count-1]:=S[S.Count-1]+')';
If Full then
Result:=IndentStrings(S,Length(Name)+4)
else
Result:=IndentStrings(S,1);
finally
S.Free;
end;
end;
function TPasSetType.GetDeclaration (full : boolean) : string;
Var
S : TStringList;
i : Integer;
begin
If EnumType is TPasEnumType then
begin
S:=TStringList.Create;
Try
If Full then
S.Add(Name+'= Set of (')
else
S.Add('Set of (');
TPasEnumType(EnumType).GetEnumNames(S);
S[S.Count-1]:=S[S.Count-1]+')';
I:=Pos('(',S[0]);
Result:=IndentStrings(S,i);
finally
S.Free;
end;
end
else
begin
Result:='Set of '+EnumType.Name;
If Full then
Result:=Name+' = '+Result;
end;
end;
function TPasRecordType.GetDeclaration (full : boolean) : string;
Var
S,T : TStringList;
temp : string;
I,J : integer;
begin
S:=TStringList.Create;
T:=TStringList.Create;
Try
Temp:='record';
If IsPacked then
if IsBitPacked then
Temp:='bitpacked '+Temp
else
Temp:='packed '+Temp;
If Full then
Temp:=Name+' = '+Temp;
S.Add(Temp);
For I:=0 to Members.Count-1 do
begin
Temp:=TPasVariable(Members[i]).GetDeclaration(True);
If Pos(LineEnding,Temp)>0 then
begin
T.Text:=Temp;
For J:=0 to T.Count-1 do
if J=T.Count-1 then
S.Add(' '+T[J]+';')
else
S.Add(' '+T[J])
end
else
S.Add(' '+Temp+';');
end;
S.Add('end');
Result:=S.Text;
ProcessHints(False, Result);
finally
S.free;
T.free;
end;
end;
procedure TPasProcedureType.GetArguments(List : TStrings);
Var
T : string;
I : Integer;
begin
For I:=0 to Args.Count-1 do
begin
T:=AccessNames[TPasArgument(Args[i]).Access];
T:=T+TPasArgument(Args[i]).GetDeclaration(True);
If I=0 then
T:='('+T;
If I<Args.Count-1 then
List.Add(T+';')
else
List.Add(T+')');
end;
end;
function TPasProcedureType.GetDeclaration (full : boolean) : string;
Var
S : TStringList;
begin
S:=TStringList.Create;
Try
If Full then
S.Add(Format('%s = ',[Name]));
S.Add(TypeName);
GetArguments(S);
If IsOfObject then
S.Add(' of object');
If Full then
Result:=IndentStrings(S,Length(S[0])+Length(S[1])+1)
else
Result:=IndentStrings(S,Length(S[0])+1);
finally
S.Free;
end;
end;
function TPasFunctionType.GetDeclaration (full : boolean) : string;
Var
S : TStringList;
T : string;
begin
S:=TStringList.Create;
Try
If Full then
S.Add(Format('%s = ',[Name]));
S.Add(TypeName);
GetArguments(S);
If Assigned(ResultEl) then
begin
T:=' : ';
If (ResultEl.ResultType.Name<>'') then
T:=T+ResultEl.ResultType.Name
else
T:=T+ResultEl.ResultType.GetDeclaration(False);
S.Add(T);
end;
If IsOfObject then
S.Add(' of object');
If Full then
Result:=IndentStrings(S,Length(S[0])+Length(S[1])+1)
else
Result:=IndentStrings(S,Length(S[0])+1);
finally
S.Free;
end;
end;
function TPasVariable.GetDeclaration (full : boolean) : string;
Const
Seps : Array[Boolean] of Char = ('=',':');
begin
If Assigned(VarType) then
begin
If VarType.Name='' then
Result:=VarType.GetDeclaration(False)
else
Result:=VarType.Name;
Result:=Result+Modifiers;
if (Value<>'') then
Result:=Result+' = '+Value;
end
else
Result:=Value;
If Full then
Result:=Name+' '+Seps[Assigned(VarType)]+' '+Result;
end;
function TPasProperty.GetDeclaration (full : boolean) : string;
Var
S : string;
I : Integer;
begin
If Assigned(VarType) then
begin
If VarType.Name='' then
Result:=VarType.GetDeclaration(False)
else
Result:=VarType.Name;
end
else
Result:=Value;
S:='';
If Assigned(Args) and (Args.Count>0) then
begin
For I:=0 to Args.Count-1 do
begin
If (S<>'') then
S:=S+';';
S:=S+TPasElement(Args[i]).GetDeclaration(true);
end;
end;
If S<>'' then
S:='['+S+']'
else
S:=' ';
If Full then
begin
Result:=Name+S+': '+Result;
If (ImplementsName<>'') then
Result:=Result+' implements '+ImplementsName;
end;
If IsDefault then
Result:=Result+'; default';
ProcessHints(True, Result);
end;
Procedure TPasProcedure.GetModifiers(List : TStrings);
Procedure DoAdd(B : Boolean; S : string);
begin
if B then
List.add('; '+S);
end;
begin
Doadd(IsVirtual,' Virtual');
DoAdd(IsDynamic,' Dynamic');
DoAdd(IsOverride,' Override');
DoAdd(IsAbstract,' Abstract');
DoAdd(IsOverload,' Overload');
DoAdd(IsReintroduced,' Reintroduce');
DoAdd(IsStatic,' Static');
DoAdd(IsMessage,' Message');
end;
Procedure TPasProcedure.AddModifier(AModifier : TProcedureModifier);
begin
Include(FModifiers,AModifier);
end;
Function TPasProcedure.IsVirtual : Boolean;
begin
Result:=pmVirtual in FModifiers;
end;
Function TPasProcedure.IsDynamic : Boolean;
begin
Result:=pmDynamic in FModifiers;
end;
Function TPasProcedure.IsAbstract : Boolean;
begin
Result:=pmAbstract in FModifiers;
end;
Function TPasProcedure.IsOverride : Boolean;
begin
Result:=pmOverride in FModifiers;
end;
Function TPasProcedure.IsExported : Boolean;
begin
Result:=pmExported in FModifiers;
end;
function TPasProcedure.IsExternal: Boolean;
begin
Result:=pmExternal in FModifiers;
end;
Function TPasProcedure.IsOverload : Boolean;
begin
Result:=pmOverload in FModifiers;
end;
Function TPasProcedure.IsMessage: Boolean;
begin
Result:=pmMessage in FModifiers;
end;
Function TPasProcedure.IsReintroduced : Boolean;
begin
Result:=pmReintroduce in FModifiers;
end;
Function TPasProcedure.IsStatic : Boolean;
begin
Result:=pmStatic in FModifiers;
end;
function TPasProcedure.IsForward: Boolean;
begin
Result:=pmForward in FModifiers;
end;
function TPasProcedure.GetDeclaration (full : boolean) : string;
Var
S : TStringList;
begin
S:=TStringList.Create;
try
If Full then
S.Add(TypeName+' '+Name);
ProcType.GetArguments(S);
GetModifiers(S);
Result:=IndentStrings(S,Length(S[0]));
finally
S.Free;
end;
end;
function TPasFunction.GetDeclaration (full : boolean) : string;
Var
S : TStringList;
T : string;
begin
S:=TStringList.Create;
try
If Full then
S.Add(TypeName+' '+Name);
ProcType.GetArguments(S);
If Assigned((Proctype as TPasFunctionType).ResultEl) then
With TPasFunctionType(ProcType).ResultEl.ResultType do
begin
T:=' : ';
If (Name<>'') then
T:=T+Name
else
T:=T+GetDeclaration(False);
S.Add(T);
end;
GetModifiers(S);
Result:=IndentStrings(S,Length(S[0]));
finally
S.Free;
end;
end;
function TPasFunction.TypeName: string;
begin
Result:='function';
end;
function TPasOperator.GetDeclaration (full : boolean) : string;
Var
S : TStringList;
T : string;
begin
S:=TStringList.Create;
try
If Full then
S.Add(TypeName+' '+Name);
ProcType.GetArguments(S);
If Assigned((Proctype as TPasFunctionType).ResultEl) then
With TPasFunctionType(ProcType).ResultEl.ResultType do
begin
T:=' : ';
If (Name<>'') then
T:=T+Name
else
T:=T+GetDeclaration(False);
S.Add(T);
end;
GetModifiers(S);
Result:=IndentStrings(S,Length(S[0]));
finally
S.Free;
end;
end;
function TPasOperator.TypeName: string;
begin
Result:='operator';
end;
function TPasClassProcedure.TypeName: string;
begin
Result:='class procedure';
end;
function TPasClassFunction.TypeName: string;
begin
Result:='class function';
end;
function TPasConstructor.TypeName: string;
begin
Result:='constructor';
end;
function TPasDestructor.TypeName: string;
begin
Result:='destructor';
end;
function TPasArgument.GetDeclaration (full : boolean) : string;
begin
If Assigned(ArgType) then
begin
If ArgType.Name<>'' then
Result:=ArgType.Name
else
Result:=ArgType.GetDeclaration(False);
If Full then
Result:=Name+': '+Result;
end
else If Full then
Result:=Name
else
Result:='';
end;
{ TPassTreeVisitor }
procedure TPassTreeVisitor.Visit(obj: TPasElement);
begin
// Needs to be implemented by descendents.
end;
{ TPasSection }
constructor TPasSection.Create(const AName: string; AParent: TPasElement);
begin
inherited Create(AName, AParent);
UsesList := TList.Create;
end;
destructor TPasSection.Destroy;
var
i: Integer;
begin
for i := 0 to UsesList.Count - 1 do
TPasType(UsesList[i]).Release;
UsesList.Free;
inherited Destroy;
end;
procedure TPasSection.AddUnitToUsesList(const AUnitName: string);
begin
UsesList.Add(TPasUnresolvedTypeRef.Create(AUnitName, Self));
end;
{ TProcedureBody }
constructor TProcedureBody.Create(const AName: string; AParent: TPasElement);
begin
inherited Create(AName, AParent);
Labels:=TList.Create;
end;
destructor TProcedureBody.Destroy;
begin
FreeAndNil(Labels);
inherited Destroy;
end;
{ TPasImplWhileDo }
destructor TPasImplWhileDo.Destroy;
begin
if Assigned(Body) then
Body.Release;
inherited Destroy;
end;
procedure TPasImplWhileDo.AddElement(Element: TPasImplElement);
begin
inherited AddElement(Element);
if Body=nil then
Body:=Element
else
raise Exception.Create('TPasImplWhileDo.AddElement body already set - please report this bug');
end;
{ TPasImplCaseOf }
destructor TPasImplCaseOf.Destroy;
begin
if Assigned(ElseBranch) then
ElseBranch.Release;
inherited Destroy;
end;
procedure TPasImplCaseOf.AddElement(Element: TPasImplElement);
begin
inherited AddElement(Element);
end;
function TPasImplCaseOf.AddCase(const Expression: string
): TPasImplCaseStatement;
begin
Result:=TPasImplCaseStatement.Create('',Self);
Result.AddExpression(Expression);
AddElement(Result);
end;
function TPasImplCaseOf.AddElse: TPasImplCaseElse;
begin
Result:=TPasImplCaseElse.Create('',Self);
ElseBranch:=Result;
AddElement(Result);
end;
{ TPasImplCaseStatement }
constructor TPasImplCaseStatement.Create(const AName: string;
AParent: TPasElement);
begin
inherited Create(AName, AParent);
Expressions:=TStringList.Create;
end;
destructor TPasImplCaseStatement.Destroy;
begin
FreeAndNil(Expressions);
if Assigned(Body) then
Body.Release;
inherited Destroy;
end;
procedure TPasImplCaseStatement.AddElement(Element: TPasImplElement);
begin
inherited AddElement(Element);
if Body=nil then
Body:=Element;
end;
procedure TPasImplCaseStatement.AddExpression(const Expr: string);
begin
Expressions.Add(Expr);
end;
{ TPasImplWithDo }
constructor TPasImplWithDo.Create(const AName: string; AParent: TPasElement);
begin
inherited Create(AName, AParent);
Expressions:=TStringList.Create;
end;
destructor TPasImplWithDo.Destroy;
begin
if Assigned(Body) then
Body.Release;
FreeAndNil(Expressions);
inherited Destroy;
end;
procedure TPasImplWithDo.AddElement(Element: TPasImplElement);
begin
inherited AddElement(Element);
if Body=nil then
Body:=Element;
end;
procedure TPasImplWithDo.AddExpression(const Expression: string);
begin
Expressions.Add(Expression);
end;
{ TPasImplTry }
destructor TPasImplTry.Destroy;
begin
if Assigned(FinallyExcept) then
FinallyExcept.Release;
if Assigned(ElseBranch) then
ElseBranch.Release;
inherited Destroy;
end;
function TPasImplTry.AddFinally: TPasImplTryFinally;
begin
Result:=TPasImplTryFinally.Create('',Self);
FinallyExcept:=Result;
end;
function TPasImplTry.AddExcept: TPasImplTryExcept;
begin
Result:=TPasImplTryExcept.Create('',Self);
FinallyExcept:=Result;
end;
function TPasImplTry.AddExceptElse: TPasImplTryExceptElse;
begin
Result:=TPasImplTryExceptElse.Create('',Self);
ElseBranch:=Result;
end;
{ TPasImplExceptOn }
destructor TPasImplExceptOn.Destroy;
begin
if Assigned(Body) then
Body.Release;
inherited Destroy;
end;
procedure TPasImplExceptOn.AddElement(Element: TPasImplElement);
begin
inherited AddElement(Element);
if Body=nil then
Body:=Element;
end;
{ TPasImplStatement }
function TPasImplStatement.CloseOnSemicolon: boolean;
begin
Result:=true;
end;
{ TPasExpr }
constructor TPasExpr.Create(AParent : TPasElement; AKind: TPasExprKind; AOpCode: TexprOpcode);
begin
Create(ClassName, AParent);
Kind:=AKind;
OpCode:=AOpCode;
end;
{ TPrimitiveExpr }
function TPrimitiveExpr.GetDeclaration(Full : Boolean):AnsiString;
begin
Result:=Value;
end;
constructor TPrimitiveExpr.Create(AParent : TPasElement; AKind: TPasExprKind; const AValue : Ansistring);
begin
inherited Create(AParent,AKind, eopNone);
Value:=AValue;
end;
{ TBoolConstExpr }
constructor TBoolConstExpr.Create(AParent : TPasElement; AKind: TPasExprKind; const ABoolValue : Boolean);
begin
inherited Create(AParent,AKind, eopNone);
Value:=ABoolValue;
end;
Function TBoolConstExpr.GetDeclaration(Full: Boolean):AnsiString;
begin
If Value then
Result:='True'
else
Result:='False';
end;
{ TUnaryExpr }
Function TUnaryExpr.GetDeclaration(Full : Boolean):AnsiString;
begin
Result:=OpCodeStrings[Opcode];
If Assigned(Operand) then
Result:=Result+Operand.GetDeclaration(Full);
end;
constructor TUnaryExpr.Create(AParent : TPasElement; AOperand: TPasExpr; AOpCode: TExprOpCode);
begin
inherited Create(AParent,pekUnary, AOpCode);
Operand:=AOperand;
end;
destructor TUnaryExpr.Destroy;
begin
Operand.Free;
end;
{ TBinaryExpr }
function TBinaryExpr.GetDeclaration(Full : Boolean):AnsiString;
begin
If Kind=pekRange then
Result:='..'
else
Result:=' '+OpcodeStrings[Opcode]+' ';
If Assigned(Left) then
Result:=Left.GetDeclaration(Full)+Result;
If Assigned(Right) then
Result:=Result +Right.GetDeclaration(Full);
end;
constructor TBinaryExpr.Create(AParent : TPasElement; xleft,xright:TPasExpr; AOpCode:TExprOpCode);
begin
inherited Create(AParent,pekBinary, AOpCode);
left:=xleft;
right:=xright;
end;
constructor TBinaryExpr.CreateRange(AParent : TPasElement; xleft,xright:TPasExpr);
begin
inherited Create(AParent,pekRange, eopNone);
left:=xleft;
right:=xright;
end;
destructor TBinaryExpr.Destroy;
begin
left.Free;
right.Free;
inherited Destroy;
end;
{ TParamsExpr }
Function TParamsExpr.GetDeclaration(Full: Boolean) : Ansistring;
Var
I : Integer;
begin
For I:=0 to Length(Params) do
begin
If (Result<>'') then
Result:=Result+', ';
Result:=Result+Params[I].GetDeclaration(Full);
end;
Result:='('+Result+')';
end;
procedure TParamsExpr.AddParam(xp:TPasExpr);
var
i : Integer;
begin
i:=Length(Params);
SetLength(Params, i+1);
Params[i]:=xp;
end;
constructor TParamsExpr.Create(AParent : TPasElement; AKind: TPasExprKind);
begin
inherited Create(AParent,AKind, eopNone)
end;
destructor TParamsExpr.Destroy;
var
i : Integer;
begin
for i:=0 to length(Params)-1 do Params[i].Free;
inherited Destroy;
end;
{ TRecordValues }
Function TRecordValues.GetDeclaration(Full : Boolean):AnsiString;
Var
I : Integer;
begin
For I:=0 to Length(Fields) do
begin
If Result='' then
Result:=Result+'; ';
Result:=Result+Fields[I].Name+': '+Fields[i].ValueExp.getDeclaration(Full);
end;
Result:='('+Result+')';
end;
constructor TRecordValues.Create(AParent : TPasElement);
begin
inherited Create(AParent,pekListOfExp, eopNone);
end;
destructor TRecordValues.Destroy;
var
i : Integer;
begin
for i:=0 to length(Fields)-1 do Fields[i].ValueExp.Free;
inherited Destroy;
end;
procedure TRecordValues.AddField(const AName:AnsiString;Value:TPasExpr);
var
i : Integer;
begin
i:=length(Fields);
SetLength(Fields, i+1);
Fields[i].Name:=AName;
Fields[i].ValueExp:=Value;
end;
{ TNilExpr }
Function TNilExpr.GetDeclaration(Full :Boolean):AnsiString;
begin
Result:='Nil';
end;
{ TInheritedExpr }
Function TInheritedExpr.GetDeclaration(Full :Boolean):AnsiString;
begin
Result:='Inherited';
end;
{ TSelfExpr }
Function TSelfExpr.GetDeclaration(Full :Boolean):AnsiString;
begin
Result:='Self';
end;
{ TArrayValues }
Function TArrayValues.GetDeclaration(Full: Boolean):AnsiString;
Var
I : Integer;
begin
For I:=0 to Length(Values) do
begin
If Result='' then
Result:=Result+', ';
Result:=Result+Values[i].getDeclaration(Full);
end;
Result:='('+Result+')';
end;
constructor TArrayValues.Create(AParent : TPasElement);
begin
inherited Create(AParent,pekListOfExp, eopNone)
end;
destructor TArrayValues.Destroy;
var
i : Integer;
begin
for i:=0 to length(Values)-1 do Values[i].Free;
inherited Destroy;
end;
procedure TArrayValues.AddValues(AValue:TPasExpr);
var
i : Integer;
begin
i:=length(Values);
SetLength(Values, i+1);
Values[i]:=AValue;
end;
{ TNilExpr }
constructor TNilExpr.Create(AParent : TPasElement);
begin
inherited Create(AParent,pekNil, eopNone);
end;
{ TInheritedExpr }
constructor TInheritedExpr.Create(AParent : TPasElement);
begin
inherited Create(AParent,pekInherited, eopNone);
end;
{ TSelfExpr }
constructor TSelfExpr.Create(AParent : TPasElement);
begin
inherited Create(AParent,pekSelf, eopNone);
end;
{ TPasLabels }
constructor TPasLabels.Create(const AName:string;AParent:TPasElement);
begin
inherited Create(AName,AParent);
Labels := TStringList.Create;
end;
destructor TPasLabels.Destroy;
begin
Labels.Free;
inherited Destroy;
end;
end.
|