Update of /cvsroot/cpptool/rfta/src/rftaparser
In directory sc8-pr-cvs1:/tmp/cvs-serv12201/src/rftaparser
Added Files:
DeclarationListParser.cpp DeclarationListParser.h
DeclarationListParserTest.cpp DeclarationListParserTest.h
DeclarationParser.cpp DeclarationParser.h
DeclarationParserTest.cpp DeclarationParserTest.h
LinkageParser.cpp LinkageParser.h NamespaceParser.cpp
NamespaceParser.h TemplateDeclarationParser.cpp
TemplateDeclarationParser.h UsingNamespaceParser.cpp
UsingNamespaceParser.h
Log Message:
-- additional files for file level parsing
--- NEW FILE: DeclarationListParser.cpp ---
// //////////////////////////////////////////////////////////////////////////
// Implementation file DeclarationListParser.cpp for class DeclarationListParser
// (c)Copyright 2003, Andre Baresel.
// Created: 2003/04/10
// //////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include <rfta/parser/ASTNodes.h>
#include "DeclarationParser.h"
#include "DeclarationListParser.h"
#include <rfta/parser/ParseContext.h>
#include <stdexcept>
namespace Refactoring
{
DeclarationListParser::DeclarationListParser( ParseContext &context,
const char *start,
const char *end )
: Parser( context, start, end )
{
}
DeclarationListParser::~DeclarationListParser()
{
}
/**
* unlike compound statement we seperate the file into ast nodes
* as we understand the syntax now.
*/
bool
DeclarationListParser::tryParse()
{
Tracker tracker( "DeclarationListParser::tryParse", *this );
do {
skipSpaces();
if (!hasNext()) break;
DeclarationParser parser(context_, current_ , end_ );
if (!parser.tryParse()) break;
current_ = parser.getCurrent();
} while ( current_ < end_ );
return true;
}
} // namespace Refactoring
--- NEW FILE: DeclarationListParser.h ---
// //////////////////////////////////////////////////////////////////////////
// Header file DeclarationListParser.h for class DeclarationListParser
// (c)Copyright 2003, Andre Baresel.
// Created: 2003/04/10
// //////////////////////////////////////////////////////////////////////////
#ifndef RFTA_DeclarationListParser_H
#define RFTA_DeclarationListParser_H
#include <rfta/parser/Parser.h>
namespace Refactoring
{
/// declaration list parser: { ... }.
class RFTAPARSER_API DeclarationListParser : public Parser
{
public:
/*! Constructs a DeclarationListParser object.
*/
DeclarationListParser( ParseContext &context,
const char *start,
const char *end );
/// Destructor.
virtual ~DeclarationListParser();
bool tryParse();
};
// Inlines methods for DeclarationListParser:
// --------------------------------------------
} // namespace Refactoring
#endif // RFTA_DeclarationListParser_H
--- NEW FILE: DeclarationListParserTest.cpp ---
// //////////////////////////////////////////////////////////////////////////
// Implementation file DeclarationListParserTest.cpp for class DeclarationListParserTest
// (c)Copyright 2003, Andre Baresel.
// Created: 2003/04/10
// //////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "DeclarationListParserTest.h"
#include <rfta/parser/ASTNodes.h>
#include "DeclarationListParser.h"
namespace Refactoring
{
RFTAPARSER_TEST_SUITE_REGISTRATION( DeclarationListParserTest );
DeclarationListParserTest::DeclarationListParserTest()
: CppUnit::TestFixture()
{
}
DeclarationListParserTest::~DeclarationListParserTest()
{
}
void
DeclarationListParserTest::setUp()
{
}
void
DeclarationListParserTest::tearDown()
{
}
void
DeclarationListParserTest::testTemplateFuntionFollowedByDecl()
{
const std::string source(
" template<typename F1,typename F2>"
"bool checkEquals( const F1 &e, const F2 &a)"
"{"
"if ( e == a ) return true;"
"return false;"
"} int x;");
int startIndex = 2;
int endIndex = source.length()-7;
SourceASTNodePtr sourceAST = RFTA_ASSERT_PARSER_PASS( DeclarationListParser,
source,
source.length() );
RFTA_ASSERT_NODE_HAS( sourceAST->getChildAt(0),
ASTNodeTypes::unparsedTemplate,
startIndex,
endIndex-startIndex );
RFTA_ASSERT_NODE_HAS( sourceAST->getChildAt(1),
ASTNodeTypes::unparsedSourcePart,
endIndex+1,
6 );
}
} // namespace Refactoring
--- NEW FILE: DeclarationListParserTest.h ---
// //////////////////////////////////////////////////////////////////////////
// Header file DeclarationListParserTest.h for class DeclarationListParserTest
// (c)Copyright 2003, Andre Baresel.
// Created: 2003/04/10
// //////////////////////////////////////////////////////////////////////////
#ifndef RFTA_DeclarationListParserTest_H
#define RFTA_DeclarationListParserTest_H
#include "ParserTesting.h"
namespace Refactoring
{
/// Unit tests for CompoundStatementParserTest
class DeclarationListParserTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( DeclarationListParserTest );
CPPUNIT_TEST( testTemplateFuntionFollowedByDecl );
CPPUNIT_TEST_SUITE_END();
public:
/*! Constructs a DeclarationListParserTest object.
*/
DeclarationListParserTest();
/// Destructor.
virtual ~DeclarationListParserTest();
void setUp();
void tearDown();
void testTemplateFuntionFollowedByDecl();
private:
/// Prevents the use of the copy constructor.
DeclarationListParserTest( const DeclarationListParserTest &other );
/// Prevents the use of the copy operator.
void operator =( const DeclarationListParserTest &other );
private:
};
// Inlines methods for DeclarationListParserTest:
// ------------------------------------------------
} // namespace Refactoring
#endif // RFTA_DeclarationListParserTest_H
--- NEW FILE: DeclarationParser.cpp ---
// //////////////////////////////////////////////////////////////////////////
// Implementation file DeclarationParser.cpp for class DeclarationParser
// (c)Copyright 2003, Andre Baresel.
// Created: 2003/04/11
// //////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "DeclarationParser.h"
#include "NamespaceParser.h"
#include "UsingNamespaceParser.h"
#include "LinkageParser.h"
#include "TypeDeclarationStatementParser.h"
#include "TemplateDeclarationParser.h"
#include <rfta/parser/ASTNodes.h>
#include <rfta/parser/ParseContext.h>
namespace Refactoring
{
DeclarationParser::DeclarationParser( ParseContext &context,
const char *start,
const char *end )
: Parser( context, start, end )
{
}
DeclarationParser::~DeclarationParser()
{
}
bool
DeclarationParser::parseCommonDeclaration()
{
Tracker tracker( "DeclarationParser::parseCommonDeclaration", *this );
// this difference is used to reduce the length of the AST node to the relevant part
// of the declaration (skipping the leading white spaces)
int start_difference = current_ - start_;
ASTNodePtr declarationNode =
createASTNode( ASTNodeTypes::unparsedSourcePart,
getParentNode(),
getCurrentIndex(),
getCurrentLength() );
context_.addNode( declarationNode );
const char * rollback = current_;
readUntilNextOf(";={");
// check for the most simple case:
if (*current_==';')
{
expect(';');
// this is a very simple kind of declaration ending with a semicolon
declarationNode->setLength( getCurrentLength() - start_difference );
return true;
}
// check for initialized declarations
if (*current_=='=')
{
readUntilNextSemiColonSkippingOverCurlyBraces();
declarationNode->setLength( getCurrentLength() - start_difference );
return true;
}
if (*current_ != '{')
throwFailure( "Don't expect anything other than '{' here." );
// check for the function declaration:
const char * start_of_curl = current_;
backtrackSkippingSpaces();
current_--;
if (*current_=='y') // special case 'try-function-body'
{
if (hasPrevious() && current_[-1]=='r')
{
current_--;
if (hasPrevious() && current_[-1]=='t')
{
// TODO: Handle the case of a try-catch-function-body
throwFailure( "Handling of try-catch-function-body's not yet implemented.");
}
}
// restore position:
current_ = start_of_curl;
}
if (*current_==')') // check for parameter declaration of a function
{
current_ = start_of_curl+1;
// read until the end of the function body
findNextBalanced('{','}');
declarationNode->setLength( getCurrentLength() - start_difference );
return true;
}
// TODO: CHECK THIS AGAINST SYNTAX:
current_--;
readUntilNextSemiColonSkippingOverCurlyBraces();
declarationNode->setLength( getCurrentLength() - start_difference );
return true;
}
bool
DeclarationParser::tryParse()
{
Tracker tracker( "DeclarationParser::parse", *this );
skipSpaces();
if (!hasNext()) return false;
int startIndex = getCurrentIndex();
const char * start = current_;
// first try one of the high level identifier:
// "template", "typedef", "namespace", "extern"
std::string identifier;
if (tryReadNextIdentifier(identifier))
{
if ( "template" == identifier )
{
// call template declaration parser
TemplateDeclarationParser parser( context_, start , end_ );
parser.parse();
current_ = parser.getCurrent();
return true;
}
else if ( "typedef" == identifier )
{
// call typedef parser
TypeDeclarationStatementParser parser( context_, start , end_ );
parser.parse(current_);
current_ = parser.getCurrent();
return true;
}
else if ( "namespace" == identifier )
{
// call namespace parser
NamespaceParser parser( context_, start , end_ );
subParse( parser );
return true;
}
else if ( "using" == identifier )
{
// call using-namespace parser
// call namespace parser
UsingNamespaceParser parser( context_, start , end_ );
subParse( parser );
return true;
}
else if ( "extern" == identifier )
{
// check if it's a surrounding extern declaration:
// e.g. extern "C" { ... }
// if not, fall through to declaration parsing...
const char * save = current_;
skipSpaces();
if (tryNextIs('\"'))
{
// it's a linkage declaration
LinkageParser parser( context_, start , end_ );
subParse( parser );
return true;
}
// FALL-THROUGH:
// "extern" parser might fall through because of declarations starting
// with the 'extern' keyword... these will be taken by the DeclarationParser
}
}
// rollback to start
current_ = start;
/* its a start of a declaration */
return parseCommonDeclaration();
}
} // namespace Refactoring
--- NEW FILE: DeclarationParser.h ---
// //////////////////////////////////////////////////////////////////////////
// Header file DeclarationParser.h for class DeclarationParser
// (c)Copyright 2003, Andre Baresel.
// Created: 2003/04/10
// //////////////////////////////////////////////////////////////////////////
#ifndef RFTA_DeclarationParser_H
#define RFTA_DeclarationParser_H
#include <rfta/parser/Parser.h>
namespace Refactoring
{
/// namespace parser.
class DeclarationParser : public Parser
{
public:
/*! Constructs a DeclarationParser object.
*/
DeclarationParser( ParseContext &context,
const char *start,
const char *end );
/// Destructor.
virtual ~DeclarationParser();
bool tryParse();
private:
bool parseCommonDeclaration();
};
// Inlines methods for DeclarationParser:
// ---------------------------------------
} // namespace Refactoring
#endif // RFTA_DeclarationParser_H
--- NEW FILE: DeclarationParserTest.cpp ---
// //////////////////////////////////////////////////////////////////////////
// Implementation file DeclarationParserTest.cpp for class DeclarationParserTest
// (c)Copyright 2003, Andre Baresel.
// Created: 2003/04/10
// //////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "DeclarationParserTest.h"
#include <rfta/parser/ASTNodes.h>
#include "DeclarationParser.h"
namespace Refactoring
{
RFTAPARSER_TEST_SUITE_REGISTRATION( DeclarationParserTest );
DeclarationParserTest::DeclarationParserTest()
: CppUnit::TestFixture()
{
}
DeclarationParserTest::~DeclarationParserTest()
{
}
void
DeclarationParserTest::setUp()
{
}
void
DeclarationParserTest::tearDown()
{
}
void
DeclarationParserTest::testNamespaceParse()
{
const std::string source( " namespace x { } " );
int startIndex = 2;
int endIndex = source.length()-1;
SourceASTNodePtr sourceAST = RFTA_ASSERT_PARSER_PASS( DeclarationParser,
source,
source.length()-1 );
RFTA_ASSERT_NODE_HAS( sourceAST->getChildAt(0),
ASTNodeTypes::unparsedNamespace,
startIndex,
endIndex-startIndex );
}
void
DeclarationParserTest::testNamespaceAlias()
{
const std::string source( " namespace x = y; " );
int startIndex = 2;
int endIndex = 18;
SourceASTNodePtr sourceAST = RFTA_ASSERT_PARSER_PASS( DeclarationParser,
source,
source.length()-1 );
RFTA_ASSERT_NODE_HAS( sourceAST->getChildAt(0),
ASTNodeTypes::unparsedNamespace,
startIndex,
endIndex-startIndex );
}
void
DeclarationParserTest::testUsingNamespace()
{
const std::string source( " using namespace x; " );
int startIndex = 1;
int endIndex = 19;
SourceASTNodePtr sourceAST = RFTA_ASSERT_PARSER_PASS( DeclarationParser,
source,
source.length()-2 );
RFTA_ASSERT_NODE_HAS( sourceAST->getChildAt(0),
ASTNodeTypes::usingNamespace,
startIndex,
endIndex-startIndex );
}
void
DeclarationParserTest::testLongUsingNamespace()
{
const std::string source( " using namespace ::x::y; " );
int startIndex = 1;
int endIndex = 24;
SourceASTNodePtr sourceAST = RFTA_ASSERT_PARSER_PASS( DeclarationParser,
source,
source.length()-2 );
RFTA_ASSERT_NODE_HAS( sourceAST->getChildAt(0),
ASTNodeTypes::usingNamespace,
startIndex,
endIndex-startIndex );
}
void
DeclarationParserTest::testGlobalTypedef()
{
const std::string source( " typedef struct x { int a; } x__; " );
int startIndex = 1;
int endIndex = 33;
SourceASTNodePtr sourceAST = RFTA_ASSERT_PARSER_PASS( DeclarationParser,
source,
source.length()-2 );
RFTA_ASSERT_NODE_HAS( sourceAST->getChildAt(0),
ASTNodeTypes::typedefStatement,
startIndex,
endIndex-startIndex );
}
void
DeclarationParserTest::testSimpleLinkage()
{
const std::string source( " extern \"C++\" { int f(); } " );
int startIndex = 2;
int endIndex = 27;
SourceASTNodePtr sourceAST = RFTA_ASSERT_PARSER_PASS( DeclarationParser,
source,
source.length()-1 );
RFTA_ASSERT_NODE_HAS( sourceAST->getChildAt(0),
ASTNodeTypes::unparsedLinkage,
startIndex,
endIndex-startIndex );
}
void
DeclarationParserTest::testSingleLinkage()
{
const std::string source( " extern \"C++\" int f(); " );
int startIndex = 2;
int endIndex = source.length()-1;
SourceASTNodePtr sourceAST = RFTA_ASSERT_PARSER_PASS( DeclarationParser,
source,
source.length()-1 );
RFTA_ASSERT_NODE_HAS( sourceAST->getChildAt(0),
ASTNodeTypes::unparsedLinkage,
startIndex,
endIndex-startIndex );
}
void
DeclarationParserTest::testSimpleDeclaration()
{
const std::string source( " extern const int x[2] = { 10 , 2 }; " );
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::unparsedSourcePart,
startIndex,
endIndex-startIndex );
}
void
DeclarationParserTest::testFunctionbody()
{
const std::string source( " extern int f(int a, int b) { ... } " );
int startIndex = 1;
int endIndex = 35;
SourceASTNodePtr sourceAST = RFTA_ASSERT_PARSER_PASS( DeclarationParser,
source,
source.length()-1 );
RFTA_ASSERT_NODE_HAS( sourceAST->getChildAt(0),
ASTNodeTypes::unparsedSourcePart,
startIndex,
endIndex-startIndex );
}
void
DeclarationParserTest::testClassDeclaration()
{
const std::string source( " class x: public v, y { public: int fct(int x) { return -1; } }; " );
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::unparsedSourcePart,
startIndex,
endIndex-startIndex );
}
void
DeclarationParserTest::testTemplateClass()
{
const std::string source( " template x< T > class v { T 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::unparsedTemplate,
startIndex,
endIndex-startIndex );
}
void
DeclarationParserTest::testTemplateFuntion()
{
const std::string source(
" template<typename F1,typename F2>"
"bool checkEquals( const F1 &e, const F2 &a)"
"{"
"if ( e == a ) return true;"
"return false;"
"} ");
int startIndex = 2;
int endIndex = source.length()-1;
SourceASTNodePtr sourceAST = RFTA_ASSERT_PARSER_PASS( DeclarationParser,
source,
source.length()-1 );
RFTA_ASSERT_NODE_HAS( sourceAST->getChildAt(0),
ASTNodeTypes::unparsedTemplate,
startIndex,
endIndex-startIndex );
}
void
DeclarationParserTest::testNestedTemplateClass()
{
const std::string source( " template x< T > template y< T2 > class v { T x; T2 y;}; " );
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::unparsedTemplate,
startIndex,
endIndex-startIndex );
}
} // namespace Refactoring
--- NEW FILE: DeclarationParserTest.h ---
// //////////////////////////////////////////////////////////////////////////
// Header file DeclarationParserTest.h for class DeclarationParserTest
// (c)Copyright 2003, Andre Baresel.
// Created: 2003/04/10
// //////////////////////////////////////////////////////////////////////////
#ifndef RFTA_DeclarationParserTest_H
#define RFTA_DeclarationParserTest_H
#include "ParserTesting.h"
namespace Refactoring
{
/// Unit tests for CompoundStatementParserTest
class DeclarationParserTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( DeclarationParserTest );
CPPUNIT_TEST( testNamespaceParse );
CPPUNIT_TEST( testUsingNamespace );
CPPUNIT_TEST( testGlobalTypedef );
CPPUNIT_TEST( testLongUsingNamespace );
CPPUNIT_TEST( testNamespaceAlias );
CPPUNIT_TEST( testSimpleLinkage );
CPPUNIT_TEST( testSingleLinkage );
CPPUNIT_TEST( testSimpleDeclaration );
CPPUNIT_TEST( testFunctionbody );
CPPUNIT_TEST( testClassDeclaration );
CPPUNIT_TEST( testTemplateClass );
CPPUNIT_TEST( testTemplateFuntion );
CPPUNIT_TEST( testNestedTemplateClass );
CPPUNIT_TEST_SUITE_END();
public:
/*! Constructs a DeclarationParserTest object.
*/
DeclarationParserTest();
/// Destructor.
virtual ~DeclarationParserTest();
void setUp();
void tearDown();
void testNamespaceParse();
void testUsingNamespace();
void testGlobalTypedef();
void testLongUsingNamespace();
void testNamespaceAlias();
void testSimpleLinkage();
void testSingleLinkage();
void testSimpleDeclaration();
void testFunctionbody();
void testClassDeclaration();
void testTemplateClass();
void testTemplateFuntion();
void testNestedTemplateClass();
private:
/// Prevents the use of the copy constructor.
DeclarationParserTest( const DeclarationParserTest &other );
/// Prevents the use of the copy operator.
void operator =( const DeclarationParserTest &other );
private:
};
// Inlines methods for DeclarationParserTest:
// ------------------------------------------------
} // namespace Refactoring
#endif // RFTA_DeclarationParserTest_H
--- NEW FILE: LinkageParser.cpp ---
// //////////////////////////////////////////////////////////////////////////
// Implementation file LinkageParser.cpp for class LinkageParser
// (c)Copyright 2003, Andre Baresel.
// Created: 2003/04/11
// //////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "LinkageParser.h"
#include "DeclarationParser.h"
#include <rfta/parser/ASTNodes.h>
#include <rfta/parser/ParseContext.h>
namespace Refactoring
{
LinkageParser::LinkageParser( ParseContext &context,
const char *start,
const char *end )
: Parser( context, start, end )
{
}
LinkageParser::~LinkageParser()
{
}
void
LinkageParser::parse()
{
Tracker tracker( "LinkageParser::parse", *this );
ASTNodePtr linkageNode =
createASTNode( ASTNodeTypes::unparsedLinkage,
getParentNode(),
getStartIndex(),
getCurrentLength() );
context_.addNode( linkageNode );
expectKeyword( "extern" );
skipSpaces();
// read the literal
expect('\"');
if (!tryReadUntilNext('\"'))
throwFailure( "Parsing has failed read string-literal." );
skipSpaces();
// check for surrounding linkage:
if (tryNextIs('{'))
{
// is surrounding linkage like: "extern "C" { ... }"
findNextBalanced('{','}');
} else
{
// is single linkage like: extern "C" ...
// setup the context to bind next node to templatebody-property
context_.bindNextNodeToProperty( linkageNode,
ASTNodeProperties::linkageBodyProperty );
DeclarationParser parser( context_, current_, end_ );
parser.tryParse();
current_ = parser.getCurrent();
}
linkageNode->setLength( getCurrentLength() );
}
} // namespace Refactoring
--- NEW FILE: LinkageParser.h ---
// //////////////////////////////////////////////////////////////////////////
// Header file LinkageParser.h for class LinkageParser
// (c)Copyright 2003, Andre Baresel.
// Created: 2003/04/10
// //////////////////////////////////////////////////////////////////////////
#ifndef RFTA_LinkageParser_H
#define RFTA_LinkageParser_H
#include <rfta/parser/Parser.h>
namespace Refactoring
{
/// namespace parser.
class LinkageParser : public Parser
{
public:
/*! Constructs a LinkageParser object.
*/
LinkageParser( ParseContext &context,
const char *start,
const char *end );
/// Destructor.
virtual ~LinkageParser();
void parse();
private:
};
// Inlines methods for LinkageParser:
// ---------------------------------------
} // namespace Refactoring
#endif // RFTA_LinkageParser_H
--- NEW FILE: NamespaceParser.cpp ---
// //////////////////////////////////////////////////////////////////////////
// Implementation file NamespaceParser.cpp for class NamespaceParser
// (c)Copyright 2003, Andre Baresel.
// Created: 2003/04/10
// //////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "NamespaceParser.h"
#include <rfta/parser/ASTNodes.h>
#include <rfta/parser/ParseContext.h>
namespace Refactoring
{
NamespaceParser::NamespaceParser( ParseContext &context,
const char *start,
const char *end )
: Parser( context, start, end )
{
}
NamespaceParser::~NamespaceParser()
{
}
void
NamespaceParser::parse()
{
Tracker tracker( "NamespaceParser::parse", *this );
ASTNodePtr namespaceNode =
createASTNode( ASTNodeTypes::unparsedNamespace,
getParentNode(),
getStartIndex(),
getCurrentLength() );
context_.addNode( namespaceNode );
expectKeyword( "namespace" );
skipSpaces();
// named namespace or unnamed namespace:
// "namespace x" or "namespace { ... }"
std::string namespace_name;
if (tryReadNextIdentifier(namespace_name))
{
// namespace has an identifier
// TODO: add property for name
} else
{
// unnamed namespace
// TODO: add property marking this as unnamed namespace
}
if (!namespace_name.empty())
{
// check for definition of a namespace alias
skipSpaces();
if (tryNextIs('='))
{
// namespace alias: "namespace x = y;"
skipSpaces();
std::string alias_name = namespace_name;
if (!tryReadNextIdentifier(namespace_name))
{
throwFailure( std::string("expected identifier for namespace alias." ));
}
// TODO: store alias name in a property
skipSpaces();
expect(';');
} else
{
// this is a usual namespace definition:
// "namespace x { }"
expect('{');
findNextBalanced('{','}');
}
}
namespaceNode->setLength( getCurrentLength() );
}
} // namespace Refactoring
--- NEW FILE: NamespaceParser.h ---
// //////////////////////////////////////////////////////////////////////////
// Header file NamespaceParser.h for class NamespaceParser
// (c)Copyright 2003, Andre Baresel.
// Created: 2003/04/10
// //////////////////////////////////////////////////////////////////////////
#ifndef RFTA_NAMESPACEPARSER_H
#define RFTA_NAMESPACEPARSER_H
#include <rfta/parser/Parser.h>
namespace Refactoring
{
/// namespace parser.
class NamespaceParser : public Parser
{
public:
/*! Constructs a NamespaceParser object.
*/
NamespaceParser( ParseContext &context,
const char *start,
const char *end );
/// Destructor.
virtual ~NamespaceParser();
void parse();
private:
};
// Inlines methods for NamespaceParser:
// ---------------------------------------
} // namespace Refactoring
#endif // RFTA_NAMESPACEPARSER_H
--- NEW FILE: TemplateDeclarationParser.cpp ---
// //////////////////////////////////////////////////////////////////////////
// Implementation file TemplateDeclarationParser.cpp for class TemplateDeclarationParser
// (c)Copyright 2003, Andre Baresel.
// Created: 2003/04/12
// //////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "TemplateDeclarationParser.h"
#include "DeclarationParser.h"
#include <rfta/parser/ASTNodes.h>
#include <rfta/parser/ParseContext.h>
namespace Refactoring
{
TemplateDeclarationParser::TemplateDeclarationParser( ParseContext &context,
const char *start,
const char *end )
: Parser( context, start, end )
{
}
TemplateDeclarationParser::~TemplateDeclarationParser()
{
}
void
TemplateDeclarationParser::parse()
{
Tracker tracker( "TemplateDeclarationParser::parse", *this );
ASTNodePtr templateNode =
createASTNode( ASTNodeTypes::unparsedTemplate,
getParentNode(),
getStartIndex(),
getCurrentLength() );
context_.addNode( templateNode );
expectKeyword( "template" );
skipSpaces();
// read the template parameter
if (tryNextIs('<'))
{
// skipping all the parameters until next '>'
findNextBalanced('<','>');
}
skipSpaces();
// setup the context to bind next node to templatebody-property
context_.bindNextNodeToProperty( templateNode,
ASTNodeProperties::templateBodyProperty );
// read the template body:
DeclarationParser parser( context_, current_ , end_ );
parser.tryParse();
current_ = parser.getCurrent();
templateNode->setLength( getCurrentLength() );
}
} // namespace Refactoring
--- NEW FILE: TemplateDeclarationParser.h ---
// //////////////////////////////////////////////////////////////////////////
// Header file TemplateDeclarationParser.h for class TemplateDeclarationParser
// (c)Copyright 2003, Andre Baresel.
// Created: 2003/04/12
// //////////////////////////////////////////////////////////////////////////
#ifndef RFTA_TemplateDeclarationParser_H
#define RFTA_TemplateDeclarationParser_H
#include <rfta/parser/Parser.h>
namespace Refactoring
{
/// namespace parser.
class TemplateDeclarationParser : public Parser
{
public:
/*! Constructs a TemplateDeclarationParser object.
*/
TemplateDeclarationParser( ParseContext &context,
const char *start,
const char *end );
/// Destructor.
virtual ~TemplateDeclarationParser();
void parse();
private:
};
// Inlines methods for TemplateDeclarationParser:
// ---------------------------------------
} // namespace Refactoring
#endif // RFTA_TemplateDeclarationParser_H
--- NEW FILE: UsingNamespaceParser.cpp ---
// //////////////////////////////////////////////////////////////////////////
// Implementation file UsingNamespaceParser.cpp for class UsingNamespaceParser
// (c)Copyright 2003, Andre Baresel.
// Created: 2003/04/10
// //////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "UsingNamespaceParser.h"
#include <rfta/parser/ASTNodes.h>
#include <rfta/parser/ParseContext.h>
namespace Refactoring
{
UsingNamespaceParser::UsingNamespaceParser( ParseContext &context,
const char *start,
const char *end )
: Parser( context, start, end )
{
}
UsingNamespaceParser::~UsingNamespaceParser()
{
}
void
UsingNamespaceParser::parse()
{
Tracker tracker( "UsingNamespaceParser::parse", *this );
ASTNodePtr namespaceNode =
createASTNode( ASTNodeTypes::usingNamespace,
getParentNode(),
getStartIndex(),
getCurrentLength() );
context_.addNode( namespaceNode );
expectKeyword( "using" );
skipSpaces();
expectKeyword( "namespace" );
skipSpaces();
// do not parse namespace identification here
readUntilNext(';');
namespaceNode->setLength( getCurrentLength() );
}
} // namespace Refactoring
--- NEW FILE: UsingNamespaceParser.h ---
// //////////////////////////////////////////////////////////////////////////
// Header file UsingNamespaceParser.h for class UsingNamespaceParser
// (c)Copyright 2003, Andre Baresel.
// Created: 2003/04/10
// //////////////////////////////////////////////////////////////////////////
#ifndef RFTA_UsingNamespaceParser_H
#define RFTA_UsingNamespaceParser_H
#include <rfta/parser/Parser.h>
namespace Refactoring
{
/// namespace parser.
class UsingNamespaceParser : public Parser
{
public:
/*! Constructs a UsingNamespaceParser object.
*/
UsingNamespaceParser( ParseContext &context,
const char *start,
const char *end );
/// Destructor.
virtual ~UsingNamespaceParser();
void parse();
private:
};
// Inlines methods for UsingNamespaceParser:
// ---------------------------------------
} // namespace Refactoring
#endif // RFTA_UsingNamespaceParser_H
|