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
22 changes: 17 additions & 5 deletions lib/token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1061,18 +1061,14 @@ void Token::function(const Function *f)
tokType(eName);
}

Token* Token::insertToken(const std::string& tokenStr, const std::string& originalNameStr, const std::string& macroNameStr, bool prepend)
Token* Token::insertToken(const std::string& tokenStr, bool prepend)
{
Token *newToken;
if (mStr.empty())
newToken = this;
else
newToken = new Token(mList, mTokensFrontBack);
newToken->str(tokenStr);
if (!originalNameStr.empty())
newToken->originalName(originalNameStr);
if (!macroNameStr.empty())
newToken->setMacroName(macroNameStr);

if (newToken != this) {
newToken->mImpl->mLineNumber = mImpl->mLineNumber;
Expand Down Expand Up @@ -1198,6 +1194,22 @@ Token* Token::insertToken(const std::string& tokenStr, const std::string& origin
return newToken;
}

Token* Token::insertToken(const std::string& tokenStr, const std::string& originalNameStr, bool prepend)
{
Token* const newToken = insertToken(tokenStr, prepend);
if (!originalNameStr.empty())
newToken->originalName(originalNameStr);
return newToken;
}

Token* Token::insertToken(const std::string& tokenStr, const std::string& originalNameStr, const std::string& macroNameStr, bool prepend)
{
Token* const newToken = insertToken(tokenStr, originalNameStr, prepend);
if (!macroNameStr.empty())
newToken->setMacroName(macroNameStr);
return newToken;
}

void Token::eraseTokens(Token *begin, const Token *end)
{
if (!begin || begin == end)
Expand Down
35 changes: 32 additions & 3 deletions lib/token.h
Original file line number Diff line number Diff line change
Expand Up @@ -959,19 +959,46 @@ class CPPCHECKLIB Token {
*/
static void eraseTokens(Token *begin, const Token *end);

/**
* Insert new token after this token. This function will handle
* relations between next and previous token also.
* @param tokenStr String for the new token.
*/
RET_NONNULL Token* insertToken(const std::string& tokenStr)
{
return insertToken(tokenStr, false);
}
/**
* Insert new token after this token. This function will handle
* relations between next and previous token also.
* @param tokenStr String for the new token.
* @param originalNameStr String used for Token::originalName().
* 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)
RET_NONNULL Token* insertToken(const std::string& tokenStr, const std::string& originalNameStr)
{
return insertToken(tokenStr, originalNameStr, false);
}
/**
* Insert new token after this token. This function will handle
* relations between next and previous token also.
* @param tokenStr String for the new token.
* @param originalNameStr String used for Token::originalName().
* @param macroNameStr String used for Token::getMacroName().
*/
RET_NONNULL Token* insertToken(const std::string& tokenStr, const std::string& originalNameStr, const std::string& macroNameStr)
{
return insertToken(tokenStr, originalNameStr, macroNameStr, false);
}

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

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

std::string mStr;
Expand Down