Fixed createLinks2() on this code: nvwa<(x > y)>

This commit is contained in:
PKEuS 2012-09-09 15:31:23 +02:00
parent a748678636
commit d44f10fc01
2 changed files with 27 additions and 17 deletions

View File

@ -2981,8 +2981,7 @@ void Tokenizer::createLinks2()
if (isC())
return;
std::stack<const Token*> type;
std::stack<Token*> links;
std::stack<Token*> type;
for (Token *token = list.front(); token; token = token->next()) {
if (token->link()) {
if (Token::Match(token, "{|[|("))
@ -2996,41 +2995,34 @@ void Tokenizer::createLinks2()
}
else if (token->str() == ";")
while (!links.empty())
links.pop();
else if (token->str() == "<" && token->previous() && token->previous()->isName() && !token->previous()->varId()) {
while (!type.empty() && type.top()->str() == "<")
type.pop();
else if (token->str() == "<" && token->previous() && token->previous()->isName() && !token->previous()->varId())
type.push(token);
links.push(token);
} else if (token->str() == ">" || token->str() == ">>") {
if (links.empty()) // < and > don't match.
else if (token->str() == ">" || token->str() == ">>") {
if (type.empty() || type.top()->str() != "<") // < and > don't match.
continue;
if (token->next() && !token->next()->isName() && !Token::Match(token->next(), ">|&|*|::|,|(|)"))
continue;
// Check type of open link
if (type.empty() || type.top()->str() != "<" || (token->str() == ">>" && type.size() < 2)) {
if (!links.empty())
links.pop();
continue;
}
const Token* top = type.top();
Token* top = type.top();
type.pop();
if (token->str() == ">>" && type.top()->str() != "<") {
type.push(top);
if (!links.empty())
links.pop();
continue;
}
if (token->str() == ">>") { // C++11 right angle bracket
if (links.size() < 2)
continue;
token->str(">");
token->insertToken(">");
}
Token::createMutualLinks(links.top(), token);
links.pop();
Token::createMutualLinks(top, token);
}
}
}

View File

@ -5506,6 +5506,24 @@ private:
ASSERT_EQUALS("", errout.str());
}
{
const char code[] = "void foo() {\n"
" nvwa<(x > y)> ERROR_nnn;\n"
"}";
errout.str("");
Settings settings;
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
const Token *tok = tokenizer.tokens();
// nvwa<(x > y)>
ASSERT_EQUALS((long long)tok->tokAt(12), (long long)tok->linkAt(6));
ASSERT_EQUALS((long long)tok->tokAt(6), (long long)tok->linkAt(12));
ASSERT_EQUALS("", errout.str());
}
}
void removeExceptionSpecification1() {