Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / TAO_IDL / be / be_visitor_sequence / sequence_cs.cpp
blobeafe28cf8dbcaf8295b0db4ff9a7eec99dbc2ee5
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 (void)
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 == 0)
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 (0);
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 // default constructor
109 *os << be_nl_2
110 << node->name () << "::" << node->local_name ()
111 << " (void)" << be_nl
112 << "{}";
114 // for unbounded sequences, we have a different set of constructors
115 if (node->unbounded ())
117 *os << be_nl_2
118 << node->name () << "::" << node->local_name () << " ("
119 << be_idt << be_idt_nl
120 << "::CORBA::ULong max)" << be_uidt_nl
121 << ": " << be_idt;
123 int status =
124 node->gen_base_class_name (os,
126 this->ctx_->scope ()->decl ());
128 // Pass it to the base constructor.
129 if (status == -1)
131 ACE_ERROR_RETURN ((LM_ERROR,
132 ACE_TEXT ("be_visitor_sequence_cs::")
133 ACE_TEXT ("visit_sequence - ")
134 ACE_TEXT ("codegen for base ")
135 ACE_TEXT ("sequence class failed\n")),
136 -1);
140 *os << " (max)" << be_uidt << be_uidt_nl
141 << "{}";
144 /// If we are using std::vector, we can't implement this
145 /// constructor.
146 if (!be_global->alt_mapping () || !node->unbounded ())
148 // Constructor with the buffer
149 *os << be_nl_2
150 << node->name () << "::" << node->local_name () << " ("
151 << be_idt << be_idt_nl;
153 if (node->unbounded ())
155 // Unbounded seq takes this extra parameter.
156 *os << "::CORBA::ULong max," << be_nl;
159 *os << "::CORBA::ULong length," << be_nl;
161 // generate the base type for the buffer
162 be_visitor_context ctx (*this->ctx_);
163 be_visitor_sequence_buffer_type bt_visitor (&ctx);
165 if (bt->accept (&bt_visitor) == -1)
167 ACE_ERROR_RETURN ((LM_ERROR,
168 ACE_TEXT ("be_visitor_sequence_cs::")
169 ACE_TEXT ("visit_sequence - ")
170 ACE_TEXT ("base type visit failed\n")),
171 -1);
174 *os << " * buffer," << be_nl
175 << "::CORBA::Boolean release)" << be_uidt
176 << be_uidt_nl
177 << " : " << be_idt << be_idt;
179 // Pass it to the base constructor.
180 if (node->gen_base_class_name (os,
182 this->ctx_->scope ()->decl ()) == -1)
184 ACE_ERROR_RETURN ((LM_ERROR,
185 ACE_TEXT ("be_visitor_sequence_cs::")
186 ACE_TEXT ("visit_sequence - ")
187 ACE_TEXT ("codegen for base ")
188 ACE_TEXT ("sequence class\n")),
189 -1);
192 *os << be_nl << "(";
194 if (node->unbounded ())
196 *os << "max, ";
199 *os << "length, buffer, release)" << be_uidt << be_uidt_nl
200 << "{}";
203 // Destructor.
204 *os << be_nl_2
205 << node->name () << "::~" << node->local_name ()
206 << " (void)" << be_nl
207 << "{}";
209 if (be_global->alt_mapping () && node->unbounded ())
211 *os << be_nl_2
212 << "::CORBA::ULong" << be_nl
213 << node->name () << "::length (void) const" << be_nl
214 << "{" << be_idt_nl
215 << "return this->size ();" << be_uidt_nl
216 << "}";
218 *os << be_nl_2
219 << "void" << be_nl
220 << node->name () << "::length ( ::CORBA::ULong length)"
221 << be_nl
222 << "{" << be_idt_nl
223 << "this->resize (length);" << be_uidt_nl
224 << "}";
226 *os << be_nl_2
227 << "::CORBA::ULong" << be_nl
228 << node->name () << "::maximum (void) const" << be_nl
229 << "{" << be_idt_nl
230 << "return this->capacity ();" << be_uidt_nl
231 << "}";
234 if (be_global->any_support ()
235 && !node->anonymous ()
236 && (!node->is_local ()
237 || be_global->gen_local_iface_anyops ()))
239 *os << be_nl_2
240 << "void "
241 << node->name () << "::_tao_any_destructor ("
242 << be_idt << be_idt_nl
243 << "void * _tao_void_pointer)" << be_uidt << be_uidt_nl
244 << "{" << be_idt_nl
245 << node->local_name () << " * _tao_tmp_pointer ="
246 << be_idt_nl
247 << "static_cast<" << node->local_name ()
248 << " *> (_tao_void_pointer);" << be_uidt_nl
249 << "delete _tao_tmp_pointer;" << be_uidt_nl
250 << "}";
253 os->gen_endif ();
255 node->cli_stub_gen (true);
256 return 0;