Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / TAO_IDL / ast / ast_visitor_tmpl_module_inst.cpp
blob94efdb43bdbf39b72fc49d961c073a4a9d0abc2e
1 /**
2 * @file ast_visitor_tmpl_module_inst.cpp
4 * @author Jeff Parsons
5 */
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"
13 #include "ast_root.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"
20 #include "ast_home.h"
21 #include "ast_provides.h"
22 #include "ast_uses.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"
35 #include "ast_enum.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,
55 bool ref_only)
56 : ast_visitor (),
57 tmi_ (nullptr),
58 ctx_ (ctx),
59 for_eventtype_ (false),
60 for_finder_ (false),
61 ref_only_ (ref_only)
65 ast_visitor_tmpl_module_inst::~ast_visitor_tmpl_module_inst ()
69 int ast_visitor_tmpl_module_inst::visit_decl (AST_Decl *)
71 return 0;
74 int
75 ast_visitor_tmpl_module_inst::visit_scope (UTL_Scope *node)
77 for (UTL_ScopeActiveIterator si (node, UTL_Scope::IK_decls);
78 !si.is_done ();
79 si.next ())
81 AST_Decl *d = si.item ();
83 if (d == nullptr)
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")),
89 -1);
92 // Send the visitor.
93 if (d == nullptr || 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")),
99 -1);
103 return 0;
107 ast_visitor_tmpl_module_inst::visit_type (AST_Type *)
109 return 0;
113 ast_visitor_tmpl_module_inst::visit_predefined_type (AST_PredefinedType *)
115 return 0;
119 ast_visitor_tmpl_module_inst::visit_interface_fwd (AST_InterfaceFwd *)
121 return 0;
125 ast_visitor_tmpl_module_inst::visit_valuebox (AST_ValueBox *)
127 return 0;
131 ast_visitor_tmpl_module_inst::visit_valuetype_fwd (AST_ValueTypeFwd *)
133 return 0;
137 ast_visitor_tmpl_module_inst::visit_component (AST_Component *node)
139 UTL_ScopedName *base_name = nullptr;
140 AST_Decl *parent =
141 this->reify_type (node->base_component ());
143 if (parent != nullptr)
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 = nullptr;
153 ACE_NEW_RETURN (node_id,
154 Identifier (node->local_name ()->get_string ()),
155 -1);
157 UTL_ScopedName *local_name = nullptr;
158 ACE_NEW_RETURN (local_name,
159 UTL_ScopedName (node_id, nullptr),
160 -1);
162 FE_ComponentHeader header (local_name,
163 base_name,
164 supports_names,
165 false);
167 AST_Component *added_comp =
168 idl_global->gen ()->create_component (header.name (),
169 header.base_component (),
170 header.supports (),
171 header.n_supports (),
172 header.supports_flat (),
173 header.n_supports_flat ());
175 if (supports_names != nullptr)
177 supports_names->destroy ();
178 delete supports_names;
179 supports_names = nullptr;
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")),
193 -1);
196 // Through with this scope.
197 idl_global->scopes ().pop ();
199 return 0;
203 ast_visitor_tmpl_module_inst::visit_eventtype_fwd (AST_EventTypeFwd *)
205 return 0;
209 ast_visitor_tmpl_module_inst::visit_component_fwd (AST_ComponentFwd *)
211 return 0;
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()).
232 return 0;
236 ast_visitor_tmpl_module_inst::visit_porttype (AST_PortType *node)
238 UTL_ScopedName sn (node->local_name (), nullptr);
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")),
253 -1);
256 idl_global->scopes ().pop ();
258 return 0;
262 ast_visitor_tmpl_module_inst::visit_provides (AST_Provides *node)
264 UTL_ScopedName sn (node->local_name (), nullptr);
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,
270 p_type);
272 idl_global->scopes ().top ()->add_to_scope (added_provides);
274 return 0;
278 ast_visitor_tmpl_module_inst::visit_uses (AST_Uses *node)
280 UTL_ScopedName sn (node->local_name (), nullptr);
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,
286 u_type,
287 node->is_multiple ());
289 idl_global->scopes ().top ()->add_to_scope (added_uses);
291 return 0;
295 ast_visitor_tmpl_module_inst::visit_publishes (AST_Publishes *node)
297 UTL_ScopedName sn (node->local_name (), nullptr);
299 AST_Type *p_type =
300 dynamic_cast<AST_Type*> (
301 this->reify_type (node->publishes_type ()));
303 AST_Publishes *added_publishes =
304 idl_global->gen ()->create_publishes (&sn,
305 p_type);
307 idl_global->scopes ().top ()->add_to_scope (added_publishes);
309 return 0;
313 ast_visitor_tmpl_module_inst::visit_emits (AST_Emits *node)
315 UTL_ScopedName sn (node->local_name (), nullptr);
317 AST_Type *e_type =
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);
326 return 0;
330 ast_visitor_tmpl_module_inst::visit_consumes (AST_Consumes *node)
332 UTL_ScopedName sn (node->local_name (), nullptr);
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);
341 return 0;
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 (), nullptr);
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);
357 return 0;
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 (), nullptr);
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);
373 return 0;
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 (), nullptr);
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")),
396 -1);
399 idl_global->scopes ().pop ();
401 return 0;
405 ast_visitor_tmpl_module_inst::visit_home (AST_Home *node)
407 UTL_ScopedName *base_name = nullptr;
408 AST_Decl *parent =
409 this->reify_type (node->base_home ());
411 if (parent != nullptr)
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 = nullptr;
422 AST_Component *managed_comp = dynamic_cast<AST_Component*> (this->reify_type (node->managed_component ()));
424 if (managed_comp != nullptr)
426 managed_comp_name = managed_comp->name ();
429 UTL_ScopedName *p_key_name = nullptr;
431 AST_ValueType *p_key = dynamic_cast<AST_ValueType*> (this->reify_type (node->primary_key ()));
433 if (p_key != nullptr)
435 p_key_name = p_key->name ();
438 Identifier *node_id = nullptr;
439 ACE_NEW_RETURN (node_id,
440 Identifier (node->local_name ()->get_string ()),
441 -1);
443 UTL_ScopedName *local_name = nullptr;
444 ACE_NEW_RETURN (local_name,
445 UTL_ScopedName (node_id, nullptr),
446 -1);
448 FE_HomeHeader header (local_name,
449 base_name,
450 supports_names,
451 managed_comp_name,
452 p_key_name);
454 AST_Home *added_home =
455 idl_global->gen ()->create_home (header.name (),
456 header.base_home (),
457 header.managed_component (),
458 header.primary_key (),
459 header.supports (),
460 header.n_supports (),
461 header.supports_flat (),
462 header.n_supports_flat ());
464 if (supports_names != nullptr)
466 supports_names->destroy ();
467 delete supports_names;
468 supports_names = nullptr;
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")),
482 -1);
485 // Through with this scope.
486 idl_global->scopes ().pop ();
488 return 0;
492 ast_visitor_tmpl_module_inst::visit_structure_fwd (AST_StructureFwd *)
494 return 0;
498 ast_visitor_tmpl_module_inst::visit_exception (AST_Exception *)
500 return 0;
504 ast_visitor_tmpl_module_inst::visit_expression (AST_Expression *)
506 return 0;
510 ast_visitor_tmpl_module_inst::visit_enum (AST_Enum *node)
512 UTL_ScopedName sn (node->local_name (), nullptr);
514 AST_Enum *added_enum =
515 idl_global->gen ()->create_enum (&sn,
516 node->is_local (),
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")),
529 -1);
532 idl_global->scopes ().pop ();
534 return 0;
538 ast_visitor_tmpl_module_inst::visit_union (AST_Union *node)
540 UTL_ScopedName sn (node->local_name (), nullptr);
542 AST_Union *added_union =
543 idl_global->gen ()->create_union (node->disc_type (),
544 &sn,
545 node->is_local (),
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")),
559 -1);
562 // Through with this scope.
563 idl_global->scopes ().pop ();
565 added_union->member_count ();
567 return 0;
571 ast_visitor_tmpl_module_inst::visit_union_fwd (AST_UnionFwd *)
573 return 0;
577 ast_visitor_tmpl_module_inst::visit_union_branch (AST_UnionBranch *node)
579 AST_Type *ft =
580 dynamic_cast<AST_Type*> (
581 this->reify_type (node->field_type ()));
583 UTL_ScopedName sn (node->local_name (), nullptr);
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.
594 AST_Union *u =
595 dynamic_cast<AST_Union*> (idl_global->scopes ().top ());
597 u->fe_add_union_branch (added_branch);
599 return 0;
603 ast_visitor_tmpl_module_inst::visit_union_label (AST_UnionLabel *)
605 return 0;
609 ast_visitor_tmpl_module_inst::visit_enum_val (AST_EnumVal *node)
611 UTL_ScopedName sn (node->local_name (), nullptr);
613 AST_EnumVal *added_enum_val =
614 idl_global->gen ()->create_enum_val (
615 node->constant_value ()->ev ()->u.ulval,
616 &sn);
618 idl_global->scopes ().top ()->add_to_scope (added_enum_val);
620 return 0;
624 ast_visitor_tmpl_module_inst::visit_array (AST_Array *)
626 return 0;
630 ast_visitor_tmpl_module_inst::visit_sequence (AST_Sequence *)
632 return 0;
636 ast_visitor_tmpl_module_inst::visit_map (AST_Map *)
638 return 0;
642 ast_visitor_tmpl_module_inst::visit_string (AST_String *)
644 return 0;
648 ast_visitor_tmpl_module_inst::visit_param_holder (AST_Param_Holder *)
650 return 0;
654 ast_visitor_tmpl_module_inst::visit_root (AST_Root *)
656 return 0;
660 ast_visitor_tmpl_module_inst::visit_native (AST_Native *)
662 return 0;
666 ast_visitor_tmpl_module_inst::visit_module (AST_Module *node)
668 UTL_ScopedName sn (node->local_name (), nullptr);
670 AST_Module *added_module =
671 idl_global->gen ()->create_module (idl_global->scopes ().top (),
672 &sn);
674 added_module->from_inst (this->tmi_);
676 AST_Module *m =
677 dynamic_cast<AST_Module*> (idl_global->scopes ().top ());
679 m->fe_add_module (added_module);
681 idl_global->scopes ().push (added_module);
683 AST_Template_Module_Ref *ref = node->from_ref ();
684 UTL_StrList const *old_refs = idl_global->alias_params ();
686 if (ref != nullptr)
688 added_module->from_ref (ref);
689 idl_global->alias_params (ref->param_refs ());
692 if (this->visit_scope (node) == -1)
694 ACE_ERROR_RETURN ((LM_ERROR,
695 ACE_TEXT ("ast_visitor_tmpl_module_inst::")
696 ACE_TEXT ("visit_module - ")
697 ACE_TEXT ("visit scope failed\n")),
698 -1);
701 // Restore scope stack.
702 idl_global->scopes ().pop ();
704 idl_global->alias_params (const_cast<UTL_StrList *> (old_refs));
706 return 0;
709 // Not called from ast_template_module::accept() but from
710 // visit_template_module_inst() in this visitor.
712 ast_visitor_tmpl_module_inst::visit_template_module (
713 AST_Template_Module *node)
715 this->ctx_->template_params (node->template_params ());
717 if (this->visit_scope (node) == -1)
719 ACE_ERROR_RETURN ((LM_ERROR,
720 ACE_TEXT ("ast_visitor_tmpl_module_inst::")
721 ACE_TEXT ("visit_template_module - ")
722 ACE_TEXT ("visit scope failed\n")),
723 -1);
726 return 0;
730 ast_visitor_tmpl_module_inst::visit_template_module_inst (
731 AST_Template_Module_Inst *node)
733 this->ctx_->template_args (node->template_args ());
734 this->tmi_ = node;
736 AST_Module *instance =
737 idl_global->gen ()->create_module (idl_global->scopes ().top (),
738 node->name ());
740 instance->from_inst (node);
742 // Add the new module to the scope containing the template
743 // module instantiation.
744 AST_Module *m =
745 dynamic_cast<AST_Module*> (idl_global->scopes ().top ());
747 m->fe_add_module (instance);
749 // Update our scope management.
750 idl_global->scopes ().push (instance);
752 AST_Template_Module *tm = node->ref ();
754 if (this->visit_template_module (tm) == -1)
756 ACE_ERROR_RETURN ((LM_ERROR,
757 ACE_TEXT ("ast_visitor_tmpl_module_inst::")
758 ACE_TEXT ("visit_template_module_inst - ")
759 ACE_TEXT ("visit_template_module failed\n")),
760 -1);
763 // By checking this member for a non-zero value, we can tell if
764 // we are processing an instantiated template module or not. We
765 // need to know this, for example while visiting an IDL module,
766 // to decide whether to create an implied IDL module or just
767 // visit its scope.
768 this->ctx_->template_args (nullptr);
770 // Restore the scope stack.
771 idl_global->scopes ().pop ();
773 return 0;
777 ast_visitor_tmpl_module_inst::visit_eventtype (AST_EventType *node)
779 this->for_eventtype_ = true;
780 return this->visit_valuetype (node);
784 ast_visitor_tmpl_module_inst::visit_valuetype (AST_ValueType *node)
786 UTL_NameList *parent_names =
787 this->create_name_list (node->inherits (),
788 node->n_inherits ());
790 UTL_NameList *supports_names =
791 this->create_name_list (node->supports (),
792 node->n_supports ());
794 Identifier *node_id = nullptr;
795 ACE_NEW_RETURN (node_id,
796 Identifier (node->local_name ()->get_string ()),
797 -1);
799 UTL_ScopedName *local_name = nullptr;
800 ACE_NEW_RETURN (local_name,
801 UTL_ScopedName (node_id, nullptr),
802 -1);
804 AST_ValueType *added_vtype = nullptr;
806 FE_OBVHeader header (local_name,
807 parent_names,
808 supports_names,
809 (parent_names != nullptr
810 ? parent_names->truncatable ()
811 : false),
812 this->for_eventtype_);
814 if (this->for_eventtype_)
816 added_vtype =
817 idl_global->gen ()->create_eventtype (header.name (),
818 header.inherits (),
819 header.n_inherits (),
820 header.inherits_concrete (),
821 header.inherits_flat (),
822 header.n_inherits_flat (),
823 header.supports (),
824 header.n_supports (),
825 header.supports_concrete (),
826 false,
827 header.truncatable (),
828 false);
830 else
832 added_vtype =
833 idl_global->gen ()->create_valuetype (header.name (),
834 header.inherits (),
835 header.n_inherits (),
836 header.inherits_concrete (),
837 header.inherits_flat (),
838 header.n_inherits_flat (),
839 header.supports (),
840 header.n_supports (),
841 header.supports_concrete (),
842 false,
843 header.truncatable (),
844 false);
847 if (parent_names != nullptr)
849 parent_names->destroy ();
850 delete parent_names;
851 parent_names = nullptr;
854 if (supports_names != nullptr)
856 supports_names->destroy ();
857 delete supports_names;
858 supports_names = nullptr;
861 idl_global->scopes ().top ()->add_to_scope (added_vtype);
863 // Update the scope management.
864 idl_global->scopes ().push (added_vtype);
866 if (this->visit_scope (node) != 0)
868 ACE_ERROR_RETURN ((LM_ERROR,
869 ACE_TEXT ("ast_visitor_tmpl_module_inst::")
870 ACE_TEXT ("visit_valuetype - ")
871 ACE_TEXT ("visit_scope failed\n")),
872 -1);
875 // Through with this scope.
876 idl_global->scopes ().pop ();
878 // Reset the flag.
879 this->for_eventtype_ = false;
881 return 0;
885 ast_visitor_tmpl_module_inst::visit_interface (AST_Interface *node)
887 UTL_NameList *parent_names =
888 this->create_name_list (node->inherits (),
889 node->n_inherits ());
891 Identifier *node_id = nullptr;
892 ACE_NEW_RETURN (node_id,
893 Identifier (node->local_name ()->get_string ()),
894 -1);
896 UTL_ScopedName *local_name = nullptr;
897 ACE_NEW_RETURN (local_name,
898 UTL_ScopedName (node_id, nullptr),
899 -1);
901 FE_InterfaceHeader header (local_name,
902 parent_names,
903 node->is_local (),
904 node->is_abstract (),
905 true);
907 AST_Interface *added_iface =
908 idl_global->gen ()->create_interface (header.name (),
909 header.inherits (),
910 header.n_inherits (),
911 header.inherits_flat (),
912 header.n_inherits_flat (),
913 header.is_local (),
914 header.is_abstract ());
916 if (parent_names != nullptr)
918 parent_names->destroy ();
919 delete parent_names;
920 parent_names = nullptr;
923 idl_global->scopes ().top ()->add_to_scope (added_iface);
925 // If this interface has both abstract and concrete parents,
926 // extra code needs to be generated for it, such as overrides
927 // of _is_nil() and release().
928 added_iface->analyze_parentage ();
930 // Update the scope stack.
931 idl_global->scopes ().push (added_iface);
933 if (this->visit_scope (node) != 0)
935 ACE_ERROR_RETURN ((LM_ERROR,
936 ACE_TEXT ("ast_visitor_tmpl_module_inst::")
937 ACE_TEXT ("visit_interface - ")
938 ACE_TEXT ("visit_scope failed\n")),
939 -1);
942 // Through with this scope.
943 idl_global->scopes ().pop ();
945 return 0;
949 ast_visitor_tmpl_module_inst::visit_attribute (AST_Attribute *node)
951 AST_Type *ft =
952 dynamic_cast<AST_Type*> (
953 this->reify_type (node->field_type ()));
955 AST_Attribute *added_attr =
956 idl_global->gen ()->create_attribute (node->readonly (),
958 node->name (),
959 node->is_local (),
960 node->is_abstract ());
962 idl_global->scopes ().top ()->add_to_scope (added_attr);
964 // These will work even if the exception lists are null.
966 UTL_ExceptList *old_ex = node->get_get_exceptions ();
967 UTL_ExceptList *new_ex = this->reify_exception_list (old_ex);
968 added_attr->be_add_get_exceptions (new_ex);
970 old_ex = node->get_set_exceptions ();
971 new_ex = this->reify_exception_list (old_ex);
972 added_attr->be_add_set_exceptions (new_ex);
974 return 0;
978 ast_visitor_tmpl_module_inst::visit_operation (AST_Operation *node)
980 AST_Type *rt =
981 dynamic_cast<AST_Type*> (
982 this->reify_type (node->return_type ()));
984 Identifier id (node->local_name ()->get_string ());
985 UTL_ScopedName sn (&id, nullptr);
987 AST_Operation *added_op =
988 idl_global->gen ()->create_operation (rt,
989 node->flags (),
990 &sn,
991 node->is_local (),
992 node->is_abstract ());
994 idl_global->scopes ().top ()->add_to_scope (added_op);
996 // Update the scope stack.
997 idl_global->scopes ().push (added_op);
999 if (this->visit_scope (node) != 0)
1001 ACE_ERROR_RETURN ((LM_ERROR,
1002 ACE_TEXT ("ast_visitor_tmpl_module_inst::")
1003 ACE_TEXT ("visit_operation - ")
1004 ACE_TEXT ("visit_scope failed\n")),
1005 -1);
1008 // Through with this scope.
1009 idl_global->scopes ().pop ();
1011 UTL_ExceptList *new_ex =
1012 this->reify_exception_list (node->exceptions ());
1014 added_op->be_add_exceptions (new_ex);
1016 return 0;
1020 ast_visitor_tmpl_module_inst::visit_argument (AST_Argument *node)
1022 AST_Type *t =
1023 dynamic_cast<AST_Type*> (
1024 this->reify_type (node->field_type ()));
1026 if (t == nullptr)
1028 ACE_ERROR_RETURN ((LM_ERROR,
1029 ACE_TEXT ("ast_visitor_tmpl_module_inst::")
1030 ACE_TEXT ("visit_argument - ")
1031 ACE_TEXT ("reify_type failed\n")),
1032 -1);
1035 AST_Argument *added_arg =
1036 idl_global->gen ()->create_argument (node->direction (),
1038 node->name ());
1040 idl_global->scopes ().top ()->add_to_scope (added_arg);
1042 return 0;
1046 ast_visitor_tmpl_module_inst::visit_typedef (AST_Typedef *node)
1048 AST_Type *bt =
1049 dynamic_cast<AST_Type*> (
1050 this->reify_type (node->base_type ()));
1052 UTL_ScopedName sn (node->local_name (), nullptr);
1054 AST_Typedef *added_td =
1055 idl_global->gen ()->create_typedef (bt,
1056 &sn,
1057 false,
1058 false);
1060 idl_global->scopes ().top ()->add_to_scope (added_td);
1062 return 0;
1066 ast_visitor_tmpl_module_inst::visit_constant (AST_Constant *node)
1068 AST_Param_Holder *ph =
1069 node->constant_value ()->param_holder ();
1071 AST_Expression *v = nullptr;
1072 AST_Expression::ExprType et = node->et ();
1074 if (ph != nullptr)
1076 ast_visitor_reifying rv (this->ctx_);
1078 if (rv.visit_param_holder (ph) != 0)
1080 ACE_ERROR_RETURN ((LM_ERROR,
1081 ACE_TEXT ("ast_visitor_tmpl_module_inst::")
1082 ACE_TEXT ("visit_constant - ")
1083 ACE_TEXT ("reification of param ")
1084 ACE_TEXT ("holder failed\n")),
1085 -1);
1088 AST_Constant *c =
1089 dynamic_cast<AST_Constant*> (rv.reified_node ());
1091 /// We don't use the reified node's ExprType here, since
1092 /// it was created from a template arg that (for const
1093 /// type template args) was a literal. The arg name was
1094 /// matched with a template param list to check correctness,
1095 /// but not the type. Thus an integer literal, for example,
1096 /// will be a 64-bit type usually, but what we want is
1097 /// the type of the constant we are visiting. When the
1098 /// new expression and constant are created below, things
1099 /// will be coerced to the ExprType passed in, and if
1100 /// there is a mismatch, we'll get an error at that point.
1101 v = c->constant_value ();
1103 else
1105 v = node->constant_value ();
1108 AST_Expression *new_v =
1109 idl_global->gen ()->create_expr (v, et);
1111 AST_Constant *added_const =
1112 idl_global->gen ()->create_constant (et,
1113 new_v,
1114 node->name ());
1116 idl_global->scopes ().top ()->add_to_scope (added_const);
1118 return 0;
1122 ast_visitor_tmpl_module_inst::visit_structure (AST_Structure *node)
1124 UTL_ScopedName sn (node->name ()->last_component (), nullptr);
1126 AST_Structure *added_struct =
1127 idl_global->gen ()->create_structure (&sn,
1128 node->is_local (),
1129 node->is_abstract ());
1131 idl_global->scopes ().top ()->add_to_scope (added_struct);
1133 // Update our scope stack.
1134 idl_global->scopes ().push (added_struct);
1136 if (this->visit_scope (node) != 0)
1138 ACE_ERROR_RETURN ((LM_ERROR,
1139 ACE_TEXT ("ast_visitor_tmpl_module_inst::")
1140 ACE_TEXT ("visit_structure - ")
1141 ACE_TEXT ("visit_scope() failed\n")),
1142 -1);
1145 // Through with this scope.
1146 idl_global->scopes ().pop ();
1148 return 0;
1152 ast_visitor_tmpl_module_inst::visit_field (AST_Field *node)
1154 AST_Type *t =
1155 dynamic_cast<AST_Type*> (
1156 this->reify_type (node->field_type ()));
1158 AST_Field *added_field =
1159 idl_global->gen ()->create_field (t,
1160 node->name (),
1161 node->visibility ());
1163 idl_global->scopes ().top ()->add_to_scope (added_field);
1165 return 0;
1169 ast_visitor_tmpl_module_inst::visit_factory (AST_Factory *node)
1171 Identifier id (node->local_name ()->get_string ());
1172 UTL_ScopedName sn (&id, nullptr);
1174 AST_Factory *added_factory = nullptr;
1176 if (this->for_finder_)
1178 added_factory =
1179 idl_global->gen ()->create_finder (&sn);
1181 else
1183 added_factory =
1184 idl_global->gen ()->create_factory (&sn);
1187 idl_global->scopes ().top ()->add_to_scope (added_factory);
1189 // Update the scope stack.
1190 idl_global->scopes ().push (added_factory);
1192 if (this->visit_scope (node) != 0)
1194 ACE_ERROR_RETURN ((LM_ERROR,
1195 ACE_TEXT ("ast_visitor_tmpl_module_inst::")
1196 ACE_TEXT ("visit_factory - ")
1197 ACE_TEXT ("visit_scope() failed\n")),
1198 -1);
1201 // Through with this scope.
1202 idl_global->scopes ().pop ();
1204 UTL_ExceptList *reified_exceps =
1205 this->reify_exception_list (node->exceptions ());
1207 added_factory->be_add_exceptions (reified_exceps);
1209 // In case it was set for this call.
1210 this->for_finder_ = false;
1212 return 0;
1216 ast_visitor_tmpl_module_inst::visit_finder (AST_Finder *node)
1218 this->for_finder_ = true;
1219 return this->visit_factory (node);
1222 AST_Decl *
1223 ast_visitor_tmpl_module_inst::reify_type (AST_Decl *d)
1225 if (d == nullptr)
1227 return nullptr;
1230 if (this->ref_only_)
1232 // If d is a param holder, the lookup will return a heap
1233 // allocation, which we need since this node's destination
1234 // owns param holders.
1235 if (d->node_type () == AST_Decl::NT_param_holder)
1237 return
1238 idl_global->scopes ().top ()->lookup_by_name (
1239 d->name (),
1240 true);
1242 else
1244 return d;
1248 ast_visitor_reifying rv (this->ctx_);
1250 if (d->ast_accept (&rv) != 0)
1252 ACE_ERROR ((LM_ERROR,
1253 ACE_TEXT ("ast_visitor_tmpl_module_inst::")
1254 ACE_TEXT ("reify_type() - reifying ")
1255 ACE_TEXT ("visitor failed on %C\n"),
1256 d->full_name ()));
1258 return nullptr;
1261 return rv.reified_node ();
1264 UTL_ExceptList *
1265 ast_visitor_tmpl_module_inst::reify_exception_list (
1266 UTL_ExceptList *orig)
1268 if (orig == nullptr)
1270 return nullptr;
1273 UTL_ExceptList *retval = nullptr;
1275 for (UTL_ExceptlistActiveIterator i (orig);
1276 !i.is_done ();
1277 i.next ())
1279 AST_Type *ex =
1280 dynamic_cast<AST_Type*> (this->reify_type (i.item ()));
1282 UTL_ExceptList *ex_list = nullptr;
1283 ACE_NEW_RETURN (ex_list,
1284 UTL_ExceptList (ex, nullptr),
1285 nullptr);
1287 if (retval == nullptr)
1289 retval = ex_list;
1291 else
1293 retval->nconc (ex_list);
1297 return retval;
1300 UTL_NameList *
1301 ast_visitor_tmpl_module_inst::create_name_list (AST_Type **list,
1302 long length)
1304 UTL_NameList *retval = nullptr;
1306 for (long i = 0; i < length; ++i)
1308 AST_Type *item =
1309 dynamic_cast<AST_Type*> (this->reify_type (list[i]));
1311 // We copy each name added so we can call destroy() on the
1312 // list, which disposes of the contents as well as the
1313 // nested tail pointers.
1314 UTL_NameList *name_item = nullptr;
1315 ACE_NEW_RETURN (name_item,
1316 UTL_NameList (item->name ()->copy (), nullptr),
1317 nullptr);
1319 if (retval == nullptr)
1321 retval = name_item;
1323 else
1325 retval->nconc (name_item);
1329 return retval;