Disabled C++ specific checks and simplifications when checking a C or non-C++ file.

This commit is contained in:
PKEuS 2012-09-10 19:02:32 +02:00
parent 87131f6105
commit 5940d77a62
9 changed files with 42 additions and 9 deletions

View File

@ -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();

View File

@ -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

View File

@ -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();

View File

@ -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);

View File

@ -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();

View File

@ -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();
}

View File

@ -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<unsigned int> 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";

View File

@ -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();

View File

@ -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<std::string> 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<Space> classInfo;
for (Token *tok = list.front(); tok; tok = tok->next()) {
if (Token::Match(tok, "class|struct|namespace %type% :|{") &&