From 575cb242c2d14705284b79e65a22113e8c0a5853 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 9 Apr 2011 16:22:47 +0200 Subject: [PATCH] Refactoring: Use Token::isOp --- lib/token.h | 2 +- lib/tokenize.cpp | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/token.h b/lib/token.h index 69d96e918..27498b3ea 100644 --- a/lib/token.h +++ b/lib/token.h @@ -175,7 +175,7 @@ public: } bool isExtendedOp() const { - return isOp() || + return isOp() || (this && _str.size() == 1 && _str.find_first_of(",[]()?:") != std::string::npos); } bool isBoolean() const diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 4c46e11ff..073030c79 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -5594,11 +5594,12 @@ bool Tokenizer::simplifyFunctionReturn() else if (indentlevel == 0 && Token::Match(tok, "%var% ( ) { return %num% ; }") && tok->str() != ")") { - std::ostringstream pattern; - pattern << "[(=+-*/] " << tok->str() << " ( ) [;)+-*/]"; + const std::string pattern("%any% " + tok->str() + " ( ) %any%"); for (Token *tok2 = _tokens; tok2; tok2 = tok2->next()) { - if (Token::Match(tok2, pattern.str().c_str())) + if (Token::Match(tok2, pattern.c_str()) && + (tok2->isOp() || Token::Match(tok2, "(|[|=")) && + (tok2->tokAt(4)->isOp() || Token::Match(tok2->tokAt(4), ";|]|)"))) { tok2 = tok2->next(); tok2->str(tok->strAt(5));