variable id: handling 'return' and 'else' better

This commit is contained in:
Daniel Marjamäki 2009-02-28 20:21:48 +00:00
parent 045477e6ac
commit c3bbd603c0
2 changed files with 30 additions and 0 deletions

View File

@ -519,6 +519,9 @@ void Tokenizer::setVarId()
if (Token::Match(tok, "[;{}(] %any%")) if (Token::Match(tok, "[;{}(] %any%"))
tok = tok->next(); tok = tok->next();
if (Token::Match(tok, "else|return"))
continue;
if (!(firstMatch = Token::Match(tok, "%type% *| %var%")) if (!(firstMatch = Token::Match(tok, "%type% *| %var%"))
&& !Token::Match(tok, "%type% %type% *| %var%")) && !Token::Match(tok, "%type% %type% *| %var%"))
continue; continue;

View File

@ -99,6 +99,7 @@ private:
TEST_CASE(varid4); TEST_CASE(varid4);
TEST_CASE(varid5); TEST_CASE(varid5);
// TODO TEST_CASE(varid6); // Function parameters aren't handled well yet // TODO TEST_CASE(varid6); // Function parameters aren't handled well yet
TEST_CASE(varidReturn);
TEST_CASE(file1); TEST_CASE(file1);
TEST_CASE(file2); TEST_CASE(file2);
@ -876,6 +877,32 @@ private:
ASSERT_EQUALS(expected, actual); ASSERT_EQUALS(expected, actual);
} }
void varidReturn()
{
const std::string code("int f()\n"
"{\n"
" int a;\n"
" return a;\n"
"}\n");
// tokenize..
Tokenizer tokenizer;
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList();
// result..
const std::string actual(tokenizer.tokens()->stringifyList(true));
const std::string expected("\n"
"1: int f ( )\n"
"2: {\n"
"3: int a@1 ;\n"
"4: return a@1 ;\n"
"5: }\n");
ASSERT_EQUALS(expected, actual);
}