2 //=============================================================================
4 * @file sequence_ch.cpp
6 * Visitor generating code for Sequence in the client header
8 * @author Aniruddha Gokhale
10 //=============================================================================
14 // Root visitor for client header.
15 be_visitor_sequence_ch::be_visitor_sequence_ch (be_visitor_context
*ctx
)
16 : be_visitor_decl (ctx
)
20 be_visitor_sequence_ch::~be_visitor_sequence_ch (void)
24 int be_visitor_sequence_ch::visit_sequence (be_sequence
*node
)
26 if (node
->defined_in () == 0)
28 // The node is a nested sequence, and has had no scope defined.
29 node
->set_defined_in (DeclAsScope (this->ctx_
->scope ()->decl ()));
32 // First create a name for ourselves.
33 if (node
->create_name (this->ctx_
->tdef ()) == -1)
35 ACE_ERROR_RETURN ((LM_ERROR
,
36 ACE_TEXT ("be_visitor_sequence_ch::")
37 ACE_TEXT ("visit_sequence - ")
38 ACE_TEXT ("failed creating name\n")),
42 // We don't check cli_hdr_gen() here. If we are generated more
43 // than once as an anonymous sequence, the name guard will cause
44 // the C++ preprocessor to catch it. If we are generated more than
45 // once as a typedef (caused by a comma separated list of
46 // typedefs), our name will be changed by the call above and the
47 // name guard will not catch it, but that's ok - we want to
48 // be generated for each typedef.
49 if (node
->imported ())
54 TAO_OutStream
*os
= this->ctx_
->stream ();
56 // Retrieve the base type since we may need to do some code
57 // generation for the base type.
58 be_type
*bt
= dynamic_cast<be_type
*> (node
->base_type ());
62 ACE_ERROR_RETURN ((LM_ERROR
,
63 ACE_TEXT ("be_visitor_sequence_ch::")
64 ACE_TEXT ("visit_sequence - ")
65 ACE_TEXT ("Bad element type\n")),
69 bt
->seen_in_sequence (true);
70 AST_Decl::NodeType nt
= bt
->node_type ();
72 // If our base type is an anonymous sequence, we must create a name
73 // and generate a class declaration for it as well.
74 if (nt
== AST_Decl::NT_sequence
)
76 // Temporarily make the context's tdef node 0 so the nested call
77 // to create_name will not get confused and give our anonymous
78 // sequence element type the same name as we have.
79 be_typedef
*tmp
= this->ctx_
->tdef ();
82 if (bt
->accept (this) != 0)
84 ACE_ERROR_RETURN ((LM_ERROR
,
85 ACE_TEXT ("be_visitor_sequence_ch::")
86 ACE_TEXT ("visit_sequence - ")
87 ACE_TEXT ("codegen for anonymous ")
88 ACE_TEXT ("base type failed\n")),
92 // Restore the tdef value.
93 this->ctx_
->tdef (tmp
);
98 TAO_INSERT_COMMENT (os
);
100 if (idl_global
->dcps_sequence_type_defined (node
->full_name ()))
102 // Special Implementation for OpenDDS
104 << "typedef ::TAO::DCPS::ZeroCopyDataSeq< "
105 << node
->base_type ()->full_name ()
106 << ", DCPS_ZERO_COPY_SEQ_DEFAULT_SIZE> "
107 << node
->original_local_name ()
112 os
->gen_ifdef_macro (node
->flat_name ());
116 /// If we are using std::vector, we won't be using _vars
117 /// and _outs. They may get redefined and reinstated later.
118 if (!be_global
->alt_mapping () || !node
->unbounded ())
120 if (this->ctx_
->tdef () != 0)
122 *os
<< "class " << node
->local_name () << ";";
125 if (this->ctx_
->tdef () != 0)
127 this->gen_varout_typedefs (node
, bt
);
132 *os
<< "typedef std::vector< ";
134 // Generate the base type for the buffer.
135 be_visitor_context
ctx (*this->ctx_
);
136 ctx
.state (TAO_CodeGen::TAO_SEQUENCE_BUFFER_TYPE_CH
);
137 be_visitor_sequence_buffer_type
bt_visitor (&ctx
);
139 if (bt
->accept (&bt_visitor
) == -1)
141 ACE_ERROR_RETURN ((LM_ERROR
,
142 ACE_TEXT ("be_visitor_sequence_ch::")
143 ACE_TEXT ("visit_sequence - ")
144 ACE_TEXT ("buffer type visit failed\n")),
148 *os
<< "> " << node
->local_name () << ";";
151 node
->cli_hdr_gen (true);
156 << "class " << be_global
->stub_export_macro () << " "
157 << node
->local_name () << be_idt_nl
158 << ": public" << be_idt
<< be_idt_nl
;
161 node
->gen_base_class_name (os
,
163 this->ctx_
->scope ()->decl ());
167 ACE_ERROR_RETURN ((LM_ERROR
,
168 ACE_TEXT ("be_visitor_sequence_ch::")
169 ACE_TEXT ("visit_sequence - ")
170 ACE_TEXT ("Base class name ")
171 ACE_TEXT ("generation failed\n")),
175 *os
<< be_uidt
<< be_uidt
<< be_uidt
;
179 << "public:" << be_idt
;
182 << node
->local_name () << " (void);";
184 if (node
->unbounded ())
187 << node
->local_name () << " ( ::CORBA::ULong max);";
190 /// If we are using std::vector, we can't implement this
192 if (!be_global
->alt_mapping () || !node
->unbounded ())
195 << node
->local_name () << " (" << be_idt
;
197 if (node
->unbounded ())
200 << "::CORBA::ULong max,";
204 << "::CORBA::ULong length," << be_nl
;
206 // Generate the base type for the buffer.
207 be_visitor_context
ctx (*this->ctx_
);
208 ctx
.state (TAO_CodeGen::TAO_SEQUENCE_BUFFER_TYPE_CH
);
209 be_visitor_sequence_buffer_type
bt_visitor (&ctx
);
211 if (bt
->accept (&bt_visitor
) == -1)
213 ACE_ERROR_RETURN ((LM_ERROR
,
214 ACE_TEXT ("be_visitor_sequence_ch::")
215 ACE_TEXT ("visit_sequence - ")
216 ACE_TEXT ("buffer type visit failed\n")),
220 *os
<< "* buffer," << be_nl
221 << "::CORBA::Boolean release = false);" << be_uidt
;
224 // Default copy/move constructor and assignment operators
225 *os
<< "\n#if defined (ACE_HAS_CPP11)" << be_nl
226 << node
->local_name () << " (const " << node
->local_name () << " &) = default;" << be_nl
227 << node
->local_name () << " (" << node
->local_name () << " &&) = default;" << be_nl
228 << node
->local_name () << "& operator= (const " << node
->local_name () << " &) = default;" << be_nl
229 << node
->local_name () << "& operator= (" << node
->local_name () << " &&) = default;"
230 << "\n#endif /* ACE_HAS_CPP11 */" << be_nl
;
232 *os
<< "virtual ~" << node
->local_name () << " (void);";
234 if (be_global
->alt_mapping () && node
->unbounded ())
237 << "virtual ::CORBA::ULong length (void) const;"
239 << "virtual void length (::CORBA::ULong);"
241 << "virtual ::CORBA::ULong maximum (void) const;";
246 node
->gen_stub_decls (os
);
248 // TAO provides extensions for octet sequences, first find out if
249 // the base type is an octet (or an alias for octet).
250 be_predefined_type
*predef
= 0;
252 if (bt
->base_node_type () == AST_Type::NT_pre_defined
)
255 dynamic_cast<be_typedef
*> (bt
);
259 predef
= dynamic_cast<be_predefined_type
*> (bt
);
264 dynamic_cast<be_predefined_type
*> (
265 alias
->primitive_base_type ()
270 // Now generate the extension...
272 && predef
->pt () == AST_PredefinedType::PT_octet
273 && node
->unbounded ()
274 && !be_global
->alt_mapping ())
277 << "\n#if (TAO_NO_COPY_OCTET_SEQUENCES == 1)" << be_nl
278 << node
->local_name () << " (::CORBA::ULong length, const ACE_Message_Block* mb)"
280 << ": ::TAO::unbounded_value_sequence< ::CORBA::Octet>"
281 << " (length, mb) {}" << be_uidt_nl
282 << "\n#endif /* TAO_NO_COPY_OCTET_SEQUENCE == 1 */";
291 node
->cli_hdr_gen (true);
296 be_visitor_sequence_ch::gen_varout_typedefs (be_sequence
*node
,
299 TAO_OutStream
*os
= this->ctx_
->stream ();
303 AST_Type::SIZE_TYPE st
= elem
->size_type ();
306 << (st
== AST_Type::FIXED
? "::TAO_FixedSeq_Var_T<"
307 : "::TAO_VarSeq_Var_T<")
308 << node
->local_name ();
311 << node
->local_name () << "_var;" << be_nl
;
313 *os
<< "typedef ::TAO_Seq_Out_T<"
314 << node
->local_name ()
315 << "> " << node
->local_name () << "_out;" << be_nl
;