2 //=============================================================================
6 * Visitor generating code for Interfaces. This is a generic visitor.
8 * @author Aniruddha Gokhale
10 //=============================================================================
12 #include "interface.h"
14 be_visitor_interface::be_visitor_interface (be_visitor_context
*ctx
)
15 : be_visitor_scope (ctx
)
19 be_visitor_interface::~be_visitor_interface ()
23 // This method must be overridden by the derived interface visitors.
25 be_visitor_interface::visit_interface (be_interface
*)
31 be_visitor_interface::visit_scope (be_scope
*node
)
33 if (this->be_visitor_scope::visit_scope (node
) == -1)
38 be_interface
*intf
= dynamic_cast<be_interface
*> (node
);
45 if (intf
->is_abstract ())
50 if (! intf
->has_mixed_parentage ())
55 be_interface::tao_code_emitter helper
= nullptr;
57 switch (this->ctx_
->state ())
59 case TAO_CodeGen::TAO_INTERFACE_CH
:
61 be_visitor_interface_ch::gen_abstract_ops_helper
;
63 case TAO_CodeGen::TAO_ROOT_CS
:
65 be_visitor_interface_cs::gen_abstract_ops_helper
;
67 case TAO_CodeGen::TAO_ROOT_SH
:
69 be_visitor_interface_sh::gen_abstract_ops_helper
;
71 case TAO_CodeGen::TAO_INTERFACE_DIRECT_PROXY_IMPL_SH
:
73 be_visitor_interface_direct_proxy_impl_sh::gen_abstract_ops_helper
;
75 case TAO_CodeGen::TAO_ROOT_SS
:
77 be_visitor_interface_ss::gen_abstract_ops_helper
;
79 case TAO_CodeGen::TAO_INTERFACE_DIRECT_PROXY_IMPL_SS
:
81 be_visitor_interface_direct_proxy_impl_ss::gen_abstract_ops_helper
;
87 if (helper
== nullptr)
92 // 'abstract_paths_only' arg is FALSE here because we want to traverse
93 // through concrete parents to get to all the abstract ones. The helper
94 // will do nothing unless the base interface passed to it is abstract.
96 intf
->traverse_inheritance_graph (helper
,
97 this->ctx_
->stream (),
102 ACE_ERROR_RETURN ((LM_ERROR
,
103 "be_visitor_interface_*::"
105 "traversal of inheritance graph failed\n"),
113 be_visitor_interface::is_amh_rh_node (be_interface
*node
)
116 if (node
->original_interface () != nullptr)
118 // and the name starts with AMH
119 if (ACE_OS::strncmp (node
->local_name (), "AMH", 3) == 0)
121 // then it is an AMH node.
130 be_visitor_interface::add_abstract_op_args (AST_Operation
*old_op
,
131 be_operation
&new_op
)
133 AST_Decl
*d
= nullptr;
135 for (UTL_ScopeActiveIterator
si (old_op
, UTL_Scope::IK_decls
);
140 new_op
.add_to_scope (d
);
143 UTL_ExceptList
*excep_list
= old_op
->exceptions ();
145 if (nullptr != excep_list
)
147 new_op
.be_add_exceptions (excep_list
->copy ());
151 // All common visit methods for interface visitor.
154 be_visitor_interface::visit_attribute (be_attribute
*node
)
156 // Instantiate a visitor context with a copy of our context. This info
157 // will be modified based on what type of node we are visiting.
158 be_visitor_context
ctx (*this->ctx_
);
161 // Same visitor for all the above cases where an action is taken.
162 be_visitor_attribute
visitor (&ctx
);
164 if (node
->accept (&visitor
) == -1)
166 ACE_ERROR_RETURN ((LM_ERROR
,
167 "(%N:%l) be_visitor_interface::"
169 "failed to accept visitor\n"),
177 be_visitor_interface::visit_constant (be_constant
*node
)
179 // Instantiate a visitor context with a copy of our context. This info
180 // will be modified based on what type of node we are visiting
181 be_visitor_context
ctx (*this->ctx_
);
185 switch (this->ctx_
->state ())
187 case TAO_CodeGen::TAO_INTERFACE_CH
:
189 be_visitor_constant_ch
visitor (&ctx
);
190 status
= node
->accept (&visitor
);
193 case TAO_CodeGen::TAO_ROOT_CS
:
195 be_visitor_constant_cs
visitor (&ctx
);
196 status
= node
->accept (&visitor
);
200 return 0; // nothing to be done
205 ACE_ERROR_RETURN ((LM_ERROR
,
206 "(%N:%l) be_visitor_interface::"
208 "failed to accept visitor\n"),
216 be_visitor_interface::visit_native (be_native
*node
)
218 // Instantiate a visitor context with a copy of our context. This info
219 // will be modified based on what type of node we are visiting
220 be_visitor_context
ctx (*this->ctx_
);
224 switch (this->ctx_
->state ())
226 case TAO_CodeGen::TAO_INTERFACE_CH
:
228 be_visitor_native_ch
visitor (&ctx
);
229 status
= node
->accept (&visitor
);
233 return 0; // nothing to be done
238 ACE_ERROR_RETURN ((LM_ERROR
,
239 "(%N:%l) be_visitor_interface::"
241 "failed to accept visitor\n"),
249 be_visitor_interface::visit_enum (be_enum
*node
)
251 // Instantiate a visitor context with a copy of our context. This info
252 // will be modified based on what type of node we are visiting
253 be_visitor_context
ctx (*this->ctx_
);
257 switch (this->ctx_
->state ())
259 case TAO_CodeGen::TAO_INTERFACE_CH
:
261 be_visitor_enum_ch
visitor (&ctx
);
262 status
= node
->accept (&visitor
);
265 case TAO_CodeGen::TAO_ROOT_CS
:
267 be_visitor_enum_cs
visitor (&ctx
);
268 status
= node
->accept (&visitor
);
271 case TAO_CodeGen::TAO_ROOT_ANY_OP_CH
:
273 be_visitor_enum_any_op_ch
visitor (&ctx
);
274 status
= node
->accept (&visitor
);
277 case TAO_CodeGen::TAO_ROOT_ANY_OP_CS
:
279 be_visitor_enum_any_op_cs
visitor (&ctx
);
280 status
= node
->accept (&visitor
);
283 case TAO_CodeGen::TAO_ROOT_CDR_OP_CH
:
285 be_visitor_enum_cdr_op_ch
visitor (&ctx
);
286 status
= node
->accept (&visitor
);
289 case TAO_CodeGen::TAO_ROOT_CDR_OP_CS
:
291 be_visitor_enum_cdr_op_cs
visitor (&ctx
);
292 status
= node
->accept (&visitor
);
296 return 0; // nothing to be done
301 ACE_ERROR_RETURN ((LM_ERROR
,
302 "(%N:%l) be_visitor_interface::"
304 "failed to accept visitor\n"),
311 // visit an exception
313 be_visitor_interface::visit_exception (be_exception
*node
)
315 // Instantiate a visitor context with a copy of our context. This info
316 // will be modified based on what type of node we are visiting.
317 be_visitor_context
ctx (*this->ctx_
);
321 switch (this->ctx_
->state ())
323 case TAO_CodeGen::TAO_INTERFACE_CH
:
325 be_visitor_exception_ch
visitor (&ctx
);
326 status
= node
->accept (&visitor
);
329 case TAO_CodeGen::TAO_ROOT_CI
:
331 be_visitor_exception_ci
visitor (&ctx
);
332 status
= node
->accept (&visitor
);
335 case TAO_CodeGen::TAO_ROOT_CS
:
337 be_visitor_exception_cs
visitor (&ctx
);
338 status
= node
->accept (&visitor
);
341 case TAO_CodeGen::TAO_ROOT_ANY_OP_CH
:
343 be_visitor_exception_any_op_ch
visitor (&ctx
);
344 status
= node
->accept (&visitor
);
347 case TAO_CodeGen::TAO_ROOT_ANY_OP_CS
:
349 be_visitor_exception_any_op_cs
visitor (&ctx
);
350 status
= node
->accept (&visitor
);
353 case TAO_CodeGen::TAO_ROOT_CDR_OP_CH
:
355 be_visitor_exception_cdr_op_ch
visitor (&ctx
);
356 status
= node
->accept (&visitor
);
359 case TAO_CodeGen::TAO_ROOT_CDR_OP_CS
:
361 be_visitor_exception_cdr_op_cs
visitor (&ctx
);
362 status
= node
->accept (&visitor
);
366 return 0; // nothing to be done
371 ACE_ERROR_RETURN ((LM_ERROR
,
372 "(%N:%l) be_visitor_interface::"
374 "failed to accept visitor\n"),
381 // visit an operation
383 be_visitor_interface::visit_operation (be_operation
*node
)
385 // Instantiate a visitor context with a copy of our context. This info
386 // will be modified ased on what type of node we are visiting
387 be_visitor_context
ctx (*this->ctx_
);
391 switch (this->ctx_
->state ())
393 // These first two cases may have the context state changed
394 // by a strategy, so we use the visitor factory below.
395 case TAO_CodeGen::TAO_INTERFACE_CH
:
397 ctx
.state (TAO_CodeGen::TAO_OPERATION_CH
);
398 be_visitor_operation_ch
visitor (&ctx
);
399 status
= node
->accept (&visitor
);
402 case TAO_CodeGen::TAO_ROOT_CS
:
403 ctx
.state (TAO_CodeGen::TAO_OPERATION_CS
);
405 if (node
->is_sendc_ami ())
407 be_visitor_operation_ami_cs
visitor (&ctx
);
408 status
= node
->accept (&visitor
);
412 be_visitor_operation_cs
visitor (&ctx
);
413 status
= node
->accept (&visitor
);
417 case TAO_CodeGen::TAO_ROOT_SH
:
419 be_visitor_operation_sh
visitor (&ctx
);
420 status
= node
->accept (&visitor
);
423 case TAO_CodeGen::TAO_ROOT_EXH
:
424 case TAO_CodeGen::TAO_ROOT_IH
:
426 be_visitor_operation_ih
visitor (&ctx
);
427 status
= node
->accept (&visitor
);
430 case TAO_CodeGen::TAO_ROOT_SS
:
432 be_visitor_operation_ss
visitor (&ctx
);
433 status
= node
->accept (&visitor
);
436 case TAO_CodeGen::TAO_ROOT_IS
:
438 be_visitor_operation_is
visitor (&ctx
);
439 status
= node
->accept (&visitor
);
442 case TAO_CodeGen::TAO_ROOT_TIE_SH
:
444 be_visitor_operation_tie_sh
visitor (&ctx
);
445 status
= node
->accept (&visitor
);
448 case TAO_CodeGen::TAO_ROOT_TIE_SS
:
450 be_visitor_operation_tie_ss
visitor (&ctx
);
451 status
= node
->accept (&visitor
);
454 case TAO_CodeGen::TAO_INTERFACE_SMART_PROXY_CH
:
456 be_visitor_operation_smart_proxy_ch
visitor (&ctx
);
457 status
= node
->accept (&visitor
);
460 case TAO_CodeGen::TAO_INTERFACE_SMART_PROXY_CS
:
462 be_visitor_operation_smart_proxy_cs
visitor (&ctx
);
463 status
= node
->accept (&visitor
);
466 case TAO_CodeGen::TAO_INTERFACE_DIRECT_PROXY_IMPL_SH
:
468 be_visitor_operation_proxy_impl_xh
visitor (&ctx
);
469 status
= node
->accept (&visitor
);
472 case TAO_CodeGen::TAO_INTERFACE_AMH_RH_SH
:
474 be_visitor_amh_rh_operation_sh
visitor (&ctx
);
475 status
= node
->accept (&visitor
);
478 case TAO_CodeGen::TAO_INTERFACE_AMH_RH_SS
:
480 be_visitor_amh_rh_operation_ss
visitor (&ctx
);
481 status
= node
->accept (&visitor
);
484 case TAO_CodeGen::TAO_INTERFACE_DIRECT_PROXY_IMPL_SS
:
486 be_visitor_operation_direct_proxy_impl_ss
visitor (&ctx
);
487 status
= node
->accept (&visitor
);
490 case TAO_CodeGen::TAO_ROOT_ANY_OP_CH
:
491 case TAO_CodeGen::TAO_ROOT_ANY_OP_CS
:
492 case TAO_CodeGen::TAO_ROOT_CDR_OP_CH
:
493 case TAO_CodeGen::TAO_ROOT_CDR_OP_CS
:
494 case TAO_CodeGen::TAO_ROOT_CI
:
495 return 0; // nothing to be done
498 ACE_ERROR_RETURN ((LM_ERROR
,
499 "(%N:%l) be_visitor_interface::"
501 "Bad context state\n"),
510 else if (status
== -1)
512 ACE_ERROR_RETURN ((LM_ERROR
,
513 "(%N:%l) be_visitor_interface::"
515 "failed to accept visitor\n"),
523 be_visitor_interface::visit_structure (be_structure
*node
)
525 // Instantiate a visitor context with a copy of our context. This info
526 // will be modified based on what type of node we are visiting.
527 be_visitor_context
ctx (*this->ctx_
);
531 switch (this->ctx_
->state ())
533 case TAO_CodeGen::TAO_INTERFACE_CH
:
535 be_visitor_structure_ch
visitor (&ctx
);
536 status
= node
->accept (&visitor
);
539 case TAO_CodeGen::TAO_ROOT_CI
:
541 be_visitor_structure_ci
visitor (&ctx
);
542 status
= node
->accept (&visitor
);
545 case TAO_CodeGen::TAO_ROOT_CS
:
547 be_visitor_structure_cs
visitor (&ctx
);
548 status
= node
->accept (&visitor
);
551 case TAO_CodeGen::TAO_ROOT_ANY_OP_CH
:
553 be_visitor_structure_any_op_ch
visitor (&ctx
);
554 status
= node
->accept (&visitor
);
557 case TAO_CodeGen::TAO_ROOT_ANY_OP_CS
:
559 be_visitor_structure_any_op_cs
visitor (&ctx
);
560 status
= node
->accept (&visitor
);
563 case TAO_CodeGen::TAO_ROOT_CDR_OP_CH
:
565 be_visitor_structure_cdr_op_ch
visitor (&ctx
);
566 status
= node
->accept (&visitor
);
569 case TAO_CodeGen::TAO_ROOT_CDR_OP_CS
:
571 be_visitor_structure_cdr_op_cs
visitor (&ctx
);
572 status
= node
->accept (&visitor
);
576 return 0; // nothing to be done
581 ACE_ERROR_RETURN ((LM_ERROR
,
582 "(%N:%l) be_visitor_interface::"
584 "failed to accept visitor\n"),
592 be_visitor_interface::visit_structure_fwd (be_structure_fwd
*node
)
594 // Instantiate a visitor context with a copy of our context. This info
595 // will be modified based on what type of node we are visiting.
596 be_visitor_context
ctx (*this->ctx_
);
600 switch (this->ctx_
->state ())
602 case TAO_CodeGen::TAO_INTERFACE_CH
:
604 be_visitor_structure_fwd_ch
visitor (&ctx
);
605 status
= node
->accept (&visitor
);
609 return 0; // nothing to be done
614 ACE_ERROR_RETURN ((LM_ERROR
,
615 "(%N:%l) be_visitor_interface::"
616 "visit_structure_fwd - "
617 "failed to accept visitor\n"),
625 be_visitor_interface::visit_union (be_union
*node
)
627 // Instantiate a visitor context with a copy of our context. This info
628 // will be modified based on what type of node we are visiting.
629 be_visitor_context
ctx (*this->ctx_
);
633 switch (this->ctx_
->state ())
635 case TAO_CodeGen::TAO_INTERFACE_CH
:
637 be_visitor_union_ch
visitor (&ctx
);
638 status
= node
->accept (&visitor
);
641 case TAO_CodeGen::TAO_ROOT_CI
:
643 be_visitor_union_ci
visitor (&ctx
);
644 status
= node
->accept (&visitor
);
647 case TAO_CodeGen::TAO_ROOT_CS
:
649 be_visitor_union_cs
visitor (&ctx
);
650 status
= node
->accept (&visitor
);
653 case TAO_CodeGen::TAO_ROOT_ANY_OP_CH
:
655 be_visitor_union_any_op_ch
visitor (&ctx
);
656 status
= node
->accept (&visitor
);
659 case TAO_CodeGen::TAO_ROOT_ANY_OP_CS
:
661 be_visitor_union_any_op_cs
visitor (&ctx
);
662 status
= node
->accept (&visitor
);
665 case TAO_CodeGen::TAO_ROOT_CDR_OP_CH
:
667 be_visitor_union_cdr_op_ch
visitor (&ctx
);
668 status
= node
->accept (&visitor
);
671 case TAO_CodeGen::TAO_ROOT_CDR_OP_CS
:
673 be_visitor_union_cdr_op_cs
visitor (&ctx
);
674 status
= node
->accept (&visitor
);
678 return 0; // nothing to be done
683 ACE_ERROR_RETURN ((LM_ERROR
,
684 "(%N:%l) be_visitor_interface::"
686 "failed to accept visitor\n"),
694 be_visitor_interface::visit_union_fwd (be_union_fwd
*node
)
696 // Instantiate a visitor context with a copy of our context. This info
697 // will be modified based on what type of node we are visiting.
698 be_visitor_context
ctx (*this->ctx_
);
702 switch (this->ctx_
->state ())
704 case TAO_CodeGen::TAO_INTERFACE_CH
:
706 be_visitor_union_fwd_ch
visitor (&ctx
);
707 status
= node
->accept (&visitor
);
711 return 0; // nothing to be done
716 ACE_ERROR_RETURN ((LM_ERROR
,
717 "(%N:%l) be_visitor_interface::"
719 "failed to accept visitor\n"),
727 be_visitor_interface::visit_typedef (be_typedef
*node
)
729 // Instantiate a visitor context with a copy of our context. This info
730 // will be modified based on what type of node we are visiting.
731 be_visitor_context
ctx (*this->ctx_
);
735 switch (this->ctx_
->state ())
737 case TAO_CodeGen::TAO_INTERFACE_CH
:
739 be_visitor_typedef_ch
visitor (&ctx
);
740 status
= node
->accept (&visitor
);
743 case TAO_CodeGen::TAO_ROOT_CI
:
745 be_visitor_typedef_ci
visitor (&ctx
);
746 status
= node
->accept (&visitor
);
749 case TAO_CodeGen::TAO_ROOT_CS
:
751 be_visitor_typedef_cs
visitor (&ctx
);
752 status
= node
->accept (&visitor
);
755 case TAO_CodeGen::TAO_ROOT_ANY_OP_CH
:
757 be_visitor_typedef_any_op_ch
visitor (&ctx
);
758 status
= node
->accept (&visitor
);
761 case TAO_CodeGen::TAO_ROOT_ANY_OP_CS
:
763 be_visitor_typedef_any_op_cs
visitor (&ctx
);
764 status
= node
->accept (&visitor
);
767 case TAO_CodeGen::TAO_ROOT_CDR_OP_CH
:
769 be_visitor_typedef_cdr_op_ch
visitor (&ctx
);
770 status
= node
->accept (&visitor
);
773 case TAO_CodeGen::TAO_ROOT_CDR_OP_CS
:
775 be_visitor_typedef_cdr_op_cs
visitor (&ctx
);
776 status
= node
->accept (&visitor
);
780 return 0; // nothing to be done
785 ACE_ERROR_RETURN ((LM_ERROR
,
786 "(%N:%l) be_visitor_interface::"
788 "failed to accept visitor\n"),