Skip to content

Commit 169bc78

Browse files
committed
moved some --debug --verbose logic out of Tokenizer
1 parent 291c053 commit 169bc78

3 files changed

Lines changed: 46 additions & 6 deletions

File tree

cli/cmdlineparser.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
446446

447447
bool def = false;
448448
bool maxconfigs = false;
449+
bool debug = false;
449450

450451
ImportProject::Type projectType = ImportProject::Type::NONE;
451452
ImportProject project;
@@ -651,6 +652,9 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
651652
mSettings.cppHeaderProbe = true;
652653
}
653654

655+
else if (std::strcmp(argv[i], "--debug") == 0)
656+
debug = true;
657+
654658
else if (std::strcmp(argv[i], "--debug-ast") == 0)
655659
mSettings.debugast = true;
656660

@@ -663,8 +667,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
663667
mSettings.debugignore = true;
664668

665669
// Show --debug output after the first simplifications
666-
else if (std::strcmp(argv[i], "--debug") == 0 ||
667-
std::strcmp(argv[i], "--debug-normal") == 0)
670+
else if (std::strcmp(argv[i], "--debug-normal") == 0)
668671
mSettings.debugnormal = true;
669672

670673
// Show debug warnings for lookup for configuration files
@@ -1610,10 +1613,17 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
16101613

16111614
if (mSettings.force)
16121615
mSettings.maxConfigs = INT_MAX;
1613-
16141616
else if ((def || mSettings.preprocessOnly) && !maxconfigs)
16151617
mSettings.maxConfigs = 1U;
16161618

1619+
if (debug) {
1620+
mSettings.debugnormal = true;
1621+
if (mSettings.verbose) {
1622+
mSettings.debugast = true;
1623+
mSettings.debugsymdb = true;
1624+
}
1625+
}
1626+
16171627
if (mSettings.jobs > 1 && mSettings.buildDir.empty()) {
16181628
// TODO: bail out instead?
16191629
if (mSettings.checks.isEnabled(Checks::unusedFunction))

lib/tokenize.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5938,7 +5938,6 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
59385938
}
59395939
//---------------------------------------------------------------------------
59405940

5941-
// TODO: do not depend on --verbose
59425941
void Tokenizer::printDebugOutput(std::ostream &out) const
59435942
{
59445943
if (!list.front())
@@ -5959,11 +5958,12 @@ void Tokenizer::printDebugOutput(std::ostream &out) const
59595958
if (mSymbolDatabase) {
59605959
if (xml)
59615960
mSymbolDatabase->printXml(out);
5962-
else if (mSettings.debugsymdb || (mSettings.debugnormal && mSettings.verbose))
5961+
else if (mSettings.debugsymdb)
59635962
mSymbolDatabase->printOut("Symbol database");
59645963
}
59655964

5966-
if (mSettings.debugast || (mSettings.debugnormal && mSettings.verbose))
5965+
// TODO: do not depend on --verbose
5966+
if (mSettings.debugast)
59675967
list.front()->printAst(mSettings.verbose, xml, list.getFiles(), out);
59685968

59695969
if (mSettings.debugnormal || mSettings.debugvalueflow)

test/testcmdlineparser.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,9 @@ class TestCmdlineParser : public TestFixture {
462462
TEST_CASE(debugSymdb);
463463
TEST_CASE(debugAst);
464464
TEST_CASE(debugValueflow);
465+
TEST_CASE(debugNormal);
466+
TEST_CASE(debug);
467+
TEST_CASE(debugVerbose);
465468

466469
TEST_CASE(ignorepaths1);
467470
TEST_CASE(ignorepaths2);
@@ -3173,6 +3176,33 @@ class TestCmdlineParser : public TestFixture {
31733176
ASSERT_EQUALS(true, settings->debugvalueflow);
31743177
}
31753178

3179+
void debugNormal() {
3180+
REDIRECT;
3181+
const char * const argv[] = {"cppcheck", "--debug-normal", "file.cpp"};
3182+
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
3183+
ASSERT_EQUALS(true, settings->debugnormal);
3184+
}
3185+
3186+
void debug() {
3187+
REDIRECT;
3188+
const char * const argv[] = {"cppcheck", "--debug", "file.cpp"};
3189+
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
3190+
ASSERT_EQUALS(true, settings->debugnormal);
3191+
ASSERT_EQUALS(false, settings->debugvalueflow);
3192+
ASSERT_EQUALS(false, settings->debugast);
3193+
ASSERT_EQUALS(false, settings->debugsymdb);
3194+
}
3195+
3196+
void debugVerbose() {
3197+
REDIRECT;
3198+
const char * const argv[] = {"cppcheck", "--debug", "--verbose", "file.cpp"};
3199+
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
3200+
ASSERT_EQUALS(true, settings->debugnormal);
3201+
ASSERT_EQUALS(false, settings->debugvalueflow);
3202+
ASSERT_EQUALS(true, settings->debugast);
3203+
ASSERT_EQUALS(true, settings->debugsymdb);
3204+
}
3205+
31763206
void ignorepaths1() {
31773207
REDIRECT;
31783208
const char * const argv[] = {"cppcheck", "-isrc", "file.cpp"};

0 commit comments

Comments
 (0)