2 * @file ast_visitor_tmpl_module_inst.cpp
6 //=============================================================================
8 #include "ast_visitor_tmpl_module_inst.h"
9 #include "ast_visitor_reifying.h"
10 #include "ast_visitor_context.h"
11 #include "ast_generator.h"
14 #include "ast_module.h"
15 #include "ast_template_module.h"
16 #include "ast_template_module_inst.h"
17 #include "ast_template_module_ref.h"
18 #include "ast_eventtype.h"
19 #include "ast_interface.h"
21 #include "ast_provides.h"
23 #include "ast_publishes.h"
24 #include "ast_emits.h"
25 #include "ast_consumes.h"
26 #include "ast_mirror_port.h"
27 #include "ast_connector.h"
28 #include "ast_attribute.h"
29 #include "ast_operation.h"
30 #include "ast_argument.h"
31 #include "ast_typedef.h"
32 #include "ast_constant.h"
33 #include "ast_union.h"
34 #include "ast_union_branch.h"
36 #include "ast_enum_val.h"
37 #include "ast_finder.h"
38 #include "ast_param_holder.h"
39 #include "ast_expression.h"
41 #include "ast_param_holder.h"
43 #include "utl_namelist.h"
44 #include "utl_identifier.h"
45 #include "utl_exceptlist.h"
46 #include "utl_labellist.h"
48 #include "fe_obv_header.h"
49 #include "fe_home_header.h"
51 #include "nr_extern.h"
53 ast_visitor_tmpl_module_inst::ast_visitor_tmpl_module_inst (
54 ast_visitor_context
*ctx
,
59 for_eventtype_ (false),
65 ast_visitor_tmpl_module_inst::~ast_visitor_tmpl_module_inst (void)
69 int ast_visitor_tmpl_module_inst::visit_decl (AST_Decl
*)
75 ast_visitor_tmpl_module_inst::visit_scope (UTL_Scope
*node
)
77 for (UTL_ScopeActiveIterator
si (node
, UTL_Scope::IK_decls
);
81 AST_Decl
*d
= si
.item ();
85 ACE_ERROR_RETURN ((LM_ERROR
,
86 ACE_TEXT ("ast_visitor_tmpl_module_inst::")
87 ACE_TEXT ("visit_scope - ")
88 ACE_TEXT ("bad node in this scope\n")),
93 if (d
== 0 || d
->ast_accept (this) == -1)
95 ACE_ERROR_RETURN ((LM_ERROR
,
96 ACE_TEXT ("ast_visitor_tmpl_module_inst::")
97 ACE_TEXT ("visit_scope - ")
98 ACE_TEXT ("codegen for scope failed\n")),
107 ast_visitor_tmpl_module_inst::visit_type (AST_Type
*)
113 ast_visitor_tmpl_module_inst::visit_predefined_type (AST_PredefinedType
*)
119 ast_visitor_tmpl_module_inst::visit_interface_fwd (AST_InterfaceFwd
*)
125 ast_visitor_tmpl_module_inst::visit_valuebox (AST_ValueBox
*)
131 ast_visitor_tmpl_module_inst::visit_valuetype_fwd (AST_ValueTypeFwd
*)
137 ast_visitor_tmpl_module_inst::visit_component (AST_Component
*node
)
139 UTL_ScopedName
*base_name
= 0;
141 this->reify_type (node
->base_component ());
145 base_name
= parent
->name ();
148 UTL_NameList
*supports_names
=
149 this->create_name_list (node
->supports (),
150 node
->n_supports ());
152 Identifier
*node_id
= 0;
153 ACE_NEW_RETURN (node_id
,
154 Identifier (node
->local_name ()->get_string ()),
157 UTL_ScopedName
*local_name
= 0;
158 ACE_NEW_RETURN (local_name
,
159 UTL_ScopedName (node_id
, 0),
162 FE_ComponentHeader
header (local_name
,
167 AST_Component
*added_comp
=
168 idl_global
->gen ()->create_component (header
.name (),
169 header
.base_component (),
171 header
.n_supports (),
172 header
.supports_flat (),
173 header
.n_supports_flat ());
175 if (supports_names
!= 0)
177 supports_names
->destroy ();
178 delete supports_names
;
182 idl_global
->scopes ().top ()->add_to_scope (added_comp
);
184 // Update the scope management.
185 idl_global
->scopes ().push (added_comp
);
187 if (this->visit_scope (node
) != 0)
189 ACE_ERROR_RETURN ((LM_ERROR
,
190 ACE_TEXT ("ast_visitor_tmpl_module_inst::")
191 ACE_TEXT ("visit_component - ")
192 ACE_TEXT ("visit_scope failed\n")),
196 // Through with this scope.
197 idl_global
->scopes ().pop ();
203 ast_visitor_tmpl_module_inst::visit_eventtype_fwd (AST_EventTypeFwd
*)
209 ast_visitor_tmpl_module_inst::visit_component_fwd (AST_ComponentFwd
*)
215 ast_visitor_tmpl_module_inst::visit_template_module_ref (
216 AST_Template_Module_Ref
*)
218 // A subclass of this visitor is launched when an 'alias'
219 // construct is parsed, which creates the necessary implied IDL
220 // in the template module. This visitor skips the alias and
221 // processes the implied IDL. It's a bit inefficient to have
222 // the implied IDL in both the template module and its
223 // instantiations, but otherwise the lookup issues are
224 // extremely complicated. This approach allows
225 // lookup_by_name_local() to just skip over the alias and
226 // match the module of the same name occurring later in the
227 // template module scope. From that vantage point, the
228 // reifying visitor uses its established mechanism to jump
229 // to the module of the same name in the instantiated template
230 // module scope (see ast_visitor_reifying::check_and_store()
231 // and ast_visitor_reifying::template_module_rel_name()).
236 ast_visitor_tmpl_module_inst::visit_porttype (AST_PortType
*node
)
238 UTL_ScopedName
sn (node
->local_name (), 0);
240 AST_PortType
*added_porttype
=
241 idl_global
->gen ()->create_porttype (&sn
);
243 idl_global
->scopes ().top ()->add_to_scope (added_porttype
);
245 idl_global
->scopes ().push (added_porttype
);
247 if (this->visit_scope (node
) != 0)
249 ACE_ERROR_RETURN ((LM_ERROR
,
250 ACE_TEXT ("ast_visitor_tmpl_module_inst::")
251 ACE_TEXT ("visit_porttype - ")
252 ACE_TEXT ("visit_scope failed\n")),
256 idl_global
->scopes ().pop ();
262 ast_visitor_tmpl_module_inst::visit_provides (AST_Provides
*node
)
264 UTL_ScopedName
sn (node
->local_name (), 0);
266 AST_Type
*p_type
= dynamic_cast<AST_Type
*> (this->reify_type (node
->provides_type ()));
268 AST_Provides
*added_provides
=
269 idl_global
->gen ()->create_provides (&sn
,
272 idl_global
->scopes ().top ()->add_to_scope (added_provides
);
278 ast_visitor_tmpl_module_inst::visit_uses (AST_Uses
*node
)
280 UTL_ScopedName
sn (node
->local_name (), 0);
282 AST_Type
*u_type
= dynamic_cast<AST_Type
*> (this->reify_type (node
->uses_type ()));
284 AST_Uses
*added_uses
=
285 idl_global
->gen ()->create_uses (&sn
,
287 node
->is_multiple ());
289 idl_global
->scopes ().top ()->add_to_scope (added_uses
);
295 ast_visitor_tmpl_module_inst::visit_publishes (AST_Publishes
*node
)
297 UTL_ScopedName
sn (node
->local_name (), 0);
300 dynamic_cast<AST_Type
*> (
301 this->reify_type (node
->publishes_type ()));
303 AST_Publishes
*added_publishes
=
304 idl_global
->gen ()->create_publishes (&sn
,
307 idl_global
->scopes ().top ()->add_to_scope (added_publishes
);
313 ast_visitor_tmpl_module_inst::visit_emits (AST_Emits
*node
)
315 UTL_ScopedName
sn (node
->local_name (), 0);
318 dynamic_cast<AST_Type
*> (
319 this->reify_type (node
->emits_type ()));
321 AST_Emits
*added_emits
=
322 idl_global
->gen ()->create_emits (&sn
, e_type
);
324 idl_global
->scopes ().top ()->add_to_scope (added_emits
);
330 ast_visitor_tmpl_module_inst::visit_consumes (AST_Consumes
*node
)
332 UTL_ScopedName
sn (node
->local_name (), 0);
334 AST_Type
*c_type
= dynamic_cast<AST_Type
*> (this->reify_type (node
->consumes_type ()));
336 AST_Consumes
*added_consumes
=
337 idl_global
->gen ()->create_consumes (&sn
, c_type
);
339 idl_global
->scopes ().top ()->add_to_scope (added_consumes
);
345 ast_visitor_tmpl_module_inst::visit_extended_port (
346 AST_Extended_Port
*node
)
348 AST_PortType
*pt
= dynamic_cast<AST_PortType
*> (this->reify_type (node
->port_type ()));
350 UTL_ScopedName
sn (node
->local_name (), 0);
352 AST_Extended_Port
*added_ep
=
353 idl_global
->gen ()->create_extended_port (&sn
, pt
);
355 idl_global
->scopes ().top ()->add_to_scope (added_ep
);
361 ast_visitor_tmpl_module_inst::visit_mirror_port (
362 AST_Mirror_Port
*node
)
364 AST_PortType
*pt
= dynamic_cast<AST_PortType
*> (this->reify_type (node
->port_type ()));
366 UTL_ScopedName
sn (node
->local_name (), 0);
368 AST_Mirror_Port
*added_mp
=
369 idl_global
->gen ()->create_mirror_port (&sn
, pt
);
371 idl_global
->scopes ().top ()->add_to_scope (added_mp
);
377 ast_visitor_tmpl_module_inst::visit_connector (AST_Connector
*node
)
379 AST_Connector
*parent
= dynamic_cast<AST_Connector
*> (this->reify_type (node
->base_connector ()));
381 UTL_ScopedName
sn (node
->local_name (), 0);
383 AST_Connector
*added_connector
=
384 idl_global
->gen ()->create_connector (&sn
, parent
);
386 idl_global
->scopes ().top ()->add_to_scope (added_connector
);
388 idl_global
->scopes ().push (added_connector
);
390 if (this->visit_scope (node
) != 0)
392 ACE_ERROR_RETURN ((LM_ERROR
,
393 ACE_TEXT ("ast_visitor_tmpl_module_inst::")
394 ACE_TEXT ("visit_connector - ")
395 ACE_TEXT ("visit scope failed\n")),
399 idl_global
->scopes ().pop ();
405 ast_visitor_tmpl_module_inst::visit_home (AST_Home
*node
)
407 UTL_ScopedName
*base_name
= 0;
409 this->reify_type (node
->base_home ());
413 base_name
= parent
->name ();
416 UTL_NameList
*supports_names
=
417 this->create_name_list (node
->supports (),
418 node
->n_supports ());
420 UTL_ScopedName
*managed_comp_name
= 0;
422 AST_Component
*managed_comp
= dynamic_cast<AST_Component
*> (this->reify_type (node
->managed_component ()));
424 if (managed_comp
!= 0)
426 managed_comp_name
= managed_comp
->name ();
429 UTL_ScopedName
*p_key_name
= 0;
431 AST_ValueType
*p_key
= dynamic_cast<AST_ValueType
*> (this->reify_type (node
->primary_key ()));
435 p_key_name
= p_key
->name ();
438 Identifier
*node_id
= 0;
439 ACE_NEW_RETURN (node_id
,
440 Identifier (node
->local_name ()->get_string ()),
443 UTL_ScopedName
*local_name
= 0;
444 ACE_NEW_RETURN (local_name
,
445 UTL_ScopedName (node_id
, 0),
448 FE_HomeHeader
header (local_name
,
454 AST_Home
*added_home
=
455 idl_global
->gen ()->create_home (header
.name (),
457 header
.managed_component (),
458 header
.primary_key (),
460 header
.n_supports (),
461 header
.supports_flat (),
462 header
.n_supports_flat ());
464 if (supports_names
!= 0)
466 supports_names
->destroy ();
467 delete supports_names
;
471 idl_global
->scopes ().top ()->add_to_scope (added_home
);
473 // Update the scope management.
474 idl_global
->scopes ().push (added_home
);
476 if (this->visit_scope (node
) != 0)
478 ACE_ERROR_RETURN ((LM_ERROR
,
479 ACE_TEXT ("ast_visitor_tmpl_module_inst::")
480 ACE_TEXT ("visit_home - ")
481 ACE_TEXT ("visit_scope failed\n")),
485 // Through with this scope.
486 idl_global
->scopes ().pop ();
492 ast_visitor_tmpl_module_inst::visit_structure_fwd (AST_StructureFwd
*)
498 ast_visitor_tmpl_module_inst::visit_exception (AST_Exception
*)
504 ast_visitor_tmpl_module_inst::visit_expression (AST_Expression
*)
510 ast_visitor_tmpl_module_inst::visit_enum (AST_Enum
*node
)
512 UTL_ScopedName
sn (node
->local_name (), 0);
514 AST_Enum
*added_enum
=
515 idl_global
->gen ()->create_enum (&sn
,
517 node
->is_abstract ());
519 idl_global
->scopes ().top ()->add_to_scope (added_enum
);
521 idl_global
->scopes ().push (added_enum
);
523 if (this->visit_scope (node
) != 0)
525 ACE_ERROR_RETURN ((LM_ERROR
,
526 ACE_TEXT ("ast_visitor_tmpl_module_inst::")
527 ACE_TEXT ("visit_enum - ")
528 ACE_TEXT ("visit_scope failed\n")),
532 idl_global
->scopes ().pop ();
538 ast_visitor_tmpl_module_inst::visit_union (AST_Union
*node
)
540 UTL_ScopedName
sn (node
->local_name (), 0);
542 AST_Union
*added_union
=
543 idl_global
->gen ()->create_union (node
->disc_type (),
546 node
->is_abstract ());
548 idl_global
->scopes ().top ()->add_to_scope (added_union
);
550 // Update our scope stack.
551 idl_global
->scopes ().push (added_union
);
553 if (this->visit_scope (node
) != 0)
555 ACE_ERROR_RETURN ((LM_ERROR
,
556 ACE_TEXT ("ast_visitor_tmpl_module_inst::")
557 ACE_TEXT ("visit_union - ")
558 ACE_TEXT ("visit_scope() failed\n")),
562 // Through with this scope.
563 idl_global
->scopes ().pop ();
565 added_union
->member_count ();
571 ast_visitor_tmpl_module_inst::visit_union_fwd (AST_UnionFwd
*)
577 ast_visitor_tmpl_module_inst::visit_union_branch (AST_UnionBranch
*node
)
580 dynamic_cast<AST_Type
*> (
581 this->reify_type (node
->field_type ()));
583 UTL_ScopedName
sn (node
->local_name (), 0);
585 // The union branch owns its label list so we have to copy it.
586 UTL_LabelList
*ll
= node
->labels ()->copy ();
588 AST_UnionBranch
*added_branch
=
589 idl_global
->gen ()->create_union_branch (ll
, ft
, &sn
);
591 // fe_add_union_branch() does necessary things besides calling
592 // add_to_scope() so we need to reuse it.
595 dynamic_cast<AST_Union
*> (idl_global
->scopes ().top ());
597 u
->fe_add_union_branch (added_branch
);
603 ast_visitor_tmpl_module_inst::visit_union_label (AST_UnionLabel
*)
609 ast_visitor_tmpl_module_inst::visit_enum_val (AST_EnumVal
*node
)
611 UTL_ScopedName
sn (node
->local_name (), 0);
613 AST_EnumVal
*added_enum_val
=
614 idl_global
->gen ()->create_enum_val (
615 node
->constant_value ()->ev ()->u
.ulval
,
618 idl_global
->scopes ().top ()->add_to_scope (added_enum_val
);
624 ast_visitor_tmpl_module_inst::visit_array (AST_Array
*)
630 ast_visitor_tmpl_module_inst::visit_sequence (AST_Sequence
*)
636 ast_visitor_tmpl_module_inst::visit_string (AST_String
*)
642 ast_visitor_tmpl_module_inst::visit_param_holder (AST_Param_Holder
*)
648 ast_visitor_tmpl_module_inst::visit_root (AST_Root
*)
654 ast_visitor_tmpl_module_inst::visit_native (AST_Native
*)
660 ast_visitor_tmpl_module_inst::visit_module (AST_Module
*node
)
662 UTL_ScopedName
sn (node
->local_name (), 0);
664 AST_Module
*added_module
=
665 idl_global
->gen ()->create_module (idl_global
->scopes ().top (),
668 added_module
->from_inst (this->tmi_
);
671 dynamic_cast<AST_Module
*> (idl_global
->scopes ().top ());
673 m
->fe_add_module (added_module
);
675 idl_global
->scopes ().push (added_module
);
677 AST_Template_Module_Ref
*ref
= node
->from_ref ();
678 UTL_StrList
const *old_refs
= idl_global
->alias_params ();
682 added_module
->from_ref (ref
);
683 idl_global
->alias_params (ref
->param_refs ());
686 if (this->visit_scope (node
) == -1)
688 ACE_ERROR_RETURN ((LM_ERROR
,
689 ACE_TEXT ("ast_visitor_tmpl_module_inst::")
690 ACE_TEXT ("visit_module - ")
691 ACE_TEXT ("visit scope failed\n")),
695 // Restore scope stack.
696 idl_global
->scopes ().pop ();
698 idl_global
->alias_params (const_cast<UTL_StrList
*> (old_refs
));
703 // Not called from ast_template_module::accept() but from
704 // visit_template_module_inst() in this visitor.
706 ast_visitor_tmpl_module_inst::visit_template_module (
707 AST_Template_Module
*node
)
709 this->ctx_
->template_params (node
->template_params ());
711 if (this->visit_scope (node
) == -1)
713 ACE_ERROR_RETURN ((LM_ERROR
,
714 ACE_TEXT ("ast_visitor_tmpl_module_inst::")
715 ACE_TEXT ("visit_template_module - ")
716 ACE_TEXT ("visit scope failed\n")),
724 ast_visitor_tmpl_module_inst::visit_template_module_inst (
725 AST_Template_Module_Inst
*node
)
727 this->ctx_
->template_args (node
->template_args ());
730 AST_Module
*instance
=
731 idl_global
->gen ()->create_module (idl_global
->scopes ().top (),
734 instance
->from_inst (node
);
736 // Add the new module to the scope containing the template
737 // module instantiation.
739 dynamic_cast<AST_Module
*> (idl_global
->scopes ().top ());
741 m
->fe_add_module (instance
);
743 // Update our scope management.
744 idl_global
->scopes ().push (instance
);
746 AST_Template_Module
*tm
= node
->ref ();
748 if (this->visit_template_module (tm
) == -1)
750 ACE_ERROR_RETURN ((LM_ERROR
,
751 ACE_TEXT ("ast_visitor_tmpl_module_inst::")
752 ACE_TEXT ("visit_template_module_inst - ")
753 ACE_TEXT ("visit_template_module failed\n")),
757 // By checking this member for a non-zero value, we can tell if
758 // we are processing an instantiated template module or not. We
759 // need to know this, for example while visiting an IDL module,
760 // to decide whether to create an implied IDL module or just
762 this->ctx_
->template_args (0);
764 // Restore the scope stack.
765 idl_global
->scopes ().pop ();
771 ast_visitor_tmpl_module_inst::visit_eventtype (AST_EventType
*node
)
773 this->for_eventtype_
= true;
774 return this->visit_valuetype (node
);
778 ast_visitor_tmpl_module_inst::visit_valuetype (AST_ValueType
*node
)
780 UTL_NameList
*parent_names
=
781 this->create_name_list (node
->inherits (),
782 node
->n_inherits ());
784 UTL_NameList
*supports_names
=
785 this->create_name_list (node
->supports (),
786 node
->n_supports ());
788 Identifier
*node_id
= 0;
789 ACE_NEW_RETURN (node_id
,
790 Identifier (node
->local_name ()->get_string ()),
793 UTL_ScopedName
*local_name
= 0;
794 ACE_NEW_RETURN (local_name
,
795 UTL_ScopedName (node_id
, 0),
798 AST_ValueType
*added_vtype
= 0;
800 FE_OBVHeader
header (local_name
,
804 ? parent_names
->truncatable ()
806 this->for_eventtype_
);
808 if (this->for_eventtype_
)
811 idl_global
->gen ()->create_eventtype (header
.name (),
813 header
.n_inherits (),
814 header
.inherits_concrete (),
815 header
.inherits_flat (),
816 header
.n_inherits_flat (),
818 header
.n_supports (),
819 header
.supports_concrete (),
821 header
.truncatable (),
827 idl_global
->gen ()->create_valuetype (header
.name (),
829 header
.n_inherits (),
830 header
.inherits_concrete (),
831 header
.inherits_flat (),
832 header
.n_inherits_flat (),
834 header
.n_supports (),
835 header
.supports_concrete (),
837 header
.truncatable (),
841 if (parent_names
!= 0)
843 parent_names
->destroy ();
848 if (supports_names
!= 0)
850 supports_names
->destroy ();
851 delete supports_names
;
855 idl_global
->scopes ().top ()->add_to_scope (added_vtype
);
857 // Update the scope management.
858 idl_global
->scopes ().push (added_vtype
);
860 if (this->visit_scope (node
) != 0)
862 ACE_ERROR_RETURN ((LM_ERROR
,
863 ACE_TEXT ("ast_visitor_tmpl_module_inst::")
864 ACE_TEXT ("visit_valuetype - ")
865 ACE_TEXT ("visit_scope failed\n")),
869 // Through with this scope.
870 idl_global
->scopes ().pop ();
873 this->for_eventtype_
= false;
879 ast_visitor_tmpl_module_inst::visit_interface (AST_Interface
*node
)
881 UTL_NameList
*parent_names
=
882 this->create_name_list (node
->inherits (),
883 node
->n_inherits ());
885 Identifier
*node_id
= 0;
886 ACE_NEW_RETURN (node_id
,
887 Identifier (node
->local_name ()->get_string ()),
890 UTL_ScopedName
*local_name
= 0;
891 ACE_NEW_RETURN (local_name
,
892 UTL_ScopedName (node_id
, 0),
895 FE_InterfaceHeader
header (local_name
,
898 node
->is_abstract (),
901 AST_Interface
*added_iface
=
902 idl_global
->gen ()->create_interface (header
.name (),
904 header
.n_inherits (),
905 header
.inherits_flat (),
906 header
.n_inherits_flat (),
908 header
.is_abstract ());
910 if (parent_names
!= 0)
912 parent_names
->destroy ();
917 idl_global
->scopes ().top ()->add_to_scope (added_iface
);
919 // If this interface has both abstract and concrete parents,
920 // extra code needs to be generated for it, such as overrides
921 // of _is_nil() and release().
922 added_iface
->analyze_parentage ();
924 // Update the scope stack.
925 idl_global
->scopes ().push (added_iface
);
927 if (this->visit_scope (node
) != 0)
929 ACE_ERROR_RETURN ((LM_ERROR
,
930 ACE_TEXT ("ast_visitor_tmpl_module_inst::")
931 ACE_TEXT ("visit_interface - ")
932 ACE_TEXT ("visit_scope failed\n")),
936 // Through with this scope.
937 idl_global
->scopes ().pop ();
943 ast_visitor_tmpl_module_inst::visit_attribute (AST_Attribute
*node
)
946 dynamic_cast<AST_Type
*> (
947 this->reify_type (node
->field_type ()));
949 AST_Attribute
*added_attr
=
950 idl_global
->gen ()->create_attribute (node
->readonly (),
954 node
->is_abstract ());
956 idl_global
->scopes ().top ()->add_to_scope (added_attr
);
958 // These will work even if the exception lists are null.
960 UTL_ExceptList
*old_ex
= node
->get_get_exceptions ();
961 UTL_ExceptList
*new_ex
= this->reify_exception_list (old_ex
);
962 added_attr
->be_add_get_exceptions (new_ex
);
964 old_ex
= node
->get_set_exceptions ();
965 new_ex
= this->reify_exception_list (old_ex
);
966 added_attr
->be_add_set_exceptions (new_ex
);
972 ast_visitor_tmpl_module_inst::visit_operation (AST_Operation
*node
)
975 dynamic_cast<AST_Type
*> (
976 this->reify_type (node
->return_type ()));
978 Identifier
id (node
->local_name ()->get_string ());
979 UTL_ScopedName
sn (&id
, 0);
981 AST_Operation
*added_op
=
982 idl_global
->gen ()->create_operation (rt
,
986 node
->is_abstract ());
988 idl_global
->scopes ().top ()->add_to_scope (added_op
);
990 // Update the scope stack.
991 idl_global
->scopes ().push (added_op
);
993 if (this->visit_scope (node
) != 0)
995 ACE_ERROR_RETURN ((LM_ERROR
,
996 ACE_TEXT ("ast_visitor_tmpl_module_inst::")
997 ACE_TEXT ("visit_operation - ")
998 ACE_TEXT ("visit_scope failed\n")),
1002 // Through with this scope.
1003 idl_global
->scopes ().pop ();
1005 UTL_ExceptList
*new_ex
=
1006 this->reify_exception_list (node
->exceptions ());
1008 added_op
->be_add_exceptions (new_ex
);
1014 ast_visitor_tmpl_module_inst::visit_argument (AST_Argument
*node
)
1017 dynamic_cast<AST_Type
*> (
1018 this->reify_type (node
->field_type ()));
1022 ACE_ERROR_RETURN ((LM_ERROR
,
1023 ACE_TEXT ("ast_visitor_tmpl_module_inst::")
1024 ACE_TEXT ("visit_argument - ")
1025 ACE_TEXT ("reify_type failed\n")),
1029 AST_Argument
*added_arg
=
1030 idl_global
->gen ()->create_argument (node
->direction (),
1034 idl_global
->scopes ().top ()->add_to_scope (added_arg
);
1040 ast_visitor_tmpl_module_inst::visit_typedef (AST_Typedef
*node
)
1043 dynamic_cast<AST_Type
*> (
1044 this->reify_type (node
->base_type ()));
1046 UTL_ScopedName
sn (node
->local_name (), 0);
1048 AST_Typedef
*added_td
=
1049 idl_global
->gen ()->create_typedef (bt
,
1054 idl_global
->scopes ().top ()->add_to_scope (added_td
);
1060 ast_visitor_tmpl_module_inst::visit_constant (AST_Constant
*node
)
1062 AST_Param_Holder
*ph
=
1063 node
->constant_value ()->param_holder ();
1065 AST_Expression
*v
= 0;
1066 AST_Expression::ExprType et
= node
->et ();
1070 ast_visitor_reifying
rv (this->ctx_
);
1072 if (rv
.visit_param_holder (ph
) != 0)
1074 ACE_ERROR_RETURN ((LM_ERROR
,
1075 ACE_TEXT ("ast_visitor_tmpl_module_inst::")
1076 ACE_TEXT ("visit_constant - ")
1077 ACE_TEXT ("reification of param ")
1078 ACE_TEXT ("holder failed\n")),
1083 dynamic_cast<AST_Constant
*> (rv
.reified_node ());
1085 /// We don't use the reified node's ExprType here, since
1086 /// it was created from a template arg that (for const
1087 /// type template args) was a literal. The arg name was
1088 /// matched with a template param list to check correctness,
1089 /// but not the type. Thus an integer literal, for example,
1090 /// will be a 64-bit type usually, but what we want is
1091 /// the type of the constant we are visiting. When the
1092 /// new expression and constant are created below, things
1093 /// will be coerced to the ExprType passed in, and if
1094 /// there is a mismatch, we'll get an error at that point.
1095 v
= c
->constant_value ();
1099 v
= node
->constant_value ();
1102 AST_Expression
*new_v
=
1103 idl_global
->gen ()->create_expr (v
, et
);
1105 AST_Constant
*added_const
=
1106 idl_global
->gen ()->create_constant (et
,
1110 idl_global
->scopes ().top ()->add_to_scope (added_const
);
1116 ast_visitor_tmpl_module_inst::visit_structure (AST_Structure
*node
)
1118 UTL_ScopedName
sn (node
->name ()->last_component (), 0);
1120 AST_Structure
*added_struct
=
1121 idl_global
->gen ()->create_structure (&sn
,
1123 node
->is_abstract ());
1125 idl_global
->scopes ().top ()->add_to_scope (added_struct
);
1127 // Update our scope stack.
1128 idl_global
->scopes ().push (added_struct
);
1130 if (this->visit_scope (node
) != 0)
1132 ACE_ERROR_RETURN ((LM_ERROR
,
1133 ACE_TEXT ("ast_visitor_tmpl_module_inst::")
1134 ACE_TEXT ("visit_structure - ")
1135 ACE_TEXT ("visit_scope() failed\n")),
1139 // Through with this scope.
1140 idl_global
->scopes ().pop ();
1146 ast_visitor_tmpl_module_inst::visit_field (AST_Field
*node
)
1149 dynamic_cast<AST_Type
*> (
1150 this->reify_type (node
->field_type ()));
1152 AST_Field
*added_field
=
1153 idl_global
->gen ()->create_field (t
,
1155 node
->visibility ());
1157 idl_global
->scopes ().top ()->add_to_scope (added_field
);
1163 ast_visitor_tmpl_module_inst::visit_factory (AST_Factory
*node
)
1165 Identifier
id (node
->local_name ()->get_string ());
1166 UTL_ScopedName
sn (&id
, 0);
1168 AST_Factory
*added_factory
= 0;
1170 if (this->for_finder_
)
1173 idl_global
->gen ()->create_finder (&sn
);
1178 idl_global
->gen ()->create_factory (&sn
);
1181 idl_global
->scopes ().top ()->add_to_scope (added_factory
);
1183 // Update the scope stack.
1184 idl_global
->scopes ().push (added_factory
);
1186 if (this->visit_scope (node
) != 0)
1188 ACE_ERROR_RETURN ((LM_ERROR
,
1189 ACE_TEXT ("ast_visitor_tmpl_module_inst::")
1190 ACE_TEXT ("visit_factory - ")
1191 ACE_TEXT ("visit_scope() failed\n")),
1195 // Through with this scope.
1196 idl_global
->scopes ().pop ();
1198 UTL_ExceptList
*reified_exceps
=
1199 this->reify_exception_list (node
->exceptions ());
1201 added_factory
->be_add_exceptions (reified_exceps
);
1203 // In case it was set for this call.
1204 this->for_finder_
= false;
1210 ast_visitor_tmpl_module_inst::visit_finder (AST_Finder
*node
)
1212 this->for_finder_
= true;
1213 return this->visit_factory (node
);
1217 ast_visitor_tmpl_module_inst::reify_type (AST_Decl
*d
)
1224 if (this->ref_only_
)
1226 // If d is a param holder, the lookup will return a heap
1227 // allocation, which we need since this node's destination
1228 // owns param holders.
1229 if (d
->node_type () == AST_Decl::NT_param_holder
)
1232 idl_global
->scopes ().top ()->lookup_by_name (
1242 ast_visitor_reifying
rv (this->ctx_
);
1244 if (d
->ast_accept (&rv
) != 0)
1246 ACE_ERROR ((LM_ERROR
,
1247 ACE_TEXT ("ast_visitor_tmpl_module_inst::")
1248 ACE_TEXT ("reify_type() - reifying ")
1249 ACE_TEXT ("visitor failed on %C\n"),
1255 return rv
.reified_node ();
1259 ast_visitor_tmpl_module_inst::reify_exception_list (
1260 UTL_ExceptList
*orig
)
1267 UTL_ExceptList
*retval
= 0;
1269 for (UTL_ExceptlistActiveIterator
i (orig
);
1274 dynamic_cast<AST_Type
*> (this->reify_type (i
.item ()));
1276 UTL_ExceptList
*ex_list
= 0;
1277 ACE_NEW_RETURN (ex_list
,
1278 UTL_ExceptList (ex
, 0),
1287 retval
->nconc (ex_list
);
1295 ast_visitor_tmpl_module_inst::create_name_list (AST_Type
**list
,
1298 UTL_NameList
*retval
= 0;
1300 for (long i
= 0; i
< length
; ++i
)
1303 dynamic_cast<AST_Type
*> (this->reify_type (list
[i
]));
1305 // We copy each name added so we can call destroy() on the
1306 // list, which disposes of the contents as well as the
1307 // nested tail pointers.
1308 UTL_NameList
*name_item
= 0;
1309 ACE_NEW_RETURN (name_item
,
1310 UTL_NameList (item
->name ()->copy (), 0),
1319 retval
->nconc (name_item
);