Tokenizer::simplifyTemplates: Broke out the functionality that extract a list of template instantiations

This commit is contained in:
Daniel Marjamäki 2011-02-12 20:17:58 +01:00
parent 25d6bfe3c4
commit 00bdf618f2
2 changed files with 43 additions and 29 deletions

View File

@ -2646,37 +2646,10 @@ std::list<Token *> Tokenizer::simplifyTemplatesGetTemplateDeclarations()
return templates;
}
void Tokenizer::simplifyTemplates()
std::list<Token *> Tokenizer::simplifyTemplatesGetTemplateInstantiations()
{
std::set<std::string> expandedtemplates(simplifyTemplatesExpandSpecialized());
// Locate templates..
std::list<Token *> templates(simplifyTemplatesGetTemplateDeclarations());
if (templates.empty())
{
removeTemplates(_tokens);
return;
}
// There are templates..
// Remove "typename" unless used in template arguments..
for (Token *tok = _tokens; tok; tok = tok->next())
{
if (tok->str() == "typename")
tok->deleteThis();
if (Token::simpleMatch(tok, "template <"))
{
while (tok && tok->str() != ">")
tok = tok->next();
if (!tok)
break;
}
}
// Locate possible instantiations of templates..
std::list<Token *> used;
for (Token *tok = _tokens; tok; tok = tok->next())
{
// template definition.. skip it
@ -2717,6 +2690,41 @@ void Tokenizer::simplifyTemplates()
}
}
return used;
}
void Tokenizer::simplifyTemplates()
{
std::set<std::string> expandedtemplates(simplifyTemplatesExpandSpecialized());
// Locate templates..
std::list<Token *> templates(simplifyTemplatesGetTemplateDeclarations());
if (templates.empty())
{
removeTemplates(_tokens);
return;
}
// There are templates..
// Remove "typename" unless used in template arguments..
for (Token *tok = _tokens; tok; tok = tok->next())
{
if (tok->str() == "typename")
tok->deleteThis();
if (Token::simpleMatch(tok, "template <"))
{
while (tok && tok->str() != ">")
tok = tok->next();
if (!tok)
break;
}
}
// Locate possible instantiations of templates..
std::list<Token *> used(simplifyTemplatesGetTemplateInstantiations());
// No template instantiations? Then remove all templates.
if (used.empty())
{

View File

@ -409,6 +409,12 @@ public:
*/
std::list<Token *> simplifyTemplatesGetTemplateDeclarations();
/**
* Get template instantiations
* @return list of template instantiations
*/
std::list<Token *> simplifyTemplatesGetTemplateInstantiations();
/**
* Used after simplifyTemplates to perform a little cleanup.
* Sometimes the simplifyTemplates isn't fully successful and then