Skip to content

Commit 6561762

Browse files
committed
moved some --debug --verbose logic out of Tokenizer
1 parent 1af769e commit 6561762

3 files changed

Lines changed: 61 additions & 5 deletions

File tree

cli/cmdlineparser.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
415415

416416
bool def = false;
417417
bool maxconfigs = false;
418+
bool debug = false;
418419

419420
ImportProject::Type projectType = ImportProject::Type::NONE;
420421
ImportProject project;
@@ -636,7 +637,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
636637
// Show --debug output after the first simplifications
637638
else if (std::strcmp(argv[i], "--debug") == 0 ||
638639
std::strcmp(argv[i], "--debug-normal") == 0)
639-
mSettings.debugnormal = true;
640+
debug = true;
640641

641642
// Show debug warnings for lookup for configuration files
642643
else if (std::strcmp(argv[i], "--debug-lookup") == 0)
@@ -1591,10 +1592,17 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
15911592

15921593
if (mSettings.force)
15931594
mSettings.maxConfigs = INT_MAX;
1594-
15951595
else if ((def || mSettings.preprocessOnly) && !maxconfigs)
15961596
mSettings.maxConfigs = 1U;
15971597

1598+
if (debug) {
1599+
mSettings.debugnormal = true;
1600+
if (mSettings.verbose) {
1601+
mSettings.debugast = true;
1602+
mSettings.debugsymdb = true;
1603+
}
1604+
}
1605+
15981606
if (mSettings.jobs > 1 && mSettings.buildDir.empty()) {
15991607
// TODO: bail out instead?
16001608
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: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,10 @@ class TestCmdlineParser : public TestFixture {
462462
TEST_CASE(debugSymdb);
463463
TEST_CASE(debugAst);
464464
TEST_CASE(debugValueflow);
465+
TEST_CASE(debugNormal);
466+
TEST_CASE(debugNormalVerbose);
467+
TEST_CASE(debug);
468+
TEST_CASE(debugVerbose);
465469

466470
TEST_CASE(ignorepaths1);
467471
TEST_CASE(ignorepaths2);
@@ -3179,6 +3183,50 @@ class TestCmdlineParser : public TestFixture {
31793183
ASSERT_EQUALS(true, settings->debugvalueflow);
31803184
}
31813185

3186+
void debugNormal() {
3187+
REDIRECT;
3188+
const char * const argv[] = {"cppcheck", "--debug-normal", "file.cpp"};
3189+
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
3190+
ASSERT_EQUALS(true, settings->debugnormal);
3191+
ASSERT_EQUALS(false, settings->debugSimplified);
3192+
ASSERT_EQUALS(false, settings->debugvalueflow);
3193+
ASSERT_EQUALS(false, settings->debugast);
3194+
ASSERT_EQUALS(false, settings->debugsymdb);
3195+
}
3196+
3197+
void debugNormalVerbose() {
3198+
REDIRECT;
3199+
const char * const argv[] = {"cppcheck", "--debug-normal", "--verbose", "file.cpp"};
3200+
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
3201+
ASSERT_EQUALS(true, settings->debugnormal);
3202+
ASSERT_EQUALS(false, settings->debugSimplified);
3203+
ASSERT_EQUALS(false, settings->debugvalueflow);
3204+
ASSERT_EQUALS(true, settings->debugast);
3205+
ASSERT_EQUALS(true, settings->debugsymdb);
3206+
}
3207+
3208+
void debug() {
3209+
REDIRECT;
3210+
const char * const argv[] = {"cppcheck", "--debug", "file.cpp"};
3211+
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
3212+
ASSERT_EQUALS(true, settings->debugnormal);
3213+
ASSERT_EQUALS(false, settings->debugSimplified);
3214+
ASSERT_EQUALS(false, settings->debugvalueflow);
3215+
ASSERT_EQUALS(false, settings->debugast);
3216+
ASSERT_EQUALS(false, settings->debugsymdb);
3217+
}
3218+
3219+
void debugVerbose() {
3220+
REDIRECT;
3221+
const char * const argv[] = {"cppcheck", "--debug", "--verbose", "file.cpp"};
3222+
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
3223+
ASSERT_EQUALS(true, settings->debugnormal);
3224+
ASSERT_EQUALS(false, settings->debugSimplified);
3225+
ASSERT_EQUALS(false, settings->debugvalueflow);
3226+
ASSERT_EQUALS(true, settings->debugast);
3227+
ASSERT_EQUALS(true, settings->debugsymdb);
3228+
}
3229+
31823230
void ignorepaths1() {
31833231
REDIRECT;
31843232
const char * const argv[] = {"cppcheck", "-isrc", "file.cpp"};

0 commit comments

Comments
 (0)