Tokenizer:simplifyMathFunctions: added support for acos[f|l] functions.

This commit is contained in:
orbitcowboy 2013-10-09 07:59:32 -07:00
parent 58c09f80b6
commit 6eaa2f2444
3 changed files with 38 additions and 8 deletions

View File

@ -8343,7 +8343,7 @@ bool Tokenizer::isTwoNumber(const std::string &s)
// exp2f(), exp2l(), log2(), log2f(), log2l(), log1p(), // exp2f(), exp2l(), log2(), log2f(), log2l(), log1p(),
// log1pf(), log1pl(), log10(), log10l(), log10f(), // log1pf(), log1pl(), log10(), log10l(), log10f(),
// log(),logf(),logl(),logb(),logbf(),logbl(), acosh() // log(),logf(),logl(),logb(),logbf(),logbl(), acosh()
// acoshf(), acoshl() // acoshf(), acoshl(), acos(), acosf(), acosl()
// in the tokenlist. // in the tokenlist.
// //
// Reference: // Reference:
@ -8420,11 +8420,10 @@ bool Tokenizer::simplifyMathFunctions()
tok->str("0"); // insert result into token list tok->str("0"); // insert result into token list
simplifcationMade = true; simplifcationMade = true;
} }
} else if (Token::Match(tok, "log2|log2f|log2l|log|logf|logl|log10|log10f|log10l|logb|logbf|logbl|acosh|acoshf|acoshl ( %num% )")) { } else if (Token::Match(tok, "log2|log2f|log2l|log|logf|logl|log10|log10f|log10l|logb|logbf|logbl|acosh|acoshf|acoshl|acos|acosf|acosl ( %num% )")) {
// Simplify: log2[f|l](1) = 0 , log10[f|l](1) = 0 // Simplify: log2[f|l](1) = 0 , log10[f|l](1) = 0
// log[f|l](1) = 0 , logb10[f|l](1) = 0 // log[f|l](1) = 0 , logb10[f|l](1) = 0
// acosh[f|l](1) = 0 // acosh[f|l](1) = 0, acos[f|l](1) = 0
// TODO: acos[f|l](1) = 0
// get number string // get number string
const std::string parameter(tok->tokAt(2)->str()); const std::string parameter(tok->tokAt(2)->str());
// is parameter 1 ? // is parameter 1 ?

View File

@ -1471,8 +1471,7 @@ private:
// acos, acosf, acosl // acos, acosf, acosl
check("void foo()\n" check("void foo()\n"
"{\n" "{\n"
" return acos(1) \n" " return acos(-1) \n"
" + acos(-1) \n"
" + acos(0.1) \n" " + acos(0.1) \n"
" + acos(0.0001) \n" " + acos(0.0001) \n"
" + acos(0.01) \n" " + acos(0.01) \n"
@ -1482,7 +1481,6 @@ private:
" + acos(0.1E-1) \n" " + acos(0.1E-1) \n"
" + acos(+0.1E-1) \n" " + acos(+0.1E-1) \n"
" + acos(-0.1E-1) \n" " + acos(-0.1E-1) \n"
" + acosf(1) \n"
" + acosf(-1) \n" " + acosf(-1) \n"
" + acosf(0.1) \n" " + acosf(0.1) \n"
" + acosf(0.0001) \n" " + acosf(0.0001) \n"
@ -1493,7 +1491,6 @@ private:
" + acosf(0.1E-1) \n" " + acosf(0.1E-1) \n"
" + acosf(+0.1E-1) \n" " + acosf(+0.1E-1) \n"
" + acosf(-0.1E-1) \n" " + acosf(-0.1E-1) \n"
" + acosl(1) \n"
" + acosl(-1) \n" " + acosl(-1) \n"
" + acosl(0.1) \n" " + acosl(0.1) \n"
" + acosl(0.0001) \n" " + acosl(0.0001) \n"

View File

@ -515,6 +515,7 @@ private:
TEST_CASE(simplifyMathFunctions_fmin); TEST_CASE(simplifyMathFunctions_fmin);
TEST_CASE(simplifyMathFunctions_fmax); TEST_CASE(simplifyMathFunctions_fmax);
TEST_CASE(simplifyMathFunctions_acosh); TEST_CASE(simplifyMathFunctions_acosh);
TEST_CASE(simplifyMathFunctions_acos);
TEST_CASE(simplifyMathExpressions); //ticket #1620 TEST_CASE(simplifyMathExpressions); //ticket #1620
@ -8344,6 +8345,39 @@ private:
ASSERT_EQUALS(false, Tokenizer::isTwoNumber("garbage")); ASSERT_EQUALS(false, Tokenizer::isTwoNumber("garbage"));
} }
void simplifyMathFunctions_acos() {
// verify acos(), acosf(), acosl() - simplifcation
const char code_acos[] ="void f(int x) {\n"
" std::cout << acos(x);\n" // do not simplify
" std::cout << acos(1L);\n" // simplify to 0
"}";
const char expected_acos[] = "void f ( int x ) {\n"
"std :: cout << acos ( x ) ;\n"
"std :: cout << 0 ;\n"
"}";
ASSERT_EQUALS(expected_acos, tokenizeAndStringify(code_acos));
const char code_acosf[] ="void f(float x) {\n"
" std::cout << acosf(x);\n" // do not simplify
" std::cout << acosf(1.0f);\n" // simplify to 0
"}";
const char expected_acosf[] = "void f ( float x ) {\n"
"std :: cout << acosf ( x ) ;\n"
"std :: cout << 0 ;\n"
"}";
ASSERT_EQUALS(expected_acosf, tokenizeAndStringify(code_acosf));
const char code_acosl[] ="void f(long double x) {\n"
" std::cout << acosl(x);\n" // do not simplify
" std::cout << acosl(1.0d);\n" // simplify to 0
"}";
const char expected_acosl[] = "void f ( long double x ) {\n"
"std :: cout << acosl ( x ) ;\n"
"std :: cout << 0 ;\n"
"}";
ASSERT_EQUALS(expected_acosl, tokenizeAndStringify(code_acosl));
}
void simplifyMathFunctions_acosh() { void simplifyMathFunctions_acosh() {
// verify acosh(), acoshf(), acoshl() - simplifcation // verify acosh(), acoshf(), acoshl() - simplifcation
const char code_acosh[] ="void f(int x) {\n" const char code_acosh[] ="void f(int x) {\n"