root.cpp
来自「这是广泛使用的通信开源项目,对于大容量,高并发的通讯要求完全能够胜任,他广泛可用」· C++ 代码 · 共 1,816 行 · 第 1/4 页
CPP
1,816 行
// ============================================================================
//
// = LIBRARY
// TAO IDL
//
// = FILENAME
// root.cpp
//
// = DESCRIPTION
// Visitor generating code for the Root node. This is a generic visitor.
//
// = AUTHOR
// Aniruddha Gokhale
//
// ============================================================================
ACE_RCSID (be_visitor_root,
root,
"root.cpp,v 1.44 2003/12/31 20:25:58 bala Exp")
// Generic Root visitor
be_visitor_root::be_visitor_root (be_visitor_context *ctx)
: be_visitor_scope (ctx)
{
}
be_visitor_root::~be_visitor_root (void)
{
}
// This method must be overridden by the derived root visitors.
int
be_visitor_root::init (void)
{
return -1;
}
int be_visitor_root::visit_root (be_root *node)
{
// Open the appropriate output file based on what state we are in. The
// overridden "init" method of derived classes will do the job.
if (this->init () == -1)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_root::init - "
"failed to initialize context\n"),
-1);
}
int status = 0;
be_visitor_context ctx = *this->ctx_;
switch (this->ctx_->state ())
{
case TAO_CodeGen::TAO_ROOT_CS:
{
be_visitor_arg_traits arg_visitor ("", &ctx);
status = node->accept (&arg_visitor);
if (status == -1)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_root::"
"visit_root - "
"failed to generate stub arg traits\n"),
-1);
}
}
break;
case TAO_CodeGen::TAO_ROOT_SS:
{
if (be_global->gen_thru_poa_collocation ()
|| be_global->gen_direct_collocation ())
{
be_visitor_arg_traits arg_visitor ("", &ctx);
status = node->accept (&arg_visitor);
if (status == -1)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_root::"
"visit_root - "
"failed to generate stub arg traits\n"),
-1);
}
}
}
break;
default:
break;
}
if (this->visit_scope (node) == -1)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_root::visit_root - "
"codegen for scope failed\n"),
-1);
}
TAO_OutStream *os = this->ctx_->stream ();
// If we are generating the client header file, this is the place to
// generate the proxy broker factory function pointer declarations
// and the extern declarations for non-defined interfaces.
if (this->ctx_->state () == TAO_CodeGen::TAO_ROOT_CH)
{
be_interface *i = 0;
be_interface_fwd *ifwd = 0;
size_t index = 0;
size_t size = be_global->non_local_interfaces.size ();
if (size > 0)
{
*os << be_nl << be_nl
<< "// Proxy Broker Factory function pointer declarations."
<< be_nl << be_nl << "// TAO_IDL - Generated from" << be_nl
<< "// " << __FILE__ << ":" << __LINE__;
}
for (index = 0; index < size; ++index)
{
be_global->non_local_interfaces.dequeue_head (i);
*os << be_nl << be_nl
<< "extern " << be_global->stub_export_macro () << be_nl
<< "TAO::Collocation_Proxy_Broker *" << be_nl
<< "(*" << i->flat_client_enclosing_scope ()
<< i->base_proxy_broker_name ()
<< "_Factory_function_pointer) ("
<< be_idt << be_idt_nl
<< "CORBA::Object_ptr obj" << be_uidt_nl
<< ");" << be_uidt;
}
size = be_global->non_defined_interfaces.size ();
if (size > 0)
{
*os << be_nl << be_nl << "// TAO_IDL - Generated from" << be_nl
<< "// " << __FILE__ << ":" << __LINE__;
}
for (index = 0; index < size; ++index)
{
be_global->non_defined_interfaces.dequeue_head (ifwd);
*os << be_nl << be_nl;
if (ifwd->is_valuetype ())
{
*os << "// External declarations for undefined valuetype"
<< be_nl << be_nl
<< "// " << ifwd->full_name () << be_nl;
*os << be_global->stub_export_macro () << be_nl
<< "void" << be_nl
<< "tao_" << ifwd->flat_name ()
<< "_add_ref ("
<< be_idt << be_idt_nl
<< ifwd->full_name () << " *" << be_uidt_nl
<< ");" << be_uidt_nl << be_nl
<< be_global->stub_export_macro () << be_nl
<< "void" << be_nl
<< "tao_" << ifwd->flat_name ()
<< "_remove_ref (" << be_idt << be_idt_nl
<< ifwd->full_name () << " *" << be_uidt_nl
<< ");" << be_uidt;
}
}
size = be_global->mixed_parentage_interfaces.size ();
if (size > 0)
{
*os << be_nl << be_nl << "// TAO_IDL - Generated from" << be_nl
<< "// " << __FILE__ << ":" << __LINE__ << be_nl << be_nl;
*os << "// Overrides of CORBA::release and CORBA::is_nil for"
<< be_nl
<< "// interfaces that inherit from both CORBA::Object" << be_nl
<< "// and CORBA::AbstractBase." << be_nl << be_nl
<< "namespace CORBA" << be_nl
<< "{" << be_idt;
}
for (index = 0; index < size; ++index)
{
be_global->mixed_parentage_interfaces.dequeue_head (i);
*os << be_nl
<< "TAO_NAMESPACE_STORAGE_CLASS void release ("
<< i->name () << "_ptr);" << be_nl
<< "TAO_NAMESPACE_STORAGE_CLASS CORBA::Boolean is_nil ("
<< i->name () << "_ptr);";
}
if (size > 0)
{
*os << be_uidt_nl
<< "}";
}
}
// Make one more pass over the entire tree and generate the OBV_ namespaces
// and OBV_ classes.
idl_bool obv = 1;
status = 0;
switch (this->ctx_->state ())
{
case TAO_CodeGen::TAO_ROOT_CH:
ctx.state (TAO_CodeGen::TAO_MODULE_OBV_CH);
break;
case TAO_CodeGen::TAO_ROOT_CI:
ctx.state (TAO_CodeGen::TAO_MODULE_OBV_CI);
break;
case TAO_CodeGen::TAO_ROOT_CS:
ctx.state (TAO_CodeGen::TAO_MODULE_OBV_CS);
break;
default:
obv = 0;
break;
}
if (obv == 1)
{
be_visitor_obv_module visitor (&ctx);
status = visitor.visit_scope (node);
obv = 0;
if (status == -1)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_root::"
"visit_root - "
"failed to generate OBV_ things\n"),
-1);
}
}
status = 0;
ctx = *this->ctx_;
switch (this->ctx_->state ())
{
case TAO_CodeGen::TAO_ROOT_CH:
{
be_visitor_traits visitor (&ctx);
status = node->accept (&visitor);
if (status == -1)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_root::"
"visit_root - "
"failed to generate traits\n"),
-1);
}
}
break;
default:
break;
}
// The next thing we need to do is make one more pass thru the entire tree
// and generate code for all the <<= and >>= operators for all the
// user-defined types.
ctx = *this->ctx_;
status = 0;
switch (this->ctx_->state ())
{
case TAO_CodeGen::TAO_ROOT_CH:
{
ctx.state (TAO_CodeGen::TAO_ROOT_ANY_OP_CH);
if (be_global->any_support ())
{
if (be_global->gen_anyop_files ())
{
// Switch streams, ctx will be reassigned when this
// pass is done.
ctx.stream (tao_cg->anyop_header ());
}
be_visitor_root_any_op visitor (&ctx);
status = node->accept (&visitor);
if (be_global->gen_anyop_files ())
{
(void) tao_cg->end_anyop_header ();
}
}
break;
}
case TAO_CodeGen::TAO_ROOT_CS:
{
ctx.state (TAO_CodeGen::TAO_ROOT_ANY_OP_CS);
if (be_global->any_support ())
{
if (be_global->gen_anyop_files ())
{
// Switch streams, ctx will be reassigned when this
// pass is done.
ctx.stream (tao_cg->anyop_source ());
}
be_visitor_root_any_op visitor (&ctx);
status = node->accept (&visitor);
if (be_global->gen_anyop_files ())
{
(void) tao_cg->end_anyop_source ();
}
}
break;
}
case TAO_CodeGen::TAO_ROOT_IH:
case TAO_CodeGen::TAO_ROOT_SH:
case TAO_CodeGen::TAO_ROOT_CI:
case TAO_CodeGen::TAO_ROOT_IS:
case TAO_CodeGen::TAO_ROOT_SI:
case TAO_CodeGen::TAO_ROOT_SS:
case TAO_CodeGen::TAO_ROOT_TIE_SH:
break;
default:
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_root::"
"visit_constant - "
"Bad context state\n"),
-1);
}
}
if (status == -1)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_root::"
"visit_root - "
"failed to generate Any operators\n"),
-1);
}
// Make another pass over the entire tree and generate the CDR operators.
ctx = *this->ctx_;
status = 0;
switch (this->ctx_->state ())
{
case TAO_CodeGen::TAO_ROOT_CH:
{
ctx.state (TAO_CodeGen::TAO_ROOT_CDR_OP_CH);
be_visitor_root_cdr_op visitor (&ctx);
status = node->accept (&visitor);
break;
}
case TAO_CodeGen::TAO_ROOT_CI:
{
ctx.state (TAO_CodeGen::TAO_ROOT_CDR_OP_CI);
be_visitor_root_cdr_op visitor (&ctx);
status = node->accept (&visitor);
break;
}
case TAO_CodeGen::TAO_ROOT_CS:
{
ctx.state (TAO_CodeGen::TAO_ROOT_CDR_OP_CS);
be_visitor_root_cdr_op visitor (&ctx);
status = node->accept (&visitor);
break;
}
case TAO_CodeGen::TAO_ROOT_SH:
case TAO_CodeGen::TAO_ROOT_IH:
case TAO_CodeGen::TAO_ROOT_SI:
case TAO_CodeGen::TAO_ROOT_SS:
case TAO_CodeGen::TAO_ROOT_IS:
case TAO_CodeGen::TAO_ROOT_TIE_SH:
break; // nothing to be done
default:
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_root::"
"visit_root - "
"Bad context state\n"),
-1);
}
}
if (status == -1)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_root::"
"visit_root - "
"failed to generate CDR operators\n"),
-1);
}
if (be_global->gen_tmplinst ())
{
if (this->gen_explicit_tmplinst (node, os) != 0)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_root::"
"visit_root - "
"explicit template instantiation "
"generation failed\n"),
-1);
}
}
// Generate any final code such as #endifs and/or EOF newlines.
switch (this->ctx_->state ())
{
case TAO_CodeGen::TAO_ROOT_CH:
(void) tao_cg->end_client_header ();
break;
case TAO_CodeGen::TAO_ROOT_CI:
case TAO_CodeGen::TAO_ROOT_CS:
*os << "\n\n";
break;
case TAO_CodeGen::TAO_ROOT_SH:
(void) tao_cg->end_server_header ();
break;
case TAO_CodeGen::TAO_ROOT_IS:
break;
case TAO_CodeGen::TAO_ROOT_IH:
(void) tao_cg->end_implementation_header (
be_global->be_get_implementation_hdr_fname (0)
);
break;
case TAO_CodeGen::TAO_ROOT_SI:
if (be_global->gen_tie_classes ())
{
(void) tao_cg->end_server_template_inline ();
}
break;
case TAO_CodeGen::TAO_ROOT_SS:
if (be_global->gen_tie_classes ())
{
(void) tao_cg->end_server_template_skeletons ();
}
(void) tao_cg->end_server_skeletons ();
break;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?