Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

made TokensFrontBack::list a const reference #5961

Merged
merged 2 commits into from
Feb 8, 2024
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
8 changes: 4 additions & 4 deletions lib/token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void Token::update_property_info()
else if (std::isalpha((unsigned char)mStr[0]) || mStr[0] == '_' || mStr[0] == '$') { // Name
if (mImpl->mVarId)
tokType(eVariable);
else if (mTokensFrontBack && mTokensFrontBack->list && mTokensFrontBack->list->isKeyword(mStr))
else if (mTokensFrontBack && mTokensFrontBack->list.isKeyword(mStr))
tokType(eKeyword);
else if (baseKeywords.count(mStr) > 0)
tokType(eKeyword);
Expand Down Expand Up @@ -1820,7 +1820,7 @@ void Token::printValueFlow(bool xml, std::ostream &out) const
else {
if (fileIndex != tok->fileIndex()) {
outs += "File ";
outs += tok->mTokensFrontBack->list->getFiles()[tok->fileIndex()];
outs += tok->mTokensFrontBack->list.getFiles()[tok->fileIndex()];
outs += '\n';
line = 0;
}
Expand Down Expand Up @@ -2749,8 +2749,8 @@ const Token* findLambdaEndScope(const Token* tok) {

bool Token::isCpp() const
{
if (mTokensFrontBack && mTokensFrontBack->list) {
return mTokensFrontBack->list->isCPP();
if (mTokensFrontBack) {
return mTokensFrontBack->list.isCPP();
}
return true; // assume C++ by default
}
6 changes: 3 additions & 3 deletions lib/tokenlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@
static constexpr int AST_MAX_DEPTH = 150;


TokenList::TokenList(const Settings* settings) :
mSettings(settings)
TokenList::TokenList(const Settings* settings)
: mTokensFrontBack(*this)
, mSettings(settings)
{
mTokensFrontBack.list = this;
if (mSettings && (mSettings->enforcedLang != Standards::Language::None)) {
mLang = mSettings->enforcedLang;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/tokenlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ namespace simplecpp {
* @brief This struct stores pointers to the front and back tokens of the list this token is in.
*/
struct TokensFrontBack {
explicit TokensFrontBack(const TokenList& list) : list(list) {}
Token *front{};
Token* back{};
const TokenList* list{};
const TokenList& list;
};

class CPPCHECKLIB TokenList {
Expand Down
6 changes: 4 additions & 2 deletions test/testtoken.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,8 @@ class TestToken : public TestFixture {
}

void deleteLast() const {
TokensFrontBack listEnds;
TokenList list(nullptr);
TokensFrontBack listEnds(list);
Token ** const tokensBack = &(listEnds.back);
Token tok(&listEnds);
tok.insertToken("aba");
Expand All @@ -492,7 +493,8 @@ class TestToken : public TestFixture {
}

void deleteFirst() const {
TokensFrontBack listEnds;
TokenList list(nullptr);
TokensFrontBack listEnds(list);
Token ** const tokensFront = &(listEnds.front);
Token tok(&listEnds);

Expand Down
Loading