checkMathFunctions: Refactoring the check

This commit is contained in:
PKEuS 2011-10-22 12:31:47 +02:00 committed by Daniel Marjamäki
parent 55d9f0873a
commit ccf087d2ea
2 changed files with 15 additions and 35 deletions

View File

@ -51,8 +51,7 @@ void CheckNonReentrantFunctions::nonReentrantFunctions()
continue; continue;
const Token *prev = tok->previous(); const Token *prev = tok->previous();
if (prev) if (prev) {
{
// Ignore function definitions, class members or class definitions // Ignore function definitions, class members or class definitions
if (prev->isName() || Token::Match(prev, ".|:")) if (prev->isName() || Token::Match(prev, ".|:"))
continue; continue;

View File

@ -870,7 +870,7 @@ void CheckOther::checkIncorrectLogicOperator()
enum Position { First, Second, NA }; enum Position { First, Second, NA };
enum Relation { Equal, NotEqual, Less, LessEqual, More, MoreEqual }; enum Relation { Equal, NotEqual, Less, LessEqual, More, MoreEqual };
enum LogicError { Exclusion, AlwaysTrue, AlwaysFalse, AlwaysFalseOr }; enum LogicError { Exclusion, AlwaysTrue, AlwaysFalse, AlwaysFalseOr };
struct Condition { static const struct Condition {
const char *before; const char *before;
Position position1; Position position1;
const char *op1TokStr; const char *op1TokStr;
@ -1794,40 +1794,21 @@ void CheckOther::zerodivError(const Token *tok)
void CheckOther::checkMathFunctions() void CheckOther::checkMathFunctions()
{ {
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) { for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
// case log(-2) if (tok->varId() == 0 && Token::Match(tok, "log|log10 ( %num% )")) {
if (tok->varId() == 0 && bool isNegative = MathLib::isNegative(tok->tokAt(2)->str());
Token::Match(tok, "log|log10 ( %num% )") && bool isInt = MathLib::isInt(tok->tokAt(2)->str());
MathLib::isNegative(tok->tokAt(2)->str()) && bool isFloat = MathLib::isFloat(tok->tokAt(2)->str());
MathLib::isInt(tok->tokAt(2)->str()) && if (isNegative && isInt && MathLib::toLongNumber(tok->tokAt(2)->str()) <= 0) {
MathLib::toLongNumber(tok->tokAt(2)->str()) <= 0) { mathfunctionCallError(tok); // case log(-2)
mathfunctionCallError(tok); } else if (isNegative && isFloat && MathLib::toDoubleNumber(tok->tokAt(2)->str()) <= 0.) {
} mathfunctionCallError(tok); // case log(-2.0)
// case log(-2.0) } else if (!isNegative && isFloat && MathLib::toDoubleNumber(tok->tokAt(2)->str()) <= 0.) {
else if (tok->varId() == 0 && mathfunctionCallError(tok); // case log(0.0)
Token::Match(tok, "log|log10 ( %num% )") && } else if (!isNegative && isInt && MathLib::toLongNumber(tok->tokAt(2)->str()) <= 0) {
MathLib::isNegative(tok->tokAt(2)->str()) && mathfunctionCallError(tok); // case log(0)
MathLib::isFloat(tok->tokAt(2)->str()) && }
MathLib::toDoubleNumber(tok->tokAt(2)->str()) <= 0.) {
mathfunctionCallError(tok);
} }
// case log(0.0)
else if (tok->varId() == 0 &&
Token::Match(tok, "log|log10 ( %num% )") &&
!MathLib::isNegative(tok->tokAt(2)->str()) &&
MathLib::isFloat(tok->tokAt(2)->str()) &&
MathLib::toDoubleNumber(tok->tokAt(2)->str()) <= 0.) {
mathfunctionCallError(tok);
}
// case log(0)
else if (tok->varId() == 0 &&
Token::Match(tok, "log|log10 ( %num% )") &&
!MathLib::isNegative(tok->tokAt(2)->str()) &&
MathLib::isInt(tok->tokAt(2)->str()) &&
MathLib::toLongNumber(tok->tokAt(2)->str()) <= 0) {
mathfunctionCallError(tok);
}
// acos( x ), asin( x ) where x is defined for intervall [-1,+1], but not beyound // acos( x ), asin( x ) where x is defined for intervall [-1,+1], but not beyound
else if (tok->varId() == 0 && else if (tok->varId() == 0 &&
Token::Match(tok, "acos|asin ( %num% )") && Token::Match(tok, "acos|asin ( %num% )") &&