Use =default for skeleton copy constructor
[ACE_TAO.git] / TAO / TAO_IDL / be / be_visitor_interface / interface.cpp
blob879a8d66789fd6a70007ceac8c52021d7d26d2c9
2 //=============================================================================
3 /**
4 * @file interface.cpp
6 * Visitor generating code for Interfaces. This is a generic visitor.
8 * @author Aniruddha Gokhale
9 */
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.
24 int
25 be_visitor_interface::visit_interface (be_interface *)
27 return -1;
30 int
31 be_visitor_interface::visit_scope (be_scope *node)
33 if (this->be_visitor_scope::visit_scope (node) == -1)
35 return -1;
38 be_interface *intf = dynamic_cast<be_interface*> (node);
40 if (intf == nullptr)
42 return 0;
45 if (intf->is_abstract ())
47 return 0;
50 if (! intf->has_mixed_parentage ())
52 return 0;
55 be_interface::tao_code_emitter helper = nullptr;
57 switch (this->ctx_->state ())
59 case TAO_CodeGen::TAO_INTERFACE_CH:
60 helper =
61 be_visitor_interface_ch::gen_abstract_ops_helper;
62 break;
63 case TAO_CodeGen::TAO_ROOT_CS:
64 helper =
65 be_visitor_interface_cs::gen_abstract_ops_helper;
66 break;
67 case TAO_CodeGen::TAO_ROOT_SH:
68 helper =
69 be_visitor_interface_sh::gen_abstract_ops_helper;
70 break;
71 case TAO_CodeGen::TAO_INTERFACE_DIRECT_PROXY_IMPL_SH:
72 helper =
73 be_visitor_interface_direct_proxy_impl_sh::gen_abstract_ops_helper;
74 break;
75 case TAO_CodeGen::TAO_ROOT_SS:
76 helper =
77 be_visitor_interface_ss::gen_abstract_ops_helper;
78 break;
79 case TAO_CodeGen::TAO_INTERFACE_DIRECT_PROXY_IMPL_SS:
80 helper =
81 be_visitor_interface_direct_proxy_impl_ss::gen_abstract_ops_helper;
82 break;
83 default:
84 break;
87 if (helper == nullptr)
89 return 0;
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.
95 int status =
96 intf->traverse_inheritance_graph (helper,
97 this->ctx_->stream (),
98 false);
100 if (status == -1)
102 ACE_ERROR_RETURN ((LM_ERROR,
103 "be_visitor_interface_*::"
104 "visit_scope - "
105 "traversal of inheritance graph failed\n"),
106 -1);
109 return 0;
113 be_visitor_interface::is_amh_rh_node (be_interface *node)
115 //If, is implied-IDL
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.
122 return 1;
126 return 0;
129 void
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);
136 !si.is_done ();
137 si.next ())
139 d = si.item ();
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_);
159 ctx.node (node);
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::"
168 "visit_attribute - "
169 "failed to accept visitor\n"),
170 -1);
173 return 0;
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_);
182 ctx.node (node);
183 int status = 0;
185 switch (this->ctx_->state ())
187 case TAO_CodeGen::TAO_INTERFACE_CH:
189 be_visitor_constant_ch visitor (&ctx);
190 status = node->accept (&visitor);
191 break;
193 case TAO_CodeGen::TAO_ROOT_CS:
195 be_visitor_constant_cs visitor (&ctx);
196 status = node->accept (&visitor);
197 break;
199 default:
200 return 0; // nothing to be done
203 if (status == -1)
205 ACE_ERROR_RETURN ((LM_ERROR,
206 "(%N:%l) be_visitor_interface::"
207 "visit_constant - "
208 "failed to accept visitor\n"),
209 -1);
212 return 0;
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_);
221 ctx.node (node);
222 int status = 0;
224 switch (this->ctx_->state ())
226 case TAO_CodeGen::TAO_INTERFACE_CH:
228 be_visitor_native_ch visitor (&ctx);
229 status = node->accept (&visitor);
230 break;
232 default:
233 return 0; // nothing to be done
236 if (status == -1)
238 ACE_ERROR_RETURN ((LM_ERROR,
239 "(%N:%l) be_visitor_interface::"
240 "visit_native - "
241 "failed to accept visitor\n"),
242 -1);
245 return 0;
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_);
254 ctx.node (node);
255 int status = 0;
257 switch (this->ctx_->state ())
259 case TAO_CodeGen::TAO_INTERFACE_CH:
261 be_visitor_enum_ch visitor (&ctx);
262 status = node->accept (&visitor);
263 break;
265 case TAO_CodeGen::TAO_ROOT_CS:
267 be_visitor_enum_cs visitor (&ctx);
268 status = node->accept (&visitor);
269 break;
271 case TAO_CodeGen::TAO_ROOT_ANY_OP_CH:
273 be_visitor_enum_any_op_ch visitor (&ctx);
274 status = node->accept (&visitor);
275 break;
277 case TAO_CodeGen::TAO_ROOT_ANY_OP_CS:
279 be_visitor_enum_any_op_cs visitor (&ctx);
280 status = node->accept (&visitor);
281 break;
283 case TAO_CodeGen::TAO_ROOT_CDR_OP_CH:
285 be_visitor_enum_cdr_op_ch visitor (&ctx);
286 status = node->accept (&visitor);
287 break;
289 case TAO_CodeGen::TAO_ROOT_CDR_OP_CS:
291 be_visitor_enum_cdr_op_cs visitor (&ctx);
292 status = node->accept (&visitor);
293 break;
295 default:
296 return 0; // nothing to be done
299 if (status == -1)
301 ACE_ERROR_RETURN ((LM_ERROR,
302 "(%N:%l) be_visitor_interface::"
303 "visit_enum - "
304 "failed to accept visitor\n"),
305 -1);
308 return 0;
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_);
318 ctx.node (node);
319 int status = 0;
321 switch (this->ctx_->state ())
323 case TAO_CodeGen::TAO_INTERFACE_CH:
325 be_visitor_exception_ch visitor (&ctx);
326 status = node->accept (&visitor);
327 break;
329 case TAO_CodeGen::TAO_ROOT_CI:
331 be_visitor_exception_ci visitor (&ctx);
332 status = node->accept (&visitor);
333 break;
335 case TAO_CodeGen::TAO_ROOT_CS:
337 be_visitor_exception_cs visitor (&ctx);
338 status = node->accept (&visitor);
339 break;
341 case TAO_CodeGen::TAO_ROOT_ANY_OP_CH:
343 be_visitor_exception_any_op_ch visitor (&ctx);
344 status = node->accept (&visitor);
345 break;
347 case TAO_CodeGen::TAO_ROOT_ANY_OP_CS:
349 be_visitor_exception_any_op_cs visitor (&ctx);
350 status = node->accept (&visitor);
351 break;
353 case TAO_CodeGen::TAO_ROOT_CDR_OP_CH:
355 be_visitor_exception_cdr_op_ch visitor (&ctx);
356 status = node->accept (&visitor);
357 break;
359 case TAO_CodeGen::TAO_ROOT_CDR_OP_CS:
361 be_visitor_exception_cdr_op_cs visitor (&ctx);
362 status = node->accept (&visitor);
363 break;
365 default:
366 return 0; // nothing to be done
369 if (status == -1)
371 ACE_ERROR_RETURN ((LM_ERROR,
372 "(%N:%l) be_visitor_interface::"
373 "visit_exception - "
374 "failed to accept visitor\n"),
375 -1);
378 return 0;
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_);
388 ctx.node (node);
389 int status = 1;
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);
400 break;
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);
410 else
412 be_visitor_operation_cs visitor (&ctx);
413 status = node->accept (&visitor);
416 break;
417 case TAO_CodeGen::TAO_ROOT_SH:
419 be_visitor_operation_sh visitor (&ctx);
420 status = node->accept (&visitor);
421 break;
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);
428 break;
430 case TAO_CodeGen::TAO_ROOT_SS:
432 be_visitor_operation_ss visitor (&ctx);
433 status = node->accept (&visitor);
434 break;
436 case TAO_CodeGen::TAO_ROOT_IS:
438 be_visitor_operation_is visitor (&ctx);
439 status = node->accept (&visitor);
440 break;
442 case TAO_CodeGen::TAO_ROOT_TIE_SH:
444 be_visitor_operation_tie_sh visitor (&ctx);
445 status = node->accept (&visitor);
446 break;
448 case TAO_CodeGen::TAO_ROOT_TIE_SS:
450 be_visitor_operation_tie_ss visitor (&ctx);
451 status = node->accept (&visitor);
452 break;
454 case TAO_CodeGen::TAO_INTERFACE_SMART_PROXY_CH:
456 be_visitor_operation_smart_proxy_ch visitor (&ctx);
457 status = node->accept (&visitor);
458 break;
460 case TAO_CodeGen::TAO_INTERFACE_SMART_PROXY_CS:
462 be_visitor_operation_smart_proxy_cs visitor (&ctx);
463 status = node->accept (&visitor);
464 break;
466 case TAO_CodeGen::TAO_INTERFACE_DIRECT_PROXY_IMPL_SH:
468 be_visitor_operation_proxy_impl_xh visitor (&ctx);
469 status = node->accept (&visitor);
470 break;
472 case TAO_CodeGen::TAO_INTERFACE_AMH_RH_SH:
474 be_visitor_amh_rh_operation_sh visitor (&ctx);
475 status = node->accept (&visitor);
476 break;
478 case TAO_CodeGen::TAO_INTERFACE_AMH_RH_SS:
480 be_visitor_amh_rh_operation_ss visitor (&ctx);
481 status = node->accept (&visitor);
482 break;
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);
488 break;
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
496 default:
498 ACE_ERROR_RETURN ((LM_ERROR,
499 "(%N:%l) be_visitor_interface::"
500 "visit_operation - "
501 "Bad context state\n"),
502 -1);
506 if (status == 0)
508 return 0;
510 else if (status == -1)
512 ACE_ERROR_RETURN ((LM_ERROR,
513 "(%N:%l) be_visitor_interface::"
514 "visit_operation - "
515 "failed to accept visitor\n"),
516 -1);
519 return 0;
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_);
528 ctx.node (node);
529 int status = 0;
531 switch (this->ctx_->state ())
533 case TAO_CodeGen::TAO_INTERFACE_CH:
535 be_visitor_structure_ch visitor (&ctx);
536 status = node->accept (&visitor);
537 break;
539 case TAO_CodeGen::TAO_ROOT_CI:
541 be_visitor_structure_ci visitor (&ctx);
542 status = node->accept (&visitor);
543 break;
545 case TAO_CodeGen::TAO_ROOT_CS:
547 be_visitor_structure_cs visitor (&ctx);
548 status = node->accept (&visitor);
549 break;
551 case TAO_CodeGen::TAO_ROOT_ANY_OP_CH:
553 be_visitor_structure_any_op_ch visitor (&ctx);
554 status = node->accept (&visitor);
555 break;
557 case TAO_CodeGen::TAO_ROOT_ANY_OP_CS:
559 be_visitor_structure_any_op_cs visitor (&ctx);
560 status = node->accept (&visitor);
561 break;
563 case TAO_CodeGen::TAO_ROOT_CDR_OP_CH:
565 be_visitor_structure_cdr_op_ch visitor (&ctx);
566 status = node->accept (&visitor);
567 break;
569 case TAO_CodeGen::TAO_ROOT_CDR_OP_CS:
571 be_visitor_structure_cdr_op_cs visitor (&ctx);
572 status = node->accept (&visitor);
573 break;
575 default:
576 return 0; // nothing to be done
579 if (status == -1)
581 ACE_ERROR_RETURN ((LM_ERROR,
582 "(%N:%l) be_visitor_interface::"
583 "visit_structure - "
584 "failed to accept visitor\n"),
585 -1);
588 return 0;
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_);
597 ctx.node (node);
598 int status = 0;
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);
606 break;
608 default:
609 return 0; // nothing to be done
612 if (status == -1)
614 ACE_ERROR_RETURN ((LM_ERROR,
615 "(%N:%l) be_visitor_interface::"
616 "visit_structure_fwd - "
617 "failed to accept visitor\n"),
618 -1);
621 return 0;
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_);
630 ctx.node (node);
631 int status = 0;
633 switch (this->ctx_->state ())
635 case TAO_CodeGen::TAO_INTERFACE_CH:
637 be_visitor_union_ch visitor (&ctx);
638 status = node->accept (&visitor);
639 break;
641 case TAO_CodeGen::TAO_ROOT_CI:
643 be_visitor_union_ci visitor (&ctx);
644 status = node->accept (&visitor);
645 break;
647 case TAO_CodeGen::TAO_ROOT_CS:
649 be_visitor_union_cs visitor (&ctx);
650 status = node->accept (&visitor);
651 break;
653 case TAO_CodeGen::TAO_ROOT_ANY_OP_CH:
655 be_visitor_union_any_op_ch visitor (&ctx);
656 status = node->accept (&visitor);
657 break;
659 case TAO_CodeGen::TAO_ROOT_ANY_OP_CS:
661 be_visitor_union_any_op_cs visitor (&ctx);
662 status = node->accept (&visitor);
663 break;
665 case TAO_CodeGen::TAO_ROOT_CDR_OP_CH:
667 be_visitor_union_cdr_op_ch visitor (&ctx);
668 status = node->accept (&visitor);
669 break;
671 case TAO_CodeGen::TAO_ROOT_CDR_OP_CS:
673 be_visitor_union_cdr_op_cs visitor (&ctx);
674 status = node->accept (&visitor);
675 break;
677 default:
678 return 0; // nothing to be done
681 if (status == -1)
683 ACE_ERROR_RETURN ((LM_ERROR,
684 "(%N:%l) be_visitor_interface::"
685 "visit_union - "
686 "failed to accept visitor\n"),
687 -1);
690 return 0;
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_);
699 ctx.node (node);
700 int status = 0;
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);
708 break;
710 default:
711 return 0; // nothing to be done
714 if (status == -1)
716 ACE_ERROR_RETURN ((LM_ERROR,
717 "(%N:%l) be_visitor_interface::"
718 "visit_union_fwd - "
719 "failed to accept visitor\n"),
720 -1);
723 return 0;
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_);
732 ctx.node (node);
733 int status = 0;
735 switch (this->ctx_->state ())
737 case TAO_CodeGen::TAO_INTERFACE_CH:
739 be_visitor_typedef_ch visitor (&ctx);
740 status = node->accept (&visitor);
741 break;
743 case TAO_CodeGen::TAO_ROOT_CI:
745 be_visitor_typedef_ci visitor (&ctx);
746 status = node->accept (&visitor);
747 break;
749 case TAO_CodeGen::TAO_ROOT_CS:
751 be_visitor_typedef_cs visitor (&ctx);
752 status = node->accept (&visitor);
753 break;
755 case TAO_CodeGen::TAO_ROOT_ANY_OP_CH:
757 be_visitor_typedef_any_op_ch visitor (&ctx);
758 status = node->accept (&visitor);
759 break;
761 case TAO_CodeGen::TAO_ROOT_ANY_OP_CS:
763 be_visitor_typedef_any_op_cs visitor (&ctx);
764 status = node->accept (&visitor);
765 break;
767 case TAO_CodeGen::TAO_ROOT_CDR_OP_CH:
769 be_visitor_typedef_cdr_op_ch visitor (&ctx);
770 status = node->accept (&visitor);
771 break;
773 case TAO_CodeGen::TAO_ROOT_CDR_OP_CS:
775 be_visitor_typedef_cdr_op_cs visitor (&ctx);
776 status = node->accept (&visitor);
777 break;
779 default:
780 return 0; // nothing to be done
783 if (status == -1)
785 ACE_ERROR_RETURN ((LM_ERROR,
786 "(%N:%l) be_visitor_interface::"
787 "visit_typedef - "
788 "failed to accept visitor\n"),
789 -1);
792 return 0;