From 27c37896a03725b4d8c51609ce304699de0db5ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 15 Apr 2012 14:19:17 +0200 Subject: [PATCH] Tokenizer::setVarIdNew : use new setVarId function in TestTokenizer::varidReturn2. --- lib/tokenize.cpp | 21 +++++++++++++++++---- test/testtokenize.cpp | 2 +- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 045b129ac..825752e1e 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2863,13 +2863,20 @@ void Tokenizer::setVarIdNew() std::map variableId; std::map > structMembers; std::stack< std::map > scopeInfo; + std::stack executableScope; + executableScope.push(false); for (Token *tok = _tokens; tok; tok = tok->next()) { // scope info to handle shadow variables.. if (tok->str() == "(" && Token::simpleMatch(tok->link(), ") {")) { scopeInfo.push(variableId); - } else if (tok->str() == "{" && !Token::simpleMatch(tok->previous(), ")")) { - scopeInfo.push(variableId); + } else if (tok->str() == "{") { + if (Token::simpleMatch(tok->previous(), ")")) { + executableScope.push(true); + } else { + executableScope.push(executableScope.top()); + scopeInfo.push(variableId); + } } else if (tok->str() == "}") { if (scopeInfo.empty()) { variableId.clear(); @@ -2877,9 +2884,15 @@ void Tokenizer::setVarIdNew() variableId.swap(scopeInfo.top()); scopeInfo.pop(); } + + executableScope.pop(); + if (executableScope.empty()) { // should not possibly happen + executableScope.push(false); + } } - if (tok == _tokens || Token::Match(tok, "[;{}(,]")) { + if (tok == _tokens || Token::Match(tok, "[;{},]") || + (tok->str()=="(" && (!executableScope.top() || Token::simpleMatch(tok->link(), ") {")))) { // locate the variable name.. const Token *tok2 = (tok == _tokens) ? tok : tok->next(); if (!tok2) @@ -2896,7 +2909,7 @@ void Tokenizer::setVarIdNew() tok = tok2->previous(); } - if (decl && Token::Match(tok2->previous(), "%type% ( !!)")) { + else if (decl && Token::Match(tok2->previous(), "%type% ( !!)")) { const Token *tok3 = tok2->next(); if (!setVarIdParseDeclaration(&tok3,variableId)) { variableId[tok2->previous()->str()] = ++_varId; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index b435779b3..43ac86217 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -2712,7 +2712,7 @@ private: "{\n" " unsigned long mask = (1UL << size_) - 1;\n" " return (abits_val_ & mask);\n" - "}\n"); + "}\n", false, "test.c"); const std::string expected("\n\n##file 0\n" "1: void foo ( )\n"