Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / TAO / TAO_IDL / be / be_visitor_sequence / sequence_cs.cpp
blob5994c5bef8ee2c3977134762e16ec7f81fef0251
2 //=============================================================================
3 /**
4 * @file sequence_cs.cpp
6 * Visitor generating code for Sequences in the client stubs file
8 * @author Aniruddha Gokhale
9 */
10 //=============================================================================
12 #include "sequence.h"
14 // ************************************************************
15 // Root visitor for client stub class
16 // ************************************************************
18 be_visitor_sequence_cs::be_visitor_sequence_cs (be_visitor_context *ctx)
19 : be_visitor_decl (ctx)
23 be_visitor_sequence_cs::~be_visitor_sequence_cs ()
27 int be_visitor_sequence_cs::visit_sequence (be_sequence *node)
29 // First create a name for ourselves.
30 if (node->create_name (this->ctx_->tdef ()) == -1)
32 ACE_ERROR_RETURN ((LM_ERROR,
33 ACE_TEXT ("be_visitor_sequence_cs::")
34 ACE_TEXT ("visit_sequence - ")
35 ACE_TEXT ("failed creating name\n")),
36 -1);
39 // We don't check cli_stub_gen() here. If we are generated more
40 // than once as an anonymous sequence, the name guard will cause
41 // the C++ preprocessor to catch it. If we are generated more than
42 // once as a typedef (caused by a comma separated list of
43 // typedefs), our name will be changed by the call above and the
44 // name guard will not catch it, but that's ok - we want to
45 // be generated for each typedef.
46 if (node->imported ())
48 return 0;
51 if (idl_global->dcps_sequence_type_defined (node->full_name ()))
53 return 0;
56 be_type *bt = dynamic_cast<be_type*> (node->base_type ());
58 if (bt == nullptr)
60 ACE_ERROR_RETURN ((LM_ERROR,
61 ACE_TEXT ("be_visitor_sequence_cs::")
62 ACE_TEXT ("visit_sequence - ")
63 ACE_TEXT ("Bad element type\n")),
64 -1);
67 AST_Decl::NodeType nt = bt->node_type ();
69 // If our base type is an anonymous sequence, we must create a name
70 // and generate a class declaration for it as well.
71 if (nt == AST_Decl::NT_sequence)
73 // Temporarily make the context's tdef node 0 so the nested call
74 // to create_name will not get confused and give our anonymous
75 // sequence element type the same name as we have.
76 be_typedef *tmp = this->ctx_->tdef ();
77 this->ctx_->tdef (nullptr);
79 if (bt->accept (this) != 0)
81 ACE_ERROR_RETURN ((LM_ERROR,
82 ACE_TEXT ("be_visitor_sequence_cs::")
83 ACE_TEXT ("visit_sequence - ")
84 ACE_TEXT ("codegen for anonymous ")
85 ACE_TEXT ("base type failed\n")),
86 -1);
89 // Restore the tdef value.
90 this->ctx_->tdef (tmp);
93 if (be_global->alt_mapping () && node->unbounded ())
95 // We are just a typedef and don't need any stub source
96 // code generation.
97 return 0;
100 TAO_OutStream *os = this->ctx_->stream ();
102 *os << be_nl_2;
104 TAO_INSERT_COMMENT (os);
106 os->gen_ifdef_macro (node->flat_name ());
108 // for unbounded sequences, we have a different set of constructors
109 if (node->unbounded ())
111 *os << be_nl_2
112 << node->name () << "::" << node->local_name () << " ("
113 << be_idt << be_idt_nl
114 << "::CORBA::ULong max)" << be_uidt_nl
115 << ": " << be_idt;
117 int status =
118 node->gen_base_class_name (os,
120 this->ctx_->scope ()->decl ());
122 // Pass it to the base constructor.
123 if (status == -1)
125 ACE_ERROR_RETURN ((LM_ERROR,
126 ACE_TEXT ("be_visitor_sequence_cs::")
127 ACE_TEXT ("visit_sequence - ")
128 ACE_TEXT ("codegen for base ")
129 ACE_TEXT ("sequence class failed\n")),
130 -1);
134 *os << " (max)" << be_uidt << be_uidt_nl
135 << "{}";
138 /// If we are using std::vector, we can't implement this
139 /// constructor.
140 if (!be_global->alt_mapping () || !node->unbounded ())
142 // Constructor with the buffer
143 *os << be_nl_2
144 << node->name () << "::" << node->local_name () << " ("
145 << be_idt << be_idt_nl;
147 if (node->unbounded ())
149 // Unbounded seq takes this extra parameter.
150 *os << "::CORBA::ULong max," << be_nl;
153 *os << "::CORBA::ULong length," << be_nl;
155 // generate the base type for the buffer
156 be_visitor_context ctx (*this->ctx_);
157 be_visitor_sequence_buffer_type bt_visitor (&ctx);
159 if (bt->accept (&bt_visitor) == -1)
161 ACE_ERROR_RETURN ((LM_ERROR,
162 ACE_TEXT ("be_visitor_sequence_cs::")
163 ACE_TEXT ("visit_sequence - ")
164 ACE_TEXT ("base type visit failed\n")),
165 -1);
168 *os << " * buffer," << be_nl
169 << "::CORBA::Boolean release)" << be_uidt
170 << be_uidt_nl
171 << " : " << be_idt << be_idt;
173 // Pass it to the base constructor.
174 if (node->gen_base_class_name (os,
176 this->ctx_->scope ()->decl ()) == -1)
178 ACE_ERROR_RETURN ((LM_ERROR,
179 ACE_TEXT ("be_visitor_sequence_cs::")
180 ACE_TEXT ("visit_sequence - ")
181 ACE_TEXT ("codegen for base ")
182 ACE_TEXT ("sequence class\n")),
183 -1);
186 *os << be_nl << "(";
188 if (node->unbounded ())
190 *os << "max, ";
193 *os << "length, buffer, release)" << be_uidt << be_uidt_nl
194 << "{}";
197 if (be_global->alt_mapping () && node->unbounded ())
199 *os << be_nl_2
200 << "::CORBA::ULong" << be_nl
201 << node->name () << "::length () const" << be_nl
202 << "{" << be_idt_nl
203 << "return this->size ();" << be_uidt_nl
204 << "}";
206 *os << be_nl_2
207 << "void" << be_nl
208 << node->name () << "::length (::CORBA::ULong length)"
209 << be_nl
210 << "{" << be_idt_nl
211 << "this->resize (length);" << be_uidt_nl
212 << "}";
214 *os << be_nl_2
215 << "::CORBA::ULong" << be_nl
216 << node->name () << "::maximum () const" << be_nl
217 << "{" << be_idt_nl
218 << "return this->capacity ();" << be_uidt_nl
219 << "}";
222 if (be_global->any_support ()
223 && !node->anonymous ()
224 && (!node->is_local ()
225 || be_global->gen_local_iface_anyops ()))
227 *os << be_nl_2
228 << "void "
229 << node->name () << "::_tao_any_destructor ("
230 << be_idt << be_idt_nl
231 << "void * _tao_void_pointer)" << be_uidt << be_uidt_nl
232 << "{" << be_idt_nl
233 << node->local_name () << " * _tao_tmp_pointer ="
234 << be_idt_nl
235 << "static_cast<" << node->local_name ()
236 << " *> (_tao_void_pointer);" << be_uidt_nl
237 << "delete _tao_tmp_pointer;" << be_uidt_nl
238 << "}";
241 os->gen_endif ();
243 node->cli_stub_gen (true);
244 return 0;