Token::index(): Created Token member that indicates the Token position in the token list. It can be used to quickly check if tok1 precedes tok2.

This commit is contained in:
Daniel Marjamäki 2019-06-21 22:16:23 +02:00
parent d636a83f8b
commit beea7fa8d2
4 changed files with 22 additions and 3 deletions

View File

@ -224,7 +224,7 @@ bool precedes(const Token * tok1, const Token * tok2)
return false;
if (!tok2)
return false;
return tok1->progressValue() < tok2->progressValue();
return tok1->index() < tok2->index();
}
static bool isAliased(const Token * startTok, const Token * endTok, unsigned int varid)

View File

@ -1742,6 +1742,13 @@ void Token::assignProgressValues(Token *tok)
tok2->mImpl->mProgressValue = count++ * 100 / total_count;
}
void Token::assignIndexes()
{
unsigned int index = (mPrevious ? mPrevious->mImpl->mIndex : 0) + 1;
for (Token *tok = this; tok; tok = tok->next())
tok->mImpl->mIndex = index++;
}
void Token::setValueType(ValueType *vt)
{
if (vt != mImpl->mValueType) {

View File

@ -76,6 +76,11 @@ struct TokenImpl {
*/
unsigned int mProgressValue;
/**
* Token index. Position in token list
*/
unsigned int mIndex;
// original name like size_t
std::string* mOriginalName;
@ -103,6 +108,7 @@ struct TokenImpl {
, mScope(nullptr)
, mFunction(nullptr) // Initialize whole union
, mProgressValue(0)
, mIndex(0)
, mOriginalName(nullptr)
, mValueType(nullptr)
, mValues(nullptr)
@ -853,7 +859,7 @@ public:
*/
static void move(Token *srcStart, Token *srcEnd, Token *newLocation);
/** Get progressValue */
/** Get progressValue (0 - 100) */
unsigned int progressValue() const {
return mImpl->mProgressValue;
}
@ -987,6 +993,12 @@ public:
mImpl->mValues->remove_if(pred);
}
unsigned int index() const {
return mImpl->mIndex;
}
void assignIndexes();
private:
void next(Token *nextToken) {

View File

@ -4522,7 +4522,7 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
validate();
Token::assignProgressValues(list.front());
list.front()->assignIndexes();
return true;
}