tmplinst_cs.cpp
来自「这是广泛使用的通信开源项目,对于大容量,高并发的通讯要求完全能够胜任,他广泛可用」· C++ 代码 · 共 1,290 行 · 第 1/3 页
CPP
1,290 行
//=============================================================================
/**
* @file tmplinst_cs.cpp
*
* tmplinst_cs.cpp,v 1.6 2003/11/21 02:16:43 parsons Exp
*
* This visitor generates explicit template instantiations, guarded so they
* are seen only by compilers whose platforms require explicit template
* instantiation.
*
* @author Jeff Parsons <j.parsons@vanderbilt.edu>
*/
//=============================================================================
be_visitor_tmplinst_cs::be_visitor_tmplinst_cs (be_visitor_context *ctx)
: be_visitor_tmplinst (ctx)
{
}
be_visitor_tmplinst_cs::~be_visitor_tmplinst_cs (void)
{
}
int
be_visitor_tmplinst_cs::visit_interface (be_interface *node)
{
if (this->this_mode_generated (node))
{
return 0;
}
TAO_OutStream *os = this->ctx_->stream ();
// For arg/return type helper template classes. This must come before
// the check for an imported or undefined node because such a node
// could still be used in an operation and thus cause the use of
// an arg helper template class.
if (node->seen_in_operation ())
{
os->gen_ifdef_macro (node->flat_name (), "arg_traits_tmplinst");
*os << be_nl << be_nl
<< this->prefix_ << this->linebreak_ << be_idt << be_idt_nl
<< "TAO::Arg_Traits<" << this->linebreak_ << be_idt << be_idt_nl
<< node->name () << this->linebreak_ << be_uidt_nl
<< ">" << this->suffix_ << be_uidt << be_uidt << be_uidt;
*os << be_nl << be_nl
<< this->prefix_ << this->linebreak_ << be_idt << be_idt_nl
<< "TAO::Object_Arg_Traits_T<" << this->linebreak_
<< be_idt << be_idt_nl
<< node->name () << "_ptr," << this->linebreak_ << be_nl
<< node->name () << "_var," << this->linebreak_ << be_nl
<< node->name () << "_out," << this->linebreak_ << be_nl
<< "TAO::Objref_Traits<" << node->name ()
<< ">" << this->linebreak_ << be_uidt_nl
<< ">" << this->suffix_ << be_uidt << be_uidt << be_uidt;
os->gen_endif ();
}
// If one of these is true we can skip the rest.
if (node->imported () || !node->is_defined ())
{
this->this_mode_generated (node, I_TRUE);
return 0;
}
// Interfaces can contain declarations of structs, unions, sequences
// or arrays.
if (this->visit_scope (node) != 0)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_tmplinst_cs::"
"visit_interface - visit scope failed\n"),
-1);
}
// For the traits template class.
*os << be_nl << be_nl
<< this->prefix_ << this->linebreak_ << be_idt << be_idt_nl
<< "TAO::Objref_Traits<" << this->linebreak_ << be_idt << be_idt_nl
<< node->name () << this->linebreak_ << be_uidt_nl
<< ">" << this->suffix_ << be_uidt << be_uidt << be_uidt;
// For the _var and _out typedefs.
*os << be_nl << be_nl
<< this->prefix_ << this->linebreak_ << be_idt << be_idt_nl
<< "TAO_Objref_Var_T<" << this->linebreak_ << be_idt << be_idt_nl
<< node->name () << be_uidt_nl
<< ">" << this->suffix_ << be_uidt << be_uidt_nl << be_uidt_nl
<< this->prefix_<< this->linebreak_ << be_idt << be_idt_nl
<< "TAO_Objref_Out_T<" << this->linebreak_ << be_idt << be_idt_nl
<< node->name () << be_uidt_nl
<< ">" << this->suffix_ << be_uidt << be_uidt << be_uidt;
// Called by _narrow() for non-local interfaces.
if (!node->is_local ())
{
*os << be_nl << be_nl
<< this->prefix_ << this->linebreak_ << be_idt << be_idt_nl;
if (!node->is_abstract ())
{
*os << "TAO::Narrow_Utils<" << this->linebreak_
<< be_idt << be_idt_nl;
}
else
{
*os << "TAO::AbstractBase_Narrow_Utils<" << this->linebreak_
<< be_idt << be_idt_nl;
}
*os << node->name () << this->linebreak_ << be_uidt_nl
<< ">" << this->suffix_ << be_uidt << be_uidt << be_uidt;
}
if (be_global->gen_smart_proxies ())
{
// Its necessary to take care of the nested case.
// The smart proxy classes are in the same scope as the proxy.
be_decl* scope =
be_scope::narrow_from_scope (node->defined_in ())->decl ();
*os << be_nl << be_nl
<< this->prefix_ << this->linebreak_ << be_idt << be_idt_nl
<< "TAO_Singleton<" << this->linebreak_ << be_idt << be_idt_nl
<< scope->full_name ();
// Only if there exists any nesting "::" is needed!
if (node->is_nested ())
{
*os << "::";
}
*os <<"TAO_" << node->flat_name ()
<< "_Proxy_Factory_Adapter," << this->linebreak_ << be_nl
<< "TAO_SYNCH_RECURSIVE_MUTEX" << this->linebreak_ << be_uidt_nl
<< ">" << this->suffix_ << be_uidt << be_uidt << be_uidt;
}
// For Any impl template class.
if (be_global->any_support ())
{
TAO_OutStream *tmp = os;
if (be_global->gen_anyop_files ())
{
os = tao_cg->anyop_source ();
}
*os << be_nl << be_nl
<< this->prefix_ << this->linebreak_ << be_idt << be_idt_nl
<< "TAO::Any_Impl_T<" << this->linebreak_ << be_idt << be_idt_nl
<< node->name () << this->linebreak_ << be_uidt_nl
<< ">" << this->suffix_ << be_uidt << be_uidt << be_uidt;
os = tmp;
}
this->this_mode_generated (node, I_TRUE);
return 0;
}
int
be_visitor_tmplinst_cs::visit_valuetype (be_valuetype *node)
{
if (this->this_mode_generated (node))
{
return 0;
}
TAO_OutStream *os = this->ctx_->stream ();
// For arg/return type helper template classes.
if (node->seen_in_operation ())
{
os->gen_ifdef_macro (node->flat_name (), "arg_traits_tmplinst");
*os << be_nl << be_nl
<< this->prefix_ << this->linebreak_ << be_idt << be_idt_nl
<< " TAO::Arg_Traits<" << this->linebreak_ << be_idt << be_idt_nl
<< node->name () << this->linebreak_ << be_uidt_nl
<< ">" << this->suffix_ << be_uidt << be_uidt << be_uidt;
*os << be_nl << be_nl
<< this->prefix_ << this->linebreak_ << be_idt << be_idt_nl
<< "TAO::Object_Arg_Traits_T<" << this->linebreak_
<< be_idt << be_idt_nl
<< node->name () << " *," << this->linebreak_ << be_nl
<< node->name () << "_var," << this->linebreak_ << be_nl
<< node->name () << "_out," << this->linebreak_ << be_nl
<< "TAO::Objref_Traits<" << node->name () << "> "
<< this->linebreak_ << be_uidt_nl
<< ">" << this->suffix_ << be_uidt << be_uidt << be_uidt;
os->gen_endif ();
}
if (node->imported () || !node->is_defined ())
{
this->this_mode_generated (node, I_TRUE);
return 0;
}
if (this->visit_scope (node) != 0)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_tmplinst_cs::"
"visit_valuetype - visit scope failed\n"),
-1);
}
// For _var and _out template classes.
*os << be_nl << be_nl
<< this->prefix_ << this->linebreak_ << be_idt << be_idt_nl
<< "TAO::Value_Traits<" << this->linebreak_ << be_idt << be_idt_nl
<< node->name () << this->linebreak_ << be_uidt_nl
<< ">" << this->suffix_ << be_uidt << be_uidt << be_uidt;
*os << be_nl << be_nl
<< this->prefix_ << this->linebreak_ << be_idt << be_idt_nl
<< "TAO_Value_Var_T<" << this->linebreak_ << be_idt << be_idt_nl
<< node->name () << this->linebreak_ << be_nl
<< be_uidt_nl
<< ">" << this->suffix_ << be_uidt << be_uidt_nl << be_uidt_nl
<< this->prefix_ << this->linebreak_ << be_idt << be_idt_nl
<< "TAO_Value_Out_T<" << this->linebreak_ << be_idt << be_idt_nl
<< node->name () << this->linebreak_ << be_nl
<< be_uidt_nl
<< ">" << this->suffix_ << be_uidt << be_uidt << be_uidt;
// For Any impl template class.
if (be_global->any_support ())
{
TAO_OutStream *tmp = os;
if (be_global->gen_anyop_files ())
{
os = tao_cg->anyop_source ();
}
*os << be_nl << be_nl
<< this->prefix_ << this->linebreak_ << be_idt << be_idt_nl
<< "TAO::Any_Impl_T<" << this->linebreak_ << be_idt << be_idt_nl
<< node->name () << this->linebreak_ << be_uidt_nl
<< ">" << this->suffix_ << be_uidt << be_uidt << be_uidt;
os = tmp;
}
this->this_mode_generated (node, I_TRUE);
return 0;
}
int
be_visitor_tmplinst_cs::visit_operation (be_operation *node)
{
if (this->this_mode_generated (node)
|| node->imported ()
|| node->is_local ())
{
return 0;
}
const char * S = "";
be_visitor_arg_tmplinst visitor (this->ctx_,
this->mode_,
this->prefix_,
this->suffix_,
this->linebreak_,
S);
be_type *bt = be_type::narrow_from_decl (node->return_type ());
visitor.direction ();
if (bt->accept (&visitor) != 0)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_tmplinst_cs::"
"visit_operation - "
"codegen for return type failed\n"),
-1);
}
be_argument *arg = 0;
for (UTL_ScopeActiveIterator si (node, UTL_Scope::IK_decls);
!si.is_done ();
si.next ())
{
arg = be_argument::narrow_from_decl (si.item ());
visitor.direction (arg->direction ());
bt = be_type::narrow_from_decl (arg->field_type ());
if (bt->accept (&visitor) != 0)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_tmplinst_cs::"
"visit_operation - "
"codegen for argument failed\n"),
-1);
}
}
this->this_mode_generated (node, I_TRUE);
return 0;
}
int
be_visitor_tmplinst_cs::visit_sequence (be_sequence *node)
{
if (this->this_mode_generated (node))
{
return 0;
}
TAO_OutStream *os = this->ctx_->stream ();
be_typedef *alias = this->ctx_->alias ();
// For arg/return type helper template classes.
// If the node is anonymous, it can't have been seen in an operation,
// so no check is necessary for alias == 0.
if (node->seen_in_operation ())
{
os->gen_ifdef_macro (node->flat_name (), "arg_traits_tmplinst");
*os << be_nl << be_nl
<< this->prefix_ << " TAO::Arg_Traits<" << alias->name ()
<< ">" << this->suffix_;
*os << be_nl << be_nl
<< this->prefix_ << this->linebreak_ << be_idt << be_idt_nl
<< "TAO::Var_Size_Arg_Traits_T<" << this->linebreak_
<< be_idt << be_idt_nl
<< alias->name () << "," << this->linebreak_ << be_nl
<< alias->name () << "_var," << this->linebreak_ << be_nl
<< alias->name () << "_out" << this->linebreak_ << be_uidt_nl
<< ">" << this->suffix_ << be_uidt << be_uidt << be_uidt;
os->gen_endif ();
}
if (node->imported ())
{
this->this_mode_generated (node, I_TRUE);
return 0;
}
// For _var and _out template classes.
be_type *bt = be_type::narrow_from_decl (node->base_type ());
AST_Decl::NodeType nt = bt->node_type ();
if (!bt->seq_elem_tmplinst ())
{
// This is a no-op unless our element is a managed type.
this->gen_managed_type_tmplinst (node, bt);
bt->seq_elem_tmplinst (I_TRUE);
}
if (this->ctx_->alias () != 0)
{
this->gen_varout_tmplinst (node,
bt);
}
be_typedef *td = 0;
while (nt == AST_Decl::NT_typedef)
{
td = be_typedef::narrow_from_decl (bt);
nt = td->base_node_type ();
}
// basic IDL types are in TAO. Sequences of (w)strings in TAO are
// specializations and so are not template classes.
if ((nt != AST_Decl::NT_pre_defined
&& nt != AST_Decl::NT_string
&& nt != AST_Decl::NT_wstring)
|| ! node->unbounded ())
{
if (this->gen_base_class_tmplinst (node) == -1)
{
return -1;
}
}
// For Any impl template class.
if (be_global->any_support () && !node->anonymous ())
{
TAO_OutStream *tmp = os;
if (be_global->gen_anyop_files ())
{
os = tao_cg->anyop_source ();
}
*os << be_nl << be_nl
<< this->prefix_ << this->linebreak_ << be_idt << be_idt_nl
<< "TAO::Any_Dual_Impl_T<" << this->linebreak_
<< be_idt << be_idt_nl
<< node->name () << this->linebreak_ << be_uidt_nl
<< ">" << this->suffix_ << be_uidt << be_uidt << be_uidt;
os = tmp;
}
this->this_mode_generated (node, I_TRUE);
return 0;
}
int
be_visitor_tmplinst_cs::visit_string (be_string *node)
{
if (this->this_mode_generated (node) || !node->seen_in_operation ())
{
return 0;
}
unsigned long bound = node->max_size ()->ev ()->u.ulval;
be_typedef *alias = this->ctx_->alias ();
// Unbounded (w)string args are handled as a predefined type.
// Bounded (w)strings must come in as a typedef - they can't
// be used directly as arguments or return types.
if (bound == 0 || alias == 0)
{
this->this_mode_generated (node, I_TRUE);
return 0;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?