2 //=============================================================================
4 * @file exception_cs.cpp
6 * Visitor generating code for Exception in the stubs file
8 * @author Aniruddha Gokhale
10 //=============================================================================
12 #include "exception.h"
13 #include "be_visitor_typecode/typecode_defn.h"
15 // ***************************************************************************
17 // ***************************************************************************
19 be_visitor_exception_cs::be_visitor_exception_cs (be_visitor_context
*ctx
)
20 : be_visitor_exception (ctx
)
24 be_visitor_exception_cs::~be_visitor_exception_cs ()
28 // Visit the Exception_Cs node and its scope.
29 int be_visitor_exception_cs::visit_exception (be_exception
*node
)
31 if (node
->cli_stub_gen () || node
->imported ())
36 TAO_OutStream
*os
= this->ctx_
->stream ();
40 // Generate stub code required of any anonymous types of members.
41 if (this->visit_scope (node
) == -1)
43 ACE_ERROR_RETURN ((LM_ERROR
,
44 ACE_TEXT ("be_visitor_exception::")
45 ACE_TEXT ("visit_exception - ")
46 ACE_TEXT ("code for stub failed\n")),
50 be_visitor_context
ctx (*this->ctx_
);
52 // Constructor taking all members. It exists only if there are any
54 if (node
->member_count () > 0)
56 // Generate the signature.
57 ctx
.state (TAO_CodeGen::TAO_EXCEPTION_CTOR_CS
);
58 be_visitor_exception_ctor
ec_visitor (&ctx
);
60 if (node
->accept (&ec_visitor
) == -1)
62 ACE_ERROR_RETURN ((LM_ERROR
,
63 ACE_TEXT ("be_visitor_exception::")
64 ACE_TEXT ("visit_exception - ")
65 ACE_TEXT ("codegen for ctor failed\n")),
70 << ": ::CORBA::UserException ("
71 << be_idt
<< be_idt
<< be_idt_nl
72 << "\"" << node
->repoID () << "\"," << be_nl
73 << "\"" << node
->local_name () << "\")" << be_uidt
74 << be_uidt
<< be_uidt
<< be_uidt_nl
;
77 // Assign each individual member. We need yet another state.
80 // Indicate that the special ctor is being generated.
83 be_visitor_exception_ctor_assign
eca_visitor (&ctx
);
85 if (node
->accept (&eca_visitor
) == -1)
87 ACE_ERROR_RETURN ((LM_ERROR
,
88 ACE_TEXT ("be_visitor_exception_cs::")
89 ACE_TEXT ("visit_exception - ")
90 ACE_TEXT ("codegen for scope failed\n")),
94 *os
<< be_uidt_nl
<< "}" << be_nl_2
;
97 TAO_INSERT_COMMENT (os
);
99 // Default constructor.
100 *os
<< node
->name () << "::" << node
->local_name ()
101 << " ()" << be_idt_nl
;
102 *os
<< ": ::CORBA::UserException (" << be_idt
<< be_idt
<< be_idt_nl
103 << "\"" << node
->repoID () << "\"," << be_nl
104 << "\"" << node
->local_name () << "\")" << be_uidt
105 << be_uidt
<< be_uidt
<< be_uidt_nl
;
107 *os
<< "}" << be_nl_2
;
110 *os
<< node
->name () << "::" << node
->local_name () << " (const ::"
111 << node
->name () << " &_tao_excp)" << be_idt_nl
;
112 *os
<< ": ::CORBA::UserException (" << be_idt
<< be_idt
<< be_idt_nl
113 << "_tao_excp._rep_id ()," << be_nl
114 << "_tao_excp._name ())" << be_uidt
115 << be_uidt
<< be_uidt
<< be_uidt_nl
;
120 if (node
->nmembers () > 0)
124 // Assign each individual member.
125 be_visitor_exception_ctor_assign
visitor (&ctx
);
127 if (node
->accept (&visitor
) == -1)
129 ACE_ERROR_RETURN ((LM_ERROR
,
130 ACE_TEXT ("be_visitor_exception_cs::")
131 ACE_TEXT ("visit_exception - ")
132 ACE_TEXT ("codegen for scope failed\n")),
140 // Assignment operator.
141 *os
<< node
->name () << "&" << be_nl
;
142 *os
<< node
->name () << "::operator= (const ::"
143 << node
->name () << " &_tao_excp)" << be_nl
145 << "this->::CORBA::UserException::operator= "
148 // Assign each individual member.
150 be_visitor_exception_ctor_assign
ca_visitor (&ctx
);
152 if (node
->accept (&ca_visitor
) == -1)
154 ACE_ERROR_RETURN ((LM_ERROR
,
155 ACE_TEXT ("be_visitor_exception_cs::")
156 ACE_TEXT ("visit_exception - ")
157 ACE_TEXT ("codegen for scope failed\n")),
162 << "return *this;" << be_uidt_nl
165 if (be_global
->any_support ())
169 << "::_tao_any_destructor (void *_tao_void_pointer)" << be_nl
171 << node
->local_name () << " *_tao_tmp_pointer =" << be_idt_nl
173 << node
->local_name () << " *> (_tao_void_pointer);" << be_uidt_nl
174 << "delete _tao_tmp_pointer;" << be_uidt_nl
178 // Non-const downcast method.
179 *os
<< node
->name () << " *" << be_nl
;
180 *os
<< node
->name () << "::_downcast (::CORBA::Exception *_tao_excp)" << be_nl
;
181 *os
<< "{" << be_idt_nl
;
182 *os
<< "return dynamic_cast<" << node
->local_name ()
183 << " *> (_tao_excp);" << be_uidt_nl
;
184 *os
<< "}" << be_nl_2
;
186 // Const downcast method.
187 *os
<< "const " << node
->name () << " *" << be_nl
;
188 *os
<< node
->name () << "::_downcast (::CORBA::Exception const *_tao_excp)"
190 *os
<< "{" << be_idt_nl
;
191 *os
<< "return dynamic_cast<const " << node
->local_name ()
192 << " *> (_tao_excp);" << be_uidt_nl
;
193 *os
<< "}" << be_nl_2
;
195 // Generate the _alloc method.
196 *os
<< "::CORBA::Exception *" << node
->name ()
197 << "::_alloc ()" << be_nl
;
198 *os
<< "{" << be_idt_nl
;
199 *os
<< "::CORBA::Exception *retval {};" << be_nl
200 << "ACE_NEW_RETURN (retval, ::" << node
->name ()
201 << ", nullptr);" << be_nl
202 << "return retval;" << be_uidt_nl
;
203 *os
<< "}" << be_nl_2
;
205 *os
<< "::CORBA::Exception *" << be_nl
206 << node
->name () << "::_tao_duplicate () const" << be_nl
208 << "::CORBA::Exception *result {};" << be_nl
209 << "ACE_NEW_RETURN (result, "
210 << "::" << node
->name () << " (*this), nullptr);"
212 << "return result;" << be_uidt_nl
215 *os
<< "void " << node
->name () << "::_raise () const" << be_nl
217 << "throw *this;" << be_uidt_nl
220 *os
<< "void " << node
->name ()
221 << "::_tao_encode (";
223 if (!node
->is_local ())
225 *os
<< "TAO_OutputCDR &cdr) const" << be_nl
227 << "if (!(cdr << *this))" << be_idt_nl
229 << "throw ::CORBA::MARSHAL ();" << be_uidt_nl
230 << "}" << be_uidt
<< be_uidt_nl
;
232 *os
<< "}" << be_nl_2
;
236 *os
<< "TAO_OutputCDR &) const" << be_nl
239 *os
<< "throw ::CORBA::MARSHAL ();" << be_uidt_nl
;
241 *os
<< "}" << be_nl_2
;
244 *os
<< "void " << node
->name ()
245 << "::_tao_decode (";
247 if (!node
->is_local ())
249 *os
<< "TAO_InputCDR &cdr)" << be_nl
251 << "if (!(cdr >> *this))" << be_idt_nl
253 << "throw ::CORBA::MARSHAL ();" << be_uidt_nl
254 << "}" << be_uidt
<< be_uidt_nl
;
256 *os
<< "}" << be_nl_2
;
260 *os
<< "TAO_InputCDR &)" << be_nl
263 *os
<< "throw ::CORBA::MARSHAL ();" << be_uidt_nl
;
265 *os
<< "}" << be_nl_2
;
268 if ((ACE_OS::strcmp (node
->full_name (), "CORBA::InvalidPolicies") == 0) ||
269 (ACE_OS::strcmp (node
->full_name (), "CORBA::PolicyError") == 0))
271 *os
<< "// TAO extension - the virtual _type method." << be_nl
272 << "::CORBA::TypeCode_ptr " << node
->name ()
273 << "::_tao_type () const" << be_nl
275 << "TAO_AnyTypeCode_Adapter *adapter =" << be_idt_nl
276 << "ACE_Dynamic_Service<TAO_AnyTypeCode_Adapter>::instance ("
277 << "\"AnyTypeCode_Adapter\");" << be_uidt_nl
278 << "if (!adapter)" << be_idt_nl
280 // FUZZ: disable check_for_ace_log_categories
281 << "TAOLIB_ERROR_RETURN ((LM_ERROR," << be_idt_nl
282 // FUZZ: enable check_for_ace_log_categories
283 << "ACE_TEXT (\"TAO \")," << be_nl
284 << "ACE_TEXT (\"Unable to find the \")" << be_nl
285 << "ACE_TEXT (\"AnyTypeCode Adapter instance\")), 0);" << be_uidt
<< be_uidt_nl
287 << "return adapter->_tao_type_" << node
->local_name () << "();" << be_uidt_nl
291 // Switch streams to the *A.cpp file if we are using this option.
292 if (be_global
->gen_anyop_files ())
294 os
= tao_cg
->anyop_source ();
298 if ((ACE_OS::strcmp (node
->full_name (), "CORBA::InvalidPolicies") != 0) &&
299 (ACE_OS::strcmp (node
->full_name (), "CORBA::PolicyError") != 0))
301 if (be_global
->tc_support ())
303 *os
<< "// TAO extension - the virtual _type method." << be_nl
;
304 *os
<< "::CORBA::TypeCode_ptr " << node
->name ()
305 << "::_tao_type () const" << be_nl
;
306 *os
<< "{" << be_idt_nl
;
307 *os
<< "return ::" << node
->tc_name () << ";" << be_uidt_nl
;
312 if (be_global
->tc_support ())
315 TAO::be_visitor_struct_typecode
tc_visitor (&ctx
);
317 if (tc_visitor
.visit_exception (node
) == -1)
319 ACE_ERROR_RETURN ((LM_ERROR
,
320 ACE_TEXT ("be_visitor_exception_cs::")
321 ACE_TEXT ("visit_exception - ")
322 ACE_TEXT ("TypeCode definition failed\n")),
327 node
->cli_stub_gen (true);