Refactoring: Rename variable used -> templateInstantiations

This commit is contained in:
Reijo Tomperi 2011-12-24 00:03:03 +02:00
parent dca03c3ce2
commit 00cbf02d84
2 changed files with 20 additions and 20 deletions

View File

@ -2967,7 +2967,7 @@ std::list<Token *> Tokenizer::simplifyTemplatesGetTemplateInstantiations()
void Tokenizer::simplifyTemplatesUseDefaultArgumentValues(const std::list<Token *> &templates, void Tokenizer::simplifyTemplatesUseDefaultArgumentValues(const std::list<Token *> &templates,
const std::list<Token *> &instantiations) const std::list<Token *> &templateInstantiations)
{ {
for (std::list<Token *>::const_iterator iter1 = templates.begin(); iter1 != templates.end(); ++iter1) { for (std::list<Token *>::const_iterator iter1 = templates.begin(); iter1 != templates.end(); ++iter1) {
// template parameters with default value has syntax such as: // template parameters with default value has syntax such as:
@ -3002,7 +3002,7 @@ void Tokenizer::simplifyTemplatesUseDefaultArgumentValues(const std::list<Token
continue; continue;
// iterate through all template instantiations // iterate through all template instantiations
for (std::list<Token *>::const_iterator iter2 = instantiations.begin(); iter2 != instantiations.end(); ++iter2) { for (std::list<Token *>::const_iterator iter2 = templateInstantiations.begin(); iter2 != templateInstantiations.end(); ++iter2) {
Token *tok = *iter2; Token *tok = *iter2;
if (!Token::Match(tok, (classname + " < %any%").c_str())) if (!Token::Match(tok, (classname + " < %any%").c_str()))
@ -3122,7 +3122,7 @@ void Tokenizer::simplifyTemplatesExpandTemplate(const Token *tok,
std::vector<const Token *> &type, std::vector<const Token *> &type,
const std::string &newName, const std::string &newName,
std::vector<const Token *> &types2, std::vector<const Token *> &types2,
std::list<Token *> &used) std::list<Token *> &templateInstantiations)
{ {
int _indentlevel = 0; int _indentlevel = 0;
int _parlevel = 0; int _parlevel = 0;
@ -3206,7 +3206,7 @@ void Tokenizer::simplifyTemplatesExpandTemplate(const Token *tok,
if (Token::Match(tok3, "%type% <")) { if (Token::Match(tok3, "%type% <")) {
//if (!Token::simpleMatch(tok3, (name + " <").c_str())) //if (!Token::simpleMatch(tok3, (name + " <").c_str()))
//done = false; //done = false;
used.push_back(_tokensBack); templateInstantiations.push_back(_tokensBack);
} }
// link() newly tokens manually // link() newly tokens manually
@ -3238,7 +3238,7 @@ void Tokenizer::simplifyTemplatesExpandTemplate(const Token *tok,
} }
void Tokenizer::simplifyTemplatesInstantiate(const Token *tok, void Tokenizer::simplifyTemplatesInstantiate(const Token *tok,
std::list<Token *> &used, std::list<Token *> &templateInstantiations,
std::set<std::string> &expandedtemplates) std::set<std::string> &expandedtemplates)
{ {
// this variable is not used at the moment. The intention was to // this variable is not used at the moment. The intention was to
@ -3266,13 +3266,13 @@ void Tokenizer::simplifyTemplatesInstantiate(const Token *tok,
const bool isfunc(tok->strAt(namepos + 1) == "("); const bool isfunc(tok->strAt(namepos + 1) == "(");
// locate template usage.. // locate template usage..
std::string::size_type sz1 = used.size(); std::string::size_type sz1 = templateInstantiations.size();
unsigned int recursiveCount = 0; unsigned int recursiveCount = 0;
for (std::list<Token *>::const_iterator iter2 = used.begin(); iter2 != used.end(); ++iter2) { for (std::list<Token *>::const_iterator iter2 = templateInstantiations.begin(); iter2 != templateInstantiations.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 != templateInstantiations.size()) {
sz1 = used.size(); sz1 = templateInstantiations.size();
simplifyCalculations(); simplifyCalculations();
++recursiveCount; ++recursiveCount;
if (recursiveCount > 100) { if (recursiveCount > 100) {
@ -3355,7 +3355,7 @@ void Tokenizer::simplifyTemplatesInstantiate(const Token *tok,
if (expandedtemplates.find(newName) == expandedtemplates.end()) { if (expandedtemplates.find(newName) == expandedtemplates.end()) {
expandedtemplates.insert(newName); expandedtemplates.insert(newName);
simplifyTemplatesExpandTemplate(tok,name,type,newName,types2,used); simplifyTemplatesExpandTemplate(tok,name,type,newName,types2,templateInstantiations);
} }
// Replace all these template usages.. // Replace all these template usages..
@ -3388,7 +3388,7 @@ void Tokenizer::simplifyTemplatesInstantiate(const Token *tok,
tok4->str(newName); tok4->str(newName);
for (Token *tok6 = tok4->next(); tok6 != tok5; tok6 = tok6->next()) { for (Token *tok6 = tok4->next(); tok6 != tok5; tok6 = tok6->next()) {
if (tok6->isName()) if (tok6->isName())
used.remove(tok6); templateInstantiations.remove(tok6);
} }
removeTokens.push_back(std::pair<Token*,Token*>(tok4, tok5->next())); removeTokens.push_back(std::pair<Token*,Token*>(tok4, tok5->next()));
} }
@ -3432,16 +3432,16 @@ void Tokenizer::simplifyTemplates()
} }
// Locate possible instantiations of templates.. // Locate possible instantiations of templates..
std::list<Token *> used(simplifyTemplatesGetTemplateInstantiations()); std::list<Token *> templateInstantiations(simplifyTemplatesGetTemplateInstantiations());
// No template instantiations? Then remove all templates. // No template instantiations? Then remove all templates.
if (used.empty()) { if (templateInstantiations.empty()) {
removeTemplates(_tokens); removeTemplates(_tokens);
return; return;
} }
// Template arguments with default values // Template arguments with default values
simplifyTemplatesUseDefaultArgumentValues(templates, used); simplifyTemplatesUseDefaultArgumentValues(templates, templateInstantiations);
// expand templates // expand templates
//bool done = false; //bool done = false;
@ -3449,7 +3449,7 @@ void Tokenizer::simplifyTemplates()
{ {
//done = true; //done = true;
for (std::list<Token *>::reverse_iterator iter1 = templates.rbegin(); iter1 != templates.rend(); ++iter1) { for (std::list<Token *>::reverse_iterator iter1 = templates.rbegin(); iter1 != templates.rend(); ++iter1) {
simplifyTemplatesInstantiate(*iter1, used, expandedtemplates); simplifyTemplatesInstantiate(*iter1, templateInstantiations, expandedtemplates);
} }
} }

View File

@ -473,20 +473,20 @@ public:
/** /**
* simplify template instantiations (use default argument values) * simplify template instantiations (use default argument values)
* @param templates list of template declarations * @param templates list of template declarations
* @param instantiations list of template instantiations * @param templateInstantiations list of template instantiations
*/ */
void simplifyTemplatesUseDefaultArgumentValues(const std::list<Token *> &templates, void simplifyTemplatesUseDefaultArgumentValues(const std::list<Token *> &templates,
const std::list<Token *> &instantiations); const std::list<Token *> &templateInstantiations);
/** /**
* Simplify templates : expand all instantiatiations for a template * Simplify templates : expand all instantiatiations for a template
* @todo It seems that inner templates should be instantiated recursively * @todo It seems that inner templates should be instantiated recursively
* @param tok token where the template declaration begins * @param tok token where the template declaration begins
* @param used a list of template usages (not necessarily just for this template) * @param templateInstantiations a list of template usages (not necessarily just for this template)
* @param expandedtemplates all templates that has been expanded so far. The full names are stored. * @param expandedtemplates all templates that has been expanded so far. The full names are stored.
*/ */
void simplifyTemplatesInstantiate(const Token *tok, void simplifyTemplatesInstantiate(const Token *tok,
std::list<Token *> &used, std::list<Token *> &templateInstantiations,
std::set<std::string> &expandedtemplates); std::set<std::string> &expandedtemplates);
void simplifyTemplatesExpandTemplate(const Token *tok, void simplifyTemplatesExpandTemplate(const Token *tok,
@ -494,7 +494,7 @@ public:
std::vector<const Token *> &type, std::vector<const Token *> &type,
const std::string &newName, const std::string &newName,
std::vector<const Token *> &types2, std::vector<const Token *> &types2,
std::list<Token *> &used); std::list<Token *> &templateInstantiations);
/** /**
* Match template declaration/instantiation * Match template declaration/instantiation