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> #include <stdexcept>
Settings::Settings() Settings::Settings()
: inconclusive(false)
{ {
_debug = false; _debug = false;
_checkCodingStyle = false; _checkCodingStyle = false;
@ -38,46 +37,7 @@ Settings::Settings()
_showtime = 0; // TODO: use enum _showtime = 0; // TODO: use enum
_append = ""; _append = "";
_terminate = false; _terminate = false;
} inconclusive = 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()
{
} }

View File

@ -16,8 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef SETTINGS_H #ifndef settingsH
#define SETTINGS_H #define settingsH
#include <list> #include <list>
#include <string> #include <string>
@ -49,25 +49,14 @@ private:
/** @brief terminate checking */ /** @brief terminate checking */
bool _terminate; bool _terminate;
Settings(bool all);
public: public:
Settings(); 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? */ /** @brief Is --debug given? */
bool _debug; bool _debug;
/** @brief Inconclusive checks - for debugging of Cppcheck */ /** @brief Inconclusive checks - for debugging of Cppcheck */
const bool inconclusive; bool inconclusive;
/** @brief Is --style given? */ /** @brief Is --style given? */
bool _checkCodingStyle; bool _checkCodingStyle;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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