Skip to content

Commit 4bb3d95

Browse files
authored
cleaned up some Token::insertToken*() calls (#7791)
1 parent dca6e38 commit 4bb3d95

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

lib/templatesimplifier.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,7 +1581,7 @@ void TemplateSimplifier::addNamespace(const TokenAndName &templateDeclaration, c
15811581
}
15821582
} else {
15831583
if (insert)
1584-
mTokenList.back()->tokAt(offset)->insertToken(token, emptyString);
1584+
mTokenList.back()->tokAt(offset)->insertToken(token);
15851585
else
15861586
mTokenList.addtoken(token, tok->linenr(), tok->column(), tok->fileIndex());
15871587
}
@@ -1592,10 +1592,10 @@ void TemplateSimplifier::addNamespace(const TokenAndName &templateDeclaration, c
15921592
if (token != tokStart->str() || tok->strAt(-1) != "::") {
15931593
if (insert) {
15941594
if (!inTemplate)
1595-
mTokenList.back()->tokAt(offset)->insertToken(templateDeclaration.scope().substr(start), emptyString);
1595+
mTokenList.back()->tokAt(offset)->insertToken(templateDeclaration.scope().substr(start));
15961596
else
15971597
mTokenList.back()->tokAt(offset)->str(mTokenList.back()->strAt(offset) + templateDeclaration.scope().substr(start));
1598-
mTokenList.back()->tokAt(offset)->insertToken("::", emptyString);
1598+
mTokenList.back()->tokAt(offset)->insertToken("::");
15991599
} else {
16001600
if (!inTemplate)
16011601
mTokenList.addtoken(templateDeclaration.scope().substr(start), tok->linenr(), tok->column(), tok->fileIndex());
@@ -1762,7 +1762,7 @@ void TemplateSimplifier::expandTemplate(
17621762
++typeindentlevel;
17631763
else if (typetok->str() == ")")
17641764
--typeindentlevel;
1765-
dst->insertToken(typetok->str(), typetok->originalName(), typetok->getMacroName(), true);
1765+
dst->insertTokenBefore(typetok->str(), typetok->originalName(), typetok->getMacroName());
17661766
dst->previous()->linenr(start->linenr());
17671767
dst->previous()->column(start->column());
17681768
Token *previous = dst->previous();
@@ -1790,7 +1790,7 @@ void TemplateSimplifier::expandTemplate(
17901790
}
17911791
}
17921792
if (pointerType && Token::simpleMatch(dst1, "const")) {
1793-
dst->insertToken("const", dst1->originalName(), dst1->getMacroName(), true);
1793+
dst->insertTokenBefore("const", dst1->originalName(), dst1->getMacroName());
17941794
dst->previous()->linenr(start->linenr());
17951795
dst->previous()->column(start->column());
17961796
dst1->deleteThis();
@@ -1842,15 +1842,15 @@ void TemplateSimplifier::expandTemplate(
18421842
}
18431843
// just copy the token if it wasn't instantiated
18441844
if (start != closing) {
1845-
dst->insertToken(start->str(), start->originalName(), start->getMacroName(), true);
1845+
dst->insertTokenBefore(start->str(), start->originalName(), start->getMacroName());
18461846
dst->previous()->linenr(start->linenr());
18471847
dst->previous()->column(start->column());
18481848
dst->previous()->isSigned(start->isSigned());
18491849
dst->previous()->isUnsigned(start->isUnsigned());
18501850
dst->previous()->isLong(start->isLong());
18511851
}
18521852
} else {
1853-
dst->insertToken(start->str(), start->originalName(), start->getMacroName(), true);
1853+
dst->insertTokenBefore(start->str(), start->originalName(), start->getMacroName());
18541854
dst->previous()->linenr(start->linenr());
18551855
dst->previous()->column(start->column());
18561856
dst->previous()->isSigned(start->isSigned());

lib/token.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -964,10 +964,12 @@ class CPPCHECKLIB Token {
964964
* relations between next and previous token also.
965965
* @param tokenStr String for the new token.
966966
* @param originalNameStr String used for Token::originalName().
967-
* @param prepend Insert the new token before this token when it's not
968967
* the first one on the tokens list.
969968
*/
970-
RET_NONNULL Token* insertToken(const std::string& tokenStr, const std::string& originalNameStr = emptyString, const std::string& macroNameStr = emptyString, bool prepend = false);
969+
RET_NONNULL Token* insertToken(const std::string& tokenStr, const std::string& originalNameStr = emptyString, const std::string& macroNameStr = emptyString)
970+
{
971+
return insertToken(tokenStr, originalNameStr, macroNameStr, false);
972+
}
971973

972974
RET_NONNULL Token* insertTokenBefore(const std::string& tokenStr, const std::string& originalNameStr = emptyString, const std::string& macroNameStr = emptyString)
973975
{
@@ -1402,6 +1404,8 @@ class CPPCHECKLIB Token {
14021404
*/
14031405
static const char *chrInFirstWord(const char *str, char c);
14041406

1407+
RET_NONNULL Token* insertToken(const std::string& tokenStr, const std::string& originalNameStr, const std::string& macroNameStr, bool prepend);
1408+
14051409
std::string mStr;
14061410

14071411
Token* mNext{};

lib/tokenize.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2972,7 +2972,7 @@ bool Tokenizer::simplifyUsing()
29722972
structEnd = structEnd->link();
29732973

29742974
// add ';' after end of struct
2975-
structEnd->insertToken(";", emptyString);
2975+
structEnd->insertToken(";");
29762976

29772977
// add name for anonymous struct
29782978
if (!hasName) {
@@ -2982,8 +2982,8 @@ bool Tokenizer::simplifyUsing()
29822982
else
29832983
newName = "Unnamed" + std::to_string(mUnnamedCount++);
29842984
TokenList::copyTokens(structEnd->next(), tok, start);
2985-
structEnd->tokAt(5)->insertToken(newName, emptyString);
2986-
start->insertToken(newName, emptyString);
2985+
structEnd->tokAt(5)->insertToken(newName);
2986+
start->insertToken(newName);
29872987
} else
29882988
TokenList::copyTokens(structEnd->next(), tok, start->next());
29892989

0 commit comments

Comments
 (0)