2 //=============================================================================
6 * Visitor generating code for Root in the client header
8 * @author Aniruddha Gokhale
10 //=============================================================================
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
),
24 be_visitor_root_ch::~be_visitor_root_ch ()
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")),
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")),
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")),
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")),
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")),
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")),
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")),
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")),
113 (void) tao_cg
->end_client_header ();
119 be_visitor_root_ch::init ()
121 /// First open the client-side file for writing
123 tao_cg
->start_client_header (
124 be_global
->be_get_client_hdr_fname ());
128 ACE_ERROR_RETURN ((LM_ERROR
,
129 ACE_TEXT ("be_visitor_root_ch::init - ")
130 ACE_TEXT ("Error opening client header file\n")),
134 /// Initialize the stream.
135 this->ctx_
->stream (tao_cg
->client_header ());
137 this->o_
= this->ctx_
->stream ();
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
);
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
;
160 << "namespace TAO" << be_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
171 *o_
<< be_global
->core_versioning_end () << be_nl
;
176 be_visitor_root_ch::gen_ref_counting_overrides ()
178 size_t size
= be_global
->non_defined_interfaces
.size ();
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
);
196 if (ifwd
->is_valuetype ())
198 *o_
<< "// External declarations for undefined valuetype"
200 << "// " << ifwd
->full_name () << be_nl
;
202 *o_
<< be_global
->stub_export_macro () << be_nl
204 << "tao_" << ifwd
->flat_name ()
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
211 << "tao_" << ifwd
->flat_name ()
212 << "_remove_ref (" << be_idt
<< be_idt_nl
213 << ifwd
->full_name () << " *" << be_uidt_nl
220 be_visitor_root_ch::gen_static_corba_overrides ()
222 size_t size
= idl_global
->mixed_parentage_interfaces ().size ();
230 AST_Interface
*i
= nullptr;
232 TAO_INSERT_COMMENT (o_
);
234 *o_
<< be_global
->core_versioning_begin ();
237 << "// Overrides of CORBA::release and CORBA::is_nil for"
239 << "// interfaces that inherit from both CORBA::Object" << be_nl
240 << "// and CORBA::AbstractBase." << be_nl_2
241 << "namespace CORBA" << be_nl
244 for (index
= 0; index
< size
; ++index
)
246 idl_global
->mixed_parentage_interfaces ().dequeue_head (i
);
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);";
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 ())
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
)
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 ();
317 be_visitor_root_ch::gen_cdr_ops (be_root
*node
)
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
);