New simplification: Remove 'extern "C"' from C++ code.
Refactorization in cppcheck.cpp: Catch exception as const reference instead of non-const reference.
This commit is contained in:
parent
8cb904feaa
commit
1c3c94dc67
|
@ -225,7 +225,7 @@ unsigned int CppCheck::processFile(const std::string& filename)
|
||||||
|
|
||||||
++checkCount;
|
++checkCount;
|
||||||
}
|
}
|
||||||
} catch (std::runtime_error &e) {
|
} catch (const std::runtime_error &e) {
|
||||||
// Exception was thrown when checking this file..
|
// Exception was thrown when checking this file..
|
||||||
const std::string fixedpath = Path::toNativeSeparators(filename);
|
const std::string fixedpath = Path::toNativeSeparators(filename);
|
||||||
_errorLogger.reportOut("Bailing out from checking " + fixedpath + ": " + e.what());
|
_errorLogger.reportOut("Bailing out from checking " + fixedpath + ": " + e.what());
|
||||||
|
|
|
@ -1977,6 +1977,10 @@ bool Tokenizer::tokenize(std::istream &code,
|
||||||
// combine "- %num%"
|
// combine "- %num%"
|
||||||
concatenateNegativeNumber();
|
concatenateNegativeNumber();
|
||||||
|
|
||||||
|
// remove extern "C" and extern "C" {}
|
||||||
|
if (isCPP())
|
||||||
|
simplifyExternC();
|
||||||
|
|
||||||
// simplify weird but legal code: "[;{}] ( { code; } ) ;"->"[;{}] code;"
|
// simplify weird but legal code: "[;{}] ( { code; } ) ;"->"[;{}] code;"
|
||||||
simplifyRoundCurlyParenthesis();
|
simplifyRoundCurlyParenthesis();
|
||||||
|
|
||||||
|
@ -2451,6 +2455,20 @@ void Tokenizer::concatenateNegativeNumber()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Tokenizer::simplifyExternC()
|
||||||
|
{
|
||||||
|
for (Token *tok = _tokens; tok; tok = tok->next()) {
|
||||||
|
if (Token::Match(tok, "extern \"C\" {|")) {
|
||||||
|
if (tok->strAt(2) == "{") {
|
||||||
|
tok->linkAt(2)->deleteThis();
|
||||||
|
tok->deleteNext(2);
|
||||||
|
} else
|
||||||
|
tok->deleteNext();
|
||||||
|
tok->deleteThis();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Tokenizer::simplifyRoundCurlyParenthesis()
|
void Tokenizer::simplifyRoundCurlyParenthesis()
|
||||||
{
|
{
|
||||||
for (Token *tok = _tokens; tok; tok = tok->next()) {
|
for (Token *tok = _tokens; tok; tok = tok->next()) {
|
||||||
|
|
|
@ -489,6 +489,8 @@ public:
|
||||||
|
|
||||||
void concatenateNegativeNumber();
|
void concatenateNegativeNumber();
|
||||||
|
|
||||||
|
void simplifyExternC();
|
||||||
|
|
||||||
void simplifyRoundCurlyParenthesis();
|
void simplifyRoundCurlyParenthesis();
|
||||||
|
|
||||||
void simplifyDebugNew();
|
void simplifyDebugNew();
|
||||||
|
|
|
@ -161,6 +161,7 @@ private:
|
||||||
TEST_CASE(simplifyKnownVariablesBailOutSwitchBreak); // ticket #2324
|
TEST_CASE(simplifyKnownVariablesBailOutSwitchBreak); // ticket #2324
|
||||||
TEST_CASE(simplifyKnownVariablesFloat); // #2454 - float variable
|
TEST_CASE(simplifyKnownVariablesFloat); // #2454 - float variable
|
||||||
TEST_CASE(simplifyKnownVariablesClassMember); // #2815 - value of class member may be changed by function call
|
TEST_CASE(simplifyKnownVariablesClassMember); // #2815 - value of class member may be changed by function call
|
||||||
|
TEST_CASE(simplifyExternC);
|
||||||
|
|
||||||
TEST_CASE(varid1);
|
TEST_CASE(varid1);
|
||||||
TEST_CASE(varid2);
|
TEST_CASE(varid2);
|
||||||
|
@ -2508,6 +2509,10 @@ private:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void simplifyExternC() {
|
||||||
|
ASSERT_EQUALS("int foo ( ) ;", tokenizeAndStringify("extern \"C\" int foo();"));
|
||||||
|
ASSERT_EQUALS("int foo ( ) ;", tokenizeAndStringify("extern \"C\" { int foo(); }"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string tokenizeDebugListing(const std::string &code, bool simplify = false, const char filename[] = "test.cpp") {
|
std::string tokenizeDebugListing(const std::string &code, bool simplify = false, const char filename[] = "test.cpp") {
|
||||||
|
@ -3222,7 +3227,7 @@ private:
|
||||||
void varid40() {
|
void varid40() {
|
||||||
const std::string code("extern \"C\" int (*a())();");
|
const std::string code("extern \"C\" int (*a())();");
|
||||||
ASSERT_EQUALS("\n\n##file 0\n"
|
ASSERT_EQUALS("\n\n##file 0\n"
|
||||||
"1: extern \"C\" int ( * a ( ) ) ( ) ;\n",
|
"1: int ( * a ( ) ) ( ) ;\n",
|
||||||
tokenizeDebugListing(code));
|
tokenizeDebugListing(code));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue