Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / TAO_IDL / be / be_decl.cpp
blob07d121b3427ecdc85528719cfcb443332dd44284
2 //=============================================================================
3 /**
4 * @file be_decl.cpp
6 * Extension of class AST_Decl that provides additional means for C++
7 * mapping.
9 * @author Copyright 1994-1995 by Sun Microsystems
10 * @author Inc. and Aniruddha Gokhale
12 //=============================================================================
14 #include "be_decl.h"
15 #include "be_scope.h"
16 #include "be_interface.h"
17 #include "be_interface_fwd.h"
18 #include "be_valuetype.h"
19 #include "be_component.h"
20 #include "be_eventtype.h"
21 #include "be_home.h"
22 #include "be_module.h"
23 #include "be_root.h"
24 #include "be_exception.h"
25 #include "be_structure.h"
26 #include "be_union.h"
27 #include "be_enum.h"
28 #include "be_operation.h"
29 #include "be_factory.h"
30 #include "be_finder.h"
31 #include "be_sequence.h"
32 #include "be_visitor.h"
34 #include "ast_structure_fwd.h"
35 #include "ast_typedef.h"
36 #include "ast_string.h"
38 #include "utl_identifier.h"
40 #include "global_extern.h"
41 #include "ace/Log_Msg.h"
42 #include "ace/String_Base.h"
44 be_decl::be_decl (AST_Decl::NodeType type,
45 UTL_ScopedName *n)
46 : COMMON_Base (),
47 AST_Decl (type,
48 n),
49 cli_hdr_gen_ (false),
50 cli_stub_gen_ (false),
51 cli_inline_gen_ (false),
52 srv_hdr_gen_ (false),
53 impl_hdr_gen_ (false),
54 srv_skel_gen_ (false),
55 impl_skel_gen_ (false),
56 srv_inline_gen_ (false),
57 tie_skel_gen_ (false),
58 cli_hdr_any_op_gen_ (false),
59 cli_stub_any_op_gen_ (false),
60 cli_hdr_cdr_op_gen_ (false),
61 cli_stub_cdr_op_gen_ (false),
62 cli_inline_cdr_op_gen_ (false),
63 cli_inline_cdr_decl_gen_ (false),
64 cli_traits_gen_ (false),
65 cli_arg_traits_gen_ (false),
66 srv_arg_traits_gen_ (false),
67 srv_sarg_traits_gen_ (false),
68 cli_pragma_inst_gen_ (false),
69 cli_inarg_tmpl_class_gen_ (false),
70 cli_inarg_pragma_inst_gen_ (false),
71 cli_inoutarg_tmpl_class_gen_ (false),
72 cli_inoutarg_pragma_inst_gen_ (false),
73 cli_outarg_tmpl_class_gen_ (false),
74 cli_outarg_pragma_inst_gen_ (false),
75 cli_retarg_tmpl_class_gen_ (false),
76 cli_retarg_pragma_inst_gen_ (false),
77 srv_tmpl_class_gen_ (false),
78 srv_pragma_inst_gen_ (false),
79 srv_inarg_tmpl_class_gen_ (false),
80 srv_inarg_pragma_inst_gen_ (false),
81 srv_inoutarg_tmpl_class_gen_ (false),
82 srv_inoutarg_pragma_inst_gen_ (false),
83 srv_outarg_tmpl_class_gen_ (false),
84 srv_outarg_pragma_inst_gen_ (false),
85 srv_retarg_tmpl_class_gen_ (false),
86 srv_retarg_pragma_inst_gen_ (false),
87 ccm_pre_proc_gen_ (false),
88 ex_idl_facet_gen_ (false),
89 svnt_hdr_facet_gen_ (false),
90 svnt_src_facet_gen_ (false),
91 exec_hdr_facet_gen_ (false),
92 exec_src_facet_gen_ (false),
93 ami4ccm_ex_idl_gen_ (false)
97 be_decl::~be_decl ()
101 void
102 be_decl::compute_full_name (const char *prefix,
103 const char *suffix,
104 char *&name)
106 if (prefix == nullptr || suffix == nullptr)
108 return;
111 ACE_CString prefix_str (prefix);
112 ACE_CString suffix_str (suffix);
113 ACE_CString result_str;
115 // Get parent.
116 if (this->defined_in () == nullptr)
118 // Global scope.
120 // Prefix.
121 result_str = prefix_str;
123 // Local name.
124 result_str += ACE_CString (this->local_name ()->get_string ());
126 // Suffix.
127 result_str += suffix_str;
129 else
131 // Get scope name.
132 be_decl * const parent =
133 dynamic_cast<be_scope*> (this->defined_in ())->decl ();
135 if (parent == nullptr)
137 ACE_ERROR ((LM_ERROR,
138 "(%N:%l) be_decl::"
139 "compute_full_name - "
140 "scope name is nil\n"));
142 return;
145 // Parent name.
146 result_str = ACE_CString (parent->full_name ());
148 // _
149 if (ACE_OS::strcmp (parent->full_name (), "") != 0)
151 result_str += ACE_CString ("::");
154 // Prefix.
155 result_str += prefix_str;
157 // Local name.
158 result_str += ACE_CString (this->local_name ()->get_string ());
160 // Suffix.
161 result_str += suffix_str;
164 name = ACE_OS::strdup (result_str.fast_rep ());
167 void
168 be_decl::compute_flat_name (const char *prefix,
169 const char *suffix,
170 char *&name)
172 if (prefix == nullptr || suffix == nullptr)
174 return;
177 ACE_CString prefix_str (prefix);
178 ACE_CString suffix_str (suffix);
180 ACE_CString result_str;
182 // Get parent.
183 if (this->defined_in () == nullptr)
185 // Global scope.
187 // Prefix.
188 result_str = prefix_str;
190 // Local name. Leave out _cxx_ prefix, if any.
191 result_str +=
192 ACE_CString (
193 this->original_local_name ()->get_string ());
195 // Suffix.
196 result_str += suffix_str;
198 else
200 // Get scope name.
201 be_decl * const parent =
202 dynamic_cast<be_scope*> (this->defined_in ())->decl ();
203 if (parent == nullptr)
205 ACE_ERROR ((LM_ERROR,
206 "(%N:%l) be_decl::"
207 "compute_flat_name - "
208 "scope name is nil\n"));
210 return;
213 // Parent name.
214 result_str = ACE_CString (parent->flat_name ());
216 // _
217 if (ACE_OS::strcmp (parent->flat_name (), "") != 0)
218 result_str += "_";
220 // Prefix.
221 result_str += prefix_str;
223 // Local name. Leave out _cxx_ prefix, if any.
224 result_str +=
225 ACE_CString (
226 this->original_local_name ()->get_string ());
228 // Suffix.
229 result_str += suffix_str;
232 name = ACE_OS::strdup (result_str.c_str ());
235 void
236 be_decl::destroy ()
240 void
241 be_decl::set_local (bool val)
243 this->is_local_ = val;
246 // Return the scope created by this node (if one exists, else NULL).
247 be_scope *
248 be_decl::scope ()
250 be_decl *d = this;
252 switch (this->node_type ())
254 case AST_Decl::NT_interface_fwd:
255 // Resolve forward declared interface by looking at full_definition()
256 // field and iterating.
258 dynamic_cast<be_interface*> (
259 (dynamic_cast<be_interface_fwd*> (this))->full_definition ()
261 // Fall through
262 case AST_Decl::NT_interface:
263 return dynamic_cast<be_interface*> (d);
264 case AST_Decl::NT_module:
265 return dynamic_cast<be_module*> (d);
266 case AST_Decl::NT_root:
267 return dynamic_cast<be_root*> (d);
268 case AST_Decl::NT_except:
269 return dynamic_cast<be_exception*> (d);
270 case AST_Decl::NT_union:
271 return dynamic_cast<be_union*> (d);
272 case AST_Decl::NT_struct:
273 return dynamic_cast<be_structure*> (d);
274 case AST_Decl::NT_enum:
275 return dynamic_cast<be_enum*> (d);
276 case AST_Decl::NT_op:
277 return dynamic_cast<be_operation*> (d);
278 case AST_Decl::NT_factory:
279 return dynamic_cast<be_factory*> (d);
280 case AST_Decl::NT_finder:
281 return dynamic_cast<be_finder*> (d);
282 case AST_Decl::NT_sequence:
283 return dynamic_cast<be_sequence*> (d);
284 case AST_Decl::NT_valuetype:
285 return dynamic_cast<be_valuetype*> (d);
286 case AST_Decl::NT_component:
287 return dynamic_cast<be_component*> (d);
288 case AST_Decl::NT_eventtype:
289 return dynamic_cast<be_eventtype*> (d);
290 case AST_Decl::NT_home:
291 return dynamic_cast<be_home*> (d);
292 default:
293 return nullptr;
297 // Boolean methods to test if code was already generated.
298 bool
299 be_decl::cli_hdr_gen ()
301 return this->cli_hdr_gen_;
304 bool
305 be_decl::cli_stub_gen ()
307 return this->cli_stub_gen_;
310 bool
311 be_decl::cli_hdr_any_op_gen ()
313 return this->cli_hdr_any_op_gen_;
316 bool
317 be_decl::cli_stub_any_op_gen ()
319 return this->cli_stub_any_op_gen_;
322 bool
323 be_decl::cli_hdr_cdr_op_gen ()
325 return this->cli_hdr_cdr_op_gen_;
328 bool
329 be_decl::cli_stub_cdr_op_gen ()
331 return this->cli_stub_cdr_op_gen_;
334 bool
335 be_decl::cli_inline_cdr_op_gen ()
337 return this->cli_inline_cdr_op_gen_;
340 bool
341 be_decl::cli_inline_cdr_decl_gen ()
343 return this->cli_inline_cdr_decl_gen_;
346 bool
347 be_decl::cli_traits_gen ()
349 return this->cli_traits_gen_;
352 bool
353 be_decl::cli_arg_traits_gen ()
355 return this->cli_arg_traits_gen_;
358 bool
359 be_decl::srv_arg_traits_gen ()
361 return this->srv_arg_traits_gen_;
364 bool
365 be_decl::srv_sarg_traits_gen ()
367 return this->srv_sarg_traits_gen_;
370 bool
371 be_decl::cli_pragma_inst_gen ()
373 return this->cli_pragma_inst_gen_;
376 bool
377 be_decl::cli_inarg_tmpl_class_gen ()
379 return this->cli_inarg_tmpl_class_gen_;
382 bool
383 be_decl::cli_inarg_pragma_inst_gen ()
385 return this->cli_inarg_pragma_inst_gen_;
388 bool
389 be_decl::cli_inoutarg_tmpl_class_gen ()
391 return this->cli_inoutarg_tmpl_class_gen_;
394 bool
395 be_decl::cli_inoutarg_pragma_inst_gen ()
397 return this->cli_inoutarg_pragma_inst_gen_;
400 bool
401 be_decl::cli_outarg_tmpl_class_gen ()
403 return this->cli_outarg_tmpl_class_gen_;
406 bool
407 be_decl::cli_outarg_pragma_inst_gen ()
409 return this->cli_outarg_pragma_inst_gen_;
412 bool
413 be_decl::cli_retarg_tmpl_class_gen ()
415 return this->cli_retarg_tmpl_class_gen_;
418 bool
419 be_decl::cli_retarg_pragma_inst_gen ()
421 return this->cli_retarg_pragma_inst_gen_;
424 bool
425 be_decl::srv_tmpl_class_gen ()
427 return this->srv_tmpl_class_gen_;
430 bool
431 be_decl::srv_pragma_inst_gen ()
433 return this->srv_pragma_inst_gen_;
436 bool
437 be_decl::srv_inarg_tmpl_class_gen ()
439 return this->srv_inarg_tmpl_class_gen_;
442 bool
443 be_decl::srv_inarg_pragma_inst_gen ()
445 return this->srv_inarg_pragma_inst_gen_;
448 bool
449 be_decl::srv_inoutarg_tmpl_class_gen ()
451 return this->srv_inoutarg_tmpl_class_gen_;
454 bool
455 be_decl::srv_inoutarg_pragma_inst_gen ()
457 return this->srv_inoutarg_pragma_inst_gen_;
460 bool
461 be_decl::srv_outarg_tmpl_class_gen ()
463 return this->srv_outarg_tmpl_class_gen_;
466 bool
467 be_decl::srv_outarg_pragma_inst_gen ()
469 return this->srv_outarg_pragma_inst_gen_;
472 bool
473 be_decl::srv_retarg_tmpl_class_gen ()
475 return this->srv_retarg_tmpl_class_gen_;
478 bool
479 be_decl::srv_retarg_pragma_inst_gen ()
481 return this->cli_retarg_pragma_inst_gen_;
484 bool
485 be_decl::cli_inline_gen ()
487 return this->cli_inline_gen_;
490 bool
491 be_decl::srv_hdr_gen ()
493 return this->srv_hdr_gen_;
496 bool
497 be_decl::impl_hdr_gen ()
499 return this->impl_hdr_gen_;
502 bool
503 be_decl::srv_skel_gen ()
505 return this->srv_skel_gen_;
508 bool
509 be_decl::impl_skel_gen ()
511 return this->impl_skel_gen_;
514 bool
515 be_decl::srv_inline_gen ()
517 return this->srv_inline_gen_;
520 bool
521 be_decl::tie_skel_gen ()
523 return this->tie_skel_gen_;
526 bool
527 be_decl::ccm_pre_proc_gen ()
529 return this->ccm_pre_proc_gen_;
532 bool
533 be_decl::ex_idl_facet_gen ()
535 return this->ex_idl_facet_gen_;
538 bool
539 be_decl::svnt_hdr_facet_gen ()
541 return this->svnt_hdr_facet_gen_;
544 bool
545 be_decl::svnt_src_facet_gen ()
547 return this->svnt_src_facet_gen_;
550 bool
551 be_decl::exec_hdr_facet_gen ()
553 return this->exec_hdr_facet_gen_;
556 bool
557 be_decl::exec_src_facet_gen ()
559 return this->exec_src_facet_gen_;
562 bool
563 be_decl::ami4ccm_ex_idl_gen ()
565 return this->ami4ccm_ex_idl_gen_;
568 // Set the flag indicating that code generation is done.
569 void
570 be_decl::cli_hdr_gen (bool val)
572 this->cli_hdr_gen_ = val;
575 void
576 be_decl::cli_stub_gen (bool val)
578 this->cli_stub_gen_ = val;
581 void
582 be_decl::cli_hdr_any_op_gen (bool val)
584 this->cli_hdr_any_op_gen_ = val;
587 void
588 be_decl::cli_stub_any_op_gen (bool val)
590 this->cli_stub_any_op_gen_ = val;
593 void
594 be_decl::cli_hdr_cdr_op_gen (bool val)
596 this->cli_hdr_cdr_op_gen_ = val;
599 void
600 be_decl::cli_stub_cdr_op_gen (bool val)
602 this->cli_stub_cdr_op_gen_ = val;
605 void
606 be_decl::cli_inline_cdr_op_gen (bool val)
608 this->cli_inline_cdr_op_gen_ = val;
611 void
612 be_decl::cli_inline_cdr_decl_gen (bool val)
614 this->cli_inline_cdr_decl_gen_ = val;
617 void
618 be_decl::cli_inline_gen (bool val)
620 this->cli_inline_gen_ = val;
623 void
624 be_decl::cli_traits_gen (bool val)
626 this->cli_traits_gen_ = val;
629 void
630 be_decl::cli_arg_traits_gen (bool val)
632 this->cli_arg_traits_gen_ = val;
635 void
636 be_decl::srv_arg_traits_gen (bool val)
638 this->srv_arg_traits_gen_ = val;
641 void
642 be_decl::srv_sarg_traits_gen (bool val)
644 this->srv_sarg_traits_gen_ = val;
647 void
648 be_decl::cli_pragma_inst_gen (bool val)
650 this->cli_pragma_inst_gen_ = val;
653 void
654 be_decl::cli_inarg_tmpl_class_gen (bool val)
656 this->cli_inarg_tmpl_class_gen_ = val;
659 void
660 be_decl::cli_inarg_pragma_inst_gen (bool val)
662 this->cli_inarg_pragma_inst_gen_ = val;
665 void
666 be_decl::cli_inoutarg_tmpl_class_gen (bool val)
668 this->cli_inoutarg_tmpl_class_gen_ = val;
671 void
672 be_decl::cli_inoutarg_pragma_inst_gen (bool val)
674 this->cli_inoutarg_pragma_inst_gen_ = val;
677 void
678 be_decl::cli_outarg_tmpl_class_gen (bool val)
680 this->cli_outarg_tmpl_class_gen_ = val;
683 void
684 be_decl::cli_outarg_pragma_inst_gen (bool val)
686 this->cli_outarg_pragma_inst_gen_ = val;
689 void
690 be_decl::cli_retarg_tmpl_class_gen (bool val)
692 this->cli_retarg_tmpl_class_gen_ = val;
695 void
696 be_decl::cli_retarg_pragma_inst_gen (bool val)
698 this->cli_retarg_pragma_inst_gen_ = val;
701 void
702 be_decl::srv_tmpl_class_gen (bool val)
704 this->srv_tmpl_class_gen_ = val;
707 void
708 be_decl::srv_pragma_inst_gen (bool val)
710 this->srv_pragma_inst_gen_ = val;
713 void
714 be_decl::srv_inarg_tmpl_class_gen (bool val)
716 this->srv_inarg_tmpl_class_gen_ = val;
719 void
720 be_decl::srv_inarg_pragma_inst_gen (bool val)
722 this->srv_inarg_pragma_inst_gen_ = val;
725 void
726 be_decl::srv_inoutarg_tmpl_class_gen (bool val)
728 this->srv_inoutarg_tmpl_class_gen_ = val;
731 void
732 be_decl::srv_inoutarg_pragma_inst_gen (bool val)
734 this->srv_inoutarg_pragma_inst_gen_ = val;
737 void
738 be_decl::srv_outarg_tmpl_class_gen (bool val)
740 this->srv_outarg_tmpl_class_gen_ = val;
743 void
744 be_decl::srv_outarg_pragma_inst_gen (bool val)
746 this->srv_outarg_pragma_inst_gen_ = val;
749 void
750 be_decl::srv_retarg_tmpl_class_gen (bool val)
752 this->srv_retarg_tmpl_class_gen_ = val;
755 void
756 be_decl::srv_retarg_pragma_inst_gen (bool val)
758 this->srv_retarg_pragma_inst_gen_ = val;
761 void
762 be_decl::srv_hdr_gen (bool val)
764 this->srv_hdr_gen_ = val;
767 void
768 be_decl::impl_hdr_gen (bool val)
770 this->impl_hdr_gen_ = val;
774 void
775 be_decl::srv_skel_gen (bool val)
777 this->srv_skel_gen_ = val;
780 void
781 be_decl::srv_inline_gen (bool val)
783 this->srv_inline_gen_ = val;
786 void
787 be_decl::tie_skel_gen (bool val)
789 this->tie_skel_gen_ = val;
792 void
793 be_decl::ccm_pre_proc_gen (bool val)
795 this->ccm_pre_proc_gen_ = val;
798 void
799 be_decl::ex_idl_facet_gen (bool val)
801 this->ex_idl_facet_gen_ = val;
804 void
805 be_decl::svnt_hdr_facet_gen (bool val)
807 this->svnt_hdr_facet_gen_ = val;
810 void
811 be_decl::svnt_src_facet_gen (bool val)
813 this->svnt_src_facet_gen_ = val;
816 void
817 be_decl::exec_hdr_facet_gen (bool val)
819 this->exec_hdr_facet_gen_ = val;
822 void
823 be_decl::exec_src_facet_gen (bool val)
825 this->exec_src_facet_gen_ = val;
828 void
829 be_decl::ami4ccm_ex_idl_gen (bool val)
831 this->ami4ccm_ex_idl_gen_ = val;
834 //==========================================
837 be_decl::accept (be_visitor *visitor)
839 return visitor->visit_decl (this);