Skip to content

Commit 191359d

Browse files
dmcppcheckclaude
andcommitted
Add combineWithNext() for the token joins in TokenList::combineOperators()
No behaviour change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 6a576de commit 191359d

1 file changed

Lines changed: 22 additions & 28 deletions

File tree

‎simplecpp.cpp‎

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,13 @@ static bool isAnonymousReferenceParameter(const simplecpp::Token *tok)
13521352
return false;
13531353
}
13541354

1355+
/** Append the next token to tok, and delete the next token */
1356+
static void combineWithNext(simplecpp::TokenList &tokens, simplecpp::Token *tok)
1357+
{
1358+
tok->setstr(tok->str() + tok->next->str());
1359+
tokens.deleteToken(tok->next);
1360+
}
1361+
13551362
void simplecpp::TokenList::combineOperators()
13561363
{
13571364
std::stack<bool, std::vector<bool>> executableScope{{false}};
@@ -1363,34 +1370,28 @@ void simplecpp::TokenList::combineOperators()
13631370
// ellipsis ...
13641371
if (tok->next && tok->next->op == '.' && tok->next->location.col == (tok->location.col + 1) &&
13651372
tok->next->next && tok->next->next->op == '.' && tok->next->next->location.col == (tok->location.col + 2)) {
1366-
tok->setstr("...");
1367-
deleteToken(tok->next);
1368-
deleteToken(tok->next);
1373+
combineWithNext(*this, tok);
1374+
combineWithNext(*this, tok);
13691375
continue;
13701376
}
13711377
// float literals..
13721378
if (tok->previous && tok->previous->number && sameline(tok->previous, tok) && tok->previous->str().find_first_of("._") == std::string::npos) {
13731379
tok->setstr(tok->previous->str() + '.');
13741380
deleteToken(tok->previous);
1375-
if (sameline(tok, tok->next) && (isFloatSuffix(tok->next) || (tok->next && tok->next->startsWithOneOf("AaBbCcDdEeFfPp") && !isAlternativeAndBitandBitor(tok->next)))) {
1376-
tok->setstr(tok->str() + tok->next->str());
1377-
deleteToken(tok->next);
1378-
}
1379-
}
1380-
if (tok->next && tok->next->number) {
1381-
tok->setstr(tok->str() + tok->next->str());
1382-
deleteToken(tok->next);
1381+
if (sameline(tok, tok->next) && (isFloatSuffix(tok->next) || (tok->next && tok->next->startsWithOneOf("AaBbCcDdEeFfPp") && !isAlternativeAndBitandBitor(tok->next))))
1382+
combineWithNext(*this, tok);
13831383
}
1384+
if (tok->next && tok->next->number)
1385+
combineWithNext(*this, tok);
13841386
}
13851387
// match: [0-9.]+E [+-] [0-9]+
13861388
const char lastChar = tok->str()[tok->str().size() - 1];
13871389
if (tok->number && !isOct(tok->str()) &&
13881390
((!isHex(tok->str()) && (lastChar == 'E' || lastChar == 'e')) ||
13891391
(isHex(tok->str()) && (lastChar == 'P' || lastChar == 'p'))) &&
13901392
tok->next && tok->next->isOneOf("+-") && tok->next->next && tok->next->next->number) {
1391-
tok->setstr(tok->str() + tok->next->op + tok->next->next->str());
1392-
deleteToken(tok->next);
1393-
deleteToken(tok->next);
1393+
combineWithNext(*this, tok);
1394+
combineWithNext(*this, tok);
13941395
}
13951396

13961397
if (tok->op == '\0' || !tok->next || tok->next->op == '\0')
@@ -1405,23 +1406,17 @@ void simplecpp::TokenList::combineOperators()
14051406
// void f(x&=2)
14061407
if (tok->op == '&' && !executableScope.top() && isAnonymousReferenceParameter(tok))
14071408
continue;
1408-
tok->setstr(tok->str() + "=");
1409-
deleteToken(tok->next);
1409+
combineWithNext(*this, tok);
14101410
} else if ((tok->op == '|' || tok->op == '&') && tok->op == tok->next->op) {
1411-
tok->setstr(tok->str() + tok->next->str());
1412-
deleteToken(tok->next);
1411+
combineWithNext(*this, tok);
14131412
} else if (tok->op == ':' && tok->next->op == ':') {
1414-
tok->setstr(tok->str() + tok->next->str());
1415-
deleteToken(tok->next);
1413+
combineWithNext(*this, tok);
14161414
} else if (tok->op == '-' && tok->next->op == '>') {
1417-
tok->setstr(tok->str() + tok->next->str());
1418-
deleteToken(tok->next);
1415+
combineWithNext(*this, tok);
14191416
} else if ((tok->op == '<' || tok->op == '>') && tok->op == tok->next->op) {
1420-
tok->setstr(tok->str() + tok->next->str());
1421-
deleteToken(tok->next);
1417+
combineWithNext(*this, tok);
14221418
if (tok->next && tok->next->op == '=' && tok->next->next && tok->next->next->op != '=') {
1423-
tok->setstr(tok->str() + tok->next->str());
1424-
deleteToken(tok->next);
1419+
combineWithNext(*this, tok);
14251420
}
14261421
} else if ((tok->op == '+' || tok->op == '-') && tok->op == tok->next->op) {
14271422
if (tok->location.col + 1U != tok->next->location.col)
@@ -1430,8 +1425,7 @@ void simplecpp::TokenList::combineOperators()
14301425
continue;
14311426
if (tok->next->next && tok->next->next->number)
14321427
continue;
1433-
tok->setstr(tok->str() + tok->next->str());
1434-
deleteToken(tok->next);
1428+
combineWithNext(*this, tok);
14351429
}
14361430
}
14371431
}

0 commit comments

Comments
 (0)