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
|
// $Id$
/*
COPYRIGHT
Copyright 1992, 1993, 1994 Sun Microsystems, Inc. Printed in the United
States of America. All Rights Reserved.
This product is protected by copyright and distributed under the following
license restricting its use.
The Interface Definition Language Compiler Front End (CFE) is made
available for your use provided that you include this license and copyright
notice on all media and documentation and the software program in which
this product is incorporated in whole or part. You may copy and extend
functionality (but may not remove functionality) of the Interface
Definition Language CFE without charge, but you are not authorized to
license or distribute it to anyone else except as part of a product or
program developed by you or with the express written consent of Sun
Microsystems, Inc. ("Sun").
The names of Sun Microsystems, Inc. and any of its subsidiaries or
affiliates may not be used in advertising or publicity pertaining to
distribution of Interface Definition Language CFE as permitted herein.
This license is effective until terminated by Sun for failure to comply
with this license. Upon termination, you shall destroy or return all code
and documentation for the Interface Definition Language CFE.
INTERFACE DEFINITION LANGUAGE CFE IS PROVIDED AS IS WITH NO WARRANTIES OF
ANY KIND INCLUDING THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS
FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR ARISING FROM A COURSE OF
DEALING, USAGE OR TRADE PRACTICE.
INTERFACE DEFINITION LANGUAGE CFE IS PROVIDED WITH NO SUPPORT AND WITHOUT
ANY OBLIGATION ON THE PART OF Sun OR ANY OF ITS SUBSIDIARIES OR AFFILIATES
TO ASSIST IN ITS USE, CORRECTION, MODIFICATION OR ENHANCEMENT.
SUN OR ANY OF ITS SUBSIDIARIES OR AFFILIATES SHALL HAVE NO LIABILITY WITH
RESPECT TO THE INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY
INTERFACE DEFINITION LANGUAGE CFE OR ANY PART THEREOF.
IN NO EVENT WILL SUN OR ANY OF ITS SUBSIDIARIES OR AFFILIATES BE LIABLE FOR
ANY LOST REVENUE OR PROFITS OR OTHER SPECIAL, INDIRECT AND CONSEQUENTIAL
DAMAGES, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
Use, duplication, or disclosure by the government is subject to
restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
Technical Data and Computer Software clause at DFARS 252.227-7013 and FAR
52.227-19.
Sun, Sun Microsystems and the Sun logo are trademarks or registered
trademarks of Sun Microsystems, Inc.
SunSoft, Inc.
2550 Garcia Avenue
Mountain View, California 94043
NOTE:
SunOS, SunSoft, Sun, Solaris, Sun Microsystems or the Sun logo are
trademarks or registered trademarks of Sun Microsystems, Inc.
*/
// The generator protocol is explained in detail in the IDL CFE
// design document.
// The AST_Generator class provides operations to instantiate any
// of the AST nodes. It contains an operation for every constructor
// of every AST class.
#include "ast_root.h"
#include "ast_valuetype.h"
#include "ast_valuetype_fwd.h"
#include "ast_eventtype.h"
#include "ast_eventtype_fwd.h"
#include "ast_component.h"
#include "ast_component_fwd.h"
#include "ast_home.h"
#include "ast_exception.h"
#include "ast_enum.h"
#include "ast_attribute.h"
#include "ast_union.h"
#include "ast_union_fwd.h"
#include "ast_union_branch.h"
#include "ast_enum_val.h"
#include "ast_array.h"
#include "ast_sequence.h"
#include "ast_string.h"
#include "ast_structure_fwd.h"
#include "ast_native.h"
#include "ast_factory.h"
#include "utl_identifier.h"
#include "nr_extern.h"
#include "ace/OS_NS_wchar.h"
#include "ast_generator.h"
ACE_RCSID (ast,
ast_generator,
"$Id$")
AST_PredefinedType *
AST_Generator::create_predefined_type (AST_PredefinedType::PredefinedType t,
UTL_ScopedName *n)
{
AST_PredefinedType *retval = 0;
ACE_NEW_RETURN (retval,
AST_PredefinedType (t,
n),
0);
return retval;
}
AST_Module *
AST_Generator::create_module (UTL_Scope *s,
UTL_ScopedName *n)
{
// We create this first so if we find a module with the
// same name from an included file, we can add its
// members to the new module's scope.
AST_Module *retval = 0;
ACE_NEW_RETURN (retval,
AST_Module (n),
0);
AST_Decl *d = 0;
AST_Module *m = 0;
UTL_ScopeActiveIterator iter (s,
UTL_Scope::IK_decls);
// Check for another module of the same name in this scope.
while (!iter.is_done ())
{
d = iter.item ();
if (d->node_type () == AST_Decl::NT_module)
{
// Does it have the same name as the one we're
// supposed to create.
if (d->local_name ()->compare (n->last_component ()))
{
m = AST_Module::narrow_from_decl (d);
// Get m's previous_ member, plus all it's decls,
// into the new modules's previous_ member.
retval->add_to_previous (m);
}
}
iter.next ();
}
// If this scope is itself a module, and has been previously
// opened, the previous opening may contain a previous opening
// of the module we're creating.
d = ScopeAsDecl (s);
AST_Decl::NodeType nt = d->node_type ();
if (nt == AST_Decl::NT_module || nt == AST_Decl::NT_root)
{
m = AST_Module::narrow_from_decl (d);
// AST_Module::previous_ is a set, so it contains each
// entry only once, but previous_ will contain the decls
// from all previous openings. See comment in
// AST_Module::add_to_previous() body.
d = m->look_in_previous (n->last_component ());
if (d != 0)
{
if (d->node_type () == AST_Decl::NT_module)
{
m = AST_Module::narrow_from_decl (d);
retval->add_to_previous (m);
}
}
}
return retval;
}
AST_Root *
AST_Generator::create_root (UTL_ScopedName *n)
{
AST_Root *retval = 0;
ACE_NEW_RETURN (retval,
AST_Root (n),
0);
return retval;
}
AST_Interface *
AST_Generator::create_interface (UTL_ScopedName *n,
AST_Interface **inherits,
long n_inherits,
AST_Interface **inherits_flat,
long n_inherits_flat,
idl_bool local,
idl_bool abstract)
{
AST_Interface *retval = 0;
ACE_NEW_RETURN (retval,
AST_Interface (n,
inherits,
n_inherits,
inherits_flat,
n_inherits_flat,
local,
abstract),
0);
return retval;
}
AST_InterfaceFwd *
AST_Generator::create_interface_fwd (UTL_ScopedName *n,
idl_bool local,
idl_bool abstract)
{
AST_InterfaceFwd *retval = 0;
ACE_NEW_RETURN (retval,
AST_InterfaceFwd (this->create_interface (n,
0,
-1,
0,
0,
local,
abstract),
n),
0);
return retval;
}
AST_ValueType *
AST_Generator::create_valuetype (UTL_ScopedName *n,
AST_Interface **inherits,
long n_inherits,
AST_ValueType *inherits_concrete,
AST_Interface **inherits_flat,
long n_inherits_flat,
AST_Interface **supports,
long n_supports,
AST_Interface *supports_concrete,
idl_bool abstract,
idl_bool truncatable,
idl_bool custom)
{
AST_ValueType *retval = 0;
ACE_NEW_RETURN (retval,
AST_ValueType (n,
inherits,
n_inherits,
inherits_concrete,
inherits_flat,
n_inherits_flat,
supports,
n_supports,
supports_concrete,
abstract,
truncatable,
custom),
0);
// The following helps with OBV_ namespace generation.
AST_Module *m = AST_Module::narrow_from_scope (retval->defined_in ());
if (m != 0)
{
m->set_has_nested_valuetype ();
}
return retval;
}
AST_ValueTypeFwd *
AST_Generator::create_valuetype_fwd (UTL_ScopedName *n,
idl_bool abstract)
{
AST_ValueType *dummy = this->create_valuetype (n,
0,
-1,
0,
0,
0,
0,
0,
0,
abstract,
I_FALSE,
I_FALSE);
AST_ValueTypeFwd *retval = 0;
ACE_NEW_RETURN (retval,
AST_ValueTypeFwd (dummy,
n),
0);
return retval;
}
AST_EventType *
AST_Generator::create_eventtype (UTL_ScopedName *n,
AST_Interface **inherits,
long n_inherits,
AST_ValueType *inherits_concrete,
AST_Interface **inherits_flat,
long n_inherits_flat,
AST_Interface **supports,
long n_supports,
AST_Interface *supports_concrete,
idl_bool abstract,
idl_bool truncatable,
idl_bool custom)
{
AST_EventType *retval = 0;
ACE_NEW_RETURN (retval,
AST_EventType (n,
inherits,
n_inherits,
inherits_concrete,
inherits_flat,
n_inherits_flat,
supports,
n_supports,
supports_concrete,
abstract,
truncatable,
custom),
0);
// The following helps with OBV_ namespace generation.
AST_Module *m = AST_Module::narrow_from_scope (retval->defined_in ());
if (m != 0)
{
m->set_has_nested_valuetype ();
}
return retval;
}
AST_EventTypeFwd *
AST_Generator::create_eventtype_fwd (UTL_ScopedName *n,
idl_bool abstract)
{
AST_EventType *dummy = this->create_eventtype (n,
0,
-1,
0,
0,
0,
0,
0,
0,
abstract,
I_FALSE,
I_FALSE);
AST_EventTypeFwd *retval = 0;
ACE_NEW_RETURN (retval,
AST_EventTypeFwd (dummy,
n),
0);
return retval;
}
AST_Component *
AST_Generator::create_component (UTL_ScopedName *n,
AST_Component *base_component,
AST_Interface **supports,
long n_supports,
AST_Interface **supports_flat,
long n_supports_flat)
{
AST_Component *retval = 0;
ACE_NEW_RETURN (retval,
AST_Component (n,
base_component,
supports,
n_supports,
supports_flat,
n_supports_flat),
0);
return retval;
}
AST_ComponentFwd *
AST_Generator::create_component_fwd (UTL_ScopedName *n)
{
AST_Component *dummy = this->create_component (n,
0,
0,
-1,
0,
0);
AST_ComponentFwd *retval = 0;
ACE_NEW_RETURN (retval,
AST_ComponentFwd (dummy,
n),
0);
return retval;
}
AST_Home *
AST_Generator::create_home (UTL_ScopedName *n,
AST_Home *base_home,
AST_Component *managed_component,
AST_ValueType *primary_key,
AST_Interface **supports,
long n_supports,
AST_Interface **supports_flat,
long n_supports_flat)
{
AST_Home *retval = 0;
ACE_NEW_RETURN (retval,
AST_Home (n,
base_home,
managed_component,
primary_key,
supports,
n_supports,
supports_flat,
n_supports_flat),
0);
return retval;
}
AST_Exception *
AST_Generator::create_exception (UTL_ScopedName *n,
idl_bool local,
idl_bool abstract)
{
AST_Exception *retval = 0;
ACE_NEW_RETURN (retval,
AST_Exception (n,
local,
abstract),
0);
return retval;
}
AST_Structure *
AST_Generator::create_structure (UTL_ScopedName *n,
idl_bool local,
idl_bool abstract)
{
AST_Structure *retval = 0;
ACE_NEW_RETURN (retval,
AST_Structure (n,
local,
abstract),
0);
return retval;
}
AST_StructureFwd *
AST_Generator::create_structure_fwd (UTL_ScopedName *n)
{
AST_Structure *dummy = this->create_structure (n,
0,
0);
AST_StructureFwd *retval = 0;
ACE_NEW_RETURN (retval,
AST_StructureFwd (dummy,
n),
0);
return retval;
}
AST_Enum *
AST_Generator::create_enum (UTL_ScopedName *n,
idl_bool local,
idl_bool abstract)
{
AST_Enum *retval = 0;
ACE_NEW_RETURN (retval,
AST_Enum (n,
local,
abstract),
0);
return retval;
}
AST_Operation *
AST_Generator::create_operation (AST_Type *rt,
AST_Operation::Flags fl,
UTL_ScopedName *n,
idl_bool local,
idl_bool abstract)
{
AST_Operation *retval = 0;
ACE_NEW_RETURN (retval,
AST_Operation (rt,
fl,
n,
local,
abstract),
0);
return retval;
}
AST_Field *
AST_Generator::create_field (AST_Type *ft,
UTL_ScopedName *n,
AST_Field::Visibility vis)
{
AST_Field *retval = 0;
ACE_NEW_RETURN (retval,
AST_Field (ft,
n,
vis),
0);
return retval;
}
AST_Argument *
AST_Generator::create_argument (AST_Argument::Direction d,
AST_Type *ft,
UTL_ScopedName *n)
{
AST_Argument *retval = 0;
ACE_NEW_RETURN (retval,
AST_Argument (d,
ft,
n),
0);
return retval;
}
AST_Attribute *
AST_Generator::create_attribute (idl_bool ro,
AST_Type *ft,
UTL_ScopedName *n,
idl_bool local,
idl_bool abstract)
{
AST_Attribute *retval = 0;
ACE_NEW_RETURN (retval,
AST_Attribute (ro,
ft,
n,
local,
abstract),
0);
return retval;
}
AST_Union *
AST_Generator::create_union (AST_ConcreteType *dt,
UTL_ScopedName *n,
idl_bool local,
idl_bool abstract)
{
AST_Union *retval = 0;
ACE_NEW_RETURN (retval,
AST_Union (dt,
n,
local,
abstract),
0);
return retval;
}
AST_UnionFwd *
AST_Generator::create_union_fwd (UTL_ScopedName *n)
{
AST_Union *dummy = this->create_union (0,
n,
0,
0);
AST_UnionFwd *retval = 0;
ACE_NEW_RETURN (retval,
AST_UnionFwd (dummy,
n),
0);
return retval;
}
AST_UnionBranch *
AST_Generator::create_union_branch (UTL_LabelList *ll,
AST_Type *ft,
UTL_ScopedName *n)
{
AST_UnionBranch *retval = 0;
ACE_NEW_RETURN (retval,
AST_UnionBranch (ll,
ft,
n),
0);
return retval;
}
AST_UnionLabel *
AST_Generator::create_union_label (AST_UnionLabel::UnionLabel ul,
AST_Expression *v)
{
AST_UnionLabel *retval = 0;
ACE_NEW_RETURN (retval,
AST_UnionLabel (ul,
v),
0);
return retval;
}
AST_Constant *
AST_Generator::create_constant (AST_Expression::ExprType et,
AST_Expression *ev,
UTL_ScopedName *n)
{
AST_Constant *retval = 0;
ACE_NEW_RETURN (retval,
AST_Constant (et,
ev,
n),
0);
return retval;
}
AST_Expression *
AST_Generator::create_expr (UTL_ScopedName *n)
{
AST_Expression *retval = 0;
ACE_NEW_RETURN (retval,
AST_Expression (n),
0);
return retval;
}
AST_Expression *
AST_Generator::create_expr (AST_Expression *v,
AST_Expression::ExprType t)
{
AST_Expression *retval = 0;
ACE_NEW_RETURN (retval,
AST_Expression (v,
t),
0);
return retval;
}
AST_Expression *
AST_Generator::create_expr (AST_Expression::ExprComb c,
AST_Expression *v1,
AST_Expression *v2)
{
AST_Expression *retval = 0;
ACE_NEW_RETURN (retval,
AST_Expression (c,
v1,
v2),
0);
return retval;
}
AST_Expression *
AST_Generator::create_expr (long v)
{
AST_Expression *retval = 0;
ACE_NEW_RETURN (retval,
AST_Expression (v),
0);
return retval;
}
AST_Expression *
AST_Generator::create_expr (long v,
AST_Expression::ExprType t)
{
AST_Expression *retval = 0;
ACE_NEW_RETURN (retval,
AST_Expression (v,
t),
0);
return retval;
}
AST_Expression *
AST_Generator::create_expr (ACE_UINT64 v,
AST_Expression::ExprType t)
{
AST_Expression *retval = 0;
ACE_NEW_RETURN (retval,
AST_Expression (v,
t),
0);
return retval;
}
AST_Expression *
AST_Generator::create_expr (UTL_String *s)
{
AST_Expression *retval = 0;
ACE_NEW_RETURN (retval,
AST_Expression (s),
0);
return retval;
}
AST_Expression *
AST_Generator::create_expr (char c)
{
AST_Expression *retval = 0;
ACE_NEW_RETURN (retval,
AST_Expression (c),
0);
return retval;
}
AST_Expression *
AST_Generator::create_expr (ACE_OutputCDR::from_wchar wc)
{
AST_Expression *retval = 0;
ACE_NEW_RETURN (retval,
AST_Expression (wc),
0);
return retval;
}
AST_Expression *
AST_Generator::create_expr (char *s)
{
AST_Expression *retval = 0;
ACE_NEW_RETURN (retval,
AST_Expression (s),
0);
return retval;
}
AST_Expression *
AST_Generator::create_expr (double d)
{
AST_Expression *retval = 0;
ACE_NEW_RETURN (retval,
AST_Expression (d),
0);
return retval;
}
AST_EnumVal *
AST_Generator::create_enum_val (unsigned long v,
UTL_ScopedName *n)
{
AST_EnumVal *retval = 0;
ACE_NEW_RETURN (retval,
AST_EnumVal (v,
n),
0);
return retval;
}
AST_Array *
AST_Generator::create_array (UTL_ScopedName *n,
unsigned long ndims,
UTL_ExprList *dims,
idl_bool local,
idl_bool abstract)
{
AST_Array *retval = 0;
ACE_NEW_RETURN (retval,
AST_Array (n,
ndims,
dims,
local,
abstract),
0);
return retval;
}
AST_Sequence *
AST_Generator::create_sequence (AST_Expression *ms,
AST_Type *bt,
UTL_ScopedName *n,
idl_bool local,
idl_bool abstract)
{
AST_Sequence *retval = 0;
ACE_NEW_RETURN (retval,
AST_Sequence (ms,
bt,
n,
local,
abstract),
0);
return retval;
}
AST_String *
AST_Generator::create_string (AST_Expression *ms)
{
Identifier id ("string");
UTL_ScopedName n (&id,
0);
AST_String *retval = 0;
ACE_NEW_RETURN (retval,
AST_String (AST_Decl::NT_string,
&n,
ms),
0);
return retval;
}
AST_String *
AST_Generator::create_wstring (AST_Expression *ms)
{
Identifier id (sizeof (ACE_CDR::WChar) == 1
? "string"
: "wstring");
UTL_ScopedName n (&id,
0);
AST_Decl::NodeType nt = sizeof (ACE_CDR::WChar) == 1
? AST_Decl::NT_string
: AST_Decl::NT_wstring;
AST_String *retval = 0;
ACE_NEW_RETURN (retval,
AST_String (nt,
&n,
ms,
sizeof (ACE_OS::WChar)),
0);
return retval;
}
AST_Typedef *
AST_Generator::create_typedef (AST_Type *bt,
UTL_ScopedName *n,
idl_bool local,
idl_bool abstract)
{
AST_Typedef *retval = 0;
ACE_NEW_RETURN (retval,
AST_Typedef (bt,
n,
local,
abstract),
0);
return retval;
}
AST_Native *
AST_Generator::create_native (UTL_ScopedName *n)
{
AST_Native *retval = 0;
ACE_NEW_RETURN (retval,
AST_Native (n),
0);
return retval;
}
AST_Factory *
AST_Generator::create_factory (UTL_ScopedName *n)
{
AST_Factory *retval = 0;
ACE_NEW_RETURN (retval,
AST_Factory (n),
0);
return retval;
}
|