Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / TAO_IDL / ast / ast_visitor_tmpl_module_inst.cpp
blobe2ffabd23912935538a12be76845827041ad8656
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_ (0),
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 (void)
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 == 0)
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 == 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")),
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 = 0;
140 AST_Decl *parent =
141 this->reify_type (node->base_component ());
143 if (parent != 0)
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 ()),
155 -1);
157 UTL_ScopedName *local_name = 0;
158 ACE_NEW_RETURN (local_name,
159 UTL_ScopedName (node_id, 0),
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 != 0)
177 supports_names->destroy ();
178 delete supports_names;
179 supports_names = 0;
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 (), 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")),
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 (), 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,
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 (), 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,
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 (), 0);
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 (), 0);
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 (), 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);
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 (), 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);
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 (), 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);
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 (), 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")),
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 = 0;
408 AST_Decl *parent =
409 this->reify_type (node->base_home ());
411 if (parent != 0)
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 ()));
433 if (p_key != 0)
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 ()),
441 -1);
443 UTL_ScopedName *local_name = 0;
444 ACE_NEW_RETURN (local_name,
445 UTL_ScopedName (node_id, 0),
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 != 0)
466 supports_names->destroy ();
467 delete supports_names;
468 supports_names = 0;
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 (), 0);
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 (), 0);
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 (), 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.
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 (), 0);
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_string (AST_String *)
638 return 0;
642 ast_visitor_tmpl_module_inst::visit_param_holder (AST_Param_Holder *)
644 return 0;
648 ast_visitor_tmpl_module_inst::visit_root (AST_Root *)
650 return 0;
654 ast_visitor_tmpl_module_inst::visit_native (AST_Native *)
656 return 0;
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 (),
666 &sn);
668 added_module->from_inst (this->tmi_);
670 AST_Module *m =
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 ();
680 if (ref != 0)
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")),
692 -1);
695 // Restore scope stack.
696 idl_global->scopes ().pop ();
698 idl_global->alias_params (const_cast<UTL_StrList *> (old_refs));
700 return 0;
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")),
717 -1);
720 return 0;
724 ast_visitor_tmpl_module_inst::visit_template_module_inst (
725 AST_Template_Module_Inst *node)
727 this->ctx_->template_args (node->template_args ());
728 this->tmi_ = node;
730 AST_Module *instance =
731 idl_global->gen ()->create_module (idl_global->scopes ().top (),
732 node->name ());
734 instance->from_inst (node);
736 // Add the new module to the scope containing the template
737 // module instantiation.
738 AST_Module *m =
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")),
754 -1);
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
761 // visit its scope.
762 this->ctx_->template_args (0);
764 // Restore the scope stack.
765 idl_global->scopes ().pop ();
767 return 0;
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 ()),
791 -1);
793 UTL_ScopedName *local_name = 0;
794 ACE_NEW_RETURN (local_name,
795 UTL_ScopedName (node_id, 0),
796 -1);
798 AST_ValueType *added_vtype = 0;
800 FE_OBVHeader header (local_name,
801 parent_names,
802 supports_names,
803 (parent_names != 0
804 ? parent_names->truncatable ()
805 : false),
806 this->for_eventtype_);
808 if (this->for_eventtype_)
810 added_vtype =
811 idl_global->gen ()->create_eventtype (header.name (),
812 header.inherits (),
813 header.n_inherits (),
814 header.inherits_concrete (),
815 header.inherits_flat (),
816 header.n_inherits_flat (),
817 header.supports (),
818 header.n_supports (),
819 header.supports_concrete (),
820 false,
821 header.truncatable (),
822 false);
824 else
826 added_vtype =
827 idl_global->gen ()->create_valuetype (header.name (),
828 header.inherits (),
829 header.n_inherits (),
830 header.inherits_concrete (),
831 header.inherits_flat (),
832 header.n_inherits_flat (),
833 header.supports (),
834 header.n_supports (),
835 header.supports_concrete (),
836 false,
837 header.truncatable (),
838 false);
841 if (parent_names != 0)
843 parent_names->destroy ();
844 delete parent_names;
845 parent_names = 0;
848 if (supports_names != 0)
850 supports_names->destroy ();
851 delete supports_names;
852 supports_names = 0;
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")),
866 -1);
869 // Through with this scope.
870 idl_global->scopes ().pop ();
872 // Reset the flag.
873 this->for_eventtype_ = false;
875 return 0;
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 ()),
888 -1);
890 UTL_ScopedName *local_name = 0;
891 ACE_NEW_RETURN (local_name,
892 UTL_ScopedName (node_id, 0),
893 -1);
895 FE_InterfaceHeader header (local_name,
896 parent_names,
897 node->is_local (),
898 node->is_abstract (),
899 true);
901 AST_Interface *added_iface =
902 idl_global->gen ()->create_interface (header.name (),
903 header.inherits (),
904 header.n_inherits (),
905 header.inherits_flat (),
906 header.n_inherits_flat (),
907 header.is_local (),
908 header.is_abstract ());
910 if (parent_names != 0)
912 parent_names->destroy ();
913 delete parent_names;
914 parent_names = 0;
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")),
933 -1);
936 // Through with this scope.
937 idl_global->scopes ().pop ();
939 return 0;
943 ast_visitor_tmpl_module_inst::visit_attribute (AST_Attribute *node)
945 AST_Type *ft =
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 (),
952 node->name (),
953 node->is_local (),
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);
968 return 0;
972 ast_visitor_tmpl_module_inst::visit_operation (AST_Operation *node)
974 AST_Type *rt =
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,
983 node->flags (),
984 &sn,
985 node->is_local (),
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")),
999 -1);
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);
1010 return 0;
1014 ast_visitor_tmpl_module_inst::visit_argument (AST_Argument *node)
1016 AST_Type *t =
1017 dynamic_cast<AST_Type*> (
1018 this->reify_type (node->field_type ()));
1020 if (t == 0)
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")),
1026 -1);
1029 AST_Argument *added_arg =
1030 idl_global->gen ()->create_argument (node->direction (),
1032 node->name ());
1034 idl_global->scopes ().top ()->add_to_scope (added_arg);
1036 return 0;
1040 ast_visitor_tmpl_module_inst::visit_typedef (AST_Typedef *node)
1042 AST_Type *bt =
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,
1050 &sn,
1051 false,
1052 false);
1054 idl_global->scopes ().top ()->add_to_scope (added_td);
1056 return 0;
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 ();
1068 if (ph != 0)
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")),
1079 -1);
1082 AST_Constant *c =
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 ();
1097 else
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,
1107 new_v,
1108 node->name ());
1110 idl_global->scopes ().top ()->add_to_scope (added_const);
1112 return 0;
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,
1122 node->is_local (),
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")),
1136 -1);
1139 // Through with this scope.
1140 idl_global->scopes ().pop ();
1142 return 0;
1146 ast_visitor_tmpl_module_inst::visit_field (AST_Field *node)
1148 AST_Type *t =
1149 dynamic_cast<AST_Type*> (
1150 this->reify_type (node->field_type ()));
1152 AST_Field *added_field =
1153 idl_global->gen ()->create_field (t,
1154 node->name (),
1155 node->visibility ());
1157 idl_global->scopes ().top ()->add_to_scope (added_field);
1159 return 0;
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_)
1172 added_factory =
1173 idl_global->gen ()->create_finder (&sn);
1175 else
1177 added_factory =
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")),
1192 -1);
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;
1206 return 0;
1210 ast_visitor_tmpl_module_inst::visit_finder (AST_Finder *node)
1212 this->for_finder_ = true;
1213 return this->visit_factory (node);
1216 AST_Decl *
1217 ast_visitor_tmpl_module_inst::reify_type (AST_Decl *d)
1219 if (d == 0)
1221 return 0;
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)
1231 return
1232 idl_global->scopes ().top ()->lookup_by_name (
1233 d->name (),
1234 true);
1236 else
1238 return d;
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"),
1250 d->full_name ()));
1252 return 0;
1255 return rv.reified_node ();
1258 UTL_ExceptList *
1259 ast_visitor_tmpl_module_inst::reify_exception_list (
1260 UTL_ExceptList *orig)
1262 if (orig == 0)
1264 return 0;
1267 UTL_ExceptList *retval = 0;
1269 for (UTL_ExceptlistActiveIterator i (orig);
1270 !i.is_done ();
1271 i.next ())
1273 AST_Type *ex =
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),
1281 if (retval == 0)
1283 retval = ex_list;
1285 else
1287 retval->nconc (ex_list);
1291 return retval;
1294 UTL_NameList *
1295 ast_visitor_tmpl_module_inst::create_name_list (AST_Type **list,
1296 long length)
1298 UTL_NameList *retval = 0;
1300 for (long i = 0; i < length; ++i)
1302 AST_Type *item =
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),
1313 if (retval == 0)
1315 retval = name_item;
1317 else
1319 retval->nconc (name_item);
1323 return retval;