Tokenizer: add assert(_settings) to Tokenizer to insure the tokenizer always has settings. Ticket: #2219

This commit is contained in:
Robert Reif 2010-12-01 18:00:55 +01:00 committed by Daniel Marjamäki
parent b41447384c
commit f12c0c7ada
25 changed files with 706 additions and 404 deletions

View File

@ -1115,7 +1115,8 @@ std::list<std::string> Preprocessor::getcfgs(const std::string &filedata, const
void Preprocessor::simplifyCondition(const std::map<std::string, std::string> &variables, std::string &condition, bool match) void Preprocessor::simplifyCondition(const std::map<std::string, std::string> &variables, std::string &condition, bool match)
{ {
Tokenizer tokenizer; Settings settings;
Tokenizer tokenizer(&settings, NULL);
std::istringstream istr(("(" + condition + ")").c_str()); std::istringstream istr(("(" + condition + ")").c_str());
tokenizer.tokenize(istr, "", "", true); tokenizer.tokenize(istr, "", "", true);
@ -1307,7 +1308,7 @@ std::string Preprocessor::getcode(const std::string &filedata, std::string cfg,
if (line.find("=") != std::string::npos) if (line.find("=") != std::string::npos)
{ {
Tokenizer tokenizer; Tokenizer tokenizer(settings, NULL);
line.erase(0, sizeof("#pragma endasm")); line.erase(0, sizeof("#pragma endasm"));
std::istringstream tempIstr(line.c_str()); std::istringstream tempIstr(line.c_str());
tokenizer.tokenize(tempIstr, ""); tokenizer.tokenize(tempIstr, "");
@ -1732,6 +1733,8 @@ static void getparams(const std::string &line,
class PreprocessorMacro class PreprocessorMacro
{ {
private: private:
Settings settings;
/** tokens of this macro */ /** tokens of this macro */
Tokenizer tokenizer; Tokenizer tokenizer;
@ -1824,6 +1827,8 @@ public:
PreprocessorMacro(const std::string &macro) PreprocessorMacro(const std::string &macro)
: _macro(macro), _prefix("__cppcheck__") : _macro(macro), _prefix("__cppcheck__")
{ {
tokenizer.setSettings(&settings);
// Tokenize the macro to make it easier to handle // Tokenize the macro to make it easier to handle
std::istringstream istr(macro.c_str()); std::istringstream istr(macro.c_str());
tokenizer.createTokens(istr); tokenizer.createTokens(istr);

View File

@ -59,6 +59,9 @@ Tokenizer::Tokenizer()
Tokenizer::Tokenizer(const Settings *settings, ErrorLogger *errorLogger) Tokenizer::Tokenizer(const Settings *settings, ErrorLogger *errorLogger)
: _settings(settings), _errorLogger(errorLogger) : _settings(settings), _errorLogger(errorLogger)
{ {
// make sure settings are specified
assert(_settings);
_tokens = 0; _tokens = 0;
_tokensBack = 0; _tokensBack = 0;
_codeWithTemplates = false; _codeWithTemplates = false;
@ -1812,6 +1815,9 @@ bool Tokenizer::tokenize(std::istream &code,
const std::string &configuration, const std::string &configuration,
const bool preprocessorCondition) const bool preprocessorCondition)
{ {
// make sure settings specified
assert(_settings);
_configuration = configuration; _configuration = configuration;
// The "_files" vector remembers what files have been tokenized.. // The "_files" vector remembers what files have been tokenized..

View File

@ -521,6 +521,11 @@ public:
return _codeWithTemplates; return _codeWithTemplates;
} }
void setSettings(const Settings *settings)
{
_settings = settings;
}
private: private:
/** Disable copy constructor, no implementation */ /** Disable copy constructor, no implementation */
Tokenizer(const Tokenizer &); Tokenizer(const Tokenizer &);
@ -531,7 +536,7 @@ private:
Token *_tokens, *_tokensBack; Token *_tokens, *_tokensBack;
std::map<std::string, unsigned int> _typeSize; std::map<std::string, unsigned int> _typeSize;
std::vector<std::string> _files; std::vector<std::string> _files;
const Settings * const _settings; const Settings * _settings;
ErrorLogger * const _errorLogger; ErrorLogger * const _errorLogger;
/** E.g. "A" for code where "#ifdef A" is true. This is used to /** E.g. "A" for code where "#ifdef A" is true. This is used to

View File

@ -37,10 +37,14 @@ private:
void check(const char code[]) void check(const char code[])
{ {
// Tokenize.. // Clear the error buffer..
errout.str("");
Settings settings; Settings settings;
settings.debugwarnings = true; settings.debugwarnings = true;
Tokenizer tokenizer(&settings, 0);
// Tokenize..
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
@ -51,9 +55,6 @@ private:
// Fill function list // Fill function list
tokenizer.fillFunctionList(); tokenizer.fillFunctionList();
// Clear the error buffer..
errout.str("");
// Check auto variables // Check auto variables
CheckAutoVariables checkAutoVariables(&tokenizer, &settings, this); CheckAutoVariables checkAutoVariables(&tokenizer, &settings, this);
checkAutoVariables.autoVariables(); checkAutoVariables.autoVariables();

View File

@ -38,8 +38,15 @@ private:
void check(const char code[], bool inconclusive = true) void check(const char code[], bool inconclusive = true)
{ {
// Clear the error buffer..
errout.str("");
Settings settings;
settings.inconclusive = inconclusive;
settings._checkCodingStyle = true;
// Tokenize.. // Tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
@ -49,13 +56,7 @@ private:
// Fill function list // Fill function list
tokenizer.fillFunctionList(); tokenizer.fillFunctionList();
// Clear the error buffer..
errout.str("");
// Check for buffer overruns.. // Check for buffer overruns..
Settings settings;
settings.inconclusive = inconclusive;
settings._checkCodingStyle = true;
CheckBufferOverrun checkBufferOverrun(&tokenizer, &settings, this); CheckBufferOverrun checkBufferOverrun(&tokenizer, &settings, this);
checkBufferOverrun.bufferOverrun(); checkBufferOverrun.bufferOverrun();
checkBufferOverrun.negativeIndex(); checkBufferOverrun.negativeIndex();
@ -302,14 +303,16 @@ private:
void arrayInfo() void arrayInfo()
{ {
// Tokenize..
Tokenizer tokenizer;
std::istringstream istr("XY(1) const int a[2] = { 1, 2 };");
tokenizer.tokenize(istr, "test.cpp");
// Clear the error buffer.. // Clear the error buffer..
errout.str(""); errout.str("");
Settings settings;
// Tokenize..
Tokenizer tokenizer(&settings, this);
std::istringstream istr("XY(1) const int a[2] = { 1, 2 };");
tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifySizeof(); tokenizer.simplifySizeof();
CheckBufferOverrun::ArrayInfo ai; CheckBufferOverrun::ArrayInfo ai;
@ -2506,17 +2509,18 @@ private:
void epcheck(const char code[]) void epcheck(const char code[])
{ {
// Clear the error buffer..
errout.str("");
Settings settings;
// Tokenize.. // Tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
// Clear the error buffer..
errout.str("");
// Check for buffer overruns.. // Check for buffer overruns..
Settings settings;
CheckBufferOverrun checkBufferOverrun(&tokenizer, &settings, this); CheckBufferOverrun checkBufferOverrun(&tokenizer, &settings, this);
checkBufferOverrun.executionPaths(); checkBufferOverrun.executionPaths();
} }

View File

@ -45,18 +45,19 @@ private:
void check(const char code[]) void check(const char code[])
{ {
// Clear the error buffer..
errout.str("");
Settings settings;
settings._checkCodingStyle = true;
// Tokenize.. // Tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
tokenizer.setVarId(); tokenizer.setVarId();
// Clear the error buffer..
errout.str("");
// Check char variable usage.. // Check char variable usage..
Settings settings;
settings._checkCodingStyle = true;
CheckOther checkOther(&tokenizer, &settings, this); CheckOther checkOther(&tokenizer, &settings, this);
checkOther.checkCharVariable(); checkOther.checkCharVariable();
} }

View File

@ -179,18 +179,19 @@ private:
// Check the operator Equal // Check the operator Equal
void checkOpertorEq(const char code[]) void checkOpertorEq(const char code[])
{ {
// Clear the error log
errout.str("");
Settings settings;
settings._checkCodingStyle = true;
// Tokenize.. // Tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
// Clear the error log
errout.str("");
// Check.. // Check..
Settings settings;
settings._checkCodingStyle = true;
CheckClass checkClass(&tokenizer, &settings, this); CheckClass checkClass(&tokenizer, &settings, this);
checkClass.operatorEq(); checkClass.operatorEq();
} }
@ -250,18 +251,19 @@ private:
// Check that operator Equal returns reference to this // Check that operator Equal returns reference to this
void checkOpertorEqRetRefThis(const char code[]) void checkOpertorEqRetRefThis(const char code[])
{ {
// Clear the error log
errout.str("");
Settings settings;
settings._checkCodingStyle = true;
// Tokenize.. // Tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
// Clear the error log
errout.str("");
// Check.. // Check..
Settings settings;
settings._checkCodingStyle = true;
CheckClass checkClass(&tokenizer, &settings, this); CheckClass checkClass(&tokenizer, &settings, this);
checkClass.operatorEqRetRefThis(); checkClass.operatorEqRetRefThis();
} }
@ -463,18 +465,19 @@ private:
// Check that operator Equal checks for assignment to self // Check that operator Equal checks for assignment to self
void checkOpertorEqToSelf(const char code[]) void checkOpertorEqToSelf(const char code[])
{ {
// Clear the error log
errout.str("");
Settings settings;
settings._checkCodingStyle = true;
// Tokenize.. // Tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
// Clear the error log
errout.str("");
// Check.. // Check..
Settings settings;
settings._checkCodingStyle = true;
CheckClass checkClass(&tokenizer, &settings, this); CheckClass checkClass(&tokenizer, &settings, this);
checkClass.operatorEqToSelf(); checkClass.operatorEqToSelf();
} }
@ -1263,18 +1266,19 @@ private:
// Check that base classes have virtual destructors // Check that base classes have virtual destructors
void checkVirtualDestructor(const char code[]) void checkVirtualDestructor(const char code[])
{ {
// Clear the error log
errout.str("");
Settings settings;
settings.inconclusive = true;
// Tokenize.. // Tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
// Clear the error log
errout.str("");
// Check.. // Check..
Settings settings;
settings.inconclusive = true;
CheckClass checkClass(&tokenizer, &settings, this); CheckClass checkClass(&tokenizer, &settings, this);
checkClass.virtualDestructor(); checkClass.virtualDestructor();
} }
@ -1490,18 +1494,19 @@ private:
void checkUninitVar(const char code[]) void checkUninitVar(const char code[])
{ {
// Clear the error log
errout.str("");
Settings settings;
settings._checkCodingStyle = true;
// Tokenize.. // Tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
// Clear the error log
errout.str("");
// Check.. // Check..
Settings settings;
settings._checkCodingStyle = true;
CheckClass checkClass(&tokenizer, &settings, this); CheckClass checkClass(&tokenizer, &settings, this);
checkClass.constructors(); checkClass.constructors();
} }
@ -2490,18 +2495,19 @@ private:
void checkUninitVarJava(const char code[]) void checkUninitVarJava(const char code[])
{ {
// Clear the error log
errout.str("");
Settings settings;
settings._checkCodingStyle = true;
// Tokenize.. // Tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.java"); tokenizer.tokenize(istr, "test.java");
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
// Clear the error log
errout.str("");
// Check.. // Check..
Settings settings;
settings._checkCodingStyle = true;
CheckClass checkClass(&tokenizer, &settings, this); CheckClass checkClass(&tokenizer, &settings, this);
checkClass.constructors(); checkClass.constructors();
} }
@ -2518,18 +2524,19 @@ private:
void checkNoConstructor(const char code[]) void checkNoConstructor(const char code[])
{ {
// Clear the error log
errout.str("");
Settings settings;
settings._checkCodingStyle = true;
// Tokenize.. // Tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
// Clear the error log
errout.str("");
// Check.. // Check..
Settings settings;
settings._checkCodingStyle = true;
CheckClass checkClass(&tokenizer, &settings, this); CheckClass checkClass(&tokenizer, &settings, this);
checkClass.constructors(); checkClass.constructors();
} }
@ -2588,17 +2595,17 @@ private:
void checkNoMemset(const char code[]) void checkNoMemset(const char code[])
{ {
// Tokenize..
Tokenizer tokenizer;
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
// Clear the error log // Clear the error log
errout.str(""); errout.str("");
// Check..
Settings settings; Settings settings;
// Tokenize..
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
// Check..
CheckClass checkClass(&tokenizer, &settings, this); CheckClass checkClass(&tokenizer, &settings, this);
checkClass.noMemset(); checkClass.noMemset();
} }
@ -2691,18 +2698,19 @@ private:
void checkThisSubtraction(const char code[]) void checkThisSubtraction(const char code[])
{ {
// Clear the error log
errout.str("");
Settings settings;
settings._checkCodingStyle = true;
// Tokenize.. // Tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
// Clear the error log
errout.str("");
// Check.. // Check..
Settings settings;
settings._checkCodingStyle = true;
CheckClass checkClass(&tokenizer, &settings, this); CheckClass checkClass(&tokenizer, &settings, this);
checkClass.thisSubtraction(); checkClass.thisSubtraction();
} }
@ -2728,12 +2736,6 @@ private:
void checkConst(const char code[], const Settings *s = 0) void checkConst(const char code[], const Settings *s = 0)
{ {
// Tokenize..
Tokenizer tokenizer;
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList();
// Clear the error log // Clear the error log
errout.str(""); errout.str("");
@ -2743,6 +2745,13 @@ private:
settings = *s; settings = *s;
else else
settings._checkCodingStyle = true; settings._checkCodingStyle = true;
// Tokenize..
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList();
CheckClass checkClass(&tokenizer, &settings, this); CheckClass checkClass(&tokenizer, &settings, this);
checkClass.checkConst(); checkClass.checkConst();
} }

View File

@ -36,19 +36,20 @@ private:
void check(const char code[], bool showAll = false) void check(const char code[], bool showAll = false)
{ {
// Clear the error buffer..
errout.str("");
Settings settings;
settings.inconclusive = showAll;
settings._checkCodingStyle = true;
// Tokenize.. // Tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
// Clear the error buffer..
errout.str("");
// Check class constructors.. // Check class constructors..
Settings settings;
settings.inconclusive = showAll;
settings._checkCodingStyle = true;
CheckClass checkClass(&tokenizer, &settings, this); CheckClass checkClass(&tokenizer, &settings, this);
checkClass.constructors(); checkClass.constructors();
} }

View File

@ -38,17 +38,17 @@ public:
private: private:
void check(const char code[], bool style = true) void check(const char code[], bool style = true)
{ {
// Tokenize..
Tokenizer tokenizer;
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
// Clear the error buffer.. // Clear the error buffer..
errout.str(""); errout.str("");
Settings settings; Settings settings;
settings._checkCodingStyle = style; settings._checkCodingStyle = style;
// Tokenize..
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
// Check for unsigned divisions.. // Check for unsigned divisions..
CheckOther checkOther(&tokenizer, &settings, this); CheckOther checkOther(&tokenizer, &settings, this);
checkOther.checkUnsignedDivision(); checkOther.checkUnsignedDivision();

View File

@ -40,18 +40,19 @@ private:
void check(const std::string &code) void check(const std::string &code)
{ {
// Clear the error buffer..
errout.str("");
Settings settings;
settings.addEnabled("all");
// Tokenize.. // Tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code.c_str()); std::istringstream istr(code.c_str());
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
// Clear the error buffer..
errout.str("");
// Check char variable usage.. // Check char variable usage..
Settings settings;
settings.addEnabled("all");
CheckExceptionSafety checkExceptionSafety(&tokenizer, &settings, this); CheckExceptionSafety checkExceptionSafety(&tokenizer, &settings, this);
checkExceptionSafety.runSimplifiedChecks(&tokenizer, &settings, this); checkExceptionSafety.runSimplifiedChecks(&tokenizer, &settings, this);
} }

View File

@ -38,18 +38,19 @@ public:
private: private:
void check(const char code[]) void check(const char code[])
{ {
// Clear the error buffer..
errout.str("");
Settings settings;
settings._checkCodingStyle = true;
// Tokenize.. // Tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
// Clear the error buffer..
errout.str("");
// Check for incomplete statements.. // Check for incomplete statements..
Settings settings;
settings._checkCodingStyle = true;
CheckOther checkOther(&tokenizer, &settings, this); CheckOther checkOther(&tokenizer, &settings, this);
checkOther.checkIncompleteStatement(); checkOther.checkIncompleteStatement();
} }

View File

@ -45,18 +45,19 @@ private:
void check(const char code[]) void check(const char code[])
{ {
// Clear the error buffer..
errout.str("");
Settings settings;
// Tokenize.. // Tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
tokenizer.setVarId(); tokenizer.setVarId();
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
// Clear the error buffer..
errout.str("");
// Check for memory leaks.. // Check for memory leaks..
Settings settings;
CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, &settings, this); CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, &settings, this);
checkMemoryLeak.localleaks(); checkMemoryLeak.localleaks();
} }
@ -142,8 +143,13 @@ private:
CheckMemoryLeak::AllocType functionReturnType(const char code[]) CheckMemoryLeak::AllocType functionReturnType(const char code[])
{ {
// Clear the error buffer..
errout.str("");
Settings settings;
// Tokenize.. // Tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
tokenizer.setVarId(); tokenizer.setVarId();
@ -192,7 +198,13 @@ private:
" int ret = open();\n" " int ret = open();\n"
" }\n" " }\n"
"};\n"; "};\n";
Tokenizer tokenizer;
// Clear the error buffer..
errout.str("");
Settings settings;
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
@ -218,20 +230,22 @@ public:
private: private:
void check(const char code[], bool showAll = false) void check(const char code[], bool showAll = false)
{ {
// Clear the error buffer..
errout.str("");
Settings settings;
settings.inconclusive = showAll;
// Tokenize.. // Tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
tokenizer.setVarId(); tokenizer.setVarId();
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
// Clear the error buffer.. tokenizer.fillFunctionList();
errout.str("");
// Check for memory leaks.. // Check for memory leaks..
Settings settings;
settings.inconclusive = showAll;
tokenizer.fillFunctionList();
CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, &settings, this); CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, &settings, this);
checkMemoryLeak.checkReallocUsage(); checkMemoryLeak.checkReallocUsage();
checkMemoryLeak.check(); checkMemoryLeak.check();
@ -417,8 +431,13 @@ private:
std::string getcode(const char code[], const char varname[], bool classfunc=false) const std::string getcode(const char code[], const char varname[], bool classfunc=false) const
{ {
// Clear the error buffer..
errout.str("");
Settings settings;
// Tokenize.. // Tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, NULL);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
@ -426,7 +445,7 @@ private:
const unsigned int varId(Token::findmatch(tokenizer.tokens(), varname)->varId()); const unsigned int varId(Token::findmatch(tokenizer.tokens(), varname)->varId());
// getcode.. // getcode..
CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, 0, 0); CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, &settings, NULL);
checkMemoryLeak.parse_noreturn(); checkMemoryLeak.parse_noreturn();
std::list<const Token *> callstack; std::list<const Token *> callstack;
callstack.push_back(0); callstack.push_back(0);
@ -635,8 +654,13 @@ private:
std::string simplifycode(const char code[]) const std::string simplifycode(const char code[]) const
{ {
// Clear the error buffer..
errout.str("");
Settings settings;
// Tokenize.. // Tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, NULL);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
Token *tokens = const_cast<Token *>(tokenizer.tokens()); Token *tokens = const_cast<Token *>(tokenizer.tokens());
@ -657,7 +681,6 @@ private:
} }
} }
Settings settings;
CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, &settings, NULL); CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, &settings, NULL);
checkMemoryLeak.simplifycode(tokens); checkMemoryLeak.simplifycode(tokens);
@ -783,9 +806,13 @@ private:
// is there a leak in given code? if so, return the linenr // is there a leak in given code? if so, return the linenr
unsigned int dofindleak(const char code[]) const unsigned int dofindleak(const char code[]) const
{ {
// Tokenize.. // Clear the error buffer..
errout.str("");
Settings settings; Settings settings;
settings.debug = settings.debugwarnings = true; settings.debug = settings.debugwarnings = true;
// Tokenize..
Tokenizer tokenizer(&settings, NULL); Tokenizer tokenizer(&settings, NULL);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
@ -2479,22 +2506,20 @@ private:
void checkvcl(const char code[]) void checkvcl(const char code[])
{ {
// Tokenize..
Tokenizer tokenizer;
{
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
}
tokenizer.setVarId();
tokenizer.simplifyTokenList();
// Clear the error buffer.. // Clear the error buffer..
errout.str(""); errout.str("");
// Check for memory leaks..
Settings settings; Settings settings;
settings.inconclusive = true; settings.inconclusive = true;
// Tokenize..
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
tokenizer.setVarId();
tokenizer.simplifyTokenList();
// Check for memory leaks..
CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, &settings, this); CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, &settings, this);
checkMemoryLeak.check(); checkMemoryLeak.check();
} }
@ -3108,20 +3133,22 @@ private:
*/ */
void check(const char code[]) void check(const char code[])
{ {
// Clear the error buffer..
errout.str("");
Settings settings;
settings._checkCodingStyle = true;
// Tokenize.. // Tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
tokenizer.setVarId(); tokenizer.setVarId();
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
// Clear the error buffer.. tokenizer.fillFunctionList();
errout.str("");
// Check for memory leaks.. // Check for memory leaks..
Settings settings;
settings._checkCodingStyle = true;
tokenizer.fillFunctionList();
CheckMemoryLeakInClass checkMemoryLeak(&tokenizer, &settings, this); CheckMemoryLeakInClass checkMemoryLeak(&tokenizer, &settings, this);
checkMemoryLeak.check(); checkMemoryLeak.check();
} }
@ -3717,17 +3744,18 @@ public:
private: private:
void check(const char code[]) void check(const char code[])
{ {
// Clear the error buffer..
errout.str("");
Settings settings;
// Tokenize.. // Tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
// Clear the error buffer..
errout.str("");
// Check for memory leaks.. // Check for memory leaks..
Settings settings;
CheckMemoryLeakStructMember checkMemoryLeakStructMember(&tokenizer, &settings, this); CheckMemoryLeakStructMember checkMemoryLeakStructMember(&tokenizer, &settings, this);
checkMemoryLeakStructMember.check(); checkMemoryLeakStructMember.check();
} }
@ -3951,17 +3979,18 @@ public:
private: private:
void check(const char code[]) void check(const char code[])
{ {
// Clear the error buffer..
errout.str("");
Settings settings;
// Tokenize.. // Tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
// Clear the error buffer..
errout.str("");
// Check for memory leaks.. // Check for memory leaks..
Settings settings;
CheckMemoryLeakNoVar checkMemoryLeakNoVar(&tokenizer, &settings, this); CheckMemoryLeakNoVar checkMemoryLeakNoVar(&tokenizer, &settings, this);
checkMemoryLeakNoVar.check(); checkMemoryLeakNoVar.check();
} }

View File

@ -48,17 +48,18 @@ private:
void check(const char code[]) void check(const char code[])
{ {
// Tokenize..
Tokenizer tokenizer;
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
// Clear the error buffer.. // Clear the error buffer..
errout.str(""); errout.str("");
// Check for redundant code..
Settings settings; Settings settings;
settings._checkCodingStyle = true; settings._checkCodingStyle = true;
// Tokenize..
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
// Check for redundant code..
CheckNullPointer checkNullPointer(&tokenizer, &settings, this); CheckNullPointer checkNullPointer(&tokenizer, &settings, this);
checkNullPointer.nullPointer(); checkNullPointer.nullPointer();
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();

View File

@ -52,8 +52,15 @@ private:
void check(const char code[]) void check(const char code[])
{ {
// Clear the error buffer..
errout.str("");
Settings settings;
settings._checkCodingStyle = true;
settings.inconclusive = true;
// Tokenize.. // Tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
@ -64,13 +71,7 @@ private:
// Fill function list // Fill function list
tokenizer.fillFunctionList(); tokenizer.fillFunctionList();
// Clear the error buffer..
errout.str("");
// Check for obsolete functions.. // Check for obsolete functions..
Settings settings;
settings._checkCodingStyle = true;
settings.inconclusive = true;
CheckObsoleteFunctions checkObsoleteFunctions(&tokenizer, &settings, this); CheckObsoleteFunctions checkObsoleteFunctions(&tokenizer, &settings, this);
checkObsoleteFunctions.obsoleteFunctions(); checkObsoleteFunctions.obsoleteFunctions();
} }

View File

@ -96,19 +96,19 @@ private:
void check(const char code[]) void check(const char code[])
{ {
// Clear the error buffer..
errout.str("");
Settings settings;
settings._checkCodingStyle = true;
// Tokenize.. // Tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
// Check.. // Check..
Settings settings;
settings._checkCodingStyle = true;
CheckOther checkOther(&tokenizer, &settings, this); CheckOther checkOther(&tokenizer, &settings, this);
// Clear the error buffer..
errout.str("");
checkOther.sizeofsizeof(); checkOther.sizeofsizeof();
checkOther.sizeofCalculation(); checkOther.sizeofCalculation();
checkOther.checkRedundantAssignmentInSwitch(); checkOther.checkRedundantAssignmentInSwitch();
@ -239,19 +239,20 @@ private:
void sprintfUsage(const char code[]) void sprintfUsage(const char code[])
{ {
// Clear the error buffer..
errout.str("");
Settings settings;
// Tokenize.. // Tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
tokenizer.setVarId(); tokenizer.setVarId();
//tokenizer.tokens()->printOut( "tokens" ); //tokenizer.tokens()->printOut( "tokens" );
// Clear the error buffer..
errout.str("");
// Check for redundant code.. // Check for redundant code..
Settings settings;
CheckOther checkOther(&tokenizer, &settings, this); CheckOther checkOther(&tokenizer, &settings, this);
checkOther.invalidFunctionUsage(); checkOther.invalidFunctionUsage();
} }
@ -309,17 +310,18 @@ private:
void strPlusChar(const char code[]) void strPlusChar(const char code[])
{ {
// Clear the error buffer..
errout.str("");
Settings settings;
// Tokenize.. // Tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
tokenizer.setVarId(); tokenizer.setVarId();
// Clear the error buffer..
errout.str("");
// Check for redundant code.. // Check for redundant code..
Settings settings;
CheckOther checkOther(&tokenizer, &settings, this); CheckOther checkOther(&tokenizer, &settings, this);
checkOther.strPlusChar(); checkOther.strPlusChar();
} }
@ -369,17 +371,18 @@ private:
void varScope(const char code[]) void varScope(const char code[])
{ {
// Tokenize..
Tokenizer tokenizer;
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
// Clear the error buffer.. // Clear the error buffer..
errout.str(""); errout.str("");
// Check for redundant code..
Settings settings; Settings settings;
settings._checkCodingStyle = true; settings._checkCodingStyle = true;
// Tokenize..
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
// Check for redundant code..
CheckOther checkOther(&tokenizer, &settings, this); CheckOther checkOther(&tokenizer, &settings, this);
checkOther.checkVariableScope(); checkOther.checkVariableScope();
} }
@ -570,24 +573,23 @@ private:
void checkOldStylePointerCast(const char code[]) void checkOldStylePointerCast(const char code[])
{ {
// Clear the error buffer..
errout.str("");
Settings settings;
settings._checkCodingStyle = true;
// Tokenize.. // Tokenize..
Tokenizer tokenizerCpp; Tokenizer tokenizerCpp(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizerCpp.tokenize(istr, "test.cpp"); tokenizerCpp.tokenize(istr, "test.cpp");
tokenizerCpp.setVarId(); tokenizerCpp.setVarId();
Tokenizer tokenizerC; Tokenizer tokenizerC(&settings, this);
std::istringstream istr2(code); std::istringstream istr2(code);
tokenizerC.tokenize(istr2, "test.c"); tokenizerC.tokenize(istr2, "test.c");
tokenizerC.setVarId(); tokenizerC.setVarId();
// Clear the error buffer..
errout.str("");
// Check for redundant code..
Settings settings;
settings._checkCodingStyle = true;
CheckOther checkOtherCpp(&tokenizerCpp, &settings, this); CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);
checkOtherCpp.warningOldStylePointerCast(); checkOtherCpp.warningOldStylePointerCast();
@ -670,15 +672,16 @@ private:
void testPassedByValue(const char code[]) void testPassedByValue(const char code[])
{ {
Tokenizer tokenizer;
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
// Clear the error buffer.. // Clear the error buffer..
errout.str(""); errout.str("");
Settings settings; Settings settings;
settings._checkCodingStyle = true; settings._checkCodingStyle = true;
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
CheckOther checkOther(&tokenizer, &settings, this); CheckOther checkOther(&tokenizer, &settings, this);
checkOther.checkConstantFunctionParameter(); checkOther.checkConstantFunctionParameter();
} }
@ -1155,8 +1158,6 @@ private:
void trac1132() void trac1132()
{ {
errout.str("");
std::istringstream code("#include <iostream>\n" std::istringstream code("#include <iostream>\n"
"class Lock\n" "class Lock\n"
"{\n" "{\n"
@ -1178,12 +1179,14 @@ private:
"}\n" "}\n"
); );
Tokenizer tokenizer; errout.str("");
tokenizer.tokenize(code, "trac1132.cpp");
tokenizer.simplifyTokenList();
Settings settings; Settings settings;
Tokenizer tokenizer(&settings, this);
tokenizer.tokenize(code, "trac1132.cpp");
tokenizer.simplifyTokenList();
CheckOther checkOther(&tokenizer, &settings, this); CheckOther checkOther(&tokenizer, &settings, this);
checkOther.checkMisusedScopedObject(); checkOther.checkMisusedScopedObject();

View File

@ -37,8 +37,15 @@ private:
void check(const char code[]) void check(const char code[])
{ {
// Clear the error buffer..
errout.str("");
Settings settings;
settings._checkCodingStyle = true;
settings.inconclusive = true;
// Tokenize.. // Tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
@ -49,13 +56,7 @@ private:
// Fill function list // Fill function list
tokenizer.fillFunctionList(); tokenizer.fillFunctionList();
// Clear the error buffer..
errout.str("");
// Check for postfix operators.. // Check for postfix operators..
Settings settings;
settings._checkCodingStyle = true;
settings.inconclusive = true;
CheckPostfixOperator checkPostfixOperator(&tokenizer, &settings, this); CheckPostfixOperator checkPostfixOperator(&tokenizer, &settings, this);
checkPostfixOperator.postfixOperator(); checkPostfixOperator.postfixOperator();
} }

View File

@ -198,7 +198,8 @@ private:
{ {
const char code[] = " \t a //\n" const char code[] = " \t a //\n"
" #aa\t /* remove this */\tb \r\n"; " #aa\t /* remove this */\tb \r\n";
Preprocessor preprocessor(0,this); Settings settings;
Preprocessor preprocessor(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
std::string codestr(preprocessor.read(istr,"test.c",0)); std::string codestr(preprocessor.read(istr,"test.c",0));
ASSERT_EQUALS("a \n#aa b \n", codestr); ASSERT_EQUALS("a \n#aa b \n", codestr);
@ -207,7 +208,8 @@ private:
void readCode2() void readCode2()
{ {
const char code[] = "R\"( \" /* abc */ \n)\""; const char code[] = "R\"( \" /* abc */ \n)\"";
Preprocessor preprocessor(0,this); Settings settings;
Preprocessor preprocessor(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
std::string codestr(preprocessor.read(istr,"test.c",0)); std::string codestr(preprocessor.read(istr,"test.c",0));
ASSERT_EQUALS("\" \\\" /* abc */ \\n\"\n", codestr); ASSERT_EQUALS("\" \\\" /* abc */ \\n\"\n", codestr);
@ -266,7 +268,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -287,7 +290,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -307,7 +311,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -329,7 +334,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -351,7 +357,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -374,7 +381,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -393,7 +401,8 @@ private:
"#elif defined (A)\n"; "#elif defined (A)\n";
std::istringstream istr(filedata); std::istringstream istr(filedata);
Preprocessor preprocessor(0,this); Settings settings;
Preprocessor preprocessor(&settings, this);
const std::string actual(preprocessor.read(istr, "test.c", 0)); const std::string actual(preprocessor.read(istr, "test.c", 0));
// Compare results.. // Compare results..
@ -412,7 +421,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
errout.str(""); errout.str("");
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
@ -438,7 +448,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
errout.str(""); errout.str("");
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
@ -458,7 +469,8 @@ private:
// Read string.. // Read string..
std::istringstream istr(filedata); std::istringstream istr(filedata);
Preprocessor preprocessor(0,this); Settings settings;
Preprocessor preprocessor(&settings, this);
ASSERT_EQUALS("#error\n\n123", preprocessor.read(istr,"test.c",0)); ASSERT_EQUALS("#error\n\n123", preprocessor.read(istr,"test.c",0));
} }
@ -487,7 +499,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Expected configurations: "" and "ABC" // Expected configurations: "" and "ABC"
@ -507,7 +520,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Expected configurations: "" and "ABC" // Expected configurations: "" and "ABC"
@ -530,10 +544,11 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
Tokenizer tok; Tokenizer tok(&settings, this);
std::istringstream codeStream(actual[""]); std::istringstream codeStream(actual[""]);
tok.tokenize(codeStream, "main.cpp"); tok.tokenize(codeStream, "main.cpp");
@ -551,7 +566,8 @@ private:
// Preprocess // Preprocess
std::istringstream istr(filedata); std::istringstream istr(filedata);
Preprocessor preprocessor(0, this); Settings settings;
Preprocessor preprocessor(&settings, this);
ASSERT_EQUALS("\n\n\n", preprocessor.read(istr, "test.c", 0)); ASSERT_EQUALS("\n\n\n", preprocessor.read(istr, "test.c", 0));
} }
@ -568,7 +584,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -585,7 +602,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -602,7 +620,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -623,7 +642,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -640,7 +660,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -661,7 +682,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -683,7 +705,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -746,7 +769,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -767,7 +791,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -794,7 +819,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -820,7 +846,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -851,7 +878,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -874,7 +902,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -896,7 +925,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -916,7 +946,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -936,7 +967,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -952,7 +984,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -969,7 +1002,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -992,7 +1026,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -1156,7 +1191,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
Preprocessor preprocessor(0, this); Settings settings;
Preprocessor preprocessor(&settings, this);
ASSERT_EQUALS("#define str \"abc\" \"def\" \n\nabcdef = str;\n", preprocessor.read(istr, "test.c", 0)); ASSERT_EQUALS("#define str \"abc\" \"def\" \n\nabcdef = str;\n", preprocessor.read(istr, "test.c", 0));
} }
@ -1168,7 +1204,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
Preprocessor preprocessor(0, this); Settings settings;
Preprocessor preprocessor(&settings, this);
ASSERT_EQUALS("#define sqr(aa) aa * aa\n\nsqr(5);\n", preprocessor.read(istr, "test.c", 0)); ASSERT_EQUALS("#define sqr(aa) aa * aa\n\nsqr(5);\n", preprocessor.read(istr, "test.c", 0));
} }
@ -1180,7 +1217,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
Preprocessor preprocessor(0, this); Settings settings;
Preprocessor preprocessor(&settings, this);
ASSERT_EQUALS("const char *str = \"abcdefghi\"\n\n\n", preprocessor.read(istr, "test.c", 0)); ASSERT_EQUALS("const char *str = \"abcdefghi\"\n\n\n", preprocessor.read(istr, "test.c", 0));
} }
@ -1194,7 +1232,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -1219,7 +1258,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -1553,7 +1593,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -1665,7 +1706,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -1719,7 +1761,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -1791,7 +1834,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -1813,7 +1857,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -1831,7 +1876,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -1850,7 +1896,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -1883,7 +1930,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
ASSERT_EQUALS(expected, actual[""]); ASSERT_EQUALS(expected, actual[""]);
@ -1971,7 +2019,8 @@ private:
const std::string filedata("a\xC8"); const std::string filedata("a\xC8");
std::istringstream istr(filedata); std::istringstream istr(filedata);
errout.str(""); errout.str("");
Preprocessor preprocessor(0, this); Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.read(istr, "test.cpp", 0); preprocessor.read(istr, "test.cpp", 0);
ASSERT_EQUALS("[test.cpp:1]: (error) The code contains characters that are unhandled. Neither unicode nor extended ascii are supported. (line=1, character code=c8)\n", errout.str()); ASSERT_EQUALS("[test.cpp:1]: (error) The code contains characters that are unhandled. Neither unicode nor extended ascii are supported. (line=1, character code=c8)\n", errout.str());
} }
@ -1980,7 +2029,8 @@ private:
{ {
const std::string filedata("//\xC8"); const std::string filedata("//\xC8");
std::istringstream istr(filedata.c_str()); std::istringstream istr(filedata.c_str());
Preprocessor preprocessor(0, this); Settings settings;
Preprocessor preprocessor(&settings, this);
ASSERT_EQUALS("", preprocessor.read(istr, "test.cpp", 0)); ASSERT_EQUALS("", preprocessor.read(istr, "test.cpp", 0));
} }
@ -1988,7 +2038,8 @@ private:
{ {
const std::string filedata("\"\xC8\""); const std::string filedata("\"\xC8\"");
std::istringstream istr(filedata.c_str()); std::istringstream istr(filedata.c_str());
Preprocessor preprocessor(0, this); Settings settings;
Preprocessor preprocessor(&settings, this);
ASSERT_EQUALS(filedata, preprocessor.read(istr, "test.cpp", 0)); ASSERT_EQUALS(filedata, preprocessor.read(istr, "test.cpp", 0));
} }
@ -2004,7 +2055,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -2025,7 +2077,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -2046,7 +2099,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -2069,7 +2123,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor(0, this); Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c", std::list<std::string>()); preprocessor.preprocess(istr, actual, "file.c", std::list<std::string>());
// Compare results.. // Compare results..
@ -2090,7 +2145,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor(0, this); Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c", std::list<std::string>()); preprocessor.preprocess(istr, actual, "file.c", std::list<std::string>());
// Compare results.. // Compare results..
@ -2144,7 +2200,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -2166,7 +2223,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -2183,7 +2241,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -2200,7 +2259,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -2217,7 +2277,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -2236,7 +2297,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -2280,7 +2342,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
@ -2301,7 +2364,8 @@ private:
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Preprocessor preprocessor; Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..

View File

@ -712,9 +712,12 @@ private:
std::string elseif(const char code[]) std::string elseif(const char code[])
{ {
std::istringstream istr(code); errout.str("");
Tokenizer tokenizer; Settings settings;
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code);
tokenizer.createTokens(istr); tokenizer.createTokens(istr);
tokenizer.elseif(); tokenizer.elseif();
return tokenizer.tokens()->stringifyList(false); return tokenizer.tokens()->stringifyList(false);
@ -773,8 +776,11 @@ private:
// Simplify 'sizeof'.. // Simplify 'sizeof'..
std::string sizeof_(const char code[], bool simplify = true) std::string sizeof_(const char code[], bool simplify = true)
{ {
// tokenize.. errout.str("");
Settings settings; Settings settings;
// tokenize..
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
@ -798,7 +804,11 @@ private:
unsigned int sizeofFromTokenizer(const char type[]) unsigned int sizeofFromTokenizer(const char type[])
{ {
Tokenizer tokenizer; errout.str("");
Settings settings;
Tokenizer tokenizer(&settings, this);
std::istringstream istr(""); std::istringstream istr("");
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
@ -2072,8 +2082,10 @@ private:
" x(sizeof typename);\n" " x(sizeof typename);\n"
" type = 0;\n" " type = 0;\n"
"}"; "}";
errout.str("");
Settings settings;
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
Tokenizer tokenizer;
tokenizer.tokenize(istr, "test.c", "", false); tokenizer.tokenize(istr, "test.c", "", false);
std::ostringstream ostr; std::ostringstream ostr;
for (const Token *tok1 = tokenizer.tokens(); tok1; tok1 = tok1->next()) for (const Token *tok1 = tokenizer.tokens(); tok1; tok1 = tok1->next())
@ -2124,8 +2136,10 @@ private:
std::string simplifyIfAssign(const char code[]) std::string simplifyIfAssign(const char code[])
{ {
errout.str("");
Settings settings;
// tokenize.. // tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
@ -2203,8 +2217,10 @@ private:
std::string simplifyIfNot(const char code[]) std::string simplifyIfNot(const char code[])
{ {
errout.str("");
Settings settings;
// tokenize.. // tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
@ -2236,8 +2252,10 @@ private:
std::string simplifyLogicalOperators(const char code[]) std::string simplifyLogicalOperators(const char code[])
{ {
errout.str("");
Settings settings;
// tokenize.. // tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
@ -2562,8 +2580,10 @@ private:
" c();\n" " c();\n"
"}"; "}";
errout.str("");
Settings settings;
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
Tokenizer tokenizer;
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
tokenizer.validate(); tokenizer.validate();
@ -2595,8 +2615,10 @@ private:
"}"; "}";
errout.str("");
Settings settings;
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
Tokenizer tokenizer;
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
tokenizer.validate(); tokenizer.validate();
@ -3136,13 +3158,14 @@ private:
"typedef std::vector<Func> CallQueue;" "typedef std::vector<Func> CallQueue;"
"int main() {}"; "int main() {}";
Tokenizer tokenizer;
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
// Clear the error buffer.. // Clear the error buffer..
errout.str(""); errout.str("");
Settings settings;
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
@ -3163,13 +3186,14 @@ private:
" FP_M(val);" " FP_M(val);"
"};"; "};";
Tokenizer tokenizer;
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
// Clear the error buffer.. // Clear the error buffer..
errout.str(""); errout.str("");
Settings settings;
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
@ -3209,13 +3233,14 @@ private:
" CHFOO freem;\n" " CHFOO freem;\n"
"} STRFOO;"; "} STRFOO;";
Tokenizer tokenizer;
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
// Clear the error buffer.. // Clear the error buffer..
errout.str(""); errout.str("");
Settings settings;
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
@ -3240,13 +3265,14 @@ private:
const char code[] = "typedef vector<int[4]> a;\n" const char code[] = "typedef vector<int[4]> a;\n"
"a b;\n"; "a b;\n";
Tokenizer tokenizer;
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
// Clear the error buffer.. // Clear the error buffer..
errout.str(""); errout.str("");
Settings settings;
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
ASSERT_EQUALS(true, tokenizer.validate()); ASSERT_EQUALS(true, tokenizer.validate());
@ -3304,13 +3330,14 @@ private:
// ticket #1284 // ticket #1284
const char code[] = "typedef jobject invoke_t (jobject, Proxy *, Method *, JArray< jobject > *);"; const char code[] = "typedef jobject invoke_t (jobject, Proxy *, Method *, JArray< jobject > *);";
Tokenizer tokenizer;
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
// Clear the error buffer.. // Clear the error buffer..
errout.str(""); errout.str("");
Settings settings;
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
ASSERT_EQUALS(true, tokenizer.validate()); ASSERT_EQUALS(true, tokenizer.validate());
@ -3767,6 +3794,7 @@ private:
// Check simplifyTypedef // Check simplifyTypedef
void checkSimplifyTypedef(const char code[]) void checkSimplifyTypedef(const char code[])
{ {
errout.str("");
// Tokenize.. // Tokenize..
Settings settings; Settings settings;
settings.inconclusive = true; settings.inconclusive = true;
@ -3774,7 +3802,6 @@ private:
settings.debugwarnings = true; // show warnings about unhandled typedef settings.debugwarnings = true; // show warnings about unhandled typedef
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
errout.str("");
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
} }
@ -5576,13 +5603,13 @@ private:
// Check simplifyEnum // Check simplifyEnum
void checkSimplifyEnum(const char code[]) void checkSimplifyEnum(const char code[])
{ {
errout.str("");
// Tokenize.. // Tokenize..
Settings settings; Settings settings;
settings.inconclusive = true; 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);
errout.str("");
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
} }

View File

@ -107,19 +107,20 @@ private:
void check(const std::string &code) void check(const std::string &code)
{ {
// Clear the error buffer..
errout.str("");
Settings settings;
settings.inconclusive = true;
settings._checkCodingStyle = true;
// Tokenize.. // Tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code.c_str()); std::istringstream istr(code.c_str());
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
// Clear the error buffer..
errout.str("");
// Check.. // Check..
Settings settings;
settings.inconclusive = true;
settings._checkCodingStyle = true;
CheckStl checkStl; CheckStl checkStl;
checkStl.runSimplifiedChecks(&tokenizer, &settings, this); checkStl.runSimplifiedChecks(&tokenizer, &settings, this);
} }
@ -888,7 +889,8 @@ private:
" for ( \n" " for ( \n"
"}\n"; "}\n";
Tokenizer tokenizer(0, this); Settings settings;
Tokenizer tokenizer(&settings, this);
std::istringstream istr(src); std::istringstream istr(src);
ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp")); ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp"));
ASSERT_EQUALS("[test.cpp:3]: (error) Invalid number of character (() when these macros are defined: ''.\n", errout.str()); ASSERT_EQUALS("[test.cpp:3]: (error) Invalid number of character (() when these macros are defined: ''.\n", errout.str());

View File

@ -19,6 +19,7 @@
#include "testsuite.h" #include "testsuite.h"
#include "tokenize.h" #include "tokenize.h"
#include "token.h" #include "token.h"
#include "settings.h"
#include <cstring> #include <cstring>
@ -227,6 +228,7 @@ private:
private: private:
std::istringstream _sample; std::istringstream _sample;
const Token* _tokens; const Token* _tokens;
Settings _settings;
Tokenizer _tokenizer; Tokenizer _tokenizer;
public: public:
@ -234,6 +236,7 @@ private:
:_sample(sample) :_sample(sample)
,_tokens(NULL) ,_tokens(NULL)
{ {
_tokenizer.setSettings(&_settings);
_tokenizer.tokenize(_sample, "test.cpp"); _tokenizer.tokenize(_sample, "test.cpp");
_tokens = _tokenizer.tokens(); _tokens = _tokenizer.tokens();
} }

View File

@ -299,9 +299,10 @@ private:
{ {
errout.str(""); errout.str("");
// tokenize..
Settings settings; Settings settings;
settings.debugwarnings = true; settings.debugwarnings = true;
// tokenize..
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
@ -490,8 +491,12 @@ private:
{ {
std::string filedata(10000, 'a'); std::string filedata(10000, 'a');
errout.str("");
Settings settings;
// tokenize.. // tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(filedata); std::istringstream istr(filedata);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
@ -506,8 +511,12 @@ private:
{ {
const char code[] = "int *f(int *);"; const char code[] = "int *f(int *);";
errout.str("");
Settings settings;
// tokenize.. // tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
@ -524,8 +533,12 @@ private:
{ {
const char code[] = "t = (static_cast<std::vector<int> *>(&p));\n"; const char code[] = "t = (static_cast<std::vector<int> *>(&p));\n";
errout.str("");
Settings settings;
// tokenize.. // tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
@ -873,7 +886,11 @@ private:
std::string simplifyKnownVariables(const char code[]) std::string simplifyKnownVariables(const char code[])
{ {
Tokenizer tokenizer; errout.str("");
Settings settings;
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
@ -1915,7 +1932,11 @@ private:
std::string tokenizeDebugListing(const std::string &code, bool simplify = false) std::string tokenizeDebugListing(const std::string &code, bool simplify = false)
{ {
Tokenizer tokenizer; errout.str("");
Settings settings;
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
@ -3018,8 +3039,12 @@ private:
"#endfile\n" "#endfile\n"
"a3\n"; "a3\n";
errout.str("");
Settings settings;
// tokenize.. // tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "a"); tokenizer.tokenize(istr, "a");
@ -3050,8 +3075,12 @@ private:
"#endfile\n" "#endfile\n"
"a5\n"; "a5\n";
errout.str("");
Settings settings;
// tokenize.. // tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "a"); tokenizer.tokenize(istr, "a");
@ -3071,12 +3100,15 @@ private:
"123\n" "123\n"
"#endfile\n"; "#endfile\n";
errout.str("");
Settings settings;
// tokenize.. // tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "a.cpp"); tokenizer.tokenize(istr, "a.cpp");
ASSERT_EQUALS("[c:\\a.h:1]", tokenizer.fileLine(tokenizer.tokens())); ASSERT_EQUALS("[c:\\a.h:1]", tokenizer.fileLine(tokenizer.tokens()));
} }
@ -3087,8 +3119,12 @@ private:
{ {
const char code[] = "TEST(var,val) var##_##val = val\n"; const char code[] = "TEST(var,val) var##_##val = val\n";
errout.str("");
Settings settings;
// Tokenize.. // Tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, ""); tokenizer.tokenize(istr, "");
@ -3104,8 +3140,12 @@ private:
{ {
const char code[] = "DBG(fmt,args...) printf(fmt, ## args)\n"; const char code[] = "DBG(fmt,args...) printf(fmt, ## args)\n";
errout.str("");
Settings settings;
// Tokenize.. // Tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, ""); tokenizer.tokenize(istr, "");
@ -3156,8 +3196,12 @@ private:
" free(((void*)p));\n" " free(((void*)p));\n"
"}"; "}";
errout.str("");
Settings settings;
// tokenize.. // tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
@ -3177,8 +3221,12 @@ private:
" return;\n" " return;\n"
"}"; "}";
errout.str("");
Settings settings;
// tokenize.. // tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
@ -3198,8 +3246,12 @@ private:
" if (( true )==(true)){}\n" " if (( true )==(true)){}\n"
"}"; "}";
errout.str("");
Settings settings;
// tokenize.. // tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
@ -3217,8 +3269,12 @@ private:
" if (( 2 )==(2)){}\n" " if (( 2 )==(2)){}\n"
"}"; "}";
errout.str("");
Settings settings;
// tokenize.. // tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
@ -3236,8 +3292,12 @@ private:
" if( g(10)){}\n" " if( g(10)){}\n"
"}"; "}";
errout.str("");
Settings settings;
// tokenize.. // tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
@ -3258,8 +3318,12 @@ private:
" (free(p));\n" " (free(p));\n"
"}"; "}";
errout.str("");
Settings settings;
// tokenize.. // tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
@ -3280,8 +3344,12 @@ private:
" (delete p);\n" " (delete p);\n"
"}"; "}";
errout.str("");
Settings settings;
// tokenize.. // tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
@ -3300,8 +3368,12 @@ private:
" (delete [] p);\n" " (delete [] p);\n"
"}"; "}";
errout.str("");
Settings settings;
// tokenize.. // tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
@ -3319,8 +3391,12 @@ private:
{ {
const char code[] = "(!(abc.a))"; const char code[] = "(!(abc.a))";
errout.str("");
Settings settings;
// tokenize.. // tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
@ -3336,8 +3412,12 @@ private:
{ {
const char code[] = ";char *p; (delete(p), (p)=0);"; const char code[] = ";char *p; (delete(p), (p)=0);";
errout.str("");
Settings settings;
// tokenize.. // tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
@ -3379,8 +3459,12 @@ private:
" int e = 4+2;\n" " int e = 4+2;\n"
"}\n"; "}\n";
errout.str("");
Settings settings;
// tokenize.. // tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
@ -3402,8 +3486,12 @@ private:
"};\n" "};\n"
"}\n"; "}\n";
errout.str("");
Settings settings;
// tokenize.. // tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
@ -3428,8 +3516,12 @@ private:
"int a = 2;\n" "int a = 2;\n"
"}\n"; "}\n";
errout.str("");
Settings settings;
// tokenize.. // tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
@ -3452,8 +3544,12 @@ private:
"foo2->a=a;\n" "foo2->a=a;\n"
"}\n"; "}\n";
errout.str("");
Settings settings;
// tokenize.. // tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
@ -3689,7 +3785,8 @@ private:
{ {
errout.str(""); errout.str("");
const char code[] = "void f() {}"; const char code[] = "void f() {}";
Tokenizer tokenizer(0, this); Settings settings;
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
ASSERT_EQUALS(true, tokenizer.tokenize(istr, "test.cpp")); ASSERT_EQUALS(true, tokenizer.tokenize(istr, "test.cpp"));
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
@ -3698,7 +3795,8 @@ private:
{ {
errout.str(""); errout.str("");
const char code[] = "void f() {{}"; const char code[] = "void f() {{}";
Tokenizer tokenizer(0, this); Settings settings;
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp")); ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp"));
ASSERT_EQUALS("[test.cpp:1]: (error) Invalid number of character ({) when these macros are defined: ''.\n", errout.str()); ASSERT_EQUALS("[test.cpp:1]: (error) Invalid number of character ({) when these macros are defined: ''.\n", errout.str());
@ -3707,7 +3805,8 @@ private:
{ {
errout.str(""); errout.str("");
const char code[] = "void f()) {}"; const char code[] = "void f()) {}";
Tokenizer tokenizer(0, this); Settings settings;
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp")); ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp"));
ASSERT_EQUALS("[test.cpp:1]: (error) Invalid number of character (() when these macros are defined: ''.\n", errout.str()); ASSERT_EQUALS("[test.cpp:1]: (error) Invalid number of character (() when these macros are defined: ''.\n", errout.str());
@ -3716,7 +3815,8 @@ private:
{ {
errout.str(""); errout.str("");
const char code[] = "namespace extract{\nB(weighted_moment)\n}\nusing extract::weighted_moment;\n"; const char code[] = "namespace extract{\nB(weighted_moment)\n}\nusing extract::weighted_moment;\n";
Tokenizer tokenizer(0, this); Settings settings;
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
ASSERT_EQUALS(true, tokenizer.tokenize(istr, "test.cpp")); ASSERT_EQUALS(true, tokenizer.tokenize(istr, "test.cpp"));
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
@ -3729,7 +3829,8 @@ private:
"{\n" "{\n"
" foo(;\n" " foo(;\n"
"}\n"; "}\n";
Tokenizer tokenizer(0, this); Settings settings;
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp", "ABC")); ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp", "ABC"));
ASSERT_EQUALS("[test.cpp:3]: (error) Invalid number of character (() when these macros are defined: 'ABC'.\n", errout.str()); ASSERT_EQUALS("[test.cpp:3]: (error) Invalid number of character (() when these macros are defined: 'ABC'.\n", errout.str());
@ -3741,7 +3842,8 @@ private:
"{\n" "{\n"
" for(;;){ foo();\n" " for(;;){ foo();\n"
"}\n"; "}\n";
Tokenizer tokenizer(0, this); Settings settings;
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp")); ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp"));
ASSERT_EQUALS("[test.cpp:2]: (error) Invalid number of character ({) when these macros are defined: ''.\n", errout.str()); ASSERT_EQUALS("[test.cpp:2]: (error) Invalid number of character ({) when these macros are defined: ''.\n", errout.str());
@ -3753,7 +3855,8 @@ private:
"{\n" "{\n"
" a[10;\n" " a[10;\n"
"}\n"; "}\n";
Tokenizer tokenizer(0, this); Settings settings;
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp")); ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp"));
ASSERT_EQUALS("[test.cpp:3]: (error) Invalid number of character ([) when these macros are defined: ''.\n", errout.str()); ASSERT_EQUALS("[test.cpp:3]: (error) Invalid number of character ([) when these macros are defined: ''.\n", errout.str());
@ -3767,7 +3870,8 @@ private:
"{\n" "{\n"
" b());\n" " b());\n"
"}\n"; "}\n";
Tokenizer tokenizer(0, this); Settings settings;
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp")); ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp"));
ASSERT_EQUALS("[test.cpp:2]: (error) Invalid number of character (() when these macros are defined: ''.\n", errout.str()); ASSERT_EQUALS("[test.cpp:2]: (error) Invalid number of character (() when these macros are defined: ''.\n", errout.str());
@ -3781,7 +3885,8 @@ private:
{ {
errout.str(""); errout.str("");
std::istringstream istr("x<y>z> xyz;\n"); std::istringstream istr("x<y>z> xyz;\n");
Tokenizer tokenizer(0, this); Settings settings;
Tokenizer tokenizer(&settings, this);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
@ -3790,7 +3895,8 @@ private:
{ {
errout.str(""); errout.str("");
std::istringstream istr("template<class T> operator<(T a, T b) { }\n"); std::istringstream istr("template<class T> operator<(T a, T b) { }\n");
Tokenizer tokenizer(0, this); Settings settings;
Tokenizer tokenizer(&settings, this);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
@ -3800,7 +3906,8 @@ private:
errout.str(""); errout.str("");
std::istringstream istr("void f(a) int a;\n" std::istringstream istr("void f(a) int a;\n"
"{ ;x<y; }"); "{ ;x<y; }");
Tokenizer tokenizer(0, this); Settings settings;
Tokenizer tokenizer(&settings, this);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
@ -3810,7 +3917,8 @@ private:
errout.str(""); errout.str("");
std::istringstream istr("void f()\n" std::istringstream istr("void f()\n"
"try { ;x<y; }"); "try { ;x<y; }");
Tokenizer tokenizer(0, this); Settings settings;
Tokenizer tokenizer(&settings, this);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
@ -3819,7 +3927,8 @@ private:
{ {
errout.str(""); errout.str("");
std::istringstream istr("x<y<int> xyz;\n"); std::istringstream istr("x<y<int> xyz;\n");
Tokenizer tokenizer(0, this); Settings settings;
Tokenizer tokenizer(&settings, this);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str()); ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
} }
@ -3833,7 +3942,8 @@ private:
" , ConcreteVisitable\n" " , ConcreteVisitable\n"
" , Dummy< _visitableIndex >\n" " , Dummy< _visitableIndex >\n"
" >::type ConcreteVisitableOrDummy;\n"); " >::type ConcreteVisitableOrDummy;\n");
Tokenizer tokenizer(0, this); Settings settings;
Tokenizer tokenizer(&settings, this);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
ASSERT_EQUALS("[test.cpp:2]: (error) syntax error\n", errout.str()); ASSERT_EQUALS("[test.cpp:2]: (error) syntax error\n", errout.str());
} }
@ -3952,7 +4062,9 @@ private:
const char code[] = "class A{\n" const char code[] = "class A{\n"
" void f() {}\n" " void f() {}\n"
"};"; "};";
Tokenizer tokenizer; errout.str("");
Settings settings;
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
const Token *tok = tokenizer.tokens(); const Token *tok = tokenizer.tokens();
@ -3974,7 +4086,9 @@ private:
" char a[10];\n" " char a[10];\n"
" char *b ; b = new char[a[0]];\n" " char *b ; b = new char[a[0]];\n"
"};"; "};";
Tokenizer tokenizer; errout.str("");
Settings settings;
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
const Token *tok = tokenizer.tokens(); const Token *tok = tokenizer.tokens();
@ -3995,7 +4109,9 @@ private:
const char code[] = "void f(){\n" const char code[] = "void f(){\n"
" foo(g());\n" " foo(g());\n"
"};"; "};";
Tokenizer tokenizer; errout.str("");
Settings settings;
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
const Token *tok = tokenizer.tokens(); const Token *tok = tokenizer.tokens();
@ -4065,7 +4181,9 @@ private:
void simplifyString() void simplifyString()
{ {
Tokenizer tokenizer; errout.str("");
Settings settings;
Tokenizer tokenizer(&settings, this);
ASSERT_EQUALS("\"abc\"", tokenizer.simplifyString("\"abc\"")); ASSERT_EQUALS("\"abc\"", tokenizer.simplifyString("\"abc\""));
ASSERT_EQUALS("\"a\"", tokenizer.simplifyString("\"\\x3\"")); ASSERT_EQUALS("\"a\"", tokenizer.simplifyString("\"\\x3\""));
ASSERT_EQUALS("\"a\"", tokenizer.simplifyString("\"\\x33\"")); ASSERT_EQUALS("\"a\"", tokenizer.simplifyString("\"\\x33\""));
@ -4102,7 +4220,9 @@ private:
std::string simplifyFunctionPointers(const char code[]) std::string simplifyFunctionPointers(const char code[])
{ {
Tokenizer tokenizer; errout.str("");
Settings settings;
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyFunctionPointers(); tokenizer.simplifyFunctionPointers();
@ -4205,8 +4325,10 @@ private:
std::string arraySize_(const std::string &code) std::string arraySize_(const std::string &code)
{ {
errout.str("");
Settings settings;
// tokenize.. // tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code.c_str()); std::istringstream istr(code.c_str());
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
@ -4725,8 +4847,10 @@ private:
std::string javatest(const char javacode[]) std::string javatest(const char javacode[])
{ {
errout.str("");
Settings settings;
// tokenize.. // tokenize..
Tokenizer tokenizer(0, this); Tokenizer tokenizer(&settings, this);
std::istringstream istr(javacode); std::istringstream istr(javacode);
tokenizer.tokenize(istr, "test.java"); tokenizer.tokenize(istr, "test.java");

View File

@ -50,17 +50,18 @@ private:
void checkUninitVar(const char code[]) void checkUninitVar(const char code[])
{ {
// Clear the error buffer..
errout.str("");
Settings settings;
// Tokenize.. // Tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
// Clear the error buffer..
errout.str("");
// Check for redundant code.. // Check for redundant code..
Settings settings;
CheckUninitVar check(&tokenizer, &settings, this); CheckUninitVar check(&tokenizer, &settings, this);
check.executionPaths(); check.executionPaths();
} }
@ -1187,8 +1188,13 @@ private:
std::string analyseFunctions(const char code[]) std::string analyseFunctions(const char code[])
{ {
// Clear the error buffer..
errout.str("");
Settings settings;
// Tokenize.. // Tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");

View File

@ -51,17 +51,18 @@ private:
void check(const char code[]) void check(const char code[])
{ {
// Tokenize..
Tokenizer tokenizer;
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
// Clear the error buffer.. // Clear the error buffer..
errout.str(""); errout.str("");
// Check for unused functions..
Settings settings; Settings settings;
settings._checkCodingStyle = true; settings._checkCodingStyle = true;
// Tokenize..
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
// Check for unused functions..
CheckUnusedFunctions checkUnusedFunctions(&tokenizer, &settings, this); CheckUnusedFunctions checkUnusedFunctions(&tokenizer, &settings, this);
checkUnusedFunctions.parseTokens(tokenizer); checkUnusedFunctions.parseTokens(tokenizer);
checkUnusedFunctions.check(this); checkUnusedFunctions.check(this);
@ -198,7 +199,12 @@ private:
std::ostringstream fname; std::ostringstream fname;
fname << "test" << i << ".cpp"; fname << "test" << i << ".cpp";
Tokenizer tokenizer; // Clear the error buffer..
errout.str("");
Settings settings;
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, fname.str().c_str()); tokenizer.tokenize(istr, fname.str().c_str());

View File

@ -62,18 +62,19 @@ private:
void check(const char code[]) void check(const char code[])
{ {
// Clear the error buffer..
errout.str("");
Settings settings;
settings._checkCodingStyle = true;
// Tokenize.. // Tokenize..
Tokenizer tokenizer; Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
// Clear the error buffer..
errout.str("");
// Check for unused private functions.. // Check for unused private functions..
Settings settings;
settings._checkCodingStyle = true;
CheckClass checkClass(&tokenizer, &settings, this); CheckClass checkClass(&tokenizer, &settings, this);
checkClass.privateFunctions(); checkClass.privateFunctions();
} }

View File

@ -111,18 +111,18 @@ private:
void checkStructMemberUsage(const char code[]) void checkStructMemberUsage(const char code[])
{ {
// Tokenize..
Tokenizer tokenizer;
std::istringstream istr(code);
// Clear the error buffer.. // Clear the error buffer..
errout.str(""); errout.str("");
Settings settings;
settings._checkCodingStyle = true;
// Tokenize..
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
// Check for unused variables.. // Check for unused variables..
Settings settings;
settings._checkCodingStyle = true;
CheckOther checkOther(&tokenizer, &settings, this); CheckOther checkOther(&tokenizer, &settings, this);
checkOther.checkStructMemberUsage(); checkOther.checkStructMemberUsage();
} }
@ -339,18 +339,18 @@ private:
void functionVariableUsage(const char code[]) void functionVariableUsage(const char code[])
{ {
// Tokenize..
Tokenizer tokenizer;
std::istringstream istr(code);
// Clear the error buffer.. // Clear the error buffer..
errout.str(""); errout.str("");
Settings settings;
settings._checkCodingStyle = true;
// Tokenize..
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
// Check for unused variables.. // Check for unused variables..
Settings settings;
settings._checkCodingStyle = true;
CheckOther checkOther(&tokenizer, &settings, this); CheckOther checkOther(&tokenizer, &settings, this);
checkOther.functionVariableUsage(); checkOther.functionVariableUsage();
} }