cdr_op_ci.cpp
来自「这是广泛使用的通信开源项目,对于大容量,高并发的通讯要求完全能够胜任,他广泛可用」· C++ 代码 · 共 1,019 行 · 第 1/3 页
CPP
1,019 行
// ============================================================================
//
// = LIBRARY
// TAO IDL
//
// = FILENAME
// field_cdr_op_ci.cpp
//
// = DESCRIPTION
// Visitor generating code for Field in the client stubs file.
//
// = AUTHOR
// Aniruddha Gokhale
//
// ============================================================================
#include "be_visitor_array/cdr_op_ci.h"
#include "be_visitor_enum/cdr_op_ci.h"
#include "be_visitor_sequence/cdr_op_ci.h"
#include "be_visitor_structure/cdr_op_ci.h"
#include "be_visitor_union/cdr_op_ci.h"
ACE_RCSID (be_visitor_field,
cdr_op_ci,
"cdr_op_ci.cpp,v 1.15 2003/10/28 18:30:37 bala Exp")
// **********************************************
// Visitor for field in the client stubs file.
// **********************************************
// Constructor.
be_visitor_field_cdr_op_ci::be_visitor_field_cdr_op_ci (
be_visitor_context *ctx
)
: be_visitor_decl (ctx)
{
}
// Destructor.
be_visitor_field_cdr_op_ci::~be_visitor_field_cdr_op_ci (void)
{
}
// Visit the field node.
int
be_visitor_field_cdr_op_ci::visit_field (be_field *node)
{
be_type *bt = be_type::narrow_from_decl (node->field_type ());
if (bt == 0)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_field_cdr_op_ci::"
"visit_field - "
"Bad field type\n"),
-1);
}
// Save the node.
this->ctx_->node (node);
if (bt->accept (this) == -1)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_field_cdr_op_ci::"
"visit_field - "
"codegen for field type failed\n"),
-1);
}
return 0;
}
// Visit array,
int
be_visitor_field_cdr_op_ci::visit_array (be_array *node)
{
TAO_OutStream *os = this->ctx_->stream ();
be_field *f = this->ctx_->be_node_as_field ();
if (f == 0)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_field_cdr_op_ci::"
"visit_array - "
"cannot retrieve field node\n"),
-1);
}
// For anonymous arrays, the type name has a _ prepended. We compute
// the full_name with or without the underscore and use it later on.
char fname [NAMEBUFSIZE];
// 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 () == 0 // 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 generation 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 << "(strm >> "
<< "_tao_aggregate_" << f->local_name () << ")";
return 0;
case TAO_CodeGen::TAO_CDR_OUTPUT:
*os << "(strm << "
<< "_tao_aggregate_" << f->local_name () << ")";
return 0;
case TAO_CodeGen::TAO_CDR_SCOPE:
// This is done in cdr_op_cs and hacked into *.i.
break;
default:
// Error.
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_field_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 () == 0 // Not a typedef.
&& node->is_child (this->ctx_->scope ()))
{
// This is the case for anonymous arrays. Generate the <<, >> operators
// for the type defined by the anonymous array.
// 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_);
// Set the node to be the node being visited. The scope is
// still the same.
ctx.node (node);
// First generate the declaration.
be_visitor_array_cdr_op_ci visitor (&ctx);
if (node->accept (&visitor) == -1)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_field_cdr_op_ci::"
"visit_array - "
"codegen failed\n"),
-1);
}
}
return 0;
}
// Visit enum type.
int
be_visitor_field_cdr_op_ci::visit_enum (be_enum *node)
{
TAO_OutStream *os = this->ctx_->stream ();
// Retrieve the field node.
be_field *f = this->ctx_->be_node_as_field ();
if (f == 0)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_field_cdr_op_ci::"
"visit_array - "
"cannot retrieve field 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 << "(strm >> _tao_aggregate." << f->local_name () << ")";
return 0;
case TAO_CodeGen::TAO_CDR_OUTPUT:
*os << "(strm << _tao_aggregate." << 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_field_cdr_op_ci::"
"visit_enum - "
"bad sub state\n"),
-1);
}
if (node->node_type () != AST_Decl::NT_typedef // Not a typedef.
&& node->is_child (this->ctx_->scope ())) // Node is defined inside
// the structure.
{
// 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_);
// Set the node to be the node being visited. The scope
// is still the same.
ctx.node (node);
// Generate the typcode for enums.
be_visitor_enum_cdr_op_ci visitor (&ctx);
if (node->accept (&visitor) == -1)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_field_cdr_op_ci::"
"visit_enum - "
"codegen failed\n"),
-1);
}
}
return 0;
}
// Visit interface type.
int
be_visitor_field_cdr_op_ci::visit_interface (be_interface *node)
{
TAO_OutStream *os = this->ctx_->stream ();
be_field *f = this->ctx_->be_node_as_field ();
if (!f)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_field_cdr_op_ci::"
"visit_interface - "
"cannot retrieve field 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 << "(strm >> _tao_aggregate." << f->local_name () << ".out ())";
break;
case TAO_CodeGen::TAO_CDR_OUTPUT:
if (node->is_defined ())
{
*os << "CORBA::Object::marshal (" << be_idt << be_idt_nl
<< "_tao_aggregate." << f->local_name () << ".in ()," << be_nl
<< "strm" << be_uidt_nl
<< ")" << be_uidt;
}
else
{
AST_Decl *parent = ScopeAsDecl (node->defined_in ());
if (parent != 0 && parent->node_type () != AST_Decl::NT_root)
{
*os << parent->name () << "::";
}
*os << "TAO::Objref_Traits<" << node->name () << ">::tao_marshal ("
<< be_idt << be_idt_nl
<< "_tao_aggregate." << f->local_name () << ".in ()," << be_nl
<< "strm" << be_uidt_nl
<< ")" << be_uidt;
}
break;
case TAO_CodeGen::TAO_CDR_SCOPE:
// Nothing to be done because an interface cannot be declared inside a
// structure.
break;
default:
// Error.
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_field_cdr_op_ci::"
"visit_interface - "
"bad sub state\n"),
-1);
}
return 0;
}
// Visit interface forward type.
int
be_visitor_field_cdr_op_ci::visit_interface_fwd (be_interface_fwd *node)
{
TAO_OutStream *os = this->ctx_->stream ();
// Retrieve the field node.
be_field *f = this->ctx_->be_node_as_field ();
if (f == 0)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_field_cdr_op_ci::"
"visit_interface_fwd - "
"cannot retrieve field node\n"),
-1);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?