Skip to content

Commit eed2e82

Browse files
authored
Revert "Cleanup: Removed Tokenizer::simplifyTokenList2. As a side-effect, rules for "simple" token list are now executed on normal token list." (cppcheck-opensource#2666)
This reverts commit 187cde1.
1 parent 70d2f02 commit eed2e82

12 files changed

Lines changed: 9501 additions & 782 deletions

cli/cmdlineparser.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,10 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
258258
else if (std::strcmp(argv[i], "--debug-bug-hunting") == 0)
259259
mSettings->debugBugHunting = true;
260260

261+
// Flag used for various purposes during debugging
262+
else if (std::strcmp(argv[i], "--debug-simplified") == 0)
263+
mSettings->debugSimplified = true;
264+
261265
// Show template information
262266
else if (std::strcmp(argv[i], "--debug-template") == 0)
263267
mSettings->debugtemplate = true;

lib/cppcheck.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ CppCheck::CppCheck(ErrorLogger &errorLogger,
249249
, mSuppressInternalErrorFound(false)
250250
, mUseGlobalSuppressions(useGlobalSuppressions)
251251
, mTooManyConfigs(false)
252+
, mSimplify(true)
252253
, mExecuteCommand(executeCommand)
253254
{
254255
}
@@ -384,7 +385,7 @@ unsigned int CppCheck::check(const std::string &path)
384385
clangimport::parseClangAstDump(&tokenizer, ast);
385386
ValueFlow::setValues(&tokenizer.list, const_cast<SymbolDatabase *>(tokenizer.getSymbolDatabase()), this, &mSettings);
386387
if (mSettings.debugnormal)
387-
tokenizer.printDebugOutput();
388+
tokenizer.printDebugOutput(1);
388389
checkNormalTokens(tokenizer);
389390
return mExitCode;
390391
}
@@ -755,8 +756,18 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
755756
checkUnusedFunctions.parseTokens(mTokenizer, filename.c_str(), &mSettings);
756757

757758
// simplify more if required, skip rest of iteration if failed
758-
if (hasRule("simple")) {
759-
std::cout << "Handling of \"simple\" rules was removed in Cppcheck 2.1. Rule is executed on normal token list instead." << std::endl;
759+
if (mSimplify && hasRule("simple")) {
760+
std::cout << "Handling of \"simple\" rules is deprecated and will be removed in Cppcheck 2.5." << std::endl;
761+
762+
// if further simplification fails then skip rest of iteration
763+
Timer timer3("Tokenizer::simplifyTokenList2", mSettings.showtime, &s_timerResults);
764+
result = mTokenizer.simplifyTokenList2();
765+
timer3.stop();
766+
if (!result)
767+
continue;
768+
769+
if (!Settings::terminated())
770+
executeRules("simple", mTokenizer);
760771
}
761772

762773
} catch (const simplecpp::Output &o) {
@@ -960,7 +971,6 @@ void CppCheck::checkNormalTokens(const Tokenizer &tokenizer)
960971
}
961972

962973
executeRules("normal", tokenizer);
963-
executeRules("simple", tokenizer);
964974
}
965975
}
966976

lib/cppcheck.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ class CPPCHECKLIB CppCheck : ErrorLogger {
128128
void tooManyConfigsError(const std::string &file, const std::size_t numberOfConfigurations);
129129
void purgedConfigurationMessage(const std::string &file, const std::string& configuration);
130130

131+
void dontSimplify() {
132+
mSimplify = false;
133+
}
134+
131135
/** Analyse whole program, run this after all TUs has been scanned.
132136
* This is deprecated and the plan is to remove this when
133137
* .analyzeinfo is good enough.
@@ -223,6 +227,9 @@ class CPPCHECKLIB CppCheck : ErrorLogger {
223227
/** Are there too many configs? */
224228
bool mTooManyConfigs;
225229

230+
/** Simplify code? true by default */
231+
bool mSimplify;
232+
226233
/** File info used for whole program analysis */
227234
std::list<Check::FileInfo*> mFileInfo;
228235

lib/settings.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Settings::Settings()
4141
daca(false),
4242
debugBugHunting(false),
4343
debugnormal(false),
44+
debugSimplified(false),
4445
debugtemplate(false),
4546
debugwarnings(false),
4647
dump(false),

lib/settings.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ class CPPCHECKLIB Settings : public cppcheck::Platform {
130130
/** @brief Is --debug-normal given? */
131131
bool debugnormal;
132132

133+
/** @brief Is --debug-simplified given? */
134+
bool debugSimplified;
135+
133136
/** @brief Is --debug-template given? */
134137
bool debugtemplate;
135138

0 commit comments

Comments
 (0)