Added --debug-warnings that we can use to enable various debug warnings

This commit is contained in:
Daniel Marjamäki 2010-08-27 20:28:00 +02:00
parent 8eee4cf2e8
commit d45186d645
11 changed files with 60 additions and 38 deletions

View File

@ -76,7 +76,7 @@ void CheckClass::createSymbolDatabase()
// only create variable list and base list if not namespace
if (!new_info->isNamespace)
{
new_info->getVarList();
new_info->getVarList(_settings->debugwarnings);
// goto initial '{'
tok2 = initBaseInfo(new_info, tok);
@ -417,7 +417,7 @@ const Token *CheckClass::initBaseInfo(SpaceInfo *info, const Token *tok)
return tok2;
}
void CheckClass::SpaceInfo::getVarList()
void CheckClass::SpaceInfo::getVarList(bool debugwarnings)
{
// Get variable list..
const Token *tok1 = classDef;
@ -629,9 +629,9 @@ void CheckClass::SpaceInfo::getVarList()
// If the vartok was set in the if-blocks above, create a entry for this variable..
if (vartok && vartok->str() != "operator")
{
if (vartok->varId() == 0)
if (vartok->varId() == 0 && debugwarnings)
{
check->reportError(vartok, Severity::error, "cppcheckError", "Internal error. CheckClass::SpaceInfo::getVarList found variable \'" + vartok->str() + "\' with varid 0.");
check->reportError(vartok, Severity::debug, "debug", "CheckClass::SpaceInfo::getVarList found variable \'" + vartok->str() + "\' with varid 0.");
}
varlist.push_back(Var(vartok, false, varaccess, isMutable, isStatic, isClass));

View File

@ -241,7 +241,7 @@ private:
void markAllVar(bool value);
/** @brief initialize varlist */
void getVarList();
void getVarList(bool debugwarnings);
/**
* @brief parse a scope for a constructor or member function and set the "init" flags in the provided varlist

View File

@ -2153,7 +2153,7 @@ void CheckMemoryLeakInFunction::checkScope(const Token *Tok1, const std::string
simplifycode(tok);
if (_settings->_debug && _settings->_verbose)
if (_settings->debug && _settings->_verbose)
{
tok->printOut(("Checkmemoryleak: simplifycode result for: " + varname).c_str());
}
@ -2183,7 +2183,7 @@ void CheckMemoryLeakInFunction::checkScope(const Token *Tok1, const std::string
}
// detect cases that "simplifycode" don't handle well..
else if (_settings->_debug)
else if (_settings->debugwarnings)
{
Token *first = tok;
while (first && first->str() == ";")
@ -2204,10 +2204,11 @@ void CheckMemoryLeakInFunction::checkScope(const Token *Tok1, const std::string
// Unhandled case..
if (! noerr)
{
std::cout << "Token listing..\n ";
std::ostringstream errmsg;
errmsg << "inconclusive leak: ";
for (const Token *tok2 = tok; tok2; tok2 = tok2->next())
std::cout << " " << tok2->str();
std::cout << "\n";
errmsg << " " << tok2->str();
reportError(_tokenizer->tokens(), Severity::debug, "debug", errmsg.str());
}
}

View File

@ -246,7 +246,11 @@ bool CppCheck::parseFromArgs(int argc, const char* const argv[])
// Flag used for various purposes during debugging
else if (strcmp(argv[i], "--debug") == 0)
_settings._debug = true;
_settings.debug = _settings.debugwarnings = true;
// Show debug warnings
else if (strcmp(argv[i], "--debug-warnings") == 0)
_settings.debugwarnings = true;
// Inconclusive checking - keep this for compatibility but don't
// handle it

View File

@ -1030,8 +1030,12 @@ std::list<std::string> Preprocessor::getcfgs(const std::string &filedata, const
if (unhandled)
{
// unhandled ifdef configuration..
if (_errorLogger && _settings && _settings->_debug)
_errorLogger->reportOut("unhandled configuration: " + *it);
if (_errorLogger && _settings && _settings->debugwarnings)
{
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
const ErrorLogger::ErrorMessage errmsg(locationList, Severity::debug, "unhandled configuration: " + *it, "debug");
_errorLogger->reportErr(errmsg);
}
ret.erase(it++);
}

View File

@ -28,7 +28,7 @@
Settings::Settings()
{
_debug = false;
debug = debugwarnings = false;
_checkCodingStyle = false;
_errorsOnly = false;
_inlineSuppressions = false;

View File

@ -49,7 +49,10 @@ public:
Settings();
/** @brief Is --debug given? */
bool _debug;
bool debug;
/** @brief Is --debug-warnings given? */
bool debugwarnings;
/** @brief Inconclusive checks - for debugging of Cppcheck */
bool inconclusive;

View File

@ -637,7 +637,15 @@ bool Tokenizer::duplicateTypedef(Token **tokPtr, const Token *name)
void Tokenizer::unsupportedTypedef(const Token *tok) const
{
#ifndef NDEBUG
// ###### The ifdef will be removed soon - the message will only be shown if --debug-warnings are given. #######
#ifdef NDEBUG
if (!_settings)
return;
if (!_settings->debugwarnings)
return;
#endif
std::ostringstream str;
const Token *tok1 = tok;
while (tok && tok->str() != ";")
@ -656,15 +664,14 @@ void Tokenizer::unsupportedTypedef(const Token *tok) const
locationList.push_back(loc);
const ErrorLogger::ErrorMessage errmsg(locationList,
Severity::error,
Severity::debug,
"Failed to parse \'" + str.str() + "\'. The checking continues anyway.",
"cppcheckError");
"debug");
if (_errorLogger)
_errorLogger->reportErr(errmsg);
else
Check::reportError(errmsg);
#endif
}
struct SpaceInfo
@ -2405,19 +2412,25 @@ void Tokenizer::simplifyTemplates()
namepos = 3;
else
{
#ifndef NDEBUG
// debug message that we bail out..
if (_settings && _settings->_debug)
if (_settings && _settings->debugwarnings)
{
std::cout << "simplifyTemplates debug-information: bailing out: "
<< file(tok->tokAt(namepos))
<< ": "
<< tok->tokAt(namepos)->linenr()
<< ": "
<< tok->tokAt(namepos)->str()
<< std::endl;
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
ErrorLogger::ErrorMessage::FileLocation loc;
loc.line = tok->linenr();
loc.setfile(file(tok));
locationList.push_back(loc);
const ErrorLogger::ErrorMessage errmsg(locationList,
Severity::debug,
"simplifyTemplates: bailing out",
"debug");
if (_errorLogger)
_errorLogger->reportErr(errmsg);
else
Check::reportError(errmsg);
}
#endif
continue;
}
if ((tok->tokAt(namepos)->str() == "*" || tok->tokAt(namepos)->str() == "&"))
@ -3910,7 +3923,7 @@ bool Tokenizer::simplifyTokenList()
removeRedundantAssignment();
simplifyComma();
if (_settings && _settings->_debug)
if (_settings && _settings->debug)
{
_tokens->printOut(0, _files);
}

View File

@ -741,7 +741,7 @@ private:
{
// Tokenize..
Settings settings;
settings._debug = true;
settings.debug = settings.debugwarnings = true;
Tokenizer tokenizer(&settings, NULL);
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");

View File

@ -1082,7 +1082,7 @@ private:
std::istringstream istr(filedata);
std::map<std::string, std::string> actual;
Settings settings;
settings._debug = true;
settings.debug = settings.debugwarnings = true;
settings._verbose = true;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c");
@ -1092,7 +1092,7 @@ private:
ASSERT_EQUALS("\n\n\n", actual[""]);
// the "defined(DEF_10) || defined(DEF_11)" are not handled correctly..
ASSERT_EQUALS("unhandled configuration: defined(DEF_10)||defined(DEF_11)\n", output.str());
ASSERT_EQUALS("(debug) unhandled configuration: defined(DEF_10)||defined(DEF_11)\n", errout.str());
TODO_ASSERT_EQUALS(2, actual.size());
TODO_ASSERT_EQUALS("\na1;\n\n", actual["DEF_10"]);

View File

@ -3704,6 +3704,7 @@ private:
Settings settings;
settings.inconclusive = true;
settings._checkCodingStyle = true;
settings.debugwarnings = true; // show warnings about unhandled typedef
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code);
errout.str("");
@ -4236,11 +4237,7 @@ private:
// this is invalid C so just make sure it doesn't crash
checkSimplifyTypedef(code);
#ifndef NDEBUG
ASSERT_EQUALS("[test.cpp:1]: (error) Failed to parse 'typedef int ( * int ( * ) ( ) ) ( ) ;'. The checking continues anyway.\n", errout.str());
#else
ASSERT_EQUALS("", errout.str());
#endif
ASSERT_EQUALS("[test.cpp:1]: (debug) Failed to parse 'typedef int ( * int ( * ) ( ) ) ( ) ;'. The checking continues anyway.\n", errout.str());
}
{