Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / TAO_IDL / be / be_visitor_root / root_ch.cpp
blob100195bb188bc7d449cf9ddfeae47dff5996132d
2 //=============================================================================
3 /**
4 * @file root_ch.cpp
6 * Visitor generating code for Root in the client header
8 * @author Aniruddha Gokhale
9 */
10 //=============================================================================
12 #include "root.h"
14 // ********************************
15 // Root visitor for client header
16 // ********************************
18 be_visitor_root_ch::be_visitor_root_ch (be_visitor_context *ctx)
19 : be_visitor_root (ctx),
20 o_ (nullptr)
24 be_visitor_root_ch::~be_visitor_root_ch ()
28 int
29 be_visitor_root_ch::visit_root (be_root *node)
31 if (this->init () == -1)
33 ACE_ERROR_RETURN ((LM_ERROR,
34 ACE_TEXT ("be_visitor_root_ch::init - ")
35 ACE_TEXT ("failed to initialize\n")),
36 -1);
39 this->gen_fwd_decls ();
41 if (this->visit_scope (node) == -1)
43 ACE_ERROR_RETURN ((LM_ERROR,
44 ACE_TEXT ("be_visitor_root_ch::visit_root - ")
45 ACE_TEXT ("codegen for scope failed\n")),
46 -1);
49 if (be_global->gen_arg_traits ())
51 if (this->gen_arg_traits (node) == -1)
53 ACE_ERROR_RETURN ((LM_ERROR,
54 ACE_TEXT ("be_visitor_root_ch::")
55 ACE_TEXT ("visit_root - failed to ")
56 ACE_TEXT ("generate stub arg traits\n")),
57 -1);
61 this->gen_ref_counting_overrides ();
63 this->gen_static_corba_overrides ();
65 if (this->gen_obv_decls (node) == -1)
67 ACE_ERROR_RETURN ((LM_ERROR,
68 ACE_TEXT ("be_visitor_root_ch::")
69 ACE_TEXT ("visit_root - ")
70 ACE_TEXT ("failed to generate OBV_ decls\n")),
71 -1);
74 if (this->gen_object_traits (node) == -1)
76 ACE_ERROR_RETURN ((LM_ERROR,
77 ACE_TEXT ("be_visitor_root_ch::")
78 ACE_TEXT ("visit_root - failed to ")
79 ACE_TEXT ("generate object traits\n")),
80 -1);
84 if (this->gen_template_exports (node) == -1)
86 ACE_ERROR_RETURN ((LM_ERROR,
87 ACE_TEXT ("be_visitor_root::")
88 ACE_TEXT ("visit_root - ")
89 ACE_TEXT ("failed to export templates\n")),
90 -1);
93 if (this->gen_any_ops (node) == -1)
95 ACE_ERROR_RETURN ((LM_ERROR,
96 ACE_TEXT ("be_visitor_root_ch::")
97 ACE_TEXT ("visit_root - failed to ")
98 ACE_TEXT ("generate Any operators\n")),
99 -1);
103 if (this->gen_cdr_ops (node) == -1)
105 ACE_ERROR_RETURN ((LM_ERROR,
106 ACE_TEXT ("be_visitor_root_ch::")
107 ACE_TEXT ("visit_root - failed to ")
108 ACE_TEXT ("generate CDR operators\n")),
109 -1);
113 (void) tao_cg->end_client_header ();
115 return 0;
119 be_visitor_root_ch::init ()
121 /// First open the client-side file for writing
122 int status =
123 tao_cg->start_client_header (
124 be_global->be_get_client_hdr_fname ());
126 if (status == -1)
128 ACE_ERROR_RETURN ((LM_ERROR,
129 ACE_TEXT ("be_visitor_root_ch::init - ")
130 ACE_TEXT ("Error opening client header file\n")),
131 -1);
134 /// Initialize the stream.
135 this->ctx_->stream (tao_cg->client_header ());
137 this->o_ = this->ctx_->stream ();
139 return 0;
143 be_visitor_root_ch::gen_arg_traits (be_root *node)
145 be_visitor_context ctx = *this->ctx_;
146 be_visitor_arg_traits arg_visitor ("", &ctx);
147 return node->accept (&arg_visitor);
150 void
151 be_visitor_root_ch::gen_fwd_decls ()
153 if (idl_global->non_local_iface_seen_)
155 TAO_INSERT_COMMENT (o_);
157 *o_ << be_global->core_versioning_begin () << be_nl;
159 *o_ << be_nl_2
160 << "namespace TAO" << be_nl
161 << "{" << be_idt_nl;
163 if (idl_global->abstract_iface_seen_)
165 *o_ << "template<typename T> class AbstractBase_Narrow_Utils;" << be_nl;
168 *o_ << "template<typename T> class Narrow_Utils;" << be_uidt_nl
169 << "}" ;
171 *o_ << be_global->core_versioning_end () << be_nl;
175 void
176 be_visitor_root_ch::gen_ref_counting_overrides ()
178 size_t size = be_global->non_defined_interfaces.size ();
180 if (size == 0)
182 return;
185 size_t index = 0;
186 be_interface_fwd *ifwd = nullptr;
188 TAO_INSERT_COMMENT (o_);
190 for (index = 0; index < size; ++index)
192 be_global->non_defined_interfaces.dequeue_head (ifwd);
194 *o_ << be_nl_2;
196 if (ifwd->is_valuetype ())
198 *o_ << "// External declarations for undefined valuetype"
199 << be_nl_2
200 << "// " << ifwd->full_name () << be_nl;
202 *o_ << be_global->stub_export_macro () << be_nl
203 << "void" << be_nl
204 << "tao_" << ifwd->flat_name ()
205 << "_add_ref ("
206 << be_idt << be_idt_nl
207 << ifwd->full_name () << " *" << be_uidt_nl
208 << ");" << be_uidt_nl << be_nl
209 << be_global->stub_export_macro () << be_nl
210 << "void" << be_nl
211 << "tao_" << ifwd->flat_name ()
212 << "_remove_ref (" << be_idt << be_idt_nl
213 << ifwd->full_name () << " *" << be_uidt_nl
214 << ");" << be_uidt;
219 void
220 be_visitor_root_ch::gen_static_corba_overrides ()
222 size_t size = idl_global->mixed_parentage_interfaces ().size ();
224 if (size == 0)
226 return;
229 size_t index = 0;
230 AST_Interface *i = nullptr;
232 TAO_INSERT_COMMENT (o_);
234 *o_ << be_global->core_versioning_begin ();
236 *o_ << be_nl
237 << "// Overrides of CORBA::release and CORBA::is_nil for"
238 << be_nl
239 << "// interfaces that inherit from both CORBA::Object" << be_nl
240 << "// and CORBA::AbstractBase." << be_nl_2
241 << "namespace CORBA" << be_nl
242 << "{" << be_idt;
244 for (index = 0; index < size; ++index)
246 idl_global->mixed_parentage_interfaces ().dequeue_head (i);
248 *o_ << be_nl
249 << "extern " << be_global->stub_export_macro () << " void release ("
250 << i->name () << "_ptr);" << be_nl
251 << "extern " << be_global->stub_export_macro () << " ::CORBA::Boolean is_nil ("
252 << i->name () << "_ptr);";
255 *o_ << be_uidt_nl
256 << "}";
258 *o_ << be_global->core_versioning_end ();
262 be_visitor_root_ch::gen_obv_decls (be_root *node)
264 be_visitor_context ctx = *this->ctx_;
265 ctx.state (TAO_CodeGen::TAO_MODULE_OBV_CH);
267 be_visitor_obv_module obv_visitor (&ctx);
269 return obv_visitor.visit_scope (node);
273 be_visitor_root_ch::gen_object_traits (be_root *node)
275 be_visitor_context ctx = *this->ctx_;
276 be_visitor_traits traits_visitor (&ctx);
277 return node->accept (&traits_visitor);
281 be_visitor_root_ch::gen_template_exports (be_root *node)
283 if (! be_global->gen_template_export ())
285 return 0;
288 be_visitor_context ctx = *this->ctx_;
289 be_visitor_template_export export_visitor (&ctx);
290 return node->accept (&export_visitor);
294 be_visitor_root_ch::gen_any_ops (be_root *node)
296 int status = 0;
298 if (be_global->any_support ())
300 be_visitor_context ctx = *this->ctx_;
301 ctx.state (TAO_CodeGen::TAO_ROOT_ANY_OP_CH);
302 be_visitor_root_any_op any_op_visitor (&ctx);
303 status = node->accept (&any_op_visitor);
306 /// Conditional switch to the *A.h stream is done
307 /// in the visitor constructor.
308 if (be_global->gen_anyop_files ())
310 (void) tao_cg->end_anyop_header ();
313 return status;
317 be_visitor_root_ch::gen_cdr_ops (be_root *node)
319 int status = 0;
321 if (be_global->cdr_support ())
323 be_visitor_context ctx = *this->ctx_;
324 ctx.state (TAO_CodeGen::TAO_ROOT_CDR_OP_CH);
325 be_visitor_root_cdr_op visitor (&ctx);
326 status = node->accept (&visitor);
329 return status;