Tokenizer: Fixed bug, const and volatile functions were not recogniced

by fillFunctionList()
This commit is contained in:
Reijo Tomperi 2008-12-03 20:22:48 +00:00
parent d3a2a32a58
commit 5eb653911e
2 changed files with 51 additions and 3 deletions

View File

@ -42,7 +42,9 @@ private:
TEST_CASE( inlineasm ); TEST_CASE( inlineasm );
TEST_CASE( dupfuncname ); TEST_CASE( dupfuncname );
TEST_CASE( const_and_volatile_functions );
} }
@ -146,6 +148,42 @@ private:
ASSERT_EQUALS( 1, tokenizer._functionList.size() ); ASSERT_EQUALS( 1, tokenizer._functionList.size() );
ASSERT_EQUALS( std::string("b"), tokenizer._functionList[0]->aaaa() ); ASSERT_EQUALS( std::string("b"), tokenizer._functionList[0]->aaaa() );
}
void const_and_volatile_functions()
{
const char code[] = "class B\n\
{\n\
public:\n\
void a();\n\
void b() const;\n\
void c() volatile;\n\
};\n\
\n\
void B::a()\n\
{}\n\
\n\
void B::b() const\n\
{}\n\
\n\
void B::c() volatile\n\
{}\n";
// tokenize..
Tokenizer tokenizer;
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
tokenizer.fillFunctionList();
ASSERT_EQUALS( 3, tokenizer._functionList.size() );
if( tokenizer._functionList.size() == 3 )
{
ASSERT_EQUALS( std::string("a"), tokenizer._functionList[0]->aaaa() );
ASSERT_EQUALS( std::string("b"), tokenizer._functionList[1]->aaaa() );
ASSERT_EQUALS( std::string("c"), tokenizer._functionList[2]->aaaa() );
}
} }
}; };

View File

@ -1084,6 +1084,16 @@ void Tokenizer::fillFunctionList()
{ {
_functionList.push_back( tok ); _functionList.push_back( tok );
tok = tok2; tok = tok2;
}
else if ( TOKEN::Match(tok2, ") const {") )
{
_functionList.push_back( tok );
tok = tok2;
}
else if ( TOKEN::Match(tok2, ") volatile {") )
{
_functionList.push_back( tok );
tok = tok2;
} }
else else
{ {
@ -1100,7 +1110,7 @@ void Tokenizer::fillFunctionList()
// If the _functionList functions with duplicate names, remove them // If the _functionList functions with duplicate names, remove them
// TODO this will need some better handling // TODO this will need some better handling
for ( unsigned int func1 = 0; func1 < _functionList.size(); ) for ( unsigned int func1 = 0; func1 < _functionList.size(); )
{ {
bool hasDuplicates = false; bool hasDuplicates = false;
for ( unsigned int func2 = func1 + 1; func2 < _functionList.size(); ) for ( unsigned int func2 = func1 + 1; func2 < _functionList.size(); )
{ {
@ -1123,7 +1133,7 @@ void Tokenizer::fillFunctionList()
{ {
_functionList.erase( _functionList.begin() + func1 ); _functionList.erase( _functionList.begin() + func1 );
} }
} }
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------