Skip to content

Commit

Permalink
made TokensFrontBack::list a const reference
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Feb 8, 2024
1 parent 6ee2c86 commit 341aa8c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
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 {
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

0 comments on commit 341aa8c

Please sign in to comment.