astyle formatting
This commit is contained in:
parent
0cad22314e
commit
8b5aae9adb
|
@ -2439,7 +2439,7 @@ 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)
|
// case log(-2)
|
||||||
if (Token::Match(tok, "log ( %num% )") &&
|
if (Token::Match(tok, "log ( %num% )") &&
|
||||||
MathLib::isNegative(tok->tokAt(2)->str()) &&
|
MathLib::isNegative(tok->tokAt(2)->str()) &&
|
||||||
MathLib::isInt(tok->tokAt(2)->str()) &&
|
MathLib::isInt(tok->tokAt(2)->str()) &&
|
||||||
|
@ -2447,32 +2447,32 @@ void CheckOther::checkMathFunctions()
|
||||||
{
|
{
|
||||||
mathfunctionCallError(tok);
|
mathfunctionCallError(tok);
|
||||||
}
|
}
|
||||||
// case log(-2.0)
|
// case log(-2.0)
|
||||||
else if (Token::Match(tok, "log ( %num% )") &&
|
else if (Token::Match(tok, "log ( %num% )") &&
|
||||||
MathLib::isNegative(tok->tokAt(2)->str()) &&
|
MathLib::isNegative(tok->tokAt(2)->str()) &&
|
||||||
MathLib::isFloat(tok->tokAt(2)->str()) &&
|
MathLib::isFloat(tok->tokAt(2)->str()) &&
|
||||||
MathLib::toDoubleNumber(tok->tokAt(2)->str()) <= 0.)
|
MathLib::toDoubleNumber(tok->tokAt(2)->str()) <= 0.)
|
||||||
{
|
{
|
||||||
mathfunctionCallError(tok);
|
mathfunctionCallError(tok);
|
||||||
}
|
}
|
||||||
|
|
||||||
// case log(0.0)
|
// case log(0.0)
|
||||||
else if (Token::Match(tok, "log ( %num% )") &&
|
else if (Token::Match(tok, "log ( %num% )") &&
|
||||||
!MathLib::isNegative(tok->tokAt(2)->str()) &&
|
!MathLib::isNegative(tok->tokAt(2)->str()) &&
|
||||||
MathLib::isFloat(tok->tokAt(2)->str()) &&
|
MathLib::isFloat(tok->tokAt(2)->str()) &&
|
||||||
MathLib::toDoubleNumber(tok->tokAt(2)->str()) <= 0.)
|
MathLib::toDoubleNumber(tok->tokAt(2)->str()) <= 0.)
|
||||||
{
|
{
|
||||||
mathfunctionCallError(tok);
|
mathfunctionCallError(tok);
|
||||||
}
|
}
|
||||||
|
|
||||||
// case log(0)
|
// case log(0)
|
||||||
else if (Token::Match(tok, "log ( %num% )") &&
|
else if (Token::Match(tok, "log ( %num% )") &&
|
||||||
!MathLib::isNegative(tok->tokAt(2)->str()) &&
|
!MathLib::isNegative(tok->tokAt(2)->str()) &&
|
||||||
MathLib::isInt(tok->tokAt(2)->str()) &&
|
MathLib::isInt(tok->tokAt(2)->str()) &&
|
||||||
MathLib::toLongNumber(tok->tokAt(2)->str()) <= 0)
|
MathLib::toLongNumber(tok->tokAt(2)->str()) <= 0)
|
||||||
{
|
{
|
||||||
mathfunctionCallError(tok);
|
mathfunctionCallError(tok);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2622,7 +2622,7 @@ void CheckOther::zerodivError(const Token *tok)
|
||||||
|
|
||||||
void CheckOther::mathfunctionCallError(const Token *tok)
|
void CheckOther::mathfunctionCallError(const Token *tok)
|
||||||
{
|
{
|
||||||
reportError(tok, Severity::error, "wrongmathcall","Passing value " + tok->tokAt(2)->str() + " to " + tok->str() + "() leads to undefined result");
|
reportError(tok, Severity::error, "wrongmathcall", "Passing value " + tok->tokAt(2)->str() + " to " + tok->str() + "() leads to undefined result");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckOther::postIncrementError(const Token *tok, const std::string &var_name, const bool isIncrement)
|
void CheckOther::postIncrementError(const Token *tok, const std::string &var_name, const bool isIncrement)
|
||||||
|
|
|
@ -82,7 +82,7 @@ public:
|
||||||
checkOther.strPlusChar();
|
checkOther.strPlusChar();
|
||||||
checkOther.invalidFunctionUsage();
|
checkOther.invalidFunctionUsage();
|
||||||
checkOther.checkZeroDivision();
|
checkOther.checkZeroDivision();
|
||||||
checkOther.checkMathFunctions();
|
checkOther.checkMathFunctions();
|
||||||
|
|
||||||
// New type of check: Check execution paths
|
// New type of check: Check execution paths
|
||||||
checkOther.executionPaths();
|
checkOther.executionPaths();
|
||||||
|
@ -151,8 +151,8 @@ public:
|
||||||
/** @brief %Check zero division*/
|
/** @brief %Check zero division*/
|
||||||
void checkZeroDivision();
|
void checkZeroDivision();
|
||||||
|
|
||||||
/** @brief %Check for parameters given to math function that do not make sense*/
|
/** @brief %Check for parameters given to math function that do not make sense*/
|
||||||
void checkMathFunctions();
|
void checkMathFunctions();
|
||||||
|
|
||||||
/** @brief %Check for post increment/decrement in for loop*/
|
/** @brief %Check for post increment/decrement in for loop*/
|
||||||
void postIncrement();
|
void postIncrement();
|
||||||
|
@ -188,7 +188,7 @@ public:
|
||||||
void uninitdataError(const Token *tok, const std::string &varname);
|
void uninitdataError(const Token *tok, const std::string &varname);
|
||||||
void uninitvarError(const Token *tok, const std::string &varname);
|
void uninitvarError(const Token *tok, const std::string &varname);
|
||||||
void zerodivError(const Token *tok);
|
void zerodivError(const Token *tok);
|
||||||
void mathfunctionCallError(const Token *tok);
|
void mathfunctionCallError(const Token *tok);
|
||||||
void postIncrementError(const Token *tok, const std::string &var_name, const bool isIncrement);
|
void postIncrementError(const Token *tok, const std::string &var_name, const bool isIncrement);
|
||||||
|
|
||||||
void getErrorMessages()
|
void getErrorMessages()
|
||||||
|
@ -201,7 +201,7 @@ public:
|
||||||
uninitdataError(0, "varname");
|
uninitdataError(0, "varname");
|
||||||
uninitvarError(0, "varname");
|
uninitvarError(0, "varname");
|
||||||
zerodivError(0);
|
zerodivError(0);
|
||||||
mathfunctionCallError(0);
|
mathfunctionCallError(0);
|
||||||
|
|
||||||
// style
|
// style
|
||||||
cstyleCastError(0);
|
cstyleCastError(0);
|
||||||
|
|
|
@ -77,15 +77,15 @@ std::string MathLib::toString(T d)
|
||||||
|
|
||||||
bool MathLib::isFloat(const std::string &s)
|
bool MathLib::isFloat(const std::string &s)
|
||||||
{
|
{
|
||||||
// every number that contains a . is a float
|
// every number that contains a . is a float
|
||||||
if (s.find("." , 0) != std::string::npos)
|
if (s.find("." , 0) != std::string::npos)
|
||||||
return true;
|
return true;
|
||||||
// scientific notation
|
// scientific notation
|
||||||
else if (s.find("E-", 0) != std::string::npos
|
else if (s.find("E-", 0) != std::string::npos
|
||||||
|| s.find("e-", 0) != std::string::npos)
|
|| s.find("e-", 0) != std::string::npos)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MathLib::isNegative(const std::string &s)
|
bool MathLib::isNegative(const std::string &s)
|
||||||
|
@ -94,11 +94,11 @@ bool MathLib::isNegative(const std::string &s)
|
||||||
unsigned long n = 0;
|
unsigned long n = 0;
|
||||||
// eat up whitespace
|
// eat up whitespace
|
||||||
while (std::isspace(s[n])) ++n;
|
while (std::isspace(s[n])) ++n;
|
||||||
// every negative number has a negative sign
|
// every negative number has a negative sign
|
||||||
if (s[n] == '-')
|
if (s[n] == '-')
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MathLib::isInt(const std::string & s)
|
bool MathLib::isInt(const std::string & s)
|
||||||
|
|
|
@ -37,8 +37,8 @@ public:
|
||||||
static std::string toString(T d);
|
static std::string toString(T d);
|
||||||
|
|
||||||
static bool isInt(const std::string & str);
|
static bool isInt(const std::string & str);
|
||||||
static bool isFloat(const std::string &str);
|
static bool isFloat(const std::string &str);
|
||||||
static bool isNegative(const std::string &str);
|
static bool isNegative(const std::string &str);
|
||||||
|
|
||||||
static std::string add(const std::string & first, const std::string & second);
|
static std::string add(const std::string & first, const std::string & second);
|
||||||
static std::string subtract(const std::string & first, const std::string & second);
|
static std::string subtract(const std::string & first, const std::string & second);
|
||||||
|
|
|
@ -167,23 +167,23 @@ private:
|
||||||
ASSERT_EQUALS(false, MathLib::isInt("+1.E-1"));
|
ASSERT_EQUALS(false, MathLib::isInt("+1.E-1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void isnegative()
|
void isnegative()
|
||||||
{
|
{
|
||||||
ASSERT_EQUALS(true, MathLib::isNegative("-1"));
|
ASSERT_EQUALS(true, MathLib::isNegative("-1"));
|
||||||
ASSERT_EQUALS(true, MathLib::isNegative("-1."));
|
ASSERT_EQUALS(true, MathLib::isNegative("-1."));
|
||||||
ASSERT_EQUALS(true, MathLib::isNegative("-1.0"));
|
ASSERT_EQUALS(true, MathLib::isNegative("-1.0"));
|
||||||
ASSERT_EQUALS(true, MathLib::isNegative("-1.0E+2"));
|
ASSERT_EQUALS(true, MathLib::isNegative("-1.0E+2"));
|
||||||
ASSERT_EQUALS(true, MathLib::isNegative("-1.0E-2"));
|
ASSERT_EQUALS(true, MathLib::isNegative("-1.0E-2"));
|
||||||
|
|
||||||
ASSERT_EQUALS(false, MathLib::isNegative("+1"));
|
ASSERT_EQUALS(false, MathLib::isNegative("+1"));
|
||||||
ASSERT_EQUALS(false, MathLib::isNegative("+1."));
|
ASSERT_EQUALS(false, MathLib::isNegative("+1."));
|
||||||
ASSERT_EQUALS(false, MathLib::isNegative("+1.0"));
|
ASSERT_EQUALS(false, MathLib::isNegative("+1.0"));
|
||||||
ASSERT_EQUALS(false, MathLib::isNegative("+1.0E+2"));
|
ASSERT_EQUALS(false, MathLib::isNegative("+1.0E+2"));
|
||||||
ASSERT_EQUALS(false, MathLib::isNegative("+1.0E-2"));
|
ASSERT_EQUALS(false, MathLib::isNegative("+1.0E-2"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void isfloat()
|
void isfloat()
|
||||||
{
|
{
|
||||||
ASSERT_EQUALS(false, MathLib::isFloat("0"));
|
ASSERT_EQUALS(false, MathLib::isFloat("0"));
|
||||||
ASSERT_EQUALS(true , MathLib::isFloat("0."));
|
ASSERT_EQUALS(true , MathLib::isFloat("0."));
|
||||||
ASSERT_EQUALS(true , MathLib::isFloat("0.0"));
|
ASSERT_EQUALS(true , MathLib::isFloat("0.0"));
|
||||||
|
@ -194,7 +194,7 @@ private:
|
||||||
ASSERT_EQUALS(true , MathLib::isFloat("+0.0E+1"));
|
ASSERT_EQUALS(true , MathLib::isFloat("+0.0E+1"));
|
||||||
ASSERT_EQUALS(true , MathLib::isFloat("+0.0E-1"));
|
ASSERT_EQUALS(true , MathLib::isFloat("+0.0E-1"));
|
||||||
ASSERT_EQUALS(true , MathLib::isFloat("-0.0E+1"));
|
ASSERT_EQUALS(true , MathLib::isFloat("-0.0E+1"));
|
||||||
ASSERT_EQUALS(true , MathLib::isFloat("-0.0E-1"));
|
ASSERT_EQUALS(true , MathLib::isFloat("-0.0E-1"));
|
||||||
|
|
||||||
ASSERT_EQUALS(false , MathLib::isFloat("1"));
|
ASSERT_EQUALS(false , MathLib::isFloat("1"));
|
||||||
ASSERT_EQUALS(false , MathLib::isFloat("-1"));
|
ASSERT_EQUALS(false , MathLib::isFloat("-1"));
|
||||||
|
@ -214,7 +214,7 @@ private:
|
||||||
ASSERT_EQUALS(true , MathLib::isFloat("1.0E+1"));
|
ASSERT_EQUALS(true , MathLib::isFloat("1.0E+1"));
|
||||||
ASSERT_EQUALS(true , MathLib::isFloat("1.0E-1"));
|
ASSERT_EQUALS(true , MathLib::isFloat("1.0E-1"));
|
||||||
ASSERT_EQUALS(true , MathLib::isFloat("-1.0E+1"));
|
ASSERT_EQUALS(true , MathLib::isFloat("-1.0E+1"));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
REGISTER_TEST(TestMathLib)
|
REGISTER_TEST(TestMathLib)
|
||||||
|
|
|
@ -90,7 +90,7 @@ private:
|
||||||
|
|
||||||
TEST_CASE(passedByValue);
|
TEST_CASE(passedByValue);
|
||||||
|
|
||||||
TEST_CASE(mathfunctionCall1);
|
TEST_CASE(mathfunctionCall1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void check(const char code[])
|
void check(const char code[])
|
||||||
|
@ -112,7 +112,7 @@ private:
|
||||||
checkOther.warningRedundantCode();
|
checkOther.warningRedundantCode();
|
||||||
checkOther.checkZeroDivision();
|
checkOther.checkZeroDivision();
|
||||||
checkOther.unreachableCode();
|
checkOther.unreachableCode();
|
||||||
checkOther.checkMathFunctions();
|
checkOther.checkMathFunctions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2158,8 +2158,8 @@ private:
|
||||||
ASSERT_EQUALS("[test.cpp:1]: (style) Function parameter 'v' is passed by value. It could be passed by reference instead.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:1]: (style) Function parameter 'v' is passed by value. It could be passed by reference instead.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void mathfunctionCall1()
|
void mathfunctionCall1()
|
||||||
{
|
{
|
||||||
check("void foo()\n"
|
check("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" std::cout << log(-2) << std::endl;\n"
|
" std::cout << log(-2) << std::endl;\n"
|
||||||
|
@ -2176,7 +2176,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" std::cout << log(-1.0) << std::endl;\n"
|
" std::cout << log(-1.0) << std::endl;\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -1.0 to log() leads to undefined result\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -1.0 to log() leads to undefined result\n", errout.str());
|
||||||
|
|
||||||
check("void foo()\n"
|
check("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -2219,7 +2219,7 @@ private:
|
||||||
" std::cout << log(1E-3) << std::endl;\n"
|
" std::cout << log(1E-3) << std::endl;\n"
|
||||||
"}");
|
"}");
|
||||||
TODO_ASSERT_EQUALS("", errout.str());
|
TODO_ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue