From: <net...@us...> - 2003-09-06 21:46:11
|
Update of /cvsroot/cpptool/rfta/src/rfta In directory sc8-pr-cvs1:/tmp/cvs-serv447/src/rfta Added Files: GlobalIdentifierResolver.h GlobalIdentifierResolver.cpp Log Message: -- global identifier resolver (does call IdentifierResolver for local searches) --- NEW FILE: GlobalIdentifierResolver.h --- // ////////////////////////////////////////////////////////////////////////// // (c)Copyright 2003, Andre Baresel. // Created: 2003/08/27 // ////////////////////////////////////////////////////////////////////////// #ifndef RFTA_GlobalIdentifierResolver_H #define RFTA_GlobalIdentifierResolver_H #include <rfta/refactoring/Config.h> #include <rfta/parser/ASTNode.h> #include <rfta/parser/ASTNodeAndPropertyVisitor.h> #include <rfta/parser/ASTNodeVisitor.h> namespace Refactoring { // just abstract: class IdentifierResolverStrategy; /// Explores an AST searching for local scope identifiers. class GlobalIdentifierResolver : public ASTNodeAndPropertyVisitor { public: GlobalIdentifierResolver ( IdentifierResolverStrategy &context ); virtual void visitNode( const ASTNodePtr &node ); protected: bool canSkipNode( const ASTNodePtr& node ) const; bool needsToVisitProperties( const ASTNodePtr& node ) const; bool needsToVisitChildren( const ASTNodePtr& node ) const; bool needsToHandleNode( const ASTNodePtr& node ) const; void handleNode( const ASTNodePtr& node ); private: IdentifierResolverStrategy &context_; }; } // namespace Refactoring #endif // RFTA_GlobalIdentifierResolver_H --- NEW FILE: GlobalIdentifierResolver.cpp --- // ////////////////////////////////////////////////////////////////////////// // (c)Copyright 2003, Andre Baresel // Created: 2003/08/27 // ////////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "GlobalIdentifierResolver.h" #include "IdentifierResolver.h" #include "IdentifierResolverStrategy.h" #include <rfta/Parser/ASTNodes.h> namespace Refactoring { void GlobalIdentifierResolver::visitNode( const ASTNodePtr &node ) { // actions before visiting properties and childs if (node->getType() == ASTNodeTypes::classSpecifier) { // add class definition reference... context_.declareClass(node); // add namespace if (node->hasProperty(ASTNodeProperties::classNameProperty)) { // named classes ASTNodePtr classIdent = node->getProperty(ASTNodeProperties::classNameProperty); std::string ident = classIdent->getBlankedText(); context_.enterNamedSubScope(ident); ASTNodeAndPropertyVisitor::visitNode(node); context_.leaveNamedSubScope(); } else { // unnamed classes: context_.enterUnnamedSubScope(); ASTNodeAndPropertyVisitor::visitNode(node); context_.leaveNamedSubScope(); } } else { // visit properties and childs: ASTNodeAndPropertyVisitor::visitNode(node); } } GlobalIdentifierResolver::GlobalIdentifierResolver ( IdentifierResolverStrategy &context ): context_(context) { } bool GlobalIdentifierResolver::canSkipNode(const ASTNodePtr& node) const { return false; } bool GlobalIdentifierResolver::needsToVisitProperties(const ASTNodePtr& node ) const { if (node->getType() == ASTNodeTypes::compoundStatement) return false; return true; } bool GlobalIdentifierResolver::needsToVisitChildren(const ASTNodePtr& node ) const { if (node->getType() == ASTNodeTypes::compoundStatement) return false; return true; } bool GlobalIdentifierResolver::needsToHandleNode( const ASTNodePtr& node ) const { return true; } void GlobalIdentifierResolver::handleNode( const ASTNodePtr& node ) { if (node->getType() == ASTNodeTypes::compoundStatement) { // make reuse of Old-Identifier-Resolver IdentifierResolver resolve(context_); resolve.visitNode(node); return; } if (node->getType() == ASTNodeTypes::declarator) { // get the identifier node ASTNodePtr ident = node->getChildAt(0); context_.declareLocalVariable(ident); } } } // namespace Refactoring |