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
4 changes: 3 additions & 1 deletion lib/token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,8 @@ Token* Token::insertToken(const std::string& tokenStr, const std::string& origin
newToken->str(tokenStr);
if (!originalNameStr.empty())
newToken->originalName(originalNameStr);
newToken->setMacroName(macroNameStr);
if (!macroNameStr.empty())
newToken->setMacroName(macroNameStr);

if (newToken != this) {
newToken->mImpl->mLineNumber = mImpl->mLineNumber;
Expand Down Expand Up @@ -2599,6 +2600,7 @@ const ValueFlow::Value* Token::getContainerSizeValue(const MathLib::bigint val)

TokenImpl::~TokenImpl()
{
delete mMacroName;
delete mOriginalName;
delete mValueType;
delete mValues;
Expand Down
11 changes: 7 additions & 4 deletions lib/token.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ struct TokenImpl {
std::string* mOriginalName{};

// If this token came from a macro replacement list, this is the name of that macro
std::string mMacroName;
std::string* mMacroName{};

// ValueType
ValueType* mValueType{};
Expand Down Expand Up @@ -480,7 +480,7 @@ class CPPCHECKLIB Token {
setFlag(fIsStandardType, b);
}
bool isExpandedMacro() const {
return !mImpl->mMacroName.empty();
return !!mImpl->mMacroName;
}
bool isCast() const {
return getFlag(fIsCast);
Expand Down Expand Up @@ -805,10 +805,13 @@ class CPPCHECKLIB Token {
}

const std::string& getMacroName() const {
return mImpl->mMacroName;
return mImpl->mMacroName ? *mImpl->mMacroName : mEmptyString;
}
void setMacroName(std::string name) {
mImpl->mMacroName = std::move(name);
if (!mImpl->mMacroName)
mImpl->mMacroName = new std::string(std::move(name));
else
*mImpl->mMacroName = std::move(name);
}

template<size_t count>
Expand Down
6 changes: 4 additions & 2 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,8 @@ namespace {
if (pointerType) {
tok->insertToken("const");
tok->next()->column(tok->column());
tok->next()->setMacroName(tok->previous()->getMacroName());
if (!tok->previous()->getMacroName().empty())
tok->next()->setMacroName(tok->previous()->getMacroName());
tok->deletePrevious();
}
}
Expand Down Expand Up @@ -7319,7 +7320,8 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, const Token * const tokEnd, co
endDecl = endDecl->next();
endDecl->next()->isSplittedVarDeclEq(true);
endDecl->insertToken(varName->str());
endDecl->next()->setMacroName(varName->getMacroName());
if (!varName->getMacroName().empty())
endDecl->next()->setMacroName(varName->getMacroName());
continue;
}
//non-VLA case
Expand Down
9 changes: 6 additions & 3 deletions lib/tokenlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ void TokenList::addtoken(const Token *tok)
mTokensFrontBack.back->str(tok->str());
if (!tok->originalName().empty())
mTokensFrontBack.back->originalName(tok->originalName());
mTokensFrontBack.back->setMacroName(tok->getMacroName());
if (!tok->getMacroName().empty())
mTokensFrontBack.back->setMacroName(tok->getMacroName());
}

mTokensFrontBack.back->flags(tok->flags());
Expand Down Expand Up @@ -332,7 +333,8 @@ void TokenList::insertTokens(Token *dest, const Token *src, nonneg int n)
dest->varId(src->varId());
dest->tokType(src->tokType());
dest->flags(src->flags());
dest->setMacroName(src->getMacroName());
if (!src->getMacroName().empty())
dest->setMacroName(src->getMacroName());
src = src->next();
--n;
}
Expand Down Expand Up @@ -415,7 +417,8 @@ void TokenList::createTokens(simplecpp::TokenList&& tokenList)
mTokensFrontBack.back->fileIndex(tok->location.fileIndex);
mTokensFrontBack.back->linenr(tok->location.line);
mTokensFrontBack.back->column(tok->location.col);
mTokensFrontBack.back->setMacroName(tok->macro);
if (!tok->macro.empty())
mTokensFrontBack.back->setMacroName(tok->macro);

tok = tok->next;
if (tok)
Expand Down