You can subscribe to this list here.
2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(37) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
(15) |
Feb
(26) |
Mar
(97) |
Apr
(224) |
May
(226) |
Jun
|
Jul
(3) |
Aug
(22) |
Sep
(48) |
Oct
|
Nov
|
Dec
(38) |
2004 |
Jan
(28) |
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
(37) |
Jul
|
Aug
(73) |
Sep
|
Oct
|
Nov
|
Dec
|
From: <bl...@us...> - 2003-03-24 07:58:25
|
Update of /cvsroot/cpptool/rfta/include/rfta/refactoring In directory sc8-pr-cvs1:/tmp/cvs-serv4949/include/rfta/refactoring Modified Files: CodeModel.h CodeModelExpressions.h CodeModelForward.h Log Message: * adding a separator between variable declaration. Index: CodeModel.h =================================================================== RCS file: /cvsroot/cpptool/rfta/include/rfta/refactoring/CodeModel.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CodeModel.h 16 Mar 2003 13:44:24 -0000 1.2 --- CodeModel.h 24 Mar 2003 07:57:49 -0000 1.3 *************** *** 55,59 **** void setElementSource( Element &element, const ASTNodePtr &node ); ! const std::string getDeclaratorPrimaryType( const ASTNodePtr &declaratorNode ); const Declarator makeVariableDeclarator( const ASTNodePtr &variableDeclaratorNode ); ExpressionPtr makeVariableInitializerExpression( const ASTNodePtr &initializerNode ); --- 55,59 ---- void setElementSource( Element &element, const ASTNodePtr &node ); ! TypePartPtr getDeclaratorPrimaryType( const ASTNodePtr &declaratorNode ); const Declarator makeVariableDeclarator( const ASTNodePtr &variableDeclaratorNode ); ExpressionPtr makeVariableInitializerExpression( const ASTNodePtr &initializerNode ); Index: CodeModelExpressions.h =================================================================== RCS file: /cvsroot/cpptool/rfta/include/rfta/refactoring/CodeModelExpressions.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** CodeModelExpressions.h 16 Mar 2003 16:18:39 -0000 1.10 --- CodeModelExpressions.h 24 Mar 2003 07:57:49 -0000 1.11 *************** *** 50,60 **** }; class DeclaratorExpression : public Expression { public: ! DeclaratorExpression( const std::string primaryType ); - std::string getPrimaryType() const; - void setPrimaryType( const std::string &primaryType ); int getDeclaratorCount() const; --- 50,77 ---- }; + + class TypePart : public Element + { + public: + TypePart( const std::string &typePart = "" ); + + std::string getTypeText() const; + + private: + std::string typePart_; + }; + + class DeclaratorExpression : public Expression { public: ! DeclaratorExpression( const TypePartPtr &primaryType ); ! ! TypePartPtr getPrimaryType() const; ! ! void setPrimaryType( const TypePartPtr &primaryType ); ! ! Change getPrimaryTypeChange() const; int getDeclaratorCount() const; *************** *** 72,76 **** typedef std::vector<Declarator> Declarators; Declarators declarators_; ! std::string primaryType_; }; --- 89,93 ---- typedef std::vector<Declarator> Declarators; Declarators declarators_; ! ChangeTracker<TypePartPtr> primaryTypeTracker_; }; Index: CodeModelForward.h =================================================================== RCS file: /cvsroot/cpptool/rfta/include/rfta/refactoring/CodeModelForward.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** CodeModelForward.h 21 Mar 2003 07:32:25 -0000 1.10 --- CodeModelForward.h 24 Mar 2003 07:57:49 -0000 1.11 *************** *** 15,18 **** --- 15,19 ---- class Element; class Label; + class TypePart; class BreakStatement; *************** *** 53,56 **** --- 54,58 ---- typedef boost::shared_ptr<Element> ElementPtr; typedef boost::shared_ptr<Label> LabelPtr; + typedef boost::shared_ptr<TypePart> TypePartPtr; typedef boost::shared_ptr<DeclaratorExpression> DeclaratorExpressionPtr; typedef boost::shared_ptr<Expression> ExpressionPtr; |
From: <bl...@us...> - 2003-03-24 07:58:23
|
Update of /cvsroot/cpptool/rfta/include/rfta/parser In directory sc8-pr-cvs1:/tmp/cvs-serv4949/include/rfta/parser Modified Files: ASTNodes.h Log Message: * adding a separator between variable declaration. Index: ASTNodes.h =================================================================== RCS file: /cvsroot/cpptool/rfta/include/rfta/parser/ASTNodes.h,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** ASTNodes.h 18 Mar 2003 08:10:26 -0000 1.12 --- ASTNodes.h 24 Mar 2003 07:57:49 -0000 1.13 *************** *** 149,152 **** --- 149,153 ---- /// TypePrefix id[suffix]; static const ASTNodeProperty typeDeclSuffixProperty; + static const ASTNodeProperty typeDeclSeparator; /// TypePrefix id[suffix]; |
From: <bl...@us...> - 2003-03-24 07:57:55
|
Update of /cvsroot/cpptool/rfta/src/rftaparser In directory sc8-pr-cvs1:/tmp/cvs-serv4949/src/rftaparser Modified Files: ASTNodes.cpp Log Message: * adding a separator between variable declaration. Index: ASTNodes.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/ASTNodes.cpp,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** ASTNodes.cpp 18 Mar 2003 08:10:54 -0000 1.14 --- ASTNodes.cpp 24 Mar 2003 07:57:51 -0000 1.15 *************** *** 79,82 **** --- 79,84 ---- const ASTNodeProperty ASTNodeProperties::expressionTypeProperty ( "expression-type-property" ); + + const ASTNodeProperty ASTNodeProperties::typeDeclSeparator( "type-decl-separator-property" ); } // namespace Refactoring |
Update of /cvsroot/cpptool/rfta/src/rfta In directory sc8-pr-cvs1:/tmp/cvs-serv4949/src/rfta Modified Files: CodeModel.cpp CodeModelExpressions.cpp CodeModelGeneratorTest.cpp CodeRewriter.cpp CodeWriterInsertTest.cpp CodeWriterTestBase.cpp CodeWriterTestBase.h Log Message: * adding a separator between variable declaration. Index: CodeModel.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeModel.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** CodeModel.cpp 18 Mar 2003 22:37:46 -0000 1.8 --- CodeModel.cpp 24 Mar 2003 07:57:51 -0000 1.9 *************** *** 312,316 **** Generator::generateDeclarator( const ASTNodePtr &expression ) { ! const std::string primaryType( getDeclaratorPrimaryType( expression ) ); DeclaratorExpressionPtr declaratorExpression( new DeclaratorExpression( primaryType ) ); setElementSource( *declaratorExpression, expression ); --- 312,316 ---- Generator::generateDeclarator( const ASTNodePtr &expression ) { ! TypePartPtr primaryType( getDeclaratorPrimaryType( expression ) ); DeclaratorExpressionPtr declaratorExpression( new DeclaratorExpression( primaryType ) ); setElementSource( *declaratorExpression, expression ); *************** *** 328,332 **** ! const std::string Generator::getDeclaratorPrimaryType( const ASTNodePtr &declaratorNode ) { --- 328,332 ---- ! TypePartPtr Generator::getDeclaratorPrimaryType( const ASTNodePtr &declaratorNode ) { *************** *** 334,338 **** ASTNodePtr typePrefix = firstDecl->getProperty( ASTNodeProperties::typeDeclPrefixProperty ); ! return typePrefix->getBlankedText(); } --- 334,340 ---- ASTNodePtr typePrefix = firstDecl->getProperty( ASTNodeProperties::typeDeclPrefixProperty ); ! TypePartPtr typePart( new TypePart() ); ! setElementSource( *typePart, typePrefix ); ! return typePart; } Index: CodeModelExpressions.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeModelExpressions.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** CodeModelExpressions.cpp 16 Mar 2003 16:18:40 -0000 1.9 --- CodeModelExpressions.cpp 24 Mar 2003 07:57:51 -0000 1.10 *************** *** 74,93 **** ! DeclaratorExpression::DeclaratorExpression( const std::string primaryType ) ! : primaryType_( primaryType ) { } ! std::string DeclaratorExpression::getPrimaryType() const { ! return primaryType_; } void ! DeclaratorExpression::setPrimaryType( const std::string &primaryType ) { ! primaryType_ = primaryType; } --- 74,100 ---- ! DeclaratorExpression::DeclaratorExpression( const TypePartPtr &primaryType ) ! : primaryTypeTracker_( primaryType ) { } ! TypePartPtr DeclaratorExpression::getPrimaryType() const { ! return primaryTypeTracker_.getElement(); } void ! DeclaratorExpression::setPrimaryType( const TypePartPtr &primaryType ) { ! primaryTypeTracker_.setElement( primaryType ); ! } ! ! ! Change ! DeclaratorExpression::getPrimaryTypeChange() const ! { ! return primaryTypeTracker_.getChange(); } *************** *** 140,143 **** --- 147,166 ---- { visitor.visit( *this ); + } + + + + TypePart::TypePart( const std::string &typePart ) + : typePart_( typePart ) + { + } + + + std::string + TypePart::getTypeText() const + { + if ( isFromSource() ) + return getSourceText(); + return typePart_; } Index: CodeModelGeneratorTest.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeModelGeneratorTest.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CodeModelGeneratorTest.cpp 16 Mar 2003 13:44:25 -0000 1.3 --- CodeModelGeneratorTest.cpp 24 Mar 2003 07:57:51 -0000 1.4 *************** *** 51,55 **** generator.generateDeclarator( sourceNode_->getChildAt(0) ); ! RFTA_ASSERT_EQUAL( "int ", declExpression->getPrimaryType() ); RFTA_ASSERT_EQUAL( 1, declExpression->getDeclaratorCount() ); --- 51,55 ---- generator.generateDeclarator( sourceNode_->getChildAt(0) ); ! RFTA_ASSERT_EQUAL( "int ", declExpression->getPrimaryType()->getTypeText() ); RFTA_ASSERT_EQUAL( 1, declExpression->getDeclaratorCount() ); Index: CodeRewriter.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeRewriter.cpp,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** CodeRewriter.cpp 21 Mar 2003 07:32:25 -0000 1.32 --- CodeRewriter.cpp 24 Mar 2003 07:57:51 -0000 1.33 *************** *** 353,357 **** beginInsertNewStatement(); ! insertText( declarators->getPrimaryType() ); const Declarator &declarator = declarators->getDeclaratorAt(0); --- 353,357 ---- beginInsertNewStatement(); ! insertText( declarators->getPrimaryType()->getTypeText() ); const Declarator &declarator = declarators->getDeclaratorAt(0); Index: CodeWriterInsertTest.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeWriterInsertTest.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** CodeWriterInsertTest.cpp 21 Mar 2003 07:32:26 -0000 1.6 --- CodeWriterInsertTest.cpp 24 Mar 2003 07:57:51 -0000 1.7 *************** *** 280,284 **** CodeWriterInsertTest::testInsertDeclarationStatement() { ! CodeModel::DeclaratorExpressionPtr declarators( new CodeModel::DeclaratorExpression( "int " ) ); CodeModel::Declarator declarator( "", "var", "[3]" ); declarators->appendDeclarator( declarator ); --- 280,285 ---- CodeWriterInsertTest::testInsertDeclarationStatement() { ! CodeModel::DeclaratorExpressionPtr declarators( ! new CodeModel::DeclaratorExpression( makeTypePart( "int " ) ) ); CodeModel::Declarator declarator( "", "var", "[3]" ); declarators->appendDeclarator( declarator ); Index: CodeWriterTestBase.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeWriterTestBase.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CodeWriterTestBase.cpp 18 Mar 2003 22:37:50 -0000 1.3 --- CodeWriterTestBase.cpp 24 Mar 2003 07:57:51 -0000 1.4 *************** *** 81,84 **** --- 81,91 ---- + CodeModel::TypePartPtr + CodeWriterTestBase::makeTypePart( const std::string &typePart ) + { + return CodeModel::TypePartPtr( new CodeModel::TypePart( typePart ) ); + } + + void CodeWriterTestBase::generateAndCheckSource( const std::string &expectedSource ) Index: CodeWriterTestBase.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeWriterTestBase.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CodeWriterTestBase.h 18 Mar 2003 22:37:51 -0000 1.3 --- CodeWriterTestBase.h 24 Mar 2003 07:57:51 -0000 1.4 *************** *** 36,39 **** --- 36,41 ---- CodeModel::LabelPtr makeLabel( const std::string &labelName ); + CodeModel::TypePartPtr makeTypePart( const std::string &typePart ); + void generateAndCheckSource( const std::string &expectedSource ); |
From: <bl...@us...> - 2003-03-24 07:57:55
|
Update of /cvsroot/cpptool/rfta/src In directory sc8-pr-cvs1:/tmp/cvs-serv4949/src Modified Files: rfta.opt Log Message: * adding a separator between variable declaration. Index: rfta.opt =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta.opt,v retrieving revision 1.89 retrieving revision 1.90 diff -C2 -d -r1.89 -r1.90 Binary files /tmp/cvsE0gNcT and /tmp/cvschCtWD differ |
From: <bl...@us...> - 2003-03-21 07:32:29
|
Update of /cvsroot/cpptool/rfta/src/rfta In directory sc8-pr-cvs1:/tmp/cvs-serv18910/src/rfta Modified Files: CodeRewriter.cpp CodeWriterInsertTest.cpp CodeWriterInsertTest.h Log Message: * added support for inserting a single variable declaration without initializer. Index: CodeRewriter.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeRewriter.cpp,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** CodeRewriter.cpp 18 Mar 2003 22:37:48 -0000 1.31 --- CodeRewriter.cpp 21 Mar 2003 07:32:25 -0000 1.32 *************** *** 348,351 **** --- 348,365 ---- CodeRewriter::visit( DeclarationStatement &statement ) { + if ( isInserting() ) + { + DeclaratorExpressionPtr declarators = statement.getDeclaration(); + + beginInsertNewStatement(); + insertText( declarators->getPrimaryType() ); + + const Declarator &declarator = declarators->getDeclaratorAt(0); + insertText( declarator.getType() ); + insertText( declarator.getName() ); + insertText( declarator.getTypeSuffix() ); + + endInsertNewStatement(); + } } Index: CodeWriterInsertTest.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeWriterInsertTest.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** CodeWriterInsertTest.cpp 18 Mar 2003 22:37:48 -0000 1.5 --- CodeWriterInsertTest.cpp 21 Mar 2003 07:32:26 -0000 1.6 *************** *** 277,279 **** --- 277,293 ---- + void + CodeWriterInsertTest::testInsertDeclarationStatement() + { + CodeModel::DeclaratorExpressionPtr declarators( new CodeModel::DeclaratorExpression( "int " ) ); + CodeModel::Declarator declarator( "", "var", "[3]" ); + declarators->appendDeclarator( declarator ); + CodeModel::StatementPtr declarationStatement( new CodeModel::DeclarationStatement( declarators ) ); + checkGeneratedSource( declarationStatement, + "{\n" + " int var[3];\n" + "}" ); + } + + } // namespace Refactoring Index: CodeWriterInsertTest.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeWriterInsertTest.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** CodeWriterInsertTest.h 18 Mar 2003 22:37:48 -0000 1.4 --- CodeWriterInsertTest.h 21 Mar 2003 07:32:26 -0000 1.5 *************** *** 33,36 **** --- 33,37 ---- CPPUNIT_TEST( testInsertExpressionStatement ); CPPUNIT_TEST( testInsertForStatement ); + CPPUNIT_TEST( testInsertDeclarationStatement ); CPPUNIT_TEST_SUITE_END(); *************** *** 58,61 **** --- 59,63 ---- void testInsertExpressionStatement(); void testInsertForStatement(); + void testInsertDeclarationStatement(); private: |
From: <bl...@us...> - 2003-03-21 07:32:28
|
Update of /cvsroot/cpptool/rfta/include/rfta/refactoring In directory sc8-pr-cvs1:/tmp/cvs-serv18910/include/rfta/refactoring Modified Files: CodeModelForward.h Log Message: * added support for inserting a single variable declaration without initializer. Index: CodeModelForward.h =================================================================== RCS file: /cvsroot/cpptool/rfta/include/rfta/refactoring/CodeModelForward.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** CodeModelForward.h 18 Mar 2003 22:37:44 -0000 1.9 --- CodeModelForward.h 21 Mar 2003 07:32:25 -0000 1.10 *************** *** 62,65 **** --- 62,66 ---- typedef boost::shared_ptr<Statement> StatementPtr; typedef boost::weak_ptr<Statement> StatementWeakPtr; + typedef boost::shared_ptr<DeclaratorExpression> DeclaratorExpressionPtr; |
From: <bl...@us...> - 2003-03-18 22:38:22
|
Update of /cvsroot/cpptool/rfta/include/rfta/refactoring In directory sc8-pr-cvs1:/tmp/cvs-serv2540/include/rfta/refactoring Modified Files: CodeModelForward.h CodeModelStatements.h Log Message: * modified ForStatement generation (use null expression instead of missing property) * added support for inserting and replacing ForStatement. Index: CodeModelForward.h =================================================================== RCS file: /cvsroot/cpptool/rfta/include/rfta/refactoring/CodeModelForward.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** CodeModelForward.h 16 Mar 2003 16:18:39 -0000 1.8 --- CodeModelForward.h 18 Mar 2003 22:37:44 -0000 1.9 *************** *** 57,60 **** --- 57,61 ---- typedef boost::shared_ptr<DoStatement> DoStatementPtr; typedef boost::shared_ptr<WhileStatement> WhileStatementPtr; + typedef boost::shared_ptr<ForStatement> ForStatementPtr; typedef boost::weak_ptr<Expression> ExpressionWeakPtr; typedef boost::shared_ptr<CompoundStatement> CompoundStatementPtr; Index: CodeModelStatements.h =================================================================== RCS file: /cvsroot/cpptool/rfta/include/rfta/refactoring/CodeModelStatements.h,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** CodeModelStatements.h 16 Mar 2003 21:38:42 -0000 1.16 --- CodeModelStatements.h 18 Mar 2003 22:37:46 -0000 1.17 *************** *** 180,193 **** { public: ! ForStatement( const StatementPtr &declaration, const ExpressionPtr &condition, const ExpressionPtr &iteration, const StatementPtr &iteratedStatement ); ! StatementPtr getDeclarationStatement() const; ! void setDeclarationStatement( const StatementPtr &statement ); ! ExpressionPtr getIterationExpression() const; ! void getIterationExpression( const ExpressionPtr &iteration ); // overriden from Statement --- 180,199 ---- { public: ! ForStatement( const ExpressionPtr &declaration, const ExpressionPtr &condition, const ExpressionPtr &iteration, const StatementPtr &iteratedStatement ); ! ExpressionPtr getDeclaration() const; ! void setDeclaration( const ExpressionPtr &declaration ); ! ! Change getDeclarationChange() const; ! ! ExpressionPtr getIteration() const; ! ! void setIteration( const ExpressionPtr &iteration ); ! ! Change getIterationChange() const; // overriden from Statement *************** *** 198,203 **** private: ! StatementPtr declarationStatement_; ! ExpressionPtr iterationExpression_; }; --- 204,209 ---- private: ! ExpressionChangeTracker declarationTracker_; ! ExpressionChangeTracker iterationTracker_; }; |
From: <bl...@us...> - 2003-03-18 22:38:15
|
Update of /cvsroot/cpptool/rfta/src/rfta In directory sc8-pr-cvs1:/tmp/cvs-serv2540/src/rfta Modified Files: CodeModel.cpp CodeModelStatements.cpp CodeRewriter.cpp CodeWriterInsertTest.cpp CodeWriterInsertTest.h CodeWriterTest.cpp CodeWriterTest.h CodeWriterTestBase.cpp CodeWriterTestBase.h IndentLevelManager.cpp IndentLevelManager.h Log Message: * modified ForStatement generation (use null expression instead of missing property) * added support for inserting and replacing ForStatement. Index: CodeModel.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeModel.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** CodeModel.cpp 16 Mar 2003 13:44:25 -0000 1.7 --- CodeModel.cpp 18 Mar 2003 22:37:46 -0000 1.8 *************** *** 70,74 **** { CompoundStatementPtr compound( new CompoundStatement() ); - // compound->setSourceRange( compoundNode->getRange() ); for ( int index = 0; index < compoundNode->getChildCount(); ++index ) --- 70,73 ---- *************** *** 184,210 **** statement->getProperty( ASTNodeProperties::iterationProperty ); - StatementPtr declaration; ASTNodePtr declarationNode = forIterationNode->getProperty( ASTNodeProperties::declarationProperty ); ! if ( !declarationNode ) ! declaration.reset( new NullStatement() ); ! else ! declaration = generateStatement( declarationNode ); - ExpressionPtr condition; ASTNodePtr conditionNode = forIterationNode->getProperty( ASTNodeProperties::conditionProperty ); ! if ( !conditionNode ) ! condition.reset( new DefaultConditionExpression() ); ! else ! condition = generateExpression( conditionNode ); - ExpressionPtr iteration; ASTNodePtr iterationNode = ! forIterationNode->getProperty( ASTNodeProperties::iterationProperty ); ! if ( !iterationNode ) ! iteration.reset( new NullExpression() ); ! else ! iteration = generateExpression( iterationNode ); return StatementPtr( new ForStatement( declaration, --- 183,197 ---- statement->getProperty( ASTNodeProperties::iterationProperty ); ASTNodePtr declarationNode = forIterationNode->getProperty( ASTNodeProperties::declarationProperty ); ! ExpressionPtr declaration = generateExpression( declarationNode ); ASTNodePtr conditionNode = forIterationNode->getProperty( ASTNodeProperties::conditionProperty ); ! ExpressionPtr condition = generateExpression( conditionNode ); ASTNodePtr iterationNode = ! forIterationNode->getProperty( ASTNodeProperties::nextStepProperty ); ! ExpressionPtr iteration = generateExpression( iterationNode ); return StatementPtr( new ForStatement( declaration, Index: CodeModelStatements.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeModelStatements.cpp,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** CodeModelStatements.cpp 16 Mar 2003 21:38:41 -0000 1.15 --- CodeModelStatements.cpp 18 Mar 2003 22:37:47 -0000 1.16 *************** *** 333,372 **** ! ForStatement::ForStatement( const StatementPtr &declaration, const ExpressionPtr &condition, const ExpressionPtr &iteration, const StatementPtr &iteratedStatement ) : IterationStatement( condition, iteratedStatement ) ! , declarationStatement_( declaration ) ! , iterationExpression_( iteration ) { } ! StatementPtr ! ForStatement::getDeclarationStatement() const { ! return declarationStatement_; } void ! ForStatement::setDeclarationStatement( const StatementPtr &statement ) { ! declarationStatement_ = statement; } ExpressionPtr ! ForStatement::getIterationExpression() const { ! return iterationExpression_; } void ! ForStatement::getIterationExpression( const ExpressionPtr &iteration ) { ! iterationExpression_ = iteration; } --- 333,387 ---- ! ! ForStatement::ForStatement( const ExpressionPtr &declaration, const ExpressionPtr &condition, const ExpressionPtr &iteration, const StatementPtr &iteratedStatement ) : IterationStatement( condition, iteratedStatement ) ! , declarationTracker_( declaration ) ! , iterationTracker_( iteration ) { } ! ExpressionPtr ! ForStatement::getDeclaration() const { ! return declarationTracker_.getElement(); } void ! ForStatement::setDeclaration( const ExpressionPtr &declaration ) { ! declarationTracker_.setElement( declaration ); ! } ! ! ! Change ! ForStatement::getDeclarationChange() const ! { ! return declarationTracker_.getChange(); } ExpressionPtr ! ForStatement::getIteration() const { ! return iterationTracker_.getElement(); } void ! ForStatement::setIteration( const ExpressionPtr &iteration ) { ! iterationTracker_.setElement( iteration ); ! } ! ! ! Change ! ForStatement::getIterationChange() const ! { ! return iterationTracker_.getChange(); } *************** *** 384,387 **** --- 399,404 ---- { IterationStatement::setElementIsFromSource(); + declarationTracker_.setElementIsFromSource(); + iterationTracker_.setElementIsFromSource(); } Index: CodeRewriter.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeRewriter.cpp,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** CodeRewriter.cpp 16 Mar 2003 21:38:41 -0000 1.30 --- CodeRewriter.cpp 18 Mar 2003 22:37:48 -0000 1.31 *************** *** 196,200 **** mode_ = inserting; ! if ( isInserting() && deletionType == bracedExpressionDelete ) insertText( " " ); --- 196,201 ---- mode_ = inserting; ! if ( isInserting() && ( deletionType == bracedExpressionDelete ! || deletionType == trailingExpressionDelete ) ) insertText( " " ); *************** *** 412,415 **** --- 413,454 ---- CodeRewriter::visit( ForStatement &statement ) { + if ( isInserting() ) + { + beginInsertNewStatement(); + insertText( "for (" ); + } + + handleMandatoryChange( statement.getDeclarationChange(), + *statement.getDeclaration(), + trailingExpressionDelete ); + + if ( isInserting() ) + insertText( ";" ); + + handleMandatoryChange( statement.getConditionChange(), + *statement.getCondition(), + trailingExpressionDelete ); + + if ( isInserting() ) + insertText( ";" ); + + handleMandatoryChange( statement.getIterationChange(), + *statement.getIteration(), + bracedExpressionDelete ); + + IndentLevelManager::IndentRestorer restorer( indentManager_ ); + StatementPtr iteratedStatement = statement.getIteratedStatement(); + if ( isInserting() ) + { + insertText( ")" ); + indentManager_.enterNewWhileStatement( iteratedStatement ); + } + else + indentManager_.enterExistingForStatement( iteratedStatement, + statement.getSourceRange().getStartIndex() ); + + handleMandatoryChange( statement.getIteratedStatementChange(), + *iteratedStatement, + statementDelete ); } *************** *** 418,424 **** CodeRewriter::visit( GotoStatement &statement ) { ! beginInsertNewStatement(); ! insertText( "goto " + statement.getLabel()->getLabelName() ); ! endInsertNewStatement(); } --- 457,473 ---- CodeRewriter::visit( GotoStatement &statement ) { ! if ( isInserting() ) ! { ! beginInsertNewStatement(); ! insertText( "goto " + statement.getLabel()->getLabelName() ); ! } ! /* // Need to add visitor for Label... ! // insertText( "goto " + statement.getLabel()->getLabelName() ); ! handleMandatoryChange( statement.getLabelChange(), ! *statement.getLabel(), ! trailingExpressionDelete ); ! */ ! if ( isInserting() ) ! endInsertNewStatement(); } Index: CodeWriterInsertTest.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeWriterInsertTest.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** CodeWriterInsertTest.cpp 16 Mar 2003 15:33:10 -0000 1.4 --- CodeWriterInsertTest.cpp 18 Mar 2003 22:37:48 -0000 1.5 *************** *** 191,196 **** CodeWriterInsertTest::testInsertLabelStatement() { ! CodeModel::LabelPtr label( new CodeModel::Label( "error" ) ); ! CodeModel::StatementPtr labelStatement( new CodeModel::LabelStatement( label ) ); checkGeneratedSource( labelStatement, "{\n" --- 191,195 ---- CodeWriterInsertTest::testInsertLabelStatement() { ! CodeModel::StatementPtr labelStatement( new CodeModel::LabelStatement( makeLabel( "error" ) ) ); checkGeneratedSource( labelStatement, "{\n" *************** *** 203,208 **** CodeWriterInsertTest::testInsertGotoStatement() { ! CodeModel::LabelPtr label( new CodeModel::Label( "error" ) ); ! CodeModel::StatementPtr gotoStatement( new CodeModel::GotoStatement( label ) ); checkGeneratedSource( gotoStatement, "{\n" --- 202,206 ---- CodeWriterInsertTest::testInsertGotoStatement() { ! CodeModel::StatementPtr gotoStatement( new CodeModel::GotoStatement( makeLabel( "error" ) ) ); checkGeneratedSource( gotoStatement, "{\n" *************** *** 254,257 **** --- 252,276 ---- "{\n" " call( 1234 );\n" + "}" ); + } + + + void + CodeWriterInsertTest::testInsertForStatement() + { + CodeModel::ExpressionPtr declaration( makeExpression( "x = 0" ) ); + CodeModel::ExpressionPtr condition( makeExpression( "x < 10" ) ); + CodeModel::ExpressionPtr iteration( makeExpression( "++x" ) ); + CodeModel::StatementPtr iteratedStatement( new CodeModel::NullStatement() ); + + CodeModel::ForStatementPtr forStatement( + new CodeModel::ForStatement( declaration, + condition, + iteration, + iteratedStatement ) ); + checkGeneratedSource( forStatement, + "{\n" + " for ( x = 0; x < 10; ++x )\n" + " ;\n" "}" ); } Index: CodeWriterInsertTest.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeWriterInsertTest.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CodeWriterInsertTest.h 16 Mar 2003 10:23:07 -0000 1.3 --- CodeWriterInsertTest.h 18 Mar 2003 22:37:48 -0000 1.4 *************** *** 32,35 **** --- 32,36 ---- CPPUNIT_TEST( testInsertIfThenElseStatement ); CPPUNIT_TEST( testInsertExpressionStatement ); + CPPUNIT_TEST( testInsertForStatement ); CPPUNIT_TEST_SUITE_END(); *************** *** 56,59 **** --- 57,61 ---- void testInsertIfThenElseStatement(); void testInsertExpressionStatement(); + void testInsertForStatement(); private: Index: CodeWriterTest.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeWriterTest.cpp,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** CodeWriterTest.cpp 16 Mar 2003 21:38:41 -0000 1.31 --- CodeWriterTest.cpp 18 Mar 2003 22:37:48 -0000 1.32 *************** *** 419,422 **** --- 419,522 ---- + void + CodeWriterTest::testModifyGotoStatement() + { + source_ = "{\n" + " goto label2;\n" + "}"; + generateCompound(); + + CodeModel::GotoStatement &gotoStatement = + dynamic_cast<CodeModel::GotoStatement &>( *compound_->getStatementAt(0) ); + gotoStatement.setLabel( makeLabel( "error" ) ); + generateAndCheckSource( "{\n" + " goto error;\n" + "}" ); + } + + + void + CodeWriterTest::testModifyForDeclarationExpression() + { + source_ = "{\n" + " for( ; x <10; ++x )\n" + " {\n" + " }\n" + "}"; + generateCompound(); + + CodeModel::ForStatement &forStatement = + dynamic_cast<CodeModel::ForStatement &>( *compound_->getStatementAt(0) ); + forStatement.setDeclaration( makeExpression( "x = 0" ) ); + generateAndCheckSource( "{\n" + " for( x = 0; x <10; ++x )\n" + " {\n" + " }\n" + "}" ); + } + + + void + CodeWriterTest::testModifyForConditionExpression() + { + source_ = "{\n" + " for( ; x < 10; ++x )\n" + " {\n" + " }\n" + "}"; + generateCompound(); + + CodeModel::ForStatement &forStatement = + dynamic_cast<CodeModel::ForStatement &>( *compound_->getStatementAt(0) ); + forStatement.setCondition( makeExpression( "x+y < 100" ) ); + generateAndCheckSource( "{\n" + " for( ; x+y < 100; ++x )\n" + " {\n" + " }\n" + "}" ); + } + + + void + CodeWriterTest::testModifyForIterationExpression() + { + source_ = "{\n" + " for( ; x < 10; ++x )\n" + " {\n" + " }\n" + "}"; + generateCompound(); + + CodeModel::ForStatement &forStatement = + dynamic_cast<CodeModel::ForStatement &>( *compound_->getStatementAt(0) ); + forStatement.setIteration( makeExpression( "y++, x++" ) ); + generateAndCheckSource( "{\n" + " for( ; x < 10; y++, x++ )\n" + " {\n" + " }\n" + "}" ); + } + + + void + CodeWriterTest::testModifyForIteratedStatement() + { + source_ = "{\n" + " for( ; x < 10; ++x )\n" + " {\n" + " }\n" + "}"; + generateCompound(); + + CodeModel::ForStatement &forStatement = + dynamic_cast<CodeModel::ForStatement &>( *compound_->getStatementAt(0) ); + forStatement.setIteratedStatement( makeBreakStatement() ); + generateAndCheckSource( "{\n" + " for( ; x < 10; ++x )\n" + " break;\n" + "}" ); + } + + } // namespace Refactoring Index: CodeWriterTest.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeWriterTest.h,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** CodeWriterTest.h 16 Mar 2003 21:38:41 -0000 1.26 --- CodeWriterTest.h 18 Mar 2003 22:37:49 -0000 1.27 *************** *** 35,38 **** --- 35,43 ---- CPPUNIT_TEST( testModifyCaseStatement ); CPPUNIT_TEST( testModifyExpressionStatement ); + // CPPUNIT_TEST( testModifyGotoStatement ); // goto is not parsed, yet... + CPPUNIT_TEST( testModifyForDeclarationExpression ); + CPPUNIT_TEST( testModifyForConditionExpression ); + CPPUNIT_TEST( testModifyForIterationExpression ); + CPPUNIT_TEST( testModifyForIteratedStatement ); CPPUNIT_TEST_SUITE_END(); *************** *** 72,75 **** --- 77,87 ---- void testModifyExpressionStatement(); + + void testModifyGotoStatement(); + + void testModifyForDeclarationExpression(); + void testModifyForConditionExpression(); + void testModifyForIterationExpression(); + void testModifyForIteratedStatement(); private: Index: CodeWriterTestBase.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeWriterTestBase.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CodeWriterTestBase.cpp 16 Mar 2003 10:23:07 -0000 1.2 --- CodeWriterTestBase.cpp 18 Mar 2003 22:37:50 -0000 1.3 *************** *** 74,77 **** --- 74,84 ---- + CodeModel::LabelPtr + CodeWriterTestBase::makeLabel( const std::string &labelName ) + { + return CodeModel::LabelPtr( new CodeModel::Label( labelName ) ); + } + + void CodeWriterTestBase::generateAndCheckSource( const std::string &expectedSource ) Index: CodeWriterTestBase.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeWriterTestBase.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CodeWriterTestBase.h 16 Mar 2003 10:23:07 -0000 1.2 --- CodeWriterTestBase.h 18 Mar 2003 22:37:51 -0000 1.3 *************** *** 34,37 **** --- 34,39 ---- CodeModel::StatementPtr makeBreakStatement(); + CodeModel::LabelPtr makeLabel( const std::string &labelName ); + void generateAndCheckSource( const std::string &expectedSource ); Index: IndentLevelManager.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/IndentLevelManager.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** IndentLevelManager.cpp 16 Mar 2003 20:57:23 -0000 1.8 --- IndentLevelManager.cpp 18 Mar 2003 22:37:51 -0000 1.9 *************** *** 95,98 **** --- 95,115 ---- + void + IndentLevelManager::enterExistingForStatement( const CodeModel::StatementPtr &subStatement, + int startingPos ) + { + if ( !isCompoundStatement( subStatement ) ) + pushIndent( findIndentLevelOf( startingPos ) + indentWidth_ ); + } + + + void + IndentLevelManager::enterNewForStatement( const CodeModel::StatementPtr &subStatement ) + { + if ( !isCompoundStatement( subStatement ) ) + pushIndent( getIndentLevel() + indentWidth_ ); + } + + bool IndentLevelManager::isCompoundStatement( const CodeModel::StatementPtr &subStatement ) const Index: IndentLevelManager.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/IndentLevelManager.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** IndentLevelManager.h 16 Mar 2003 20:57:24 -0000 1.9 --- IndentLevelManager.h 18 Mar 2003 22:37:51 -0000 1.10 *************** *** 76,79 **** --- 76,84 ---- void enterNewDoStatement( const CodeModel::StatementPtr &subStatement ); + void enterExistingForStatement( const CodeModel::StatementPtr &subStatement, + int startingPos ); + + void enterNewForStatement( const CodeModel::StatementPtr &subStatement ); + int getIndentLevel() const; |
From: <bl...@us...> - 2003-03-18 08:12:21
|
Update of /cvsroot/cpptool/rfta/src/rftaparser In directory sc8-pr-cvs1:/tmp/cvs-serv702/src/rftaparser Modified Files: ForIterationExpressionParser.cpp ForIterationExpressionParser.h Log Message: * modified to match not structure (null expression instead of no node) * refactored a bit Index: ForIterationExpressionParser.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/ForIterationExpressionParser.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ForIterationExpressionParser.cpp 20 Dec 2002 19:41:14 -0000 1.1 --- ForIterationExpressionParser.cpp 18 Mar 2003 08:12:18 -0000 1.2 *************** *** 15,139 **** ! ForIterationExpressionParser::ForIterationExpressionParser( ParseContext &context, ! const char *start, ! const char *end ) ! : Parser( context, start, end ) ! { ! } ! ! ! ForIterationExpressionParser::~ForIterationExpressionParser() ! { ! } ! ! bool ! ForIterationExpressionParser::parse( ) ! { ! Tracker tracker( "ForIterationExpressionParser::parse", *this ); ! ASTNodePtr iterationExpression = ! Parser::createASTNode( ASTNodeTypes::forIterationExpression, ! getParentNode(), ! getStartIndex()+1, ! getCurrentLength() ); ! // set up root node created by this parser ! context_.addNode( iterationExpression ); ! ! // ! // PARSE FOR-DECLARATION-EXPRESSION ! // ! // get to the beginning of the for-declaration ! expect( '(' ); ! skipSpaces(); ! // check if the for-declaration is not empty ! // (no property node will be added in case of an empty declaration element) ! if (*current_ !=';') ! { ! int startIndex = getCurrentIndex(); ! // find the end of the condition property: ! if ( !tryReadUntilNext( ';' ) ) ! return false; ! int declarationLength = getCurrentIndex() - startIndex; ! ASTNodePtr declarationNode = ! Parser::createASTNode( ASTNodeTypes::declarationOrExpression, ! iterationExpression, ! startIndex, ! declarationLength ); ! iterationExpression->setPropertyNode( ASTNodeProperties::declarationProperty, ! declarationNode ); ! } else ! { // this is an empty declaration, so skip only the ';' ! current_++; ! } ! // ! // CREATE NODE FOR 'FOR-CONDITION-EXPRESSION' ! // ! // start a sub parser to get the condition-property ! current_--; // just to make sure that we got all... ! expect( ';' ); ! skipSpaces(); - if (*current_ !=';') - { - int startIndex = getCurrentIndex(); - // find the end of the condition property: - if ( !tryReadUntilNext( ';' ) ) - return false; - int conditionLength = getCurrentIndex() - startIndex; ! ASTNodePtr conditionNode = ! Parser::createASTNode( ASTNodeTypes::unparsedConditionExpression, ! iterationExpression, ! startIndex, ! conditionLength ); - iterationExpression->setPropertyNode( ASTNodeProperties::conditionProperty, - conditionNode ); - } else - { // this is an empty condition, so skip only the ';' - current_++; - } ! // ! // PARSE FOR-NEXT-EXPRESSION ! // ! // start a sub parser to get the next-step-property ! current_--; // just to make sure that we got all... ! expect( ';' ); ! skipSpaces(); - if (*current_ !=')') - { - int startIndex = getCurrentIndex(); - // find the end of the next-step property: - if ( !tryReadUntilNext( ')' ) ) - return false; - int nextStepLength = getCurrentIndex() - startIndex - 1; // "-1" because ')' is not part of the next step ! ! //@todo: [AB] is this really a "declarationOrExpression" ? ! ASTNodePtr nextStepNode = ! Parser::createASTNode( ASTNodeTypes::declarationOrExpression, ! iterationExpression, ! startIndex, ! nextStepLength ); - iterationExpression->setPropertyNode( ASTNodeProperties::nextStepProperty, - nextStepNode ); - - } else - { // this is an empty next-step-expression, so skip only the ')' - current_++; - } - // current-length minus 2 because of the '(' and ')' we do not count - iterationExpression->setLength( getCurrentLength() - 2 ); ! return true; ! } ! } // namespace Refactoring --- 15,129 ---- ! ForIterationExpressionParser::ForIterationExpressionParser( ParseContext &context, ! const char *start, ! const char *end ) ! : Parser( context, start, end ) ! { ! } ! ! ! ForIterationExpressionParser::~ForIterationExpressionParser() ! { ! } ! ! ! bool ! ForIterationExpressionParser::parse( ) ! { ! Tracker tracker( "ForIterationExpressionParser::parse", *this ); ! ! ASTNodePtr iterationExpression = ! Parser::createASTNode( ASTNodeTypes::forIterationExpression, ! getParentNode(), ! getStartIndex()+1, ! getCurrentLength() ); ! // set up root node created by this parser ! context_.addNode( iterationExpression ); ! expect( '(' ); ! skipSpaces(); ! int declarationStartIndex = getCurrentIndex(); ! if ( !tryReadUntilNext( ';' ) ) ! return false; ! addDeclarationNode( declarationStartIndex, getCurrentIndex()-1, iterationExpression ); ! skipSpaces(); ! int conditionStartIndex = getCurrentIndex(); ! if ( !tryReadUntilNext( ';' ) ) ! return false; ! addConditionNode( conditionStartIndex, getCurrentIndex()-1, iterationExpression ); ! skipSpaces(); ! int iterationStartIndex = getCurrentIndex(); ! if ( !tryReadUntilNext( ')' ) ) ! return false; ! //@todo: [AB] is this really a "declarationOrExpression" ? ! addIterationNode( iterationStartIndex, getCurrentIndex()-1, iterationExpression ); ! // current-length minus 2 because of the '(' and ')' we do not count ! iterationExpression->setLength( getCurrentLength() - 2 ); ! return true; ! } ! void ! ForIterationExpressionParser::addDeclarationNode( int startIndex, ! int endIndex, ! const ASTNodePtr &iterationExpression ) ! { ! addNode( startIndex, ! endIndex, ! iterationExpression, ! ASTNodeTypes::declarationOrExpression, ! ASTNodeProperties::declarationProperty ); ! } ! void ! ForIterationExpressionParser::addConditionNode( int startIndex, ! int endIndex, ! const ASTNodePtr &iterationExpression ) ! { ! addNode( startIndex, ! endIndex, ! iterationExpression, ! ASTNodeTypes::unparsedConditionExpression, ! ASTNodeProperties::conditionProperty ); ! } ! void ! ForIterationExpressionParser::addIterationNode( int startIndex, ! int endIndex, ! const ASTNodePtr &iterationExpression ) ! { ! addNode( startIndex, ! endIndex, ! iterationExpression, ! ASTNodeTypes::declarationOrExpression, ! ASTNodeProperties::nextStepProperty ); ! } ! void ! ForIterationExpressionParser::addNode( int startIndex, ! int endIndex, ! const ASTNodePtr &iterationExpression, ! const ASTNodeType &nodeType, ! const ASTNodeProperty &nodeProperty ) ! { ! int length = endIndex - startIndex; ! ASTNodeType actualNodeType = (length == 0) ? ASTNodeTypes::nullExpression ! : nodeType; ! ASTNodePtr node = Parser::createASTNode( actualNodeType, ! iterationExpression, ! startIndex, ! length ); ! ! iterationExpression->setPropertyNode( nodeProperty, node ); ! } ! } // namespace Refactoring Index: ForIterationExpressionParser.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/ForIterationExpressionParser.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ForIterationExpressionParser.h 20 Dec 2002 19:41:12 -0000 1.1 --- ForIterationExpressionParser.h 18 Mar 2003 08:12:18 -0000 1.2 *************** *** 28,31 **** --- 28,48 ---- bool parse(); + + private: + void addDeclarationNode( int startIndex, + int endIndex, + const ASTNodePtr &iterationExpression ); + void addConditionNode( int startIndex, + int endIndex, + const ASTNodePtr &iterationExpression ); + void addIterationNode( int startIndex, + int endIndex, + const ASTNodePtr &iterationExpression ); + + void addNode( int startIndex, + int endIndex, + const ASTNodePtr &iterationExpression, + const ASTNodeType &nodeType, + const ASTNodeProperty &nodeProperty ); }; |
From: <bl...@us...> - 2003-03-18 08:11:57
|
Update of /cvsroot/cpptool/rfta/src/rftaparser In directory sc8-pr-cvs1:/tmp/cvs-serv537/src/rftaparser Modified Files: ForStatementParserTest.cpp ForStatementParserTest.h Log Message: * fixed test bug for 'for (;;) * modified to match not structure (null expression instead of no node) Index: ForStatementParserTest.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/ForStatementParserTest.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ForStatementParserTest.cpp 20 Dec 2002 16:52:11 -0000 1.1 --- ForStatementParserTest.cpp 18 Mar 2003 08:11:55 -0000 1.2 *************** *** 60,63 **** --- 60,65 ---- ForStatementParserTest::testForNoArgs() { + checkFor( "", "", "" ); + /* std::string iterationExpr( ";;" ); std::string source( "for (" + iterationExpr + ") ;" ); *************** *** 82,91 **** propertyStart, propertyEnd - propertyStart ); ! // it should not have a declaration property ! CPPUNIT_ASSERT( !forAST->hasProperty( ASTNodeProperties::declarationProperty ) ); ! // it should not hace a condition property ! CPPUNIT_ASSERT( !forAST->hasProperty( ASTNodeProperties::conditionProperty ) ); ! // it should not hace a next-step property ! CPPUNIT_ASSERT( !forAST->hasProperty( ASTNodeProperties::nextStepProperty ) ); } --- 84,92 ---- propertyStart, propertyEnd - propertyStart ); ! ASTNodePtr forIterationsNode = forAST->getProperty( ASTNodeProperties::iterationProperty ); ! CPPUNIT_ASSERT( forIterationsNode->hasProperty( ASTNodeProperties::declarationProperty ) ); ! CPPUNIT_ASSERT( forIterationsNode->hasProperty( ASTNodeProperties::conditionProperty ) ); ! CPPUNIT_ASSERT( forIterationsNode->hasProperty( ASTNodeProperties::nextStepProperty ) ); ! */ } *************** *** 93,98 **** ForStatementParserTest::testSimpleFor() { ! std::string decl ( "i=0;" ); ! std::string cond ( "i<10;" ); std::string next ( "i++" ); --- 94,99 ---- ForStatementParserTest::testSimpleFor() { ! std::string decl ( "i=0" ); ! std::string cond ( "i<10" ); std::string next ( "i++" ); *************** *** 103,109 **** ForStatementParserTest::testDeclaringFor() { ! std::string iterationExpr( "int index = 0 ; index < 10 ; index++ " ); ! std::string decl ( "int index = 0 ;" ); ! std::string cond ( "index < 10 ;" ); std::string next ( "index++" ); --- 104,109 ---- ForStatementParserTest::testDeclaringFor() { ! std::string decl ( "int index = 0" ); ! std::string cond ( "index < 10" ); std::string next ( "index++" ); *************** *** 112,125 **** void ! ForStatementParserTest::checkFor( ! std::string decl, ! std::string cond, ! std::string next ! ) { ! std::string iterationExpr( decl+cond+next ); std::string source( "for (" + iterationExpr + ") ;" ); int startIndex = 0; int endIndex = source.length(); SourceASTNodePtr sourceAST = RFTA_ASSERT_KEYWORD_PARSER_PASS( ForStatementParser, --- 112,128 ---- void ! ForStatementParserTest::checkFor( std::string decl, ! std::string cond, ! std::string next ) { ! std::string iterationExpr( decl + ";" + cond + ";" + next ); std::string source( "for (" + iterationExpr + ") ;" ); int startIndex = 0; int endIndex = source.length(); + int iterationsStartIndex = std::string( "for (" ).length(); + int iterationsEndIndex = iterationsStartIndex + iterationExpr.length(); + int declarationStartIndex = iterationsStartIndex; + int conditionStartIndex = declarationStartIndex + decl.length() +1; + int iterationStartIndex = conditionStartIndex + cond.length() + 1; SourceASTNodePtr sourceAST = RFTA_ASSERT_KEYWORD_PARSER_PASS( ForStatementParser, *************** *** 133,173 **** endIndex-startIndex ); - int propertyStart = startIndex + std::string("for (").length(); - int propertyEnd = propertyStart + iterationExpr.length(); RFTA_ASSERT_NODE_PROPERTY_HAS( forAST, ASTNodeProperties::iterationProperty, ASTNodeTypes::forIterationExpression, ! propertyStart, ! propertyEnd - propertyStart ); ! if ( forAST->hasProperty( ASTNodeProperties::iterationProperty ) ) ! { ! ASTNodePtr iterationProp = forAST->getProperty( ASTNodeProperties::iterationProperty ); ! int declStart = propertyStart; ! int declLen = decl.length(); ! int condStart = declStart+declLen; ! int condLen = cond.length(); ! int nextStart = condStart+condLen; ! int nextLen = next.length(); ! // check for declaration property: ! RFTA_ASSERT_NODE_PROPERTY_HAS( iterationProp, ! ASTNodeProperties::declarationProperty, ! ASTNodeTypes::declarationOrExpression, ! declStart, ! declLen ); ! // check for condition property: ! RFTA_ASSERT_NODE_PROPERTY_HAS( iterationProp, ! ASTNodeProperties::conditionProperty, ! ASTNodeTypes::unparsedConditionExpression, ! condStart, ! condLen ); ! // check for condition property: ! RFTA_ASSERT_NODE_PROPERTY_HAS( iterationProp, ! ASTNodeProperties::nextStepProperty, ! ASTNodeTypes::declarationOrExpression, ! nextStart, ! nextLen ); ! } } } // namespace Refactoring --- 136,181 ---- endIndex-startIndex ); RFTA_ASSERT_NODE_PROPERTY_HAS( forAST, ASTNodeProperties::iterationProperty, ASTNodeTypes::forIterationExpression, ! iterationsStartIndex, ! iterationsEndIndex - iterationsStartIndex ); ! ASTNodePtr iterationProp = forAST->getProperty( ASTNodeProperties::iterationProperty ); ! RFTA_ASSERT_NODE_PROPERTY_HAS( iterationProp, ! ASTNodeProperties::declarationProperty, ! getExpectedNodeTypeFor( decl ), ! declarationStartIndex, ! decl.length() ); ! RFTA_ASSERT_NODE_PROPERTY_HAS( iterationProp, ! ASTNodeProperties::conditionProperty, ! getExpectedConditionNodeTypeFor( cond ), ! conditionStartIndex, ! cond.length() ); ! RFTA_ASSERT_NODE_PROPERTY_HAS( iterationProp, ! ASTNodeProperties::nextStepProperty, ! getExpectedNodeTypeFor( decl ), ! iterationStartIndex, ! next.length() ); ! } ! ! ! ASTNodeType ! ForStatementParserTest::getExpectedNodeTypeFor( const std::string &expression ) ! { ! if ( expression.empty() ) ! return ASTNodeTypes::nullExpression; ! return ASTNodeTypes::declarationOrExpression; } + + + ASTNodeType + ForStatementParserTest::getExpectedConditionNodeTypeFor( const std::string &expression ) + { + if ( expression.empty() ) + return ASTNodeTypes::nullExpression; + return ASTNodeTypes::unparsedConditionExpression; + } + } // namespace Refactoring Index: ForStatementParserTest.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/ForStatementParserTest.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ForStatementParserTest.h 20 Dec 2002 16:52:11 -0000 1.1 --- ForStatementParserTest.h 18 Mar 2003 08:11:55 -0000 1.2 *************** *** 8,11 **** --- 8,12 ---- #include "ParserTesting.h" + #include <rfta/parser/ASTNodes.h> *************** *** 46,49 **** --- 47,54 ---- void ForStatementParserTest::checkFor( std::string decl, std::string cond, std::string next ); + + ASTNodeType getExpectedNodeTypeFor( const std::string &expression ); + + ASTNodeType getExpectedConditionNodeTypeFor( const std::string &expression ); private: |
From: <bl...@us...> - 2003-03-18 08:10:57
|
Update of /cvsroot/cpptool/rfta/src/rftaparser In directory sc8-pr-cvs1:/tmp/cvs-serv32606/src/rftaparser Modified Files: ASTNodes.cpp Log Message: * added nullExpression node type Index: ASTNodes.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/ASTNodes.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** ASTNodes.cpp 28 Dec 2002 10:45:57 -0000 1.13 --- ASTNodes.cpp 18 Mar 2003 08:10:54 -0000 1.14 *************** *** 26,29 **** --- 26,30 ---- const ASTNodeType ASTNodeTypes::unparsedExpressionStatement( "unparsed-expression", isStatement | needMutation | mayHaveLocalScopeIdentifierChildren ); const ASTNodeType ASTNodeTypes::expression( "expression", isStatement | mayHaveLocalScopeIdentifierChildren ); + const ASTNodeType ASTNodeTypes::nullExpression( "nullExpression" ); const ASTNodeType ASTNodeTypes::declarationExpression( "declaration-expression", isStatement | mayHaveVariableDeclChildren | mayHaveLocalScopeIdentifierChildren | mayHaveScopeGeneratorChildren ); const ASTNodeType ASTNodeTypes::declarationOrExpression( "declaration-or-expression", isStatement | needMutation | mayHaveVariableDeclProperties | mayHaveLocalScopeIdentifierChildren ); |
From: <bl...@us...> - 2003-03-18 08:10:31
|
Update of /cvsroot/cpptool/rfta/include/rfta/parser In directory sc8-pr-cvs1:/tmp/cvs-serv32470/include/rfta/parser Modified Files: ASTNodes.h Log Message: * added nullExpression node type Index: ASTNodes.h =================================================================== RCS file: /cvsroot/cpptool/rfta/include/rfta/parser/ASTNodes.h,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** ASTNodes.h 28 Dec 2002 10:45:57 -0000 1.11 --- ASTNodes.h 18 Mar 2003 08:10:26 -0000 1.12 *************** *** 60,63 **** --- 60,64 ---- static const ASTNodeType unparsedExpressionStatement; static const ASTNodeType expression; + static const ASTNodeType nullExpression; /// declaration |
From: <bl...@us...> - 2003-03-16 21:38:45
|
Update of /cvsroot/cpptool/rfta/include/rfta/refactoring In directory sc8-pr-cvs1:/tmp/cvs-serv29748/include/rfta/refactoring Modified Files: CodeModelStatements.h Log Message: * added support for replacing expression statement. Index: CodeModelStatements.h =================================================================== RCS file: /cvsroot/cpptool/rfta/include/rfta/refactoring/CodeModelStatements.h,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** CodeModelStatements.h 16 Mar 2003 21:27:05 -0000 1.15 --- CodeModelStatements.h 16 Mar 2003 21:38:42 -0000 1.16 *************** *** 317,321 **** --- 317,324 ---- ExpressionPtr getExpression() const; + void setExpression( const ExpressionPtr &expression ); + + Change getExpressionChange() const; // overriden from Statement |
From: <bl...@us...> - 2003-03-16 21:38:45
|
Update of /cvsroot/cpptool/rfta/src/rfta In directory sc8-pr-cvs1:/tmp/cvs-serv29748/src/rfta Modified Files: CodeModelStatements.cpp CodeRewriter.cpp CodeWriterTest.cpp CodeWriterTest.h Log Message: * added support for replacing expression statement. Index: CodeModelStatements.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeModelStatements.cpp,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** CodeModelStatements.cpp 16 Mar 2003 21:27:03 -0000 1.14 --- CodeModelStatements.cpp 16 Mar 2003 21:38:41 -0000 1.15 *************** *** 588,591 **** --- 588,598 ---- + Change + ExpressionStatement::getExpressionChange() const + { + return expressionTracker_.getChange(); + } + + void ExpressionStatement::accept( StatementVisitor &visitor ) Index: CodeRewriter.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeRewriter.cpp,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** CodeRewriter.cpp 16 Mar 2003 21:27:03 -0000 1.29 --- CodeRewriter.cpp 16 Mar 2003 21:38:41 -0000 1.30 *************** *** 392,398 **** CodeRewriter::visit( ExpressionStatement &statement ) { ! beginInsertNewStatement(); ! statement.getExpression()->accept( *this ); ! endInsertNewStatement(); } --- 392,403 ---- CodeRewriter::visit( ExpressionStatement &statement ) { ! if ( isInserting() ) ! beginInsertNewStatement(); ! ! handleMandatoryChange( statement.getExpressionChange(), ! *statement.getExpression() ); ! ! if ( isInserting() ) ! endInsertNewStatement(); } Index: CodeWriterTest.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeWriterTest.cpp,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** CodeWriterTest.cpp 16 Mar 2003 21:27:04 -0000 1.30 --- CodeWriterTest.cpp 16 Mar 2003 21:38:41 -0000 1.31 *************** *** 402,405 **** --- 402,422 ---- + void + CodeWriterTest::testModifyExpressionStatement() + { + source_ = "{\n" + " call( 123 );\n" + "}"; + generateCompound(); + + CodeModel::ExpressionStatement &expressionStatement = + dynamic_cast<CodeModel::ExpressionStatement &>( *compound_->getStatementAt(0) ); + expressionStatement.setExpression( makeExpression( "x++;" ) ); // @todo expression statement node should not includes the ';' as part of the expression. + generateAndCheckSource( "{\n" + " x++;\n" + "}" ); + } + + } // namespace Refactoring Index: CodeWriterTest.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeWriterTest.h,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** CodeWriterTest.h 16 Mar 2003 21:27:05 -0000 1.25 --- CodeWriterTest.h 16 Mar 2003 21:38:41 -0000 1.26 *************** *** 34,37 **** --- 34,38 ---- CPPUNIT_TEST( testModifyDoIteratedStatement ); CPPUNIT_TEST( testModifyCaseStatement ); + CPPUNIT_TEST( testModifyExpressionStatement ); CPPUNIT_TEST_SUITE_END(); *************** *** 69,72 **** --- 70,75 ---- void testModifyCaseStatement(); + + void testModifyExpressionStatement(); private: |
From: <bl...@us...> - 2003-03-16 21:27:40
|
Update of /cvsroot/cpptool/rfta/src/rfta In directory sc8-pr-cvs1:/tmp/cvs-serv24813/src/rfta Modified Files: CodeModelStatements.cpp CodeRewriter.cpp CodeWriterTest.cpp CodeWriterTest.h Log Message: * added support for replacing case value. Index: CodeModelStatements.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeModelStatements.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** CodeModelStatements.cpp 16 Mar 2003 20:32:42 -0000 1.13 --- CodeModelStatements.cpp 16 Mar 2003 21:27:03 -0000 1.14 *************** *** 455,458 **** --- 455,465 ---- + Change + CaseStatement::getConditionChange() const + { + return conditionValueTracker_.getChange(); + } + + void CaseStatement::accept( StatementVisitor &visitor ) Index: CodeRewriter.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeRewriter.cpp,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** CodeRewriter.cpp 16 Mar 2003 20:57:21 -0000 1.28 --- CodeRewriter.cpp 16 Mar 2003 21:27:03 -0000 1.29 *************** *** 259,265 **** beginInsertNewStatement(); insertText( "case " ); - statement.getConditionValue()->accept( *this ); - endInsertNewLabelStatement(); } } --- 259,269 ---- beginInsertNewStatement(); insertText( "case " ); } + + handleMandatoryChange( statement.getConditionChange(), + *statement.getConditionValue() ); + + if ( isInserting() ) + endInsertNewLabelStatement(); } Index: CodeWriterTest.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeWriterTest.cpp,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** CodeWriterTest.cpp 16 Mar 2003 20:57:22 -0000 1.29 --- CodeWriterTest.cpp 16 Mar 2003 21:27:04 -0000 1.30 *************** *** 385,388 **** --- 385,405 ---- + void + CodeWriterTest::testModifyCaseStatement() + { + source_ = "{\n" + " case 12:\n" + "}"; + generateCompound(); + + CodeModel::CaseStatement &caseStatement = + dynamic_cast<CodeModel::CaseStatement &>( *compound_->getStatementAt(0) ); + caseStatement.setConditionValue( makeExpression( "'x'" ) ); + generateAndCheckSource( "{\n" + " case 'x':\n" + "}" ); + } + + } // namespace Refactoring Index: CodeWriterTest.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeWriterTest.h,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** CodeWriterTest.h 16 Mar 2003 20:57:22 -0000 1.24 --- CodeWriterTest.h 16 Mar 2003 21:27:05 -0000 1.25 *************** *** 33,36 **** --- 33,37 ---- CPPUNIT_TEST( testModifyDoCondition ); CPPUNIT_TEST( testModifyDoIteratedStatement ); + CPPUNIT_TEST( testModifyCaseStatement ); CPPUNIT_TEST_SUITE_END(); *************** *** 66,69 **** --- 67,72 ---- void testModifyDoCondition(); void testModifyDoIteratedStatement(); + + void testModifyCaseStatement(); private: |
From: <bl...@us...> - 2003-03-16 21:27:21
|
Update of /cvsroot/cpptool/rfta/include/rfta/refactoring In directory sc8-pr-cvs1:/tmp/cvs-serv24813/include/rfta/refactoring Modified Files: CodeModelStatements.h Log Message: * added support for replacing case value. Index: CodeModelStatements.h =================================================================== RCS file: /cvsroot/cpptool/rfta/include/rfta/refactoring/CodeModelStatements.h,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** CodeModelStatements.h 16 Mar 2003 20:32:43 -0000 1.14 --- CodeModelStatements.h 16 Mar 2003 21:27:05 -0000 1.15 *************** *** 248,251 **** --- 248,253 ---- void setConditionValue( const ExpressionPtr &conditionValue ); + Change getConditionChange() const; + // overriden from Statement void accept( StatementVisitor &visitor ); |
Update of /cvsroot/cpptool/rfta/src/rfta In directory sc8-pr-cvs1:/tmp/cvs-serv13500/src/rfta Modified Files: CodeRewriter.cpp CodeWriterTest.cpp CodeWriterTest.h IndentLevelManager.cpp IndentLevelManager.h Log Message: * added support for replacing do/while condition and iterated statement Index: CodeRewriter.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeRewriter.cpp,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** CodeRewriter.cpp 16 Mar 2003 20:32:42 -0000 1.27 --- CodeRewriter.cpp 16 Mar 2003 20:57:21 -0000 1.28 *************** *** 349,360 **** CodeRewriter::visit( DoStatement &statement ) { ! beginInsertNewStatement(); ! insertText( "do" ); ! statement.getIteratedStatement()->accept( *this ); ! beginInsertNewStatement(); ! insertText( "while ( " ); ! statement.getCondition()->accept( *this ); ! insertText( " )" ); ! endInsertNewStatement(); } --- 349,385 ---- CodeRewriter::visit( DoStatement &statement ) { ! IndentLevelManager::IndentRestorer restorer( indentManager_ ); ! StatementPtr iteratedStatement = statement.getIteratedStatement(); ! if ( isInserting() ) ! { ! beginInsertNewStatement(); ! insertText( "do" ); ! indentManager_.enterNewDoStatement( iteratedStatement ); ! } ! else ! indentManager_.enterExistingDoStatement( iteratedStatement, ! statement.getSourceRange().getStartIndex() ); ! ! handleMandatoryChange( statement.getIteratedStatementChange(), ! *iteratedStatement, ! statementDelete ); ! ! restorer.restoreIndentLevel(); ! ! if ( isInserting() ) ! { ! beginInsertNewStatement(); ! insertText( "while (" ); ! } ! ! handleMandatoryChange( statement.getConditionChange(), ! *statement.getCondition(), ! bracedExpressionDelete ); ! ! if ( isInserting() ) ! { ! insertText( ")" ); ! endInsertNewStatement(); ! } } *************** *** 554,558 **** handleMandatoryChange( statement.getIteratedStatementChange(), ! *statement.getIteratedStatement(), statementDelete ); } --- 579,583 ---- handleMandatoryChange( statement.getIteratedStatementChange(), ! *iteratedStatement, statementDelete ); } Index: CodeWriterTest.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeWriterTest.cpp,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** CodeWriterTest.cpp 16 Mar 2003 20:32:43 -0000 1.28 --- CodeWriterTest.cpp 16 Mar 2003 20:57:22 -0000 1.29 *************** *** 325,329 **** void ! CodeWriterTest::testModifyWhileIterationStatement() { source_ = "{\n" --- 325,329 ---- void ! CodeWriterTest::testModifyWhileIteratedStatement() { source_ = "{\n" *************** *** 339,342 **** --- 339,384 ---- " while ( true )\n" " break;\n" + "}" ); + } + + + void + CodeWriterTest::testModifyDoCondition() + { + source_ = "{\n" + " do\n" + " ;\n" + " while ( true );\n" + "}"; + generateCompound(); + + CodeModel::DoStatement &doStatement = + dynamic_cast<CodeModel::DoStatement &>( *compound_->getStatementAt(0) ); + doStatement.setCondition( makeExpression( "false" ) ); + generateAndCheckSource( "{\n" + " do\n" + " ;\n" + " while ( false );\n" + "}" ); + } + + + void + CodeWriterTest::testModifyDoIteratedStatement() + { + source_ = "{\n" + " do\n" + " ;\n" + " while ( true );\n" + "}"; + generateCompound(); + + CodeModel::DoStatement &doStatement = + dynamic_cast<CodeModel::DoStatement &>( *compound_->getStatementAt(0) ); + doStatement.setIteratedStatement( makeBreakStatement() ); + generateAndCheckSource( "{\n" + " do\n" + " break;\n" + " while ( true );\n" "}" ); } Index: CodeWriterTest.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeWriterTest.h,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** CodeWriterTest.h 16 Mar 2003 20:32:43 -0000 1.23 --- CodeWriterTest.h 16 Mar 2003 20:57:22 -0000 1.24 *************** *** 30,34 **** CPPUNIT_TEST( testAddReturnValue ); CPPUNIT_TEST( testModifyWhileCondition ); ! CPPUNIT_TEST( testModifyWhileIterationStatement ); CPPUNIT_TEST_SUITE_END(); --- 30,36 ---- CPPUNIT_TEST( testAddReturnValue ); CPPUNIT_TEST( testModifyWhileCondition ); ! CPPUNIT_TEST( testModifyWhileIteratedStatement ); ! CPPUNIT_TEST( testModifyDoCondition ); ! CPPUNIT_TEST( testModifyDoIteratedStatement ); CPPUNIT_TEST_SUITE_END(); *************** *** 60,64 **** void testModifyWhileCondition(); ! void testModifyWhileIterationStatement(); private: --- 62,69 ---- void testModifyWhileCondition(); ! void testModifyWhileIteratedStatement(); ! ! void testModifyDoCondition(); ! void testModifyDoIteratedStatement(); private: Index: IndentLevelManager.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/IndentLevelManager.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** IndentLevelManager.cpp 16 Mar 2003 20:32:43 -0000 1.7 --- IndentLevelManager.cpp 16 Mar 2003 20:57:23 -0000 1.8 *************** *** 78,81 **** --- 78,98 ---- + void + IndentLevelManager::enterExistingDoStatement( const CodeModel::StatementPtr &subStatement, + int startingPos ) + { + if ( !isCompoundStatement( subStatement ) ) + pushIndent( findIndentLevelOf( startingPos ) + indentWidth_ ); + } + + + void + IndentLevelManager::enterNewDoStatement( const CodeModel::StatementPtr &subStatement ) + { + if ( !isCompoundStatement( subStatement ) ) + pushIndent( getIndentLevel() + indentWidth_ ); + } + + bool IndentLevelManager::isCompoundStatement( const CodeModel::StatementPtr &subStatement ) const Index: IndentLevelManager.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/IndentLevelManager.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** IndentLevelManager.h 16 Mar 2003 20:32:43 -0000 1.8 --- IndentLevelManager.h 16 Mar 2003 20:57:24 -0000 1.9 *************** *** 71,74 **** --- 71,79 ---- void enterNewWhileStatement( const CodeModel::StatementPtr &subStatement ); + void enterExistingDoStatement( const CodeModel::StatementPtr &subStatement, + int startingPos ); + + void enterNewDoStatement( const CodeModel::StatementPtr &subStatement ); + int getIndentLevel() const; |
From: <bl...@us...> - 2003-03-16 20:32:49
|
Update of /cvsroot/cpptool/rfta/include/rfta/refactoring In directory sc8-pr-cvs1:/tmp/cvs-serv3293/include/rfta/refactoring Modified Files: CodeModelStatements.h Log Message: * added support for replacing while condition and iterated statement * 'while' compound substatement is not indented Index: CodeModelStatements.h =================================================================== RCS file: /cvsroot/cpptool/rfta/include/rfta/refactoring/CodeModelStatements.h,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** CodeModelStatements.h 16 Mar 2003 16:18:39 -0000 1.13 --- CodeModelStatements.h 16 Mar 2003 20:32:43 -0000 1.14 *************** *** 139,143 **** --- 139,146 ---- StatementPtr getIteratedStatement() const; + void setIteratedStatement( const StatementPtr &statement ); + + Change getIteratedStatementChange() const; // overriden from Statement |
Update of /cvsroot/cpptool/rfta/src/rfta In directory sc8-pr-cvs1:/tmp/cvs-serv3293/src/rfta Modified Files: CodeModelStatements.cpp CodeRewriter.cpp CodeRewriter.h CodeWriterTest.cpp CodeWriterTest.h IndentLevelManager.cpp IndentLevelManager.h Log Message: * added support for replacing while condition and iterated statement * 'while' compound substatement is not indented Index: CodeModelStatements.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeModelStatements.cpp,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** CodeModelStatements.cpp 16 Mar 2003 16:18:40 -0000 1.12 --- CodeModelStatements.cpp 16 Mar 2003 20:32:42 -0000 1.13 *************** *** 278,281 **** --- 278,288 ---- + Change + IterationStatement::getIteratedStatementChange() const + { + return iteratedStatementTracker_.getChange(); + } + + void IterationStatement::accept( StatementVisitor &visitor ) Index: CodeRewriter.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeRewriter.cpp,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** CodeRewriter.cpp 16 Mar 2003 19:55:05 -0000 1.26 --- CodeRewriter.cpp 16 Mar 2003 20:32:42 -0000 1.27 *************** *** 129,132 **** --- 129,147 ---- void + CodeRewriter::deleteBracedExpression( const SourceRange &range ) + { + int startIndex = range.getStartIndex(); + while ( startIndex > 0 && isSpace( originalSource_.at( startIndex-1 ) ) ) + --startIndex; + + int endIndex = range.getEndIndex(); + while ( endIndex < originalSource_.length() && isSpace( originalSource_.at( endIndex ) ) ) + ++endIndex; + + deleteText( SourceRange( startIndex, endIndex - startIndex ) ); + } + + + void CodeRewriter::deleteRange( const SourceRange &range, DeletionType deletionType ) *************** *** 136,139 **** --- 151,156 ---- else if ( deletionType == trailingExpressionDelete ) deleteTrailingExpression( range ); + else if ( deletionType == bracedExpressionDelete ) + deleteBracedExpression( range ); else deleteText( range ); *************** *** 179,183 **** --- 196,206 ---- mode_ = inserting; + if ( isInserting() && deletionType == bracedExpressionDelete ) + insertText( " " ); + element.accept( *this ); + + if ( isInserting() && deletionType == bracedExpressionDelete ) + insertText( " " ); } *************** *** 478,483 **** } - SourceRange range( ); - handleOptionalChange( statement.getValueChange(), statement.getValue(), --- 501,504 ---- *************** *** 511,519 **** CodeRewriter::visit( WhileStatement &statement ) { ! beginInsertNewStatement(); ! insertText( "while ( " ); ! statement.getCondition()->accept( *this ); ! insertText( " )" ); ! statement.getIteratedStatement()->accept( *this ); } --- 532,559 ---- CodeRewriter::visit( WhileStatement &statement ) { ! if ( isInserting() ) ! { ! beginInsertNewStatement(); ! insertText( "while (" ); ! } ! ! handleMandatoryChange( statement.getConditionChange(), ! *statement.getCondition(), ! bracedExpressionDelete ); ! ! IndentLevelManager::IndentRestorer restorer( indentManager_ ); ! StatementPtr iteratedStatement = statement.getIteratedStatement(); ! if ( isInserting() ) ! { ! insertText( ")" ); ! indentManager_.enterNewWhileStatement( iteratedStatement ); ! } ! else ! indentManager_.enterExistingWhileStatement( iteratedStatement, ! statement.getSourceRange().getStartIndex() ); ! ! handleMandatoryChange( statement.getIteratedStatementChange(), ! *statement.getIteratedStatement(), ! statementDelete ); } Index: CodeRewriter.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeRewriter.h,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** CodeRewriter.h 16 Mar 2003 19:55:06 -0000 1.12 --- CodeRewriter.h 16 Mar 2003 20:32:43 -0000 1.13 *************** *** 76,80 **** minimalDelete =0, statementDelete, ! trailingExpressionDelete }; --- 76,81 ---- minimalDelete =0, statementDelete, ! trailingExpressionDelete, ! bracedExpressionDelete }; *************** *** 133,136 **** --- 134,139 ---- void deleteTrailingExpression( const SourceRange &range ); + + void deleteBracedExpression( const SourceRange &range ); void deleteRange( const SourceRange &range, Index: CodeWriterTest.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeWriterTest.cpp,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** CodeWriterTest.cpp 16 Mar 2003 19:55:06 -0000 1.27 --- CodeWriterTest.cpp 16 Mar 2003 20:32:43 -0000 1.28 *************** *** 305,308 **** --- 305,346 ---- + void + CodeWriterTest::testModifyWhileCondition() + { + source_ = "{\n" + " while ( true )\n" + " ;\n" + "}"; + generateCompound(); + + CodeModel::WhileStatement &whileStatement = + dynamic_cast<CodeModel::WhileStatement &>( *compound_->getStatementAt(0) ); + whileStatement.setCondition( makeExpression( "false" ) ); + generateAndCheckSource( "{\n" + " while ( false )\n" + " ;\n" + "}" ); + } + + + void + CodeWriterTest::testModifyWhileIterationStatement() + { + source_ = "{\n" + " while ( true )\n" + " ;\n" + "}"; + generateCompound(); + + CodeModel::WhileStatement &whileStatement = + dynamic_cast<CodeModel::WhileStatement &>( *compound_->getStatementAt(0) ); + whileStatement.setIteratedStatement( makeBreakStatement() ); + generateAndCheckSource( "{\n" + " while ( true )\n" + " break;\n" + "}" ); + } + + } // namespace Refactoring Index: CodeWriterTest.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeWriterTest.h,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** CodeWriterTest.h 16 Mar 2003 16:18:41 -0000 1.22 --- CodeWriterTest.h 16 Mar 2003 20:32:43 -0000 1.23 *************** *** 29,32 **** --- 29,34 ---- CPPUNIT_TEST( testRemoveReturnValue ); CPPUNIT_TEST( testAddReturnValue ); + CPPUNIT_TEST( testModifyWhileCondition ); + CPPUNIT_TEST( testModifyWhileIterationStatement ); CPPUNIT_TEST_SUITE_END(); *************** *** 56,59 **** --- 58,64 ---- void testRemoveReturnValue(); void testAddReturnValue(); + + void testModifyWhileCondition(); + void testModifyWhileIterationStatement(); private: Index: IndentLevelManager.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/IndentLevelManager.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** IndentLevelManager.cpp 16 Mar 2003 10:23:07 -0000 1.6 --- IndentLevelManager.cpp 16 Mar 2003 20:32:43 -0000 1.7 *************** *** 6,9 **** --- 6,10 ---- #include "stdafx.h" #include "IndentLevelManager.h" + #include <rfta/refactoring/CodeModelStatements.h> *************** *** 57,60 **** --- 58,85 ---- { pushIndent( getIndentLevel() + indentWidth_ ); + } + + + void + IndentLevelManager::enterExistingWhileStatement( const CodeModel::StatementPtr &subStatement, + int startingPos ) + { + if ( !isCompoundStatement( subStatement ) ) + pushIndent( findIndentLevelOf( startingPos ) + indentWidth_ ); + } + + + void + IndentLevelManager::enterNewWhileStatement( const CodeModel::StatementPtr &subStatement ) + { + if ( !isCompoundStatement( subStatement ) ) + pushIndent( getIndentLevel() + indentWidth_ ); + } + + + bool + IndentLevelManager::isCompoundStatement( const CodeModel::StatementPtr &subStatement ) const + { + return dynamic_cast<CodeModel::CompoundStatement *>( subStatement.get() ) != 0; } Index: IndentLevelManager.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/IndentLevelManager.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** IndentLevelManager.h 16 Mar 2003 10:23:07 -0000 1.7 --- IndentLevelManager.h 16 Mar 2003 20:32:43 -0000 1.8 *************** *** 6,10 **** #define RFTA_INDENTLEVELMANAGER_H ! #include <rfta/refactoring/Config.h> #include <string> --- 6,10 ---- #define RFTA_INDENTLEVELMANAGER_H ! #include <rfta/refactoring/CodeModelForward.h> #include <string> *************** *** 66,69 **** --- 66,74 ---- void enterNewElseStatement(); + void enterExistingWhileStatement( const CodeModel::StatementPtr &subStatement, + int startingPos ); + + void enterNewWhileStatement( const CodeModel::StatementPtr &subStatement ); + int getIndentLevel() const; *************** *** 72,76 **** --- 77,84 ---- private: int findIndentLevelOf( int pos ) const; + void pushIndent( int indent ); + + bool isCompoundStatement( const CodeModel::StatementPtr &subStatement ) const; private: |
From: <bl...@us...> - 2003-03-16 19:55:11
|
Update of /cvsroot/cpptool/rfta/src/rfta In directory sc8-pr-cvs1:/tmp/cvs-serv20936/src/rfta Modified Files: CodeRewriter.cpp CodeRewriter.h CodeWriterTest.cpp Log Message: * refactored some more Index: CodeRewriter.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeRewriter.cpp,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** CodeRewriter.cpp 16 Mar 2003 16:25:23 -0000 1.25 --- CodeRewriter.cpp 16 Mar 2003 19:55:05 -0000 1.26 *************** *** 117,120 **** --- 117,144 ---- + void + CodeRewriter::deleteTrailingExpression( const SourceRange &range ) + { + int startIndex = range.getStartIndex(); + while ( startIndex > 0 && isSpace( originalSource_.at( startIndex-1 ) ) ) + --startIndex; + + deleteText( SourceRange( startIndex, range.getEndIndex() - startIndex ) ); + } + + + void + CodeRewriter::deleteRange( const SourceRange &range, + DeletionType deletionType ) + { + if ( deletionType == statementDelete ) + deleteStatement( range ); + else if ( deletionType == trailingExpressionDelete ) + deleteTrailingExpression( range ); + else + deleteText( range ); + } + + bool CodeRewriter::isSpace( char c ) const *************** *** 139,154 **** void ! CodeRewriter::makeRequiredChangeAndVisitElement( const CodeModel::Change &change, ! CodeModel::Element &element, ! DeletionType deletionType ) { - // Element may only be unmodified or replaced... (should use a different enum type ?) - if ( isUpdating() && change.wasReplaced() ) { ! if ( deletionType == statementDelete ) ! deleteStatement( change.oldRange_ ); ! else ! deleteText( change.oldRange_ ); setCurrentInsertionPos( change.oldRange_.getEndIndex() ); } --- 163,173 ---- void ! CodeRewriter::handleMandatoryChange( const CodeModel::Change &change, ! CodeModel::Element &element, ! DeletionType deletionType ) { if ( isUpdating() && change.wasReplaced() ) { ! deleteRange( change.oldRange_, deletionType ); setCurrentInsertionPos( change.oldRange_.getEndIndex() ); } *************** *** 165,168 **** --- 184,221 ---- void + CodeRewriter::handleOptionalChange( const CodeModel::Change &change, + const CodeModel::ElementPtr &element, + const std::string &valueSeparator, + int addingIndex, + DeletionType deletionType ) + { + if ( isUpdating() && ( change.wasRemoved() || change.wasReplaced() ) ) + { + deleteRange( change.oldRange_, deletionType ); + setCurrentInsertionPos( change.oldRange_.getEndIndex() ); + } + + if ( !element + || ( isUpdating() && change.wasRemoved() ) ) + return; + + if ( isUpdating() && change.wasAdded() ) + setCurrentInsertionPos( addingIndex ); + + if ( isInserting() + || ( isUpdating() && (change.wasAdded() || change.wasReplaced() ) ) ) + insertText( valueSeparator ); + + ModeRestorer restorer( mode_ ); + if ( isUpdating() && change.isUnmodified() ) + mode_ = updating; + else + mode_ = inserting; + + element->accept( *this ); + } + + + void CodeRewriter::visit( BreakStatement &statement ) { *************** *** 322,327 **** insertText( "if ( " ); } ! makeRequiredChangeAndVisitElement( statement.getConditionChange(), ! *statement.getCondition() ); IndentLevelManager::IndentRestorer restorer( indentManager_ ); --- 375,380 ---- insertText( "if ( " ); } ! handleMandatoryChange( statement.getConditionChange(), ! *statement.getCondition() ); IndentLevelManager::IndentRestorer restorer( indentManager_ ); *************** *** 335,341 **** Change thenChange = statement.getThenStatementChange(); ! makeRequiredChangeAndVisitElement( thenChange, ! *statement.getThenStatement(), ! statementDelete ); Change elseChange = statement.getElseStatementChange(); --- 388,394 ---- Change thenChange = statement.getThenStatementChange(); ! handleMandatoryChange( thenChange, ! *statement.getThenStatement(), ! statementDelete ); Change elseChange = statement.getElseStatementChange(); *************** *** 418,451 **** CodeRewriter::visit( ReturnStatement &statement ) { ! if ( isUpdating() ) { ! Change change = statement.getValueChange(); ! if ( change.type_ == Change::replaced || change.type_ == Change::removed ) ! deleteText( change.oldRange_ ); ! ! if ( change.type_ == Change::removed || !statement.hasValue() ) ! return; ! ! ModeModifier mode( mode_, change.type_ == Change::unmodified ? updating : inserting ); ! if ( mode_ == inserting ) ! currentInsertionPos_ = statement.getSourceRange().getEndIndex() -1; ! if ( change.type_ == Change::added ) ! insertText( " " ); ! statement.getValue()->accept( *this ); ! } ! else if ( isInserting() ) ! { ! beginInsertNewStatement(); ! insertText( "return" ); ! if ( statement.hasValue() ) ! { ! insertText( " " ); ! statement.getValue()->accept( *this ); ! } endInsertNewStatement(); - } } --- 471,491 ---- CodeRewriter::visit( ReturnStatement &statement ) { ! const std::string keyWord( "return" ); ! if ( isInserting() ) { ! beginInsertNewStatement(); ! insertText( keyWord ); ! } ! SourceRange range( ); ! handleOptionalChange( statement.getValueChange(), ! statement.getValue(), ! " ", ! statement.getSourceRange().getStartIndex() + keyWord.length(), ! trailingExpressionDelete ); ! if ( isInserting() ) endInsertNewStatement(); } Index: CodeRewriter.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeRewriter.h,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** CodeRewriter.h 16 Mar 2003 16:25:24 -0000 1.11 --- CodeRewriter.h 16 Mar 2003 19:55:06 -0000 1.12 *************** *** 75,79 **** { minimalDelete =0, ! statementDelete }; --- 75,80 ---- { minimalDelete =0, ! statementDelete, ! trailingExpressionDelete }; *************** *** 131,141 **** void deleteStatement( const SourceRange &range ); bool isSpace( char c ) const; bool isNewLine( char c ) const; ! void makeRequiredChangeAndVisitElement( const CodeModel::Change &change, ! CodeModel::Element &element, ! DeletionType deletionType = minimalDelete ); void setCurrentInsertionPos( int index ); --- 132,161 ---- void deleteStatement( const SourceRange &range ); + void deleteTrailingExpression( const SourceRange &range ); + + void deleteRange( const SourceRange &range, + DeletionType deletionType ); + bool isSpace( char c ) const; bool isNewLine( char c ) const; ! /*! Handles text change for a element that always exist. ! * Possible changes are restricted to replaced and unmodified. ! */ ! void handleMandatoryChange( const CodeModel::Change &change, ! CodeModel::Element &element, ! DeletionType deletionType = minimalDelete ); ! ! /*! Handles text change for a element that may not exist. ! * Possible changes are replaced, unmodified, added and removed. ! * \param valueSeparator Text inserted before the element if it exist ! * \param addingIndex Index the element text is inserted at if it is being added. ! */ ! void handleOptionalChange( const CodeModel::Change &change, ! const CodeModel::ElementPtr &element, ! const std::string &valueSeparator, ! int addingIndex, ! DeletionType deletionType = minimalDelete ); void setCurrentInsertionPos( int index ); Index: CodeWriterTest.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeWriterTest.cpp,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** CodeWriterTest.cpp 16 Mar 2003 16:18:41 -0000 1.26 --- CodeWriterTest.cpp 16 Mar 2003 19:55:06 -0000 1.27 *************** *** 283,287 **** returnStatement.setValue( CodeModel::ExpressionPtr() ); generateAndCheckSource( "{\n" ! " return ;\n" "}" ); } --- 283,287 ---- returnStatement.setValue( CodeModel::ExpressionPtr() ); generateAndCheckSource( "{\n" ! " return;\n" "}" ); } |
From: <bl...@us...> - 2003-03-16 16:25:26
|
Update of /cvsroot/cpptool/rfta/src/rfta In directory sc8-pr-cvs1:/tmp/cvs-serv29464/src/rfta Modified Files: CodeRewriter.cpp CodeRewriter.h Log Message: * refactored some more Index: CodeRewriter.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeRewriter.cpp,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** CodeRewriter.cpp 16 Mar 2003 16:18:41 -0000 1.24 --- CodeRewriter.cpp 16 Mar 2003 16:25:23 -0000 1.25 *************** *** 140,144 **** void CodeRewriter::makeRequiredChangeAndVisitElement( const CodeModel::Change &change, ! CodeModel::Element &element ) { // Element may only be unmodified or replaced... (should use a different enum type ?) --- 140,145 ---- void CodeRewriter::makeRequiredChangeAndVisitElement( const CodeModel::Change &change, ! CodeModel::Element &element, ! DeletionType deletionType ) { // Element may only be unmodified or replaced... (should use a different enum type ?) *************** *** 146,150 **** if ( isUpdating() && change.wasReplaced() ) { ! deleteText( change.oldRange_ ); setCurrentInsertionPos( change.oldRange_.getEndIndex() ); } --- 147,154 ---- if ( isUpdating() && change.wasReplaced() ) { ! if ( deletionType == statementDelete ) ! deleteStatement( change.oldRange_ ); ! else ! deleteText( change.oldRange_ ); setCurrentInsertionPos( change.oldRange_.getEndIndex() ); } *************** *** 318,326 **** insertText( "if ( " ); } ! { ! makeRequiredChangeAndVisitElement( statement.getConditionChange(), ! *statement.getCondition() ); ! // statement.getCondition()->accept( *this ); ! } IndentLevelManager::IndentRestorer restorer( indentManager_ ); --- 322,327 ---- insertText( "if ( " ); } ! makeRequiredChangeAndVisitElement( statement.getConditionChange(), ! *statement.getCondition() ); IndentLevelManager::IndentRestorer restorer( indentManager_ ); *************** *** 334,354 **** Change thenChange = statement.getThenStatementChange(); ! if ( !isInserting() && !thenChange.isUnmodified() ) ! { ! deleteStatement( thenChange.oldRange_ ); ! if ( thenChange.wasReplaced() ) ! currentInsertionPos_ = thenChange.oldRange_.getEndIndex(); ! } ! ! Mode thenMode; ! if ( isInserting() || !thenChange.isUnmodified() ) ! thenMode = inserting; ! else ! thenMode = updating; ! ! { ! ModeModifier mode( mode_, thenMode ); ! statement.getThenStatement()->accept( *this ); ! } Change elseChange = statement.getElseStatementChange(); --- 335,341 ---- Change thenChange = statement.getThenStatementChange(); ! makeRequiredChangeAndVisitElement( thenChange, ! *statement.getThenStatement(), ! statementDelete ); Change elseChange = statement.getElseStatementChange(); Index: CodeRewriter.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeRewriter.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** CodeRewriter.h 16 Mar 2003 16:18:41 -0000 1.10 --- CodeRewriter.h 16 Mar 2003 16:25:24 -0000 1.11 *************** *** 72,75 **** --- 72,81 ---- }; + enum DeletionType + { + minimalDelete =0, + statementDelete + }; + class ModeRestorer { *************** *** 130,134 **** void makeRequiredChangeAndVisitElement( const CodeModel::Change &change, ! CodeModel::Element &element ); void setCurrentInsertionPos( int index ); --- 136,141 ---- void makeRequiredChangeAndVisitElement( const CodeModel::Change &change, ! CodeModel::Element &element, ! DeletionType deletionType = minimalDelete ); void setCurrentInsertionPos( int index ); |
Update of /cvsroot/cpptool/rfta/src/rfta In directory sc8-pr-cvs1:/tmp/cvs-serv26062/src/rfta Modified Files: CodeModelElement.cpp CodeModelExpressions.cpp CodeModelStatements.cpp CodeRewriter.cpp CodeRewriter.h CodeWriterTest.cpp CodeWriterTest.h Log Message: * introduced ElementVisitor * added tests for IfStatement and fixed a bug * prepared some rewriter refactoring Index: CodeModelElement.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeModelElement.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** CodeModelElement.cpp 16 Mar 2003 13:51:08 -0000 1.8 --- CodeModelElement.cpp 16 Mar 2003 16:18:40 -0000 1.9 *************** *** 62,65 **** --- 62,71 ---- + void + Element::accept( ElementVisitor &visitor ) + { + } + + } // namespace CodeModel } // namespace Refactoring Index: CodeModelExpressions.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeModelExpressions.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** CodeModelExpressions.cpp 16 Mar 2003 13:51:09 -0000 1.8 --- CodeModelExpressions.cpp 16 Mar 2003 16:18:40 -0000 1.9 *************** *** 16,19 **** --- 16,27 ---- + void + Expression::accept( ElementVisitor &visitor ) + { + accept( static_cast<ExpressionVisitor &>( visitor ) ); + } + + + GenericExpression::GenericExpression( const std::string &value ) : value_( value ) Index: CodeModelStatements.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeModelStatements.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** CodeModelStatements.cpp 16 Mar 2003 15:33:10 -0000 1.11 --- CodeModelStatements.cpp 16 Mar 2003 16:18:40 -0000 1.12 *************** *** 19,22 **** --- 19,29 ---- + void + Statement::accept( ElementVisitor &visitor ) + { + accept( static_cast<StatementVisitor &>( visitor ) ); + } + + void *************** *** 140,143 **** --- 147,157 ---- { conditionTracker_.setElement( condition ); + } + + + Change + ConditionStatement::getConditionChange() const + { + return conditionTracker_.getChange(); } Index: CodeRewriter.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeRewriter.cpp,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** CodeRewriter.cpp 16 Mar 2003 15:43:09 -0000 1.23 --- CodeRewriter.cpp 16 Mar 2003 16:18:41 -0000 1.24 *************** *** 132,135 **** --- 132,164 ---- void + CodeRewriter::setCurrentInsertionPos( int index ) + { + currentInsertionPos_ = index; + } + + + void + CodeRewriter::makeRequiredChangeAndVisitElement( const CodeModel::Change &change, + CodeModel::Element &element ) + { + // Element may only be unmodified or replaced... (should use a different enum type ?) + + if ( isUpdating() && change.wasReplaced() ) + { + deleteText( change.oldRange_ ); + setCurrentInsertionPos( change.oldRange_.getEndIndex() ); + } + + ModeRestorer restorer( mode_ ); + if ( isUpdating() && change.isUnmodified() ) + mode_ = updating; + else + mode_ = inserting; + + element.accept( *this ); + } + + + void CodeRewriter::visit( BreakStatement &statement ) { *************** *** 289,293 **** insertText( "if ( " ); } ! statement.getCondition()->accept( *this ); IndentLevelManager::IndentRestorer restorer( indentManager_ ); --- 318,326 ---- insertText( "if ( " ); } ! { ! makeRequiredChangeAndVisitElement( statement.getConditionChange(), ! *statement.getCondition() ); ! // statement.getCondition()->accept( *this ); ! } IndentLevelManager::IndentRestorer restorer( indentManager_ ); Index: CodeRewriter.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeRewriter.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** CodeRewriter.h 16 Mar 2003 10:23:07 -0000 1.9 --- CodeRewriter.h 16 Mar 2003 16:18:41 -0000 1.10 *************** *** 21,26 **** /// Rewrite source to match change made to the model. ! class CodeRewriter : private StatementVisitor ! , private ExpressionVisitor { public: --- 21,25 ---- /// Rewrite source to match change made to the model. ! class CodeRewriter : private ElementVisitor { public: *************** *** 73,97 **** }; ! class ModeModifier { public: ! ModeModifier( Mode &mode, ! Mode newMode ) ! : oldMode_( mode ) ! , mode_( mode ) { - mode_ = newMode; } ! ~ModeModifier() { mode_ = oldMode_; } ! private: Mode &mode_; Mode oldMode_; }; SourceRange getCurrentInsertionRange() const; --- 72,107 ---- }; ! class ModeRestorer { public: ! ModeRestorer( Mode &mode ) ! : oldMode_( mode ) ! , mode_( mode ) { } ! ~ModeRestorer() { mode_ = oldMode_; } ! protected: Mode &mode_; + + private: Mode oldMode_; }; + class ModeModifier : public ModeRestorer + { + public: + ModeModifier( Mode &mode, + Mode newMode ) + : ModeRestorer( mode ) + { + mode_ = newMode; + } + }; + SourceRange getCurrentInsertionRange() const; *************** *** 118,121 **** --- 128,136 ---- bool isNewLine( char c ) const; + + void makeRequiredChangeAndVisitElement( const CodeModel::Change &change, + CodeModel::Element &element ); + + void setCurrentInsertionPos( int index ); private: Index: CodeWriterTest.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeWriterTest.cpp,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** CodeWriterTest.cpp 16 Mar 2003 15:43:09 -0000 1.25 --- CodeWriterTest.cpp 16 Mar 2003 16:18:41 -0000 1.26 *************** *** 234,237 **** --- 234,258 ---- void + CodeWriterTest::testModifyIfCondition() + { + source_ = "{\n" + " if ( true )\n" + " return 5;\n" + " return 2;\n" + "}"; + generateCompound(); + + CodeModel::IfStatement &ifStatement = + dynamic_cast<CodeModel::IfStatement &>( *compound_->getStatementAt(0) ); + ifStatement.setCondition( makeExpression( "x < y" ) ); + generateAndCheckSource( "{\n" + " if ( x < y )\n" + " return 5;\n" + " return 2;\n" + "}" ); + } + + + void CodeWriterTest::testModifyReturnValue() { Index: CodeWriterTest.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeWriterTest.h,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** CodeWriterTest.h 16 Mar 2003 15:43:09 -0000 1.21 --- CodeWriterTest.h 16 Mar 2003 16:18:41 -0000 1.22 *************** *** 25,28 **** --- 25,29 ---- CPPUNIT_TEST( testRemoveElseFromIfThenStatement ); CPPUNIT_TEST( testModifyElseFromIfThenStatement ); + CPPUNIT_TEST( testModifyIfCondition ); CPPUNIT_TEST( testModifyReturnValue ); CPPUNIT_TEST( testRemoveReturnValue ); *************** *** 50,53 **** --- 51,55 ---- void testRemoveElseFromIfThenStatement(); void testModifyElseFromIfThenStatement(); + void testModifyIfCondition(); void testModifyReturnValue(); |
From: <bl...@us...> - 2003-03-16 16:18:43
|
Update of /cvsroot/cpptool/rfta/src In directory sc8-pr-cvs1:/tmp/cvs-serv26062/src Modified Files: rfta.opt Log Message: * introduced ElementVisitor * added tests for IfStatement and fixed a bug * prepared some rewriter refactoring Index: rfta.opt =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta.opt,v retrieving revision 1.88 retrieving revision 1.89 diff -C2 -d -r1.88 -r1.89 Binary files /tmp/cvsP60vxj and /tmp/cvs0fy64r differ |
Update of /cvsroot/cpptool/rfta/include/rfta/refactoring In directory sc8-pr-cvs1:/tmp/cvs-serv26062/include/rfta/refactoring Modified Files: CodeModelElement.h CodeModelExpressions.h CodeModelForward.h CodeModelStatements.h CodeModelVisitor.h Log Message: * introduced ElementVisitor * added tests for IfStatement and fixed a bug * prepared some rewriter refactoring Index: CodeModelElement.h =================================================================== RCS file: /cvsroot/cpptool/rfta/include/rfta/refactoring/CodeModelElement.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** CodeModelElement.h 16 Mar 2003 15:33:09 -0000 1.10 --- CodeModelElement.h 16 Mar 2003 16:18:39 -0000 1.11 *************** *** 40,43 **** --- 40,45 ---- void setSource( const ASTNodePtr &node ); + virtual void accept( ElementVisitor &visitor ); + private: /** Called after setSource() is called. Index: CodeModelExpressions.h =================================================================== RCS file: /cvsroot/cpptool/rfta/include/rfta/refactoring/CodeModelExpressions.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** CodeModelExpressions.h 16 Mar 2003 13:51:06 -0000 1.9 --- CodeModelExpressions.h 16 Mar 2003 16:18:39 -0000 1.10 *************** *** 22,25 **** --- 22,27 ---- virtual ~Expression(); + void accept( ElementVisitor &visitor ); + virtual void accept( ExpressionVisitor &visitor ) =0; }; Index: CodeModelForward.h =================================================================== RCS file: /cvsroot/cpptool/rfta/include/rfta/refactoring/CodeModelForward.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** CodeModelForward.h 16 Mar 2003 15:33:09 -0000 1.7 --- CodeModelForward.h 16 Mar 2003 16:18:39 -0000 1.8 *************** *** 12,15 **** --- 12,16 ---- namespace Refactoring { namespace CodeModel { + class Change; class Element; class Label; *************** *** 48,51 **** --- 49,53 ---- class ExpressionVisitor; class StatementVisitor; + class ElementVisitor; typedef boost::shared_ptr<Element> ElementPtr; Index: CodeModelStatements.h =================================================================== RCS file: /cvsroot/cpptool/rfta/include/rfta/refactoring/CodeModelStatements.h,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** CodeModelStatements.h 16 Mar 2003 15:43:09 -0000 1.12 --- CodeModelStatements.h 16 Mar 2003 16:18:39 -0000 1.13 *************** *** 22,25 **** --- 22,27 ---- virtual ~Statement(); + void accept( ElementVisitor &visitor ); + virtual void accept( StatementVisitor &visitor ) =0; }; *************** *** 82,85 **** --- 84,89 ---- void setCondition( const ExpressionPtr &condition ); + + Change getConditionChange() const; // overriden from Statement Index: CodeModelVisitor.h =================================================================== RCS file: /cvsroot/cpptool/rfta/include/rfta/refactoring/CodeModelVisitor.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CodeModelVisitor.h 22 Dec 2002 11:44:01 -0000 1.2 --- CodeModelVisitor.h 16 Mar 2003 16:18:39 -0000 1.3 *************** *** 58,61 **** --- 58,66 ---- + class ElementVisitor : public StatementVisitor + , public ExpressionVisitor + { + }; + } // namespace CodeModel } // namespace Refactoring |