From dd64637ff1478fbc822e340042a73c44014346d5 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Thu, 27 Aug 2009 23:33:42 +0700 Subject: [PATCH] Fixed #616 (Tokenizer: simplifyTemplates() should link() all inserted brackets) This also fixed #619. http://sourceforge.net/apps/trac/cppcheck/ticket/616 http://sourceforge.net/apps/trac/cppcheck/ticket/619 --- src/tokenize.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/tokenize.cpp b/src/tokenize.cpp index 0338d80f8..c540e70b4 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -34,6 +34,7 @@ #include #include #include +#include //--------------------------------------------------------------------------- @@ -654,6 +655,9 @@ void Tokenizer::simplifyTemplates() continue; int indentlevel = 0; + std::stack braces; // holds "{" tokens + std::stack brackets; // holds "(" tokens + for (; tok3; tok3 = tok3->next()) { if (tok3->str() == "{") @@ -668,6 +672,8 @@ void Tokenizer::simplifyTemplates() // if indentlevel ever becomes 0, cppcheck will write: // ### Error: Invalid number of character { addtoken("}", tok3->linenr(), tok3->fileIndex()); + Token::createMutualLinks(braces.top(), _tokensBack); + braces.pop(); break; } --indentlevel; @@ -689,7 +695,29 @@ void Tokenizer::simplifyTemplates() // copy else + { addtoken(tok3->str().c_str(), tok3->linenr(), tok3->fileIndex()); + + // link() newly tokens manually + if (tok3->str() == "{") + { + braces.push(_tokensBack); + } + else if (tok3->str() == "}") + { + Token::createMutualLinks(braces.top(), _tokensBack); + braces.pop(); + } + else if (tok3->str() == "(") + { + brackets.push(_tokensBack); + } + else if (tok3->str() == ")") + { + Token::createMutualLinks(brackets.top(), _tokensBack); + brackets.pop(); + } + } } } }