Fixed #3204 (Refactor standards support in Settings)
This commit is contained in:
parent
9e5beab4a8
commit
b332ea8222
|
@ -377,16 +377,16 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
||||||
|
|
||||||
// --std
|
// --std
|
||||||
else if (strcmp(argv[i], "--std=posix") == 0) {
|
else if (strcmp(argv[i], "--std=posix") == 0) {
|
||||||
_settings->posix = true;
|
_settings->standards.posix = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --C99
|
// --C99
|
||||||
else if (strcmp(argv[i], "--std=c99") == 0) {
|
else if (strcmp(argv[i], "--std=c99") == 0) {
|
||||||
_settings->c99 = true;
|
_settings->standards.c99 = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (strcmp(argv[i], "--std=c++11") == 0) {
|
else if (strcmp(argv[i], "--std=c++11") == 0) {
|
||||||
_settings->cpp11 = true;
|
_settings->standards.cpp11 = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Output formatter
|
// Output formatter
|
||||||
|
|
|
@ -1193,7 +1193,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const ArrayInfo &arrayInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
// readlink()
|
// 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));
|
const MathLib::bigint n = MathLib::toLongNumber(tok->strAt(6));
|
||||||
if (total_size > 0 && n > total_size)
|
if (total_size > 0 && n > total_size)
|
||||||
outOfBoundsError(tok->tokAt(4), "readlink() buf size", true, n, total_size);
|
outOfBoundsError(tok->tokAt(4), "readlink() buf size", true, n, total_size);
|
||||||
|
|
|
@ -32,7 +32,7 @@ namespace {
|
||||||
|
|
||||||
void CheckNonReentrantFunctions::nonReentrantFunctions()
|
void CheckNonReentrantFunctions::nonReentrantFunctions()
|
||||||
{
|
{
|
||||||
if (!_settings->posix || !_settings->isEnabled("portability"))
|
if (!_settings->standards.posix || !_settings->isEnabled("portability"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Don't check C# and Java code
|
// Don't check C# and Java code
|
||||||
|
|
|
@ -65,7 +65,7 @@ void CheckObsoleteFunctions::obsoleteFunctions()
|
||||||
// Therefore this is "information"
|
// Therefore this is "information"
|
||||||
reportError(tok->tokAt(1), Severity::style, "obsoleteFunctions"+it->first, it->second);
|
reportError(tok->tokAt(1), Severity::style, "obsoleteFunctions"+it->first, it->second);
|
||||||
} else {
|
} else {
|
||||||
if (_settings->posix) {
|
if (_settings->standards.posix) {
|
||||||
it = _obsoletePosixFunctions.find(tok->str());
|
it = _obsoletePosixFunctions.find(tok->str());
|
||||||
if (it != _obsoletePosixFunctions.end()) {
|
if (it != _obsoletePosixFunctions.end()) {
|
||||||
// If checking an old code base it might be uninteresting to update obsolete functions.
|
// 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);
|
reportError(tok->tokAt(1), Severity::style, "obsoleteFunctions"+it->first, it->second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (_settings->c99) {
|
if (_settings->standards.c99) {
|
||||||
it = _obsoleteC99Functions.find(tok->str());
|
it = _obsoleteC99Functions.find(tok->str());
|
||||||
if (it != _obsoleteC99Functions.end()) {
|
if (it != _obsoleteC99Functions.end()) {
|
||||||
reportError(tok->tokAt(1), Severity::style, "obsoleteFunctions"+it->first, it->second);
|
reportError(tok->tokAt(1), Severity::style, "obsoleteFunctions"+it->first, it->second);
|
||||||
|
|
|
@ -44,8 +44,6 @@ Settings::Settings()
|
||||||
reportProgress = false;
|
reportProgress = false;
|
||||||
ifcfg = false;
|
ifcfg = false;
|
||||||
checkConfiguration = false;
|
checkConfiguration = false;
|
||||||
c99 = false;
|
|
||||||
posix = false;
|
|
||||||
|
|
||||||
// This assumes the code you are checking is for the same architecture this is compiled on.
|
// This assumes the code you are checking is for the same architecture this is compiled on.
|
||||||
#if defined(_WIN64)
|
#if defined(_WIN64)
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include "suppressions.h"
|
#include "suppressions.h"
|
||||||
|
#include "standards.h"
|
||||||
|
|
||||||
/// @addtogroup Core
|
/// @addtogroup Core
|
||||||
/// @{
|
/// @{
|
||||||
|
@ -182,14 +183,8 @@ public:
|
||||||
/** Is the 'configuration checking' wanted? */
|
/** Is the 'configuration checking' wanted? */
|
||||||
bool checkConfiguration;
|
bool checkConfiguration;
|
||||||
|
|
||||||
/** Code is posix - it is not compatible with non-posix environments */
|
/** Struct contains standards settings */
|
||||||
bool posix;
|
Standards standards;
|
||||||
|
|
||||||
/** 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;
|
|
||||||
|
|
||||||
/** size of standard types */
|
/** size of standard types */
|
||||||
unsigned int sizeof_bool;
|
unsigned int sizeof_bool;
|
||||||
|
|
|
@ -2401,7 +2401,7 @@ bool Tokenizer::tokenize(std::istream &code,
|
||||||
|
|
||||||
removeRedundantSemicolons();
|
removeRedundantSemicolons();
|
||||||
|
|
||||||
if (_settings->cpp11) {
|
if (_settings->standards.cpp11) {
|
||||||
for (Token *tok = _tokens; tok; tok = tok->next()) {
|
for (Token *tok = _tokens; tok; tok = tok->next()) {
|
||||||
if (tok->str() == "nullptr")
|
if (tok->str() == "nullptr")
|
||||||
tok->str("0");
|
tok->str("0");
|
||||||
|
|
|
@ -41,7 +41,7 @@ private:
|
||||||
|
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings.inconclusive = true;
|
settings.inconclusive = true;
|
||||||
settings.posix = true;
|
settings.standards.posix = true;
|
||||||
settings.experimental = experimental;
|
settings.experimental = experimental;
|
||||||
settings.addEnabled("style");
|
settings.addEnabled("style");
|
||||||
settings.addEnabled("portability");
|
settings.addEnabled("portability");
|
||||||
|
|
|
@ -552,7 +552,7 @@ private:
|
||||||
Settings settings;
|
Settings settings;
|
||||||
CmdLineParser parser(&settings);
|
CmdLineParser parser(&settings);
|
||||||
ASSERT(parser.ParseFromArgs(3, argv));
|
ASSERT(parser.ParseFromArgs(3, argv));
|
||||||
ASSERT(settings.posix);
|
ASSERT(settings.standards.posix);
|
||||||
}
|
}
|
||||||
|
|
||||||
void stdc99() {
|
void stdc99() {
|
||||||
|
@ -561,7 +561,7 @@ private:
|
||||||
Settings settings;
|
Settings settings;
|
||||||
CmdLineParser parser(&settings);
|
CmdLineParser parser(&settings);
|
||||||
ASSERT(parser.ParseFromArgs(3, argv));
|
ASSERT(parser.ParseFromArgs(3, argv));
|
||||||
ASSERT(settings.c99);
|
ASSERT(settings.standards.c99);
|
||||||
}
|
}
|
||||||
|
|
||||||
void stdcpp11() {
|
void stdcpp11() {
|
||||||
|
@ -570,7 +570,7 @@ private:
|
||||||
Settings settings;
|
Settings settings;
|
||||||
CmdLineParser parser(&settings);
|
CmdLineParser parser(&settings);
|
||||||
ASSERT(parser.ParseFromArgs(3, argv));
|
ASSERT(parser.ParseFromArgs(3, argv));
|
||||||
ASSERT(settings.cpp11);
|
ASSERT(settings.standards.cpp11);
|
||||||
}
|
}
|
||||||
|
|
||||||
void suppressionsOld() {
|
void suppressionsOld() {
|
||||||
|
|
|
@ -41,7 +41,7 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings.posix = true;
|
settings.standards.posix = true;
|
||||||
settings.addEnabled("portability");
|
settings.addEnabled("portability");
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
|
|
|
@ -62,7 +62,7 @@ private:
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings.addEnabled("style");
|
settings.addEnabled("style");
|
||||||
settings.inconclusive = inconclusive;
|
settings.inconclusive = inconclusive;
|
||||||
settings.cpp11 = cpp11;
|
settings.standards.cpp11 = cpp11;
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
|
|
|
@ -72,8 +72,8 @@ private:
|
||||||
|
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings.addEnabled("style");
|
settings.addEnabled("style");
|
||||||
settings.posix = true;
|
settings.standards.posix = true;
|
||||||
settings.c99 = true;
|
settings.standards.c99 = true;
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
|
|
Loading…
Reference in New Issue