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 ()
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 ();
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")),
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 // for unbounded sequences, we have a different set of constructors
109 if (node
->unbounded ())
112 << node
->name () << "::" << node
->local_name () << " ("
113 << be_idt
<< be_idt_nl
114 << "::CORBA::ULong max)" << be_uidt_nl
118 node
->gen_base_class_name (os
,
120 this->ctx_
->scope ()->decl ());
122 // Pass it to the base constructor.
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")),
134 *os
<< " (max)" << be_uidt
<< be_uidt_nl
138 /// If we are using std::vector, we can't implement this
140 if (!be_global
->alt_mapping () || !node
->unbounded ())
142 // Constructor with the buffer
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")),
168 *os
<< " * buffer," << be_nl
169 << "::CORBA::Boolean release)" << be_uidt
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")),
188 if (node
->unbounded ())
193 *os
<< "length, buffer, release)" << be_uidt
<< be_uidt_nl
197 if (be_global
->alt_mapping () && node
->unbounded ())
200 << "::CORBA::ULong" << be_nl
201 << node
->name () << "::length () const" << be_nl
203 << "return this->size ();" << be_uidt_nl
208 << node
->name () << "::length (::CORBA::ULong length)"
211 << "this->resize (length);" << be_uidt_nl
215 << "::CORBA::ULong" << be_nl
216 << node
->name () << "::maximum () const" << be_nl
218 << "return this->capacity ();" << be_uidt_nl
222 if (be_global
->any_support ()
223 && !node
->anonymous ()
224 && (!node
->is_local ()
225 || be_global
->gen_local_iface_anyops ()))
229 << node
->name () << "::_tao_any_destructor ("
230 << be_idt
<< be_idt_nl
231 << "void * _tao_void_pointer)" << be_uidt
<< be_uidt_nl
233 << node
->local_name () << " * _tao_tmp_pointer ="
235 << "static_cast<" << node
->local_name ()
236 << " *> (_tao_void_pointer);" << be_uidt_nl
237 << "delete _tao_tmp_pointer;" << be_uidt_nl
243 node
->cli_stub_gen (true);