CheckOther::checkComparisonOfBoolWithBool,checkComparisonOfFuncReturningBool: use symbolDatabase to check only tokens in executable code.
This commit is contained in:
parent
9a462d8a0a
commit
60de3e75af
|
@ -2231,40 +2231,44 @@ void CheckOther::checkComparisonOfFuncReturningBool()
|
||||||
|
|
||||||
const SymbolDatabase * const symbolDatabase = _tokenizer->getSymbolDatabase();
|
const SymbolDatabase * const symbolDatabase = _tokenizer->getSymbolDatabase();
|
||||||
|
|
||||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
|
for (std::list<Scope>::const_iterator scope = symbolDatabase->scopeList.begin(); scope != symbolDatabase->scopeList.end(); ++scope) {
|
||||||
if (tok->previous() && tok->type() == Token::eComparisonOp && tok->str() != "==" && tok->str() != "!=") {
|
if (!scope->isExecutable())
|
||||||
const Token *first_token;
|
continue;
|
||||||
bool first_token_func_of_type_bool = false;
|
for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
|
||||||
if (Token::simpleMatch(tok->previous(), ")")) {
|
if (tok->previous() && tok->type() == Token::eComparisonOp && tok->str() != "==" && tok->str() != "!=") {
|
||||||
first_token = tok->previous()->link()->previous();
|
const Token *first_token;
|
||||||
} else {
|
bool first_token_func_of_type_bool = false;
|
||||||
first_token = tok->previous();
|
if (Token::simpleMatch(tok->previous(), ")")) {
|
||||||
}
|
first_token = tok->previous()->link()->previous();
|
||||||
if (Token::Match(first_token, "%var% (") && !Token::Match(first_token->previous(), "::|.")) {
|
} else {
|
||||||
const Function* func = symbolDatabase->findFunctionByName(first_token->str(), first_token->scope());
|
first_token = tok->previous();
|
||||||
if (func && func->tokenDef && func->tokenDef->strAt(-1) == "bool") {
|
|
||||||
first_token_func_of_type_bool = true;
|
|
||||||
}
|
}
|
||||||
}
|
if (Token::Match(first_token, "%var% (") && !Token::Match(first_token->previous(), "::|.")) {
|
||||||
|
const Function* func = symbolDatabase->findFunctionByName(first_token->str(), first_token->scope());
|
||||||
Token *second_token = tok->next();
|
if (func && func->tokenDef && func->tokenDef->strAt(-1) == "bool") {
|
||||||
bool second_token_func_of_type_bool = false;
|
first_token_func_of_type_bool = true;
|
||||||
while (second_token->str()=="!") {
|
}
|
||||||
second_token = second_token->next();
|
|
||||||
}
|
|
||||||
if (Token::Match(second_token, "%var% (") && !Token::Match(second_token->previous(), "::|.")) {
|
|
||||||
const Function* func = symbolDatabase->findFunctionByName(second_token->str(), second_token->scope());
|
|
||||||
if (func && func->tokenDef && func->tokenDef->strAt(-1) == "bool") {
|
|
||||||
second_token_func_of_type_bool = true;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ((first_token_func_of_type_bool == true) && (second_token_func_of_type_bool == true)) {
|
Token *second_token = tok->next();
|
||||||
comparisonOfTwoFuncsReturningBoolError(first_token->next(), first_token->str(), second_token->str());
|
bool second_token_func_of_type_bool = false;
|
||||||
} else if (first_token_func_of_type_bool == true) {
|
while (second_token->str()=="!") {
|
||||||
comparisonOfFuncReturningBoolError(first_token->next(), first_token->str());
|
second_token = second_token->next();
|
||||||
} else if (second_token_func_of_type_bool == true) {
|
}
|
||||||
comparisonOfFuncReturningBoolError(second_token->previous(), second_token->str());
|
if (Token::Match(second_token, "%var% (") && !Token::Match(second_token->previous(), "::|.")) {
|
||||||
|
const Function* func = symbolDatabase->findFunctionByName(second_token->str(), second_token->scope());
|
||||||
|
if (func && func->tokenDef && func->tokenDef->strAt(-1) == "bool") {
|
||||||
|
second_token_func_of_type_bool = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((first_token_func_of_type_bool == true) && (second_token_func_of_type_bool == true)) {
|
||||||
|
comparisonOfTwoFuncsReturningBoolError(first_token->next(), first_token->str(), second_token->str());
|
||||||
|
} else if (first_token_func_of_type_bool == true) {
|
||||||
|
comparisonOfFuncReturningBoolError(first_token->next(), first_token->str());
|
||||||
|
} else if (second_token_func_of_type_bool == true) {
|
||||||
|
comparisonOfFuncReturningBoolError(second_token->previous(), second_token->str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2307,25 +2311,29 @@ void CheckOther::checkComparisonOfBoolWithBool()
|
||||||
|
|
||||||
const SymbolDatabase* const symbolDatabase = _tokenizer->getSymbolDatabase();
|
const SymbolDatabase* const symbolDatabase = _tokenizer->getSymbolDatabase();
|
||||||
|
|
||||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
|
for (std::list<Scope>::const_iterator scope = symbolDatabase->scopeList.begin(); scope != symbolDatabase->scopeList.end(); ++scope) {
|
||||||
if (tok->previous() && tok->type() == Token::eComparisonOp && tok->str() != "==" && tok->str() != "!=") {
|
if (!scope->isExecutable())
|
||||||
bool first_token_bool = false;
|
continue;
|
||||||
bool second_token_bool = false;
|
for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
|
||||||
|
if (tok->previous() && tok->type() == Token::eComparisonOp && tok->str() != "==" && tok->str() != "!=") {
|
||||||
|
bool first_token_bool = false;
|
||||||
|
bool second_token_bool = false;
|
||||||
|
|
||||||
const Token *first_token = tok->previous();
|
const Token *first_token = tok->previous();
|
||||||
if (first_token->varId()) {
|
if (first_token->varId()) {
|
||||||
if (isBool(symbolDatabase->getVariableFromVarId(first_token->varId()))) {
|
if (isBool(symbolDatabase->getVariableFromVarId(first_token->varId()))) {
|
||||||
first_token_bool = true;
|
first_token_bool = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
const Token *second_token = tok->next();
|
||||||
const Token *second_token = tok->next();
|
if (second_token->varId()) {
|
||||||
if (second_token->varId()) {
|
if (isBool(symbolDatabase->getVariableFromVarId(second_token->varId()))) {
|
||||||
if (isBool(symbolDatabase->getVariableFromVarId(second_token->varId()))) {
|
second_token_bool = true;
|
||||||
second_token_bool = true;
|
}
|
||||||
|
}
|
||||||
|
if ((first_token_bool == true) && (second_token_bool == true)) {
|
||||||
|
comparisonOfBoolWithBoolError(first_token->next(), first_token->str());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if ((first_token_bool == true) && (second_token_bool == true)) {
|
|
||||||
comparisonOfBoolWithBoolError(first_token->next(), first_token->str());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue