Fixed #3204 (Refactor standards support in Settings)

This commit is contained in:
Marek Zmysłowski 2011-10-22 09:45:48 +02:00 committed by Daniel Marjamäki
parent 9e5beab4a8
commit b332ea8222
12 changed files with 19 additions and 26 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -23,6 +23,7 @@
#include <string>
#include <set>
#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;

View File

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

View File

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

View File

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

View File

@ -41,7 +41,7 @@ private:
errout.str("");
Settings settings;
settings.posix = true;
settings.standards.posix = true;
settings.addEnabled("portability");
// Tokenize..

View File

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

View File

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