From: <bl...@us...> - 2003-04-29 22:13:22
|
Update of /cvsroot/cpptool/rfta/bin In directory sc8-pr-cvs1:/tmp/cvs-serv23650/bin Modified Files: test.bat Added Files: CPPParser.cpp Log Message: * added a test using CPPParser.cpp (with class declaration in anonymous namespace and inline method implementation) --- NEW FILE: CPPParser.cpp --- #include "stdafx.h" #include <rfta/parser/CPPParser.h> #include <rfta/parser/NonSemanticBlanker.h> #include <rfta/parser/MaxLODMutator.h> #include <rfta/parser/DeclarationListParser.h> #include <rfta/parser/ParseContext.h> #include <rfta/parser/ParserError.h> #include <rfta/parser/ASTNodeAndPropertyVisitor.h> #include <rfta/parser/ASTNodes.h> namespace Refactoring { namespace { class FunctionImplementationVisitor : public ASTNodeAndPropertyVisitor { public: FunctionImplementationVisitor( int functionBodyPosition ) : functionBodyPosition_( functionBodyPosition ) , foundFunction_( false ) { } ASTNodePtr findFunctionImplementation( const ASTNodePtr &node ) { visitNode( node ); if ( !foundFunction_ ) return ASTNodePtr(); return functionImplementationNode_; } protected: // overridden from ASTNodeAndPropertyVisitor bool canSkipNode( const ASTNodePtr &node ) const { return foundFunction_; } bool needsToVisitProperties( const ASTNodePtr &node ) const { return !foundFunction_; } bool needsToVisitChildren( const ASTNodePtr &node ) const { return node->getType().hasSomeFeatureOf( ASTNodeTypeFeatures::mayHaveFunctionImplChildren ); } bool needsToHandleNode( const ASTNodePtr& node ) const { return node->getType() == ASTNodeTypes::functionImplementation && !foundFunction_; } void handleNode( const ASTNodePtr& node ) { if ( node->getRange().contains( SourceRange( functionBodyPosition_,0 ) ) ) { foundFunction_ = true; functionImplementationNode_ = node; } } private: bool foundFunction_; int functionBodyPosition_; ASTNodePtr functionImplementationNode_; }; } CPPParser::CPPParser( const std::string &source ) { NullPPDirectiveListener nullListener; std::string blankedSource; NonSemanticBlanker blanker( source, blankedSource, nullListener ); blanker.blank(); sourceNode_ = SourceASTNode::create( blankedSource, source ); } SourceASTNodePtr CPPParser::getSourceNode() const { return sourceNode_; } ASTNodePtr CPPParser::parseForFunctionBodyAt( int position ) { parseAll(); FunctionImplementationVisitor visitor( position ); return visitor.findFunctionImplementation( sourceNode_ ); } void CPPParser::parseForFunctionDeclarations() { parseAll(); } void CPPParser::parseAll() { ParseContext context( sourceNode_ ); DeclarationListParser parser( context, sourceNode_->getBlankedSourceStart(), sourceNode_->getBlankedSourceEnd() ); if ( !parser.tryParse() ) throw ParserError( "top level source file parsing failed.", context ); MaxLODMutator mutator; mutator.mutate( sourceNode_, sourceNode_ ); } */ } // namespace Refactoring Index: test.bat =================================================================== RCS file: /cvsroot/cpptool/rfta/bin/test.bat,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** test.bat 29 Apr 2003 10:06:11 -0000 1.9 --- test.bat 29 Apr 2003 21:46:55 -0000 1.10 *************** *** 7,9 **** --- 7,10 ---- rem astdump 0 15 DeclarativeCondition.cpp ast rem astdump 0 4 ForDeclaration.cpp ast + astdump 1 127 CPPParser.cpp ast |