Skip to content

Commit 1f5ddf6

Browse files
committed
moved some --debug --verbose logic out of Tokenizer
1 parent d95ae44 commit 1f5ddf6

3 files changed

Lines changed: 43 additions & 5 deletions

File tree

cli/cmdlineparser.cpp

Lines changed: 10 additions & 2 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;
@@ -667,7 +668,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
667668
// Show --debug output after the first simplifications
668669
else if (std::strcmp(argv[i], "--debug") == 0 ||
669670
std::strcmp(argv[i], "--debug-normal") == 0)
670-
mSettings.debugnormal = true;
671+
debug = true;
671672

672673
// Show debug warnings for lookup for configuration files
673674
else if (std::strcmp(argv[i], "--debug-lookup") == 0)
@@ -1618,10 +1619,17 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
16181619

16191620
if (mSettings.force)
16201621
mSettings.maxConfigs = INT_MAX;
1621-
16221622
else if ((def || mSettings.preprocessOnly) && !maxconfigs)
16231623
mSettings.maxConfigs = 1U;
16241624

1625+
if (debug) {
1626+
mSettings.debugnormal = true;
1627+
if (mSettings.verbose) {
1628+
mSettings.debugast = true;
1629+
mSettings.debugsymdb = true;
1630+
}
1631+
}
1632+
16251633
if (mSettings.jobs > 1 && mSettings.buildDir.empty()) {
16261634
// TODO: bail out instead?
16271635
if (mSettings.checks.isEnabled(Checks::unusedFunction))

lib/tokenize.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5941,7 +5941,6 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
59415941
}
59425942
//---------------------------------------------------------------------------
59435943

5944-
// TODO: do not depend on --verbose
59455944
void Tokenizer::printDebugOutput(std::ostream &out) const
59465945
{
59475946
if (!list.front())
@@ -5962,11 +5961,12 @@ void Tokenizer::printDebugOutput(std::ostream &out) const
59625961
if (mSymbolDatabase) {
59635962
if (xml)
59645963
mSymbolDatabase->printXml(out);
5965-
else if (mSettings.debugsymdb || (mSettings.debugnormal && mSettings.verbose))
5964+
else if (mSettings.debugsymdb)
59665965
mSymbolDatabase->printOut("Symbol database");
59675966
}
59685967

5969-
if (mSettings.debugast || (mSettings.debugnormal && mSettings.verbose))
5968+
// TODO: do not depend on --verbose
5969+
if (mSettings.debugast)
59705970
list.front()->printAst(mSettings.verbose, xml, list.getFiles(), out);
59715971

59725972
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);
@@ -3178,6 +3181,33 @@ class TestCmdlineParser : public TestFixture {
31783181
ASSERT_EQUALS(true, settings->debugvalueflow);
31793182
}
31803183

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

0 commit comments

Comments
 (0)