Tokenizer: Added a simple validation function that we can use during debugging

This commit is contained in:
Daniel Marjamäki 2009-09-13 15:35:37 +02:00
parent 62bdf032ac
commit e3119235e0
2 changed files with 39 additions and 0 deletions

View File

@ -3913,3 +3913,35 @@ void Tokenizer::simplifyComma()
} }
} }
bool Tokenizer::validate() const
{
std::stack<const Token *> linktok;
for (const Token *tok = tokens(); tok; tok = tok->next())
{
if (Token::Match(tok, "[{(]"))
{
assert(tok->link() != 0);
linktok.push(tok);
continue;
}
else if (Token::Match(tok, "[})]"))
{
assert(tok->link() != 0);
assert(linktok.empty() == false);
assert(tok->link() == linktok.top());
assert(tok == tok->link()->link());
linktok.pop();
continue;
}
assert(tok->link() == 0);
}
assert(linktok.empty());
return true;
}

View File

@ -305,6 +305,13 @@ private:
/** Disable assignments.. */ /** Disable assignments.. */
Tokenizer(const Tokenizer &); Tokenizer(const Tokenizer &);
/**
* assert that tokens are ok - used during debugging for example
* to catch problems in simplifyTokenList.
* @return always true.
*/
bool validate() const;
/** Disable assignment operator */ /** Disable assignment operator */
void operator=(const Tokenizer &); void operator=(const Tokenizer &);