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;
const Token *prev = tok->previous();
if (prev)
{
if (prev) {
// Ignore function definitions, class members or class definitions
if (prev->isName() || Token::Match(prev, ".|:"))
continue;

View File

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