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-05-05 08:03:33
|
Update of /cvsroot/cpptool/rfta/bug In directory sc8-pr-cvs1:/tmp/cvs-serv30629/bug Modified Files: List.txt Log Message: * added some 'minor' parser bug I found when inspecting ast/ogre/ogrebspscenemanager.cpp.html Index: List.txt =================================================================== RCS file: /cvsroot/cpptool/rfta/bug/List.txt,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** List.txt 4 May 2003 07:35:06 -0000 1.7 --- List.txt 5 May 2003 08:03:31 -0000 1.8 *************** *** 67,70 **** --- 67,87 ---- => parse up to next ';' instead of '{' --- + Bad local identifier parsing (ogre/ogrebspscenemanager.cpp.html) + mPendingGeometry.vertexStride = sizeof(float) * 7 + sizeof(int); + mPendingGeometry.pIndexes = new unsigned short[mLevel->mNumElements]; + (unsigned long*)mAABGeometry.pDiffuseColour + mAABGeometry.numVertices + mlpD3DDevice = NULL + => 'float', 'int', 'short', 'long', 'NULL' parsed as local-scope-indentifier; + --- + Bad variable-decl-expression range (ogre/ogrebspscenemanager.cpp.html) + - in BspSceneManager::~BspSceneManager() + delete mBspResMgr; + - in ? + std::pair<MaterialFaceGroupMap::iterator, bool> matgrpi; + - in addBoudingBox(): + unsigned long visibleColour; + => range extends to the end of the compound statement + --- + |
From: <bl...@us...> - 2003-05-04 22:13:54
|
Update of /cvsroot/cpptool/rfta/src/rftaparser In directory sc8-pr-cvs1:/tmp/cvs-serv24589/src/rftaparser Modified Files: MiniParserTest.cpp MiniParserTest.h Log Message: * added 'at least one spaces parser': space * added repeat parser * added trivial callback mecanism using Boost.Function. Index: MiniParserTest.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/MiniParserTest.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MiniParserTest.cpp 4 May 2003 18:19:28 -0000 1.1 --- MiniParserTest.cpp 4 May 2003 22:13:51 -0000 1.2 *************** *** 30,40 **** int expectedEnd = -1 ) { ! if ( expectedEnd ) expectedEnd = text.length(); Xtl::ParseResult result = parse( text, parser ); failIf( !result.matched_, "parsing failed" ); ! checkEquals( text.c_str(), result.matchStart_, "wrong match start" ); ! checkEquals( text.c_str() + expectedEnd, result.matchEnd_ , "wrong match end" ); } --- 30,41 ---- int expectedEnd = -1 ) { ! if ( expectedEnd == -1 ) expectedEnd = text.length(); Xtl::ParseResult result = parse( text, parser ); failIf( !result.matched_, "parsing failed" ); ! const char *start = text.c_str(); ! checkEquals( 0, result.matchStart_ - start, "wrong match start" ); ! checkEquals( expectedEnd, result.matchEnd_ - start, "wrong match end" ); } *************** *** 169,172 **** --- 170,226 ---- RFTA_ASSERT_MINIPARSER_FAIL( "+", parser2 ); RFTA_ASSERT_MINIPARSER_FAIL( "", parser2 ); + } + + + void + MiniParserTest::testParseRepeat() + { + const Xtl::MiniParser &parser = Xtl::makeRepeatParser( Xtl::StringMiniParser( "ab" ) ); + RFTA_ASSERT_MINIPARSER_PASS( "", parser ); + RFTA_ASSERT_MINIPARSER_PASS( "ab", parser ); + RFTA_ASSERT_MINIPARSER_PASS( "ababababab", parser ); + RFTA_ASSERT_MINIPARSER_PASS( "ababa", parser, 4 ); + + const Xtl::MiniParser &parser2 = Xtl::makeOnceOrMoreParser( Xtl::StringMiniParser( "ab" ) ); + RFTA_ASSERT_MINIPARSER_FAIL( "", parser2 ); + RFTA_ASSERT_MINIPARSER_PASS( "ab", parser2 ); + RFTA_ASSERT_MINIPARSER_PASS( "ababababab", parser2 ); + RFTA_ASSERT_MINIPARSER_PASS( "ababa", parser2, 4 ); + + const Xtl::MiniParser &parser3 = Xtl::makeRepeatParser( Xtl::StringMiniParser( "ab" ), 3 ); + RFTA_ASSERT_MINIPARSER_FAIL( "", parser3 ); + RFTA_ASSERT_MINIPARSER_FAIL( "ab", parser3 ); + RFTA_ASSERT_MINIPARSER_PASS( "ababab", parser3 ); + RFTA_ASSERT_MINIPARSER_PASS( "ababababa", parser3, 8 ); + RFTA_ASSERT_MINIPARSER_FAIL( "ababa", parser3 ); + } + + + void + MiniParserTest::testParseSpaces() + { + RFTA_ASSERT_MINIPARSER_PASS( " ", Xtl::spaces ); + RFTA_ASSERT_MINIPARSER_PASS( " ", Xtl::spaces ); + RFTA_ASSERT_MINIPARSER_FAIL( "", Xtl::spaces ); + RFTA_ASSERT_MINIPARSER_FAIL( "a", Xtl::spaces ); + RFTA_ASSERT_MINIPARSER_PASS( " a", Xtl::spaces, 2 ); + } + + + namespace { + static Xtl::CStringView callback1Text; + static void callback1( const Xtl::CStringView &text ) + { + callback1Text = text; + } + } + + void + MiniParserTest::testParseCallback() + { + const Xtl::MiniParser &parser = Xtl::spaces>> Xtl::StringMiniParser( "ab" )[&callback1] >> Xtl::spaces; + const std::string text( " ab " ); + RFTA_ASSERT_MINIPARSER_PASS( text, parser ); + RFTA_ASSERT_EQUAL( "ab", callback1Text.str() ); } Index: MiniParserTest.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/MiniParserTest.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MiniParserTest.h 4 May 2003 18:19:28 -0000 1.1 --- MiniParserTest.h 4 May 2003 22:13:51 -0000 1.2 *************** *** 25,28 **** --- 25,31 ---- CPPUNIT_TEST( testParseOptional ); CPPUNIT_TEST( testParseAlternative ); + CPPUNIT_TEST( testParseRepeat ); + CPPUNIT_TEST( testParseSpaces ); + CPPUNIT_TEST( testParseCallback ); CPPUNIT_TEST_SUITE_END(); *************** *** 49,52 **** --- 52,61 ---- void testParseAlternative(); + + void testParseRepeat(); + + void testParseSpaces(); + + void testParseCallback(); private: |
From: <bl...@us...> - 2003-05-04 22:13:54
|
Update of /cvsroot/cpptool/rfta/include/xtl In directory sc8-pr-cvs1:/tmp/cvs-serv24589/include/xtl Modified Files: MiniParser.h Log Message: * added 'at least one spaces parser': space * added repeat parser * added trivial callback mecanism using Boost.Function. Index: MiniParser.h =================================================================== RCS file: /cvsroot/cpptool/rfta/include/xtl/MiniParser.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MiniParser.h 4 May 2003 18:19:27 -0000 1.1 --- MiniParser.h 4 May 2003 22:13:51 -0000 1.2 *************** *** 2,5 **** --- 2,6 ---- #define XTL_MINIPARSER_H_INCLUDED + #include <boost/function.hpp> #include <xtl/CStringView.h> #include <stdexcept> *************** *** 18,22 **** class AlternativeMiniParser; ! class Scanner { --- 19,23 ---- class AlternativeMiniParser; ! /// Scanner, hold the text being parsed and provide iterator and backtracking. class Scanner { *************** *** 78,82 **** } ! private: const Iterator start_; const Iterator end_; --- 79,83 ---- } ! protected: const Iterator start_; const Iterator end_; *************** *** 85,90 **** ! ! struct ParseResult { --- 86,90 ---- ! /// Result of a parse (returned by each mini-parser). struct ParseResult { *************** *** 107,126 **** ! struct MandatoryMiniParserCategory ! { ! enum { isOptional = false }; ! }; ! ! ! struct OptionalMiniParserCategory ! { ! enum { isOptional = true }; ! }; ! ! class MiniParser { public: ! typedef MandatoryMiniParserCategory Category; virtual ParseResult parse( Scanner &scanner ) const = 0; --- 107,115 ---- ! /// Base abstract class for all parser class MiniParser { public: ! typedef boost::function1<void, const Xtl::CStringView &> MatchedCallback; virtual ParseResult parse( Scanner &scanner ) const = 0; *************** *** 132,149 **** ParseResult matched( Scanner::Iterator start, const Scanner &scanner ) const { ! return ParseResult( start, scanner.current() ); } ParseResult concatResult( const ParseResult &left, const ParseResult &right ) const { ! return ParseResult( left.matchStart_, right.matchEnd_ ); } ParseResult emptyMatch( Scanner::Iterator start ) const { ! return ParseResult( start, start ); } }; --- 121,158 ---- ParseResult matched( Scanner::Iterator start, + Scanner::Iterator end ) const + { + if ( callback_ ) + { + Xtl::CStringView text( start, end ); + callback_( text ); + } + return ParseResult( start, end ); + } + + ParseResult matched( Scanner::Iterator start, const Scanner &scanner ) const { ! return matched( start, scanner.current() ); } ParseResult concatResult( const ParseResult &left, const ParseResult &right ) const { ! ! return matched( left.matchStart_, right.matchEnd_ ); } ParseResult emptyMatch( Scanner::Iterator start ) const { ! return matched( start, start ); ! } ! ! protected: ! void setCallback( MatchedCallback callback ) ! { ! callback_ = callback; } + + MatchedCallback callback_; }; *************** *** 153,180 **** { public: template<typename RightParserType> SequenceMiniParser<DerivedParserType,RightParserType> operator >>( const RightParserType &parser) const { ! return makeSequenceParser( static_cast<const DerivedParserType &>(*this), parser ); } - template<typename RightParserType> AlternativeMiniParser<DerivedParserType,RightParserType> operator |( const RightParserType &parser) const { ! return makeAlternativeParser( static_cast<const DerivedParserType &>(*this), parser ); } - OptionalMiniParser<DerivedParserType> operator !() const { ! return makeOptionalParser( static_cast<const DerivedParserType &>(*this) ); } - }; class CharMiniParser : public MiniParserBase<CharMiniParser> { --- 162,203 ---- { public: + const DerivedParserType &derived() const + { + return static_cast<const DerivedParserType &>(*this); + } + + DerivedParserType &derived() + { + return static_cast<DerivedParserType &>(*this); + } + template<typename RightParserType> SequenceMiniParser<DerivedParserType,RightParserType> operator >>( const RightParserType &parser) const { ! return makeSequenceParser( derived(), parser ); } template<typename RightParserType> AlternativeMiniParser<DerivedParserType,RightParserType> operator |( const RightParserType &parser) const { ! return makeAlternativeParser( derived(), parser ); } OptionalMiniParser<DerivedParserType> operator !() const { ! return makeOptionalParser( derived() ); } + DerivedParserType &operator[]( MatchedCallback callback ) + { + setCallback( callback ); + return derived(); + } + }; + /// Matches a single character class CharMiniParser : public MiniParserBase<CharMiniParser> { *************** *** 205,208 **** --- 228,254 ---- + /// Matches one or more spaces + class SpacesMiniParser : public MiniParserBase<SpacesMiniParser> + { + public: + ParseResult parse( Scanner &scanner ) const + { + if ( scanner.hasNext() && *scanner == ' ' ) + { + Scanner::Iterator start = scanner.current(); + ++scanner; + while ( scanner.hasNext() && *scanner == ' ' ) + ++scanner; + return matched( start, scanner ); + } + + return noMatch(); + } + }; + + + const SpacesMiniParser spaces = SpacesMiniParser(); + + class StringMiniParser : public MiniParserBase<StringMiniParser> { *************** *** 388,393 **** typedef UnaryMiniParser<ParserType,OptionalMiniParser<ParserType> > SuperClass; - typedef OptionalMiniParserCategory Category; - OptionalMiniParser( const ParserType &parser ) : SuperClass( parser ) --- 434,437 ---- *************** *** 457,460 **** --- 501,562 ---- { return AlternativeMiniParser<LeftParserType,RightParserType>( left, right ); + } + + + template<typename ParserType> + class RepeatMiniParser : public UnaryMiniParser<ParserType + ,RepeatMiniParser<ParserType> > + { + public: + typedef UnaryMiniParser<ParserType,RepeatMiniParser<ParserType> > SuperClass; + + RepeatMiniParser( const ParserType &parser, + int minOccurrence ) + : SuperClass( parser ) + , minOccurrence_( minOccurrence ) + { + } + + ParseResult parse( Scanner &scanner ) const + { + Scanner::Iterator initial = scanner.current(); + int count = 0; + while ( scanner.hasNext() ) + { + Scanner::Iterator rollback = scanner.current(); + ParseResult result = parser_.parse( scanner ); + if ( !result.matched_ ) + { + scanner.backtrack( rollback ); + break; + } + ++count; + } + + if ( count < minOccurrence_ ) + { + scanner.backtrack( initial ); + return noMatch(); + } + + return matched( initial, scanner ); + } + + int minOccurrence_; + int maxOccurrence_; + }; + + + template<typename ParserType> + RepeatMiniParser<ParserType> makeRepeatParser( const ParserType &parser, int minOccurrence = 0 ) + { + return RepeatMiniParser<ParserType>( parser, minOccurrence ); + } + + + template<typename ParserType> + RepeatMiniParser<ParserType> makeOnceOrMoreParser( const ParserType &parser ) + { + return RepeatMiniParser<ParserType>( parser, 1 ); } |
From: <bl...@us...> - 2003-05-04 18:19:48
|
Update of /cvsroot/cpptool/rfta/src/rftaparser In directory sc8-pr-cvs1:/tmp/cvs-serv31173/src/rftaparser Modified Files: Parser.cpp Log Message: * removed dead code Index: Parser.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/Parser.cpp,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** Parser.cpp 4 May 2003 07:34:43 -0000 1.12 --- Parser.cpp 4 May 2003 18:19:45 -0000 1.13 *************** *** 93,105 **** % Xtl::CStringView( error.context_ ).getSubString(0, 60).str() % error.context_.getString().str() ).str(); - /* - - std::string message = error.what(); - message += "\n- Current line: " + boost::lexical_cast<std::string>( currentLine ); - 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_ ); } --- 93,96 ---- |
From: <bl...@us...> - 2003-05-04 18:19:30
|
Update of /cvsroot/cpptool/rfta/src/rftaparser In directory sc8-pr-cvs1:/tmp/cvs-serv31091/src/rftaparser Modified Files: rftaparser.dsp Added Files: MiniParserTest.cpp MiniParserTest.h Log Message: * experimenting with implementation of a simplistic parser framework (akin to Boost.Spirit, but much more simple). Still need to devise how matched parts are returned... --- NEW FILE: MiniParserTest.cpp --- // ////////////////////////////////////////////////////////////////////////// // (c)Copyright 2002, Baptiste Lepilleur. // Created: 2003/05/04 // ////////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "MiniParserTest.h" namespace Refactoring { RFTAPARSER_TEST_SUITE_REGISTRATION( MiniParserTest ); namespace Testing { struct MiniParserAsserter : public Asserter<MiniParserAsserter> { template<typename Parser> Xtl::ParseResult parse( const std::string &text, const Parser &parser ) { Xtl::Scanner scanner( text.c_str(), text.c_str() + text.length() ); return parser.parse( scanner ); } template<typename Parser> void checkParser( const std::string &text, const Parser &parser, int expectedEnd = -1 ) { if ( expectedEnd ) expectedEnd = text.length(); Xtl::ParseResult result = parse( text, parser ); failIf( !result.matched_, "parsing failed" ); checkEquals( text.c_str(), result.matchStart_, "wrong match start" ); checkEquals( text.c_str() + expectedEnd, result.matchEnd_ , "wrong match end" ); } template<typename Parser> void checkParserFail( const std::string &text, const Parser &parser ) { Xtl::ParseResult result = parse( text, parser ); failIf( result.matched_, "parsing should have failed" ); } }; #define RFTA_ASSERT_MINIPARSER_PASS \ RFTA_CUSTOM_ASSERT( Refactoring::Testing::MiniParserAsserter ).checkParser #define RFTA_ASSERT_MINIPARSER_FAIL \ RFTA_CUSTOM_ASSERT( Refactoring::Testing::MiniParserAsserter ).checkParserFail } // namespace Testing MiniParserTest::MiniParserTest() { } MiniParserTest::~MiniParserTest() { } void MiniParserTest::setUp() { } void MiniParserTest::tearDown() { } void MiniParserTest::testParseChLit() { RFTA_ASSERT_MINIPARSER_PASS( "a", Xtl::CharMiniParser( 'a' ) ); RFTA_ASSERT_MINIPARSER_FAIL( "b", Xtl::CharMiniParser( 'c' ) ); } void MiniParserTest::testParseString() { RFTA_ASSERT_MINIPARSER_PASS( "abcdef", Xtl::StringMiniParser( "abcdef" ) ); RFTA_ASSERT_MINIPARSER_PASS( "a", Xtl::StringMiniParser( "a" ) ); RFTA_ASSERT_MINIPARSER_PASS( "", Xtl::StringMiniParser( "" ) ); RFTA_ASSERT_MINIPARSER_FAIL( "abcdef", Xtl::StringMiniParser( "abcfgh" ) ); RFTA_ASSERT_MINIPARSER_FAIL( "", Xtl::StringMiniParser( "a" ) ); } void MiniParserTest::testParseCppIdentifier() { RFTA_ASSERT_MINIPARSER_PASS( "ab_012AC", Xtl::CppIdentifierMiniParser() ); RFTA_ASSERT_MINIPARSER_PASS( "ABC", Xtl::CppIdentifierMiniParser() ); RFTA_ASSERT_MINIPARSER_PASS( "a", Xtl::CppIdentifierMiniParser() ); RFTA_ASSERT_MINIPARSER_PASS( "_", Xtl::CppIdentifierMiniParser() ); RFTA_ASSERT_MINIPARSER_FAIL( "0", Xtl::CppIdentifierMiniParser() ); } void MiniParserTest::testParseMacroIdentifier() { RFTA_ASSERT_MINIPARSER_PASS( "A0_DEF", Xtl::MacroIdentifierMiniParser() ); RFTA_ASSERT_MINIPARSER_PASS( "ABC", Xtl::MacroIdentifierMiniParser() ); RFTA_ASSERT_MINIPARSER_PASS( "_", Xtl::MacroIdentifierMiniParser() ); RFTA_ASSERT_MINIPARSER_FAIL( "a_c", Xtl::MacroIdentifierMiniParser() ); RFTA_ASSERT_MINIPARSER_FAIL( "0", Xtl::MacroIdentifierMiniParser() ); } void MiniParserTest::testParseSequence() { RFTA_ASSERT_MINIPARSER_PASS( "->", Xtl::makeSequenceParser( Xtl::CharMiniParser( '-' ), Xtl::StringMiniParser( ">" ) ) ); const Xtl::MiniParser &parser = Xtl::CharMiniParser( '-' ) >> Xtl::CharMiniParser( '>' ); RFTA_ASSERT_MINIPARSER_PASS( "->", parser ); RFTA_ASSERT_MINIPARSER_FAIL( "=>", parser ); const Xtl::MiniParser &parser2 = Xtl::StringMiniParser( "class " ) >> Xtl::CppIdentifierMiniParser() >> Xtl::CharMiniParser( ':' ); RFTA_ASSERT_MINIPARSER_PASS( "class SourceRange:", parser2 ); RFTA_ASSERT_MINIPARSER_FAIL( "class SourceRange{", parser2 ); } void MiniParserTest::testParseOptional() { RFTA_ASSERT_MINIPARSER_PASS( "a", Xtl::makeOptionalParser( Xtl::CharMiniParser( 'a' ) ) ); RFTA_ASSERT_MINIPARSER_PASS( "ba", Xtl::makeOptionalParser( Xtl::CharMiniParser( 'a' ) ), 0 ); RFTA_ASSERT_MINIPARSER_PASS( "", Xtl::makeOptionalParser( Xtl::CharMiniParser( 'a' ) ) ); RFTA_ASSERT_MINIPARSER_PASS( "a", !Xtl::CharMiniParser( 'a' ) ); RFTA_ASSERT_MINIPARSER_PASS( "b", !Xtl::CharMiniParser( 'a' ), 0 ); RFTA_ASSERT_MINIPARSER_PASS( "", !Xtl::CharMiniParser( 'a' ) ); } void MiniParserTest::testParseAlternative() { const Xtl::MiniParser &parser = Xtl::makeAlternativeParser( Xtl::CharMiniParser( '-' ), Xtl::CharMiniParser( '>' ) ); RFTA_ASSERT_MINIPARSER_PASS( "-", parser ); RFTA_ASSERT_MINIPARSER_PASS( ">", parser ); RFTA_ASSERT_MINIPARSER_FAIL( "+", parser ); RFTA_ASSERT_MINIPARSER_FAIL( "", parser ); const Xtl::MiniParser &parser2 = Xtl::CharMiniParser( '-' ) | Xtl::CharMiniParser( '>' ); RFTA_ASSERT_MINIPARSER_PASS( "-", parser2 ); RFTA_ASSERT_MINIPARSER_PASS( ">", parser2 ); RFTA_ASSERT_MINIPARSER_FAIL( "+", parser2 ); RFTA_ASSERT_MINIPARSER_FAIL( "", parser2 ); } } // namespace Refactoring --- NEW FILE: MiniParserTest.h --- // ////////////////////////////////////////////////////////////////////////// // (c)Copyright 2002, Baptiste Lepilleur. // Created: 2003/05/04 // ////////////////////////////////////////////////////////////////////////// #ifndef RFTA_MINIPARSERTEST_H #define RFTA_MINIPARSERTEST_H #include "UnitTesting.h" #include <xtl/MiniParser.h> namespace Refactoring { /// Unit tests for MiniParserTest class MiniParserTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE( MiniParserTest ); CPPUNIT_TEST( testParseChLit ); CPPUNIT_TEST( testParseString ); CPPUNIT_TEST( testParseCppIdentifier ); CPPUNIT_TEST( testParseMacroIdentifier ); CPPUNIT_TEST( testParseSequence ); CPPUNIT_TEST( testParseOptional ); CPPUNIT_TEST( testParseAlternative ); CPPUNIT_TEST_SUITE_END(); public: /*! Constructs a MiniParserTest object. */ MiniParserTest(); /// Destructor. virtual ~MiniParserTest(); void setUp(); void tearDown(); void testParseChLit(); void testParseString(); void testParseCppIdentifier(); void testParseMacroIdentifier(); void testParseSequence(); void testParseOptional(); void testParseAlternative(); private: }; // Inlines methods for MiniParserTest: // ----------------------------------- } // namespace Refactoring #endif // RFTA_MINIPARSERTEST_H Index: rftaparser.dsp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/rftaparser.dsp,v retrieving revision 1.51 retrieving revision 1.52 diff -C2 -d -r1.51 -r1.52 *** rftaparser.dsp 4 May 2003 06:56:09 -0000 1.51 --- rftaparser.dsp 4 May 2003 18:19:28 -0000 1.52 *************** *** 158,161 **** --- 158,165 ---- # Begin Source File + SOURCE=..\..\include\xtl\MiniParser.h + # End Source File + # Begin Source File + SOURCE=..\..\include\xtl\NullEnumerator.h # End Source File *************** *** 672,675 **** --- 676,687 ---- !ENDIF + # End Source File + # Begin Source File + + SOURCE=.\MiniParserTest.cpp + # End Source File + # Begin Source File + + SOURCE=.\MiniParserTest.h # End Source File # End Group |
From: <bl...@us...> - 2003-05-04 18:19:30
|
Update of /cvsroot/cpptool/rfta/include/xtl In directory sc8-pr-cvs1:/tmp/cvs-serv31091/include/xtl Added Files: MiniParser.h Log Message: * experimenting with implementation of a simplistic parser framework (akin to Boost.Spirit, but much more simple). Still need to devise how matched parts are returned... --- NEW FILE: MiniParser.h --- #ifndef XTL_MINIPARSER_H_INCLUDED #define XTL_MINIPARSER_H_INCLUDED #include <xtl/CStringView.h> #include <stdexcept> namespace Xtl { template<typename LeftParserType ,typename RightParserType> class SequenceMiniParser; template<typename ParserType> class OptionalMiniParser; template<typename LeftParserType ,typename RightParserType> class AlternativeMiniParser; class Scanner { public: typedef const char *Iterator; explicit Scanner( const Xtl::CStringView &content ) : start_( content.getStart() ) , end_( content.getEnd() ) , current_( start_ ) { } Scanner( const char *first, const char *last ) : start_( first ) , end_( last ) , current_( start_ ) { } bool hasNext() const { return current_ != end_; } bool isAtEnd() const { return current_ == end_; } char operator *() const { #ifndef NDEBUG if ( isAtEnd() ) throw std::logic_error( "Scanner::operator *() called at end of content." ); #endif return *current_; } Scanner &operator ++() { #ifndef NDEBUG if ( isAtEnd() ) throw std::logic_error( "Scanner::operator ++() called at end of content." ); #endif ++current_; return *this; } Scanner::Iterator current() const { return current_; } void backtrack( Scanner::Iterator rollback ) { current_ = rollback; } private: const Iterator start_; const Iterator end_; Iterator current_; }; struct ParseResult { ParseResult() : matched_( false ) { } ParseResult( Scanner::Iterator start, Scanner::Iterator end ) : matched_( true ) , matchStart_( start ) , matchEnd_( end ) { } bool matched_; Scanner::Iterator matchStart_; Scanner::Iterator matchEnd_; }; struct MandatoryMiniParserCategory { enum { isOptional = false }; }; struct OptionalMiniParserCategory { enum { isOptional = true }; }; class MiniParser { public: typedef MandatoryMiniParserCategory Category; virtual ParseResult parse( Scanner &scanner ) const = 0; ParseResult noMatch() const { return ParseResult(); } ParseResult matched( Scanner::Iterator start, const Scanner &scanner ) const { return ParseResult( start, scanner.current() ); } ParseResult concatResult( const ParseResult &left, const ParseResult &right ) const { return ParseResult( left.matchStart_, right.matchEnd_ ); } ParseResult emptyMatch( Scanner::Iterator start ) const { return ParseResult( start, start ); } }; template<typename DerivedParserType> class MiniParserBase : public MiniParser { public: template<typename RightParserType> SequenceMiniParser<DerivedParserType,RightParserType> operator >>( const RightParserType &parser) const { return makeSequenceParser( static_cast<const DerivedParserType &>(*this), parser ); } template<typename RightParserType> AlternativeMiniParser<DerivedParserType,RightParserType> operator |( const RightParserType &parser) const { return makeAlternativeParser( static_cast<const DerivedParserType &>(*this), parser ); } OptionalMiniParser<DerivedParserType> operator !() const { return makeOptionalParser( static_cast<const DerivedParserType &>(*this) ); } }; class CharMiniParser : public MiniParserBase<CharMiniParser> { public: CharMiniParser( char ch ) : ch_( ch ) { } ParseResult parse( Scanner &scanner ) const { if ( scanner.hasNext() ) { if ( *scanner == ch_ ) { Scanner::Iterator start = scanner.current(); ++scanner; return matched( start, scanner ); } } return noMatch(); } private: char ch_; }; class StringMiniParser : public MiniParserBase<StringMiniParser> { public: StringMiniParser( const std::string &text ) : text_( text ) , first_( text_.c_str() ) , last_( text_.c_str() + text_.length() ) { } ParseResult parse( Scanner &scanner ) const { Scanner::Iterator start = scanner.current(); const char *str = first_; while ( str != last_ ) { if ( scanner.isAtEnd() || *scanner != *str ) return noMatch(); ++str; ++scanner; } return matched( start, scanner ); } private: std::string text_; const char *first_; const char *last_; }; struct CppIdentifierTraits { inline static bool isIdentifierFirstLetter( char letter ) { return (letter >= 'a' && letter <= 'z' ) || (letter >= 'A' && letter <= 'Z' ) || letter == '_'; } inline static bool isIdentifierLetter( char letter ) { return (letter >= 'a' && letter <= 'z' ) || (letter >= 'A' && letter <= 'Z' ) || (letter >= '0' && letter <= '9' ) || letter == '_'; } }; struct MacroIdentifierTraits { inline static bool isIdentifierFirstLetter( char letter ) { return (letter >= 'A' && letter <= 'Z' ) || letter == '_'; } inline static bool isIdentifierLetter( char letter ) { return (letter >= 'A' && letter <= 'Z' ) || (letter >= '0' && letter <= '9' ) || letter == '_'; } }; template<typename IdentifierTraits> class IdentifierMiniParser : public MiniParserBase< IdentifierMiniParser<IdentifierTraits> > { public: ParseResult parse( Scanner &scanner ) const { Scanner::Iterator start = scanner.current(); if ( scanner.hasNext() && IdentifierTraits::isIdentifierFirstLetter( *scanner ) ) { ++scanner; while ( scanner.hasNext() && IdentifierTraits::isIdentifierLetter( *scanner ) ) ++scanner; return matched( start, scanner ); } return noMatch(); } }; typedef IdentifierMiniParser<CppIdentifierTraits> CppIdentifierMiniParser; typedef IdentifierMiniParser<MacroIdentifierTraits> MacroIdentifierMiniParser; template<typename ParserType ,typename DerivedParserType> class UnaryMiniParser : public MiniParserBase<DerivedParserType> { public: typedef ParserType Parser; UnaryMiniParser( const Parser &parser ) : parser_( parser ) { } protected: Parser parser_; }; template<typename LeftParserType ,typename RightParserType ,typename DerivedParserType> class BinaryMiniParser : public MiniParserBase<DerivedParserType> { public: typedef LeftParserType LeftParser; typedef RightParserType RightParser; BinaryMiniParser( const LeftParser &left, const RightParser &right ) : leftParser_( left ) , rightParser_( right ) { } protected: LeftParser leftParser_; RightParser rightParser_; }; template<typename LeftParserType ,typename RightParserType> class SequenceMiniParser : public BinaryMiniParser<LeftParserType ,RightParserType ,SequenceMiniParser<LeftParserType ,RightParserType> > { public: typedef BinaryMiniParser<LeftParserType ,RightParserType ,SequenceMiniParser<LeftParserType ,RightParserType> > SuperClass; SequenceMiniParser( const LeftParser &left, const RightParser &right ) : SuperClass( left, right ) { } ParseResult parse( Scanner &scanner ) const { ParseResult leftResult = leftParser_.parse( scanner ); if ( leftResult.matched_ ) { ParseResult rightResult = rightParser_.parse( scanner ); if ( rightResult.matched_ ) return concatResult( leftResult, rightResult ); } return noMatch(); } }; template<typename LeftParserType ,typename RightParserType> SequenceMiniParser<LeftParserType,RightParserType> makeSequenceParser( const LeftParserType &left, const RightParserType &right ) { return SequenceMiniParser<LeftParserType,RightParserType>( left, right ); } template<typename ParserType> class OptionalMiniParser : public UnaryMiniParser<ParserType ,OptionalMiniParser<ParserType> > { public: typedef UnaryMiniParser<ParserType,OptionalMiniParser<ParserType> > SuperClass; typedef OptionalMiniParserCategory Category; OptionalMiniParser( const ParserType &parser ) : SuperClass( parser ) { } ParseResult parse( Scanner &scanner ) const { Scanner::Iterator rollback = scanner.current(); ParseResult result = parser_.parse( scanner ); if ( result.matched_ ) return result; scanner.backtrack( rollback ); return emptyMatch( rollback ); } }; template<typename ParserType> OptionalMiniParser<ParserType> makeOptionalParser( const ParserType &parser ) { return OptionalMiniParser<ParserType>( parser ); } template<typename LeftParserType ,typename RightParserType> class AlternativeMiniParser : public BinaryMiniParser<LeftParserType ,RightParserType ,AlternativeMiniParser<LeftParserType ,RightParserType> > { public: typedef BinaryMiniParser<LeftParserType ,RightParserType ,AlternativeMiniParser<LeftParserType ,RightParserType> > SuperClass; AlternativeMiniParser( const LeftParser &left, const RightParser &right ) : SuperClass( left, right ) { } ParseResult parse( Scanner &scanner ) const { Scanner::Iterator initial = scanner.current(); ParseResult leftResult = leftParser_.parse( scanner ); if ( leftResult.matched_ ) return leftResult; scanner.backtrack( initial ); return rightParser_.parse( scanner ); } }; template<typename LeftParserType ,typename RightParserType> AlternativeMiniParser<LeftParserType,RightParserType> makeAlternativeParser( const LeftParserType &left, const RightParserType &right ) { return AlternativeMiniParser<LeftParserType,RightParserType>( left, right ); } } // namespace Xtl #endif // XTL_MINIPARSER_H_INCLUDED |
From: <bl...@us...> - 2003-05-04 07:35:09
|
Update of /cvsroot/cpptool/rfta/bug In directory sc8-pr-cvs1:/tmp/cvs-serv17504/bug Modified Files: List.txt Log Message: * added cosntructor bug parse Index: List.txt =================================================================== RCS file: /cvsroot/cpptool/rfta/bug/List.txt,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** List.txt 3 May 2003 22:22:39 -0000 1.6 --- List.txt 4 May 2003 07:35:06 -0000 1.7 *************** *** 42,46 **** WXDLLEXPORT_DATA(extern const wxChar*) wxEmptyString; => this is interpreter as a macro declaration declaration & something ? ! --- 42,70 ---- WXDLLEXPORT_DATA(extern const wxChar*) wxEmptyString; => this is interpreter as a macro declaration declaration & something ? ! --- ! bad constructor handling (wxwindows/dirctrlg.h) ! wxGenericDirCtrl(wxWindow *parent, const wxWindowID id = -1, ! const wxString &dir = wxDirDialogDefaultFolderStr, ! const wxPoint& pos = wxDefaultPosition, ! const wxSize& size = wxDefaultSize, ! long style = wxDIRCTRL_3D_INTERNAL|wxSUNKEN_BORDER, ! const wxString& filter = wxEmptyString, ! int defaultFilter = 0, ! const wxString& name = wxTreeCtrlNameStr ) ! { ! Init(); ! Create(parent, id, dir, pos, size, style, filter, defaultFilter, name); ! } ! ! bool Create(wxWindow *parent, const wxWindowID id = -1, ! const wxString &dir = wxDirDialogDefaultFolderStr, ! const wxPoint& pos = wxDefaultPosition, ! const wxSize& size = wxDefaultSize, ! long style = wxDIRCTRL_3D_INTERNAL|wxSUNKEN_BORDER, ! const wxString& filter = wxEmptyString, ! int defaultFilter = 0, ! const wxString& name = wxTreeCtrlNameStr ); ! => parse up to next ';' instead of '{' ! --- |
From: <bl...@us...> - 2003-05-04 07:34:45
|
Update of /cvsroot/cpptool/rfta/src/rftaparser In directory sc8-pr-cvs1:/tmp/cvs-serv17287/src/rftaparser Modified Files: Parser.cpp Log Message: * added line number to error message on parse failure Index: Parser.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/Parser.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** Parser.cpp 4 May 2003 06:55:25 -0000 1.11 --- Parser.cpp 4 May 2003 07:34:43 -0000 1.12 *************** *** 11,14 **** --- 11,15 ---- #include <rfta/parser/ParserTools.h> #include <xtl/CStringView.h> + #include <boost/lexical_cast.hpp> *************** *** 76,86 **** 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_ ); } --- 77,118 ---- Parser::throwFailure( const ParserTools::ParseError &error ) { + Xtl::CStringView source( context_.getSourceNode()->getOriginalSource() ); + int startLine = getLineNumberOf( start_ ); + int endLine = getLineNumberOf( end_ ); + int currentLine = getLineNumberOf( error.context_ ); + + boost::format formatter( + "%s\n" + "- Parser lines: current = %d, start = %d, end = %d\n" + "- Current text: %s\n" + "- While analyzing:\n%s" ); + + std::string message = + (formatter % error.what() + % currentLine % startLine % endLine + % Xtl::CStringView( error.context_ ).getSubString(0, 60).str() + % error.context_.getString().str() ).str(); + /* + std::string message = error.what(); + message += "\n- Current line: " + boost::lexical_cast<std::string>( currentLine ); 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_ ); + } + + + int + Parser::getLineNumberOf( const char *position ) const + { + if ( !position ) + return -1; + + Xtl::CStringView source( context_.getSourceNode()->getOriginalSource() ); + const char *originalPosition = source.getStart() + getIndexOf( position ); + return std::count( source.getStart(), originalPosition, '\n' ) +1; } |
From: <bl...@us...> - 2003-05-04 07:34:45
|
Update of /cvsroot/cpptool/rfta/include/rfta/parser In directory sc8-pr-cvs1:/tmp/cvs-serv17287/include/rfta/parser Modified Files: Parser.h Log Message: * added line number to error message on parse failure Index: Parser.h =================================================================== RCS file: /cvsroot/cpptool/rfta/include/rfta/parser/Parser.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Parser.h 4 May 2003 06:55:25 -0000 1.10 --- Parser.h 4 May 2003 07:34:42 -0000 1.11 *************** *** 146,151 **** return true; } - - return false; } catch ( ParserTools::ParseError &error ) --- 146,149 ---- *************** *** 153,157 **** --- 151,159 ---- throwFailure( error ); } + + return false; } + + int getLineNumberOf( const char *position ) const; ParseContext &context_; *************** *** 159,164 **** const char *const start_; const char *const end_; - - private: }; --- 161,164 ---- |
From: <bl...@us...> - 2003-05-04 07:34:11
|
Update of /cvsroot/cpptool/rfta/src/rftaparser In directory sc8-pr-cvs1:/tmp/cvs-serv16999/src/rftaparser Modified Files: SourceASTNode.cpp Log Message: * return original and blanked source as CStringView Index: SourceASTNode.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/SourceASTNode.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** SourceASTNode.cpp 25 Dec 2002 22:39:02 -0000 1.7 --- SourceASTNode.cpp 4 May 2003 07:34:06 -0000 1.8 *************** *** 8,11 **** --- 8,12 ---- #include <rfta/parser/ASTNodes.h> #include <rfta/parser/SourceASTNode.h> + #include <xtl/CStringView.h> #include <stdexcept> *************** *** 71,74 **** --- 72,89 ---- { return realSource_.substr( range.getStartIndex(), range.getLength() ); + } + + + Xtl::CStringView + SourceASTNode::getBlankedSource() const + { + return Xtl::CStringView( blankedSourceStart_, blankedSourceStart_ + blankedSource_.length() ); + } + + + Xtl::CStringView + SourceASTNode::getOriginalSource() const + { + return Xtl::CStringView( realSource_.c_str(), realSource_.c_str() + realSource_.length() ); } |
From: <bl...@us...> - 2003-05-04 07:34:11
|
Update of /cvsroot/cpptool/rfta/include/rfta/parser In directory sc8-pr-cvs1:/tmp/cvs-serv16999/include/rfta/parser Modified Files: SourceASTNode.h Log Message: * return original and blanked source as CStringView Index: SourceASTNode.h =================================================================== RCS file: /cvsroot/cpptool/rfta/include/rfta/parser/SourceASTNode.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** SourceASTNode.h 22 Dec 2002 16:03:50 -0000 1.8 --- SourceASTNode.h 4 May 2003 07:34:06 -0000 1.9 *************** *** 8,11 **** --- 8,12 ---- #include <rfta/parser/ASTNode.h> + #include <xtl/Forwards.h> *************** *** 35,38 **** --- 36,44 ---- const std::string getOriginalTextFor( const SourceRange &range ) const; + + Xtl::CStringView getBlankedSource() const; + + Xtl::CStringView getOriginalSource() const; + protected: |
From: <bl...@us...> - 2003-05-04 06:56:51
|
Update of /cvsroot/cpptool/rfta/src/rftaparser In directory sc8-pr-cvs1:/tmp/cvs-serv623/src/rftaparser Modified Files: CPPParserTest.cpp DeclarationDetailsParser.cpp DeclarationDetailsParser.h DeclarationParserTest.cpp DeclarationParserTest.h UnparsedDeclarationMutatorTest.cpp UnparsedDeclarationMutatorTest.h Log Message: * added support for class declaration with export macro: class RFTA_API SourceRange... Index: CPPParserTest.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/CPPParserTest.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CPPParserTest.cpp 3 May 2003 17:43:12 -0000 1.2 --- CPPParserTest.cpp 4 May 2003 06:56:47 -0000 1.3 *************** *** 120,122 **** --- 120,123 ---- } + } // namespace Refactoring Index: DeclarationDetailsParser.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/DeclarationDetailsParser.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** DeclarationDetailsParser.cpp 3 May 2003 21:52:15 -0000 1.7 --- DeclarationDetailsParser.cpp 4 May 2003 06:56:47 -0000 1.8 *************** *** 10,13 **** --- 10,14 ---- #include <rfta/parser/ParseContext.h> #include <rfta/parser/DeclarationListParser.h> + #include <xtl/CStringView.h> #include "EnumBodyParser.h" *************** *** 185,206 **** { 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, ! getCurrentIndex()-specifierStart ! ); ! specifierList->addChild(specifier); ! return; // FINISH HERE --- 186,192 ---- { if (!tryNextIs(':')) ! throwFailure( "A class name can not start with a single ':'. Expected a double colon => '::'." ); ! readElaboratedTypeName( specifierStart, specifierList ); return; // FINISH HERE *************** *** 209,240 **** // 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, ! getCurrentIndex()-specifierStart ! ); ! specifierList->addChild(specifier); ! ! if ( !tryNextIs(';') ) // this is not a forward declaration ! { ! // read the complete specifier: ! readClassOrEnumSpecifier( specifier, specifierIdent ); ! } ! ! // set real length after completed parsing ! specifier->setLength(getCurrentIndex()-specifierStart); ! return; } --- 195,213 ---- // 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;") ! Xtl::CStringView secondIdent; ! if ( tryReadNextIdentifier( secondIdent ) ) ! skipSpaces(); ! ! Xtl::CStringView thirdIdent; // in the case of export macro: class RFTA_API SourceRange {}; ! if ( tryReadNextIdentifier( thirdIdent ) ) { skipSpaces(); + secondIdent = thirdIdent; // @todo ignore export macro for now, will need to store it. } // check if no identifier or the identifier is not followed by a ':' (e.g. "class x {" ! if ( secondIdent.isEmpty() || !tryNextIs(':') ) { ! addAnonymousClassNodeAndReadBody( specifierStart, specifierList, specifierIdent ); return; } *************** *** 244,275 **** if ( !tryNextIs(':') ) { ! // yes it's - so parse the class specifier ! if (specifierIdent == "class" || specifierIdent == "struct" || specifierIdent == "union") ! { ! ! // add the specifier node ! ASTNodePtr specifier = ! createASTNode( ! ASTNodeTypes::classSpecifier, ! specifierList, ! specifierStart, ! getCurrentIndex()-specifierStart ! ); ! specifierList->addChild(specifier); ! ! // read the complete specifier: ! readClassOrEnumSpecifier( specifier, specifierIdent ); ! ! // set real length after completed parsing ! specifier->setLength(getCurrentIndex()-specifierStart); ! ! return; ! // FINISH HERE (the class specifier ends here !) ! } ! throwFailure( "unknown specifier type: " + specifierIdent ); } // 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(); --- 217,237 ---- if ( !tryNextIs(':') ) { ! addNamedClassNodeAndReadBody( specifierStart, specifierList, specifierIdent ); ! return; } // 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" + addNestedNameClassNodeAndReadBody( specifierStart, specifierList, specifierIdent, secondIdent.str() ); + } + + + void + DeclarationDetailsParser::addNestedNameClassNodeAndReadBody( int specifierStart, + const ASTNodePtr &specifierList, + const std::string &specifierIdent, + const std::string &baseName ) + { + std::string secondIdent = baseName; skipSpaces(); *************** *** 291,294 **** --- 253,321 ---- } + + void + DeclarationDetailsParser::readElaboratedTypeName( int specifierStart, + const ASTNodePtr &specifierList ) + { + skipSpaces(); + // read the full name: + std::string name("::"); + readNestedName(name); + + // add the specifier node + ASTNodePtr specifier = createASTNode( ASTNodeTypes::elaboratedTypeSpecifier, + specifierList, + specifierStart, + getCurrentIndex()-specifierStart ); + specifierList->addChild(specifier); + } + + + void + DeclarationDetailsParser::addAnonymousClassNodeAndReadBody( int specifierStart, + const ASTNodePtr &specifierList, + const std::string &specifierIdent ) + { + // add the specifier node + ASTNodePtr specifier = createASTNode( ASTNodeTypes::classSpecifier, + specifierList, + specifierStart, + getCurrentIndex()-specifierStart ); + specifierList->addChild(specifier); + + if ( !tryNextIs(';') ) // this is not a forward declaration + { + // read the complete specifier: + readClassOrEnumSpecifier( specifier, specifierIdent ); + } + + // set real length after completed parsing + specifier->setLength(getCurrentIndex()-specifierStart); + } + + + void + DeclarationDetailsParser::addNamedClassNodeAndReadBody( int specifierStart, + const ASTNodePtr &specifierList, + const std::string &specifierIdent ) + { + if ( !isClassTypeSpecifier( specifierIdent ) ) + throwFailure( "unknown specifier type: " + specifierIdent ); + + // add the specifier node + ASTNodePtr specifier = createASTNode( ASTNodeTypes::classSpecifier, + specifierList, + specifierStart, + getCurrentIndex()-specifierStart ); + specifierList->addChild(specifier); + + // read the complete specifier: + readClassOrEnumSpecifier( specifier, specifierIdent ); + + // set real length after completed parsing + specifier->setLength(getCurrentIndex()-specifierStart); + } + + bool DeclarationDetailsParser::tryParseUserDefinedType(std::string& typename_) *************** *** 409,413 **** std::string keyword ) { ! if ( keyword == "class" || keyword == "struct" || keyword == "union" ) { ASTNodePtr body = readClassSpecifierBodySkippingInheritance( specifier ); --- 436,440 ---- std::string keyword ) { ! if ( isClassTypeSpecifier( keyword ) ) { ASTNodePtr body = readClassSpecifierBodySkippingInheritance( specifier ); *************** *** 948,951 **** --- 975,979 ---- } + bool DeclarationDetailsParser::isOperatorIdentifier(std::string name) *************** *** 957,960 **** --- 985,995 ---- return name.substr(pos+1) == "operator"; + } + + + bool + DeclarationDetailsParser::isClassTypeSpecifier( const std::string &specifier ) + { + return specifier == "class" || specifier == "struct" || specifier == "union"; } Index: DeclarationDetailsParser.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/DeclarationDetailsParser.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** DeclarationDetailsParser.h 3 May 2003 17:41:38 -0000 1.3 --- DeclarationDetailsParser.h 4 May 2003 06:56:47 -0000 1.4 *************** *** 50,53 **** --- 50,70 ---- bool tryParseUserDefinedType(std::string& typename_); + void readElaboratedTypeName( int specifierStart, + const ASTNodePtr &specifierList ); + + void addAnonymousClassNodeAndReadBody( int specifierStart, + const ASTNodePtr &specifierList, + const std::string &specifierIdent ); + + void addNamedClassNodeAndReadBody( int specifierStart, + const ASTNodePtr &specifierList, + const std::string &specifierIdent ); + + void addNestedNameClassNodeAndReadBody( int specifierStart, + const ASTNodePtr &specifierList, + const std::string &specifierIdent, + const std::string &baseName ); + + void readNestedName(std::string& nestedname); void readClassOrEnumSpecifier( const ASTNodePtr& specifier, *************** *** 86,89 **** --- 103,107 ---- static bool isOperatorIdentifier(std::string name); + static bool isClassTypeSpecifier( const std::string &specifier ); private: Index: DeclarationParserTest.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/DeclarationParserTest.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** DeclarationParserTest.cpp 1 May 2003 19:04:31 -0000 1.7 --- DeclarationParserTest.cpp 4 May 2003 06:56:47 -0000 1.8 *************** *** 251,254 **** --- 251,270 ---- void + DeclarationParserTest::testClassForwardDeclarationWithDllExport() + { + const std::string source( " class RFTA_API X; " ); + int startIndex = 1; + int endIndex = source.length()-1; + SourceASTNodePtr sourceAST = RFTA_ASSERT_PARSER_PASS( DeclarationParser, + source, + source.length()-1 ); + RFTA_ASSERT_NODE_HAS( sourceAST->getChildAt(0), + ASTNodeTypes::unparsedDeclaration, + startIndex, + endIndex-startIndex ); + } + + + void DeclarationParserTest::testTemplateClass() { Index: DeclarationParserTest.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/DeclarationParserTest.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** DeclarationParserTest.h 1 May 2003 19:04:32 -0000 1.5 --- DeclarationParserTest.h 4 May 2003 06:56:47 -0000 1.6 *************** *** 29,32 **** --- 29,33 ---- CPPUNIT_TEST( testClassDeclaration ); CPPUNIT_TEST( testClassForwardDeclaration ); + CPPUNIT_TEST( testClassForwardDeclarationWithDllExport ); CPPUNIT_TEST( testTemplateClass ); CPPUNIT_TEST( testTemplateFuntion ); *************** *** 57,60 **** --- 58,62 ---- void testClassDeclaration(); void testClassForwardDeclaration(); + void testClassForwardDeclarationWithDllExport(); void testTemplateClass(); void testTemplateFuntion(); Index: UnparsedDeclarationMutatorTest.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/UnparsedDeclarationMutatorTest.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** UnparsedDeclarationMutatorTest.cpp 3 May 2003 20:40:06 -0000 1.11 --- UnparsedDeclarationMutatorTest.cpp 4 May 2003 06:56:47 -0000 1.12 *************** *** 271,274 **** --- 271,292 ---- void + UnparsedDeclarationMutatorTest::testClassForwardDeclarationWithDllExport() + { + Testing::KeyedString source; + source.addKeyed(SPECIFIER , "class RFTA_API SourceRange;" ); + + SourceASTNodePtr sourceNode = RFTA_ASSERT_DECLARATION_MUTATOR_PASS( source ); + ASTNodePtr node = sourceNode->getChildAt(0); + + // check AST: + RFTA_ASSERT_DECLARATION( source, sourceNode ); + + // check specifier types: + ASTNodePtr specifierList = node->getProperty( ASTNodeProperties::declarationSpecifiersProperty ); + RFTA_ASSERT_NODE_TYPE( specifierList->getChildAt(0), ASTNodeTypes::classSpecifier, "class-specifier" ); + } + + + void UnparsedDeclarationMutatorTest::testEnumDeclaration() { Index: UnparsedDeclarationMutatorTest.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/UnparsedDeclarationMutatorTest.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** UnparsedDeclarationMutatorTest.h 3 May 2003 18:06:37 -0000 1.7 --- UnparsedDeclarationMutatorTest.h 4 May 2003 06:56:48 -0000 1.8 *************** *** 24,27 **** --- 24,28 ---- CPPUNIT_TEST( testClassDeclarationWithInheritance ); CPPUNIT_TEST( testClassForwardDeclaration ); + CPPUNIT_TEST( testClassForwardDeclarationWithDllExport ); CPPUNIT_TEST( testEnumDeclaration ); CPPUNIT_TEST( testUnamedEnumDeclaration ); *************** *** 70,73 **** --- 71,75 ---- void testClassDeclarationWithInheritance(); void testClassForwardDeclaration(); + void testClassForwardDeclarationWithDllExport(); void testEnumDeclaration(); void testUnamedEnumDeclaration(); |
From: <bl...@us...> - 2003-05-04 06:56:13
|
Update of /cvsroot/cpptool/rfta/src/rftaparser In directory sc8-pr-cvs1:/tmp/cvs-serv359/src/rftaparser Modified Files: rftaparser.dsp Log Message: * fixed release configuration settings Index: rftaparser.dsp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/rftaparser.dsp,v retrieving revision 1.50 retrieving revision 1.51 diff -C2 -d -r1.50 -r1.51 *** rftaparser.dsp 3 May 2003 21:52:15 -0000 1.50 --- rftaparser.dsp 4 May 2003 06:56:09 -0000 1.51 *************** *** 810,817 **** --- 810,835 ---- SOURCE=.\EnumBodyParserTest.cpp + + !IF "$(CFG)" == "rftaparser - Win32 Release" + + # PROP Exclude_From_Build 1 + + !ELSEIF "$(CFG)" == "rftaparser - Win32 Debug" + + !ENDIF + # End Source File # Begin Source File SOURCE=.\EnumBodyParserTest.h + + !IF "$(CFG)" == "rftaparser - Win32 Release" + + # PROP Exclude_From_Build 1 + + !ELSEIF "$(CFG)" == "rftaparser - Win32 Debug" + + !ENDIF + # End Source File # Begin Source File *************** *** 896,903 **** --- 914,939 ---- SOURCE=.\MacroDeclarationParserTest.cpp + + !IF "$(CFG)" == "rftaparser - Win32 Release" + + # PROP Exclude_From_Build 1 + + !ELSEIF "$(CFG)" == "rftaparser - Win32 Debug" + + !ENDIF + # End Source File # Begin Source File SOURCE=.\MacroDeclarationParserTest.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-05-04 06:55:50
|
Update of /cvsroot/cpptool/rfta/src/rfta In directory sc8-pr-cvs1:/tmp/cvs-serv32565/src/rfta Modified Files: ParserTools.cpp Log Message: * fixed bug in tryReadIdentifier Index: ParserTools.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/ParserTools.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ParserTools.cpp 3 May 2003 17:39:18 -0000 1.6 --- ParserTools.cpp 4 May 2003 06:55:47 -0000 1.7 *************** *** 77,81 **** Xtl::CStringEnumerator identifierStart = enumerator; - identifier = enumerator.getString(); if ( isValidIdentifierFirstLetter( *enumerator ) ) { --- 77,80 ---- *************** *** 85,89 **** } ! identifier.setEnd(enumerator.getCurrentPos()); return identifier.getLength() != 0; --- 84,88 ---- } ! identifier = Xtl::CStringView( identifierStart, enumerator ); return identifier.getLength() != 0; |
From: <bl...@us...> - 2003-05-04 06:55:28
|
Update of /cvsroot/cpptool/rfta/src/rftaparser In directory sc8-pr-cvs1:/tmp/cvs-serv32351/src/rftaparser Modified Files: Parser.cpp Log Message: * added tryReadNextIdentifier for a CStringView Index: Parser.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/Parser.cpp,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Parser.cpp 1 May 2003 21:07:29 -0000 1.10 --- Parser.cpp 4 May 2003 06:55:25 -0000 1.11 *************** *** 53,66 **** Parser::throwFailure( const std::string &message ) { ! std::string currentContext; ! if ( current_ < end_ && current_ >= start_ ) ! { ! int length = end_ - current_; ! currentContext.assign( current_, length > 60 ? 60 : length ); ! } ! ! const std::string extendedMessage = message + "\nCurrent Context: " + currentContext; ! ! throw ParserError( extendedMessage, context_ ); } --- 53,59 ---- Parser::throwFailure( const std::string &message ) { ! Xtl::CStringEnumerator enumerator( start_, end_ ); ! enumerator.setCurrent( current_ ); ! throwFailure( ParserTools::ParseError( message, enumerator ) ); } *************** *** 198,218 **** bool ! Parser::tryReadNextIdentifier( std::string &identifier ) { ! if ( !hasNext() ) ! return false; ! const char *identifierStart = current_; ! if ( isValidIdentifierFirstLetter( *current_ ) ) ! { ! ++current_; ! while ( hasNext() && isIdentifierLetter( *current_ ) ) ! ++current_; ! } ! int identifierLength = current_ - identifierStart; ! identifier.assign( identifierStart, identifierLength ); ! return identifierLength != 0; } --- 191,213 ---- bool ! Parser::tryReadNextIdentifier( Xtl::CStringView &identifier ) { ! Xtl::CStringEnumerator current( Xtl::CStringView( start_, end_ ) ); ! current.setCurrent( current_ ); ! bool identifierFound = ParserTools::tryReadIdentifier( current, identifier ); ! current_ = current; ! return identifierFound; ! } ! ! bool ! Parser::tryReadNextIdentifier( std::string &identifier ) ! { ! Xtl::CStringView identifierString; ! bool identifierFound = tryReadNextIdentifier( identifierString ); ! identifier = identifierString.str(); ! return identifierFound; } |
From: <bl...@us...> - 2003-05-04 06:55:28
|
Update of /cvsroot/cpptool/rfta/include/rfta/parser In directory sc8-pr-cvs1:/tmp/cvs-serv32351/include/rfta/parser Modified Files: Parser.h Log Message: * added tryReadNextIdentifier for a CStringView Index: Parser.h =================================================================== RCS file: /cvsroot/cpptool/rfta/include/rfta/parser/Parser.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Parser.h 3 May 2003 22:23:19 -0000 1.9 --- Parser.h 4 May 2003 06:55:25 -0000 1.10 *************** *** 96,99 **** --- 96,100 ---- bool tryReadNextIdentifier( std::string &identifier ); + bool tryReadNextIdentifier( Xtl::CStringView &identifier ); bool tryExpectNextKeyword( const char *expectedKeyword ); |
From: <bl...@us...> - 2003-05-04 06:54:38
|
Update of /cvsroot/cpptool/rfta/bin In directory sc8-pr-cvs1:/tmp/cvs-serv31878/bin Modified Files: lister.py Log Message: * fixed url link bug (replace \ with /) Index: lister.py =================================================================== RCS file: /cvsroot/cpptool/rfta/bin/lister.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** lister.py 1 May 2003 09:08:08 -0000 1.3 --- lister.py 4 May 2003 06:54:33 -0000 1.4 *************** *** 111,115 **** def __init__( self, url, content ): Tag.__init__( self, 'A', content ) ! self.setAttribute( 'HREF', url ) class LocalLinkTag(Tag): --- 111,115 ---- def __init__( self, url, content ): Tag.__init__( self, 'A', content ) ! self.setAttribute( 'HREF', url.replace( '\\', '/' ) ) class LocalLinkTag(Tag): |
From: <bl...@us...> - 2003-05-03 22:23:23
|
Update of /cvsroot/cpptool/rfta/src/rftaparser In directory sc8-pr-cvs1:/tmp/cvs-serv29751/src/rftaparser Modified Files: MacroDeclarationParser.cpp MacroDeclarationParserTest.cpp MacroDeclarationParserTest.h Log Message: * better macro detection (must be suffixed by (...)) Index: MacroDeclarationParser.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/MacroDeclarationParser.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MacroDeclarationParser.cpp 3 May 2003 21:52:15 -0000 1.1 --- MacroDeclarationParser.cpp 3 May 2003 22:23:19 -0000 1.2 *************** *** 46,50 **** Xtl::CStringView parameters( current ); if ( *current != '(' ) ! throw ParserTools::ParseError( "expected '(' after macro name not found.", current ); ParserTools::findNextBalanced( ++current, '(', ')' ); --- 46,50 ---- Xtl::CStringView parameters( current ); if ( *current != '(' ) ! return false; ParserTools::findNextBalanced( ++current, '(', ')' ); Index: MacroDeclarationParserTest.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/MacroDeclarationParserTest.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MacroDeclarationParserTest.cpp 3 May 2003 21:52:15 -0000 1.1 --- MacroDeclarationParserTest.cpp 3 May 2003 22:23:19 -0000 1.2 *************** *** 99,101 **** --- 99,125 ---- + void + MacroDeclarationParserTest::testFailIfNotUpperCase() + { + addMacroDeclaration( "someMethod", "", "()", "" ); + RFTA_ASSERT_PARSER_FAIL( MacroDeclarationParser, source_ ); + } + + + void + MacroDeclarationParserTest::testFailIfUpperButNoUnderScore() + { + addMacroDeclaration( "TYPE", "", "()", "" ); + RFTA_ASSERT_PARSER_FAIL( MacroDeclarationParser, source_ ); + } + + + void + MacroDeclarationParserTest::testFailIfNoBrace() + { + addMacroDeclaration( "EXPORT_STUFF", "", "", "" ); + RFTA_ASSERT_PARSER_FAIL( MacroDeclarationParser, source_ ); + } + + } // namespace Refactoring Index: MacroDeclarationParserTest.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/MacroDeclarationParserTest.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MacroDeclarationParserTest.h 3 May 2003 21:52:15 -0000 1.1 --- MacroDeclarationParserTest.h 3 May 2003 22:23:19 -0000 1.2 *************** *** 20,23 **** --- 20,26 ---- CPPUNIT_TEST( testMacroDeclarationWithParameters ); CPPUNIT_TEST( testMacroDeclarationWithTrailingSemiColon ); + CPPUNIT_TEST( testFailIfNotUpperCase ); + CPPUNIT_TEST( testFailIfUpperButNoUnderScore ); + CPPUNIT_TEST( testFailIfNoBrace ); CPPUNIT_TEST_SUITE_END(); *************** *** 36,39 **** --- 39,45 ---- void testMacroDeclarationWithParameters(); void testMacroDeclarationWithTrailingSemiColon(); + void testFailIfNotUpperCase(); + void testFailIfUpperButNoUnderScore(); + void testFailIfNoBrace(); private: |
From: <bl...@us...> - 2003-05-03 22:23:22
|
Update of /cvsroot/cpptool/rfta/include/rfta/parser In directory sc8-pr-cvs1:/tmp/cvs-serv29751/include/rfta/parser Modified Files: Parser.h Log Message: * better macro detection (must be suffixed by (...)) Index: Parser.h =================================================================== RCS file: /cvsroot/cpptool/rfta/include/rfta/parser/Parser.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Parser.h 1 May 2003 20:50:44 -0000 1.8 --- Parser.h 3 May 2003 22:23:19 -0000 1.9 *************** *** 124,129 **** void subParse( ParserType &subParser ) { ! subParser.parse(); ! current_ = subParser.getCurrent(); } --- 124,136 ---- void subParse( ParserType &subParser ) { ! try ! { ! subParser.parse(); ! current_ = subParser.getCurrent(); ! } ! catch ( ParserTools::ParseError &error ) ! { ! throwFailure( error ); ! } } *************** *** 131,141 **** bool trySubParse( ParserType &subParser ) { ! if ( subParser.tryParse() ) { ! current_ = subParser.getCurrent(); ! return true; ! } ! return false; } --- 138,155 ---- bool trySubParse( ParserType &subParser ) { ! try { ! if ( subParser.tryParse() ) ! { ! current_ = subParser.getCurrent(); ! return true; ! } ! return false; ! } ! catch ( ParserTools::ParseError &error ) ! { ! throwFailure( error ); ! } } |
From: <bl...@us...> - 2003-05-03 22:22:44
|
Update of /cvsroot/cpptool/rfta/bug In directory sc8-pr-cvs1:/tmp/cvs-serv29580/bug Modified Files: List.txt Log Message: * added support for MFC & wxWindow macro style in declaration list. Any identifier in upper case, with at least one '_' starting a declaration will start a macro declaration. Index: List.txt =================================================================== RCS file: /cvsroot/cpptool/rfta/bug/List.txt,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** List.txt 3 May 2003 21:54:10 -0000 1.5 --- List.txt 3 May 2003 22:22:39 -0000 1.6 *************** *** 23,33 **** => header include members initializer. - - --- - MFC macros (dc++\hubframe.h.html) - BEGIN_MSG_MAP(HubFrame) - MESSAGE_HANDLER(WM_CLOSE, onClose) - MESSAGE_HANDLER(WM_MDIACTIVATE, onActivate) - MESSAGE_HANDLER(WM_NCACTIVATE, onActivate) --- bad variable declaration (emule\archiverecovery.cpp.html) --- 23,26 ---- *************** *** 46,49 **** --- 39,46 ---- => parse failure, expected '{' --- + fail to handle wrapping 'export' keyword correctly (wxwindows/combobox.h.html): + WXDLLEXPORT_DATA(extern const wxChar*) wxEmptyString; + => this is interpreter as a macro declaration declaration & something ? + |
From: <bl...@us...> - 2003-05-03 21:54:14
|
Update of /cvsroot/cpptool/rfta/bug In directory sc8-pr-cvs1:/tmp/cvs-serv19545/bug Modified Files: List.txt Log Message: * added bug: ' class EXPORT_MACRO ClassName' Index: List.txt =================================================================== RCS file: /cvsroot/cpptool/rfta/bug/List.txt,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** List.txt 3 May 2003 17:47:47 -0000 1.4 --- List.txt 3 May 2003 21:54:10 -0000 1.5 *************** *** 41,44 **** --- 41,49 ---- * '->' should not be allowed as an end of template * should not attempt to parse for a variable declaration in for condition expression. + --- + failed to parse for 'dll export' macros: (wxwindows/accel.h.htm) + class WXDLLEXPORT wxKeyEvent + => parse failure, expected '{' + --- |
From: <bl...@us...> - 2003-05-03 21:52:20
|
Update of /cvsroot/cpptool/rfta/src/rftaparser In directory sc8-pr-cvs1:/tmp/cvs-serv18791/src/rftaparser Modified Files: ASTNodes.cpp DeclarationDetailsParser.cpp DeclarationListParser.cpp DeclarationListParserTest.cpp DeclarationListParserTest.h rftaparser.dsp Added Files: MacroDeclarationParser.cpp MacroDeclarationParser.h MacroDeclarationParserTest.cpp MacroDeclarationParserTest.h Log Message: * added support for MFC & wxWindow macro style in declaration list. Any identifier in upper case, with at least one '_' starting a declaration will start a macro declaration. * a macro declaration eat the patter IDENTIFIER( parameters ) * notes that it does not the bug were macro is use to export a symbol. --- NEW FILE: MacroDeclarationParser.cpp --- // ////////////////////////////////////////////////////////////////////////// // (c)Copyright 2002, Baptiste Lepilleur. // Created: 2003/05/03 // ////////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "MacroDeclarationParser.h" #include <rfta/parser/ASTNodes.h> #include <rfta/parser/ParseContext.h> #include <algorithm> namespace Refactoring { MacroDeclarationParser::MacroDeclarationParser( ParseContext &context, const char *start, const char *end ) : Parser( context, start, end ) { } MacroDeclarationParser::~MacroDeclarationParser() { } bool MacroDeclarationParser::tryParse() { Tracker tracker( "MacroDeclarationParser::tryParse", *this ); Xtl::CStringEnumerator current( current_, end_ ); ParserTools::skipSpaces( current ); Xtl::CStringView macroName; if ( !tryReadNextMacroIdentifier( current, macroName ) ) return false; if ( !isMacroName( macroName ) ) return false; ParserTools::skipSpaces( current ); Xtl::CStringView parameters( current ); if ( *current != '(' ) throw ParserTools::ParseError( "expected '(' after macro name not found.", current ); ParserTools::findNextBalanced( ++current, '(', ')' ); parameters.setEnd( ++current ); if ( *current == ';' ) ++current; Xtl::CStringView macroDeclaration( macroName.getStart(), current ); addMacroNodes( macroDeclaration, macroName, parameters ); current_ = current; return true; } bool MacroDeclarationParser::tryReadNextMacroIdentifier( Xtl::CStringEnumerator ¤t, Xtl::CStringView &identifier ) { if ( !current.hasNext() ) return false; Xtl::CStringEnumerator identifierStart = current; identifier = current; if ( isValidIdentifierFirstLetter( *current ) ) { ++current;; while ( current.hasNext() && isIdentifierLetter( *current ) ) current++; } identifier.setEnd( current ); return identifier.getLength() != 0; } bool MacroDeclarationParser::isValidMacroFirstLetter( char letter ) { return (letter >= 'A' && letter <= 'Z' ) || letter == '_'; } bool MacroDeclarationParser::isValidMacroLetter( char letter ) { return (letter >= 'A' && letter <= 'Z' ) || (letter >= '0' && letter <= '9' ) || letter == '_'; } bool MacroDeclarationParser::isMacroName( const Xtl::CStringView ¯oName ) { return std::find( macroName.getStart(), macroName.getEnd(), '_' ) != macroName.getEnd(); } void MacroDeclarationParser::addMacroNodes( const Xtl::CStringView ¯o, const Xtl::CStringView ¯oName, const Xtl::CStringView ¶meters ) { ASTNodePtr macroNode = createASTNode( ASTNodeTypes::macro, getParentNode(), macro ); ASTNodePtr nameNode = createASTNode( ASTNodeTypes::macroIdentifier, macroNode, macroName ); ASTNodePtr parametersNode = createASTNode( ASTNodeTypes::macroParameters, macroNode, parameters ); macroNode->setPropertyNode( ASTNodeProperties::macroIdentifier, nameNode ); macroNode->setPropertyNode( ASTNodeProperties::macroParameters, parametersNode ); context_.addNode( macroNode ); } } // namespace Refactoring --- NEW FILE: MacroDeclarationParser.h --- // ////////////////////////////////////////////////////////////////////////// // (c)Copyright 2002, Baptiste Lepilleur. // Created: 2003/05/03 // ////////////////////////////////////////////////////////////////////////// #ifndef RFTA_MACRODECLARATIONPARSER_H #define RFTA_MACRODECLARATIONPARSER_H #include <rfta/parser/Parser.h> #include <rfta/parser/ParserTools.h> namespace Refactoring { /// This class represents class RFTAPARSER_API MacroDeclarationParser : public Parser { public: /*! Constructs a MacroDeclarationParser object. */ MacroDeclarationParser( ParseContext &context, const char *start, const char *end ); /// Destructor. virtual ~MacroDeclarationParser(); bool tryParse(); private: bool tryReadNextMacroIdentifier( Xtl::CStringEnumerator ¤t, Xtl::CStringView &identifier ); bool isMacroName( const Xtl::CStringView ¯oName ); void addMacroNodes( const Xtl::CStringView ¯o, const Xtl::CStringView ¯oName, const Xtl::CStringView ¶meters ); static bool isValidMacroFirstLetter( char letter ); static bool isValidMacroLetter( char letter ); }; // Inlines methods for MacroDeclarationParser: // ------------------------------------------- } // namespace Refactoring #endif // RFTA_MACRODECLARATIONPARSER_H --- NEW FILE: MacroDeclarationParserTest.cpp --- // ////////////////////////////////////////////////////////////////////////// // (c)Copyright 2002, Baptiste Lepilleur. // Created: 2003/05/03 // ////////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "MacroDeclarationParser.h" #include "MacroDeclarationParserTest.h" #include <rfta/parser/ASTNodes.h> namespace Refactoring { CPPUNIT_TEST_SUITE_REGISTRATION( MacroDeclarationParserTest ); MacroDeclarationParserTest::MacroDeclarationParserTest() { } MacroDeclarationParserTest::~MacroDeclarationParserTest() { } void MacroDeclarationParserTest::setUp() { SourceBuilderTestBase::setUp(); } void MacroDeclarationParserTest::tearDown() { SourceBuilderTestBase::tearDown(); } void MacroDeclarationParserTest::addMacroDeclaration( const std::string &name, const std::string &spacer1, const std::string ¶meters, const std::string &spacer2 ) { builder_->mark( "MACRO" ); builder_->addKeyed( name, "NAME" ); builder_->add( spacer1 ); builder_->addKeyed( parameters, "PARAMETERS" ); builder_->add( spacer2 ); builder_->extend( "MACRO" ); } void MacroDeclarationParserTest::checkParseMacroDeclaration() { SourceASTNodePtr sourceNode = RFTA_ASSERT_PARSER_PASS( MacroDeclarationParser, source_, source_.length() ); ASTNodePtr macroNode = sourceNode->getChildAt(0); RFTA_ASSERT_NODE_HAS( macroNode, ASTNodeTypes::macro, builder_->getRange("MACRO"), "macro node" ); RFTA_ASSERT_NODE_PROPERTY_HAS( macroNode, ASTNodeProperties::macroIdentifier, ASTNodeTypes::macroIdentifier, builder_->getRange("NAME"), "macro identifier node"); RFTA_ASSERT_NODE_PROPERTY_HAS( macroNode, ASTNodeProperties::macroParameters, ASTNodeTypes::macroParameters, builder_->getRange("PARAMETERS"), "macro parameters node"); } void MacroDeclarationParserTest::testEmptyMacroDeclaration() { addMacroDeclaration( "IMPLEMENT_DYNAMIC", "", "()", "" ); checkParseMacroDeclaration(); } void MacroDeclarationParserTest::testMacroDeclarationWithParameters() { addMacroDeclaration( "IMPLEMENT_DYNAMIC", "", "( SomeClass, someMethod )", "" ); checkParseMacroDeclaration(); } void MacroDeclarationParserTest::testMacroDeclarationWithTrailingSemiColon() { addMacroDeclaration( "IMPLEMENT_DYNAMIC", "", "()", ";" ); checkParseMacroDeclaration(); } } // namespace Refactoring --- NEW FILE: MacroDeclarationParserTest.h --- // ////////////////////////////////////////////////////////////////////////// // (c)Copyright 2002, Baptiste Lepilleur. // Created: 2003/05/03 // ////////////////////////////////////////////////////////////////////////// #ifndef RFTA_MACRODECLARATIONPARSERTEST_H #define RFTA_MACRODECLARATIONPARSERTEST_H #include "SourceBuilderTestBase.h" namespace Refactoring { /// Unit tests for MacroDeclarationParserTest class MacroDeclarationParserTest : public SourceBuilderTestBase { CPPUNIT_TEST_SUITE( MacroDeclarationParserTest ); CPPUNIT_TEST( testEmptyMacroDeclaration ); CPPUNIT_TEST( testMacroDeclarationWithParameters ); CPPUNIT_TEST( testMacroDeclarationWithTrailingSemiColon ); CPPUNIT_TEST_SUITE_END(); public: /*! Constructs a MacroDeclarationParserTest object. */ MacroDeclarationParserTest(); /// Destructor. virtual ~MacroDeclarationParserTest(); void setUp(); void tearDown(); void testEmptyMacroDeclaration(); void testMacroDeclarationWithParameters(); void testMacroDeclarationWithTrailingSemiColon(); private: void addMacroDeclaration( const std::string &name, const std::string &spacer1, const std::string ¶meters, const std::string &spacer2 ); void checkParseMacroDeclaration(); }; // Inlines methods for MacroDeclarationParserTest: // ----------------------------------------------- } // namespace Refactoring #endif // RFTA_MACRODECLARATIONPARSERTEST_H Index: ASTNodes.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/ASTNodes.cpp,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** ASTNodes.cpp 3 May 2003 17:45:13 -0000 1.23 --- ASTNodes.cpp 3 May 2003 21:52:15 -0000 1.24 *************** *** 78,81 **** --- 78,84 ---- const ASTNodeType ASTNodeTypes::assignmentExpression( "assignment-expression-marker"); const ASTNodeType ASTNodeTypes::expressionList( "expression-list-marker" ); + const ASTNodeType ASTNodeTypes::macro( "macro" ); + const ASTNodeType ASTNodeTypes::macroIdentifier( "macro-identifier" ); + const ASTNodeType ASTNodeTypes::macroParameters( "macro-parameter" ); *************** *** 119,122 **** --- 122,127 ---- const ASTNodeProperty ASTNodeProperties::enumBodyProperty ( "enumeration-body-property" ); const ASTNodeProperty ASTNodeProperties::classBodyProperty( "class-body-property" ); + const ASTNodeProperty ASTNodeProperties::macroIdentifier( "macro-identifier-property" ); + const ASTNodeProperty ASTNodeProperties::macroParameters( "macro-parameters-property" ); } // namespace Refactoring Index: DeclarationDetailsParser.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/DeclarationDetailsParser.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** DeclarationDetailsParser.cpp 3 May 2003 18:06:37 -0000 1.6 --- DeclarationDetailsParser.cpp 3 May 2003 21:52:15 -0000 1.7 *************** *** 446,459 **** EnumBodyParser bodyParser( context_, current_, end_ ); subParse( bodyParser ); - /* - expect('{'); - - ASTNodePtr body = createASTNode( ASTNodeTypes::unparsedDeclarationList, - specifier, - getCurrentIndex(), - 0 ); - specifier->setPropertyNode( ASTNodeProperties::enumBodyProperty , body ); - return body; - */ } --- 446,449 ---- Index: DeclarationListParser.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/DeclarationListParser.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** DeclarationListParser.cpp 1 May 2003 21:08:58 -0000 1.6 --- DeclarationListParser.cpp 3 May 2003 21:52:15 -0000 1.7 *************** *** 6,16 **** #include "stdafx.h" #include <rfta/parser/ASTNodes.h> #include <rfta/parser/DeclarationParser.h> - #include <rfta/parser/DeclarationListParser.h> #include <rfta/parser/ParseContext.h> - #include <stdexcept> #include <rfta/parser/ParserTools.h> #include <set> --- 6,17 ---- #include "stdafx.h" + #include <rfta/parser/DeclarationListParser.h> #include <rfta/parser/ASTNodes.h> #include <rfta/parser/DeclarationParser.h> #include <rfta/parser/ParseContext.h> #include <rfta/parser/ParserTools.h> #include <set> + #include <stdexcept> + #include "MacroDeclarationParser.h" *************** *** 63,66 **** --- 64,71 ---- continue; } + + MacroDeclarationParser macroParser( context_, current_, end_ ); + if ( trySubParse( macroParser ) ) + continue; DeclarationParser parser(context_, current_ , end_ ); Index: DeclarationListParserTest.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/DeclarationListParserTest.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** DeclarationListParserTest.cpp 3 May 2003 17:43:12 -0000 1.4 --- DeclarationListParserTest.cpp 3 May 2003 21:52:15 -0000 1.5 *************** *** 90,92 **** --- 90,109 ---- + void + DeclarationListParserTest::testMacros() + { + const std::string source( + "BEGIN_MSG_MAP(HubFrame) " + " MESSAGE_HANDLER(WM_CLOSE, onClose) " + "END_MSG_MAP()" ); + SourceASTNodePtr sourceNode = RFTA_ASSERT_PARSER_PASS( DeclarationListParser, + source, + source.length() ); + RFTA_ASSERT_EQUAL( 3, sourceNode->getChildCount() ); + RFTA_ASSERT_NODE_TYPE( sourceNode->getChildAt(0), ASTNodeTypes::macro ); + RFTA_ASSERT_NODE_TYPE( sourceNode->getChildAt(1), ASTNodeTypes::macro ); + RFTA_ASSERT_NODE_TYPE( sourceNode->getChildAt(2), ASTNodeTypes::macro ); + } + + } // namespace Refactoring Index: DeclarationListParserTest.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/DeclarationListParserTest.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** DeclarationListParserTest.h 3 May 2003 17:43:12 -0000 1.2 --- DeclarationListParserTest.h 3 May 2003 21:52:15 -0000 1.3 *************** *** 20,23 **** --- 20,24 ---- CPPUNIT_TEST( testTemplateFuntionFollowedByDecl ); CPPUNIT_TEST( testUnamedEnumDeclaration ); + CPPUNIT_TEST( testMacros ); CPPUNIT_TEST_SUITE_END(); *************** *** 35,38 **** --- 36,40 ---- void testTemplateFuntionFollowedByDecl(); void testUnamedEnumDeclaration(); + void testMacros(); private: Index: rftaparser.dsp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/rftaparser.dsp,v retrieving revision 1.49 retrieving revision 1.50 diff -C2 -d -r1.49 -r1.50 *** rftaparser.dsp 3 May 2003 17:38:45 -0000 1.49 --- rftaparser.dsp 3 May 2003 21:52:15 -0000 1.50 *************** *** 250,253 **** --- 250,261 ---- # Begin Source File + SOURCE=.\EnumBodyParser.cpp + # End Source File + # Begin Source File + + SOURCE=.\EnumBodyParser.h + # End Source File + # Begin Source File + SOURCE=.\FlowControlStatementParser.cpp # End Source File *************** *** 298,301 **** --- 306,317 ---- # Begin Source File + SOURCE=.\MacroDeclarationParser.cpp + # End Source File + # Begin Source File + + SOURCE=.\MacroDeclarationParser.h + # End Source File + # Begin Source File + SOURCE=.\NamespaceParser.cpp # End Source File *************** *** 879,882 **** --- 895,906 ---- # Begin Source File + SOURCE=.\MacroDeclarationParserTest.cpp + # End Source File + # Begin Source File + + SOURCE=.\MacroDeclarationParserTest.h + # End Source File + # Begin Source File + SOURCE=.\NonSemanticBlankerTest.cpp *************** *** 1226,1258 **** SOURCE=.\KeyedString.h - - !IF "$(CFG)" == "rftaparser - Win32 Release" - - !ELSEIF "$(CFG)" == "rftaparser - Win32 Debug" - - !ENDIF - # End Source File # Begin Source File SOURCE=..\rftatest\SourceBuilder.cpp - - !IF "$(CFG)" == "rftaparser - Win32 Release" - - !ELSEIF "$(CFG)" == "rftaparser - Win32 Debug" - - !ENDIF - # End Source File # Begin Source File SOURCE=..\..\include\rfta\test\SourceBuilder.h - - !IF "$(CFG)" == "rftaparser - Win32 Release" - - !ELSEIF "$(CFG)" == "rftaparser - Win32 Debug" - - !ENDIF - # End Source File # Begin Source File --- 1250,1261 ---- *************** *** 1511,1539 **** # Begin Source File ! SOURCE=.\EnumBodyParser.cpp # End Source File # Begin Source File ! SOURCE=.\EnumBodyParser.h # End Source File # Begin Source File ! SOURCE=.\Makefile.am # End Source File # Begin Source File ! SOURCE=.\NonSemanticBlanker.cpp # End Source File # Begin Source File ! SOURCE=..\..\include\rfta\parser\NonSemanticBlanker.h # End Source File # Begin Source File ! SOURCE=..\rfta\ParserTools.cpp # End Source File # Begin Source File ! SOURCE=..\..\include\rfta\parser\ParserTools.h # End Source File # End Target --- 1514,1542 ---- # Begin Source File ! SOURCE=.\Makefile.am # End Source File # Begin Source File ! SOURCE=.\NonSemanticBlanker.cpp # End Source File # Begin Source File ! SOURCE=..\..\include\rfta\parser\NonSemanticBlanker.h # End Source File # Begin Source File ! SOURCE=..\rfta\ParserTools.cpp # End Source File # Begin Source File ! SOURCE=..\..\include\rfta\parser\ParserTools.h # End Source File # Begin Source File ! SOURCE=.\SourceBuilderTestBase.cpp # End Source File # Begin Source File ! SOURCE=.\SourceBuilderTestBase.h # End Source File # End Target |
From: <bl...@us...> - 2003-05-03 21:52:20
|
Update of /cvsroot/cpptool/rfta/doc In directory sc8-pr-cvs1:/tmp/cvs-serv18791/doc Modified Files: AbstractSyntaxSTreeStructure.txt Log Message: * added support for MFC & wxWindow macro style in declaration list. Any identifier in upper case, with at least one '_' starting a declaration will start a macro declaration. * a macro declaration eat the patter IDENTIFIER( parameters ) * notes that it does not the bug were macro is use to export a symbol. Index: AbstractSyntaxSTreeStructure.txt =================================================================== RCS file: /cvsroot/cpptool/rfta/doc/AbstractSyntaxSTreeStructure.txt,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** AbstractSyntaxSTreeStructure.txt 3 May 2003 17:45:38 -0000 1.9 --- AbstractSyntaxSTreeStructure.txt 3 May 2003 21:52:14 -0000 1.10 *************** *** 58,61 **** --- 58,65 ---- * Declaration-Level-Elements + {single-declaration} + [macro] + [declaration] + // each declaration consists of a list of specifier and a list of declarators (with optional init) [declaration] *************** *** 104,107 **** --- 108,115 ---- ?ptr-declarator-property => [#unparsed] ?nested-name-property => [#declarator-identifier] + + [macro] + macro-identifier-property => [#macro-identifier] + macro-parameters-property => [#macro-parameters] // for now, will probably need to be detailed. * Statements a function/method body level |
From: <bl...@us...> - 2003-05-03 21:52:20
|
Update of /cvsroot/cpptool/rfta/include/rfta/parser In directory sc8-pr-cvs1:/tmp/cvs-serv18791/include/rfta/parser Modified Files: ASTNodes.h Log Message: * added support for MFC & wxWindow macro style in declaration list. Any identifier in upper case, with at least one '_' starting a declaration will start a macro declaration. * a macro declaration eat the patter IDENTIFIER( parameters ) * notes that it does not the bug were macro is use to export a symbol. Index: ASTNodes.h =================================================================== RCS file: /cvsroot/cpptool/rfta/include/rfta/parser/ASTNodes.h,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** ASTNodes.h 3 May 2003 17:45:13 -0000 1.20 --- ASTNodes.h 3 May 2003 21:52:15 -0000 1.21 *************** *** 163,166 **** --- 163,172 ---- static const ASTNodeType expressionList; + // macro node types. + static const ASTNodeType macro; + static const ASTNodeType macroIdentifier; + static const ASTNodeType macroParameters; + + }; *************** *** 236,239 **** --- 242,248 ---- static const ASTNodeProperty enumBodyProperty; static const ASTNodeProperty classBodyProperty; + + static const ASTNodeProperty macroIdentifier; + static const ASTNodeProperty macroParameters; }; |
From: <bl...@us...> - 2003-05-03 21:49:26
|
Update of /cvsroot/cpptool/rfta/src/rftaparser In directory sc8-pr-cvs1:/tmp/cvs-serv17777/src/rftaparser Added Files: SourceBuilderTestBase.cpp SourceBuilderTestBase.h Log Message: * based class for test that use SourceBuilder --- NEW FILE: SourceBuilderTestBase.cpp --- // ////////////////////////////////////////////////////////////////////////// // (c)Copyright 2002, Baptiste Lepilleur. // Created: 2003/05/03 // ////////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "SourceBuilderTestBase.h" namespace Refactoring { SourceBuilderTestBase::SourceBuilderTestBase() { } SourceBuilderTestBase::~SourceBuilderTestBase() { } void SourceBuilderTestBase::setUp() { source_ = ""; builder_.reset( new Testing::SourceBuilder( source_ ) ); } void SourceBuilderTestBase::tearDown() { builder_.reset(); source_ = ""; } } // namespace Refactoring --- NEW FILE: SourceBuilderTestBase.h --- // ////////////////////////////////////////////////////////////////////////// // (c)Copyright 2002, Baptiste Lepilleur. // Created: 2003/05/03 // ////////////////////////////////////////////////////////////////////////// #ifndef RFTA_SOURCEBUILDERTESTBASE_H #define RFTA_SOURCEBUILDERTESTBASE_H #include "ParserTesting.h" #include <rfta/test/SourceBuilder.h> #include <boost/shared_ptr.hpp> namespace Refactoring { /// Unit tests for SourceBuilderTestBase class SourceBuilderTestBase : public CppUnit::TestFixture { public: /*! Constructs a SourceBuilderTestBase object. */ SourceBuilderTestBase(); /// Destructor. virtual ~SourceBuilderTestBase(); void setUp(); void tearDown(); protected: std::string source_; boost::shared_ptr<Testing::SourceBuilder> builder_; }; // Inlines methods for SourceBuilderTestBase: // ------------------------------------------ } // namespace Refactoring #endif // RFTA_SOURCEBUILDERTESTBASE_H |