From 4aef89c31188058877be8f923613efadaa10c273 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 16 Feb 2009 17:41:33 +0000 Subject: [PATCH] tokenizer: fixed issues related to variable ids * use setVarId in simplifyTokenList * make sure function parameters and variables declared in for example for loops get variable ids --- src/tokenize.cpp | 15 ++++++++++----- test/testtokenize.cpp | 3 +-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/tokenize.cpp b/src/tokenize.cpp index 55ce59646..fcc6e8a05 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -541,7 +541,13 @@ void Tokenizer::setVarId() else if (tok2->str() == "(") ++parlevel; else if (tok2->str() == ")") - --parlevel; + { + // Is this a function parameter or a variable declared in for example a for loop? + if (parlevel==0 && indentlevel==0 && Token::Match(tok2, ") const| {")) + ; + else + --parlevel; + } else if (parlevel < 0 && tok2->str() == ";") break; dot = bool(tok2->str() == "."); @@ -922,8 +928,6 @@ void Tokenizer::simplifyTokenList() if (Token::Match(next, "* ( %var% + %num% )")) { - unsigned int varid = tok->tokAt(3)->varId(); - const char *str[4] = {"var", "[", "num", "]"}; str[0] = tok->strAt(3); str[2] = tok->strAt(5); @@ -932,8 +936,6 @@ void Tokenizer::simplifyTokenList() { tok = tok->next(); tok->str(str[i]); - if (i == 0) - tok->varId(varid); } tok->deleteNext(); @@ -1052,6 +1054,9 @@ void Tokenizer::simplifyTokenList() } } + // In case variable declarations have been updated... + setVarId(); + // Replace NULL with 0.. for (Token *tok = _tokens; tok; tok = tok->next()) { diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index c93575c99..64971df8d 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -94,7 +94,7 @@ private: TEST_CASE(varid2); TEST_CASE(varid3); TEST_CASE(varid4); - // TODO TEST_CASE(varid5); // There is currently a problem for "int a,b;" => "int a; int b;" + TEST_CASE(varid5); TEST_CASE(file1); TEST_CASE(file2); @@ -745,7 +745,6 @@ private: Tokenizer tokenizer; std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); - tokenizer.setVarId(); tokenizer.simplifyTokenList(); // result..