|
From: <bl...@us...> - 2003-05-28 07:36:25
|
Update of /cvsroot/cpptool/rfta/src/rfta
In directory sc8-pr-cvs1:/tmp/cvs-serv19238/src/rfta
Modified Files:
rfta.dsp
Added Files:
CodeModelParser.cpp CodeModelParserTest.cpp
CodeModelParserTest.h
Log Message:
* added CodeModelParser, similar to CPPParser but returns CodeModel object instead of ASTNode.
--- NEW FILE: CodeModelParser.cpp ---
#include "stdafx.h"
#include <rfta/refactoring/CodeModelParser.h>
#include <rfta/refactoring/CodeModelGenerator.h>
#include <rfta/refactoring/CodeModelDeclarations.h>
namespace Refactoring { namespace CodeModel
{
Parser::Parser( const std::string &source )
: parser_( source )
{
}
FunctionDeclarationPtr
Parser::getFunctionBodyAt( int position )
{
ASTNodePtr functionNode = parser_.parseForFunctionBodyAt( position );
if ( !functionNode )
return FunctionDeclarationPtr();
Generator generator;
return generator.generateFunctionDeclaration( functionNode );
}
}} // namespace Refactoring { namespace CodeModel
--- NEW FILE: CodeModelParserTest.cpp ---
// //////////////////////////////////////////////////////////////////////////
// (c)Copyright 2002, Baptiste Lepilleur.
// Created: 2003/05/27
// //////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "CodeModelParserTest.h"
#include <rfta/refactoring/CodeModelParser.h>
#include <rfta/refactoring/CodeModelDeclarations.h>
#include <rfta/refactoring/CodeModelStatements.h>
namespace Refactoring
{
RFTA_TEST_SUITE_REGISTRATION( CodeModelParserTest );
CodeModelParserTest::CodeModelParserTest()
{
}
CodeModelParserTest::~CodeModelParserTest()
{
}
void
CodeModelParserTest::setUp()
{
SourceBasedTestBase::setUp();
}
void
CodeModelParserTest::tearDown()
{
SourceBasedTestBase::tearDown();
}
void
CodeModelParserTest::testGetFunctionAt()
{
source_ = "void function() { ";
builder_->addKeyingMid( "", "return", ";", "FN" );
source_ += "}";
CodeModel::Parser parser( source_ );
CodeModel::FunctionDeclarationPtr function = parser.getFunctionBodyAt( builder_->getStartIndex( "FN" ) );
CodeModel::FunctionNamePtr functionName = function->getFunctionName();
std::string name = functionName->getName();
RFTA_ASSERT_EQUAL( "void function() ", name ); // because of incomplete parsing, should be 'function'.
CodeModel::CompoundStatementPtr compound = function->getBody();
CPPUNIT_ASSERT( compound );
RFTA_ASSERT_EQUAL( 1, compound->getStatementCount() );
CodeModel::StatementPtr statement = compound->getStatementAt(0);
CPPUNIT_ASSERT( boost::dynamic_pointer_cast<CodeModel::ReturnStatement>(statement) );
}
} // namespace Refactoring
--- NEW FILE: CodeModelParserTest.h ---
// //////////////////////////////////////////////////////////////////////////
// (c)Copyright 2002, Baptiste Lepilleur.
// Created: 2003/05/27
// //////////////////////////////////////////////////////////////////////////
#ifndef RFTA_CODEMODELPARSERTEST_H
#define RFTA_CODEMODELPARSERTEST_H
#include "SourceBasedTestBase.h"
namespace Refactoring
{
/// Unit tests for CodeModelParserTest
class CodeModelParserTest : public SourceBasedTestBase
{
CPPUNIT_TEST_SUITE( CodeModelParserTest );
CPPUNIT_TEST( testGetFunctionAt );
CPPUNIT_TEST_SUITE_END();
public:
/*! Constructs a CodeModelParserTest object.
*/
CodeModelParserTest();
/// Destructor.
virtual ~CodeModelParserTest();
void setUp();
void tearDown();
void testGetFunctionAt();
private:
/// Prevents the use of the copy constructor.
CodeModelParserTest( const CodeModelParserTest &other );
/// Prevents the use of the copy operator.
void operator =( const CodeModelParserTest &other );
private:
};
// Inlines methods for CodeModelParserTest:
// ----------------------------------------
} // namespace Refactoring
#endif // RFTA_CODEMODELPARSERTEST_H
Index: rfta.dsp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/rfta.dsp,v
retrieving revision 1.49
retrieving revision 1.50
diff -C2 -d -r1.49 -r1.50
*** rfta.dsp 26 May 2003 21:12:33 -0000 1.49
--- rfta.dsp 28 May 2003 07:36:21 -0000 1.50
***************
*** 335,338 ****
--- 335,346 ----
# Begin Source File
+ SOURCE=.\CodeModelDeclarations.cpp
+ # End Source File
+ # Begin Source File
+
+ SOURCE=..\..\include\rfta\refactoring\CodeModelDeclarations.h
+ # End Source File
+ # Begin Source File
+
SOURCE=.\CodeModelElement.cpp
# End Source File
***************
*** 363,366 ****
--- 371,382 ----
# Begin Source File
+ SOURCE=.\CodeModelParser.cpp
+ # End Source File
+ # Begin Source File
+
+ SOURCE=..\..\include\rfta\refactoring\CodeModelParser.h
+ # End Source File
+ # Begin Source File
+
SOURCE=.\CodeModelStatements.cpp
# End Source File
***************
*** 996,999 ****
--- 1012,1023 ----
!ENDIF
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\CodeModelParserTest.cpp
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\CodeModelParserTest.h
# End Source File
# Begin Source File
|