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

@ -43,6 +43,8 @@ private:
TEST_CASE( inlineasm ); TEST_CASE( inlineasm );
TEST_CASE( dupfuncname ); TEST_CASE( dupfuncname );
TEST_CASE( const_and_volatile_functions );
} }
@ -147,6 +149,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() );
}
}
}; };
REGISTER_TEST( TestTokenizer ) REGISTER_TEST( TestTokenizer )

View File

@ -1085,6 +1085,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
{ {
tok = tok2; tok = tok2;