From b332ea822263e9795d73e012062d533aed315f07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Zmys=C5=82owski?= Date: Sat, 22 Oct 2011 09:45:48 +0200 Subject: [PATCH] Fixed #3204 (Refactor standards support in Settings) --- cli/cmdlineparser.cpp | 6 +++--- lib/checkbufferoverrun.cpp | 2 +- lib/checknonreentrantfunctions.cpp | 2 +- lib/checkobsoletefunctions.cpp | 4 ++-- lib/settings.cpp | 2 -- lib/settings.h | 11 +++-------- lib/tokenize.cpp | 2 +- test/testbufferoverrun.cpp | 2 +- test/testcmdlineparser.cpp | 6 +++--- test/testnonreentrantfunctions.cpp | 2 +- test/testnullpointer.cpp | 2 +- test/testobsoletefunctions.cpp | 4 ++-- 12 files changed, 19 insertions(+), 26 deletions(-) diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 1641a2853..e26f97c6f 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -377,16 +377,16 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[]) // --std else if (strcmp(argv[i], "--std=posix") == 0) { - _settings->posix = true; + _settings->standards.posix = true; } // --C99 else if (strcmp(argv[i], "--std=c99") == 0) { - _settings->c99 = true; + _settings->standards.c99 = true; } else if (strcmp(argv[i], "--std=c++11") == 0) { - _settings->cpp11 = true; + _settings->standards.cpp11 = true; } // Output formatter diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index d46f9e5aa..d9508615b 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -1193,7 +1193,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const ArrayInfo &arrayInfo } // readlink() - if (_settings->posix && Token::Match(tok, "readlink ( %any% , %varid% , %num% )", arrayInfo.varid())) { + if (_settings->standards.posix && Token::Match(tok, "readlink ( %any% , %varid% , %num% )", arrayInfo.varid())) { const MathLib::bigint n = MathLib::toLongNumber(tok->strAt(6)); if (total_size > 0 && n > total_size) outOfBoundsError(tok->tokAt(4), "readlink() buf size", true, n, total_size); diff --git a/lib/checknonreentrantfunctions.cpp b/lib/checknonreentrantfunctions.cpp index 84171dfc6..0066a9d94 100644 --- a/lib/checknonreentrantfunctions.cpp +++ b/lib/checknonreentrantfunctions.cpp @@ -32,7 +32,7 @@ namespace { void CheckNonReentrantFunctions::nonReentrantFunctions() { - if (!_settings->posix || !_settings->isEnabled("portability")) + if (!_settings->standards.posix || !_settings->isEnabled("portability")) return; // Don't check C# and Java code diff --git a/lib/checkobsoletefunctions.cpp b/lib/checkobsoletefunctions.cpp index e0e9cfe1a..8d53bfca4 100644 --- a/lib/checkobsoletefunctions.cpp +++ b/lib/checkobsoletefunctions.cpp @@ -65,7 +65,7 @@ void CheckObsoleteFunctions::obsoleteFunctions() // Therefore this is "information" reportError(tok->tokAt(1), Severity::style, "obsoleteFunctions"+it->first, it->second); } else { - if (_settings->posix) { + if (_settings->standards.posix) { it = _obsoletePosixFunctions.find(tok->str()); if (it != _obsoletePosixFunctions.end()) { // If checking an old code base it might be uninteresting to update obsolete functions. @@ -73,7 +73,7 @@ void CheckObsoleteFunctions::obsoleteFunctions() reportError(tok->tokAt(1), Severity::style, "obsoleteFunctions"+it->first, it->second); } } - if (_settings->c99) { + if (_settings->standards.c99) { it = _obsoleteC99Functions.find(tok->str()); if (it != _obsoleteC99Functions.end()) { reportError(tok->tokAt(1), Severity::style, "obsoleteFunctions"+it->first, it->second); diff --git a/lib/settings.cpp b/lib/settings.cpp index 79e35cc6f..9ce9aa90a 100644 --- a/lib/settings.cpp +++ b/lib/settings.cpp @@ -44,8 +44,6 @@ Settings::Settings() reportProgress = false; ifcfg = false; checkConfiguration = false; - c99 = false; - posix = false; // This assumes the code you are checking is for the same architecture this is compiled on. #if defined(_WIN64) diff --git a/lib/settings.h b/lib/settings.h index f2524cb65..2d26b4655 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -23,6 +23,7 @@ #include #include #include "suppressions.h" +#include "standards.h" /// @addtogroup Core /// @{ @@ -182,14 +183,8 @@ public: /** Is the 'configuration checking' wanted? */ bool checkConfiguration; - /** Code is posix - it is not compatible with non-posix environments */ - bool posix; - - /** Code is C99 standard - it is not compatible with previous versions */ - bool c99; - - /** Code follows C++11 standard - it is not compatible with previous versions */ - bool cpp11; + /** Struct contains standards settings */ + Standards standards; /** size of standard types */ unsigned int sizeof_bool; diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 4e5f82282..cec81f4f7 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2401,7 +2401,7 @@ bool Tokenizer::tokenize(std::istream &code, removeRedundantSemicolons(); - if (_settings->cpp11) { + if (_settings->standards.cpp11) { for (Token *tok = _tokens; tok; tok = tok->next()) { if (tok->str() == "nullptr") tok->str("0"); diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 2b1ab08b4..4b0dc2f07 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -41,7 +41,7 @@ private: Settings settings; settings.inconclusive = true; - settings.posix = true; + settings.standards.posix = true; settings.experimental = experimental; settings.addEnabled("style"); settings.addEnabled("portability"); diff --git a/test/testcmdlineparser.cpp b/test/testcmdlineparser.cpp index e036eeb26..c9147c3d2 100644 --- a/test/testcmdlineparser.cpp +++ b/test/testcmdlineparser.cpp @@ -552,7 +552,7 @@ private: Settings settings; CmdLineParser parser(&settings); ASSERT(parser.ParseFromArgs(3, argv)); - ASSERT(settings.posix); + ASSERT(settings.standards.posix); } void stdc99() { @@ -561,7 +561,7 @@ private: Settings settings; CmdLineParser parser(&settings); ASSERT(parser.ParseFromArgs(3, argv)); - ASSERT(settings.c99); + ASSERT(settings.standards.c99); } void stdcpp11() { @@ -570,7 +570,7 @@ private: Settings settings; CmdLineParser parser(&settings); ASSERT(parser.ParseFromArgs(3, argv)); - ASSERT(settings.cpp11); + ASSERT(settings.standards.cpp11); } void suppressionsOld() { diff --git a/test/testnonreentrantfunctions.cpp b/test/testnonreentrantfunctions.cpp index e86f95c31..b0730cf7e 100644 --- a/test/testnonreentrantfunctions.cpp +++ b/test/testnonreentrantfunctions.cpp @@ -41,7 +41,7 @@ private: errout.str(""); Settings settings; - settings.posix = true; + settings.standards.posix = true; settings.addEnabled("portability"); // Tokenize.. diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 4cb0266ba..c6c938e56 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -62,7 +62,7 @@ private: Settings settings; settings.addEnabled("style"); settings.inconclusive = inconclusive; - settings.cpp11 = cpp11; + settings.standards.cpp11 = cpp11; // Tokenize.. Tokenizer tokenizer(&settings, this); diff --git a/test/testobsoletefunctions.cpp b/test/testobsoletefunctions.cpp index a755a2f4a..8cbb4fe8f 100644 --- a/test/testobsoletefunctions.cpp +++ b/test/testobsoletefunctions.cpp @@ -72,8 +72,8 @@ private: Settings settings; settings.addEnabled("style"); - settings.posix = true; - settings.c99 = true; + settings.standards.posix = true; + settings.standards.c99 = true; // Tokenize.. Tokenizer tokenizer(&settings, this);