summaryrefslogtreecommitdiff
path: root/TAO/TAO_IDL/be/be_visitor_exception.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'TAO/TAO_IDL/be/be_visitor_exception.cpp')
-rw-r--r--TAO/TAO_IDL/be/be_visitor_exception.cpp290
1 files changed, 290 insertions, 0 deletions
diff --git a/TAO/TAO_IDL/be/be_visitor_exception.cpp b/TAO/TAO_IDL/be/be_visitor_exception.cpp
new file mode 100644
index 00000000000..5b633b93b6f
--- /dev/null
+++ b/TAO/TAO_IDL/be/be_visitor_exception.cpp
@@ -0,0 +1,290 @@
+//
+// $Id$
+//
+
+// ============================================================================
+//
+// = LIBRARY
+// TAO IDL
+//
+// = FILENAME
+// be_visitor_exception.cpp
+//
+// = DESCRIPTION
+// Visitors for generation of code for Exception
+//
+// = AUTHOR
+// Aniruddha Gokhale
+//
+// ============================================================================
+
+#include "idl.h"
+#include "idl_extern.h"
+#include "be.h"
+
+#include "be_visitor_exception.h"
+
+// generic struct visitor
+be_visitor_exception::be_visitor_exception (be_visitor_context *ctx)
+ : be_visitor_scope (ctx)
+{
+}
+
+be_visitor_exception::~be_visitor_exception (void)
+{
+}
+
+// visit the Exception node and its scope
+int
+be_visitor_exception::visit_exception (be_exception *node)
+{
+ return -1; // must be overriden
+}
+
+int
+be_visitor_exception::visit_field (be_field *node)
+{
+ // instantiate a visitor context with a copy of our context. This info
+ // will be modified based on what type of node we are visiting
+ be_visitor_context ctx (*this->ctx_);
+ ctx.node (node); // set the node to be the node being visited. The scope is
+ // still the same
+
+ // this switch is acceptable rather than having derived visitors overriding
+ // this method and differing only in what state they set
+
+ switch (this->ctx_->state ())
+ {
+ case TAO_CodeGen::TAO_STRUCT_CH:
+ ctx.state (TAO_CodeGen::TAO_FIELD_CH);
+ break;
+ case TAO_CodeGen::TAO_STRUCT_CI:
+ ctx.state (TAO_CodeGen::TAO_FIELD_CI);
+ break;
+ case TAO_CodeGen::TAO_STRUCT_CS:
+ ctx.state (TAO_CodeGen::TAO_FIELD_CS);
+ break;
+ default:
+ {
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "(%N:%l) be_visitor_exception::"
+ "visit_field - "
+ "Bad context state\n"
+ ), -1);
+ }
+ break;
+ }
+
+ be_visitor *visitor = tao_cg->make_visitor (&ctx);
+ if (!visitor)
+ {
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "(%N:%l) be_visitor_exception::"
+ "visit_field - "
+ "NUL visitor\n"
+ ), -1);
+ }
+
+ // let the node accept this visitor
+ if (node->accept (visitor) == -1)
+ {
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "(%N:%l) be_visitor_exception::"
+ "visit_field - "
+ "failed to accept visitor\n"
+ ), -1);
+ }
+ delete visitor;
+ return 0;
+}
+
+// ******************************************************
+// for client header
+// ******************************************************
+
+be_visitor_exception_ch::be_visitor_exception_ch (be_visitor_context *ctx)
+ : be_visitor_exception (ctx)
+{
+}
+
+be_visitor_exception_ch::~be_visitor_exception_ch (void)
+{
+}
+
+// visit the Exception node and its scope
+int be_visitor_exception_ch::visit_exception (be_exception *node)
+{
+ TAO_OutStream *os; // output stream
+
+ if (!node->cli_hdr_gen ()) // not already generated
+ {
+ os = this->ctx_->stream ();
+
+ os->indent (); // start from whatever indentation level we were at
+ *os << "struct " << node->local_name () << be_nl
+ << "{\n" << be_idt;
+
+ // generate code for field members
+ if (this->visit_scope (node) == -1)
+ {
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "(%N:%l) be_visitor_exception_ch::"
+ "visit_exception - "
+ "codegen for scope failed\n"), -1);
+ }
+
+ os->decr_indent ();
+ *os << "};\n\n";
+
+ // generate var defn
+ if (node->gen_var_defn () == -1)
+ {
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "(%N:%l) be_visitor_exception_ch::"
+ "visit_exception - "
+ "codegen for _var failed\n"), -1);
+ }
+
+ // a class is generated for an out defn only for a variable length struct
+ if (node->size_type () == be_decl::VARIABLE)
+ {
+ if (node->gen_out_defn () == -1)
+ {
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "(%N:%l) be_visitor_exception_ch::"
+ "visit_exception - "
+ "codegen for _out failed\n"), -1);
+ }
+ }
+ else
+ {
+ os->indent ();
+ *os << "typedef " << node->local_name () << " &" << node->local_name
+ () << "_out;\n\n";
+ }
+
+ // generate the typecode decl
+ if (node->is_nested ())
+ {
+ // we have a scoped name
+ os->indent ();
+
+ *os << "static CORBA::TypeCode_ptr " << node->tc_name
+ ()->last_component () << ";\n\n";
+ }
+ else
+ {
+ // we are in the ROOT scope
+ os->indent ();
+ *os << "extern CORBA::TypeCode_ptr " << node->tc_name
+ ()->last_component () << ";\n\n";
+ }
+ node->cli_hdr_gen (I_TRUE);
+ }
+ return 0;
+}
+
+// ******************************************************
+// for client inline
+// ******************************************************
+
+be_visitor_exception_ci::be_visitor_exception_ci (be_visitor_context *ctx)
+ : be_visitor_exception (ctx)
+{
+}
+
+be_visitor_exception_ci::~be_visitor_exception_ci (void)
+{
+}
+
+// visit the Exception node and its scope
+int be_visitor_exception_ci::visit_exception (be_exception *node)
+{
+ if (!node->cli_inline_gen ())
+ {
+ if (node->gen_var_impl () == -1)
+ {
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "(%N:%l) be_visitor_exception_ci::"
+ "visit_exception - "
+ "codegen for _var failed\n"), -1);
+ }
+ if (node->size_type () == be_decl::VARIABLE &&
+ node->gen_out_impl () == -1)
+ {
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "(%N:%l) be_visitor_exception_ci::"
+ "visit_exception - "
+ "codegen for _out failed\n"), -1);
+ }
+ // all we have to do is to visit the scope
+ if (this->visit_scope (node) == -1)
+ {
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "(%N:%l) be_visitor_exception_ci::"
+ "visit_exception - "
+ "codegen for scope failed\n"), -1);
+ }
+ node->cli_inline_gen (I_TRUE);
+ }
+ return 0;
+}
+
+// for client stubs
+be_visitor_exception_cs::be_visitor_exception_cs (be_visitor_context *ctx)
+ : be_visitor_exception (ctx)
+{
+}
+
+be_visitor_exception_cs::~be_visitor_exception_cs (void)
+{
+}
+
+// visit the Exception_Cs node and its scope
+int be_visitor_exception_cs::visit_exception (be_exception *node)
+{
+ TAO_OutStream *os; // output stream
+
+ if (!node->cli_stub_gen ())
+ {
+ os = this->ctx_->stream ();
+
+ // generate the typecode information here
+ os->indent (); // start from current indentation level
+ *os << "static const CORBA::Long _oc_" << node->flatname () << "[] =" <<
+ be_nl;
+ *os << "{\n";
+ os->incr_indent (0);
+ // note that we just need the parameters here and hence we generate the
+ // encapsulation for the parameters
+ if (node->gen_encapsulation () == -1)
+ {
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "(%N:%l) be_visitor_exception_cs::"
+ "visit_exception - "
+ "codegen for typecode failed\n"), -1);
+ }
+ os->decr_indent ();
+ *os << "};" << be_nl;
+
+ *os << "static CORBA::TypeCode _tc__tc_" << node->flatname () <<
+ " (CORBA::tk_struct, sizeof (_oc_" << node->flatname () <<
+ "), (unsigned char *) &_oc_" << node->flatname () <<
+ ", CORBA::B_FALSE);" << be_nl;
+ *os << "CORBA::TypeCode_ptr " << node->tc_name () << " = &_tc__tc_" <<
+ node->flatname () << ";\n\n";
+
+ // do any code generation required for the scope members
+ // all we have to do is to visit the scope
+ if (this->visit_scope (node) == -1)
+ {
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "(%N:%l) be_visitor_exception_cs::"
+ "visit_exception - "
+ "codegen for scope failed\n"), -1);
+ }
+ node->cli_stub_gen (I_TRUE);
+ }
+
+ return 0;
+}