From e3119235e00f91a7bc69651287147fc697f39e58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 13 Sep 2009 15:35:37 +0200 Subject: [PATCH] Tokenizer: Added a simple validation function that we can use during debugging --- src/tokenize.cpp | 32 ++++++++++++++++++++++++++++++++ src/tokenize.h | 7 +++++++ 2 files changed, 39 insertions(+) diff --git a/src/tokenize.cpp b/src/tokenize.cpp index 3e3a66e24..b58692026 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -3913,3 +3913,35 @@ void Tokenizer::simplifyComma() } } + + +bool Tokenizer::validate() const +{ + std::stack 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; +} diff --git a/src/tokenize.h b/src/tokenize.h index 0fb66852f..0e87f6a96 100644 --- a/src/tokenize.h +++ b/src/tokenize.h @@ -305,6 +305,13 @@ private: /** Disable assignments.. */ 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 */ void operator=(const Tokenizer &);