From: <net...@us...> - 2003-04-05 12:13:39
|
Update of /cvsroot/cpptool/rfta/src/rfta In directory sc8-pr-cvs1:/tmp/cvs-serv16599/src/rfta Modified Files: InlineTempRefactoringTest.h InlineTempRefactoringTest.cpp InlineTempRefactoring.cpp Log Message: bugfix + new tests for bug Index: InlineTempRefactoringTest.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/InlineTempRefactoringTest.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** InlineTempRefactoringTest.h 30 Dec 2002 10:44:08 -0000 1.2 --- InlineTempRefactoringTest.h 5 Apr 2003 12:13:36 -0000 1.3 *************** *** 22,26 **** CPPUNIT_TEST( testThrowNoInitializer ); CPPUNIT_TEST( testThrowInitializerNotSupported ); ! CPPUNIT_TEST( testThrowVariableAssigned ); CPPUNIT_TEST( testDetectComplexVariableAssignments ); CPPUNIT_TEST( testMultipleDeclarationInitLast ); --- 22,26 ---- CPPUNIT_TEST( testThrowNoInitializer ); CPPUNIT_TEST( testThrowInitializerNotSupported ); ! CPPUNIT_TEST( testThrowVariableAssigned ); CPPUNIT_TEST( testDetectComplexVariableAssignments ); CPPUNIT_TEST( testMultipleDeclarationInitLast ); *************** *** 28,31 **** --- 28,33 ---- CPPUNIT_TEST( testMultipleDeclarationInitMiddle ); CPPUNIT_TEST( testInitExpression ); + CPPUNIT_TEST( testSelectInSubScope ); + CPPUNIT_TEST( testThrowNoDeclaration ); CPPUNIT_TEST_SUITE_END(); *************** *** 53,56 **** --- 55,61 ---- void testInitExpression(); + + void testSelectInSubScope(); + void testThrowNoDeclaration(); private: Index: InlineTempRefactoringTest.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/InlineTempRefactoringTest.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** InlineTempRefactoringTest.cpp 30 Dec 2002 13:57:22 -0000 1.3 --- InlineTempRefactoringTest.cpp 5 Apr 2003 12:13:36 -0000 1.4 *************** *** 317,320 **** --- 317,362 ---- } + void + InlineTempRefactoringTest::testSelectInSubScope() + { + builder_->add( + "{" + " double y,x = 4;" ); + builder_->addKeyingMid( " {y += y * ","x",";}", "selection" ); + + builder_->add( + " return x * getQuantity();" + "}" ); + + applyRefactoring( "x" ); + + std::string expectedSource( + "{" + " double y;" + " {y += y * 4;}" + " return 4 * getQuantity();" + "}" ); + std::string actualSource( document_->getAllText() ); + RFTA_ASSERT_EQUAL( expectedSource, actualSource ); + } + + void + InlineTempRefactoringTest::testThrowNoDeclaration() + { + builder_->add( + "namespace xx { int x;" + "int func() { double y;" ); + builder_->addKeyingMid( " {y += y * ","x",";}", "selection" ); + + builder_->add( + " return x * getQuantity();" + "}" ); + + builder_->add( + "}"); + + applyRefactoringExpectThrow( "x", RefactoringError::identifierIsNotLocalVariable, CPPUNIT_SOURCELINE() ); + } + } // namespace Refactoring Index: InlineTempRefactoring.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/InlineTempRefactoring.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** InlineTempRefactoring.cpp 15 Mar 2003 16:57:39 -0000 1.5 --- InlineTempRefactoring.cpp 5 Apr 2003 12:13:36 -0000 1.6 *************** *** 11,14 **** --- 11,15 ---- #include <rfta/parser/ParseContext.h> #include <rfta/parser/StatementParser.h> + #include <rfta/parser/ParserError.h> #include <rfta/parser/MaxLODMutator.h> #include <rfta/parser/ExpressionOperationMutator.h> *************** *** 19,23 **** #include "TransformList.h" - namespace Refactoring { --- 20,23 ---- *************** *** 72,97 **** blanker.blank(); ! // find the compound statement where the temporary is located: ! int compoundStartIndex = ! ToolsBox::findCompoundBefore( blankedSource, temporaryLocation_ ); ! if ( compoundStartIndex < 0 ) ! throw RefactoringError( RefactoringError::temporaryNotInFunctionBody ); ! // 'lazy' parse the source ! sourceNode_ = SourceASTNode::create( blankedSource, source ); ! ParseContext context( sourceNode_ ); ! StatementParser parser( context, ! sourceNode_->getBlankedSourceStart() + ! compoundStartIndex, ! sourceNode_->getBlankedSourceEnd() ); ! parser.parse(); ! // do mutate to highest level until we know how to do it 'lazy' ! MaxLODMutator mutator; ! mutator.mutate( sourceNode_, sourceNode_ ); ! // find all occurrences of the temporary. ! findLocaleVariableOccurrences(); // check for initializer property and throw exception if not found --- 72,123 ---- blanker.blank(); ! int start_at = temporaryLocation_; ! bool scope_extended = false; ! while (true) ! { ! // find the compound statement where the temporary is located: ! int compoundStartIndex = ! ToolsBox::findCompoundBefore( blankedSource, start_at ); ! if ( compoundStartIndex < 0 ) ! throw RefactoringError( RefactoringError::temporaryNotInFunctionBody ); ! // 'lazy' parse the source ! sourceNode_ = SourceASTNode::create( blankedSource, source ); ! ParseContext context( sourceNode_ ); ! StatementParser parser( context, ! sourceNode_->getBlankedSourceStart() + ! compoundStartIndex, ! sourceNode_->getBlankedSourceEnd() ); ! try { ! parser.parse(); ! // do mutate to highest level until we know how to do it 'lazy' ! MaxLODMutator mutator; ! mutator.mutate( sourceNode_, sourceNode_ ); ! } ! catch (ParserError e) ! { ! // tried to parse outside a function body ? ! // TODO: is this change of the exception ok ? (AndreBaresel) ! throw RefactoringError( RefactoringError::identifierIsNotLocalVariable); ! } ! try { ! // find all occurrences of the temporary. ! findLocaleVariableOccurrences(); ! break; ! } ! catch (RefactoringError e) ! { ! if (e.getCause() == RefactoringError::identifierIsNotLocalVariable) ! { ! start_at = compoundStartIndex-1; ! if (start_at>=0) ! continue; ! } ! throw e; ! } ! } // check for initializer property and throw exception if not found |