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...> - 2004-01-13 22:28:17
|
Update of /cvsroot/cpptool/rfta/src/rfta
In directory sc8-pr-cvs1:/tmp/cvs-serv10304/rfta
Modified Files:
SplitDeclarationRefactoring.cpp
Log Message:
-- integrated preprocessor (replaced all NonSemanticBlanker)
Index: SplitDeclarationRefactoring.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/SplitDeclarationRefactoring.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** SplitDeclarationRefactoring.cpp 20 Dec 2003 08:59:50 -0000 1.6
--- SplitDeclarationRefactoring.cpp 13 Jan 2004 22:28:13 -0000 1.7
***************
*** 10,16 ****
#include "IdentifierResolverContext.h"
#include "ReplaceTextTransform.h"
- #include "PreProcessTransform.h"
#include <rfta/refactoring/TransformList.h>
- #include <rfta/parser/MacroReplaceRegistration.h>
#include <rfta/parser/MaxLODMutator.h>
#include <rfta/parser/PreProcessor.h>
--- 10,14 ----
***************
*** 22,26 ****
#include <rfta/parser/ASTNodes.h>
#include <rfta/refactoring/RefactoringError.h>
! #include <rfta/refactoring/TextDocument.h>
#include <rfta/refactoring/CodeModelGenerator.h>
#include <rfta/refactoring/CodeModelStatements.h>
--- 20,26 ----
#include <rfta/parser/ASTNodes.h>
#include <rfta/refactoring/RefactoringError.h>
! #include <rfta/parser/TextDocument.h>
! #include <rfta/parser/Source.h>
! #include <rfta/refactoring/TransformList.h>
#include <rfta/refactoring/CodeModelGenerator.h>
#include <rfta/refactoring/CodeModelStatements.h>
***************
*** 34,40 ****
SplitDeclarationRefactoring::
! SplitDeclarationRefactoring( TextDocument &document,
int declarationLocation )
! : RefactoringBase( document )
, declarationLocation_( declarationLocation )
{
--- 34,41 ----
SplitDeclarationRefactoring::
! SplitDeclarationRefactoring( SourcePtr source,
! SourceManager& manager,
int declarationLocation )
! : RefactoringBase( source, manager )
, declarationLocation_( declarationLocation )
{
***************
*** 56,86 ****
// preprocess
! PreProcessor proc( source );
! MacroReplaceRegistration registration;
! std::string blankedSource = proc.process(registration);
! registration.finishUpData();
// correct pointer to location after preprocessing
! declarationLocation_ -= registration.getReplacementDeltaBefore(SourceRange( declarationLocation_, 1 ));
!
! // store macro replacement information
! int idx;
! for (idx=0; idx < registration.getSize(); idx++)
! {
! MacroReplaceRegistration::MacroReplacement entry = registration.getEntry(idx);
! transforms_.add( *new PreProcessTransform( entry.position_, entry.macroText_.size() - entry.replacement_.size() ) );
! }
int compoundStartIndex =
! ToolsBox::findCompoundBefore( blankedSource, declarationLocation_ );
if ( compoundStartIndex < 0 )
throw RefactoringError( RefactoringError::temporaryNotInFunctionBody );
! sourceNode_ = SourceASTNode::create( blankedSource, source );
ParseContext context( sourceNode_ );
StatementParser parser( context,
sourceNode_->getBlankedSourceStart() +
! compoundStartIndex,
sourceNode_->getBlankedSourceEnd() );
parser.parse();
--- 57,80 ----
// preprocess
! PreProcessorContext preproc_context( getSourceManager() );
! PreProcessor proc( getSource(), preproc_context );
!
! proc.setOption(PreProcessor::skipIncludes); // TODO: disable this if preprocessor features can handle all system headers
! blankedSource_ = proc.process();
// correct pointer to location after preprocessing
! declarationLocation_ = getSource()->getRangePreProcessed(SourceRange( declarationLocation_, 1 )).getStartIndex();
int compoundStartIndex =
! ToolsBox::findCompoundBefore( blankedSource_, declarationLocation_ );
if ( compoundStartIndex < 0 )
throw RefactoringError( RefactoringError::temporaryNotInFunctionBody );
! sourceNode_ = SourceASTNode::create( blankedSource_, source, getSource() );
ParseContext context( sourceNode_ );
StatementParser parser( context,
sourceNode_->getBlankedSourceStart() +
! compoundStartIndex,
sourceNode_->getBlankedSourceEnd() );
parser.parse();
***************
*** 151,157 ****
}
! std::string source( getDocument().getAllText());
! CodeModel::CodeRewriter writer(source, 2);
! writer.rewrite(compound, transforms_, getDocument());
}
--- 145,150 ----
}
! CodeModel::CodeRewriter writer(getSource(), 2);
! writer.rewrite(compound);
}
|
Update of /cvsroot/cpptool/rfta/src/rfta
In directory sc8-pr-cvs1:/tmp/cvs-serv10043/rfta
Modified Files:
ReduceTempScopeRefactoringTest.h Transform.h
ReduceTempScopeRefactoringTest.cpp SplitTempRefactoringTest.h
InlineTempRefactoringTest.h ReduceTempScopeRefactoring.cpp
RefactoringBase.cpp SplitDeclarationRefactoringTest.cpp
SplitDeclarationRefactoringTest.h SplitTempRefactoringTest.cpp
CodeWriterTestBase.h InlineTempRefactoringTest.cpp
TransformListTest.h ReplaceTextTransform.cpp
ReplaceTextTransform.h MockTextDocument.h TransformList.cpp
IndentLevelManager.cpp SourceBasedTestBase.h
CodeWriterTestBase.cpp RenameTempRefactoringTest.h
SplitTempRefactoring.cpp InlineTempRefactoring.cpp
IndentLevelManager.h RenameTempRefactoringTest.cpp
RenameTempRefactoring.cpp CodeWriterTest.cpp CodeRewriter.cpp
Log Message:
-- integrated preprocessor (replaced all NonSemanticBlanker)
Index: ReduceTempScopeRefactoringTest.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/ReduceTempScopeRefactoringTest.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** ReduceTempScopeRefactoringTest.h 21 Dec 2002 14:40:41 -0000 1.1
--- ReduceTempScopeRefactoringTest.h 13 Jan 2004 22:27:35 -0000 1.2
***************
*** 7,11 ****
#include "SourceBasedTestBase.h"
!
namespace Refactoring
--- 7,11 ----
#include "SourceBasedTestBase.h"
! #include <rfta/test/SourceManagerMock.h>
namespace Refactoring
***************
*** 37,41 ****
void applyRefactoring();
! boost::shared_ptr<PlainTextDocument> document_;
};
--- 37,42 ----
void applyRefactoring();
! Testing::SourceManagerMock sourceMngMock_;
! SourcePtr sourceDoc_;
};
Index: Transform.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/Transform.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Transform.h 16 Dec 2003 13:47:00 -0000 1.1
--- Transform.h 13 Jan 2004 22:27:35 -0000 1.2
***************
*** 8,11 ****
--- 8,12 ----
#include <rfta/refactoring/Config.h>
+ #include <boost/shared_ptr.hpp>
namespace Refactoring
***************
*** 13,16 ****
--- 14,19 ----
class TextDocument;
+ class Source;
+ typedef boost::shared_ptr<Source> SourcePtr;
***************
*** 31,34 ****
--- 34,42 ----
virtual int apply( TextDocument &document ) const = 0;
+ /**
+ * does the text transformation and returns the delta-length
+ */
+ virtual int apply( SourcePtr pSource ) const = 0;
+
virtual void moveStartIndexBy( int delta ) = 0;
Index: ReduceTempScopeRefactoringTest.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/ReduceTempScopeRefactoringTest.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** ReduceTempScopeRefactoringTest.cpp 22 Dec 2002 15:47:34 -0000 1.2
--- ReduceTempScopeRefactoringTest.cpp 13 Jan 2004 22:27:35 -0000 1.3
***************
*** 6,11 ****
#include "stdafx.h"
#include "ReduceTempScopeRefactoringTest.h"
! #include <rfta/refactoring/PlainTextDocument.h>
#include <rfta/refactoring/ReduceTempScopeRefactoring.h>
--- 6,12 ----
#include "stdafx.h"
#include "ReduceTempScopeRefactoringTest.h"
! #include <rfta/parser/PlainTextDocument.h>
#include <rfta/refactoring/ReduceTempScopeRefactoring.h>
+ #include <rfta/parser/Source.h>
***************
*** 43,49 ****
ReduceTempScopeRefactoringTest::applyRefactoring()
{
! document_.reset( new PlainTextDocument( source_ ) );
int selectionIndex = builder_->getStartIndex( "selection" );
! ReduceTempScopeRefactoring refactoring( *document_,
selectionIndex );
refactoring.apply();
--- 44,51 ----
ReduceTempScopeRefactoringTest::applyRefactoring()
{
! sourceDoc_ = SourcePtr( new Source( TextDocumentPtr(new PlainTextDocument( source_ ) ) ) );
int selectionIndex = builder_->getStartIndex( "selection" );
! ReduceTempScopeRefactoring refactoring( sourceDoc_,
! sourceMngMock_,
selectionIndex );
refactoring.apply();
***************
*** 71,75 ****
" }"
"}";
! std::string actualSource( document_->getAllText() );
// RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
--- 73,77 ----
" }"
"}";
! std::string actualSource( sourceDoc_->getOriginalText() );
// RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
Index: SplitTempRefactoringTest.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/SplitTempRefactoringTest.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** SplitTempRefactoringTest.h 19 Dec 2003 20:14:39 -0000 1.2
--- SplitTempRefactoringTest.h 13 Jan 2004 22:27:35 -0000 1.3
***************
*** 7,11 ****
#include "SourceBasedTestBase.h"
!
namespace Refactoring
--- 7,11 ----
#include "SourceBasedTestBase.h"
! #include <rfta/test/SourceManagerMock.h>
namespace Refactoring
***************
*** 40,44 ****
void applyRefactoring( const std::string &newTemporaryName );
! boost::shared_ptr<PlainTextDocument> document_;
};
--- 40,44 ----
void applyRefactoring( const std::string &newTemporaryName );
! Testing::SourceManagerMock sourceMngMock_;
};
Index: InlineTempRefactoringTest.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/InlineTempRefactoringTest.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** InlineTempRefactoringTest.h 5 Apr 2003 12:13:36 -0000 1.3
--- InlineTempRefactoringTest.h 13 Jan 2004 22:27:35 -0000 1.4
***************
*** 8,11 ****
--- 8,12 ----
#include "SourceBasedTestBase.h"
#include <rfta/refactoring/RefactoringError.h>
+ #include <rfta/test/SourceManagerMock.h>
namespace Refactoring
***************
*** 72,76 ****
void applyRefactoringNoThrow ( const std::string &assignment , const std::string &LocaleVariableName , const CppUnit::SourceLine &sourceLine );
! boost::shared_ptr<PlainTextDocument> document_;
};
--- 73,79 ----
void applyRefactoringNoThrow ( const std::string &assignment , const std::string &LocaleVariableName , const CppUnit::SourceLine &sourceLine );
! //boost::shared_ptr<PlainTextDocument> document_;
! SourcePtr sourceDoc_;
! Testing::SourceManagerMock sourceMngMock_;
};
Index: ReduceTempScopeRefactoring.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/ReduceTempScopeRefactoring.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** ReduceTempScopeRefactoring.cpp 22 Dec 2002 15:47:34 -0000 1.3
--- ReduceTempScopeRefactoring.cpp 13 Jan 2004 22:27:35 -0000 1.4
***************
*** 13,19 ****
ReduceTempScopeRefactoring::ReduceTempScopeRefactoring(
! TextDocument &document,
int localeVariableLocation )
! : RefactoringBase( document )
, localeVariableLocation_( localeVariableLocation )
{
--- 13,20 ----
ReduceTempScopeRefactoring::ReduceTempScopeRefactoring(
! SourcePtr source,
! SourceManager& manager,
int localeVariableLocation )
! : RefactoringBase( source, manager )
, localeVariableLocation_( localeVariableLocation )
{
Index: RefactoringBase.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/RefactoringBase.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** RefactoringBase.cpp 22 Dec 2002 16:03:52 -0000 1.4
--- RefactoringBase.cpp 13 Jan 2004 22:27:35 -0000 1.5
***************
*** 9,18 ****
#include <rfta/refactoring/RefactoringBase.h>
#include <rfta/parser/SourceRange.h>
namespace Refactoring{
! RefactoringBase::RefactoringBase( TextDocument& document )
! : baseDocument_( document )
{
}
--- 9,20 ----
#include <rfta/refactoring/RefactoringBase.h>
#include <rfta/parser/SourceRange.h>
+ #include <rfta/parser/Source.h>
namespace Refactoring{
! RefactoringBase::RefactoringBase( SourcePtr source, SourceManager& manager )
! : source_( source )
! , manager_( manager )
{
}
***************
*** 27,31 ****
RefactoringBase::getDocument()
{
! return baseDocument_;
}
--- 29,33 ----
RefactoringBase::getDocument()
{
! return *(source_->getTextDocument());
}
Index: SplitDeclarationRefactoringTest.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/SplitDeclarationRefactoringTest.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** SplitDeclarationRefactoringTest.cpp 19 Dec 2003 20:14:27 -0000 1.4
--- SplitDeclarationRefactoringTest.cpp 13 Jan 2004 22:27:35 -0000 1.5
***************
*** 7,11 ****
#include "SplitDeclarationRefactoringTest.h"
#include <rfta/refactoring/SplitDeclarationRefactoring.h>
! #include <rfta/refactoring/PlainTextDocument.h>
--- 7,12 ----
#include "SplitDeclarationRefactoringTest.h"
#include <rfta/refactoring/SplitDeclarationRefactoring.h>
! #include <rfta/parser/PlainTextDocument.h>
! #include <rfta/parser/Source.h>
***************
*** 36,40 ****
SplitDeclarationRefactoringTest::tearDown()
{
- document_.reset();
SourceBasedTestBase::tearDown();
}
--- 37,40 ----
***************
*** 44,50 ****
SplitDeclarationRefactoringTest::applyRefactoring( )
{
! document_.reset( new PlainTextDocument( source_ ) );
int selectionIndex = builder_->getStartIndex( "selection" );
! SplitDeclarationRefactoring refactoring( *document_,
selectionIndex );
refactoring.apply( );
--- 44,52 ----
SplitDeclarationRefactoringTest::applyRefactoring( )
{
! sourceDoc_ = SourcePtr( new Source( TextDocumentPtr( new PlainTextDocument( source_ ) ) ) );
!
int selectionIndex = builder_->getStartIndex( "selection" );
! SplitDeclarationRefactoring refactoring( sourceDoc_,
! sourceMngMock_,
selectionIndex );
refactoring.apply( );
***************
*** 65,69 ****
" double y;\n"
"}\n" );
! std::string actualSource( document_->getAllText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
--- 67,71 ----
" double y;\n"
"}\n" );
! std::string actualSource( sourceDoc_->getOriginalText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
***************
*** 83,87 ****
" double &z;\n"
"}\n" );
! std::string actualSource( document_->getAllText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
--- 85,89 ----
" double &z;\n"
"}\n" );
! std::string actualSource( sourceDoc_->getOriginalText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
***************
*** 101,105 ****
" double&z;\n"
"}\n" );
! std::string actualSource( document_->getAllText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
--- 103,107 ----
" double&z;\n"
"}\n" );
! std::string actualSource( sourceDoc_->getOriginalText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
***************
*** 121,125 ****
" bool n, m;\n"
"}\n");
! std::string actualSource( document_->getAllText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
--- 123,127 ----
" bool n, m;\n"
"}\n");
! std::string actualSource( sourceDoc_->getOriginalText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
***************
*** 138,142 ****
" int y(2);\n"
"}\n");
! std::string actualSource( document_->getAllText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
--- 140,144 ----
" int y(2);\n"
"}\n");
! std::string actualSource( sourceDoc_->getOriginalText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
***************
*** 161,165 ****
" }\n"
"}\n");
! std::string actualSource( document_->getAllText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
--- 163,167 ----
" }\n"
"}\n");
! std::string actualSource( sourceDoc_->getOriginalText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
***************
*** 181,185 ****
" ;\n"
"}\n");
! std::string actualSource( document_->getAllText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
--- 183,187 ----
" ;\n"
"}\n");
! std::string actualSource( sourceDoc_->getOriginalText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
***************
*** 202,206 ****
" double y;\n"
"}\n" );
! std::string actualSource( document_->getAllText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
--- 204,208 ----
" double y;\n"
"}\n" );
! std::string actualSource( sourceDoc_->getOriginalText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
Index: SplitDeclarationRefactoringTest.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/SplitDeclarationRefactoringTest.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** SplitDeclarationRefactoringTest.h 19 Dec 2003 20:14:27 -0000 1.4
--- SplitDeclarationRefactoringTest.h 13 Jan 2004 22:27:35 -0000 1.5
***************
*** 7,11 ****
#include "SourceBasedTestBase.h"
!
namespace Refactoring
--- 7,11 ----
#include "SourceBasedTestBase.h"
! #include <rfta/test/SourceManagerMock.h>
namespace Refactoring
***************
*** 52,56 ****
void applyRefactoring( );
! boost::shared_ptr<PlainTextDocument> document_;
};
--- 52,57 ----
void applyRefactoring( );
! Testing::SourceManagerMock sourceMngMock_;
! SourcePtr sourceDoc_;
};
Index: SplitTempRefactoringTest.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/SplitTempRefactoringTest.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** SplitTempRefactoringTest.cpp 19 Dec 2003 20:14:39 -0000 1.4
--- SplitTempRefactoringTest.cpp 13 Jan 2004 22:27:35 -0000 1.5
***************
*** 7,11 ****
#include "SplitTempRefactoringTest.h"
#include <rfta/refactoring/SplitTempRefactoring.h>
! #include <rfta/refactoring/PlainTextDocument.h>
--- 7,12 ----
#include "SplitTempRefactoringTest.h"
#include <rfta/refactoring/SplitTempRefactoring.h>
! #include <rfta/parser/PlainTextDocument.h>
! #include <rfta/parser/Source.h>
***************
*** 35,40 ****
void
SplitTempRefactoringTest::tearDown()
! {
! document_.reset();
SourceBasedTestBase::tearDown();
}
--- 36,40 ----
void
SplitTempRefactoringTest::tearDown()
! {
SourceBasedTestBase::tearDown();
}
***************
*** 44,50 ****
SplitTempRefactoringTest::applyRefactoring( const std::string &newTemporaryName )
{
! document_.reset( new PlainTextDocument( source_ ) );
int selectionIndex = builder_->getStartIndex( "selection" );
! SplitTempRefactoring refactoring( *document_,
selectionIndex );
refactoring.apply( newTemporaryName );
--- 44,52 ----
SplitTempRefactoringTest::applyRefactoring( const std::string &newTemporaryName )
{
! sourceDoc_ = SourcePtr( new Source( TextDocumentPtr( new PlainTextDocument( source_ ) ) ) );
!
int selectionIndex = builder_->getStartIndex( "selection" );
! SplitTempRefactoring refactoring( sourceDoc_,
! sourceMngMock_,
selectionIndex );
refactoring.apply( newTemporaryName );
***************
*** 73,77 ****
" doSomething( x );"
"}" );
! std::string actualSource( document_->getAllText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
--- 75,79 ----
" doSomething( x );"
"}" );
! std::string actualSource( sourceDoc_->getOriginalText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
***************
*** 102,106 ****
" doSomething( x );"
"}" );
! std::string actualSource( document_->getAllText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
--- 104,108 ----
" doSomething( x );"
"}" );
! std::string actualSource( sourceDoc_->getOriginalText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
Index: CodeWriterTestBase.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeWriterTestBase.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** CodeWriterTestBase.h 6 Apr 2003 18:06:59 -0000 1.5
--- CodeWriterTestBase.h 13 Jan 2004 22:27:35 -0000 1.6
***************
*** 8,12 ****
#include <rfta/refactoring/CodeModelStatements.h>
#include <rfta/refactoring/CodeModelExpressions.h>
! #include <rfta/refactoring/PlainTextDocument.h>
#include "CodeRewriter.h"
#include "SourceBasedTestBase.h"
--- 8,12 ----
#include <rfta/refactoring/CodeModelStatements.h>
#include <rfta/refactoring/CodeModelExpressions.h>
! #include <rfta/parser/PlainTextDocument.h>
#include "CodeRewriter.h"
#include "SourceBasedTestBase.h"
***************
*** 42,47 ****
void generateAndCheckSource( const std::string &expectedSource );
! CodeModel::CompoundStatementPtr compound_;
! boost::shared_ptr<PlainTextDocument> document_;
boost::shared_ptr<CodeModel::CodeRewriter> writer_;
};
--- 42,46 ----
void generateAndCheckSource( const std::string &expectedSource );
! CodeModel::CompoundStatementPtr compound_;
boost::shared_ptr<CodeModel::CodeRewriter> writer_;
};
Index: InlineTempRefactoringTest.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/InlineTempRefactoringTest.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** InlineTempRefactoringTest.cpp 6 Apr 2003 16:17:19 -0000 1.5
--- InlineTempRefactoringTest.cpp 13 Jan 2004 22:27:35 -0000 1.6
***************
*** 7,11 ****
#include "InlineTempRefactoringTest.h"
#include <rfta/refactoring/InlineTempRefactoring.h>
! #include <rfta/refactoring/PlainTextDocument.h>
--- 7,12 ----
#include "InlineTempRefactoringTest.h"
#include <rfta/refactoring/InlineTempRefactoring.h>
! #include <rfta/parser/PlainTextDocument.h>
! #include <rfta/parser/Source.h>
***************
*** 36,40 ****
InlineTempRefactoringTest::tearDown()
{
! document_.reset();
SourceBasedTestBase::tearDown();
}
--- 37,41 ----
InlineTempRefactoringTest::tearDown()
{
! sourceDoc_->getTextDocument().reset();
SourceBasedTestBase::tearDown();
}
***************
*** 46,52 ****
InlineTempRefactoringTest::applyRefactoring( const std::string &LocaleVariableName )
{
! document_.reset( new PlainTextDocument( source_ ) );
int selectionIndex = builder_->getStartIndex( "selection" );
! InlineTempRefactoring refactoring( *document_,
selectionIndex );
refactoring.apply( refactoring.areBracesSuggested() );
--- 47,55 ----
InlineTempRefactoringTest::applyRefactoring( const std::string &LocaleVariableName )
{
! TextDocumentPtr document(new PlainTextDocument( source_ ));
! sourceDoc_ = SourcePtr( new Source(document) );
int selectionIndex = builder_->getStartIndex( "selection" );
! InlineTempRefactoring refactoring( sourceDoc_,
! sourceMngMock_,
selectionIndex );
refactoring.apply( refactoring.areBracesSuggested() );
***************
*** 65,72 ****
bool failed = true;
RefactoringError expected(_cause);
! document_.reset( new PlainTextDocument( source_ ) );
int selectionIndex = builder_->getStartIndex( "selection" );
try {
! InlineTempRefactoring refactoring( *document_,
selectionIndex );
refactoring.apply( refactoring.areBracesSuggested() );
--- 68,79 ----
bool failed = true;
RefactoringError expected(_cause);
!
! TextDocumentPtr document(new PlainTextDocument( source_ ));
! sourceDoc_ = SourcePtr( new Source(document) );
!
int selectionIndex = builder_->getStartIndex( "selection" );
try {
! InlineTempRefactoring refactoring( sourceDoc_,
! sourceMngMock_,
selectionIndex );
refactoring.apply( refactoring.areBracesSuggested() );
***************
*** 137,141 ****
" return 4 * getQuantity();"
"}" );
! std::string actualSource( document_->getAllText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
--- 144,148 ----
" return 4 * getQuantity();"
"}" );
! std::string actualSource( sourceDoc_->getOriginalText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
***************
*** 160,164 ****
" return 4 * getQuantity();"
"}" );
! std::string actualSource( document_->getAllText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
--- 167,171 ----
" return 4 * getQuantity();"
"}" );
! std::string actualSource( sourceDoc_->getOriginalText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
***************
*** 241,245 ****
" return 4 * getQuantity();"
"}" );
! std::string actualSource( document_->getAllText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
--- 248,252 ----
" return 4 * getQuantity();"
"}" );
! std::string actualSource( sourceDoc_->getOriginalText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
***************
*** 265,269 ****
" return 4 * getQuantity();"
"}" );
! std::string actualSource( document_->getAllText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
--- 272,276 ----
" return 4 * getQuantity();"
"}" );
! std::string actualSource( sourceDoc_->getOriginalText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
***************
*** 289,293 ****
" return 4 * getQuantity();"
"}" );
! std::string actualSource( document_->getAllText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
--- 296,300 ----
" return 4 * getQuantity();"
"}" );
! std::string actualSource( sourceDoc_->getOriginalText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
***************
*** 313,317 ****
" return ( 4 + 3 ) * getQuantity();"
"}" );
! std::string actualSource( document_->getAllText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
--- 320,324 ----
" return ( 4 + 3 ) * getQuantity();"
"}" );
! std::string actualSource( sourceDoc_->getOriginalText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
***************
*** 337,341 ****
" return 4 * getQuantity();"
"}" );
! std::string actualSource( document_->getAllText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
--- 344,348 ----
" return 4 * getQuantity();"
"}" );
! std::string actualSource( sourceDoc_->getOriginalText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
Index: TransformListTest.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/TransformListTest.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** TransformListTest.h 20 Dec 2003 08:59:50 -0000 1.5
--- TransformListTest.h 13 Jan 2004 22:27:35 -0000 1.6
***************
*** 8,14 ****
#include "MockTextDocument.h"
#include "ReplaceTextTransform.h"
- #include <rfta/refactoring/TransformList.h>
#include "UnitTesting.h"
#include <boost/shared_ptr.hpp>
--- 8,14 ----
#include "MockTextDocument.h"
#include "ReplaceTextTransform.h"
#include "UnitTesting.h"
#include <boost/shared_ptr.hpp>
+ #include <rfta/refactoring/TransformList.h>
Index: ReplaceTextTransform.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/ReplaceTextTransform.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** ReplaceTextTransform.cpp 16 May 2003 19:55:02 -0000 1.6
--- ReplaceTextTransform.cpp 13 Jan 2004 22:27:35 -0000 1.7
***************
*** 6,10 ****
#include "stdafx.h"
#include "ReplaceTextTransform.h"
! #include <rfta/refactoring/TextDocument.h>
--- 6,11 ----
#include "stdafx.h"
#include "ReplaceTextTransform.h"
! #include <rfta/parser/TextDocument.h>
! #include <rfta/parser/Source.h>
***************
*** 35,38 ****
--- 36,51 ----
}
+ int
+ ReplaceTextTransform::apply( SourcePtr pSource ) const
+ {
+ Source& where = pSource->getSourceOrigin(range_);
+ SourceRange r = pSource->getRangeOrigin(range_);
+
+ int lengthDelta = text_.length() - range_.getLength();
+ where.getTextDocument()->replaceTextRange( r, text_ );
+
+ return lengthDelta;
+ }
+
void
Index: ReplaceTextTransform.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/ReplaceTextTransform.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** ReplaceTextTransform.h 16 Dec 2003 13:27:29 -0000 1.6
--- ReplaceTextTransform.h 13 Jan 2004 22:27:35 -0000 1.7
***************
*** 32,35 ****
--- 32,37 ----
int apply( TextDocument &document ) const;
+ int apply( SourcePtr pSource ) const;
+
void moveStartIndexBy( int delta );
Index: MockTextDocument.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/MockTextDocument.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** MockTextDocument.h 16 May 2003 19:55:02 -0000 1.7
--- MockTextDocument.h 13 Jan 2004 22:27:35 -0000 1.8
***************
*** 8,12 ****
#include <boost/utility.hpp>
#include <mock/Expectations.h>
! #include <rfta/refactoring/TextDocument.h>
#include <deque>
--- 8,12 ----
#include <boost/utility.hpp>
#include <mock/Expectations.h>
! #include <rfta/parser/TextDocument.h>
#include <deque>
Index: TransformList.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/TransformList.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** TransformList.cpp 20 Dec 2003 08:59:50 -0000 1.7
--- TransformList.cpp 13 Jan 2004 22:27:35 -0000 1.8
***************
*** 7,12 ****
#include "stdafx.h"
#include "ReplaceTextTransform.h"
- #include <rfta/refactoring/TransformList.h>
#include <rfta/parser/SourceRange.h>
#include <algorithm>
--- 7,12 ----
#include "stdafx.h"
#include "ReplaceTextTransform.h"
#include <rfta/parser/SourceRange.h>
+ #include <rfta/refactoring/TransformList.h>
#include <algorithm>
***************
*** 63,66 ****
--- 63,82 ----
}
+ void
+ TransformList::apply( SourcePtr pSource )
+ {
+ sortListByStartIndex();
+
+ int totalDelta = 0;
+ while ( !transforms_.empty() )
+ {
+ TransformPtr transform = transforms_.front();
+ transforms_.pop_front();
+
+ transform->moveStartIndexBy( totalDelta );
+ totalDelta += transform->apply( pSource );
+ }
+ }
+
struct TransformList::SortPredicate
Index: IndentLevelManager.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/IndentLevelManager.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** IndentLevelManager.cpp 18 Mar 2003 22:37:51 -0000 1.9
--- IndentLevelManager.cpp 13 Jan 2004 22:27:35 -0000 1.10
***************
*** 13,20 ****
! IndentLevelManager::IndentLevelManager( const std::string &originalSource,
int indentWidth )
! : originalSource_( originalSource )
! , indentWidth_( indentWidth )
{
}
--- 13,20 ----
! IndentLevelManager::IndentLevelManager( SourcePtr source,
int indentWidth )
! : indentWidth_( indentWidth )
! , source_( source )
{
}
***************
*** 123,128 ****
{
int indent = 0;
! while ( --pos >= 0 && originalSource_[pos] != '\n' )
++indent;
return indent;
}
--- 123,132 ----
{
int indent = 0;
! SourceRange r(pos,1);r.moveStartIndexBy(-1);
! while ( r.getStartIndex() >= 0 && source_->getOriginalText(r)[0] != '\n' )
! {
++indent;
+ r.moveStartIndexBy(-1);
+ }
return indent;
}
Index: SourceBasedTestBase.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/SourceBasedTestBase.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** SourceBasedTestBase.h 16 Dec 2003 13:32:45 -0000 1.9
--- SourceBasedTestBase.h 13 Jan 2004 22:27:35 -0000 1.10
***************
*** 11,17 ****
#include <rfta/parser/SourceASTNode.h>
#include <rfta/test/SourceBuilder.h>
#include <rfta/parser/ParseContext.h>
#include <rfta/parser/MaxLODMutator.h>
! #include <rfta/parser/NonSemanticBlanker.h>
namespace Refactoring
--- 11,19 ----
#include <rfta/parser/SourceASTNode.h>
#include <rfta/test/SourceBuilder.h>
+ #include <rfta/test/SourceManagerMock.h>
#include <rfta/parser/ParseContext.h>
#include <rfta/parser/MaxLODMutator.h>
! #include <rfta/parser/Preprocessor.h>
! #include <rfta/parser/PreprocessorContext.h>
namespace Refactoring
***************
*** 39,42 ****
--- 41,46 ----
ASTNodePtr getVariableNode( const std::string &variableRangeKey );
+ SourcePtr sourceDoc_;
+ Testing::SourceManagerMock sourceMngMock_;
std::string source_;
SourceASTNodePtr sourceNode_;
***************
*** 46,50 ****
void parse(ParserType*)
{
! sourceNode_ = SourceASTNode::create( source_, source_ );
ParseContext context( sourceNode_ );
ParserType parser( context,
--- 50,54 ----
void parse(ParserType*)
{
! sourceNode_ = SourceASTNode::create( source_, source_, sourceDoc_ );
ParseContext context( sourceNode_ );
ParserType parser( context,
***************
*** 61,70 ****
void blankAndParse(ParserType*)
{
! std::string blankedSource;
! PPDirectiveListenerPtr nullListener(new NullPPDirectiveListener());
! NonSemanticBlanker blanker( source_, blankedSource, nullListener );
! blanker.blank();
! sourceNode_ = SourceASTNode::create( blankedSource, source_ );
ParseContext context( sourceNode_ );
ParserType parser( context,
--- 65,77 ----
void blankAndParse(ParserType*)
{
! if (sourceDoc_ == SourcePtr() )
! sourceDoc_ = SourcePtr( new Source( TextDocumentPtr( new PlainTextDocument( source_ ) ) ) );
! PreProcessorContext ppcontext( sourceMngMock_ );
! PreProcessor proc( sourceDoc_, ppcontext);
! proc.setOption(PreProcessor::skipIncludes); // TODO: disable this if preprocessor features can handle all system headers
! std::string blankedSource = proc.process();
!
! sourceNode_ = SourceASTNode::create( blankedSource, source_, sourceDoc_ );
ParseContext context( sourceNode_ );
ParserType parser( context,
Index: CodeWriterTestBase.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeWriterTestBase.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** CodeWriterTestBase.cpp 19 Dec 2003 20:12:05 -0000 1.10
--- CodeWriterTestBase.cpp 13 Jan 2004 22:27:35 -0000 1.11
***************
*** 8,11 ****
--- 8,12 ----
#include <rfta/refactoring/CodeModelGenerator.h>
#include <rfta/Parser/StatementsParser.h>
+ #include <rfta/parser/Source.h>
namespace Refactoring
***************
*** 17,21 ****
SourceBasedTestBase::setUp();
compound_.reset();
! document_.reset();
writer_.reset();
}
--- 18,22 ----
SourceBasedTestBase::setUp();
compound_.reset();
! sourceDoc_ = SourcePtr();
writer_.reset();
}
***************
*** 26,30 ****
{
writer_.reset();
! document_.reset();
compound_.reset();
SourceBasedTestBase::tearDown();
--- 27,31 ----
{
writer_.reset();
! sourceDoc_ = SourcePtr();
compound_.reset();
SourceBasedTestBase::tearDown();
***************
*** 41,45 ****
compound_ = generator.generateCompound( compoundNode );
- document_.reset( new PlainTextDocument( source_ ) );
}
--- 42,45 ----
***************
*** 48,53 ****
CodeWriterTestBase::rewriteSource()
{
! writer_.reset( new CodeModel::CodeRewriter( source_, 2 ) );
! writer_->rewrite( compound_, TransformList(), *document_ );
}
--- 48,53 ----
CodeWriterTestBase::rewriteSource()
{
! writer_.reset( new CodeModel::CodeRewriter( sourceDoc_, 2 ) );
! writer_->rewrite( compound_ );
}
***************
*** 99,103 ****
{
rewriteSource();
! RFTA_ASSERT_EQUAL( expectedSource, document_->getAllText() );
}
--- 99,103 ----
{
rewriteSource();
! RFTA_ASSERT_EQUAL( expectedSource, sourceDoc_->getOriginalText() );
}
Index: RenameTempRefactoringTest.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/RenameTempRefactoringTest.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** RenameTempRefactoringTest.h 10 May 2003 10:55:14 -0000 1.10
--- RenameTempRefactoringTest.h 13 Jan 2004 22:27:35 -0000 1.11
***************
*** 7,11 ****
#include "SourceBasedTestBase.h"
!
namespace Refactoring
--- 7,11 ----
#include "SourceBasedTestBase.h"
! #include <rfta/test/SourceManagerMock.h>
namespace Refactoring
***************
*** 55,59 ****
const std::string &oldLocaleVariableName );
! boost::shared_ptr<PlainTextDocument> document_;
};
--- 55,60 ----
const std::string &oldLocaleVariableName );
! Testing::SourceManagerMock sourceMngMock_;
! SourcePtr sourceDoc_;
};
Index: SplitTempRefactoring.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/SplitTempRefactoring.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** SplitTempRefactoring.cpp 19 Dec 2003 20:14:39 -0000 1.10
--- SplitTempRefactoring.cpp 13 Jan 2004 22:27:35 -0000 1.11
***************
*** 10,15 ****
#include "IdentifierResolverContext.h"
#include "ReplaceTextTransform.h"
- #include "PreProcessTransform.h"
- #include <rfta/parser/MacroReplaceRegistration.h>
#include <rfta/parser/MaxLODMutator.h>
#include <rfta/parser/PreProcessor.h>
--- 10,13 ----
***************
*** 21,25 ****
#include <rfta/parser/ASTNodes.h>
#include <rfta/refactoring/RefactoringError.h>
! #include <rfta/refactoring/TextDocument.h>
--- 19,24 ----
#include <rfta/parser/ASTNodes.h>
#include <rfta/refactoring/RefactoringError.h>
! #include <rfta/parser/TextDocument.h>
! #include <rfta/parser/Source.h>
***************
*** 28,34 ****
! SplitTempRefactoring::SplitTempRefactoring( TextDocument &document,
int temporaryLocation )
! : RefactoringBase( document )
, temporaryLocation_( temporaryLocation )
{
--- 27,34 ----
! SplitTempRefactoring::SplitTempRefactoring( SourcePtr source,
! SourceManager &manager,
int temporaryLocation )
! : RefactoringBase( source, manager )
, temporaryLocation_( temporaryLocation )
{
***************
*** 49,68 ****
throw RefactoringError( RefactoringError::selectionNotInSource );
! // preprocess
! PreProcessor proc( source );
! MacroReplaceRegistration registration;
! std::string blankedSource = proc.process(registration);
! registration.finishUpData();
! // correct pointer to location after preprocessing
! temporaryLocation_ -= registration.getReplacementDeltaBefore(SourceRange( temporaryLocation_, 1 ));
! // store macro replacement information
! int idx;
! for (idx=0; idx < registration.getSize(); idx++)
! {
! MacroReplaceRegistration::MacroReplacement entry = registration.getEntry(idx);
! transforms_.add( *new PreProcessTransform( entry.position_, entry.macroText_.size() - entry.replacement_.size() ) );
! }
int compoundStartIndex =
--- 49,61 ----
throw RefactoringError( RefactoringError::selectionNotInSource );
! // preprocess
! PreProcessorContext preproc_context( getSourceManager() );
! PreProcessor proc( getSource(), preproc_context );
! proc.setOption(PreProcessor::skipIncludes); // TODO: disable this if preprocessor features can handle all system headers
! std::string blankedSource = proc.process();
! // correct pointer to location after preprocessing
! temporaryLocation_ = getSource()->getRangePreProcessed(SourceRange( temporaryLocation_, 1 )).getStartIndex();
int compoundStartIndex =
***************
*** 72,76 ****
! sourceNode_ = SourceASTNode::create( blankedSource, source );
ParseContext context( sourceNode_ );
StatementParser parser( context,
--- 65,69 ----
! sourceNode_ = SourceASTNode::create( blankedSource, source, getSource() );
ParseContext context( sourceNode_ );
StatementParser parser( context,
***************
*** 139,143 ****
}
! transforms_.apply( getDocument() );
}
--- 132,136 ----
}
! transforms_.apply( getSource() );
}
Index: InlineTempRefactoring.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/InlineTempRefactoring.cpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** InlineTempRefactoring.cpp 20 Dec 2003 08:59:50 -0000 1.11
--- InlineTempRefactoring.cpp 13 Jan 2004 22:27:35 -0000 1.12
***************
*** 7,12 ****
#include <rfta/refactoring/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>
--- 7,13 ----
#include <rfta/refactoring/InlineTempRefactoring.h>
#include <rfta/refactoring/RefactoringError.h>
! #include <rfta/parser/TextDocument.h>
! #include <rfta/parser/PreProcessor.h>
! #include <rfta/parser/Source.h>
#include <rfta/parser/ParseContext.h>
#include <rfta/parser/StatementParser.h>
***************
*** 24,30 ****
! InlineTempRefactoring::InlineTempRefactoring( TextDocument &document,
int temporaryLocation )
! : RefactoringBase( document )
, temporaryLocation_( temporaryLocation )
{
--- 25,32 ----
! InlineTempRefactoring::InlineTempRefactoring( SourcePtr source,
! SourceManager& manager,
int temporaryLocation )
! : RefactoringBase( source, manager )
, temporaryLocation_( temporaryLocation )
{
***************
*** 66,74 ****
throw RefactoringError( RefactoringError::selectionNotInSource );
! // blank the source code
! PPDirectiveListenerPtr nullListener(new NullPPDirectiveListener());
! std::string blankedSource;
! NonSemanticBlanker blanker( source, blankedSource, nullListener );
! blanker.blank();
int start_at = temporaryLocation_;
--- 68,79 ----
throw RefactoringError( RefactoringError::selectionNotInSource );
! // preprocess
! PreProcessorContext preproc_context( getSourceManager() );
! PreProcessor proc( getSource(), preproc_context );
! proc.setOption(PreProcessor::skipIncludes); // TODO: disable this if preprocessor features can handle all system headers
! std::string blankedSource = proc.process();
!
! // correct pointer to location after preprocessing
! temporaryLocation_ = getSource()->getRangePreProcessed(SourceRange( temporaryLocation_, 1 )).getStartIndex();
int start_at = temporaryLocation_;
***************
*** 84,88 ****
// 'lazy' parse the source
! sourceNode_ = SourceASTNode::create( blankedSource, source );
ParseContext context( sourceNode_ );
StatementParser parser( context,
--- 89,93 ----
// 'lazy' parse the source
! sourceNode_ = SourceASTNode::create( blankedSource, source, getSource() );
ParseContext context( sourceNode_ );
StatementParser parser( context,
***************
*** 377,381 ****
! transforms.apply( getDocument() );
}
--- 382,386 ----
! transforms.apply( getSource() );
}
Index: IndentLevelManager.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/IndentLevelManager.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** IndentLevelManager.h 22 Apr 2003 19:18:16 -0000 1.12
--- IndentLevelManager.h 13 Jan 2004 22:27:35 -0000 1.13
***************
*** 7,10 ****
--- 7,11 ----
#include <rfta/refactoring/CodeModelForward.h>
+ #include <rfta/parser/Source.h>
#include <deque>
#include <string>
***************
*** 51,55 ****
/*! Constructs a IndentLevelManager object.
*/
! IndentLevelManager( const std::string &originalSource,
int indentWidth = 2 );
--- 52,56 ----
/*! Constructs a IndentLevelManager object.
*/
! IndentLevelManager( SourcePtr source,
int indentWidth = 2 );
***************
*** 97,101 ****
Indents indents_;
! const std::string originalSource_;
int indentWidth_;
};
--- 98,102 ----
Indents indents_;
! SourcePtr source_;
int indentWidth_;
};
Index: RenameTempRefactoringTest.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/RenameTempRefactoringTest.cpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** RenameTempRefactoringTest.cpp 16 Dec 2003 13:26:10 -0000 1.17
--- RenameTempRefactoringTest.cpp 13 Jan 2004 22:27:35 -0000 1.18
***************
*** 7,12 ****
#include "RenameTempRefactoringTest.h"
#include <rfta/refactoring/RenameTempRefactoring.h>
! #include <rfta/refactoring/PlainTextDocument.h>
#include <rfta/refactoring/RefactoringError.h>
--- 7,13 ----
#include "RenameTempRefactoringTest.h"
#include <rfta/refactoring/RenameTempRefactoring.h>
! #include <rfta/parser/PlainTextDocument.h>
#include <rfta/refactoring/RefactoringError.h>
+ #include <rfta/parser/Source.h>
***************
*** 37,41 ****
RenameTempRefactoringTest::tearDown()
{
- document_.reset();
SourceBasedTestBase::tearDown();
}
--- 38,41 ----
***************
*** 46,52 ****
const std::string &oldLocaleVariableName )
{
! document_.reset( new PlainTextDocument( source_ ) );
int selectionIndex = builder_->getStartIndex( "selection" );
! RenameTempRefactoring refactoring( *document_,
selectionIndex );
refactoring.apply( newTemporaryName );
--- 46,54 ----
const std::string &oldLocaleVariableName )
{
! sourceDoc_ = SourcePtr( new Source( TextDocumentPtr( new PlainTextDocument( source_ ) ) ) );
!
int selectionIndex = builder_->getStartIndex( "selection" );
! RenameTempRefactoring refactoring( sourceDoc_,
! sourceMngMock_,
selectionIndex );
refactoring.apply( newTemporaryName );
***************
*** 76,80 ****
" return price * getQuantity();"
"}" );
! std::string actualSource( document_->getAllText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
--- 78,82 ----
" return price * getQuantity();"
"}" );
! std::string actualSource( sourceDoc_->getOriginalText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
***************
*** 100,104 ****
" return price * getQuantity();"
"}" );
! std::string actualSource( document_->getAllText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
--- 102,106 ----
" return price * getQuantity();"
"}" );
! std::string actualSource( sourceDoc_->getOriginalText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
***************
*** 126,130 ****
" return price * getQuantity();"
"}" );
! std::string actualSource( document_->getAllText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
--- 128,132 ----
" return price * getQuantity();"
"}" );
! std::string actualSource( sourceDoc_->getOriginalText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
***************
*** 152,156 ****
" return price * getQuantity();"
"}" );
! std::string actualSource( document_->getAllText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
--- 154,158 ----
" return price * getQuantity();"
"}" );
! std::string actualSource( sourceDoc_->getOriginalText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
***************
*** 186,190 ****
" return price * getQuantity();"
"}" );
! std::string actualSource( document_->getAllText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
--- 188,192 ----
" return price * getQuantity();"
"}" );
! std::string actualSource( sourceDoc_->getOriginalText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
***************
*** 207,211 ****
" CppUnit::XmlOutputter xmlOutputter( &resultCollector, xmlFile );"
"}" );
! std::string actualSource( document_->getAllText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
--- 209,213 ----
" CppUnit::XmlOutputter xmlOutputter( &resultCollector, xmlFile );"
"}" );
! std::string actualSource( sourceDoc_->getOriginalText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
***************
*** 242,246 ****
" return price * getQuantity();"
"}" );
! std::string actualSource( document_->getAllText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
--- 244,248 ----
" return price * getQuantity();"
"}" );
! std::string actualSource( sourceDoc_->getOriginalText() );
RFTA_ASSERT_EQUAL( expectedSource, actualSource );
}
Index: RenameTempRefactoring.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/RenameTempRefactoring.cpp,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** RenameTempRefactoring.cpp 16 Dec 2003 13:26:10 -0000 1.18
--- RenameTempRefactoring.cpp 13 Jan 2004 22:27:35 -0000 1.19
***************
*** 10,14 ****
#include "IdentifierResolverContext.h"
#include "ReplaceTextTransform.h"
- #include "PreProcessTransform.h"
#include <rfta/parser/MaxLODMutator.h>
#include <rfta/parser/PreProcessor.h>
--- 10,13 ----
***************
*** 20,25 ****
#include <rfta/parser/ASTNodes.h>
#include <rfta/refactoring/RefactoringError.h>
! #include <rfta/refactoring/TextDocument.h>
! #include <rfta/parser/MacroReplaceRegistration.h>
--- 19,24 ----
#include <rfta/parser/ASTNodes.h>
#include <rfta/refactoring/RefactoringError.h>
! #include <rfta/parser/TextDocument.h>
! #include <rfta/parser/Source.h>
***************
*** 27,34 ****
{
! RenameTempRefactoring::RenameTempRefactoring( TextDocument &document,
int temporaryLocation )
! : RefactoringBase( document )
! , temporaryLocation_( temporaryLocation )
{
prepare();
--- 26,34 ----
{
! RenameTempRefactoring::RenameTempRefactoring( SourcePtr source,
! SourceManager& manager,
int temporaryLocation )
! : RefactoringBase( source, manager )
! , temporaryLocation_( temporaryLocation )
{
prepare();
***************
*** 67,85 ****
if ( temporaryLocation_ >= source.length() )
throw RefactoringError( RefactoringError::selectionNotInSource );
-
- PreProcessor proc( source );
- MacroReplaceRegistration registration;
- std::string blankedSource = proc.process(registration);
- registration.finishUpData();
! // fix source offset after preprocessing (macros might have moved the position)
! temporaryLocation_ -= registration.getReplacementDeltaBefore(SourceRange( temporaryLocation_, 1 ));
! int idx;
! for (idx=0; idx < registration.getSize(); idx++)
! {
! MacroReplaceRegistration::MacroReplacement entry = registration.getEntry(idx);
! transforms_.add( *new PreProcessTransform( entry.position_, entry.macroText_.size() - entry.replacement_.size() ) );
! }
int start_at = temporaryLocation_;
--- 67,79 ----
if ( temporaryLocation_ >= source.length() )
throw RefactoringError( RefactoringError::selectionNotInSource );
! PreProcessorContext context( getSourceManager() );
! PreProcessor proc( getSource(), context);
! proc.setOption(PreProcessor::skipIncludes); // TODO: disable this if preprocessor features can handle all system headers
! std::string blankedSource = proc.process();
!
! // fix source offset after preprocessing (macros might have moved the position)
! temporaryLocation_ = getSource()->getRangePreProcessed(SourceRange( temporaryLocation_, 1 )).getStartIndex();
int start_at = temporaryLocation_;
***************
*** 95,99 ****
// 'lazy' parse the source
! sourceNode_ = SourceASTNode::create( blankedSource, source );
ParseContext context( sourceNode_ );
StatementParser parser( context,
--- 89,93 ----
// 'lazy' parse the source
! sourceNode_ = SourceASTNode::create( blankedSource, source, getSource() );
ParseContext context( sourceNode_ );
StatementParser parser( context,
***************
*** 150,154 ****
}
! transforms_.apply( getDocument() );
}
--- 144,148 ----
}
! transforms_.apply( getSource() );
}
Index: CodeWriterTest.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeWriterTest.cpp,v
retrieving revision 1.36
retrieving revision 1.37
diff -C2 -d -r1.36 -r1.37
*** CodeWriterTest.cpp 24 Apr 2003 16:28:30 -0000 1.36
--- CodeWriterTest.cpp 13 Jan 2004 22:27:35 -0000 1.37
***************
*** 6,9 ****
--- 6,10 ----
#include "stdafx.h"
#include "CodeWriterTest.h"
+ #include <rfta/parser/Source.h>
***************
*** 52,56 ****
rewriteSource();
! RFTA_ASSERT_EQUAL( expectedSource, document_->getAllText() );
}
--- 53,57 ----
rewriteSource();
! RFTA_ASSERT_EQUAL( expectedSource, sourceDoc_->getOriginalText() );
}
***************
*** 80,84 ****
" return;\n"
"}";
! RFTA_ASSERT_EQUAL( expectedSource, document_->getAllText() );
}
--- 81,85 ----
" return;\n"
"}";
! RFTA_ASSERT_EQUAL( expectedSource, sourceDoc_->getOriginalText() );
}
***************
*** 100,104 ****
" return true;\n"
" }";
! RFTA_ASSERT_EQUAL( expectedSource, document_->getAllText() );
}
--- 101,105 ----
" return true;\n"
" }";
! RFTA_ASSERT_EQUAL( expectedSource, sourceDoc_->getOriginalText() );
}
***************
*** 123,127 ****
" return 6;\n"
"}";
! RFTA_ASSERT_EQUAL( expectedSource, document_->getAllText() );
}
--- 124,128 ----
" return 6;\n"
"}";
! RFTA_ASSERT_EQUAL( expectedSource, sourceDoc_->getOriginalText() );
}
***************
*** 162,166 ****
" return 3;\n"
"}";
! RFTA_ASSERT_EQUAL( expectedSource, document_->getAllText() );
}
--- 163,167 ----
" return 3;\n"
"}";
! RFTA_ASSERT_EQUAL( expectedSource, sourceDoc_->getOriginalText() );
}
Index: CodeRewriter.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeRewriter.cpp,v
retrieving revision 1.46
retrieving revision 1.47
diff -C2 -d -r1.46 -r1.47
*** CodeRewriter.cpp 19 Dec 2003 20:11:36 -0000 1.46
--- CodeRewriter.cpp 13 Jan 2004 22:27:35 -0000 1.47
***************
*** 7,11 ****
#include "CodeRewriter.h"
#include "ReplaceTextTransform.h"
! #include <rfta/refactoring/TextDocument.h>
#include <rfta/refactoring/CodeModelExpressions.h>
#include <rfta/refactoring/CodeModelStatements.h>
--- 7,11 ----
#include "CodeRewriter.h"
#include "ReplaceTextTransform.h"
! #include <rfta/parser/Source.h>
#include <rfta/refactoring/CodeModelExpressions.h>
#include <rfta/refactoring/CodeModelStatements.h>
***************
*** 15,24 ****
! CodeRewriter::CodeRewriter( const std::string &originalSource,
int indentWidth )
! : originalSource_( originalSource )
, indentWidth_( indentWidth )
, currentInsertionPos_( 0 )
! , indentManager_( originalSource )
, mode_( updating )
{
--- 15,24 ----
! CodeRewriter::CodeRewriter( const SourcePtr source,
int indentWidth )
! : source_( source )
, indentWidth_( indentWidth )
, currentInsertionPos_( 0 )
! , indentManager_( source )
, mode_( updating )
{
***************
*** 32,43 ****
void
! CodeRewriter::rewrite( const StatementPtr &statement,
! TransformList& preprocesstransforms,
! TextDocument &document )
{
statement->accept( *this );
! // @TODO(Andre): Check conflics between statement transforms and preprocessing...
! transforms_.add(preprocesstransforms);
! transforms_.apply( document );
}
--- 32,39 ----
void
! CodeRewriter::rewrite( const StatementPtr &statement )
{
statement->accept( *this );
! transforms_.apply( source_ );
}
***************
*** 110,120 ****
CodeRewriter::deleteStatement( const SourceRange &range )
{
! int startIndex = range.getStartIndex();
! while ( startIndex > 0 && isSpace( originalSource_.at( startIndex-1 ) ) )
! --startIndex;
! while ( startIndex > 0 && isNewLine( originalSource_.at( startIndex-1 ) ) )
! --startIndex;
!
! deleteText( SourceRange( startIndex, range.getEndIndex() - startIndex ) );
}
--- 106,117 ----
CodeRewriter::deleteStatement( const SourceRange &range )
{
! SourceRange r = range; r.setLength(1);r.moveStartIndexBy(-1);
! while ( r.getStartIndex() >= 0 && isSpace( source_->getOriginalText(r)[0] ) )
! r.moveStartIndexBy(-1);
! while ( r.getStartIndex() >= 0 && isNewLine( source_->getOriginalText(r)[0] ) )
! r.moveStartIndexBy(-1);
! r.moveStartIndexBy(1);
! r.setEndIndex(range.getEndIndex());
! deleteText( r );
}
***************
*** 123,131 ****
CodeRewriter::deleteTrailingExpression( const SourceRange &range )
{
! int startIndex = range.getStartIndex();
! while ( startIndex > 0 && isSpace( originalSource_.at( startIndex-1 ) ) )
! --startIndex;
!
! deleteText( SourceRange( startIndex, range.getEndIndex() - startIndex ) );
}
--- 120,129 ----
CodeRewriter::deleteTrailingExpression( const SourceRange &range )
{
! SourceRange r = range; r.setLength(1);r.moveStartIndexBy(-1);
! while ( r.getStartIndex() >= 0 && isSpace( source_->getOriginalText(r)[0] ) )
! r.moveStartIndexBy(-1);
! r.moveStartIndexBy(1);
! r.setEndIndex(range.getEndIndex());
! deleteText( r );
}
***************
*** 134,146 ****
CodeRewriter::deleteBracedExpression( const SourceRange &range )
{
! int startIndex = range.getStartIndex();
! while ( startIndex > 0 && isSpace( originalSource_.at( startIndex-1 ) ) )
! --startIndex;
!
! int endIndex = range.getEndIndex();
! while ( endIndex < originalSource_.length() && isSpace( originalSource_.at( endIndex ) ) )
! ++endIndex;
! deleteText( SourceRange( startIndex, endIndex - startIndex ) );
}
--- 132,146 ----
CodeRewriter::deleteBracedExpression( const SourceRange &range )
{
! SourceRange r = range; r.setLength(1);r.moveStartIndexBy(-1);
! while ( r.getStartIndex() >= 0 && isSpace( source_->getOriginalText(r)[0] ) )
! r.moveStartIndexBy(-1);
! r.moveStartIndexBy(1);
!
! SourceRange end = range; end.moveStartIndexBy(range.getLength());end.setLength(1);
! while ( !source_->getOriginalText(end).empty() && isSpace( source_->getOriginalText(end)[0] ) )
! end.moveStartIndexBy(1);
! r.setEndIndex(end.getStartIndex() );
! deleteText( r );
}
***************
*** 434,438 ****
{
insertText( ")" );
! indentManager_.enterNewWhileStatement( iteratedStatement );
}
else
--- 434,438 ----
{
insertText( ")" );
! indentManager_.enterNewForStatement( iteratedStatement );
}
else
|
Update of /cvsroot/cpptool/rfta/src/rftaparser
In directory sc8-pr-cvs1:/tmp/cvs-serv10043/rftaparser
Modified Files:
UnparsedDeclaratorMutatorTest.cpp CPPParser.cpp
EnumBodyParserTest.cpp ExpressionOperationMutatorTest.cpp
ParseContextTest.cpp UnparsedCompoundMutatorTest.cpp
CPPParserTest.cpp DeclarationDetailsParserTest.cpp
ParserTesting.h UnparsedDeclarationListMutatorTest.cpp
ExpressionMutatorTest.cpp SourceASTNode.cpp Parser.cpp
VariableDeclMutatorTest.cpp UnparsedDeclarationMutatorTest.cpp
Log Message:
-- integrated preprocessor (replaced all NonSemanticBlanker)
Index: UnparsedDeclaratorMutatorTest.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftaparser/UnparsedDeclaratorMutatorTest.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** UnparsedDeclaratorMutatorTest.cpp 15 Sep 2003 09:13:31 -0000 1.2
--- UnparsedDeclaratorMutatorTest.cpp 13 Jan 2004 22:27:35 -0000 1.3
***************
*** 29,33 ****
const CppUnit::SourceLine &sourceLine )
{
! SourceASTNodePtr sourceNode = SourceASTNode::create( source, source );
ParseContext context( sourceNode );
--- 29,34 ----
const CppUnit::SourceLine &sourceLine )
{
! SourcePtr sourceDoc = SourcePtr( new Source( TextDocumentPtr( new PlainTextDocument( source ) ) ) );
! SourceASTNodePtr sourceNode = SourceASTNode::create( source, source, sourceDoc );
ParseContext context( sourceNode );
Index: CPPParser.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftaparser/CPPParser.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** CPPParser.cpp 16 Dec 2003 13:21:51 -0000 1.3
--- CPPParser.cpp 13 Jan 2004 22:27:35 -0000 1.4
***************
*** 1,6 ****
#include "stdafx.h"
#include <rfta/parser/CPPParser.h>
- #include <rfta/parser/NonSemanticBlanker.h>
#include <rfta/parser/MaxLODMutator.h>
#include <rfta/parser/DeclarationListParser.h>
--- 1,6 ----
#include "stdafx.h"
+ #include <rfta/parser/PreProcessor.h>
#include <rfta/parser/CPPParser.h>
#include <rfta/parser/MaxLODMutator.h>
#include <rfta/parser/DeclarationListParser.h>
***************
*** 9,12 ****
--- 9,14 ----
#include <rfta/parser/ASTNodeAndPropertyVisitor.h>
#include <rfta/parser/ASTNodes.h>
+ #include <rfta/parser/Source.h>
+ #include <rfta/parser/PlainTextDocument.h>
namespace Refactoring {
***************
*** 76,85 ****
CPPParser::CPPParser( const std::string &source )
{
! PPDirectiveListenerPtr pNullListener( new NullPPDirectiveListener() );
! std::string blankedSource;
! NonSemanticBlanker blanker( source, blankedSource, pNullListener );
! blanker.blank();
! sourceNode_ = SourceASTNode::create( blankedSource, source );
}
--- 78,91 ----
CPPParser::CPPParser( const std::string &source )
{
! sourceDoc_ = SourcePtr( new Source( TextDocumentPtr( new PlainTextDocument( source ) ) ) );
! NullSourceManager manager;
! PreProcessorContext context( manager );
! PreProcessor proc( sourceDoc_, context);
!
! proc.setOption(PreProcessor::skipIncludes); // TODO: disable this if preprocessor features can handle all system headers
! std::string blankedSource = proc.process();
!
! sourceNode_ = SourceASTNode::create( blankedSource, source, sourceDoc_ );
}
***************
*** 97,101 ****
parseAll();
! FunctionImplementationVisitor visitor( position );
return visitor.findFunctionImplementation( sourceNode_ );
}
--- 103,110 ----
parseAll();
! // translate to preprocessed text position:
! SourceRange r = sourceDoc_->getRangePreProcessed(SourceRange(position,1));
!
! FunctionImplementationVisitor visitor( r.getStartIndex() );
return visitor.findFunctionImplementation( sourceNode_ );
}
***************
*** 124,127 ****
--- 133,150 ----
}
+ int
+ CPPParser::getPreProcessedPosition(int ofs)
+ {
+ // translate to preprocessed text position:
+ SourceRange r = sourceDoc_->getRangePreProcessed(SourceRange(ofs,1));
+ return r.getStartIndex();
+ }
+
+ SourceRange
+ CPPParser::getPreProcessedRange(SourceRange orignal)
+ {
+ return sourceDoc_->getRangePreProcessed(orignal);
+ }
+
} // namespace Refactoring
Index: EnumBodyParserTest.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftaparser/EnumBodyParserTest.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** EnumBodyParserTest.cpp 16 Dec 2003 13:22:21 -0000 1.3
--- EnumBodyParserTest.cpp 13 Jan 2004 22:27:35 -0000 1.4
***************
*** 9,12 ****
--- 9,13 ----
#include <xtl/Type.h>
#include <rfta/parser/ASTNodes.h>
+ #include <rfta/parser/PlainTextDocument.h>
#include <boost/lexical_cast.hpp>
***************
*** 24,28 ****
Xtl::Type<ParserType> )
{
! SourceASTNodePtr sourceNode = SourceASTNode::create( source, source );
ParseContext context( sourceNode );
ParserType parser( context,
--- 25,30 ----
Xtl::Type<ParserType> )
{
! SourcePtr sourceDoc = SourcePtr( new Source( TextDocumentPtr( new PlainTextDocument( source ) ) ) );
! SourceASTNodePtr sourceNode = SourceASTNode::create( source, source, sourceDoc );
ParseContext context( sourceNode );
ParserType parser( context,
Index: ExpressionOperationMutatorTest.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftaparser/ExpressionOperationMutatorTest.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** ExpressionOperationMutatorTest.cpp 3 May 2003 17:34:55 -0000 1.4
--- ExpressionOperationMutatorTest.cpp 13 Jan 2004 22:27:35 -0000 1.5
***************
*** 45,49 ****
const CppUnit::SourceLine &sourceLine )
{
! SourceASTNodePtr sourceNode = SourceASTNode::create( expression, expression );
ParseContext context( sourceNode );
ASTNodePtr expressionNode = ASTNode::create( ASTNodeTypes::unparsedExpressionStatement,
--- 45,50 ----
const CppUnit::SourceLine &sourceLine )
{
! SourcePtr sourceDoc = SourcePtr( new Source( TextDocumentPtr( new PlainTextDocument( expression ) ) ) );
! SourceASTNodePtr sourceNode = SourceASTNode::create( expression, expression, sourceDoc );
ParseContext context( sourceNode );
ASTNodePtr expressionNode = ASTNode::create( ASTNodeTypes::unparsedExpressionStatement,
Index: ParseContextTest.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftaparser/ParseContextTest.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** ParseContextTest.cpp 20 Dec 2002 08:30:50 -0000 1.4
--- ParseContextTest.cpp 13 Jan 2004 22:27:35 -0000 1.5
***************
*** 7,11 ****
#include "stdafx.h"
#include "ParseContextTest.h"
!
namespace Refactoring
--- 7,12 ----
#include "stdafx.h"
#include "ParseContextTest.h"
! #include <rfta/parser/PlainTextDocument.h>
! #include <rfta/parser/Source.h>
namespace Refactoring
***************
*** 41,45 ****
{
const std::string source( ";" );
! SourceASTNodePtr sourceAST = SourceASTNode::create( source, source );
ParseContext context( sourceAST );
CPPUNIT_ASSERT( context.getSourceNode() == sourceAST );
--- 42,47 ----
{
const std::string source( ";" );
! SourcePtr sourceDoc = SourcePtr( new Source( TextDocumentPtr( new PlainTextDocument( source ) ) ) );
! SourceASTNodePtr sourceAST = SourceASTNode::create( source, source, sourceDoc );
ParseContext context( sourceAST );
CPPUNIT_ASSERT( context.getSourceNode() == sourceAST );
***************
*** 53,57 ****
{
const std::string source( "{;}" );
! SourceASTNodePtr sourceAST = SourceASTNode::create( source, source );
ParseContext context( sourceAST );
context.enterParser( "Parser1", sourceAST->getBlankedSourceStart() );
--- 55,60 ----
{
const std::string source( "{;}" );
! SourcePtr sourceDoc = SourcePtr( new Source( TextDocumentPtr( new PlainTextDocument( source ) ) ) );
! SourceASTNodePtr sourceAST = SourceASTNode::create( source, source, sourceDoc );
ParseContext context( sourceAST );
context.enterParser( "Parser1", sourceAST->getBlankedSourceStart() );
***************
*** 76,80 ****
{
const std::string source( "{;}" );
! SourceASTNodePtr sourceNode = SourceASTNode::create( source, source );
ParseContext context( sourceNode );
--- 79,84 ----
{
const std::string source( "{;}" );
! SourcePtr sourceDoc = SourcePtr( new Source( TextDocumentPtr( new PlainTextDocument( source ) ) ) );
! SourceASTNodePtr sourceNode = SourceASTNode::create( source, source, sourceDoc );
ParseContext context( sourceNode );
Index: UnparsedCompoundMutatorTest.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftaparser/UnparsedCompoundMutatorTest.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** UnparsedCompoundMutatorTest.cpp 20 Dec 2002 08:30:51 -0000 1.4
--- UnparsedCompoundMutatorTest.cpp 13 Jan 2004 22:27:35 -0000 1.5
***************
*** 12,15 ****
--- 12,16 ----
#include <rfta/parser/ParseContext.h>
#include <rfta/parser/SourceASTNode.h>
+ #include "TextDocumentMock.h"
***************
*** 49,53 ****
int startIndex = 2;
int length = source.length() -4;
! SourceASTNodePtr sourceNode = SourceASTNode::create( source, source );
ASTNodePtr compoundNode = ASTNode::create(
ASTNodeTypes::unparsedCompoundStatement,
--- 50,55 ----
int startIndex = 2;
int length = source.length() -4;
! SourcePtr sourceDoc = SourcePtr( new Source( TextDocumentPtr( new Testing::TextDocumentMock( source ) ) ) );
! SourceASTNodePtr sourceNode = SourceASTNode::create( source, source, sourceDoc );
ASTNodePtr compoundNode = ASTNode::create(
ASTNodeTypes::unparsedCompoundStatement,
Index: CPPParserTest.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftaparser/CPPParserTest.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** CPPParserTest.cpp 28 May 2003 07:13:24 -0000 1.5
--- CPPParserTest.cpp 13 Jan 2004 22:27:35 -0000 1.6
***************
*** 48,53 ****
RFTA_ASSERT_NODE_TYPE( functionNode, ASTNodeTypes::functionImplementation, "function node" );
CPPUNIT_ASSERT_MESSAGE( "Failed to find function implementation node", functionNode );
! CPPUNIT_ASSERT( functionNode->getRange().contains( SourceRange( selectionIndex, 0 ) ) );
! CPPUNIT_ASSERT( functionNode->getRange() == source.getKeyedRange( functionKey_, 0 ) );
}
--- 48,53 ----
RFTA_ASSERT_NODE_TYPE( functionNode, ASTNodeTypes::functionImplementation, "function node" );
CPPUNIT_ASSERT_MESSAGE( "Failed to find function implementation node", functionNode );
! CPPUNIT_ASSERT( functionNode->getRange().contains( SourceRange( parser.getPreProcessedPosition(selectionIndex), 0 ) ) );
! CPPUNIT_ASSERT( functionNode->getRange() == parser.getPreProcessedRange(source.getKeyedRange( functionKey_, 0 ) ) );
}
Index: DeclarationDetailsParserTest.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftaparser/DeclarationDetailsParserTest.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** DeclarationDetailsParserTest.cpp 6 Sep 2003 21:41:58 -0000 1.5
--- DeclarationDetailsParserTest.cpp 13 Jan 2004 22:27:35 -0000 1.6
***************
*** 10,13 ****
--- 10,14 ----
#include "DeclarationDetailsParser.h"
#include "KeyedString.h"
+ #include <rfta/parser/PlainTextDocument.h>
***************
*** 22,26 ****
Refactoring::Testing::Identity<ParserType> )
{
! SourceASTNodePtr sourceNode = SourceASTNode::create( source, source );
ParseContext context( sourceNode );
--- 23,28 ----
Refactoring::Testing::Identity<ParserType> )
{
! SourcePtr sourceDoc = SourcePtr( new Source( TextDocumentPtr( new PlainTextDocument( source ) ) ) );
! SourceASTNodePtr sourceNode = SourceASTNode::create( source, source, sourceDoc );
ParseContext context( sourceNode );
***************
*** 56,60 ****
Refactoring::Testing::Identity<ParserType> )
{
! SourceASTNodePtr sourceNode = SourceASTNode::create( source, source );
ParseContext context( sourceNode );
--- 58,63 ----
Refactoring::Testing::Identity<ParserType> )
{
! SourcePtr sourceDoc = SourcePtr( new Source( TextDocumentPtr( new PlainTextDocument( source ) ) ) );
! SourceASTNodePtr sourceNode = SourceASTNode::create( source, source, sourceDoc );
ParseContext context( sourceNode );
Index: ParserTesting.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftaparser/ParserTesting.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** ParserTesting.h 3 May 2003 20:40:06 -0000 1.6
--- ParserTesting.h 13 Jan 2004 22:27:35 -0000 1.7
***************
*** 5,8 ****
--- 5,10 ----
#include <rfta/parser/ParserError.h>
#include <rfta/parser/SourceASTNode.h>
+ #include <rfta/parser/Source.h>
+ #include <rfta/parser/PlainTextDocument.h>
#include "UnitTesting.h"
***************
*** 134,138 ****
Identity<ParserType> )
{
! SourceASTNodePtr sourceAST = SourceASTNode::create( source, source );
ParseContext context( sourceAST );
ParserType parser( context,
--- 136,141 ----
Identity<ParserType> )
{
! SourcePtr sourceDoc = SourcePtr( new Source( TextDocumentPtr( new PlainTextDocument( source ) ) ) );
! SourceASTNodePtr sourceAST = SourceASTNode::create( source, source, sourceDoc );
ParseContext context( sourceAST );
ParserType parser( context,
***************
*** 153,157 ****
Identity<ParserType> )
{
! SourceASTNodePtr sourceAST = SourceASTNode::create( source, source );
ParseContext context( sourceAST );
ParserType parser( context,
--- 156,161 ----
Identity<ParserType> )
{
! SourcePtr sourceDoc = SourcePtr( new Source( TextDocumentPtr( new PlainTextDocument( source ) ) ) );
! SourceASTNodePtr sourceAST = SourceASTNode::create( source, source, sourceDoc );
ParseContext context( sourceAST );
ParserType parser( context,
***************
*** 179,183 ****
Identity<ParserType> )
{
! SourceASTNodePtr sourceAST = SourceASTNode::create( source, source );
ParseContext context( sourceAST );
const char *start = sourceAST->getBlankedSourceStart();
--- 183,188 ----
Identity<ParserType> )
{
! SourcePtr sourceDoc = SourcePtr( new Source( TextDocumentPtr( new PlainTextDocument( source ) ) ) );
! SourceASTNodePtr sourceAST = SourceASTNode::create( source, source, sourceDoc );
ParseContext context( sourceAST );
const char *start = sourceAST->getBlankedSourceStart();
***************
*** 208,212 ****
Identity<ParserType> )
{
! SourceASTNodePtr sourceAST = SourceASTNode::create( source, source );
ParseContext context( sourceAST );
ParserType parser( context,
--- 213,218 ----
Identity<ParserType> )
{
! SourcePtr sourceDoc = SourcePtr( new Source( TextDocumentPtr( new PlainTextDocument( source ) ) ) );
! SourceASTNodePtr sourceAST = SourceASTNode::create( source, source, sourceDoc );
ParseContext context( sourceAST );
ParserType parser( context,
***************
*** 237,241 ****
Identity<ParserType> )
{
! SourceASTNodePtr sourceAST = SourceASTNode::create( source, source );
ParseContext context( sourceAST );
const char *start = sourceAST->getBlankedSourceStart();
--- 243,248 ----
Identity<ParserType> )
{
! SourcePtr sourceDoc = SourcePtr( new Source( TextDocumentPtr( new PlainTextDocument( source ) ) ) );
! SourceASTNodePtr sourceAST = SourceASTNode::create( source, source, sourceDoc );
ParseContext context( sourceAST );
const char *start = sourceAST->getBlankedSourceStart();
Index: UnparsedDeclarationListMutatorTest.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftaparser/UnparsedDeclarationListMutatorTest.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** UnparsedDeclarationListMutatorTest.cpp 6 Sep 2003 21:37:06 -0000 1.6
--- UnparsedDeclarationListMutatorTest.cpp 13 Jan 2004 22:27:35 -0000 1.7
***************
*** 54,58 ****
const std::string source( "namespace y { int x; float (*f)(int x); } " );
! SourceASTNodePtr sourceNode = SourceASTNode::create( source, source );
ParseContext context(sourceNode);
--- 54,59 ----
const std::string source( "namespace y { int x; float (*f)(int x); } " );
! SourcePtr sourceDoc = SourcePtr( new Source( TextDocumentPtr( new PlainTextDocument( source ) ) ) );
! SourceASTNodePtr sourceNode = SourceASTNode::create( source, source, sourceDoc );
ParseContext context(sourceNode);
***************
*** 103,107 ****
source << ";";
! SourceASTNodePtr sourceNode = SourceASTNode::create( source, source );
// parse declaration:
--- 104,109 ----
source << ";";
! SourcePtr sourceDoc = SourcePtr( new Source( TextDocumentPtr( new PlainTextDocument( source ) ) ) );
! SourceASTNodePtr sourceNode = SourceASTNode::create( source, source, sourceDoc );
// parse declaration:
Index: ExpressionMutatorTest.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftaparser/ExpressionMutatorTest.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** ExpressionMutatorTest.cpp 20 Dec 2002 08:30:50 -0000 1.7
--- ExpressionMutatorTest.cpp 13 Jan 2004 22:27:35 -0000 1.8
***************
*** 11,14 ****
--- 11,15 ----
#include <rfta/parser/ParseContext.h>
#include <rfta/parser/SourceASTNode.h>
+ #include <rfta/parser/PlainTextDocument.h>
***************
*** 24,29 ****
const CppUnit::SourceLine &sourceLine )
{
! std::string expression = beforeIdentifier + identifier + afterIdentifier;
! SourceASTNodePtr sourceNode = SourceASTNode::create( expression, expression );
ParseContext context( sourceNode );
ASTNodePtr expressionNode = ASTNode::create( ASTNodeTypes::unparsedExpressionStatement,
--- 25,31 ----
const CppUnit::SourceLine &sourceLine )
{
! std::string expression = beforeIdentifier + identifier + afterIdentifier;
! SourcePtr sourceDoc = SourcePtr( new Source( TextDocumentPtr( new PlainTextDocument( expression ) ) ) );
! SourceASTNodePtr sourceNode = SourceASTNode::create( expression, expression, sourceDoc );
ParseContext context( sourceNode );
ASTNodePtr expressionNode = ASTNode::create( ASTNodeTypes::unparsedExpressionStatement,
***************
*** 47,51 ****
const CppUnit::SourceLine &sourceLine )
{
! SourceASTNodePtr sourceNode = SourceASTNode::create( expression, expression );
ParseContext context( sourceNode );
ASTNodePtr expressionNode = ASTNode::create( ASTNodeTypes::unparsedExpressionStatement,
--- 49,54 ----
const CppUnit::SourceLine &sourceLine )
{
! SourcePtr sourceDoc = SourcePtr( new Source( TextDocumentPtr( new PlainTextDocument( expression ) ) ) );
! SourceASTNodePtr sourceNode = SourceASTNode::create( expression, expression, sourceDoc );
ParseContext context( sourceNode );
ASTNodePtr expressionNode = ASTNode::create( ASTNodeTypes::unparsedExpressionStatement,
***************
*** 130,134 ****
source += "value;";
int length = source.length() - start;
! SourceASTNodePtr sourceNode = SourceASTNode::create( source, source );
ParseContext context( sourceNode );
ASTNodePtr expressionNode =
--- 133,138 ----
source += "value;";
int length = source.length() - start;
! SourcePtr sourceDoc = SourcePtr( new Source( TextDocumentPtr( new PlainTextDocument( source ) ) ) );
! SourceASTNodePtr sourceNode = SourceASTNode::create( source, source, sourceDoc );
ParseContext context( sourceNode );
ASTNodePtr expressionNode =
Index: SourceASTNode.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftaparser/SourceASTNode.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** SourceASTNode.cpp 16 Dec 2003 13:29:01 -0000 1.9
--- SourceASTNode.cpp 13 Jan 2004 22:27:35 -0000 1.10
***************
*** 17,24 ****
SourceASTNodePtr
SourceASTNode::create( const std::string &blankedSource,
! const std::string &realSource )
{
SourceASTNodePtr sourceNode( new SourceASTNode( blankedSource,
! realSource ) );
sourceNode->setSourceNode( sourceNode );
--- 17,26 ----
SourceASTNodePtr
SourceASTNode::create( const std::string &blankedSource,
! const std::string &realSource,
! const SourcePtr source )
{
SourceASTNodePtr sourceNode( new SourceASTNode( blankedSource,
! realSource,
! source ) );
sourceNode->setSourceNode( sourceNode );
***************
*** 28,32 ****
SourceASTNode::SourceASTNode( const std::string &blankedSource,
! const std::string &realSource )
: ASTNode( ASTNodeTypes::source,
ASTNodeWeakPtr(),
--- 30,35 ----
SourceASTNode::SourceASTNode( const std::string &blankedSource,
! const std::string &realSource,
! const SourcePtr source )
: ASTNode( ASTNodeTypes::source,
ASTNodeWeakPtr(),
***************
*** 35,38 ****
--- 38,42 ----
, realSource_( realSource )
, blankedSourceStart_( blankedSource_.c_str() )
+ , sourceDoc_ ( source )
{
/*
***************
*** 91,94 ****
--- 95,104 ----
}
+ SourcePtr
+ SourceASTNode::getSource() const
+ {
+ return sourceDoc_;
+ }
+
} // namespace Refactoring
Index: Parser.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftaparser/Parser.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** Parser.cpp 4 May 2003 18:19:45 -0000 1.13
--- Parser.cpp 13 Jan 2004 22:27:35 -0000 1.14
***************
*** 10,13 ****
--- 10,14 ----
#include <rfta/parser/ParserError.h>
#include <rfta/parser/ParserTools.h>
+ #include <rfta/parser/Source.h>
#include <xtl/CStringView.h>
#include <boost/lexical_cast.hpp>
***************
*** 76,88 ****
void
Parser::throwFailure( const ParserTools::ParseError &error )
! {
! Xtl::CStringView source( context_.getSourceNode()->getOriginalSource() );
int startLine = getLineNumberOf( start_ );
int endLine = getLineNumberOf( end_ );
int currentLine = getLineNumberOf( error.context_ );
boost::format formatter(
"%s\n"
! "- Parser lines: current = %d, start = %d, end = %d\n"
"- Current text: %s\n"
"- While analyzing:\n%s" );
--- 77,90 ----
void
Parser::throwFailure( const ParserTools::ParseError &error )
! {
int startLine = getLineNumberOf( start_ );
int endLine = getLineNumberOf( end_ );
int currentLine = getLineNumberOf( error.context_ );
+ std::string startFile = context_.getSourceNode()->getSource()->getSourceOrigin(SourceRange( getIndexOf( start_ ), 1 ) ).getIdentifier();
+ std::string endFile = context_.getSourceNode()->getSource()->getSourceOrigin(SourceRange( getIndexOf( end_ ), 1 ) ).getIdentifier();
boost::format formatter(
"%s\n"
! "- Parser lines: current = %d, start = %d (file: %s), end = %d (file: %s)\n"
"- Current text: %s\n"
"- While analyzing:\n%s" );
***************
*** 90,94 ****
std::string message =
(formatter % error.what()
! % currentLine % startLine % endLine
% Xtl::CStringView( error.context_ ).getSubString(0, 60).str()
% error.context_.getString().str() ).str();
--- 92,98 ----
std::string message =
(formatter % error.what()
! % currentLine
! % startLine % startFile.c_str()
! % endLine % endFile.c_str()
% Xtl::CStringView( error.context_ ).getSubString(0, 60).str()
% error.context_.getString().str() ).str();
***************
*** 103,109 ****
return -1;
! Xtl::CStringView source( context_.getSourceNode()->getOriginalSource() );
! const char *originalPosition = source.getStart() + getIndexOf( position );
! return std::count( source.getStart(), originalPosition, '\n' ) +1;
}
--- 107,111 ----
return -1;
! return context_.getSourceNode()->getSource()->getLineNumberOf(getIndexOf( position ));
}
Index: VariableDeclMutatorTest.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftaparser/VariableDeclMutatorTest.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** VariableDeclMutatorTest.cpp 21 Apr 2003 03:06:27 -0000 1.15
--- VariableDeclMutatorTest.cpp 13 Jan 2004 22:27:35 -0000 1.16
***************
*** 28,32 ****
const CppUnit::SourceLine &sourceLine )
{
! SourceASTNodePtr sourceNode = SourceASTNode::create( source, source );
ParseContext context( sourceNode );
--- 28,33 ----
const CppUnit::SourceLine &sourceLine )
{
! SourcePtr sourceDoc = SourcePtr( new Source( TextDocumentPtr( new PlainTextDocument( source ) ) ) );
! SourceASTNodePtr sourceNode = SourceASTNode::create( source, source, sourceDoc );
ParseContext context( sourceNode );
***************
*** 56,60 ****
const CppUnit::SourceLine &sourceLine )
{
! SourceASTNodePtr sourceNode = SourceASTNode::create( source, source );
ParseContext context( sourceNode );
--- 57,62 ----
const CppUnit::SourceLine &sourceLine )
{
! SourcePtr sourceDoc = SourcePtr( new Source( TextDocumentPtr( new PlainTextDocument( source ) ) ) );
! SourceASTNodePtr sourceNode = SourceASTNode::create( source, source, sourceDoc );
ParseContext context( sourceNode );
***************
*** 381,385 ****
int length = source.length() - 2 - startIndex;
! SourceASTNodePtr sourceNode = SourceASTNode::create( source, source );
ParseContext context( sourceNode );
--- 383,388 ----
int length = source.length() - 2 - startIndex;
! SourcePtr sourceDoc = SourcePtr( new Source( TextDocumentPtr( new PlainTextDocument( source ) ) ) );
! SourceASTNodePtr sourceNode = SourceASTNode::create( source, source, sourceDoc );
ParseContext context( sourceNode );
Index: UnparsedDeclarationMutatorTest.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftaparser/UnparsedDeclarationMutatorTest.cpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** UnparsedDeclarationMutatorTest.cpp 24 Sep 2003 20:29:59 -0000 1.16
--- UnparsedDeclarationMutatorTest.cpp 13 Jan 2004 22:27:35 -0000 1.17
***************
*** 29,33 ****
const CppUnit::SourceLine &sourceLine )
{
! SourceASTNodePtr sourceNode = SourceASTNode::create( source, source );
ParseContext context( sourceNode );
--- 29,34 ----
const CppUnit::SourceLine &sourceLine )
{
! SourcePtr sourceDoc = SourcePtr( new Source( TextDocumentPtr( new PlainTextDocument( source ) ) ) );
! SourceASTNodePtr sourceNode = SourceASTNode::create( source, source, sourceDoc );
ParseContext context( sourceNode );
|
|
From: <net...@us...> - 2004-01-13 22:27:39
|
Update of /cvsroot/cpptool/rfta/src/astdumper
In directory sc8-pr-cvs1:/tmp/cvs-serv10043/astdumper
Modified Files:
ASTDumper.h Main.cpp ASTDumper.cpp
Log Message:
-- integrated preprocessor (replaced all NonSemanticBlanker)
Index: ASTDumper.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/astdumper/ASTDumper.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** ASTDumper.h 1 May 2003 09:08:09 -0000 1.3
--- ASTDumper.h 13 Jan 2004 22:27:35 -0000 1.4
***************
*** 28,31 ****
--- 28,32 ----
bool dump( const std::string &source,
+ const boost::filesystem::path &sourceDir,
const boost::filesystem::path &logDir,
const std::string &title );
***************
*** 33,36 ****
--- 34,38 ----
private:
bool writeAST( const std::string &source,
+ const boost::filesystem::path &sourcePath,
HTMLWriter &writer );
};
Index: Main.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/astdumper/Main.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** Main.cpp 26 May 2003 21:13:52 -0000 1.5
--- Main.cpp 13 Jan 2004 22:27:35 -0000 1.6
***************
*** 49,54 ****
else
{
! try
! {
boost::filesystem::path path( argv[1],
boost::filesystem::native );
--- 49,54 ----
else
{
! //try
! {
boost::filesystem::path path( argv[1],
boost::filesystem::native );
***************
*** 59,65 ****
Refactoring::ASTDumper dumper;
! return dumper.dump( source, outputPath, path.string() ) ? 0 : 2;
}
! catch ( std::exception &e )
{
std::cerr << "Fatal error:\n"
--- 59,65 ----
Refactoring::ASTDumper dumper;
! return dumper.dump( source, path.branch_path(), outputPath, path.string() ) ? 0 : 2;
}
! /* catch ( std::exception &e )
{
std::cerr << "Fatal error:\n"
***************
*** 68,72 ****
<< e.what() << std::endl;
return 2;
! }
}
}
\ No newline at end of file
--- 68,72 ----
<< e.what() << std::endl;
return 2;
! }*/
}
}
\ No newline at end of file
Index: ASTDumper.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/astdumper/ASTDumper.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** ASTDumper.cpp 20 Dec 2003 09:03:49 -0000 1.10
--- ASTDumper.cpp 13 Jan 2004 22:27:35 -0000 1.11
***************
*** 12,21 ****
#include <rfta/parser/ASTNodeVisitor.h>
#include <rfta/parser/MaxLODMutator.h>
! #include <rfta/parser/NonSemanticBlanker.h>
#include <rfta/parser/ParseContext.h>
#include <rfta/parser/ParserError.h>
#include <rfta/parser/SourceASTNode.h>
#include <rfta/parser/DeclarationListParser.h>
!
namespace Refactoring
--- 12,23 ----
#include <rfta/parser/ASTNodeVisitor.h>
#include <rfta/parser/MaxLODMutator.h>
! #include <rfta/parser/PreProcessor.h>
#include <rfta/parser/ParseContext.h>
#include <rfta/parser/ParserError.h>
#include <rfta/parser/SourceASTNode.h>
#include <rfta/parser/DeclarationListParser.h>
! #include <rfta/parser/FileSourceManager.h>
! #include <rfta/parser/Source.h>
! #include <rfta/parser/PlainTextDocument.h>
namespace Refactoring
***************
*** 90,94 ****
writer_.write( node->getType().getName() );
writer_.lineBreak();
! writer_.writePreformated( node->getOriginalText() );
}
--- 92,97 ----
writer_.write( node->getType().getName() );
writer_.lineBreak();
! //writer_.writePreformated( node->getOriginalText() );
! writer_.writePreformated( node->getBlankedText() );
}
***************
*** 135,138 ****
--- 138,142 ----
bool
ASTDumper::dump( const std::string &source,
+ const boost::filesystem::path &sourcePath,
const boost::filesystem::path &filePath,
const std::string &title )
***************
*** 156,160 ****
anchorTagger.end();
writer.writeH2( "Abstract syntax tree:" );
! bool succeed = writeAST( source, writer );
writer.writeFooter();
--- 160,164 ----
anchorTagger.end();
writer.writeH2( "Abstract syntax tree:" );
! bool succeed = writeAST( source, sourcePath, writer );
writer.writeFooter();
***************
*** 166,177 ****
bool
ASTDumper::writeAST( const std::string &source,
HTMLWriter &writer )
{
! PPDirectiveListenerPtr nullListener( new NullPPDirectiveListener() );
! std::string blankedSource;
! NonSemanticBlanker blanker( source, blankedSource, nullListener );
! blanker.blank();
! SourceASTNodePtr sourceAST = SourceASTNode::create( blankedSource, source );
ParseContext context( sourceAST );
DeclarationListParser parser( context,
--- 170,194 ----
bool
ASTDumper::writeAST( const std::string &source,
+ const boost::filesystem::path &sourcePath,
HTMLWriter &writer )
{
! FileSourceManager manager;
! manager.setRoot(sourcePath);
! manager.setInclude("C:\\Programme\\Microsoft Visual Studio\\VC98\\INCLUDE");
! SourcePtr sourceDoc = SourcePtr( new Source( TextDocumentPtr( new PlainTextDocument( source ) ) ) );
!
! PreProcessorContext ppcontext( manager );
! PreProcessor proc( sourceDoc, ppcontext );
! ppcontext.addMacro("__cplusplus","");
!
! // Not all system headers are handled correctly at the moment - so turn off include parsing:
! proc.setOption(PreProcessor::skipIncludes);
!
! printf("Preprocess file...\n");
! std::string blankedSource = proc.process();
! printf("finished...\n");
!
! SourceASTNodePtr sourceAST = SourceASTNode::create( blankedSource, source, sourceDoc );
ParseContext context( sourceAST );
DeclarationListParser parser( context,
***************
*** 180,183 ****
--- 197,201 ----
bool succeed = true;
+ printf("Parse...\n");
try
{
***************
*** 194,200 ****
--- 212,222 ----
succeed = false;
}
+
+ printf("finished...\n");
+ printf("Dump...\n");
ASTDumpVisitor visitor( writer, sourceAST );
visitor.visitNode( sourceAST );
+ printf("finished...\n");
return succeed;
}
|
|
From: <net...@us...> - 2004-01-13 22:27:39
|
Update of /cvsroot/cpptool/rfta/src/rftavc6addin
In directory sc8-pr-cvs1:/tmp/cvs-serv10043/rftavc6addin
Modified Files:
Commands.cpp
Log Message:
-- integrated preprocessor (replaced all NonSemanticBlanker)
Index: Commands.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftavc6addin/Commands.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** Commands.cpp 18 May 2003 09:19:10 -0000 1.6
--- Commands.cpp 13 Jan 2004 22:27:36 -0000 1.7
***************
*** 10,13 ****
--- 10,14 ----
#include "SplitLocaleVariableDialog.h"
#include "VCLineBasedTextDocument.h"
+ #include <rfta/parser/Source.h>
#include <rfta/refactoring/RefactoringError.h>
#include <rfta/refactoring/RenameTempRefactoring.h>
***************
*** 193,197 ****
try
{
! Refactoring::RenameTempRefactoring refactoring( document,
selection.getStartIndex() );
--- 194,201 ----
try
{
! Refactoring::SourcePtr sourceDoc( new Refactoring::Source( document.shared_from_this() ) );
! Refactoring::NullSourceManager manager; //< TODO Change to IDE managed file access
! Refactoring::RenameTempRefactoring refactoring( sourceDoc,
! manager,
selection.getStartIndex() );
***************
*** 227,232 ****
try
{
! Refactoring::InlineTempRefactoring refactoring( document,
! selection.getStartIndex() );
bool addBraces = refactoring.areBracesSuggested();
--- 231,239 ----
try
{
! Refactoring::SourcePtr sourceDoc( new Refactoring::Source( document.shared_from_this() ) );
! Refactoring::NullSourceManager manager; //< TODO Change to IDE managed file access
! Refactoring::InlineTempRefactoring refactoring( sourceDoc,
! manager,
! selection.getStartIndex() );
bool addBraces = refactoring.areBracesSuggested();
***************
*** 262,267 ****
try
{
! Refactoring::SplitTempRefactoring refactoring( document,
! selection.getStartIndex() );
SplitLocaleVariableDialog dialog;
--- 269,277 ----
try
{
! Refactoring::SourcePtr sourceDoc( new Refactoring::Source( document.shared_from_this() ) );
! Refactoring::NullSourceManager manager; //< TODO Change to IDE managed file access
! Refactoring::SplitTempRefactoring refactoring( sourceDoc,
! manager,
! selection.getStartIndex() );
SplitLocaleVariableDialog dialog;
|
|
From: <net...@us...> - 2004-01-13 22:27:38
|
Update of /cvsroot/cpptool/rfta/src/eclipseplugin/CppBridge
In directory sc8-pr-cvs1:/tmp/cvs-serv10043/eclipseplugin/CppBridge
Modified Files:
EclipseBridge_RenameLocaleVariable.cpp EclipseDocumentHelper.h
Log Message:
-- integrated preprocessor (replaced all NonSemanticBlanker)
Index: EclipseBridge_RenameLocaleVariable.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/eclipseplugin/CppBridge/EclipseBridge_RenameLocaleVariable.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** EclipseBridge_RenameLocaleVariable.cpp 15 Feb 2003 13:32:03 -0000 1.1
--- EclipseBridge_RenameLocaleVariable.cpp 13 Jan 2004 22:27:35 -0000 1.2
***************
*** 8,11 ****
--- 8,12 ----
#include <rfta/refactoring/RefactoringError.h>
#include <rfta/refactoring/RenameTempRefactoring.h>
+ #include <rfta/parser/Source.h>
#include "..\generatedcode\org_eclipse_cpprefactoring_internal_EclipseBridge.h"
***************
*** 22,26 ****
LONG _stdcall testexc(struct _EXCEPTION_POINTERS *ExceptionInfo)
{
! MessageBox(NULL,"Userdefined C++ Exception Handler. Choose CANCEL in next dialog to debug.","C++ Exception Catched",MB_OK);
return EXCEPTION_CONTINUE_SEARCH;
}
--- 23,27 ----
LONG _stdcall testexc(struct _EXCEPTION_POINTERS *ExceptionInfo)
{
! MessageBox(NULL,"Userdefined C++ Exception handler within Refactoring-Eclipse-Plugin. Choose CANCEL in next dialog to debug.","C++ Exception Catched",MB_OK);
return EXCEPTION_CONTINUE_SEARCH;
}
***************
*** 33,37 ****
#endif
! /**
* function is called from eclipse environment and does
* apply RenameLocalVar-Refactoring.
--- 34,38 ----
#endif
! /**
* function is called from eclipse environment and does
* apply RenameLocalVar-Refactoring.
***************
*** 49,52 ****
--- 50,56 ----
jclass JavaException = 0;
EclipseHandler * hdl = 0;
+
+ // create a simple source manager (TODO: integrate this with the IDE file managment)
+ Refactoring::NullSourceManager manager;
try {
***************
*** 59,63 ****
{
EclipseDocumentHelper& doc = hdl->getActiveDocument();
! Refactoring::RenameTempRefactoring refactoring( doc, doc.getSelectionRange().getStartIndex() );
oldname = refactoring.getOldVariableName().c_str();
--- 63,68 ----
{
EclipseDocumentHelper& doc = hdl->getActiveDocument();
! Refactoring::SourcePtr sourceDoc_ = Refactoring::SourcePtr( new Refactoring::Source(doc.shared_from_this()) );
! Refactoring::RenameTempRefactoring refactoring( sourceDoc_, manager, doc.getSelectionRange().getStartIndex() );
oldname = refactoring.getOldVariableName().c_str();
Index: EclipseDocumentHelper.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/eclipseplugin/CppBridge/EclipseDocumentHelper.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** EclipseDocumentHelper.h 16 May 2003 19:55:01 -0000 1.2
--- EclipseDocumentHelper.h 13 Jan 2004 22:27:35 -0000 1.3
***************
*** 11,15 ****
#include <jni.h>
#include <string>
! #include <rfta/refactoring/TextDocument.h>
class EclipseDocumentHelper: public Refactoring::TextDocument {
--- 11,15 ----
#include <jni.h>
#include <string>
! #include <rfta/parser/TextDocument.h>
class EclipseDocumentHelper: public Refactoring::TextDocument {
|
|
From: <net...@us...> - 2004-01-13 22:25:30
|
Update of /cvsroot/cpptool/rfta/src/rftaparser
In directory sc8-pr-cvs1:/tmp/cvs-serv9723/rftaparser
Added Files:
PlainTextDocument.cpp
Log Message:
-- moved closer to preprocessor
--- NEW FILE: PlainTextDocument.cpp ---
// //////////////////////////////////////////////////////////////////////////
// (c)Copyright 2002, Baptiste Lepilleur.
// Created: 2002/10/31
// //////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include <rfta/parser/PlainTextDocument.h>
namespace Refactoring
{
PlainTextDocument::PlainTextDocument()
{
}
PlainTextDocument::PlainTextDocument( const std::string &content )
: content_( content )
{
}
PlainTextDocument::~PlainTextDocument()
{
}
const std::string
PlainTextDocument::getAllText() const
{
return content_;
}
std::string
PlainTextDocument::getTextRange( const Refactoring::SourceRange &range )
{
return content_.substr( range.getStartIndex(),
range.getLength() );
}
void
PlainTextDocument::replaceTextRange( const Refactoring::SourceRange &range,
const std::string &text )
{
std::string::iterator it = content_.begin() + range.getStartIndex();
content_.replace( it, it + range.getLength(), text );
}
} // namespace Refactoring
|
|
From: <net...@us...> - 2004-01-13 22:18:30
|
Update of /cvsroot/cpptool/rfta/src/rftaparser
In directory sc8-pr-cvs1:/tmp/cvs-serv8283/rftaparser
Modified Files:
PreProcessorTest.cpp PreProcessorTest.h PreProcessor.cpp
Added Files:
FileSourceManager.cpp PositionTranslator.cpp
PositionTranslatorTest.cpp PositionTranslatorTest.h
PreProcessorContext.cpp Source.cpp SourceTest.cpp SourceTest.h
Log Message:
preprocessor implementation
--- NEW FILE: FileSourceManager.cpp ---
// //////////////////////////////////////////////////////////////////////////
// Source file FileSourceManager.cpp for class FileSourceManager
// (c)Copyright 2003, Andre Baresel.
// Created: 2003/12/28
// //////////////////////////////////////////////////////////////////////////
#include <iosfwd>
#include <fstream>
#include <iostream>
#include <stdexcept>
#include <string>
#include <rfta/parser/FileSourceManager.h>
#include <rfta/parser/Source.h>
#include <rfta/parser/PlainTextDocument.h>
#include <boost/format.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/filesystem//operations.hpp>
static std::string readSourceFile( const boost::filesystem::path &path )
{
boost::filesystem::ifstream stream( path );
if (!stream.is_open()) return "";
std::string source;
while ( !stream.eof() )
{
std::string line;
std::getline( stream, line );
source += line;
source += '\n';
}
return source;
}
namespace Refactoring
{
SourcePtr
FileSourceManager::open(std::string sourceName)
{
if (sourceName=="stdexcept")
int i = 0;
// try original name
boost::filesystem::path path( sourceName,
boost::filesystem::native );
// try relative path to root source
if (!boost::filesystem::exists(path))
path = sourcePath_ / path;
// try include paths:
if (!boost::filesystem::exists(path))
{
PathList::iterator i;
boost::filesystem::path sourcepath( sourceName,
boost::filesystem::native );
for (i= includeDirList_.begin(); i!=includeDirList_.end(); i++)
{
if (boost::filesystem::exists(*i / sourcepath))
{
path = *i / sourcepath;
break;
}
}
}
std::string source;
if (boost::filesystem::exists(path))
source = readSourceFile( path );
TextDocumentPtr doc(new PlainTextDocument(source));
SourcePtr result(new Source(doc, path.native_file_string()));
return result;
}
} // namespace Refactoring
--- NEW FILE: PositionTranslator.cpp ---
// //////////////////////////////////////////////////////////////////////////
// Source file PositionTranslator.cpp for class PositionTranslator
// (c)Copyright 2003, Andre Baresel.
// Created: 2003/12/31
// //////////////////////////////////////////////////////////////////////////
#include <stdafx.h>
#include <rfta/parser/PositionTranslator.h>
namespace Refactoring
{
void
PositionTranslator::addReplacement(const SourceRange& range, int replacementLen)
{
TranslationMap::const_iterator before = getLower(range.getStartIndex());
SourceRange tmp_preprocessed = range;
int diffBefore = 0;
if ( before != translationMap_.end() && before->first < range.getStartIndex() )
{
diffBefore = before->second.offsetDifference_;
tmp_preprocessed.moveStartIndexBy(-diffBefore);
}
tmp_preprocessed.setLength(replacementLen);
Transposition entry;
entry.origin_ = range;
entry.offsetDifference_ = range.getLength()-replacementLen+diffBefore;
entry.preprocessed_ = tmp_preprocessed;
translationMap_[tmp_preprocessed.getStartIndex()] = entry;
int moveBy = range.getLength()-replacementLen;
changeFollowingTranslation(translationMap_.find(tmp_preprocessed.getStartIndex()),moveBy);
}
void
PositionTranslator::changeFollowingTranslation(TranslationMap::iterator first, int moveBy)
{
if (moveBy == 0) return; // nothing to do.
if (moveBy < 0)
{
TranslationMap::iterator it = translationMap_.end();
it--;
while (it != first)
{
Transposition entry = it->second;
entry.preprocessed_.moveStartIndexBy(-moveBy);
entry.offsetDifference_ += moveBy;
TranslationMap::iterator todel = it;it--;
translationMap_.erase(todel);
translationMap_[entry.preprocessed_.getStartIndex()] = entry;
}
} else
{
TranslationMap::iterator it = first;
it++;
while (it != translationMap_.end())
{
Transposition entry = it->second;
entry.preprocessed_.moveStartIndexBy(-moveBy);
entry.offsetDifference_ += moveBy;
TranslationMap::iterator todel = it;it++;
translationMap_.erase(todel);
translationMap_[entry.preprocessed_.getStartIndex()] = entry;
}
}
}
/**
* translates the position of preprocessed source code into
* the original range.
*/
SourceRange
PositionTranslator::translate(const SourceRange& range) const
{
TranslationMap::const_iterator before = getLower(range.getStartIndex());
SourceRange result = range;
if (before != translationMap_.end() && before->first < range.getStartIndex())
{
if (range.getStartIndex() < before->second.preprocessed_.getEndIndex())
{
if (before == translationMap_.begin())
return result;
before--;
}
result.moveStartIndexBy(before->second.offsetDifference_);
}
return result;
}
/**
* translates the position of original source code into
* the range in preprocessed.
*/
SourceRange
PositionTranslator::reverseTranslate(const SourceRange& range) const
{
SourceRange result=range;
TranslationMap::const_iterator it = translationMap_.begin();
int offset = 0;
while (it!=translationMap_.end() && it->second.origin_.getStartIndex() <= range.getStartIndex())
{
it++;
}
// no translation before:
if (it == translationMap_.begin())
return result;
it--;
// check if inside translation range:
if (range.getStartIndex() < it->second.origin_.getEndIndex() )
{
if (it == translationMap_.begin()) // inside first translation--> leave range as it is
return result;
it--;
}
result.moveStartIndexBy(-it->second.offsetDifference_);
return result;
}
PositionTranslator::TranslationMap::const_iterator
PositionTranslator::getLower(int index) const
{
TranslationMap::const_iterator it = translationMap_.begin();
while (it!=translationMap_.end() && it->first < index)
it++;
if (it != translationMap_.begin()) it--;
return it;
}
PositionTranslator::TranslationMap::const_iterator
PositionTranslator::getUpper(int index) const
{
TranslationMap::const_iterator it = translationMap_.begin();
while (it!=translationMap_.end() && it->first <= index)
it++;
if (it!=translationMap_.end()) it++;
return it;
}
} // namespace Refactoring
--- NEW FILE: PositionTranslatorTest.cpp ---
// //////////////////////////////////////////////////////////////////////////
// Source file PositionTranslatorTest.cpp for class PositionTranslatorTest
// (c)Copyright 2003, Andre Baresel
// Created: 2003/12/13
// //////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "PositionTranslatorTest.h"
#include <rfta/parser/PositionTranslator.h>
namespace Refactoring
{
RFTAPARSER_TEST_SUITE_REGISTRATION( PositionTranslatorTest );
PositionTranslatorTest::PositionTranslatorTest()
{
}
PositionTranslatorTest::~PositionTranslatorTest()
{
}
void
PositionTranslatorTest::setUp()
{
}
void
PositionTranslatorTest::tearDown()
{
}
void
PositionTranslatorTest::testExtensions()
{
PositionTranslator trans;
/**
* test shows position translation for three ranges enlarged by different
* replacements:
*/
SourceRange r1(0,10);
trans.addReplacement(r1,20); // increase size by 10 = (20-10)
SourceRange r2(20,10);
trans.addReplacement(r2,25); // increase size by 15 = (25-10)
SourceRange r3(15,5);
trans.addReplacement(r3,10); // increase size by 5 = (10-5)
// original source ranges:
// |x10x| 5 |x 5x|x10x| (the 'x' mark enlarged ranges)
// equivalent source ranges after replacements:
// |+20+| 5 |+10+|+25+| (the '+' mark the new size)
// now translate positions of 'source-after-replacment' into original positions.
CPPUNIT_ASSERT_EQUAL(SourceRange(5,2),trans.translate(SourceRange(5,2))); /* within first replacement -> no change */
CPPUNIT_ASSERT_EQUAL(SourceRange(11,3),trans.translate(SourceRange(21,3))); /* after first replc. -> move by 10 */
CPPUNIT_ASSERT_EQUAL(SourceRange(15,3),trans.translate(SourceRange(25,3))); /* within second replc. -> move by 10 */
CPPUNIT_ASSERT_EQUAL(SourceRange(20,3),trans.translate(SourceRange(35,3))); /* after second replc. -> move by 15 */
CPPUNIT_ASSERT_EQUAL(SourceRange(30,1),trans.translate(SourceRange(60,1))); /* after third replc. -> move by 30 */
}
void
PositionTranslatorTest::testShorten()
{
PositionTranslator trans;
// source ranges of original code and their change by replacements
SourceRange r1(30,10);
trans.addReplacement(r1,5);
SourceRange r2(20,5);
trans.addReplacement(r2,1);
SourceRange r3(5,15);
trans.addReplacement(r3,5);
// original source:
// 5 |x15x|x5x| 5 |x10x| (the 'x' mark reduced ranges)
// source after replacements:
// 5 |-5-|-1-| 5 |-5-| (the '-' mark the new size)
// now translate positions of 'source-after-replacment' into original positions.
CPPUNIT_ASSERT_EQUAL(SourceRange(0,2),trans.translate(SourceRange(0,2))); /* before first replacement -> no change */
CPPUNIT_ASSERT_EQUAL(SourceRange(7,1),trans.translate(SourceRange(7,1))); /* within first replacement -> no change */
CPPUNIT_ASSERT_EQUAL(SourceRange(20,3),trans.translate(SourceRange(10,3))); /* within second replc. -> move by -10 */
CPPUNIT_ASSERT_EQUAL(SourceRange(26,3),trans.translate(SourceRange(12,3))); /* after second replc. -> move by -14 */
CPPUNIT_ASSERT_EQUAL(SourceRange(31,3),trans.translate(SourceRange(17,3))); /* within third replc. -> move by -14 */
CPPUNIT_ASSERT_EQUAL(SourceRange(41,5),trans.translate(SourceRange(22,5))); /* after third replc. -> move by -19 */
}
void
PositionTranslatorTest::testMixture()
{
PositionTranslator trans;
SourceRange r1(5,15);
trans.addReplacement(r1,5);
SourceRange r2(30,10);
trans.addReplacement(r2,14);
SourceRange r3(20,5);
trans.addReplacement(r3,10);
SourceRange r4(25,5);
trans.addReplacement(r4,1);
// original source:
// 5 |x15x|x5x|x5x|x10x| (the 'x' mark reduced ranges)
// source after replacements:
// 5 |-5-|+10+|-1-|+14+| (the '-/+' mark the new size)
// now translate positions of 'source-after-replacment' into original positions.
CPPUNIT_ASSERT_EQUAL(SourceRange(0,2),trans.translate( SourceRange(0,2))); /* before first replacement -> no change */
CPPUNIT_ASSERT_EQUAL(SourceRange(7,1),trans.translate( SourceRange(7,1))); /* within first replacement -> no change */
CPPUNIT_ASSERT_EQUAL(SourceRange(20,3),trans.translate(SourceRange(10,3))); /* within second replc. -> move by -10 */
CPPUNIT_ASSERT_EQUAL(SourceRange(25,3),trans.translate(SourceRange(20,3))); /* within third replc. -> move by -15 */
CPPUNIT_ASSERT_EQUAL(SourceRange(31,5),trans.translate(SourceRange(22,5))); /* within fourth replc. -> move by -9 */
CPPUNIT_ASSERT_EQUAL(SourceRange(40,5),trans.translate(SourceRange(35,5))); /* after fourth replc. -> move by -5 */
}
void
PositionTranslatorTest::testReverseTranslate()
{
PositionTranslator trans;
SourceRange r1(5,15);
trans.addReplacement(r1,5);
SourceRange r2(30,10);
trans.addReplacement(r2,14);
SourceRange r3(20,5);
trans.addReplacement(r3,10);
SourceRange r4(25,5);
trans.addReplacement(r4,1);
// original source:
// 5 |x15x|x5x|x5x|x10x| (the 'x' mark reduced ranges)
// source after replacements:
// 5 |-5-|+10+|-1-|+14+| (the '-/+' mark the new size)
// now translate positions of 'source-after-replacment' into original positions.
CPPUNIT_ASSERT_EQUAL(SourceRange(0,2),trans.reverseTranslate( SourceRange(0,2))); /* before first replacement -> no change */
CPPUNIT_ASSERT_EQUAL(SourceRange(7,1),trans.reverseTranslate( SourceRange(7,1))); /* within first replacement -> no change */
CPPUNIT_ASSERT_EQUAL(SourceRange(10,3),trans.reverseTranslate(SourceRange(20,3))); /* within second replc. -> move by -10 */
CPPUNIT_ASSERT_EQUAL(SourceRange(20,3),trans.reverseTranslate(SourceRange(25,3))); /* within third replc. -> move by -15 */
CPPUNIT_ASSERT_EQUAL(SourceRange(22,5),trans.reverseTranslate(SourceRange(31,5))); /* within fourth replc. -> move by -9 */
CPPUNIT_ASSERT_EQUAL(SourceRange(35,5),trans.reverseTranslate(SourceRange(40,5))); /* after fourth replc. -> move by -5 */
}
} // namespace Refactoring
--- NEW FILE: PositionTranslatorTest.h ---
// //////////////////////////////////////////////////////////////////////////
// Header file PositionTranslatorTest.h for class PositionTranslatorTest
// (c)Copyright 2003, Andre Baresel
// Created: 2003/12/31
// //////////////////////////////////////////////////////////////////////////
#ifndef RFTA_POSITIONTRANSLATORTEST_H
#define RFTA_POSITIONTRANSLATORTEST_H
#include "ParserTesting.h"
namespace Refactoring
{
/// Unit tests for PreProcessor
class PositionTranslatorTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( PositionTranslatorTest );
CPPUNIT_TEST( testExtensions );
CPPUNIT_TEST( testShorten );
CPPUNIT_TEST( testMixture );
CPPUNIT_TEST( testReverseTranslate );
CPPUNIT_TEST_SUITE_END();
public:
/*! Constructs a PositionTranslatorTest object.
*/
PositionTranslatorTest();
/// Destructor.
virtual ~PositionTranslatorTest();
void setUp();
void tearDown();
void testExtensions();
void testShorten();
void testMixture();
void testReverseTranslate();
private:
/// Prevents the use of the copy constructor.
PositionTranslatorTest( const PositionTranslatorTest &other );
/// Prevents the use of the copy operator.
void operator =( const PositionTranslatorTest &other );
private:
};
// Inlines methods for PositionTranslatorTest:
// ----------------------------------------
} // namespace Refactoring
#endif // RFTA_POSITIONTRANSLATORTEST_H
--- NEW FILE: PreProcessorContext.cpp ---
// //////////////////////////////////////////////////////////////////////////
// Source file PreProcessorContext.h for class PreProcessorContext
// (c)Copyright 2003, Andre Baresel
// Created: 2003/12/13
// //////////////////////////////////////////////////////////////////////////
#include <stdafx.h>
#include <rfta/parser/PreProcessorContext.h>
#include <rfta/parser/PreProcessorError.h>
#include <xtl/Type.h>
#include <xtl/CStringView.h>
#include <rfta/parser/ParserTools.h>
#include <rfta/parser/SourceManager.h>
#include <rfta/parser/PreProcessor.h>
#include <rfta/parser/Source.h>
namespace Refactoring
{
bool
PreProcessorContext::isMacroIdentifier( std::string identifier )
{
MacroDefMap::iterator i = macroDef_.find(identifier);
return i != macroDef_.end();
}
std::string
PreProcessorContext::getMacroReplacement( std::string macroident )
{
MacroDefMap::iterator i = macroDef_.find(macroident);
if (i == macroDef_.end())
ThrowPreProcessError(std::string("Macro '")+macroident+"'is not defined.");
return i->second;
}
void
PreProcessorContext::addMacro(std::string ident, std::string replacement)
{
macroDef_[ident] = replacement;
}
/**
* set 'source' as active source and store
* the former source-ptr.
*/
void
PreProcessorContext::enterSource(SourcePtr source)
{
sources_.push(source_);
source_ = source;
}
/**
* leave current source and return to parent.
* (restore former source-ptr)
*/
void
PreProcessorContext::leaveSource()
{
source_ = sources_.top();
sources_.pop();
}
} // namespace Refactoring
--- NEW FILE: Source.cpp ---
// //////////////////////////////////////////////////////////////////////////
// Implementation file Source.cpp for class Source
// (c)Copyright 2003, Andre Baresel.
// Created: 2003/12/25
// //////////////////////////////////////////////////////////////////////////
#include <stdafx.h>
#include <rfta/parser/Source.h>
namespace Refactoring
{
Source::Source(TextDocumentPtr document)
: document_(document)
{
}
Source::Source(TextDocumentPtr document, std::string identifier)
: document_(document)
, identifier_(identifier)
{
}
Source::~Source()
{
}
/**
* returns the source that holds the range.
* (does care about includes)
*/
Source&
Source::getSourceOrigin(const SourceRange& range)
{
IncludeList::const_iterator i = getSourceOriginInternal(range);
if (i!=includeList_.end())
{
return *(i->include_);
}
else
{
return *this;
}
}
/**
* return the source text of the range in original file.
* (does translate the position and uses the original source)
*/
std::string
Source::getOriginalText(const SourceRange& range)
{
IncludeList::const_iterator where = getSourceOriginInternal(range);
// check if the range is located in include source:
if (where != includeList_.end())
{
SourceRange r = translator_.translate(range);
r.moveStartIndexBy(-where->range_.getStartIndex());
// get it from included source
return where->include_->getOriginalText(r);
}
// translate position in current source:
SourceRange original = translator_.translate(range);
std::string completeTxt = getOriginalText();
int len = original.getLength();
// TODO: throw exception:
if (completeTxt.length() < original.getStartIndex() + len)
len = completeTxt.length() - original.getStartIndex();
return std::string( completeTxt.c_str() + original.getStartIndex(),
len );
}
/**
* returns the range in original source
*/
SourceRange
Source::getRangeOrigin(const SourceRange& range) const
{
IncludeList::const_iterator where = getSourceOriginInternal(range);
// check if the range is located in include source:
if (where != includeList_.end())
{
SourceRange r = translator_.translate(range);
r.moveStartIndexBy(-where->range_.getStartIndex());
// get it from included source
return where->include_->getRangeOrigin(r);
}
return translator_.translate(range);
}
/**
* returns the range in preprocessed source
*/
SourceRange
Source::getRangePreProcessed(const SourceRange& range)
{
return translator_.reverseTranslate(range);
}
/**
* returns the includelist iterator position that holds the range.
* --> end() in case of no include
*/
Source::IncludeList::const_iterator
Source::getSourceOriginInternal(const SourceRange& range) const
{
IncludeList::const_iterator i;
SourceRange first = range;
first.setLength(1); // check if first character falls into the include-range
for (i=includeList_.begin(); i!=includeList_.end(); i++)
{
if (i->preprocessedRange_.contains(first))
{
break;
}
}
return i;
}
/**
* store range of an include
*/
void
Source::registerInclude(const SourceRange& range, int includeLength, const SourcePtr include)
{
IncludeEntry entry;
entry.include_ = include;
entry.range_ = range;
entry.preprocessedRange_ = translator_.reverseTranslate( range );
entry.preprocessedRange_.setLength( includeLength );
includeList_.push_back(entry);
translator_.addReplacement(range,includeLength);
}
/**
* store range of a text replacement (e.g. Macro)
*/
void
Source::registerReplacement(const SourceRange& range, int replacementLen)
{
translator_.addReplacement(range,replacementLen);
}
/**
* @param index position in preprocessed source text.
*
* @return line number
*/
int
Source::getLineNumberOf(int index) const
{
SourceRange range(index,1);
IncludeList::const_iterator where = getSourceOriginInternal(range);
if (where != includeList_.end())
{
SourceRange r = translator_.translate(range);
r.moveStartIndexBy(-where->range_.getStartIndex());
// get it from included source
return where->include_->getLineNumberOf(r.getStartIndex());
}
SourceRange r = getRangeOrigin(range);
std::string completeTxt = document_->getAllText();
return std::count( completeTxt.c_str(), completeTxt.c_str()+r.getStartIndex(), '\n' ) +1;
}
} // namespace Refactoring
--- NEW FILE: SourceTest.cpp ---
// //////////////////////////////////////////////////////////////////////////
// Source file SourceTest.cpp for class SourceTest
// (c)Copyright 2004, Andre Baresel
// Created: 2004/1/1
// //////////////////////////////////////////////////////////////////////////
#include <stdafx.h>
#include "SourceTest.h"
#include "KeyedString.h"
#include <rfta/parser/Source.h>
#include "TextDocumentMock.h"
namespace Refactoring
{
RFTAPARSER_TEST_SUITE_REGISTRATION( SourceTest );
SourceTest::SourceTest()
{
}
SourceTest::~SourceTest()
{
}
void
SourceTest::setUp()
{
}
void
SourceTest::tearDown()
{
}
void
SourceTest::testSimpleInclude()
{
/**
* 'source' object is storing original source text and
* links to includes. It can restore offset from preprocessed source to
* original source text. This is tested here.
*/
// original source:
Testing::KeyedString str;
str.addKeyed("BEFORE", "int var_before;\n");
str.addKeyed("INCLUDE","#include <header.h>\n");
str.addKeyed("AFTER", "int var_after;\n");
TextDocumentPtr doc = TextDocumentPtr(new Testing::TextDocumentMock(str));
Source src(doc);
// source of include:
std::string doc2_txt = "int inside_header;";
TextDocumentPtr doc2 = TextDocumentPtr(new Testing::TextDocumentMock(doc2_txt));
SourcePtr include = SourcePtr(new Source(doc2));
// preprocessor operation that registers an include:
SourceRange directive_range(str.getKeyedIndex("INCLUDE",0),str.getKeyedLen("INCLUDE",0));
src.registerInclude(directive_range,doc2_txt.length(),SourcePtr(include));
// for testing we create the corresponding preprocessed source
// just to have offset to be restored:
Testing::KeyedString preprocessed;
preprocessed.addKeyed("BEFORE", "int var_before;") << " ";
preprocessed.addKeyed("INCLUDE","int inside_header;");
preprocessed.addKeyed("AFTER", "int var_after;");
// this are the offsets which will be tested:
SourceRange before_range(SourceRange(preprocessed.getKeyedIndex("BEFORE",0),preprocessed.getKeyedLen("BEFORE",0)));
SourceRange include_range(SourceRange(preprocessed.getKeyedIndex("INCLUDE",0),preprocessed.getKeyedLen("INCLUDE",0)));
SourceRange after_range(SourceRange(preprocessed.getKeyedIndex("AFTER",0),preprocessed.getKeyedLen("AFTER",0)));
// use the offsets of preprocessed text to get the original source text:
// imagine that 'source' does only know about registered 'include' and
// does the offset translation with this information)
CPPUNIT_ASSERT_EQUAL(str.asString(), src.getOriginalText());
CPPUNIT_ASSERT_EQUAL(std::string("int var_before;"), src.getOriginalText(before_range));
CPPUNIT_ASSERT_EQUAL(std::string("int inside_header;"), src.getOriginalText(include_range));
CPPUNIT_ASSERT_EQUAL(std::string("int var_after;"), src.getOriginalText(after_range));
}
void
SourceTest::testNestedInclude()
{
/**
* 'source' object is storing original source text and
* links to includes. It can restore offset from preprocessed source to
* original source text. This is tested here.
*/
// original source:
Testing::KeyedString str;
str.addKeyed("BEFORE", "int var_before;\n");
str.addKeyed("INCLUDE","#include <header.h>\n");
str.addKeyed("AFTER", "int var_after;\n");
TextDocumentPtr doc = TextDocumentPtr(new Testing::TextDocumentMock(str));
Source src(doc);
// source of includes:
std::string doc2_txt = "int inside_header;\n#include <header2.h>\n";
TextDocumentPtr doc2 = TextDocumentPtr(new Testing::TextDocumentMock(doc2_txt));
SourcePtr include = SourcePtr(new Source(doc2));
std::string doc3_txt = "int inside_header2;";
TextDocumentPtr doc3 = TextDocumentPtr(new Testing::TextDocumentMock(doc3_txt));
SourcePtr include2 = SourcePtr(new Source(doc3));
// preprocessor operation that registers an include:
SourceRange directive_range(str.getKeyedIndex("INCLUDE",0),str.getKeyedLen("INCLUDE",0));
src.registerInclude(directive_range,doc2_txt.length()-2,SourcePtr(include)); // '-2' is correction of nested include
// preprocessing nested header
SourceRange directive2_range(19,21); // position of '#include <header2.h>' in doc2_txt
include->registerInclude(directive2_range,doc3_txt.length(),SourcePtr(include2));
// for testing we create the corresponding preprocessed source
// just to have offset to be restored:
Testing::KeyedString preprocessed;
preprocessed.addKeyed("BEFORE", "int var_before;") << " ";
preprocessed.addKeyed("INCLUDE", "int inside_header;") << " ";
preprocessed.addKeyed("INCLUDE2","int inside_header2;");
preprocessed.addKeyed("AFTER", "int var_after;");
// this are the offsets which will be tested:
SourceRange before_range(SourceRange(preprocessed.getKeyedIndex("BEFORE",0),preprocessed.getKeyedLen("BEFORE",0)));
SourceRange include_range(SourceRange(preprocessed.getKeyedIndex("INCLUDE",0),preprocessed.getKeyedLen("INCLUDE",0)));
SourceRange include2_range(SourceRange(preprocessed.getKeyedIndex("INCLUDE2",0),preprocessed.getKeyedLen("INCLUDE2",0)));
SourceRange after_range(SourceRange(preprocessed.getKeyedIndex("AFTER",0),preprocessed.getKeyedLen("AFTER",0)));
// use the offsets of preprocessed text to get the original source text:
// imagine that 'source' does only know about registered 'include' and
// does the offset translation with this information)
CPPUNIT_ASSERT_EQUAL(str.asString(), src.getOriginalText());
CPPUNIT_ASSERT_EQUAL(std::string("int var_before;"), src.getOriginalText(before_range));
CPPUNIT_ASSERT_EQUAL(std::string("int inside_header;"), src.getOriginalText(include_range));
CPPUNIT_ASSERT_EQUAL(std::string("int inside_header2;"), src.getOriginalText(include2_range));
CPPUNIT_ASSERT_EQUAL(std::string("int var_after;"), src.getOriginalText(after_range));
}
void
SourceTest::testIncludeSequence()
{
// original source:
Testing::KeyedString str;
str.addKeyed("BEFORE", "int var_before;\n");
str.addKeyed("INCLUDE", "#include <header.h>\n");
str.addKeyed("INCLUDE2","#include <header2.h>\n");
str.addKeyed("AFTER", "int var_after;\n");
TextDocumentPtr doc = TextDocumentPtr(new Testing::TextDocumentMock(str));
Source src(doc);
// source of includes:
std::string doc2_txt = "int h1;";
TextDocumentPtr doc2 = TextDocumentPtr(new Testing::TextDocumentMock(doc2_txt));
SourcePtr include = SourcePtr(new Source(doc2));
std::string doc3_txt = "int h2;";
TextDocumentPtr doc3 = TextDocumentPtr(new Testing::TextDocumentMock(doc3_txt));
SourcePtr include2 = SourcePtr(new Source(doc3));
// preprocessor operation that registers an include:
SourceRange directive_range(str.getKeyedIndex("INCLUDE",0),str.getKeyedLen("INCLUDE",0));
src.registerInclude(directive_range,doc2_txt.length(),SourcePtr(include));
// preprocessor operation that registers an include:
SourceRange directive2_range(str.getKeyedIndex("INCLUDE2",0),str.getKeyedLen("INCLUDE2",0));
src.registerInclude(directive2_range,doc3_txt.length(),SourcePtr(include2));
// for testing we create the corresponding preprocessed source
// just to have offset to be restored:
Testing::KeyedString preprocessed;
preprocessed.addKeyed("BEFORE", "int var_before;") << " ";
preprocessed.addKeyed("INCLUDE", "int h1;");
preprocessed.addKeyed("INCLUDE2","int h2;");
preprocessed.addKeyed("AFTER", "int var_after;");
// this are the offsets which will be tested:
SourceRange before_range(SourceRange(preprocessed.getKeyedIndex("BEFORE",0),preprocessed.getKeyedLen("BEFORE",0)));
SourceRange include_range(SourceRange(preprocessed.getKeyedIndex("INCLUDE",0),preprocessed.getKeyedLen("INCLUDE",0)));
SourceRange include2_range(SourceRange(preprocessed.getKeyedIndex("INCLUDE2",0),preprocessed.getKeyedLen("INCLUDE2",0)));
SourceRange after_range(SourceRange(preprocessed.getKeyedIndex("AFTER",0),preprocessed.getKeyedLen("AFTER",0)));
// use the offsets of preprocessed text to get the original source text:
// imagine that 'source' does only know about registered 'include' and
// does the offset translation with this information)
CPPUNIT_ASSERT_EQUAL(str.asString(), src.getOriginalText());
CPPUNIT_ASSERT_EQUAL(std::string("int var_before;"), src.getOriginalText(before_range));
CPPUNIT_ASSERT_EQUAL(std::string("int h1;"), src.getOriginalText(include_range));
CPPUNIT_ASSERT_EQUAL(std::string("int h2;"), src.getOriginalText(include2_range));
CPPUNIT_ASSERT_EQUAL(std::string("int var_after;"), src.getOriginalText(after_range));
}
void
SourceTest::testSimpleMacro()
{
// original source:
Testing::KeyedString str;
std::string macro_txt = "int macrorepl;";
std::string macro_def = std::string("#define DEF_VAR ")+macro_txt+"\n";
str.addKeyed("DEF", macro_def);
str << "{\n";
str.addKeyed("USE", "DEF_VAR") << "\n";
str << "}\n";
str.addKeyed("AFTER", "int var_after;\n");
TextDocumentPtr doc = TextDocumentPtr(new Testing::TextDocumentMock(str));
Source src(doc);
// preprocessing macro definition replacement:
SourceRange directive1_range(str.getKeyedIndex("DEF",0),str.getKeyedLen("DEF",0));
src.registerReplacement(directive1_range,1);
// preprocessing macro use replacement:
SourceRange directive2_range(str.getKeyedIndex("USE",0),str.getKeyedLen("USE",0));
src.registerReplacement(directive2_range,macro_txt.length());
// for testing we create the corresponding preprocessed source
// just to have offset to be restored:
Testing::KeyedString preprocessed;
preprocessed.addKeyed("DEF", " ") << "{ ";
preprocessed.addKeyed("USE", macro_txt.c_str() ) << " } ";
preprocessed.addKeyed("AFTER", "int var_after;") << " ";
// this are the offsets which will be tested:
SourceRange def_range(SourceRange(preprocessed.getKeyedIndex("DEF",0),macro_def.length()));
SourceRange use_range(SourceRange(preprocessed.getKeyedIndex("USE",0),7));
SourceRange after_range(SourceRange(preprocessed.getKeyedIndex("AFTER",0),preprocessed.getKeyedLen("AFTER",0)));
// use the offsets of preprocessed text to get the original source text:
// imagine that 'source' does only know about registered 'include' and
// does the offset translation with this information)
CPPUNIT_ASSERT_EQUAL(str.asString(), src.getOriginalText());
CPPUNIT_ASSERT_EQUAL(macro_def , src.getOriginalText(def_range));
CPPUNIT_ASSERT_EQUAL(std::string("DEF_VAR"), src.getOriginalText(use_range));
CPPUNIT_ASSERT_EQUAL(std::string("int var_after;"), src.getOriginalText(after_range));
}
void
SourceTest::testMixedIncludeMacro()
{
// original source:
Testing::KeyedString str;
str.addKeyed("BEFORE", "int var_before;\n");
str.addKeyed("INCLUDE", "#include <header.h>\n");
str.addKeyed("MACRO", "DEF_VAR") << "\n";
str.addKeyed("INCLUDE2","#include <header2.h>\n");
str.addKeyed("AFTER", "int var_after;\n");
TextDocumentPtr doc = TextDocumentPtr(new Testing::TextDocumentMock(str));
Source src(doc);
// source of includes:
std::string doc2_txt = "int h1;";
TextDocumentPtr doc2 = TextDocumentPtr(new Testing::TextDocumentMock(doc2_txt));
SourcePtr include = SourcePtr(new Source(doc2));
std::string doc3_txt = "int h2;";
TextDocumentPtr doc3 = TextDocumentPtr(new Testing::TextDocumentMock(doc3_txt));
SourcePtr include2 = SourcePtr(new Source(doc3));
std::string macro_txt = "int macrorepl;";
// preprocessor operation that registers an include:
SourceRange directive_range(str.getKeyedIndex("INCLUDE",0),str.getKeyedLen("INCLUDE",0));
src.registerInclude(directive_range,doc2_txt.length(),SourcePtr(include));
// preprocessing macro replacement:
SourceRange directive2_range(str.getKeyedIndex("MACRO",0),str.getKeyedLen("MACRO",0));
src.registerReplacement(directive2_range,macro_txt.length());
// preprocessing nested header
SourceRange directive3_range(str.getKeyedIndex("INCLUDE2",0),str.getKeyedLen("INCLUDE2",0));
src.registerInclude(directive3_range,doc3_txt.length(),SourcePtr(include2));
// for testing we create the corresponding preprocessed source
// just to have offset to be restored:
Testing::KeyedString preprocessed;
preprocessed.addKeyed("BEFORE", "int var_before;") << " ";
preprocessed.addKeyed("INCLUDE", "int h1;");
preprocessed.addKeyed("MACRO", macro_txt.c_str() ) << " ";
preprocessed.addKeyed("INCLUDE2","int h2;");
preprocessed.addKeyed("AFTER", "int var_after;");
// this are the offsets which will be tested:
SourceRange before_range(SourceRange(preprocessed.getKeyedIndex("BEFORE",0),preprocessed.getKeyedLen("BEFORE",0)));
SourceRange include_range(SourceRange(preprocessed.getKeyedIndex("INCLUDE",0),preprocessed.getKeyedLen("INCLUDE",0)));
SourceRange macro_range(SourceRange(preprocessed.getKeyedIndex("MACRO",0),7));
SourceRange include2_range(SourceRange(preprocessed.getKeyedIndex("INCLUDE2",0),preprocessed.getKeyedLen("INCLUDE2",0)));
SourceRange after_range(SourceRange(preprocessed.getKeyedIndex("AFTER",0),preprocessed.getKeyedLen("AFTER",0)));
// use the offsets of preprocessed text to get the original source text:
// imagine that 'source' does only know about registered 'include' and
// does the offset translation with this information)
CPPUNIT_ASSERT_EQUAL(str.asString(), src.getOriginalText());
CPPUNIT_ASSERT_EQUAL(std::string("int var_before;"), src.getOriginalText(before_range));
CPPUNIT_ASSERT_EQUAL(std::string("int h1;"), src.getOriginalText(include_range));
CPPUNIT_ASSERT_EQUAL(std::string("DEF_VAR"), src.getOriginalText(macro_range));
CPPUNIT_ASSERT_EQUAL(std::string("int h2;"), src.getOriginalText(include2_range));
CPPUNIT_ASSERT_EQUAL(std::string("int var_after;"), src.getOriginalText(after_range));
}
void
SourceTest::testMacroInsideInclude()
{
// original source:
Testing::KeyedString str;
str.addKeyed("BEFORE", "int var_before;\n");
str.addKeyed("INCLUDE", "#include <header.h>\n");
str.addKeyed("INCLUDE2","#include <header2.h>\n");
str.addKeyed("AFTER", "int var_after;\n");
TextDocumentPtr doc = TextDocumentPtr(new Testing::TextDocumentMock(str));
Source src(doc);
// source of includes:
std::string doc2_txt = "int h1;DEF_VAR\n";
TextDocumentPtr doc2 = TextDocumentPtr(new Testing::TextDocumentMock(doc2_txt));
SourcePtr include = SourcePtr(new Source(doc2));
std::string doc3_txt = "int h2;";
TextDocumentPtr doc3 = TextDocumentPtr(new Testing::TextDocumentMock(doc3_txt));
SourcePtr include2 = SourcePtr(new Source(doc3));
std::string macro_txt = "int m;";
// preprocessor operation that registers an include:
SourceRange directive_range(str.getKeyedIndex("INCLUDE",0),str.getKeyedLen("INCLUDE",0));
src.registerInclude(directive_range,doc2_txt.length()-1,SourcePtr(include)); // '-1' is correction of macro replacement
// preprocessing macro replacement:
SourceRange directive2_range(7,7);
include->registerReplacement(directive2_range,macro_txt.length());
// preprocessing nested header
SourceRange directive3_range(str.getKeyedIndex("INCLUDE2",0),str.getKeyedLen("INCLUDE2",0));
src.registerInclude(directive3_range,doc3_txt.length(),SourcePtr(include2));
// for testing we create the corresponding preprocessed source
// just to have offset to be restored:
Testing::KeyedString preprocessed;
preprocessed.addKeyed("BEFORE", "int var_before;") << " ";
preprocessed.setKeyStart("INCLUDE");
preprocessed << "int h1;";
preprocessed.addKeyed("MACRO", macro_txt.c_str() ) << " ";
preprocessed.setKeyEnd("INCLUDE");
preprocessed.addKeyed("INCLUDE2","int h2;");
preprocessed.addKeyed("AFTER", "int var_after;");
// this are the offsets which will be tested:
SourceRange before_range(SourceRange(preprocessed.getKeyedIndex("BEFORE",0),preprocessed.getKeyedLen("BEFORE",0)));
SourceRange include_range(SourceRange(preprocessed.getKeyedIndex("INCLUDE",0),15));
SourceRange macro_range(SourceRange(preprocessed.getKeyedIndex("MACRO",0),7));
SourceRange include2_range(SourceRange(preprocessed.getKeyedIndex("INCLUDE2",0),preprocessed.getKeyedLen("INCLUDE2",0)));
SourceRange after_range(SourceRange(preprocessed.getKeyedIndex("AFTER",0),preprocessed.getKeyedLen("AFTER",0)));
// use the offsets of preprocessed text to get the original source text:
// imagine that 'source' does only know about registered 'include' and
// does the offset translation with this information)
CPPUNIT_ASSERT_EQUAL(str.asString(), src.getOriginalText());
CPPUNIT_ASSERT_EQUAL(std::string("int var_before;"), src.getOriginalText(before_range));
CPPUNIT_ASSERT_EQUAL(std::string("int h1;DEF_VAR\n"), src.getOriginalText(include_range));
CPPUNIT_ASSERT_EQUAL(std::string("DEF_VAR"), src.getOriginalText(macro_range));
CPPUNIT_ASSERT_EQUAL(std::string("int h2;"), src.getOriginalText(include2_range));
CPPUNIT_ASSERT_EQUAL(std::string("int var_after;"), src.getOriginalText(after_range));
}
} // namespace Refactoring
--- NEW FILE: SourceTest.h ---
// //////////////////////////////////////////////////////////////////////////
// Header file SourceTest.h for class SourceTest
// (c)Copyright 2003, Andre Baresel
// Created: 2003/12/13
// //////////////////////////////////////////////////////////////////////////
#ifndef RFTA_SOURCETEST_H
#define RFTA_SOURCETEST_H
#include "ParserTesting.h"
namespace Refactoring
{
/// Unit tests for Source
class SourceTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( SourceTest );
CPPUNIT_TEST( testSimpleInclude );
CPPUNIT_TEST( testNestedInclude );
CPPUNIT_TEST( testIncludeSequence );
CPPUNIT_TEST( testSimpleMacro );
CPPUNIT_TEST( testMixedIncludeMacro );
CPPUNIT_TEST( testMacroInsideInclude );
CPPUNIT_TEST_SUITE_END();
public:
/*! Constructs a SourceTest object.
*/
SourceTest();
/// Destructor.
virtual ~SourceTest();
void setUp();
void tearDown();
void testSimpleInclude();
void testNestedInclude();
void testIncludeSequence();
void testSimpleMacro();
void testMixedIncludeMacro();
void testMacroInsideInclude();
private:
/// Prevents the use of the copy constructor.
SourceTest( const SourceTest &other );
/// Prevents the use of the copy operator.
void operator =( const SourceTest &other );
private:
};
// Inlines methods for SourceTest:
// ----------------------------------------
} // namespace Refactoring
#endif // RFTA_SOURCETEST_H
Index: PreProcessorTest.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftaparser/PreProcessorTest.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** PreProcessorTest.cpp 16 Dec 2003 13:47:00 -0000 1.1
--- PreProcessorTest.cpp 13 Jan 2004 22:18:25 -0000 1.2
***************
*** 7,12 ****
#include "stdafx.h"
#include "PreProcessorTest.h"
#include <rfta/parser/PreProcessor.h>
- #include <rfta/parser/MacroReplaceRegistration.h>
namespace Refactoring
--- 7,14 ----
#include "stdafx.h"
#include "PreProcessorTest.h"
+ #include <rfta/test/SourceManagerMock.h>
+ #include <rfta/parser/Source.h>
+ #include "TextDocumentMock.h"
#include <rfta/parser/PreProcessor.h>
namespace Refactoring
***************
*** 40,62 ****
PreProcessorTest::testSimpleReplace()
{
! std::string source = "#define TEXT \"String\"\n\
! char * var = TEXT;\n\
! ";
! std::string expected= " \
! char * var = \"String\"; ";
! // do the preprocessing (use directive information)
std::string preprocessed;
! PreProcessor proc(source);
! MacroReplaceRegistration registration;
! preprocessed = proc.process(registration);
CPPUNIT_ASSERT_EQUAL(expected, preprocessed);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("Expected size of Macro-Replacement-Registration is wrong.",
- 1, registration.getSize());
- MacroReplaceRegistration::MacroReplacement entry = registration.getEntry(0);
- CPPUNIT_ASSERT_EQUAL(SourceRange(43,4),entry.position_);
}
} // namespace Refactoring
--- 42,163 ----
PreProcessorTest::testSimpleReplace()
{
! std::string sourcetxt = "#define TEXT \"String\"\n"
! " char * var = TEXT;\n"
! " ";
! std::string expected= " "
! " char * var = \"String\"; ";
! // create a preprocessor context:
! Testing::SourceManagerMock manager;
! PreProcessorContext context(manager);
! TextDocumentPtr textdoc(new Testing::TextDocumentMock(sourcetxt));
! SourcePtr source(new Source(textdoc));
!
! PreProcessor proc(source,context);
!
std::string preprocessed;
! preprocessed = proc.process();
!
! CPPUNIT_ASSERT_EQUAL(std::string("[")+expected+std::string("]"), std::string("[")+preprocessed+std::string("]"));
! }
!
! void
! PreProcessorTest::testSingleInclude()
! {
! // setup:
! std::string sourcetxt = "#include <hello.h> \nint i;\
! char * var;";
! std::string helloinclude = "char * h;int x,y,z;\n";
!
! // expectation:
! std::string expected= "char * h;int x,y,z; int i;\
! char * var;";
!
! TextDocumentPtr sourcedoc(new Testing::TextDocumentMock(sourcetxt));
! SourcePtr source(new Source(sourcedoc));
!
! // prepare some mock objects for 'include file' accesses
! Testing::SourceManagerMock manager;
! TextDocumentPtr textdoc(new Testing::TextDocumentMock(helloinclude));
! manager.setSource("hello.h",SourcePtr(new Source(textdoc)));
!
! // create a preprocessor context with prepared mockups
! PreProcessorContext context(manager);
!
! PreProcessor proc(source,context);
!
! std::string preprocessed;
! preprocessed = proc.process();
CPPUNIT_ASSERT_EQUAL(expected, preprocessed);
}
+ void
+ PreProcessorTest::testSingleIfDef()
+ {
+ // setup:
+ std::string sourcetxt = "#ifdef NOT\n\
+ char * nvar;\n#endif\nchar * var;";
+
+ // expectation:
+ std::string expected= " char * var;";
+
+ TextDocumentPtr sourcedoc(new Testing::TextDocumentMock(sourcetxt));
+ SourcePtr source(new Source(sourcedoc));
+
+ // prepare some mock objects for 'include file' accesses
+ Testing::SourceManagerMock manager;
+
+ // create a preprocessor context with prepared mockups
+ PreProcessorContext context(manager);
+
+ PreProcessor proc(source,context);
+
+ std::string preprocessed;
+ preprocessed = proc.process();
+
+ CPPUNIT_ASSERT_EQUAL(expected, preprocessed);
+ }
+
+ void
+ PreProcessorTest::testNestedIfDef()
+ {
+ // setup:
+ std::string sourcetxt =
+
+ "#define YES\n"
+
+ "#ifndef NOT\n"
+ "#ifndef YES\n"
+ "char * this_not;\n"
+ "#else\n"
+ "short but_this;\n"
+ "#endif\n"
+ "#else\n"
+ "#ifndef NOT\n"
+ "int i;\n"
+ "#endif\n"
+ "#endif\n"
+ "char * var;";
+
+ // expectation:
+ std::string expected= " short but_this; char * var;";
+
+ TextDocumentPtr sourcedoc(new Testing::TextDocumentMock(sourcetxt));
+ SourcePtr source(new Source(sourcedoc));
+
+ // prepare some mock objects for 'include file' accesses
+ Testing::SourceManagerMock manager;
+
+ // create a preprocessor context with prepared mockups
+ PreProcessorContext context(manager);
+
+ PreProcessor proc(source,context);
+
+ std::string preprocessed;
+ preprocessed = proc.process();
+
+ CPPUNIT_ASSERT_EQUAL(expected, preprocessed);
+ }
} // namespace Refactoring
Index: PreProcessorTest.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftaparser/PreProcessorTest.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** PreProcessorTest.h 16 Dec 2003 13:47:00 -0000 1.1
--- PreProcessorTest.h 13 Jan 2004 22:18:25 -0000 1.2
***************
*** 17,20 ****
--- 17,23 ----
CPPUNIT_TEST_SUITE( PreProcessorTest );
CPPUNIT_TEST( testSimpleReplace );
+ CPPUNIT_TEST( testSingleInclude );
+ CPPUNIT_TEST( testSingleIfDef );
+ CPPUNIT_TEST( testNestedIfDef );
CPPUNIT_TEST_SUITE_END();
***************
*** 31,34 ****
--- 34,40 ----
void testSimpleReplace();
+ void testSingleInclude();
+ void testSingleIfDef();
+ void testNestedIfDef();
private:
Index: PreProcessor.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftaparser/PreProcessor.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** PreProcessor.cpp 19 Dec 2003 20:13:21 -0000 1.2
--- PreProcessor.cpp 13 Jan 2004 22:18:25 -0000 1.3
***************
*** 8,97 ****
#include <rfta/parser/PreProcessor.h>
#include <xtl/Type.h>
#include <xtl/CStringView.h>
#include <rfta/parser/SourceRange.h>
#include <rfta/parser/ParserTools.h>
! #include "PreProcessResolver.h"
! #include <rfta/parser/NonSemanticBlanker.h>
namespace Refactoring
{
! PreProcessor::PreProcessor( const std::string &textToPreProcess):
! toPreProcess_(textToPreProcess)
{
}
/**
! * does tokenize the string, skipping strings and symbols.
! * only identifiers will be checked for macro identifiers.
*
*/
std::string
! PreProcessor::process(MacroReplaceListener& listener)
! {
! std::string preprocessed;
! std::string blanked(toPreProcess_);
! // first blank the source code
! PreProcessResolverPtr pResolver(new PreProcessResolver());
! NonSemanticBlanker blanker(toPreProcess_, blanked, pResolver);
! blanker.blank();
! // now do the preprocessing
! const char * start = blanked.c_str();
! const char * end = start + blanked.length();
! bool foundIdentifier;
! const char * current = start;
! do
! {
! const char * lastpos = current;
! int identlen = 0;
! foundIdentifier = false;
! while (current != end && !ParserTools::isIdentifierLetter(*current))
{
! current++;
}
! if (current != end && ParserTools::isValidIdentifierFirstLetter(*current))
{
! foundIdentifier = true;
! while (current+identlen != end && ParserTools::isIdentifierLetter(*(current+identlen)))
! identlen++;
}
! else
! // this is a number - skip:
! while (current != end && ParserTools::isIdentifierLetter(*current))
! current++;
!
! if (foundIdentifier)
{
! // copy the skipped characters:
! preprocessed += std::string( lastpos,current-lastpos);
! // do the replacement:
! std::string ident(current,identlen);
! if (pResolver->isMacroIdentifier(ident))
{
! // replace
! std::string replacement = pResolver->getMacroReplacement(ident);
! preprocessed += replacement;
! // register macro replacement
! SourceRange position(current-start,identlen);
! listener.macroReplacement(position,ident,replacement);
} else
! // keep it, this is no macro
! preprocessed += ident;
! current+=identlen;
! } else
! {
! // copy the last characters:
! preprocessed += std::string( lastpos,(end-lastpos));
! }
! } while (current != end);
! return preprocessed;
}
--- 8,464 ----
#include <rfta/parser/PreProcessor.h>
+ #include <rfta/parser/PreProcessorError.h>
#include <xtl/Type.h>
#include <xtl/CStringView.h>
#include <rfta/parser/SourceRange.h>
#include <rfta/parser/ParserTools.h>
! #include <rfta/parser/Source.h>
namespace Refactoring
{
! PreProcessor::PreProcessor( const SourcePtr source,PreProcessorContext& context)
! :source_(source)
! ,toPreProcess_(source->getOriginalText())
! ,context_(context)
{
}
/**
! * processes directives, blank text strings,
! * tokenize the string:
! * + skip symbols.
! * + identifiers will be compared with macro identifiers.
*
*/
std::string
! PreProcessor::process()
! {
! blanked_ = toPreProcess_;
! const char *str = toPreProcess_.c_str();
! textStart_ = str;
! textEnd_ = str + toPreProcess_.length();
! // blank the source code and replace macros / insert includes
! current_ = textStart_;
! newLine_ = true;
! offset_diff = 0;
! while ( current_ != textEnd_ )
! {
! char c = *current_;
! if ( c == '/' && current_[1] )
! {
! char c2 = current_[1];
! if ( c2 == '/' )
! current_ = deleteUntilEol( current_ );
! else if ( c2 == '*' )
! current_ = deleteCComment( current_ );
! else
! ++current_;
! }
! else
! blanksStringsAndPreprocessorDirectives();
! }
! return blanked_;
! }
!
! bool
! PreProcessor::isEol( char c )
! {
! return c == '\n' || c == '\r';
! }
!
! void PreProcessor::addSpaceReplacement(const int start, const int len)
! {
! blanked_.erase(start - offset_diff, len-1 );
! blanked_[start- offset_diff]=' ';
! offset_diff+=len-1;
! source_->registerReplacement(SourceRange(start,len),1);
! }
!
! void PreProcessor::addTextDeletion(const int start, const int len)
! {
! blanked_.erase(start - offset_diff, len );
! offset_diff+=len;
! source_->registerReplacement(SourceRange(start,len),0);
! }
!
! void PreProcessor::addTextReplacement(const int relstart, const int len, std::string text)
! {
! int start = relstart - offset_diff;
! blanked_.replace(start , len, text );
! offset_diff+=len - text.length();
! }
!
! const char *
! PreProcessor::deleteUntilEol( const char *current )
! {
! const char *start = current;
! while ( current != textEnd_ && !isEol( *current ) )
! ++current;
!
! int length = current - start;
! addTextDeletion(start - textStart_, length);
!
! return current;
! }
!
!
! const char *
! PreProcessor::deleteCComment( const char *current )
! {
! const char *start = current;
! while ( current != textEnd_ )
{
! char c = *current++;
! if( c == '*' && current[0] == '/' )
! {
! ++current;
! break;
! }
}
! int length = current - start;
! addTextDeletion(start - textStart_, length);
!
! //blanked_.replace( start - textStart_, length, length, ' ' );
! return current;
! }
!
! inline const char *
! PreProcessor::blanksNewLine( const char *current )
! {
! int index = current - textStart_;
!
! blanked_[index - offset_diff] = ' ';
! ++index;
! ++current;
! if ( *current == '\n' || *current == '\r' )
{
! blanked_[index - offset_diff] = ' ';
! ++current;
}
!
! return current;
! }
!
!
! const char *
! PreProcessor::blanksString( const char *current,
! char endOfStringChar )
! {
! const char *start = current;
! ++current;
! while ( current != textEnd_ )
{
! char c = *current++;
! if ( c == '\\' )
! {
! if ( current == textEnd_ )
! break;
! ++current;
! }
! else if ( c == endOfStringChar )
! break;
! }
!
! int length = current - start -2;
! if (length>0)
! addSpaceReplacement(start - textStart_+1, length);
! return current;
! }
!
!
! const char *
! PreProcessor::blanksPreprocessorDirective( const char *current )
! {
! const char *start = current;
! ++current;
! while ( current != textEnd_ )
! {
! char c = *current++;
! if ( c == '\\' )
! {
! while ( isEol( *current ) )
! ++current;
! }
! else if ( isEol( c ) )
! break;
! }
! return parseDirective( start, current );
! }
!
! const char *
! PreProcessor::parseDirective( const char *first,const char *last )
! {
! // check for '#define' keyword:
! if (strncmp(first,"#define ",8)==0)
! {
! return handleDefine(first,last);
!
! } else
! if (strncmp(first,"#include ",9)==0)
! {
! return handleInclude(first, last);
! } else
! if (strncmp(first,"#ifdef",6)==0)
! {
! if (!checkIfDef(first+6,last))
{
! // continue after 'else' or 'endif'
! const char * end = skipUntilElseEndIf(first );
! addSpaceReplacement( first - textStart_, end - first);
! return end;
! }
! // continue after 'last'
! int length = last - 1 - first;
! addSpaceReplacement( first - textStart_, length);
! return last;
! } else
! if (strncmp(first,"#ifndef",7)==0)
! {
! if (checkIfDef(first+8,last))
! {
! // continue after 'else' or 'endif'
! const char * end = skipUntilElseEndIf(first);
! addTextDeletion( first - textStart_, end - first);
! return end;
! }
! // remove 'directive'
! int length = last -1 - first;
! addTextDeletion( first - textStart_, length);
! // continue at the new line character after 'directive'
! return last - 1;
! } else
! if (strncmp(first,"#else", 5)==0)
! {
! // continue after 'else' or 'endif'
! const char * end = skipUntilElseEndIf(first+5 );
! addSpaceReplacement( first - textStart_, end - first);
! return end;
! } else
! {
! int length = last - 1 - first;
! addTextDeletion( first - textStart_, length);
! // continue at the new line character after 'directive'
! return last - 1;
! }
! }
! const char *
! PreProcessor::handleDefine(const char *first, const char *last )
! {
! Xtl::CStringEnumerator en( Xtl::CStringView( first, last ) );
! // skip define keyword and spaces
! en.setCurrent( first + 8 );
! ParserTools::skipSpaces(en);
!
! Xtl::CStringView identifier;
! ParserTools::tryReadIdentifier( en, identifier );
!
! // do not understand this...
! if (identifier.getLength() == 0)
! ThrowPreProcessError("Do not understand syntax of this '#define' directive.");
!
! ParserTools::skipSpaces(en);
! // macro text is all but not the newline character...
! context_.addMacro(identifier.str() , std::string( en.getCurrentPos(), last-1-en.getCurrentPos()));
!
! int length = last -1 - first;
! addSpaceReplacement( first - textStart_, length);
!
! // continue at the new line character after 'directive'
! return last-1;
! }
!
! const char *
! PreProcessor::handleInclude(const char *first, const char *last )
! {
! Xtl::CStringEnumerator en( Xtl::CStringView( first, last ) );
!
! // check preprocessor option 'SkipIncludes'
! if (isOptionSet(skipIncludes))
! {
! int length = last - 1 - first;
! addTextDeletion( first - textStart_, length);
! return last-1;
! }
!
! // skip define keyword and spaces
! en.setCurrent( first + 9 );
! ParserTools::skipSpaces(en);
!
! const char * current = en.getCurrentPos();
! if (*current != '\"' && *current !='<')
! ThrowPreProcessError("Do not understand syntax of this '#include' directive.");
!
! const char * filename_start = current+1;
! en++;
! if (*current=='\"')
! ParserTools::skipUntil(en,'\"');
! else
! ParserTools::skipUntil(en,'>');
!
! std::string filename(current+1,en.getCurrentPos()-current-2);
!
! SourcePtr pIncludefile = context_.getSourceManager().open(filename);
!
! PreProcessor include_processor(pIncludefile,context_);
! std::string include_txt = include_processor.process();
!
! int length = last - 1 - first;
! if (checkNoneWhiteSpace(include_txt))
! {
! addTextReplacement(first - textStart_, length, include_txt);
! } else
! {
! // TODO: remove added position translation from 'context_'
! addTextDeletion( first - textStart_, length);
! }
! source_->registerInclude(SourceRange(first - textStart_,length),include_txt.length(),pIncludefile);
!
! // continue at the new line character after 'directive'
! return last-1;
! }
!
! /**
! * checks an ifdef/ifndef term
! */
! bool
! PreProcessor::checkIfDef(const char * start, const char * end)
! {
! // TODO: real expression evaluation
! Xtl::CStringEnumerator en( Xtl::CStringView( start, end ) );
! Xtl::CStringView identifier;
! ParserTools::skipSpaces(en);
! ParserTools::tryReadIdentifier( en, identifier );
! if (identifier.getLength() != 0)
! {
! return context_.isMacroIdentifier(identifier.str());
! } else
! return false;
! }
!
! const char *
! PreProcessor::skipUntilElseEndIf(const char * start)
! {
! int cnt=0;
! const char * cur = start;
! do {
! const char * next = strstr(cur,"#ifdef");
! const char * end = strstr(cur,"#endif");
! const char * end2 = strstr(cur,"#else");
!
! // first check if '#else' comes before '#endif'
! if (end2 != 0 && end2 < end)
! end = end2;
!
! if (end == 0)
! {
! cur = textEnd_;
! return textEnd_;
! }
! if (next == 0 || next > end)
! {
! cnt--;
! cur = end+6;
! } else if (next != 0)
! {
! cnt++;
! cur = next+6;
} else
! cur++;
! }
! while (start != textEnd_ && cnt>0);
! // return final location
! return cur;
! }
! void
! PreProcessor::blanksStringsAndPreprocessorDirectives( )
! {
! char c(*current_);
! switch ( c )
! {
! case ' ':
! ++current_;
! break;
! case '\t':
! blanked_[ current_++ - textStart_ - offset_diff ] = ' ';
! break;
! case '\n':
! case '\r':
! current_ = blanksNewLine( current_ );
! newLine_ = true;
! break;
! case '"':
! current_ = blanksString( current_, '"' );
! break;
! case '\'':
! current_ = blanksString( current_, '\'' );
! break;
! case '#':
! if ( newLine_ )
! {
! current_ = blanksPreprocessorDirective( current_ );
! break;
! }
! newLine_ = true;
! ++current_;
! break;
! default:
! // identifier letters can lead to macro replacements:
! if (ParserTools::isValidIdentifierFirstLetter(*current_))
! {
! int identlen=1;
! while (current_+identlen != textEnd_ && ParserTools::isIdentifierLetter(*(current_+identlen)))
! identlen++;
! std::string ident(current_,identlen);
! if (ident == "_STD_END")
! identlen++;
! if (context_.isMacroIdentifier(ident))
! {
! // macro replace
! std::string replacement = context_.getMacroReplacement(ident);
! addTextReplacement(current_-textStart_,identlen,replacement);
! // register macro replacement
! SourceRange position(current_-textStart_,identlen);
! source_->registerReplacement(position,replacement.length());
! }
! current_+=identlen;
! } else
! {
! // skip any other non whitespace character and set the 'we-are-in-a-new-line' flag to false
! newLine_ = false;
! ++current_;
! }
! break;
! }
! // TODO: Remove this implementation check.
! if (*current_ != blanked_[current_-textStart_-offset_diff])
! int debug=0;
! }
! bool
! PreProcessor::checkNoneWhiteSpace(const std::string& text)
! {
! Xtl::CStringEnumerator en( Xtl::CStringView( text.c_str(), text.c_str()+text.length() ) );
! ParserTools::skipSpaces(en);
! return (en.getCurrentPos()!=text.c_str()+text....
[truncated message content] |
|
From: <net...@us...> - 2004-01-13 22:18:28
|
Update of /cvsroot/cpptool/rfta/src/rftatest
In directory sc8-pr-cvs1:/tmp/cvs-serv8283/rftatest
Added Files:
SourceManagerMock.cpp
Log Message:
preprocessor implementation
--- NEW FILE: SourceManagerMock.cpp ---
// //////////////////////////////////////////////////////////////////////////
// Source file SourceManagerMock.cpp for class SourceManagerMock
// (c)Copyright 2003, Andre Baresel.
// Created: 2003/12/27
// //////////////////////////////////////////////////////////////////////////
#include <stdafx.h>
#include <rfta/test/SourceManagerMock.h>
namespace Refactoring
{
namespace Testing
{
/**
* create an source object for the given name.
*/
SourcePtr
SourceManagerMock::open(std::string sourceName)
{
return sourceMap_[sourceName];
}
void
SourceManagerMock::setSource(std::string sourceName, SourcePtr pSource)
{
sourceMap_[sourceName] = pSource;
}
// std::map<std::string,SourcePtr> sourceMap_;
} // namespace
} // namespace
|
|
From: <net...@us...> - 2004-01-13 21:59:38
|
Update of /cvsroot/cpptool/rfta/include/rfta/refactoring In directory sc8-pr-cvs1:/tmp/cvs-serv3729/rfta/include/rfta/refactoring Removed Files: PlainTextDocument.h TextDocument.h Log Message: -- files have been moved to preprocessor code (rftaparser-module) --- PlainTextDocument.h DELETED --- --- TextDocument.h DELETED --- |
|
From: <net...@us...> - 2004-01-13 21:59:38
|
Update of /cvsroot/cpptool/rfta/src/rfta In directory sc8-pr-cvs1:/tmp/cvs-serv3729/rfta/src/rfta Removed Files: PlainTextDocument.cpp TextDocument.cpp Log Message: -- files have been moved to preprocessor code (rftaparser-module) --- PlainTextDocument.cpp DELETED --- --- TextDocument.cpp DELETED --- |
|
From: <net...@us...> - 2004-01-13 21:58:51
|
Update of /cvsroot/cpptool/rfta/src/rftaparser In directory sc8-pr-cvs1:/tmp/cvs-serv3551/rfta/src/rftaparser Removed Files: NonSemanticBlanker.cpp NonSemanticBlankerTest.cpp NonSemanticBlankerTest.h PreProcessResolver.cpp PreProcessResolver.h PreProcessResolverTest.cpp PreProcessResolverTest.h Log Message: -- removed because of new preprocessing concept --- NonSemanticBlanker.cpp DELETED --- --- NonSemanticBlankerTest.cpp DELETED --- --- NonSemanticBlankerTest.h DELETED --- --- PreProcessResolver.cpp DELETED --- --- PreProcessResolver.h DELETED --- --- PreProcessResolverTest.cpp DELETED --- --- PreProcessResolverTest.h DELETED --- |
|
From: <net...@us...> - 2004-01-13 21:58:51
|
Update of /cvsroot/cpptool/rfta/include/rfta/parser In directory sc8-pr-cvs1:/tmp/cvs-serv3551/rfta/include/rfta/parser Removed Files: MacroReplaceListener.h MacroReplaceRegistration.h NonSemanticBlanker.h PPDirectiveListener.h Log Message: -- removed because of new preprocessing concept --- MacroReplaceListener.h DELETED --- --- MacroReplaceRegistration.h DELETED --- --- NonSemanticBlanker.h DELETED --- --- PPDirectiveListener.h DELETED --- |
|
From: <net...@us...> - 2004-01-13 21:52:08
|
Update of /cvsroot/cpptool/rfta/src/rfta
In directory sc8-pr-cvs1:/tmp/cvs-serv2060/rfta/src/rfta
Modified Files:
CodeRewriter.h
Log Message:
-- changes for 'preprocessed' source (Source.h)
Index: CodeRewriter.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeRewriter.h,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** CodeRewriter.h 20 Dec 2003 08:59:50 -0000 1.22
--- CodeRewriter.h 13 Jan 2004 21:52:04 -0000 1.23
***************
*** 7,13 ****
#include "IndentLevelManager.h"
- #include <rfta/refactoring/TransformList.h>
#include <rfta/parser/SourceRange.h>
#include <rfta/refactoring/CodeModelVisitor.h>
#include <string>
--- 7,14 ----
#include "IndentLevelManager.h"
#include <rfta/parser/SourceRange.h>
#include <rfta/refactoring/CodeModelVisitor.h>
+ #include <rfta/refactoring/TransformList.h>
+ #include <rfta/parser/Source.h>
#include <string>
***************
*** 24,28 ****
{
public:
! CodeRewriter( const std::string &originalSource,
int indentWidth );
--- 25,29 ----
{
public:
! CodeRewriter( const SourcePtr source,
int indentWidth );
***************
*** 30,36 ****
virtual ~CodeRewriter();
! void rewrite( const StatementPtr &statement,
! TransformList& preprocesstransforms,
! TextDocument &document );
private:
--- 31,35 ----
virtual ~CodeRewriter();
! void rewrite( const StatementPtr &statement );
private:
***************
*** 173,177 ****
IndentLevelManager indentManager_;
TransformList transforms_;
! const std::string originalSource_;
int currentInsertionPos_;
int indentWidth_;
--- 172,176 ----
IndentLevelManager indentManager_;
TransformList transforms_;
! SourcePtr source_;
int currentInsertionPos_;
int indentWidth_;
|
|
From: <bl...@us...> - 2003-12-20 09:03:52
|
Update of /cvsroot/cpptool/rfta/src/astdumper
In directory sc8-pr-cvs1:/tmp/cvs-serv12842/src/astdumper
Modified Files:
ASTDumper.cpp
Log Message:
* updated to new NonSemanticBlanker prototype
Index: ASTDumper.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/astdumper/ASTDumper.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** ASTDumper.cpp 3 May 2003 17:45:12 -0000 1.9
--- ASTDumper.cpp 20 Dec 2003 09:03:49 -0000 1.10
***************
*** 168,172 ****
HTMLWriter &writer )
{
! NullPPDirectiveListener nullListener;
std::string blankedSource;
NonSemanticBlanker blanker( source, blankedSource, nullListener );
--- 168,172 ----
HTMLWriter &writer )
{
! PPDirectiveListenerPtr nullListener( new NullPPDirectiveListener() );
std::string blankedSource;
NonSemanticBlanker blanker( source, blankedSource, nullListener );
|
|
From: <bl...@us...> - 2003-12-20 08:59:53
|
Update of /cvsroot/cpptool/rfta/include/rfta/refactoring
In directory sc8-pr-cvs1:/tmp/cvs-serv12061/include/rfta/refactoring
Modified Files:
RenameTempRefactoring.h
Added Files:
TransformList.h
Log Message:
* Moved TransformList.h to include/rfta/refactoring as it is an interface header
--- NEW FILE: TransformList.h ---
// //////////////////////////////////////////////////////////////////////////
// Header file TransformList.h for class TransformList
// (c)Copyright 2002, Baptiste Lepilleur.
// Created: 2002/10/24
// //////////////////////////////////////////////////////////////////////////
#ifndef RFTA_TRANSFORMLIST_H
#define RFTA_TRANSFORMLIST_H
#include <rfta/refactoring/Config.h>
#include <deque>
#include <boost/shared_ptr.hpp>
#include <rfta/parser/SourceRange.h>
namespace Refactoring
{
class Transform;
class TextDocument;
/// List of Transform.
class TransformList
{
public:
/*! Constructs a TransformList object.
*/
TransformList();
/// Destructor.
virtual ~TransformList();
void add( TransformList &transforms );
void add( Transform &transform );
/**
* does check existing transformations for overlapping with given range.
*
* Attention: Function does only work if 'sortListByStartIndex' was called first !
*
* @param 'range' source range to be checked for overlapping
*/
bool hasOverlapping( const SourceRange& range);
void apply( TextDocument &document );
private:
/// Prevents the use of the copy constructor.
TransformList( const TransformList &other );
/// Prevents the use of the copy operator.
void operator =( const TransformList &other );
struct SortPredicate;
void sortListByStartIndex();
private:
typedef boost::shared_ptr<Transform> TransformPtr;
typedef std::deque<TransformPtr> Transforms;
Transforms transforms_;
};
// Inlines methods for TransformList:
// ----------------------------------
} // namespace Refactoring
#endif // RFTA_TRANSFORMLIST_H
Index: RenameTempRefactoring.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/include/rfta/refactoring/RenameTempRefactoring.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** RenameTempRefactoring.h 16 Dec 2003 13:26:11 -0000 1.13
--- RenameTempRefactoring.h 20 Dec 2003 08:59:50 -0000 1.14
***************
*** 10,14 ****
#include <rfta/refactoring/RefactoringBase.h>
#include <rfta/refactoring/ToolsBox.h>
! #include "TransformList.h"
namespace Refactoring
--- 10,14 ----
#include <rfta/refactoring/RefactoringBase.h>
#include <rfta/refactoring/ToolsBox.h>
! #include <rfta/refactoring/TransformList.h>
namespace Refactoring
|
Update of /cvsroot/cpptool/rfta/src/rfta In directory sc8-pr-cvs1:/tmp/cvs-serv12061/src/rfta Modified Files: CodeRewriter.h InlineTempRefactoring.cpp SplitDeclarationRefactoring.cpp TransformList.cpp TransformListTest.h Removed Files: TransformList.h Log Message: * Moved TransformList.h to include/rfta/refactoring as it is an interface header Index: CodeRewriter.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/CodeRewriter.h,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** CodeRewriter.h 19 Dec 2003 20:11:37 -0000 1.21 --- CodeRewriter.h 20 Dec 2003 08:59:50 -0000 1.22 *************** *** 7,11 **** #include "IndentLevelManager.h" ! #include "TransformList.h" #include <rfta/parser/SourceRange.h> #include <rfta/refactoring/CodeModelVisitor.h> --- 7,11 ---- #include "IndentLevelManager.h" ! #include <rfta/refactoring/TransformList.h> #include <rfta/parser/SourceRange.h> #include <rfta/refactoring/CodeModelVisitor.h> Index: InlineTempRefactoring.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/InlineTempRefactoring.cpp,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** InlineTempRefactoring.cpp 16 Dec 2003 13:24:06 -0000 1.10 --- InlineTempRefactoring.cpp 20 Dec 2003 08:59:50 -0000 1.11 *************** *** 18,22 **** #include "IdentifierResolver.h" #include "ReplaceTextTransform.h" ! #include "TransformList.h" namespace Refactoring --- 18,22 ---- #include "IdentifierResolver.h" #include "ReplaceTextTransform.h" ! #include <rfta/refactoring/TransformList.h> namespace Refactoring Index: SplitDeclarationRefactoring.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/SplitDeclarationRefactoring.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** SplitDeclarationRefactoring.cpp 19 Dec 2003 20:14:27 -0000 1.5 --- SplitDeclarationRefactoring.cpp 20 Dec 2003 08:59:50 -0000 1.6 *************** *** 11,15 **** #include "ReplaceTextTransform.h" #include "PreProcessTransform.h" ! #include "TransformList.h" #include <rfta/parser/MacroReplaceRegistration.h> #include <rfta/parser/MaxLODMutator.h> --- 11,15 ---- #include "ReplaceTextTransform.h" #include "PreProcessTransform.h" ! #include <rfta/refactoring/TransformList.h> #include <rfta/parser/MacroReplaceRegistration.h> #include <rfta/parser/MaxLODMutator.h> Index: TransformList.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/TransformList.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** TransformList.cpp 19 Dec 2003 20:15:21 -0000 1.6 --- TransformList.cpp 20 Dec 2003 08:59:50 -0000 1.7 *************** *** 7,11 **** #include "stdafx.h" #include "ReplaceTextTransform.h" ! #include "TransformList.h" #include <rfta/parser/SourceRange.h> #include <algorithm> --- 7,11 ---- #include "stdafx.h" #include "ReplaceTextTransform.h" ! #include <rfta/refactoring/TransformList.h> #include <rfta/parser/SourceRange.h> #include <algorithm> Index: TransformListTest.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/TransformListTest.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** TransformListTest.h 6 Mar 2003 22:18:41 -0000 1.4 --- TransformListTest.h 20 Dec 2003 08:59:50 -0000 1.5 *************** *** 8,12 **** #include "MockTextDocument.h" #include "ReplaceTextTransform.h" ! #include "TransformList.h" #include "UnitTesting.h" #include <boost/shared_ptr.hpp> --- 8,12 ---- #include "MockTextDocument.h" #include "ReplaceTextTransform.h" ! #include <rfta/refactoring/TransformList.h> #include "UnitTesting.h" #include <boost/shared_ptr.hpp> --- TransformList.h DELETED --- |
|
From: <net...@us...> - 2003-12-19 20:15:24
|
Update of /cvsroot/cpptool/rfta/src/rfta
In directory sc8-pr-cvs1:/tmp/cvs-serv29108/rfta/src/rfta
Modified Files:
TransformList.cpp TransformList.h
Log Message:
-- added function to add two transform lists
Index: TransformList.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/TransformList.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** TransformList.cpp 16 Dec 2003 13:44:18 -0000 1.5
--- TransformList.cpp 19 Dec 2003 20:15:21 -0000 1.6
***************
*** 33,36 ****
--- 33,49 ----
}
+ void
+ TransformList::add( TransformList &transforms )
+ {
+ Transforms::iterator i;
+ for (i = transforms.transforms_.begin();
+ i != transforms.transforms_.end();
+ i++)
+ {
+ TransformPtr v (*i);
+ transforms_.push_back( v );
+ }
+ }
+
void
Index: TransformList.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/TransformList.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** TransformList.h 16 Dec 2003 13:44:18 -0000 1.2
--- TransformList.h 19 Dec 2003 20:15:21 -0000 1.3
***************
*** 31,34 ****
--- 31,35 ----
virtual ~TransformList();
+ void add( TransformList &transforms );
void add( Transform &transform );
|
|
From: <net...@us...> - 2003-12-19 20:14:43
|
Update of /cvsroot/cpptool/rfta/src/rfta
In directory sc8-pr-cvs1:/tmp/cvs-serv28910/rfta/src/rfta
Modified Files:
SplitTempRefactoring.cpp SplitTempRefactoringTest.cpp
SplitTempRefactoringTest.h
Log Message:
-- added preprocessor support + test
Index: SplitTempRefactoring.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/SplitTempRefactoring.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** SplitTempRefactoring.cpp 16 Dec 2003 13:43:34 -0000 1.9
--- SplitTempRefactoring.cpp 19 Dec 2003 20:14:39 -0000 1.10
***************
*** 10,16 ****
#include "IdentifierResolverContext.h"
#include "ReplaceTextTransform.h"
! #include "TransformList.h"
#include <rfta/parser/MaxLODMutator.h>
! #include <rfta/parser/NonSemanticBlanker.h>
#include <rfta/parser/ParseContext.h>
#include <rfta/parser/ParserError.h>
--- 10,17 ----
#include "IdentifierResolverContext.h"
#include "ReplaceTextTransform.h"
! #include "PreProcessTransform.h"
! #include <rfta/parser/MacroReplaceRegistration.h>
#include <rfta/parser/MaxLODMutator.h>
! #include <rfta/parser/PreProcessor.h>
#include <rfta/parser/ParseContext.h>
#include <rfta/parser/ParserError.h>
***************
*** 48,55 ****
throw RefactoringError( RefactoringError::selectionNotInSource );
! PPDirectiveListenerPtr nullListener(new NullPPDirectiveListener());
! std::string blankedSource;
! NonSemanticBlanker blanker( source, blankedSource, nullListener );
! blanker.blank();
int compoundStartIndex =
--- 49,68 ----
throw RefactoringError( RefactoringError::selectionNotInSource );
! // preprocess
! PreProcessor proc( source );
! MacroReplaceRegistration registration;
! std::string blankedSource = proc.process(registration);
! registration.finishUpData();
!
! // correct pointer to location after preprocessing
! temporaryLocation_ -= registration.getReplacementDeltaBefore(SourceRange( temporaryLocation_, 1 ));
!
! // store macro replacement information
! int idx;
! for (idx=0; idx < registration.getSize(); idx++)
! {
! MacroReplaceRegistration::MacroReplacement entry = registration.getEntry(idx);
! transforms_.add( *new PreProcessTransform( entry.position_, entry.macroText_.size() - entry.replacement_.size() ) );
! }
int compoundStartIndex =
***************
*** 87,91 ****
const std::string &newTemporaryName )
{
- TransformList transforms;
/*ScopesHolder scopes( sourceNode_ );
--- 100,103 ----
***************
*** 117,121 ****
sourceNode_->getBlankedTextFor(variableTypePtr->getRange());
SourceRange nullRange(range.getStartIndex(), 0);
! transforms.add( *new ReplaceTextTransform( nullRange,
variableType ) );
break;
--- 129,133 ----
sourceNode_->getBlankedTextFor(variableTypePtr->getRange());
SourceRange nullRange(range.getStartIndex(), 0);
! transforms_.add( *new ReplaceTextTransform( nullRange,
variableType ) );
break;
***************
*** 123,131 ****
}
! transforms.add( *new ReplaceTextTransform( range,
newTemporaryName ) );
}
! transforms.apply( getDocument() );
}
--- 135,143 ----
}
! transforms_.add( *new ReplaceTextTransform( range,
newTemporaryName ) );
}
! transforms_.apply( getDocument() );
}
Index: SplitTempRefactoringTest.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/SplitTempRefactoringTest.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** SplitTempRefactoringTest.cpp 22 Dec 2002 15:47:34 -0000 1.3
--- SplitTempRefactoringTest.cpp 19 Dec 2003 20:14:39 -0000 1.4
***************
*** 77,80 ****
--- 77,109 ----
}
+ void
+ SplitTempRefactoringTest::testMacroAppearance()
+ {
+ builder_->add(
+ "#define TEXT int y=1;\n"
+ "{"
+ " TEXT\n"
+ " double x = getPrice();" );
+ builder_->addKeyingMid( " doSomething( ", "x", " );", "selection" );
+ builder_->add(
+ " x = getNewPrice();"
+ " doSomething( x );"
+ "}" );
+
+ applyRefactoring( "price" );
+
+ std::string expectedSource(
+ "#define TEXT int y=1;\n"
+ "{"
+ " TEXT\n"
+ " double price = getPrice();"
+ " doSomething( price );"
+ " double x = getNewPrice();"
+ " doSomething( x );"
+ "}" );
+ std::string actualSource( document_->getAllText() );
+ RFTA_ASSERT_EQUAL( expectedSource, actualSource );
+ }
+
Index: SplitTempRefactoringTest.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/SplitTempRefactoringTest.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** SplitTempRefactoringTest.h 13 Dec 2002 15:28:23 -0000 1.1
--- SplitTempRefactoringTest.h 19 Dec 2003 20:14:39 -0000 1.2
***************
*** 20,23 ****
--- 20,24 ----
CPPUNIT_TEST_SUITE( SplitTempRefactoringTest );
CPPUNIT_TEST( testEasiestCase );
+ CPPUNIT_TEST( testMacroAppearance );
CPPUNIT_TEST_SUITE_END();
***************
*** 34,37 ****
--- 35,39 ----
void testEasiestCase();
+ void testMacroAppearance();
private:
|
|
From: <net...@us...> - 2003-12-19 20:14:42
|
Update of /cvsroot/cpptool/rfta/include/rfta/refactoring
In directory sc8-pr-cvs1:/tmp/cvs-serv28910/rfta/include/rfta/refactoring
Modified Files:
SplitTempRefactoring.h
Log Message:
-- added preprocessor support + test
Index: SplitTempRefactoring.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/include/rfta/refactoring/SplitTempRefactoring.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** SplitTempRefactoring.h 22 Dec 2002 16:03:50 -0000 1.6
--- SplitTempRefactoring.h 19 Dec 2003 20:14:40 -0000 1.7
***************
*** 8,11 ****
--- 8,12 ----
#include "ToolsBox.h"
+ #include "TransformList.h"
#include <boost/utility.hpp>
#include <rfta/parser/ASTNode.h>
***************
*** 42,45 ****
--- 43,47 ----
int temporaryLocation_;
SourceASTNodePtr sourceNode_;
+ TransformList transforms_;
};
|
|
From: <net...@us...> - 2003-12-19 20:14:30
|
Update of /cvsroot/cpptool/rfta/include/rfta/refactoring
In directory sc8-pr-cvs1:/tmp/cvs-serv28824/rfta/include/rfta/refactoring
Modified Files:
SplitDeclarationRefactoring.h
Log Message:
-- added preprocessor support + test
Index: SplitDeclarationRefactoring.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/include/rfta/refactoring/SplitDeclarationRefactoring.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** SplitDeclarationRefactoring.h 22 Apr 2003 19:23:25 -0000 1.2
--- SplitDeclarationRefactoring.h 19 Dec 2003 20:14:27 -0000 1.3
***************
*** 12,15 ****
--- 12,16 ----
#include <rfta/parser/SourceRange.h>
#include <rfta/refactoring/RefactoringBase.h>
+ #include "TransformList.h"
#include <rfta/refactoring/CodeModelForward.h>
***************
*** 46,49 ****
--- 47,51 ----
int declarationLocation_;
SourceASTNodePtr sourceNode_;
+ TransformList transforms_;
};
|
|
From: <net...@us...> - 2003-12-19 20:14:30
|
Update of /cvsroot/cpptool/rfta/src/rfta
In directory sc8-pr-cvs1:/tmp/cvs-serv28824/rfta/src/rfta
Modified Files:
SplitDeclarationRefactoring.cpp
SplitDeclarationRefactoringTest.cpp
SplitDeclarationRefactoringTest.h
Log Message:
-- added preprocessor support + test
Index: SplitDeclarationRefactoring.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/SplitDeclarationRefactoring.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** SplitDeclarationRefactoring.cpp 16 Dec 2003 13:43:34 -0000 1.4
--- SplitDeclarationRefactoring.cpp 19 Dec 2003 20:14:27 -0000 1.5
***************
*** 10,16 ****
#include "IdentifierResolverContext.h"
#include "ReplaceTextTransform.h"
#include "TransformList.h"
#include <rfta/parser/MaxLODMutator.h>
! #include <rfta/parser/NonSemanticBlanker.h>
#include <rfta/parser/ParseContext.h>
#include <rfta/parser/ParserError.h>
--- 10,18 ----
#include "IdentifierResolverContext.h"
#include "ReplaceTextTransform.h"
+ #include "PreProcessTransform.h"
#include "TransformList.h"
+ #include <rfta/parser/MacroReplaceRegistration.h>
#include <rfta/parser/MaxLODMutator.h>
! #include <rfta/parser/PreProcessor.h>
#include <rfta/parser/ParseContext.h>
#include <rfta/parser/ParserError.h>
***************
*** 53,60 ****
throw RefactoringError( RefactoringError::selectionNotInSource );
! PPDirectiveListenerPtr nullListener(new NullPPDirectiveListener());
! std::string blankedSource;
! NonSemanticBlanker blanker( source, blankedSource, nullListener );
! blanker.blank();
int compoundStartIndex =
--- 55,74 ----
throw RefactoringError( RefactoringError::selectionNotInSource );
! // preprocess
! PreProcessor proc( source );
! MacroReplaceRegistration registration;
! std::string blankedSource = proc.process(registration);
! registration.finishUpData();
!
! // correct pointer to location after preprocessing
! declarationLocation_ -= registration.getReplacementDeltaBefore(SourceRange( declarationLocation_, 1 ));
!
! // store macro replacement information
! int idx;
! for (idx=0; idx < registration.getSize(); idx++)
! {
! MacroReplaceRegistration::MacroReplacement entry = registration.getEntry(idx);
! transforms_.add( *new PreProcessTransform( entry.position_, entry.macroText_.size() - entry.replacement_.size() ) );
! }
int compoundStartIndex =
***************
*** 139,143 ****
std::string source( getDocument().getAllText());
CodeModel::CodeRewriter writer(source, 2);
! writer.rewrite(compound, getDocument());
}
--- 153,157 ----
std::string source( getDocument().getAllText());
CodeModel::CodeRewriter writer(source, 2);
! writer.rewrite(compound, transforms_, getDocument());
}
Index: SplitDeclarationRefactoringTest.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/SplitDeclarationRefactoringTest.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** SplitDeclarationRefactoringTest.cpp 25 Apr 2003 07:53:26 -0000 1.3
--- SplitDeclarationRefactoringTest.cpp 19 Dec 2003 20:14:27 -0000 1.4
***************
*** 185,188 ****
--- 185,209 ----
}
+ void
+ SplitDeclarationRefactoringTest::testMacroUse()
+ {
+ builder_->add("#define D double z;\n");
+ builder_->add("{\n");
+ builder_->add(" D\n");
+ builder_->addKeyingMid(" double ", "x", ", y;\n", "selection");
+ builder_->add("}\n");
+ applyRefactoring( );
+
+ std::string expectedSource(
+ "#define D double z;\n"
+ "{\n"
+ " D\n"
+ " double x;\n"
+ " double y;\n"
+ "}\n" );
+ std::string actualSource( document_->getAllText() );
+ RFTA_ASSERT_EQUAL( expectedSource, actualSource );
+ }
+
} // namespace Refactoring
Index: SplitDeclarationRefactoringTest.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/SplitDeclarationRefactoringTest.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** SplitDeclarationRefactoringTest.h 25 Apr 2003 07:53:26 -0000 1.3
--- SplitDeclarationRefactoringTest.h 19 Dec 2003 20:14:27 -0000 1.4
***************
*** 25,28 ****
--- 25,29 ----
CPPUNIT_TEST( testInitializers );
CPPUNIT_TEST( testSubscope );
+ CPPUNIT_TEST( testMacroUse );
// CPPUNIT_TEST( testForDeclerations );
CPPUNIT_TEST_SUITE_END();
***************
*** 46,49 ****
--- 47,51 ----
void testSubscope();
void testForDeclerations();
+ void testMacroUse();
private:
|
|
From: <net...@us...> - 2003-12-19 20:14:11
|
Update of /cvsroot/cpptool/rfta/src/rftatest In directory sc8-pr-cvs1:/tmp/cvs-serv28755/rfta/src/rftatest Modified Files: SourceBuilder.cpp Log Message: -- added <stdafx.h> Index: SourceBuilder.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftatest/SourceBuilder.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SourceBuilder.cpp 16 Dec 2003 13:33:50 -0000 1.2 --- SourceBuilder.cpp 19 Dec 2003 20:14:08 -0000 1.3 *************** *** 3,6 **** --- 3,7 ---- // Created: 2002/11/27 // ////////////////////////////////////////////////////////////////////////// + #include <stdafx.h> #include <rfta/test/SourceBuilder.h> |
|
From: <net...@us...> - 2003-12-19 20:13:24
|
Update of /cvsroot/cpptool/rfta/src/rftaparser In directory sc8-pr-cvs1:/tmp/cvs-serv28632/rfta/src/rftaparser Modified Files: PreProcessor.cpp PreProcessorError.cpp PreProcessResolver.cpp Log Message: -- added <stdafx.h> Index: PreProcessor.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/PreProcessor.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PreProcessor.cpp 16 Dec 2003 13:47:00 -0000 1.1 --- PreProcessor.cpp 19 Dec 2003 20:13:21 -0000 1.2 *************** *** 4,7 **** --- 4,8 ---- // Created: 2003/12/13 // ////////////////////////////////////////////////////////////////////////// + #include <stdafx.h> #include <string> Index: PreProcessorError.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/PreProcessorError.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PreProcessorError.cpp 16 Dec 2003 13:47:00 -0000 1.1 --- PreProcessorError.cpp 19 Dec 2003 20:13:21 -0000 1.2 *************** *** 4,8 **** // Created: 2003/12/14 // ////////////////////////////////////////////////////////////////////////// ! #include <rfta/parser/PreProcessorError.h> #include <string> --- 4,8 ---- // Created: 2003/12/14 // ////////////////////////////////////////////////////////////////////////// ! #include <stdafx.h> #include <rfta/parser/PreProcessorError.h> #include <string> Index: PreProcessResolver.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/PreProcessResolver.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PreProcessResolver.cpp 16 Dec 2003 13:47:00 -0000 1.1 --- PreProcessResolver.cpp 19 Dec 2003 20:13:21 -0000 1.2 *************** *** 4,7 **** --- 4,8 ---- // Created: 2003/12/13 // ////////////////////////////////////////////////////////////////////////// + #include <stdafx.h> #include "PreProcessResolver.h" #include <rfta/parser/PreProcessorError.h> |
|
From: <net...@us...> - 2003-12-19 20:12:42
|
Update of /cvsroot/cpptool/rfta/src/rftaparser In directory sc8-pr-cvs1:/tmp/cvs-serv28462/rfta/src/rftaparser Modified Files: MacroReplaceRegistration.cpp Log Message: -- added <stdafx.h> Index: MacroReplaceRegistration.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/MacroReplaceRegistration.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MacroReplaceRegistration.cpp 16 Dec 2003 13:47:00 -0000 1.1 --- MacroReplaceRegistration.cpp 19 Dec 2003 20:12:37 -0000 1.2 *************** *** 4,8 **** // Created: 2003/12/14 // ////////////////////////////////////////////////////////////////////////// ! #pragma warning( disable: 4786 ) #include <rfta/parser/MacroReplaceRegistration.h> #include <utility> --- 4,8 ---- // Created: 2003/12/14 // ////////////////////////////////////////////////////////////////////////// ! #include <stdafx.h> #include <rfta/parser/MacroReplaceRegistration.h> #include <utility> |