2 //=============================================================================
4 * @file sequence_cs.cpp
6 * Visitor generating code for Sequences in the client stubs file
8 * @author Aniruddha Gokhale
10 //=============================================================================
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")),
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 ())
51 if (idl_global
->dcps_sequence_type_defined (node
->full_name ()))
56 be_type
*bt
= dynamic_cast<be_type
*> (node
->base_type ());
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")),
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 ();
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")),
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
100 TAO_OutStream
*os
= this->ctx_
->stream ();
104 TAO_INSERT_COMMENT (os
);
106 os
->gen_ifdef_macro (node
->flat_name ());
108 // default constructor
110 << node
->name () << "::" << node
->local_name ()
111 << " (void)" << be_nl
114 // for unbounded sequences, we have a different set of constructors
115 if (node
->unbounded ())
118 << node
->name () << "::" << node
->local_name () << " ("
119 << be_idt
<< be_idt_nl
120 << "::CORBA::ULong max)" << be_uidt_nl
124 node
->gen_base_class_name (os
,
126 this->ctx_
->scope ()->decl ());
128 // Pass it to the base constructor.
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")),
140 *os
<< " (max)" << be_uidt
<< be_uidt_nl
144 /// If we are using std::vector, we can't implement this
146 if (!be_global
->alt_mapping () || !node
->unbounded ())
148 // Constructor with the buffer
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")),
174 *os
<< " * buffer," << be_nl
175 << "::CORBA::Boolean release)" << be_uidt
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")),
194 if (node
->unbounded ())
199 *os
<< "length, buffer, release)" << be_uidt
<< be_uidt_nl
205 << node
->name () << "::~" << node
->local_name ()
206 << " (void)" << be_nl
209 if (be_global
->alt_mapping () && node
->unbounded ())
212 << "::CORBA::ULong" << be_nl
213 << node
->name () << "::length (void) const" << be_nl
215 << "return this->size ();" << be_uidt_nl
220 << node
->name () << "::length ( ::CORBA::ULong length)"
223 << "this->resize (length);" << be_uidt_nl
227 << "::CORBA::ULong" << be_nl
228 << node
->name () << "::maximum (void) const" << be_nl
230 << "return this->capacity ();" << be_uidt_nl
234 if (be_global
->any_support ()
235 && !node
->anonymous ()
236 && (!node
->is_local ()
237 || be_global
->gen_local_iface_anyops ()))
241 << node
->name () << "::_tao_any_destructor ("
242 << be_idt
<< be_idt_nl
243 << "void * _tao_void_pointer)" << be_uidt
<< be_uidt_nl
245 << node
->local_name () << " * _tao_tmp_pointer ="
247 << "static_cast<" << node
->local_name ()
248 << " *> (_tao_void_pointer);" << be_uidt_nl
249 << "delete _tao_tmp_pointer;" << be_uidt_nl
255 node
->cli_stub_gen (true);