Refactoring: Refactoring the Settings class

This commit is contained in:
Daniel Marjamäki 2010-04-17 09:23:54 +02:00
parent 3bab5f6bd6
commit c0e9a546f7
13 changed files with 36 additions and 77 deletions

View File

@ -24,7 +24,6 @@
#include <stdexcept>
Settings::Settings()
: inconclusive(false)
{
_debug = false;
_checkCodingStyle = false;
@ -38,46 +37,7 @@ Settings::Settings()
_showtime = 0; // TODO: use enum
_append = "";
_terminate = false;
}
Settings::Settings(const Settings &s)
: inconclusive(s.inconclusive)
{
*this = s;
}
// Constructor used in unit testing..
Settings::Settings(bool all)
: inconclusive(all)
{
Settings s;
*this = s; // This assigns all members except "inconclusive"
}
const Settings &Settings::operator=(const Settings & s)
{
if (&s == this)
return *this;
_debug = s._debug;
_checkCodingStyle = s._checkCodingStyle;
_errorsOnly = s._errorsOnly;
_inlineSuppressions = s._inlineSuppressions;
_verbose = s._verbose;
_force = s._force;
_xml = s._xml;
_jobs = s._jobs;
_exitCode = s._exitCode;
_showtime = s._showtime;
_append = s._append;
_terminate = s._terminate;
_outputFormat = s._outputFormat;
return *this;
}
Settings::~Settings()
{
inconclusive = false;
}

View File

@ -16,8 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SETTINGS_H
#define SETTINGS_H
#ifndef settingsH
#define settingsH
#include <list>
#include <string>
@ -49,25 +49,14 @@ private:
/** @brief terminate checking */
bool _terminate;
Settings(bool all);
public:
Settings();
Settings(const Settings &s);
const Settings &operator=(const Settings &s);
virtual ~Settings();
/** @brief Return test settings where inconclusive is true */
static Settings testSettings()
{
return Settings(true);
}
/** @brief Is --debug given? */
bool _debug;
/** @brief Inconclusive checks - for debugging of Cppcheck */
const bool inconclusive;
bool inconclusive;
/** @brief Is --style given? */
bool _checkCodingStyle;

View File

@ -53,7 +53,8 @@ private:
errout.str("");
// Check for buffer overruns..
Settings settings(showAll ? Settings::testSettings() : Settings());
Settings settings;
settings.inconclusive = showAll;
settings._checkCodingStyle = true;
CheckBufferOverrun checkBufferOverrun(&tokenizer, &settings, this);
checkBufferOverrun.bufferOverrun();

View File

@ -417,7 +417,8 @@ private:
errout.str("");
// Check..
Settings settings(Settings::testSettings());
Settings settings;
settings.inconclusive = true;
settings._checkCodingStyle = true;
CheckClass checkClass(&tokenizer, &settings, this);
checkClass.operatorEqToSelf();
@ -1391,7 +1392,8 @@ private:
errout.str("");
// Check..
Settings settings(Settings::testSettings());
Settings settings;
settings.inconclusive = true;
CheckClass checkClass(&tokenizer, &settings, this);
checkClass.constructors();
}
@ -2106,7 +2108,7 @@ private:
errout.str("");
// Check..
Settings settings(Settings::testSettings());
Settings settings;
settings._checkCodingStyle = true;
CheckClass checkClass(&tokenizer, &settings, this);
checkClass.thisSubtraction();

View File

@ -46,7 +46,8 @@ private:
errout.str("");
// Check class constructors..
Settings settings(showAll ? Settings::testSettings() : Settings());
Settings settings;
settings.inconclusive = showAll;
settings._checkCodingStyle = true;
CheckClass checkClass(&tokenizer, &settings, this);
checkClass.constructors();

View File

@ -53,7 +53,8 @@ private:
errout.str("");
// Check for dangerous functions..
Settings settings(Settings::testSettings());
Settings settings;
settings.inconclusive = true;
CheckDangerousFunctions checkDangerousFunctions(&tokenizer, &settings, this);
checkDangerousFunctions.dangerousFunctions();
}

View File

@ -46,7 +46,8 @@ private:
// Clear the error buffer..
errout.str("");
Settings settings(all ? Settings::testSettings() : Settings());
Settings settings;
settings.inconclusive = all;
settings._checkCodingStyle = style;
// Check for unsigned divisions..

View File

@ -47,9 +47,8 @@ private:
// Clear the error buffer..
errout.str("");
Settings settings(Settings::testSettings());
// Check for unused variables..
// Check for incomplete statements..
Settings settings;
CheckOther checkOther(&tokenizer, &settings, this);
checkOther.checkIncompleteStatement();
}

View File

@ -212,8 +212,8 @@ private:
errout.str("");
// Check for memory leaks..
Settings settings(showAll ? Settings::testSettings() : Settings());
settings._debug = true;
Settings settings;
settings.inconclusive = showAll;
tokenizer.fillFunctionList();
CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, &settings, this);
checkMemoryLeak.check();
@ -600,7 +600,8 @@ private:
}
}
Settings settings(all ? Settings::testSettings() : Settings());
Settings settings;
settings.inconclusive = all;
CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, &settings, NULL);
all = false;
checkMemoryLeak.simplifycode(tokens, all);
@ -2141,8 +2142,8 @@ private:
errout.str("");
// Check for memory leaks..
Settings settings(Settings::testSettings());
settings._debug = true;
Settings settings;
settings.inconclusive = true;
{
std::istringstream istr(_autoDealloc);
@ -2712,8 +2713,8 @@ private:
errout.str("");
// Check for memory leaks..
Settings settings(showAll ? Settings::testSettings() : Settings());
settings._debug = true;
Settings settings;
settings.inconclusive = true;
tokenizer.fillFunctionList();
CheckMemoryLeakInClass checkMemoryLeak(&tokenizer, &settings, this);
checkMemoryLeak.check();

View File

@ -1060,8 +1060,8 @@ private:
std::istringstream istr(filedata);
std::map<std::string, std::string> actual;
Settings settings;
settings._verbose = true;
settings._debug = true;
settings._verbose = true;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c");

View File

@ -3488,7 +3488,8 @@ private:
void checkSimplifyTypedef(const char code[])
{
// Tokenize..
Settings settings(Settings::testSettings());
Settings settings;
settings.inconclusive = true;
settings._checkCodingStyle = true;
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code);
@ -4255,7 +4256,8 @@ private:
void checkSimplifyEnum(const char code[])
{
// Tokenize..
Settings settings(Settings::testSettings());
Settings settings;
settings.inconclusive = true;
settings._checkCodingStyle = true;
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code);

View File

@ -92,7 +92,8 @@ private:
errout.str("");
// Check..
Settings settings(Settings::testSettings());
Settings settings;
settings.inconclusive = true;
settings._checkCodingStyle = true;
CheckStl checkStl;
checkStl.runSimplifiedChecks(&tokenizer, &settings, this);

View File

@ -3114,7 +3114,8 @@ private:
void checkSimplifyInitVar(const char code[], bool simplify = false)
{
// Tokenize..
Settings settings(Settings::testSettings());
Settings settings;
settings.inconclusive = true;
settings._checkCodingStyle = true;
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code);