|
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();
|