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: <net...@us...> - 2002-12-30 10:41:24
|
Update of /cvsroot/cpptool/rfta/src/rftavc6addin/res In directory sc8-pr-cvs1:/tmp/cvs-serv29707/src/rftavc6addin/res Modified Files: TBarMedm.bmp Log Message: -- redesign icons, added icons for new fcts Index: TBarMedm.bmp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftavc6addin/res/TBarMedm.bmp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 Binary files /tmp/cvsYEQPnV and /tmp/cvsY9J3yG differ |
|
From: <net...@us...> - 2002-12-30 10:41:11
|
Update of /cvsroot/cpptool/rfta/src/rftavc6addin/res In directory sc8-pr-cvs1:/tmp/cvs-serv29661/src/rftavc6addin/res Added Files: toolbar_.bmp toolbar1.bmp Log Message: -- redesign icons, added icons for new fcts --- NEW FILE: toolbar_.bmp --- (This appears to be a binary file; contents omitted.) --- NEW FILE: toolbar1.bmp --- (This appears to be a binary file; contents omitted.) |
|
From: <net...@us...> - 2002-12-30 10:40:04
|
Update of /cvsroot/cpptool/rfta/src/rfta In directory sc8-pr-cvs1:/tmp/cvs-serv29339 Removed Files: InlineTempRefactoring.h Log Message: has been moved to include\rfta --- InlineTempRefactoring.h DELETED --- |
|
From: <net...@us...> - 2002-12-28 10:52:53
|
Update of /cvsroot/cpptool/rfta/src/rftaparser
In directory sc8-pr-cvs1:/tmp/cvs-serv31963/src/rftaparser
Modified Files:
ExpressionOperationMutatorTest.cpp
Log Message:
-- deactivated expression list test
Index: ExpressionOperationMutatorTest.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftaparser/ExpressionOperationMutatorTest.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** ExpressionOperationMutatorTest.cpp 28 Dec 2002 10:37:57 -0000 1.1
--- ExpressionOperationMutatorTest.cpp 28 Dec 2002 10:52:50 -0000 1.2
***************
*** 92,95 ****
--- 92,98 ----
SourceASTNodePtr sourceAST = Testing::createAST("a=10,i=2",CPPUNIT_SOURCELINE() );
+ /*
+ deactiated because expression-list-parsing is not implemented.
+
ASTNodePtr expr = sourceAST->getChildAt(0);
if (!expr->hasProperty(ASTNodeProperties::expressionTypeProperty))
***************
*** 113,116 ****
--- 116,120 ----
5,
3 );
+ */
}
|
|
From: <net...@us...> - 2002-12-28 10:52:18
|
Update of /cvsroot/cpptool/rfta/src/rfta
In directory sc8-pr-cvs1:/tmp/cvs-serv31478/src/rfta
Modified Files:
InlineTempRefactoring.cpp
Log Message:
-- removed debug code
Index: InlineTempRefactoring.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/InlineTempRefactoring.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** InlineTempRefactoring.cpp 28 Dec 2002 10:44:39 -0000 1.1
--- InlineTempRefactoring.cpp 28 Dec 2002 10:52:15 -0000 1.2
***************
*** 147,154 ****
if (!parentExpr->hasProperty(ASTNodeProperties::expressionTypeProperty))
{
! // call mutator on this expression:
! SourceASTNodePtr sourceNode = boost::make_shared(parentExpr->getSourceNode());
! ParseContext context( sourceNode );
! ExpressionOperationMutator mutator( context, parentExpr, sourceNode );
mutator.mutate();
// check if no expression type was added:
--- 147,153 ----
if (!parentExpr->hasProperty(ASTNodeProperties::expressionTypeProperty))
{
! // call mutator on this expression:
! ParseContext context( sourceNode_ );
! ExpressionOperationMutator mutator( context, parentExpr, sourceNode_ );
mutator.mutate();
// check if no expression type was added:
|
|
From: <net...@us...> - 2002-12-28 10:45:59
|
Update of /cvsroot/cpptool/rfta/src/rftaparser
In directory sc8-pr-cvs1:/tmp/cvs-serv26256/src/rftaparser
Modified Files:
ASTNodes.cpp
Log Message:
-- new nodetypes and properties for extended expression
Index: ASTNodes.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftaparser/ASTNodes.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** ASTNodes.cpp 20 Dec 2002 19:37:54 -0000 1.12
--- ASTNodes.cpp 28 Dec 2002 10:45:57 -0000 1.13
***************
*** 50,53 ****
--- 50,55 ----
const ASTNodeType ASTNodeTypes::variableIdentifier( "variable-identifier", isLocalScopeIdentifier );
const ASTNodeType ASTNodeTypes::localScopeIdentifier( "local-scope-identifier", isLocalScopeIdentifier );
+ const ASTNodeType ASTNodeTypes::assignmentExpression( "assignment-expression-marker");
+ const ASTNodeType ASTNodeTypes::expressionList( "expression-list-marker" );
***************
*** 74,77 ****
--- 76,81 ----
const ASTNodeProperty ASTNodeProperties::conditionProperty( "condition-property" );
const ASTNodeProperty ASTNodeProperties::nextStepProperty( "next-step-property" );
+
+ const ASTNodeProperty ASTNodeProperties::expressionTypeProperty ( "expression-type-property" );
} // namespace Refactoring
|
|
From: <net...@us...> - 2002-12-28 10:45:59
|
Update of /cvsroot/cpptool/rfta/include/rfta/parser
In directory sc8-pr-cvs1:/tmp/cvs-serv26256/include/rfta/parser
Modified Files:
ASTNodes.h
Log Message:
-- new nodetypes and properties for extended expression
Index: ASTNodes.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/include/rfta/parser/ASTNodes.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** ASTNodes.h 20 Dec 2002 19:38:03 -0000 1.10
--- ASTNodes.h 28 Dec 2002 10:45:57 -0000 1.11
***************
*** 104,107 ****
--- 104,111 ----
static const ASTNodeType localScopeIdentifier;
+ // expression node types:
+ static const ASTNodeType assignmentExpression;
+ static const ASTNodeType expressionList;
+
};
***************
*** 160,163 ****
--- 164,170 ----
static const ASTNodeProperty conditionProperty;
static const ASTNodeProperty nextStepProperty;
+
+ // expression type property:
+ static const ASTNodeProperty expressionTypeProperty;
};
|
|
From: <net...@us...> - 2002-12-28 10:44:43
|
Update of /cvsroot/cpptool/rfta/src/rfta
In directory sc8-pr-cvs1:/tmp/cvs-serv25280/src/rfta
Added Files:
InlineTempRefactoringTest.h InlineTempRefactoringTest.cpp
InlineTempRefactoring.h InlineTempRefactoring.cpp
Log Message:
-- inlinetemprefactoring implementation & test
--- NEW FILE: InlineTempRefactoringTest.h ---
// //////////////////////////////////////////////////////////////////////////
// (c)Copyright 2002, Baptiste Lepilleur.
// Created: 2002/12/25
// //////////////////////////////////////////////////////////////////////////
#ifndef RFTA_INLINETEMPREFACTORINGTEST_H
#define RFTA_INLINETEMPREFACTORINGTEST_H
#include "SourceBasedTestBase.h"
#include <rfta/refactoring/RefactoringError.h>
namespace Refactoring
{
class PlainTextDocument;
/// Unit tests for InlineTempRefactoringTest
class InlineTempRefactoringTest : public SourceBasedTestBase
{
CPPUNIT_TEST_SUITE( InlineTempRefactoringTest );
CPPUNIT_TEST( testEasiestCase );
CPPUNIT_TEST( testThrowNoInitializer );
CPPUNIT_TEST( testThrowInitializerNotSupported );
CPPUNIT_TEST( testThrowVariableAssigned );
CPPUNIT_TEST( testDetectComplexVariableAssignments );
CPPUNIT_TEST( testMultipleDeclarationInitLast );
CPPUNIT_TEST( testMultipleDeclarationInitFirst );
CPPUNIT_TEST( testMultipleDeclarationInitMiddle );
CPPUNIT_TEST( testInitExpression );
CPPUNIT_TEST_SUITE_END();
public:
/*! Constructs a InlineTempRefactoringTest object.
*/
InlineTempRefactoringTest();
/// Destructor.
virtual ~InlineTempRefactoringTest();
void setUp();
void tearDown();
void testEasiestCase();
void testThrowNoInitializer();
void testThrowInitializerNotSupported();
void testThrowVariableAssigned();
void testDetectComplexVariableAssignments();
void testMultipleDeclarationInitLast();
void testMultipleDeclarationInitFirst();
void testMultipleDeclarationInitMiddle();
void testInitExpression();
private:
/// Prevents the use of the copy constructor.
InlineTempRefactoringTest( const InlineTempRefactoringTest &other );
/// Prevents the use of the copy operator.
void operator =( const InlineTempRefactoringTest &other );
private:
void applyRefactoring( const std::string &LocaleVariableName );
void applyRefactoringExpectThrow( const std::string &LocaleVariableName , RefactoringError::Cause _cause ,const CppUnit::SourceLine &sourceLine );
void applyRefactoringExpectThrow( const std::string &assigment , const std::string &LocaleVariableName , RefactoringError::Cause _cause ,const CppUnit::SourceLine &sourceLine );
void applyRefactoringNoThrow ( const std::string &assignment , const std::string &LocaleVariableName , const CppUnit::SourceLine &sourceLine );
boost::shared_ptr<PlainTextDocument> document_;
};
// Inlines methods for InlineTempRefactoringTest:
// ----------------------------------------------
} // namespace Refactoring
#endif // RFTA_INLINETEMPREFACTORINGTEST_H
--- NEW FILE: InlineTempRefactoringTest.cpp ---
// //////////////////////////////////////////////////////////////////////////
// (c)Copyright 2002, Baptiste Lepilleur.
// Created: 2002/12/25
// //////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "InlineTempRefactoringTest.h"
#include "InlineTempRefactoring.h"
#include <rfta/refactoring/PlainTextDocument.h>
namespace Refactoring
{
RFTA_TEST_SUITE_REGISTRATION( InlineTempRefactoringTest );
InlineTempRefactoringTest::InlineTempRefactoringTest()
{
}
InlineTempRefactoringTest::~InlineTempRefactoringTest()
{
}
void
InlineTempRefactoringTest::setUp()
{
SourceBasedTestBase::setUp();
}
void
InlineTempRefactoringTest::tearDown()
{
document_.reset();
SourceBasedTestBase::tearDown();
}
/**
* Help function used for applying refactoring algorithm to one example.
*/
void
InlineTempRefactoringTest::applyRefactoring( const std::string &LocaleVariableName )
{
document_.reset( new PlainTextDocument( source_ ) );
int selectionIndex = builder_->getStartIndex( "selection" );
InlineTempRefactoring refactoring( *document_,
selectionIndex );
refactoring.apply( );
CPPUNIT_ASSERT_EQUAL( LocaleVariableName, refactoring.getVariableName() );
}
/**
* Help function to test if refactoring implementation throws the expected exception,
* with the correct 'exception-reason'
*/
void
InlineTempRefactoringTest::applyRefactoringExpectThrow( const std::string &LocaleVariableName ,
RefactoringError::Cause _cause,
const CppUnit::SourceLine &sourceLine )
{
bool failed = true;
RefactoringError expected(_cause);
document_.reset( new PlainTextDocument( source_ ) );
int selectionIndex = builder_->getStartIndex( "selection" );
try {
InlineTempRefactoring refactoring( *document_,
selectionIndex );
refactoring.apply( );
std::string failure = std::string("Test fails since it expects the refactoring error '") + expected.what() + "'.";
CppUnit::Asserter::fail( CppUnit::Message( failure ), sourceLine );
}
catch (RefactoringError& err)
{
// todo@: compare the 'cause'
if ( err.getCause() != expected.getCause() )
{
std::string failure = std::string("Test fails since it throws Exception'")+err.what()+"' instead of expected '" + expected.what() + "'.";
CppUnit::Asserter::fail( CppUnit::Message( failure ), sourceLine );
}
}
}
void
InlineTempRefactoringTest::applyRefactoringExpectThrow( const std::string &assignment , const std::string &LocaleVariableName , RefactoringError::Cause _cause ,const CppUnit::SourceLine &sourceLine )
{
SourceBasedTestBase::setUp();
builder_->add( "{ double y = 2;" );
builder_->addKeyingMid( " double ", LocaleVariableName ,"= 5;", "selection" );
builder_->add( assignment );
builder_->add( "}" );
applyRefactoringExpectThrow( LocaleVariableName , RefactoringError::variableIsAssigned , sourceLine );
SourceBasedTestBase::tearDown();
}
void
InlineTempRefactoringTest::applyRefactoringNoThrow( const std::string &assignment , const std::string &LocaleVariableName , const CppUnit::SourceLine &sourceLine )
{
SourceBasedTestBase::setUp();
builder_->add( "{ double y = 2;" );
builder_->addKeyingMid( " double ", LocaleVariableName ,"= 5;", "selection" );
builder_->add( assignment );
builder_->add( "}" );
try {
applyRefactoring( LocaleVariableName );
}
catch (RefactoringError& err)
{
std::string failure = std::string("Test fails since it throws Exception '")+err.what()+"'. This was not expected.";
CppUnit::Asserter::fail( CppUnit::Message( failure ), sourceLine );
}
SourceBasedTestBase::tearDown();
}
void
InlineTempRefactoringTest::testEasiestCase()
{
builder_->add(
"{"
" double y;" );
builder_->addKeyingMid( " double ", "x"," = 4;", "selection" );
builder_->add( "y += y * x;");
builder_->add(
" return x * getQuantity();"
"}" );
applyRefactoring( "x" );
std::string expectedSource(
"{"
" double y;"
" y += y * 4;"
" return 4 * getQuantity();"
"}" );
std::string actualSource( document_->getAllText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
void
InlineTempRefactoringTest::testThrowNoInitializer()
{
builder_->add(
"{"
" double y;" );
builder_->addKeyingMid( " double ", "x",";", "selection" );
builder_->add( "y += y * x;");
builder_->add(
" return x * getQuantity();"
"}" );
applyRefactoringExpectThrow( "x" , RefactoringError::identifierIsNotInitialized , CPPUNIT_SOURCELINE() );
}
void
InlineTempRefactoringTest::testThrowInitializerNotSupported()
{
builder_->add(
"{"
" double y = 2;" );
builder_->addKeyingMid( " double ", "x","= 5 * y;", "selection" );
builder_->add( "y += y * x;");
builder_->add(
" return x * getQuantity();"
"}" );
applyRefactoringExpectThrow( "x" , RefactoringError::initializerValueNotSupported , CPPUNIT_SOURCELINE() );
}
void
InlineTempRefactoringTest::testThrowVariableAssigned()
{
applyRefactoringExpectThrow( "x = 2;", "x" , RefactoringError::variableIsAssigned , CPPUNIT_SOURCELINE() );
}
void
InlineTempRefactoringTest::testDetectComplexVariableAssignments()
{
applyRefactoringExpectThrow( "*c += x = 1;" , "x" , RefactoringError::variableIsAssigned , CPPUNIT_SOURCELINE() );
applyRefactoringExpectThrow( "if (x=1) ;" , "x" , RefactoringError::variableIsAssigned , CPPUNIT_SOURCELINE() );
applyRefactoringNoThrow ( "if (x==1) ;" , "x" , CPPUNIT_SOURCELINE() );
applyRefactoringExpectThrow( "y=2,x=1;" , "x" , RefactoringError::variableIsAssigned , CPPUNIT_SOURCELINE() );
applyRefactoringNoThrow ( "y=2,x==1;" , "x" , CPPUNIT_SOURCELINE() );
applyRefactoringExpectThrow( "int j = x = 2;", "x" , RefactoringError::variableIsAssigned , CPPUNIT_SOURCELINE() );
// the following will fail because of incomplete expression parser:
/*
applyRefactoringExpectThrow( "*c += ( x += 1 );" , "x" , RefactoringError::variableIsAssigned , CPPUNIT_SOURCELINE() );
applyRefactoringExpectThrow( "fct(x = 1);" , "x" , RefactoringError::variableIsAssigned , CPPUNIT_SOURCELINE() );
applyRefactoringExpectThrow( "x++;" , "x" , RefactoringError::variableIsAssigned , CPPUNIT_SOURCELINE() );
*/
}
void
InlineTempRefactoringTest::testMultipleDeclarationInitLast()
{
builder_->add(
"{"
" double y;" );
builder_->addKeyingMid( " double z , ", "x"," = 4;" , "selection" );
builder_->add( " y += y * x;");
builder_->add(
" return x * getQuantity();"
"}" );
applyRefactoring( "x" );
std::string expectedSource(
"{"
" double y; double z;"
" y += y * 4;"
" return 4 * getQuantity();"
"}" );
std::string actualSource( document_->getAllText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
void
InlineTempRefactoringTest::testMultipleDeclarationInitFirst()
{
builder_->add(
"{"
" double y;" );
builder_->addKeyingMid( " double ", "x"," = 4, z;", "selection" );
builder_->add( " y += y * x;");
builder_->add(
" return x * getQuantity();"
"}" );
applyRefactoring( "x" );
std::string expectedSource(
"{"
" double y; double z;"
" y += y * 4;"
" return 4 * getQuantity();"
"}" );
std::string actualSource( document_->getAllText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
void
InlineTempRefactoringTest::testMultipleDeclarationInitMiddle()
{
builder_->add(
"{"
" double y;" );
builder_->addKeyingMid( " double v , ", "x"," = 4, z;", "selection" );
builder_->add( " y += y * x;");
builder_->add(
" return x * getQuantity();"
"}" );
applyRefactoring( "x" );
std::string expectedSource(
"{"
" double y; double v , z;"
" y += y * 4;"
" return 4 * getQuantity();"
"}" );
std::string actualSource( document_->getAllText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
void
InlineTempRefactoringTest::testInitExpression()
{
builder_->add(
"{"
" double y;" );
builder_->addKeyingMid( " double ", "x"," = 4 + 3;", "selection" );
builder_->add( "y += y * x;");
builder_->add(
" return x * getQuantity();"
"}" );
applyRefactoring( "x" );
std::string expectedSource(
"{"
" double y;"
" y += y * ( 4 + 3 );"
" return ( 4 + 3 ) * getQuantity();"
"}" );
std::string actualSource( document_->getAllText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
} // namespace Refactoring
--- NEW FILE: InlineTempRefactoring.h ---
// //////////////////////////////////////////////////////////////////////////
// (c)Copyright 2002, Andre Baresel
// Created: 2002/12/25
// //////////////////////////////////////////////////////////////////////////
#ifndef RFTA_RFTA_INLINETEMPREFACTORING_H
#define RFTA_RFTA_INLINETEMPREFACTORING_H
#include <rfta/parser/ASTNode.h>
#include <rfta/refactoring/RefactoringBase.h>
#include <rfta/refactoring/ToolsBox.h>
namespace Refactoring
{
/// This class implements the algorithm for InlineTemp refactoring.
class RFTA_API InlineTempRefactoring : public RefactoringBase
{
public:
/**
* constructs on object and prepares the inlining
*/
InlineTempRefactoring(TextDocument &document,int temporaryLocation);
/**
* destroys object data.
*/
virtual ~InlineTempRefactoring();
/**
* function executes the inlining.
*/
void apply( );
/**
* function returns the name of the temporary which is about to be inlined
*/
const std::string getVariableName() const;
/**
* returns the number of occurences of the variable.
*/
int getVariableOccurrenceCount() const;
private:
void prepare(); //< does prepare the inlining (check if it's possible and find the locations for inlining)
void findLocaleVariableOccurrences(); //< find the locations of variable uses
void calculateTempDeclRange(); //< finds the source range of the temporary declaration
bool isInitializerAtomic(); //< does check the initializer for being an atomic value or not
void checkForVariableAssignments();
int temporaryLocation_; //< location where refactoring was asked for
SourceASTNodePtr sourceNode_; //< parsed source of the location
ToolsBox::ASTNodes occurrences_; //< occurences of the temporary variable
ASTNodePtr localeVariableNode_; //< ast node of the identifier at selection
ASTNodePtr temporaryDecl; //< ast node of the declaration of the selected identifier
ASTNodePtr initValue_; //< ast node of the initializer that initializes the selected variable
SourceRange rangeOfTempDeclaration; //< Range of temporary declaration that is inlined (this range can be erased after inlining)
bool tempDeclaredInMiddle; //< true if the temporary is declared between other variables.
};
// Inlines methods for InlineTempRefactoring:
// ------------------------------------------
} // namespace Refactoring
#endif // RFTA_RFTA_INLINETEMPREFACTORING_H
--- NEW FILE: InlineTempRefactoring.cpp ---
// //////////////////////////////////////////////////////////////////////////
// (c)Copyright 2002, Baptiste Lepilleur.
// Created: 2002/12/25
// //////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "InlineTempRefactoring.h"
#include <rfta/refactoring/RefactoringError.h>
#include <rfta/refactoring/TextDocument.h>
#include <rfta/parser/NonSemanticBlanker.h>
#include <rfta/parser/ParseContext.h>
#include <rfta/parser/StatementParser.h>
#include <rfta/parser/MaxLODMutator.h>
#include <rfta/parser/ExpressionOperationMutator.h>
#include <rfta/parser/ASTNodes.h>
#include "IdentifierResolverContext.h"
#include "IdentifierResolver.h"
#include "ReplaceTextTransform.h"
#include "TransformList.h"
namespace Refactoring
{
InlineTempRefactoring::InlineTempRefactoring( TextDocument &document,
int temporaryLocation )
: RefactoringBase( document )
, temporaryLocation_( temporaryLocation )
{
prepare();
}
InlineTempRefactoring::~InlineTempRefactoring()
{
}
/**
* this might not work anymore after inlining has been done.
*/
const std::string
InlineTempRefactoring::getVariableName() const
{
if ( !localeVariableNode_ )
throw RefactoringError( RefactoringError::identifierIsNotLocalVariable );
return localeVariableNode_->getBlankedText();
}
int
InlineTempRefactoring::getVariableOccurrenceCount() const
{
if ( !localeVariableNode_ )
throw RefactoringError( RefactoringError::identifierIsNotLocalVariable );
return occurrences_.size();
}
void
InlineTempRefactoring::prepare()
{
// get the source code:
std::string source( getDocument().getAllText() );
if ( temporaryLocation_ >= source.length() )
throw RefactoringError( RefactoringError::selectionNotInSource );
// blank the source code
NullPPDirectiveListener nullListener;
std::string blankedSource;
NonSemanticBlanker blanker( source, blankedSource, nullListener );
blanker.blank();
// find the compound statement where the temporary is located:
int compoundStartIndex =
ToolsBox::findCompoundBefore( blankedSource, temporaryLocation_ );
if ( compoundStartIndex < 0 )
throw RefactoringError( RefactoringError::temporaryNotInFunctionBody );
// 'lazy' parse the source
sourceNode_ = SourceASTNode::create( blankedSource, source );
ParseContext context( sourceNode_ );
StatementParser parser( context,
sourceNode_->getBlankedSourceStart() +
compoundStartIndex,
sourceNode_->getBlankedSourceEnd() );
parser.parse();
// do mutate to highest level until we know how to do it 'lazy'
MaxLODMutator mutator;
mutator.mutate( sourceNode_, sourceNode_ );
// find all occurrences of the temporary.
findLocaleVariableOccurrences();
// check for initializer property and throw exception if not found
if (!temporaryDecl->hasProperty(ASTNodeProperties::variableInitializerProperty))
throw RefactoringError( RefactoringError::identifierIsNotInitialized );
ASTNodePtr initializerNode_;
initializerNode_ = temporaryDecl->getProperty(ASTNodeProperties::variableInitializerProperty);
// check for value expression:
if (!initializerNode_->hasProperty(ASTNodeProperties::valueProperty))
throw RefactoringError( RefactoringError::initializerValueNotSupported );
initValue_ = initializerNode_->getProperty(ASTNodeProperties::valueProperty);
// @todo: EXTEND THIS BY CHECKING IF local-scope-identifiers can be inlined
int numberOfChilds = initValue_->getChildCount();
if (numberOfChilds > 0)
{
for (int idx = 0; idx < numberOfChilds; idx++ )
{
ASTNodePtr child = initValue_->getChildAt(idx);
if ( child->getType() == ASTNodeTypes::localScopeIdentifier )
throw RefactoringError( RefactoringError::initializerValueNotSupported );
}
}
checkForVariableAssignments();
}
/**
* check all occurences for:
* not being assignments to the identifier
*
* function throws an exception in case of a detected assignment.
*/
void
InlineTempRefactoring::checkForVariableAssignments()
{
for ( ToolsBox::ASTNodes::const_iterator it = occurrences_.begin();
it != occurrences_.end();
++it )
{
if ( *it != localeVariableNode_)
{
// get the expression this variable belongs to:
ASTNodePtr parentExpr = boost::make_shared((*it)->getParentNode());
bool go_deeper = false;
do {
go_deeper = false;
if (!parentExpr->hasProperty(ASTNodeProperties::expressionTypeProperty))
{
// call mutator on this expression:
SourceASTNodePtr sourceNode = boost::make_shared(parentExpr->getSourceNode());
ParseContext context( sourceNode );
ExpressionOperationMutator mutator( context, parentExpr, sourceNode );
mutator.mutate();
// check if no expression type was added:
if (!parentExpr->hasProperty(ASTNodeProperties::expressionTypeProperty))
break;
}
// check if the expression is an assignment:
ASTNodePtr exprType = parentExpr->getProperty(ASTNodeProperties::expressionTypeProperty);
if (exprType->getType() == ASTNodeTypes::assignmentExpression)
{
// find the first child that is <expression>
int idx;
for (idx=0;idx<parentExpr->getChildCount();idx++)
if (parentExpr->getChildAt(idx)->getType()==ASTNodeTypes::expression)
break;
// check if localVariable is on the left hand side:
ASTNodePtr left = parentExpr->getChildAt(idx);
SourceRange varRange = (*it)->getRange();
SourceRange leftRange = left->getRange();
if (leftRange.contains(varRange))
throw RefactoringError( RefactoringError::variableIsAssigned );
else
{
parentExpr = parentExpr->getChildAt(idx+1);
go_deeper = true;
}
}
} while (go_deeper);
}
}
}
void
InlineTempRefactoring::findLocaleVariableOccurrences()
{
SourceRange temporaryRange( temporaryLocation_, 1 );
localeVariableNode_ = ToolsBox::findIdentifierNodeAt( temporaryRange,
sourceNode_ );
if ( !localeVariableNode_ )
throw RefactoringError( RefactoringError::selectionIsNotAnIdentifier );
IdentifierResolverContext context( sourceNode_ );
IdentifierResolver resolver( context );
resolver.visitNode( sourceNode_ );
try
{
temporaryDecl =
context.getLocalVariableIdentifierDeclaration( localeVariableNode_ );
ASTNodePtr compoundNode = sourceNode_->getChildAt(0);
ToolsBox::getLocalVariableOccurrences( compoundNode,
temporaryDecl,
sourceNode_,
context,
occurrences_ );
}
catch ( NotLocalVariableIdentifierError & )
{
throw RefactoringError( RefactoringError::identifierIsNotLocalVariable );
}
}
/**
* function does check if the temporary is declared in its own declaration expression
* or if it's part of a declaration for more than one variable.
*/
void InlineTempRefactoring::calculateTempDeclRange()
{
tempDeclaredInMiddle = false;
// remove the declaration of the temporary:
ASTNodePtr decl_expr = boost::make_shared(temporaryDecl->getParentNode());
int countVarDecl = 0;
for (int j = 0; j < decl_expr->getChildCount(); j++ )
{
if (decl_expr->getChildAt(j)->getType() == ASTNodeTypes::variableDeclExpression )
countVarDecl++;
}
// check number of variables declared in this declaration:
if ( countVarDecl == 1)
// Temp is declared in its own declaration expression, range is the full expression
rangeOfTempDeclaration = decl_expr->getRange();
else
{ // Temp is declared together with other variables, we need to calculate the range
ASTNodePtr tempVarNameNode = temporaryDecl->getProperty(ASTNodeProperties::variableNameProperty);
// find out the declaration just before the temporary is declared:
int tempVarBegin = tempVarNameNode->getRange().getStartIndex();
int tempVarEnd = initValue_->getRange().getEndIndex();
int lastChildEndBefore = 0;
int firstChildStartAfter = decl_expr->getRange().getEndIndex() - 1; // ends just before the semicolon
bool childDeclaredAfterTemp = false;
for (int j = 0; j < decl_expr->getChildCount(); j++ )
{
ASTNodePtr child = decl_expr->getChildAt(j);
if ( temporaryDecl == child ) continue;
ASTNodePtr childNameNode = child->getProperty(ASTNodeProperties::variableNameProperty);
int childEndIndex = child->getRange().getEndIndex();
int childStartIndex = childNameNode->getRange().getStartIndex();
// check if the current child is the last before the temporary:
if ( childEndIndex < tempVarBegin && childEndIndex > lastChildEndBefore )
lastChildEndBefore = childEndIndex;
// check if the current child is declared after the temporary:
if ( childStartIndex > tempVarEnd && firstChildStartAfter > childStartIndex )
{
childDeclaredAfterTemp = true;
firstChildStartAfter = childStartIndex;
}
}
// temp is declared between other in case:
// there're declaration after its declaration && it is not the first
tempDeclaredInMiddle = childDeclaredAfterTemp && ( lastChildEndBefore != 0 );
// check if temporary is declared as first:
if ( lastChildEndBefore==0 )
lastChildEndBefore = tempVarBegin; // in this case delete range beginning at the temp-var-name
// calculate the range:
SourceRange merged ( lastChildEndBefore , firstChildStartAfter - lastChildEndBefore );
rangeOfTempDeclaration = merged;
}
}
bool InlineTempRefactoring::isInitializerAtomic()
{
SourceRange range = initValue_->getRange();
const char * start = &sourceNode_->getBlankedSourceStart()[range.getStartIndex()];
const char * end = &sourceNode_->getBlankedSourceStart()[range.getEndIndex()];
const char * c = start;
while (c != end)
{
switch (*c)
{
case '+': case '-': case '*': case '/': case '%': case '&':
case '|': case ',': case '~': case '^': return false;
}
c++;
}
return true;
}
void
InlineTempRefactoring::apply()
{
TransformList transforms;
calculateTempDeclRange();
if (tempDeclaredInMiddle)
transforms.add( *new ReplaceTextTransform( rangeOfTempDeclaration , " , " ) );
else
transforms.add( *new ReplaceTextTransform( rangeOfTempDeclaration , "" ) );
std::string newtext;
if (isInitializerAtomic())
{
newtext = initValue_->getOriginalText();
while (isspace(newtext[0])) newtext.erase(0,1);
while (isspace(newtext[newtext.length()-1])) newtext.erase(newtext.length()-1,1);
}
else
newtext = std::string("(") + initValue_->getOriginalText() + " )";
for ( ToolsBox::ASTNodes::const_iterator it = occurrences_.begin();
it != occurrences_.end();
++it )
{
if ( *it != localeVariableNode_)
{
SourceRange range = (*it)->getRange();
transforms.add( *new ReplaceTextTransform( range,
newtext ) );
}
}
transforms.apply( getDocument() );
}
} // namespace Refactoring
|
|
From: <net...@us...> - 2002-12-28 10:40:26
|
Update of /cvsroot/cpptool/rfta/src/rfta In directory sc8-pr-cvs1:/tmp/cvs-serv21695/src/rfta Modified Files: rfta.dsp Log Message: -- added inlinetemprefactoring sources Index: rfta.dsp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/rfta.dsp,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** rfta.dsp 23 Dec 2002 22:31:02 -0000 1.31 --- rfta.dsp 28 Dec 2002 10:40:23 -0000 1.32 *************** *** 56,61 **** # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib cppunit_dll.lib /nologo /dll /machine:I386 /out:"..\..\build\rfta\Release/rfta_mdr.ext" /libpath:"../../deplib/cppunit/lib" /libpath:"../../lib" # Begin Special Build Tool ! TargetDir=\prg\vc\Rfta\build\rfta\Release ! TargetPath=\prg\vc\Rfta\build\rfta\Release\rfta_mdr.ext TargetName=rfta_mdr SOURCE="$(InputPath)" --- 56,61 ---- # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib cppunit_dll.lib /nologo /dll /machine:I386 /out:"..\..\build\rfta\Release/rfta_mdr.ext" /libpath:"../../deplib/cppunit/lib" /libpath:"../../lib" # Begin Special Build Tool ! TargetDir=\Projects\Cpptool\rfta\build\rfta\Release ! TargetPath=\Projects\Cpptool\rfta\build\rfta\Release\rfta_mdr.ext TargetName=rfta_mdr SOURCE="$(InputPath)" *************** *** 90,95 **** # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib cppunitd_dll.lib /nologo /dll /debug /machine:I386 /out:"..\..\build\rfta\Debug\rfta_mdd.ext" /pdbtype:sept /libpath:"../../deplib/cppunit/lib" /libpath:"../../lib" # Begin Special Build Tool ! TargetDir=\prg\vc\Rfta\build\rfta\Debug ! TargetPath=\prg\vc\Rfta\build\rfta\Debug\rfta_mdd.ext TargetName=rfta_mdd SOURCE="$(InputPath)" --- 90,95 ---- # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib cppunitd_dll.lib /nologo /dll /debug /machine:I386 /out:"..\..\build\rfta\Debug\rfta_mdd.ext" /pdbtype:sept /libpath:"../../deplib/cppunit/lib" /libpath:"../../lib" # Begin Special Build Tool ! TargetDir=\Projects\Cpptool\rfta\build\rfta\Debug ! TargetPath=\Projects\Cpptool\rfta\build\rfta\Debug\rfta_mdd.ext TargetName=rfta_mdd SOURCE="$(InputPath)" *************** *** 215,218 **** --- 215,226 ---- # Begin Source File + SOURCE=.\InlineTempRefactoring.cpp + # End Source File + # Begin Source File + + SOURCE=.\InlineTempRefactoring.h + # End Source File + # Begin Source File + SOURCE=.\ReduceTempScopeRefactoring.cpp # End Source File *************** *** 680,683 **** --- 688,699 ---- # PROP Default_Filter "" + # Begin Source File + + SOURCE=.\InlineTempRefactoringTest.cpp + # End Source File + # Begin Source File + + SOURCE=.\InlineTempRefactoringTest.h + # End Source File # Begin Source File |
|
From: <net...@us...> - 2002-12-28 10:39:41
|
Update of /cvsroot/cpptool/rfta/src/rfta
In directory sc8-pr-cvs1:/tmp/cvs-serv21068/src/rfta
Modified Files:
RefactoringError.cpp
Log Message:
-- added new exception cause-elements for inline-temp-refactoring
Index: RefactoringError.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/RefactoringError.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** RefactoringError.cpp 19 Dec 2002 20:18:28 -0000 1.3
--- RefactoringError.cpp 28 Dec 2002 10:39:38 -0000 1.4
***************
*** 39,42 ****
--- 39,48 ----
case identifierIsNotLocalVariable:
return "the selected identifier is not a locale variable.";
+ case identifierIsNotInitialized:
+ return "the selected variable is not initialized in declaration.";
+ case initializerValueNotSupported:
+ return "the initializer value of the selected variable is not supported for this operation.";
+ case variableIsAssigned:
+ return "the temporary variable is assigned after initialization.";
}
|
|
From: <net...@us...> - 2002-12-28 10:39:41
|
Update of /cvsroot/cpptool/rfta/include/rfta/refactoring
In directory sc8-pr-cvs1:/tmp/cvs-serv21068/include/rfta/refactoring
Modified Files:
RefactoringError.h
Log Message:
-- added new exception cause-elements for inline-temp-refactoring
Index: RefactoringError.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/include/rfta/refactoring/RefactoringError.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** RefactoringError.h 18 Dec 2002 22:05:40 -0000 1.1
--- RefactoringError.h 28 Dec 2002 10:39:38 -0000 1.2
***************
*** 23,26 ****
--- 23,29 ----
selectionIsNotAnIdentifier,
identifierIsNotLocalVariable,
+ identifierIsNotInitialized, //< exception thrown in InlineTemp
+ initializerValueNotSupported, //< exception thrown in InlineTemp
+ variableIsAssigned //< exception thrown in InlineTemp
};
|
|
From: <net...@us...> - 2002-12-28 10:39:02
|
Update of /cvsroot/cpptool/rfta/src/rftaparser
In directory sc8-pr-cvs1:/tmp/cvs-serv20463/src/rftaparser
Modified Files:
ExpressionMutator.cpp
Log Message:
-- added new tokens for tokenizer
Index: ExpressionMutator.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftaparser/ExpressionMutator.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** ExpressionMutator.cpp 20 Dec 2002 08:30:50 -0000 1.8
--- ExpressionMutator.cpp 28 Dec 2002 10:38:59 -0000 1.9
***************
*** 50,80 ****
const char *tokenStart = current_;
const char *tokenEnd = 0;
! TokenType tokenType = none;
! char c = *current_++;
! if ( c == '.' )
! {
! tokenType = dot;
! }
! else if ( c == '-' && current_ != end_ && *current_ == '>' )
! {
! ++current_;
! tokenType = arrow;
! }
! else if ( c == ':' && current_ != end_ && *current_ == ':' )
! {
! ++current_;
! tokenType = scopeOperator;
! }
! else if ( ParserTools::isValidIdentifierFirstLetter( c ) )
{
while ( current_ != end_ && ParserTools::isIdentifierLetter(*current_) )
++current_;
tokenType = identifier;
! }
! else if ( c == ' ' )
continue;
- else
- tokenType = other;
addToken( tokenStart, current_, tokenType, tokens );
}
--- 50,208 ----
const char *tokenStart = current_;
const char *tokenEnd = 0;
! TokenType tokenType = other;
! char c = *current_++;
!
! if ( ParserTools::isValidIdentifierFirstLetter( c ) )
{
while ( current_ != end_ && ParserTools::isIdentifierLetter(*current_) )
++current_;
tokenType = identifier;
! } else
! switch (c)
! {
! case ' ':
continue;
+ case '.':
+ tokenType = dot;
+ break;
+
+ case '?':
+ tokenType = questMark;
+ break;
+
+ case '-':
+ if (current_ != end_ && *current_ == '>' )
+ {
+ ++current_;
+ tokenType = arrow;
+ } else
+ if (current_ != end_ && *current_ == '=')
+ {
+ ++current_;
+ tokenType = minusAssign;
+ } else
+ tokenType = minus;
+
+
+ break;
+
+ case ',':
+ tokenType = comma;
+ break;
+
+ case '=':
+ if (current_ == end_ || *current_ != '=')
+ tokenType = assign;
+ else
+ if (*current_ == '=')
+ {
+ ++current_;
+ tokenType = equal;
+ }
+ break;
+
+ case '+':
+ if (current_ != end_ && *current_ == '=')
+ {
+ ++current_;
+ tokenType = plusAssign;
+ }
+ break;
+
+ case '%':
+ if (current_ != end_ && *current_ == '=')
+ {
+ ++current_;
+ tokenType = modAssign;
+ }
+ break;
+
+ case '/':
+ if (current_ != end_ && *current_ == '=')
+ {
+ ++current_;
+ tokenType = divAssign;
+ }
+ break;
+
+ case '*':
+ if (current_ != end_ && *current_ == '=')
+ {
+ ++current_;
+ tokenType = mulAssign;
+ }
+ break;
+
+ case '&':
+ if (current_ != end_ && *current_ == '=')
+ {
+ ++current_;
+ tokenType = andAssign;
+ }
+ break;
+
+ case '|':
+ if (current_ != end_ && *current_ == '=')
+ {
+ ++current_;
+ tokenType = orAssign;
+ }
+ break;
+
+ case '^':
+ if (current_ != end_ && *current_ == '=')
+ {
+ ++current_;
+ tokenType = xorAssign;
+ }
+ break;
+
+ case '<':
+ if (current_ != end_ && *current_ == '<')
+ {
+ ++current_;
+ if (current_ == end_ || *current_ != '=')
+ tokenType = leftShift;
+ else
+ {
+ ++current_;
+ tokenType = lshiftAssign;
+ }
+ }
+ break;
+
+ case '>':
+ if (current_ != end_ && *current_ == '>')
+ {
+ ++current_;
+ if (current_ == end_ || *current_ != '=')
+ tokenType = rightShift;
+ else
+ {
+ ++current_;
+ tokenType = rshiftAssign;
+ }
+ }
+ break;
+
+ case '(':
+ tokenType = openBrace;
+ break;
+
+ case ')':
+ tokenType = closeBrace;
+ break;
+
+ case ':':
+ if ( current_ != end_ && *current_ == ':' )
+ {
+ ++current_;
+ tokenType = scopeOperator;
+ }
+ else
+ tokenType = colon;
+ break;
+ }
addToken( tokenStart, current_, tokenType, tokens );
}
***************
*** 127,132 ****
TokenType nextToken )
{
! return token == identifier &&
! ( previousToken == none || previousToken == other ) &&
nextToken != scopeOperator &&
nextToken != identifier;
--- 255,265 ----
TokenType nextToken )
{
! return token == identifier &&
!
! previousToken != arrow &&
! previousToken != colon &&
! previousToken != dot &&
! previousToken != scopeOperator &&
!
nextToken != scopeOperator &&
nextToken != identifier;
***************
*** 151,155 ****
ASTNodePtr variable =
createASTNode( ASTNodeTypes::localScopeIdentifier,
! getParentNode(),
(token.start_ - start_) + getStartIndex(),
token.end_ - token.start_ );
--- 284,288 ----
ASTNodePtr variable =
createASTNode( ASTNodeTypes::localScopeIdentifier,
! node_,
(token.start_ - start_) + getStartIndex(),
token.end_ - token.start_ );
|
|
From: <net...@us...> - 2002-12-28 10:39:01
|
Update of /cvsroot/cpptool/rfta/include/rfta/parser
In directory sc8-pr-cvs1:/tmp/cvs-serv20463/include/rfta/parser
Modified Files:
ExpressionMutator.h
Log Message:
-- added new tokens for tokenizer
Index: ExpressionMutator.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/include/rfta/parser/ExpressionMutator.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** ExpressionMutator.h 16 Nov 2002 11:12:43 -0000 1.2
--- ExpressionMutator.h 28 Dec 2002 10:38:59 -0000 1.3
***************
*** 8,12 ****
#include <rfta/parser/Parser.h>
#include <rfta/parser/SourceASTNode.h>
!
namespace Refactoring
--- 8,12 ----
#include <rfta/parser/Parser.h>
#include <rfta/parser/SourceASTNode.h>
! #include <rfta/parser/ParseContext.h>
namespace Refactoring
***************
*** 37,40 ****
--- 37,60 ----
dot,
identifier,
+ comma,
+ colon,
+ openBrace,
+ closeBrace,
+ minus,
+ assign,
+ plusAssign,
+ minusAssign,
+ modAssign,
+ divAssign,
+ mulAssign,
+ andAssign,
+ lshiftAssign,
+ rshiftAssign,
+ orAssign,
+ xorAssign,
+ leftShift,
+ rightShift,
+ equal,
+ questMark,
other
};
***************
*** 73,76 ****
--- 93,98 ----
ASTNodePtr node_;
+
+ friend class ExpressionOperationMutator;
};
|
|
From: <net...@us...> - 2002-12-28 10:38:00
|
Update of /cvsroot/cpptool/rfta/include/rfta/parser
In directory sc8-pr-cvs1:/tmp/cvs-serv19772/include/rfta/parser
Added Files:
ExpressionOperationMutator.h
Log Message:
-- extended expression parsing with new ExpressionOperationMutator
--- NEW FILE: ExpressionOperationMutator.h ---
// //////////////////////////////////////////////////////////////////////////
// (c)Copyright 2002, Baptiste Lepilleur.
// Created: 2002/12/27
// //////////////////////////////////////////////////////////////////////////
#ifndef RFTA_EXPRESSIONOPERATIONMUTATOR_H
#define RFTA_EXPRESSIONOPERATIONMUTATOR_H
#include <rfta/parser/Mutator.h>
#include <rfta/parser/ExpressionMutator.h>
namespace Refactoring
{
/**
* This class is used to create a subtree of an expression with its
* operation-property in parent node and new child nodes for the operators
*/
class RFTAPARSER_API ExpressionOperationMutator : public ExpressionMutator
{
public:
/*! Constructs a ExpressionOperationMutator object.
*/
ExpressionOperationMutator(ParseContext &context,
const ASTNodePtr &node,
const SourceASTNodePtr &sourceNode);
/// Destructor.
virtual ~ExpressionOperationMutator();
void mutate();
private:
/// Prevents the use of the copy constructor.
ExpressionOperationMutator( const ExpressionOperationMutator &other );
/// Prevents the use of the copy operator.
void operator =( const ExpressionOperationMutator &other );
void splitExpressionList(ExpressionMutator::Tokens token) const;
void splitAssignmentExpression(ExpressionMutator::Tokens token) const;
void splitConditionalExpression(ExpressionMutator::Tokens token) const;
void skipBalancedBraces(ExpressionMutator::Tokens::iterator& it,ExpressionMutator::Tokens& token) const;
SourceASTNodePtr sourceNode_;
private:
};
// Inlines methods for ExpressionOperationMutator:
// -----------------------------------------------
} // namespace Refactoring
#endif // RFTA_EXPRESSIONOPERATIONMUTATOR_H
|
Update of /cvsroot/cpptool/rfta/src/rftaparser
In directory sc8-pr-cvs1:/tmp/cvs-serv19772/src/rftaparser
Modified Files:
rftaparser.dsp
Added Files:
ExpressionOperationMutatorTest.h
ExpressionOperationMutatorTest.cpp
ExpressionOperationMutator.cpp
Log Message:
-- extended expression parsing with new ExpressionOperationMutator
--- NEW FILE: ExpressionOperationMutatorTest.h ---
// //////////////////////////////////////////////////////////////////////////
// (c)Copyright 2002, Baptiste Lepilleur.
// Created: 2002/12/27
// //////////////////////////////////////////////////////////////////////////
#ifndef RFTA_EXPRESSIONOPERATIONMUTATORTEST_H
#define RFTA_EXPRESSIONOPERATIONMUTATORTEST_H
#include "UnitTesting.h"
namespace Refactoring
{
/// Unit tests for ExpressionOperationMutatorTest
class ExpressionOperationMutatorTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( ExpressionOperationMutatorTest );
CPPUNIT_TEST( testSplitToAssignment );
CPPUNIT_TEST( testSplitToExpressionList );
CPPUNIT_TEST_SUITE_END();
public:
/*! Constructs a ExpressionOperationMutatorTest object.
*/
ExpressionOperationMutatorTest();
/// Destructor.
virtual ~ExpressionOperationMutatorTest();
void setUp();
void tearDown();
void testSplitToAssignment();
void testSplitToExpressionList();
private:
/// Prevents the use of the copy constructor.
ExpressionOperationMutatorTest( const ExpressionOperationMutatorTest &other );
/// Prevents the use of the copy operator.
void operator =( const ExpressionOperationMutatorTest &other );
private:
};
// Inlines methods for ExpressionOperationMutatorTest:
// ---------------------------------------------------
} // namespace Refactoring
#endif // RFTA_EXPRESSIONOPERATIONMUTATORTEST_H
--- NEW FILE: ExpressionOperationMutatorTest.cpp ---
// //////////////////////////////////////////////////////////////////////////
// (c)Copyright 2002, Baptiste Lepilleur.
// Created: 2002/12/27
// //////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "ExpressionOperationMutatorTest.h"
#include "ParserTesting.h"
#include <rfta/parser/ASTNode.h>
#include <rfta/parser/ASTNodes.h>
#include <rfta/parser/ParseContext.h>
#include <rfta/parser/SourceASTNode.h>
#include <rfta/parser/ExpressionOperationMutator.h>
namespace Refactoring
{
CPPUNIT_TEST_SUITE_REGISTRATION( ExpressionOperationMutatorTest );
ExpressionOperationMutatorTest::ExpressionOperationMutatorTest()
{
}
ExpressionOperationMutatorTest::~ExpressionOperationMutatorTest()
{
}
void
ExpressionOperationMutatorTest::setUp()
{
}
void
ExpressionOperationMutatorTest::tearDown()
{
}
namespace Testing {
static SourceASTNodePtr createAST( const std::string &expression,
const CppUnit::SourceLine &sourceLine )
{
SourceASTNodePtr sourceNode = SourceASTNode::create( expression, expression );
ParseContext context( sourceNode );
ASTNodePtr expressionNode = ASTNode::create( ASTNodeTypes::unparsedExpressionStatement,
sourceNode,
0, expression.length(),
sourceNode );
sourceNode->addChild( expressionNode );
ExpressionOperationMutator mutator(context,expressionNode, sourceNode);
mutator.mutate();
return sourceNode;
}
}
void
ExpressionOperationMutatorTest::testSplitToAssignment()
{
SourceASTNodePtr sourceAST = Testing::createAST("a=10",CPPUNIT_SOURCELINE() );
ASTNodePtr expr = sourceAST->getChildAt(0);
// check existence of expression-type-property
if (!expr->hasProperty(ASTNodeProperties::expressionTypeProperty))
{
CppUnit::Asserter::fail( CppUnit::Message( "Expected an expression type property." ), CPPUNIT_SOURCELINE() );
return;
}
// check property contents:
ASTNodePtr typeProperty = expr->getProperty(ASTNodeProperties::expressionTypeProperty);
if ( typeProperty->getType() != ASTNodeTypes::assignmentExpression )
{
CppUnit::Asserter::fail( CppUnit::Message( "Expected an assignment expression on top level." ), CPPUNIT_SOURCELINE() );
return;
}
// check left and right side of the expression
ASTNodePtr left = expr->getChildAt(0);
ASTNodePtr right = expr->getChildAt(1);
if (! (left->getRange() == SourceRange(0,1)) )
CPPUNIT_FAIL("Wrong range on left side");
if (! (right->getRange() == SourceRange(2,2)) )
CPPUNIT_FAIL("Wrong range on right side");
}
void
ExpressionOperationMutatorTest::testSplitToExpressionList()
{
SourceASTNodePtr sourceAST = Testing::createAST("a=10,i=2",CPPUNIT_SOURCELINE() );
ASTNodePtr expr = sourceAST->getChildAt(0);
if (!expr->hasProperty(ASTNodeProperties::expressionTypeProperty))
{
CppUnit::Asserter::fail( CppUnit::Message( "Expected an expression type property." ), CPPUNIT_SOURCELINE() );
return;
}
ASTNodePtr typeProperty = expr->getProperty(ASTNodeProperties::expressionTypeProperty);
if ( typeProperty->getType() != ASTNodeTypes::expressionList )
{
CppUnit::Asserter::fail( CppUnit::Message( "Expected an expression list on top level." ), CPPUNIT_SOURCELINE() );
return;
}
// check left and right side of the expression
RFTA_ASSERT_NODE_HAS(expr->getChildAt(0),
ASTNodeTypes::expression,
0,
4 );
RFTA_ASSERT_NODE_HAS(expr->getChildAt(1),
ASTNodeTypes::expression,
5,
3 );
}
} // namespace Refactoring
--- NEW FILE: ExpressionOperationMutator.cpp ---
// //////////////////////////////////////////////////////////////////////////
// (c)Copyright 2002, Andre Baresel.
// Created: 2002/12/27
// //////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include <rfta/parser/ExpressionOperationMutator.h>
#include <rfta/parser/ASTNodes.h>
namespace Refactoring
{
ExpressionOperationMutator::ExpressionOperationMutator( ParseContext &context,
const ASTNodePtr &node,
const SourceASTNodePtr &sourceNode)
: ExpressionMutator( context, node, sourceNode )
, sourceNode_ ( sourceNode )
{
}
ExpressionOperationMutator::~ExpressionOperationMutator()
{
}
void
ExpressionOperationMutator::mutate()
{
ExpressionMutator::Tokens tokens;
parseTokens(tokens);
splitExpressionList(tokens);
}
void ExpressionOperationMutator::skipBalancedBraces(ExpressionMutator::Tokens::iterator& i,
ExpressionMutator::Tokens& token) const
{
int cntOpen=1;
i++;
// skip until balanced close brace:
while (i!=token.end() && cntOpen>0)
{
if ((*i).type_ == ExpressionMutator::openBrace)
{
cntOpen++;i++;
} else if ((*i).type_ == ExpressionMutator::closeBrace)
{
cntOpen--;
} else
i++;
}
}
void ExpressionOperationMutator::splitExpressionList(ExpressionMutator::Tokens token) const
{
bool exprListDetectedBefore = false;
// find first ',' or '('
ExpressionMutator::Tokens::iterator i = token.begin();
while (i!=token.end())
{
if ((*i).type_ == ExpressionMutator::openBrace)
{
skipBalancedBraces(i,token);
}
if ((*i).type_ == ExpressionMutator::comma)
{
// collect a expression-list element:
if (!exprListDetectedBefore)
{
exprListDetectedBefore = true;
// add a property marking this expression as expression-list
int OpStart = (*i).start_ - sourceNode_->getBlankedSourceStart();
ASTNodePtr property = createASTNode(ASTNodeTypes::expressionList,node_,OpStart,1);
node_->setPropertyNode(ASTNodeProperties::expressionTypeProperty,property);
}
}
i++;
}
// check if a comma was found:
if (i!=token.end())
{
// split assignment at this iterator position:
// stop here - further mutation can be done by request.
return;
}
// we didn't found an expression list so check for assignment expression:
splitAssignmentExpression(token);
}
void ExpressionOperationMutator::splitAssignmentExpression(ExpressionMutator::Tokens token) const
{
ExpressionMutator::Tokens::iterator i = token.begin();
while (i!=token.end())
{
if ((*i).type_ == ExpressionMutator::assign ||
(*i).type_ == ExpressionMutator::mulAssign ||
(*i).type_ == ExpressionMutator::divAssign ||
(*i).type_ == ExpressionMutator::modAssign ||
(*i).type_ == ExpressionMutator::plusAssign ||
(*i).type_ == ExpressionMutator::minusAssign ||
(*i).type_ == ExpressionMutator::rshiftAssign ||
(*i).type_ == ExpressionMutator::lshiftAssign ||
(*i).type_ == ExpressionMutator::andAssign ||
(*i).type_ == ExpressionMutator::xorAssign ||
(*i).type_ == ExpressionMutator::orAssign)
break; // expression needs to be splitted here
if ((*i).type_ == ExpressionMutator::questMark)
{
splitConditionalExpression(token);
return;
}
if ((*i).type_ == ExpressionMutator::openBrace)
{
skipBalancedBraces(i,token);
}
i++;
}
// check if an assignment operation was found:
if (i!=token.end())
{
// split assignment at this iterator position:
int exprStart = node_->getRange().getStartIndex();
int exprEnd = node_->getRange().getEndIndex();
int asngOpStart = (*i).start_ - sourceNode_->getBlankedSourceStart();
int asngOpEnd = (*i).end_ - sourceNode_->getBlankedSourceStart();
ASTNodePtr property = createASTNode(ASTNodeTypes::assignmentExpression,node_,asngOpStart,asngOpEnd-asngOpStart);
node_->setPropertyNode(ASTNodeProperties::expressionTypeProperty,property);
ASTNodePtr leftOperand = createASTNode(ASTNodeTypes::expression,node_,exprStart, asngOpStart - exprStart);
ASTNodePtr rightOperand = createASTNode(ASTNodeTypes::expression,node_,asngOpEnd, exprEnd - asngOpEnd);
node_->addChild(leftOperand);
node_->addChild(rightOperand);
return;
}
}
void ExpressionOperationMutator::splitConditionalExpression(ExpressionMutator::Tokens token) const
{
// not yet implemented
return;
}
} // namespace Refactoring
Index: rftaparser.dsp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftaparser/rftaparser.dsp,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** rftaparser.dsp 22 Dec 2002 16:03:53 -0000 1.25
--- rftaparser.dsp 28 Dec 2002 10:37:57 -0000 1.26
***************
*** 56,61 ****
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"..\..\build\rftaparser\Release/rftaparser_mdr.ext" /libpath:"../../deplib/cppunit/lib"
# Begin Special Build Tool
! TargetDir=\prg\vc\Rfta\build\rftaparser\Release
! TargetPath=\prg\vc\Rfta\build\rftaparser\Release\rftaparser_mdr.ext
TargetName=rftaparser_mdr
SOURCE="$(InputPath)"
--- 56,61 ----
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"..\..\build\rftaparser\Release/rftaparser_mdr.ext" /libpath:"../../deplib/cppunit/lib"
# Begin Special Build Tool
! TargetDir=\Projects\Cpptool\rfta\build\rftaparser\Release
! TargetPath=\Projects\Cpptool\rfta\build\rftaparser\Release\rftaparser_mdr.ext
TargetName=rftaparser_mdr
SOURCE="$(InputPath)"
***************
*** 90,95 ****
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib cppunitd_dll.lib /nologo /dll /debug /machine:I386 /out:"..\..\build\rftaparser\Debug/rftaparser_mdd.ext" /pdbtype:sept /libpath:"../../deplib/cppunit/lib"
# Begin Special Build Tool
! TargetDir=\prg\vc\Rfta\build\rftaparser\Debug
! TargetPath=\prg\vc\Rfta\build\rftaparser\Debug\rftaparser_mdd.ext
TargetName=rftaparser_mdd
SOURCE="$(InputPath)"
--- 90,95 ----
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib cppunitd_dll.lib /nologo /dll /debug /machine:I386 /out:"..\..\build\rftaparser\Debug/rftaparser_mdd.ext" /pdbtype:sept /libpath:"../../deplib/cppunit/lib"
# Begin Special Build Tool
! TargetDir=\Projects\Cpptool\rfta\build\rftaparser\Debug
! TargetPath=\Projects\Cpptool\rfta\build\rftaparser\Debug\rftaparser_mdd.ext
TargetName=rftaparser_mdd
SOURCE="$(InputPath)"
***************
*** 322,325 ****
--- 322,333 ----
# Begin Source File
+ SOURCE=.\ExpressionOperationMutator.cpp
+ # End Source File
+ # Begin Source File
+
+ SOURCE=..\..\include\rfta\parser\ExpressionOperationMutator.h
+ # End Source File
+ # Begin Source File
+
SOURCE=.\MaxLODMutator.cpp
# End Source File
***************
*** 555,558 ****
--- 563,574 ----
!ENDIF
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\ExpressionOperationMutatorTest.cpp
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\ExpressionOperationMutatorTest.h
# End Source File
# Begin Source File
|
|
From: <bl...@us...> - 2002-12-25 22:40:54
|
Update of /cvsroot/cpptool/rfta/src/rfta
In directory sc8-pr-cvs1:/tmp/cvs-serv32632/src/rfta
Modified Files:
CodeWriterTest.cpp
Log Message:
* spaces are now allowed around the if condition
Index: CodeWriterTest.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeWriterTest.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** CodeWriterTest.cpp 25 Dec 2002 12:13:56 -0000 1.2
--- CodeWriterTest.cpp 25 Dec 2002 22:40:51 -0000 1.3
***************
*** 61,65 ****
{
source_ = "{"
! " if (true)"
" return;"
"}";
--- 61,65 ----
{
source_ = "{"
! " if ( true )"
" return;"
"}";
***************
*** 80,84 ****
std::string expectedSource = "{"
! " if (false)"
" return;"
"}";
--- 80,84 ----
std::string expectedSource = "{"
! " if ( false )"
" return;"
"}";
|
|
From: <bl...@us...> - 2002-12-25 22:40:24
|
Update of /cvsroot/cpptool/rfta/include/rfta/parser
In directory sc8-pr-cvs1:/tmp/cvs-serv32542/include/rfta/parser
Modified Files:
Parser.h
Log Message:
* if condition node is trimed
Index: Parser.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/include/rfta/parser/Parser.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Parser.h 20 Dec 2002 08:30:51 -0000 1.3
--- Parser.h 25 Dec 2002 22:40:21 -0000 1.4
***************
*** 42,45 ****
--- 42,49 ----
int startIndex,
int length ) const;
+
+ ASTNodePtr createASTNode( const ASTNodeType &type,
+ const ASTNodeWeakPtr &parentNode,
+ const SourceRange &sourceRange ) const;
protected:
***************
*** 96,99 ****
--- 100,109 ----
void throwFailure( const boost::format &format );
+
+ int getIndexOf( const char *pos );
+
+ SourceRange getTrimedRange( const SourceRange &sourceRange );
+ SourceRange getTrimedRangeFromIndexes( int startIndex,
+ int endIndex );
template<typename ParserType>
|
|
From: <bl...@us...> - 2002-12-25 22:40:24
|
Update of /cvsroot/cpptool/rfta/src/rftaparser
In directory sc8-pr-cvs1:/tmp/cvs-serv32542/src/rftaparser
Modified Files:
IfStatementParser.cpp Parser.cpp
Log Message:
* if condition node is trimed
Index: IfStatementParser.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftaparser/IfStatementParser.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** IfStatementParser.cpp 20 Dec 2002 08:30:50 -0000 1.8
--- IfStatementParser.cpp 25 Dec 2002 22:40:21 -0000 1.9
***************
*** 41,45 ****
expect( '(' );
findNextBalanced( '(', ')' );
! int conditionLength = getCurrentIndex() - conditionIndex;
ASTNodePtr statement =
--- 41,45 ----
expect( '(' );
findNextBalanced( '(', ')' );
! int conditionEndIndex = getCurrentIndex();
ASTNodePtr statement =
***************
*** 51,57 ****
ASTNodePtr conditionNode =
createASTNode( ASTNodeTypes::unparsedConditionExpression,
! statement,
! conditionIndex+1,
! conditionLength-2 );
statement->setPropertyNode( ASTNodeProperties::selectionProperty,
--- 51,57 ----
ASTNodePtr conditionNode =
createASTNode( ASTNodeTypes::unparsedConditionExpression,
! statement,
! getTrimedRangeFromIndexes( conditionIndex+1,
! conditionEndIndex-1 ) );
statement->setPropertyNode( ASTNodeProperties::selectionProperty,
Index: Parser.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftaparser/Parser.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Parser.cpp 20 Dec 2002 08:30:51 -0000 1.4
--- Parser.cpp 25 Dec 2002 22:40:21 -0000 1.5
***************
*** 258,266 ****
int length ) const
{
return ASTNode::create( type,
parentNode,
! startIndex,
! length,
context_.getSourceNode() );
}
--- 258,310 ----
int length ) const
{
+ return createASTNode( type,
+ parentNode,
+ SourceRange( startIndex, length ) );
+ }
+
+
+ ASTNodePtr
+ Parser::createASTNode( const ASTNodeType &type,
+ const ASTNodeWeakPtr &parentNode,
+ const SourceRange &sourceRange ) const
+ {
return ASTNode::create( type,
parentNode,
! sourceRange,
context_.getSourceNode() );
+ }
+
+
+ int
+ Parser::getIndexOf( const char *pos )
+ {
+ return pos - context_.getSourceNode()->getBlankedSourceStart();
+ }
+
+
+ SourceRange
+ Parser::getTrimedRange( const SourceRange &sourceRange )
+ {
+ const char *start = context_.getSourceNode()->getBlankedSourceStart()
+ + sourceRange.getStartIndex();
+ const char *last = start + sourceRange.getLength();
+
+ while ( start < last && *start == ' ' )
+ ++start;
+
+ while ( last > start && last[-1] == ' ' )
+ --last;
+
+ int newStartIndex = getIndexOf( start );
+ int newLength = getIndexOf( last ) - newStartIndex;
+ return SourceRange( newStartIndex, newLength );
+ }
+
+
+ SourceRange
+ Parser::getTrimedRangeFromIndexes( int startIndex, int endIndex )
+ {
+ return getTrimedRange( SourceRange( startIndex,
+ endIndex - startIndex ) );
}
|
|
From: <bl...@us...> - 2002-12-25 22:39:49
|
Update of /cvsroot/cpptool/rfta/include/rfta/refactoring
In directory sc8-pr-cvs1:/tmp/cvs-serv32386/include/rfta/refactoring
Modified Files:
LineBasedTextDocument.h
Log Message:
* added tab size attribute
Index: LineBasedTextDocument.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/include/rfta/refactoring/LineBasedTextDocument.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** LineBasedTextDocument.h 22 Dec 2002 16:03:50 -0000 1.5
--- LineBasedTextDocument.h 25 Dec 2002 22:39:46 -0000 1.6
***************
*** 52,56 ****
/*! Constructs a LineBasedTextDocument object.
*/
! LineBasedTextDocument();
/// Destructor.
--- 52,56 ----
/*! Constructs a LineBasedTextDocument object.
*/
! LineBasedTextDocument( int tabSize );
/// Destructor.
***************
*** 100,103 ****
--- 100,105 ----
#endif
std::string content_;
+
+ int tabSize_;
};
|
Update of /cvsroot/cpptool/rfta/src/rfta
In directory sc8-pr-cvs1:/tmp/cvs-serv32386/src/rfta
Modified Files:
LineBasedTextDocument.cpp LineBasedTextDocumentTest.cpp
MockLineBasedTextDocument.cpp MockLineBasedTextDocument.h
Log Message:
* added tab size attribute
Index: LineBasedTextDocument.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/LineBasedTextDocument.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** LineBasedTextDocument.cpp 22 Dec 2002 16:03:52 -0000 1.4
--- LineBasedTextDocument.cpp 25 Dec 2002 22:39:46 -0000 1.5
***************
*** 43,47 ****
! LineBasedTextDocument::LineBasedTextDocument()
{
}
--- 43,48 ----
! LineBasedTextDocument::LineBasedTextDocument( int tabSize )
! : tabSize_( tabSize )
{
}
Index: LineBasedTextDocumentTest.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/LineBasedTextDocumentTest.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** LineBasedTextDocumentTest.cpp 22 Dec 2002 16:03:52 -0000 1.4
--- LineBasedTextDocumentTest.cpp 25 Dec 2002 22:39:46 -0000 1.5
***************
*** 28,32 ****
LineBasedTextDocumentTest::setUp()
{
! document_.reset( new MockLineBasedTextDocument() );
}
--- 28,32 ----
LineBasedTextDocumentTest::setUp()
{
! document_.reset( new MockLineBasedTextDocument( 3 ) );
}
Index: MockLineBasedTextDocument.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/MockLineBasedTextDocument.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** MockLineBasedTextDocument.cpp 6 Nov 2002 20:49:15 -0000 1.1
--- MockLineBasedTextDocument.cpp 25 Dec 2002 22:39:46 -0000 1.2
***************
*** 12,17 ****
! MockLineBasedTextDocument::MockLineBasedTextDocument()
: Mock::Expectations( "MockLineBasedTextDocument" )
{
}
--- 12,18 ----
! MockLineBasedTextDocument::MockLineBasedTextDocument( int tabSize )
: Mock::Expectations( "MockLineBasedTextDocument" )
+ , LineBasedTextDocument( tabSize )
{
}
Index: MockLineBasedTextDocument.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/MockLineBasedTextDocument.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** MockLineBasedTextDocument.h 6 Nov 2002 20:49:15 -0000 1.1
--- MockLineBasedTextDocument.h 25 Dec 2002 22:39:46 -0000 1.2
***************
*** 21,25 ****
/*! Constructs a MockLineBasedTextDocument object.
*/
! MockLineBasedTextDocument();
/// Destructor.
--- 21,25 ----
/*! Constructs a MockLineBasedTextDocument object.
*/
! MockLineBasedTextDocument( int tabSize );
/// Destructor.
|
|
From: <bl...@us...> - 2002-12-25 22:39:05
|
Update of /cvsroot/cpptool/rfta/include/rfta/parser
In directory sc8-pr-cvs1:/tmp/cvs-serv32233/include/rfta/parser
Modified Files:
ASTNode.h
Log Message:
* deprecated old constructo and now using a SourceRange object to specify the node range.
Index: ASTNode.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/include/rfta/parser/ASTNode.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** ASTNode.h 22 Dec 2002 16:03:49 -0000 1.14
--- ASTNode.h 25 Dec 2002 22:39:03 -0000 1.15
***************
*** 34,37 ****
--- 34,43 ----
static ASTNodePtr create( const ASTNodeType &type,
const ASTNodeWeakPtr &parentNode,
+ const SourceRange &sourceRange,
+ const SourceASTNodeWeakPtr &sourceNode );
+
+ // deprecated
+ static ASTNodePtr create( const ASTNodeType &type,
+ const ASTNodeWeakPtr &parentNode,
int startIndex,
int length,
***************
*** 83,88 ****
ASTNode( const ASTNodeType &type,
const ASTNodeWeakPtr &parentNode,
! int startIndex,
! int length );
void setSourceNode( const SourceASTNodeWeakPtr &sourceNode );
--- 89,93 ----
ASTNode( const ASTNodeType &type,
const ASTNodeWeakPtr &parentNode,
! const SourceRange &sourceRange );
void setSourceNode( const SourceASTNodeWeakPtr &sourceNode );
|
|
From: <bl...@us...> - 2002-12-25 22:39:05
|
Update of /cvsroot/cpptool/rfta/src/rftaparser
In directory sc8-pr-cvs1:/tmp/cvs-serv32233/src/rftaparser
Modified Files:
ASTNode.cpp SourceASTNode.cpp
Log Message:
* deprecated old constructo and now using a SourceRange object to specify the node range.
Index: ASTNode.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftaparser/ASTNode.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** ASTNode.cpp 22 Dec 2002 16:03:53 -0000 1.12
--- ASTNode.cpp 25 Dec 2002 22:39:02 -0000 1.13
***************
*** 25,33 ****
ASTNode::create( const ASTNodeType &type,
const ASTNodeWeakPtr &parentNode,
! int startIndex,
! int length,
const SourceASTNodeWeakPtr &sourceNode )
{
! ASTNodePtr node( new ASTNode( type, parentNode, startIndex, length ) );
node->setSourceNode( sourceNode );
--- 25,32 ----
ASTNode::create( const ASTNodeType &type,
const ASTNodeWeakPtr &parentNode,
! const SourceRange &sourceRange,
const SourceASTNodeWeakPtr &sourceNode )
{
! ASTNodePtr node( new ASTNode( type, parentNode, sourceRange ) );
node->setSourceNode( sourceNode );
***************
*** 36,46 ****
ASTNode::ASTNode( const ASTNodeType &type,
const ASTNodeWeakPtr &parentNode,
! int startIndex,
! int length )
: parentNode_( parentNode )
, type_( type )
! , range_( startIndex, length )
{
}
--- 35,58 ----
+ ASTNodePtr
+ ASTNode::create( const ASTNodeType &type,
+ const ASTNodeWeakPtr &parentNode,
+ int startIndex,
+ int length,
+ const SourceASTNodeWeakPtr &sourceNode )
+ {
+ return create( type,
+ parentNode,
+ SourceRange( startIndex, length),
+ sourceNode );
+ }
+
+
ASTNode::ASTNode( const ASTNodeType &type,
const ASTNodeWeakPtr &parentNode,
! const SourceRange &sourceRange )
: parentNode_( parentNode )
, type_( type )
! , range_( sourceRange )
{
}
Index: SourceASTNode.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftaparser/SourceASTNode.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** SourceASTNode.cpp 22 Dec 2002 16:03:53 -0000 1.6
--- SourceASTNode.cpp 25 Dec 2002 22:39:02 -0000 1.7
***************
*** 30,35 ****
: ASTNode( ASTNodeTypes::source,
ASTNodeWeakPtr(),
! 0,
! blankedSource.length() )
, blankedSource_( blankedSource )
, realSource_( realSource )
--- 30,34 ----
: ASTNode( ASTNodeTypes::source,
ASTNodeWeakPtr(),
! SourceRange( 0, blankedSource.length() ) )
, blankedSource_( blankedSource )
, realSource_( realSource )
|
|
From: <bl...@us...> - 2002-12-25 12:38:12
|
Update of /cvsroot/cpptool/rfta/src/rftavc6addin
In directory sc8-pr-cvs1:/tmp/cvs-serv11132/src/rftavc6addin
Modified Files:
TextDocumentHelper.cpp TextDocumentHelper.h
Log Message:
* add getTabSize() to retrieve the tab size setting.
Index: TextDocumentHelper.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftavc6addin/TextDocumentHelper.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** TextDocumentHelper.cpp 18 Dec 2002 22:53:27 -0000 1.1
--- TextDocumentHelper.cpp 25 Dec 2002 12:38:09 -0000 1.2
***************
*** 43,44 ****
--- 43,53 ----
_document->Close( CComVariant(dsSaveChangesNo), &status );
}
+
+
+ int
+ TextDocumentHelper::getTabSize()
+ {
+ long tabSize;
+ _document->get_TabSize( &tabSize );
+ return tabSize;
+ }
Index: TextDocumentHelper.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftavc6addin/TextDocumentHelper.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** TextDocumentHelper.h 18 Dec 2002 22:53:27 -0000 1.1
--- TextDocumentHelper.h 25 Dec 2002 12:38:09 -0000 1.2
***************
*** 28,31 ****
--- 28,33 ----
void discardingClose();
+ int getTabSize();
+
private:
CComPtr<ITextDocument> _document;
|
|
From: <bl...@us...> - 2002-12-25 12:13:59
|
Update of /cvsroot/cpptool/rfta/include/rfta/refactoring
In directory sc8-pr-cvs1:/tmp/cvs-serv6744/include/rfta/refactoring
Modified Files:
CodeModelElement.h CodeModelExpressions.h
Log Message:
* added rewriting for a replaced expression
Index: CodeModelElement.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/include/rfta/refactoring/CodeModelElement.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** CodeModelElement.h 23 Dec 2002 22:31:02 -0000 1.2
--- CodeModelElement.h 25 Dec 2002 12:13:57 -0000 1.3
***************
*** 29,34 ****
--- 29,39 ----
bool hasSourceRange() const;
+ bool wasReplaced() const;
+
+ void replace();
+
private:
SourceRange sourceRange_;
+ bool wasReplaced_;
};
Index: CodeModelExpressions.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/include/rfta/refactoring/CodeModelExpressions.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** CodeModelExpressions.h 22 Dec 2002 15:47:00 -0000 1.3
--- CodeModelExpressions.h 25 Dec 2002 12:13:57 -0000 1.4
***************
*** 29,34 ****
--- 29,42 ----
{
public:
+ GenericExpression( const std::string &value );
+
+ const std::string getValue() const;
+ void setValue( const std::string &value );
+
// overridden from Expression
void accept( ExpressionVisitor &visitor );
+
+ private:
+ std::string value_;
};
|
Update of /cvsroot/cpptool/rfta/src/rfta
In directory sc8-pr-cvs1:/tmp/cvs-serv6744/src/rfta
Modified Files:
CodeModel.cpp CodeModelElement.cpp CodeModelExpressions.cpp
CodeRewriter.cpp CodeRewriter.h CodeWriterTest.cpp
Log Message:
* added rewriting for a replaced expression
Index: CodeModel.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeModel.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** CodeModel.cpp 23 Dec 2002 22:31:02 -0000 1.2
--- CodeModel.cpp 25 Dec 2002 12:13:56 -0000 1.3
***************
*** 305,309 ****
Generator::generateGenericExpression( const ASTNodePtr &expressionNode )
{
! ExpressionPtr expression( new GenericExpression() );
expression->setSourceRange( expressionNode->getRange() );
return expression;
--- 305,310 ----
Generator::generateGenericExpression( const ASTNodePtr &expressionNode )
{
! std::string value = expressionNode->getOriginalText();
! ExpressionPtr expression( new GenericExpression( value ) );
expression->setSourceRange( expressionNode->getRange() );
return expression;
Index: CodeModelElement.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeModelElement.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** CodeModelElement.cpp 23 Dec 2002 22:31:02 -0000 1.2
--- CodeModelElement.cpp 25 Dec 2002 12:13:56 -0000 1.3
***************
*** 13,16 ****
--- 13,17 ----
Element::Element()
+ : wasReplaced_( false )
{
unsetSourceRange();
***************
*** 27,30 ****
--- 28,32 ----
{
sourceRange_ = sourceRange;
+ wasReplaced_ = false;
}
***************
*** 48,51 ****
--- 50,67 ----
{
return sourceRange_.getStartIndex() != -1;
+ }
+
+
+ bool
+ Element::wasReplaced() const
+ {
+ return wasReplaced_;
+ }
+
+
+ void
+ Element::replace()
+ {
+ wasReplaced_ = true;
}
Index: CodeModelExpressions.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeModelExpressions.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** CodeModelExpressions.cpp 22 Dec 2002 11:44:01 -0000 1.2
--- CodeModelExpressions.cpp 25 Dec 2002 12:13:56 -0000 1.3
***************
*** 16,19 ****
--- 16,39 ----
+ GenericExpression::GenericExpression( const std::string &value )
+ : value_( value )
+ {
+ }
+
+
+ const std::string
+ GenericExpression::getValue() const
+ {
+ return value_;
+ }
+
+
+ void
+ GenericExpression::setValue( const std::string &value )
+ {
+ replace();
+ value_ = value;
+ }
+
void
Index: CodeRewriter.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeRewriter.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** CodeRewriter.cpp 22 Dec 2002 15:47:01 -0000 1.1
--- CodeRewriter.cpp 25 Dec 2002 12:13:56 -0000 1.2
***************
*** 6,9 ****
--- 6,13 ----
#include "stdafx.h"
#include "CodeRewriter.h"
+ #include "ReplaceTextTransform.h"
+ #include <rfta/refactoring/TextDocument.h>
+ #include <rfta/refactoring/CodeModelExpressions.h>
+ #include <rfta/refactoring/CodeModelStatements.h>
***************
*** 23,30 ****
void
! CodeRewriter::rewrite( Element &element,
TextDocument &document )
{
! // element.rewrite( *this );
}
--- 27,209 ----
void
! CodeRewriter::rewrite( Statement &statement,
TextDocument &document )
{
! statement.accept( *this );
!
! transforms_.apply( document );
! }
!
!
! void
! CodeRewriter::visit( BreakStatement &statement )
! {
! }
!
!
! void
! CodeRewriter::visit( CaseStatement &statement )
! {
! }
!
!
! void
! CodeRewriter::visit( CompoundStatement &statement )
! {
! for ( int index =0; index < statement.getStatementCount(); ++index )
! statement.getStatementAt( index )->accept( *this );
! }
!
!
! void
! CodeRewriter::visit( ConditionStatement &statement )
! {
! }
!
!
! void
! CodeRewriter::visit( ContinueStatement &statement )
! {
! }
!
!
! void
! CodeRewriter::visit( DefaultStatement &statement )
! {
! }
!
!
! void
! CodeRewriter::visit( DeclarationStatement &statement )
! {
! }
!
!
! void
! CodeRewriter::visit( DoStatement &statement )
! {
! }
!
!
! void
! CodeRewriter::visit( ExpressionStatement &statement )
! {
! }
!
!
! void
! CodeRewriter::visit( FlowControlStatement &statement )
! {
! }
!
!
! void
! CodeRewriter::visit( ForStatement &statement )
! {
! }
!
!
! void
! CodeRewriter::visit( GotoStatement &statement )
! {
! }
!
!
! void
! CodeRewriter::visit( IfStatement &statement )
! {
! statement.getCondition()->accept( *this );
! statement.getThenStatement()->accept( *this );
! if ( statement.hasElseStatement() )
! statement.getElseStatement()->accept( *this );
! }
!
!
! void
! CodeRewriter::visit( IterationStatement &statement )
! {
! }
!
!
! void
! CodeRewriter::visit( LabelStatement &statement )
! {
! }
!
!
! void
! CodeRewriter::visit( NullStatement &statement )
! {
! }
!
!
! void
! CodeRewriter::visit( ReturnStatement &statement )
! {
! }
!
!
! void
! CodeRewriter::visit( SwitchLabelStatement &statement )
! {
! }
!
!
! void
! CodeRewriter::visit( SwitchStatement &statement )
! {
! }
!
!
! void
! CodeRewriter::visit( WhileStatement &statement )
! {
! }
!
!
! void
! CodeRewriter::visit( AssignInitializerExpression &expression )
! {
! }
!
!
! void
! CodeRewriter::visit( ConstructorInitializerExpression &expression )
! {
! }
!
!
! void
! CodeRewriter::visit( DeclaratorExpression &expression )
! {
! }
!
!
! void
! CodeRewriter::visit( DefaultConditionExpression &expression )
! {
! }
!
!
! void
! CodeRewriter::visit( Expression &expression )
! {
! }
!
!
! void
! CodeRewriter::visit( GenericExpression &expression )
! {
! if ( expression.wasReplaced() )
! {
! transforms_.add( *new ReplaceTextTransform( expression.getSourceRange(),
! expression.getValue() ) );
! }
! }
!
!
! void
! CodeRewriter::visit( NullExpression &expression )
! {
}
Index: CodeRewriter.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeRewriter.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** CodeRewriter.h 22 Dec 2002 15:47:01 -0000 1.1
--- CodeRewriter.h 25 Dec 2002 12:13:56 -0000 1.2
***************
*** 6,10 ****
#define RFTA_CODEREWRITER_H
! #include <rfta/refactoring/CodeModelElement.h>
namespace Refactoring {
--- 6,11 ----
#define RFTA_CODEREWRITER_H
! #include <rfta/refactoring/CodeModelVisitor.h>
! #include "TransformList.h"
namespace Refactoring {
***************
*** 16,20 ****
/// Rewrite source to match change made to the model.
! class CodeRewriter
{
public:
--- 17,22 ----
/// Rewrite source to match change made to the model.
! class CodeRewriter : private StatementVisitor
! , private ExpressionVisitor
{
public:
***************
*** 24,31 ****
virtual ~CodeRewriter();
! void rewrite( Element &element,
TextDocument &document );
private:
const std::string originalSource_;
};
--- 26,66 ----
virtual ~CodeRewriter();
! void rewrite( Statement &statement,
TextDocument &document );
private:
+ // overridden from StatementVisitor
+ void visit( BreakStatement &statement );
+ void visit( CaseStatement &statement );
+ void visit( CompoundStatement &statement );
+ void visit( ConditionStatement &statement );
+ void visit( ContinueStatement &statement );
+ void visit( DefaultStatement &statement );
+ void visit( DeclarationStatement &statement );
+ void visit( DoStatement &statement );
+ void visit( ExpressionStatement &statement );
+ void visit( FlowControlStatement &statement );
+ void visit( ForStatement &statement );
+ void visit( GotoStatement &statement );
+ void visit( IfStatement &statement );
+ void visit( IterationStatement &statement );
+ void visit( LabelStatement &statement );
+ void visit( NullStatement &statement );
+ void visit( ReturnStatement &statement );
+ void visit( SwitchLabelStatement &statement );
+ void visit( SwitchStatement &statement );
+ void visit( WhileStatement &statement );
+
+ // overridden from ExpressionVisitor
+ void visit( AssignInitializerExpression &expression );
+ void visit( ConstructorInitializerExpression &expression );
+ void visit( DeclaratorExpression &expression );
+ void visit( DefaultConditionExpression &expression );
+ void visit( Expression &expression );
+ void visit( GenericExpression &expression );
+ void visit( NullExpression &expression );
+
+ private:
+ TransformList transforms_;
const std::string originalSource_;
};
Index: CodeWriterTest.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeWriterTest.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** CodeWriterTest.cpp 22 Dec 2002 15:47:01 -0000 1.1
--- CodeWriterTest.cpp 25 Dec 2002 12:13:56 -0000 1.2
***************
*** 61,65 ****
{
source_ = "{"
! " doStuff();"
"}";
--- 61,66 ----
{
source_ = "{"
! " if (true)"
! " return;"
"}";
***************
*** 68,73 ****
RFTA_ASSERT_EQUAL( 1, compound_->getStatementCount() );
! CodeModel::StatementPtr statement( new CodeModel::NullStatement() );
! compound_->setStatementAt( 0, statement );
CodeModel::CodeRewriter writer( source_ );
--- 69,78 ----
RFTA_ASSERT_EQUAL( 1, compound_->getStatementCount() );
! CodeModel::IfStatement &ifStatement =
! static_cast<CodeModel::IfStatement &>( *compound_->getStatementAt(0) );
! CodeModel::GenericExpression &condition =
! static_cast<CodeModel::GenericExpression &>(
! *ifStatement.getCondition() );
! condition.setValue( "false" );
CodeModel::CodeRewriter writer( source_ );
***************
*** 75,81 ****
std::string expectedSource = "{"
! " ;"
"}";
! // RFTA_ASSERT_EQUAL( expectedSource, document_->getAllText() );
}
--- 80,87 ----
std::string expectedSource = "{"
! " if (false)"
! " return;"
"}";
! RFTA_ASSERT_EQUAL( expectedSource, document_->getAllText() );
}
|