From f12c0c7ada68d222e95434bbec5012306229d758 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Wed, 1 Dec 2010 18:00:55 +0100 Subject: [PATCH] Tokenizer: add assert(_settings) to Tokenizer to insure the tokenizer always has settings. Ticket: #2219 --- lib/preprocessor.cpp | 9 +- lib/tokenize.cpp | 6 + lib/tokenize.h | 7 +- test/testautovariables.cpp | 11 +- test/testbufferoverrun.cpp | 38 +++--- test/testcharvar.cpp | 13 +- test/testclass.cpp | 131 ++++++++++--------- test/testconstructors.cpp | 15 ++- test/testdivision.cpp | 10 +- test/testexceptionsafety.cpp | 13 +- test/testincompletestatement.cpp | 13 +- test/testmemleak.cpp | 117 ++++++++++------- test/testnullpointer.cpp | 13 +- test/testobsoletefunctions.cpp | 15 ++- test/testother.cpp | 85 ++++++------ test/testpostfixoperator.cpp | 15 ++- test/testpreprocessor.cpp | 194 ++++++++++++++++++--------- test/testsimplifytokens.cpp | 91 ++++++++----- test/teststl.cpp | 18 +-- test/testtoken.cpp | 3 + test/testtokenize.cpp | 218 ++++++++++++++++++++++++------- test/testuninitvar.cpp | 18 ++- test/testunusedfunctions.cpp | 20 ++- test/testunusedprivfunc.cpp | 13 +- test/testunusedvar.cpp | 24 ++-- 25 files changed, 706 insertions(+), 404 deletions(-) diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index a181064eb..6995a018a 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -1115,7 +1115,8 @@ std::list Preprocessor::getcfgs(const std::string &filedata, const void Preprocessor::simplifyCondition(const std::map &variables, std::string &condition, bool match) { - Tokenizer tokenizer; + Settings settings; + Tokenizer tokenizer(&settings, NULL); std::istringstream istr(("(" + condition + ")").c_str()); 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) { - Tokenizer tokenizer; + Tokenizer tokenizer(settings, NULL); line.erase(0, sizeof("#pragma endasm")); std::istringstream tempIstr(line.c_str()); tokenizer.tokenize(tempIstr, ""); @@ -1732,6 +1733,8 @@ static void getparams(const std::string &line, class PreprocessorMacro { private: + Settings settings; + /** tokens of this macro */ Tokenizer tokenizer; @@ -1824,6 +1827,8 @@ public: PreprocessorMacro(const std::string ¯o) : _macro(macro), _prefix("__cppcheck__") { + tokenizer.setSettings(&settings); + // Tokenize the macro to make it easier to handle std::istringstream istr(macro.c_str()); tokenizer.createTokens(istr); diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index c6a59fe23..5fbca28aa 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -59,6 +59,9 @@ Tokenizer::Tokenizer() Tokenizer::Tokenizer(const Settings *settings, ErrorLogger *errorLogger) : _settings(settings), _errorLogger(errorLogger) { + // make sure settings are specified + assert(_settings); + _tokens = 0; _tokensBack = 0; _codeWithTemplates = false; @@ -1812,6 +1815,9 @@ bool Tokenizer::tokenize(std::istream &code, const std::string &configuration, const bool preprocessorCondition) { + // make sure settings specified + assert(_settings); + _configuration = configuration; // The "_files" vector remembers what files have been tokenized.. diff --git a/lib/tokenize.h b/lib/tokenize.h index 8cd5c6466..8605398ce 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -521,6 +521,11 @@ public: return _codeWithTemplates; } + void setSettings(const Settings *settings) + { + _settings = settings; + } + private: /** Disable copy constructor, no implementation */ Tokenizer(const Tokenizer &); @@ -531,7 +536,7 @@ private: Token *_tokens, *_tokensBack; std::map _typeSize; std::vector _files; - const Settings * const _settings; + const Settings * _settings; ErrorLogger * const _errorLogger; /** E.g. "A" for code where "#ifdef A" is true. This is used to diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index 80639b23c..c721d685c 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -37,10 +37,14 @@ private: void check(const char code[]) { - // Tokenize.. + // Clear the error buffer.. + errout.str(""); + Settings settings; settings.debugwarnings = true; - Tokenizer tokenizer(&settings, 0); + + // Tokenize.. + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); tokenizer.simplifyTokenList(); @@ -51,9 +55,6 @@ private: // Fill function list tokenizer.fillFunctionList(); - // Clear the error buffer.. - errout.str(""); - // Check auto variables CheckAutoVariables checkAutoVariables(&tokenizer, &settings, this); checkAutoVariables.autoVariables(); diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index b9055c30f..847d808ea 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -38,8 +38,15 @@ private: void check(const char code[], bool inconclusive = true) { + // Clear the error buffer.. + errout.str(""); + + Settings settings; + settings.inconclusive = inconclusive; + settings._checkCodingStyle = true; + // Tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); @@ -49,13 +56,7 @@ private: // Fill function list tokenizer.fillFunctionList(); - // Clear the error buffer.. - errout.str(""); - // Check for buffer overruns.. - Settings settings; - settings.inconclusive = inconclusive; - settings._checkCodingStyle = true; CheckBufferOverrun checkBufferOverrun(&tokenizer, &settings, this); checkBufferOverrun.bufferOverrun(); checkBufferOverrun.negativeIndex(); @@ -302,14 +303,16 @@ private: 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.. 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(); CheckBufferOverrun::ArrayInfo ai; @@ -2506,17 +2509,18 @@ private: void epcheck(const char code[]) { + // Clear the error buffer.. + errout.str(""); + + Settings settings; + // Tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); tokenizer.simplifyTokenList(); - // Clear the error buffer.. - errout.str(""); - // Check for buffer overruns.. - Settings settings; CheckBufferOverrun checkBufferOverrun(&tokenizer, &settings, this); checkBufferOverrun.executionPaths(); } diff --git a/test/testcharvar.cpp b/test/testcharvar.cpp index b9b82d1b8..d8d0d7236 100644 --- a/test/testcharvar.cpp +++ b/test/testcharvar.cpp @@ -45,18 +45,19 @@ private: void check(const char code[]) { + // Clear the error buffer.. + errout.str(""); + + Settings settings; + settings._checkCodingStyle = true; + // Tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); tokenizer.setVarId(); - // Clear the error buffer.. - errout.str(""); - // Check char variable usage.. - Settings settings; - settings._checkCodingStyle = true; CheckOther checkOther(&tokenizer, &settings, this); checkOther.checkCharVariable(); } diff --git a/test/testclass.cpp b/test/testclass.cpp index 4861919f5..35e97109c 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -179,18 +179,19 @@ private: // Check the operator Equal void checkOpertorEq(const char code[]) { + // Clear the error log + errout.str(""); + + Settings settings; + settings._checkCodingStyle = true; + // Tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); tokenizer.simplifyTokenList(); - // Clear the error log - errout.str(""); - // Check.. - Settings settings; - settings._checkCodingStyle = true; CheckClass checkClass(&tokenizer, &settings, this); checkClass.operatorEq(); } @@ -250,18 +251,19 @@ private: // Check that operator Equal returns reference to this void checkOpertorEqRetRefThis(const char code[]) { + // Clear the error log + errout.str(""); + + Settings settings; + settings._checkCodingStyle = true; + // Tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); tokenizer.simplifyTokenList(); - // Clear the error log - errout.str(""); - // Check.. - Settings settings; - settings._checkCodingStyle = true; CheckClass checkClass(&tokenizer, &settings, this); checkClass.operatorEqRetRefThis(); } @@ -463,18 +465,19 @@ private: // Check that operator Equal checks for assignment to self void checkOpertorEqToSelf(const char code[]) { + // Clear the error log + errout.str(""); + + Settings settings; + settings._checkCodingStyle = true; + // Tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); tokenizer.simplifyTokenList(); - // Clear the error log - errout.str(""); - // Check.. - Settings settings; - settings._checkCodingStyle = true; CheckClass checkClass(&tokenizer, &settings, this); checkClass.operatorEqToSelf(); } @@ -1263,18 +1266,19 @@ private: // Check that base classes have virtual destructors void checkVirtualDestructor(const char code[]) { + // Clear the error log + errout.str(""); + + Settings settings; + settings.inconclusive = true; + // Tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); tokenizer.simplifyTokenList(); - // Clear the error log - errout.str(""); - // Check.. - Settings settings; - settings.inconclusive = true; CheckClass checkClass(&tokenizer, &settings, this); checkClass.virtualDestructor(); } @@ -1490,18 +1494,19 @@ private: void checkUninitVar(const char code[]) { + // Clear the error log + errout.str(""); + + Settings settings; + settings._checkCodingStyle = true; + // Tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); tokenizer.simplifyTokenList(); - // Clear the error log - errout.str(""); - // Check.. - Settings settings; - settings._checkCodingStyle = true; CheckClass checkClass(&tokenizer, &settings, this); checkClass.constructors(); } @@ -2490,18 +2495,19 @@ private: void checkUninitVarJava(const char code[]) { + // Clear the error log + errout.str(""); + + Settings settings; + settings._checkCodingStyle = true; + // Tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.java"); tokenizer.simplifyTokenList(); - // Clear the error log - errout.str(""); - // Check.. - Settings settings; - settings._checkCodingStyle = true; CheckClass checkClass(&tokenizer, &settings, this); checkClass.constructors(); } @@ -2518,18 +2524,19 @@ private: void checkNoConstructor(const char code[]) { + // Clear the error log + errout.str(""); + + Settings settings; + settings._checkCodingStyle = true; + // Tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); tokenizer.simplifyTokenList(); - // Clear the error log - errout.str(""); - // Check.. - Settings settings; - settings._checkCodingStyle = true; CheckClass checkClass(&tokenizer, &settings, this); checkClass.constructors(); } @@ -2588,17 +2595,17 @@ private: void checkNoMemset(const char code[]) { - // Tokenize.. - Tokenizer tokenizer; - std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); - - // Clear the error log errout.str(""); - // Check.. Settings settings; + + // Tokenize.. + Tokenizer tokenizer(&settings, this); + std::istringstream istr(code); + tokenizer.tokenize(istr, "test.cpp"); + + // Check.. CheckClass checkClass(&tokenizer, &settings, this); checkClass.noMemset(); } @@ -2691,18 +2698,19 @@ private: void checkThisSubtraction(const char code[]) { + // Clear the error log + errout.str(""); + + Settings settings; + settings._checkCodingStyle = true; + // Tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); tokenizer.simplifyTokenList(); - // Clear the error log - errout.str(""); - // Check.. - Settings settings; - settings._checkCodingStyle = true; CheckClass checkClass(&tokenizer, &settings, this); checkClass.thisSubtraction(); } @@ -2728,12 +2736,6 @@ private: 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 errout.str(""); @@ -2743,6 +2745,13 @@ private: settings = *s; else 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.checkConst(); } diff --git a/test/testconstructors.cpp b/test/testconstructors.cpp index b4350cb0d..b7e72eb61 100644 --- a/test/testconstructors.cpp +++ b/test/testconstructors.cpp @@ -36,19 +36,20 @@ private: void check(const char code[], bool showAll = false) { + // Clear the error buffer.. + errout.str(""); + + Settings settings; + settings.inconclusive = showAll; + settings._checkCodingStyle = true; + // Tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); tokenizer.simplifyTokenList(); - // Clear the error buffer.. - errout.str(""); - // Check class constructors.. - Settings settings; - settings.inconclusive = showAll; - settings._checkCodingStyle = true; CheckClass checkClass(&tokenizer, &settings, this); checkClass.constructors(); } diff --git a/test/testdivision.cpp b/test/testdivision.cpp index c58d4202c..456bf877d 100644 --- a/test/testdivision.cpp +++ b/test/testdivision.cpp @@ -38,17 +38,17 @@ public: private: void check(const char code[], bool style = true) { - // Tokenize.. - Tokenizer tokenizer; - std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); - // Clear the error buffer.. errout.str(""); Settings settings; settings._checkCodingStyle = style; + // Tokenize.. + Tokenizer tokenizer(&settings, this); + std::istringstream istr(code); + tokenizer.tokenize(istr, "test.cpp"); + // Check for unsigned divisions.. CheckOther checkOther(&tokenizer, &settings, this); checkOther.checkUnsignedDivision(); diff --git a/test/testexceptionsafety.cpp b/test/testexceptionsafety.cpp index 81f3f1004..52b93e1b2 100644 --- a/test/testexceptionsafety.cpp +++ b/test/testexceptionsafety.cpp @@ -40,18 +40,19 @@ private: void check(const std::string &code) { + // Clear the error buffer.. + errout.str(""); + + Settings settings; + settings.addEnabled("all"); + // Tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code.c_str()); tokenizer.tokenize(istr, "test.cpp"); tokenizer.simplifyTokenList(); - // Clear the error buffer.. - errout.str(""); - // Check char variable usage.. - Settings settings; - settings.addEnabled("all"); CheckExceptionSafety checkExceptionSafety(&tokenizer, &settings, this); checkExceptionSafety.runSimplifiedChecks(&tokenizer, &settings, this); } diff --git a/test/testincompletestatement.cpp b/test/testincompletestatement.cpp index 653584bdf..6fe2a2a35 100644 --- a/test/testincompletestatement.cpp +++ b/test/testincompletestatement.cpp @@ -38,18 +38,19 @@ public: private: void check(const char code[]) { + // Clear the error buffer.. + errout.str(""); + + Settings settings; + settings._checkCodingStyle = true; + // Tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); tokenizer.simplifyTokenList(); - // Clear the error buffer.. - errout.str(""); - // Check for incomplete statements.. - Settings settings; - settings._checkCodingStyle = true; CheckOther checkOther(&tokenizer, &settings, this); checkOther.checkIncompleteStatement(); } diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index f70273365..736baecb0 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -45,18 +45,19 @@ private: void check(const char code[]) { + // Clear the error buffer.. + errout.str(""); + + Settings settings; + // Tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); tokenizer.setVarId(); tokenizer.simplifyTokenList(); - // Clear the error buffer.. - errout.str(""); - // Check for memory leaks.. - Settings settings; CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, &settings, this); checkMemoryLeak.localleaks(); } @@ -142,8 +143,13 @@ private: CheckMemoryLeak::AllocType functionReturnType(const char code[]) { + // Clear the error buffer.. + errout.str(""); + + Settings settings; + // Tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); tokenizer.setVarId(); @@ -192,7 +198,13 @@ private: " int ret = open();\n" " }\n" "};\n"; - Tokenizer tokenizer; + + // Clear the error buffer.. + errout.str(""); + + Settings settings; + + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); @@ -218,20 +230,22 @@ public: private: void check(const char code[], bool showAll = false) { + // Clear the error buffer.. + errout.str(""); + + Settings settings; + settings.inconclusive = showAll; + // Tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); tokenizer.setVarId(); tokenizer.simplifyTokenList(); - // Clear the error buffer.. - errout.str(""); + tokenizer.fillFunctionList(); // Check for memory leaks.. - Settings settings; - settings.inconclusive = showAll; - tokenizer.fillFunctionList(); CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, &settings, this); checkMemoryLeak.checkReallocUsage(); checkMemoryLeak.check(); @@ -417,8 +431,13 @@ private: std::string getcode(const char code[], const char varname[], bool classfunc=false) const { + // Clear the error buffer.. + errout.str(""); + + Settings settings; + // Tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, NULL); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); tokenizer.simplifyTokenList(); @@ -426,7 +445,7 @@ private: const unsigned int varId(Token::findmatch(tokenizer.tokens(), varname)->varId()); // getcode.. - CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, 0, 0); + CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, &settings, NULL); checkMemoryLeak.parse_noreturn(); std::list callstack; callstack.push_back(0); @@ -635,8 +654,13 @@ private: std::string simplifycode(const char code[]) const { + // Clear the error buffer.. + errout.str(""); + + Settings settings; + // Tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, NULL); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); Token *tokens = const_cast(tokenizer.tokens()); @@ -657,7 +681,6 @@ private: } } - Settings settings; CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, &settings, NULL); checkMemoryLeak.simplifycode(tokens); @@ -783,9 +806,13 @@ private: // is there a leak in given code? if so, return the linenr unsigned int dofindleak(const char code[]) const { - // Tokenize.. + // Clear the error buffer.. + errout.str(""); + Settings settings; settings.debug = settings.debugwarnings = true; + + // Tokenize.. Tokenizer tokenizer(&settings, NULL); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); @@ -2479,22 +2506,20 @@ private: 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.. errout.str(""); - // Check for memory leaks.. Settings settings; 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); checkMemoryLeak.check(); } @@ -3108,20 +3133,22 @@ private: */ void check(const char code[]) { + // Clear the error buffer.. + errout.str(""); + + Settings settings; + settings._checkCodingStyle = true; + // Tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); tokenizer.setVarId(); tokenizer.simplifyTokenList(); - // Clear the error buffer.. - errout.str(""); + tokenizer.fillFunctionList(); // Check for memory leaks.. - Settings settings; - settings._checkCodingStyle = true; - tokenizer.fillFunctionList(); CheckMemoryLeakInClass checkMemoryLeak(&tokenizer, &settings, this); checkMemoryLeak.check(); } @@ -3717,17 +3744,18 @@ public: private: void check(const char code[]) { + // Clear the error buffer.. + errout.str(""); + + Settings settings; + // Tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); tokenizer.simplifyTokenList(); - // Clear the error buffer.. - errout.str(""); - // Check for memory leaks.. - Settings settings; CheckMemoryLeakStructMember checkMemoryLeakStructMember(&tokenizer, &settings, this); checkMemoryLeakStructMember.check(); } @@ -3951,17 +3979,18 @@ public: private: void check(const char code[]) { + // Clear the error buffer.. + errout.str(""); + + Settings settings; + // Tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); tokenizer.simplifyTokenList(); - // Clear the error buffer.. - errout.str(""); - // Check for memory leaks.. - Settings settings; CheckMemoryLeakNoVar checkMemoryLeakNoVar(&tokenizer, &settings, this); checkMemoryLeakNoVar.check(); } diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 5e421c1f9..89c67d70f 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -48,17 +48,18 @@ private: void check(const char code[]) { - // Tokenize.. - Tokenizer tokenizer; - std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); - // Clear the error buffer.. errout.str(""); - // Check for redundant code.. Settings settings; 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.nullPointer(); tokenizer.simplifyTokenList(); diff --git a/test/testobsoletefunctions.cpp b/test/testobsoletefunctions.cpp index 980853803..3aab0db6a 100644 --- a/test/testobsoletefunctions.cpp +++ b/test/testobsoletefunctions.cpp @@ -52,8 +52,15 @@ private: void check(const char code[]) { + // Clear the error buffer.. + errout.str(""); + + Settings settings; + settings._checkCodingStyle = true; + settings.inconclusive = true; + // Tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); tokenizer.simplifyTokenList(); @@ -64,13 +71,7 @@ private: // Fill function list tokenizer.fillFunctionList(); - // Clear the error buffer.. - errout.str(""); - // Check for obsolete functions.. - Settings settings; - settings._checkCodingStyle = true; - settings.inconclusive = true; CheckObsoleteFunctions checkObsoleteFunctions(&tokenizer, &settings, this); checkObsoleteFunctions.obsoleteFunctions(); } diff --git a/test/testother.cpp b/test/testother.cpp index 5691aedd1..52110521e 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -96,19 +96,19 @@ private: void check(const char code[]) { + // Clear the error buffer.. + errout.str(""); + + Settings settings; + settings._checkCodingStyle = true; + // Tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); // Check.. - Settings settings; - settings._checkCodingStyle = true; CheckOther checkOther(&tokenizer, &settings, this); - - // Clear the error buffer.. - errout.str(""); - checkOther.sizeofsizeof(); checkOther.sizeofCalculation(); checkOther.checkRedundantAssignmentInSwitch(); @@ -239,19 +239,20 @@ private: void sprintfUsage(const char code[]) { + // Clear the error buffer.. + errout.str(""); + + Settings settings; + // Tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); tokenizer.setVarId(); //tokenizer.tokens()->printOut( "tokens" ); - // Clear the error buffer.. - errout.str(""); - // Check for redundant code.. - Settings settings; CheckOther checkOther(&tokenizer, &settings, this); checkOther.invalidFunctionUsage(); } @@ -309,17 +310,18 @@ private: void strPlusChar(const char code[]) { + // Clear the error buffer.. + errout.str(""); + + Settings settings; + // Tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); tokenizer.setVarId(); - // Clear the error buffer.. - errout.str(""); - // Check for redundant code.. - Settings settings; CheckOther checkOther(&tokenizer, &settings, this); checkOther.strPlusChar(); } @@ -369,17 +371,18 @@ private: void varScope(const char code[]) { - // Tokenize.. - Tokenizer tokenizer; - std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); - // Clear the error buffer.. errout.str(""); - // Check for redundant code.. Settings settings; 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.checkVariableScope(); } @@ -570,24 +573,23 @@ private: void checkOldStylePointerCast(const char code[]) { + // Clear the error buffer.. + errout.str(""); + + Settings settings; + settings._checkCodingStyle = true; + // Tokenize.. - Tokenizer tokenizerCpp; + Tokenizer tokenizerCpp(&settings, this); std::istringstream istr(code); tokenizerCpp.tokenize(istr, "test.cpp"); tokenizerCpp.setVarId(); - Tokenizer tokenizerC; + Tokenizer tokenizerC(&settings, this); std::istringstream istr2(code); tokenizerC.tokenize(istr2, "test.c"); tokenizerC.setVarId(); - // Clear the error buffer.. - errout.str(""); - - // Check for redundant code.. - Settings settings; - settings._checkCodingStyle = true; - CheckOther checkOtherCpp(&tokenizerCpp, &settings, this); checkOtherCpp.warningOldStylePointerCast(); @@ -670,15 +672,16 @@ private: void testPassedByValue(const char code[]) { - Tokenizer tokenizer; - std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); - // Clear the error buffer.. errout.str(""); Settings settings; settings._checkCodingStyle = true; + + Tokenizer tokenizer(&settings, this); + std::istringstream istr(code); + tokenizer.tokenize(istr, "test.cpp"); + CheckOther checkOther(&tokenizer, &settings, this); checkOther.checkConstantFunctionParameter(); } @@ -1155,8 +1158,6 @@ private: void trac1132() { - errout.str(""); - std::istringstream code("#include \n" "class Lock\n" "{\n" @@ -1178,12 +1179,14 @@ private: "}\n" ); - Tokenizer tokenizer; - tokenizer.tokenize(code, "trac1132.cpp"); - tokenizer.simplifyTokenList(); + errout.str(""); Settings settings; + Tokenizer tokenizer(&settings, this); + tokenizer.tokenize(code, "trac1132.cpp"); + tokenizer.simplifyTokenList(); + CheckOther checkOther(&tokenizer, &settings, this); checkOther.checkMisusedScopedObject(); diff --git a/test/testpostfixoperator.cpp b/test/testpostfixoperator.cpp index d5d87b6e5..4a93aec50 100644 --- a/test/testpostfixoperator.cpp +++ b/test/testpostfixoperator.cpp @@ -37,8 +37,15 @@ private: void check(const char code[]) { + // Clear the error buffer.. + errout.str(""); + + Settings settings; + settings._checkCodingStyle = true; + settings.inconclusive = true; + // Tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); tokenizer.simplifyTokenList(); @@ -49,13 +56,7 @@ private: // Fill function list tokenizer.fillFunctionList(); - // Clear the error buffer.. - errout.str(""); - // Check for postfix operators.. - Settings settings; - settings._checkCodingStyle = true; - settings.inconclusive = true; CheckPostfixOperator checkPostfixOperator(&tokenizer, &settings, this); checkPostfixOperator.postfixOperator(); } diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 37ca80744..3a491c0f4 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -198,7 +198,8 @@ private: { const char code[] = " \t a //\n" " #aa\t /* remove this */\tb \r\n"; - Preprocessor preprocessor(0,this); + Settings settings; + Preprocessor preprocessor(&settings, this); std::istringstream istr(code); std::string codestr(preprocessor.read(istr,"test.c",0)); ASSERT_EQUALS("a \n#aa b \n", codestr); @@ -207,7 +208,8 @@ private: void readCode2() { const char code[] = "R\"( \" /* abc */ \n)\""; - Preprocessor preprocessor(0,this); + Settings settings; + Preprocessor preprocessor(&settings, this); std::istringstream istr(code); std::string codestr(preprocessor.read(istr,"test.c",0)); ASSERT_EQUALS("\" \\\" /* abc */ \\n\"\n", codestr); @@ -266,7 +268,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -287,7 +290,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -307,7 +311,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -329,7 +334,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -351,7 +357,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -374,7 +381,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -393,7 +401,8 @@ private: "#elif defined (A)\n"; std::istringstream istr(filedata); - Preprocessor preprocessor(0,this); + Settings settings; + Preprocessor preprocessor(&settings, this); const std::string actual(preprocessor.read(istr, "test.c", 0)); // Compare results.. @@ -412,7 +421,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); errout.str(""); preprocessor.preprocess(istr, actual, "file.c"); @@ -438,7 +448,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); errout.str(""); preprocessor.preprocess(istr, actual, "file.c"); @@ -458,7 +469,8 @@ private: // Read string.. 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)); } @@ -487,7 +499,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Expected configurations: "" and "ABC" @@ -507,7 +520,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Expected configurations: "" and "ABC" @@ -530,10 +544,11 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); - Tokenizer tok; + Tokenizer tok(&settings, this); std::istringstream codeStream(actual[""]); tok.tokenize(codeStream, "main.cpp"); @@ -551,7 +566,8 @@ private: // Preprocess 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)); } @@ -568,7 +584,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -585,7 +602,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -602,7 +620,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -623,7 +642,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -640,7 +660,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -661,7 +682,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -683,7 +705,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -746,7 +769,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -767,7 +791,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -794,7 +819,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -820,7 +846,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -851,7 +878,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -874,7 +902,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -896,7 +925,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -916,7 +946,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -936,7 +967,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -952,7 +984,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -969,7 +1002,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -992,7 +1026,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -1156,7 +1191,8 @@ private: // Preprocess => actual result.. 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)); } @@ -1168,7 +1204,8 @@ private: // Preprocess => actual result.. 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)); } @@ -1180,7 +1217,8 @@ private: // Preprocess => actual result.. 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)); } @@ -1194,7 +1232,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -1219,7 +1258,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -1553,7 +1593,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -1665,7 +1706,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -1719,7 +1761,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -1791,7 +1834,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -1813,7 +1857,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -1831,7 +1876,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -1850,7 +1896,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -1883,7 +1930,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); ASSERT_EQUALS(expected, actual[""]); @@ -1971,7 +2019,8 @@ private: const std::string filedata("a\xC8"); std::istringstream istr(filedata); errout.str(""); - Preprocessor preprocessor(0, this); + Settings settings; + Preprocessor preprocessor(&settings, this); 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()); } @@ -1980,7 +2029,8 @@ private: { const std::string filedata("//\xC8"); std::istringstream istr(filedata.c_str()); - Preprocessor preprocessor(0, this); + Settings settings; + Preprocessor preprocessor(&settings, this); ASSERT_EQUALS("", preprocessor.read(istr, "test.cpp", 0)); } @@ -1988,7 +2038,8 @@ private: { const std::string filedata("\"\xC8\""); 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)); } @@ -2004,7 +2055,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -2025,7 +2077,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -2046,7 +2099,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -2069,7 +2123,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor(0, this); + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c", std::list()); // Compare results.. @@ -2090,7 +2145,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor(0, this); + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c", std::list()); // Compare results.. @@ -2144,7 +2200,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -2166,7 +2223,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -2183,7 +2241,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -2200,7 +2259,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -2217,7 +2277,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -2236,7 +2297,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -2280,7 +2342,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. @@ -2301,7 +2364,8 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor; + Settings settings; + Preprocessor preprocessor(&settings, this); preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 4ab5544dc..061110fc2 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -712,9 +712,12 @@ private: 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.elseif(); return tokenizer.tokens()->stringifyList(false); @@ -773,8 +776,11 @@ private: // Simplify 'sizeof'.. std::string sizeof_(const char code[], bool simplify = true) { - // tokenize.. + errout.str(""); + Settings settings; + + // tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); @@ -798,7 +804,11 @@ private: unsigned int sizeofFromTokenizer(const char type[]) { - Tokenizer tokenizer; + errout.str(""); + + Settings settings; + + Tokenizer tokenizer(&settings, this); std::istringstream istr(""); tokenizer.tokenize(istr, "test.cpp"); tokenizer.simplifyTokenList(); @@ -2072,8 +2082,10 @@ private: " x(sizeof typename);\n" " type = 0;\n" "}"; + errout.str(""); + Settings settings; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - Tokenizer tokenizer; tokenizer.tokenize(istr, "test.c", "", false); std::ostringstream ostr; for (const Token *tok1 = tokenizer.tokens(); tok1; tok1 = tok1->next()) @@ -2124,8 +2136,10 @@ private: std::string simplifyIfAssign(const char code[]) { + errout.str(""); + Settings settings; // tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); @@ -2203,8 +2217,10 @@ private: std::string simplifyIfNot(const char code[]) { + errout.str(""); + Settings settings; // tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); @@ -2236,8 +2252,10 @@ private: std::string simplifyLogicalOperators(const char code[]) { + errout.str(""); + Settings settings; // tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); @@ -2562,8 +2580,10 @@ private: " c();\n" "}"; + errout.str(""); + Settings settings; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - Tokenizer tokenizer; tokenizer.tokenize(istr, "test.cpp"); tokenizer.simplifyTokenList(); tokenizer.validate(); @@ -2595,8 +2615,10 @@ private: "}"; + errout.str(""); + Settings settings; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - Tokenizer tokenizer; tokenizer.tokenize(istr, "test.cpp"); tokenizer.simplifyTokenList(); tokenizer.validate(); @@ -3136,13 +3158,14 @@ private: "typedef std::vector CallQueue;" "int main() {}"; - Tokenizer tokenizer; - std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); - // Clear the error buffer.. errout.str(""); + Settings settings; + Tokenizer tokenizer(&settings, this); + std::istringstream istr(code); + tokenizer.tokenize(istr, "test.cpp"); + tokenizer.simplifyTokenList(); ASSERT_EQUALS("", errout.str()); @@ -3163,13 +3186,14 @@ private: " FP_M(val);" "};"; - Tokenizer tokenizer; - std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); - // Clear the error buffer.. errout.str(""); + Settings settings; + Tokenizer tokenizer(&settings, this); + std::istringstream istr(code); + tokenizer.tokenize(istr, "test.cpp"); + tokenizer.simplifyTokenList(); ASSERT_EQUALS("", errout.str()); @@ -3209,13 +3233,14 @@ private: " CHFOO freem;\n" "} STRFOO;"; - Tokenizer tokenizer; - std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); - // Clear the error buffer.. errout.str(""); + Settings settings; + Tokenizer tokenizer(&settings, this); + std::istringstream istr(code); + tokenizer.tokenize(istr, "test.cpp"); + tokenizer.simplifyTokenList(); ASSERT_EQUALS("", errout.str()); @@ -3240,13 +3265,14 @@ private: const char code[] = "typedef vector a;\n" "a b;\n"; - Tokenizer tokenizer; - std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); - // Clear the error buffer.. errout.str(""); + Settings settings; + Tokenizer tokenizer(&settings, this); + std::istringstream istr(code); + tokenizer.tokenize(istr, "test.cpp"); + tokenizer.simplifyTokenList(); ASSERT_EQUALS(true, tokenizer.validate()); @@ -3304,13 +3330,14 @@ private: // ticket #1284 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.. errout.str(""); + Settings settings; + Tokenizer tokenizer(&settings, this); + std::istringstream istr(code); + tokenizer.tokenize(istr, "test.cpp"); + tokenizer.simplifyTokenList(); ASSERT_EQUALS(true, tokenizer.validate()); @@ -3767,6 +3794,7 @@ private: // Check simplifyTypedef void checkSimplifyTypedef(const char code[]) { + errout.str(""); // Tokenize.. Settings settings; settings.inconclusive = true; @@ -3774,7 +3802,6 @@ private: settings.debugwarnings = true; // show warnings about unhandled typedef Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - errout.str(""); tokenizer.tokenize(istr, "test.cpp"); } @@ -5576,13 +5603,13 @@ private: // Check simplifyEnum void checkSimplifyEnum(const char code[]) { + errout.str(""); // Tokenize.. Settings settings; settings.inconclusive = true; settings._checkCodingStyle = true; Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - errout.str(""); tokenizer.tokenize(istr, "test.cpp"); tokenizer.simplifyTokenList(); } diff --git a/test/teststl.cpp b/test/teststl.cpp index b045f22e5..b1fb91544 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -107,19 +107,20 @@ private: void check(const std::string &code) { + // Clear the error buffer.. + errout.str(""); + + Settings settings; + settings.inconclusive = true; + settings._checkCodingStyle = true; + // Tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code.c_str()); tokenizer.tokenize(istr, "test.cpp"); tokenizer.simplifyTokenList(); - // Clear the error buffer.. - errout.str(""); - // Check.. - Settings settings; - settings.inconclusive = true; - settings._checkCodingStyle = true; CheckStl checkStl; checkStl.runSimplifiedChecks(&tokenizer, &settings, this); } @@ -888,7 +889,8 @@ private: " for ( \n" "}\n"; - Tokenizer tokenizer(0, this); + Settings settings; + Tokenizer tokenizer(&settings, this); std::istringstream istr(src); 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()); diff --git a/test/testtoken.cpp b/test/testtoken.cpp index 89770dc7e..c9f25ad80 100644 --- a/test/testtoken.cpp +++ b/test/testtoken.cpp @@ -19,6 +19,7 @@ #include "testsuite.h" #include "tokenize.h" #include "token.h" +#include "settings.h" #include @@ -227,6 +228,7 @@ private: private: std::istringstream _sample; const Token* _tokens; + Settings _settings; Tokenizer _tokenizer; public: @@ -234,6 +236,7 @@ private: :_sample(sample) ,_tokens(NULL) { + _tokenizer.setSettings(&_settings); _tokenizer.tokenize(_sample, "test.cpp"); _tokens = _tokenizer.tokens(); } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index ecdba6c65..9c72889de 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -299,9 +299,10 @@ private: { errout.str(""); - // tokenize.. Settings settings; settings.debugwarnings = true; + + // tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); @@ -490,8 +491,12 @@ private: { std::string filedata(10000, 'a'); + errout.str(""); + + Settings settings; + // tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(filedata); tokenizer.tokenize(istr, "test.cpp"); @@ -506,8 +511,12 @@ private: { const char code[] = "int *f(int *);"; + errout.str(""); + + Settings settings; + // tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); @@ -524,8 +533,12 @@ private: { const char code[] = "t = (static_cast *>(&p));\n"; + errout.str(""); + + Settings settings; + // tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); @@ -873,7 +886,11 @@ private: std::string simplifyKnownVariables(const char code[]) { - Tokenizer tokenizer; + errout.str(""); + + Settings settings; + + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); @@ -1915,7 +1932,11 @@ private: std::string tokenizeDebugListing(const std::string &code, bool simplify = false) { - Tokenizer tokenizer; + errout.str(""); + + Settings settings; + + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); @@ -3018,8 +3039,12 @@ private: "#endfile\n" "a3\n"; + errout.str(""); + + Settings settings; + // tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "a"); @@ -3050,8 +3075,12 @@ private: "#endfile\n" "a5\n"; + errout.str(""); + + Settings settings; + // tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "a"); @@ -3071,12 +3100,15 @@ private: "123\n" "#endfile\n"; + errout.str(""); + + Settings settings; + // tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "a.cpp"); - 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"; + errout.str(""); + + Settings settings; + // Tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, ""); @@ -3104,8 +3140,12 @@ private: { const char code[] = "DBG(fmt,args...) printf(fmt, ## args)\n"; + errout.str(""); + + Settings settings; + // Tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, ""); @@ -3156,8 +3196,12 @@ private: " free(((void*)p));\n" "}"; + errout.str(""); + + Settings settings; + // tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); @@ -3177,8 +3221,12 @@ private: " return;\n" "}"; + errout.str(""); + + Settings settings; + // tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); @@ -3198,8 +3246,12 @@ private: " if (( true )==(true)){}\n" "}"; + errout.str(""); + + Settings settings; + // tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); @@ -3217,8 +3269,12 @@ private: " if (( 2 )==(2)){}\n" "}"; + errout.str(""); + + Settings settings; + // tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); @@ -3236,8 +3292,12 @@ private: " if( g(10)){}\n" "}"; + errout.str(""); + + Settings settings; + // tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); @@ -3258,8 +3318,12 @@ private: " (free(p));\n" "}"; + errout.str(""); + + Settings settings; + // tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); @@ -3280,8 +3344,12 @@ private: " (delete p);\n" "}"; + errout.str(""); + + Settings settings; + // tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); @@ -3300,8 +3368,12 @@ private: " (delete [] p);\n" "}"; + errout.str(""); + + Settings settings; + // tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); @@ -3319,8 +3391,12 @@ private: { const char code[] = "(!(abc.a))"; + errout.str(""); + + Settings settings; + // tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); @@ -3336,8 +3412,12 @@ private: { const char code[] = ";char *p; (delete(p), (p)=0);"; + errout.str(""); + + Settings settings; + // tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); @@ -3379,8 +3459,12 @@ private: " int e = 4+2;\n" "}\n"; + errout.str(""); + + Settings settings; + // tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); @@ -3402,8 +3486,12 @@ private: "};\n" "}\n"; + errout.str(""); + + Settings settings; + // tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); tokenizer.simplifyTokenList(); @@ -3428,8 +3516,12 @@ private: "int a = 2;\n" "}\n"; + errout.str(""); + + Settings settings; + // tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); @@ -3452,8 +3544,12 @@ private: "foo2->a=a;\n" "}\n"; + errout.str(""); + + Settings settings; + // tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); @@ -3689,7 +3785,8 @@ private: { errout.str(""); const char code[] = "void f() {}"; - Tokenizer tokenizer(0, this); + Settings settings; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); ASSERT_EQUALS(true, tokenizer.tokenize(istr, "test.cpp")); ASSERT_EQUALS("", errout.str()); @@ -3698,7 +3795,8 @@ private: { errout.str(""); const char code[] = "void f() {{}"; - Tokenizer tokenizer(0, this); + Settings settings; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); 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()); @@ -3707,7 +3805,8 @@ private: { errout.str(""); const char code[] = "void f()) {}"; - Tokenizer tokenizer(0, this); + Settings settings; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); 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()); @@ -3716,7 +3815,8 @@ private: { errout.str(""); 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); ASSERT_EQUALS(true, tokenizer.tokenize(istr, "test.cpp")); tokenizer.simplifyTokenList(); @@ -3729,7 +3829,8 @@ private: "{\n" " foo(;\n" "}\n"; - Tokenizer tokenizer(0, this); + Settings settings; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); 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()); @@ -3741,7 +3842,8 @@ private: "{\n" " for(;;){ foo();\n" "}\n"; - Tokenizer tokenizer(0, this); + Settings settings; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); 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()); @@ -3753,7 +3855,8 @@ private: "{\n" " a[10;\n" "}\n"; - Tokenizer tokenizer(0, this); + Settings settings; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); 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()); @@ -3767,7 +3870,8 @@ private: "{\n" " b());\n" "}\n"; - Tokenizer tokenizer(0, this); + Settings settings; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); 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()); @@ -3781,7 +3885,8 @@ private: { errout.str(""); std::istringstream istr("xz> xyz;\n"); - Tokenizer tokenizer(0, this); + Settings settings; + Tokenizer tokenizer(&settings, this); tokenizer.tokenize(istr, "test.cpp"); ASSERT_EQUALS("", errout.str()); } @@ -3790,7 +3895,8 @@ private: { errout.str(""); std::istringstream istr("template operator<(T a, T b) { }\n"); - Tokenizer tokenizer(0, this); + Settings settings; + Tokenizer tokenizer(&settings, this); tokenizer.tokenize(istr, "test.cpp"); ASSERT_EQUALS("", errout.str()); } @@ -3800,7 +3906,8 @@ private: errout.str(""); std::istringstream istr("void f(a) int a;\n" "{ ;x xyz;\n"); - Tokenizer tokenizer(0, this); + Settings settings; + Tokenizer tokenizer(&settings, this); tokenizer.tokenize(istr, "test.cpp"); ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str()); } @@ -3833,7 +3942,8 @@ private: " , ConcreteVisitable\n" " , Dummy< _visitableIndex >\n" " >::type ConcreteVisitableOrDummy;\n"); - Tokenizer tokenizer(0, this); + Settings settings; + Tokenizer tokenizer(&settings, this); tokenizer.tokenize(istr, "test.cpp"); ASSERT_EQUALS("[test.cpp:2]: (error) syntax error\n", errout.str()); } @@ -3952,7 +4062,9 @@ private: const char code[] = "class A{\n" " void f() {}\n" "};"; - Tokenizer tokenizer; + errout.str(""); + Settings settings; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); const Token *tok = tokenizer.tokens(); @@ -3974,7 +4086,9 @@ private: " char a[10];\n" " char *b ; b = new char[a[0]];\n" "};"; - Tokenizer tokenizer; + errout.str(""); + Settings settings; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); const Token *tok = tokenizer.tokens(); @@ -3995,7 +4109,9 @@ private: const char code[] = "void f(){\n" " foo(g());\n" "};"; - Tokenizer tokenizer; + errout.str(""); + Settings settings; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); const Token *tok = tokenizer.tokens(); @@ -4065,7 +4181,9 @@ private: void simplifyString() { - Tokenizer tokenizer; + errout.str(""); + Settings settings; + Tokenizer tokenizer(&settings, this); ASSERT_EQUALS("\"abc\"", tokenizer.simplifyString("\"abc\"")); ASSERT_EQUALS("\"a\"", tokenizer.simplifyString("\"\\x3\"")); ASSERT_EQUALS("\"a\"", tokenizer.simplifyString("\"\\x33\"")); @@ -4102,7 +4220,9 @@ private: std::string simplifyFunctionPointers(const char code[]) { - Tokenizer tokenizer; + errout.str(""); + Settings settings; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); tokenizer.simplifyFunctionPointers(); @@ -4205,8 +4325,10 @@ private: std::string arraySize_(const std::string &code) { + errout.str(""); + Settings settings; // tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code.c_str()); tokenizer.tokenize(istr, "test.cpp"); @@ -4725,8 +4847,10 @@ private: std::string javatest(const char javacode[]) { + errout.str(""); + Settings settings; // tokenize.. - Tokenizer tokenizer(0, this); + Tokenizer tokenizer(&settings, this); std::istringstream istr(javacode); tokenizer.tokenize(istr, "test.java"); diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 570885d63..27716cf70 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -50,17 +50,18 @@ private: void checkUninitVar(const char code[]) { + // Clear the error buffer.. + errout.str(""); + + Settings settings; + // Tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); tokenizer.simplifyTokenList(); - // Clear the error buffer.. - errout.str(""); - // Check for redundant code.. - Settings settings; CheckUninitVar check(&tokenizer, &settings, this); check.executionPaths(); } @@ -1187,8 +1188,13 @@ private: std::string analyseFunctions(const char code[]) { + // Clear the error buffer.. + errout.str(""); + + Settings settings; + // Tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); diff --git a/test/testunusedfunctions.cpp b/test/testunusedfunctions.cpp index 2689b7783..2dc338511 100644 --- a/test/testunusedfunctions.cpp +++ b/test/testunusedfunctions.cpp @@ -51,17 +51,18 @@ private: void check(const char code[]) { - // Tokenize.. - Tokenizer tokenizer; - std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); - // Clear the error buffer.. errout.str(""); - // Check for unused functions.. Settings settings; 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.parseTokens(tokenizer); checkUnusedFunctions.check(this); @@ -198,7 +199,12 @@ private: std::ostringstream fname; fname << "test" << i << ".cpp"; - Tokenizer tokenizer; + // Clear the error buffer.. + errout.str(""); + + Settings settings; + + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, fname.str().c_str()); diff --git a/test/testunusedprivfunc.cpp b/test/testunusedprivfunc.cpp index f039bd541..2c09d20fb 100644 --- a/test/testunusedprivfunc.cpp +++ b/test/testunusedprivfunc.cpp @@ -62,18 +62,19 @@ private: void check(const char code[]) { + // Clear the error buffer.. + errout.str(""); + + Settings settings; + settings._checkCodingStyle = true; + // Tokenize.. - Tokenizer tokenizer; + Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); tokenizer.simplifyTokenList(); - // Clear the error buffer.. - errout.str(""); - // Check for unused private functions.. - Settings settings; - settings._checkCodingStyle = true; CheckClass checkClass(&tokenizer, &settings, this); checkClass.privateFunctions(); } diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 5f11e0db0..b8f852fb7 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -111,18 +111,18 @@ private: void checkStructMemberUsage(const char code[]) { - // Tokenize.. - Tokenizer tokenizer; - std::istringstream istr(code); - // Clear the error buffer.. errout.str(""); + Settings settings; + settings._checkCodingStyle = true; + + // Tokenize.. + Tokenizer tokenizer(&settings, this); + std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); // Check for unused variables.. - Settings settings; - settings._checkCodingStyle = true; CheckOther checkOther(&tokenizer, &settings, this); checkOther.checkStructMemberUsage(); } @@ -339,18 +339,18 @@ private: void functionVariableUsage(const char code[]) { - // Tokenize.. - Tokenizer tokenizer; - std::istringstream istr(code); - // Clear the error buffer.. errout.str(""); + Settings settings; + settings._checkCodingStyle = true; + + // Tokenize.. + Tokenizer tokenizer(&settings, this); + std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); // Check for unused variables.. - Settings settings; - settings._checkCodingStyle = true; CheckOther checkOther(&tokenizer, &settings, this); checkOther.functionVariableUsage(); }