Fixed createLinks2() on this code: nvwa<(x > y)>
This commit is contained in:
parent
a748678636
commit
d44f10fc01
|
@ -2981,8 +2981,7 @@ void Tokenizer::createLinks2()
|
||||||
if (isC())
|
if (isC())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std::stack<const Token*> type;
|
std::stack<Token*> type;
|
||||||
std::stack<Token*> links;
|
|
||||||
for (Token *token = list.front(); token; token = token->next()) {
|
for (Token *token = list.front(); token; token = token->next()) {
|
||||||
if (token->link()) {
|
if (token->link()) {
|
||||||
if (Token::Match(token, "{|[|("))
|
if (Token::Match(token, "{|[|("))
|
||||||
|
@ -2996,41 +2995,34 @@ void Tokenizer::createLinks2()
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (token->str() == ";")
|
else if (token->str() == ";")
|
||||||
while (!links.empty())
|
while (!type.empty() && type.top()->str() == "<")
|
||||||
links.pop();
|
type.pop();
|
||||||
else if (token->str() == "<" && token->previous() && token->previous()->isName() && !token->previous()->varId()) {
|
else if (token->str() == "<" && token->previous() && token->previous()->isName() && !token->previous()->varId())
|
||||||
type.push(token);
|
type.push(token);
|
||||||
links.push(token);
|
else if (token->str() == ">" || token->str() == ">>") {
|
||||||
} else if (token->str() == ">" || token->str() == ">>") {
|
if (type.empty() || type.top()->str() != "<") // < and > don't match.
|
||||||
if (links.empty()) // < and > don't match.
|
|
||||||
continue;
|
continue;
|
||||||
if (token->next() && !token->next()->isName() && !Token::Match(token->next(), ">|&|*|::|,|(|)"))
|
if (token->next() && !token->next()->isName() && !Token::Match(token->next(), ">|&|*|::|,|(|)"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Check type of open link
|
// Check type of open link
|
||||||
if (type.empty() || type.top()->str() != "<" || (token->str() == ">>" && type.size() < 2)) {
|
if (type.empty() || type.top()->str() != "<" || (token->str() == ">>" && type.size() < 2)) {
|
||||||
if (!links.empty())
|
|
||||||
links.pop();
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const Token* top = type.top();
|
|
||||||
|
Token* top = type.top();
|
||||||
type.pop();
|
type.pop();
|
||||||
if (token->str() == ">>" && type.top()->str() != "<") {
|
if (token->str() == ">>" && type.top()->str() != "<") {
|
||||||
type.push(top);
|
type.push(top);
|
||||||
if (!links.empty())
|
|
||||||
links.pop();
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (token->str() == ">>") { // C++11 right angle bracket
|
if (token->str() == ">>") { // C++11 right angle bracket
|
||||||
if (links.size() < 2)
|
|
||||||
continue;
|
|
||||||
token->str(">");
|
token->str(">");
|
||||||
token->insertToken(">");
|
token->insertToken(">");
|
||||||
}
|
}
|
||||||
|
|
||||||
Token::createMutualLinks(links.top(), token);
|
Token::createMutualLinks(top, token);
|
||||||
links.pop();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5506,6 +5506,24 @@ private:
|
||||||
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
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() {
|
void removeExceptionSpecification1() {
|
||||||
|
|
Loading…
Reference in New Issue