be_visitor_amh_pre_proc.cpp
来自「这是广泛使用的通信开源项目,对于大容量,高并发的通讯要求完全能够胜任,他广泛可用」· C++ 代码 · 共 937 行 · 第 1/2 页
CPP
937 行
/**
* @file be_visitor_amh_pre_proc.cpp
*
* be_visitor_amh_pre_proc.cpp,v 1.26 2003/10/28 18:30:37 bala Exp
*
* This visitor creates for AMH implied IDL constructs the appropriate AST
* (Abstract Syntax Tree) node, sets the corresponding interface or operation
* strategy on it and enteres the nodes into the AST.
*
* @author Darrell Brunsch <brunsch@cs.wustl.edu>
* @author Mayur Deshpande <mayur@ics.uci.edu>
* @author Carlos O'Ryan <coryan@uci.edu>
*/
//=============================================================================
#include "be_visitor_amh_pre_proc.h"
#include "be_visitor_context.h"
#include "be_root.h"
#include "be_module.h"
#include "be_interface.h"
#include "be_valuetype.h"
#include "be_attribute.h"
#include "be_operation.h"
#include "be_predefined_type.h"
#include "be_argument.h"
#include "utl_identifier.h"
#include "global_extern.h"
#include "ace/Log_Msg.h"
ACE_RCSID (be,
be_visitor_amh_pre_proc,
"be_visitor_amh_pre_proc.cpp,v 1.26 2003/10/28 18:30:37 bala Exp")
be_visitor_amh_pre_proc::be_visitor_amh_pre_proc (be_visitor_context *ctx)
: be_visitor_scope (ctx)
{
}
be_visitor_amh_pre_proc::~be_visitor_amh_pre_proc (void)
{
}
int
be_visitor_amh_pre_proc::visit_root (be_root *node)
{
if (this->visit_scope (node) == -1)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_amh_pre_proc::"
"visit_root - visit scope failed\n"),
-1);
}
return 0;
}
int
be_visitor_amh_pre_proc::visit_module (be_module *node)
{
if (!node->imported () && this->visit_scope (node) == -1)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_amh_pre_proc::"
"visit_module - visit scope failed\n"),
-1);
}
return 0;
}
int
be_visitor_amh_pre_proc::visit_interface (be_interface *node)
{
// Do not generate AMH classes for any sort of implied IDL.
if (node->original_interface () != 0)
{
return 0;
}
// Don't generate AMH classes for imported, local or abstract interfaces
// either...
// @@ Mayur, maybe we do want to insert the AMH node for imported
// interfaces, not because we want to generate code for them, but
// because the (imported-AMH-) node could be needed to generate a
// non-imported, AMH node, for example, for a derived interface.
if (node->imported () || node->is_local () || node->is_abstract ())
{
return 0;
}
AST_Module *module =
AST_Module::narrow_from_scope (node->defined_in ());
if (module == 0)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_amh_pre_proc::"
"visit_interface - module is null\n"),
-1);
}
// Create the exception holder, it needs to go before the response
// handler, because the response handler uses an exception holder as
// argument for some of its operations....
be_valuetype *excep_holder =
this->create_exception_holder (node);
excep_holder->set_defined_in (node->defined_in ());
excep_holder->original_interface (node);
module->set_has_nested_valuetype ();
// Create the ResponseHandler class
be_interface *response_handler =
this->create_response_handler (node,
excep_holder);
if (response_handler == 0)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%N:%l) be_visitor_amh_pre_proc::"
"visit_interface - "
"creating the response handler failed\n"),
-1);
}
response_handler->set_defined_in (node->defined_in ());
// Insert the response handler after the node.
module->be_add_interface (response_handler,
node);
// Remember from whom we were cloned
response_handler->original_interface (node);
module->be_add_interface (excep_holder, node);
return 0;
}
be_interface *
be_visitor_amh_pre_proc::create_response_handler (
be_interface *node,
be_valuetype *exception_holder
)
{
// Generate 'AMH_InterfaceResponseHandler'
ACE_CString class_name;
class_name += "AMH_";
class_name += node->local_name ();
class_name += "ResponseHandler";
UTL_ScopedName *amh_name =
ACE_dynamic_cast(UTL_ScopedName*,node->name ()->copy ());
Identifier *local_name = amh_name->last_component ();
local_name->replace_string (class_name.c_str ());
// @@ Mayur, you are not filling up the list of inherited classes,
// however, you *are* using that same list in the amh_rh_sh.cpp and
// amh_rh_sh.cpp file... you need to fill up the list, i.e. discover
// the inherited classes in the original interface, change their
// names and then use the symbol table to look up the
// AMH-response-handler nodes.
be_interface *response_handler = 0;
ACE_NEW_RETURN (response_handler,
be_interface (amh_name, // name
0, // list of inherited
0, // number of inherited
0, // list of ancestors
0, // number of ancestors
1, // local
0), // non-abstract
0);
response_handler->set_name (amh_name);
response_handler->set_defined_in (node->defined_in ());
response_handler->set_imported (node->imported ());
response_handler->set_line (node->line ());
response_handler->set_file_name (node->file_name ());
response_handler->gen_fwd_helper_name ();
this->add_rh_node_members (node, response_handler, exception_holder);
return response_handler;
}
int
be_visitor_amh_pre_proc::add_rh_node_members ( be_interface *node,
be_interface *response_handler,
be_valuetype *exception_holder)
{
// Now our customized valuetype is created, we have to
// add now the operations and attributes to the scope.
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_amh_pre_proc::"
"visit_interface - "
"bad node in this scope\n"),
0);
}
AST_Decl::NodeType nt = d->node_type ();
if (nt == AST_Decl::NT_attr)
{
be_attribute *attribute = be_attribute::narrow_from_decl (d);
if (!attribute)
{
return 0;
}
}
else if (nt == AST_Decl::NT_op)
{
be_operation* operation = be_operation::narrow_from_decl (d);
if (operation)
{
this->create_response_handler_operation (operation,
response_handler,
exception_holder);
}
}
else
{
continue;
}
}
return 1;
}
int
be_visitor_amh_pre_proc::create_response_handler_operation (
be_operation *node,
be_interface *response_handler,
be_valuetype *exception_holder
)
{
if (!node)
{
return -1;
}
// @@ Mayur, we do want to generate code for oneways! This is
// needed to support reliable oneways with the SYNC_WITH_TARGET
// policy.
if (node->flags () == AST_Operation::OP_oneway)
{
// We do nothing for oneways!
return 0;
}
if (this->add_normal_reply (node, response_handler) == -1)
{
return -1;
}
return this->add_exception_reply (node,
response_handler,
exception_holder);
}
int
be_visitor_amh_pre_proc::add_exception_reply (be_operation *node,
be_interface *response_handler,
be_valuetype *exception_holder)
{
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);
// Create the name...
UTL_ScopedName *operation_name = node->compute_name ("",
"_excep");
be_operation *node_excep = 0;
ACE_NEW_RETURN (node_excep,
be_operation (rt,
AST_Operation::OP_noflags,
operation_name,
1,
0),
-1);
ACE_NEW_RETURN (id,
Identifier ("holder"),
-1);
ACE_NEW_RETURN (sn,
UTL_ScopedName (id,
0),
-1);
be_argument *argument = 0;
ACE_NEW_RETURN (argument,
be_argument (AST_Argument::dir_IN,
exception_holder,
sn),
-1);
argument->set_defined_in (node_excep);
node_excep->be_add_argument (argument);
node_excep->set_defined_in (response_handler);
response_handler->be_add_operation (node_excep);
return 0;
}
int
be_visitor_amh_pre_proc::add_normal_reply (be_operation *node,
be_interface *response_handler)
{
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 *,
response_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,
1,
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 ("return_value"),
-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 response handler to the argument list
operation->be_add_argument (arg);
}
// Iterate over the arguments and put all the out and inout arguments
// into the new method.
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_amh_pre_proc::"
"create_response_handler_operation - "
"bad node in this scope\n"),
-1);
}
//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_INOUT ||
original_arg->direction () == AST_Argument::dir_OUT)
{
// Create the argument
be_argument *arg = 0;
ACE_NEW_RETURN (arg,
be_argument (AST_Argument::dir_IN,
original_arg->field_type (),
original_arg->name ()),
-1);
operation->be_add_argument (arg);
}
}
operation->set_defined_in (response_handler);
// We do not copy the exceptions because the exceptions
// are delivered by the excep methods.
// After having generated the operation we insert it into the
// response handler interface.
response_handler->be_add_operation (operation);
return 0;
}
int
be_visitor_amh_pre_proc::visit_operation (be_operation *node)
{
// @@ Mayur, we do want to generate code for oneways! This is
// needed to support reliable oneways with the SYNC_WITH_TARGET
// policy.
// We do nothing for oneways!
if (node->flags () == AST_Operation::OP_oneway)
{
return 0;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?