2 //=============================================================================
4 * @file exception_ch.cpp
6 * Visitor generating code for Exception in the client header
8 * @author Aniruddha Gokhale
10 //=============================================================================
12 #include "exception.h"
13 #include "be_visitor_typecode/typecode_decl.h"
14 #include "global_extern.h"
17 // ******************************************************
19 // ******************************************************
21 be_visitor_exception_ch::be_visitor_exception_ch (be_visitor_context
*ctx
)
22 : be_visitor_exception (ctx
)
26 be_visitor_exception_ch::~be_visitor_exception_ch ()
30 // Visit the Exception node and its scope.
31 int be_visitor_exception_ch::visit_exception (be_exception
*node
)
33 if (node
->cli_hdr_gen () || node
->imported ())
38 TAO_OutStream
*os
= this->ctx_
->stream ();
40 TAO_INSERT_COMMENT (os
);
42 *os
<< be_nl_2
<< "class " << be_global
->stub_export_macro ()
43 << " " << node
->local_name ()
44 << " : public ::CORBA::UserException" << be_nl
;
46 << "public:" << be_idt
;
48 // Generate code for field members.
49 if (this->visit_scope (node
) == -1)
51 ACE_ERROR_RETURN ((LM_ERROR
,
52 ACE_TEXT ("be_visitor_exception_ch::")
53 ACE_TEXT ("visit_exception - ")
54 ACE_TEXT ("codegen for scope failed\n")),
58 // Constructors and destructor.
60 << node
->local_name () << " (void);" << be_nl
61 << node
->local_name () << " (const " << node
->local_name ()
63 << "~" << node
->local_name () << " (void);\n" << be_nl
;
65 // Assignment operator.
66 *os
<< node
->local_name () << " &operator= (const "
67 << node
->local_name () << " &);" << be_nl_2
;
69 if (be_global
->any_support ())
71 *os
<< "static void _tao_any_destructor (void *);" << be_nl_2
;
74 *os
<< "static " << node
->local_name ()
75 << " *_downcast ( ::CORBA::Exception *);" << be_nl
76 << "static const " << node
->local_name ()
77 << " *_downcast ( ::CORBA::Exception const *);" << be_nl_2
;
79 *os
<< "static ::CORBA::Exception *_alloc (void);" << be_nl_2
;
81 *os
<< "virtual ::CORBA::Exception *"
82 << "_tao_duplicate (void) const;\n" << be_nl
83 << "virtual void _raise (void) const;\n" << be_nl
84 << "virtual void _tao_encode (TAO_OutputCDR &cdr) const;" << be_nl
85 << "virtual void _tao_decode (TAO_InputCDR &cdr);";
87 // Generate constructor that takes each member as a parameter. We need a
88 // new state. Such a constructor exists if we have members.
89 if (node
->member_count () > 0)
91 be_visitor_context
ctx (*this->ctx_
);
92 ctx
.state (TAO_CodeGen::TAO_EXCEPTION_CTOR_CH
);
93 be_visitor_exception_ctor
visitor (&ctx
);
95 if (node
->accept (&visitor
) == -1)
97 ACE_ERROR_RETURN ((LM_ERROR
,
98 ACE_TEXT ("be_visitor_exception::")
99 ACE_TEXT ("visit_exception - ")
100 ACE_TEXT ("codegen for ctor failed\n")),
105 if (be_global
->tc_support ())
108 << "virtual ::CORBA::TypeCode_ptr _tao_type (void) const;";
111 *os
<< be_uidt_nl
<< "};";
113 if (be_global
->tc_support ())
115 be_visitor_context
ctx (*this->ctx_
);
116 be_visitor_typecode_decl
visitor (&ctx
);
118 if (node
->accept (&visitor
) == -1)
120 ACE_ERROR_RETURN ((LM_ERROR
,
121 ACE_TEXT ("be_visitor_exception_ch::")
122 ACE_TEXT ("visit_exception - ")
123 ACE_TEXT ("TypeCode declaration failed\n")),
128 node
->cli_hdr_gen (1);