parent
28182084f2
commit
791242ea78
|
@ -4432,6 +4432,7 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
|
|||
// remove calling conventions __cdecl, __stdcall..
|
||||
simplifyCallingConvention();
|
||||
|
||||
addSemicolonAfterUnknownMacro();
|
||||
|
||||
// remove some unhandled macros in global scope
|
||||
removeMacrosInGlobalScope();
|
||||
|
@ -5179,6 +5180,24 @@ void Tokenizer::removeMacroInVarDecl()
|
|||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void Tokenizer::addSemicolonAfterUnknownMacro()
|
||||
{
|
||||
if (!isCPP())
|
||||
return;
|
||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||
if (tok->str() != ")")
|
||||
continue;
|
||||
const Token *macro = tok->link() ? tok->link()->previous() : nullptr;
|
||||
if (!macro || !macro->isName())
|
||||
continue;
|
||||
if (Token::simpleMatch(tok, ") try") && !Token::Match(macro, "if|for|while"))
|
||||
tok->insertToken(";");
|
||||
else if (Token::simpleMatch(tok, ") using"))
|
||||
tok->insertToken(";");
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void Tokenizer::removeRedundantAssignment()
|
||||
{
|
||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||
|
|
|
@ -248,6 +248,8 @@ public:
|
|||
/** Remove macros in global scope */
|
||||
void removeMacrosInGlobalScope();
|
||||
|
||||
void addSemicolonAfterUnknownMacro();
|
||||
|
||||
/** Remove undefined macro in class definition:
|
||||
* class DLLEXPORT Fred { };
|
||||
* class Fred FINAL : Base { };
|
||||
|
|
|
@ -406,6 +406,8 @@ private:
|
|||
TEST_CASE(removeMacrosInGlobalScope);
|
||||
TEST_CASE(removeMacroInVarDecl);
|
||||
|
||||
TEST_CASE(addSemicolonAfterUnknownMacro);
|
||||
|
||||
// a = b = 0;
|
||||
TEST_CASE(multipleAssignment);
|
||||
|
||||
|
@ -6424,6 +6426,13 @@ private:
|
|||
ASSERT_EQUALS("void f ( ) { CONST struct ABC abc ; }", tokenizeAndStringify("void f() { SECTION(\".data.ro\") CONST struct ABC abc; }"));
|
||||
}
|
||||
|
||||
void addSemicolonAfterUnknownMacro() {
|
||||
// #6975
|
||||
ASSERT_EQUALS("void f ( ) { MACRO ( ) ; try { } }", tokenizeAndStringify("void f() { MACRO() try {} }"));
|
||||
// #9376
|
||||
ASSERT_EQUALS("MACRO ( ) ; using namespace foo ;", tokenizeAndStringify("MACRO() using namespace foo;"));
|
||||
}
|
||||
|
||||
void multipleAssignment() {
|
||||
ASSERT_EQUALS("a = b = 0 ;", tokenizeAndStringify("a=b=0;"));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue