Added '--check-headers=no' option.
This commit is contained in:
parent
5087f15035
commit
f5c274b3b1
|
@ -155,6 +155,10 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
|||
else if (std::strcmp(argv[i], "--dump") == 0)
|
||||
mSettings->dump = true;
|
||||
|
||||
// --check-headers=no
|
||||
else if (std::strcmp(argv[i], "--check-headers=no") == 0)
|
||||
mSettings->checkHeaders = false;
|
||||
|
||||
// max ctu depth
|
||||
else if (std::strncmp(argv[i], "--max-ctu-depth=", 16) == 0)
|
||||
mSettings->maxCtuDepth = std::atoi(argv[i] + 16);
|
||||
|
@ -914,6 +918,8 @@ void CmdLineParser::printHelp()
|
|||
" incremental analysis, distributed analysis.\n"
|
||||
" --check-config Check cppcheck configuration. The normal code\n"
|
||||
" analysis is disabled by this flag.\n"
|
||||
" --check-headers=no Turn off checking of included files, to make the\n"
|
||||
" analysis faster.\n"
|
||||
" --check-library Show information messages when library files have\n"
|
||||
" incomplete info.\n"
|
||||
" --config-exclude=<dir>\n"
|
||||
|
|
|
@ -49,6 +49,7 @@ Settings::Settings()
|
|||
maxConfigs(12),
|
||||
enforcedLang(None),
|
||||
reportProgress(false),
|
||||
checkHeaders(true),
|
||||
checkConfiguration(false),
|
||||
checkLibrary(false)
|
||||
{
|
||||
|
|
|
@ -285,6 +285,10 @@ public:
|
|||
/** Check for incomplete info in library files? */
|
||||
bool checkLibrary;
|
||||
|
||||
/** Check code in the headers, this is on by default but can
|
||||
* be turned off to save CPU */
|
||||
bool checkHeaders;
|
||||
|
||||
/** Struct contains standards settings */
|
||||
Standards standards;
|
||||
|
||||
|
|
|
@ -3630,6 +3630,8 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
|
|||
|
||||
createLinks();
|
||||
|
||||
simplifyHeaders();
|
||||
|
||||
// Remove __asm..
|
||||
simplifyAsm();
|
||||
|
||||
|
@ -4257,6 +4259,40 @@ void Tokenizer::dump(std::ostream &out) const
|
|||
list.front()->printValueFlow(true, out);
|
||||
}
|
||||
|
||||
void Tokenizer::simplifyHeaders()
|
||||
{
|
||||
// TODO : can we remove anything in headers here? Like unused declarations.
|
||||
// Maybe if --dump is used we want to have _everything_.
|
||||
|
||||
if (mSettings->checkHeaders)
|
||||
// Default=full analysis. All information in the headers are kept.
|
||||
return;
|
||||
|
||||
// We want to remove selected stuff from the headers but not *everything*.
|
||||
// The intention here is to not damage the analysis of the source file.
|
||||
|
||||
// TODO: Remove unused types/variables/etc in headers..
|
||||
|
||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||
if (tok->fileIndex() == 0)
|
||||
// Keep all code in the source file
|
||||
continue;
|
||||
|
||||
// Remove executable code
|
||||
if (tok->str() == "{") {
|
||||
const Token *prev = tok->previous();
|
||||
while (prev && prev->isName())
|
||||
prev = prev->previous();
|
||||
if (Token::simpleMatch(prev, ")")) {
|
||||
// Replace all tokens from { to } with a ";".
|
||||
Token::eraseTokens(tok,tok->link()->next());
|
||||
tok->str(";");
|
||||
tok->link(nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Tokenizer::removeMacrosInGlobalScope()
|
||||
{
|
||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||
|
|
|
@ -164,6 +164,13 @@ public:
|
|||
*/
|
||||
bool simplifyTokenList2();
|
||||
|
||||
/**
|
||||
* If --check-headers=no has been given; then remove unneeded code in headers.
|
||||
* - All executable code.
|
||||
* - Unused types/variables/etc
|
||||
*/
|
||||
void simplifyHeaders();
|
||||
|
||||
/**
|
||||
* Deletes dead code between 'begin' and 'end'.
|
||||
* In general not everything can be erased, such as:
|
||||
|
|
Loading…
Reference in New Issue