|
From: <net...@us...> - 2003-09-06 21:52:51
|
Update of /cvsroot/cpptool/rfta/src/rfta
In directory sc8-pr-cvs1:/tmp/cvs-serv1754/src/rfta
Modified Files:
IdentifierResolverContextTest.cpp IdentifierResolverContext.h
IdentifierResolverContext.cpp
Log Message:
-- preparations for global identifier resolver (global do not work yet)
Index: IdentifierResolverContextTest.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/IdentifierResolverContextTest.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** IdentifierResolverContextTest.cpp 15 May 2003 16:29:13 -0000 1.6
--- IdentifierResolverContextTest.cpp 6 Sep 2003 21:52:46 -0000 1.7
***************
*** 57,64 ****
ASTNodePtr x0 = getVariableNode( "x.0" );
ASTNodePtr x1 = getIdentifierNode( "x.1" );
! context_->enterNewLocalVariableScope();
context_->declareLocalVariable( x0 );
context_->resolveUnqualifiedIdentifier( x1 );
! context_->exitLocalVariableScope();
CPPUNIT_ASSERT( context_->isLocalVariableIdentifier( x1 ) );
--- 57,64 ----
ASTNodePtr x0 = getVariableNode( "x.0" );
ASTNodePtr x1 = getIdentifierNode( "x.1" );
! context_->enterUnnamedSubScope();
context_->declareLocalVariable( x0 );
context_->resolveUnqualifiedIdentifier( x1 );
! context_->leaveUnnamedSubScope();
CPPUNIT_ASSERT( context_->isLocalVariableIdentifier( x1 ) );
***************
*** 95,112 ****
ASTNodePtr xb0 = getVariableNode( "x.b.0" );
ASTNodePtr xb1 = getIdentifierNode( "x.b.1" );
! context_->enterNewLocalVariableScope();
context_->declareLocalVariable( x0 );
context_->resolveUnqualifiedIdentifier( x1 );
context_->declareLocalVariable( y0 );
! context_->enterNewLocalVariableScope();
context_->declareLocalVariable( xb0 );
context_->resolveUnqualifiedIdentifier( xb1 );
context_->resolveUnqualifiedIdentifier( y1 );
! context_->exitLocalVariableScope();
context_->resolveUnqualifiedIdentifier( y2 );
context_->resolveUnqualifiedIdentifier( x2 );
! context_->exitLocalVariableScope();
CPPUNIT_ASSERT( context_->isLocalVariableIdentifier( x1 ) );
--- 95,112 ----
ASTNodePtr xb0 = getVariableNode( "x.b.0" );
ASTNodePtr xb1 = getIdentifierNode( "x.b.1" );
! context_->enterUnnamedSubScope();
context_->declareLocalVariable( x0 );
context_->resolveUnqualifiedIdentifier( x1 );
context_->declareLocalVariable( y0 );
! context_->enterUnnamedSubScope();
context_->declareLocalVariable( xb0 );
context_->resolveUnqualifiedIdentifier( xb1 );
context_->resolveUnqualifiedIdentifier( y1 );
! context_->leaveUnnamedSubScope();
context_->resolveUnqualifiedIdentifier( y2 );
context_->resolveUnqualifiedIdentifier( x2 );
! context_->leaveUnnamedSubScope();
CPPUNIT_ASSERT( context_->isLocalVariableIdentifier( x1 ) );
***************
*** 145,156 ****
ASTNodePtr x0 = getVariableNode( "x.0" );
ASTNodePtr y0 = getVariableNode( "y.0" );
! context_->enterNewLocalVariableScope();
context_->declareLocalVariable( x0 );
! context_->enterNewLocalVariableScope();
context_->declareLocalVariable( y0 );
! context_->exitLocalVariableScope();
! context_->exitLocalVariableScope();
CPPUNIT_ASSERT( context_->isLocalVariableIdentifier( getIdentifierNode( "x.0" ) ) );
--- 145,156 ----
ASTNodePtr x0 = getVariableNode( "x.0" );
ASTNodePtr y0 = getVariableNode( "y.0" );
! context_->enterUnnamedSubScope();
context_->declareLocalVariable( x0 );
! context_->enterUnnamedSubScope();
context_->declareLocalVariable( y0 );
! context_->leaveUnnamedSubScope();
! context_->leaveUnnamedSubScope();
CPPUNIT_ASSERT( context_->isLocalVariableIdentifier( getIdentifierNode( "x.0" ) ) );
***************
*** 177,188 ****
ASTNodePtr x0 = getVariableNode( "x.0" );
ASTNodePtr x1 = getIdentifierNode( "x.1" );
! context_->enterNewLocalVariableScope();
! context_->enterNewLocalVariableScope();
context_->declareLocalVariable( x0 );
! context_->exitLocalVariableScope();
context_->resolveUnqualifiedIdentifier( x1 );
! context_->exitLocalVariableScope();
CPPUNIT_ASSERT( context_->isLocalVariableIdentifier( getIdentifierNode( "x.0" ) ) );
--- 177,188 ----
ASTNodePtr x0 = getVariableNode( "x.0" );
ASTNodePtr x1 = getIdentifierNode( "x.1" );
! context_->enterUnnamedSubScope();
! context_->enterUnnamedSubScope();
context_->declareLocalVariable( x0 );
! context_->leaveUnnamedSubScope();
context_->resolveUnqualifiedIdentifier( x1 );
! context_->leaveUnnamedSubScope();
CPPUNIT_ASSERT( context_->isLocalVariableIdentifier( getIdentifierNode( "x.0" ) ) );
Index: IdentifierResolverContext.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/IdentifierResolverContext.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** IdentifierResolverContext.h 27 Apr 2003 22:02:02 -0000 1.5
--- IdentifierResolverContext.h 6 Sep 2003 21:52:46 -0000 1.6
***************
*** 7,10 ****
--- 7,11 ----
#include "IdentifierResolverStrategy.h"
+ #include "IdentifierScope.h"
#include <boost/utility.hpp>
#include <rfta/parser/SourceASTNode.h>
***************
*** 49,59 ****
public: // overriden from IdentifierResolverStrategy
! void enterNewLocalVariableScope();
! void exitLocalVariableScope();
! void declareLocalVariable( const ASTNodePtr &localVariableDeclNode );
void resolveUnqualifiedIdentifier( const ASTNodePtr &identifierNode );
private:
ASTNodePtr getLocalVariableNameNode( const ASTNodePtr &localVariableDeclNode ) const;
--- 50,68 ----
public: // overriden from IdentifierResolverStrategy
! void enterUnnamedSubScope();
! void leaveUnnamedSubScope();
! void declareLocalVariable( const ASTNodePtr &localVariableDeclNode );
void resolveUnqualifiedIdentifier( const ASTNodePtr &identifierNode );
+ void enterNamedSubScope(std::string name);
+ void leaveNamedSubScope();
+
+ void declareClass( const ASTNodePtr &specifierNode);
+
+ void addScopeLookup(std::string qualifiedName);
+ void removeScopeLookup(std::string qualifiedName);
+
private:
ASTNodePtr getLocalVariableNameNode( const ASTNodePtr &localVariableDeclNode ) const;
***************
*** 70,73 ****
--- 79,87 ----
typedef std::map<ASTNodePtr,ASTNodePtr> ResolvedUnqualifiedIdentifiers;
ResolvedUnqualifiedIdentifiers resolvedIdentifiers_;
+
+ //> information on persistent identifier scopes (classes / namespaces)
+ IdentifierScopePtr identifierRootScope_;
+ IdentifierScopePtr identifierCurrentScope_;
+ std::vector<IdentifierScopePtr> scopeLookups_;
};
Index: IdentifierResolverContext.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/IdentifierResolverContext.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** IdentifierResolverContext.cpp 10 May 2003 10:55:14 -0000 1.8
--- IdentifierResolverContext.cpp 6 Sep 2003 21:52:46 -0000 1.9
***************
*** 15,18 ****
--- 15,20 ----
IdentifierResolverContext::IdentifierResolverContext()
{
+ identifierRootScope_ = IdentifierScope::createScope(IdentifierScopeWeakPtr());
+ identifierCurrentScope_ = identifierRootScope_;
}
***************
*** 20,28 ****
IdentifierResolverContext::~IdentifierResolverContext()
{
}
void
! IdentifierResolverContext::enterNewLocalVariableScope()
{
scopeLocalVariables_.push_back( LocalVariables() );
--- 22,33 ----
IdentifierResolverContext::~IdentifierResolverContext()
{
+ scopeLookups_.erase(scopeLookups_.begin(),scopeLookups_.end());
+ identifierCurrentScope_.reset();
+ identifierRootScope_.reset();
}
void
! IdentifierResolverContext::enterUnnamedSubScope()
{
scopeLocalVariables_.push_back( LocalVariables() );
***************
*** 31,39 ****
void
! IdentifierResolverContext::exitLocalVariableScope()
{
if ( scopeLocalVariables_.empty() )
! throw std::logic_error( "IdentifierResolverContext::exitLocalVariableScope(): "
! "no matching enterNewLocalVariableScope()." );
LocalVariables &variables = scopeLocalVariables_.back();
--- 36,44 ----
void
! IdentifierResolverContext::leaveUnnamedSubScope()
{
if ( scopeLocalVariables_.empty() )
! throw std::logic_error( "IdentifierResolverContext::leaveUnnamedSubScope(): "
! "no matching enterUnnamedSubScope()." );
LocalVariables &variables = scopeLocalVariables_.back();
***************
*** 47,51 ****
if ( itName == visibleLocalVariables_.end() )
{
! throw std::logic_error( "IdentifierResolverContext::exitLocalVariableScope(): "
"inconsitent state, variable declared but not in visible variable list." );
}
--- 52,56 ----
if ( itName == visibleLocalVariables_.end() )
{
! throw std::logic_error( "IdentifierResolverContext::leaveUnnamedSubScope(): "
"inconsitent state, variable declared but not in visible variable list." );
}
***************
*** 140,143 ****
--- 145,187 ----
{
return identifierNode->getBlankedText();
+ }
+
+ void
+ IdentifierResolverContext::enterNamedSubScope(std::string name)
+ {
+ identifierCurrentScope_ = IdentifierScope::createSubScope(identifierCurrentScope_,name);
+ }
+
+ void
+ IdentifierResolverContext::leaveNamedSubScope()
+ {
+ identifierCurrentScope_ = boost::make_shared( identifierCurrentScope_->getParentScope() );
+ }
+
+ void
+ IdentifierResolverContext::addScopeLookup(std::string qualifiedName)
+ {
+ IdentifierScopePtr specifiedScope = identifierCurrentScope_->getQualifiedScope( qualifiedName );
+ scopeLookups_.push_back( specifiedScope );
+ }
+
+ void
+ IdentifierResolverContext::removeScopeLookup(std::string qualifiedName)
+ {
+ IdentifierScopePtr specifiedScope = identifierCurrentScope_->getQualifiedScope( qualifiedName );
+
+ std::vector<IdentifierScopePtr>::iterator it;
+ for (it = scopeLookups_.begin(); it != scopeLookups_.end(); it++)
+ if (*it == specifiedScope)
+ {
+ scopeLookups_.erase(it);
+ it--;
+ }
+ }
+
+ void
+ IdentifierResolverContext::declareClass( const ASTNodePtr &specifierNode)
+ {
+ //TODO: Implement this...
}
|