From 49430afabe9b04826ebca3594a337e0204c40ae5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 25 Apr 2009 16:55:00 +0200 Subject: [PATCH] varid: Set variable id for stl containers and iterators --- src/tokenize.cpp | 15 +++++++++++++++ test/testtokenize.cpp | 21 +++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/tokenize.cpp b/src/tokenize.cpp index d0522df68..fa01f33b9 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -631,6 +631,21 @@ void Tokenizer::setVarId() if (Token::simpleMatch(tok, "std ::")) tok = tok->tokAt(2); + // Skip template arguments.. + if (Token::Match(tok, "%type% <")) + { + Token *tok2 = tok->tokAt(2); + while (tok2 && (tok2->isName() || tok2->str() == "*")) + tok2 = tok2->next(); + + if (Token::Match(tok2, "> %var%")) + tok = tok2; + else if (Token::Match(tok2, "> :: %var%")) + tok = tok2->next(); + else + continue; // Not code that I understand / not a variable declaration + } + // Determine name of declared variable.. const char *varname = 0; Token *tok2 = tok->tokAt(1); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 80b8984e5..6a114b66d 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -107,6 +107,7 @@ private: TEST_CASE(varidReturn); TEST_CASE(varid8); TEST_CASE(varid9); + TEST_CASE(varidStl); TEST_CASE(file1); TEST_CASE(file2); @@ -1049,6 +1050,26 @@ private: ASSERT_EQUALS(expected, actual); } + void varidStl() + { + const std::string code("list ints;\n" + "list::iterator it;\n"); + + // tokenize.. + Tokenizer tokenizer; + std::istringstream istr(code); + tokenizer.tokenize(istr, "test.cpp"); + tokenizer.setVarId(); + + // result.. + const std::string actual(tokenizer.tokens()->stringifyList(true)); + const std::string expected("\n\n##file 0\n" + "1: list < int > ints@1 ;\n" + "2: list < int > :: iterator it@2 ;\n"); + + ASSERT_EQUALS(expected, actual); + } +