From: <bl...@us...> - 2003-04-29 22:01:00
|
Update of /cvsroot/cpptool/rfta/src/rftaparser In directory sc8-pr-cvs1:/tmp/cvs-serv28984/src/rftaparser Modified Files: ASTNodes.cpp CPPParser.cpp Log Message: * implemented CPPParser::parseFunctionImplementationAt() * added node type features to explorer up to function body level Index: ASTNodes.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/ASTNodes.cpp,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** ASTNodes.cpp 29 Apr 2003 10:29:16 -0000 1.21 --- ASTNodes.cpp 29 Apr 2003 22:00:53 -0000 1.22 *************** *** 11,15 **** { ! const ASTNodeType ASTNodeTypes::source( "source-file", isCompositeStatement ); const ASTNodeType ASTNodeTypes::unknownConstruct ( "unknown-construct" , 0 ); --- 11,15 ---- { ! const ASTNodeType ASTNodeTypes::source( "source-file", isCompositeStatement | mayHaveFunctionImplChildren ); const ASTNodeType ASTNodeTypes::unknownConstruct ( "unknown-construct" , 0 ); *************** *** 19,24 **** const ASTNodeType ASTNodeTypes::usingNamespace ( "using-namespace" , 0 ); const ASTNodeType ASTNodeTypes::namespaceAlias ( "namespace-alias" , mayHaveLocalScopeIdentifierChildren ); ! const ASTNodeType ASTNodeTypes::namespaceDeclaration ( "namespace-declaration" , mayHaveLocalScopeIdentifierChildren ); ! const ASTNodeType ASTNodeTypes::declarationList ( "declaration-list" , mayHaveLocalScopeIdentifierChildren ); const ASTNodeType ASTNodeTypes::functionImplementation ( "function-implementation" , mayHaveLocalScopeIdentifierChildren ); const ASTNodeType ASTNodeTypes::unparsedDeclarationList ( "unparsed-declaration-list", mayHaveLocalScopeIdentifierChildren ); --- 19,24 ---- const ASTNodeType ASTNodeTypes::usingNamespace ( "using-namespace" , 0 ); const ASTNodeType ASTNodeTypes::namespaceAlias ( "namespace-alias" , mayHaveLocalScopeIdentifierChildren ); ! const ASTNodeType ASTNodeTypes::namespaceDeclaration ( "namespace-declaration" , mayHaveLocalScopeIdentifierChildren | mayHaveFunctionImplChildren ); ! const ASTNodeType ASTNodeTypes::declarationList ( "declaration-list" , mayHaveLocalScopeIdentifierChildren | mayHaveFunctionImplChildren ); const ASTNodeType ASTNodeTypes::functionImplementation ( "function-implementation" , mayHaveLocalScopeIdentifierChildren ); const ASTNodeType ASTNodeTypes::unparsedDeclarationList ( "unparsed-declaration-list", mayHaveLocalScopeIdentifierChildren ); Index: CPPParser.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/CPPParser.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CPPParser.cpp 26 Apr 2003 21:13:35 -0000 1.1 --- CPPParser.cpp 29 Apr 2003 22:00:54 -0000 1.2 *************** *** 7,14 **** --- 7,77 ---- #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 ) { *************** *** 29,35 **** ! void CPPParser::parseForFunctionBodyAt( int position ) { } --- 92,102 ---- ! ASTNodePtr CPPParser::parseForFunctionBodyAt( int position ) { + parseAll(); + + FunctionImplementationVisitor visitor( position ); + return visitor.findFunctionImplementation( sourceNode_ ); } *************** *** 38,41 **** --- 105,109 ---- CPPParser::parseForFunctionDeclarations() { + parseAll(); } *************** *** 49,66 **** sourceNode_->getBlankedSourceEnd() ); ! try ! { ! if ( !parser.tryParse() ) ! { ! } // should report error in some way... ! MaxLODMutator mutator; ! mutator.mutate( sourceNode_, sourceNode_ ); ! } ! catch ( ParserError & ) ! { ! // should report error in some way... ! } } ! } // namespace Refactoring \ No newline at end of file --- 117,127 ---- sourceNode_->getBlankedSourceEnd() ); ! if ( !parser.tryParse() ) ! throw ParserError( "top level source file parsing failed.", context ); ! MaxLODMutator mutator; ! mutator.mutate( sourceNode_, sourceNode_ ); } ! } // namespace Refactoring ! |