ast_decl.cpp
来自「这是广泛使用的通信开源项目,对于大容量,高并发的通讯要求完全能够胜任,他广泛可用」· C++ 代码 · 共 1,428 行 · 第 1/3 页
CPP
1,428 行
// ast_decl.cpp,v 1.55 2004/01/07 16:53:50 parsons Exp
/*
COPYRIGHT
Copyright 1992, 1993, 1994 Sun Microsystems, Inc. Printed in the United
States of America. All Rights Reserved.
This product is protected by copyright and distributed under the following
license restricting its use.
The Interface Definition Language Compiler Front End (CFE) is made
available for your use provided that you include this license and copyright
notice on all media and documentation and the software program in which
this product is incorporated in whole or part. You may copy and extend
functionality (but may not remove functionality) of the Interface
Definition Language CFE without charge, but you are not authorized to
license or distribute it to anyone else except as part of a product or
program developed by you or with the express written consent of Sun
Microsystems, Inc. ("Sun").
The names of Sun Microsystems, Inc. and any of its subsidiaries or
affiliates may not be used in advertising or publicity pertaining to
distribution of Interface Definition Language CFE as permitted herein.
This license is effective until terminated by Sun for failure to comply
with this license. Upon termination, you shall destroy or return all code
and documentation for the Interface Definition Language CFE.
INTERFACE DEFINITION LANGUAGE CFE IS PROVIDED AS IS WITH NO WARRANTIES OF
ANY KIND INCLUDING THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS
FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR ARISING FROM A COURSE OF
DEALING, USAGE OR TRADE PRACTICE.
INTERFACE DEFINITION LANGUAGE CFE IS PROVIDED WITH NO SUPPORT AND WITHOUT
ANY OBLIGATION ON THE PART OF Sun OR ANY OF ITS SUBSIDIARIES OR AFFILIATES
TO ASSIST IN ITS USE, CORRECTION, MODIFICATION OR ENHANCEMENT.
SUN OR ANY OF ITS SUBSIDIARIES OR AFFILIATES SHALL HAVE NO LIABILITY WITH
RESPECT TO THE INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY
INTERFACE DEFINITION LANGUAGE CFE OR ANY PART THEREOF.
IN NO EVENT WILL SUN OR ANY OF ITS SUBSIDIARIES OR AFFILIATES BE LIABLE FOR
ANY LOST REVENUE OR PROFITS OR OTHER SPECIAL, INDIRECT AND CONSEQUENTIAL
DAMAGES, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
Use, duplication, or disclosure by the government is subject to
restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
Technical Data and Computer Software clause at DFARS 252.227-7013 and FAR
52.227-19.
Sun, Sun Microsystems and the Sun logo are trademarks or registered
trademarks of Sun Microsystems, Inc.
SunSoft, Inc.
2550 Garcia Avenue
Mountain View, California 94043
NOTE:
SunOS, SunSoft, Sun, Solaris, Sun Microsystems or the Sun logo are
trademarks or registered trademarks of Sun Microsystems, Inc.
*/
/*
* AST_Decl is the base class for all AST nodes except AST_Expression.
* AST_Decls have a node type (a value from the enum AST_Decl::NodeType)
* and a name (a UTL_ScopedName).
* Additionally AST_Decl nodes record the scope of definition, the
* file name in which they were defined, the line on which they were
* defined in that file, and a boolean denoting whether this is the
* main file or an #include'd file.
*/
#include "ast_interface.h"
#include "ast_module.h"
#include "ast_array.h"
#include "ast_field.h"
#include "ast_structure.h"
#include "ast_sequence.h"
#include "ast_string.h"
#include "ast_typedef.h"
#include "ast_visitor.h"
#include "global_extern.h"
#include "nr_extern.h"
#include "utl_identifier.h"
#include "utl_scope.h"
#include "utl_err.h"
#include "ace/OS_NS_stdio.h"
// FUZZ: disable check_for_streams_include
#include "ace/streams.h"
ACE_RCSID (ast,
ast_decl,
"ast_decl.cpp,v 1.55 2004/01/07 16:53:50 parsons Exp")
COMMON_Base::COMMON_Base (idl_bool local,
idl_bool abstract)
: is_local_ (local),
is_abstract_ (abstract)
{
}
idl_bool
COMMON_Base::is_local (void)
{
return this->is_local_;
}
idl_bool
COMMON_Base::is_abstract (void)
{
return this->is_abstract_;
}
void
COMMON_Base::destroy (void)
{
}
// Constructor(s) and destructor.
AST_Decl::AST_Decl (void)
: COMMON_Base (),
repoID_ (0),
flat_name_ (0),
contains_wstring_ (-1),
pd_imported (I_FALSE),
pd_in_main_file (I_FALSE),
pd_defined_in (0),
pd_node_type (NT_module),
pd_line (-1),
pd_file_name (0),
pd_local_name (0),
pd_original_local_name (0),
pd_added (I_FALSE),
full_name_ (0),
prefix_ (0),
version_ (0),
anonymous_ (I_FALSE),
typeid_set_ (I_FALSE),
last_referenced_as_ (0),
prefix_scope_ (0)
{
}
AST_Decl::AST_Decl (NodeType nt,
UTL_ScopedName *n,
idl_bool anonymous)
: COMMON_Base (),
repoID_ (0),
flat_name_ (0),
contains_wstring_ (-1),
pd_imported (idl_global->imported ()),
pd_in_main_file (idl_global->in_main_file ()),
pd_defined_in (idl_global->scopes ().depth () > 0
? idl_global->scopes ().top ()
: 0),
pd_node_type (nt),
pd_line (idl_global->lineno ()),
pd_file_name (idl_global->filename ()),
pd_name (0),
pd_local_name (n == 0 ? 0 : n->last_component ()->copy ()),
pd_original_local_name (0),
pd_added (I_FALSE),
full_name_ (0),
prefix_ (0),
version_ (0),
anonymous_ (anonymous),
typeid_set_ (I_FALSE),
last_referenced_as_ (0),
prefix_scope_ (0)
{
this->compute_full_name (n);
char *prefix = 0;
idl_global->pragma_prefixes ().top (prefix);
if (prefix == 0)
{
this->prefix_ = ACE::strnew ("");
}
else
{
this->prefix_ = ACE::strnew (prefix);
}
if (n != 0)
{
// The function body creates its own copy.
this->original_local_name (n->last_component ());
}
this->compute_repoID ();
}
AST_Decl::~AST_Decl (void)
{
}
// Private operations.
// Compute our private UTL_ScopedName member.
void
AST_Decl::compute_full_name (UTL_ScopedName *n)
{
// This should happen only when we are a non-void predefined type,
// in which case our scoped name has already been created by the
// AST_PredefinedType constructor.
if (n == 0)
{
return;
}
UTL_ScopedName *cn = 0;
AST_Decl *d = 0;
// Initialize this name to 0.
this->pd_name = 0;
// Global scope?
if (this->defined_in () == 0)
{
this->pd_name = (UTL_IdList *) n->copy ();
return;
}
// OK, not global. So copy name of containing scope, then
// smash last cdr of copy with new component
d = ScopeAsDecl (this->defined_in ());
if (d != 0)
{
cn = d->name ();
}
if (cn != 0)
{
this->pd_name = (UTL_IdList *) cn->copy ();
}
if (this->pd_local_name != 0)
{
if (this->pd_name == 0)
{
ACE_NEW (this->pd_name,
UTL_ScopedName (this->pd_local_name->copy (),
0));
}
else
{
UTL_ScopedName *conc_name = 0;
ACE_NEW (conc_name,
UTL_ScopedName (this->pd_local_name->copy (),
0));
this->pd_name->nconc (conc_name);
}
}
}
void
AST_Decl::set_prefix_with_typeprefix_r (char *value,
UTL_Scope *appeared_in)
{
if (this->typeid_set_)
{
return;
}
if (this->prefix_scope_ != 0)
{
AST_Decl *decl = ScopeAsDecl (this->prefix_scope_);
idl_bool overridden =
decl->has_ancestor (ScopeAsDecl (appeared_in));
if (overridden)
{
return;
}
}
delete [] this->repoID_;
this->repoID_ = 0;
this->prefix (value);
this->prefix_scope_ = appeared_in;
UTL_Scope *s = DeclAsScope (this);
if (s != 0)
{
AST_Decl *tmp = 0;
UTL_Scope *s_tmp = 0;
for (UTL_ScopeActiveIterator i (s, UTL_Scope::IK_decls);
!i.is_done ();
i.next ())
{
tmp = i.item ();
s_tmp = DeclAsScope (tmp);
if (s_tmp == 0)
{
continue;
}
tmp->set_prefix_with_typeprefix_r (value,
appeared_in);
}
}
// This will recursively catch all previous openings of a module.
if (this->node_type () == AST_Decl::NT_module)
{
AST_Decl **d = 0;
AST_Module *m = AST_Module::narrow_from_decl (this);
for (ACE_Unbounded_Set_Iterator<AST_Decl *> iter (m->previous ());
!iter.done ();
iter.advance ())
{
iter.next (d);
if ((*d)->node_type () == AST_Decl::NT_pre_defined)
{
continue;
}
(*d)->set_prefix_with_typeprefix_r (value,
appeared_in);
}
}
this->compute_repoID ();
}
// Protected operations.
// Compute stringified fully scoped name.
void
AST_Decl::compute_full_name (void)
{
if (this->full_name_ != 0)
{
return;
}
else
{
size_t namelen = 0;
long first = I_TRUE;
long second = I_FALSE;
char *name = 0;
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.
name = i.item ()->get_string ();
namelen += ACE_OS::strlen (name);
if (first)
{
if (ACE_OS::strcmp (name, "") != 0)
{
// Does not start with a "".
first = I_FALSE;
}
else
{
second = I_TRUE;
}
}
}
ACE_NEW (this->full_name_,
char[namelen + 1]);
this->full_name_[0] = '\0';
first = I_TRUE;
second = I_FALSE;
for (UTL_IdListActiveIterator j (this->name ());
!j.is_done ();
j.next ())
{
if (!first)
{
ACE_OS::strcat (this->full_name_, "::");
}
else if (second)
{
first = second = I_FALSE;
}
// Print the identifier.
name = j.item ()->get_string ();
ACE_OS::strcat (this->full_name_, name);
if (first)
{
if (ACE_OS::strcmp (name, "") != 0)
{
// Does not start with a "".
first = I_FALSE;
}
else
{
second = I_TRUE;
}
}
}
}
}
// Compute stringified repository ID.
void
AST_Decl::compute_repoID (void)
{
if (this->repoID_ != 0)
{
return;
}
size_t namelen = 4; // for the prefix "IDL:"
long first = I_TRUE;
long second = I_FALSE;
char *name = 0;
const char *prefix = (this->prefix_ ? this->prefix_ : "");
UTL_Scope *scope = this->defined_in ();
const char *parent_prefix = 0;
// If our prefix is empty, we check to see if an ancestor has one.
while (ACE_OS::strcmp (prefix, "") == 0 && scope != 0)
{
AST_Decl *parent = ScopeAsDecl (scope);
if (parent->node_type () == AST_Decl::NT_root
&& parent->imported ())
{
break;
}
parent_prefix = parent->prefix ();
prefix = (parent_prefix ? parent_prefix : "");
scope = parent->defined_in ();
}
// in the first loop compute the total length
namelen += ACE_OS::strlen (prefix) + 1;
const char *version = this->version_;
scope = this->defined_in ();
// If our version is has not bee set, we use the parent's, if any.
while (version == 0 && scope != 0)
{
AST_Decl *parent = ScopeAsDecl (scope);
version = parent->version ();
scope = parent->defined_in ();
}
if (version != 0)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?