cdr_op_ci.cpp
来自「这是广泛使用的通信开源项目,对于大容量,高并发的通讯要求完全能够胜任,他广泛可用」· C++ 代码 · 共 1,029 行 · 第 1/3 页
CPP
1,029 行
//
// cdr_op_ci.cpp,v 1.21 2003/10/28 18:30:38 bala Exp
//
// ============================================================================
//
// = LIBRARY
// TAO IDL
//
// = FILENAME
// union_branch_cdr_op_ci.cpp
//
// = DESCRIPTION
// Visitor generating code for Union_Branch in the client stubs file.
//
// = AUTHOR
// Aniruddha Gokhale
//
// ============================================================================
ACE_RCSID (be_visitor_union_branch,
cdr_op_ci,
"cdr_op_ci.cpp,v 1.21 2003/10/28 18:30:38 bala Exp")
// **********************************************
// Visitor for union_branch in the client stubs file.
// **********************************************
be_visitor_union_branch_cdr_op_ci::be_visitor_union_branch_cdr_op_ci (
be_visitor_context *ctx
)
: be_visitor_decl (ctx)
{
}
be_visitor_union_branch_cdr_op_ci::~be_visitor_union_branch_cdr_op_ci (void)
{
}
// Visit the union_branch node.
int
be_visitor_union_branch_cdr_op_ci::visit_union_branch (be_union_branch *node)
{
be_type *bt = be_type::narrow_from_decl (node->field_type ());
if (!bt)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_union_branch_cdr_op_ci::"
"visit_union_branch - "
"Bad union_branch type\n"),
-1);
}
this->ctx_->node (node);
if (bt->accept (this) == -1)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_union_branch_cdr_op_ci::"
"visit_union_branch - "
"codegen for union_branch type failed\n"),
-1);
}
return 0;
}
int
be_visitor_union_branch_cdr_op_ci::visit_array (be_array *node)
{
TAO_OutStream *os = this->ctx_->stream ();
// Retrieve the union_branch node.
be_union_branch *f = this->ctx_->be_node_as_union_branch ();
if (!f)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_union_branch_cdr_op_ci::"
"visit_array - "
"cannot retrieve union_branch node\n"),
-1);
}
// For anonymous arrays, the type name has a _ prepended. We compute the
// fullname with or without the underscore and use it later on.
char fname [NAMEBUFSIZE]; // to hold the full and
// Save the node's local name and full name in a buffer for quick
// use later on.
ACE_OS::memset (fname,
'\0',
NAMEBUFSIZE);
if (!this->ctx_->alias () // not a typedef
&& node->is_child (this->ctx_->scope ()))
{
// For anonymous arrays ...
// we have to generate a name for us that has an underscore
// prepended to our local name. This needs to be inserted after
// the parents's name.
if (node->is_nested ())
{
be_decl *parent =
be_scope::narrow_from_scope (node->defined_in ())->decl ();
ACE_OS::sprintf (fname,
"%s::_%s",
parent->full_name (),
node->local_name ()->get_string ());
}
else
{
ACE_OS::sprintf (fname,
"_%s",
node->full_name ());
}
}
else
{
// Typedefed node.
ACE_OS::sprintf (fname, "%s", node->full_name ());
}
// Check what is the code generations substate. Are we generating code for
// the in/out operators for our parent or for us?
switch (this->ctx_->sub_state ())
{
case TAO_CodeGen::TAO_CDR_INPUT:
*os << fname << " _tao_union_tmp;" << be_nl
<< fname << "_forany _tao_union_helper ("
<< be_idt << be_idt_nl
<< "_tao_union_tmp" << be_uidt_nl
<< ");" << be_uidt_nl
<< "result = strm >> _tao_union_helper;" << be_nl << be_nl
<< "if (result)" << be_idt_nl
<< "{" << be_idt_nl
<< "_tao_union." << f->local_name ()
<< " (_tao_union_tmp);" << be_nl
<< "_tao_union._d (_tao_discriminant);" << be_uidt_nl
<< "}" << be_uidt;
return 0;
case TAO_CodeGen::TAO_CDR_OUTPUT:
*os << fname << "_forany _tao_union_tmp (" << be_idt << be_idt_nl
<< "_tao_union."
<< f->local_name () << " ()" << be_uidt_nl
<<");" << be_uidt_nl
<< "result = strm << _tao_union_tmp;";
return 0;
case TAO_CodeGen::TAO_CDR_SCOPE:
// This is done in cdr_op_cs.cpp and hacked into *.i.
break;
default:
// Error.
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_union_branch_cdr_op_ci::"
"visit_array - "
"bad sub state\n"),
-1);
}
// If not a typedef and we are defined in the use scope, we must be defined.
if (!this->ctx_->alias () // not a typedef
&& node->is_child (this->ctx_->scope ()))
{
// This is the case for anonymous arrays.
// 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);
// First generate the declaration.
be_visitor_array_cdr_op_ci visitor (&ctx);
if (visitor.visit_array (node) == -1)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_union_branch_cdr_op_ci::"
"visit_array - "
"codegen failed\n"),
-1);
}
}
return 0;
}
int
be_visitor_union_branch_cdr_op_ci::visit_enum (be_enum *node)
{
TAO_OutStream *os = this->ctx_->stream ();
// Retrieve the union_branch node
be_union_branch *f = this->ctx_->be_node_as_union_branch ();
if (!f)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_union_branch_cdr_op_ci::"
"visit_array - "
"cannot retrieve union_branch node\n"),
-1);
}
// Check what is the code generations substate. Are we generating code for
// the in/out operators for our parent or for us?
switch (this->ctx_->sub_state ())
{
case TAO_CodeGen::TAO_CDR_INPUT:
*os << node->name () << " _tao_union_tmp"
<< ";" << be_nl
<< "result = strm >> _tao_union_tmp;" << be_nl
<< "if (result)" << be_idt_nl
<< "{" << be_idt_nl
<< "_tao_union." << f->local_name ()
<< " (_tao_union_tmp);" << be_nl
<< "_tao_union._d (_tao_discriminant);" << be_uidt_nl
<< "}" << be_uidt;
return 0;
case TAO_CodeGen::TAO_CDR_OUTPUT:
*os << "result = strm << _tao_union." << f->local_name () << " ();";
return 0;
case TAO_CodeGen::TAO_CDR_SCOPE:
// Proceed further.
break;
default:
// Error.
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_union_branch_cdr_op_ci::"
"visit_enum - "
"bad sub state\n"),
-1);
}
// Not a typedef and node is defined inside the union. Otherwise the cdr
// operator is generated elsewhere.
if (node->node_type () != AST_Decl::NT_typedef
&& node->is_child (this->ctx_->scope ()))
{
// 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);
be_visitor_enum_cdr_op_ci visitor (&ctx);
if (visitor.visit_enum (node) == -1)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_union_branch_cdr_op_ci::"
"visit_enum - "
"codegen failed\n"),
-1);
}
}
return 0;
}
int
be_visitor_union_branch_cdr_op_ci::visit_interface (be_interface *node)
{
TAO_OutStream *os = this->ctx_->stream ();
// Retrieve the union_branch node.
be_union_branch *f = this->ctx_->be_node_as_union_branch ();
if (!f)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_union_branch_cdr_op_ci::"
"visit_interface - "
"cannot retrieve union_branch node\n"),
-1);
}
// Check what is the code generations substate. Are we generating code for
// the in/out operators for our parent or for us?
switch (this->ctx_->sub_state ())
{
case TAO_CodeGen::TAO_CDR_INPUT:
if (node->is_local ())
{
*os << "result = 0;";
}
else
{
*os << node->name () << "_var _tao_union_tmp;" << be_nl
<< "result = strm >> _tao_union_tmp.inout ();" << be_nl << be_nl
<< "if (result)" << be_idt_nl
<< "{" << be_idt_nl
<< "_tao_union."
<< f->local_name () << " (_tao_union_tmp.in ());" << be_nl
<< "_tao_union._d (_tao_discriminant);" << be_uidt_nl
<< "}" << be_uidt;
}
break;
case TAO_CodeGen::TAO_CDR_OUTPUT:
if (node->is_defined ())
{
*os << "result = _tao_union."
<< f->local_name () << " ()->marshal (strm);";
}
else
{
*os << "result =" << be_idt_nl
<< "TAO::Objref_Traits<" << node->name () << ">::tao_marshal ("
<< be_idt << be_idt_nl
<< "_tao_union." << f->local_name () << " ()," << be_nl
<< "strm" << be_uidt_nl
<< ");" << be_uidt << be_uidt;
}
break;
case TAO_CodeGen::TAO_CDR_SCOPE:
// Nothing to be done because an interface cannot be declared inside a
// union.
break;
default:
// Error.
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_union_branch_cdr_op_ci::"
"visit_interface - "
"bad sub state\n"),
-1);
}
return 0;
}
int
be_visitor_union_branch_cdr_op_ci::visit_interface_fwd (be_interface_fwd *node)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?