speed up checks by caching commonly looked up stuff in the symbol database (checkIncorrectLogicOperator). Ticket: #4266.
This commit is contained in:
parent
f82eff6589
commit
6578b78077
|
@ -1170,28 +1170,36 @@ void CheckOther::checkIncorrectLogicOperator()
|
||||||
if (!_settings->isEnabled("style"))
|
if (!_settings->isEnabled("style"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (const Token* tok = _tokenizer->tokens(); tok; tok = tok->next()) {
|
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
|
||||||
|
const std::size_t functions = symbolDatabase->functionScopes.size();
|
||||||
|
for (std::size_t ii = 0; ii < functions; ++ii) {
|
||||||
|
const Scope * scope = symbolDatabase->functionScopes[ii];
|
||||||
|
for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
|
||||||
// Find a pair of comparison expressions with or without parenthesis
|
// Find a pair of comparison expressions with or without parenthesis
|
||||||
// with a shared variable and constants and with a logical operator between them.
|
// with a shared variable and constants and with a logical operator between them.
|
||||||
// e.g. if (x != 3 || x != 4)
|
// e.g. if (x != 3 || x != 4)
|
||||||
const Token *term1Tok = NULL, *term2Tok = NULL;
|
const Token *term1Tok = NULL, *term2Tok = NULL;
|
||||||
const Token *op1Tok = NULL, *op2Tok = NULL, *op3Tok = NULL, *nextTok = NULL;
|
const Token *op1Tok = NULL, *op2Tok = NULL, *op3Tok = NULL, *nextTok = NULL;
|
||||||
|
|
||||||
if (Token::Match(tok, "( %any% !=|==|<|>|>=|<= %any% ) &&|%oror%")) {
|
if (Token::Match(tok, "( %any% %op% %any% ) &&|%oror%") &&
|
||||||
|
tok->tokAt(2)->isComparisonOp()) {
|
||||||
term1Tok = tok->next();
|
term1Tok = tok->next();
|
||||||
op1Tok = tok->tokAt(2);
|
op1Tok = tok->tokAt(2);
|
||||||
op2Tok = tok->tokAt(5);
|
op2Tok = tok->tokAt(5);
|
||||||
} else if (Token::Match(tok, "%any% !=|==|<|>|>=|<= %any% &&|%oror%")) {
|
} else if (Token::Match(tok, "%any% %op% %any% &&|%oror%") &&
|
||||||
|
tok->tokAt(1)->isComparisonOp()) {
|
||||||
term1Tok = tok;
|
term1Tok = tok;
|
||||||
op1Tok = tok->next();
|
op1Tok = tok->next();
|
||||||
op2Tok = tok->tokAt(3);
|
op2Tok = tok->tokAt(3);
|
||||||
}
|
}
|
||||||
if (op2Tok) {
|
if (op2Tok) {
|
||||||
if (Token::Match(op2Tok->next(), "( %any% !=|==|<|>|>=|<= %any% ) %any%")) {
|
if (Token::Match(op2Tok->next(), "( %any% %op% %any% ) %any%") &&
|
||||||
|
op2Tok->tokAt(3)->isComparisonOp()) {
|
||||||
term2Tok = op2Tok->tokAt(2);
|
term2Tok = op2Tok->tokAt(2);
|
||||||
op3Tok = op2Tok->tokAt(3);
|
op3Tok = op2Tok->tokAt(3);
|
||||||
nextTok = op2Tok->tokAt(6);
|
nextTok = op2Tok->tokAt(6);
|
||||||
} else if (Token::Match(op2Tok->next(), "%any% !=|==|<|>|>=|<= %any% %any%")) {
|
} else if (Token::Match(op2Tok->next(), "%any% %op% %any% %any%") &&
|
||||||
|
op2Tok->tokAt(2)->isComparisonOp()) {
|
||||||
term2Tok = op2Tok->next();
|
term2Tok = op2Tok->next();
|
||||||
op3Tok = op2Tok->tokAt(2);
|
op3Tok = op2Tok->tokAt(2);
|
||||||
nextTok = op2Tok->tokAt(4);
|
nextTok = op2Tok->tokAt(4);
|
||||||
|
@ -1364,6 +1372,7 @@ void CheckOther::checkIncorrectLogicOperator()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckOther::incorrectLogicOperatorError(const Token *tok, const std::string &condition, bool always)
|
void CheckOther::incorrectLogicOperatorError(const Token *tok, const std::string &condition, bool always)
|
||||||
|
|
|
@ -190,6 +190,9 @@ public:
|
||||||
return isOp() ||
|
return isOp() ||
|
||||||
_type == eExtendedOp;
|
_type == eExtendedOp;
|
||||||
}
|
}
|
||||||
|
bool isComparisonOp() const {
|
||||||
|
return _type == eComparisonOp;
|
||||||
|
}
|
||||||
bool isAssignmentOp() const {
|
bool isAssignmentOp() const {
|
||||||
return _type == eAssignmentOp;
|
return _type == eAssignmentOp;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue