You can subscribe to this list here.
| 2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(37) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2003 |
Jan
(15) |
Feb
(26) |
Mar
(97) |
Apr
(224) |
May
(226) |
Jun
|
Jul
(3) |
Aug
(22) |
Sep
(48) |
Oct
|
Nov
|
Dec
(38) |
| 2004 |
Jan
(28) |
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
(37) |
Jul
|
Aug
(73) |
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <bl...@us...> - 2003-04-27 22:02:07
|
Update of /cvsroot/cpptool/rfta/src/rfta
In directory sc8-pr-cvs1:/tmp/cvs-serv30698/src/rfta
Modified Files:
IdentifierResolverContext.cpp IdentifierResolverContext.h
IdentifierResolverContextTest.cpp InlineTempRefactoring.cpp
RenameTempRefactoring.cpp SplitTempRefactoring.cpp
ToolsBoxTest.cpp
Log Message:
* removed extra parameters for IdentifierResolverContext constructor.
Index: IdentifierResolverContext.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/IdentifierResolverContext.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** IdentifierResolverContext.cpp 20 Dec 2002 08:30:52 -0000 1.6
--- IdentifierResolverContext.cpp 27 Apr 2003 22:02:02 -0000 1.7
***************
*** 12,17 ****
{
! IdentifierResolverContext::IdentifierResolverContext( const SourceASTNodePtr &sourceNode )
! : sourceNode_( sourceNode )
{
}
--- 12,16 ----
{
! IdentifierResolverContext::IdentifierResolverContext()
{
}
Index: IdentifierResolverContext.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/IdentifierResolverContext.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** IdentifierResolverContext.h 15 Dec 2002 22:11:05 -0000 1.4
--- IdentifierResolverContext.h 27 Apr 2003 22:02:02 -0000 1.5
***************
*** 39,43 ****
/*! Constructs a IdentifierResolverContext object.
*/
! IdentifierResolverContext( const SourceASTNodePtr &sourceNode );
/// Destructor.
--- 39,43 ----
/*! Constructs a IdentifierResolverContext object.
*/
! IdentifierResolverContext();
/// Destructor.
***************
*** 70,75 ****
typedef std::map<ASTNodePtr,ASTNodePtr> ResolvedUnqualifiedIdentifiers;
ResolvedUnqualifiedIdentifiers resolvedIdentifiers_;
-
- SourceASTNodePtr sourceNode_;
};
--- 70,73 ----
Index: IdentifierResolverContextTest.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/IdentifierResolverContextTest.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** IdentifierResolverContextTest.cpp 16 Dec 2002 20:09:43 -0000 1.3
--- IdentifierResolverContextTest.cpp 27 Apr 2003 22:02:02 -0000 1.4
***************
*** 43,47 ****
{
parse();
! context_.reset( new IdentifierResolverContext( sourceNode_ ) );
}
--- 43,47 ----
{
parse();
! context_.reset( new IdentifierResolverContext() );
}
Index: InlineTempRefactoring.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/InlineTempRefactoring.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** InlineTempRefactoring.cpp 6 Apr 2003 16:17:18 -0000 1.7
--- InlineTempRefactoring.cpp 27 Apr 2003 22:02:02 -0000 1.8
***************
*** 250,254 ****
throw RefactoringError( RefactoringError::selectionIsNotAnIdentifier );
! IdentifierResolverContext context( sourceNode_ );
IdentifierResolver resolver( context );
resolver.visitNode( sourceNode_ );
--- 250,254 ----
throw RefactoringError( RefactoringError::selectionIsNotAnIdentifier );
! IdentifierResolverContext context;
IdentifierResolver resolver( context );
resolver.visitNode( sourceNode_ );
Index: RenameTempRefactoring.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/RenameTempRefactoring.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** RenameTempRefactoring.cpp 5 Apr 2003 12:14:45 -0000 1.15
--- RenameTempRefactoring.cpp 27 Apr 2003 22:02:03 -0000 1.16
***************
*** 155,159 ****
throw RefactoringError( RefactoringError::selectionIsNotAnIdentifier );
! IdentifierResolverContext context( sourceNode_ );
IdentifierResolver resolver( context );
resolver.visitNode( sourceNode_ );
--- 155,159 ----
throw RefactoringError( RefactoringError::selectionIsNotAnIdentifier );
! IdentifierResolverContext context;
IdentifierResolver resolver( context );
resolver.visitNode( sourceNode_ );
Index: SplitTempRefactoring.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/SplitTempRefactoring.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** SplitTempRefactoring.cpp 22 Dec 2002 16:03:52 -0000 1.7
--- SplitTempRefactoring.cpp 27 Apr 2003 22:02:03 -0000 1.8
***************
*** 140,144 ****
throw RefactoringError( RefactoringError::selectionIsNotAnIdentifier );
! IdentifierResolverContext context( sourceNode_ );
IdentifierResolver resolver( context );
resolver.visitNode( sourceNode_ );
--- 140,144 ----
throw RefactoringError( RefactoringError::selectionIsNotAnIdentifier );
! IdentifierResolverContext context;
IdentifierResolver resolver( context );
resolver.visitNode( sourceNode_ );
Index: ToolsBoxTest.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/ToolsBoxTest.cpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** ToolsBoxTest.cpp 22 Dec 2002 16:03:53 -0000 1.14
--- ToolsBoxTest.cpp 27 Apr 2003 22:02:03 -0000 1.15
***************
*** 307,311 ****
ASTNodePtr compoundNode = sourceNode_->getChildAt(1);
! IdentifierResolverContext context( sourceNode_ );
IdentifierResolver resolver( context );
resolver.visitNode( compoundNode );
--- 307,311 ----
ASTNodePtr compoundNode = sourceNode_->getChildAt(1);
! IdentifierResolverContext context;
IdentifierResolver resolver( context );
resolver.visitNode( compoundNode );
|
|
From: <bl...@us...> - 2003-04-27 22:00:47
|
Update of /cvsroot/cpptool/rfta/src/pyrfta
In directory sc8-pr-cvs1:/tmp/cvs-serv30084/src/pyrfta
Modified Files:
ExposeBase.cpp
Log Message:
* added automatic string conversion
Index: ExposeBase.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/pyrfta/ExposeBase.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** ExposeBase.cpp 10 Apr 2003 08:40:34 -0000 1.2
--- ExposeBase.cpp 27 Apr 2003 22:00:42 -0000 1.3
***************
*** 21,24 ****
--- 21,25 ----
.def_readwrite( "type", &Change::type_ )
.def_readwrite( "oldRange", &Change::oldRange_ )
+ .def( "__repr__", &Change::toString )
;
***************
*** 39,43 ****
.def( "contains", &SourceRange::contains )
.def( "overlap", &SourceRange::overlap )
! .def( "toString", &SourceRange::toString ) // should use str(self)
.def( self == self )
.def( self < self )
--- 40,44 ----
.def( "contains", &SourceRange::contains )
.def( "overlap", &SourceRange::overlap )
! .def( "__repr__", &SourceRange::toString )
.def( self == self )
.def( self < self )
|
|
From: <bl...@us...> - 2003-04-27 22:00:46
|
Update of /cvsroot/cpptool/rfta/include/rfta/refactoring
In directory sc8-pr-cvs1:/tmp/cvs-serv30084/include/rfta/refactoring
Modified Files:
ChangeTrackers.h
Log Message:
* added automatic string conversion
Index: ChangeTrackers.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/include/rfta/refactoring/ChangeTrackers.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** ChangeTrackers.h 22 Apr 2003 19:11:39 -0000 1.3
--- ChangeTrackers.h 27 Apr 2003 22:00:40 -0000 1.4
***************
*** 60,63 ****
--- 60,69 ----
}
+ const std::string toString() const
+ {
+ const char *types[] = { "added", "replaced", "removed", "unmodified" };
+ return std::string("Change<type=") + types[type_] + ";oldRange=" + oldRange_.toString() + ">";
+ }
+
ChangeType type_;
SourceRange oldRange_;
|
|
From: <bl...@us...> - 2003-04-27 21:59:52
|
Update of /cvsroot/cpptool/rfta/src/rftaparser
In directory sc8-pr-cvs1:/tmp/cvs-serv29686/src/rftaparser
Modified Files:
rftaparser.dsp
Added Files:
EnumeratorTest.cpp EnumeratorTest.h
Log Message:
* added Enumerator concept. Allow enumeration of STL container while hiding implementation.
--- NEW FILE: EnumeratorTest.cpp ---
// //////////////////////////////////////////////////////////////////////////
// (c)Copyright 2002, Baptiste Lepilleur.
// Created: 2003/04/27
// //////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "EnumeratorTest.h"
#include <algorithm>
#include <iterator>
namespace Refactoring
{
RFTAPARSER_TEST_SUITE_REGISTRATION( EnumeratorTest );
EnumeratorTest::EnumeratorTest()
{
}
EnumeratorTest::~EnumeratorTest()
{
}
void
EnumeratorTest::setUp()
{
deque1_.clear();
deque1_.push_back( 12 ); // must be ordered
deque1_.push_back( 23 );
deque1_.push_back( 34 );
vector1_.clear();
std::copy( deque1_.begin(), deque1_.end(), std::back_inserter( vector1_ ) );
set1_.clear();
std::copy( deque1_.begin(), deque1_.end(), std::inserter( set1_, set1_.begin() ) );
}
void
EnumeratorTest::tearDown()
{
set1_.clear();
vector1_.clear();
deque1_.clear();
}
void
EnumeratorTest::testNullEnumerator()
{
IntEnum e;
checkHasNoMoreElements( e );
IntEnum e2( e );
checkHasNoMoreElements( e2 );
IntEnum e3( e.clone() );
checkHasNoMoreElements( e3 );
}
void
EnumeratorTest::testStlEnumerator()
{
IntEnum e1 = Xtl::enumStl( deque1_ );
checkContent( e1 );
IntEnum e2 = Xtl::enumStl( vector1_ );
checkContent( e2 );
IntEnum e3 = Xtl::enumStl( set1_ );
checkContent( e3 );
CharEnum e4 = Xtl::enumStl( deque1_, Xtl::Type<char>() );
checkContent( e4 );
CharEnum e5 = Xtl::enumStl( vector1_, Xtl::Type<char>() );
checkContent( e5 );
CharEnum e6 = Xtl::enumStl( set1_, Xtl::Type<char>() );
checkContent( e6 );
}
void
EnumeratorTest::testStlRangeEnumerator()
{
IntEnum e1a = Xtl::enumStl( deque1_.begin(), deque1_.begin()+2 );
IntEnum e1b = Xtl::enumStl( deque1_.begin()+1, deque1_.begin()+3 );
checkRangesContent( e1a, e1b );
IntEnum e2a = Xtl::enumStl( vector1_.begin(), vector1_.begin()+2 );
IntEnum e2b = Xtl::enumStl( vector1_.begin()+1, vector1_.begin()+3 );
checkRangesContent( e2a, e2b );
IntSet::iterator itEnd = set1_.end();
--itEnd;
IntSet::iterator itStart = set1_.begin();
itStart++;
IntEnum e3a = Xtl::enumStl( set1_.begin(), itEnd );
IntEnum e3b = Xtl::enumStl( itStart, set1_.end() );
checkRangesContent( e3a, e3b );
CharEnum e4a = Xtl::enumStl( deque1_.begin(), deque1_.begin()+2, Xtl::Type<char>() );
CharEnum e4b = Xtl::enumStl( deque1_.begin()+1, deque1_.begin()+3, Xtl::Type<char>() );
checkRangesContent( e4a, e4b );
CharEnum e5a = Xtl::enumStl( vector1_.begin(), vector1_.begin()+2, Xtl::Type<char>() );
CharEnum e5b = Xtl::enumStl( vector1_.begin()+1, vector1_.begin()+3, Xtl::Type<char>() );
checkRangesContent( e5a, e5b );
CharEnum e6a = Xtl::enumStl( set1_.begin(), itEnd, Xtl::Type<char>() );
CharEnum e6b = Xtl::enumStl( itStart, set1_.end(), Xtl::Type<char>() );
checkRangesContent( e6a, e6b );
}
void
EnumeratorTest::testStlEnumConstructAdapator()
{
IntDequeEnum e = Xtl::enumStl( deque1_, Xtl::Type<IntDeque>() ); // force usage of IntDeque constructor
IntDeque a = e.getNext();
RFTA_ASSERT_EQUAL( 12, a.size() );
IntDeque b = e.getNext();
RFTA_ASSERT_EQUAL( 23, b.size() );
IntDeque c = e.getNext();
RFTA_ASSERT_EQUAL( 34, c.size() );
checkHasNoMoreElements( e );
}
} // namespace Refactoring
--- NEW FILE: EnumeratorTest.h ---
// //////////////////////////////////////////////////////////////////////////
// (c)Copyright 2002, Baptiste Lepilleur.
// Created: 2003/04/27
// //////////////////////////////////////////////////////////////////////////
#ifndef RFTA_ENUMERATORTEST_H
#define RFTA_ENUMERATORTEST_H
#include "UnitTesting.h"
#include <xtl/Enumerator.h>
#include <xtl/StlEnumerator.h>
#include <deque>
#include <set>
#include <vector>
namespace Refactoring
{
/// Unit tests for EnumeratorTest
class EnumeratorTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( EnumeratorTest );
CPPUNIT_TEST( testNullEnumerator );
CPPUNIT_TEST( testStlEnumerator );
CPPUNIT_TEST( testStlRangeEnumerator );
CPPUNIT_TEST( testStlEnumConstructAdapator );
CPPUNIT_TEST_SUITE_END();
public:
/*! Constructs a EnumeratorTest object.
*/
EnumeratorTest();
/// Destructor.
virtual ~EnumeratorTest();
void setUp();
void tearDown();
void testNullEnumerator();
void testStlEnumerator();
void testStlRangeEnumerator();
void testStlEnumConstructAdapator();
private:
typedef Xtl::Enumerator<int> IntEnum;
typedef Xtl::Enumerator<char> CharEnum;
template<typename EnumeratorType>
void checkHasNoMoreElements( EnumeratorType &e )
{
CPPUNIT_ASSERT( !e.hasNext() );
RFTA_ASSERT_THROW( e.getNext(), Xtl::EnumeratorError );
}
template<typename EnumeratorType>
void checkContent( EnumeratorType &e )
{
RFTA_ASSERT_EQUAL( 12, e.getNext() );
RFTA_ASSERT_EQUAL( 23, e.getNext() );
RFTA_ASSERT_EQUAL( 34, e.getNext() );
checkHasNoMoreElements( e );
}
template<typename EnumeratorType>
void checkRangesContent( EnumeratorType &e1, EnumeratorType &e2 )
{
RFTA_ASSERT_EQUAL( 12, e1.getNext() );
RFTA_ASSERT_EQUAL( 23, e1.getNext() );
checkHasNoMoreElements( e1 );
RFTA_ASSERT_EQUAL( 23, e2.getNext() );
RFTA_ASSERT_EQUAL( 34, e2.getNext() );
checkHasNoMoreElements( e2 );
}
typedef std::deque<int> IntDeque;
IntDeque deque1_;
typedef std::vector<int> IntVector;
IntVector vector1_;
typedef std::set<int> IntSet;
IntSet set1_;
typedef Xtl::Enumerator<IntDeque> IntDequeEnum;
};
// Inlines methods for EnumeratorTest:
// -----------------------------------
} // namespace Refactoring
#endif // RFTA_ENUMERATORTEST_H
Index: rftaparser.dsp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftaparser/rftaparser.dsp,v
retrieving revision 1.40
retrieving revision 1.41
diff -C2 -d -r1.40 -r1.41
*** rftaparser.dsp 26 Apr 2003 21:13:35 -0000 1.40
--- rftaparser.dsp 27 Apr 2003 21:59:49 -0000 1.41
***************
*** 130,141 ****
--- 130,173 ----
# Begin Source File
+ SOURCE=..\..\include\xtl\EnumAdaptor.h
+ # End Source File
+ # Begin Source File
+
+ SOURCE=..\..\include\xtl\Enumerator.h
+ # End Source File
+ # Begin Source File
+
+ SOURCE=..\..\include\xtl\EnumeratorImpl.h
+ # End Source File
+ # Begin Source File
+
SOURCE=..\..\include\xtl\Forwards.h
# End Source File
# Begin Source File
+ SOURCE=..\..\include\xtl\Int2Type.h
+ # End Source File
+ # Begin Source File
+
SOURCE=..\..\include\xtl\IntrusiveCount.h
# End Source File
# Begin Source File
+ SOURCE=..\..\include\xtl\NullEnumerator.h
+ # End Source File
+ # Begin Source File
+
+ SOURCE=..\..\include\xtl\StlEnumerator.h
+ # End Source File
+ # Begin Source File
+
+ SOURCE=..\..\include\xtl\StlMapEnumerator.h
+ # End Source File
+ # Begin Source File
+
+ SOURCE=..\..\include\xtl\Type.h
+ # End Source File
+ # Begin Source File
+
SOURCE=..\..\include\xtl\VirtualFunctor.h
# End Source File
***************
*** 581,584 ****
--- 613,642 ----
SOURCE=.\CStringViewTest.h
+
+ !IF "$(CFG)" == "rftaparser - Win32 Release"
+
+ # PROP Exclude_From_Build 1
+
+ !ELSEIF "$(CFG)" == "rftaparser - Win32 Debug"
+
+ !ENDIF
+
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\EnumeratorTest.cpp
+
+ !IF "$(CFG)" == "rftaparser - Win32 Release"
+
+ # PROP Exclude_From_Build 1
+
+ !ELSEIF "$(CFG)" == "rftaparser - Win32 Debug"
+
+ !ENDIF
+
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\EnumeratorTest.h
!IF "$(CFG)" == "rftaparser - Win32 Release"
|
Update of /cvsroot/cpptool/rfta/include/xtl
In directory sc8-pr-cvs1:/tmp/cvs-serv29686/include/xtl
Added Files:
EnumAdaptor.h Enumerator.h EnumeratorImpl.h Int2Type.h
NullEnumerator.h StlEnumerator.h StlMapEnumerator.h Type.h
Log Message:
* added Enumerator concept. Allow enumeration of STL container while hiding implementation.
--- NEW FILE: EnumAdaptor.h ---
#ifndef XTL_ENUMADAPTOR_H_INCLUDED
#define XTL_ENUMADAPTOR_H_INCLUDED
#include <boost/config.hpp>
namespace Xtl {
template<typename EnumeratedType>
struct EnumAdaptor
{
typedef EnumeratedType EnumeratedType;
};
template<typename EnumeratedType>
struct IdendityEnumAdpator : public EnumAdaptor<EnumeratedType>
{
EnumeratedType operator()( const EnumeratedType &source ) const
{
return source;
}
};
template<typename EnumeratedType>
struct ConstructEnumAdaptor : public EnumAdaptor<EnumeratedType>
{
template<typename SourceType>
EnumeratedType operator()( const SourceType &source ) const
{
return EnumeratedType( source );
}
};
template<typename EnumeratedType>
struct FirstEnumAdaptor : public EnumAdaptor<EnumeratedType>
{
template<typename SourceType>
EnumeratedType operator()( const SourceType &source ) const
{
return EnumeratedType( source.first );
}
};
template<typename EnumeratedType>
struct SecondEnumAdaptor : public EnumAdaptor<EnumeratedType>
{
template<typename SourceType>
EnumeratedType operator()( const SourceType &source ) const
{
return EnumeratedType( source.second );
}
};
template<typename EnumeratedType>
struct DerefEnumAdaptor : public EnumAdaptor<EnumeratedType>
{
template<typename SourceType>
EnumeratedType operator()( const SourceType &source ) const
{
return EnumeratedType( *source );
}
};
template<typename Functor>
struct TransformEnumAdaptor : public EnumAdaptor<BOOST_DEDUCED_TYPENAME Functor::result_type>
{
TransformEnumAdaptor()
{
}
TransformEnumAdaptor( Functor functor )
: functor_( functor )
{
}
template<typename SourceType>
EnumeratedType operator()( const SourceType &source ) const
{
return functor_( source );
}
Functor functor_;
};
template<typename OutterAdaptor
,typename InnerFunctor>
struct ComposeAdaptor : public EnumAdaptor<BOOST_DEDUCED_TYPENAME OutterAdaptor::EnumeratedType>
{
ComposeAdaptor()
{
}
ComposeAdaptor( OutterAdaptor outter,
InnerFunctor inner )
: outter_( outter )
, inner_( inner )
{
}
template<typename SourceType>
EnumeratedType operator()( const SourceType &x ) const
{
return outter_( inner_( x ) );
}
OutterAdaptor outter_;
InnerFunctor inner_;
};
} // namespace Xtl
#endif // XTL_ENUMADAPTOR_H_INCLUDED
--- NEW FILE: Enumerator.h ---
#ifndef XTL_ENUMERATOR_H_INCLUDED
#define XTL_ENUMERATOR_H_INCLUDED
#include <xtl/NullEnumerator.h>
namespace Xtl {
template<typename EnumeratedType>
class Enumerator
{
public:
typedef boost::intrusive_ptr< EnumeratorImpl<EnumeratedType> > ImplPtr;
Enumerator()
: impl_( new NullEnumeratorImpl<EnumeratedType>() )
{
}
Enumerator( const ImplPtr &impl )
: impl_( impl )
{
}
EnumeratedType getNext()
{
return impl_->getNext();
}
bool hasNext() const
{
return impl_->hasNext();
}
Enumerator clone() const
{
return Enumerator( impl_->clone() );
}
private:
ImplPtr impl_;
};
} // namespace Xtl
#endif // XTL_ENUMERATOR_H_INCLUDED
--- NEW FILE: EnumeratorImpl.h ---
#ifndef XTL_ENUMERATORIMPL_H_INCLUDED
#define XTL_ENUMERATORIMPL_H_INCLUDED
#include <boost/intrusive_ptr.hpp>
#include <xtl/IntrusiveCount.h>
#include <stdexcept>
namespace Xtl {
class EnumeratorError : public std::out_of_range
{
public:
EnumeratorError()
: std::out_of_range( "Enumerator::getNext() called with no next item" )
{
}
~EnumeratorError() throw()
{
}
};
template<typename EnumeratedType>
class EnumeratorImpl : public IntrusiveCount
{
public:
typedef boost::intrusive_ptr<EnumeratorImpl> Ptr;
virtual EnumeratedType getNext() =0;
virtual bool hasNext() const =0;
virtual Ptr clone() const =0;
};
} // namespace Xtl
#endif // XTL_ENUMERATORIMPL_H_INCLUDED
--- NEW FILE: Int2Type.h ---
#ifndef XTL_INT2TYPE_H_INCLUDED
#define XTL_INT2TYPE_H_INCLUDED
// Based on Andrei Alexandrescu article in C++ user journal.
namespace Xtl {
template <int v>
struct Int2Type
{
enum { value = v };
};
} // namespace Xtl
#endif // XTL_INT2TYPE_H_INCLUDED
--- NEW FILE: NullEnumerator.h ---
#ifndef XTL_NULLENUMERATOR_H_INCLUDED
#define XTL_NULLENUMERATOR_H_INCLUDED
#include <xtl/EnumeratorImpl.h>
namespace Xtl {
template<typename EnumeratedType>
class NullEnumeratorImpl : public EnumeratorImpl<EnumeratedType>
{
public: // overridden from EnumeratorImpl
EnumeratedType getNext()
{
throw EnumeratorError();
}
bool hasNext() const
{
return false;
}
Ptr clone() const
{
return Ptr( const_cast<NullEnumeratorImpl *>(this) ); // no state, don't need cloning
}
};
} // namespace Xtl
#endif // XTL_NULLENUMERATOR_H_INCLUDED
--- NEW FILE: StlEnumerator.h ---
#ifndef XTL_STLENUMERATOR_H_INCLUDED
#define XTL_STLENUMERATOR_H_INCLUDED
#include <xtl/Enumerator.h>
#include <xtl/EnumAdaptor.h>
#include <xtl/Int2Type.h>
#include <xtl/Type.h>
#include <boost/type_traits.hpp>
#include <functional>
namespace Xtl {
template<typename StlForwardIteratorType
,typename EnumeratedType
,typename Adaptor=IdendityEnumAdpator<EnumeratedType> >
class StlEnumeratorImpl : public EnumeratorImpl<EnumeratedType>
{
public:
typedef StlEnumeratorImpl<StlForwardIteratorType,EnumeratedType,Adaptor> ThisType;
enum {
isIdentityAdaptor = ::boost::is_convertible<IdendityEnumAdpator<EnumeratedType>
,Adaptor>::value
};
StlEnumeratorImpl( StlForwardIteratorType first,
StlForwardIteratorType last )
: current_( first )
, last_( last )
{
}
StlEnumeratorImpl( StlForwardIteratorType first,
StlForwardIteratorType last,
Adaptor adaptor )
: current_( first )
, last_( last )
, adaptor_( adaptor )
{
}
public: // overridden from EnumeratorImpl
EnumeratedType getNext()
{
if ( current_ == last_ )
throw EnumeratorError();
return doGetNext( Int2Type<isIdentityAdaptor>() );
}
bool hasNext() const
{
return current_ != last_;
}
Ptr clone() const
{
return Ptr( new ThisType( current_, last_ ) );
}
private:
inline EnumeratedType doGetNext( Int2Type<true> )
{
return *current_++;
}
inline EnumeratedType doGetNext( Int2Type<false> )
{
return adaptor_( *current_++ );
}
private:
StlForwardIteratorType current_;
StlForwardIteratorType last_;
Adaptor adaptor_;
};
template<typename StlIteratorType
,typename Adaptor>
Enumerator<BOOST_DEDUCED_TYPENAME Adaptor::EnumeratedType>
enumStlAdapt( StlIteratorType first, StlIteratorType last, Adaptor adaptor )
{
typedef BOOST_DEDUCED_TYPENAME Adaptor::EnumeratedType EnumeratedType;
return Enumerator<EnumeratedType>(
new StlEnumeratorImpl<StlIteratorType
,EnumeratedType
,Adaptor>( first, last, adaptor ) );
}
template<typename StlContainerType
,typename Adaptor>
Enumerator<BOOST_DEDUCED_TYPENAME Adaptor::EnumeratedType>
enumStlAdapt( const StlContainerType &sequence, Adaptor adaptor )
{
return enumStlAdapt( sequence.begin(), sequence.end(), adaptor );
}
template<typename StlContainerType
,typename EnumeratedType>
Enumerator<EnumeratedType>
enumStl( const StlContainerType &sequence, Type<EnumeratedType> )
{
return Enumerator<EnumeratedType>(
new StlEnumeratorImpl<BOOST_DEDUCED_TYPENAME StlContainerType::const_iterator
,EnumeratedType
,ConstructEnumAdaptor<EnumeratedType> >(
sequence.begin(), sequence.end() ) );
}
template<typename StlContainerType>
Enumerator<BOOST_DEDUCED_TYPENAME StlContainerType::value_type>
enumStl( const StlContainerType &sequence )
{
return enumStlAdapt( sequence,
IdendityEnumAdpator<BOOST_DEDUCED_TYPENAME StlContainerType::value_type>() );
}
template<typename StlIteratorType
,typename EnumeratedType>
Enumerator<EnumeratedType>
enumStl( StlIteratorType first, StlIteratorType last, Type<EnumeratedType> )
{
return Enumerator<EnumeratedType>(
new StlEnumeratorImpl<StlIteratorType
,EnumeratedType
,ConstructEnumAdaptor<EnumeratedType> >( first, last ) );
}
#if defined( BOOST_MSVC_STD_ITERATOR ) // VC6, std::vector::iterator is a pointer => type is not extractable !
/// \warning : first and last iterator must be of exactly the same type. Unexpected behavior otherwise.
/// no compile-time way to force that constraint. It is highly recommended to compile on a conforming STL( vc7).
template<typename Category
,typename EnumeratedType
,typename Distance
,typename IteratorType>
Enumerator<EnumeratedType>
enumStl( const std::iterator<Category, EnumeratedType, Distance> &first,
const IteratorType &last )
{
return enumStlAdapt( static_cast<const IteratorType &>(first), last,
IdendityEnumAdpator<EnumeratedType>() );
}
// Overload to handle std::vector::iterator, which is a pointer.
template<typename EnumeratedType>
Enumerator<EnumeratedType>
enumStl( const EnumeratedType *first, const EnumeratedType *last )
{
return enumStlAdapt( first, last, IdendityEnumAdpator<EnumeratedType>() );
}
#else // std::iterator_traits is available for all container (including std::vector)
template<typename StlIteratorType>
Enumerator<BOOST_DEDUCED_TYPENAME std::iterator_traits<StlIteratorType>::value_type>
enumStl( StlIteratorType first, StlIteratorType last )
{
typedef BOOST_DEDUCED_TYPENAME std::iterator_traits<StlIteratorType>::value_type EnumeratedType;
return enumStlAdapt( first, last,
IdendityEnumAdpator<EnumeratedType>() );
}
#endif
template<typename StlMapType>
Enumerator<BOOST_DEDUCED_TYPENAME StlMapType::key_type>
enumStlMapKeys( const StlMapType &map )
{
typedef BOOST_DEDUCED_TYPENAME StlMapType::key_type EnumeratedType;
return enumStlAdapt( map, FirstEnumAdaptor<EnumeratedType>() );
}
template<typename StlMapType
,typename Adaptor>
Enumerator<BOOST_DEDUCED_TYPENAME Adaptor::EnumeratedType>
enumStlMapKeysAdapt( const StlMapType &map, Adaptor adaptor )
{
return enumStlAdapt( map, ComposeAdaptor<Adaptor,FirstEnumAdaptor>() );
}
template<typename StlMapType
,typename EnumeratedType>
Enumerator<BOOST_DEDUCED_TYPENAME StlMapType::key_type>
enumStlMapKeys( const StlMapType &map, Type<EnumeratedType>() )
{
return enumStlMapKeysAdapt( map, ConstructEnumAdaptor<EnumeratedType>() );
}
template<typename StlIteratorType>
Enumerator<BOOST_DEDUCED_TYPENAME std::iterator_traits<StlIteratorType>::value_type>
enumStlMapKeys( StlIteratorType first, StlIteratorType last )
{
typedef BOOST_DEDUCED_TYPENAME std::iterator_traits<StlIteratorType>::value_type EnumeratedType;
return enumStlAdapt( first, last,
FirstEnumAdaptor<EnumeratedType>() );
}
template<typename StlIteratorType
,typename Adaptor>
Enumerator<BOOST_DEDUCED_TYPENAME Adaptor::EnumeratedType>
enumStlMapKeys( StlIteratorType first, StlIteratorType last, Adaptor adaptor )
{
return enumStlAdapt( first, last,
ComposeAdaptor<Adaptor,FirstEnumAdaptor>() );
}
template<typename StlIteratorType
,typename EnumeratedType>
Enumerator<EnumeratedType>
enumStlMapKeys( StlIteratorType first, StlIteratorType last, Type<EnumeratedType> )
{
return enumStlMapKeysAdapt( first, last, ConstructEnumAdaptor<EnumeratedType>() );
}
template<typename StlMapType>
Enumerator<BOOST_DEDUCED_TYPENAME StlMapType::referent_type>
enumStlMapValues( const StlMapType &map )
{
typedef BOOST_DEDUCED_TYPENAME StlMapType::referent_type EnumeratedType;
return enumStlAdapt( map, SecondEnumAdaptor<EnumeratedType>() );
}
template<typename StlMapType
,typename Adaptor>
Enumerator<BOOST_DEDUCED_TYPENAME Adaptor::EnumeratedType>
enumStlMapValuesAdapt( const StlMapType &map, Adaptor adaptor )
{
typedef BOOST_DEDUCED_TYPENAME StlMapType::referent_type EnumeratedType;
return enumStlAdapt( map, ComposeAdaptor<Adaptor,SecondEnumAdaptor>() );
}
template<typename StlIteratorType>
Enumerator<BOOST_DEDUCED_TYPENAME std::iterator_traits<StlIteratorType>::value_type>
enumStlMapValues( StlIteratorType first, StlIteratorType last )
{
typedef BOOST_DEDUCED_TYPENAME std::iterator_traits<StlIteratorType>::value_type EnumeratedType;
return enumStlAdapt( first, last,
SecondEnumAdaptor<EnumeratedType>() );
}
template<typename StlIteratorType
,typename Adaptor>
Enumerator<BOOST_DEDUCED_TYPENAME Adaptor::EnumeratedType>
enumStlMapValuesAdapt( StlIteratorType first, StlIteratorType last, Adaptor adaptor )
{
return enumStlAdapt( first, last,
ComposeAdaptor<Adaptor,SecondEnumAdaptor>() );
}
template<typename StlIteratorType
,typename EnumeratedType>
Enumerator<EnumeratedType>
enumStlMapValues( StlIteratorType first, StlIteratorType last, Type<EnumeratedType> )
{
return enumStlMapValuesAdapt( first, last, ConstructEnumAdaptor<EnumeratedType>() );
}
} // namespace Xtl
#endif // XTL_STLENUMERATOR_H_INCLUDED
--- NEW FILE: StlMapEnumerator.h ---
#ifndef XTL_STLMAPENUMERATOR_H_INCLUDED
#define XTL_STLMAPENUMERATOR_H_INCLUDED
#include <xtl/Enumerator.h>
#include <xtl/type.h>
namespace Xtl {
template<typename StlForwardIteratorType
,typename EnumeratedType>
class StlEnumeratorImpl : public EnumeratorImpl<EnumeratedType>
{
public:
typedef StlEnumeratorImpl<StlForwardIteratorType,EnumeratedType> ThisType;
StlEnumeratorImpl( StlForwardIteratorType first,
StlForwardIteratorType last )
: current_( first )
, last_( last )
{
}
public: // overridden from EnumeratorImpl
EnumeratedType getNext()
{
if ( current_ == last_ )
throw EnumeratorError();
return *current_++;
}
bool hasNext() const
{
return current_ != last_;
}
Ptr clone() const
{
return Ptr( new ThisType( current_, last_ ) );
}
private:
StlForwardIteratorType current_;
StlForwardIteratorType last_;
};
template<typename StlContainerType
,typename EnumeratedType>
Enumerator<EnumeratedType>
enumStl( const StlContainerType &sequence, Type<EnumeratedType> )
{
return Enumerator<EnumeratedType>(
new StlEnumeratorImpl<BOOST_DEDUCED_TYPENAME StlContainerType::const_iterator
,EnumeratedType>( sequence.begin(), sequence.end() ) );
}
template<typename StlContainerType>
Enumerator<BOOST_DEDUCED_TYPENAME StlContainerType::value_type>
enumStl( const StlContainerType &sequence )
{
return enumStl( sequence, Type<BOOST_DEDUCED_TYPENAME StlContainerType::value_type>() );
}
template<typename MapType
,typename EnumeratedType>
Enumerator<EnumeratedType>
enumMapKeys( const MapType &map, Type<EnumeratedType>() )
{
return Enumerator<EnumeratedType>( new StlMapEnumerator<EnumeratedType
,MapType::const_iterator
,MapEnumerateKeysPolicy>( map.begin(), map.end() ) );
}
} // namespace Xtl
#endif // XTL_STLMAPENUMERATOR_H_INCLUDED
--- NEW FILE: Type.h ---
#ifndef XTL_TYPE_H_INCLUDED
#define XTL_TYPE_H_INCLUDED
namespace Xtl {
/** A simple type wrapper.
*
* Common technic to pass a type as a parameter.
*/
template<typename WrappedType>
struct Type
{
typedef WrappedType OriginalType;
};
} // namespace Xtl
#endif // XTL_TYPE_H_INCLUDED
|
|
From: <bl...@us...> - 2003-04-27 13:02:01
|
Update of /cvsroot/cpptool/rfta/bin In directory sc8-pr-cvs1:/tmp/cvs-serv20474/bin Added Files: install-python-extension.bat Log Message: * added, copy pyrfta extension to python dir --- NEW FILE: install-python-extension.bat --- set PYTHON_DIR=C:\Python22 set INSTALL_DIR=%PYTHON_DIR%\DLLs xcopy /Y rfta_mdr.ext %INSTALL_DIR% xcopy /Y rftaparser_mdr.ext %INSTALL_DIR% xcopy /Y pyrfta.pyd %INSTALL_DIR% pause |
|
From: <bl...@us...> - 2003-04-27 13:00:58
|
Update of /cvsroot/cpptool/rfta/src/pyrfta
In directory sc8-pr-cvs1:/tmp/cvs-serv19937/src/pyrfta
Modified Files:
Forwards.h pyrfta.cpp pyrfta.dsp
Added Files:
ExposeCPPParser.cpp
Log Message:
* exposed to python: CPPParser, ASTNode, ASTNodeVisitor, ASTNodePropertyVisitor, ASTNodeProperty, ASTNodeType
--- NEW FILE: ExposeCPPParser.cpp ---
#include "Forwards.h"
#include <boost/python.hpp>
#include <rfta/parser/CPPParser.h>
#include <rfta/parser/ASTNodePropertyVisitor.h>
#include <rfta/parser/ASTNodeVisitor.h>
using namespace boost::python;
using namespace Refactoring;
class ASTNodeVisitorWrap : public ASTNodeVisitor
{
public:
PyObject *self;
ASTNodeVisitorWrap( PyObject *self_ )
: self(self_)
{
}
// overridden from ASTNodeVisitor
void visitNode( const ASTNodePtr &node )
{
call_method<void>( self, "visitNode", object(node) );
}
};
class ASTNodePropertyVisitorWrap : public ASTNodePropertyVisitor
{
public:
PyObject *self;
ASTNodePropertyVisitorWrap( PyObject *self_ )
: self(self_)
{
}
// overridden from ASTNodePropertyVisitor
void visitProperty( const ASTNodeProperty &property,
const ASTNodePtr &propertyNode )
{
call_method<void>( self, "visitProperty", property, object(propertyNode) );
}
};
void
exposeCPPParser()
{
class_<CPPParser>( "CPPParser", init<std::string>() )
.def( "parseAll", &CPPParser::parseAll )
.add_property( "sourceNode", &CPPParser::getSourceNode )
;
class_<ASTNode, ASTNodePtr, boost::noncopyable>( "ASTNode", no_init )
.add_property( "type",
make_function( &ASTNode::getType, return_value_policy<copy_const_reference>() ),
&ASTNode::mutateType )
// .def( "getType", &ASTNode::getType, return_value_policy<copy_const_reference>() )
.add_property( "length", &ASTNode::getLength, &ASTNode::setLength )
.add_property( "startIndex", &ASTNode::getStartIndex )
.add_property( "range", make_function( &ASTNode::getRange, return_value_policy<copy_const_reference>() ) )
// get parent node
.def( "addChild", &ASTNode::addChild )
.def( "getChildCount", &ASTNode::getChildCount )
.def( "getChildAt", make_function( &ASTNode::getChildAt, return_value_policy<copy_const_reference>() ) )
.def( "setPropertyNode", &ASTNode::setPropertyNode )
.def( "hasProperty", &ASTNode::hasProperty )
.def( "getProperty", &ASTNode::getProperty )
.def( "removeProperty", &ASTNode::removeProperty )
.def( "removeAllProperties", &ASTNode::removeAllProperties )
.def( "visitProperties", &ASTNode::visitProperties )
.def( "visitChildNodes", &ASTNode::visitChildNodes )
.add_property( "blankedText", &ASTNode::getBlankedText )
.add_property( "originalText", &ASTNode::getOriginalText )
;
class_<SourceASTNode, SourceASTNodePtr, bases<ASTNode>, boost::noncopyable>( "SourceASTNode", no_init )
;
class_<ASTNodeVisitor, ASTNodeVisitorWrap, boost::noncopyable>( "ASTNodeVisitor" )
;
class_<ASTNodePropertyVisitor, ASTNodePropertyVisitorWrap, boost::noncopyable>( "ASTNodePropertyVisitor" )
;
class_<ASTNodeType>( "ASTNodeType" )
.add_property( "name", make_function( &ASTNodeType::getName, return_value_policy<copy_const_reference>() ) )
.def( "isValid", &ASTNodeType::isValid )
;
class_<ASTNodeProperty>( "ASTNodeProperty" )
.add_property( "name", make_function( &ASTNodeProperty::getName, return_value_policy<copy_const_reference>() ) )
;
}
Index: Forwards.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/pyrfta/Forwards.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Forwards.h 6 Apr 2003 07:20:23 -0000 1.2
--- Forwards.h 27 Apr 2003 13:00:53 -0000 1.3
***************
*** 3,6 ****
--- 3,7 ----
+ void exposeCPPParser();
void exposeBase();
void exposeStatements();
Index: pyrfta.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/pyrfta/pyrfta.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** pyrfta.cpp 6 Apr 2003 07:20:23 -0000 1.5
--- pyrfta.cpp 27 Apr 2003 13:00:53 -0000 1.6
***************
*** 94,97 ****
--- 94,98 ----
BOOST_PYTHON_MODULE(pyrfta)
{
+ exposeCPPParser();
exposeBase();
exposeStatements();
Index: pyrfta.dsp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/pyrfta/pyrfta.dsp,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** pyrfta.dsp 6 Apr 2003 07:20:23 -0000 1.4
--- pyrfta.dsp 27 Apr 2003 13:00:53 -0000 1.5
***************
*** 112,115 ****
--- 112,119 ----
# Begin Source File
+ SOURCE=.\ExposeCPPParser.cpp
+ # End Source File
+ # Begin Source File
+
SOURCE=.\ExposeExpressions.cpp
# End Source File
|
|
From: <bl...@us...> - 2003-04-27 12:58:27
|
Update of /cvsroot/cpptool/rfta/include/rfta/parser
In directory sc8-pr-cvs1:/tmp/cvs-serv18411/include/rfta/parser
Modified Files:
CPPParser.h
Log Message:
* class is now exported
Index: CPPParser.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/include/rfta/parser/CPPParser.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** CPPParser.h 26 Apr 2003 21:13:34 -0000 1.1
--- CPPParser.h 27 Apr 2003 12:58:24 -0000 1.2
***************
*** 7,11 ****
! class CPPParser
{
public:
--- 7,11 ----
! class RFTAPARSER_API CPPParser
{
public:
|
|
From: <bl...@us...> - 2003-04-26 21:13:39
|
Update of /cvsroot/cpptool/rfta/include/rfta/parser
In directory sc8-pr-cvs1:/tmp/cvs-serv10364/include/rfta/parser
Added Files:
CPPParser.h
Log Message:
* added CPPParser, interface to the rftaparser library
--- NEW FILE: CPPParser.h ---
#ifndef RFTAPARSER_CPPPARSER_H_INCLUDED
#define RFTAPARSER_CPPPARSER_H_INCLUDED
#include <rfta/parser/SourceASTNode.h>
namespace Refactoring {
class CPPParser
{
public:
CPPParser( const std::string &source );
SourceASTNodePtr getSourceNode() const;
void parseForFunctionBodyAt( int position );
void parseForFunctionDeclarations();
void parseAll();
private:
SourceASTNodePtr sourceNode_;
};
} // namespace Refactoring
#endif // RFTAPARSER_CPPPARSER_H_INCLUDED
|
|
From: <bl...@us...> - 2003-04-26 21:13:39
|
Update of /cvsroot/cpptool/rfta/src/rftaparser
In directory sc8-pr-cvs1:/tmp/cvs-serv10364/src/rftaparser
Modified Files:
rftaparser.dsp
Added Files:
CPPParser.cpp
Log Message:
* added CPPParser, interface to the rftaparser library
--- NEW FILE: CPPParser.cpp ---
#include "stdafx.h"
#include <rfta/parser/CPPParser.h>
#include <rfta/parser/NonSemanticBlanker.h>
#include <rfta/parser/MaxLODMutator.h>
#include <rfta/parser/DeclarationListParser.h>
#include <rfta/parser/ParseContext.h>
#include <rfta/parser/ParserError.h>
namespace Refactoring {
CPPParser::CPPParser( const std::string &source )
{
NullPPDirectiveListener nullListener;
std::string blankedSource;
NonSemanticBlanker blanker( source, blankedSource, nullListener );
blanker.blank();
sourceNode_ = SourceASTNode::create( blankedSource, source );
}
SourceASTNodePtr
CPPParser::getSourceNode() const
{
return sourceNode_;
}
void
CPPParser::parseForFunctionBodyAt( int position )
{
}
void
CPPParser::parseForFunctionDeclarations()
{
}
void
CPPParser::parseAll()
{
ParseContext context( sourceNode_ );
DeclarationListParser parser( context,
sourceNode_->getBlankedSourceStart(),
sourceNode_->getBlankedSourceEnd() );
try
{
if ( !parser.tryParse() )
{
} // should report error in some way...
MaxLODMutator mutator;
mutator.mutate( sourceNode_, sourceNode_ );
}
catch ( ParserError & )
{
// should report error in some way...
}
}
} // namespace Refactoring
Index: rftaparser.dsp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftaparser/rftaparser.dsp,v
retrieving revision 1.39
retrieving revision 1.40
diff -C2 -d -r1.39 -r1.40
*** rftaparser.dsp 26 Apr 2003 13:13:37 -0000 1.39
--- rftaparser.dsp 26 Apr 2003 21:13:35 -0000 1.40
***************
*** 130,133 ****
--- 130,137 ----
# Begin Source File
+ SOURCE=..\..\include\xtl\Forwards.h
+ # End Source File
+ # Begin Source File
+
SOURCE=..\..\include\xtl\IntrusiveCount.h
# End Source File
***************
*** 1304,1307 ****
--- 1308,1323 ----
SOURCE=..\..\deplib\boostcvs\libs\filesystem\src\path_posix_windows.cpp
# SUBTRACT CPP /YX /Yc /Yu
+ # End Source File
+ # End Group
+ # Begin Group "Interface"
+
+ # PROP Default_Filter ""
+ # Begin Source File
+
+ SOURCE=.\CPPParser.cpp
+ # End Source File
+ # Begin Source File
+
+ SOURCE=..\..\include\rfta\parser\CPPParser.h
# End Source File
# End Group
|
|
From: <bl...@us...> - 2003-04-26 21:13:04
|
Update of /cvsroot/cpptool/rfta/include/xtl
In directory sc8-pr-cvs1:/tmp/cvs-serv10120/include/xtl
Added Files:
Forwards.h
Log Message:
* added forward declarations
--- NEW FILE: Forwards.h ---
#ifndef XTL_FORWARDS_H_INCLUDED
#define XTL_FORWARDS_H_INCLUDED
namespace Xtl {
class CStringView;
class CStringEnumerator;
class CStringBackEnumerator;
} // namespace Xtl
#endif // XTL_FORWARDS_H_INCLUDED
|
|
From: <bl...@us...> - 2003-04-26 21:12:38
|
Update of /cvsroot/cpptool/rfta/src/rftaparser
In directory sc8-pr-cvs1:/tmp/cvs-serv9956/src/rftaparser
Modified Files:
CaseStatementParser.cpp CaseStatementParser.h
Log Message:
* refactored to use CStringView
Index: CaseStatementParser.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftaparser/CaseStatementParser.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** CaseStatementParser.cpp 20 Dec 2002 08:30:50 -0000 1.3
--- CaseStatementParser.cpp 26 Apr 2003 21:12:36 -0000 1.4
***************
*** 9,12 ****
--- 9,14 ----
#include <rfta/parser/ASTNodes.h>
#include <rfta/parser/ParseContext.h>
+ #include <rfta/parser/ParserTools.h>
+ #include <xtl/CStringView.h>
***************
*** 33,84 ****
Tracker tracker( "CaseStatementParser::parse", *this );
! current_ = keywordEnd;
!
! skipSpaces();
!
! int constantStartIndex = getCurrentIndex();
! skipUntilColonBalancingBraces();
!
! const char *actualEnd = current_;
!
! --current_; // skip colon
! backtrackSkippingSpaces();
! int constantLength = getCurrentIndex() - constantStartIndex;
! if ( constantLength <= 0 )
! throwFailure( "expected constant not found!" );
! current_ = actualEnd;
! ASTNodePtr caseStatementNode =
! createASTNode( ASTNodeTypes::caseStatement,
! getParentNode(),
! getStartIndex(),
! getCurrentLength() );
! context_.addNode( caseStatementNode );
! ASTNodePtr constantNode =
! createASTNode( ASTNodeTypes::constantExpression,
! caseStatementNode,
! constantStartIndex,
! constantLength );
! caseStatementNode->setPropertyNode( ASTNodeProperties::constantValueProperty,
! constantNode );
! }
! void
! CaseStatementParser::skipUntilColonBalancingBraces()
! {
! while ( current_ != end_ )
{
! char c = *current_++;
! if ( c == '(' )
! findNextBalanced( '(', ')' );
! else if ( c == ':' )
! return;
}
-
- throwFailure( "failed to find expected ':' after constant expression." );
}
--- 35,73 ----
Tracker tracker( "CaseStatementParser::parse", *this );
! try
! {
! Xtl::CStringEnumerator current( Xtl::CStringView(keywordEnd, end_).enumerate() );
! ParserTools::skipSpaces( current );
! Xtl::CStringView constant( current );
! ParserTools::skipUntil( current, ':', ParserTools::SkipBalancingBracePolicy() );
! Xtl::CStringView caseStatement( start_, current.getCurrentPos() );
! Xtl::CStringBackEnumerator backTracker( --current );
! ParserTools::skipSpaces( backTracker );
! constant.setEnd( backTracker.getCurrentPos() );
! if ( constant.isEmpty() )
! throwFailure( "Missing case constant." );
! ASTNodePtr caseStatementNode =
! createASTNode( ASTNodeTypes::caseStatement,
! getParentNode(),
! caseStatement );
! context_.addNode( caseStatementNode );
+ ASTNodePtr constantNode =
+ createASTNode( ASTNodeTypes::constantExpression,
+ caseStatementNode,
+ constant );
+ caseStatementNode->setPropertyNode( ASTNodeProperties::constantValueProperty,
+ constantNode );
! current_ = caseStatement.getEnd();
! }
! catch ( ParserTools::ParseError &e )
{
! throwFailure( e );
}
}
Index: CaseStatementParser.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftaparser/CaseStatementParser.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** CaseStatementParser.h 24 Oct 2002 19:10:58 -0000 1.1
--- CaseStatementParser.h 26 Apr 2003 21:12:36 -0000 1.2
***************
*** 30,36 ****
private:
- void skipUntilColonBalancingBraces();
-
- private:
};
--- 30,33 ----
|
|
From: <bl...@us...> - 2003-04-26 21:11:34
|
Update of /cvsroot/cpptool/rfta/src/rftaparser
In directory sc8-pr-cvs1:/tmp/cvs-serv9532/src/rftaparser
Modified Files:
Parser.cpp
Log Message:
* added functionalities to use CStringView & CStringEnumerator
Index: Parser.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftaparser/Parser.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** Parser.cpp 26 Apr 2003 10:51:59 -0000 1.7
--- Parser.cpp 26 Apr 2003 21:11:30 -0000 1.8
***************
*** 9,12 ****
--- 9,14 ----
#include <rfta/parser/Parser.h>
#include <rfta/parser/ParserError.h>
+ #include <rfta/parser/ParserTools.h>
+ #include <xtl/CStringView.h>
***************
*** 78,81 ****
--- 80,96 ----
+ void
+ Parser::throwFailure( const ParserTools::ParseError &error )
+ {
+ std::string message = error.what();
+ message += "\n- Current position: ";
+ message += Xtl::CStringView( error.context_ ).getSubString(0, 60).str();
+ message += "\n- While analyzing:\n";
+ message += error.context_.getString().str();
+
+ throw ParserError( message, context_ );
+ }
+
+
const ASTNodeWeakPtr &
Parser::getParentNode() const
***************
*** 301,306 ****
int
! Parser::getIndexOf( const char *pos )
{
return pos - context_.getSourceNode()->getBlankedSourceStart();
--- 316,333 ----
+ ASTNodePtr
+ Parser::createASTNode( const ASTNodeType &type,
+ const ASTNodeWeakPtr &parentNode,
+ const Xtl::CStringView &string ) const
+ {
+ return createASTNode( type,
+ parentNode,
+ getIndexOf( string.getStart() ),
+ string.getLength() );
+ }
+
+
int
! Parser::getIndexOf( const char *pos ) const
{
return pos - context_.getSourceNode()->getBlankedSourceStart();
|
|
From: <bl...@us...> - 2003-04-26 21:11:33
|
Update of /cvsroot/cpptool/rfta/include/rfta/parser
In directory sc8-pr-cvs1:/tmp/cvs-serv9532/include/rfta/parser
Modified Files:
Parser.h ParserTools.h
Log Message:
* added functionalities to use CStringView & CStringEnumerator
Index: Parser.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/include/rfta/parser/Parser.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** Parser.h 26 Apr 2003 10:51:58 -0000 1.6
--- Parser.h 26 Apr 2003 21:11:29 -0000 1.7
***************
*** 8,11 ****
--- 8,12 ----
#include <rfta/parser/ASTNode.h>
+ #include <xtl/Forwards.h>
#include <boost/utility.hpp>
#include <boost/format.hpp>
***************
*** 13,17 ****
namespace Refactoring
{
!
class ParseContext;
--- 14,22 ----
namespace Refactoring
{
!
! namespace ParserTools {
! class ParseError;
! }
!
class ParseContext;
***************
*** 46,49 ****
--- 51,58 ----
const ASTNodeWeakPtr &parentNode,
const SourceRange &sourceRange ) const;
+
+ ASTNodePtr createASTNode( const ASTNodeType &type,
+ const ASTNodeWeakPtr &parentNode,
+ const Xtl::CStringView &string ) const;
protected:
***************
*** 103,107 ****
void throwFailure( const boost::format &format );
! int getIndexOf( const char *pos );
SourceRange getTrimedRange( const SourceRange &sourceRange );
--- 112,118 ----
void throwFailure( const boost::format &format );
! void throwFailure( const ParserTools::ParseError &error );
!
! int getIndexOf( const char *pos ) const;
SourceRange getTrimedRange( const SourceRange &sourceRange );
Index: ParserTools.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/include/rfta/parser/ParserTools.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** ParserTools.h 22 Dec 2002 16:03:50 -0000 1.3
--- ParserTools.h 26 Apr 2003 21:11:30 -0000 1.4
***************
*** 3,6 ****
--- 3,9 ----
#include <rfta/parser/Config.h>
+ #include <xtl/CStringView.h>
+ #include <stdexcept>
+ #include <string>
***************
*** 13,16 ****
--- 16,31 ----
{
+ class ParseError : public std::runtime_error
+ {
+ public:
+ ParseError( const std::string &message,
+ const Xtl::CStringEnumerator &context )
+ : std::runtime_error( message )
+ {
+ }
+
+ Xtl::CStringEnumerator context_;
+ };
+
inline bool
***************
*** 38,41 ****
--- 53,165 ----
const char *end,
int inIdentifierIndex );
+
+ // A Skip Policy must have a single method compatible with the following signature:
+ // Notes that type Enumerator may be either CStringEnumerator and CStringBackEnumerator.
+ // A templated member function is usually used to deal with both case.
+ // void handleSkip( Enumerator &enumerator );
+
+ struct SkipNonePolicy
+ {
+ static void handleSkip( Xtl::CStringEnumerator &enumerator )
+ {
+ }
+
+ static void handleSkip( Xtl::CStringBackEnumerator &enumerator )
+ {
+ }
+ };
+
+ template<typename Enumerator>
+ static void
+ skipSpaces( Enumerator &enumerator )
+ {
+ while ( enumerator.hasNext() && *enumerator == ' ' )
+ ++enumerator;
+ }
+
+
+ template<typename Enumerator
+ ,typename SkipPolicy>
+ static void
+ skipUntil( Enumerator &enumerator,
+ char charToFind,
+ const SkipPolicy &skipPolicy = SkipPolicy() )
+ {
+ while ( enumerator.hasNext() )
+ {
+ skipPolicy.handleSkip( enumerator );
+ if ( *enumerator++ == charToFind )
+ return;
+ }
+
+ throw ParseError( "missing character", enumerator );
+ }
+
+
+ template<typename Enumerator>
+ static void
+ skipUntil( Enumerator &enumerator,
+ char charToFind )
+ {
+ skipUntil( enumerator, charToFind, SkipNonePolicy() );
+ }
+
+
+ template<typename Enumerator
+ ,typename SkipPolicy>
+ static void
+ findNextBalanced( Enumerator &enumerator,
+ char opening,
+ char closing,
+ const SkipPolicy &skipPolicy = SkipPolicy() )
+ {
+ Enumerator start = enumerator;
+ int balance = 1;
+ while ( enumerator.hasNext() )
+ {
+ if ( *enumerator == opening )
+ ++balance;
+ else if ( *enumerator == closing )
+ {
+ --balance;
+ if ( balance == 0 )
+ return;
+ }
+ else
+ skipPolicy.handleSkip( enumerator );
+
+ ++enumerator;
+ }
+
+ throw ParseError( "unbalanced symbol", --start );
+ }
+
+
+ template<typename Enumerator>
+ static void
+ findNextBalanced( Enumerator &enumerator,
+ char opening,
+ char closing )
+ {
+ findNextBalanced( enumerator, opening, closing, SkipNonePolicy() );
+ }
+
+
+ struct SkipBalancingBracePolicy
+ {
+
+ static void handleSkip( Xtl::CStringEnumerator &enumerator )
+ {
+ if ( *enumerator == '(' )
+ findNextBalanced( ++enumerator, '(', ')' );
+ }
+
+ static void handleSkip( Xtl::CStringBackEnumerator &enumerator )
+ {
+ if ( *enumerator == ')' )
+ findNextBalanced( ++enumerator, ')', '(' );
+ }
+
+ };
|
|
From: <bl...@us...> - 2003-04-26 21:10:32
|
Update of /cvsroot/cpptool/rfta/include/xtl
In directory sc8-pr-cvs1:/tmp/cvs-serv9038/include/xtl
Modified Files:
CStringView.h
Log Message:
* changed the BackEnumerator to use the iterator_helper instead of the reverse iterator (incorrect type were returned by the implementation)
Index: CStringView.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/include/xtl/CStringView.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** CStringView.h 26 Apr 2003 13:13:36 -0000 1.2
--- CStringView.h 26 Apr 2003 21:10:27 -0000 1.3
***************
*** 18,21 ****
--- 18,25 ----
{
public:
+ enum {
+ unlimited = 0x7ffffff
+ };
+
CStringView()
: start_( 0 )
***************
*** 32,35 ****
--- 36,59 ----
}
+ CStringView( const CStringEnumerator &enumerator );
+
+ CStringView( const CStringBackEnumerator &enumerator );
+
+ void setStart( const char *start )
+ {
+ if ( start >= end_ )
+ start_ = start;
+ else
+ start_ = end_;
+ }
+
+ void setEnd( const char *end )
+ {
+ if ( end >= start_ )
+ end_ = end;
+ else
+ end_ = start_;
+ }
+
CStringView getSlice( int startIndex,
int endIndex = -1 ) const
***************
*** 48,51 ****
--- 72,90 ----
}
+ CStringView getSubString( int startIndex,
+ int length = unlimited )
+ {
+ if ( startIndex < 0 )
+ startIndex = 0;
+ else if ( startIndex > getLength() )
+ return CStringView();
+
+ if ( length == unlimited
+ || startIndex + length > getLength() )
+ length = getLength() - startIndex;
+
+ return CStringView( start_, start_ + length );
+ }
+
CStringEnumerator enumerate() const;
***************
*** 92,96 ****
bool operator ==( const std::string &other ) const
{
! return (start_ && other == std::string( start_, getLength() ) ) ||
other.empty();
}
--- 131,135 ----
bool operator ==( const std::string &other ) const
{
! return (start_ && other == str() ) ||
other.empty();
}
***************
*** 101,104 ****
--- 140,148 ----
}
+ const std::string str() const
+ {
+ return std::string( start_, getLength() );
+ }
+
private:
const char *start_;
***************
*** 107,114 ****
! class CStringEnumerator : public boost::random_access_iterator_helper<CStringEnumerator
, char
, std::ptrdiff_t
--- 151,213 ----
+ class CStringEnumeratorBase
+ {
+ public:
+ typedef char Reference;
+ typedef std::ptrdiff_t Distance;
+ CStringEnumeratorBase()
+ : current_( 0 )
+ {
+ }
+
+ CStringEnumeratorBase( const CStringView &string,
+ const char *current )
+ : string_( string )
+ , current_( current )
+ {
+ }
+ const char *getCurrentPos() const
+ {
+ return current_;
+ }
! int getCurrentIndex() const
! {
! return current_ - string_.getStart();
! }
!
! const CStringView &getString() const
! {
! return string_;
! }
!
! bool operator ==( const CStringEnumeratorBase &other ) const
! {
! return current_ == other.current_;
! }
!
! bool operator <( const CStringEnumeratorBase &other ) const
! {
! return current_ < other.current_;
! }
!
! bool withinString() const
! {
! return current_ >= string_.getStart() && current_ < string_.getEnd();
! }
!
! protected:
! CStringView string_;
! const char *current_;
! };
!
!
!
!
!
! class CStringEnumerator : public CStringEnumeratorBase
! , public boost::random_access_iterator_helper<CStringEnumerator
, char
, std::ptrdiff_t
***************
*** 118,127 ****
public:
typedef CStringEnumerator self;
- typedef char Reference;
- typedef std::ptrdiff_t Distance;
-
CStringEnumerator()
- : current_( 0 )
{
}
--- 217,222 ----
***************
*** 129,143 ****
CStringEnumerator( const char *current,
const char *end )
! : string_( current, end )
! , current_( string_.isEmpty() ? 0 : current )
{
}
CStringEnumerator( const CStringView &string )
! : string_( string )
! , current_( string_.getStart() )
{
}
char operator*() const
{
--- 224,239 ----
CStringEnumerator( const char *current,
const char *end )
! : CStringEnumeratorBase( CStringView( current, end ),
! string_.isEmpty() ? 0 : current )
{
}
CStringEnumerator( const CStringView &string )
! : CStringEnumeratorBase( string, string.getStart() )
{
}
+ CStringEnumerator( const CStringBackEnumerator &other );
+
char operator*() const
{
***************
*** 171,184 ****
}
- bool operator ==( const self &other ) const
- {
- return current_ == other.current_;
- }
-
- bool operator <( const self &other ) const
- {
- return current_ < other.current_;
- }
-
bool hasPrevious() const
{
--- 267,270 ----
***************
*** 190,212 ****
return current_ < string_.getEnd();
}
-
- const char *getCurrentPos() const
- {
- return current_;
- }
-
- const CStringView &getString() const
- {
- return string_;
- }
-
- private:
- CStringView string_;
- const char *current_;
};
! inline CStringEnumerator::Distance
! operator -( const CStringEnumerator &x, const CStringEnumerator &y )
{
return x.getCurrentPos() - y.getCurrentPos();
--- 276,284 ----
return current_ < string_.getEnd();
}
};
! inline CStringEnumeratorBase::Distance
! operator -( const CStringEnumeratorBase &x, const CStringEnumeratorBase &y )
{
return x.getCurrentPos() - y.getCurrentPos();
***************
*** 216,224 ****
! class CStringBackEnumerator : public std::reverse_iterator<CStringEnumerator, char, char>
{
- private:
- typedef std::reverse_iterator<CStringEnumerator, char, char> SuperClass;
public:
CStringBackEnumerator()
{
--- 288,301 ----
! class CStringBackEnumerator : public CStringEnumeratorBase
! , public boost::random_access_iterator_helper<CStringBackEnumerator
! , char
! , std::ptrdiff_t
! , const char *
! , char>
{
public:
+ typedef CStringBackEnumerator self;
+
CStringBackEnumerator()
{
***************
*** 226,256 ****
CStringBackEnumerator( const CStringEnumerator &other )
! : SuperClass( other )
{
}
! char getNext()
{
! return *(*this)++;
}
! bool hasPrevious() const
{
! return current.hasNext();
}
! bool hasNext() const
{
! return current.hasPrevious();
}
! const char *getCurrentPos() const
{
! return current.getCurrentPos();
}
! const CStringView &getString() const
{
! return current.getString();
}
};
--- 303,349 ----
CStringBackEnumerator( const CStringEnumerator &other )
! : CStringEnumeratorBase( other.getString(), other.getCurrentPos() )
{
}
! char operator*() const
{
! if ( current_ > string_.getStart() )
! return current_[-1];
! return 0;
}
! self &operator ++()
{
! --current_;
! return *this;
}
! self &operator --()
{
! ++current_;
! return *this;
}
! self &operator +=( Distance n )
{
! current_ -= n;
! return *this;
}
! self &operator -=( Distance n )
{
! current_ += n;
! return *this;
! }
!
! bool hasNext() const
! {
! return current_ > string_.getStart();
! }
!
! bool hasPrevious() const
! {
! return current_ < string_.getEnd();
}
};
***************
*** 272,275 ****
--- 365,383 ----
+ inline CStringView::CStringView( const CStringEnumerator &enumerator )
+ : start_( enumerator.getCurrentPos() )
+ , end_( enumerator.getString().end_ )
+ {
+
+ }
+
+
+ inline CStringView::CStringView( const CStringBackEnumerator &enumerator )
+ : start_( enumerator.getString().start_ )
+ , end_( enumerator.getCurrentPos() )
+ {
+ }
+
+
inline CStringEnumerator
CStringView::enumerate() const
***************
*** 302,305 ****
--- 410,419 ----
{
return CStringBackEnumerator( enumerate( startIndex, endIndex ) );
+ }
+
+
+ inline CStringEnumerator::CStringEnumerator( const CStringBackEnumerator &other )
+ : CStringEnumeratorBase( other.getString(), other.getCurrentPos() )
+ {
}
|
|
From: <bl...@us...> - 2003-04-26 13:13:40
|
Update of /cvsroot/cpptool/rfta/src/rftaparser
In directory sc8-pr-cvs1:/tmp/cvs-serv32663/src/rftaparser
Modified Files:
CStringEnumeratorTest.cpp CStringEnumeratorTest.h
rftaparser.dsp
Log Message:
* added reverse iterator for CStringEnumerator
* fixed release configuration
Index: CStringEnumeratorTest.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftaparser/CStringEnumeratorTest.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** CStringEnumeratorTest.cpp 26 Apr 2003 12:09:45 -0000 1.1
--- CStringEnumeratorTest.cpp 26 Apr 2003 13:13:37 -0000 1.2
***************
*** 29,32 ****
--- 29,33 ----
CStringEnumeratorTest::setUp()
{
+ RFTA_ASSERT_EQUAL( 5, text_.length() );
enumText_ = Xtl::CStringEnumerator( string_ );
}
***************
*** 44,47 ****
--- 45,49 ----
Xtl::CStringEnumerator enumEmpty;
CPPUNIT_ASSERT( !enumEmpty.hasNext() );
+ CPPUNIT_ASSERT( !enumEmpty.hasPrevious() );
CPPUNIT_ASSERT( enumEmpty.getCurrentPos() == 0 );
CPPUNIT_ASSERT( enumEmpty.getString().isEmpty() );
***************
*** 54,58 ****
CPPUNIT_ASSERT( enumText_.getString() == string_ );
CPPUNIT_ASSERT( enumText_.getCurrentPos() == string_.getStart() );
- RFTA_ASSERT_EQUAL( '1', enumText_.getCurrent() );
RFTA_ASSERT_EQUAL( '1', *enumText_ );
}
--- 56,59 ----
***************
*** 62,65 ****
--- 63,67 ----
CStringEnumeratorTest::testIncrement()
{
+ CPPUNIT_ASSERT( enumText_.hasNext() );
RFTA_ASSERT_EQUAL( '1', *enumText_++ );
RFTA_ASSERT_EQUAL( '2', *enumText_++ );
***************
*** 68,71 ****
--- 70,74 ----
RFTA_ASSERT_EQUAL( '5', *enumText_++ );
RFTA_ASSERT_EQUAL( 0, *enumText_ );
+ CPPUNIT_ASSERT( enumText_.hasPrevious() );
}
***************
*** 168,171 ****
--- 171,190 ----
CPPUNIT_ASSERT( enumEnd > enumText_);
CPPUNIT_ASSERT( enumEnd > enum2);
+ }
+
+
+ void
+ CStringEnumeratorTest::testBackEnumerator()
+ {
+ Xtl::CStringBackEnumerator backEnum( enumText_ + 5 );
+ CPPUNIT_ASSERT( backEnum.hasNext() );
+ CPPUNIT_ASSERT( !backEnum.hasPrevious() );
+ RFTA_ASSERT_EQUAL( '5', *backEnum++ );
+ RFTA_ASSERT_EQUAL( '4', *backEnum++ );
+ RFTA_ASSERT_EQUAL( '3', *backEnum++ );
+ RFTA_ASSERT_EQUAL( '2', *backEnum++ );
+ RFTA_ASSERT_EQUAL( '1', *backEnum++ );
+ CPPUNIT_ASSERT( !backEnum.hasNext() );
+ CPPUNIT_ASSERT( backEnum.hasPrevious() );
}
Index: CStringEnumeratorTest.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftaparser/CStringEnumeratorTest.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** CStringEnumeratorTest.h 26 Apr 2003 12:09:45 -0000 1.1
--- CStringEnumeratorTest.h 26 Apr 2003 13:13:37 -0000 1.2
***************
*** 28,31 ****
--- 28,32 ----
CPPUNIT_TEST( testEquality );
CPPUNIT_TEST( testComparable );
+ CPPUNIT_TEST( testBackEnumerator );
CPPUNIT_TEST_SUITE_END();
***************
*** 54,57 ****
--- 55,60 ----
void testEquality();
void testComparable();
+
+ void testBackEnumerator();
private:
Index: rftaparser.dsp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftaparser/rftaparser.dsp,v
retrieving revision 1.38
retrieving revision 1.39
diff -C2 -d -r1.38 -r1.39
*** rftaparser.dsp 26 Apr 2003 12:08:24 -0000 1.38
--- rftaparser.dsp 26 Apr 2003 13:13:37 -0000 1.39
***************
*** 538,553 ****
--- 538,589 ----
SOURCE=.\CStringEnumeratorTest.cpp
+
+ !IF "$(CFG)" == "rftaparser - Win32 Release"
+
+ # PROP Exclude_From_Build 1
+
+ !ELSEIF "$(CFG)" == "rftaparser - Win32 Debug"
+
+ !ENDIF
+
# End Source File
# Begin Source File
SOURCE=.\CStringEnumeratorTest.h
+
+ !IF "$(CFG)" == "rftaparser - Win32 Release"
+
+ # PROP Exclude_From_Build 1
+
+ !ELSEIF "$(CFG)" == "rftaparser - Win32 Debug"
+
+ !ENDIF
+
# End Source File
# Begin Source File
SOURCE=.\CStringViewTest.cpp
+
+ !IF "$(CFG)" == "rftaparser - Win32 Release"
+
+ # PROP Exclude_From_Build 1
+
+ !ELSEIF "$(CFG)" == "rftaparser - Win32 Debug"
+
+ !ENDIF
+
# End Source File
# Begin Source File
SOURCE=.\CStringViewTest.h
+
+ !IF "$(CFG)" == "rftaparser - Win32 Release"
+
+ # PROP Exclude_From_Build 1
+
+ !ELSEIF "$(CFG)" == "rftaparser - Win32 Debug"
+
+ !ENDIF
+
# End Source File
# End Group
***************
*** 1140,1147 ****
--- 1176,1201 ----
SOURCE=.\UnparsedDeclarationMutatorTest.cpp
+
+ !IF "$(CFG)" == "rftaparser - Win32 Release"
+
+ # PROP Exclude_From_Build 1
+
+ !ELSEIF "$(CFG)" == "rftaparser - Win32 Debug"
+
+ !ENDIF
+
# End Source File
# Begin Source File
SOURCE=.\UnparsedDeclarationMutatorTest.h
+
+ !IF "$(CFG)" == "rftaparser - Win32 Release"
+
+ # PROP Exclude_From_Build 1
+
+ !ELSEIF "$(CFG)" == "rftaparser - Win32 Debug"
+
+ !ENDIF
+
# End Source File
# Begin Source File
|
|
From: <bl...@us...> - 2003-04-26 13:13:39
|
Update of /cvsroot/cpptool/rfta/include/xtl
In directory sc8-pr-cvs1:/tmp/cvs-serv32663/include/xtl
Modified Files:
CStringView.h
Log Message:
* added reverse iterator for CStringEnumerator
* fixed release configuration
Index: CStringView.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/include/xtl/CStringView.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** CStringView.h 26 Apr 2003 12:09:45 -0000 1.1
--- CStringView.h 26 Apr 2003 13:13:36 -0000 1.2
***************
*** 12,15 ****
--- 12,16 ----
class CStringView;
class CStringEnumerator;
+ class CStringBackEnumerator;
***************
*** 51,54 ****
--- 52,60 ----
CStringEnumerator enumerate( int startIndex,
int endIndex ) const;
+
+ CStringBackEnumerator backEnumerate() const;
+
+ CStringBackEnumerator backEnumerate( int startIndex,
+ int endIndex ) const;
const char *getStart() const
***************
*** 134,145 ****
}
- int getRemainingLength() const
- {
- return string_.getEnd() - current_;
- }
-
char operator*() const
{
! return getCurrent();
}
--- 140,148 ----
}
char operator*() const
{
! if ( current_ < string_.getEnd() )
! return *current_;
! return 0;
}
***************
*** 178,193 ****
}
! char getNext()
! {
! if ( current_ < string_.getEnd() )
! return *current_++;
! return 0;
! }
!
! char getCurrent() const
{
! if ( current_ < string_.getEnd() )
! return *current_;
! return 0;
}
--- 181,187 ----
}
! bool hasPrevious() const
{
! return current_ > string_.getStart();
}
***************
*** 221,283 ****
! /*
! class CStringBackEnumerator
{
public:
CStringBackEnumerator()
- : current_( 0 )
- , end_( 0 )
{
}
! CStringBackEnumerator( const char *current,
! const char *start )
! : current_( start ? current : 0 )
! , start_( start ? start : current )
! {
! }
!
!
! CStringBackEnumerator( const CStringView &cstringView );
!
! int getRemainingLength() const
{
- return current_ - start_;
}
char getNext()
{
! if ( current_ >= start_ )
! return *current_--;
! return 0;
}
! char getCurrent() const
{
! if ( current_ >= start_ )
! return *current_;
! return 0;
}
bool hasNext() const
{
! return current_ >= start_;
}
const char *getCurrentPos() const
{
! return current_;
}
! const char *getStartPos() const
{
! return start_;
}
-
- private:
- const char *current_;
- const char *start_;
};
! */
--- 215,259 ----
!
! class CStringBackEnumerator : public std::reverse_iterator<CStringEnumerator, char, char>
{
+ private:
+ typedef std::reverse_iterator<CStringEnumerator, char, char> SuperClass;
public:
CStringBackEnumerator()
{
}
! CStringBackEnumerator( const CStringEnumerator &other )
! : SuperClass( other )
{
}
char getNext()
{
! return *(*this)++;
}
! bool hasPrevious() const
{
! return current.hasNext();
}
bool hasNext() const
{
! return current.hasPrevious();
}
const char *getCurrentPos() const
{
! return current.getCurrentPos();
}
! const CStringView &getString() const
{
! return current.getString();
}
};
!
***************
*** 295,298 ****
--- 271,275 ----
}
+
inline CStringEnumerator
CStringView::enumerate() const
***************
*** 301,304 ****
--- 278,282 ----
}
+
inline CStringEnumerator
CStringView::enumerate( int startIndex,
***************
*** 309,312 ****
--- 287,305 ----
start_ + endIndex );
return CStringEnumerator();
+ }
+
+
+ inline CStringBackEnumerator
+ CStringView::backEnumerate() const
+ {
+ return CStringBackEnumerator( enumerate() );
+ }
+
+
+ inline CStringBackEnumerator
+ CStringView::backEnumerate( int startIndex,
+ int endIndex ) const
+ {
+ return CStringBackEnumerator( enumerate( startIndex, endIndex ) );
}
|
|
From: <bl...@us...> - 2003-04-26 12:09:48
|
Update of /cvsroot/cpptool/rfta/src/rftaparser
In directory sc8-pr-cvs1:/tmp/cvs-serv12839/src/rftaparser
Added Files:
CStringEnumeratorTest.cpp CStringEnumeratorTest.h
CStringViewTest.cpp CStringViewTest.h
Log Message:
* added const char * string wrapper and iterator (still need adjustment).
--- NEW FILE: CStringEnumeratorTest.cpp ---
// //////////////////////////////////////////////////////////////////////////
// (c)Copyright 2002, Baptiste Lepilleur.
// Created: 2003/04/26
// //////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "CStringEnumeratorTest.h"
namespace Refactoring
{
RFTAPARSER_TEST_SUITE_REGISTRATION( CStringEnumeratorTest );
CStringEnumeratorTest::CStringEnumeratorTest()
: text_( "12345" )
, string_( text_.c_str(), text_.c_str() + text_.length() )
{
}
CStringEnumeratorTest::~CStringEnumeratorTest()
{
}
void
CStringEnumeratorTest::setUp()
{
enumText_ = Xtl::CStringEnumerator( string_ );
}
void
CStringEnumeratorTest::tearDown()
{
}
void
CStringEnumeratorTest::testDefaultConstructor()
{
Xtl::CStringEnumerator enumEmpty;
CPPUNIT_ASSERT( !enumEmpty.hasNext() );
CPPUNIT_ASSERT( enumEmpty.getCurrentPos() == 0 );
CPPUNIT_ASSERT( enumEmpty.getString().isEmpty() );
}
void
CStringEnumeratorTest::testStringConstructor()
{
CPPUNIT_ASSERT( enumText_.getString() == string_ );
CPPUNIT_ASSERT( enumText_.getCurrentPos() == string_.getStart() );
RFTA_ASSERT_EQUAL( '1', enumText_.getCurrent() );
RFTA_ASSERT_EQUAL( '1', *enumText_ );
}
void
CStringEnumeratorTest::testIncrement()
{
RFTA_ASSERT_EQUAL( '1', *enumText_++ );
RFTA_ASSERT_EQUAL( '2', *enumText_++ );
RFTA_ASSERT_EQUAL( '4', *++enumText_ );
enumText_++;
RFTA_ASSERT_EQUAL( '5', *enumText_++ );
RFTA_ASSERT_EQUAL( 0, *enumText_ );
}
void
CStringEnumeratorTest::testIndex()
{
RFTA_ASSERT_EQUAL( '1', enumText_[0] );
RFTA_ASSERT_EQUAL( '2', enumText_[1] );
RFTA_ASSERT_EQUAL( '3', enumText_[2] );
RFTA_ASSERT_EQUAL( '4', enumText_[3] );
RFTA_ASSERT_EQUAL( '5', enumText_[4] );
RFTA_ASSERT_EQUAL( 0, enumText_[5] );
++enumText_;
++enumText_;
RFTA_ASSERT_EQUAL( 0, enumText_[-3] );
RFTA_ASSERT_EQUAL( '1', enumText_[-2] );
RFTA_ASSERT_EQUAL( '2', enumText_[-1] );
}
void
CStringEnumeratorTest::testDecrement()
{
enumText_++;
enumText_++;
RFTA_ASSERT_EQUAL( '3', *enumText_-- );
RFTA_ASSERT_EQUAL( '1', *--enumText_ );
RFTA_ASSERT_EQUAL( '1', *enumText_-- );
RFTA_ASSERT_EQUAL( 0, *enumText_ );
}
void
CStringEnumeratorTest::testAddable()
{
Xtl::CStringEnumerator enum2 = enumText_ + 2;
RFTA_ASSERT_EQUAL( '3', *enum2 );
enumText_ += 3;
RFTA_ASSERT_EQUAL( '4', *enumText_ );
}
void
CStringEnumeratorTest::testSubstractable()
{
Xtl::CStringEnumerator enumEnd = enumText_ + 5;
Xtl::CStringEnumerator enum2 = enumEnd - 2;
RFTA_ASSERT_EQUAL( '4', *enum2 );
enumEnd -= 4;
RFTA_ASSERT_EQUAL( '2', *enumEnd );
}
void
CStringEnumeratorTest::testDistance()
{
Xtl::CStringEnumerator enumEnd = enumText_ + 5;
Xtl::CStringEnumerator enum3 = enumEnd - 2;
RFTA_ASSERT_EQUAL( 3, enum3 - enumText_ );
RFTA_ASSERT_EQUAL( 2, enumEnd - enum3 );
RFTA_ASSERT_EQUAL( -2, enum3 - enumEnd );
RFTA_ASSERT_EQUAL( -3, enumText_ - enum3 );
}
void
CStringEnumeratorTest::testEquality()
{
Xtl::CStringEnumerator enumEnd = enumText_ + 5;
Xtl::CStringEnumerator enum2 = enumText_ + 2;
CPPUNIT_ASSERT( enumText_ == enumText_ );
CPPUNIT_ASSERT( enum2 == enum2 );
CPPUNIT_ASSERT( enumEnd == enumEnd );
CPPUNIT_ASSERT( enumText_ +5 == enumEnd );
CPPUNIT_ASSERT( enumText_ != enumEnd );
CPPUNIT_ASSERT( enumText_ != enum2 );
}
void
CStringEnumeratorTest::testComparable()
{
Xtl::CStringEnumerator enumEnd = enumText_ + 5;
Xtl::CStringEnumerator enum2 = enumText_ + 2;
CPPUNIT_ASSERT( enumText_ < enumEnd );
CPPUNIT_ASSERT( enumText_ < enum2 );
CPPUNIT_ASSERT( !(enumText_ < enumText_ ) );
CPPUNIT_ASSERT( enumText_ <= enumEnd );
CPPUNIT_ASSERT( enumText_ <= enumText_ );
CPPUNIT_ASSERT( !(enumText_ >= enumEnd) );
CPPUNIT_ASSERT( enumEnd >= enumText_);
CPPUNIT_ASSERT( enumEnd >= enum2);
CPPUNIT_ASSERT( !(enumText_ > enumEnd) );
CPPUNIT_ASSERT( enumEnd > enumText_);
CPPUNIT_ASSERT( enumEnd > enum2);
}
} // namespace Refactoring
--- NEW FILE: CStringEnumeratorTest.h ---
// //////////////////////////////////////////////////////////////////////////
// (c)Copyright 2002, Baptiste Lepilleur.
// Created: 2003/04/26
// //////////////////////////////////////////////////////////////////////////
#ifndef RFTA_CSTRINGENUMERATORTEST_H
#define RFTA_CSTRINGENUMERATORTEST_H
#include "UnitTesting.h"
#include <xtl/CStringView.h>
namespace Refactoring
{
/// Unit tests for CStringEnumeratorTest
class CStringEnumeratorTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( CStringEnumeratorTest );
CPPUNIT_TEST( testDefaultConstructor );
CPPUNIT_TEST( testStringConstructor );
CPPUNIT_TEST( testIncrement );
CPPUNIT_TEST( testIndex );
CPPUNIT_TEST( testDecrement );
CPPUNIT_TEST( testAddable );
CPPUNIT_TEST( testSubstractable );
CPPUNIT_TEST( testDistance );
CPPUNIT_TEST( testEquality );
CPPUNIT_TEST( testComparable );
CPPUNIT_TEST_SUITE_END();
public:
/*! Constructs a CStringEnumeratorTest object.
*/
CStringEnumeratorTest();
/// Destructor.
virtual ~CStringEnumeratorTest();
void setUp();
void tearDown();
void testDefaultConstructor();
void testStringConstructor();
void testIncrement();
void testIndex();
void testDecrement();
void testAddable();
void testSubstractable();
void testDistance();
void testEquality();
void testComparable();
private:
const std::string text_;
Xtl::CStringEnumerator enumText_;
Xtl::CStringView string_;
};
// Inlines methods for CStringEnumeratorTest:
// ------------------------------------------
} // namespace Refactoring
#endif // RFTA_CSTRINGENUMERATORTEST_H
--- NEW FILE: CStringViewTest.cpp ---
// //////////////////////////////////////////////////////////////////////////
// (c)Copyright 2002, Baptiste Lepilleur.
// Created: 2003/04/26
// //////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "CStringViewTest.h"
namespace Refactoring
{
RFTAPARSER_TEST_SUITE_REGISTRATION( CStringViewTest );
CStringViewTest::CStringViewTest()
: text_( "123456789" )
, start_( text_.c_str() )
, end_( start_ + text_.length() )
{
}
CStringViewTest::~CStringViewTest()
{
}
void
CStringViewTest::setUp()
{
RFTA_ASSERT_EQUAL( 9, text_.length() );
}
void
CStringViewTest::tearDown()
{
}
void
CStringViewTest::testDefaultConstructor()
{
Xtl::CStringView empty;
RFTA_ASSERT_EQUAL( 0, empty.getLength() );
CPPUNIT_ASSERT( empty.getStart() == 0 );
CPPUNIT_ASSERT( empty.getEnd() == 0 );
CPPUNIT_ASSERT( empty.isEmpty() );
Xtl::CStringView emptySlice( empty.getSlice(0,0) );
CPPUNIT_ASSERT( emptySlice.isEmpty() );
RFTA_ASSERT_EQUAL( 0, emptySlice.getLength() );
}
void
CStringViewTest::testRangeConstructor()
{
Xtl::CStringView s1( start_, end_ );
RFTA_ASSERT_EQUAL( start_, s1.getStart() );
RFTA_ASSERT_EQUAL( end_, s1.getEnd() );
RFTA_ASSERT_EQUAL( text_.length(), s1.getLength() );
CPPUNIT_ASSERT( !s1.isEmpty() );
Xtl::CStringView s2( start_, 0 );
CPPUNIT_ASSERT( s2.isEmpty() );
CPPUNIT_ASSERT( s2.getStart() == 0 );
CPPUNIT_ASSERT( s2.getEnd() == 0 );
Xtl::CStringView s3( 0, end_ );
CPPUNIT_ASSERT( s3.isEmpty() );
CPPUNIT_ASSERT( s3.getStart() == 0 );
CPPUNIT_ASSERT( s3.getEnd() == 0 );
}
void
CStringViewTest::testGetSlice()
{
Xtl::CStringView s1( start_, end_ );
Xtl::CStringView s2( s1.getSlice( 0, s1.getLength() ) );
RFTA_ASSERT_EQUAL( s1.getStart(), s2.getStart() );
RFTA_ASSERT_EQUAL( s1.getEnd(), s2.getEnd() );
RFTA_ASSERT_EQUAL( s1.getLength(), s2.getLength() );
Xtl::CStringView s3( s1.getSlice( 0, 3 ) );
RFTA_ASSERT_EQUAL( s1.getStart(), s3.getStart() );
RFTA_ASSERT_EQUAL( s1.getStart() + 3, s3.getEnd() );
RFTA_ASSERT_EQUAL( 3, s3.getLength() );
Xtl::CStringView s4( s1.getSlice( 5, s1.getLength() ) );
RFTA_ASSERT_EQUAL( s1.getStart()+5, s4.getStart() );
RFTA_ASSERT_EQUAL( s1.getEnd(), s4.getEnd() );
RFTA_ASSERT_EQUAL( s1.getLength()-5, s4.getLength() );
Xtl::CStringView s5( s1.getSlice( 4, 7 ) );
RFTA_ASSERT_EQUAL( s1.getStart()+4, s5.getStart() );
RFTA_ASSERT_EQUAL( s1.getStart()+7, s5.getEnd() );
RFTA_ASSERT_EQUAL( 7-4, s5.getLength() );
Xtl::CStringView s6( s1.getSlice( 5 ) );
RFTA_ASSERT_EQUAL( s1.getStart()+5, s6.getStart() );
RFTA_ASSERT_EQUAL( s1.getEnd(), s6.getEnd() );
RFTA_ASSERT_EQUAL( s1.getLength()-5, s6.getLength() );
RFTA_ASSERT_THROW( s1.getSlice( -1 ), std::out_of_range );
RFTA_ASSERT_THROW( s1.getSlice( 13 ), std::out_of_range );
RFTA_ASSERT_THROW( s1.getSlice( 10 ), std::out_of_range );
RFTA_ASSERT_THROW( s1.getSlice( 1, 13 ), std::out_of_range );
RFTA_ASSERT_THROW( s1.getSlice( 1, 10 ), std::out_of_range );
}
void
CStringViewTest::testEnumerate()
{
Xtl::CStringView empty;
Xtl::CStringEnumerator enumEmpty( empty.enumerate() );
CPPUNIT_ASSERT( enumEmpty.getCurrentPos() == 0 );
CPPUNIT_ASSERT( enumEmpty.getString().getStart() == 0 );
CPPUNIT_ASSERT( enumEmpty.getString().getEnd() == 0 );
Xtl::CStringView s1( start_, end_ );
Xtl::CStringEnumerator enumS1( s1.enumerate() );
CPPUNIT_ASSERT( enumS1.getCurrentPos() == start_ );
CPPUNIT_ASSERT( enumS1.getString().getStart() == start_ );
CPPUNIT_ASSERT( enumS1.getString().getEnd() == end_ );
}
void
CStringViewTest::testEqual()
{
Xtl::CStringView s1( start_, end_ );
Xtl::CStringView s2( start_, end_ );
CPPUNIT_ASSERT( s1 == s2 );
const std::string text2( "123456789abcdef" );
Xtl::CStringView s3( text2.c_str(), text2.c_str() + text2.length() );
CPPUNIT_ASSERT( s1 != s3 );
Xtl::CStringView s4( s3.getSlice(0, 9) );
CPPUNIT_ASSERT( s1 == s4 );
Xtl::CStringView s5( s3.getSlice(2, 11) );
CPPUNIT_ASSERT( s1 != s5 );
}
void
CStringViewTest::testEqualToString()
{
Xtl::CStringView s1( start_, end_ );
CPPUNIT_ASSERT( s1 == text_ );
CPPUNIT_ASSERT( text_ == s1 );
}
} // namespace Refactoring
--- NEW FILE: CStringViewTest.h ---
// //////////////////////////////////////////////////////////////////////////
// (c)Copyright 2002, Baptiste Lepilleur.
// Created: 2003/04/26
// //////////////////////////////////////////////////////////////////////////
#ifndef RFTA_CSTRINGVIEWTEST_H
#define RFTA_CSTRINGVIEWTEST_H
#include "UnitTesting.h"
#include <xtl/CStringView.h>
namespace Refactoring
{
/// Unit tests for CStringViewTest
class CStringViewTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( CStringViewTest );
CPPUNIT_TEST( testDefaultConstructor );
CPPUNIT_TEST( testRangeConstructor );
CPPUNIT_TEST( testGetSlice );
CPPUNIT_TEST( testEnumerate );
CPPUNIT_TEST( testEqual );
CPPUNIT_TEST( testEqualToString );
CPPUNIT_TEST_SUITE_END();
public:
/*! Constructs a CStringViewTest object.
*/
CStringViewTest();
/// Destructor.
virtual ~CStringViewTest();
void setUp();
void tearDown();
void testDefaultConstructor();
void testRangeConstructor();
void testGetSlice();
void testEnumerate();
void testEqual();
void testEqualToString();
private:
const std::string text_;
const char *const start_;
const char *const end_;
};
// Inlines methods for CStringViewTest:
// ------------------------------------
} // namespace Refactoring
#endif // RFTA_CSTRINGVIEWTEST_H
|
|
From: <bl...@us...> - 2003-04-26 12:09:47
|
Update of /cvsroot/cpptool/rfta/include/xtl
In directory sc8-pr-cvs1:/tmp/cvs-serv12839/include/xtl
Added Files:
CStringView.h
Log Message:
* added const char * string wrapper and iterator (still need adjustment).
--- NEW FILE: CStringView.h ---
#ifndef XTL_CSTRINGVIEW_H_INCLUDED
#define XTL_CSTRINGVIEW_H_INCLUDED
#include <stdexcept>
#include <string>
#include <cstring>
#include <boost/operators.hpp>
namespace Xtl {
class CStringView;
class CStringEnumerator;
class CStringView
{
public:
CStringView()
: start_( 0 )
, end_( 0 )
{
}
CStringView( const char *start,
const char *end )
: start_( end ? start : 0 )
, end_( start ? end : 0 )
{
}
CStringView getSlice( int startIndex,
int endIndex = -1 ) const
{
if ( startIndex > end_ - start_ || startIndex < 0 )
throw std::out_of_range( "CStringView::getSlice(), startIndex" );
if ( endIndex == -1 )
endIndex = getLength();
if ( endIndex > end_ - start_ )
throw std::out_of_range( "CStringView::getSlice(), endIndex" );
return CStringView( start_ + startIndex,
start_ + endIndex );
}
CStringEnumerator enumerate() const;
CStringEnumerator enumerate( int startIndex,
int endIndex ) const;
const char *getStart() const
{
return start_;
}
const char *getEnd() const
{
return end_;
}
int getLength() const
{
return end_ - start_;
}
bool isEmpty() const
{
return getLength() == 0;
}
bool operator ==( const CStringView &other ) const
{
return getLength() == other.getLength()
&& ( ( start_ == other.start_ && end_ == other.end_ )
|| std::memcmp( start_, other.start_, getLength() ) == 0 );
}
bool operator !=( const CStringView &other ) const
{
return !( *this == other );
}
bool operator ==( const std::string &other ) const
{
return (start_ && other == std::string( start_, getLength() ) ) ||
other.empty();
}
bool operator !=( const std::string &other ) const
{
return !( *this == other );
}
private:
const char *start_;
const char *end_;
};
class CStringEnumerator : public boost::random_access_iterator_helper<CStringEnumerator
, char
, std::ptrdiff_t
, const char *
, char>
{
public:
typedef CStringEnumerator self;
typedef char Reference;
typedef std::ptrdiff_t Distance;
CStringEnumerator()
: current_( 0 )
{
}
CStringEnumerator( const char *current,
const char *end )
: string_( current, end )
, current_( string_.isEmpty() ? 0 : current )
{
}
CStringEnumerator( const CStringView &string )
: string_( string )
, current_( string_.getStart() )
{
}
int getRemainingLength() const
{
return string_.getEnd() - current_;
}
char operator*() const
{
return getCurrent();
}
self &operator ++()
{
++current_;
return *this;
}
self &operator --()
{
--current_;
return *this;
}
self &operator +=( Distance n )
{
current_ += n;
return *this;
}
self &operator -=( Distance n )
{
current_ -= n;
return *this;
}
bool operator ==( const self &other ) const
{
return current_ == other.current_;
}
bool operator <( const self &other ) const
{
return current_ < other.current_;
}
char getNext()
{
if ( current_ < string_.getEnd() )
return *current_++;
return 0;
}
char getCurrent() const
{
if ( current_ < string_.getEnd() )
return *current_;
return 0;
}
bool hasNext() const
{
return current_ < string_.getEnd();
}
const char *getCurrentPos() const
{
return current_;
}
const CStringView &getString() const
{
return string_;
}
private:
CStringView string_;
const char *current_;
};
inline CStringEnumerator::Distance
operator -( const CStringEnumerator &x, const CStringEnumerator &y )
{
return x.getCurrentPos() - y.getCurrentPos();
}
/*
class CStringBackEnumerator
{
public:
CStringBackEnumerator()
: current_( 0 )
, end_( 0 )
{
}
CStringBackEnumerator( const char *current,
const char *start )
: current_( start ? current : 0 )
, start_( start ? start : current )
{
}
CStringBackEnumerator( const CStringView &cstringView );
int getRemainingLength() const
{
return current_ - start_;
}
char getNext()
{
if ( current_ >= start_ )
return *current_--;
return 0;
}
char getCurrent() const
{
if ( current_ >= start_ )
return *current_;
return 0;
}
bool hasNext() const
{
return current_ >= start_;
}
const char *getCurrentPos() const
{
return current_;
}
const char *getStartPos() const
{
return start_;
}
private:
const char *current_;
const char *start_;
};
*/
inline bool
operator ==( const std::string &s1, const CStringView &s2 )
{
return s2 == s1;
}
inline bool
operator !=( const std::string &s1, const CStringView &s2 )
{
return s2 != s1;
}
inline CStringEnumerator
CStringView::enumerate() const
{
return CStringEnumerator( *this );
}
inline CStringEnumerator
CStringView::enumerate( int startIndex,
int endIndex ) const
{
if ( start_ )
return CStringEnumerator( start_ + startIndex,
start_ + endIndex );
return CStringEnumerator();
}
} // namespace Xtl
#endif // XTL_CSTRINGVIEW_H_INCLUDED
|
|
From: <bl...@us...> - 2003-04-26 12:08:27
|
Update of /cvsroot/cpptool/rfta/src/rftavc6addin In directory sc8-pr-cvs1:/tmp/cvs-serv12367/src/rftavc6addin Modified Files: rftavc6addin.dsp Log Message: * added boost compatibility headers for c-style headers (cstring, cstdio...) Index: rftavc6addin.dsp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftavc6addin/rftavc6addin.dsp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** rftavc6addin.dsp 1 Apr 2003 18:22:57 -0000 1.4 --- rftavc6addin.dsp 26 Apr 2003 12:08:24 -0000 1.5 *************** *** 44,48 **** # PROP Target_Dir "" # ADD BASE CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_WINDLL" /D "_AFXDLL" /Yu"stdafx.h" /FD /c ! # ADD CPP /nologo /MD /W3 /GR /GX /O2 /I "../../include" /I "../../deplib/cppunit/include" /I "../../deplib/boostcvs" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_WINDLL" /D "_AFXDLL" /D "_MBCS" /D "_USRDLL" /Yu"stdafx.h" /FD /c # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 --- 44,48 ---- # PROP Target_Dir "" # ADD BASE CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_WINDLL" /D "_AFXDLL" /Yu"stdafx.h" /FD /c ! # ADD CPP /nologo /MD /W3 /GR /GX /O2 /I "../../deplib/boost-compatibility" /I "../../include" /I "../../deplib/cppunit/include" /I "../../deplib/boostcvs" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_WINDLL" /D "_AFXDLL" /D "_MBCS" /D "_USRDLL" /Yu"stdafx.h" /FD /c # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 *************** *** 76,80 **** # PROP Target_Dir "" # ADD BASE CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_WINDLL" /D "_AFXDLL" /Yu"stdafx.h" /FD /GZ /c ! # ADD CPP /nologo /MDd /W3 /Gm /GR /GX /ZI /Od /I "../../include" /I "../../deplib/cppunit/include" /I "../../deplib/boostcvs" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_WINDLL" /D "_AFXDLL" /D "_MBCS" /D "_USRDLL" /Yu"stdafx.h" /FD /GZ /c # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 --- 76,80 ---- # PROP Target_Dir "" # ADD BASE CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_WINDLL" /D "_AFXDLL" /Yu"stdafx.h" /FD /GZ /c ! # ADD CPP /nologo /MDd /W3 /Gm /GR /GX /ZI /Od /I "../../deplib/boost-compatibility" /I "../../include" /I "../../deplib/cppunit/include" /I "../../deplib/boostcvs" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_WINDLL" /D "_AFXDLL" /D "_MBCS" /D "_USRDLL" /Yu"stdafx.h" /FD /GZ /c # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 |
|
From: <bl...@us...> - 2003-04-26 12:08:27
|
Update of /cvsroot/cpptool/rfta/src/rftaparser In directory sc8-pr-cvs1:/tmp/cvs-serv12367/src/rftaparser Modified Files: rftaparser.dsp Log Message: * added boost compatibility headers for c-style headers (cstring, cstdio...) Index: rftaparser.dsp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/rftaparser.dsp,v retrieving revision 1.37 retrieving revision 1.38 diff -C2 -d -r1.37 -r1.38 *** rftaparser.dsp 26 Apr 2003 11:09:27 -0000 1.37 --- rftaparser.dsp 26 Apr 2003 12:08:24 -0000 1.38 *************** *** 44,48 **** # PROP Target_Dir "" # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "RFTA_EXPORTS" /Yu"stdafx.h" /FD /c ! # ADD CPP /nologo /MD /W3 /GR /GX /O2 /I "../../include" /I "../../deplib/cppunit/include" /I "../../deplib/boostcvs" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "RFTAPARSER_DLL_BUILD" /D "RFTAPARSER_NO_UT" /Yu"stdafx.h" /FD /c # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 --- 44,48 ---- # PROP Target_Dir "" # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "RFTA_EXPORTS" /Yu"stdafx.h" /FD /c ! # ADD CPP /nologo /MD /W3 /GR /GX /O2 /I "../../deplib/boost-compatibility" /I "../../include" /I "../../deplib/cppunit/include" /I "../../deplib/boostcvs" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "RFTAPARSER_DLL_BUILD" /D "RFTAPARSER_NO_UT" /Yu"stdafx.h" /FD /c # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 *************** *** 78,82 **** # PROP Target_Dir "" # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "RFTA_EXPORTS" /Yu"stdafx.h" /FD /GZ /c ! # ADD CPP /nologo /MDd /W3 /Gm /GR /GX /ZI /Od /I "../../include" /I "../../deplib/cppunit/include" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "RFTAPARSER_DLL_BUILD" /D CPPUNIT_WRAP_COLUMN=120 /Yu"stdafx.h" /FD /GZ /c # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 --- 78,82 ---- # PROP Target_Dir "" # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "RFTA_EXPORTS" /Yu"stdafx.h" /FD /GZ /c ! # ADD CPP /nologo /MDd /W3 /Gm /GR /GX /ZI /Od /I "../../deplib/boost-compatibility" /I "../../include" /I "../../deplib/cppunit/include" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "RFTAPARSER_DLL_BUILD" /D CPPUNIT_WRAP_COLUMN=120 /Yu"stdafx.h" /FD /GZ /c # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 *************** *** 126,129 **** --- 126,133 ---- # Begin Source File + SOURCE=..\..\include\xtl\CStringView.h + # End Source File + # Begin Source File + SOURCE=..\..\include\xtl\IntrusiveCount.h # End Source File *************** *** 528,531 **** --- 532,555 ---- # PROP Default_Filter "" + # Begin Group "XtlTest" + + # PROP Default_Filter "" + # Begin Source File + + SOURCE=.\CStringEnumeratorTest.cpp + # End Source File + # Begin Source File + + SOURCE=.\CStringEnumeratorTest.h + # End Source File + # Begin Source File + + SOURCE=.\CStringViewTest.cpp + # End Source File + # Begin Source File + + SOURCE=.\CStringViewTest.h + # End Source File + # End Group # Begin Source File |
|
From: <bl...@us...> - 2003-04-26 12:08:26
|
Update of /cvsroot/cpptool/rfta/src/rfta In directory sc8-pr-cvs1:/tmp/cvs-serv12367/src/rfta Modified Files: rfta.dsp Log Message: * added boost compatibility headers for c-style headers (cstring, cstdio...) Index: rfta.dsp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/rfta.dsp,v retrieving revision 1.44 retrieving revision 1.45 diff -C2 -d -r1.44 -r1.45 *** rfta.dsp 22 Apr 2003 19:25:35 -0000 1.44 --- rfta.dsp 26 Apr 2003 12:08:24 -0000 1.45 *************** *** 44,48 **** # PROP Target_Dir "" # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "RFTA_EXPORTS" /Yu"stdafx.h" /FD /c ! # ADD CPP /nologo /MD /W3 /GR /GX /O2 /I "../../include" /I "../../deplib/cppunit/include" /I "../../deplib/boostcvs" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "RFTA_DLL_BUILD" /D "RFTA_NO_UT" /Yu"stdafx.h" /FD /c # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 --- 44,48 ---- # PROP Target_Dir "" # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "RFTA_EXPORTS" /Yu"stdafx.h" /FD /c ! # ADD CPP /nologo /MD /W3 /GR /GX /O2 /I "../../deplib/boost-compatibility" /I "../../include" /I "../../deplib/cppunit/include" /I "../../deplib/boostcvs" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "RFTA_DLL_BUILD" /D "RFTA_NO_UT" /Yu"stdafx.h" /FD /c # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 *************** *** 78,82 **** # PROP Target_Dir "" # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "RFTA_EXPORTS" /Yu"stdafx.h" /FD /GZ /c ! # ADD CPP /nologo /MDd /W3 /Gm /GR /GX /ZI /Od /I "../../include" /I "../../deplib/cppunit/include" /I "../../deplib/boostcvs" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "RFTA_DLL_BUILD" /D CPPUNIT_WRAP_COLUMN=120 /Yu"stdafx.h" /FD /GZ /c # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 --- 78,82 ---- # PROP Target_Dir "" # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "RFTA_EXPORTS" /Yu"stdafx.h" /FD /GZ /c ! # ADD CPP /nologo /MDd /W3 /Gm /GR /GX /ZI /Od /I "../../deplib/boost-compatibility" /I "../../include" /I "../../deplib/cppunit/include" /I "../../deplib/boostcvs" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "RFTA_DLL_BUILD" /D CPPUNIT_WRAP_COLUMN=120 /Yu"stdafx.h" /FD /GZ /c # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 |
|
From: <bl...@us...> - 2003-04-26 12:08:26
|
Update of /cvsroot/cpptool/rfta/deplib/boost-compatibility
In directory sc8-pr-cvs1:/tmp/cvs-serv12367/deplib/boost-compatibility
Added Files:
cassert cctype cerrno cfloat climits clocale cmath csetjmp
csignal cstdarg cstddef cstdio cstdlib cstring ctime cwchar
cwctype
Log Message:
* added boost compatibility headers for c-style headers (cstring, cstdio...)
--- NEW FILE: cassert ---
// This file is automatically generated. Do not edit.
// ['../../../libs/compatibility/generate_cpp_c_headers.py']
// Mon Apr 16 15:16:00 2001 ('PST', 'PDT')
#ifndef __CASSERT_HEADER
#define __CASSERT_HEADER
#include <assert.h>
#endif // CASSERT_HEADER
--- NEW FILE: cctype ---
// This file is automatically generated. Do not edit.
// ['../../../libs/compatibility/generate_cpp_c_headers.py']
// Mon Apr 16 15:16:00 2001 ('PST', 'PDT')
#ifndef __CCTYPE_HEADER
#define __CCTYPE_HEADER
#include <ctype.h>
namespace std {
using ::isalnum;
using ::isdigit;
using ::isprint;
using ::isupper;
using ::tolower;
using ::isalpha;
using ::isgraph;
using ::ispunct;
using ::isxdigit;
using ::toupper;
using ::iscntrl;
using ::islower;
using ::isspace;
}
#endif // CCTYPE_HEADER
--- NEW FILE: cerrno ---
// This file is automatically generated. Do not edit.
// ['../../../libs/compatibility/generate_cpp_c_headers.py']
// Mon Apr 16 15:16:00 2001 ('PST', 'PDT')
#ifndef __CERRNO_HEADER
#define __CERRNO_HEADER
#include <errno.h>
#endif // CERRNO_HEADER
--- NEW FILE: cfloat ---
// This file is automatically generated. Do not edit.
// ['../../../libs/compatibility/generate_cpp_c_headers.py']
// Mon Apr 16 15:16:00 2001 ('PST', 'PDT')
#ifndef __CFLOAT_HEADER
#define __CFLOAT_HEADER
#include <float.h>
#endif // CFLOAT_HEADER
--- NEW FILE: climits ---
// This file is automatically generated. Do not edit.
// ['../../../libs/compatibility/generate_cpp_c_headers.py']
// Mon Apr 16 15:16:00 2001 ('PST', 'PDT')
#ifndef __CLIMITS_HEADER
#define __CLIMITS_HEADER
#include <limits.h>
#endif // CLIMITS_HEADER
--- NEW FILE: clocale ---
// This file is automatically generated. Do not edit.
// ['../../../libs/compatibility/generate_cpp_c_headers.py']
// Mon Apr 16 15:16:00 2001 ('PST', 'PDT')
#ifndef __CLOCALE_HEADER
#define __CLOCALE_HEADER
#include <locale.h>
namespace std {
using ::lconv;
using ::localeconv;
using ::setlocale;
}
#endif // CLOCALE_HEADER
--- NEW FILE: cmath ---
// This file is automatically generated. Do not edit.
// ['../../../libs/compatibility/generate_cpp_c_headers.py']
// Mon Apr 16 15:16:00 2001 ('PST', 'PDT')
#ifndef __CMATH_HEADER
#define __CMATH_HEADER
#include <math.h>
namespace std {
using ::acos;
using ::cos;
using ::fmod;
using ::modf;
using ::tan;
using ::asin;
using ::cosh;
using ::frexp;
using ::pow;
using ::tanh;
using ::atan;
using ::exp;
using ::ldexp;
using ::sin;
using ::atan2;
using ::fabs;
using ::log;
using ::sinh;
using ::ceil;
using ::floor;
using ::log10;
using ::sqrt;
}
#endif // CMATH_HEADER
--- NEW FILE: csetjmp ---
// This file is automatically generated. Do not edit.
// ['../../../libs/compatibility/generate_cpp_c_headers.py']
// Mon Apr 16 15:16:00 2001 ('PST', 'PDT')
#ifndef __CSETJMP_HEADER
#define __CSETJMP_HEADER
#include <setjmp.h>
namespace std {
using ::jmp_buf;
using ::longjmp;
}
#endif // CSETJMP_HEADER
--- NEW FILE: csignal ---
// This file is automatically generated. Do not edit.
// ['../../../libs/compatibility/generate_cpp_c_headers.py']
// Mon Apr 16 15:16:00 2001 ('PST', 'PDT')
#ifndef __CSIGNAL_HEADER
#define __CSIGNAL_HEADER
#include <signal.h>
namespace std {
using ::sig_atomic_t;
using ::raise;
using ::signal;
}
#endif // CSIGNAL_HEADER
--- NEW FILE: cstdarg ---
// This file is automatically generated. Do not edit.
// ['../../../libs/compatibility/generate_cpp_c_headers.py']
// Mon Apr 16 15:16:00 2001 ('PST', 'PDT')
#ifndef __CSTDARG_HEADER
#define __CSTDARG_HEADER
#include <stdarg.h>
namespace std {
using ::va_list;
}
#endif // CSTDARG_HEADER
--- NEW FILE: cstddef ---
// This file is automatically generated. Do not edit.
// ['../../../libs/compatibility/generate_cpp_c_headers.py']
// Mon Apr 16 15:16:00 2001 ('PST', 'PDT')
#ifndef __CSTDDEF_HEADER
#define __CSTDDEF_HEADER
#include <stddef.h>
namespace std {
using ::ptrdiff_t;
using ::size_t;
}
#endif // CSTDDEF_HEADER
--- NEW FILE: cstdio ---
// This file is automatically generated. Do not edit.
// ['../../../libs/compatibility/generate_cpp_c_headers.py']
// Mon Apr 16 15:16:00 2001 ('PST', 'PDT')
#ifndef __CSTDIO_HEADER
#define __CSTDIO_HEADER
#include <stdio.h>
namespace std {
using ::FILE;
using ::fpos_t;
using ::size_t;
using ::clearerr;
using ::fgets;
using ::fscanf;
using ::gets;
using ::rename;
using ::tmpfile;
using ::fclose;
using ::fopen;
using ::fseek;
using ::perror;
using ::rewind;
using ::tmpnam;
using ::feof;
using ::fprintf;
using ::fsetpos;
using ::printf;
using ::scanf;
using ::ungetc;
using ::ferror;
using ::fputc;
using ::ftell;
using ::putc;
using ::setbuf;
using ::vfprintf;
using ::fflush;
using ::fputs;
using ::fwrite;
using ::putchar;
using ::setvbuf;
using ::vprintf;
using ::fgetc;
using ::fread;
using ::getc;
using ::puts;
using ::sprintf;
using ::vsprintf;
using ::fgetpos;
using ::freopen;
using ::getchar;
using ::remove;
using ::sscanf;
}
#endif // CSTDIO_HEADER
--- NEW FILE: cstdlib ---
// This file is automatically generated. Do not edit.
// ['../../../libs/compatibility/generate_cpp_c_headers.py']
// Mon Apr 16 15:16:00 2001 ('PST', 'PDT')
#ifndef __CSTDLIB_HEADER
#define __CSTDLIB_HEADER
#include <stdlib.h>
namespace std {
using ::abort;
using ::atexit;
using ::exit;
using ::getenv;
using ::system;
using ::calloc;
using ::malloc;
using ::free;
using ::realloc;
using ::atol;
using ::mblen;
using ::strtod;
using ::wctomb;
using ::atof;
using ::mbstowcs;
using ::strtol;
using ::wcstombs;
using ::atoi;
using ::mbtowc;
using ::strtoul;
using ::bsearch;
using ::qsort;
using ::div_t;
using ::ldiv_t;
using ::abs;
using ::labs;
using ::srand;
using ::div;
using ::ldiv;
using ::rand;
}
#endif // CSTDLIB_HEADER
--- NEW FILE: cstring ---
// This file is automatically generated. Do not edit.
// ['../../../libs/compatibility/generate_cpp_c_headers.py']
// Mon Apr 16 15:16:00 2001 ('PST', 'PDT')
#ifndef __CSTRING_HEADER
#define __CSTRING_HEADER
#include <string.h>
namespace std {
using ::size_t;
using ::memchr;
using ::strcat;
using ::strcspn;
using ::strncpy;
using ::strtok;
using ::memcmp;
using ::strchr;
using ::strerror;
using ::strpbrk;
using ::strxfrm;
using ::memcpy;
using ::strcmp;
using ::strlen;
using ::strrchr;
using ::memmove;
using ::strcoll;
using ::strncat;
using ::strspn;
using ::memset;
using ::strcpy;
using ::strncmp;
using ::strstr;
}
#endif // CSTRING_HEADER
--- NEW FILE: ctime ---
// This file is automatically generated. Do not edit.
// ['../../../libs/compatibility/generate_cpp_c_headers.py']
// Mon Apr 16 15:16:00 2001 ('PST', 'PDT')
#ifndef __CTIME_HEADER
#define __CTIME_HEADER
#include <time.h>
namespace std {
using ::size_t;
using ::clock_t;
using ::time_t;
using ::tm;
using ::asctime;
using ::clock;
using ::difftime;
using ::localtime;
using ::strftime;
using ::ctime;
using ::gmtime;
using ::mktime;
using ::time;
}
#endif // CTIME_HEADER
--- NEW FILE: cwchar ---
// This file is automatically generated. Do not edit.
// ['../../../libs/compatibility/generate_cpp_c_headers.py']
// Mon Apr 16 15:16:00 2001 ('PST', 'PDT')
#ifndef __CWCHAR_HEADER
#define __CWCHAR_HEADER
#include <wchar.h>
namespace std {
using ::mbstate_t;
using ::wint_t;
using ::size_t;
#if !(defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730)
using ::btowc;
#endif
#if !(defined(__linux) && defined(__DECCXX_VER) && __DECCXX_VER <= 60390005)
using ::getwchar;
#endif
#if !(defined(__linux) && defined(__DECCXX_VER) && __DECCXX_VER <= 60390005)
using ::ungetwc;
#endif
using ::wcscpy;
#if !(defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730)
using ::wcsrtombs;
#endif
#if !(defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730)
using ::wmemchr;
#endif
#if !(defined(__linux) && defined(__DECCXX_VER) && __DECCXX_VER <= 60390005)
using ::fgetwc;
#endif
#if !(defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730)
using ::mbrlen;
#endif
#if !(defined(__linux) && defined(__DECCXX_VER) && __DECCXX_VER <= 60390005)
#if !(defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730)
using ::vfwprintf;
#endif
#endif
using ::wcscspn;
using ::wcsspn;
#if !(defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730)
using ::wmemcmp;
#endif
#if !(defined(__linux) && defined(__DECCXX_VER) && __DECCXX_VER <= 60390005)
using ::fgetws;
#endif
#if !(defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730)
using ::mbrtowc;
#endif
#if !(defined(__linux) && defined(__DECCXX_VER) && __DECCXX_VER <= 60390005)
#if !(defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730)
using ::vswprintf;
#endif
#endif
#if !(defined(__linux) && defined(__DECCXX_VER) && __DECCXX_VER <= 60390005)
using ::wcsftime;
#endif
using ::wcsstr;
#if !(defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730)
using ::wmemcpy;
#endif
#if !(defined(__linux) && defined(__DECCXX_VER) && __DECCXX_VER <= 60390005)
using ::fputwc;
#endif
#if !(defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730)
using ::mbsinit;
#endif
#if !(defined(__linux) && defined(__DECCXX_VER) && __DECCXX_VER <= 60390005)
#if !(defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730)
using ::vwprintf;
#endif
#endif
using ::wcslen;
using ::wcstod;
#if !(defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730)
using ::wmemmove;
#endif
#if !(defined(__linux) && defined(__DECCXX_VER) && __DECCXX_VER <= 60390005)
using ::fputws;
#endif
#if !(defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730)
using ::mbsrtowcs;
#endif
#if !(defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730)
using ::wcrtomb;
#endif
using ::wcsncat;
using ::wcstok;
#if !(defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730)
using ::wmemset;
#endif
#if !(defined(__linux) && defined(__DECCXX_VER) && __DECCXX_VER <= 60390005)
#if !(defined(__DECCXX_VER) && __DECCXX_VER <= 60290024)
#if !(defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730)
using ::fwide;
#endif
#endif
#endif
#if !(defined(__linux) && defined(__DECCXX_VER) && __DECCXX_VER <= 60390005)
using ::putwc;
#endif
using ::wcscat;
using ::wcsncmp;
using ::wcstol;
#if !(defined(__linux) && defined(__DECCXX_VER) && __DECCXX_VER <= 60390005)
#if !(defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730)
using ::wprintf;
#endif
#endif
#if !(defined(__linux) && defined(__DECCXX_VER) && __DECCXX_VER <= 60390005)
#if !(defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730)
using ::fwprintf;
#endif
#endif
#if !(defined(__linux) && defined(__DECCXX_VER) && __DECCXX_VER <= 60390005)
using ::putwchar;
#endif
using ::wcschr;
using ::wcsncpy;
using ::wcstoul;
#if !(defined(__linux) && defined(__DECCXX_VER) && __DECCXX_VER <= 60390005)
#if !(defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730)
using ::wscanf;
#endif
#endif
#if !(defined(__linux) && defined(__DECCXX_VER) && __DECCXX_VER <= 60390005)
#if !(defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730)
using ::fwscanf;
#endif
#endif
#if !(defined(__linux) && defined(__DECCXX_VER) && __DECCXX_VER <= 60390005)
#if !(defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730)
using ::swprintf;
#endif
#endif
using ::wcscmp;
using ::wcspbrk;
using ::wcsxfrm;
#if !(defined(__linux) && defined(__DECCXX_VER) && __DECCXX_VER <= 60390005)
using ::getwc;
#endif
#if !(defined(__linux) && defined(__DECCXX_VER) && __DECCXX_VER <= 60390005)
#if !(defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730)
using ::swscanf;
#endif
#endif
using ::wcscoll;
using ::wcsrchr;
#if !(defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730)
using ::wctob;
#endif
}
#endif // CWCHAR_HEADER
--- NEW FILE: cwctype ---
// This file is automatically generated. Do not edit.
// ['../../../libs/compatibility/generate_cpp_c_headers.py']
// Mon Apr 16 15:16:00 2001 ('PST', 'PDT')
#ifndef __CWCTYPE_HEADER
#define __CWCTYPE_HEADER
#include <wctype.h>
namespace std {
#if !(defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730)
using ::wctrans_t;
#endif
using ::wctype_t;
using ::wint_t;
using ::iswalnum;
using ::iswctype;
using ::iswlower;
using ::iswspace;
#if !(defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730)
using ::towctrans;
#endif
#if !(defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730)
using ::wctrans;
#endif
using ::iswalpha;
using ::iswdigit;
using ::iswprint;
using ::iswupper;
using ::towlower;
using ::wctype;
using ::iswcntrl;
using ::iswgraph;
using ::iswpunct;
using ::iswxdigit;
using ::towupper;
}
#endif // CWCTYPE_HEADER
|
|
From: <net...@us...> - 2003-04-26 11:09:31
|
Update of /cvsroot/cpptool/rfta/src/rftaparser In directory sc8-pr-cvs1:/tmp/cvs-serv26803/src/rftaparser Modified Files: rftaparser.dsp Log Message: -- declaration parsing (splits to specifier and declarators) Index: rftaparser.dsp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/rftaparser.dsp,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -d -r1.36 -r1.37 *** rftaparser.dsp 22 Apr 2003 19:25:37 -0000 1.36 --- rftaparser.dsp 26 Apr 2003 11:09:27 -0000 1.37 *************** *** 414,417 **** --- 414,425 ---- # Begin Source File + SOURCE=.\UnparsedDeclarationMutator.cpp + # End Source File + # Begin Source File + + SOURCE=.\UnparsedDeclarationMutator.h + # End Source File + # Begin Source File + SOURCE=.\VariableDeclMutator.cpp # End Source File *************** *** 1104,1107 **** --- 1112,1123 ---- !ENDIF + # End Source File + # Begin Source File + + SOURCE=.\UnparsedDeclarationMutatorTest.cpp + # End Source File + # Begin Source File + + SOURCE=.\UnparsedDeclarationMutatorTest.h # End Source File # Begin Source File |
Update of /cvsroot/cpptool/rfta/src/rftaparser
In directory sc8-pr-cvs1:/tmp/cvs-serv25838/src/rftaparser
Added Files:
UnparsedDeclarationMutatorTest.h
UnparsedDeclarationMutatorTest.cpp
UnparsedDeclarationMutator.h UnparsedDeclarationMutator.cpp
Log Message:
-- declaration parsing (splits to specifier and declarators)
-- this is different to variabledeclmutator !
--- NEW FILE: UnparsedDeclarationMutatorTest.h ---
// //////////////////////////////////////////////////////////////////////////
// Header file UnparsedDeclarationMutatorTest.h for class UnparsedDeclarationMutatorTest
// (c)Copyright 2003, Andre Baresel.
// Created: 2003/04/18
// //////////////////////////////////////////////////////////////////////////
#ifndef RFTA_UnparsedDeclarationMutatorTest_H
#define RFTA_UnparsedDeclarationMutatorTest_H
#include "ParserTesting.h"
namespace Refactoring
{
/// Unit tests for UnparsedDeclarationMutatorTest
class UnparsedDeclarationMutatorTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( UnparsedDeclarationMutatorTest );
CPPUNIT_TEST( testSimpleDeclaration );
//CPPUNIT_TEST( testSpecialNestedName ); // will fail because type information is needed
CPPUNIT_TEST( testFunctionDeclaration );
CPPUNIT_TEST( testClassDeclaration );
CPPUNIT_TEST( testClassDeclarationWithInheritance );
CPPUNIT_TEST( testEnumDeclaration );
CPPUNIT_TEST( testPointerDecl );
CPPUNIT_TEST( testFctPointer );
CPPUNIT_TEST( testUserTypeFctPointer );
CPPUNIT_TEST( testSimpleTemplate );
CPPUNIT_TEST( testParameterTemplate );
CPPUNIT_TEST( testElaboratedClass );
CPPUNIT_TEST( testElaboratedUnion );
CPPUNIT_TEST( testUnnamedStruct );
CPPUNIT_TEST( testDeclareOperator ); // will fail because of a 'todo'
CPPUNIT_TEST( testConvertOperator ); // will fail because of a 'todo'
CPPUNIT_TEST( testDetectFunctionPtr );
CPPUNIT_TEST( testDetectUserDefType_Ptr );
CPPUNIT_TEST( testDetectUserDefType_Ref );
CPPUNIT_TEST( testDeclaringConst );
CPPUNIT_TEST( testDeclaringExceptions );
CPPUNIT_TEST( testDeclaringArray );
CPPUNIT_TEST( testStructTypedef );
CPPUNIT_TEST( testTypedefDeclaration );
CPPUNIT_TEST_SUITE_END();
public:
/*! Constructs a UnparsedDeclarationMutatorTest object.
*/
UnparsedDeclarationMutatorTest();
/// Destructor.
virtual ~UnparsedDeclarationMutatorTest();
void setUp();
void tearDown();
void testSimpleDeclaration();
void testFunctionDeclaration();
void testClassDeclaration();
void testClassDeclarationWithInheritance();
void testEnumDeclaration();
void testPointerDecl();
void testFctPointer();
void testUserTypeFctPointer();
void testSimpleTemplate();
void testParameterTemplate();
void testSpecialNestedName();
void testElaboratedClass();
void testElaboratedUnion();
void testUnnamedStruct();
void testDeclareOperator();
void testConvertOperator();
void testDetectFunctionPtr();
void testDetectUserDefType_Ptr();
void testDetectUserDefType_Ref();
void testDeclaringConst();
void testDeclaringExceptions();
void testDeclaringArray();
void testStructTypedef();
void testTypedefDeclaration();
private:
/// Prevents the use of the copy constructor.
UnparsedDeclarationMutatorTest( const UnparsedDeclarationMutatorTest &other );
/// Prevents the use of the copy operator.
void operator =( const UnparsedDeclarationMutatorTest &other );
private:
};
// Inlines methods for UnparsedDeclarationMutatorTest:
// ------------------------------------------------
} // namespace Refactoring
#endif // RFTA_UnparsedDeclarationMutatorTest_H
--- NEW FILE: UnparsedDeclarationMutatorTest.cpp ---
// //////////////////////////////////////////////////////////////////////////
// Implementation file UnparsedDeclarationMutatorTest.cpp for class UnparsedDeclarationMutatorTest
// (c)Copyright 2003, Andre Baresel.
// Created: 2003/04/18
// //////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "UnparsedDeclarationMutator.h"
#include "UnparsedDeclarationMutatorTest.h"
#include <rfta/parser/ASTNode.h>
#include <rfta/parser/ASTNodes.h>
#include <rfta/parser/ParseContext.h>
#include <rfta/parser/SourceASTNode.h>
#include <boost/format.hpp>
namespace Refactoring
{
RFTAPARSER_TEST_SUITE_REGISTRATION( UnparsedDeclarationMutatorTest );
namespace Testing
{
static SourceASTNodePtr checkDeclarationMutatorPass( const std::string &source,
const CppUnit::SourceLine &sourceLine )
{
SourceASTNodePtr sourceNode = SourceASTNode::create( source, source );
ParseContext context( sourceNode );
// simulate statement level parsing
ASTNodePtr statement =
ASTNode::create( ASTNodeTypes::declarationOrExpression,
sourceNode,
0,
source.length(),
sourceNode );
context.addNode( statement );
// do variable declaration parsing
UnparsedDeclarationMutator mutator( context,
statement,
sourceNode );
CppUnit::Message message( "mutator failed",
"Source:\n" + source );
CppUnit::Asserter::failIf( !mutator.tryMutate(), message, sourceLine );
return sourceNode;
}
static void checkDeclaration( const std::string& source,
const SourceASTNodePtr& sourceNode,
const std::vector<int> specifierStart,
const std::vector<int> specifierLen,
const std::vector<int> declStart,
const std::vector<int> declLen,
const CppUnit::SourceLine &sourceLine )
{
ASTNodePtr node = sourceNode->getChildAt(0);
int specifierCount = __min(specifierStart.size(), specifierLen.size());
int declaratorCount = __min(declStart.size() , declLen.size());
// check AST:
checkASTNodeHas ( node,
ASTNodeTypes::declaration,
0,
source.length(),
sourceLine,
"ASTNodeTypes::declaration"
);
if (specifierCount>0)
checkASTNodePropertyHas( node,
ASTNodeProperties::declarationSpecifiersProperty,
ASTNodeTypes::declarationSpecifierList,
specifierStart[0],
specifierLen[specifierCount-1]+specifierStart[specifierCount-1]-specifierStart[0],
sourceLine,
"ASTNodeProperties::declarationSpecifiersProperty"
);
ASTNodePtr specifierList = node->getProperty(ASTNodeProperties::declarationSpecifiersProperty);
// check number of specifiers parsed:
CppUnit::assertEquals( specifierList->getChildCount(), specifierCount, sourceLine,
boost::io::str(boost::format("Bad number of specifiers:\n Actual %1%\n Expected %2%.")
% specifierList->getChildCount()
% specifierCount ) );
int idx;
for (idx=0; idx<specifierCount; idx++)
{
ASTNodePtr specifierNode = specifierList->getChildAt(idx);
CppUnit::assertEquals( specifierStart[idx], specifierNode->getStartIndex(), sourceLine,
boost::io::str(boost::format("Specifier %1%: bad node start index.") % idx) );
CppUnit::assertEquals( specifierLen[idx] , specifierNode->getLength(), sourceLine,
boost::io::str(boost::format("Specifier %1%: bad node length.") % idx) );
}
// check declarators
CppUnit::assertEquals( node->getChildCount() , declaratorCount , sourceLine,
"Wrong number of declarators." );
for (idx=0; idx<declaratorCount; idx++)
{
ASTNodePtr declNode = node->getChildAt(idx);
CppUnit::assertEquals( declStart[idx], declNode->getStartIndex(), sourceLine,
boost::io::str(boost::format("Declarator %1%: bad node start index.") % idx) );
CppUnit::assertEquals( declLen[idx] , declNode->getLength(), sourceLine,
boost::io::str(boost::format("Declarator %1%: bad node length.") % idx) );
}
}
} // namespace Testing
#define RFTA_ASSERT_DECLARATION_MUTATOR_PASS( source ) \
Refactoring::Testing::checkDeclarationMutatorPass( source, CPPUNIT_SOURCELINE() )
#define RFTA_ASSERT_DECLARATION( source,sourceAST,specStart,specLen,declaratorStart,declaratorLen )\
Refactoring::Testing::checkDeclaration( \
source, sourceAST, specStart, specLen, \
declaratorStart, declaratorLen, CPPUNIT_SOURCELINE() )
UnparsedDeclarationMutatorTest::UnparsedDeclarationMutatorTest()
: CppUnit::TestFixture()
{
}
UnparsedDeclarationMutatorTest::~UnparsedDeclarationMutatorTest()
{
}
void
UnparsedDeclarationMutatorTest::setUp()
{
}
void
UnparsedDeclarationMutatorTest::tearDown()
{
}
template<typename T> std::vector<T>& operator<< (std::vector<T>& list, T val)
{
list.push_back(val);
return list;
}
template std::vector<int>& operator<<(std::vector<int>&, int);
void
UnparsedDeclarationMutatorTest::testSimpleDeclaration()
{
const std::string source( "const short int std::x;" );
std::vector<int> specStart, declStart;
std::vector<int> specLen , declLen;
specStart << 0 << 6 << 12;
specLen << 5 << 5 << 3 ;
declStart << 16;
declLen << 6;
SourceASTNodePtr sourceAST = RFTA_ASSERT_DECLARATION_MUTATOR_PASS( source );
ASTNodePtr node = sourceAST->getChildAt(0);
// check AST:
RFTA_ASSERT_DECLARATION(source,sourceAST,specStart,specLen,declStart,declLen);
// check specifier types:
ASTNodePtr specifierList = node->getProperty( ASTNodeProperties::declarationSpecifiersProperty );
RFTA_ASSERT_NODE_TYPE( specifierList->getChildAt(0), ASTNodeTypes::simpleTypeSpecifier );
RFTA_ASSERT_NODE_TYPE( specifierList->getChildAt(1), ASTNodeTypes::simpleTypeSpecifier);
RFTA_ASSERT_NODE_TYPE( specifierList->getChildAt(2), ASTNodeTypes::simpleTypeSpecifier);
// check declarator types:
RFTA_ASSERT_NODE_TYPE( node->getChildAt(0), ASTNodeTypes::unparsedDeclarator );
}
void
UnparsedDeclarationMutatorTest::testFunctionDeclaration()
{
const std::string source( "int fct(int p1, unsigned int p2, typename tp<int> p3);" );
std::vector<int> specStart, declStart;
std::vector<int> specLen , declLen;
specStart << 0;
specLen << 3;
declStart << 4;
declLen << int(source.length()-5);
SourceASTNodePtr sourceAST = RFTA_ASSERT_DECLARATION_MUTATOR_PASS( source );
ASTNodePtr node = sourceAST->getChildAt(0);
// check AST:
RFTA_ASSERT_DECLARATION(source,sourceAST,specStart,specLen,declStart,declLen);
// check specifier types:
ASTNodePtr specifierList = node->getProperty( ASTNodeProperties::declarationSpecifiersProperty );
RFTA_ASSERT_NODE_TYPE( specifierList->getChildAt(0), ASTNodeTypes::simpleTypeSpecifier );
// check declarator types:
RFTA_ASSERT_NODE_TYPE( node->getChildAt(0), ASTNodeTypes::unparsedDeclarator );
}
void
UnparsedDeclarationMutatorTest::testClassDeclaration()
{
const std::string source( "class x { public: int x() { } } y;" );
std::vector<int> specStart, declStart;
std::vector<int> specLen , declLen;
specStart << 0;
specLen << int(source.length()-3);
declStart << int(source.length()-2);
declLen << 1;
SourceASTNodePtr sourceAST = RFTA_ASSERT_DECLARATION_MUTATOR_PASS( source );
ASTNodePtr node = sourceAST->getChildAt(0);
// check AST:
RFTA_ASSERT_DECLARATION(source,sourceAST,specStart,specLen,declStart,declLen);
// check specifier types:
ASTNodePtr specifierList = node->getProperty( ASTNodeProperties::declarationSpecifiersProperty );
RFTA_ASSERT_NODE_TYPE( specifierList->getChildAt(0), ASTNodeTypes::classSpecifier );
// check declarator types:
RFTA_ASSERT_NODE_TYPE( node->getChildAt(0), ASTNodeTypes::unparsedDeclarator );
}
void
UnparsedDeclarationMutatorTest::testClassDeclarationWithInheritance()
{
const std::string source( "class x: public std::c1, protected user::c3 { public: int x() { } };" );
std::vector<int> specStart, declStart;
std::vector<int> specLen , declLen;
specStart << 0;
specLen << int(source.length()-1);
SourceASTNodePtr sourceAST = RFTA_ASSERT_DECLARATION_MUTATOR_PASS( source );
ASTNodePtr node = sourceAST->getChildAt(0);
// check AST:
RFTA_ASSERT_DECLARATION(source,sourceAST,specStart,specLen,declStart,declLen);
// check specifier types:
ASTNodePtr specifierList = node->getProperty( ASTNodeProperties::declarationSpecifiersProperty );
RFTA_ASSERT_NODE_TYPE( specifierList->getChildAt(0), ASTNodeTypes::classSpecifier );
}
void
UnparsedDeclarationMutatorTest::testEnumDeclaration()
{
const std::string source( "enum x { a = 0, b, c };" );
std::vector<int> specStart, declStart;
std::vector<int> specLen , declLen;
specStart << 0;
specLen << int(source.length()-1);
SourceASTNodePtr sourceAST = RFTA_ASSERT_DECLARATION_MUTATOR_PASS( source );
ASTNodePtr node = sourceAST->getChildAt(0);
// check AST:
RFTA_ASSERT_DECLARATION(source,sourceAST,specStart,specLen,declStart,declLen);
// check specifier types:
ASTNodePtr specifierList = node->getProperty( ASTNodeProperties::declarationSpecifiersProperty );
RFTA_ASSERT_NODE_TYPE( specifierList->getChildAt(0), ASTNodeTypes::enumSpecifier );
}
void
UnparsedDeclarationMutatorTest::testPointerDecl()
{
const std::string source( "int *f;" );
std::vector<int> specStart, declStart;
std::vector<int> specLen , declLen;
specStart << 0;
specLen << 3;
declStart << 4;
declLen << 2;
SourceASTNodePtr sourceAST = RFTA_ASSERT_DECLARATION_MUTATOR_PASS( source );
ASTNodePtr node = sourceAST->getChildAt(0);
// check AST:
RFTA_ASSERT_DECLARATION(source,sourceAST,specStart,specLen,declStart,declLen);
// check specifier types:
ASTNodePtr specifierList = node->getProperty( ASTNodeProperties::declarationSpecifiersProperty );
RFTA_ASSERT_NODE_TYPE( specifierList->getChildAt(0), ASTNodeTypes::simpleTypeSpecifier );
// check declarator types:
RFTA_ASSERT_NODE_TYPE( node->getChildAt(0), ASTNodeTypes::unparsedDeclarator);
}
void
UnparsedDeclarationMutatorTest::testFctPointer()
{
const std::string source( "int (*f)(int);" );
std::vector<int> specStart, declStart;
std::vector<int> specLen , declLen;
specStart << 0;
specLen << 3;
declStart << 4;
declLen << int(std::string("(*f)(int)").size());
SourceASTNodePtr sourceAST = RFTA_ASSERT_DECLARATION_MUTATOR_PASS( source );
ASTNodePtr node = sourceAST->getChildAt(0);
// check AST:
RFTA_ASSERT_DECLARATION(source,sourceAST,specStart,specLen,declStart,declLen);
// check specifier types:
ASTNodePtr specifierList = node->getProperty( ASTNodeProperties::declarationSpecifiersProperty );
RFTA_ASSERT_NODE_TYPE( specifierList->getChildAt(0), ASTNodeTypes::simpleTypeSpecifier );
// check declarator types:
RFTA_ASSERT_NODE_TYPE( node->getChildAt(0), ASTNodeTypes::unparsedDeclarator);
}
void
UnparsedDeclarationMutatorTest::testUserTypeFctPointer()
{
const std::string source( "usertype (*f)(int x);" );
std::vector<int> specStart, declStart;
std::vector<int> specLen , declLen;
specStart << 0;
specLen << 8;
declStart << 9;
declLen << int(std::string("(*f)(int x)").size());
SourceASTNodePtr sourceAST = RFTA_ASSERT_DECLARATION_MUTATOR_PASS( source );
ASTNodePtr node = sourceAST->getChildAt(0);
// check AST:
RFTA_ASSERT_DECLARATION(source,sourceAST,specStart,specLen,declStart,declLen);
// check specifier types:
ASTNodePtr specifierList = node->getProperty( ASTNodeProperties::declarationSpecifiersProperty );
RFTA_ASSERT_NODE_TYPE( specifierList->getChildAt(0), ASTNodeTypes::simpleTypeSpecifier );
// check declarator types:
RFTA_ASSERT_NODE_TYPE( node->getChildAt(0), ASTNodeTypes::unparsedDeclarator);
}
void
UnparsedDeclarationMutatorTest::testSimpleTemplate()
{
#undef SPECIFIER
#undef DECLARATOR
#define SPECIFIER "std::vector< std::vector<int> >"
#define DECLARATOR "&v = par_0"
const std::string source( SPECIFIER " " DECLARATOR ";" );
std::vector<int> specStart, declStart;
std::vector<int> specLen , declLen;
specStart << 0;
specLen << int(strlen( SPECIFIER ));
declStart << int(strlen( SPECIFIER ))+1;
declLen << int(strlen( DECLARATOR ));
SourceASTNodePtr sourceAST = RFTA_ASSERT_DECLARATION_MUTATOR_PASS( source );
ASTNodePtr node = sourceAST->getChildAt(0);
// check AST:
RFTA_ASSERT_DECLARATION(source,sourceAST,specStart,specLen,declStart,declLen);
// check specifier types:
ASTNodePtr specifierList = node->getProperty( ASTNodeProperties::declarationSpecifiersProperty );
RFTA_ASSERT_NODE_TYPE( specifierList->getChildAt(0), ASTNodeTypes::simpleTypeSpecifier );
// check declarator types:
RFTA_ASSERT_NODE_TYPE( node->getChildAt(0), ASTNodeTypes::unparsedDeclarator);
}
void
UnparsedDeclarationMutatorTest::testParameterTemplate()
{
#undef SPECIFIER
#undef DECLARATOR
#define SPECIFIER "usertmpl<int>(0,1)"
#define DECLARATOR "&v"
const std::string source( SPECIFIER " " DECLARATOR ";" );
std::vector<int> specStart, declStart;
std::vector<int> specLen , declLen;
specStart << 0;
specLen << int(strlen( SPECIFIER ));
declStart << int(strlen( SPECIFIER ))+1;
declLen << int(strlen( DECLARATOR ));
SourceASTNodePtr sourceAST = RFTA_ASSERT_DECLARATION_MUTATOR_PASS( source );
ASTNodePtr node = sourceAST->getChildAt(0);
// check AST:
RFTA_ASSERT_DECLARATION(source,sourceAST,specStart,specLen,declStart,declLen);
// check specifier types:
ASTNodePtr specifierList = node->getProperty( ASTNodeProperties::declarationSpecifiersProperty );
RFTA_ASSERT_NODE_TYPE( specifierList->getChildAt(0), ASTNodeTypes::simpleTypeSpecifier );
// check declarator types:
RFTA_ASSERT_NODE_TYPE( node->getChildAt(0), ASTNodeTypes::unparsedDeclarator);
}
void
UnparsedDeclarationMutatorTest::testSpecialNestedName()
{
/* EXAMPLE FOR THIS TEST:
typedef int myint;
class x {
public:
static myint y;
};
myint ::x::y;
btw: spaces are allowed between '::' and idenfifier ("x ::y" equals "x::y")
"class x ::z::y" has also two meanings !
*/
#undef SPECIFIER
#undef DECLARATOR
#define SPECIFIER "myint"
#define DECLARATOR "::x::y"
const std::string source( SPECIFIER " " DECLARATOR ";" );
std::vector<int> specStart, declStart;
std::vector<int> specLen , declLen;
specStart << 0;
specLen << int(strlen( SPECIFIER ));
declStart << int(strlen( SPECIFIER ))+1;
declLen << int(strlen( DECLARATOR ));
SourceASTNodePtr sourceAST = RFTA_ASSERT_DECLARATION_MUTATOR_PASS( source );
ASTNodePtr node = sourceAST->getChildAt(0);
// check AST:
RFTA_ASSERT_DECLARATION(source,sourceAST,specStart,specLen,declStart,declLen);
// check specifier types:
ASTNodePtr specifierList = node->getProperty( ASTNodeProperties::declarationSpecifiersProperty );
RFTA_ASSERT_NODE_TYPE( specifierList->getChildAt(0), ASTNodeTypes::simpleTypeSpecifier );
// check declarator types:
RFTA_ASSERT_NODE_TYPE( node->getChildAt(0), ASTNodeTypes::unparsedDeclarator);
}
void
UnparsedDeclarationMutatorTest::testElaboratedClass()
{
#undef SPECIFIER
#undef DECLARATOR
#define SPECIFIER "class ::x::x1::x3"
#define DECLARATOR "y"
const std::string source( SPECIFIER " " DECLARATOR ";" );
std::vector<int> specStart, declStart;
std::vector<int> specLen , declLen;
specStart << 0;
specLen << int(strlen( SPECIFIER ));
declStart << int(strlen( SPECIFIER ))+1;
declLen << int(strlen( DECLARATOR ));
SourceASTNodePtr sourceAST = RFTA_ASSERT_DECLARATION_MUTATOR_PASS( source );
ASTNodePtr node = sourceAST->getChildAt(0);
// check AST:
RFTA_ASSERT_DECLARATION(source,sourceAST,specStart,specLen,declStart,declLen);
// check specifier types:
ASTNodePtr specifierList = node->getProperty( ASTNodeProperties::declarationSpecifiersProperty );
RFTA_ASSERT_NODE_TYPE( specifierList->getChildAt(0), ASTNodeTypes::elaboratedTypeSpecifier );
// check declarator types:
RFTA_ASSERT_NODE_TYPE( node->getChildAt(0), ASTNodeTypes::unparsedDeclarator);
}
void
UnparsedDeclarationMutatorTest::testElaboratedUnion()
{
#undef SPECIFIER
#undef DECLARATOR
#define SPECIFIER "union y::x"
#define DECLARATOR ""
const std::string source( SPECIFIER " " DECLARATOR ";" );
std::vector<int> specStart, declStart;
std::vector<int> specLen , declLen;
specStart << 0;
specLen << int(strlen( SPECIFIER ));
SourceASTNodePtr sourceAST = RFTA_ASSERT_DECLARATION_MUTATOR_PASS( source );
ASTNodePtr node = sourceAST->getChildAt(0);
// check AST:
RFTA_ASSERT_DECLARATION(source,sourceAST,specStart,specLen,declStart,declLen);
// check specifier types:
ASTNodePtr specifierList = node->getProperty( ASTNodeProperties::declarationSpecifiersProperty );
RFTA_ASSERT_NODE_TYPE( specifierList->getChildAt(0), ASTNodeTypes::elaboratedTypeSpecifier );
}
void
UnparsedDeclarationMutatorTest::testUnnamedStruct()
{
#undef SPECIFIER
#undef DECLARATOR
#define SPECIFIER "struct { int x; }"
#define DECLARATOR "z"
const std::string source( SPECIFIER " " DECLARATOR ";" );
std::vector<int> specStart, declStart;
std::vector<int> specLen , declLen;
specStart << 0;
specLen << int(strlen( SPECIFIER ));
declStart << int(strlen( SPECIFIER ))+1;
declLen << int(strlen( DECLARATOR ));
SourceASTNodePtr sourceAST = RFTA_ASSERT_DECLARATION_MUTATOR_PASS( source );
ASTNodePtr node = sourceAST->getChildAt(0);
// check AST:
RFTA_ASSERT_DECLARATION(source,sourceAST,specStart,specLen,declStart,declLen);
// check specifier types:
ASTNodePtr specifierList = node->getProperty( ASTNodeProperties::declarationSpecifiersProperty );
RFTA_ASSERT_NODE_TYPE( specifierList->getChildAt(0), ASTNodeTypes::classSpecifier );
// check declarator types:
RFTA_ASSERT_NODE_TYPE( node->getChildAt(0), ASTNodeTypes::unparsedDeclarator);
}
void
UnparsedDeclarationMutatorTest::testDeclareOperator()
{
#undef SPECIFIER
#undef DECLARATOR
#define SPECIFIER "int"
#define DECLARATOR "operator<<(class T, int)"
const std::string source( SPECIFIER " " DECLARATOR ";" );
std::vector<int> specStart, declStart;
std::vector<int> specLen , declLen;
specStart << 0;
specLen << int(strlen( SPECIFIER ));
declStart << int(strlen( SPECIFIER ))+1;
declLen << int(strlen( DECLARATOR ));
SourceASTNodePtr sourceAST = RFTA_ASSERT_DECLARATION_MUTATOR_PASS( source );
ASTNodePtr node = sourceAST->getChildAt(0);
// check AST:
RFTA_ASSERT_DECLARATION(source,sourceAST,specStart,specLen,declStart,declLen);
// check specifier types:
ASTNodePtr specifierList = node->getProperty( ASTNodeProperties::declarationSpecifiersProperty );
RFTA_ASSERT_NODE_TYPE( specifierList->getChildAt(0), ASTNodeTypes::simpleTypeSpecifier );
// check declarator types:
RFTA_ASSERT_NODE_TYPE( node->getChildAt(0), ASTNodeTypes::unparsedDeclarator);
}
void
UnparsedDeclarationMutatorTest::testConvertOperator()
{
#undef SPECIFIER
#undef DECLARATOR
#define SPECIFIER ""
#define DECLARATOR "operator short int() (class T)"
const std::string source( SPECIFIER " " DECLARATOR ";" );
std::vector<int> specStart, declStart;
std::vector<int> specLen , declLen;
declStart << int(strlen( SPECIFIER ))+1;
declLen << int(strlen( DECLARATOR ));
SourceASTNodePtr sourceAST = RFTA_ASSERT_DECLARATION_MUTATOR_PASS( source );
ASTNodePtr node = sourceAST->getChildAt(0);
// check AST:
RFTA_ASSERT_DECLARATION(source,sourceAST,specStart,specLen,declStart,declLen);
// check declarator types:
RFTA_ASSERT_NODE_TYPE( node->getChildAt(0), ASTNodeTypes::unparsedDeclarator);
}
void
UnparsedDeclarationMutatorTest::testDetectFunctionPtr()
{
#undef SPECIFIER
#undef DECLARATOR
#define SPECIFIER "mytype"
#define DECLARATOR "* (*fct)(int, float) = &impl"
const std::string source( SPECIFIER " " DECLARATOR ";" );
std::vector<int> specStart, declStart;
std::vector<int> specLen , declLen;
specStart << 0;
specLen << int(strlen( SPECIFIER ));
declStart << int(strlen( SPECIFIER ))+1;
declLen << int(strlen( DECLARATOR ));
SourceASTNodePtr sourceAST = RFTA_ASSERT_DECLARATION_MUTATOR_PASS( source );
ASTNodePtr node = sourceAST->getChildAt(0);
// check AST:
RFTA_ASSERT_DECLARATION(source,sourceAST,specStart,specLen,declStart,declLen);
// check declarator types:
RFTA_ASSERT_NODE_TYPE( node->getChildAt(0), ASTNodeTypes::unparsedDeclarator);
}
void
UnparsedDeclarationMutatorTest::testDetectUserDefType_Ptr()
{
#undef SPECIFIER
#undef DECLARATOR
#define SPECIFIER "mytype"
#define DECLARATOR "* f(int)"
const std::string source( SPECIFIER " " DECLARATOR ";" );
std::vector<int> specStart, declStart;
std::vector<int> specLen , declLen;
specStart << 0;
specLen << int(strlen( SPECIFIER ));
declStart << int(strlen( SPECIFIER ))+1;
declLen << int(strlen( DECLARATOR ));
SourceASTNodePtr sourceAST = RFTA_ASSERT_DECLARATION_MUTATOR_PASS( source );
ASTNodePtr node = sourceAST->getChildAt(0);
// check AST:
RFTA_ASSERT_DECLARATION(source,sourceAST,specStart,specLen,declStart,declLen);
// check declarator types:
RFTA_ASSERT_NODE_TYPE( node->getChildAt(0), ASTNodeTypes::unparsedDeclarator);
}
void
UnparsedDeclarationMutatorTest::testDetectUserDefType_Ref()
{
#undef SPECIFIER
#undef DECLARATOR
#define SPECIFIER "mytype"
#define DECLARATOR "& f(int)"
const std::string source( SPECIFIER " " DECLARATOR ";" );
std::vector<int> specStart, declStart;
std::vector<int> specLen , declLen;
specStart << 0;
specLen << int(strlen( SPECIFIER ));
declStart << int(strlen( SPECIFIER ))+1;
declLen << int(strlen( DECLARATOR ));
SourceASTNodePtr sourceAST = RFTA_ASSERT_DECLARATION_MUTATOR_PASS( source );
ASTNodePtr node = sourceAST->getChildAt(0);
// check AST:
RFTA_ASSERT_DECLARATION(source,sourceAST,specStart,specLen,declStart,declLen);
// check declarator types:
RFTA_ASSERT_NODE_TYPE( node->getChildAt(0), ASTNodeTypes::unparsedDeclarator);
}
void
UnparsedDeclarationMutatorTest::testDeclaringConst()
{
#undef SPECIFIER
#undef DECLARATOR
#define SPECIFIER "const mytype"
#define DECLARATOR "* const f(int) const"
const std::string source( SPECIFIER " " DECLARATOR ";" );
std::vector<int> specStart, declStart;
std::vector<int> specLen , declLen;
specStart << 0 << 6;
specLen << 5 << 6;
declStart << int(strlen( SPECIFIER ))+1;
declLen << int(strlen( DECLARATOR ));
SourceASTNodePtr sourceAST = RFTA_ASSERT_DECLARATION_MUTATOR_PASS( source );
ASTNodePtr node = sourceAST->getChildAt(0);
// check AST:
RFTA_ASSERT_DECLARATION(source,sourceAST,specStart,specLen,declStart,declLen);
// check declarator types:
RFTA_ASSERT_NODE_TYPE( node->getChildAt(0), ASTNodeTypes::unparsedDeclarator);
}
void
UnparsedDeclarationMutatorTest::testDeclaringExceptions()
{
#undef SPECIFIER
#undef DECLARATOR
#define SPECIFIER "vector<int>"
#define DECLARATOR "& f(int) throw( BadParamExcep, OtherExcep )"
const std::string source( SPECIFIER " " DECLARATOR ";" );
std::vector<int> specStart, declStart;
std::vector<int> specLen , declLen;
specStart << 0 ;
specLen << 11 ;
declStart << int(strlen( SPECIFIER ))+1;
declLen << int(strlen( DECLARATOR ));
SourceASTNodePtr sourceAST = RFTA_ASSERT_DECLARATION_MUTATOR_PASS( source );
ASTNodePtr node = sourceAST->getChildAt(0);
// check AST:
RFTA_ASSERT_DECLARATION(source,sourceAST,specStart,specLen,declStart,declLen);
// check declarator types:
RFTA_ASSERT_NODE_TYPE( node->getChildAt(0), ASTNodeTypes::unparsedDeclarator);
}
void
UnparsedDeclarationMutatorTest::testDeclaringArray()
{
#undef SPECIFIER
#undef DECLARATOR
#define SPECIFIER "short int"
#define DECLARATOR "xyz[3][3] = { { 3,3,3 } , { 4,4,4 } , { 5,5,5 } }"
const std::string source( SPECIFIER " " DECLARATOR ";" );
std::vector<int> specStart, declStart;
std::vector<int> specLen , declLen;
specStart << 0 << 6 ;
specLen << 5 << 3 ;
declStart << int(strlen( SPECIFIER ))+1;
declLen << int(strlen( DECLARATOR ));
SourceASTNodePtr sourceAST = RFTA_ASSERT_DECLARATION_MUTATOR_PASS( source );
ASTNodePtr node = sourceAST->getChildAt(0);
// check AST:
RFTA_ASSERT_DECLARATION(source,sourceAST,specStart,specLen,declStart,declLen);
// check declarator types:
RFTA_ASSERT_NODE_TYPE( node->getChildAt(0), ASTNodeTypes::unparsedDeclarator);
}
void
UnparsedDeclarationMutatorTest::testTypedefDeclaration()
{
#undef SPECIFIER
#undef DECLARATOR
#define SPECIFIER "typedef short int"
#define DECLARATOR "mydef"
const std::string source( SPECIFIER " " DECLARATOR ";" );
std::vector<int> specStart, declStart;
std::vector<int> specLen , declLen;
specStart << 0 << 8 << 14;
specLen << 7 << 5 << 3;
declStart << int(strlen( SPECIFIER ))+1;
declLen << int(strlen( DECLARATOR ));
SourceASTNodePtr sourceAST = RFTA_ASSERT_DECLARATION_MUTATOR_PASS( source );
ASTNodePtr node = sourceAST->getChildAt(0);
// check AST:
RFTA_ASSERT_DECLARATION(source,sourceAST,specStart,specLen,declStart,declLen);
// check declarator types:
RFTA_ASSERT_NODE_TYPE( node->getChildAt(0), ASTNodeTypes::unparsedDeclarator);
}
void
UnparsedDeclarationMutatorTest::testStructTypedef()
{
#undef SPECIFIER
#undef DECLARATOR
#define SPECIFIER "struct c { int a; } typedef"
#define DECLARATOR "mystruct"
const std::string source( SPECIFIER " " DECLARATOR ";" );
std::vector<int> specStart, declStart;
std::vector<int> specLen , declLen;
specStart << 0 << 20 ;
specLen << 19 << 7 ;
declStart << int(strlen( SPECIFIER ))+1;
declLen << int(strlen( DECLARATOR ));
SourceASTNodePtr sourceAST = RFTA_ASSERT_DECLARATION_MUTATOR_PASS( source );
ASTNodePtr node = sourceAST->getChildAt(0);
// check AST:
RFTA_ASSERT_DECLARATION(source,sourceAST,specStart,specLen,declStart,declLen);
// check declarator types:
RFTA_ASSERT_NODE_TYPE( node->getChildAt(0), ASTNodeTypes::unparsedDeclarator);
}
} // namespace Refactoring
--- NEW FILE: UnparsedDeclarationMutator.h ---
// //////////////////////////////////////////////////////////////////////////
// Header file UnparsedDeclarationMutator.h for class UnparsedDeclarationMutator
// (c)Copyright 2003, Andre Baresel.
// Created: 2003/04/18
// //////////////////////////////////////////////////////////////////////////
#ifndef RFTA_UnparsedDeclarationMutator_H
#define RFTA_UnparsedDeclarationMutator_H
#include <rfta/parser/Parser.h>
#include <set>
namespace Refactoring
{
/// Mutate an unparsed-declaration-list into a parsed declaration-list
class UnparsedDeclarationMutator : public Parser
{
public:
/*! Constructs a UnparsedDeclarationMutator object.
*
* source range must not start with white spaces.
*/
UnparsedDeclarationMutator(
ParseContext &context,
const ASTNodePtr &node,
const SourceASTNodePtr &sourceNode);
/// Destructor.
virtual ~UnparsedDeclarationMutator();
bool tryMutate();
private:
//
// private methods for type specifier parsing:
//
// ENTRY-Point:
void parseDeclarationSpecifierList(ASTNodePtr &specifierList);
// parsing of composed specifiers (e.g. "class x { ... }"
void parseComposedSpecifier(const char * specifierStart, std::string& specifierIdent, ASTNodePtr &specifierList);
/**
* function does try to read a user defined type (it checks for a variable
* declaration)
* returns false in case of the end of specifier list
*/
bool tryParseUserDefinedType(std::string& typename_);
void readNestedName(std::string& nestedname);
void readClassOrEnumSpecifier(ASTNodePtr& specifier, std::string keyword, std::string name);
//
// private methods for declarator parsing:
//
// ENTRY-Point:
void parseDeclarators();
void parseOperator();
bool tryReadToken(std::string& token);
bool doesKeywordFollow( std::string keyword );
static bool tryFindNextBalanced( const char *¤t,
const char *end,
char opening = '<',
char closing = '>' );
bool skipOverAssignmentInitializer();
void createAndAddInitializerNode( const ASTNodePtr &variableDeclNode );
void addValueNode( const ASTNodePtr& variableDeclNode,
int start,
int end ) const;
void addInitializerNode( const ASTNodePtr& variableDeclNode,
const ASTNodeType initializerType,
int initializerStartIndex ) const;
private:
ASTNodePtr node_;
typedef std::set<std::string> KeywordSet;
KeywordSet declarationSpecifiers;
KeywordSet elaboratedSpecifiers;
};
// Inlines methods for UnparsedDeclarationMutator:
// --------------------------------------------
} // namespace Refactoring
#endif // RFTA_UnparsedDeclarationMutator_H
--- NEW FILE: UnparsedDeclarationMutator.cpp ---
// //////////////////////////////////////////////////////////////////////////
// Implementation file UnparsedDeclarationMutator.cpp for class UnparsedDeclarationMutator
// (c)Copyright 2003, Andre Baresel.
// Created: 2003/04/18
// //////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "UnparsedDeclarationMutator.h"
#include <rfta/parser/ASTNodes.h>
#include <rfta/parser/ParseContext.h>
#include <rfta/parser/DeclarationListParser.h>
namespace Refactoring
{
UnparsedDeclarationMutator::UnparsedDeclarationMutator(
ParseContext &context,
const ASTNodePtr &node,
const SourceASTNodePtr &sourceNode)
: Parser( context,
sourceNode->getBlankedSourceStart() + node->getRange().getStartIndex(),
sourceNode->getBlankedSourceStart() + node->getRange().getEndIndex() )
, node_( node )
{
// build lookup table for specifiers:
// generel specifier:
declarationSpecifiers.insert("typedef");
declarationSpecifiers.insert("friend");
// storage class
declarationSpecifiers.insert("auto");
declarationSpecifiers.insert("register");
declarationSpecifiers.insert("static");
declarationSpecifiers.insert("extern");
declarationSpecifiers.insert("mutable");
// function specifiers
declarationSpecifiers.insert("inline");
declarationSpecifiers.insert("virtual");
declarationSpecifiers.insert("explicit");
// simple type specifiers
declarationSpecifiers.insert("char");
declarationSpecifiers.insert("wchar_t");
declarationSpecifiers.insert("bool");
declarationSpecifiers.insert("short");
declarationSpecifiers.insert("int");
declarationSpecifiers.insert("long");
declarationSpecifiers.insert("signed");
declarationSpecifiers.insert("unsigned");
declarationSpecifiers.insert("float");
declarationSpecifiers.insert("double");
declarationSpecifiers.insert("void");
// cv-qualifier
declarationSpecifiers.insert("const");
declarationSpecifiers.insert("volatile");
// build lookup table for elaborated specifiers:
elaboratedSpecifiers.insert("class");
elaboratedSpecifiers.insert("struct");
elaboratedSpecifiers.insert("enum");
elaboratedSpecifiers.insert("union");
elaboratedSpecifiers.insert("typename");
}
UnparsedDeclarationMutator::~UnparsedDeclarationMutator()
{
}
bool
UnparsedDeclarationMutator::tryMutate()
{
ASTNodePtr declarationNode = node_;
node_->mutateType( ASTNodeTypes::declaration );
ASTNodePtr specifierList =
createASTNode(
ASTNodeTypes::declarationSpecifierList,
declarationNode,
getCurrentIndex(),
getCurrentLength()
);
declarationNode->setPropertyNode(
ASTNodeProperties::declarationSpecifiersProperty,
specifierList
);
// read the declaration specifier list and add childs to property:
parseDeclarationSpecifierList(specifierList);
backtrackSkippingSpaces();
specifierList->setLength(getCurrentLength());
skipSpaces();
// check if declaration has also a declarator:
if (!tryNextIs(';'))
{
// read all declarators and add childs to property:
parseDeclarators();
}
// return with no parsing error:
return true;
}
/**
* function parses all declaration specifiers until the first declarator is found.
* the decision about the end of the specifier list is done in "tryParseUserDefinedType"
*/
void
UnparsedDeclarationMutator::parseDeclarationSpecifierList(ASTNodePtr &specifierList)
{
std::string identifier;
const char * save_pointer = getCurrent();
while ( save_pointer = getCurrent(), tryReadNextIdentifier(identifier) )
{
if (declarationSpecifiers.find(identifier) != declarationSpecifiers.end())
{
// add the specifier node
ASTNodePtr specifier =
createASTNode(
ASTNodeTypes::simpleTypeSpecifier,
specifierList,
save_pointer-getStart(),
getCurrent()-save_pointer
);
specifierList->addChild(specifier);
skipSpaces();
continue;
}
// check elaborated-specifiers:
else if (elaboratedSpecifiers.find(identifier) != elaboratedSpecifiers.end())
{
skipSpaces();
parseComposedSpecifier(save_pointer, identifier, specifierList);
skipSpaces();
continue;
}
else
// check characters after symbol to find out if it's a userdefined type...
if (tryParseUserDefinedType(identifier))
{
backtrackSkippingSpaces();
// add the specifier node
ASTNodePtr specifier =
createASTNode(
ASTNodeTypes::simpleTypeSpecifier,
specifierList,
save_pointer-getStart(),
getCurrent()-save_pointer
);
specifierList->addChild(specifier);
skipSpaces();
continue;
}
else
{
current_ = save_pointer;
break;
}
}
}
/**
* function tries to parse elaborated and class/enum/struct/union specifiers
* a decision about the type is found during parsing.
*/
void
UnparsedDeclarationMutator::parseComposedSpecifier(const char * specifierStart,
std::string& specifierIdent,
ASTNodePtr &specifierList)
{
// CASE 1:
// check if identifier starts with a '::')
// (definitions can not start with nested names -> this declaration is an elaborated type
// which ends after the name)
if (tryNextIs(':'))
{
if (!tryNextIs(':'))
{
throwFailure( "Expected a double colon => '::'." );
}
skipSpaces();
// read the full name:
std::string name("::");
readNestedName(name);
// add the specifier node
ASTNodePtr specifier =
createASTNode(
ASTNodeTypes::elaboratedTypeSpecifier,
specifierList,
specifierStart-getStart(),
getCurrent()-specifierStart
);
specifierList->addChild(specifier);
return;
// FINISH HERE
}
// try to read the identifier that can be specifier after an elaborated type specifier
// if no identifier follows, an unnamed type is specifier (e.g. "struct { } x;")
std::string secondIdent;
if (tryReadNextIdentifier(secondIdent))
{
skipSpaces();
}
// check if no identifier or the identifier is not followed by a ':' (e.g. "class x {"
if (secondIdent.empty() || !tryNextIs(':'))
{
// add the specifier node
ASTNodePtr specifier =
createASTNode(
ASTNodeTypes::classSpecifier,
specifierList,
specifierStart-getStart(),
getCurrent()-specifierStart
);
specifierList->addChild(specifier);
readClassOrEnumSpecifier(specifier, specifierIdent, secondIdent);
// set real length after completed parsing
specifier->setLength(getCurrent()-specifierStart);
return;
}
// HERE we come only in case where the type is followed by a colon. "e.g. class x:"
// check if it is only a single colon (which means inheritance information e.g. "class x: public y ")
if (!tryNextIs(':'))
{
// yes it's - so parse the class specifier
if (specifierIdent == "class" || specifierIdent == "struct")
{
// add the specifier node
ASTNodePtr specifier =
createASTNode(
ASTNodeTypes::classSpecifier,
specifierList,
specifierStart-getStart(),
getCurrent()-specifierStart
);
specifierList->addChild(specifier);
// read the complete specifier:
readClassOrEnumSpecifier(specifier, specifierIdent, secondIdent);
// set real length after completed parsing
specifier->setLength(getCurrent()-specifierStart);
return;
// FINISH HERE (the class specifier ends here !)
}
throwFailure( "Expected a double colon => '::'." );
}
// HERE we come only in case of a double colon after the identifier which means:
// an elaborated type is specified: e.g. "class x::y"
skipSpaces();
// read the full name:
secondIdent.append("::");
readNestedName(secondIdent);
// add the specifier node
ASTNodePtr specifier =
createASTNode(
ASTNodeTypes::elaboratedTypeSpecifier,
specifierList,
specifierStart-getStart(),
getCurrent()-specifierStart
);
specifierList->addChild(specifier);
// set real length after completed parsing
specifier->setLength(getCurrent()-specifierStart);
}
bool
UnparsedDeclarationMutator::tryParseUserDefinedType(std::string& typename_)
{
// the 'typename_' might be a userdefined type or a declarator
// here we try to find out:
const char * rollback = current_;
if (typename_ == "operator")
return false;
// first read the fully qualified name:
skipSpaces();
// maybe a full qualified typename (e.g. "std::string")
if (tryNextIs(':'))
{
if (!tryNextIs(':'))
throwFailure("Declaration parser expects '::' in this context.");
typename_.append("::");
readNestedName(typename_);
skipSpaces();
}
// now check for template declaration:
if (tryNextIs('<')) // the use of a template type
{
// skip template usage:
findNextBalanced('<','>');
skipSpaces();
// check if it has parameter:
if (tryNextIs('('))
if (!this->tryReadUntilNext(')'))
throwFailure("Expect a closed parameter list for this template.");
return true; // yes, it's a user defined type !
}
// DO SOME LOOK AHEAD TO FIND OUT
// a possible declarator that follows:
// check existence of a next identifier, this is a sign for a userdefined type...
std::string identifier;
if (tryReadNextIdentifier(identifier))
{
current_ = rollback;
return true;
}
// check for a special case where the declarator starts with a '('
// example: "int (*(*f))(int);
if (tryNextIs('(')) // might be the declarator (e.g. "usertype (*f);" or a parameter (e.g. "int userfct()";
{
findNextBalanced('(',')');
}
skipSpaces();
std::string seperators=",;=[";
bool ret = seperators.find(*current_) == std::string::npos;
current_ = rollback;
return ret;
}
void
UnparsedDeclarationMutator::readNestedName(std::string& nestedname)
{
std::string fullName = nestedname;
std::string nameSpecifier;
bool oneMoreLevel;
do {
oneMoreLevel = false;
if (!tryReadNextIdentifier(nameSpecifier))
throwFailure( "Expected an identifier for elaborated type." );
fullName.append(nameSpecifier);
skipSpaces();
// check if identifier is followed by a '::' (additional level
if (tryNextIs(':'))
{
if (!tryNextIs(':'))
throwFailure( "Expected a double colon => '::'." );
fullName.append("::");
skipSpaces();
oneMoreLevel = true;
}
} while (oneMoreLevel);
backtrackSkippingSpaces();
}
void
UnparsedDeclarationMutator::readClassOrEnumSpecifier(ASTNodePtr& specifier, std::string keyword, std::string name)
{
if (keyword == "class" || keyword == "struct" )
{
// read over possible inheritance information
readUntilNextOf("{");
current_++;
} else
{
specifier->mutateType( ASTNodeTypes::enumSpecifier );
expect('{');
}
findNextBalanced('{','}');
}
bool
UnparsedDeclarationMutator::tryFindNextBalanced( const char *¤t,
const char *end,
char opening,
char closing )
{
int balance = 1;
while ( ++current != end )
{
char c = *current;
if ( c == closing )
{
--balance;
if ( balance == 0 )
{
++current;
return true;
}
}
else if ( c == opening )
++balance;
}
return false;
}
bool
UnparsedDeclarationMutator::skipOverAssignmentInitializer()
{
const char *start = current_;
while ( current_ != end_ )
{
char c = *current_;
if ( c == ';' || c == ',' )
return current_ != (start+1);
else if ( c == '(' )
{
if ( !tryFindNextBalanced( current_, end_, '(', ')' ) )
return false;
}
else if ( c == '[' )
{
if ( !tryFindNextBalanced( current_, end_, '[', ']' ) )
return false;
}
else if ( c == '{' )
{
if ( !tryFindNextBalanced( current_, end_, '{', '}' ) )
return false;
}
else
++current_;
}
return true;
}
void
UnparsedDeclarationMutator::parseDeclarators()
{
Tracker tracker( "UnparsedDeclarationMutator::parseDeclarators", *this );
int declaratorNumber = 1;
int prefixEndIndex = getCurrentIndex();
while ( current_ != end_ )
{
skipSpaces();
int declaratorStartIndex = getCurrentIndex();
if (doesKeywordFollow( "operator" ))
{
parseOperator();
return;
}
// find end of the init-declarator
bool declaratorEndReached = false;
bool functionDeclarator = false;
bool identifierFound = false;
do {
skipSpaces();
if (tryNextIs('*')) continue;
if (tryNextIs('&')) continue;
if (tryNextIs('('))
{
// check if this is a direct declaration of a function:
if (identifierFound)
{
functionDeclarator = true;
findNextBalanced('(',')');
} else
{
findNextBalanced('(',')');
readUntilNextOf(";,=(");
if (tryNextIs('('))
{
functionDeclarator = true;
findNextBalanced('(',')');
}
}
declaratorEndReached = true;
break;
}
if (tryNextIs('['))
{
findNextBalanced('[',']');
continue;
}
if (tryNextIs(';') || tryNextIs(',') || tryNextIs('=') || tryNextIs('{'))
{
declaratorEndReached = true;
--current_;
break;
}
std::string nestedName;
if (tryNextIs(':'))
{
if (!tryNextIs(':'))
throwFailure("Did not expect a single colon at this stage.");
nestedName = "::";
}
std::string identifier;
if (!tryReadNextIdentifier(identifier))
{
throwFailure( boost::format("unexpected character: '%1%'.") % *current_ );
} else
{
if (identifier=="const") continue;
if (identifier=="volatile") continue;
identifierFound = true;
// read fully qualified name:
nestedName.append(identifier);
if (tryReadNext("::"))
{
nestedName.append("::");
readNestedName(identifier);
}
continue;
}
} while (hasNext() && !declaratorEndReached);
if (!declaratorEndReached)
{
boost::format frmt( "failed to find expected declarator separator "
"for declaration %1%: ',;=({'. ");
throwFailure( frmt % declaratorNumber );
}
if (functionDeclarator)
{
// read the possible identifiers after function declarator:
bool found;
do {
skipSpaces();
found=false;
if (doesKeywordFollow("const") ) { found=true; }
if (doesKeywordFollow("volatile") ) { found=true; }
} while (found);
if (doesKeywordFollow("throw"))
{
skipSpaces();
expect('(');
readUntilNextOf(")");
if (*current_==')') ++current_;
}
}
ASTNodePtr
declaratorNode = createASTNode( ASTNodeTypes::unparsedDeclarator,
node_,
declaratorStartIndex,
getCurrentIndex() - declaratorStartIndex );
// the correct length is set when the initializer is added.
node_->addChild(declaratorNode);
// now go through initializers:
createAndAddInitializerNode(declaratorNode);
declaratorNumber++;
}
}
void
UnparsedDeclarationMutator::createAndAddInitializerNode( const ASTNodePtr &declaratorNode )
{
if ( !hasNext() )
return;
Tracker tracker( "UnparsedDeclarationMutator::createAndAddInitializerNode", *this );
int initializerStartIndex = getCurrentIndex();
int initializerValueStartIndex;
int initializerValueEndIndex;
int declaratorEndIndex;
ASTNodeType initializerType;
switch( *current_++ )
{
case '=':
initializerType = ASTNodeTypes::assignVariableInitializerExpression;
skipSpaces();
initializerValueStartIndex = getCurrentIndex();
skipOverAssignmentInitializer(); /// @todo should check return value
declaratorEndIndex = getCurrentIndex();
initializerValueEndIndex = getCurrentIndex();
break;
case '(':
initializerType = ASTNodeTypes::constructorVariableInitializerExpression;
initializerValueStartIndex = getCurrentIndex();
findNextBalanced( '(', ')' );
declaratorEndIndex = getCurrentIndex();
initializerValueEndIndex = getCurrentIndex() -1;
break;
case ';': case ',': case '{':
return;
default:
-- current_;
throwFailure( boost::format("unexpected character: '%1%'.") % *current_ );
}
declaratorNode->setLength( declaratorEndIndex -
declaratorNode->getStartIndex() );
addInitializerNode( declaratorNode,
initializerType,
initializerStartIndex );
addValueNode( declaratorNode,
initializerValueStartIndex,
initializerValueEndIndex );
skipSpaces();
if ( !hasNext() )
return;
if ( *current_ == ';' || *current_ == ',' )
++current_;
else
throwFailure( boost::format("unexpected character: '%1%'.") % *current_ );
}
void
UnparsedDeclarationMutator::addValueNode( const ASTNodePtr& declaratorNode,
int start,
int end) const
{
ASTNodePtr initializerNode =
declaratorNode->getProperty( ASTNodeProperties::variableInitializerProperty );
ASTNodePtr valueNode =
createASTNode( ASTNodeTypes::valueExpression,
initializerNode,
start,
end-start);
initializerNode->setPropertyNode( ASTNodeProperties::valueProperty,
valueNode );
}
void
UnparsedDeclarationMutator::addInitializerNode( const ASTNodePtr& declaratorNode,
const ASTNodeType initializerType,
int initializerStartIndex) const
{
int initializerLength = getCurrentIndex() - initializerStartIndex;
ASTNodePtr initializerNode = createASTNode( initializerType,
declaratorNode,
initializerStartIndex,
initializerLength );
declaratorNode->setPropertyNode( ASTNodeProperties::variableInitializerProperty,
initializerNode );
}
bool
UnparsedDeclarationMutator::doesKeywordFollow( std::string keyword)
{
int idx = 0;
const char * save = getCurrent();
std::string id;
bool retval = tryReadNextIdentifier(id) & id == keyword;
if (!retval) current_ = save;
return retval;
}
bool
UnparsedDeclarationMutator::tryReadToken(std::string& token)
{
std::string collect;
switch(*current_++)
{
case '+':
if (*current_== '=' )
{ current_++; collect="+="; }
else
if (*current_== '+' )
{ current_++; collect="++"; }
else
collect="+";
break;
case '-':
if (*current_== '=' )
{ current_++; collect="-="; }
else
if (*current_== '-' )
{ current_++; collect="--"; }
else
if (*current_== '>' )
{
current_++;
if (*current_== '*' )
{ current_++; collect="->*"; }
else
collect="->";
}
else
collect="-";
break;
case '*':
if (*current_== '=' )
{ current_++; collect="*="; }
else
collect="*";
break;
case '/':
if (*current_== '=' )
{ current_++; collect="/="; }
else
collect="/";
break;
case '^':
if (*current_== '=' )
{ current_++; collect="^="; }
else
collect="^";
break;
case '&':
if (*current_== '=' )
{ current_++; collect="&="; }
else
if (*current_== '&' )
{ current_++; collect="&&"; }
else
collect="&";
break;
case '|':
if (*current_== '=' )
{ current_++; collect="|="; }
else
if (*current_== '|' )
{ current_++; collect="||"; }
else
collect="|";
break;
case '~':
collect="~";
break;
case '!':
if (*current_== '=' )
{ current_++; collect="!="; }
else
collect="!";
break;
case '=':
if (*current_== '=' )
{ current_++; collect="=="; }
else
collect="=";
break;
case '<':
if (*current_== '=' )
{ current_++; collect="<="; }
else
if (*current_== '<' )
{
current_++;
if (*current_== '=' )
{
current_++; collect="<<=";
}
else
collect="<<";
}
else
collect="<";
break;
case '>':
if (*current_== '=' )
{ current_++; collect=">="; }
else
if (*current_== '>' )
{
current_++;
if (*current_== '=' )
{
current_++; collect=">>=";
}
else
collect=">>";
}
else
collect=">";
break;
case ',':
collect=",";
break;
case '(':
expect(')');
collect="()";
break;
case '[':
expect(']');
collect="[]";
break;
default:
--current_;
break;
}
token = collect;
return !token.empty();
}
void
UnparsedDeclarationMutator::parseOperator()
{
int declaratorStartIndex = getCurrentIndex() - strlen("operator");
skipSpaces();
std::string token;
if (!tryReadToken(token))
{
const char * begin = getCurrent();
if ( doesKeywordFollow("new") ) token += "new";
if ( doesKeywordFollow("delete") ) token += "delete";
if (!token.empty())
{
if ( tryReadNext("[]") ) token+="[]";
}
}
// check if operator overloading has been parsed
if (token.empty())
{
// this is not the case.
// this is 'conversion function declarator':
// skip over the type-specifier and ptr-operator elements
readUntilNextOf("(");
if ( !tryReadNext("()") )
throwFailure( "Expect '()' after a conversion function operator" );
}
// now read parameters: (for both operator and conversion function)
skipSpaces();
expect('(');
findNextBalanced('(',')');
ASTNodePtr declaratorNode = createASTNode( ASTNodeTypes::unparsedDeclarator,
node_,
declaratorStartIndex,
getCurrentIndex() - declaratorStartIndex );
node_->addChild(declaratorNode);
skipSpaces();
}
} // namespace Refactoring
|