This commit is contained in:
parent
87c0b063cb
commit
b08aabefee
|
@ -4742,9 +4742,6 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
|
||||||
// Is there C++ code in C file?
|
// Is there C++ code in C file?
|
||||||
validateC();
|
validateC();
|
||||||
|
|
||||||
// remove MACRO in variable declaration: MACRO int x;
|
|
||||||
removeMacroInVarDecl();
|
|
||||||
|
|
||||||
// Combine strings and character literals, e.g. L"string", L'c', "string1" "string2"
|
// Combine strings and character literals, e.g. L"string", L'c', "string1" "string2"
|
||||||
combineStringAndCharLiterals();
|
combineStringAndCharLiterals();
|
||||||
|
|
||||||
|
@ -5649,35 +5646,6 @@ void Tokenizer::removeMacroInClassDef()
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
void Tokenizer::removeMacroInVarDecl()
|
|
||||||
{
|
|
||||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
|
||||||
if (Token::Match(tok, "[;{}] %name% (") && tok->next()->isUpperCaseName()) {
|
|
||||||
// goto ')' parentheses
|
|
||||||
const Token *tok2 = tok;
|
|
||||||
int parlevel = 0;
|
|
||||||
while (tok2) {
|
|
||||||
if (tok2->str() == "(")
|
|
||||||
++parlevel;
|
|
||||||
else if (tok2->str() == ")") {
|
|
||||||
if (--parlevel <= 0)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
tok2 = tok2->next();
|
|
||||||
}
|
|
||||||
tok2 = tok2 ? tok2->next() : nullptr;
|
|
||||||
|
|
||||||
// check if this is a variable declaration..
|
|
||||||
const Token *tok3 = tok2;
|
|
||||||
while (tok3 && tok3->isUpperCaseName())
|
|
||||||
tok3 = tok3->next();
|
|
||||||
if (tok3 && (tok3->isStandardType() || Token::Match(tok3,"const|static|struct|union|class")))
|
|
||||||
Token::eraseTokens(tok,tok2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void Tokenizer::addSemicolonAfterUnknownMacro()
|
void Tokenizer::addSemicolonAfterUnknownMacro()
|
||||||
{
|
{
|
||||||
if (!isCPP())
|
if (!isCPP())
|
||||||
|
|
|
@ -204,9 +204,6 @@ public:
|
||||||
*/
|
*/
|
||||||
void removeMacroInClassDef();
|
void removeMacroInClassDef();
|
||||||
|
|
||||||
/** Remove unknown macro in variable declarations: PROGMEM char x; */
|
|
||||||
void removeMacroInVarDecl();
|
|
||||||
|
|
||||||
/** Add parentheses for sizeof: sizeof x => sizeof(x) */
|
/** Add parentheses for sizeof: sizeof x => sizeof(x) */
|
||||||
void sizeofAddParentheses();
|
void sizeofAddParentheses();
|
||||||
|
|
||||||
|
|
|
@ -358,7 +358,6 @@ private:
|
||||||
|
|
||||||
// Some simple cleanups of unhandled macros in the global scope
|
// Some simple cleanups of unhandled macros in the global scope
|
||||||
TEST_CASE(removeMacrosInGlobalScope);
|
TEST_CASE(removeMacrosInGlobalScope);
|
||||||
TEST_CASE(removeMacroInVarDecl);
|
|
||||||
|
|
||||||
TEST_CASE(addSemicolonAfterUnknownMacro);
|
TEST_CASE(addSemicolonAfterUnknownMacro);
|
||||||
|
|
||||||
|
@ -5318,19 +5317,6 @@ private:
|
||||||
InternalError);
|
InternalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeMacroInVarDecl() { // #4304
|
|
||||||
// only remove macros with parentheses (those hurt most)
|
|
||||||
ASSERT_EQUALS("void f ( ) { PROGMEM int x ; }", tokenizeAndStringify("void f() { PROGMEM int x ; }"));
|
|
||||||
ASSERT_EQUALS("void f ( ) { int x ; }", tokenizeAndStringify("void f() { SECTION(\".data.ro\") int x ; }"));
|
|
||||||
|
|
||||||
// various variable declarations
|
|
||||||
ASSERT_EQUALS("void f ( ) { CONST int x ; }", tokenizeAndStringify("void f() { SECTION(\".data.ro\") CONST int x ; }"));
|
|
||||||
ASSERT_EQUALS("void f ( ) { char a [ 4 ] ; }", tokenizeAndStringify("void f() { SECTION(\".data.ro\") char a[4]; }"));
|
|
||||||
ASSERT_EQUALS("void f ( ) { const char a [ 4 ] ; }", tokenizeAndStringify("void f() { SECTION(\".data.ro\") const char a[4]; }"));
|
|
||||||
ASSERT_EQUALS("void f ( ) { struct ABC abc ; }", tokenizeAndStringify("void f() { SECTION(\".data.ro\") struct ABC abc; }"));
|
|
||||||
ASSERT_EQUALS("void f ( ) { CONST struct ABC abc ; }", tokenizeAndStringify("void f() { SECTION(\".data.ro\") CONST struct ABC abc; }"));
|
|
||||||
}
|
|
||||||
|
|
||||||
void addSemicolonAfterUnknownMacro() {
|
void addSemicolonAfterUnknownMacro() {
|
||||||
// #6975
|
// #6975
|
||||||
ASSERT_EQUALS("void f ( ) { MACRO ( ) ; try { } }", tokenizeAndStringify("void f() { MACRO() try {} }"));
|
ASSERT_EQUALS("void f ( ) { MACRO ( ) ; try { } }", tokenizeAndStringify("void f() { MACRO() try {} }"));
|
||||||
|
|
|
@ -3217,6 +3217,14 @@ private:
|
||||||
" delete [] piArray;\n"
|
" delete [] piArray;\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
functionVariableUsage("int f() {\n" // #9877
|
||||||
|
" const std::vector<int> x = get();\n"
|
||||||
|
" MACRO(2U, x.size())\n"
|
||||||
|
" int i = 0;\n"
|
||||||
|
" return i;\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void localvar44() { // #4020 - FP
|
void localvar44() { // #4020 - FP
|
||||||
|
|
Loading…
Reference in New Issue