From: <bl...@us...> - 2003-04-10 08:37:56
|
Update of /cvsroot/cpptool/rfta/src/rfta In directory sc8-pr-cvs1:/tmp/cvs-serv25617/src/rfta Modified Files: CodeModel.cpp CodeModelElement.cpp CodeModelExpressions.cpp CodeModelGeneratorTest.cpp CodeModelStatements.cpp CodeRewriter.cpp CodeRewriter.h CodeWriterTest.cpp CodeWriterTest.h rfta.dsp Log Message: * added support for appending a variable declaration in a declaration expression. Index: CodeModel.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeModel.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** CodeModel.cpp 6 Apr 2003 18:06:59 -0000 1.11 --- CodeModel.cpp 10 Apr 2003 08:37:50 -0000 1.12 *************** *** 314,327 **** TypePartPtr primaryType( getDeclaratorPrimaryType( expression ) ); DeclaratorExpressionPtr declaratorExpression( new DeclaratorExpression( primaryType ) ); - setElementSource( *declaratorExpression, expression ); for ( int index = 0; index < expression->getChildCount(); ++index ) { ! DeclaratorPtr declarator = ! makeVariableDeclarator( expression->getChildAt( index ) ); declaratorExpression->appendDeclarator( declarator ); } return declaratorExpression; } --- 314,329 ---- TypePartPtr primaryType( getDeclaratorPrimaryType( expression ) ); DeclaratorExpressionPtr declaratorExpression( new DeclaratorExpression( primaryType ) ); for ( int index = 0; index < expression->getChildCount(); ++index ) { ! const ASTNodePtr &declaratorNode = expression->getChildAt( index ); ! DeclaratorPtr declarator = makeVariableDeclarator( declaratorNode ); ! setElementSource( *declarator, declaratorNode ); declaratorExpression->appendDeclarator( declarator ); } + setElementSource( *declaratorExpression, expression ); + return declaratorExpression; } *************** *** 345,348 **** --- 347,361 ---- ASTNodePtr typeNode = node->getProperty( ASTNodeProperties::typeDeclSecondaryPrefixProperty ); + TypePartPtr type = makeOptionalType( typeNode ); + + ASTNodePtr typeSuffixNode = + node->getProperty( ASTNodeProperties::typeDeclSuffixProperty ); + TypePartPtr typeSuffix = makeOptionalType( typeSuffixNode ); + + ASTNodePtr nameNode = + node->getProperty( ASTNodeProperties::variableNameProperty ); + IdentifierPtr name = makeIdentifier( nameNode ); + + /* std::string type = typeNode ? typeNode->getBlankedText() : std::string(""); *************** *** 356,370 **** : std::string(""); - ASTNodePtr initializerNode = - node->getProperty( ASTNodeProperties::variableInitializerProperty ); - TypePartPtr typePtr( new TypePart( type ) ); TypePartPtr typeSuffixPtr( new TypePart( typeSuffix ) ); IdentifierPtr namePtr( new Identifier( name ) ); if ( !initializerNode ) ! return DeclaratorPtr( new Declarator( typePtr, namePtr, typeSuffixPtr ) ); ExpressionPtr initializer = makeVariableInitializerExpression( initializerNode ); ! return DeclaratorPtr( new Declarator( typePtr, namePtr, typeSuffixPtr, initializer ) ); } --- 369,411 ---- : std::string(""); TypePartPtr typePtr( new TypePart( type ) ); + setElementSource( *typePtr, typeNode ); + TypePartPtr typeSuffixPtr( new TypePart( typeSuffix ) ); + setElementSource( *typeSuffixPtr, typeSuffixNode ); + IdentifierPtr namePtr( new Identifier( name ) ); + setElementSource( *namePtr, nameNode ); + */ + + ASTNodePtr initializerNode = + node->getProperty( ASTNodeProperties::variableInitializerProperty ); + if ( !initializerNode ) ! return DeclaratorPtr( new Declarator( type, name, typeSuffix ) ); ExpressionPtr initializer = makeVariableInitializerExpression( initializerNode ); ! return DeclaratorPtr( new Declarator( type, name, typeSuffix, initializer ) ); ! } ! ! ! TypePartPtr ! Generator::makeOptionalType( const ASTNodePtr &typeNode ) ! { ! if ( !typeNode ) ! return TypePartPtr(); ! ! TypePartPtr typePtr( new TypePart( typeNode->getBlankedText() ) ); ! setElementSource( *typePtr, typeNode ); ! return typePtr; ! } ! ! ! IdentifierPtr ! Generator::makeIdentifier( const ASTNodePtr &identifierNode ) ! { ! IdentifierPtr namePtr( new Identifier( identifierNode->getBlankedText() ) ); ! setElementSource( *namePtr, identifierNode ); ! return namePtr; } Index: CodeModelElement.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeModelElement.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** CodeModelElement.cpp 16 Mar 2003 16:18:40 -0000 1.9 --- CodeModelElement.cpp 10 Apr 2003 08:37:50 -0000 1.10 *************** *** 1,3 **** ! // ////////////////////////////////////////////////////////////////////////// // (c)Copyright 2002, Baptiste Lepilleur. // Created: 2002/12/22 --- 1,3 ---- ! / ////////////////////////////////////////////////////////////////////////// // (c)Copyright 2002, Baptiste Lepilleur. // Created: 2002/12/22 Index: CodeModelExpressions.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeModelExpressions.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** CodeModelExpressions.cpp 6 Apr 2003 18:06:59 -0000 1.13 --- CodeModelExpressions.cpp 10 Apr 2003 08:37:50 -0000 1.14 *************** *** 103,107 **** DeclaratorExpression::getDeclaratorCount() const { ! return declarators_.size(); } --- 103,107 ---- DeclaratorExpression::getDeclaratorCount() const { ! return declaratorsTracker_.getElementCount(); } *************** *** 110,114 **** DeclaratorExpression::getDeclaratorAt( int index ) const { ! return declarators_.at( index ); } --- 110,114 ---- DeclaratorExpression::getDeclaratorAt( int index ) const { ! return declaratorsTracker_.getAt( index ); } *************** *** 118,122 **** const DeclaratorPtr &declarator ) { ! declarators_.insert( declarators_.begin() + index, declarator ); } --- 118,122 ---- const DeclaratorPtr &declarator ) { ! declaratorsTracker_.insertAt( index, declarator ); } *************** *** 125,129 **** DeclaratorExpression::appendDeclarator( const DeclaratorPtr &declarator ) { ! declarators_.push_back( declarator ); } --- 125,129 ---- DeclaratorExpression::appendDeclarator( const DeclaratorPtr &declarator ) { ! declaratorsTracker_.append( declarator ); } *************** *** 132,136 **** DeclaratorExpression::removeDeclaratorAt( int index ) { ! declarators_.erase( declarators_.begin() + index ); } --- 132,165 ---- DeclaratorExpression::removeDeclaratorAt( int index ) { ! declaratorsTracker_.removeAt( index ); ! } ! ! ! Change ! DeclaratorExpression::getChangeAt( int changeIndex ) const ! { ! return declaratorsTracker_.getChangeAt( changeIndex ); ! } ! ! ! DeclaratorPtr ! DeclaratorExpression::getChangeDeclaratorAt( int changeIndex ) const ! { ! return declaratorsTracker_.getChangeElementAt( changeIndex ); ! } ! ! ! int ! DeclaratorExpression::getChangeCount() const ! { ! return declaratorsTracker_.getChangeCount(); ! } ! ! ! void ! DeclaratorExpression::setElementIsFromSource() ! { ! primaryTypeTracker_.setElementIsFromSource(); ! declaratorsTracker_.setElementIsFromSource(); } *************** *** 159,162 **** --- 188,198 ---- + void + TypePart::accept( ElementVisitor &visitor ) + { + visitor.visit( makeSharedFromThis( this ) ); + } + + Identifier::Identifier( const std::string &identifier ) *************** *** 175,185 **** Declarator::Declarator( const TypePartPtr &type, const IdentifierPtr &name, const TypePartPtr &typeSuffix ) ! : type_( type ) ! , name_( name ) ! , typeSuffix_( typeSuffix ) { } --- 211,228 ---- + void + Identifier::accept( ElementVisitor &visitor ) + { + visitor.visit( makeSharedFromThis( this ) ); + } + + Declarator::Declarator( const TypePartPtr &type, const IdentifierPtr &name, const TypePartPtr &typeSuffix ) ! : typeTracker_( type ) ! , nameTracker_( name ) ! , typeSuffixTracker_( typeSuffix ) { } *************** *** 190,196 **** const TypePartPtr &typeSuffix, const ExpressionPtr &initializer ) ! : type_( type ) ! , name_( name ) ! , typeSuffix_( typeSuffix ) , initializer_( initializer ) { --- 233,239 ---- const TypePartPtr &typeSuffix, const ExpressionPtr &initializer ) ! : typeTracker_( type ) ! , nameTracker_( name ) ! , typeSuffixTracker_( typeSuffix ) , initializer_( initializer ) { *************** *** 206,210 **** Declarator::getType() const { ! return type_; } --- 249,253 ---- Declarator::getType() const { ! return typeTracker_.getElement(); } *************** *** 213,217 **** Declarator::setType( const TypePartPtr &type ) { ! type_ = type; } --- 256,274 ---- Declarator::setType( const TypePartPtr &type ) { ! typeTracker_.setElement( type ); ! } ! ! ! bool ! Declarator::hasType() const ! { ! return typeTracker_.hasElement(); ! } ! ! ! Change ! Declarator::getTypeChange() const ! { ! return typeTracker_.getChange(); } *************** *** 220,224 **** Declarator::getTypeSuffix() const { ! return typeSuffix_; } --- 277,281 ---- Declarator::getTypeSuffix() const { ! return typeSuffixTracker_.getElement(); } *************** *** 227,231 **** Declarator::setTypeSuffix( const TypePartPtr &typeSuffix ) { ! typeSuffix_ = typeSuffix; } --- 284,302 ---- Declarator::setTypeSuffix( const TypePartPtr &typeSuffix ) { ! typeSuffixTracker_.setElement( typeSuffix ); ! } ! ! ! bool ! Declarator::hasTypeSuffix() const ! { ! return typeSuffixTracker_.hasElement(); ! } ! ! ! Change ! Declarator::getTypeSuffixChange() const ! { ! return typeSuffixTracker_.getChange(); } *************** *** 234,238 **** Declarator::getName() const { ! return name_; } --- 305,309 ---- Declarator::getName() const { ! return nameTracker_.getElement(); } *************** *** 241,245 **** Declarator::setName( const IdentifierPtr &name ) { ! name_ = name; } --- 312,323 ---- Declarator::setName( const IdentifierPtr &name ) { ! nameTracker_.setElement( name ); ! } ! ! ! Change ! Declarator::getNameChange() const ! { ! return nameTracker_.getChange(); } *************** *** 263,266 **** --- 341,353 ---- { initializer_ = initializer; + } + + + void + Declarator::setElementIsFromSource() + { + typeTracker_.setElementIsFromSource(); + nameTracker_.setElementIsFromSource(); + typeSuffixTracker_.setElementIsFromSource(); } Index: CodeModelGeneratorTest.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeModelGeneratorTest.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** CodeModelGeneratorTest.cpp 6 Apr 2003 18:06:59 -0000 1.6 --- CodeModelGeneratorTest.cpp 10 Apr 2003 08:37:50 -0000 1.7 *************** *** 55,60 **** CodeModel::DeclaratorPtr declarator = declExpression->getDeclaratorAt(0); ! RFTA_ASSERT_EQUAL( "", declarator->getType()->getTypeText() ); ! RFTA_ASSERT_EQUAL( "", declarator->getTypeSuffix()->getTypeText() ); RFTA_ASSERT_EQUAL( "x", declarator->getName()->getIdentifier() ); CPPUNIT_ASSERT( declarator->hasInitializer() ); --- 55,60 ---- CodeModel::DeclaratorPtr declarator = declExpression->getDeclaratorAt(0); ! CPPUNIT_ASSERT( !declarator->hasType() ); ! CPPUNIT_ASSERT( !declarator->hasTypeSuffix() ); RFTA_ASSERT_EQUAL( "x", declarator->getName()->getIdentifier() ); CPPUNIT_ASSERT( declarator->hasInitializer() ); Index: CodeModelStatements.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeModelStatements.cpp,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** CodeModelStatements.cpp 5 Apr 2003 18:29:01 -0000 1.17 --- CodeModelStatements.cpp 10 Apr 2003 08:37:50 -0000 1.18 *************** *** 30,37 **** CompoundStatement::removeStatementAt( int index ) { ! StatementChange &change = statements_.at( getActualIndex( index ) ); ! change.type_ = Change::removed; ! change.oldRange_ = change.statement_->getSourceRange(); ! change.statement_.reset(); } --- 30,34 ---- CompoundStatement::removeStatementAt( int index ) { ! statementsTracker_.removeAt( index ); } *************** *** 40,44 **** CompoundStatement::appendStatement( const StatementPtr &statement ) { ! statements_.push_back( StatementChange( Change::added, statement ) ); } --- 37,41 ---- CompoundStatement::appendStatement( const StatementPtr &statement ) { ! statementsTracker_.append( statement ); } *************** *** 48,53 **** const StatementPtr &statement ) { ! statements_.insert( statements_.begin() + getActualIndex(index), ! StatementChange( Change::added, statement ) ); } --- 45,49 ---- const StatementPtr &statement ) { ! statementsTracker_.insertAt( index, statement ); } *************** *** 57,64 **** const StatementPtr &statement ) { ! StatementChange &change = statements_.at( getActualIndex( index ) ); ! change.type_ = Change::replaced; ! change.oldRange_ = change.statement_->getSourceRange(); ! change.statement_ = statement; } --- 53,57 ---- const StatementPtr &statement ) { ! statementsTracker_.setAt( index, statement ); } *************** *** 67,78 **** CompoundStatement::getStatementCount() const { ! int count = 0; ! for ( Statements::const_iterator it = statements_.begin(); it != statements_.end(); ++it ) ! { ! if ( it->type_ != Change::removed ) ! ++count; ! } ! ! return count; } --- 60,64 ---- CompoundStatement::getStatementCount() const { ! return statementsTracker_.getElementCount(); } *************** *** 81,102 **** CompoundStatement::getStatementAt( int index ) const { ! return statements_.at( getActualIndex(index ) ).statement_; ! } ! ! ! int ! CompoundStatement::getActualIndex( int index ) const ! { ! int count = 0; ! for ( Statements::const_iterator it = statements_.begin(); it != statements_.end(); ++it ) ! { ! if ( it->type_ != Change::removed && count++ == index ) ! return it - statements_.begin(); ! } ! ! throw std::out_of_range( "index out of range for CompoundStatement::getActualIndex()" ); } - void CompoundStatement::accept( StatementVisitor &visitor ) --- 67,73 ---- CompoundStatement::getStatementAt( int index ) const { ! return statementsTracker_.getAt( index ); } void CompoundStatement::accept( StatementVisitor &visitor ) *************** *** 109,114 **** CompoundStatement::setElementIsFromSource() { ! for ( Statements::iterator it = statements_.begin(); it != statements_.end(); ++it ) ! it->type_ = Change::unmodified; } --- 80,84 ---- CompoundStatement::setElementIsFromSource() { ! statementsTracker_.setElementIsFromSource(); } *************** *** 117,128 **** CompoundStatement::getChangeCount() const { ! return statements_.size(); } ! CompoundStatement::StatementChange CompoundStatement::getChangeAt( int changeIndex ) const { ! return statements_.at( changeIndex ); } --- 87,105 ---- CompoundStatement::getChangeCount() const { ! return statementsTracker_.getChangeCount(); } ! Change CompoundStatement::getChangeAt( int changeIndex ) const { ! return statementsTracker_.getChangeAt( changeIndex ); ! } ! ! ! StatementPtr ! CompoundStatement::getChangeStatementAt( int changeIndex ) const ! { ! return statementsTracker_.getChangeElementAt( changeIndex ); } Index: CodeRewriter.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeRewriter.cpp,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** CodeRewriter.cpp 8 Apr 2003 08:06:36 -0000 1.38 --- CodeRewriter.cpp 10 Apr 2003 08:37:50 -0000 1.39 *************** *** 204,207 **** --- 204,210 ---- if ( isInserting() && deletionType == bracedExpressionDelete ) insertText( " " ); + + if ( isUpdating() && change.isUnmodified() ) + setCurrentInsertionPos( change.oldRange_.getEndIndex() ); } *************** *** 289,308 **** for ( int index =0; index < statement->getChangeCount(); ++index ) { ! CompoundStatement::StatementChange change = statement->getChangeAt( index ); ! if ( change.type_ == Change::removed ) { deleteText( change.oldRange_ ); ! continue; } currentInsertionPos_ = nextStatementInsertionPos; ! if ( change.type_ == Change::unmodified ) ! nextStatementInsertionPos = change.statement_->getSourceRange().getEndIndex(); ! else if ( change.type_ == Change::replaced ) ! deleteText( change.statement_->getSourceRange() ); ! ModeModifier mode( mode_, change.type_ == Change::unmodified ? updating : inserting ); ! change.statement_->accept( *this ); } --- 292,313 ---- for ( int index =0; index < statement->getChangeCount(); ++index ) { ! Change change = statement->getChangeAt( index ); ! ! if ( change.wasRemoved() || change.wasReplaced() ) { deleteText( change.oldRange_ ); ! ! if ( change.wasRemoved() ) ! continue; } currentInsertionPos_ = nextStatementInsertionPos; ! StatementPtr subStatement = statement->getChangeStatementAt( index ); ! if ( change.isUnmodified() ) ! nextStatementInsertionPos = subStatement->getSourceRange().getEndIndex(); ! ModeModifier mode( mode_, change.isUnmodified() ? updating : inserting ); ! subStatement->accept( *this ); } *************** *** 634,653 **** CodeRewriter::visit( const DeclaratorExpressionPtr &expression ) { ! if ( expression->getDeclaratorCount() == 0 ) ! return; ! beginInsertNewStatement(); ! insertText( expression->getPrimaryType()->getTypeText() ); ! for ( int index =0; index < expression->getDeclaratorCount(); ++index ) { ! if ( index > 0 ) insertText( ", " ); ! DeclaratorPtr declarator = expression->getDeclaratorAt(index); processDeclarator( declarator ); } ! endInsertNewStatement(); } --- 639,662 ---- CodeRewriter::visit( const DeclaratorExpressionPtr &expression ) { ! if ( isInserting() ) ! beginInsertNewStatement(); ! handleMandatoryChange( expression->getPrimaryTypeChange(), ! *expression->getPrimaryType() ); ! for ( int index =0; index < expression->getChangeCount(); ++index ) { ! Change change = expression->getChangeAt( index ); ! DeclaratorPtr declarator = expression->getChangeDeclaratorAt( index ); ! ! if ( index > 0 ) insertText( ", " ); ! ModeModifier mode( mode_, change.isUnmodified() ? updating : inserting ); processDeclarator( declarator ); } ! if ( isInserting() ) ! endInsertNewStatement(); } *************** *** 656,662 **** CodeRewriter::processDeclarator( const DeclaratorPtr &declarator ) { ! insertText( declarator->getType()->getTypeText() ); ! insertText( declarator->getName()->getIdentifier() ); ! insertText( declarator->getTypeSuffix()->getTypeText() ); } --- 665,678 ---- CodeRewriter::processDeclarator( const DeclaratorPtr &declarator ) { ! handleOptionalChange( declarator->getTypeChange(), ! declarator->getType(), ! "", ! currentInsertionPos_ ); ! handleMandatoryChange( declarator->getNameChange(), ! *declarator->getName() ); ! handleOptionalChange( declarator->getTypeSuffixChange(), ! declarator->getTypeSuffix(), ! "", ! currentInsertionPos_ ); } *************** *** 690,693 **** --- 706,725 ---- CodeRewriter::visit( const NullExpressionPtr &expression ) { + } + + + void + CodeRewriter::visit( const TypePartPtr &element ) + { + if ( isInserting() ) + insertText( element->getTypeText() ); + } + + + void + CodeRewriter::visit( const IdentifierPtr &element ) + { + if ( isInserting() ) + insertText( element->getIdentifier() ); } Index: CodeRewriter.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeRewriter.h,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** CodeRewriter.h 8 Apr 2003 08:06:37 -0000 1.16 --- CodeRewriter.h 10 Apr 2003 08:37:50 -0000 1.17 *************** *** 61,64 **** --- 61,68 ---- void visit( const NullExpressionPtr &expression ); + // overridden from ElementVisitor + void visit( const TypePartPtr &element ); + void visit( const IdentifierPtr &element ); + private: enum Mode Index: CodeWriterTest.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeWriterTest.cpp,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** CodeWriterTest.cpp 6 Apr 2003 15:11:23 -0000 1.33 --- CodeWriterTest.cpp 10 Apr 2003 08:37:51 -0000 1.34 *************** *** 519,522 **** --- 519,542 ---- + void + CodeWriterTest::testModifyDeclarationExpresion() + { + source_ = "{\n" + " int x;\n" + "}"; + generateCompound(); + + CodeModel::DeclarationStatement &declarationStatement = + dynamic_cast<CodeModel::DeclarationStatement &>( *compound_->getStatementAt(0) ); + CodeModel::DeclaratorPtr declarator( new CodeModel::Declarator( makeTypePart(""), + makeIdentifier("y"), + makeTypePart("") ) ); + declarationStatement.getDeclaration()->appendDeclarator( declarator ); + generateAndCheckSource( "{\n" + " int x, y;\n" + "}" ); + } + + } // namespace Refactoring Index: CodeWriterTest.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeWriterTest.h,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** CodeWriterTest.h 18 Mar 2003 22:37:49 -0000 1.27 --- CodeWriterTest.h 10 Apr 2003 08:37:51 -0000 1.28 *************** *** 40,43 **** --- 40,44 ---- CPPUNIT_TEST( testModifyForIterationExpression ); CPPUNIT_TEST( testModifyForIteratedStatement ); + CPPUNIT_TEST( testModifyDeclarationExpresion ); CPPUNIT_TEST_SUITE_END(); *************** *** 84,87 **** --- 85,90 ---- void testModifyForIterationExpression(); void testModifyForIteratedStatement(); + + void testModifyDeclarationExpresion(); private: Index: rfta.dsp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/rfta.dsp,v retrieving revision 1.42 retrieving revision 1.43 diff -C2 -d -r1.42 -r1.43 *** rfta.dsp 1 Apr 2003 18:22:57 -0000 1.42 --- rfta.dsp 10 Apr 2003 08:37:51 -0000 1.43 *************** *** 311,314 **** --- 311,318 ---- # Begin Source File + SOURCE=..\..\include\rfta\refactoring\ChangeTrackers.h + # End Source File + # Begin Source File + SOURCE=.\CodeModel.cpp # End Source File |