Tokenizer: Remove simplifyCharAt from simplifyTokenList2

This commit is contained in:
Daniel Marjamäki 2022-06-12 15:14:48 +02:00
parent 8e4da32594
commit 343d04feb4
6 changed files with 0 additions and 95 deletions

View File

@ -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 */

View File

@ -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;
}

View File

@ -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())

View File

@ -458,8 +458,6 @@ public:
*/
bool simplifyRedundantParentheses();
void simplifyCharAt();
/** Simplify references */
void simplifyReference();

View File

@ -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"

View File

@ -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;