5 Copyright 1992, 1993, 1994 Sun Microsystems, Inc. Printed in the United
6 States of America. All Rights Reserved.
8 This product is protected by copyright and distributed under the following
9 license restricting its use.
11 The Interface Definition Language Compiler Front End (CFE) is made
12 available for your use provided that you include this license and copyright
13 notice on all media and documentation and the software program in which
14 this product is incorporated in whole or part. You may copy and extend
15 functionality (but may not remove functionality) of the Interface
16 Definition Language CFE without charge, but you are not authorized to
17 license or distribute it to anyone else except as part of a product or
18 program developed by you or with the express written consent of Sun
19 Microsystems, Inc. ("Sun").
21 The names of Sun Microsystems, Inc. and any of its subsidiaries or
22 affiliates may not be used in advertising or publicity pertaining to
23 distribution of Interface Definition Language CFE as permitted herein.
25 This license is effective until terminated by Sun for failure to comply
26 with this license. Upon termination, you shall destroy or return all code
27 and documentation for the Interface Definition Language CFE.
29 INTERFACE DEFINITION LANGUAGE CFE IS PROVIDED AS IS WITH NO WARRANTIES OF
30 ANY KIND INCLUDING THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS
31 FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR ARISING FROM A COURSE OF
32 DEALING, USAGE OR TRADE PRACTICE.
34 INTERFACE DEFINITION LANGUAGE CFE IS PROVIDED WITH NO SUPPORT AND WITHOUT
35 ANY OBLIGATION ON THE PART OF Sun OR ANY OF ITS SUBSIDIARIES OR AFFILIATES
36 TO ASSIST IN ITS USE, CORRECTION, MODIFICATION OR ENHANCEMENT.
38 SUN OR ANY OF ITS SUBSIDIARIES OR AFFILIATES SHALL HAVE NO LIABILITY WITH
39 RESPECT TO THE INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY
40 INTERFACE DEFINITION LANGUAGE CFE OR ANY PART THEREOF.
42 IN NO EVENT WILL SUN OR ANY OF ITS SUBSIDIARIES OR AFFILIATES BE LIABLE FOR
43 ANY LOST REVENUE OR PROFITS OR OTHER SPECIAL, INDIRECT AND CONSEQUENTIAL
44 DAMAGES, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
46 Use, duplication, or disclosure by the government is subject to
47 restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
48 Technical Data and Computer Software clause at DFARS 252.227-7013 and FAR
51 Sun, Sun Microsystems and the Sun logo are trademarks or registered
52 trademarks of Sun Microsystems, Inc.
56 Mountain View, California 94043
60 SunOS, SunSoft, Sun, Solaris, Sun Microsystems or the Sun logo are
61 trademarks or registered trademarks of Sun Microsystems, Inc.
65 // The generator protocol is explained in detail in the IDL CFE
67 // The AST_Generator class provides operations to instantiate any
68 // of the AST nodes. It contains an operation for every constructor
69 // of every AST class.
72 #include "ast_valuebox.h"
73 #include "ast_valuetype.h"
74 #include "ast_valuetype_fwd.h"
75 #include "ast_eventtype.h"
76 #include "ast_eventtype_fwd.h"
77 #include "ast_component.h"
78 #include "ast_component_fwd.h"
80 #include "ast_mirror_port.h"
81 #include "ast_connector.h"
82 #include "ast_template_module.h"
83 #include "ast_template_module_inst.h"
84 #include "ast_template_module_ref.h"
85 #include "ast_param_holder.h"
86 #include "ast_provides.h"
88 #include "ast_publishes.h"
89 #include "ast_emits.h"
90 #include "ast_consumes.h"
91 #include "ast_exception.h"
93 #include "ast_attribute.h"
94 #include "ast_union.h"
95 #include "ast_union_fwd.h"
96 #include "ast_union_branch.h"
97 #include "ast_enum_val.h"
98 #include "ast_array.h"
99 #include "ast_sequence.h"
100 #include "ast_string.h"
101 #include "ast_structure_fwd.h"
102 #include "ast_typedef.h"
103 #include "ast_native.h"
104 #include "ast_factory.h"
105 #include "ast_finder.h"
106 #include "ast_fixed.h"
107 #include "ast_annotation_appl.h"
108 #include "ast_annotation_member.h"
110 #include "utl_identifier.h"
112 #include "nr_extern.h"
113 #include "ace/OS_NS_wchar.h"
115 #include "ast_generator.h"
118 AST_Generator::create_predefined_type (AST_PredefinedType::PredefinedType t
,
121 AST_PredefinedType
*retval
= 0;
122 ACE_NEW_RETURN (retval
,
123 AST_PredefinedType (t
, n
),
130 AST_Generator::create_module (UTL_Scope
*s
,
133 AST_Module
*retval
= 0;
135 // Check for another module of the same name in the scope.
136 for (UTL_ScopeActiveIterator
iter (s
, UTL_Scope::IK_decls
);
140 // Can't just check node type here, since it could be a
141 // template module or template module instantiation.
142 AST_Module
*m
= dynamic_cast<AST_Module
*> (iter
.item ());
143 if (m
&& m
->local_name ()->compare (n
->last_component ()))
145 // Create this new module with referance to the
146 // "first" previous module found in scope.
147 ACE_NEW_RETURN (retval
, AST_Module (n
, m
), 0);
148 retval
->prefix (const_cast<char *> (m
->prefix ()));
153 // Since the scope didn't contain the same module name, it
154 // doesn't mean that we haven't see it before. If the scope
155 // is itself a module, and has been previously opened, any
156 // of the previous openings may contain a previous opening
157 // of the module we're creating.
158 AST_Module
*prev_module
= dynamic_cast<AST_Module
*> (s
);
161 while (!!(prev_module
= prev_module
->previous_opening ()))
163 for (UTL_ScopeActiveIterator
iter (prev_module
, UTL_Scope::IK_decls
);
167 AST_Module
*m
= dynamic_cast<AST_Module
*> (iter
.item ());
168 if (m
&& m
->local_name ()->compare (n
->last_component ()))
170 // Create this new module with referance to the
171 // "first" previous module found in scope.
172 ACE_NEW_RETURN (retval
, AST_Module (n
, m
), 0);
179 // There is no previous module to this one
180 ACE_NEW_RETURN (retval
, AST_Module (n
), 0);
185 AST_Generator::create_root (UTL_ScopedName
*n
)
187 AST_Root
*retval
= 0;
188 ACE_NEW_RETURN (retval
,
196 AST_Generator::create_interface (UTL_ScopedName
*n
,
199 AST_Interface
**inherits_flat
,
200 long n_inherits_flat
,
204 AST_Interface
*retval
= 0;
205 ACE_NEW_RETURN (retval
,
219 AST_Generator::create_interface_fwd (UTL_ScopedName
*n
,
224 *full_defn
= this->create_interface (n
,
231 AST_InterfaceFwd
*retval
= 0;
232 ACE_NEW_RETURN (retval
,
233 AST_InterfaceFwd (full_defn
, n
),
236 full_defn
->fwd_decl (retval
);
241 AST_Generator::create_valuetype (UTL_ScopedName
*n
,
244 AST_Type
*inherits_concrete
,
245 AST_Interface
**inherits_flat
,
246 long n_inherits_flat
,
247 AST_Type
**supports_list
,
249 AST_Type
*supports_concrete
,
254 AST_ValueType
*retval
= 0;
255 ACE_NEW_RETURN (retval
,
270 // The following helps with OBV_ namespace generation.
271 AST_Module
*m
= dynamic_cast<AST_Module
*> (retval
->defined_in ());
274 m
->set_has_nested_valuetype ();
281 AST_Generator::create_valuetype_fwd (UTL_ScopedName
*n
,
284 AST_ValueType
*full_defn
= this->create_valuetype (n
,
297 AST_ValueTypeFwd
*retval
= 0;
298 ACE_NEW_RETURN (retval
,
299 AST_ValueTypeFwd (full_defn
,
303 full_defn
->fwd_decl (retval
);
308 AST_Generator::create_eventtype (UTL_ScopedName
*n
,
311 AST_Type
*inherits_concrete
,
312 AST_Interface
**inherits_flat
,
313 long n_inherits_flat
,
314 AST_Type
**supports_list
,
316 AST_Type
*supports_concrete
,
321 AST_EventType
*retval
= 0;
322 ACE_NEW_RETURN (retval
,
337 // The following helps with OBV_ namespace generation.
338 AST_Module
*m
= dynamic_cast<AST_Module
*> (retval
->defined_in ());
342 m
->set_has_nested_valuetype ();
349 AST_Generator::create_eventtype_fwd (UTL_ScopedName
*n
,
352 AST_EventType
*full_defn
= this->create_eventtype (n
,
365 AST_EventTypeFwd
*retval
= 0;
366 ACE_NEW_RETURN (retval
,
367 AST_EventTypeFwd (full_defn
,
371 full_defn
->fwd_decl (retval
);
376 AST_Generator::create_component (UTL_ScopedName
*n
,
377 AST_Component
*base_component
,
378 AST_Type
**supports_list
,
380 AST_Interface
**supports_flat
,
381 long n_supports_flat
)
383 AST_Component
*retval
= 0;
384 ACE_NEW_RETURN (retval
,
397 AST_Generator::create_component_fwd (UTL_ScopedName
*n
)
399 AST_Component
*full_defn
= this->create_component (n
,
406 AST_ComponentFwd
*retval
= 0;
407 ACE_NEW_RETURN (retval
,
408 AST_ComponentFwd (full_defn
,
412 full_defn
->fwd_decl (retval
);
417 AST_Generator::create_home (UTL_ScopedName
*n
,
419 AST_Component
*managed_component
,
420 AST_Type
*primary_key
,
421 AST_Type
**supports_list
,
423 AST_Interface
**supports_flat
,
424 long n_supports_flat
)
426 AST_Home
*retval
= 0;
427 ACE_NEW_RETURN (retval
,
442 AST_Generator::create_exception (UTL_ScopedName
*n
,
446 AST_Exception
*retval
= 0;
447 ACE_NEW_RETURN (retval
,
457 AST_Generator::create_structure (UTL_ScopedName
*n
,
461 AST_Structure
*retval
= 0;
462 ACE_NEW_RETURN (retval
,
472 AST_Generator::create_structure_fwd (UTL_ScopedName
*n
)
474 AST_Structure
*full_defn
= this->create_structure (n
,
477 AST_StructureFwd
*retval
= 0;
478 ACE_NEW_RETURN (retval
,
479 AST_StructureFwd (full_defn
,
483 full_defn
->fwd_decl (retval
);
488 AST_Generator::create_enum (UTL_ScopedName
*n
,
492 AST_Enum
*retval
= 0;
493 ACE_NEW_RETURN (retval
,
503 AST_Generator::create_operation (AST_Type
*rt
,
504 AST_Operation::Flags fl
,
509 AST_Operation
*retval
= 0;
510 ACE_NEW_RETURN (retval
,
522 AST_Generator::create_field (AST_Type
*ft
,
524 AST_Field::Visibility vis
)
526 AST_Field
*retval
= 0;
527 ACE_NEW_RETURN (retval
,
537 AST_Generator::create_argument (AST_Argument::Direction d
,
541 AST_Argument
*retval
= 0;
542 ACE_NEW_RETURN (retval
,
552 AST_Generator::create_attribute (bool ro
,
558 AST_Attribute
*retval
= 0;
559 ACE_NEW_RETURN (retval
,
571 AST_Generator::create_union (AST_ConcreteType
*dt
,
576 AST_Union
*retval
= 0;
577 ACE_NEW_RETURN (retval
,
588 AST_Generator::create_union_fwd (UTL_ScopedName
*n
)
590 AST_Union
*full_defn
= this->create_union (0,
594 AST_UnionFwd
*retval
= 0;
595 ACE_NEW_RETURN (retval
,
596 AST_UnionFwd (full_defn
,
600 full_defn
->fwd_decl (retval
);
605 AST_Generator::create_union_branch (UTL_LabelList
*ll
,
609 AST_UnionBranch
*retval
= 0;
610 ACE_NEW_RETURN (retval
,
620 AST_Generator::create_union_label (AST_UnionLabel::UnionLabel ul
,
623 AST_UnionLabel
*retval
= 0;
624 ACE_NEW_RETURN (retval
,
633 AST_Generator::create_constant (AST_Expression::ExprType et
,
637 AST_Constant
*retval
= 0;
638 ACE_NEW_RETURN (retval
,
648 AST_Generator::create_expr (UTL_ScopedName
*n
)
650 AST_Expression
*retval
= 0;
651 ACE_NEW_RETURN (retval
,
659 AST_Generator::create_expr (AST_Expression
*v
,
660 AST_Expression::ExprType t
)
662 AST_Expression
*retval
= 0;
663 ACE_NEW_RETURN (retval
,
672 AST_Generator::create_expr (AST_Expression::ExprComb c
,
676 AST_Expression
*retval
= 0;
677 ACE_NEW_RETURN (retval
,
687 AST_Generator::create_expr (ACE_CDR::Long v
)
689 AST_Expression
*retval
= 0;
690 ACE_NEW_RETURN (retval
,
698 AST_Generator::create_expr (ACE_CDR::LongLong l
)
700 AST_Expression
*retval
= 0;
701 ACE_NEW_RETURN (retval
,
709 AST_Generator::create_expr (ACE_CDR::Boolean b
)
711 AST_Expression
*retval
= 0;
712 ACE_NEW_RETURN (retval
,
720 AST_Generator::create_expr (ACE_CDR::ULong v
)
722 AST_Expression
*retval
= 0;
723 ACE_NEW_RETURN (retval
,
731 AST_Generator::create_expr (ACE_CDR::ULongLong l
)
733 AST_Expression
*retval
= 0;
734 ACE_NEW_RETURN (retval
,
742 AST_Generator::create_expr (ACE_CDR::ULong v
,
743 AST_Expression::ExprType t
)
745 AST_Expression
*retval
= 0;
746 ACE_NEW_RETURN (retval
,
747 AST_Expression (v
, t
),
754 AST_Generator::create_expr (UTL_String
*s
)
756 AST_Expression
*retval
= 0;
757 ACE_NEW_RETURN (retval
,
765 AST_Generator::create_expr (ACE_CDR::Char c
)
767 AST_Expression
*retval
= 0;
768 ACE_NEW_RETURN (retval
,
776 AST_Generator::create_expr (ACE_OutputCDR::from_wchar wc
)
778 AST_Expression
*retval
= 0;
779 ACE_NEW_RETURN (retval
,
787 AST_Generator::create_expr (char *s
)
789 AST_Expression
*retval
= 0;
790 ACE_NEW_RETURN (retval
,
798 AST_Generator::create_expr (ACE_CDR::Double d
)
800 AST_Expression
*retval
= 0;
801 ACE_NEW_RETURN (retval
,
809 AST_Generator::create_expr (const ACE_CDR::Fixed
&f
)
811 AST_Expression
*retval
= 0;
812 ACE_NEW_RETURN (retval
,
820 AST_Generator::create_enum_val (ACE_CDR::ULong v
,
823 AST_EnumVal
*retval
= 0;
824 ACE_NEW_RETURN (retval
,
833 AST_Generator::create_array (UTL_ScopedName
*n
,
834 ACE_CDR::ULong ndims
,
839 AST_Array
*retval
= 0;
840 ACE_NEW_RETURN (retval
,
852 AST_Generator::create_sequence (AST_Expression
*ms
,
858 AST_Sequence
*retval
= 0;
859 ACE_NEW_RETURN (retval
,
871 AST_Generator::create_string (AST_Expression
*ms
)
873 Identifier
id ("string");
874 UTL_ScopedName
n (&id
,
877 AST_String
*retval
= 0;
878 ACE_NEW_RETURN (retval
,
879 AST_String (AST_Decl::NT_string
,
888 AST_Generator::create_wstring (AST_Expression
*ms
)
890 Identifier
id (sizeof (ACE_CDR::WChar
) == 1
893 UTL_ScopedName
n (&id
,
895 AST_Decl::NodeType nt
= sizeof (ACE_CDR::WChar
) == 1
896 ? AST_Decl::NT_string
897 : AST_Decl::NT_wstring
;
899 AST_String
*retval
= 0;
900 ACE_NEW_RETURN (retval
,
904 sizeof (ACE_OS::WChar
)),
911 AST_Generator::create_fixed (AST_Expression
*digits
,
912 AST_Expression
*scale
)
914 Identifier
id ("fixed");
915 UTL_ScopedName
name (&id
, 0);
916 AST_Fixed
*retval
= 0;
917 ACE_NEW_RETURN (retval
, AST_Fixed (&name
, digits
, scale
), 0);
922 AST_Generator::create_typedef (AST_Type
*bt
,
927 AST_Typedef
*retval
= 0;
928 ACE_NEW_RETURN (retval
,
939 AST_Generator::create_native (UTL_ScopedName
*n
)
941 AST_Native
*retval
= 0;
942 ACE_NEW_RETURN (retval
,
950 AST_Generator::create_factory (UTL_ScopedName
*n
)
952 AST_Factory
*retval
= 0;
953 ACE_NEW_RETURN (retval
,
961 AST_Generator::create_finder (UTL_ScopedName
*n
)
963 AST_Finder
*retval
= 0;
964 ACE_NEW_RETURN (retval
,
972 AST_Generator::create_valuebox (UTL_ScopedName
*n
,
973 AST_Type
*boxed_type
)
975 AST_ValueBox
*retval
= 0;
976 ACE_NEW_RETURN (retval
,
977 AST_ValueBox (n
, boxed_type
),
984 AST_Generator::create_porttype (UTL_ScopedName
*n
)
986 AST_PortType
*retval
= 0;
987 ACE_NEW_RETURN (retval
,
995 AST_Generator::create_provides (UTL_ScopedName
*n
,
996 AST_Type
*provides_type
)
998 AST_Provides
*retval
= 0;
999 ACE_NEW_RETURN (retval
,
1008 AST_Generator::create_uses (UTL_ScopedName
*n
,
1009 AST_Type
*uses_type
,
1012 AST_Uses
*retval
= 0;
1013 ACE_NEW_RETURN (retval
,
1023 AST_Generator::create_publishes (UTL_ScopedName
*n
,
1024 AST_Type
*publishes_type
)
1026 AST_Publishes
*retval
= 0;
1027 ACE_NEW_RETURN (retval
,
1036 AST_Generator::create_emits (UTL_ScopedName
*n
,
1037 AST_Type
*emits_type
)
1039 AST_Emits
*retval
= 0;
1040 ACE_NEW_RETURN (retval
,
1048 AST_Generator::create_consumes (UTL_ScopedName
*n
,
1049 AST_Type
*consumes_type
)
1051 AST_Consumes
*retval
= 0;
1052 ACE_NEW_RETURN (retval
,
1061 AST_Generator::create_extended_port (
1063 AST_PortType
*porttype_ref
)
1065 AST_Extended_Port
*retval
= 0;
1066 ACE_NEW_RETURN (retval
,
1067 AST_Extended_Port (n
,
1075 AST_Generator::create_mirror_port (
1077 AST_PortType
*porttype_ref
)
1079 AST_Mirror_Port
*retval
= 0;
1080 ACE_NEW_RETURN (retval
,
1089 AST_Generator::create_connector (
1091 AST_Connector
*base_connector
)
1093 AST_Connector
*retval
= 0;
1094 ACE_NEW_RETURN (retval
,
1102 AST_Template_Module
*
1103 AST_Generator::create_template_module (
1105 FE_Utils::T_PARAMLIST_INFO
*template_params
)
1107 AST_Template_Module
*retval
= 0;
1108 ACE_NEW_RETURN (retval
,
1109 AST_Template_Module (n
,
1116 AST_Template_Module_Inst
*
1117 AST_Generator::create_template_module_inst (
1119 AST_Template_Module
*ref
,
1120 FE_Utils::T_ARGLIST
*template_args
)
1122 AST_Template_Module_Inst
*retval
= 0;
1123 ACE_NEW_RETURN (retval
,
1124 AST_Template_Module_Inst (n
,
1132 AST_Template_Module_Ref
*
1133 AST_Generator::create_template_module_ref (
1135 AST_Template_Module
*ref
,
1136 UTL_StrList
*param_refs
)
1138 AST_Template_Module_Ref
*retval
= 0;
1139 ACE_NEW_RETURN (retval
,
1140 AST_Template_Module_Ref (n
,
1149 AST_Generator::create_param_holder (
1150 UTL_ScopedName
*parameter_name
,
1151 FE_Utils::T_Param_Info
*info
)
1153 AST_Param_Holder
*retval
= 0;
1154 ACE_NEW_RETURN (retval
,
1155 AST_Param_Holder (parameter_name
,
1162 AST_Annotation_Decl
*
1163 AST_Generator::create_annotation_decl (
1164 UTL_ScopedName
*name
)
1166 AST_Annotation_Decl
*retval
= 0;
1167 ACE_NEW_RETURN (retval
, AST_Annotation_Decl (name
), 0);
1171 AST_Annotation_Appl
*
1172 AST_Generator::create_annotation_appl (
1173 UTL_ScopedName
*name
,
1174 AST_Annotation_Appl::Params
*params
)
1176 AST_Annotation_Appl
*retval
= 0;
1177 ACE_NEW_RETURN (retval
, AST_Annotation_Appl (name
, params
), 0);
1181 AST_Annotation_Member
*
1182 AST_Generator::create_annotation_member (
1183 AST_Expression::ExprType expr_type
,
1185 UTL_ScopedName
*name
)
1187 AST_Annotation_Member
*retval
= 0;
1188 ACE_NEW_RETURN (retval
, AST_Annotation_Member (expr_type
, type
, name
), 0);