template simplifier: stop running passes when nothing was simplified. (#1914)
This commit is contained in:
parent
175070ca50
commit
46b543ba27
|
@ -197,7 +197,8 @@ bool TemplateSimplifier::TokenAndName::isAliasToken(const Token *tok) const
|
||||||
}
|
}
|
||||||
|
|
||||||
TemplateSimplifier::TemplateSimplifier(Tokenizer *tokenizer)
|
TemplateSimplifier::TemplateSimplifier(Tokenizer *tokenizer)
|
||||||
: mTokenizer(tokenizer), mTokenList(tokenizer->list), mSettings(tokenizer->mSettings), mErrorLogger(tokenizer->mErrorLogger)
|
: mTokenizer(tokenizer), mTokenList(tokenizer->list), mSettings(tokenizer->mSettings),
|
||||||
|
mErrorLogger(tokenizer->mErrorLogger), mChanged(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1222,6 +1223,8 @@ void TemplateSimplifier::simplifyTemplateAliases()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mChanged = true;
|
||||||
|
|
||||||
// copy template-id from declaration to after instantiation
|
// copy template-id from declaration to after instantiation
|
||||||
Token * dst = aliasUsage.token->next()->findClosingBracket();
|
Token * dst = aliasUsage.token->next()->findClosingBracket();
|
||||||
Token * end = TokenList::copyTokens(dst, aliasDeclaration.aliasStartToken(), aliasDeclaration.aliasEndToken()->previous(), false)->next();
|
Token * end = TokenList::copyTokens(dst, aliasDeclaration.aliasStartToken(), aliasDeclaration.aliasEndToken()->previous(), false)->next();
|
||||||
|
@ -2770,6 +2773,7 @@ bool TemplateSimplifier::simplifyTemplateInstantiations(
|
||||||
if (expandedtemplates.insert(newFullName).second) {
|
if (expandedtemplates.insert(newFullName).second) {
|
||||||
expandTemplate(templateDeclaration, instantiation, typeParametersInDeclaration, newName, !specialized && !isVar);
|
expandTemplate(templateDeclaration, instantiation, typeParametersInDeclaration, newName, !specialized && !isVar);
|
||||||
instantiated = true;
|
instantiated = true;
|
||||||
|
mChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace all these template usages..
|
// Replace all these template usages..
|
||||||
|
@ -2835,6 +2839,7 @@ bool TemplateSimplifier::simplifyTemplateInstantiations(
|
||||||
if (expandedtemplates.insert(newFullName).second) {
|
if (expandedtemplates.insert(newFullName).second) {
|
||||||
expandTemplate(templateDeclaration, templateDeclaration, typeParametersInDeclaration, newName, !specialized && !isVar);
|
expandTemplate(templateDeclaration, templateDeclaration, typeParametersInDeclaration, newName, !specialized && !isVar);
|
||||||
instantiated = true;
|
instantiated = true;
|
||||||
|
mChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace all these template usages..
|
// Replace all these template usages..
|
||||||
|
@ -3289,20 +3294,19 @@ void TemplateSimplifier::simplifyTemplates(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: 4 is not the ideal number of loops.
|
unsigned int passCount = 0;
|
||||||
// We should loop until the number of declarations is 0 but we can't
|
const unsigned int passCountMax = 10;
|
||||||
// do that until we instantiate unintstantiated templates with their symbolic types.
|
for (; passCount < passCountMax; ++passCount) {
|
||||||
// That will allow the uninstantiated template code to be removed from the symbol database.
|
if (passCount) {
|
||||||
// Unfortunately the template simplifier doesn't handle namespaces properly so
|
|
||||||
// the uninstantiated template code in the symbol database can't be removed until #8768
|
|
||||||
// is fixed.
|
|
||||||
|
|
||||||
for (int i = 0; i < 4; ++i) {
|
|
||||||
if (i) {
|
|
||||||
// it may take more than one pass to simplify type aliases
|
// it may take more than one pass to simplify type aliases
|
||||||
|
bool usingChanged = false;
|
||||||
while (mTokenizer->simplifyUsing())
|
while (mTokenizer->simplifyUsing())
|
||||||
;
|
usingChanged = true;
|
||||||
|
|
||||||
|
if (!usingChanged && !mChanged)
|
||||||
|
break;
|
||||||
|
|
||||||
|
mChanged = usingChanged;
|
||||||
mTemplateDeclarations.clear();
|
mTemplateDeclarations.clear();
|
||||||
mTemplateForwardDeclarations.clear();
|
mTemplateForwardDeclarations.clear();
|
||||||
mTemplateForwardDeclarationsMap.clear();
|
mTemplateForwardDeclarationsMap.clear();
|
||||||
|
@ -3316,7 +3320,7 @@ void TemplateSimplifier::simplifyTemplates(
|
||||||
|
|
||||||
bool hasTemplates = getTemplateDeclarations();
|
bool hasTemplates = getTemplateDeclarations();
|
||||||
|
|
||||||
if (i == 0)
|
if (passCount == 0)
|
||||||
codeWithTemplates = hasTemplates;
|
codeWithTemplates = hasTemplates;
|
||||||
|
|
||||||
// Make sure there is something to simplify.
|
// Make sure there is something to simplify.
|
||||||
|
@ -3341,7 +3345,7 @@ void TemplateSimplifier::simplifyTemplates(
|
||||||
simplifyTemplateAliases();
|
simplifyTemplateAliases();
|
||||||
|
|
||||||
if (mSettings->debugtemplate)
|
if (mSettings->debugtemplate)
|
||||||
printOut("### Template Simplifier pass " + std::to_string(i + 1) + " ###");
|
printOut("### Template Simplifier pass " + std::to_string(passCount + 1) + " ###");
|
||||||
|
|
||||||
std::set<std::string> expandedtemplates;
|
std::set<std::string> expandedtemplates;
|
||||||
|
|
||||||
|
@ -3419,6 +3423,19 @@ void TemplateSimplifier::simplifyTemplates(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (passCount == passCountMax) {
|
||||||
|
if (mSettings->debugwarnings) {
|
||||||
|
const std::list<const Token*> locationList(1, mTokenList.front());
|
||||||
|
const ErrorLogger::ErrorMessage errmsg(locationList, &mTokenizer->list,
|
||||||
|
Severity::debug,
|
||||||
|
"debug",
|
||||||
|
"TemplateSimplifier: pass count limit hit before simplifications were finished.",
|
||||||
|
false);
|
||||||
|
if (mErrorLogger)
|
||||||
|
mErrorLogger->reportErr(errmsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TemplateSimplifier::syntaxError(const Token *tok)
|
void TemplateSimplifier::syntaxError(const Token *tok)
|
||||||
|
|
|
@ -460,6 +460,7 @@ private:
|
||||||
TokenList &mTokenList;
|
TokenList &mTokenList;
|
||||||
const Settings *mSettings;
|
const Settings *mSettings;
|
||||||
ErrorLogger *mErrorLogger;
|
ErrorLogger *mErrorLogger;
|
||||||
|
bool mChanged;
|
||||||
|
|
||||||
std::list<TokenAndName> mTemplateDeclarations;
|
std::list<TokenAndName> mTemplateDeclarations;
|
||||||
std::list<TokenAndName> mTemplateForwardDeclarations;
|
std::list<TokenAndName> mTemplateForwardDeclarations;
|
||||||
|
|
Loading…
Reference in New Issue