Update of /cvsroot/cpptool/rfta/src/rftaparser In directory sc8-pr-cvs1:/tmp/cvs-serv20892/src/rftaparser Added Files: UnparsedDeclarationListMutator.cpp UnparsedDeclarationListMutator.h UnparsedDeclarationListMutatorTest.cpp UnparsedDeclarationListMutatorTest.h Log Message: -- moved to declaration list mutator --- NEW FILE: UnparsedDeclarationListMutator.cpp --- // ////////////////////////////////////////////////////////////////////////// // Implementation file UnparsedDeclarationListMutator.cpp for class UnparsedDeclarationListMutator // (c)Copyright 2003, Andre Baresel. // Created: 2003/04/14 // ////////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "UnparsedDeclarationListMutator.h" #include <rfta/parser/ASTNodes.h> #include <rfta/parser/ParseContext.h> #include <rfta/parser/DeclarationListParser.h> namespace Refactoring { UnparsedDeclarationListMutator::UnparsedDeclarationListMutator() { } UnparsedDeclarationListMutator::~UnparsedDeclarationListMutator() { } void UnparsedDeclarationListMutator::mutate( const ASTNodePtr &node, const SourceASTNodePtr &sourceNode ) const { ParseContext context( sourceNode ); const char *start = sourceNode->getBlankedSourceStart() + node->getStartIndex(); const char *end = start + node->getLength(); ++start; --end; ParseContext::ParentNodePusher pusher( node, context ); DeclarationListParser parser( context, start, end ); if ( parser.tryParse() ) { node->mutateType( ASTNodeTypes::declarationList ); } } } // namespace Refactoring --- NEW FILE: UnparsedDeclarationListMutator.h --- // ////////////////////////////////////////////////////////////////////////// // Header file UnparsedDeclarationListMutator.h for class UnparsedDeclarationListMutator // (c)Copyright 2003, Andre Baresel. // Created: 2003/04/14 // ////////////////////////////////////////////////////////////////////////// #ifndef RFTA_UnparsedDeclarationListMutator_H #define RFTA_UnparsedDeclarationListMutator_H #include <rfta/parser/Mutator.h> #include <boost/utility.hpp> namespace Refactoring { /// Mutate an unparsed-declaration-list into a parsed declaration-list class UnparsedDeclarationListMutator : public Mutator , public boost::noncopyable { public: /*! Constructs a UnparsedDeclarationListMutator object. */ UnparsedDeclarationListMutator(); /// Destructor. virtual ~UnparsedDeclarationListMutator(); void mutate( const ASTNodePtr &node, const SourceASTNodePtr &sourceNode ) const; }; // Inlines methods for UnparsedDeclarationListMutator: // -------------------------------------------- } // namespace Refactoring #endif // RFTA_UnparsedDeclarationListMutator_H --- NEW FILE: UnparsedDeclarationListMutatorTest.cpp --- // ////////////////////////////////////////////////////////////////////////// // Implementation file UnparsedDeclarationListMutatorTest.cpp for class UnparsedDeclarationListMutatorTest // (c)Copyright 2003, Andre Baresel. // Created: 2003/04/14 // ////////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "UnparsedDeclarationListMutator.h" #include "NamespaceParser.h" #include "UnparsedDeclarationListMutatorTest.h" #include <rfta/parser/ASTNode.h> #include <rfta/parser/ASTNodes.h> #include <rfta/parser/ParseContext.h> #include <rfta/parser/SourceASTNode.h> namespace Refactoring { RFTAPARSER_TEST_SUITE_REGISTRATION( UnparsedDeclarationListMutatorTest ); UnparsedDeclarationListMutatorTest::UnparsedDeclarationListMutatorTest() : CppUnit::TestFixture() { } UnparsedDeclarationListMutatorTest::~UnparsedDeclarationListMutatorTest() { } void UnparsedDeclarationListMutatorTest::setUp() { } void UnparsedDeclarationListMutatorTest::tearDown() { } void UnparsedDeclarationListMutatorTest::testMutate() { /* precreate a AST with a unparsed declaration list: */ const std::string source( "namespace y { int x; float (*f)(int x); } " ); SourceASTNodePtr sourceNode = SourceASTNode::create( source, source ); ParseContext context(sourceNode); NamespaceParser parser(context, sourceNode->getBlankedSourceStart(), sourceNode->getBlankedSourceEnd()); parser.parse(); ASTNodePtr namespaceNode = sourceNode->getChildAt(0); // check precondition for test: RFTA_ASSERT_NODE_HAS( namespaceNode->getProperty(ASTNodeProperties::namespaceBodyProperty), ASTNodeTypes::unparsedDeclarationList, 12, 29 ); ASTNodePtr namespaceBody = namespaceNode->getProperty(ASTNodeProperties::namespaceBodyProperty); // execute mutator test: UnparsedDeclarationListMutator mutator; mutator.mutate( namespaceBody, sourceNode ); // check post condition: RFTA_ASSERT_NODE_PROPERTY_HAS( namespaceNode, ASTNodeProperties::namespaceBodyProperty, ASTNodeTypes::declarationList, 12, 29); RFTA_ASSERT_EQUAL( 2, namespaceNode->getProperty(ASTNodeProperties::namespaceBodyProperty)->getChildCount() ); } } // namespace Refactoring --- NEW FILE: UnparsedDeclarationListMutatorTest.h --- // ////////////////////////////////////////////////////////////////////////// // Header file UnparsedDeclarationListMutatorTest.h for class UnparsedDeclarationListMutatorTest // (c)Copyright 2003, Andre Baresel. // Created: 2003/04/14 // ////////////////////////////////////////////////////////////////////////// #ifndef RFTA_UnparsedDeclarationListMutatorTest_H #define RFTA_UnparsedDeclarationListMutatorTest_H #include "ParserTesting.h" namespace Refactoring { /// Unit tests for UnparsedDeclarationListMutatorTest class UnparsedDeclarationListMutatorTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE( UnparsedDeclarationListMutatorTest ); CPPUNIT_TEST( testMutate ); CPPUNIT_TEST_SUITE_END(); public: /*! Constructs a UnparsedDeclarationListMutatorTest object. */ UnparsedDeclarationListMutatorTest(); /// Destructor. virtual ~UnparsedDeclarationListMutatorTest(); void setUp(); void tearDown(); void testMutate(); private: /// Prevents the use of the copy constructor. UnparsedDeclarationListMutatorTest( const UnparsedDeclarationListMutatorTest &other ); /// Prevents the use of the copy operator. void operator =( const UnparsedDeclarationListMutatorTest &other ); private: }; // Inlines methods for UnparsedDeclarationListMutatorTest: // ------------------------------------------------ } // namespace Refactoring #endif // RFTA_UnparsedDeclarationListMutatorTest_H |