Skip to content

Commit 7393af8

Browse files
committed
made TokensFrontBack::list a const reference
1 parent fec2bf8 commit 7393af8

4 files changed

Lines changed: 13 additions & 10 deletions

File tree

lib/token.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ void Token::update_property_info()
150150
else if (std::isalpha((unsigned char)mStr[0]) || mStr[0] == '_' || mStr[0] == '$') { // Name
151151
if (mImpl->mVarId)
152152
tokType(eVariable);
153-
else if (mTokensFrontBack && mTokensFrontBack->list && mTokensFrontBack->list->isKeyword(mStr))
153+
else if (mTokensFrontBack && mTokensFrontBack->list.isKeyword(mStr))
154154
tokType(eKeyword);
155155
else if (baseKeywords.count(mStr) > 0)
156156
tokType(eKeyword);
@@ -1820,7 +1820,7 @@ void Token::printValueFlow(bool xml, std::ostream &out) const
18201820
else {
18211821
if (fileIndex != tok->fileIndex()) {
18221822
outs += "File ";
1823-
outs += tok->mTokensFrontBack->list->getFiles()[tok->fileIndex()];
1823+
outs += tok->mTokensFrontBack->list.getFiles()[tok->fileIndex()];
18241824
outs += '\n';
18251825
line = 0;
18261826
}
@@ -2749,8 +2749,8 @@ const Token* findLambdaEndScope(const Token* tok) {
27492749

27502750
bool Token::isCpp() const
27512751
{
2752-
if (mTokensFrontBack && mTokensFrontBack->list) {
2753-
return mTokensFrontBack->list->isCPP();
2752+
if (mTokensFrontBack) {
2753+
return mTokensFrontBack->list.isCPP();
27542754
}
27552755
return true; // assume C++ by default
27562756
}

lib/tokenlist.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@
4646
static constexpr int AST_MAX_DEPTH = 150;
4747

4848

49-
TokenList::TokenList(const Settings* settings) :
50-
mSettings(settings)
49+
TokenList::TokenList(const Settings* settings)
50+
: mTokensFrontBack(*this)
51+
, mSettings(settings)
5152
{
52-
mTokensFrontBack.list = this;
5353
if (mSettings && (mSettings->enforcedLang != Standards::Language::None)) {
5454
mLang = mSettings->enforcedLang;
5555
}

lib/tokenlist.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ namespace simplecpp {
4444
* @brief This struct stores pointers to the front and back tokens of the list this token is in.
4545
*/
4646
struct TokensFrontBack {
47+
TokensFrontBack(const TokenList& list) : list(list) {}
4748
Token *front{};
4849
Token* back{};
49-
const TokenList* list{};
50+
const TokenList& list;
5051
};
5152

5253
class CPPCHECKLIB TokenList {

test/testtoken.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,8 @@ class TestToken : public TestFixture {
482482
}
483483

484484
void deleteLast() const {
485-
TokensFrontBack listEnds;
485+
TokenList list(nullptr);
486+
TokensFrontBack listEnds(list);
486487
Token ** const tokensBack = &(listEnds.back);
487488
Token tok(&listEnds);
488489
tok.insertToken("aba");
@@ -492,7 +493,8 @@ class TestToken : public TestFixture {
492493
}
493494

494495
void deleteFirst() const {
495-
TokensFrontBack listEnds;
496+
TokenList list(nullptr);
497+
TokensFrontBack listEnds(list);
496498
Token ** const tokensFront = &(listEnds.front);
497499
Token tok(&listEnds);
498500

0 commit comments

Comments
 (0)