Skip to content

Commit deff5f7

Browse files
committed
moved TokenImpl out of global scope
1 parent 9b3c495 commit deff5f7

File tree

7 files changed

+137
-138
lines changed

7 files changed

+137
-138
lines changed

lib/checkleakautovar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ bool CheckLeakAutoVar::checkScope(const Token * const startToken,
396396
}
397397
}
398398

399-
if (tok->isCpp11init() == Cpp11init::CPP11INIT) {
399+
if (tok->isCpp11init() == Token::Cpp11init::CPP11INIT) {
400400
const Token *newTok = tok->astOperand1();
401401
const Token *oldTok = tok->astOperand2();
402402
if (newTok && newTok->varId() && oldTok && oldTok->varId()) {

lib/token.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,10 @@ const std::string Token::mEmptyString;
6464
Token::Token(const TokenList& tokenlist, std::shared_ptr<TokensFrontBack> tokensFrontBack)
6565
: mList(tokenlist)
6666
, mTokensFrontBack(std::move(tokensFrontBack))
67+
, mImpl(new Impl)
6768
, mIsC(mList.isC())
6869
, mIsCpp(mList.isCPP())
69-
{
70-
mImpl = new TokenImpl();
71-
}
70+
{}
7271

7372
Token::Token(const Token* tok)
7473
: Token(tok->mList, const_cast<Token*>(tok)->mTokensFrontBack)
@@ -2642,7 +2641,7 @@ const ValueFlow::Value* Token::getContainerSizeValue(const MathLib::bigint val)
26422641
return it == mImpl->mValues->end() ? nullptr : &*it;
26432642
}
26442643

2645-
TokenImpl::~TokenImpl()
2644+
Token::Impl::~Impl()
26462645
{
26472646
delete mMacroName;
26482647
delete mOriginalName;
@@ -2663,7 +2662,7 @@ TokenImpl::~TokenImpl()
26632662
}
26642663
}
26652664

2666-
void TokenImpl::setCppcheckAttribute(CppcheckAttributesType type, MathLib::bigint value)
2665+
void Token::Impl::setCppcheckAttribute(CppcheckAttributesType type, MathLib::bigint value)
26672666
{
26682667
CppcheckAttributes *attr = mCppcheckAttributes;
26692668
while (attr && attr->type != type)
@@ -2679,7 +2678,7 @@ void TokenImpl::setCppcheckAttribute(CppcheckAttributesType type, MathLib::bigin
26792678
}
26802679
}
26812680

2682-
bool TokenImpl::getCppcheckAttribute(CppcheckAttributesType type, MathLib::bigint &value) const
2681+
bool Token::Impl::getCppcheckAttribute(CppcheckAttributesType type, MathLib::bigint &value) const
26832682
{
26842683
CppcheckAttributes *attr = mCppcheckAttributes;
26852684
while (attr && attr->type != type)

lib/token.h

Lines changed: 98 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -63,103 +63,6 @@ struct ScopeInfo2 {
6363

6464
enum class TokenDebug : std::uint8_t { None, ValueFlow, ValueType };
6565

66-
// TODO: move these to Token when TokenImpl has been moved into the implementation
67-
enum CppcheckAttributesType : std::uint8_t { LOW, HIGH };
68-
enum class Cpp11init : std::uint8_t { UNKNOWN, CPP11INIT, NOINIT };
69-
70-
struct TokenImpl {
71-
nonneg int mVarId{};
72-
nonneg int mFileIndex{};
73-
nonneg int mLineNumber{};
74-
nonneg int mColumn{};
75-
nonneg int mExprId{};
76-
77-
// original template argument location
78-
int mTemplateArgFileIndex{-1};
79-
int mTemplateArgLineNumber{-1};
80-
int mTemplateArgColumn{-1};
81-
82-
/**
83-
* A value from 0-100 that provides a rough idea about where in the token
84-
* list this token is located.
85-
*/
86-
nonneg int mProgressValue{};
87-
88-
/**
89-
* Token index. Position in token list
90-
*/
91-
nonneg int mIndex{};
92-
93-
/** Bitfield bit count. */
94-
short mBits = -1;
95-
96-
// AST..
97-
Token* mAstOperand1{};
98-
Token* mAstOperand2{};
99-
Token* mAstParent{};
100-
101-
// symbol database information
102-
const Scope* mScope{};
103-
union {
104-
const Function *mFunction;
105-
const Variable *mVariable;
106-
const ::Type* mType;
107-
const Enumerator *mEnumerator;
108-
};
109-
110-
// original name like size_t
111-
std::string* mOriginalName{};
112-
113-
// If this token came from a macro replacement list, this is the name of that macro
114-
std::string* mMacroName{};
115-
116-
// ValueType
117-
ValueType* mValueType{};
118-
119-
// ValueFlow
120-
std::list<ValueFlow::Value>* mValues{};
121-
122-
// Pointer to a template in the template simplifier
123-
std::set<TemplateSimplifier::TokenAndName*>* mTemplateSimplifierPointers{};
124-
125-
// Pointer to the object representing this token's scope
126-
std::shared_ptr<ScopeInfo2> mScopeInfo;
127-
128-
// __cppcheck_in_range__
129-
struct CppcheckAttributes {
130-
CppcheckAttributesType type{LOW};
131-
MathLib::bigint value{};
132-
CppcheckAttributes* next{};
133-
};
134-
CppcheckAttributes* mCppcheckAttributes{};
135-
136-
// alignas expressions
137-
std::unique_ptr<std::vector<std::string>> mAttributeAlignas;
138-
void addAttributeAlignas(const std::string& a) {
139-
if (!mAttributeAlignas)
140-
mAttributeAlignas = std::unique_ptr<std::vector<std::string>>(new std::vector<std::string>());
141-
if (std::find(mAttributeAlignas->cbegin(), mAttributeAlignas->cend(), a) == mAttributeAlignas->cend())
142-
mAttributeAlignas->push_back(a);
143-
}
144-
145-
std::string mAttributeCleanup;
146-
147-
// For memoization, to speed up parsing of huge arrays #8897
148-
Cpp11init mCpp11init{Cpp11init::UNKNOWN};
149-
150-
TokenDebug mDebug{};
151-
152-
void setCppcheckAttribute(CppcheckAttributesType type, MathLib::bigint value);
153-
bool getCppcheckAttribute(CppcheckAttributesType type, MathLib::bigint &value) const;
154-
155-
TokenImpl() : mFunction(nullptr) {}
156-
157-
~TokenImpl();
158-
159-
TokenImpl(const TokenImpl &) = delete;
160-
TokenImpl operator=(const TokenImpl &) = delete;
161-
};
162-
16366
/// @addtogroup Core
16467
/// @{
16568

@@ -176,7 +79,104 @@ struct TokenImpl {
17679
class CPPCHECKLIB Token {
17780
friend class TestToken;
17881

82+
public:
83+
enum CppcheckAttributesType : std::uint8_t { LOW, HIGH };
84+
enum class Cpp11init : std::uint8_t { UNKNOWN, CPP11INIT, NOINIT };
85+
17986
private:
87+
struct Impl {
88+
nonneg int mVarId{};
89+
nonneg int mFileIndex{};
90+
nonneg int mLineNumber{};
91+
nonneg int mColumn{};
92+
nonneg int mExprId{};
93+
94+
// original template argument location
95+
int mTemplateArgFileIndex{-1};
96+
int mTemplateArgLineNumber{-1};
97+
int mTemplateArgColumn{-1};
98+
99+
/**
100+
* A value from 0-100 that provides a rough idea about where in the token
101+
* list this token is located.
102+
*/
103+
nonneg int mProgressValue{};
104+
105+
/**
106+
* Token index. Position in token list
107+
*/
108+
nonneg int mIndex{};
109+
110+
/** Bitfield bit count. */
111+
short mBits = -1;
112+
113+
// AST..
114+
Token* mAstOperand1{};
115+
Token* mAstOperand2{};
116+
Token* mAstParent{};
117+
118+
// symbol database information
119+
const Scope* mScope{};
120+
union {
121+
const Function *mFunction;
122+
const Variable *mVariable;
123+
const ::Type* mType;
124+
const Enumerator *mEnumerator;
125+
};
126+
127+
// original name like size_t
128+
std::string* mOriginalName{};
129+
130+
// If this token came from a macro replacement list, this is the name of that macro
131+
std::string* mMacroName{};
132+
133+
// ValueType
134+
ValueType* mValueType{};
135+
136+
// ValueFlow
137+
std::list<ValueFlow::Value>* mValues{};
138+
139+
// Pointer to a template in the template simplifier
140+
std::set<TemplateSimplifier::TokenAndName*>* mTemplateSimplifierPointers{};
141+
142+
// Pointer to the object representing this token's scope
143+
std::shared_ptr<ScopeInfo2> mScopeInfo;
144+
145+
// __cppcheck_in_range__
146+
struct CppcheckAttributes {
147+
CppcheckAttributesType type{LOW};
148+
MathLib::bigint value{};
149+
CppcheckAttributes* next{};
150+
};
151+
CppcheckAttributes* mCppcheckAttributes{};
152+
153+
// alignas expressions
154+
std::unique_ptr<std::vector<std::string>> mAttributeAlignas;
155+
void addAttributeAlignas(const std::string& a) {
156+
if (!mAttributeAlignas)
157+
mAttributeAlignas = std::unique_ptr<std::vector<std::string>>(new std::vector<std::string>());
158+
if (std::find(mAttributeAlignas->cbegin(), mAttributeAlignas->cend(), a) == mAttributeAlignas->cend())
159+
mAttributeAlignas->push_back(a);
160+
}
161+
162+
std::string mAttributeCleanup;
163+
164+
// For memoization, to speed up parsing of huge arrays #8897
165+
Cpp11init mCpp11init{Cpp11init::UNKNOWN};
166+
167+
TokenDebug mDebug{};
168+
169+
void setCppcheckAttribute(CppcheckAttributesType type, MathLib::bigint value);
170+
bool getCppcheckAttribute(CppcheckAttributesType type, MathLib::bigint &value) const;
171+
172+
Impl() : mFunction(nullptr) {}
173+
174+
~Impl();
175+
176+
Impl(const Impl &) = delete;
177+
Impl operator=(const Impl &) = delete;
178+
};
179+
180180
const TokenList& mList;
181181
std::shared_ptr<TokensFrontBack> mTokensFrontBack;
182182

@@ -1503,7 +1503,7 @@ class CPPCHECKLIB Token {
15031503

15041504
uint64_t mFlags{};
15051505

1506-
TokenImpl* mImpl{};
1506+
Impl* mImpl{};
15071507

15081508
/**
15091509
* Get specified flag state.

lib/tokenize.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9471,10 +9471,10 @@ void Tokenizer::simplifyCppcheckAttribute()
94719471

94729472
if (vartok->isName()) {
94739473
if (Token::Match(tok->previous(), "__cppcheck_low__ ( %num% )"))
9474-
vartok->setCppcheckAttribute(CppcheckAttributesType::LOW,
9474+
vartok->setCppcheckAttribute(Token::CppcheckAttributesType::LOW,
94759475
MathLib::toBigNumber(tok->tokAt(1)));
94769476
else if (Token::Match(tok->previous(), "__cppcheck_high__ ( %num% )"))
9477-
vartok->setCppcheckAttribute(CppcheckAttributesType::HIGH,
9477+
vartok->setCppcheckAttribute(Token::CppcheckAttributesType::HIGH,
94789478
MathLib::toBigNumber(tok->tokAt(1)));
94799479
}
94809480

@@ -9562,16 +9562,16 @@ void Tokenizer::simplifyCPPAttribute()
95629562
}
95639563
if (argtok && argtok->str() == vartok->str()) {
95649564
if (vartok->strAt(1) == ">=")
9565-
argtok->setCppcheckAttribute(CppcheckAttributesType::LOW,
9565+
argtok->setCppcheckAttribute(Token::CppcheckAttributesType::LOW,
95669566
MathLib::toBigNumber(vartok->tokAt(2)));
95679567
else if (vartok->strAt(1) == ">")
9568-
argtok->setCppcheckAttribute(CppcheckAttributesType::LOW,
9568+
argtok->setCppcheckAttribute(Token::CppcheckAttributesType::LOW,
95699569
MathLib::toBigNumber(vartok->tokAt(2)) + 1);
95709570
else if (vartok->strAt(1) == "<=")
9571-
argtok->setCppcheckAttribute(CppcheckAttributesType::HIGH,
9571+
argtok->setCppcheckAttribute(Token::CppcheckAttributesType::HIGH,
95729572
MathLib::toBigNumber(vartok->tokAt(2)));
95739573
else if (vartok->strAt(1) == "<")
9574-
argtok->setCppcheckAttribute(CppcheckAttributesType::HIGH,
9574+
argtok->setCppcheckAttribute(Token::CppcheckAttributesType::HIGH,
95759575
MathLib::toBigNumber(vartok->tokAt(2)) - 1);
95769576
}
95779577
}

lib/tokenlist.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -559,9 +559,9 @@ static Token * findCppTypeInitPar(Token *tok)
559559
static bool iscpp11init_impl(const Token * tok);
560560
static bool iscpp11init(const Token * const tok)
561561
{
562-
if (tok->isCpp11init() == Cpp11init::UNKNOWN)
562+
if (tok->isCpp11init() == Token::Cpp11init::UNKNOWN)
563563
tok->setCpp11init(iscpp11init_impl(tok));
564-
return tok->isCpp11init() == Cpp11init::CPP11INIT;
564+
return tok->isCpp11init() == Token::Cpp11init::CPP11INIT;
565565
}
566566

567567
static bool iscpp11init_impl(const Token * const tok)
@@ -570,8 +570,8 @@ static bool iscpp11init_impl(const Token * const tok)
570570
return false;
571571
const Token *nameToken = tok;
572572
while (nameToken && nameToken->str() == "{") {
573-
if (nameToken->isCpp11init() != Cpp11init::UNKNOWN)
574-
return nameToken->isCpp11init() == Cpp11init::CPP11INIT;
573+
if (nameToken->isCpp11init() != Token::Cpp11init::UNKNOWN)
574+
return nameToken->isCpp11init() == Token::Cpp11init::CPP11INIT;
575575
nameToken = nameToken->previous();
576576
if (nameToken && nameToken->str() == "," && Token::simpleMatch(nameToken->previous(), "} ,"))
577577
nameToken = nameToken->linkAt(-1);

lib/valueflow.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7160,8 +7160,8 @@ static void valueFlowSafeFunctions(const TokenList& tokenlist, const SymbolDatab
71607160
}
71617161

71627162
MathLib::bigint low, high;
7163-
bool isLow = arg.nameToken()->getCppcheckAttribute(CppcheckAttributesType::LOW, low);
7164-
bool isHigh = arg.nameToken()->getCppcheckAttribute(CppcheckAttributesType::HIGH, high);
7163+
bool isLow = arg.nameToken()->getCppcheckAttribute(Token::CppcheckAttributesType::LOW, low);
7164+
bool isHigh = arg.nameToken()->getCppcheckAttribute(Token::CppcheckAttributesType::HIGH, high);
71657165

71667166
if (!isLow && !isHigh && !all)
71677167
continue;

0 commit comments

Comments
 (0)