speed up checks by caching commonly looked up stuff in the symbol database (checkio)
This commit is contained in:
parent
8e14d7682c
commit
d7b658a5aa
|
@ -40,8 +40,12 @@ namespace {
|
|||
//---------------------------------------------------------------------------
|
||||
void CheckIO::checkCoutCerrMisusage()
|
||||
{
|
||||
const SymbolDatabase * const symbolDatabase = _tokenizer->getSymbolDatabase();
|
||||
std::size_t functions = symbolDatabase->functionScopes.size();
|
||||
for (std::size_t i = 0; i < functions; ++i) {
|
||||
const Scope * scope = symbolDatabase->functionScopes[i];
|
||||
bool firstCout = false;
|
||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
|
||||
for (const Token *tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) {
|
||||
if (tok->str() == "(")
|
||||
tok = tok->link();
|
||||
|
||||
|
@ -55,6 +59,7 @@ void CheckIO::checkCoutCerrMisusage()
|
|||
firstCout = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CheckIO::coutCerrMisusageError(const Token* tok, const std::string& streamName)
|
||||
{
|
||||
|
@ -116,8 +121,11 @@ void CheckIO::checkFileUsage()
|
|||
}
|
||||
}
|
||||
|
||||
std::size_t functions = symbolDatabase->functionScopes.size();
|
||||
for (std::size_t j = 0; j < functions; ++j) {
|
||||
const Scope * scope = symbolDatabase->functionScopes[j];
|
||||
unsigned int indent = 0;
|
||||
for (const Token* tok = _tokenizer->list.front(); tok; tok = tok->next()) {
|
||||
for (const Token *tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) {
|
||||
if (tok->str() == "{")
|
||||
indent++;
|
||||
else if (tok->str() == "}") {
|
||||
|
@ -248,6 +256,7 @@ void CheckIO::checkFileUsage()
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CheckIO::fflushOnInputStreamError(const Token *tok, const std::string &varname)
|
||||
{
|
||||
|
@ -289,7 +298,11 @@ void CheckIO::invalidScanf()
|
|||
if (!_settings->isEnabled("style"))
|
||||
return;
|
||||
|
||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
|
||||
const SymbolDatabase * const symbolDatabase = _tokenizer->getSymbolDatabase();
|
||||
std::size_t functions = symbolDatabase->functionScopes.size();
|
||||
for (std::size_t j = 0; j < functions; ++j) {
|
||||
const Scope * scope = symbolDatabase->functionScopes[j];
|
||||
for (const Token *tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
|
||||
const Token *formatToken = 0;
|
||||
if (Token::Match(tok, "scanf|vscanf ( %str% ,"))
|
||||
formatToken = tok->tokAt(2);
|
||||
|
@ -327,6 +340,7 @@ void CheckIO::invalidScanf()
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CheckIO::invalidScanfError(const Token *tok, bool portability)
|
||||
{
|
||||
|
@ -401,7 +415,10 @@ void CheckIO::checkWrongPrintfScanfArguments()
|
|||
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
|
||||
bool warning = _settings->isEnabled("style");
|
||||
|
||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
|
||||
std::size_t functions = symbolDatabase->functionScopes.size();
|
||||
for (std::size_t j = 0; j < functions; ++j) {
|
||||
const Scope * scope = symbolDatabase->functionScopes[j];
|
||||
for (const Token *tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
|
||||
if (!tok->isName()) continue;
|
||||
|
||||
const Token* argListTok = 0; // Points to first va_list argument
|
||||
|
@ -613,6 +630,7 @@ void CheckIO::checkWrongPrintfScanfArguments()
|
|||
wrongPrintfScanfArgumentsError(tok, tok->str(), numFormat, numFunction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CheckIO::wrongPrintfScanfArgumentsError(const Token* tok,
|
||||
const std::string &functionName,
|
||||
|
|
Loading…
Reference in New Issue