be_visitor_ami_pre_proc.cpp
来自「这是广泛使用的通信开源项目,对于大容量,高并发的通讯要求完全能够胜任,他广泛可用」· C++ 代码 · 共 1,431 行 · 第 1/3 页
CPP
1,431 行
{
// Create the reply handler name.
ACE_CString reply_handler_local_name;
this->generate_name (reply_handler_local_name,
"AMI_",
node->name ()->last_component ()->get_string(),
"Handler");
UTL_ScopedName *reply_handler_name =
ACE_static_cast (UTL_ScopedName *, node->name ()->copy ());
reply_handler_name->last_component ()->replace_string (
reply_handler_local_name.rep ()
);
long n_parents = 0;
AST_Interface_ptr *p_intf = this->create_inheritance_list (node, n_parents);
be_interface *reply_handler = 0;
ACE_NEW_RETURN (reply_handler,
be_interface (reply_handler_name, // name
p_intf, // list of inherited
n_parents, // number of inherited
0, // list of all ancestors
0, // number of ancestors
0, // non-local
0), // non-abstract
0);
reply_handler->set_name (reply_handler_name);
reply_handler->set_defined_in (node->defined_in ());
reply_handler->gen_fwd_helper_name ();
// Now our customized valuetype is created, we have to
// add now the operations and attributes to the scope.
if (! node->imported () && node->nmembers () > 0)
{
this->elem_number_ = 0;
// Initialize an iterator to iterate thru our scope.
for (UTL_ScopeActiveIterator si (node, UTL_Scope::IK_decls);
!si.is_done ();
si.next ())
{
AST_Decl *d = si.item ();
if (!d)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_ami_pre_proc::visit_interface - "
"bad node in this scope\n"),
0);
}
if (d->node_type () == AST_Decl::NT_attr)
{
be_attribute *attribute = be_attribute::narrow_from_decl (d);
if (attribute == 0)
{
return 0;
}
be_operation *get_operation =
this->generate_get_operation (attribute);
this->create_reply_handler_operation (get_operation,
reply_handler);
this->create_excep_operation (get_operation,
reply_handler,
excep_holder);
if (!attribute->readonly ())
{
be_operation *set_operation =
this->generate_set_operation (attribute);
this->create_reply_handler_operation (set_operation,
reply_handler);
this->create_excep_operation (set_operation,
reply_handler,
excep_holder);
}
}
else
{
be_operation* operation = be_operation::narrow_from_decl (d);
if (operation)
{
this->create_reply_handler_operation (operation,
reply_handler);
this->create_excep_operation (operation,
reply_handler,
excep_holder);
}
}
} // end of while loop
} // end of if
return reply_handler;
}
int
be_visitor_ami_pre_proc::create_raise_operation (
be_decl *node,
be_valuetype *excep_holder,
Operation_Kind operation_kind
)
{
be_operation *orig_op = 0;
if (operation_kind == NORMAL)
{
orig_op = be_operation::narrow_from_decl (node);
if (orig_op)
{
if (orig_op->flags () == AST_Operation::OP_oneway)
{
// We do nothing for oneways!
return 0;
}
}
}
Identifier *id = 0;
UTL_ScopedName *sn = 0;
ACE_NEW_RETURN (id,
Identifier ("void"),
-1);
ACE_NEW_RETURN (sn,
UTL_ScopedName (id,
0),
-1);
// Create the return type, which is "void"
be_predefined_type *rt = 0;
ACE_NEW_RETURN (rt,
be_predefined_type (AST_PredefinedType::PT_void,
sn),
-1);
// Name the operation properly
UTL_ScopedName *op_name = ACE_static_cast (UTL_ScopedName *,
excep_holder->name ()->copy ());
ACE_CString new_local_name ("raise_");
if (operation_kind == SET_OPERATION)
{
new_local_name += "set_";
}
else if (operation_kind == GET_OPERATION)
{
new_local_name += "get_";
}
new_local_name += node->name ()->last_component ()->get_string ();
ACE_NEW_RETURN (id,
Identifier (new_local_name.rep ()),
-1);
ACE_NEW_RETURN (sn,
UTL_ScopedName (id,
0),
-1);
op_name->nconc (sn);
be_operation *operation = 0;
ACE_NEW_RETURN (operation,
be_operation (rt,
AST_Operation::OP_noflags,
op_name,
0,
0),
-1);
operation->set_name (op_name);
operation->set_defined_in (excep_holder);
if (operation_kind == NORMAL)
{
if (orig_op)
{
// Copy the exceptions.
if (orig_op->exceptions ())
{
UTL_ExceptList *exceptions = orig_op->exceptions ();
operation->be_add_exceptions (exceptions);
}
}
}
// Set the proper strategy.
be_operation_ami_exception_holder_raise_strategy *boaehrs = 0;
ACE_NEW_RETURN (boaehrs,
be_operation_ami_exception_holder_raise_strategy (operation),
-1);
be_operation_strategy *old_strategy = operation->set_strategy (boaehrs);
if (old_strategy)
{
delete old_strategy;
old_strategy = 0;
}
// After having generated the operation we insert it into the
// exceptionholder valuetype.
excep_holder->be_add_operation (operation);
return 0;
}
be_operation *
be_visitor_ami_pre_proc::create_sendc_operation (be_operation *node,
int for_arguments)
{
if (node->flags () == AST_Operation::OP_oneway)
{
// We do nothing for oneways!
return 0;
}
Identifier *id = 0;
UTL_ScopedName *sn = 0;
ACE_NEW_RETURN (id,
Identifier ("void"),
0);
ACE_NEW_RETURN (sn,
UTL_ScopedName (id,
0),
0);
// Create the return type, which is "void"
be_predefined_type *rt = 0;
ACE_NEW_RETURN (rt,
be_predefined_type (
AST_PredefinedType::PT_void,
sn),
0);
// Create the new name
// Prepend "sendc_" to the name of the operation
ACE_CString original_op_name (
node->name ()->last_component ()->get_string ()
);
ACE_CString new_op_name = ACE_CString ("sendc_") + original_op_name;
UTL_ScopedName *op_name =
ACE_static_cast (UTL_ScopedName *,
node->name ()->copy ());
op_name->last_component ()->replace_string (new_op_name.rep ());
// Create the operation
be_operation *op = 0;
ACE_NEW_RETURN (op,
be_operation (rt,
AST_Operation::OP_noflags,
op_name,
0,
0),
0);
// Create the first argument, which is a Reply Handler
if (for_arguments)
{
// Create the field type
be_decl *parent =
be_scope::narrow_from_scope (node->defined_in ())->decl ();
// Add the pre- and suffix
ACE_CString excep_holder_name;
this->generate_name (excep_holder_name,
"AMI_",
parent->name ()->last_component ()->get_string (),
"Handler");
UTL_ScopedName *field_name =
ACE_static_cast (UTL_ScopedName *, parent->name ()->copy ());
field_name->last_component ()->replace_string (excep_holder_name.rep ());
be_interface *field_type = 0;
ACE_NEW_RETURN (field_type,
be_interface (field_name,
0,
0,
0,
0,
0,
0),
0);
field_type->set_defined_in (node->defined_in ());
// Create the argument.
ACE_NEW_RETURN (id,
Identifier ("ami_handler"),
0);
ACE_NEW_RETURN (sn,
UTL_ScopedName (id,
0),
0);
be_argument *arg = 0;
ACE_NEW_RETURN (arg,
be_argument (AST_Argument::dir_IN,
field_type, // is also a valuetype
sn),
0);
// Add the reply handler to the argument list
op->be_add_argument (arg);
}
// Iterate over the arguments and put all the in and inout
// into the new method.
if (node->nmembers () > 0)
{
// initialize an iterator to iterate thru our scope
for (UTL_ScopeActiveIterator si (node, UTL_Scope::IK_decls);
!si.is_done ();
si.next ())
{
AST_Decl *d = si.item ();
if (!d)
{
ACE_ERROR_RETURN ((
LM_ERROR,
"(%N:%l) be_visitor_ami_pre_proc::create_sendc_method - "
"bad node in this scope\n"
),
0
);
}
//be_decl *arg = be_decl::narrow_from_decl (d);
AST_Argument *original_arg = AST_Argument::narrow_from_decl (d);
if (original_arg->direction () == AST_Argument::dir_IN ||
original_arg->direction () == AST_Argument::dir_INOUT)
{
// Create the argument.
be_argument *arg = 0;
UTL_ScopedName arg_name (original_arg->local_name (),
0);
ACE_NEW_RETURN (arg,
be_argument (AST_Argument::dir_IN,
original_arg->field_type (),
&arg_name),
0);
op->be_add_argument (arg);
}
} // end of while loop
} // end of if
return op;
}
int
be_visitor_ami_pre_proc::create_reply_handler_operation (
be_operation *node,
be_interface *reply_handler
)
{
if (!node)
{
return -1;
}
if (node->flags () == AST_Operation::OP_oneway)
{
// We do nothing for oneways!
return 0;
}
Identifier *id = 0;
UTL_ScopedName *sn = 0;
ACE_NEW_RETURN (id,
Identifier ("void"),
-1);
ACE_NEW_RETURN (sn,
UTL_ScopedName (id,
0),
-1);
// Create the return type, which is "void"
be_predefined_type *rt = 0;
ACE_NEW_RETURN (rt,
be_predefined_type (AST_PredefinedType::PT_void,
sn),
-1);
ACE_CString original_op_name (
node->name ()->last_component ()->get_string ()
);
UTL_ScopedName *op_name =
ACE_static_cast (UTL_ScopedName *,
reply_handler->name ()-> copy ());
ACE_NEW_RETURN (id,
Identifier (original_op_name.rep ()),
-1);
ACE_NEW_RETURN (sn,
UTL_ScopedName (id,
0),
-1);
op_name->nconc (sn);
// Create the operation.
be_operation *operation = 0;
ACE_NEW_RETURN (operation,
be_operation (rt,
AST_Operation::OP_noflags,
op_name,
0,
0),
-1);
operation->set_name (op_name);
// If return type is non-void add it as first argument.
if (!node->void_return_type ())
{
ACE_NEW_RETURN (id,
Identifier ("ami_return_val"),
-1);
ACE_NEW_RETURN (sn,
UTL_ScopedName (id,
0),
-1);
// Create the argument.
be_argument *arg = 0;
ACE_NEW_RETURN (arg,
be_argument (AST_Argument::dir_IN,
node->return_type (),
sn),
-1);
// Add the reply handler to the argument list.
operation->be_add_argument (arg);
}
// Iterate over the arguments and put all the in and inout
// into the new method.
if (node->nmembers () > 0)
{
// Initialize an iterator to iterate thru our scope.
for (UTL_ScopeActiveIterator si (node, UTL_Scope::IK_decls);
!si.is_done ();
si.next ())
{
AST_Decl *d = si.item ();
if (d == 0)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?