Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions lib/templatesimplifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1581,7 +1581,7 @@ void TemplateSimplifier::addNamespace(const TokenAndName &templateDeclaration, c
}
} else {
if (insert)
mTokenList.back()->tokAt(offset)->insertToken(token, emptyString);
mTokenList.back()->tokAt(offset)->insertToken(token);
else
mTokenList.addtoken(token, tok->linenr(), tok->column(), tok->fileIndex());
}
Expand All @@ -1592,10 +1592,10 @@ void TemplateSimplifier::addNamespace(const TokenAndName &templateDeclaration, c
if (token != tokStart->str() || tok->strAt(-1) != "::") {
if (insert) {
if (!inTemplate)
mTokenList.back()->tokAt(offset)->insertToken(templateDeclaration.scope().substr(start), emptyString);
mTokenList.back()->tokAt(offset)->insertToken(templateDeclaration.scope().substr(start));
else
mTokenList.back()->tokAt(offset)->str(mTokenList.back()->strAt(offset) + templateDeclaration.scope().substr(start));
mTokenList.back()->tokAt(offset)->insertToken("::", emptyString);
mTokenList.back()->tokAt(offset)->insertToken("::");
} else {
if (!inTemplate)
mTokenList.addtoken(templateDeclaration.scope().substr(start), tok->linenr(), tok->column(), tok->fileIndex());
Expand Down Expand Up @@ -1762,7 +1762,7 @@ void TemplateSimplifier::expandTemplate(
++typeindentlevel;
else if (typetok->str() == ")")
--typeindentlevel;
dst->insertToken(typetok->str(), typetok->originalName(), typetok->getMacroName(), true);
dst->insertTokenBefore(typetok->str(), typetok->originalName(), typetok->getMacroName());
dst->previous()->linenr(start->linenr());
dst->previous()->column(start->column());
Token *previous = dst->previous();
Expand Down Expand Up @@ -1790,7 +1790,7 @@ void TemplateSimplifier::expandTemplate(
}
}
if (pointerType && Token::simpleMatch(dst1, "const")) {
dst->insertToken("const", dst1->originalName(), dst1->getMacroName(), true);
dst->insertTokenBefore("const", dst1->originalName(), dst1->getMacroName());
dst->previous()->linenr(start->linenr());
dst->previous()->column(start->column());
dst1->deleteThis();
Expand Down Expand Up @@ -1842,15 +1842,15 @@ void TemplateSimplifier::expandTemplate(
}
// just copy the token if it wasn't instantiated
if (start != closing) {
dst->insertToken(start->str(), start->originalName(), start->getMacroName(), true);
dst->insertTokenBefore(start->str(), start->originalName(), start->getMacroName());
dst->previous()->linenr(start->linenr());
dst->previous()->column(start->column());
dst->previous()->isSigned(start->isSigned());
dst->previous()->isUnsigned(start->isUnsigned());
dst->previous()->isLong(start->isLong());
}
} else {
dst->insertToken(start->str(), start->originalName(), start->getMacroName(), true);
dst->insertTokenBefore(start->str(), start->originalName(), start->getMacroName());
dst->previous()->linenr(start->linenr());
dst->previous()->column(start->column());
dst->previous()->isSigned(start->isSigned());
Expand Down
8 changes: 6 additions & 2 deletions lib/token.h
Original file line number Diff line number Diff line change
Expand Up @@ -964,10 +964,12 @@ class CPPCHECKLIB Token {
* relations between next and previous token also.
* @param tokenStr String for the new token.
* @param originalNameStr String used for Token::originalName().
* @param prepend Insert the new token before this token when it's not
* the first one on the tokens list.
*/
RET_NONNULL Token* insertToken(const std::string& tokenStr, const std::string& originalNameStr = emptyString, const std::string& macroNameStr = emptyString, bool prepend = false);
RET_NONNULL Token* insertToken(const std::string& tokenStr, const std::string& originalNameStr = emptyString, const std::string& macroNameStr = emptyString)
{
return insertToken(tokenStr, originalNameStr, macroNameStr, false);
}

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

RET_NONNULL Token* insertToken(const std::string& tokenStr, const std::string& originalNameStr, const std::string& macroNameStr, bool prepend);

std::string mStr;

Token* mNext{};
Expand Down
6 changes: 3 additions & 3 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2972,7 +2972,7 @@ bool Tokenizer::simplifyUsing()
structEnd = structEnd->link();

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

// add name for anonymous struct
if (!hasName) {
Expand All @@ -2982,8 +2982,8 @@ bool Tokenizer::simplifyUsing()
else
newName = "Unnamed" + std::to_string(mUnnamedCount++);
TokenList::copyTokens(structEnd->next(), tok, start);
structEnd->tokAt(5)->insertToken(newName, emptyString);
start->insertToken(newName, emptyString);
structEnd->tokAt(5)->insertToken(newName);
start->insertToken(newName);
} else
TokenList::copyTokens(structEnd->next(), tok, start->next());

Expand Down