TODO: This is not the correct class for simplifyCalculations(), so it should be moved away.
| 2721 | // TODO: This is not the correct class for simplifyCalculations(), so it |
| 2722 | // should be moved away. |
| 2723 | bool TemplateSimplifier::simplifyCalculations(Token* frontToken, const Token *backToken, bool isTemplate) |
| 2724 | { |
| 2725 | bool ret = false; |
| 2726 | const bool bounded = frontToken || backToken; |
| 2727 | if (!frontToken) { |
| 2728 | frontToken = mTokenList.front(); |
| 2729 | } |
| 2730 | for (Token *tok = frontToken; tok && tok != backToken; tok = tok->next()) { |
| 2731 | // Remove parentheses around variable.. |
| 2732 | // keep parentheses here: dynamic_cast<Fred *>(p); |
| 2733 | // keep parentheses here: A operator * (int); |
| 2734 | // keep parentheses here: int ( * ( * f ) ( ... ) ) (int) ; |
| 2735 | // keep parentheses here: int ( * * ( * compilerHookVector ) (void) ) ( ) ; |
| 2736 | // keep parentheses here: operator new [] (size_t); |
| 2737 | // keep parentheses here: Functor()(a ... ) |
| 2738 | // keep parentheses here: ) ( var ) ; |
| 2739 | if (validTokenEnd(bounded, tok, backToken, 4) && |
| 2740 | (Token::Match(tok->next(), "( %name% ) ;|)|,|]") || |
| 2741 | (Token::Match(tok->next(), "( %name% ) %cop%") && |
| 2742 | (tok->tokAt(2)->varId()>0 || |
| 2743 | !Token::Match(tok->tokAt(4), "[*&+-~]")))) && |
| 2744 | !tok->isName() && |
| 2745 | tok->str() != ">" && |
| 2746 | tok->str() != ")" && |
| 2747 | tok->str() != "]") { |
| 2748 | tok->deleteNext(); |
| 2749 | tok = tok->next(); |
| 2750 | tok->deleteNext(); |
| 2751 | ret = true; |
| 2752 | } |
| 2753 | |
| 2754 | if (validTokenEnd(bounded, tok, backToken, 3) && |
| 2755 | Token::Match(tok->previous(), "(|&&|%oror% %char% %comp% %num% &&|%oror%|)")) { |
| 2756 | tok->str(MathLib::toString(MathLib::toBigNumber(tok))); |
| 2757 | } |
| 2758 | |
| 2759 | if (validTokenEnd(bounded, tok, backToken, 5) && |
| 2760 | Token::Match(tok, "decltype ( %type% { } )")) { |
| 2761 | tok->deleteThis(); |
| 2762 | tok->deleteThis(); |
| 2763 | tok->deleteNext(); |
| 2764 | tok->deleteNext(); |
| 2765 | tok->deleteNext(); |
| 2766 | ret = true; |
| 2767 | } |
| 2768 | |
| 2769 | if (validTokenEnd(bounded, tok, backToken, 3) && |
| 2770 | Token::Match(tok, "decltype ( %bool%|%num% )")) { |
| 2771 | tok->deleteThis(); |
| 2772 | tok->deleteThis(); |
| 2773 | if (tok->isBoolean()) |
| 2774 | tok->str("bool"); |
| 2775 | else if (MathLib::isFloat(tok->str())) { |
| 2776 | // MathLib::getSuffix doesn't work for floating point numbers |
| 2777 | const char suffix = tok->str().back(); |
| 2778 | if (suffix == 'f' || suffix == 'F') |
| 2779 | tok->str("float"); |
| 2780 | else if (suffix == 'l' || suffix == 'L') { |
nothing calls this directly
no test coverage detected