Change approach for Tokenizer::createLinks2: assume that <> should be linked
This commit is contained in:
parent
e48d785ea4
commit
34cf62452e
|
@ -3792,10 +3792,6 @@ void Tokenizer::createLinks2()
|
||||||
const Token * templateToken = nullptr;
|
const Token * templateToken = nullptr;
|
||||||
bool isStruct = false;
|
bool isStruct = false;
|
||||||
|
|
||||||
std::set<std::string> usingNames;
|
|
||||||
std::map<std::string, bool> templateNames;
|
|
||||||
templateNames["template"] = true;
|
|
||||||
|
|
||||||
std::stack<Token*> type;
|
std::stack<Token*> type;
|
||||||
for (Token *token = list.front(); token; token = token->next()) {
|
for (Token *token = list.front(); token; token = token->next()) {
|
||||||
if (Token::Match(token, "%name%|> %name% [:<]"))
|
if (Token::Match(token, "%name%|> %name% [:<]"))
|
||||||
|
@ -3803,14 +3799,6 @@ void Tokenizer::createLinks2()
|
||||||
else if (Token::Match(token, "[;{}]"))
|
else if (Token::Match(token, "[;{}]"))
|
||||||
isStruct = false;
|
isStruct = false;
|
||||||
|
|
||||||
if (Token::Match(token, "using %name% ::")) {
|
|
||||||
const Token *tok2 = token->tokAt(3);
|
|
||||||
while (Token::Match(tok2, "%name% ::"))
|
|
||||||
tok2 = tok2->tokAt(2);
|
|
||||||
if (Token::Match(tok2, "%name% ;"))
|
|
||||||
usingNames.insert(tok2->str());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (token->link()) {
|
if (token->link()) {
|
||||||
if (Token::Match(token, "{|[|("))
|
if (Token::Match(token, "{|[|("))
|
||||||
type.push(token);
|
type.push(token);
|
||||||
|
@ -3860,32 +3848,6 @@ void Tokenizer::createLinks2()
|
||||||
while (!type.empty() && type.top()->str() == "<")
|
while (!type.empty() && type.top()->str() == "<")
|
||||||
type.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()) {
|
||||||
const bool isScoped = Token::simpleMatch(token->tokAt(-2), "::") ||
|
|
||||||
(Token::Match(token->tokAt(-2), "; %name% <") && usingNames.count(token->previous()->str()));
|
|
||||||
const bool isTemplateDecl = isScoped || Token::Match(token->tokAt(-2), "%name% %name% <");
|
|
||||||
const bool isTemplateArgPointerType = Token::Match(token, "< %type% * >");
|
|
||||||
if (!isTemplateDecl && !isTemplateArgPointerType) {
|
|
||||||
std::map<std::string, bool>::const_iterator it = templateNames.find(token->previous()->str());
|
|
||||||
if (it == templateNames.end()) {
|
|
||||||
const std::string &name = token->previous()->str();
|
|
||||||
bool isTemplateType = true;
|
|
||||||
for (const Token *tok2 = list.front(); tok2; tok2 = tok2->next()) {
|
|
||||||
if (!tok2->isName() || tok2->str() != name)
|
|
||||||
continue;
|
|
||||||
if (Token::Match(tok2->previous(), "class|struct"))
|
|
||||||
break;
|
|
||||||
if (!Token::Match(tok2->next(), "[<:({]")) {
|
|
||||||
isTemplateType = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
templateNames[name] = isTemplateType;
|
|
||||||
if (!isTemplateType)
|
|
||||||
continue;
|
|
||||||
} else if (!it->second) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
type.push(token);
|
type.push(token);
|
||||||
if (!templateToken && (token->previous()->str() == "template"))
|
if (!templateToken && (token->previous()->str() == "template"))
|
||||||
templateToken = token;
|
templateToken = token;
|
||||||
|
@ -3924,6 +3886,8 @@ void Tokenizer::createLinks2()
|
||||||
templateToken = nullptr;
|
templateToken = nullptr;
|
||||||
} else {
|
} else {
|
||||||
type.pop();
|
type.pop();
|
||||||
|
if (Token::Match(token, "> %name%") && Token::Match(top1->tokAt(-2), "%op% %name% <"))
|
||||||
|
continue;
|
||||||
Token::createMutualLinks(top1, token);
|
Token::createMutualLinks(top1, token);
|
||||||
if (top1 == templateToken)
|
if (top1 == templateToken)
|
||||||
templateToken = nullptr;
|
templateToken = nullptr;
|
||||||
|
|
Loading…
Reference in New Issue