Update of /cvsroot/cpptool/rfta/src/rftaparser In directory sc8-pr-cvs1:/tmp/cvs-serv426/src/rftaparser Modified Files: rftaparser.dsp Added Files: UnparsedNamespaceMutator.cpp UnparsedNamespaceMutator.h UnparsedNamespaceMutatorTest.cpp UnparsedNamespaceMutatorTest.h Log Message: -- namespace mutator added --- NEW FILE: UnparsedNamespaceMutator.cpp --- // ////////////////////////////////////////////////////////////////////////// // Implementation file UnparsedNamespaceMutator.cpp for class UnparsedNamespaceMutator // (c)Copyright 2003, Andre Baresel. // Created: 2003/04/14 // ////////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "UnparsedNamespaceMutator.h" #include <rfta/parser/ASTNodes.h> #include <rfta/parser/ParseContext.h> #include "DeclarationListParser.h" namespace Refactoring { UnparsedNamespaceMutator::UnparsedNamespaceMutator() { } UnparsedNamespaceMutator::~UnparsedNamespaceMutator() { } void UnparsedNamespaceMutator::mutate( const ASTNodePtr &node, const SourceASTNodePtr &sourceNode ) const { if ( node->hasProperty(ASTNodeProperties::namespaceBodyProperty ) ) { ASTNodePtr body = node->getProperty(ASTNodeProperties::namespaceBodyProperty); ParseContext context( sourceNode ); const char *start = sourceNode->getBlankedSourceStart() + body->getStartIndex(); const char *end = start + body->getLength(); ++start; --end; ParseContext::ParentNodePusher pusher( body, context ); DeclarationListParser parser( context, start, end ); if ( parser.tryParse() ) { node->mutateType( ASTNodeTypes::namespaceDeclaration ); body->mutateType( ASTNodeTypes::declarationList ); } } } } // namespace Refactoring --- NEW FILE: UnparsedNamespaceMutator.h --- // ////////////////////////////////////////////////////////////////////////// // Header file UnparsedNamespaceMutator.h for class UnparsedNamespaceMutator // (c)Copyright 2003, Andre Baresel. // Created: 2003/04/14 // ////////////////////////////////////////////////////////////////////////// #ifndef RFTA_UnparsedNamespaceMutator_H #define RFTA_UnparsedNamespaceMutator_H #include <rfta/parser/Mutator.h> #include <boost/utility.hpp> namespace Refactoring { /// Mutate an unparsed-namespace into a namespace with parsed body. class UnparsedNamespaceMutator : public Mutator , public boost::noncopyable { public: /*! Constructs a UnparsedNamespaceMutator object. */ UnparsedNamespaceMutator(); /// Destructor. virtual ~UnparsedNamespaceMutator(); void mutate( const ASTNodePtr &node, const SourceASTNodePtr &sourceNode ) const; }; // Inlines methods for UnparsedNamespaceMutator: // -------------------------------------------- } // namespace Refactoring #endif // RFTA_UnparsedNamespaceMutator_H --- NEW FILE: UnparsedNamespaceMutatorTest.cpp --- // ////////////////////////////////////////////////////////////////////////// // Implementation file UnparsedNamespaceMutatorTest.cpp for class UnparsedNamespaceMutatorTest // (c)Copyright 2003, Andre Baresel. // Created: 2003/04/14 // ////////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "UnparsedNamespaceMutator.h" #include "NamespaceParser.h" #include "UnparsedNamespaceMutatorTest.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( UnparsedNamespaceMutatorTest ); UnparsedNamespaceMutatorTest::UnparsedNamespaceMutatorTest() : CppUnit::TestFixture() { } UnparsedNamespaceMutatorTest::~UnparsedNamespaceMutatorTest() { } void UnparsedNamespaceMutatorTest::setUp() { } void UnparsedNamespaceMutatorTest::tearDown() { } void UnparsedNamespaceMutatorTest::testMutate() { const std::string source( "namespace y { int x; float (*f)(int x); } " ); SourceASTNodePtr sourceNode = SourceASTNode::create( source, source ); /* ASTNodePtr namespaceNode = ASTNode::create( ASTNodeTypes::unparsedNamespace, sourceNode, startIndex, length, sourceNode ); */ ParseContext context(sourceNode); NamespaceParser parser(context, sourceNode->getBlankedSourceStart(), sourceNode->getBlankedSourceEnd()); parser.parse(); ASTNodePtr namespaceNode = sourceNode->getChildAt(0); UnparsedNamespaceMutator mutator; mutator.mutate( namespaceNode, sourceNode ); RFTA_ASSERT_NODE_HAS( namespaceNode, ASTNodeTypes::namespaceDeclaration, 0, source.length()-2 ); 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: UnparsedNamespaceMutatorTest.h --- // ////////////////////////////////////////////////////////////////////////// // Header file UnparsedNamespaceMutatorTest.h for class UnparsedNamespaceMutatorTest // (c)Copyright 2003, Andre Baresel. // Created: 2003/04/14 // ////////////////////////////////////////////////////////////////////////// #ifndef RFTA_UnparsedNamespaceMutatorTest_H #define RFTA_UnparsedNamespaceMutatorTest_H #include "ParserTesting.h" namespace Refactoring { /// Unit tests for UnparsedNamespaceMutatorTest class UnparsedNamespaceMutatorTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE( UnparsedNamespaceMutatorTest ); CPPUNIT_TEST( testMutate ); CPPUNIT_TEST_SUITE_END(); public: /*! Constructs a UnparsedNamespaceMutatorTest object. */ UnparsedNamespaceMutatorTest(); /// Destructor. virtual ~UnparsedNamespaceMutatorTest(); void setUp(); void tearDown(); void testMutate(); private: /// Prevents the use of the copy constructor. UnparsedNamespaceMutatorTest( const UnparsedNamespaceMutatorTest &other ); /// Prevents the use of the copy operator. void operator =( const UnparsedNamespaceMutatorTest &other ); private: }; // Inlines methods for UnparsedNamespaceMutatorTest: // ------------------------------------------------ } // namespace Refactoring #endif // RFTA_UnparsedNamespaceMutatorTest_H Index: rftaparser.dsp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/rftaparser.dsp,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** rftaparser.dsp 12 Apr 2003 19:07:07 -0000 1.33 --- rftaparser.dsp 14 Apr 2003 19:45:14 -0000 1.34 *************** *** 166,170 **** # Begin Source File ! SOURCE=.\DeclarationListParser.h # End Source File # Begin Source File --- 166,170 ---- # Begin Source File ! SOURCE=..\..\include\rfta\parser\DeclarationListParser.h # End Source File # Begin Source File *************** *** 182,186 **** # Begin Source File ! SOURCE=.\DeclarationParser.h # End Source File # Begin Source File --- 182,186 ---- # Begin Source File ! SOURCE=..\..\include\rfta\parser\DeclarationParser.h # End Source File # Begin Source File *************** *** 406,409 **** --- 406,417 ---- # Begin Source File + SOURCE=.\UnparsedNamespaceMutator.cpp + # End Source File + # Begin Source File + + SOURCE=.\UnparsedNamespaceMutator.h + # End Source File + # Begin Source File + SOURCE=.\VariableDeclMutator.cpp # End Source File *************** *** 1034,1037 **** --- 1042,1053 ---- !ENDIF + # End Source File + # Begin Source File + + SOURCE=.\UnparsedNamespaceMutatorTest.cpp + # End Source File + # Begin Source File + + SOURCE=.\UnparsedNamespaceMutatorTest.h # End Source File # Begin Source File |