Code simplification now that ">>" is turned into "> >" when it closes template argument lists.
This commit is contained in:
parent
40769c9a59
commit
32a7a178e8
|
@ -86,7 +86,7 @@ void TemplateSimplifier::cleanupAfterSimplify(Token *tokens)
|
||||||
end = end->link()->next();
|
end = end->link()->next();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!Token::Match(end, "%name%|::|<|>|>>|,")) {
|
if (!Token::Match(end, "%name%|::|<|>|,")) {
|
||||||
end = nullptr;
|
end = nullptr;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -564,10 +564,10 @@ void TemplateSimplifier::useDefaultArgumentValues(const std::list<Token *> &temp
|
||||||
++templateParmDepth;
|
++templateParmDepth;
|
||||||
|
|
||||||
// end of template parameters?
|
// end of template parameters?
|
||||||
if (Token::Match(tok, ">|>>")) {
|
if (tok->str() == ">") {
|
||||||
if (Token::Match(tok, ">|>> class|struct %name%"))
|
if (Token::Match(tok, "> class|struct %name%"))
|
||||||
classname = tok->strAt(2);
|
classname = tok->strAt(2);
|
||||||
templateParmDepth -= (1 + (tok->str() == ">>"));
|
--templateParmDepth;
|
||||||
if (0 == templateParmDepth)
|
if (0 == templateParmDepth)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -649,11 +649,7 @@ void TemplateSimplifier::useDefaultArgumentValues(const std::list<Token *> &temp
|
||||||
++indentlevel;
|
++indentlevel;
|
||||||
} else if (indentlevel > 0 && tok2->str() == ">")
|
} else if (indentlevel > 0 && tok2->str() == ">")
|
||||||
--indentlevel;
|
--indentlevel;
|
||||||
else if (indentlevel > 0 && tok2->str() == ">>") {
|
else if (indentlevel == 0 && Token::Match(tok2, ",|>"))
|
||||||
indentlevel -= 2;
|
|
||||||
if (indentlevel < 0)
|
|
||||||
tok2->str(">");
|
|
||||||
} else if (indentlevel == 0 && Token::Match(tok2, ",|>|>>"))
|
|
||||||
break;
|
break;
|
||||||
if (indentlevel < 0)
|
if (indentlevel < 0)
|
||||||
break;
|
break;
|
||||||
|
@ -680,13 +676,11 @@ bool TemplateSimplifier::instantiateMatch(const Token *instance, const std::stri
|
||||||
if (patternAfter) {
|
if (patternAfter) {
|
||||||
const Token *tok = instance;
|
const Token *tok = instance;
|
||||||
unsigned int indentlevel = 0;
|
unsigned int indentlevel = 0;
|
||||||
for (tok = instance; tok && (tok->str() != ">" || indentlevel > 0) && (tok->str() != ">>" || indentlevel > 1); tok = tok->next()) {
|
for (tok = instance; tok && (tok->str() != ">" || indentlevel > 0); tok = tok->next()) {
|
||||||
if (Token::Match(tok, "[<,] %name% <") && templateParameters(tok->tokAt(2)) > 0)
|
if (Token::Match(tok, "[<,] %name% <") && templateParameters(tok->tokAt(2)) > 0)
|
||||||
++indentlevel;
|
++indentlevel;
|
||||||
if (indentlevel > 0 && tok->str() == ">")
|
if (indentlevel > 0 && tok->str() == ">")
|
||||||
--indentlevel;
|
--indentlevel;
|
||||||
if (indentlevel > 0 && tok->str() == ">>")
|
|
||||||
indentlevel -= (indentlevel > 1) ? 2 : 1;
|
|
||||||
}
|
}
|
||||||
if (!tok || !Token::Match(tok->next(), patternAfter))
|
if (!tok || !Token::Match(tok->next(), patternAfter))
|
||||||
return false;
|
return false;
|
||||||
|
@ -779,17 +773,12 @@ void TemplateSimplifier::expandTemplate(
|
||||||
if (itype < typeParametersInDeclaration.size()) {
|
if (itype < typeParametersInDeclaration.size()) {
|
||||||
unsigned int typeindentlevel = 0;
|
unsigned int typeindentlevel = 0;
|
||||||
for (const Token *typetok = typesUsedInTemplateInstantiation[itype];
|
for (const Token *typetok = typesUsedInTemplateInstantiation[itype];
|
||||||
typetok && (typeindentlevel>0 || !Token::Match(typetok, ",|>|>>"));
|
typetok && (typeindentlevel>0 || !Token::Match(typetok, ",|>"));
|
||||||
typetok = typetok->next()) {
|
typetok = typetok->next()) {
|
||||||
if (Token::Match(typetok, "%name% <") && templateParameters(typetok->next()) > 0)
|
if (Token::Match(typetok, "%name% <") && templateParameters(typetok->next()) > 0)
|
||||||
++typeindentlevel;
|
++typeindentlevel;
|
||||||
else if (typeindentlevel > 0 && typetok->str() == ">")
|
else if (typeindentlevel > 0 && typetok->str() == ">")
|
||||||
--typeindentlevel;
|
--typeindentlevel;
|
||||||
else if (typeindentlevel > 0 && typetok->str() == ">>") {
|
|
||||||
if (typeindentlevel == 1)
|
|
||||||
break;
|
|
||||||
typeindentlevel -= 2;
|
|
||||||
}
|
|
||||||
tokenlist.addtoken(typetok, tok3->linenr(), tok3->fileIndex());
|
tokenlist.addtoken(typetok, tok3->linenr(), tok3->fileIndex());
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
|
@ -1260,15 +1249,7 @@ bool TemplateSimplifier::simplifyTemplateInstantiations(
|
||||||
++indentlevel;
|
++indentlevel;
|
||||||
else if (indentlevel > 0 && Token::Match(tok3, "> [,>]"))
|
else if (indentlevel > 0 && Token::Match(tok3, "> [,>]"))
|
||||||
--indentlevel;
|
--indentlevel;
|
||||||
else if (indentlevel > 0 && tok3->str() == ">>") {
|
templateMatchPattern += tok3->str();
|
||||||
if (indentlevel == 1) {
|
|
||||||
templateMatchPattern += '>';
|
|
||||||
typeForNewNameStr += '>';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
indentlevel -= 2;
|
|
||||||
}
|
|
||||||
templateMatchPattern += (tok3->str() == ">>") ? std::string("> >") : tok3->str();
|
|
||||||
templateMatchPattern += ' ';
|
templateMatchPattern += ' ';
|
||||||
if (indentlevel == 0 && Token::Match(tok3->previous(), "[<,]"))
|
if (indentlevel == 0 && Token::Match(tok3->previous(), "[<,]"))
|
||||||
typesUsedInTemplateInstantiation.push_back(tok3);
|
typesUsedInTemplateInstantiation.push_back(tok3);
|
||||||
|
|
|
@ -2368,7 +2368,7 @@ static bool setVarIdParseDeclaration(const Token **tok, const std::map<std::stri
|
||||||
} else if ((TemplateSimplifier::templateParameters(tok2) > 0) ||
|
} else if ((TemplateSimplifier::templateParameters(tok2) > 0) ||
|
||||||
Token::simpleMatch(tok2, "< >") /* Ticket #4764 */) {
|
Token::simpleMatch(tok2, "< >") /* Ticket #4764 */) {
|
||||||
tok2 = tok2->findClosingBracket();
|
tok2 = tok2->findClosingBracket();
|
||||||
if (!Token::Match(tok2, ">|>>"))
|
if (tok2->str() != ">")
|
||||||
break;
|
break;
|
||||||
singleNameCount = 1;
|
singleNameCount = 1;
|
||||||
} else if (Token::Match(tok2, "&|&&")) {
|
} else if (Token::Match(tok2, "&|&&")) {
|
||||||
|
@ -2964,14 +2964,10 @@ void Tokenizer::createLinks2()
|
||||||
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())
|
||||||
type.push(token);
|
type.push(token);
|
||||||
else if (Token::Match(token, ">|>>")) {
|
else if (token->str() == ">") {
|
||||||
if (type.empty() || type.top()->str() != "<") // < and > don't match.
|
if (type.empty() || type.top()->str() != "<") // < and > don't match.
|
||||||
continue;
|
continue;
|
||||||
if (token->next() && !Token::Match(token->next(), "%name%|>|>>|&|*|::|,|(|)|{|;|["))
|
if (token->next() && !Token::Match(token->next(), "%name%|>|&|*|::|,|(|)|{|;|["))
|
||||||
continue;
|
|
||||||
|
|
||||||
// Check type of open link
|
|
||||||
if (token->str() == ">>" && type.size() < 2)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// if > is followed by [ .. "new a<b>[" is expected
|
// if > is followed by [ .. "new a<b>[" is expected
|
||||||
|
@ -2987,15 +2983,6 @@ void Tokenizer::createLinks2()
|
||||||
|
|
||||||
Token* top = type.top();
|
Token* top = type.top();
|
||||||
type.pop();
|
type.pop();
|
||||||
if (token->str() == ">>" && type.top()->str() != "<") {
|
|
||||||
type.push(top);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (token->str() == ">>") { // C++11 right angle bracket
|
|
||||||
token->str(">");
|
|
||||||
token->insertToken(">");
|
|
||||||
}
|
|
||||||
|
|
||||||
Token::createMutualLinks(top, token);
|
Token::createMutualLinks(top, token);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue