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
|
// $Id$
// ============================================================================
//
// = LIBRARY
// TAO IDL
//
// = FILENAME
// be_interface.cpp
//
// = DESCRIPTION
// Extension of class AST_Interface that provides additional means for C++
// mapping of an interface.
//
// = AUTHOR
// Copyright 1994-1995 by Sun Microsystems, Inc.
// and
// Aniruddha Gokhale,
// Michael Kircher
//
// ============================================================================
#include "idl.h"
#include "idl_extern.h"
#include "be_visitor_interface.h"
#include "be.h"
ACE_RCSID(be, be_interface, "$Id$")
/*
* BE_Interface
*/
// default constructor
be_interface::be_interface (void)
: skel_count_ (0),
in_mult_inheritance_ (-1),
strategy_ (new be_interface_default_strategy (this))
{
this->size_type (be_decl::VARIABLE); // always the case
this->has_constructor (I_TRUE); // always the case
}
// constructor used to build the AST
be_interface::be_interface (UTL_ScopedName *n,
AST_Interface **ih,
long nih,
UTL_StrList *p)
: AST_Interface (n, ih, nih, p),
AST_Decl (AST_Decl::NT_interface, n, p),
UTL_Scope (AST_Decl::NT_interface),
skel_count_ (0),
in_mult_inheritance_ (-1),
strategy_ (new be_interface_default_strategy (this))
{
this->size_type (be_decl::VARIABLE); // always the case
this->has_constructor (I_TRUE); // always the case
}
be_interface::~be_interface (void)
{
// We know that it cannot be 0, but..
if (!this->strategy_)
delete this->strategy_;
}
be_interface_type_strategy *
be_interface::set_strategy (be_interface_type_strategy *new_strategy)
{
be_interface_type_strategy *old = this->strategy_;
if (new_strategy != 0)
this->strategy_ = new_strategy;
return old;
}
const char *
be_interface::local_name (void) const
{
// return the local name
return this->strategy_->local_name ();
}
const char *
be_interface::full_name (void) const
{
// return the stringified full name
return this->strategy_->full_name ();
}
const char *
be_interface::flat_name (void) const
{
// return the flattened full scoped name.
return this->strategy_->flat_name ();
}
const char *
be_interface::repoID (void) const
{
// retrieve the repository ID.
return this->strategy_->repoID ();
}
const char *
be_interface::full_skel_name (void) const
{
// retrieve the fully scoped skel class name.
return this->strategy_->full_skel_name ();
}
const char *
be_interface::full_coll_name (int type) const
{
// retrieve the fully qualified collocated class name
return this->strategy_->full_coll_name (type);
}
const char *
be_interface::local_coll_name (int type) const
{
// retrieve the fully qualified collocated class name.
return this->strategy_->local_coll_name (type);
}
const char *
be_interface::relative_skel_name (const char *skel_name)
{
// relative skeleton name
return this->strategy_->relative_skel_name (skel_name);
}
void
be_interface::compute_full_skel_name (const char *prefix,
char *&skelname)
{
if (skelname)
return;
else
{
long namelen;
UTL_IdListActiveIterator *i;
long first = I_TRUE;
long second = I_FALSE;
// in the first loop compute the total length
namelen = ACE_OS::strlen (prefix);
i = new UTL_IdListActiveIterator (this->name ());
while (!(i->is_done ()))
{
if (!first)
namelen += 2; // for "::"
else if (second)
first = second = I_FALSE;
// print the identifier
namelen += ACE_OS::strlen (i->item ()->get_string ()); //
// additional 4 for the POA_ characters
if (first)
{
if (ACE_OS::strcmp (i->item ()->get_string (), "") != 0)
// does not start with a ""
first = I_FALSE;
else
second = I_TRUE;
}
i->next ();
}
delete i;
ACE_NEW (skelname, char [namelen+1]);
skelname[0] = '\0';
first = I_TRUE;
second = I_FALSE;
ACE_OS::strcat (skelname, prefix);
i = new UTL_IdListActiveIterator (this->name ());
while (!(i->is_done ()))
{
if (!first)
ACE_OS::strcat (skelname, "::");
else if (second)
first = second = I_FALSE;
// print the identifier
ACE_OS::strcat (skelname, i->item ()->get_string ());
if (first)
{
if (ACE_OS::strcmp (i->item ()->get_string (), "") != 0)
// does not start with a ""
first = I_FALSE;
else
second = I_TRUE;
}
i->next ();
}
delete i;
}
return;
}
const char*
be_interface::relative_name (const char *localname,
const char *othername)
{
// some compilers do not like generating a fully scoped name for a
// type that was defined in the same enclosing scope in which it was
// defined. We have to emit just the partial name, relative to our
// "localname"
// The tricky part here is that it is not enough to check if the
// typename we are using was defined in the current scope. But we
// need to ensure that it was not defined in any of our ancestor
// scopes as well. If that is the case, then we can generate a fully
// scoped name for that type, else we use the ACE_NESTED_CLASS macro
// thus we need some sort of relative name to be generated
static char macro [NAMEBUFSIZE];
// UNUSED: be_decl *def_scope = 0; // our defining scope
char // hold the fully scoped name
def_name [NAMEBUFSIZE],
use_name [NAMEBUFSIZE];
char // these point to the curr and next component in the scope
*def_curr = def_name,
*def_next,
*use_curr = use_name,
*use_next;
ACE_OS::memset (macro, '\0', NAMEBUFSIZE);
ACE_OS::memset (def_name, '\0', NAMEBUFSIZE);
ACE_OS::memset (use_name, '\0', NAMEBUFSIZE);
// traverse every component of the def_scope and use_scope beginning at the
// root and proceeding towards the leaf trying to see if the components
// match. Continue until there is a match and keep accumulating the path
// traversed. This forms the first argument to the ACE_NESTED_CLASS
// macro. Whenever there is no match, the remaining components of the
// def_scope form the second argument
ACE_OS::strcpy (def_name, localname);
ACE_OS::strcpy (use_name, othername);
while (def_curr && use_curr)
{
// find the first occurrence of a :: and advance the next pointers accordingly
def_next = ACE_OS::strstr (def_curr, "::");
use_next = ACE_OS::strstr (use_curr, "::");
if (def_next)
*def_next = 0;
if (use_next)
*use_next = 0;
if (!ACE_OS::strcmp (def_curr, use_curr))
{
// they have same prefix, append to arg1
def_curr = (def_next ? (def_next+2) : 0); // skip the ::
use_curr = (use_next ? (use_next+2) : 0); // skip the ::
}
else
{
// we had overwritten a ':' by a '\0' for string comparison. We
// revert back because we want the rest of the relative name to be
// used
if (def_next)
*def_next = ':';
if (use_next)
*use_next = ':';
// no match. This is the end of the first argument. Get out
// of the loop as no more comparisons are necessary
break;
}
}
// start the 2nd argument of the macro
// copy the remaining def_name (if any left)
if (def_curr)
ACE_OS::strcat (macro, def_curr);
return macro;
}
// Am I in some kind of a multiple inheritance
int be_interface::in_mult_inheritance (void)
{
if (this->in_mult_inheritance_ == -1)
{
// compute once for all
// determine if we are in some form of a multiple inheritance
if (this->traverse_inheritance_graph
(be_interface::in_mult_inheritance_helper, 0) == -1)
{
ACE_ERROR_RETURN ((LM_ERROR,
"be_interface::in_mult_inheritance "
"error determining mult inheritance\n"),
-1);
}
}
return this->in_mult_inheritance_;
}
void be_interface::in_mult_inheritance (int mi)
{
if (this->in_mult_inheritance_ == -1)
this->in_mult_inheritance_ = mi;
}
//gen copy constructors
void
be_interface::gen_copy_ctors (TAO_OutStream* os)
{
this->traverse_inheritance_graph(be_interface::gen_copy_ctors_helper,os);
return;
}
int
be_interface::gen_copy_ctors_helper (be_interface* node, be_interface* base, TAO_OutStream *os)
{
static int first = 0;
if(node != base)
{
if(first)
{
*os << idl_global->impl_class_prefix () << base->flat_name () << idl_global->impl_class_suffix () << " (t)"
<< ", " << base->full_skel_name () << " (t)";
first = 0;
}
else
{
*os << ", " << idl_global->impl_class_prefix () << base->flat_name () << idl_global->impl_class_suffix () << " (t)"
<< ", " << base->full_skel_name () << " (t)"; ;
}
}
else
{
*os << ":";
first = 1;
}
return 1;
}
//generate default constructors
void
be_interface::gen_def_ctors (TAO_OutStream* os)
{
this->traverse_inheritance_graph(be_interface::gen_def_ctors_helper,os);
return;
}
int
be_interface::gen_def_ctors_helper (be_interface* node, be_interface* base, TAO_OutStream *os)
{
static int first = 0;
if(node != base)
{
if(first)
{
*os << idl_global->impl_class_prefix () << base->flat_name () << idl_global->impl_class_suffix () << " ()";
first = 0;
}
else
{
*os << ", " << idl_global->impl_class_prefix () << base->flat_name () << idl_global->impl_class_suffix () << " ()";
}
}
else
{
*os << ":";
first = 1;
}
return 1;
}
// generate the var definition. If <interface_name> is not 0, generate
// the var defn for that name. Otherwise, do it for the interface you
// are visiting (this).
int
be_interface::gen_var_defn (char* interface_name)
{
TAO_OutStream *ch; // output stream
TAO_NL nl; // end line
char namebuf [NAMEBUFSIZE]; // names
// Decide which name to use.
if (interface_name == 0)
interface_name = (char *) this->local_name ();
// Buffer with name of the var class.
ACE_OS::memset (namebuf, '\0', NAMEBUFSIZE);
ACE_OS::sprintf (namebuf,
"%s_var",
interface_name);
// Retrieve a singleton instance of the code generator
TAO_CodeGen *cg = TAO_CODEGEN::instance ();
ch = cg->client_header ();
// generate the var definition (always in the client header).
// Depending upon the data type, there are some differences which we account
// for over here.
ch->indent (); // start with whatever was our current indent level
*ch << "class " << idl_global->stub_export_macro ()
<< " " << namebuf << nl;
*ch << "{" << nl;
*ch << "public:\n";
ch->incr_indent ();
// default constr
*ch << namebuf << " (void); // default constructor" << nl;
*ch << namebuf << " (" << interface_name << "_ptr);" << nl;
// copy constructor
*ch << namebuf << " (const " << namebuf <<
" &); // copy constructor" << nl;
// destructor
*ch << "~" << namebuf << " (void); // destructor" << nl;
*ch << nl;
// assignment operator from a pointer
*ch << namebuf << " &operator= (" << interface_name << "_ptr);" << nl;
// assignment from _var
*ch << namebuf << " &operator= (const " << namebuf <<
" &);" << nl;
// arrow operator
*ch << interface_name << "_ptr operator-> (void) const;" << nl;
*ch << nl;
// other extra types (cast operators, [] operator, and others)
*ch << "operator const " << interface_name << "_ptr &() const;" << nl;
*ch << "operator " << interface_name << "_ptr &();" << nl;
*ch << "// in, inout, out, _retn " << nl;
// the return types of in, out, inout, and _retn are based on the parameter
// passing rules and the base type
*ch << interface_name << "_ptr in (void) const;" << nl;
*ch << interface_name << "_ptr &inout (void);" << nl;
*ch << interface_name << "_ptr &out (void);" << nl;
*ch << interface_name << "_ptr _retn (void);" << nl;
// generate an additional member function that returns the underlying pointer
*ch << interface_name << "_ptr ptr (void) const;\n";
*ch << "\n";
ch->decr_indent ();
// private
*ch << "private:\n";
ch->incr_indent ();
*ch << interface_name << "_ptr ptr_;\n";
ch->decr_indent ();
*ch << "};\n\n";
return 0;
}
// implementation of the _var class. All of these get generated in the
// inline file.
// If the argument is 0, then use the name in <this>, otherwise use
// the name given. Just making the class more useful.
int
be_interface::gen_var_impl (char *interface_local_name,
char *interface_full_name)
{
TAO_OutStream *ci; // output stream
TAO_NL nl; // end line
char fname [NAMEBUFSIZE]; // to hold the full and
char lname [NAMEBUFSIZE]; // local _var names
// Decide on the names to use.
// Even if one argument is 0, there is no point using the
// arguments. Let us then use the name in this node.
if (interface_local_name == 0 || interface_full_name == 0)
{
interface_local_name = (char *) local_name ();
interface_full_name = (char *) this->full_name ();
}
ACE_OS::memset (fname, '\0', NAMEBUFSIZE);
ACE_OS::sprintf (fname, "%s_var", interface_full_name);
ACE_OS::memset (lname, '\0', NAMEBUFSIZE);
ACE_OS::sprintf (lname, "%s_var", interface_local_name);
// retrieve a singleton instance of the code generator
TAO_CodeGen *cg = TAO_CODEGEN::instance ();
ci = cg->client_inline ();
// generate the var implementation in the inline file
// Depending upon the data type, there are some differences which we
// account for over here.
ci->indent (); // start with whatever was our current indent level
*ci << "// *************************************************************"
<< nl;
*ci << "// Inline operations for class " << fname << nl;
*ci << "// *************************************************************\n\n";
// default constr
*ci << "ACE_INLINE" << nl;
*ci << fname << "::" << lname <<
" (void) // default constructor" << nl;
*ci << " " << ": ptr_ (" << interface_full_name << "::_nil ())" << nl;
*ci << "{}\n\n";
// constr from a _ptr
ci->indent ();
*ci << "ACE_INLINE" << nl;
*ci << fname << "::" << lname << " (" << interface_full_name << "_ptr p)" << nl;
*ci << " : ptr_ (p)" << nl;
*ci << "{}\n\n";
// the additional ptr () member function. This member function must be
// defined before the remaining member functions including the copy
// constructor because this inline function is used elsewhere. Hence to make
// inlining of this function possible, we must define it before its use.
ci->indent ();
*ci << "ACE_INLINE " << interface_full_name << "_ptr " << nl;
*ci << fname << "::ptr (void) const" << nl;
*ci << "{\n";
ci->incr_indent ();
*ci << "return this->ptr_;\n";
ci->decr_indent ();
*ci << "}\n\n";
// copy constructor
ci->indent ();
*ci << "ACE_INLINE" << nl;
*ci << fname << "::" << lname << " (const " << fname <<
" &p) // copy constructor" << nl;
*ci << " : ptr_ (" << interface_full_name << "::_duplicate (p.ptr ()))" << nl;
*ci << "{}\n\n";
// destructor
ci->indent ();
*ci << "ACE_INLINE" << nl;
*ci << fname << "::~" << lname << " (void) // destructor" << nl;
*ci << "{\n";
ci->incr_indent ();
*ci << "CORBA::release (this->ptr_);\n";
ci->decr_indent ();
*ci << "}\n\n";
// assignment operator
ci->indent ();
*ci << "ACE_INLINE " << fname << " &" << nl;
*ci << fname << "::operator= (" << interface_full_name <<
"_ptr p)" << nl;
*ci << "{\n";
ci->incr_indent ();
*ci << "CORBA::release (this->ptr_);" << nl;
*ci << "this->ptr_ = p;" << nl;
*ci << "return *this;\n";
ci->decr_indent ();
*ci << "}\n\n";
// assignment operator from _var
ci->indent ();
*ci << "ACE_INLINE " << fname << " &" << nl;
*ci << fname << "::operator= (const " << fname <<
" &p)" << nl;
*ci << "{\n";
ci->incr_indent ();
*ci << "if (this != &p)" << nl;
*ci << "{\n";
ci->incr_indent ();
*ci << "CORBA::release (this->ptr_);" << nl;
*ci << "this->ptr_ = " << interface_full_name << "::_duplicate (p.ptr ());\n";
ci->decr_indent ();
*ci << "}" << nl;
*ci << "return *this;\n";
ci->decr_indent ();
*ci << "}\n\n";
// other extra methods - cast operator ()
ci->indent ();
*ci << "ACE_INLINE " << nl;
*ci << fname << "::operator const " << interface_full_name <<
"_ptr &() const // cast" << nl;
*ci << "{\n";
ci->incr_indent ();
*ci << "return this->ptr_;\n";
ci->decr_indent ();
*ci << "}\n\n";
ci->indent ();
*ci << "ACE_INLINE " << nl;
*ci << fname << "::operator " << interface_full_name << "_ptr &() // cast " << nl;
*ci << "{\n";
ci->incr_indent ();
*ci << "return this->ptr_;\n";
ci->decr_indent ();
*ci << "}\n\n";
// operator->
ci->indent ();
*ci << "ACE_INLINE " << interface_full_name << "_ptr " << nl;
*ci << fname << "::operator-> (void) const" << nl;
*ci << "{\n";
ci->incr_indent ();
*ci << "return this->ptr_;\n";
ci->decr_indent ();
*ci << "}\n\n";
// in, inout, out, and _retn
ci->indent ();
*ci << "ACE_INLINE " << interface_full_name << "_ptr" << nl;
*ci << fname << "::in (void) const" << nl;
*ci << "{\n";
ci->incr_indent ();
*ci << "return this->ptr_;\n";
ci->decr_indent ();
*ci << "}\n\n";
ci->indent ();
*ci << "ACE_INLINE " << interface_full_name << "_ptr &" << nl;
*ci << fname << "::inout (void)" << nl;
*ci << "{\n";
ci->incr_indent ();
*ci << "return this->ptr_;\n";
ci->decr_indent ();
*ci << "}\n\n";
ci->indent ();
*ci << "ACE_INLINE " << interface_full_name << "_ptr &" << nl;
*ci << fname << "::out (void)" << nl;
*ci << "{\n";
ci->incr_indent ();
*ci << "CORBA::release (this->ptr_);" << nl;
*ci << "this->ptr_ = " << interface_full_name << "::_nil ();" << nl;
*ci << "return this->ptr_;\n";
ci->decr_indent ();
*ci << "}\n\n";
ci->indent ();
*ci << "ACE_INLINE " << interface_full_name << "_ptr " << nl;
*ci << fname << "::_retn (void)" << nl;
*ci << "{\n";
ci->incr_indent ();
*ci << "// yield ownership of managed obj reference" << nl;
*ci << interface_full_name << "_ptr val = this->ptr_;" << nl;
*ci << "this->ptr_ = " << interface_full_name << "::_nil ();" << nl;
*ci << "return val;\n";
ci->decr_indent ();
*ci << "}\n\n";
return 0;
}
// Generate the out definition. If <interface_name> is not 0, generate
// the out defn for that name. Otherwise, do it for the interface you
// are visiting (this).
int
be_interface::gen_out_defn (char *interface_name)
{
TAO_OutStream *ch; // output stream
TAO_NL nl; // end line
char namebuf [NAMEBUFSIZE]; // to hold the _out name
// Decide which name to use.
if (interface_name == 0)
interface_name = (char *) this->local_name ();
// Create the buffer with the name of the out class.
ACE_OS::memset (namebuf, '\0', NAMEBUFSIZE);
ACE_OS::sprintf (namebuf,
"%s_out",
interface_name);
// Retrieve a singleton instance of the code generator
TAO_CodeGen *cg = TAO_CODEGEN::instance ();
ch = cg->client_header ();
// generate the out definition (always in the client header)
ch->indent (); // start with whatever was our current indent level
*ch << "class " << idl_global->stub_export_macro ()
<< " " << namebuf << nl;
*ch << "{" << nl;
*ch << "public:\n";
ch->incr_indent ();
// No default constructor
// constructor from a pointer
*ch << namebuf << " (" << interface_name << "_ptr &);" << nl;
// constructor from a _var &
*ch << namebuf << " (" << interface_name << "_var &);" << nl;
// constructor from a _out &
*ch << namebuf << " (const " << namebuf << " &);" << nl;
// assignment operator from a _out &
*ch << namebuf << " &operator= (const " << namebuf << " &);" << nl;
// assignment operator from a pointer &, cast operator, ptr fn, operator
// -> and any other extra operators
// only interface allows assignment from var &
*ch << namebuf << " &operator= (const " << interface_name << "_var &);" << nl;
*ch << namebuf << " &operator= (" << interface_name << "_ptr);" << nl;
// cast
*ch << "operator " << interface_name << "_ptr &();" << nl;
// ptr fn
*ch << interface_name << "_ptr &ptr (void);" << nl;
// operator ->
*ch << interface_name << "_ptr operator-> (void);" << nl;
*ch << "\n";
ch->decr_indent ();
*ch << "private:\n";
ch->incr_indent ();
*ch << interface_name << "_ptr &ptr_;\n";
ch->decr_indent ();
*ch << "};\n\n";
return 0;
}
// Generate the out class definition. If <interface_name> is not 0,
// generate the out defn for that name. Otherwise, do it for the
// interface you are visiting (this).
int
be_interface::gen_out_impl (char *interface_local_name,
char *interface_full_name)
{
TAO_OutStream *ci; // output stream
TAO_NL nl; // end line
char fname [NAMEBUFSIZE]; // to hold the full and
char lname [NAMEBUFSIZE]; // local _out names
// Even if one argument is 0, there is no point using the
// arguments. Let us then use the name in this node.
if (interface_local_name == 0 || interface_full_name == 0)
{
interface_local_name = (char *) local_name ();
interface_full_name = (char *) this->full_name ();
}
ACE_OS::memset (fname, '\0', NAMEBUFSIZE);
ACE_OS::sprintf (fname, "%s_out", interface_full_name);
ACE_OS::memset (lname, '\0', NAMEBUFSIZE);
ACE_OS::sprintf (lname, "%s_out", interface_local_name);
// retrieve a singleton instance of the code generator
TAO_CodeGen *cg = TAO_CODEGEN::instance ();
ci = cg->client_inline ();
// generate the var implementation in the inline file
// Depending upon the data type, there are some differences which we account
// for over here.
ci->indent (); // start with whatever was our current indent level
*ci << "// *************************************************************"
<< nl;
*ci << "// Inline operations for class " << fname << nl;
*ci << "// *************************************************************\n\n";
// constr from a _ptr
ci->indent ();
*ci << "ACE_INLINE" << nl;
*ci << fname << "::" << lname << " (" << interface_full_name << "_ptr &p)" << nl;
*ci << " : ptr_ (p)" << nl;
*ci << "{\n";
ci->incr_indent ();
*ci << "this->ptr_ = " << interface_full_name << "::_nil ();\n";
ci->decr_indent ();
*ci << "}\n\n";
// constructor from _var &
ci->indent ();
*ci << "ACE_INLINE" << nl;
*ci << fname << "::" << lname << " (" << interface_full_name <<
"_var &p) // constructor from _var" << nl;
*ci << " : ptr_ (p.out ())" << nl;
*ci << "{\n";
ci->incr_indent ();
*ci << "CORBA::release (this->ptr_);" << nl;
*ci << "this->ptr_ = " << interface_full_name << "::_nil ();\n";
ci->decr_indent ();
*ci << "}\n\n";
// copy constructor
ci->indent ();
*ci << "ACE_INLINE" << nl;
*ci << fname << "::" << lname << " (const " << fname <<
" &p) // copy constructor" << nl;
*ci << " : ptr_ (ACE_const_cast (" << fname << "&,p).ptr_)" << nl;
*ci << "{}\n\n";
// assignment operator from _out &
ci->indent ();
*ci << "ACE_INLINE " << fname << " &" << nl;
*ci << fname << "::operator= (const " << fname <<
" &p)" << nl;
*ci << "{\n";
ci->incr_indent ();
*ci << "this->ptr_ = ACE_const_cast (" << fname << "&,p).ptr_;" << nl;
*ci << "return *this;\n";
ci->decr_indent ();
*ci << "}\n\n";
// assignment operator from _var
ci->indent ();
*ci << "ACE_INLINE " << fname << " &" << nl;
*ci << fname << "::operator= (const " << interface_full_name <<
"_var &p)" << nl;
*ci << "{\n";
ci->incr_indent ();
*ci << "this->ptr_ = " << interface_full_name << "::_duplicate (p.ptr ());" << nl;
*ci << "return *this;\n";
ci->decr_indent ();
*ci << "}\n\n";
// assignment operator from _ptr
ci->indent ();
*ci << "ACE_INLINE " << fname << " &" << nl;
*ci << fname << "::operator= (" << interface_full_name <<
"_ptr p)" << nl;
*ci << "{\n";
ci->incr_indent ();
*ci << "this->ptr_ = p;" << nl;
*ci << "return *this;\n";
ci->decr_indent ();
*ci << "}\n\n";
// other extra methods - cast operator ()
ci->indent ();
*ci << "ACE_INLINE " << nl;
*ci << fname << "::operator " << interface_full_name <<
"_ptr &() // cast" << nl;
*ci << "{\n";
ci->incr_indent ();
*ci << "return this->ptr_;\n";
ci->decr_indent ();
*ci << "}\n\n";
// ptr function
ci->indent ();
*ci << "ACE_INLINE " << interface_full_name << "_ptr &" << nl;
*ci << fname << "::ptr (void) // ptr" << nl;
*ci << "{\n";
ci->incr_indent ();
*ci << "return this->ptr_;\n";
ci->decr_indent ();
*ci << "}\n\n";
// operator->
ci->indent ();
*ci << "ACE_INLINE " << interface_full_name << "_ptr " << nl;
*ci << fname << "::operator-> (void)" << nl;
*ci << "{\n";
ci->incr_indent ();
*ci << "return this->ptr_;\n";
ci->decr_indent ();
*ci << "}\n\n";
return 0;
}
// helper.
int
be_interface::gen_operation_table ()
{
TAO_OutStream *os; // output stream.
TAO_NL nl; // end line.
// Retrieve the singleton instance of the CodeGen.
TAO_CodeGen *cg = 0;
cg = TAO_CODEGEN::instance ();
// Check out the op_lookup_strategy.
switch (cg->lookup_strategy ())
{
case TAO_CodeGen::TAO_DYNAMIC_HASH:
// Init the outstream appropriately.
os = this->strategy_->get_out_stream ();
// start from current indentation level.
os->indent ();
// Start the table generation.
*os << "static const TAO_operation_db_entry " << this->flat_name () <<
"_operations [] = {\n";
os->incr_indent (0);
// Traverse the graph.
if (this->traverse_inheritance_graph (be_interface::gen_optable_helper, os) == -1)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_interface::gen_operation_table - "
"inheritance graph traversal failed\n"), -1);
}
// generate the skeleton for the is_a method.
os->indent ();
*os << "{\"_is_a\", &" << this->full_skel_name () << "::_is_a_skel},\n";
this->skel_count_++;
os->indent ();
*os << "{\"_non_existent\", &" << this->full_skel_name () << "::_non_existent_skel}\n";
this->skel_count_++;
os->decr_indent ();
*os << "};" << nl << nl;
// XXXASG - this code should be based on using different strategies for
// demux - for next release
*os << "static const CORBA::Long _tao_" << this->flat_name ()
<< "_optable_size = sizeof (ACE_Hash_Map_Entry<const char *,"
<< " TAO_Skeleton>) * (" << (3*this->skel_count_)
<< ");" << be_nl;
*os << "static char _tao_" << this->flat_name () << "_optable_pool "
<< "[_tao_" << this->flat_name () << "_optable_size];" << be_nl;
*os << "static ACE_Static_Allocator_Base _tao_" << this->flat_name ()
<< "_allocator (_tao_" << this->flat_name () << "_optable_pool, "
<< "_tao_" << this->flat_name () << "_optable_size);" << be_nl;
*os << "static TAO_Dynamic_Hash_OpTable tao_"
<< this->flat_name () << "_optable " << "(" << be_idt << be_idt_nl
<< this->flat_name () << "_operations," << be_nl
<< this->skel_count_ << "," << be_nl
<< 2*this->skel_count_ << "," << be_nl
<< "&_tao_" << this->flat_name () << "_allocator" << be_uidt_nl
<< ");" << be_uidt_nl;
break;
case TAO_CodeGen::TAO_LINEAR_SEARCH:
// For generating linear search also, we are calling GPERF
// only.
case TAO_CodeGen::TAO_BINARY_SEARCH:
// For generating binary search also, we are calling GPERF
// only.
case TAO_CodeGen::TAO_PERFECT_HASH:
// For each interface in the IDL, have a new temp file to
// collect the input for the gperf program.
{
// Temp file name.
char *temp_file = 0;
ACE_NEW_RETURN (temp_file,
char [ACE_OS::strlen (idl_global->temp_dir ()) +
ACE_OS::strlen (this->flat_name ()) +
ACE_OS::strlen (".gperf") + 1],
-1);
ACE_OS::sprintf (temp_file,
"%s%s.gperf",
idl_global->temp_dir (),
this->flat_name ());
// Save this file name with the codegen singleton.
cg->gperf_input_filename (temp_file);
// Make a new outstream to hold the gperf_temp_file for this
// interface.
// Retrieve the singleton instance to the outstream factory.
TAO_OutStream_Factory *factory =
TAO_OUTSTREAM_FACTORY::instance ();
// Get a new instance for the temp file.
os = factory->make_outstream ();
if (os == 0)
ACE_ERROR_RETURN ((LM_ERROR,
"be_visitor_interface_ss",
"::",
"visit_interface-",
"make_outstream failed\n"),
-1);
// Store the outstream with the codegen singleton.
cg->gperf_input_stream (os);
// Open the temp file.
if (os->open (temp_file,
TAO_OutStream::TAO_GPERF_INPUT) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"be_visitor_interface_ss",
"::",
"visit_interface-",
"gperf_input.tmp file open failed\n"),
-1);
// Add the gperf input header.
this->gen_gperf_input_header (os);
// Traverse the graph.
if (this->traverse_inheritance_graph (be_interface::gen_optable_helper, os) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_interface::gen_operation_table - "
"inheritance graph traversal failed\n"),
-1);
// Generate the skeleton for the is_a method.
os->indent ();
*os << "_is_a" << ", &"
<< this->full_skel_name ()
<< "::_is_a_skel\n";
this->skel_count_++;
os->indent ();
*os << "_non_existent, &"
<< this->full_skel_name ()
<< "::_non_existent_skel\n";
this->skel_count_++;
// Input to the gperf is ready. Run gperf and get things
// done. This method also unlinks the temp file that we used
// for the gperf.
this->gen_gperf_things ();
}
break;
default:
ACE_ERROR_RETURN ((LM_ERROR,
"be_interface",
"::",
"gen_operation_table",
"unknown op_lookup_strategy\n"),
-1);
}
return 0;
}
// Output the header (type declaration and %%) to the gperf's input
// file.
void
be_interface::gen_gperf_input_header (TAO_OutStream *os)
{
*os << "class TAO_operation_db_entry {\n"
<< "public:\n"
<< "\tchar *opname_;" << "\n"
<< "\tTAO_Skeleton skel_ptr_;" << "\n"
<< "};" << "\n"
<< "%%"
<< "\n";
}
// we separate the generation of operation table entries from the
// "gen_operation_table" method. This enables us to invoke generation of
// entries for interfaces from which we inherit without any additional
// code. The parameter "derived" is the one for which the entire operation
// table is being built.
int
be_interface::gen_optable_entries (be_interface *derived)
{
UTL_ScopeActiveIterator *si;
AST_Decl *d;
TAO_OutStream *os; // output stream
// retrieve a singleton instance of the code generator
TAO_CodeGen *cg = TAO_CODEGEN::instance ();
switch (cg->lookup_strategy ())
{
case TAO_CodeGen::TAO_DYNAMIC_HASH:
// Init the outstream.
os = this->strategy_->get_out_stream ();
// The major stuff.
if (this->nmembers () > 0)
{
// if there are elements in this scope i.e., any operations and
// attributes defined by "this" which happens to be the same as "derived"
// or one of its ancestors.
si = new UTL_ScopeActiveIterator (this, UTL_Scope::IK_decls);
// instantiate a scope iterator.
while (!(si->is_done ()))
{
// get the next AST decl node
d = si->item ();
if (d->node_type () == AST_Decl::NT_op)
{
// Start from current indentation level
os->indent ();
// we are an operation node
*os << "{\"" << d->original_local_name () << "\", &"
<< derived->full_skel_name () << "::"
<< d->local_name () << "_skel},\n";
derived->skel_count_++;
}
else if (d->node_type () == AST_Decl::NT_attr)
{
AST_Attribute *attr;
// Start from current indentation level.
os->indent ();
// Generate only the "get" entry if we are
// readonly.
*os << "{\"_get_" << d->original_local_name ()
<< "\", &" << derived->full_skel_name ()
<< "::_get_" << d->local_name () << "_skel},\n";
derived->skel_count_++;
attr = AST_Attribute::narrow_from_decl (d);
if (!attr)
return -1;
if (!attr->readonly ())
{
// the set method
os->indent (); // start from current indentation level
*os << "{\"_set_" << d->original_local_name ()
<< "\", &" << derived->full_skel_name ()
<< "::_set_" << d->local_name () << "_skel},\n";
derived->skel_count_++;
}
}
si->next ();
} // end of while
delete si; // free the iterator object
}
break;
case TAO_CodeGen::TAO_LINEAR_SEARCH:
case TAO_CodeGen::TAO_BINARY_SEARCH:
case TAO_CodeGen::TAO_PERFECT_HASH:
// We call GPERF for all these three strategies.
// Init the outstream.
os = cg->gperf_input_stream ();
if (this->nmembers () > 0)
{
// if there are elements in this scope i.e., any operations and
// attributes defined by "this" which happens to be the same as "derived"
// or one of its ancestors.
si = new UTL_ScopeActiveIterator (this, UTL_Scope::IK_decls);
// instantiate a scope iterator.
while (!(si->is_done ()))
{
// Get the next AST decl node.
d = si->item ();
if (d->node_type () == AST_Decl::NT_op)
{
//
// Generate operation name.
//
// Start from current indentation level
os->indent ();
// We are an operation node. We use the original
// operation name, not the one with _cxx_ in it.
*os << d->original_local_name () << ",\t&"
<< derived->full_skel_name () << "::"
<< d->local_name () << "_skel" << "\n";
derived->skel_count_++;
}
else if (d->node_type () == AST_Decl::NT_attr)
{
AST_Attribute *attr;
// Start from current indentation level
os->indent ();
// Generate only the "get" entry if we are readonly
*os << "_get_" << d->original_local_name () << ",\t&"
<< derived->full_skel_name () << "::_get_"
<< d->local_name () << "_skel\n";
derived->skel_count_++;
attr = AST_Attribute::narrow_from_decl (d);
if (!attr)
return -1;
if (!attr->readonly ())
{
// the set method
os->indent (); // start from current indentation level
*os << "_set_" << d->original_local_name () << ",\t&"
<< derived->full_skel_name () << "::_set_"
<< d->local_name () << "_skel\n";
derived->skel_count_++;
}
}
si->next ();
} // end of while
delete si; // free the iterator object
}
break;
default:
ACE_ERROR_RETURN ((LM_ERROR,
"be_interface",
"::",
"gen_optable_entries",
"unknown op_lookup_strategy\n"),
-1);
}
return 0;
}
// template method that traverses the inheritance graph in a breadth-first
// style. The actual work on each element in the inheritance graph is carried
// out by the function passed as argument
int
be_interface::traverse_inheritance_graph (be_interface::tao_code_emitter gen,
TAO_OutStream *os)
{
long i; // loop index
ACE_Unbounded_Queue <be_interface*> queue; // Queue data structure needed for
// breadth-first traversal of
// inheritance tree
// For a special case of a deeply nested inheritance graph and one specific
// way of inheritance in which a node that was already visited, but is not present in
// the queue, gets inserted at the tail. This situation arises when a node
// multiply inherits from two or more interfaces in which the first parent is
// higher up in the tree than the second parent. In addition, if the second
// parent turns out to be a child of the first .
ACE_Unbounded_Queue <be_interface*> del_queue; // queue of dequeued nodes to
// be searched for the above case
// insert ourselves in the Queue
if (queue.enqueue_tail (this) == -1)
{
ACE_ERROR_RETURN ((LM_ERROR, "(%N:%l) be_interface::traverse_inheritance_graph - "
"error generating entries\n"), -1);
}
// do until queue is empty
while (!queue.is_empty ())
{
be_interface *bi; // element inside the queue
// use breadth-first strategy i.e., first generate entries for ourselves,
// followed by nodes that we immediately inherit from, and so on. In the
// process make sure that we do not generate code for the same node more
// than once. Such a case may arise due to multiple inheritance forming a
// diamond like inheritance graph.
// dequeue the element at the head of the queue
if (queue.dequeue_head (bi))
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_interface::traverse_graph - "
"dequeue_head failed\n"), -1);
}
// insert the dequeued element in the del_queue
if (del_queue.enqueue_tail (bi) == -1)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_interface::traverse_graph - "
"enqueue_head failed\n"), -1);
}
// use the helper method to generate code for ourself using the
// properties of the element dequeued. For the first iteration, the
// element dequeued and "this" will be the same i.e., ourselves
if (gen (this, bi, os) == -1)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_interface::traverse_graph - "
"helper code gen failed\n"), -1);
}
// now check if the dequeued element has any ancestors. If yes, insert
// them inside the queue making sure that there are no duplicates
for (i=0; i < bi->n_inherits (); i++)
{
be_interface *parent; // parent of the dequeued element
// initialize an iterator to search the queue for duplicates
ACE_Unbounded_Queue_Iterator<be_interface*> q_iter (queue);
// retrieve the next parent from which the dequeued element inherits
parent = be_interface::narrow_from_decl (bi->inherits ()[i]);
if (!parent)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_interface::gen_server_skeletons - "
"bad inherited interface\n"), -1);
}
// now insert this node at the tail of the queue, but make sure that
// it doesn't already exist in the queue
int found = 0;
while (!q_iter.done ())
{
be_interface **temp; // queue element
(void) q_iter.next (temp);
if (!ACE_OS::strcmp (parent->full_name (), (*temp)->full_name ()))
{
// we exist in this queue and cannot be inserted
found = 1;
}
if (found)
break;
(void) q_iter.advance ();
} // end of while
// initialize an iterator to search the del_queue for duplicates
ACE_Unbounded_Queue_Iterator<be_interface*> del_q_iter (del_queue);
while (!found && !del_q_iter.done ())
{
be_interface **temp; // queue element
(void) del_q_iter.next (temp);
if (!ACE_OS::strcmp (parent->full_name (), (*temp)->full_name ()))
{
// we exist in this del_queue and cannot be inserted
found = 1;
}
if (found)
break;
(void) del_q_iter.advance ();
} // end of while
if (!found)
{
// insert the parent in the queue
if (queue.enqueue_tail (parent) == -1)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_interface::gen_server_skeletons - "
"enqueue op failed\n"), -1);
}
}
} // end of for loop
} // end of while queue not empty
return 0;
}
// helpers passed to the template method
int
be_interface::gen_optable_helper (be_interface *derived,
be_interface *ancestor,
TAO_OutStream * /*os*/)
{
// generate entries for the derived class using the properties of its
// ancestors
if (ancestor->gen_optable_entries (derived) == -1)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_interface::gen_operation_table - "
"error generating entries for inherited"
"interfaces\n"), -1);
}
return 0;
}
// Run GPERF and get the correct lookup and other operations
// depending on which strategy we are using. Returns 0 on sucess, -1
// on error.
int
be_interface::gen_gperf_things (void)
{
// GPERF can give Binary search, Linear search and Perfect Hash
// methods. Generate the class defintion according to that.
// Codegen singleton.
TAO_CodeGen *cg = TAO_CODEGEN::instance ();
// Generate the correct class definition for the operation lookup
// strategy. Then, get the lookup method from GPERF. And then,
// instantiate the correct class for the operation lookup strategy
// we are following.
switch (cg->lookup_strategy ())
{
case TAO_CodeGen::TAO_PERFECT_HASH:
// Output a class definition deriving from
// TAO_Perfect_Hash_OpTable.
gen_perfect_hash_class_definition ();
// Call GPERF and get the methods defined.
if (gen_gperf_lookup_methods () == -1)
return -1;
// Create an instance of the correct class corresponding the
// operation lookup strategy we are following.
gen_perfect_hash_instance ();
break;
case TAO_CodeGen::TAO_BINARY_SEARCH:
// Output a class definition deriving from
// TAO_Binary_Search_OpTable.
this->gen_binary_search_class_definition ();
// Call GPERF and get the methods defined.
if (gen_gperf_lookup_methods () == -1)
return -1;
// Create an instance of the correct class corresponding the
// operation lookup strategy we are following.
gen_binary_search_instance ();
break;
case TAO_CodeGen::TAO_LINEAR_SEARCH:
// Output a class definition deriving from
// TAO_Linear_Search_OpTable.
gen_linear_search_class_definition ();
// Call GPERF and get the methods defined.
if (gen_gperf_lookup_methods () == -1)
return -1;
// Create an instance of the correct class corresponding the
// operation lookup strategy we are following.
gen_linear_search_instance ();
break;
default:
ACE_ERROR_RETURN ((LM_ERROR,
"tao_idl:ERROR:%N:%l:Unknown Operation Lookup Strategy\n"),
-1);
}
return 0;
}
// Outputs the class definition for the perfect hashing. This class
// will inherit from the TAO_Perfect_Hash_OpTable.
void
be_interface::gen_perfect_hash_class_definition (void)
{
// Outstream.
TAO_OutStream *os = this->strategy_->get_out_stream ();
*os << "class " << "TAO_" << this->flat_name () << "_Perfect_Hash_OpTable"
<< " : public TAO_Perfect_Hash_OpTable"
<< be_nl
<< "{"
<< be_nl
<< "private:"
<< be_nl
<< " unsigned int hash (const char *str, unsigned int len);"
<< be_nl
<< "public:"
<< be_nl
<< " const TAO_operation_db_entry * lookup (const char *str, unsigned int len);"
<< be_nl
<< "};"
<< "\n";
}
// Outputs the class definition for the binary searching. This class
// will inherit from the TAO_Binary_Seach_OpTable.
void
be_interface::gen_binary_search_class_definition (void)
{
// Outstream.
TAO_OutStream *os = this->strategy_->get_out_stream ();
*os << "class " << "TAO_" << this->flat_name () << "_Binary_Search_OpTable"
<< " : public TAO_Binary_Search_OpTable"
<< be_nl
<< "{"
<< be_nl
<< "public:"
<< be_nl
<< " const TAO_operation_db_entry * lookup (const char *str);"
<< be_nl
<< "};"
<< "\n";
}
// Outputs the class definition for the linear search. This class
// will inherit from the TAO_Linear_Search_OpTable.
void
be_interface::gen_linear_search_class_definition (void)
{
// Outstream.
TAO_OutStream *ss = this->strategy_->get_out_stream ();
*ss << "class " << "TAO_" << this->flat_name () << "_Linear_Search_OpTable"
<< " : public TAO_Linear_Search_OpTable"
<< be_nl
<< "{"
<< be_nl
<< "public:"
<< be_nl
<< " const TAO_operation_db_entry * lookup (const char *str);"
<< be_nl
<< "};"
<< "\n";
}
// We have collected the input (Operations and the corresponding
// skeleton pointers) for the gperf program. Now let us execute gperf
// and get things done.
// GPERF reads from our temp file and write to the Server Skeleton
// file.
int
be_interface::gen_gperf_lookup_methods (void)
{
// Using ACE_Process.
ACE_Process process;
ACE_Process_Options process_options;
// Codegen's singleton.
TAO_CodeGen *cg = TAO_CODEGEN::instance ();
// Adjust the offset of the underlying file pointer.
ACE_OS::rewind (cg->gperf_input_stream ()->file ());
// Set the stdin and stdout appropriately for the gperf program.
// Stdin is our temp file. Close the temp file and open. We will use
// <open_temp_file> to open the file now, so that the file will get
// deleted once when we close the file.
// Close the file.
if (ACE_OS::fclose (cg->gperf_input_stream ()->file ()) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"%p:File close failed on temp gperf's input file\n",
"fclose"),
-1);
// Open the temp file.
ACE_HANDLE input = ACE::open_temp_file (cg->gperf_input_filename (),
O_RDONLY);
if (input == ACE_INVALID_HANDLE)
ACE_ERROR_RETURN ((LM_ERROR,
"%p:File open failed on gperf's temp input file\n",
"open_temp_file"),
-1);
// Stdout is server skeleton. Do *not* close the file, just open
// again with ACE_OS::open with WRITE + APPEND option.. After this,
// remember to update the file offset to the correct location.
ACE_HANDLE output = ACE_OS::open (this->strategy_->get_out_stream_fname (),
O_WRONLY | O_APPEND);
//ACE_HANDLE output = ACE_OS::open (idl_global->be_get_server_skeleton_fname (),
// O_WRONLY | O_APPEND);
if (output == ACE_INVALID_HANDLE)
ACE_ERROR_RETURN ((LM_ERROR,
"%p:File open failed on server skeleton file\n",
"open"),
-1);
// Set the handles now in the process options.
process_options.set_handles (input, output);
// Set the command line for the gperf program. Give the right
// arguments for the operation lookup strategy that we are using.
switch (cg->lookup_strategy ())
{
// Perfect Hashing.
case TAO_CodeGen::TAO_PERFECT_HASH:
process_options.command_line ("%s"
" "
"-m -M -J -c -C"
" "
"-D -E -T -f 0"
" "
"-F 0"
" "
"-a -o -t -p -K"
" "
"opname_ -L C++"
" "
"-Z TAO_%s_Perfect_Hash_OpTable"
" "
"-N lookup",
idl_global->gperf_path (),
this->flat_name ());
break;
// Binary search methods from GPERF. Everythis and the -B flag.
case TAO_CodeGen::TAO_BINARY_SEARCH:
process_options.command_line ("%s"
" "
"-B"
" "
"-m -M -J -c -C"
" "
"-D -E -T -f 0"
" "
"-F 0"
" "
"-a -o -t -p -K"
" "
"opname_ -L C++"
" "
"-Z TAO_%s_Binary_Search_OpTable"
" "
"-N lookup",
idl_global->gperf_path (),
this->flat_name ());
break;
// Linear search methods from GPERF. Everything and the -z flag.
case TAO_CodeGen::TAO_LINEAR_SEARCH:
process_options.command_line ("%s"
" "
"-b"
" "
"-m -M -J -c -C"
" "
"-D -E -T -f 0"
" "
"-F 0"
" "
"-a -o -t -p -K"
" "
"opname_ -L C++"
" "
"-Z TAO_%s_Linear_Search_OpTable"
" "
"-N lookup",
idl_global->gperf_path (),
this->flat_name ());
break;
default:
ACE_ERROR_RETURN ((LM_ERROR,
"tao_idl:ERROR:%N:%l:Unknown Operation Lookup Strategy\n"),
-1);
}
// Spawn a process for gperf.
if (process.spawn (process_options) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"Error:%p:Couldnt spawn a process for gperf program\n"),
-1);
// Wait for gperf to complete.
if (process.wait () == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"Error:%p:Error on wait'ing for completion of gperf program.\n",
"process.wait"),
-1);
// Adjust the file offset to the EOF for the server skeleton file.
ACE_OS::fseek (this->strategy_->get_out_stream()->file (), 0, SEEK_END);
return 0;
}
// Create an instance of this perfect hash table.
void
be_interface::gen_perfect_hash_instance ()
{
// Outstream.
TAO_OutStream *os = this->strategy_->get_out_stream ();
*os << "static TAO_" << this->flat_name () << "_Perfect_Hash_OpTable"
<< " "
<< "tao_" << this->flat_name () << "_optable"
<< ";\n" << be_nl;
}
// Create an instance of the binary search optable.
void
be_interface::gen_binary_search_instance ()
{
// Outstream.
TAO_OutStream *os = this->strategy_->get_out_stream ();
*os << "static TAO_" << this->flat_name () << "_Binary_Search_OpTable"
<< " "
<< "tao_" << this->flat_name () << "_optable"
<< ";\n" << be_nl;
}
// Create an instance of this perfect hash table.
void
be_interface::gen_linear_search_instance ()
{
// Outstream.
TAO_OutStream *os = this->strategy_->get_out_stream ();
*os << "static TAO_" << this->flat_name () << "_Linear_Search_OpTable"
<< " "
<< "tao_" << this->flat_name () << "_optable"
<< ";\n" << be_nl;
}
int
be_interface::is_a_helper (be_interface * /*derived*/,
be_interface *bi,
TAO_OutStream *os)
{
// emit the comparison code
os->indent ();
*os << "(!ACE_OS::strcmp ((char *)value, \"" << bi->repoID () <<
"\")) ||\n";
return 0;
}
int
be_interface::downcast_helper (be_interface * /* derived */,
be_interface *base,
TAO_OutStream *os)
{
*os << "if (ACE_OS::strcmp (logical_type_id, \""
<< base->repoID () << "\") == 0)" << be_idt_nl
<< "return ACE_static_cast ("
<< base->full_skel_name () << "_ptr, this);" << be_uidt_nl;
return 0;
}
int
be_interface::gen_skel_helper (be_interface *derived,
be_interface *ancestor,
TAO_OutStream *os)
{
UTL_ScopeActiveIterator *si;
AST_Decl *d;
TAO_NL nl; // end line
// if derived and ancestor are same, skip it
if (derived == ancestor)
return 0;
// else generate code that does the cast to the appropriate type
if (ancestor->nmembers () > 0)
{
// if there are elements in ancestor scope i.e., any operations and
// attributes defined by "ancestor", become methods on the derived class
// which call the corresponding method of the base class by doing the
// proper casting
si = new UTL_ScopeActiveIterator (ancestor, UTL_Scope::IK_decls);
// instantiate a scope iterator.
while (!(si->is_done ()))
{
// get the next AST decl node
d = si->item ();
if (d->node_type () == AST_Decl::NT_op)
{
os->indent (); // start from current indentation level
if (os->stream_type () == TAO_OutStream::TAO_SVR_HDR)
{
// generate the static method corresponding to this method
*os << "static void " << d->local_name ()
<< "_skel (" << be_idt << be_idt_nl
<< "CORBA::ServerRequest &req, " << be_nl
<< "void *obj," << be_nl
<< "void *context," << be_nl
<< "CORBA::Environment &env =" << be_idt_nl
<< "TAO_default_environment ()"
<< be_uidt << be_uidt_nl
<< ");" << be_uidt << "\n\n";
}
else
{ // generate code in the inline file
// generate the static method corresponding to this method
*os << "ACE_INLINE void "
<< derived->full_skel_name () << "::"
<< d->local_name ()
<< "_skel (" << be_idt << be_idt_nl
<< "CORBA::ServerRequest &req," << be_nl
<< "void *obj," << be_nl
<< "void *context," << be_nl
<< "CORBA::Environment &env" << be_uidt_nl
<< ")" << be_uidt_nl
<< "{" << be_idt_nl;
*os << ancestor->full_skel_name ()
<< "_ptr impl = ("
<< derived->full_skel_name ()
<< "_ptr) obj;" << be_nl;
*os << ancestor->full_skel_name ()
<< "::" << d->local_name ()
<< "_skel (" << be_idt << be_idt_nl
<< "req," << be_nl
<< "(" << ancestor->full_skel_name ()
<< "_ptr) impl," << be_nl
<< "context," << be_nl
<< " env" << be_uidt_nl
<< ");" << be_uidt << be_uidt_nl
<< "}\n";
}
}
else if (d->node_type () == AST_Decl::NT_attr)
{
AST_Attribute *attr;
attr = AST_Attribute::narrow_from_decl (d);
if (!attr)
return -1;
os->indent (); // start from current indentation level
if (os->stream_type () == TAO_OutStream::TAO_SVR_HDR)
{
// generate the static method corresponding to this method
*os << "static void _get_" << d->local_name ()
<< "_skel (" << be_idt << be_idt_nl
<< "CORBA::ServerRequest &req," << be_nl
<< "void *obj," << be_nl
<< "void *context," << be_nl
<< "CORBA::Environment &env =" << be_idt_nl
<< "TAO_default_environment ()"
<< be_uidt << be_uidt_nl
<< ");" << be_uidt << "\n\n";
}
else
{ // generate code in the inline file
// generate the static method corresponding to this method
*os << "ACE_INLINE void "
<< derived->full_skel_name () << "::_get_"
<< d->local_name ()
<< "_skel (" << be_idt << be_idt_nl
<< "CORBA::ServerRequest &req," << be_nl
<< "void *obj," << be_nl
<< "void *context," << be_nl
<< "CORBA::Environment &env" << be_uidt_nl
<< ")" << be_uidt_nl
<< "{" << be_idt_nl
<< ancestor->full_skel_name ()
<< "_ptr impl = ("
<< derived->full_skel_name ()
<< "_ptr) obj;" << nl;
*os << ancestor->full_skel_name ()
<< "::_get_" << d->local_name ()
<< "_skel (" << be_idt << be_idt_nl
<< "req," << be_nl
<< "(" << ancestor->full_skel_name ()
<< "_ptr) impl," << be_nl
<< "context," << be_nl
<< "env" << be_uidt_nl
<< ");" << be_uidt << be_uidt_nl
<< "}\n";
}
if (!attr->readonly ())
{
// the set method
os->indent (); // start from current indentation level
if (os->stream_type () == TAO_OutStream::TAO_SVR_HDR)
{
// generate the static method corresponding to
// this method
*os << "static void _set_" << d->local_name ()
<< "_skel (" << be_idt << be_idt_nl
<< "CORBA::ServerRequest &req," << be_nl
<< "void *obj," << be_nl
<< "void *context," << be_nl
<< "CORBA::Environment &env = " << be_idt_nl
<< "TAO_default_environment ()"
<< be_uidt << be_uidt_nl
<< ");" << be_uidt << "\n\n";
}
else
{ // generate code in the inline file
// generate the static method corresponding to
// this method
*os << "ACE_INLINE void "
<< derived->full_skel_name ()
<< "::_set_" << d->local_name ()
<< "_skel (" << be_idt << be_idt_nl
<< "CORBA::ServerRequest &req," << be_nl
<< "void *obj," << be_nl
<< "void *context," << be_nl
<< "CORBA::Environment &env" << be_uidt_nl
<< ")" << be_uidt_nl
<< "{" << be_idt_nl
<< ancestor->full_skel_name ()
<< "_ptr impl = ("
<< derived->full_skel_name ()
<< "_ptr) obj;" << be_nl;
*os << ancestor->full_skel_name ()
<< "::_set_" << d->local_name ()
<< "_skel (" << be_idt << be_idt_nl
<< "req," << be_nl
<< "(" << ancestor->full_skel_name ()
<< "_ptr) impl," << be_nl
<< "context," << be_nl
<< "env" << be_uidt_nl
<< ");" << be_uidt << be_uidt_nl
<< "}\n";
}
}
}
si->next ();
} // end of while
delete si; // free the iterator object
}
return 0;
}
int
be_interface::copy_ctor_helper (be_interface *derived,
be_interface *base,
TAO_OutStream *os)
{
if (derived == base)
// we are the same. Don't do anything, otherwise we will end up calling
// ourself
return 0;
if (base->is_nested ())
{
be_decl *scope;
scope = be_scope::narrow_from_scope (base->defined_in ())->decl ();
*os << " ACE_NESTED_CLASS (POA_" << scope->name () << ","
<< base->local_name () << ") (rhs)," << be_nl;
}
else
{
*os << " " << base->full_skel_name () << " (rhs)," << be_nl;
}
return 0;
}
int
be_interface::in_mult_inheritance_helper (be_interface *derived,
be_interface *base,
TAO_OutStream *)
{
switch (derived->n_inherits ())
{
case 0:
// no parent
derived->in_mult_inheritance (0);
break;
case 1:
if (derived == base)
// prevent indefinite recursion
derived->in_mult_inheritance (-1);
else
// one parent. We have the same characteristics as our base
derived->in_mult_inheritance (base->in_mult_inheritance ());
break;
default:
// direct multiple inheritance
derived->in_mult_inheritance (1);
}
return 0;
}
int
be_interface::accept (be_visitor *visitor)
{
return visitor->visit_interface (this);
}
// ****************************************************************
be_interface_type_strategy::be_interface_type_strategy (be_interface *node)
: local_name_(0),
full_name_(0),
flat_name_(0),
repoID_(0),
full_skel_name_(0),
full_coll_name_(0),
local_coll_name_(0),
relative_skel_name_(0),
node_ (node),
cached_type_ (-1)
{
}
be_interface_type_strategy::~be_interface_type_strategy ()
{
if (this->local_name_ != 0)
delete [] this->local_name_;
if (this->full_name_ != 0)
delete [] this->full_name_;
if (this->flat_name_ != 0)
delete [] this->flat_name_;
if (this->repoID_ != 0)
delete [] this->repoID_;
if (this->full_skel_name_ != 0)
delete [] this->full_skel_name_;
if (this->full_coll_name_ != 0)
delete [] this->full_coll_name_;
if (this->local_coll_name_ != 0)
delete [] this->local_coll_name_;
if (this->relative_skel_name_ != 0)
delete [] this->relative_skel_name_;
}
// Interface Type Strategy Base Class
const char *
be_interface_type_strategy::relative_skel_name (const char *skel_name)
// relative skeleton name
{
return be_interface::relative_name (this->full_skel_name (),
skel_name);
}
// compute stringified fully qualified collocated class name.
void
be_interface_type_strategy::compute_coll_names (int type,
const char *prefix,
const char *suffix)
{
if (type == this->cached_type_ && this->full_coll_name_ != 0)
return;
else
{
this->cached_type_ = type;
delete this->full_coll_name_;
delete this->local_coll_name_;
}
static const char *collocated_names[] = { "_tao_thru_poa_collocated_",
"_tao_direct_collocated_" };
const char poa[] = "POA_";
// Reserve enough room for the "POA_" prefix, the "_tao_collocated_"
// prefix and the local name and the (optional) "::"
const char *collocated = collocated_names[type];
int name_len = ACE_OS::strlen (collocated) +
sizeof (poa) +
1;
if (prefix)
name_len += ACE_OS::strlen (prefix);
if (suffix)
name_len += ACE_OS::strlen (suffix);
{
UTL_IdListActiveIterator *i;
ACE_NEW (i, UTL_IdListActiveIterator (node_->name ()));
while (!i->is_done ())
{
// reserve 2 characters for "::".
name_len += ACE_OS::strlen (i->item ()->get_string ()) + 2;
i->next ();
}
delete i;
}
ACE_NEW (this->full_coll_name_,
char[name_len+1]);
this->full_coll_name_[0] = 0; // null terminate the string...
// Iterate again....
UTL_IdListActiveIterator *i;
ACE_NEW (i, UTL_IdListActiveIterator (node_->name ()));
// Only the first component get the "POA_" preffix.
int poa_added = 0;
while (!i->is_done ())
{
const char* item = i->item ()->get_string ();
// Increase right away, so we can test for the final component
// in the loop.
i->next ();
// We add the POA_ preffix only if the first component is not
// the global scope...
if (ACE_OS::strcmp (item, "") != 0)
{
if (!i->is_done ())
{
// We only add the POA_ preffix if there are more than
// two components in the name, in other words, if the
// class is inside some scope.
if (!poa_added)
{
ACE_OS::strcat (this->full_coll_name_, poa);
poa_added = 1;
}
ACE_OS::strcat (this->full_coll_name_, item);
ACE_OS::strcat (this->full_coll_name_, "::");
}
else
{
ACE_OS::strcat (this->full_coll_name_, collocated);
if (prefix)
ACE_OS::strcat (this->full_coll_name_, prefix);
ACE_OS::strcat (this->full_coll_name_, item);
if (suffix)
ACE_OS::strcat (this->full_coll_name_, suffix);
}
}
}
delete i;
// Compute the local name for the collocated class.
int local_len = ACE_OS::strlen (collocated) +
ACE_OS::strlen (node_->AST_Interface::local_name ()->get_string ()) +
1;
if (prefix)
local_len += ACE_OS::strlen (prefix);
if (suffix)
local_len += ACE_OS::strlen (suffix);
ACE_NEW (this->local_coll_name_, char[local_len]);
ACE_OS::strcpy(this->local_coll_name_, collocated);
if (prefix)
ACE_OS::strcat (this->local_coll_name_, prefix);
ACE_OS::strcat(this->local_coll_name_,
node_->AST_Interface::local_name ()->get_string ());
if (suffix)
ACE_OS::strcat (this->local_coll_name_, suffix);
}
void
be_interface_type_strategy::compute_names (const char *name,
const char *prefix,
const char *suffix,
char *&new_name)
{
if (!prefix || !suffix)
return;
int name_length = ACE_OS::strlen (name) +
ACE_OS::strlen (prefix) +
ACE_OS::strlen (suffix);
ACE_NEW (new_name,
char[name_length + 1]);
// copy it in
ACE_OS::strcpy (new_name, name);
const char *interface_name = 0;
int i = ACE_OS::strlen (name);
for (;i >= 1; i--)
{
if (name[i-1] == ':' && name[i] == ':')
{
interface_name = &name[i+1];
break;
}
else if (i >= 3)
if (name[i-3] == 'P' &&
name[i-2] == 'O' &&
name[i-1] == 'A' &&
name[i] == '_')
{
interface_name = &name[i+1];
break;
}
}
if (interface_name == 0)
interface_name = name;
ACE_OS::strcpy(&new_name[name_length -
ACE_OS::strlen(prefix) -
ACE_OS::strlen(interface_name) -
ACE_OS::strlen(suffix)],prefix);
ACE_OS::strcpy(&new_name[name_length -
ACE_OS::strlen(interface_name) -
ACE_OS::strlen(suffix)],interface_name);
ACE_OS::strcpy(&new_name[name_length -
ACE_OS::strlen(suffix)],suffix);
}
// ****************************************************************
// AMI Hander Strategy
be_interface_ami_handler_strategy::be_interface_ami_handler_strategy (be_interface *node)
: be_interface_type_strategy (node),
prefix_("AMI_"),
suffix_("_Handler")
{
}
be_interface_ami_handler_strategy::~be_interface_ami_handler_strategy ()
{
}
const char *
be_interface_ami_handler_strategy::full_name (void)
{
if (!this->full_name_)
this->compute_names (node_->be_decl::full_name (),
prefix_,
suffix_,
this->full_name_);
return this->full_name_;
}
const char *
be_interface_ami_handler_strategy::local_name (void)
{
if (!this->local_name_)
this->compute_names (node_->AST_Interface::local_name()->get_string (),
prefix_,
suffix_,
this->local_name_);
return this->local_name_;
}
const char *
be_interface_ami_handler_strategy::flat_name (void)
{
if (!this->flat_name_)
node_->compute_flat_name (prefix_,
suffix_,
this->flat_name_);
return this->flat_name_;
}
const char *
be_interface_ami_handler_strategy::repoID (void)
{
if (!this->repoID_)
node_->compute_repoID (prefix_,
suffix_,
this->repoID_);
return this->repoID_;
}
const char *
be_interface_ami_handler_strategy::full_skel_name (void)
{
if (this->full_skel_name_ == 0)
{
char *temp = 0;
// the following method is inherited from the base class
node_->compute_full_skel_name ("POA_", temp);
// we are now responsible for the memory of temp
this->compute_names (temp,
prefix_,
suffix_,
this->full_skel_name_);
delete temp;
}
return this->full_skel_name_;
}
const char *
be_interface_ami_handler_strategy::full_coll_name (int type)
{
this->compute_coll_names (type,
prefix_,
suffix_);
return this->full_coll_name_;
}
const char *
be_interface_ami_handler_strategy::local_coll_name (int type)
{
compute_coll_names (type,
prefix_,
suffix_);
return this->local_coll_name_;
}
TAO_OutStream *
be_interface_ami_handler_strategy::get_out_stream ()
{
// Codegen singleton.
TAO_CodeGen *cg = TAO_CODEGEN::instance ();
// Outstream.
return cg->client_stubs ();
}
const char *
be_interface_ami_handler_strategy::get_out_stream_fname ()
{
return idl_global->be_get_client_stub_fname ();
}
// ****************************************************************
// Default Strategy
be_interface_default_strategy::be_interface_default_strategy (be_interface *node)
: be_interface_type_strategy (node)
{
}
be_interface_default_strategy::~be_interface_default_strategy ()
{
}
const char *
be_interface_default_strategy::full_name (void)
{
if (!this->full_name_)
{
int len = ACE_OS::strlen (node_->be_decl::full_name ());
ACE_NEW_RETURN (this->full_name_,
char[len + 1],
0);
ACE_OS::strcpy (this->full_name_,
node_->be_decl::full_name ());
}
return this->full_name_;
}
const char *
be_interface_default_strategy::local_name (void)
{
if (!this->local_name_)
{
int len = ACE_OS::strlen (node_->AST_Interface::local_name()->get_string ());
ACE_NEW_RETURN (this->local_name_,
char[len + 1],
0);
ACE_OS::strcpy (this->local_name_,
node_->AST_Interface::local_name()->get_string ());
}
return this->local_name_;
}
const char *
be_interface_default_strategy::flat_name (void)
{
if (!this->flat_name_)
{
int len = ACE_OS::strlen (node_->be_decl::flat_name ());
ACE_NEW_RETURN (this->flat_name_,
char[len + 1],
0);
ACE_OS::strcpy (this->flat_name_,
node_->be_decl::flat_name ());
}
return this->flat_name_;
}
const char *
be_interface_default_strategy::repoID (void)
{
if (!this->repoID_)
{
int len = ACE_OS::strlen (node_->be_decl::repoID ());
ACE_NEW_RETURN (this->repoID_,
char[len + 1],
0);
ACE_OS::strcpy (this->repoID_,
node_->be_decl::repoID ());
}
return this->repoID_;
}
const char *
be_interface_default_strategy::full_skel_name (void)
{
if (this->full_skel_name_ == 0)
{
// the following method is inherited from the base class
node_->compute_full_skel_name ("POA_",
this->full_skel_name_);
}
return this->full_skel_name_;
}
const char *
be_interface_default_strategy::full_coll_name (int type)
{
this->compute_coll_names (type,
0, // prefix
0); // suffix
return this->full_coll_name_;
}
const char *
be_interface_default_strategy::local_coll_name (int type)
{
this->compute_coll_names (type,
0, // prefix
0); // suffix
return this->local_coll_name_;
}
TAO_OutStream *
be_interface_default_strategy::get_out_stream ()
{
// Codegen singleton.
TAO_CodeGen *cg = TAO_CODEGEN::instance ();
// Outstream.
return cg->server_skeletons ();
}
const char *
be_interface_default_strategy::get_out_stream_fname ()
{
return idl_global->be_get_server_skeleton_fname ();
}
// Narrowing
IMPL_NARROW_METHODS3 (be_interface, AST_Interface, be_scope, be_type)
IMPL_NARROW_FROM_DECL (be_interface)
IMPL_NARROW_FROM_SCOPE (be_interface)
#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
template class ACE_Node <be_interface*>;
template class ACE_Unbounded_Queue <be_interface*>;
template class ACE_Unbounded_Queue_Iterator <be_interface*>;
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
#pragma instantiate ACE_Node<be_interface*>
#pragma instantiate ACE_Unbounded_Queue<be_interface*>
#pragma instantiate ACE_Unbounded_Queue_Iterator<be_interface*>
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
|