📄 be_interface.cpp
字号:
// be_interface.cpp,v 1.192 2003/12/31 19:57:06 parsons Exp
// ============================================================================
//
// = LIBRARY
// TAO IDL
//
// = FILENAME
// be_interface.cpp
//
// = DESCRIPTION
// Extension of class AST_Interface that provides additional means for C++
// mapping of an interface.
//
// = AUTHOR
// Copyright 1994-1995 by Sun Microsystems, Inc.
// and
// Aniruddha Gokhale,
// Michael Kircher
//
// ============================================================================
#include "be_interface.h"
#include "be_interface_strategy.h"
#include "be_attribute.h"
#include "be_operation.h"
#include "be_exception.h"
#include "be_visitor.h"
#include "be_helper.h"
#include "be_stream_factory.h"
#include "be_extern.h"
#include "utl_identifier.h"
#include "utl_exceptlist.h"
#include "ast_generator.h"
#include "ast_component.h"
#include "global_extern.h"
#include "idl_defines.h"
#include "nr_extern.h"
#include "ace/Process.h"
#include "ace/OS_NS_time.h"
ACE_RCSID (be,
be_interface,
"be_interface.cpp,v 1.192 2003/12/31 19:57:06 parsons Exp")
// Default constructor.
be_interface::be_interface (void)
: COMMON_Base (),
AST_Decl (),
AST_Type (),
UTL_Scope (),
AST_Interface (),
be_scope (),
be_type (),
var_out_seq_decls_gen_ (0),
skel_count_ (0),
in_mult_inheritance_ (-1),
strategy_ (0),
original_interface_ (0),
has_mixed_parentage_ (-1)
{
ACE_NEW (this->strategy_,
be_interface_default_strategy (this));
}
// Constructor used to build the AST.
be_interface::be_interface (UTL_ScopedName *n,
AST_Interface **ih,
long nih,
AST_Interface **ih_flat,
long nih_flat,
idl_bool local,
idl_bool abstract)
: COMMON_Base (local,
abstract),
AST_Decl (AST_Decl::NT_interface,
n),
AST_Type (AST_Decl::NT_interface,
n),
UTL_Scope (AST_Decl::NT_interface),
AST_Interface (n,
ih,
nih,
ih_flat,
nih_flat,
local,
abstract),
be_scope (AST_Decl::NT_interface),
be_type (AST_Decl::NT_interface,
n),
var_out_seq_decls_gen_ (0),
skel_count_ (0),
in_mult_inheritance_ (-1),
original_interface_ (0),
has_mixed_parentage_ (-1)
{
ACE_NEW (this->strategy_,
be_interface_default_strategy (this));
if (this->imported () || this->node_type () == AST_Decl::NT_valuetype)
{
return ;
}
if (this->is_defined ())
{
// Set the flag that says we have a interface in this IDL file.
ACE_SET_BITS (idl_global->decls_seen_info_,
idl_global->decls_seen_masks.interface_seen_);
if (abstract)
{
// Set the flag for abstract interface seen in this IDL file.
ACE_SET_BITS (idl_global->decls_seen_info_,
idl_global->decls_seen_masks.abstract_iface_seen_);
}
if (local)
{
// Set the flag for local interface seen in this IDL file.
ACE_SET_BITS (idl_global->decls_seen_info_,
idl_global->decls_seen_masks.local_iface_seen_);
}
else
{
// Set the flag for non-local interface seen in this IDL file.
ACE_SET_BITS (idl_global->decls_seen_info_,
idl_global->decls_seen_masks.non_local_iface_seen_);
}
}
else
{
// Forward declared non-defined interface. Still gets a _var decl.
ACE_SET_BITS (idl_global->decls_seen_info_,
idl_global->decls_seen_masks.fwd_iface_seen_);
}
}
be_interface::~be_interface (void)
{
// We know that it cannot be 0, but..
if (this->strategy_ != 0)
{
delete this->strategy_;
this->strategy_ = 0;
}
}
be_interface_strategy *
be_interface::set_strategy (be_interface_strategy *new_strategy)
{
be_interface_strategy *old = this->strategy_;
if (new_strategy != 0)
{
this->strategy_ = new_strategy;
}
return old;
}
const char *
be_interface::local_name (void) const
{
// Return the local name.
return this->strategy_->local_name ();
}
const char *
be_interface::full_name (void)
{
// Return the stringified full name.
return this->strategy_->full_name ();
}
const char *
be_interface::flat_name (void)
{
// Return the flattened full scoped name.
return this->strategy_->flat_name ();
}
const char *
be_interface::repoID (void) const
{
// Retrieve the repository ID.
return this->strategy_->repoID ();
}
const char *
be_interface::full_skel_name (void) const
{
// Retrieve the fully scoped skel class name.
return this->strategy_->full_skel_name ();
}
const char *
be_interface::full_coll_name (int type) const
{
// Retrieve the fully qualified collocated class name
return this->strategy_->full_coll_name (type);
}
const char *
be_interface::local_coll_name (int type) const
{
// Retrieve the fully qualified collocated class name.
return this->strategy_->local_coll_name (type);
}
const char *
be_interface::relative_skel_name (const char *skel_name)
{
// Relative skeleton name.
return this->strategy_->relative_skel_name (skel_name);
}
void
be_interface::compute_full_skel_name (const char *prefix,
char *&skelname)
{
if (skelname != 0)
{
return;
}
else
{
size_t namelen = ACE_OS::strlen (prefix);
long first = I_TRUE;
long second = I_FALSE;
char *item_name = 0;
// In the first loop compute the total length.
for (UTL_IdListActiveIterator i (this->name ());
!i.is_done ();
i.next ())
{
if (!first)
{
namelen += 2; // for "::"
}
else if (second)
{
first = second = I_FALSE;
}
// Print the identifier.
item_name = i.item ()->get_string ();
namelen += ACE_OS::strlen (item_name);
// Additional 4 for the POA_ characters.
if (first)
{
if (ACE_OS::strcmp (item_name, "") != 0)
{
// Does not start with a "".
first = I_FALSE;
}
else
{
second = I_TRUE;
}
}
}
ACE_NEW (skelname,
char [namelen+1]);
skelname[0] = '\0';
first = I_TRUE;
second = I_FALSE;
ACE_OS::strcat (skelname, prefix);
for (UTL_IdListActiveIterator j (this->name ());
!j.is_done ();
j.next ())
{
if (!first)
{
ACE_OS::strcat (skelname, "::");
}
else if (second)
{
first = second = I_FALSE;
}
// Print the identifier.
item_name = j.item ()->get_string ();
ACE_OS::strcat (skelname, item_name);
if (first)
{
if (ACE_OS::strcmp (item_name, "") != 0)
{
// Does not start with a "".
first = I_FALSE;
}
else
{
second = I_TRUE;
}
}
}
}
}
const char*
be_interface::relative_name (const char *localname,
const char *othername)
{
// Some compilers do not like generating a fully scoped name for a
// type that was defined in the same enclosing scope in which it was
// defined. We have to emit just the partial name, relative to our
// "localname".
// The tricky part here is that it is not enough to check if the
// typename we are using was defined in the current scope. But we
// need to ensure that it was not defined in any of our ancestor
// scopes as well. If that is the case, then we can generate a fully
// scoped name for that type, else we use the ACE_NESTED_CLASS macro.
// Thus we need some sort of relative name to be generated.
static char macro [NAMEBUFSIZE];
// Hold the fully scoped name.
char def_name [NAMEBUFSIZE];
char use_name [NAMEBUFSIZE];
// These point to the curr and next component in the scope.
char *def_curr = def_name;
char *def_next;
char *use_curr = use_name;
char *use_next;
ACE_OS::memset (macro,
'\0',
NAMEBUFSIZE);
ACE_OS::memset (def_name,
'\0',
NAMEBUFSIZE);
ACE_OS::memset (use_name,
'\0',
NAMEBUFSIZE);
// Traverse every component of the def_scope and use_scope beginning at the
// root and proceeding towards the leaf trying to see if the components
// match. Continue until there is a match and keep accumulating the path
// traversed. This forms the first argument to the ACE_NESTED_CLASS
// macro. Whenever there is no match, the remaining components of the
// def_scope form the second argument.
ACE_OS::strcpy (def_name,
localname);
ACE_OS::strcpy (use_name,
othername);
while (def_curr && use_curr)
{
// Find the first occurrence of a ::
// and advance the next pointers accordingly.
def_next = ACE_OS::strstr (def_curr, "::");
use_next = ACE_OS::strstr (use_curr, "::");
if (def_next)
{
*def_next = 0;
}
if (use_next)
{
*use_next = 0;
}
if (!ACE_OS::strcmp (def_curr, use_curr))
{
// They have same prefix, append to arg1.
def_curr = (def_next ? (def_next+2) : 0); // Skip the ::
use_curr = (use_next ? (use_next+2) : 0); // Skip the ::
}
else
{
// We had overwritten a ':' by a '\0' for string comparison. We
// revert back because we want the rest of the relative name to be
// used.
if (def_next)
{
*def_next = ':';
}
if (use_next)
{
*use_next = ':';
}
// No match. This is the end of the first argument. Get out
// of the loop as no more comparisons are necessary.
break;
}
}
// Start the 2nd argument of the macro.
// Copy the remaining def_name (if any left)
if (def_curr)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -