Tokenizer::simplifyTemplates: Broke out the functionality that instantiates a template
This commit is contained in:
parent
9021f0f180
commit
4d1aae5859
112
lib/tokenize.cpp
112
lib/tokenize.cpp
|
@ -2791,56 +2791,14 @@ void Tokenizer::simplifyTemplatesUseDefaultArgumentValues(const std::list<Token
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tokenizer::simplifyTemplates()
|
void Tokenizer::simplifyTemplatesInstantiate(std::list<Token *> &used,
|
||||||
|
const Token *tok,
|
||||||
|
std::set<std::string> &expandedtemplates)
|
||||||
{
|
{
|
||||||
std::set<std::string> expandedtemplates(simplifyTemplatesExpandSpecialized());
|
// this variable is not used at the moment. the intention was to
|
||||||
|
// allow continous instantiations until all templates has been expanded
|
||||||
// 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())
|
|
||||||
{
|
|
||||||
removeTemplates(_tokens);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Template arguments with default values
|
|
||||||
simplifyTemplatesUseDefaultArgumentValues(templates, used);
|
|
||||||
|
|
||||||
// expand templates
|
|
||||||
bool done = false;
|
bool done = false;
|
||||||
//while (!done)
|
|
||||||
{
|
|
||||||
done = true;
|
|
||||||
for (std::list<Token *>::iterator iter1 = templates.begin(); iter1 != templates.end(); ++iter1)
|
|
||||||
{
|
|
||||||
Token *tok = *iter1;
|
|
||||||
std::vector<const Token *> type;
|
std::vector<const Token *> type;
|
||||||
for (tok = tok->tokAt(2); tok && tok->str() != ">"; tok = tok->next())
|
for (tok = tok->tokAt(2); tok && tok->str() != ">"; tok = tok->next())
|
||||||
{
|
{
|
||||||
|
@ -2849,7 +2807,7 @@ void Tokenizer::simplifyTemplates()
|
||||||
}
|
}
|
||||||
// bail out if the end of the file was reached
|
// bail out if the end of the file was reached
|
||||||
if (!tok)
|
if (!tok)
|
||||||
break;
|
return;
|
||||||
|
|
||||||
// get the position of the template name
|
// get the position of the template name
|
||||||
unsigned char namepos = 0;
|
unsigned char namepos = 0;
|
||||||
|
@ -2880,7 +2838,7 @@ void Tokenizer::simplifyTemplates()
|
||||||
else
|
else
|
||||||
Check::reportError(errmsg);
|
Check::reportError(errmsg);
|
||||||
}
|
}
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
if ((tok->tokAt(namepos)->str() == "*" || tok->tokAt(namepos)->str() == "&"))
|
if ((tok->tokAt(namepos)->str() == "*" || tok->tokAt(namepos)->str() == "&"))
|
||||||
++namepos;
|
++namepos;
|
||||||
|
@ -2904,7 +2862,7 @@ void Tokenizer::simplifyTemplates()
|
||||||
std::string::size_type sz1 = used.size();
|
std::string::size_type sz1 = used.size();
|
||||||
unsigned int recursiveCount = 0;
|
unsigned int recursiveCount = 0;
|
||||||
|
|
||||||
for (std::list<Token *>::iterator iter2 = used.begin(); iter2 != used.end(); ++iter2)
|
for (std::list<Token *>::const_iterator iter2 = used.begin(); iter2 != used.end(); ++iter2)
|
||||||
{
|
{
|
||||||
// If the size of "used" has changed, simplify calculations
|
// If the size of "used" has changed, simplify calculations
|
||||||
if (sz1 != used.size())
|
if (sz1 != used.size())
|
||||||
|
@ -3151,6 +3109,58 @@ void Tokenizer::simplifyTemplates()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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())
|
||||||
|
{
|
||||||
|
removeTemplates(_tokens);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Template arguments with default values
|
||||||
|
simplifyTemplatesUseDefaultArgumentValues(templates, used);
|
||||||
|
|
||||||
|
// expand templates
|
||||||
|
bool done = false;
|
||||||
|
//while (!done)
|
||||||
|
{
|
||||||
|
done = true;
|
||||||
|
for (std::list<Token *>::iterator iter1 = templates.begin(); iter1 != templates.end(); ++iter1)
|
||||||
|
{
|
||||||
|
simplifyTemplatesInstantiate(used, *iter1, expandedtemplates);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
removeTemplates(_tokens);
|
removeTemplates(_tokens);
|
||||||
|
|
|
@ -423,6 +423,13 @@ public:
|
||||||
void simplifyTemplatesUseDefaultArgumentValues(const std::list<Token *> &templates,
|
void simplifyTemplatesUseDefaultArgumentValues(const std::list<Token *> &templates,
|
||||||
const std::list<Token *> &instantiations);
|
const std::list<Token *> &instantiations);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simplify templates : expand all instantiatiations for a template
|
||||||
|
*/
|
||||||
|
void simplifyTemplatesInstantiate(std::list<Token *> &used,
|
||||||
|
const Token *tok,
|
||||||
|
std::set<std::string> &expandedtemplates);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used after simplifyTemplates to perform a little cleanup.
|
* Used after simplifyTemplates to perform a little cleanup.
|
||||||
* Sometimes the simplifyTemplates isn't fully successful and then
|
* Sometimes the simplifyTemplates isn't fully successful and then
|
||||||
|
|
Loading…
Reference in New Issue