Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / TAO_IDL / be / be_visitor_array / array_ch.cpp
blobaf79385e5d5f0855996543c13b0bd8f0eee44722
1 //=============================================================================
2 /**
3 * @file array_ch.cpp
7 * Visitor for Array code generation in client header
9 * @author Aniruddha Gokhale
11 //=============================================================================
13 #include "array.h"
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 ())
28 return 0;
31 this->ctx_->node (node);
33 // Retrieve the type.
34 be_type *bt = dynamic_cast<be_type*> (node->base_type ());
36 if (!bt)
38 ACE_ERROR_RETURN ((LM_ERROR,
39 "(%N:%l) be_visitor_array_ch::"
40 "visit_array - "
41 "bad base type\n"),
42 -1);
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)
55 == -1)
57 ACE_ERROR_RETURN ((LM_ERROR,
58 "(%N:%l) be_visitor_array_ch::"
59 "visit_array - "
60 "gen_anonymous_base_type failed\n"),
61 -1);
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
67 // the declaration.
68 if (this->ctx_->alias () == nullptr // Not a typedef.
69 && bt->is_child (this->ctx_->scope ()->decl ()))
71 int status = 0;
72 be_visitor_context ctx (*this->ctx_);
74 switch (nt)
76 case AST_Decl::NT_enum:
78 be_visitor_enum_ch ec_visitor (&ctx);
79 status = bt->accept (&ec_visitor);
80 break;
82 case AST_Decl::NT_struct:
84 be_visitor_structure_ch sc_visitor (&ctx);
85 status = bt->accept (&sc_visitor);
86 break;
88 case AST_Decl::NT_union:
90 be_visitor_union_ch uc_visitor (&ctx);
91 status = bt->accept (&uc_visitor);
92 break;
94 default:
95 break;
98 if (status == -1)
100 ACE_ERROR_RETURN ((LM_ERROR,
101 "(%N:%l) be_visitor_array_ch::"
102 "visit_array - "
103 "array base type codegen failed\n"),
104 -1);
108 *os << be_nl_2
109 << "typedef ";
111 if (bt->accept (this) == -1)
113 ACE_ERROR_RETURN ((LM_ERROR,
114 "be_visitor_array_ch::"
115 "visit_array - "
116 "base type decl failed\n"),
117 -1);
120 *os << " ";
122 be_typedef *td = this->ctx_->tdef ();
124 if (td == nullptr)
126 // We are dealing with an anonymous array case. Generate a typedef with
127 // an _ prepended to the name.
128 *os << "_";
131 *os << node->local_name ();
133 if (node->gen_dimensions (os) == -1)
135 ACE_ERROR_RETURN ((LM_ERROR,
136 "be_visitor_array_ch::"
137 "visit_array - "
138 "gen dimensions failed\n"),
139 -1);
142 *os << ";" << be_nl;
144 // Now define the slice type and other required operations
145 *os << "typedef ";
147 if (bt->accept (this) == -1)
149 ACE_ERROR_RETURN ((LM_ERROR,
150 "be_visitor_array_ch::"
151 "visit_array - "
152 "base type decl failed\n"),
153 -1);
156 *os << " ";
158 char anon_p [2];
159 ACE_OS::memset (anon_p,
160 '\0',
163 if (this->ctx_->tdef () != nullptr)
165 anon_p[0] = '\0';
167 else
169 ACE_OS::sprintf (anon_p,
170 "_");
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")),
181 -1);
184 *os << ";";
186 *os << be_nl
187 << "struct " << anon_p << node->nested_type_name (scope, "_tag")
188 << " {};" << be_nl;
190 // No _var or _out class for an anonymous (non-typedef'd) array.
191 if (td != nullptr)
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)
197 *os << be_nl_2
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
203 << ">" << be_uidt_nl
204 << node->local_name () << "_var;" << be_uidt;
206 *os << be_nl_2
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
213 << ">" << be_uidt_nl
214 << node->local_name () << "_out;" << be_uidt;
216 else
218 *os << be_nl_2
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
224 << ">" << be_uidt_nl
225 << node->local_name () << "_var;" << be_uidt;
227 *os << be_nl_2
228 << "typedef" << be_idt_nl << node->local_name () << be_nl
229 << node->local_name () << "_out;" << be_uidt;
233 // Generate _forany decl.
234 *os << be_nl_2
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
240 << ">" << be_uidt_nl
241 << anon_p << node->local_name () << "_forany;" << be_uidt;
243 *os << be_nl_2;
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 ";
255 else
257 storage_class = "extern ";
258 storage_class = storage_class + be_global->stub_export_macro ();
259 storage_class = storage_class + " ";
262 else
264 storage_class = be_global->stub_export_macro ();
265 storage_class = storage_class + " ";
268 if (td != nullptr)
270 // Typedefed array.
271 *os << storage_class.c_str() << node->nested_type_name (scope, "_slice")
272 << " *" << be_nl;
273 *os << node->nested_type_name (scope, "_alloc") << " ();"
274 << be_nl_2;
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")
282 << " *" << be_nl;
283 *os << node->nested_type_name (scope, "_dup")
284 << " (" << be_idt << be_idt_nl
285 << "const ";
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
293 << "const ";
294 *os << node->nested_type_name (scope, "_slice")
295 << " *_tao_from);" << be_uidt
296 << be_uidt;
298 else
300 // Anonymous array.
301 *os << storage_class.c_str() << node->nested_type_name (scope, "_slice", "_")
302 << " *" << be_nl;
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", "_")
312 << " *" << be_nl;
313 *os << node->nested_type_name (scope, "_dup", "_")
314 << " (" << be_idt << be_idt_nl
315 << "const ";
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
324 << "const ";
325 *os << node->nested_type_name (scope, "_slice", "_")
326 << " *_tao_from);" << be_uidt
327 << be_uidt;
330 node->cli_hdr_gen (true);
331 return 0;