From 5485e6866fc32943a7aad9590198d1a9d317e4cf Mon Sep 17 00:00:00 2001 From: Edoardo Prezioso Date: Fri, 4 Jan 2013 11:21:53 +0100 Subject: [PATCH] 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. --- lib/tokenize.cpp | 4 ++-- test/testtokenize.cpp | 54 ++++++++++++++++++++++++------------------- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 90a22b877..9c77aa60f 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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"); } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 7350b0a71..9a0189c35 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -7714,32 +7714,38 @@ private: } void simplifyMathExpressions() {//#1620 - const char *code1 ="void foo() {\n" - "std::cout<