From 7610513c49ef70ee5ffa79f3e2f706e04f327be9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 8 Apr 2019 18:59:54 +0200 Subject: [PATCH] Fixed #9090 (Do not simplify standard functions) --- lib/tokenize.cpp | 6 +- test/testsimplifytokens.cpp | 1294 +++++++++++++++++++++++++++++++++++ test/testtokenize.cpp | 1292 ---------------------------------- 3 files changed, 1297 insertions(+), 1295 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 527ee98a3..21d56968e 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4465,9 +4465,6 @@ bool Tokenizer::simplifyTokenList1(const char FileName[]) // Change initialisation of variable to assignment simplifyInitVar(); - // Convert e.g. atol("0") into 0 - simplifyMathFunctions(); - simplifyDoublePlusAndDoubleMinus(); simplifyArrayAccessSyntax(); @@ -4502,6 +4499,9 @@ bool Tokenizer::simplifyTokenList2() tok->clearValueFlow(); } + // Convert e.g. atol("0") into 0 + simplifyMathFunctions(); + // f(x=g()) => x=g(); f(x) simplifyAssignmentInFunctionCall(); diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 24e1cdaf4..e3940743a 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -52,6 +52,36 @@ private: // correct order TEST_CASE(simplifyTokenList1); + TEST_CASE(simplifyMathFunctions_sqrt); + TEST_CASE(simplifyMathFunctions_cbrt); + TEST_CASE(simplifyMathFunctions_exp); + TEST_CASE(simplifyMathFunctions_exp2); + TEST_CASE(simplifyMathFunctions_logb); + TEST_CASE(simplifyMathFunctions_log1p); + TEST_CASE(simplifyMathFunctions_ilogb); + TEST_CASE(simplifyMathFunctions_log10); + TEST_CASE(simplifyMathFunctions_log); + TEST_CASE(simplifyMathFunctions_log2); + TEST_CASE(simplifyMathFunctions_pow); + TEST_CASE(simplifyMathFunctions_fmin); + TEST_CASE(simplifyMathFunctions_fmax); + TEST_CASE(simplifyMathFunctions_acosh); + TEST_CASE(simplifyMathFunctions_acos); + TEST_CASE(simplifyMathFunctions_cosh); + TEST_CASE(simplifyMathFunctions_cos); + TEST_CASE(simplifyMathFunctions_erfc); + TEST_CASE(simplifyMathFunctions_erf); + TEST_CASE(simplifyMathFunctions_sin); + TEST_CASE(simplifyMathFunctions_sinh); + TEST_CASE(simplifyMathFunctions_asin); + TEST_CASE(simplifyMathFunctions_asinh); + TEST_CASE(simplifyMathFunctions_tan); + TEST_CASE(simplifyMathFunctions_tanh); + TEST_CASE(simplifyMathFunctions_atan); + TEST_CASE(simplifyMathFunctions_atanh); + TEST_CASE(simplifyMathFunctions_expm1); + TEST_CASE(simplifyMathExpressions); //ticket #1620 + // foo(p = new char[10]); => p = new char[10]; foo(p); TEST_CASE(simplifyAssignmentInFunctionCall); @@ -307,6 +337,1270 @@ private: tok(";while((x=f())==-1 && errno==EINTR){}",true)); } + + void simplifyMathFunctions_erfc() { + // verify erfc(), erfcf(), erfcl() - simplifcation + const char code_erfc[] ="void f(int x) {\n" + " std::cout << erfc(x);\n" // do not simplify + " std::cout << erfc(0L);\n" // simplify to 1 + "}"; + const char expected_erfc[] = "void f ( int x ) {\n" + "std :: cout << erfc ( x ) ;\n" + "std :: cout << 1 ;\n" + "}"; + ASSERT_EQUALS(expected_erfc, tok(code_erfc)); + + const char code_erfcf[] ="void f(float x) {\n" + " std::cout << erfcf(x);\n" // do not simplify + " std::cout << erfcf(0.0f);\n" // simplify to 1 + "}"; + const char expected_erfcf[] = "void f ( float x ) {\n" + "std :: cout << erfcf ( x ) ;\n" + "std :: cout << 1 ;\n" + "}"; + ASSERT_EQUALS(expected_erfcf, tok(code_erfcf)); + + const char code_erfcl[] ="void f(long double x) {\n" + " std::cout << erfcl(x);\n" // do not simplify + " std::cout << erfcl(0.0f);\n" // simplify to 1 + "}"; + const char expected_erfcl[] = "void f ( long double x ) {\n" + "std :: cout << erfcl ( x ) ;\n" + "std :: cout << 1 ;\n" + "}"; + ASSERT_EQUALS(expected_erfcl, tok(code_erfcl)); + } + + void simplifyMathFunctions_cos() { + // verify cos(), cosf(), cosl() - simplifcation + const char code_cos[] ="void f(int x) {\n" + " std::cout << cos(x);\n" // do not simplify + " std::cout << cos(0L);\n" // simplify to 1 + "}"; + const char expected_cos[] = "void f ( int x ) {\n" + "std :: cout << cos ( x ) ;\n" + "std :: cout << 1 ;\n" + "}"; + ASSERT_EQUALS(expected_cos, tok(code_cos)); + + const char code_cosf[] ="void f(float x) {\n" + " std::cout << cosf(x);\n" // do not simplify + " std::cout << cosf(0.0f);\n" // simplify to 1 + "}"; + const char expected_cosf[] = "void f ( float x ) {\n" + "std :: cout << cosf ( x ) ;\n" + "std :: cout << 1 ;\n" + "}"; + ASSERT_EQUALS(expected_cosf, tok(code_cosf)); + + const char code_cosl[] ="void f(long double x) {\n" + " std::cout << cosl(x);\n" // do not simplify + " std::cout << cosl(0.0f);\n" // simplify to 1 + "}"; + const char expected_cosl[] = "void f ( long double x ) {\n" + "std :: cout << cosl ( x ) ;\n" + "std :: cout << 1 ;\n" + "}"; + ASSERT_EQUALS(expected_cosl, tok(code_cosl)); + } + + void simplifyMathFunctions_cosh() { + // verify cosh(), coshf(), coshl() - simplifcation + const char code_cosh[] ="void f(int x) {\n" + " std::cout << cosh(x);\n" // do not simplify + " std::cout << cosh(0L);\n" // simplify to 1 + "}"; + const char expected_cosh[] = "void f ( int x ) {\n" + "std :: cout << cosh ( x ) ;\n" + "std :: cout << 1 ;\n" + "}"; + ASSERT_EQUALS(expected_cosh, tok(code_cosh)); + + const char code_coshf[] ="void f(float x) {\n" + " std::cout << coshf(x);\n" // do not simplify + " std::cout << coshf(0.0f);\n" // simplify to 1 + "}"; + const char expected_coshf[] = "void f ( float x ) {\n" + "std :: cout << coshf ( x ) ;\n" + "std :: cout << 1 ;\n" + "}"; + ASSERT_EQUALS(expected_coshf, tok(code_coshf)); + + const char code_coshl[] ="void f(long double x) {\n" + " std::cout << coshl(x);\n" // do not simplify + " std::cout << coshl(0.0f);\n" // simplify to 1 + "}"; + const char expected_coshl[] = "void f ( long double x ) {\n" + "std :: cout << coshl ( x ) ;\n" + "std :: cout << 1 ;\n" + "}"; + ASSERT_EQUALS(expected_coshl, tok(code_coshl)); + } + + 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, tok(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, tok(code_acosf)); + + const char code_acosl[] ="void f(long double x) {\n" + " std::cout << acosl(x);\n" // do not simplify + " std::cout << acosl(1.0f);\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, tok(code_acosl)); + } + + void simplifyMathFunctions_acosh() { + // verify acosh(), acoshf(), acoshl() - simplifcation + const char code_acosh[] ="void f(int x) {\n" + " std::cout << acosh(x);\n" // do not simplify + " std::cout << acosh(1L);\n" // simplify to 0 + "}"; + const char expected_acosh[] = "void f ( int x ) {\n" + "std :: cout << acosh ( x ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_acosh, tok(code_acosh)); + + const char code_acoshf[] ="void f(float x) {\n" + " std::cout << acoshf(x);\n" // do not simplify + " std::cout << acoshf(1.0f);\n" // simplify to 0 + "}"; + const char expected_acoshf[] = "void f ( float x ) {\n" + "std :: cout << acoshf ( x ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_acoshf, tok(code_acoshf)); + + const char code_acoshl[] ="void f(long double x) {\n" + " std::cout << acoshl(x);\n" // do not simplify + " std::cout << acoshl(1.0f);\n" // simplify to 0 + "}"; + const char expected_acoshl[] = "void f ( long double x ) {\n" + "std :: cout << acoshl ( x ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_acoshl, tok(code_acoshl)); + } + + void simplifyMathFunctions_sqrt() { + // verify sqrt(), sqrtf(), sqrtl() - simplifcation + const char code_sqrt[] ="void f(int x) {\n" + " std::cout << sqrt(x);\n" // do not simplify + " std::cout << sqrt(-1);\n" // do not simplify + " std::cout << sqrt(0L);\n" // simplify to 0 + " std::cout << sqrt(1L);\n" // simplify to 1 + "}"; + const char expected_sqrt[] = "void f ( int x ) {\n" + "std :: cout << sqrt ( x ) ;\n" + "std :: cout << sqrt ( -1 ) ;\n" + "std :: cout << 0 ;\n" + "std :: cout << 1 ;\n" + "}"; + ASSERT_EQUALS(expected_sqrt, tok(code_sqrt)); + + const char code_sqrtf[] ="void f(float x) {\n" + " std::cout << sqrtf(x);\n" // do not simplify + " std::cout << sqrtf(-1.0f);\n" // do not simplify + " std::cout << sqrtf(0.0f);\n" // simplify to 0 + " std::cout << sqrtf(1.0);\n" // simplify to 1 + "}"; + const char expected_sqrtf[] = "void f ( float x ) {\n" + "std :: cout << sqrtf ( x ) ;\n" + "std :: cout << sqrtf ( -1.0f ) ;\n" + "std :: cout << 0 ;\n" + "std :: cout << 1 ;\n" + "}"; + ASSERT_EQUALS(expected_sqrtf, tok(code_sqrtf)); + + const char code_sqrtl[] ="void f(long double x) {\n" + " std::cout << sqrtf(x);\n" // do not simplify + " std::cout << sqrtf(-1.0);\n" // do not simplify + " std::cout << sqrtf(0.0);\n" // simplify to 0 + " std::cout << sqrtf(1.0);\n" // simplify to 1 + "}"; + const char expected_sqrtl[] = "void f ( long double x ) {\n" + "std :: cout << sqrtf ( x ) ;\n" + "std :: cout << sqrtf ( -1.0 ) ;\n" + "std :: cout << 0 ;\n" + "std :: cout << 1 ;\n" + "}"; + ASSERT_EQUALS(expected_sqrtl, tok(code_sqrtl)); + } + + void simplifyMathFunctions_cbrt() { + // verify cbrt(), cbrtf(), cbrtl() - simplifcation + const char code_cbrt[] ="void f(int x) {\n" + " std::cout << cbrt(x);\n" // do not simplify + " std::cout << cbrt(-1);\n" // do not simplify + " std::cout << cbrt(0L);\n" // simplify to 0 + " std::cout << cbrt(1L);\n" // simplify to 1 + "}"; + const char expected_cbrt[] = "void f ( int x ) {\n" + "std :: cout << cbrt ( x ) ;\n" + "std :: cout << cbrt ( -1 ) ;\n" + "std :: cout << 0 ;\n" + "std :: cout << 1 ;\n" + "}"; + ASSERT_EQUALS(expected_cbrt, tok(code_cbrt)); + + const char code_cbrtf[] ="void f(float x) {\n" + " std::cout << cbrtf(x);\n" // do not simplify + " std::cout << cbrtf(-1.0f);\n" // do not simplify + " std::cout << cbrtf(0.0f);\n" // simplify to 0 + " std::cout << cbrtf(1.0);\n" // simplify to 1 + "}"; + const char expected_cbrtf[] = "void f ( float x ) {\n" + "std :: cout << cbrtf ( x ) ;\n" + "std :: cout << cbrtf ( -1.0f ) ;\n" + "std :: cout << 0 ;\n" + "std :: cout << 1 ;\n" + "}"; + ASSERT_EQUALS(expected_cbrtf, tok(code_cbrtf)); + + const char code_cbrtl[] ="void f(long double x) {\n" + " std::cout << cbrtl(x);\n" // do not simplify + " std::cout << cbrtl(-1.0);\n" // do not simplify + " std::cout << cbrtl(0.0);\n" // simplify to 0 + " std::cout << cbrtl(1.0);\n" // simplify to 1 + "}"; + const char expected_cbrtl[] = "void f ( long double x ) {\n" + "std :: cout << cbrtl ( x ) ;\n" + "std :: cout << cbrtl ( -1.0 ) ;\n" + "std :: cout << 0 ;\n" + "std :: cout << 1 ;\n" + "}"; + ASSERT_EQUALS(expected_cbrtl, tok(code_cbrtl)); + } + + void simplifyMathFunctions_exp2() { + // verify exp2(), exp2f(), exp2l() - simplifcation + const char code_exp2[] ="void f(int x) {\n" + " std::cout << exp2(x);\n" // do not simplify + " std::cout << exp2(-1);\n" // do not simplify + " std::cout << exp2(0L);\n" // simplify to 0 + " std::cout << exp2(1L);\n" // do not simplify + "}"; + const char expected_exp2[] = "void f ( int x ) {\n" + "std :: cout << exp2 ( x ) ;\n" + "std :: cout << exp2 ( -1 ) ;\n" + "std :: cout << 1 ;\n" + "std :: cout << exp2 ( 1L ) ;\n" + "}"; + ASSERT_EQUALS(expected_exp2, tok(code_exp2)); + + const char code_exp2f[] ="void f(float x) {\n" + " std::cout << exp2f(x);\n" // do not simplify + " std::cout << exp2f(-1.0);\n" // do not simplify + " std::cout << exp2f(0.0);\n" // simplify to 1 + " std::cout << exp2f(1.0);\n" // do not simplify + "}"; + const char expected_exp2f[] = "void f ( float x ) {\n" + "std :: cout << exp2f ( x ) ;\n" + "std :: cout << exp2f ( -1.0 ) ;\n" + "std :: cout << 1 ;\n" + "std :: cout << exp2f ( 1.0 ) ;\n" + "}"; + ASSERT_EQUALS(expected_exp2f, tok(code_exp2f)); + + const char code_exp2l[] ="void f(long double x) {\n" + " std::cout << exp2l(x);\n" // do not simplify + " std::cout << exp2l(-1.0);\n" // do not simplify + " std::cout << exp2l(0.0);\n" // simplify to 1 + " std::cout << exp2l(1.0);\n" // do not simplify + "}"; + const char expected_exp2l[] = "void f ( long double x ) {\n" + "std :: cout << exp2l ( x ) ;\n" + "std :: cout << exp2l ( -1.0 ) ;\n" + "std :: cout << 1 ;\n" + "std :: cout << exp2l ( 1.0 ) ;\n" + "}"; + ASSERT_EQUALS(expected_exp2l, tok(code_exp2l)); + } + + void simplifyMathFunctions_exp() { + // verify exp(), expf(), expl() - simplifcation + const char code_exp[] ="void f(int x) {\n" + " std::cout << exp(x);\n" // do not simplify + " std::cout << exp(-1);\n" // do not simplify + " std::cout << exp(0L);\n" // simplify to 1 + " std::cout << exp(1L);\n" // do not simplify + "}"; + const char expected_exp[] = "void f ( int x ) {\n" + "std :: cout << exp ( x ) ;\n" + "std :: cout << exp ( -1 ) ;\n" + "std :: cout << 1 ;\n" + "std :: cout << exp ( 1L ) ;\n" + "}"; + ASSERT_EQUALS(expected_exp, tok(code_exp)); + + const char code_expf[] ="void f(float x) {\n" + " std::cout << expf(x);\n" // do not simplify + " std::cout << expf(-1.0);\n" // do not simplify + " std::cout << expf(0.0);\n" // simplify to 1 + " std::cout << expf(1.0);\n" // do not simplify + "}"; + const char expected_expf[] = "void f ( float x ) {\n" + "std :: cout << expf ( x ) ;\n" + "std :: cout << expf ( -1.0 ) ;\n" + "std :: cout << 1 ;\n" + "std :: cout << expf ( 1.0 ) ;\n" + "}"; + ASSERT_EQUALS(expected_expf, tok(code_expf)); + + const char code_expl[] ="void f(long double x) {\n" + " std::cout << expl(x);\n" // do not simplify + " std::cout << expl(-1.0);\n" // do not simplify + " std::cout << expl(0.0);\n" // simplify to 1 + " std::cout << expl(1.0);\n" // do not simplify + "}"; + const char expected_expl[] = "void f ( long double x ) {\n" + "std :: cout << expl ( x ) ;\n" + "std :: cout << expl ( -1.0 ) ;\n" + "std :: cout << 1 ;\n" + "std :: cout << expl ( 1.0 ) ;\n" + "}"; + ASSERT_EQUALS(expected_expl, tok(code_expl)); + } + + void simplifyMathFunctions_erf() { + // verify erf(), erff(), erfl() - simplifcation + const char code_erf[] ="void f(int x) {\n" + " std::cout << erf(x);\n" // do not simplify + " std::cout << erf(10);\n" // do not simplify + " std::cout << erf(0L);\n" // simplify to 0 + "}"; + const char expected_erf[] = "void f ( int x ) {\n" + "std :: cout << erf ( x ) ;\n" + "std :: cout << erf ( 10 ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_erf, tok(code_erf)); + + const char code_erff[] ="void f(float x) {\n" + " std::cout << erff(x);\n" // do not simplify + " std::cout << erff(10);\n" // do not simplify + " std::cout << erff(0.0f);\n" // simplify to 0 + "}"; + const char expected_erff[] = "void f ( float x ) {\n" + "std :: cout << erff ( x ) ;\n" + "std :: cout << erff ( 10 ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_erff, tok(code_erff)); + + const char code_erfl[] ="void f(long double x) {\n" + " std::cout << erfl(x);\n" // do not simplify + " std::cout << erfl(10.0f);\n" // do not simplify + " std::cout << erfl(0.0f);\n" // simplify to 0 + "}"; + const char expected_erfl[] = "void f ( long double x ) {\n" + "std :: cout << erfl ( x ) ;\n" + "std :: cout << erfl ( 10.0f ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_erfl, tok(code_erfl)); + } + + void simplifyMathFunctions_atanh() { + // verify atanh(), atanhf(), atanhl() - simplifcation + const char code_atanh[] ="void f(int x) {\n" + " std::cout << atanh(x);\n" // do not simplify + " std::cout << atanh(10);\n" // do not simplify + " std::cout << atanh(0L);\n" // simplify to 0 + "}"; + const char expected_atanh[] = "void f ( int x ) {\n" + "std :: cout << atanh ( x ) ;\n" + "std :: cout << atanh ( 10 ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_atanh, tok(code_atanh)); + + const char code_atanhf[] ="void f(float x) {\n" + " std::cout << atanhf(x);\n" // do not simplify + " std::cout << atanhf(10);\n" // do not simplify + " std::cout << atanhf(0.0f);\n" // simplify to 0 + "}"; + const char expected_atanhf[] = "void f ( float x ) {\n" + "std :: cout << atanhf ( x ) ;\n" + "std :: cout << atanhf ( 10 ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_atanhf, tok(code_atanhf)); + + const char code_atanhl[] ="void f(long double x) {\n" + " std::cout << atanhl(x);\n" // do not simplify + " std::cout << atanhl(10.0f);\n" // do not simplify + " std::cout << atanhl(0.0d);\n" // do not simplify - invalid number! + " std::cout << atanhl(0.0f);\n" // simplify to 0 + "}"; + const char expected_atanhl[] = "void f ( long double x ) {\n" + "std :: cout << atanhl ( x ) ;\n" + "std :: cout << atanhl ( 10.0f ) ;\n" + "std :: cout << atanhl ( 0.0d ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_atanhl, tok(code_atanhl)); + } + + void simplifyMathFunctions_atan() { + // verify atan(), atanf(), atanl() - simplifcation + const char code_atan[] ="void f(int x) {\n" + " std::cout << atan(x);\n" // do not simplify + " std::cout << atan(10);\n" // do not simplify + " std::cout << atan(0L);\n" // simplify to 0 + "}"; + const char expected_atan[] = "void f ( int x ) {\n" + "std :: cout << atan ( x ) ;\n" + "std :: cout << atan ( 10 ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_atan, tok(code_atan)); + + const char code_atanf[] ="void f(float x) {\n" + " std::cout << atanf(x);\n" // do not simplify + " std::cout << atanf(10);\n" // do not simplify + " std::cout << atanf(0.0f);\n" // simplify to 0 + "}"; + const char expected_atanf[] = "void f ( float x ) {\n" + "std :: cout << atanf ( x ) ;\n" + "std :: cout << atanf ( 10 ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_atanf, tok(code_atanf)); + + const char code_atanl[] ="void f(long double x) {\n" + " std::cout << atanl(x);\n" // do not simplify + " std::cout << atanl(10.0f);\n" // do not simplify + " std::cout << atanl(0.0f);\n" // simplify to 0 + "}"; + const char expected_atanl[] = "void f ( long double x ) {\n" + "std :: cout << atanl ( x ) ;\n" + "std :: cout << atanl ( 10.0f ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_atanl, tok(code_atanl)); + } + + void simplifyMathFunctions_tanh() { + // verify tanh(), tanhf(), tanhl() - simplifcation + const char code_tanh[] ="void f(int x) {\n" + " std::cout << tanh(x);\n" // do not simplify + " std::cout << tanh(10);\n" // do not simplify + " std::cout << tanh(0L);\n" // simplify to 0 + "}"; + const char expected_tanh[] = "void f ( int x ) {\n" + "std :: cout << tanh ( x ) ;\n" + "std :: cout << tanh ( 10 ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_tanh, tok(code_tanh)); + + const char code_tanhf[] ="void f(float x) {\n" + " std::cout << tanhf(x);\n" // do not simplify + " std::cout << tanhf(10);\n" // do not simplify + " std::cout << tanhf(0.0f);\n" // simplify to 0 + "}"; + const char expected_tanhf[] = "void f ( float x ) {\n" + "std :: cout << tanhf ( x ) ;\n" + "std :: cout << tanhf ( 10 ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_tanhf, tok(code_tanhf)); + + const char code_tanhl[] ="void f(long double x) {\n" + " std::cout << tanhl(x);\n" // do not simplify + " std::cout << tanhl(10.0f);\n" // do not simplify + " std::cout << tanhl(0.0f);\n" // simplify to 0 + "}"; + const char expected_tanhl[] = "void f ( long double x ) {\n" + "std :: cout << tanhl ( x ) ;\n" + "std :: cout << tanhl ( 10.0f ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_tanhl, tok(code_tanhl)); + } + + void simplifyMathFunctions_tan() { + // verify tan(), tanf(), tanl() - simplifcation + const char code_tan[] ="void f(int x) {\n" + " std::cout << tan(x);\n" // do not simplify + " std::cout << tan(10);\n" // do not simplify + " std::cout << tan(0L);\n" // simplify to 0 + "}"; + const char expected_tan[] = "void f ( int x ) {\n" + "std :: cout << tan ( x ) ;\n" + "std :: cout << tan ( 10 ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_tan, tok(code_tan)); + + const char code_tanf[] ="void f(float x) {\n" + " std::cout << tanf(x);\n" // do not simplify + " std::cout << tanf(10);\n" // do not simplify + " std::cout << tanf(0.0f);\n" // simplify to 0 + "}"; + const char expected_tanf[] = "void f ( float x ) {\n" + "std :: cout << tanf ( x ) ;\n" + "std :: cout << tanf ( 10 ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_tanf, tok(code_tanf)); + + const char code_tanl[] ="void f(long double x) {\n" + " std::cout << tanl(x);\n" // do not simplify + " std::cout << tanl(10.0f);\n" // do not simplify + " std::cout << tanl(0.0f);\n" // simplify to 0 + "}"; + const char expected_tanl[] = "void f ( long double x ) {\n" + "std :: cout << tanl ( x ) ;\n" + "std :: cout << tanl ( 10.0f ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_tanl, tok(code_tanl)); + } + + void simplifyMathFunctions_expm1() { + // verify expm1(), expm1f(), expm1l() - simplifcation + const char code_expm1[] ="void f(int x) {\n" + " std::cout << expm1(x);\n" // do not simplify + " std::cout << expm1(10);\n" // do not simplify + " std::cout << expm1(0L);\n" // simplify to 0 + "}"; + const char expected_expm1[] = "void f ( int x ) {\n" + "std :: cout << expm1 ( x ) ;\n" + "std :: cout << expm1 ( 10 ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_expm1, tok(code_expm1)); + + const char code_expm1f[] ="void f(float x) {\n" + " std::cout << expm1f(x);\n" // do not simplify + " std::cout << expm1f(10);\n" // do not simplify + " std::cout << expm1f(0.0f);\n" // simplify to 0 + "}"; + const char expected_expm1f[] = "void f ( float x ) {\n" + "std :: cout << expm1f ( x ) ;\n" + "std :: cout << expm1f ( 10 ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_expm1f, tok(code_expm1f)); + + const char code_expm1l[] ="void f(long double x) {\n" + " std::cout << expm1l(x);\n" // do not simplify + " std::cout << expm1l(10.0f);\n" // do not simplify + " std::cout << expm1l(0.0f);\n" // simplify to 0 + "}"; + const char expected_expm1l[] = "void f ( long double x ) {\n" + "std :: cout << expm1l ( x ) ;\n" + "std :: cout << expm1l ( 10.0f ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_expm1l, tok(code_expm1l)); + } + + void simplifyMathFunctions_asinh() { + // verify asinh(), asinhf(), asinhl() - simplifcation + const char code_asinh[] ="void f(int x) {\n" + " std::cout << asinh(x);\n" // do not simplify + " std::cout << asinh(10);\n" // do not simplify + " std::cout << asinh(0L);\n" // simplify to 0 + "}"; + const char expected_asinh[] = "void f ( int x ) {\n" + "std :: cout << asinh ( x ) ;\n" + "std :: cout << asinh ( 10 ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_asinh, tok(code_asinh)); + + const char code_asinhf[] ="void f(float x) {\n" + " std::cout << asinhf(x);\n" // do not simplify + " std::cout << asinhf(10);\n" // do not simplify + " std::cout << asinhf(0.0f);\n" // simplify to 0 + "}"; + const char expected_asinhf[] = "void f ( float x ) {\n" + "std :: cout << asinhf ( x ) ;\n" + "std :: cout << asinhf ( 10 ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_asinhf, tok(code_asinhf)); + + const char code_asinhl[] ="void f(long double x) {\n" + " std::cout << asinhl(x);\n" // do not simplify + " std::cout << asinhl(10.0f);\n" // do not simplify + " std::cout << asinhl(0.0f);\n" // simplify to 0 + "}"; + const char expected_asinhl[] = "void f ( long double x ) {\n" + "std :: cout << asinhl ( x ) ;\n" + "std :: cout << asinhl ( 10.0f ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_asinhl, tok(code_asinhl)); + } + + void simplifyMathFunctions_asin() { + // verify asin(), asinf(), asinl() - simplifcation + const char code_asin[] ="void f(int x) {\n" + " std::cout << asin(x);\n" // do not simplify + " std::cout << asin(10);\n" // do not simplify + " std::cout << asin(0L);\n" // simplify to 0 + "}"; + const char expected_asin[] = "void f ( int x ) {\n" + "std :: cout << asin ( x ) ;\n" + "std :: cout << asin ( 10 ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_asin, tok(code_asin)); + + const char code_asinf[] ="void f(float x) {\n" + " std::cout << asinf(x);\n" // do not simplify + " std::cout << asinf(10);\n" // do not simplify + " std::cout << asinf(0.0f);\n" // simplify to 0 + "}"; + const char expected_asinf[] = "void f ( float x ) {\n" + "std :: cout << asinf ( x ) ;\n" + "std :: cout << asinf ( 10 ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_asinf, tok(code_asinf)); + + const char code_asinl[] ="void f(long double x) {\n" + " std::cout << asinl(x);\n" // do not simplify + " std::cout << asinl(10.0f);\n" // do not simplify + " std::cout << asinl(0.0f);\n" // simplify to 0 + "}"; + const char expected_asinl[] = "void f ( long double x ) {\n" + "std :: cout << asinl ( x ) ;\n" + "std :: cout << asinl ( 10.0f ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_asinl, tok(code_asinl)); + } + + void simplifyMathFunctions_sinh() { + // verify sinh(), sinhf(), sinhl() - simplifcation + const char code_sinh[] ="void f(int x) {\n" + " std::cout << sinh(x);\n" // do not simplify + " std::cout << sinh(10);\n" // do not simplify + " std::cout << sinh(0L);\n" // simplify to 0 + "}"; + const char expected_sinh[] = "void f ( int x ) {\n" + "std :: cout << sinh ( x ) ;\n" + "std :: cout << sinh ( 10 ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_sinh, tok(code_sinh)); + + const char code_sinhf[] ="void f(float x) {\n" + " std::cout << sinhf(x);\n" // do not simplify + " std::cout << sinhf(10);\n" // do not simplify + " std::cout << sinhf(0.0f);\n" // simplify to 0 + "}"; + const char expected_sinhf[] = "void f ( float x ) {\n" + "std :: cout << sinhf ( x ) ;\n" + "std :: cout << sinhf ( 10 ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_sinhf, tok(code_sinhf)); + + const char code_sinhl[] ="void f(long double x) {\n" + " std::cout << sinhl(x);\n" // do not simplify + " std::cout << sinhl(10.0f);\n" // do not simplify + " std::cout << sinhl(0.0f);\n" // simplify to 0 + "}"; + const char expected_sinhl[] = "void f ( long double x ) {\n" + "std :: cout << sinhl ( x ) ;\n" + "std :: cout << sinhl ( 10.0f ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_sinhl, tok(code_sinhl)); + } + + void simplifyMathFunctions_sin() { + // verify sin(), sinf(), sinl() - simplifcation + const char code_sin[] ="void f(int x) {\n" + " std::cout << sin(x);\n" // do not simplify + " std::cout << sin(10);\n" // do not simplify + " std::cout << sin(0L);\n" // simplify to 0 + "}"; + const char expected_sin[] = "void f ( int x ) {\n" + "std :: cout << sin ( x ) ;\n" + "std :: cout << sin ( 10 ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_sin, tok(code_sin)); + + const char code_sinf[] ="void f(float x) {\n" + " std::cout << sinf(x);\n" // do not simplify + " std::cout << sinf(10);\n" // do not simplify + " std::cout << sinf(0.0f);\n" // simplify to 0 + "}"; + const char expected_sinf[] = "void f ( float x ) {\n" + "std :: cout << sinf ( x ) ;\n" + "std :: cout << sinf ( 10 ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_sinf, tok(code_sinf)); + + const char code_sinl[] ="void f(long double x) {\n" + " std::cout << sinl(x);\n" // do not simplify + " std::cout << sinl(10.0f);\n" // do not simplify + " std::cout << sinl(0.0f);\n" // simplify to 0 + "}"; + const char expected_sinl[] = "void f ( long double x ) {\n" + "std :: cout << sinl ( x ) ;\n" + "std :: cout << sinl ( 10.0f ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_sinl, tok(code_sinl)); + + // #6629 + const char code[] = "class Foo { int sinf; Foo() : sinf(0) {} };"; + const char expected[] = "class Foo { int sinf ; Foo ( ) : sinf ( 0 ) { } } ;"; + ASSERT_EQUALS(expected, tok(code)); + } + + void simplifyMathFunctions_ilogb() { + // verify ilogb(), ilogbf(), ilogbl() - simplifcation + const char code_ilogb[] ="void f(int x) {\n" + " std::cout << ilogb(x);\n" // do not simplify + " std::cout << ilogb(10);\n" // do not simplify + " std::cout << ilogb(1L);\n" // simplify to 0 + "}"; + const char expected_ilogb[] = "void f ( int x ) {\n" + "std :: cout << ilogb ( x ) ;\n" + "std :: cout << ilogb ( 10 ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_ilogb, tok(code_ilogb)); + + const char code_ilogbf[] ="void f(float x) {\n" + " std::cout << ilogbf(x);\n" // do not simplify + " std::cout << ilogbf(10);\n" // do not simplify + " std::cout << ilogbf(1.0f);\n" // simplify to 0 + "}"; + const char expected_ilogbf[] = "void f ( float x ) {\n" + "std :: cout << ilogbf ( x ) ;\n" + "std :: cout << ilogbf ( 10 ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_ilogbf, tok(code_ilogbf)); + + const char code_ilogbl[] ="void f(long double x) {\n" + " std::cout << ilogbl(x);\n" // do not simplify + " std::cout << ilogbl(10.0f);\n" // do not simplify + " std::cout << ilogbl(1.0f);\n" // simplify to 0 + "}"; + const char expected_ilogbl[] = "void f ( long double x ) {\n" + "std :: cout << ilogbl ( x ) ;\n" + "std :: cout << ilogbl ( 10.0f ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_ilogbl, tok(code_ilogbl)); + } + + void simplifyMathFunctions_logb() { + // verify logb(), logbf(), logbl() - simplifcation + const char code_logb[] ="void f(int x) {\n" + " std::cout << logb(x);\n" // do not simplify + " std::cout << logb(10);\n" // do not simplify + " std::cout << logb(1L);\n" // simplify to 0 + "}"; + const char expected_logb[] = "void f ( int x ) {\n" + "std :: cout << logb ( x ) ;\n" + "std :: cout << logb ( 10 ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_logb, tok(code_logb)); + + const char code_logbf[] ="void f(float x) {\n" + " std::cout << logbf(x);\n" // do not simplify + " std::cout << logbf(10);\n" // do not simplify + " std::cout << logbf(1.0f);\n" // simplify to 0 + "}"; + const char expected_logbf[] = "void f ( float x ) {\n" + "std :: cout << logbf ( x ) ;\n" + "std :: cout << logbf ( 10 ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_logbf, tok(code_logbf)); + + const char code_logbl[] ="void f(long double x) {\n" + " std::cout << logbl(x);\n" // do not simplify + " std::cout << logbl(10.0f);\n" // do not simplify + " std::cout << logbl(1.0f);\n" // simplify to 0 + "}"; + const char expected_logbl[] = "void f ( long double x ) {\n" + "std :: cout << logbl ( x ) ;\n" + "std :: cout << logbl ( 10.0f ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_logbl, tok(code_logbl)); + } + + void simplifyMathFunctions_log1p() { + // verify log1p(), log1pf(), log1pl() - simplifcation + const char code_log1p[] ="void f(int x) {\n" + " std::cout << log1p(x);\n" // do not simplify + " std::cout << log1p(10);\n" // do not simplify + " std::cout << log1p(0L);\n" // simplify to 0 + "}"; + const char expected_log1p[] = "void f ( int x ) {\n" + "std :: cout << log1p ( x ) ;\n" + "std :: cout << log1p ( 10 ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_log1p, tok(code_log1p)); + + const char code_log1pf[] ="void f(float x) {\n" + " std::cout << log1pf(x);\n" // do not simplify + " std::cout << log1pf(10);\n" // do not simplify + " std::cout << log1pf(0.0f);\n" // simplify to 0 + "}"; + const char expected_log1pf[] = "void f ( float x ) {\n" + "std :: cout << log1pf ( x ) ;\n" + "std :: cout << log1pf ( 10 ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_log1pf, tok(code_log1pf)); + + const char code_log1pl[] ="void f(long double x) {\n" + " std::cout << log1pl(x);\n" // do not simplify + " std::cout << log1pl(10.0f);\n" // do not simplify + " std::cout << log1pl(0.0f);\n" // simplify to 0 + "}"; + const char expected_log1pl[] = "void f ( long double x ) {\n" + "std :: cout << log1pl ( x ) ;\n" + "std :: cout << log1pl ( 10.0f ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_log1pl, tok(code_log1pl)); + } + + void simplifyMathFunctions_log10() { + // verify log10(), log10f(), log10l() - simplifcation + const char code_log10[] ="void f(int x) {\n" + " std::cout << log10(x);\n" // do not simplify + " std::cout << log10(10);\n" // do not simplify + " std::cout << log10(1L);\n" // simplify to 0 + "}"; + const char expected_log10[] = "void f ( int x ) {\n" + "std :: cout << log10 ( x ) ;\n" + "std :: cout << log10 ( 10 ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_log10, tok(code_log10)); + + const char code_log10f[] ="void f(float x) {\n" + " std::cout << log10f(x);\n" // do not simplify + " std::cout << log10f(10);\n" // do not simplify + " std::cout << log10f(1.0f);\n" // simplify to 0 + "}"; + const char expected_log10f[] = "void f ( float x ) {\n" + "std :: cout << log10f ( x ) ;\n" + "std :: cout << log10f ( 10 ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_log10f, tok(code_log10f)); + + const char code_log10l[] ="void f(long double x) {\n" + " std::cout << log10l(x);\n" // do not simplify + " std::cout << log10l(10.0f);\n" // do not simplify + " std::cout << log10l(1.0f);\n" // simplify to 0 + "}"; + const char expected_log10l[] = "void f ( long double x ) {\n" + "std :: cout << log10l ( x ) ;\n" + "std :: cout << log10l ( 10.0f ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_log10l, tok(code_log10l)); + + } + void simplifyMathFunctions_log() { + // verify log(), logf(), logl() - simplifcation + const char code_log[] ="void f(int x) {\n" + " std::cout << log(x);\n" // do not simplify + " std::cout << log(10);\n" // do not simplify + " std::cout << log(1L);\n" // simplify to 0 + "}"; + const char expected_log[] = "void f ( int x ) {\n" + "std :: cout << log ( x ) ;\n" + "std :: cout << log ( 10 ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_log, tok(code_log)); + + const char code_logf[] ="void f(float x) {\n" + " std::cout << logf(x);\n" // do not simplify + " std::cout << logf(10);\n" // do not simplify + " std::cout << logf(1.0f);\n" // simplify to 0 + "}"; + const char expected_logf[] = "void f ( float x ) {\n" + "std :: cout << logf ( x ) ;\n" + "std :: cout << logf ( 10 ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_logf, tok(code_logf)); + + const char code_logl[] ="void f(long double x) {\n" + " std::cout << logl(x);\n" // do not simplify + " std::cout << logl(10.0f);\n" // do not simplify + " std::cout << logl(1.0f);\n" // simplify to 0 + "}"; + const char expected_logl[] = "void f ( long double x ) {\n" + "std :: cout << logl ( x ) ;\n" + "std :: cout << logl ( 10.0f ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_logl, tok(code_logl)); + } + + void simplifyMathFunctions_log2() { + // verify log2(), log2f(), log2l() - simplifcation + const char code_log2[] ="void f(int x) {\n" + " std::cout << log2(x);\n" // do not simplify + " std::cout << log2(10);\n" // do not simplify + " std::cout << log2(1L);\n" // simplify to 0 + "}"; + const char expected_log2[] = "void f ( int x ) {\n" + "std :: cout << log2 ( x ) ;\n" + "std :: cout << log2 ( 10 ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_log2, tok(code_log2)); + + const char code_log2f[] ="void f(float x) {\n" + " std::cout << log2f(x);\n" // do not simplify + " std::cout << log2f(10);\n" // do not simplify + " std::cout << log2f(1.0f);\n" // simplify to 0 + "}"; + const char expected_log2f[] = "void f ( float x ) {\n" + "std :: cout << log2f ( x ) ;\n" + "std :: cout << log2f ( 10 ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_log2f, tok(code_log2f)); + + const char code_log2l[] ="void f(long double x) {\n" + " std::cout << log2l(x);\n" // do not simplify + " std::cout << log2l(10.0f);\n" // do not simplify + " std::cout << log2l(1.0f);\n" // simplify to 0 + "}"; + const char expected_log2l[] = "void f ( long double x ) {\n" + "std :: cout << log2l ( x ) ;\n" + "std :: cout << log2l ( 10.0f ) ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_log2l, tok(code_log2l)); + } + + void simplifyMathFunctions_pow() { + // verify pow(),pow(),powl() - simplifcation + const char code_pow[] ="void f() {\n" + " std::cout << pow(-1.0,1);\n" + " std::cout << pow(1.0,1);\n" + " std::cout << pow(0,1);\n" + " std::cout << pow(1,-6);\n" + " std::cout << powf(-1.0,1.0f);\n" + " std::cout << powf(1.0,1.0f);\n" + " std::cout << powf(0,1.0f);\n" + " std::cout << powf(1.0,-6.0f);\n" + " std::cout << powl(-1.0,1.0);\n" + " std::cout << powl(1.0,1.0);\n" + " std::cout << powl(0,1.0);\n" + " std::cout << powl(1.0,-6.0d);\n" + "}"; + + const char expected_pow[] = "void f ( ) {\n" + "std :: cout << -1.0 ;\n" + "std :: cout << 1 ;\n" + "std :: cout << 0 ;\n" + "std :: cout << 1 ;\n" + "std :: cout << -1.0 ;\n" + "std :: cout << 1 ;\n" + "std :: cout << 0 ;\n" + "std :: cout << 1 ;\n" + "std :: cout << -1.0 ;\n" + "std :: cout << 1 ;\n" + "std :: cout << 0 ;\n" + "std :: cout << 1 ;\n" + "}"; + ASSERT_EQUALS(expected_pow, tok(code_pow)); + + // verify if code is simplified correctly. + // Do not simplify class members. + const char code_pow1[] = "int f(const Fred &fred) {return fred.pow(12,3);}"; + const char expected_pow1[] = "int f ( const Fred & fred ) { return fred . pow ( 12 , 3 ) ; }"; + ASSERT_EQUALS(expected_pow1, tok(code_pow1)); + + const char code_pow2[] = "int f() {return pow(0,0);}"; + const char expected_pow2[] = "int f ( ) { return 1 ; }"; + ASSERT_EQUALS(expected_pow2, tok(code_pow2)); + + const char code_pow3[] = "int f() {return pow(0,1);}"; + const char expected_pow3[] = "int f ( ) { return 0 ; }"; + ASSERT_EQUALS(expected_pow3, tok(code_pow3)); + + const char code_pow4[] = "int f() {return pow(1,0);}"; + const char expected_pow4[] = "int f ( ) { return 1 ; }"; + ASSERT_EQUALS(expected_pow4, tok(code_pow4)); + } + + void simplifyMathFunctions_fmin() { + // verify fmin,fminl,fminl simplifcation + const char code_fmin[] ="void f() {\n" + " std::cout << fmin(-1.0,0);\n" + " std::cout << fmin(1.0,0);\n" + " std::cout << fmin(0,0);\n" + " std::cout << fminf(-1.0,0);\n" + " std::cout << fminf(1.0,0);\n" + " std::cout << fminf(0,0);\n" + " std::cout << fminl(-1.0,0);\n" + " std::cout << fminl(1.0,0);\n" + " std::cout << fminl(0,0);\n" + "}"; + + const char expected_fmin[] = "void f ( ) {\n" + "std :: cout << -1.0 ;\n" + "std :: cout << 0 ;\n" + "std :: cout << 0 ;\n" + "std :: cout << -1.0 ;\n" + "std :: cout << 0 ;\n" + "std :: cout << 0 ;\n" + "std :: cout << -1.0 ;\n" + "std :: cout << 0 ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_fmin, tok(code_fmin)); + + // do not simplify this case + const char code_fmin1[] = "float f(float f) { return fmin(f,0);}"; + const char expected_fmin1[] = "float f ( float f ) { return fmin ( f , 0 ) ; }"; + ASSERT_EQUALS(expected_fmin1, tok(code_fmin1)); + } + + void simplifyMathFunctions_fmax() { + // verify fmax(),fmax(),fmaxl() simplifcation + const char code_fmax[] ="void f() {\n" + " std::cout << fmax(-1.0,0);\n" + " std::cout << fmax(1.0,0);\n" + " std::cout << fmax(0,0);\n" + " std::cout << fmaxf(-1.0,0);\n" + " std::cout << fmaxf(1.0,0);\n" + " std::cout << fmaxf(0,0);\n" + " std::cout << fmaxl(-1.0,0);\n" + " std::cout << fmaxl(1.0,0);\n" + " std::cout << fmaxl(0,0);\n" + "}"; + + const char expected_fmax[] = "void f ( ) {\n" + "std :: cout << 0 ;\n" + "std :: cout << 1.0 ;\n" + "std :: cout << 0 ;\n" + "std :: cout << 0 ;\n" + "std :: cout << 1.0 ;\n" + "std :: cout << 0 ;\n" + "std :: cout << 0 ;\n" + "std :: cout << 1.0 ;\n" + "std :: cout << 0 ;\n" + "}"; + ASSERT_EQUALS(expected_fmax, tok(code_fmax)); + + // do not simplify this case + const char code_fmax1[] = "float f(float f) { return fmax(f,0);}"; + const char expected_fmax1[] = "float f ( float f ) { return fmax ( f , 0 ) ; }"; + ASSERT_EQUALS(expected_fmax1, tok(code_fmax1)); + } + + void simplifyMathExpressions() { //#1620 + const char code1[] = "void foo() {\n" + " std::cout<centerX, h->centerY, 1 + index }, 1);")); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index b80e752a8..2d72a72f7 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -419,36 +419,6 @@ private: TEST_CASE(platformWin32WStringCat); // ticket #5015 TEST_CASE(platformWinWithNamespace); - TEST_CASE(simplifyMathFunctions_sqrt); - TEST_CASE(simplifyMathFunctions_cbrt); - TEST_CASE(simplifyMathFunctions_exp); - TEST_CASE(simplifyMathFunctions_exp2); - TEST_CASE(simplifyMathFunctions_logb); - TEST_CASE(simplifyMathFunctions_log1p); - TEST_CASE(simplifyMathFunctions_ilogb); - TEST_CASE(simplifyMathFunctions_log10); - TEST_CASE(simplifyMathFunctions_log); - TEST_CASE(simplifyMathFunctions_log2); - TEST_CASE(simplifyMathFunctions_pow); - TEST_CASE(simplifyMathFunctions_fmin); - TEST_CASE(simplifyMathFunctions_fmax); - TEST_CASE(simplifyMathFunctions_acosh); - TEST_CASE(simplifyMathFunctions_acos); - TEST_CASE(simplifyMathFunctions_cosh); - TEST_CASE(simplifyMathFunctions_cos); - TEST_CASE(simplifyMathFunctions_erfc); - TEST_CASE(simplifyMathFunctions_erf); - TEST_CASE(simplifyMathFunctions_sin); - TEST_CASE(simplifyMathFunctions_sinh); - TEST_CASE(simplifyMathFunctions_asin); - TEST_CASE(simplifyMathFunctions_asinh); - TEST_CASE(simplifyMathFunctions_tan); - TEST_CASE(simplifyMathFunctions_tanh); - TEST_CASE(simplifyMathFunctions_atan); - TEST_CASE(simplifyMathFunctions_atanh); - TEST_CASE(simplifyMathFunctions_expm1); - - TEST_CASE(simplifyMathExpressions); //ticket #1620 TEST_CASE(simplifyStaticConst); TEST_CASE(simplifyCPPAttribute); @@ -6863,1268 +6833,6 @@ private: ASSERT_EQUALS(false, Tokenizer::isTwoNumber("garbage")); } - void simplifyMathFunctions_erfc() { - // verify erfc(), erfcf(), erfcl() - simplifcation - const char code_erfc[] ="void f(int x) {\n" - " std::cout << erfc(x);\n" // do not simplify - " std::cout << erfc(0L);\n" // simplify to 1 - "}"; - const char expected_erfc[] = "void f ( int x ) {\n" - "std :: cout << erfc ( x ) ;\n" - "std :: cout << 1 ;\n" - "}"; - ASSERT_EQUALS(expected_erfc, tokenizeAndStringify(code_erfc)); - - const char code_erfcf[] ="void f(float x) {\n" - " std::cout << erfcf(x);\n" // do not simplify - " std::cout << erfcf(0.0f);\n" // simplify to 1 - "}"; - const char expected_erfcf[] = "void f ( float x ) {\n" - "std :: cout << erfcf ( x ) ;\n" - "std :: cout << 1 ;\n" - "}"; - ASSERT_EQUALS(expected_erfcf, tokenizeAndStringify(code_erfcf)); - - const char code_erfcl[] ="void f(long double x) {\n" - " std::cout << erfcl(x);\n" // do not simplify - " std::cout << erfcl(0.0f);\n" // simplify to 1 - "}"; - const char expected_erfcl[] = "void f ( long double x ) {\n" - "std :: cout << erfcl ( x ) ;\n" - "std :: cout << 1 ;\n" - "}"; - ASSERT_EQUALS(expected_erfcl, tokenizeAndStringify(code_erfcl)); - } - - void simplifyMathFunctions_cos() { - // verify cos(), cosf(), cosl() - simplifcation - const char code_cos[] ="void f(int x) {\n" - " std::cout << cos(x);\n" // do not simplify - " std::cout << cos(0L);\n" // simplify to 1 - "}"; - const char expected_cos[] = "void f ( int x ) {\n" - "std :: cout << cos ( x ) ;\n" - "std :: cout << 1 ;\n" - "}"; - ASSERT_EQUALS(expected_cos, tokenizeAndStringify(code_cos)); - - const char code_cosf[] ="void f(float x) {\n" - " std::cout << cosf(x);\n" // do not simplify - " std::cout << cosf(0.0f);\n" // simplify to 1 - "}"; - const char expected_cosf[] = "void f ( float x ) {\n" - "std :: cout << cosf ( x ) ;\n" - "std :: cout << 1 ;\n" - "}"; - ASSERT_EQUALS(expected_cosf, tokenizeAndStringify(code_cosf)); - - const char code_cosl[] ="void f(long double x) {\n" - " std::cout << cosl(x);\n" // do not simplify - " std::cout << cosl(0.0f);\n" // simplify to 1 - "}"; - const char expected_cosl[] = "void f ( long double x ) {\n" - "std :: cout << cosl ( x ) ;\n" - "std :: cout << 1 ;\n" - "}"; - ASSERT_EQUALS(expected_cosl, tokenizeAndStringify(code_cosl)); - } - - void simplifyMathFunctions_cosh() { - // verify cosh(), coshf(), coshl() - simplifcation - const char code_cosh[] ="void f(int x) {\n" - " std::cout << cosh(x);\n" // do not simplify - " std::cout << cosh(0L);\n" // simplify to 1 - "}"; - const char expected_cosh[] = "void f ( int x ) {\n" - "std :: cout << cosh ( x ) ;\n" - "std :: cout << 1 ;\n" - "}"; - ASSERT_EQUALS(expected_cosh, tokenizeAndStringify(code_cosh)); - - const char code_coshf[] ="void f(float x) {\n" - " std::cout << coshf(x);\n" // do not simplify - " std::cout << coshf(0.0f);\n" // simplify to 1 - "}"; - const char expected_coshf[] = "void f ( float x ) {\n" - "std :: cout << coshf ( x ) ;\n" - "std :: cout << 1 ;\n" - "}"; - ASSERT_EQUALS(expected_coshf, tokenizeAndStringify(code_coshf)); - - const char code_coshl[] ="void f(long double x) {\n" - " std::cout << coshl(x);\n" // do not simplify - " std::cout << coshl(0.0f);\n" // simplify to 1 - "}"; - const char expected_coshl[] = "void f ( long double x ) {\n" - "std :: cout << coshl ( x ) ;\n" - "std :: cout << 1 ;\n" - "}"; - ASSERT_EQUALS(expected_coshl, tokenizeAndStringify(code_coshl)); - } - - 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.0f);\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() { - // verify acosh(), acoshf(), acoshl() - simplifcation - const char code_acosh[] ="void f(int x) {\n" - " std::cout << acosh(x);\n" // do not simplify - " std::cout << acosh(1L);\n" // simplify to 0 - "}"; - const char expected_acosh[] = "void f ( int x ) {\n" - "std :: cout << acosh ( x ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_acosh, tokenizeAndStringify(code_acosh)); - - const char code_acoshf[] ="void f(float x) {\n" - " std::cout << acoshf(x);\n" // do not simplify - " std::cout << acoshf(1.0f);\n" // simplify to 0 - "}"; - const char expected_acoshf[] = "void f ( float x ) {\n" - "std :: cout << acoshf ( x ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_acoshf, tokenizeAndStringify(code_acoshf)); - - const char code_acoshl[] ="void f(long double x) {\n" - " std::cout << acoshl(x);\n" // do not simplify - " std::cout << acoshl(1.0f);\n" // simplify to 0 - "}"; - const char expected_acoshl[] = "void f ( long double x ) {\n" - "std :: cout << acoshl ( x ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_acoshl, tokenizeAndStringify(code_acoshl)); - } - - void simplifyMathFunctions_sqrt() { - // verify sqrt(), sqrtf(), sqrtl() - simplifcation - const char code_sqrt[] ="void f(int x) {\n" - " std::cout << sqrt(x);\n" // do not simplify - " std::cout << sqrt(-1);\n" // do not simplify - " std::cout << sqrt(0L);\n" // simplify to 0 - " std::cout << sqrt(1L);\n" // simplify to 1 - "}"; - const char expected_sqrt[] = "void f ( int x ) {\n" - "std :: cout << sqrt ( x ) ;\n" - "std :: cout << sqrt ( -1 ) ;\n" - "std :: cout << 0 ;\n" - "std :: cout << 1 ;\n" - "}"; - ASSERT_EQUALS(expected_sqrt, tokenizeAndStringify(code_sqrt)); - - const char code_sqrtf[] ="void f(float x) {\n" - " std::cout << sqrtf(x);\n" // do not simplify - " std::cout << sqrtf(-1.0f);\n" // do not simplify - " std::cout << sqrtf(0.0f);\n" // simplify to 0 - " std::cout << sqrtf(1.0);\n" // simplify to 1 - "}"; - const char expected_sqrtf[] = "void f ( float x ) {\n" - "std :: cout << sqrtf ( x ) ;\n" - "std :: cout << sqrtf ( -1.0f ) ;\n" - "std :: cout << 0 ;\n" - "std :: cout << 1 ;\n" - "}"; - ASSERT_EQUALS(expected_sqrtf, tokenizeAndStringify(code_sqrtf)); - - const char code_sqrtl[] ="void f(long double x) {\n" - " std::cout << sqrtf(x);\n" // do not simplify - " std::cout << sqrtf(-1.0);\n" // do not simplify - " std::cout << sqrtf(0.0);\n" // simplify to 0 - " std::cout << sqrtf(1.0);\n" // simplify to 1 - "}"; - const char expected_sqrtl[] = "void f ( long double x ) {\n" - "std :: cout << sqrtf ( x ) ;\n" - "std :: cout << sqrtf ( -1.0 ) ;\n" - "std :: cout << 0 ;\n" - "std :: cout << 1 ;\n" - "}"; - ASSERT_EQUALS(expected_sqrtl, tokenizeAndStringify(code_sqrtl)); - } - - void simplifyMathFunctions_cbrt() { - // verify cbrt(), cbrtf(), cbrtl() - simplifcation - const char code_cbrt[] ="void f(int x) {\n" - " std::cout << cbrt(x);\n" // do not simplify - " std::cout << cbrt(-1);\n" // do not simplify - " std::cout << cbrt(0L);\n" // simplify to 0 - " std::cout << cbrt(1L);\n" // simplify to 1 - "}"; - const char expected_cbrt[] = "void f ( int x ) {\n" - "std :: cout << cbrt ( x ) ;\n" - "std :: cout << cbrt ( -1 ) ;\n" - "std :: cout << 0 ;\n" - "std :: cout << 1 ;\n" - "}"; - ASSERT_EQUALS(expected_cbrt, tokenizeAndStringify(code_cbrt)); - - const char code_cbrtf[] ="void f(float x) {\n" - " std::cout << cbrtf(x);\n" // do not simplify - " std::cout << cbrtf(-1.0f);\n" // do not simplify - " std::cout << cbrtf(0.0f);\n" // simplify to 0 - " std::cout << cbrtf(1.0);\n" // simplify to 1 - "}"; - const char expected_cbrtf[] = "void f ( float x ) {\n" - "std :: cout << cbrtf ( x ) ;\n" - "std :: cout << cbrtf ( -1.0f ) ;\n" - "std :: cout << 0 ;\n" - "std :: cout << 1 ;\n" - "}"; - ASSERT_EQUALS(expected_cbrtf, tokenizeAndStringify(code_cbrtf)); - - const char code_cbrtl[] ="void f(long double x) {\n" - " std::cout << cbrtl(x);\n" // do not simplify - " std::cout << cbrtl(-1.0);\n" // do not simplify - " std::cout << cbrtl(0.0);\n" // simplify to 0 - " std::cout << cbrtl(1.0);\n" // simplify to 1 - "}"; - const char expected_cbrtl[] = "void f ( long double x ) {\n" - "std :: cout << cbrtl ( x ) ;\n" - "std :: cout << cbrtl ( -1.0 ) ;\n" - "std :: cout << 0 ;\n" - "std :: cout << 1 ;\n" - "}"; - ASSERT_EQUALS(expected_cbrtl, tokenizeAndStringify(code_cbrtl)); - } - - void simplifyMathFunctions_exp2() { - // verify exp2(), exp2f(), exp2l() - simplifcation - const char code_exp2[] ="void f(int x) {\n" - " std::cout << exp2(x);\n" // do not simplify - " std::cout << exp2(-1);\n" // do not simplify - " std::cout << exp2(0L);\n" // simplify to 0 - " std::cout << exp2(1L);\n" // do not simplify - "}"; - const char expected_exp2[] = "void f ( int x ) {\n" - "std :: cout << exp2 ( x ) ;\n" - "std :: cout << exp2 ( -1 ) ;\n" - "std :: cout << 1 ;\n" - "std :: cout << exp2 ( 1L ) ;\n" - "}"; - ASSERT_EQUALS(expected_exp2, tokenizeAndStringify(code_exp2)); - - const char code_exp2f[] ="void f(float x) {\n" - " std::cout << exp2f(x);\n" // do not simplify - " std::cout << exp2f(-1.0);\n" // do not simplify - " std::cout << exp2f(0.0);\n" // simplify to 1 - " std::cout << exp2f(1.0);\n" // do not simplify - "}"; - const char expected_exp2f[] = "void f ( float x ) {\n" - "std :: cout << exp2f ( x ) ;\n" - "std :: cout << exp2f ( -1.0 ) ;\n" - "std :: cout << 1 ;\n" - "std :: cout << exp2f ( 1.0 ) ;\n" - "}"; - ASSERT_EQUALS(expected_exp2f, tokenizeAndStringify(code_exp2f)); - - const char code_exp2l[] ="void f(long double x) {\n" - " std::cout << exp2l(x);\n" // do not simplify - " std::cout << exp2l(-1.0);\n" // do not simplify - " std::cout << exp2l(0.0);\n" // simplify to 1 - " std::cout << exp2l(1.0);\n" // do not simplify - "}"; - const char expected_exp2l[] = "void f ( long double x ) {\n" - "std :: cout << exp2l ( x ) ;\n" - "std :: cout << exp2l ( -1.0 ) ;\n" - "std :: cout << 1 ;\n" - "std :: cout << exp2l ( 1.0 ) ;\n" - "}"; - ASSERT_EQUALS(expected_exp2l, tokenizeAndStringify(code_exp2l)); - } - - void simplifyMathFunctions_exp() { - // verify exp(), expf(), expl() - simplifcation - const char code_exp[] ="void f(int x) {\n" - " std::cout << exp(x);\n" // do not simplify - " std::cout << exp(-1);\n" // do not simplify - " std::cout << exp(0L);\n" // simplify to 1 - " std::cout << exp(1L);\n" // do not simplify - "}"; - const char expected_exp[] = "void f ( int x ) {\n" - "std :: cout << exp ( x ) ;\n" - "std :: cout << exp ( -1 ) ;\n" - "std :: cout << 1 ;\n" - "std :: cout << exp ( 1L ) ;\n" - "}"; - ASSERT_EQUALS(expected_exp, tokenizeAndStringify(code_exp)); - - const char code_expf[] ="void f(float x) {\n" - " std::cout << expf(x);\n" // do not simplify - " std::cout << expf(-1.0);\n" // do not simplify - " std::cout << expf(0.0);\n" // simplify to 1 - " std::cout << expf(1.0);\n" // do not simplify - "}"; - const char expected_expf[] = "void f ( float x ) {\n" - "std :: cout << expf ( x ) ;\n" - "std :: cout << expf ( -1.0 ) ;\n" - "std :: cout << 1 ;\n" - "std :: cout << expf ( 1.0 ) ;\n" - "}"; - ASSERT_EQUALS(expected_expf, tokenizeAndStringify(code_expf)); - - const char code_expl[] ="void f(long double x) {\n" - " std::cout << expl(x);\n" // do not simplify - " std::cout << expl(-1.0);\n" // do not simplify - " std::cout << expl(0.0);\n" // simplify to 1 - " std::cout << expl(1.0);\n" // do not simplify - "}"; - const char expected_expl[] = "void f ( long double x ) {\n" - "std :: cout << expl ( x ) ;\n" - "std :: cout << expl ( -1.0 ) ;\n" - "std :: cout << 1 ;\n" - "std :: cout << expl ( 1.0 ) ;\n" - "}"; - ASSERT_EQUALS(expected_expl, tokenizeAndStringify(code_expl)); - } - - void simplifyMathFunctions_erf() { - // verify erf(), erff(), erfl() - simplifcation - const char code_erf[] ="void f(int x) {\n" - " std::cout << erf(x);\n" // do not simplify - " std::cout << erf(10);\n" // do not simplify - " std::cout << erf(0L);\n" // simplify to 0 - "}"; - const char expected_erf[] = "void f ( int x ) {\n" - "std :: cout << erf ( x ) ;\n" - "std :: cout << erf ( 10 ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_erf, tokenizeAndStringify(code_erf)); - - const char code_erff[] ="void f(float x) {\n" - " std::cout << erff(x);\n" // do not simplify - " std::cout << erff(10);\n" // do not simplify - " std::cout << erff(0.0f);\n" // simplify to 0 - "}"; - const char expected_erff[] = "void f ( float x ) {\n" - "std :: cout << erff ( x ) ;\n" - "std :: cout << erff ( 10 ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_erff, tokenizeAndStringify(code_erff)); - - const char code_erfl[] ="void f(long double x) {\n" - " std::cout << erfl(x);\n" // do not simplify - " std::cout << erfl(10.0f);\n" // do not simplify - " std::cout << erfl(0.0f);\n" // simplify to 0 - "}"; - const char expected_erfl[] = "void f ( long double x ) {\n" - "std :: cout << erfl ( x ) ;\n" - "std :: cout << erfl ( 10.0f ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_erfl, tokenizeAndStringify(code_erfl)); - } - - void simplifyMathFunctions_atanh() { - // verify atanh(), atanhf(), atanhl() - simplifcation - const char code_atanh[] ="void f(int x) {\n" - " std::cout << atanh(x);\n" // do not simplify - " std::cout << atanh(10);\n" // do not simplify - " std::cout << atanh(0L);\n" // simplify to 0 - "}"; - const char expected_atanh[] = "void f ( int x ) {\n" - "std :: cout << atanh ( x ) ;\n" - "std :: cout << atanh ( 10 ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_atanh, tokenizeAndStringify(code_atanh)); - - const char code_atanhf[] ="void f(float x) {\n" - " std::cout << atanhf(x);\n" // do not simplify - " std::cout << atanhf(10);\n" // do not simplify - " std::cout << atanhf(0.0f);\n" // simplify to 0 - "}"; - const char expected_atanhf[] = "void f ( float x ) {\n" - "std :: cout << atanhf ( x ) ;\n" - "std :: cout << atanhf ( 10 ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_atanhf, tokenizeAndStringify(code_atanhf)); - - const char code_atanhl[] ="void f(long double x) {\n" - " std::cout << atanhl(x);\n" // do not simplify - " std::cout << atanhl(10.0f);\n" // do not simplify - " std::cout << atanhl(0.0d);\n" // do not simplify - invalid number! - " std::cout << atanhl(0.0f);\n" // simplify to 0 - "}"; - const char expected_atanhl[] = "void f ( long double x ) {\n" - "std :: cout << atanhl ( x ) ;\n" - "std :: cout << atanhl ( 10.0f ) ;\n" - "std :: cout << atanhl ( 0.0d ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_atanhl, tokenizeAndStringify(code_atanhl)); - } - - void simplifyMathFunctions_atan() { - // verify atan(), atanf(), atanl() - simplifcation - const char code_atan[] ="void f(int x) {\n" - " std::cout << atan(x);\n" // do not simplify - " std::cout << atan(10);\n" // do not simplify - " std::cout << atan(0L);\n" // simplify to 0 - "}"; - const char expected_atan[] = "void f ( int x ) {\n" - "std :: cout << atan ( x ) ;\n" - "std :: cout << atan ( 10 ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_atan, tokenizeAndStringify(code_atan)); - - const char code_atanf[] ="void f(float x) {\n" - " std::cout << atanf(x);\n" // do not simplify - " std::cout << atanf(10);\n" // do not simplify - " std::cout << atanf(0.0f);\n" // simplify to 0 - "}"; - const char expected_atanf[] = "void f ( float x ) {\n" - "std :: cout << atanf ( x ) ;\n" - "std :: cout << atanf ( 10 ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_atanf, tokenizeAndStringify(code_atanf)); - - const char code_atanl[] ="void f(long double x) {\n" - " std::cout << atanl(x);\n" // do not simplify - " std::cout << atanl(10.0f);\n" // do not simplify - " std::cout << atanl(0.0f);\n" // simplify to 0 - "}"; - const char expected_atanl[] = "void f ( long double x ) {\n" - "std :: cout << atanl ( x ) ;\n" - "std :: cout << atanl ( 10.0f ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_atanl, tokenizeAndStringify(code_atanl)); - } - - void simplifyMathFunctions_tanh() { - // verify tanh(), tanhf(), tanhl() - simplifcation - const char code_tanh[] ="void f(int x) {\n" - " std::cout << tanh(x);\n" // do not simplify - " std::cout << tanh(10);\n" // do not simplify - " std::cout << tanh(0L);\n" // simplify to 0 - "}"; - const char expected_tanh[] = "void f ( int x ) {\n" - "std :: cout << tanh ( x ) ;\n" - "std :: cout << tanh ( 10 ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_tanh, tokenizeAndStringify(code_tanh)); - - const char code_tanhf[] ="void f(float x) {\n" - " std::cout << tanhf(x);\n" // do not simplify - " std::cout << tanhf(10);\n" // do not simplify - " std::cout << tanhf(0.0f);\n" // simplify to 0 - "}"; - const char expected_tanhf[] = "void f ( float x ) {\n" - "std :: cout << tanhf ( x ) ;\n" - "std :: cout << tanhf ( 10 ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_tanhf, tokenizeAndStringify(code_tanhf)); - - const char code_tanhl[] ="void f(long double x) {\n" - " std::cout << tanhl(x);\n" // do not simplify - " std::cout << tanhl(10.0f);\n" // do not simplify - " std::cout << tanhl(0.0f);\n" // simplify to 0 - "}"; - const char expected_tanhl[] = "void f ( long double x ) {\n" - "std :: cout << tanhl ( x ) ;\n" - "std :: cout << tanhl ( 10.0f ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_tanhl, tokenizeAndStringify(code_tanhl)); - } - - void simplifyMathFunctions_tan() { - // verify tan(), tanf(), tanl() - simplifcation - const char code_tan[] ="void f(int x) {\n" - " std::cout << tan(x);\n" // do not simplify - " std::cout << tan(10);\n" // do not simplify - " std::cout << tan(0L);\n" // simplify to 0 - "}"; - const char expected_tan[] = "void f ( int x ) {\n" - "std :: cout << tan ( x ) ;\n" - "std :: cout << tan ( 10 ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_tan, tokenizeAndStringify(code_tan)); - - const char code_tanf[] ="void f(float x) {\n" - " std::cout << tanf(x);\n" // do not simplify - " std::cout << tanf(10);\n" // do not simplify - " std::cout << tanf(0.0f);\n" // simplify to 0 - "}"; - const char expected_tanf[] = "void f ( float x ) {\n" - "std :: cout << tanf ( x ) ;\n" - "std :: cout << tanf ( 10 ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_tanf, tokenizeAndStringify(code_tanf)); - - const char code_tanl[] ="void f(long double x) {\n" - " std::cout << tanl(x);\n" // do not simplify - " std::cout << tanl(10.0f);\n" // do not simplify - " std::cout << tanl(0.0f);\n" // simplify to 0 - "}"; - const char expected_tanl[] = "void f ( long double x ) {\n" - "std :: cout << tanl ( x ) ;\n" - "std :: cout << tanl ( 10.0f ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_tanl, tokenizeAndStringify(code_tanl)); - } - - void simplifyMathFunctions_expm1() { - // verify expm1(), expm1f(), expm1l() - simplifcation - const char code_expm1[] ="void f(int x) {\n" - " std::cout << expm1(x);\n" // do not simplify - " std::cout << expm1(10);\n" // do not simplify - " std::cout << expm1(0L);\n" // simplify to 0 - "}"; - const char expected_expm1[] = "void f ( int x ) {\n" - "std :: cout << expm1 ( x ) ;\n" - "std :: cout << expm1 ( 10 ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_expm1, tokenizeAndStringify(code_expm1)); - - const char code_expm1f[] ="void f(float x) {\n" - " std::cout << expm1f(x);\n" // do not simplify - " std::cout << expm1f(10);\n" // do not simplify - " std::cout << expm1f(0.0f);\n" // simplify to 0 - "}"; - const char expected_expm1f[] = "void f ( float x ) {\n" - "std :: cout << expm1f ( x ) ;\n" - "std :: cout << expm1f ( 10 ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_expm1f, tokenizeAndStringify(code_expm1f)); - - const char code_expm1l[] ="void f(long double x) {\n" - " std::cout << expm1l(x);\n" // do not simplify - " std::cout << expm1l(10.0f);\n" // do not simplify - " std::cout << expm1l(0.0f);\n" // simplify to 0 - "}"; - const char expected_expm1l[] = "void f ( long double x ) {\n" - "std :: cout << expm1l ( x ) ;\n" - "std :: cout << expm1l ( 10.0f ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_expm1l, tokenizeAndStringify(code_expm1l)); - } - - void simplifyMathFunctions_asinh() { - // verify asinh(), asinhf(), asinhl() - simplifcation - const char code_asinh[] ="void f(int x) {\n" - " std::cout << asinh(x);\n" // do not simplify - " std::cout << asinh(10);\n" // do not simplify - " std::cout << asinh(0L);\n" // simplify to 0 - "}"; - const char expected_asinh[] = "void f ( int x ) {\n" - "std :: cout << asinh ( x ) ;\n" - "std :: cout << asinh ( 10 ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_asinh, tokenizeAndStringify(code_asinh)); - - const char code_asinhf[] ="void f(float x) {\n" - " std::cout << asinhf(x);\n" // do not simplify - " std::cout << asinhf(10);\n" // do not simplify - " std::cout << asinhf(0.0f);\n" // simplify to 0 - "}"; - const char expected_asinhf[] = "void f ( float x ) {\n" - "std :: cout << asinhf ( x ) ;\n" - "std :: cout << asinhf ( 10 ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_asinhf, tokenizeAndStringify(code_asinhf)); - - const char code_asinhl[] ="void f(long double x) {\n" - " std::cout << asinhl(x);\n" // do not simplify - " std::cout << asinhl(10.0f);\n" // do not simplify - " std::cout << asinhl(0.0f);\n" // simplify to 0 - "}"; - const char expected_asinhl[] = "void f ( long double x ) {\n" - "std :: cout << asinhl ( x ) ;\n" - "std :: cout << asinhl ( 10.0f ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_asinhl, tokenizeAndStringify(code_asinhl)); - } - - void simplifyMathFunctions_asin() { - // verify asin(), asinf(), asinl() - simplifcation - const char code_asin[] ="void f(int x) {\n" - " std::cout << asin(x);\n" // do not simplify - " std::cout << asin(10);\n" // do not simplify - " std::cout << asin(0L);\n" // simplify to 0 - "}"; - const char expected_asin[] = "void f ( int x ) {\n" - "std :: cout << asin ( x ) ;\n" - "std :: cout << asin ( 10 ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_asin, tokenizeAndStringify(code_asin)); - - const char code_asinf[] ="void f(float x) {\n" - " std::cout << asinf(x);\n" // do not simplify - " std::cout << asinf(10);\n" // do not simplify - " std::cout << asinf(0.0f);\n" // simplify to 0 - "}"; - const char expected_asinf[] = "void f ( float x ) {\n" - "std :: cout << asinf ( x ) ;\n" - "std :: cout << asinf ( 10 ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_asinf, tokenizeAndStringify(code_asinf)); - - const char code_asinl[] ="void f(long double x) {\n" - " std::cout << asinl(x);\n" // do not simplify - " std::cout << asinl(10.0f);\n" // do not simplify - " std::cout << asinl(0.0f);\n" // simplify to 0 - "}"; - const char expected_asinl[] = "void f ( long double x ) {\n" - "std :: cout << asinl ( x ) ;\n" - "std :: cout << asinl ( 10.0f ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_asinl, tokenizeAndStringify(code_asinl)); - } - - void simplifyMathFunctions_sinh() { - // verify sinh(), sinhf(), sinhl() - simplifcation - const char code_sinh[] ="void f(int x) {\n" - " std::cout << sinh(x);\n" // do not simplify - " std::cout << sinh(10);\n" // do not simplify - " std::cout << sinh(0L);\n" // simplify to 0 - "}"; - const char expected_sinh[] = "void f ( int x ) {\n" - "std :: cout << sinh ( x ) ;\n" - "std :: cout << sinh ( 10 ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_sinh, tokenizeAndStringify(code_sinh)); - - const char code_sinhf[] ="void f(float x) {\n" - " std::cout << sinhf(x);\n" // do not simplify - " std::cout << sinhf(10);\n" // do not simplify - " std::cout << sinhf(0.0f);\n" // simplify to 0 - "}"; - const char expected_sinhf[] = "void f ( float x ) {\n" - "std :: cout << sinhf ( x ) ;\n" - "std :: cout << sinhf ( 10 ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_sinhf, tokenizeAndStringify(code_sinhf)); - - const char code_sinhl[] ="void f(long double x) {\n" - " std::cout << sinhl(x);\n" // do not simplify - " std::cout << sinhl(10.0f);\n" // do not simplify - " std::cout << sinhl(0.0f);\n" // simplify to 0 - "}"; - const char expected_sinhl[] = "void f ( long double x ) {\n" - "std :: cout << sinhl ( x ) ;\n" - "std :: cout << sinhl ( 10.0f ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_sinhl, tokenizeAndStringify(code_sinhl)); - } - - void simplifyMathFunctions_sin() { - // verify sin(), sinf(), sinl() - simplifcation - const char code_sin[] ="void f(int x) {\n" - " std::cout << sin(x);\n" // do not simplify - " std::cout << sin(10);\n" // do not simplify - " std::cout << sin(0L);\n" // simplify to 0 - "}"; - const char expected_sin[] = "void f ( int x ) {\n" - "std :: cout << sin ( x ) ;\n" - "std :: cout << sin ( 10 ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_sin, tokenizeAndStringify(code_sin)); - - const char code_sinf[] ="void f(float x) {\n" - " std::cout << sinf(x);\n" // do not simplify - " std::cout << sinf(10);\n" // do not simplify - " std::cout << sinf(0.0f);\n" // simplify to 0 - "}"; - const char expected_sinf[] = "void f ( float x ) {\n" - "std :: cout << sinf ( x ) ;\n" - "std :: cout << sinf ( 10 ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_sinf, tokenizeAndStringify(code_sinf)); - - const char code_sinl[] ="void f(long double x) {\n" - " std::cout << sinl(x);\n" // do not simplify - " std::cout << sinl(10.0f);\n" // do not simplify - " std::cout << sinl(0.0f);\n" // simplify to 0 - "}"; - const char expected_sinl[] = "void f ( long double x ) {\n" - "std :: cout << sinl ( x ) ;\n" - "std :: cout << sinl ( 10.0f ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_sinl, tokenizeAndStringify(code_sinl)); - - // #6629 - const char code[] = "class Foo { int sinf; Foo() : sinf(0) {} };"; - const char expected[] = "class Foo { int sinf ; Foo ( ) : sinf ( 0 ) { } } ;"; - ASSERT_EQUALS(expected, tokenizeAndStringify(code)); - } - - void simplifyMathFunctions_ilogb() { - // verify ilogb(), ilogbf(), ilogbl() - simplifcation - const char code_ilogb[] ="void f(int x) {\n" - " std::cout << ilogb(x);\n" // do not simplify - " std::cout << ilogb(10);\n" // do not simplify - " std::cout << ilogb(1L);\n" // simplify to 0 - "}"; - const char expected_ilogb[] = "void f ( int x ) {\n" - "std :: cout << ilogb ( x ) ;\n" - "std :: cout << ilogb ( 10 ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_ilogb, tokenizeAndStringify(code_ilogb)); - - const char code_ilogbf[] ="void f(float x) {\n" - " std::cout << ilogbf(x);\n" // do not simplify - " std::cout << ilogbf(10);\n" // do not simplify - " std::cout << ilogbf(1.0f);\n" // simplify to 0 - "}"; - const char expected_ilogbf[] = "void f ( float x ) {\n" - "std :: cout << ilogbf ( x ) ;\n" - "std :: cout << ilogbf ( 10 ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_ilogbf, tokenizeAndStringify(code_ilogbf)); - - const char code_ilogbl[] ="void f(long double x) {\n" - " std::cout << ilogbl(x);\n" // do not simplify - " std::cout << ilogbl(10.0f);\n" // do not simplify - " std::cout << ilogbl(1.0f);\n" // simplify to 0 - "}"; - const char expected_ilogbl[] = "void f ( long double x ) {\n" - "std :: cout << ilogbl ( x ) ;\n" - "std :: cout << ilogbl ( 10.0f ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_ilogbl, tokenizeAndStringify(code_ilogbl)); - } - - void simplifyMathFunctions_logb() { - // verify logb(), logbf(), logbl() - simplifcation - const char code_logb[] ="void f(int x) {\n" - " std::cout << logb(x);\n" // do not simplify - " std::cout << logb(10);\n" // do not simplify - " std::cout << logb(1L);\n" // simplify to 0 - "}"; - const char expected_logb[] = "void f ( int x ) {\n" - "std :: cout << logb ( x ) ;\n" - "std :: cout << logb ( 10 ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_logb, tokenizeAndStringify(code_logb)); - - const char code_logbf[] ="void f(float x) {\n" - " std::cout << logbf(x);\n" // do not simplify - " std::cout << logbf(10);\n" // do not simplify - " std::cout << logbf(1.0f);\n" // simplify to 0 - "}"; - const char expected_logbf[] = "void f ( float x ) {\n" - "std :: cout << logbf ( x ) ;\n" - "std :: cout << logbf ( 10 ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_logbf, tokenizeAndStringify(code_logbf)); - - const char code_logbl[] ="void f(long double x) {\n" - " std::cout << logbl(x);\n" // do not simplify - " std::cout << logbl(10.0f);\n" // do not simplify - " std::cout << logbl(1.0f);\n" // simplify to 0 - "}"; - const char expected_logbl[] = "void f ( long double x ) {\n" - "std :: cout << logbl ( x ) ;\n" - "std :: cout << logbl ( 10.0f ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_logbl, tokenizeAndStringify(code_logbl)); - } - - void simplifyMathFunctions_log1p() { - // verify log1p(), log1pf(), log1pl() - simplifcation - const char code_log1p[] ="void f(int x) {\n" - " std::cout << log1p(x);\n" // do not simplify - " std::cout << log1p(10);\n" // do not simplify - " std::cout << log1p(0L);\n" // simplify to 0 - "}"; - const char expected_log1p[] = "void f ( int x ) {\n" - "std :: cout << log1p ( x ) ;\n" - "std :: cout << log1p ( 10 ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_log1p, tokenizeAndStringify(code_log1p)); - - const char code_log1pf[] ="void f(float x) {\n" - " std::cout << log1pf(x);\n" // do not simplify - " std::cout << log1pf(10);\n" // do not simplify - " std::cout << log1pf(0.0f);\n" // simplify to 0 - "}"; - const char expected_log1pf[] = "void f ( float x ) {\n" - "std :: cout << log1pf ( x ) ;\n" - "std :: cout << log1pf ( 10 ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_log1pf, tokenizeAndStringify(code_log1pf)); - - const char code_log1pl[] ="void f(long double x) {\n" - " std::cout << log1pl(x);\n" // do not simplify - " std::cout << log1pl(10.0f);\n" // do not simplify - " std::cout << log1pl(0.0f);\n" // simplify to 0 - "}"; - const char expected_log1pl[] = "void f ( long double x ) {\n" - "std :: cout << log1pl ( x ) ;\n" - "std :: cout << log1pl ( 10.0f ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_log1pl, tokenizeAndStringify(code_log1pl)); - } - - void simplifyMathFunctions_log10() { - // verify log10(), log10f(), log10l() - simplifcation - const char code_log10[] ="void f(int x) {\n" - " std::cout << log10(x);\n" // do not simplify - " std::cout << log10(10);\n" // do not simplify - " std::cout << log10(1L);\n" // simplify to 0 - "}"; - const char expected_log10[] = "void f ( int x ) {\n" - "std :: cout << log10 ( x ) ;\n" - "std :: cout << log10 ( 10 ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_log10, tokenizeAndStringify(code_log10)); - - const char code_log10f[] ="void f(float x) {\n" - " std::cout << log10f(x);\n" // do not simplify - " std::cout << log10f(10);\n" // do not simplify - " std::cout << log10f(1.0f);\n" // simplify to 0 - "}"; - const char expected_log10f[] = "void f ( float x ) {\n" - "std :: cout << log10f ( x ) ;\n" - "std :: cout << log10f ( 10 ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_log10f, tokenizeAndStringify(code_log10f)); - - const char code_log10l[] ="void f(long double x) {\n" - " std::cout << log10l(x);\n" // do not simplify - " std::cout << log10l(10.0f);\n" // do not simplify - " std::cout << log10l(1.0f);\n" // simplify to 0 - "}"; - const char expected_log10l[] = "void f ( long double x ) {\n" - "std :: cout << log10l ( x ) ;\n" - "std :: cout << log10l ( 10.0f ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_log10l, tokenizeAndStringify(code_log10l)); - - } - void simplifyMathFunctions_log() { - // verify log(), logf(), logl() - simplifcation - const char code_log[] ="void f(int x) {\n" - " std::cout << log(x);\n" // do not simplify - " std::cout << log(10);\n" // do not simplify - " std::cout << log(1L);\n" // simplify to 0 - "}"; - const char expected_log[] = "void f ( int x ) {\n" - "std :: cout << log ( x ) ;\n" - "std :: cout << log ( 10 ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_log, tokenizeAndStringify(code_log)); - - const char code_logf[] ="void f(float x) {\n" - " std::cout << logf(x);\n" // do not simplify - " std::cout << logf(10);\n" // do not simplify - " std::cout << logf(1.0f);\n" // simplify to 0 - "}"; - const char expected_logf[] = "void f ( float x ) {\n" - "std :: cout << logf ( x ) ;\n" - "std :: cout << logf ( 10 ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_logf, tokenizeAndStringify(code_logf)); - - const char code_logl[] ="void f(long double x) {\n" - " std::cout << logl(x);\n" // do not simplify - " std::cout << logl(10.0f);\n" // do not simplify - " std::cout << logl(1.0f);\n" // simplify to 0 - "}"; - const char expected_logl[] = "void f ( long double x ) {\n" - "std :: cout << logl ( x ) ;\n" - "std :: cout << logl ( 10.0f ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_logl, tokenizeAndStringify(code_logl)); - } - - void simplifyMathFunctions_log2() { - // verify log2(), log2f(), log2l() - simplifcation - const char code_log2[] ="void f(int x) {\n" - " std::cout << log2(x);\n" // do not simplify - " std::cout << log2(10);\n" // do not simplify - " std::cout << log2(1L);\n" // simplify to 0 - "}"; - const char expected_log2[] = "void f ( int x ) {\n" - "std :: cout << log2 ( x ) ;\n" - "std :: cout << log2 ( 10 ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_log2, tokenizeAndStringify(code_log2)); - - const char code_log2f[] ="void f(float x) {\n" - " std::cout << log2f(x);\n" // do not simplify - " std::cout << log2f(10);\n" // do not simplify - " std::cout << log2f(1.0f);\n" // simplify to 0 - "}"; - const char expected_log2f[] = "void f ( float x ) {\n" - "std :: cout << log2f ( x ) ;\n" - "std :: cout << log2f ( 10 ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_log2f, tokenizeAndStringify(code_log2f)); - - const char code_log2l[] ="void f(long double x) {\n" - " std::cout << log2l(x);\n" // do not simplify - " std::cout << log2l(10.0f);\n" // do not simplify - " std::cout << log2l(1.0f);\n" // simplify to 0 - "}"; - const char expected_log2l[] = "void f ( long double x ) {\n" - "std :: cout << log2l ( x ) ;\n" - "std :: cout << log2l ( 10.0f ) ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_log2l, tokenizeAndStringify(code_log2l)); - } - - void simplifyMathFunctions_pow() { - // verify pow(),pow(),powl() - simplifcation - const char code_pow[] ="void f() {\n" - " std::cout << pow(-1.0,1);\n" - " std::cout << pow(1.0,1);\n" - " std::cout << pow(0,1);\n" - " std::cout << pow(1,-6);\n" - " std::cout << powf(-1.0,1.0f);\n" - " std::cout << powf(1.0,1.0f);\n" - " std::cout << powf(0,1.0f);\n" - " std::cout << powf(1.0,-6.0f);\n" - " std::cout << powl(-1.0,1.0);\n" - " std::cout << powl(1.0,1.0);\n" - " std::cout << powl(0,1.0);\n" - " std::cout << powl(1.0,-6.0d);\n" - "}"; - - const char expected_pow[] = "void f ( ) {\n" - "std :: cout << -1.0 ;\n" - "std :: cout << 1 ;\n" - "std :: cout << 0 ;\n" - "std :: cout << 1 ;\n" - "std :: cout << -1.0 ;\n" - "std :: cout << 1 ;\n" - "std :: cout << 0 ;\n" - "std :: cout << 1 ;\n" - "std :: cout << -1.0 ;\n" - "std :: cout << 1 ;\n" - "std :: cout << 0 ;\n" - "std :: cout << 1 ;\n" - "}"; - ASSERT_EQUALS(expected_pow, tokenizeAndStringify(code_pow)); - - // verify if code is simplified correctly. - // Do not simplify class members. - const char code_pow1[] = "int f(const Fred &fred) {return fred.pow(12,3);}"; - const char expected_pow1[] = "int f ( const Fred & fred ) { return fred . pow ( 12 , 3 ) ; }"; - ASSERT_EQUALS(expected_pow1, tokenizeAndStringify(code_pow1)); - - const char code_pow2[] = "int f() {return pow(0,0);}"; - const char expected_pow2[] = "int f ( ) { return 1 ; }"; - ASSERT_EQUALS(expected_pow2, tokenizeAndStringify(code_pow2)); - - const char code_pow3[] = "int f() {return pow(0,1);}"; - const char expected_pow3[] = "int f ( ) { return 0 ; }"; - ASSERT_EQUALS(expected_pow3, tokenizeAndStringify(code_pow3)); - - const char code_pow4[] = "int f() {return pow(1,0);}"; - const char expected_pow4[] = "int f ( ) { return 1 ; }"; - ASSERT_EQUALS(expected_pow4, tokenizeAndStringify(code_pow4)); - } - - void simplifyMathFunctions_fmin() { - // verify fmin,fminl,fminl simplifcation - const char code_fmin[] ="void f() {\n" - " std::cout << fmin(-1.0,0);\n" - " std::cout << fmin(1.0,0);\n" - " std::cout << fmin(0,0);\n" - " std::cout << fminf(-1.0,0);\n" - " std::cout << fminf(1.0,0);\n" - " std::cout << fminf(0,0);\n" - " std::cout << fminl(-1.0,0);\n" - " std::cout << fminl(1.0,0);\n" - " std::cout << fminl(0,0);\n" - "}"; - - const char expected_fmin[] = "void f ( ) {\n" - "std :: cout << -1.0 ;\n" - "std :: cout << 0 ;\n" - "std :: cout << 0 ;\n" - "std :: cout << -1.0 ;\n" - "std :: cout << 0 ;\n" - "std :: cout << 0 ;\n" - "std :: cout << -1.0 ;\n" - "std :: cout << 0 ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_fmin, tokenizeAndStringify(code_fmin)); - - // do not simplify this case - const char code_fmin1[] = "float f(float f) { return fmin(f,0);}"; - const char expected_fmin1[] = "float f ( float f ) { return fmin ( f , 0 ) ; }"; - ASSERT_EQUALS(expected_fmin1, tokenizeAndStringify(code_fmin1)); - } - - void simplifyMathFunctions_fmax() { - // verify fmax(),fmax(),fmaxl() simplifcation - const char code_fmax[] ="void f() {\n" - " std::cout << fmax(-1.0,0);\n" - " std::cout << fmax(1.0,0);\n" - " std::cout << fmax(0,0);\n" - " std::cout << fmaxf(-1.0,0);\n" - " std::cout << fmaxf(1.0,0);\n" - " std::cout << fmaxf(0,0);\n" - " std::cout << fmaxl(-1.0,0);\n" - " std::cout << fmaxl(1.0,0);\n" - " std::cout << fmaxl(0,0);\n" - "}"; - - const char expected_fmax[] = "void f ( ) {\n" - "std :: cout << 0 ;\n" - "std :: cout << 1.0 ;\n" - "std :: cout << 0 ;\n" - "std :: cout << 0 ;\n" - "std :: cout << 1.0 ;\n" - "std :: cout << 0 ;\n" - "std :: cout << 0 ;\n" - "std :: cout << 1.0 ;\n" - "std :: cout << 0 ;\n" - "}"; - ASSERT_EQUALS(expected_fmax, tokenizeAndStringify(code_fmax)); - - // do not simplify this case - const char code_fmax1[] = "float f(float f) { return fmax(f,0);}"; - const char expected_fmax1[] = "float f ( float f ) { return fmax ( f , 0 ) ; }"; - ASSERT_EQUALS(expected_fmax1, tokenizeAndStringify(code_fmax1)); - } - - void simplifyMathExpressions() { //#1620 - const char code1[] = "void foo() {\n" - " std::cout<