Fixed #779 (Tokenizer: delete register keyword everywhere)
This commit is contained in:
parent
21717e05cd
commit
3152816619
|
@ -2917,7 +2917,15 @@ bool Tokenizer::simplifyTokenList()
|
||||||
simplifyMathFunctions();
|
simplifyMathFunctions();
|
||||||
|
|
||||||
// Remove unwanted keywords
|
// 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 (Token *tok = _tokens; tok; tok = tok->next())
|
||||||
{
|
{
|
||||||
for (unsigned ui = 0; ui < sizeof(unwantedWords) / sizeof(unwantedWords[0]) && tok->next(); ui++)
|
for (unsigned ui = 0; ui < sizeof(unwantedWords) / sizeof(unwantedWords[0]) && tok->next(); ui++)
|
||||||
|
|
|
@ -229,6 +229,10 @@ private:
|
||||||
|
|
||||||
// struct ABC { } abc; => struct ABC { }; ABC abc;
|
// struct ABC { } abc; => struct ABC { }; ABC abc;
|
||||||
TEST_CASE(simplifyStructDecl);
|
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)
|
std::string tok(const char code[], bool simplify = true)
|
||||||
|
@ -4376,6 +4380,15 @@ private:
|
||||||
ASSERT_EQUALS(expected, tok(code, false));
|
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)
|
REGISTER_TEST(TestSimplifyTokens)
|
||||||
|
|
Loading…
Reference in New Issue