Fixed #1272 (links in typedef not handled correctly)

This commit is contained in:
Daniel Marjamäki 2010-01-16 19:42:37 +01:00
parent 999176396b
commit fbefb8df34
2 changed files with 24 additions and 6 deletions

View File

@ -633,23 +633,23 @@ void Tokenizer::simplifyTypedef()
{ {
tok2->str(start->str()); tok2->str(start->str());
Token * nextToken; Token * nextToken;
std::list<Token *> links; std::stack<Token *> links;
for (nextToken = start->next(); nextToken != end->next(); nextToken = nextToken->next()) for (nextToken = start->next(); nextToken != end->next(); nextToken = nextToken->next())
{ {
tok2->insertToken(nextToken->strAt(0)); tok2->insertToken(nextToken->strAt(0));
tok2 = tok2->next(); tok2 = tok2->next();
// Check for links and fix them up // Check for links and fix them up
if (tok2->str() == "(") if (tok2->str() == "(" || tok2->str() == "[")
links.push_back(tok2); links.push(tok2);
if (tok2->str() == ")") if (tok2->str() == ")" || tok2->str() == "]")
{ {
Token * link = links.back(); Token * link = links.top();
tok2->link(link); tok2->link(link);
link->link(tok2); link->link(tok2);
links.pop_back(); links.pop();
} }
} }
} }

View File

@ -152,6 +152,7 @@ private:
TEST_CASE(simplifyTypedef15); TEST_CASE(simplifyTypedef15);
TEST_CASE(simplifyTypedef16); TEST_CASE(simplifyTypedef16);
TEST_CASE(simplifyTypedef17); TEST_CASE(simplifyTypedef17);
TEST_CASE(simplifyTypedef18); // typedef vector<int[4]> a;
TEST_CASE(reverseArraySyntax) TEST_CASE(reverseArraySyntax)
TEST_CASE(simplify_numeric_condition) TEST_CASE(simplify_numeric_condition)
@ -2537,6 +2538,23 @@ private:
ASSERT_EQUALS(expected, tok(code, false)); ASSERT_EQUALS(expected, tok(code, false));
} }
void simplifyTypedef18()
{
const char code[] = "typedef vector<int[4]> a;\n"
"a b;\n";
Tokenizer tokenizer;
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
// Clear the error buffer..
errout.str("");
tokenizer.simplifyTokenList();
ASSERT_EQUALS(true, tokenizer.validate());
}
void reverseArraySyntax() void reverseArraySyntax()
{ {
ASSERT_EQUALS("a [ 13 ]", tok("13[a]")); ASSERT_EQUALS("a [ 13 ]", tok("13[a]"));