Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / TAO_IDL / be / be_visitor_sequence / sequence_ch.cpp
blob9000e7f433b97e72441ac7bad733a5893f0c5129
2 //=============================================================================
3 /**
4 * @file sequence_ch.cpp
6 * Visitor generating code for Sequence in the client header
8 * @author Aniruddha Gokhale
9 */
10 //=============================================================================
12 #include "sequence.h"
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")),
39 -1);
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 ())
51 return 0;
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 ());
60 if (bt == 0)
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")),
66 -1);
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 ();
80 this->ctx_->tdef (0);
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")),
89 -1);
92 // Restore the tdef value.
93 this->ctx_->tdef (tmp);
96 *os << be_nl_2;
98 TAO_INSERT_COMMENT (os);
100 if (idl_global->dcps_sequence_type_defined (node->full_name ()))
102 // Special Implementation for OpenDDS
103 *os << be_nl_2
104 << "typedef ::TAO::DCPS::ZeroCopyDataSeq< "
105 << node->base_type ()->full_name ()
106 << ", DCPS_ZERO_COPY_SEQ_DEFAULT_SIZE> "
107 << node->original_local_name ()
108 << ";" << be_nl;
110 else
112 os->gen_ifdef_macro (node->flat_name ());
114 *os << be_nl_2;
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);
130 else
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")),
145 -1);
148 *os << "> " << node->local_name () << ";";
150 os->gen_endif ();
151 node->cli_hdr_gen (true);
152 return 0;
155 *os << be_nl_2
156 << "class " << be_global->stub_export_macro () << " "
157 << node->local_name () << be_idt_nl
158 << ": public" << be_idt << be_idt_nl;
160 int status =
161 node->gen_base_class_name (os,
163 this->ctx_->scope ()->decl ());
165 if (status == -1)
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")),
172 -1);
175 *os << be_uidt << be_uidt << be_uidt;
177 *os << be_nl
178 << "{" << be_nl
179 << "public:" << be_idt;
181 *os << be_nl
182 << node->local_name () << " (void);";
184 if (node->unbounded ())
186 *os << be_nl
187 << node->local_name () << " ( ::CORBA::ULong max);";
190 /// If we are using std::vector, we can't implement this
191 /// constructor.
192 if (!be_global->alt_mapping () || !node->unbounded ())
194 *os << be_nl
195 << node->local_name () << " (" << be_idt;
197 if (node->unbounded ())
199 *os << be_nl
200 << "::CORBA::ULong max,";
203 *os << be_nl
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")),
217 -1);
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 ())
236 *os << be_nl_2
237 << "virtual ::CORBA::ULong length (void) const;"
238 << be_nl
239 << "virtual void length (::CORBA::ULong);"
240 << be_nl_2
241 << "virtual ::CORBA::ULong maximum (void) const;";
244 *os << be_nl;
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)
254 be_typedef* alias =
255 dynamic_cast<be_typedef*> (bt);
257 if (alias == 0)
259 predef = dynamic_cast<be_predefined_type*> (bt);
261 else
263 predef =
264 dynamic_cast<be_predefined_type*> (
265 alias->primitive_base_type ()
270 // Now generate the extension...
271 if (predef != 0
272 && predef->pt () == AST_PredefinedType::PT_octet
273 && node->unbounded ()
274 && !be_global->alt_mapping ())
276 *os << be_nl_2
277 << "\n#if (TAO_NO_COPY_OCTET_SEQUENCES == 1)" << be_nl
278 << node->local_name () << " (::CORBA::ULong length, const ACE_Message_Block* mb)"
279 << be_idt_nl
280 << ": ::TAO::unbounded_value_sequence< ::CORBA::Octet>"
281 << " (length, mb) {}" << be_uidt_nl
282 << "\n#endif /* TAO_NO_COPY_OCTET_SEQUENCE == 1 */";
285 *os << be_uidt_nl
286 << "};";
288 os->gen_endif ();
291 node->cli_hdr_gen (true);
292 return 0;
295 void
296 be_visitor_sequence_ch::gen_varout_typedefs (be_sequence *node,
297 be_type *elem)
299 TAO_OutStream *os = this->ctx_->stream ();
301 *os << be_nl;
303 AST_Type::SIZE_TYPE st = elem->size_type ();
305 *os << "typedef "
306 << (st == AST_Type::FIXED ? "::TAO_FixedSeq_Var_T<"
307 : "::TAO_VarSeq_Var_T<")
308 << node->local_name ();
310 *os << "> "
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;