field_cs.cpp
来自「这是广泛使用的通信开源项目,对于大容量,高并发的通讯要求完全能够胜任,他广泛可用」· C++ 代码 · 共 1,169 行 · 第 1/3 页
CPP
1,169 行
//
// field_cs.cpp,v 1.22 2003/12/09 21:21:36 parsons Exp
//
// ============================================================================
//
// = LIBRARY
// TAO IDL
//
// = FILENAME
// field_cs.cpp
//
// = DESCRIPTION
// Visitor for the Valuetype class.
// This one generates code for accessor and modifier functions of
// valuetype state members (in the stub file).
//
// = AUTHOR
// Torsten Kuepper <kuepper2@lfa.uni-wuppertal.de>
// derived from be_visitor_union_branch/public_ci.cpp
//
// ============================================================================
ACE_RCSID (be_visitor_valuetype,
field_cs,
"field_cs.cpp,v 1.22 2003/12/09 21:21:36 parsons Exp")
be_visitor_valuetype_field_cs::be_visitor_valuetype_field_cs (
be_visitor_context *ctx
)
: be_visitor_decl (ctx),
in_obv_space_ (0)
{
setenclosings ("");
}
be_visitor_valuetype_field_cs::~be_visitor_valuetype_field_cs (void)
{
}
int
be_visitor_valuetype_field_cs::visit_field (be_field *node)
{
be_type *bt = be_type::narrow_from_decl (node->field_type ());
if (!bt)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_field_cs::"
"visit_field - "
"Bad field type\n"),
-1);
}
this->ctx_->node (node);
if (bt->accept (this) == -1)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_field_cs::"
"visit_field - "
"codegen for field type failed\n"),
-1);
}
return 0;
}
// Visit operations on all possible data types that a field can be
int
be_visitor_valuetype_field_cs::visit_array (be_array *node)
{
be_decl *ub = this->ctx_->node ();
be_valuetype *bu = be_valuetype::narrow_from_decl (this->ctx_->scope ());
be_type *bt;
// Check if we are visiting this node via a visit to a typedef node.
if (this->ctx_->alias ())
{
bt = this->ctx_->alias ();
}
else
{
bt = node;
}
if (!ub || !bu)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_valuetype_field_cs::"
"visit_array - "
"bad context information\n"),
-1);
}
TAO_OutStream *os = this->ctx_->stream ();
if (bt->node_type () != AST_Decl::NT_typedef
&& bt->is_child (bu))
{
be_visitor_context ctx (*this->ctx_);
ctx.node (node);
be_visitor_array_cs visitor (&ctx);
if (node->accept (&visitor) == -1)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_valuetype_field_cs::"
"visit_array - "
"codegen failed\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];
ACE_OS::memset (fname,
'\0',
NAMEBUFSIZE);
if (bt->node_type () != AST_Decl::NT_typedef
&& bt->is_child (bu))
{
// For anonymous arrays ...
// We have to generate a name for us that has an underscope prepended to
// our local name. This needs to be inserted after the parent's name.
if (bt->is_nested ())
{
be_decl *parent =
be_scope::narrow_from_scope (bt->defined_in ())->decl ();
ACE_OS::sprintf (fname,
"%s::_%s",
parent->full_name (),
bt->local_name ()->get_string ());
}
else
{
ACE_OS::sprintf (fname,
"_%s",
bt->full_name ());
}
}
else
{
// Typedefed node.
ACE_OS::sprintf (fname,
"%s",
bt->full_name ());
}
*os << be_nl << be_nl << "// TAO_IDL - Generated from" << be_nl
<< "// " << __FILE__ << ":" << __LINE__ << be_nl << be_nl;
*os << "// Accessor to set the member." << be_nl
<< this->pre_op () << "void" << be_nl;
this->op_name (bu,
os);
*os << "::" << ub->local_name () << " (" << fname
<< " val)" << be_nl
<< "{" << be_idt_nl;
*os << fname << "_copy ("
<< bu->field_pd_prefix () << ub->local_name ()
<< bu->field_pd_postfix ()
<< ", val);" << be_uidt_nl;
*os << "}" << be_nl;
*os << "// Retrieve the member." << be_nl
<< this->pre_op () << "const " << fname << "_slice *" << be_nl;
this->op_name (bu,
os);
*os << "::" << ub->local_name () << " (void) const" << be_nl
<< "{" << be_idt_nl;
*os << "return this->"
<< bu->field_pd_prefix () << ub->local_name ()
<< bu->field_pd_postfix () << ";" << be_uidt_nl
<< "}\n" << be_nl;
*os << "// Retrieve the member." << be_nl
<< this->pre_op () << fname << "_slice *" << be_nl;
this->op_name (bu,
os);
*os << "::" << ub->local_name () << " (void)" << be_nl
<< "{" << be_idt_nl;
*os << "return this->"
<< bu->field_pd_prefix () << ub->local_name ()
<< bu->field_pd_postfix () << ";" << be_uidt_nl;
*os << "}";
return 0;
}
int
be_visitor_valuetype_field_cs::visit_enum (be_enum *node)
{
be_decl *ub = this->ctx_->node ();
be_valuetype *bu = be_valuetype::narrow_from_decl (this->ctx_->scope ());
be_type *bt;
// Check if we are visiting this node via a visit to a typedef node.
if (this->ctx_->alias ())
{
bt = this->ctx_->alias ();
}
else
{
bt = node;
}
if (!ub || !bu)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_valuetype_field_cs::"
"visit_enum - "
"bad context information\n"),
-1);
}
TAO_OutStream *os = this->ctx_->stream ();
*os << be_nl << be_nl << "// TAO_IDL - Generated from" << be_nl
<< "// " << __FILE__ << ":" << __LINE__ << be_nl << be_nl;
*os << "// Accessor to set the member." << be_nl
<< this->pre_op() << "void" << be_nl;
this->op_name (bu,
os);
*os << "::" << ub->local_name () << " (" << bt->name ()
<< " val)" << be_nl
<< "{" << be_idt_nl;
*os << "this->"
<< bu->field_pd_prefix () << ub->local_name ()
<< bu->field_pd_postfix ()
<< " = val;" << be_uidt_nl;
*os << "}" << be_nl;
*os << "// Retrieve the member." << be_nl
<< this->pre_op () << bt->name () << be_nl;
this->op_name (bu,
os);
*os << "::" << ub->local_name () << " () const"
<< be_nl
<< "{" << be_idt_nl;
*os << "return this->"
<< bu->field_pd_prefix() << ub->local_name ()
<< bu->field_pd_postfix ()
<< ";" << be_uidt_nl;
*os << "}";
return 0;
}
int
be_visitor_valuetype_field_cs::visit_interface (be_interface *node)
{
be_decl *ub = this->ctx_->node ();
be_valuetype *bu = be_valuetype::narrow_from_decl (this->ctx_->scope ());
be_type *bt;
// Check if we are visiting this node via a visit to a typedef node.
if (this->ctx_->alias ())
{
bt = this->ctx_->alias ();
}
else
{
bt = node;
}
if (!ub || !bu)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_valuetype_field_cs::"
"visit_interface - "
"bad context information\n"),
-1);
}
TAO_OutStream *os = this->ctx_->stream ();
*os << be_nl << be_nl << "// TAO_IDL - Generated from" << be_nl
<< "// " << __FILE__ << ":" << __LINE__ << be_nl << be_nl;
*os << "// Accessor to set the member." << be_nl
<< this->pre_op () << "void" << be_nl;
this->op_name (bu,
os);
*os << "::" << ub->local_name () << " (" << bt->name ()
<< "_ptr val)" << be_nl
<< "{" << be_idt_nl;
*os << "this->"
<< bu->field_pd_prefix () << ub->local_name ()
<< bu->field_pd_postfix ()
<< " = " << bt->name () << "::_duplicate (val);" << be_uidt_nl;
*os << "}" << be_nl << be_nl;
*os << "// Retrieve the member." << be_nl
<< this->pre_op () << bt->name () << "_ptr " << be_nl;
this->op_name (bu,
os);
*os << "::" << ub->local_name () << " () const"
<< be_nl
<< "{" << be_idt_nl;
*os << "return this->"
<< bu->field_pd_prefix () << ub->local_name ()
<< bu->field_pd_postfix ()
<< ".ptr ();" << be_uidt_nl;
*os << "}";
return 0;
}
int
be_visitor_valuetype_field_cs::visit_interface_fwd (be_interface_fwd *node)
{
be_decl *ub = this->ctx_->node ();
be_valuetype *bu = be_valuetype::narrow_from_decl (this->ctx_->scope ());
be_type *bt;
// Check if we are visiting this node via a visit to a typedef node.
if (this->ctx_->alias ())
{
bt = this->ctx_->alias ();
}
else
{
bt = node;
}
if (!ub || !bu)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_valuetype_field_cs::"
"visit_interface - "
"bad context information\n"),
-1);
}
TAO_OutStream *os = this->ctx_->stream ();
*os << be_nl << be_nl << "// TAO_IDL - Generated from" << be_nl
<< "// " << __FILE__ << ":" << __LINE__ << be_nl << be_nl;
*os << "// Accessor to set the member." << be_nl
<< this->pre_op () << "void" << be_nl;
this->op_name (bu,
os);
*os << "::" << ub->local_name () << " (" << bt->name ()
<< "_ptr val)" << be_nl
<< "{" << be_idt_nl;
*os << "this->"
<< bu->field_pd_prefix () << ub->local_name ()
<< bu->field_pd_postfix ()
<< " = " << bt->name () << "::_duplicate (val);" << be_uidt_nl;
*os << "}" << be_nl << be_nl;
*os << "// Retrieve the member" << be_nl
<< this->pre_op () << bt->name () << "_ptr " << be_nl;
this->op_name (bu,
os);
*os << "::" << ub->local_name () << " () const"
<< be_nl
<< "{" << be_idt_nl;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?