Fixed #779 (Tokenizer: delete register keyword everywhere)

This commit is contained in:
Zachary Blair 2010-04-10 09:58:09 +02:00 committed by Daniel Marjamäki
parent 21717e05cd
commit 3152816619
2 changed files with 22 additions and 1 deletions

View File

@ -2917,7 +2917,15 @@ bool Tokenizer::simplifyTokenList()
simplifyMathFunctions();
// Remove unwanted keywords
static const char * const unwantedWords[] = { "unsigned", "unlikely", "likely" };
static const char * const unwantedWords[] = { "unsigned", "unlikely", "likely", "register", "inline" };
for (unsigned ui = 0; ui < sizeof(unwantedWords) / sizeof(unwantedWords[0]) && _tokens; ui++)
{
if (_tokens->str() == unwantedWords[ui])
{
_tokens->deleteThis();
break;
}
}
for (Token *tok = _tokens; tok; tok = tok->next())
{
for (unsigned ui = 0; ui < sizeof(unwantedWords) / sizeof(unwantedWords[0]) && tok->next(); ui++)

View File

@ -229,6 +229,10 @@ private:
// struct ABC { } abc; => struct ABC { }; ABC abc;
TEST_CASE(simplifyStructDecl);
// register int var; => int var;
// inline int foo() {} => int foo() {}
TEST_CASE(removeUnwantedKeywords);
}
std::string tok(const char code[], bool simplify = true)
@ -4376,6 +4380,15 @@ private:
ASSERT_EQUALS(expected, tok(code, false));
}
}
void removeUnwantedKeywords()
{
ASSERT_EQUALS("int var ;", tok("register int var ;", true));
ASSERT_EQUALS("short var ;", tok("register short int var ;", true));
ASSERT_EQUALS("int foo ( ) { }", tok("inline int foo ( ) { }", true));
ASSERT_EQUALS("if ( a ) { }", tok("if ( likely ( a ) ) { }", true));
ASSERT_EQUALS("if ( a ) { }", tok("if ( unlikely ( a ) ) { }", true));
}
};
REGISTER_TEST(TestSimplifyTokens)