From c0f3d5b2fb69157a343116ceac498fe0a8436752 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 8 Jun 2022 19:08:18 +0200 Subject: [PATCH] Tokenizer: remove simplifyAssignmentInFunctionCall used in simplifyTokenList2 --- lib/tokenize.cpp | 42 ------------------------------------- lib/tokenize.h | 4 ---- test/testsimplifytokens.cpp | 8 ------- 3 files changed, 54 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 993517533..da9f97465 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -5275,9 +5275,6 @@ bool Tokenizer::simplifyTokenList2() tok->clearValueFlow(); } - // f(x=g()) => x=g(); f(x) - simplifyAssignmentInFunctionCall(); - // ";a+=b;" => ";a=a+b;" simplifyCompoundAssignment(); @@ -11172,45 +11169,6 @@ void Tokenizer::simplifyDebug() } } -void Tokenizer::simplifyAssignmentInFunctionCall() -{ - for (Token *tok = list.front(); tok; tok = tok->next()) { - if (tok->str() == "(") - tok = tok->link(); - - // Find 'foo(var='. Exclude 'assert(var=' to allow tests to check that assert(...) does not contain side-effects - else if (Token::Match(tok, "[;{}] %name% ( %name% =") && - Token::simpleMatch(tok->linkAt(2), ") ;") && - !Token::Match(tok->next(), "assert|while")) { - const std::string& funcname(tok->next()->str()); - Token* const vartok = tok->tokAt(3); - - // Goto ',' or ')'.. - for (Token *tok2 = vartok->tokAt(2); tok2; tok2 = tok2->next()) { - if (tok2->link() && Token::Match(tok2, "(|[|{")) - tok2 = tok2->link(); - else if (tok2->str() == ";") - break; - else if (Token::Match(tok2, ")|,")) { - tok2 = tok2->previous(); - - tok2->insertToken(vartok->str()); - tok2->next()->varId(vartok->varId()); - - tok2->insertToken("("); - Token::createMutualLinks(tok2->next(), tok->linkAt(2)); - - tok2->insertToken(funcname); - tok2->insertToken(";"); - - Token::eraseTokens(tok, vartok); - break; - } - } - } - } -} - void Tokenizer::simplifyAssignmentBlock() { for (Token *tok = list.front(); tok; tok = tok->next()) { diff --git a/lib/tokenize.h b/lib/tokenize.h index 22b1a0dd7..82866854d 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -218,10 +218,6 @@ public: */ bool isFunctionParameterPassedByValue(const Token *fpar) const; - /** Simplify assignment in function call "f(x=g());" => "x=g();f(x);" - */ - void simplifyAssignmentInFunctionCall(); - /** Simplify assignment where rhs is a block : "x=({123;});" => "{x=123;}" */ void simplifyAssignmentBlock(); diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 7cca6fc34..98f02e083 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -60,9 +60,6 @@ private: TEST_CASE(test1); // array access. replace "*(p+1)" => "p[1]" - // foo(p = new char[10]); => p = new char[10]; foo(p); - TEST_CASE(simplifyAssignmentInFunctionCall); - // ";a+=b;" => ";a=a+b;" TEST_CASE(simplifyCompoundAssignment); @@ -1777,11 +1774,6 @@ private: } - void simplifyAssignmentInFunctionCall() { - ASSERT_EQUALS("; x = g ( ) ; f ( x ) ;", tok(";f(x=g());")); - ASSERT_EQUALS("; hs = ( xyz_t ) { h . centerX , h . centerY , 1 + index } ; putInput ( hs , 1 ) ;", tok(";putInput(hs = (xyz_t) { h->centerX, h->centerY, 1 + index }, 1);")); - } - void simplifyCompoundAssignment() { ASSERT_EQUALS("; x = x + y ;", tok("; x += y;")); ASSERT_EQUALS("; x = x - y ;", tok("; x -= y;"));