From 5940d77a6213e5546ef4eef75b8decdf31ef4cc4 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Mon, 10 Sep 2012 19:02:32 +0200 Subject: [PATCH] Disabled C++ specific checks and simplifications when checking a C or non-C++ file. --- lib/checkboost.h | 3 +++ lib/checkclass.h | 6 ++++++ lib/checkexceptionsafety.h | 3 +++ lib/checkmemoryleak.h | 2 +- lib/checkother.cpp | 4 ++-- lib/checkpostfixoperator.h | 3 +++ lib/checkstl.cpp | 6 ------ lib/checkstl.h | 3 +++ lib/tokenize.cpp | 21 +++++++++++++++++++++ 9 files changed, 42 insertions(+), 9 deletions(-) diff --git a/lib/checkboost.h b/lib/checkboost.h index 912120b06..9c3ed6e89 100644 --- a/lib/checkboost.h +++ b/lib/checkboost.h @@ -45,6 +45,9 @@ public: /** Simplified checks. The token list is simplified. */ void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { + if (!tokenizer->isCPP()) + return; + CheckBoost checkBoost(tokenizer, settings, errorLogger); checkBoost.checkBoostForeachModification(); diff --git a/lib/checkclass.h b/lib/checkclass.h index 6ed588a8f..09e36a4ef 100644 --- a/lib/checkclass.h +++ b/lib/checkclass.h @@ -44,6 +44,9 @@ public: /** @brief Run checks on the normal token list */ void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { + if (tokenizer->isC()) + return; + CheckClass checkClass(tokenizer, settings, errorLogger); // can't be a simplified check .. the 'sizeof' is used. @@ -52,6 +55,9 @@ public: /** @brief Run checks on the simplified token list */ void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { + if (tokenizer->isC()) + return; + CheckClass checkClass(tokenizer, settings, errorLogger); // Coding style checks diff --git a/lib/checkexceptionsafety.h b/lib/checkexceptionsafety.h index a08c2f4b9..332280047 100644 --- a/lib/checkexceptionsafety.h +++ b/lib/checkexceptionsafety.h @@ -53,6 +53,9 @@ public: /** Checks that uses the simplified token list */ void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { + if (tokenizer->isC()) + return; + CheckExceptionSafety checkExceptionSafety(tokenizer, settings, errorLogger); checkExceptionSafety.destructors(); checkExceptionSafety.deallocThrow(); diff --git a/lib/checkmemoryleak.h b/lib/checkmemoryleak.h index 09eafd262..022459aea 100644 --- a/lib/checkmemoryleak.h +++ b/lib/checkmemoryleak.h @@ -363,7 +363,7 @@ public: void runSimplifiedChecks(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog) { // Don't use these check for Java and C# programs.. - if (tokenizr->isJavaOrCSharp()) + if (!tokenizr->isCPP()) return; CheckMemoryLeakInClass checkMemoryLeak(tokenizr, settings, errLog); diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 415648290..b85bbc965 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1871,7 +1871,7 @@ void CheckOther::variableScopeError(const Token *tok, const std::string &varname //--------------------------------------------------------------------------- void CheckOther::checkConstantFunctionParameter() { - if (!_settings->isEnabled("performance")) + if (!_settings->isEnabled("performance") || _tokenizer->isC()) return; const SymbolDatabase * const symbolDatabase = _tokenizer->getSymbolDatabase(); @@ -3276,7 +3276,7 @@ In most scenarios, "const A & a = getA()" will be more efficient. */ void CheckOther::checkRedundantCopy() { - if (!_settings->isEnabled("performance")) + if (!_settings->isEnabled("performance") || _tokenizer->isC()) return; const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); diff --git a/lib/checkpostfixoperator.h b/lib/checkpostfixoperator.h index b8e96aa41..8d47aba39 100644 --- a/lib/checkpostfixoperator.h +++ b/lib/checkpostfixoperator.h @@ -44,6 +44,9 @@ public: { } void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { + if (tokenizer->isC()) + return; + CheckPostfixOperator checkPostfixOperator(tokenizer, settings, errorLogger); checkPostfixOperator.postfixOperator(); } diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 5ea718ba4..6aa3239d8 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -1072,9 +1072,6 @@ static bool isLocal(const SymbolDatabase* symbolDatabase, unsigned int varid) void CheckStl::string_c_str() { - if (!_tokenizer->isCPP()) - return; - const SymbolDatabase* symbolDatabase = _tokenizer->getSymbolDatabase(); // Find all functions that take std::string as argument @@ -1238,9 +1235,6 @@ static bool hasArrayEndParen(const Token *tok1) //--------------------------------------------------------------------------- void CheckStl::checkAutoPointer() { - if (!_tokenizer->isCPP()) - return; - std::set autoPtrVarId; static const char STL_CONTAINER_LIST[] = "array|bitset|deque|list|forward_list|map|multimap|multiset|priority_queue|queue|set|stack|vector|hash_map|hash_multimap|hash_set|unordered_map|unordered_multimap|unordered_set|unordered_multiset|basic_string"; diff --git a/lib/checkstl.h b/lib/checkstl.h index c667f2b42..7cd5cdc3c 100644 --- a/lib/checkstl.h +++ b/lib/checkstl.h @@ -45,6 +45,9 @@ public: /** Simplified checks. The token list is simplified. */ void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { + if (!tokenizer->isCPP()) + return; + CheckStl checkStl(tokenizer, settings, errorLogger); checkStl.stlOutOfBounds(); diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 73c44f81a..b3f963287 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2075,6 +2075,9 @@ bool Tokenizer::hasComplicatedSyntaxErrorsInTemplates() void Tokenizer::simplifyDefaultAndDeleteInsideClass() { + if (isC()) + return; + // Remove "= default|delete" inside class|struct definitions // Todo: Remove it if it is used "externally" too. for (Token *tok = list.front(); tok; tok = tok->next()) { @@ -2487,6 +2490,9 @@ void Tokenizer::simplifyLabelsCaseDefault() void Tokenizer::simplifyTemplates() { + if (isC()) + return; + for (Token *tok = list.front(); tok; tok = tok->next()) { // #2648 - simple fix for sizeof used as template parameter // TODO: this is a bit hardcoded. make a bit more generic @@ -6640,6 +6646,9 @@ bool Tokenizer::simplifyRedundantParenthesis() void Tokenizer::simplifyReference() { + if (isC()) + return; + for (Token *tok = list.front(); tok; tok = tok->next()) { // starting executable scope.. if (Token::Match(tok, ") const| {")) { @@ -7432,6 +7441,9 @@ void Tokenizer::simplifyEnum() void Tokenizer::simplifyStd() { + if (isC()) + return; + std::set f; f.insert("strcat"); f.insert("strcpy"); @@ -7946,6 +7958,9 @@ void Tokenizer::simplifyComma() void Tokenizer::removeExceptionSpecifications() { + if (isC()) + return; + for (Token* tok = list.front(); tok; tok = tok->next()) { if (Token::Match(tok, ") const| throw (")) { if (tok->next()->str() == "const") { @@ -9063,6 +9078,9 @@ void Tokenizer::deleteSymbolDatabase() void Tokenizer::simplifyOperatorName() { + if (isC()) + return; + for (Token *tok = list.front(); tok; tok = tok->next()) { if (tok->str() == "operator") { // operator op @@ -9117,6 +9135,9 @@ void Tokenizer::simplifyOperatorName() // remove unnecessary member qualification.. void Tokenizer::removeUnnecessaryQualification() { + if (isC()) + return; + std::vector classInfo; for (Token *tok = list.front(); tok; tok = tok->next()) { if (Token::Match(tok, "class|struct|namespace %type% :|{") &&