Fixed wrong tokenization of some math formulas:
The two formulas: sin^2+cos^2 = 1 and sinh^2-cosh^2 = -1 are true iff the two arguments are the same.
This commit is contained in:
parent
d37906041b
commit
5485e6866f
|
@ -9350,12 +9350,12 @@ void Tokenizer::simplifyMathExpressions()
|
|||
tok->str("0");
|
||||
}
|
||||
|
||||
if (Token::Match(tok,"pow ( sin ( %var% ) , 2 ) + pow ( cos ( %var% ) , 2 )")) {
|
||||
if (Token::Match(tok,"pow ( sin ( %any% ) , 2 ) + pow ( cos ( %any% ) , 2 )") && tok->strAt(4) == tok->strAt(14)) {
|
||||
tok->deleteNext(18);
|
||||
tok->str("1");
|
||||
}
|
||||
|
||||
if (Token::Match(tok,"pow ( sinh ( %var% ) , 2 ) - pow ( cosh ( %var% ) , 2 )")) {
|
||||
if (Token::Match(tok,"pow ( sinh ( %any% ) , 2 ) - pow ( cosh ( %any% ) , 2 )") && tok->strAt(4) == tok->strAt(14)) {
|
||||
tok->deleteNext(18);
|
||||
tok->str("-1");
|
||||
}
|
||||
|
|
|
@ -7714,32 +7714,38 @@ private:
|
|||
}
|
||||
|
||||
void simplifyMathExpressions() {//#1620
|
||||
const char *code1 ="void foo() {\n"
|
||||
"std::cout<<sin(0);\n"
|
||||
"std::cout<<cos(0);\n"
|
||||
"std::cout<<sinh(0);\n"
|
||||
"std::cout<<cosh(0);\n"
|
||||
"std::cout<<exp(0);\n"
|
||||
"std::cout<<sqrt(0);\n"
|
||||
"std::cout<<sqrt(1);\n"
|
||||
"std::cout<<ln(1);\n"
|
||||
"std::cout<<pow(sin(x),2)+pow(cos(x),2);\n"
|
||||
"std::cout<<pow(sinh(x),2)-pow(cosh(x),2);\n"
|
||||
"}";
|
||||
const char code1[] = "void foo() {\n"
|
||||
" std::cout<<sin(0);\n"
|
||||
" std::cout<<cos(0);\n"
|
||||
" std::cout<<sinh(0);\n"
|
||||
" std::cout<<cosh(0);\n"
|
||||
" std::cout<<exp(0);\n"
|
||||
" std::cout<<sqrt(0);\n"
|
||||
" std::cout<<sqrt(1);\n"
|
||||
" std::cout<<ln(1);\n"
|
||||
" std::cout<<pow(sin(x),2)+pow(cos(x),2);\n"
|
||||
" std::cout<<pow(sinh(x),2)-pow(cosh(x),2);\n"
|
||||
"}";
|
||||
|
||||
const char *expected1 ="void foo ( ) {\n"
|
||||
"std :: cout << 0 ;\n"
|
||||
"std :: cout << 1 ;\n"
|
||||
"std :: cout << 0 ;\n"
|
||||
"std :: cout << 1 ;\n"
|
||||
"std :: cout << 1 ;\n"
|
||||
"std :: cout << 0 ;\n"
|
||||
"std :: cout << 1 ;\n"
|
||||
"std :: cout << 0 ;\n"
|
||||
"std :: cout << 1 ;\n"
|
||||
"std :: cout << -1 ;\n"
|
||||
"}";
|
||||
const char expected1[] = "void foo ( ) {\n"
|
||||
"std :: cout << 0 ;\n"
|
||||
"std :: cout << 1 ;\n"
|
||||
"std :: cout << 0 ;\n"
|
||||
"std :: cout << 1 ;\n"
|
||||
"std :: cout << 1 ;\n"
|
||||
"std :: cout << 0 ;\n"
|
||||
"std :: cout << 1 ;\n"
|
||||
"std :: cout << 0 ;\n"
|
||||
"std :: cout << 1 ;\n"
|
||||
"std :: cout << -1 ;\n"
|
||||
"}";
|
||||
ASSERT_EQUALS(expected1, tokenizeAndStringify(code1));
|
||||
|
||||
const char code2[] = "void f ( ) {\n"
|
||||
"z = pow ( sin ( x ) , 2 ) + pow ( cos ( y ) , 2 ) ;\n"
|
||||
"t = pow ( sinh ( x ) , 2 ) - pow ( cosh ( y ) , 2 ) ;\n"
|
||||
"}";
|
||||
ASSERT_EQUALS(code2, tokenizeAndStringify(code2));
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue