|
From: <net...@us...> - 2003-09-07 13:29:06
|
Update of /cvsroot/cpptool/rfta/src/rfta
In directory sc8-pr-cvs1:/tmp/cvs-serv28823/rfta/src/rfta
Modified Files:
IdentifierScope.h IdentifierScope.cpp
Log Message:
-- scopes store their names now
-- remove scopes
-- lookup within unnamed scopes does also search in parent scope
Index: IdentifierScope.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/IdentifierScope.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** IdentifierScope.h 6 Sep 2003 21:49:28 -0000 1.2
--- IdentifierScope.h 7 Sep 2003 13:28:58 -0000 1.3
***************
*** 37,41 ****
{
public:
! static IdentifierScopePtr createScope(IdentifierScopeWeakPtr parent);
static IdentifierScopePtr createSubScope(IdentifierScopeWeakPtr parent, std::string scopeName);
--- 37,41 ----
{
public:
! static IdentifierScopePtr createScope(IdentifierScopeWeakPtr parent, std::string scopeName);
static IdentifierScopePtr createSubScope(IdentifierScopeWeakPtr parent, std::string scopeName);
***************
*** 50,57 ****
--- 50,63 ----
bool hasSubScope( std::string scopeName ) const;
IdentifierScopePtr getSubScope(std::string scopeName) const;
+
+ /**
+ * removes the specified child scope, returns success of operation
+ */
+ bool removeSubScope( IdentifierScopePtr child );
// TODO-1: define sub ranges for variables/types/classes/unions
// TODO-2: add function to register "identifier uses"
void addIdentifierDeclaration( std::string qualifiedName, ASTNodePtr declaration);
+ void addIdentifierUse( std::string qualifiedName, ASTNodePtr declaration);
ASTNodePtr getIdentifierDeclaration( std::string qualifiedName ) const;
***************
*** 59,63 ****
/*! protects direct creation. use static 'createScope/createSubScope'
*/
! IdentifierScope(IdentifierScopeWeakPtr parent);
private:
void registerSubScope(std::string scopeName, IdentifierScopePtr& subScope );
--- 65,69 ----
/*! protects direct creation. use static 'createScope/createSubScope'
*/
! IdentifierScope(IdentifierScopeWeakPtr parent, std::string name);
private:
void registerSubScope(std::string scopeName, IdentifierScopePtr& subScope );
***************
*** 68,71 ****
--- 74,78 ----
typedef std::map<std::string, IdentifierScopePtr> SubScopeMap;
typedef std::map<std::string, ASTNodePtr> IdentifierDeclarationMap;
+
SubScopeMap subScopes_; //< sub scopes can be defined by types and namespaces
IdentifierDeclarationMap identifierDeclaration_; //< stores declaration of this scope !
***************
*** 73,76 ****
--- 80,85 ----
IdentifierScopeWeakPtr parent_;
IdentifierScopeWeakPtr root_; // the file scope
+
+ std::string name_; //< name of the scope
};
***************
*** 95,101 ****
}
! inline IdentifierScopePtr IdentifierScope::createScope(IdentifierScopeWeakPtr parent)
{
! IdentifierScopePtr scope( new IdentifierScope(parent) );
if ( ! boost::make_shared(parent) )
scope->root_ = scope;
--- 104,110 ----
}
! inline IdentifierScopePtr IdentifierScope::createScope(IdentifierScopeWeakPtr parent, std::string scopeName)
{
! IdentifierScopePtr scope( new IdentifierScope(parent, scopeName) );
if ( ! boost::make_shared(parent) )
scope->root_ = scope;
Index: IdentifierScope.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/IdentifierScope.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** IdentifierScope.cpp 6 Sep 2003 21:49:28 -0000 1.2
--- IdentifierScope.cpp 7 Sep 2003 13:28:58 -0000 1.3
***************
*** 11,17 ****
// constructor, sets parent and root node information
! IdentifierScope::IdentifierScope(IdentifierScopeWeakPtr parent)
{
parent_ = parent;
IdentifierScopePtr tmp = boost::make_shared(parent_);
--- 11,18 ----
// constructor, sets parent and root node information
! IdentifierScope::IdentifierScope(IdentifierScopeWeakPtr parent, std::string name)
{
parent_ = parent;
+ name_ = name;
IdentifierScopePtr tmp = boost::make_shared(parent_);
***************
*** 27,31 ****
throw IdentifierScopeException(IdentifierScopeException::InvalidScope);
! IdentifierScopePtr subScope = IdentifierScope::createScope(parent);
shrd_p->registerSubScope(scopeName, subScope);
--- 28,32 ----
throw IdentifierScopeException(IdentifierScopeException::InvalidScope);
! IdentifierScopePtr subScope = IdentifierScope::createScope(parent, scopeName);
shrd_p->registerSubScope(scopeName, subScope);
***************
*** 57,60 ****
--- 58,77 ----
}
+ bool
+ IdentifierScope::removeSubScope( IdentifierScopePtr child )
+ {
+ SubScopeMap::iterator it;
+ for( it = subScopes_.begin(); it != subScopes_.end() && it->second != child; )
+ it++;
+
+ if ( it != subScopes_.end() )
+ {
+ subScopes_.erase(it);
+ return true;
+ } else
+ return false;
+
+ }
+
void
IdentifierScope::addIdentifierDeclaration( std::string qualifiedName, ASTNodePtr declaration)
***************
*** 118,122 ****
IdentifierDeclarationMap::const_iterator it = identifierDeclaration_.find( qualifiedName );
if ( it == identifierDeclaration_.end() )
! return ASTNodePtr ();
else
return it->second;
--- 135,144 ----
IdentifierDeclarationMap::const_iterator it = identifierDeclaration_.find( qualifiedName );
if ( it == identifierDeclaration_.end() )
! {
! if (name_.empty() && !getParentScope().expired())
! return boost::make_shared(getParentScope())->getIdentifierDeclaration(qualifiedName);
! else
! return ASTNodePtr ();
! }
else
return it->second;
|