@@ -4825,9 +4825,6 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
48254825 // Combine tokens..
48264826 combineOperators ();
48274827
4828- // replace 'sin(0)' to '0' and other similar math expressions
4829- simplifyMathExpressions ();
4830-
48314828 // combine "- %num%"
48324829 concatenateNegativeNumberAndAnyPositive ();
48334830
@@ -8518,18 +8515,6 @@ bool Tokenizer::isOneNumber(const std::string &s)
85188515 return isNumberOneOf (s, 1L , " 1.0" );
85198516}
85208517
8521- // ------------------------------------------------------------------------
8522- // Helper function to check whether number is two (2 or 0.2E+1 or 2E+0) or not?
8523- // @param s the string to check
8524- // @return true in case s is two and false otherwise.
8525- // ------------------------------------------------------------------------
8526- bool Tokenizer::isTwoNumber (const std::string &s)
8527- {
8528- if (!MathLib::isPositive (s))
8529- return false ;
8530- return isNumberOneOf (s, 2L , " 2.0" );
8531- }
8532-
85338518void Tokenizer::simplifyComma ()
85348519{
85358520 bool inReturn = false ;
@@ -10912,96 +10897,6 @@ void Tokenizer::printUnknownTypes() const
1091210897 }
1091310898}
1091410899
10915- void Tokenizer::simplifyMathExpressions ()
10916- {
10917- for (Token *tok = list.front (); tok; tok = tok->next ()) {
10918-
10919- // simplify Pythagorean trigonometric identity: pow(sin(x),2)+pow(cos(x),2) = 1
10920- // pow(cos(x),2)+pow(sin(x),2) = 1
10921- // @todo: sin(x) * sin(x) + cos(x) * cos(x) = 1
10922- // cos(x) * cos(x) + sin(x) * sin(x) = 1
10923- // simplify Hyperbolic identity: pow(sinh(x),2)-pow(cosh(x),2) = -1
10924- // pow(cosh(x),2)-pow(sinh(x),2) = -1
10925- // @todo: sinh(x) * sinh(x) - cosh(x) * cosh(x) = -1
10926- // cosh(x) * cosh(x) - sinh(x) * sinh(x) = -1
10927- if (Token::Match (tok, " pow|powf|powl (" )) {
10928- if (Token::Match (tok->tokAt (2 ), " sin|sinf|sinl (" )) {
10929- Token * const tok2 = tok->linkAt (3 );
10930- if (!Token::Match (tok2, " ) , %num% ) + pow|powf|powl ( cos|cosf|cosl (" ))
10931- continue ;
10932- const std::string& leftExponent = tok2->strAt (2 );
10933- if (!isTwoNumber (leftExponent))
10934- continue ; // left exponent is not 2
10935- const Token * const tok3 = tok2->tokAt (8 );
10936- Token * const tok4 = tok3->link ();
10937- if (!Token::Match (tok4, " ) , %num% )" ))
10938- continue ;
10939- const std::string& rightExponent = tok4->strAt (2 );
10940- if (!isTwoNumber (rightExponent))
10941- continue ; // right exponent is not 2
10942- if (tok->tokAt (3 )->stringifyList (tok2->next ()) == tok3->stringifyList (tok4->next ())) {
10943- Token::eraseTokens (tok, tok4->tokAt (4 ));
10944- tok->str (" 1" );
10945- }
10946- } else if (Token::Match (tok->tokAt (2 ), " cos|cosf|cosl (" )) {
10947- Token * const tok2 = tok->linkAt (3 );
10948- if (!Token::Match (tok2, " ) , %num% ) + pow|powf|powl ( sin|sinf|sinl (" ))
10949- continue ;
10950- const std::string& leftExponent = tok2->strAt (2 );
10951- if (!isTwoNumber (leftExponent))
10952- continue ; // left exponent is not 2
10953- const Token * const tok3 = tok2->tokAt (8 );
10954- Token * const tok4 = tok3->link ();
10955- if (!Token::Match (tok4, " ) , %num% )" ))
10956- continue ;
10957- const std::string& rightExponent = tok4->strAt (2 );
10958- if (!isTwoNumber (rightExponent))
10959- continue ; // right exponent is not 2
10960- if (tok->tokAt (3 )->stringifyList (tok2->next ()) == tok3->stringifyList (tok4->next ())) {
10961- Token::eraseTokens (tok, tok4->tokAt (4 ));
10962- tok->str (" 1" );
10963- }
10964- } else if (Token::Match (tok->tokAt (2 ), " sinh|sinhf|sinhl (" )) {
10965- Token * const tok2 = tok->linkAt (3 );
10966- if (!Token::Match (tok2, " ) , %num% ) - pow|powf|powl ( cosh|coshf|coshl (" ))
10967- continue ;
10968- const std::string& leftExponent = tok2->strAt (2 );
10969- if (!isTwoNumber (leftExponent))
10970- continue ; // left exponent is not 2
10971- const Token * const tok3 = tok2->tokAt (8 );
10972- Token * const tok4 = tok3->link ();
10973- if (!Token::Match (tok4, " ) , %num% )" ))
10974- continue ;
10975- const std::string& rightExponent = tok4->strAt (2 );
10976- if (!isTwoNumber (rightExponent))
10977- continue ; // right exponent is not 2
10978- if (tok->tokAt (3 )->stringifyList (tok2->next ()) == tok3->stringifyList (tok4->next ())) {
10979- Token::eraseTokens (tok, tok4->tokAt (4 ));
10980- tok->str (" -1" );
10981- }
10982- } else if (Token::Match (tok->tokAt (2 ), " cosh|coshf|coshl (" )) {
10983- Token * const tok2 = tok->linkAt (3 );
10984- if (!Token::Match (tok2, " ) , %num% ) - pow|powf|powl ( sinh|sinhf|sinhl (" ))
10985- continue ;
10986- const std::string& leftExponent = tok2->strAt (2 );
10987- if (!isTwoNumber (leftExponent))
10988- continue ; // left exponent is not 2
10989- const Token * const tok3 = tok2->tokAt (8 );
10990- Token * const tok4 = tok3->link ();
10991- if (!Token::Match (tok4, " ) , %num% )" ))
10992- continue ;
10993- const std::string& rightExponent = tok4->strAt (2 );
10994- if (!isTwoNumber (rightExponent))
10995- continue ; // right exponent is not 2
10996- if (tok->tokAt (3 )->stringifyList (tok2->next ()) == tok3->stringifyList (tok4->next ())) {
10997- Token::eraseTokens (tok, tok4->tokAt (4 ));
10998- tok->str (" -1" );
10999- }
11000- }
11001- }
11002- }
11003- }
11004-
1100510900void Tokenizer::prepareTernaryOpForAST ()
1100610901{
1100710902 // http://en.cppreference.com/w/cpp/language/operator_precedence says about ternary operator:
0 commit comments