From 343d04feb4719a9ac2760639168fd29e72a5bfa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 12 Jun 2022 15:14:48 +0200 Subject: [PATCH] Tokenizer: Remove simplifyCharAt from simplifyTokenList2 --- lib/token.cpp | 30 ------------------------------ lib/token.h | 10 ---------- lib/tokenize.cpp | 17 ----------------- lib/tokenize.h | 2 -- test/testsimplifytokens.cpp | 13 ------------- test/testtoken.cpp | 23 ----------------------- 6 files changed, 95 deletions(-) diff --git a/lib/token.cpp b/lib/token.cpp index 149bc1baa..da8e0940d 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -780,36 +780,6 @@ nonneg int Token::getStrSize(const Token *tok, const Settings *settings) return getStrArraySize(tok) * sizeofType; } -std::string Token::getCharAt(const Token *tok, MathLib::bigint index) -{ - assert(tok != nullptr); - std::string str(getStringLiteral(tok->str())); - std::string::const_iterator it = str.begin(); - const std::string::const_iterator end = str.end(); - - while (it != end) { - if (index == 0) { - if (*it == '\0') - return "\\0"; - - std::string ret(1, *it); - if (*it == '\\') { - ++it; - ret += *it; - } - return ret; - } - - if (*it == '\\') - ++it; - ++it; - --index; - } - assert(index == 0); - - return "\\0"; -} - void Token::move(Token *srcStart, Token *srcEnd, Token *newLocation) { /**[newLocation] -> b -> c -> [srcStart] -> [srcEnd] -> f */ diff --git a/lib/token.h b/lib/token.h index f4e449528..5dce2b96c 100644 --- a/lib/token.h +++ b/lib/token.h @@ -356,16 +356,6 @@ public: **/ static nonneg int getStrSize(const Token *tok, const Settings *const settings); - /** - * @return char of C-string at index (possible escaped "\\n") - * - * Should be called for %%str%% tokens only. - * - * @param tok token with C-string - * @param index position of character - **/ - static std::string getCharAt(const Token *tok, MathLib::bigint index); - const ValueType *valueType() const { return mImpl->mValueType; } diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 06ca1c146..bfe9e5178 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -5349,8 +5349,6 @@ bool Tokenizer::simplifyTokenList2() tok->clearValueFlow(); } - simplifyCharAt(); - // simplify references simplifyReference(); @@ -8993,21 +8991,6 @@ void Tokenizer::simplifyTypeIntrinsics() } } -void Tokenizer::simplifyCharAt() -{ - // Replace "string"[0] with 's' - for (Token *tok = list.front(); tok; tok = tok->next()) { - if (Token::Match(tok, "%str% [ %num% ]")) { - const MathLib::bigint index = MathLib::toLongNumber(tok->strAt(2)); - // Check within range - if (index >= 0 && index <= Token::getStrLength(tok)) { - tok->str("'" + Token::getCharAt(tok, index) + "'"); - tok->deleteNext(3); - } - } - } -} - void Tokenizer::simplifyReference() { if (isC()) diff --git a/lib/tokenize.h b/lib/tokenize.h index ebf2abfff..3fc14dcbf 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -458,8 +458,6 @@ public: */ bool simplifyRedundantParentheses(); - void simplifyCharAt(); - /** Simplify references */ void simplifyReference(); diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 82f0069c6..07b1a3307 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -213,7 +213,6 @@ private: TEST_CASE(undefinedSizeArray); TEST_CASE(simplifyArrayAddress); // Replace "&str[num]" => "(str + num)" - TEST_CASE(simplifyCharAt); TEST_CASE(simplifyOverride); // ticket #5069 TEST_CASE(simplifyNestedNamespace); TEST_CASE(simplifyNamespaceAliases1); @@ -4850,18 +4849,6 @@ private: " }", tok(code, true)); } - void simplifyCharAt() { // ticket #4481 - ASSERT_EQUALS("'h' ;", tok("\"hello\"[0] ;")); - ASSERT_EQUALS("'\\n' ;", tok("\"\\n\"[0] ;")); - ASSERT_EQUALS("'\\0' ;", tok("\"hello\"[5] ;")); - ASSERT_EQUALS("'\\0' ;", tok("\"\"[0] ;")); - ASSERT_EQUALS("'\\0' ;", tok("\"\\0\"[0] ;")); - ASSERT_EQUALS("'\\n' ;", tok("\"hello\\nworld\"[5] ;")); - ASSERT_EQUALS("'w' ;", tok("\"hello world\"[6] ;")); - ASSERT_EQUALS("\"hello\" [ 7 ] ;", tok("\"hello\"[7] ;")); - ASSERT_EQUALS("\"hello\" [ -1 ] ;", tok("\"hello\"[-1] ;")); - } - void test_4881() { const char code[] = "int evallex() {\n" " int c, t;\n" diff --git a/test/testtoken.cpp b/test/testtoken.cpp index 34a963e16..66a24c34f 100644 --- a/test/testtoken.cpp +++ b/test/testtoken.cpp @@ -62,7 +62,6 @@ private: TEST_CASE(stringTypes); TEST_CASE(getStrLength); TEST_CASE(getStrSize); - TEST_CASE(getCharAt); TEST_CASE(strValue); TEST_CASE(concatStr); @@ -412,28 +411,6 @@ private: ASSERT_EQUALS(sizeof("\\"), Token::getStrSize(&tok, &settings)); } - void getCharAt() const { - Token tok; - - tok.str("\"asdf\""); - ASSERT_EQUALS("a", Token::getCharAt(&tok, 0)); - ASSERT_EQUALS("s", Token::getCharAt(&tok, 1)); - - tok.str("\"a\\ts\""); - ASSERT_EQUALS("\\t", Token::getCharAt(&tok, 1)); - - tok.str("\"\""); - ASSERT_EQUALS("\\0", Token::getCharAt(&tok, 0)); - - tok.str("L\"a\\ts\""); - ASSERT_EQUALS("a", Token::getCharAt(&tok, 0)); - ASSERT_EQUALS("\\t", Token::getCharAt(&tok, 1)); - - tok.str("u\"a\\ts\""); - ASSERT_EQUALS("\\t", Token::getCharAt(&tok, 1)); - ASSERT_EQUALS("s", Token::getCharAt(&tok, 2)); - } - void strValue() const { Token tok;