1 //=============================================================================
7 * Visitor for Array code generation in client header
9 * @author Aniruddha Gokhale
11 //=============================================================================
15 be_visitor_array_ch::be_visitor_array_ch (be_visitor_context
*ctx
)
16 : be_visitor_array (ctx
)
20 int be_visitor_array_ch::visit_array (be_array
*node
)
22 TAO_OutStream
*os
= this->ctx_
->stream ();
23 be_decl
*scope
= this->ctx_
->scope ()->decl ();
25 // Nothing to do if we are imported or code is already generated.
26 if (node
->imported () || node
->cli_hdr_gen ())
31 this->ctx_
->node (node
);
34 be_type
*bt
= dynamic_cast<be_type
*> (node
->base_type ());
38 ACE_ERROR_RETURN ((LM_ERROR
,
39 "(%N:%l) be_visitor_array_ch::"
45 AST_Decl::NodeType nt
= bt
->node_type ();
47 TAO_INSERT_COMMENT (os
);
49 // If we contain an anonymous sequence,
50 // generate code for the sequence here.
51 if (nt
== AST_Decl::NT_sequence
)
53 if (this->gen_anonymous_base_type (bt
,
54 TAO_CodeGen::TAO_ROOT_CH
)
57 ACE_ERROR_RETURN ((LM_ERROR
,
58 "(%N:%l) be_visitor_array_ch::"
60 "gen_anonymous_base_type failed\n"),
65 // If the array is an anonymous member and if its element type
66 // is a declaration (not a reference), we must generate code for
68 if (this->ctx_
->alias () == nullptr // Not a typedef.
69 && bt
->is_child (this->ctx_
->scope ()->decl ()))
72 be_visitor_context
ctx (*this->ctx_
);
76 case AST_Decl::NT_enum
:
78 be_visitor_enum_ch
ec_visitor (&ctx
);
79 status
= bt
->accept (&ec_visitor
);
82 case AST_Decl::NT_struct
:
84 be_visitor_structure_ch
sc_visitor (&ctx
);
85 status
= bt
->accept (&sc_visitor
);
88 case AST_Decl::NT_union
:
90 be_visitor_union_ch
uc_visitor (&ctx
);
91 status
= bt
->accept (&uc_visitor
);
100 ACE_ERROR_RETURN ((LM_ERROR
,
101 "(%N:%l) be_visitor_array_ch::"
103 "array base type codegen failed\n"),
111 if (bt
->accept (this) == -1)
113 ACE_ERROR_RETURN ((LM_ERROR
,
114 "be_visitor_array_ch::"
116 "base type decl failed\n"),
122 be_typedef
*td
= this->ctx_
->tdef ();
126 // We are dealing with an anonymous array case. Generate a typedef with
127 // an _ prepended to the name.
131 *os
<< node
->local_name ();
133 if (node
->gen_dimensions (os
) == -1)
135 ACE_ERROR_RETURN ((LM_ERROR
,
136 "be_visitor_array_ch::"
138 "gen dimensions failed\n"),
144 // Now define the slice type and other required operations
147 if (bt
->accept (this) == -1)
149 ACE_ERROR_RETURN ((LM_ERROR
,
150 "be_visitor_array_ch::"
152 "base type decl failed\n"),
159 ACE_OS::memset (anon_p
,
163 if (this->ctx_
->tdef () != nullptr)
169 ACE_OS::sprintf (anon_p
,
173 *os
<< anon_p
<< node
->local_name () << "_slice";
175 if (node
->gen_dimensions (os
, 1) == -1)
177 ACE_ERROR_RETURN ((LM_ERROR
,
178 ACE_TEXT ("be_visitor_array_ch::")
179 ACE_TEXT ("visit_array - ")
180 ACE_TEXT ("gen slice dimensions failed\n")),
187 << "struct " << anon_p
<< node
->nested_type_name (scope
, "_tag")
190 // No _var or _out class for an anonymous (non-typedef'd) array.
193 // Generate _var class decl.
194 // An _out decl is generated only for a variable size array.
195 if (node
->size_type () == AST_Type::VARIABLE
)
198 << "typedef" << be_idt_nl
199 << "TAO_VarArray_Var_T<" << be_idt
<< be_idt_nl
200 << node
->local_name () << "," << be_nl
201 << node
->local_name () << "_slice," << be_nl
202 << node
->local_name () << "_tag" << be_uidt_nl
204 << node
->local_name () << "_var;" << be_uidt
;
207 << "typedef" << be_idt_nl
208 << "TAO_Array_Out_T<" << be_idt
<< be_idt_nl
209 << node
->local_name () << "," << be_nl
210 << node
->local_name () << "_var," << be_nl
211 << node
->local_name () << "_slice," << be_nl
212 << node
->local_name () << "_tag" << be_uidt_nl
214 << node
->local_name () << "_out;" << be_uidt
;
219 << "typedef" << be_idt_nl
220 << "TAO_FixedArray_Var_T<" << be_idt
<< be_idt_nl
221 << node
->local_name () << "," << be_nl
222 << node
->local_name () << "_slice," << be_nl
223 << node
->local_name () << "_tag" << be_uidt_nl
225 << node
->local_name () << "_var;" << be_uidt
;
228 << "typedef" << be_idt_nl
<< node
->local_name () << be_nl
229 << node
->local_name () << "_out;" << be_uidt
;
233 // Generate _forany decl.
235 << "typedef" << be_idt_nl
236 << "TAO_Array_Forany_T<" << be_idt
<< be_idt_nl
237 << anon_p
<< node
->local_name () << "," << be_nl
238 << anon_p
<< node
->local_name () << "_slice," << be_nl
239 << anon_p
<< node
->local_name () << "_tag" << be_uidt_nl
241 << anon_p
<< node
->local_name () << "_forany;" << be_uidt
;
245 // The _alloc, _dup, copy, and free methods. If the node is nested, the
246 // methods become static
247 ACE_CString storage_class
;
249 if (node
->is_nested ())
251 if (scope
->node_type () != AST_Decl::NT_module
)
253 storage_class
= "static ";
257 storage_class
= "extern ";
258 storage_class
= storage_class
+ be_global
->stub_export_macro ();
259 storage_class
= storage_class
+ " ";
264 storage_class
= be_global
->stub_export_macro ();
265 storage_class
= storage_class
+ " ";
271 *os
<< storage_class
.c_str() << node
->nested_type_name (scope
, "_slice")
273 *os
<< node
->nested_type_name (scope
, "_alloc") << " ();"
275 *os
<< storage_class
.c_str() << "void" << be_nl
276 << node
->nested_type_name (scope
, "_free")
277 << " (" << be_idt
<< be_idt_nl
;
278 *os
<< node
->nested_type_name (scope
, "_slice")
279 << " *_tao_slice);" << be_uidt
280 << be_uidt_nl
<< be_nl
;
281 *os
<< storage_class
.c_str() << node
->nested_type_name (scope
, "_slice")
283 *os
<< node
->nested_type_name (scope
, "_dup")
284 << " (" << be_idt
<< be_idt_nl
286 *os
<< node
->nested_type_name (scope
, "_slice")
287 << " *_tao_slice);" << be_uidt
288 << be_uidt_nl
<< be_nl
;
289 *os
<< storage_class
.c_str() << "void" << be_nl
290 << node
->nested_type_name (scope
, "_copy")
291 << " (" << be_idt
<< be_idt_nl
;
292 *os
<< node
->nested_type_name (scope
, "_slice") << " *_tao_to," << be_nl
294 *os
<< node
->nested_type_name (scope
, "_slice")
295 << " *_tao_from);" << be_uidt
301 *os
<< storage_class
.c_str() << node
->nested_type_name (scope
, "_slice", "_")
303 *os
<< node
->nested_type_name (scope
, "_alloc", "_")
304 << " ();" << be_nl_2
;
305 *os
<< storage_class
.c_str() << "void" << be_nl
306 << node
->nested_type_name (scope
, "_free", "_")
307 << " (" << be_idt
<< be_idt_nl
;
308 *os
<< node
->nested_type_name (scope
, "_slice", "_")
309 << " *_tao_slice);" << be_uidt
310 << be_uidt_nl
<< be_nl
;
311 *os
<< storage_class
.c_str() << node
->nested_type_name (scope
, "_slice", "_")
313 *os
<< node
->nested_type_name (scope
, "_dup", "_")
314 << " (" << be_idt
<< be_idt_nl
316 *os
<< node
->nested_type_name (scope
, "_slice", "_")
317 << " *_tao_slice);" << be_uidt
318 << be_uidt_nl
<< be_nl
;
319 *os
<< storage_class
.c_str() << "void" << be_nl
320 << node
->nested_type_name (scope
, "_copy", "_")
321 << " (" << be_idt
<< be_idt_nl
;
322 *os
<< node
->nested_type_name (scope
, "_slice", "_")
323 << " *_tao_to," << be_nl
325 *os
<< node
->nested_type_name (scope
, "_slice", "_")
326 << " *_tao_from);" << be_uidt
330 node
->cli_hdr_gen (true);