Refactoring lookups in TemplateSimplifier

This commit is contained in:
Daniel Marjamäki 2018-01-05 15:27:43 +01:00
parent a1cc44eb21
commit f74c19bbed
1 changed files with 31 additions and 17 deletions

View File

@ -31,6 +31,28 @@
#include <stack> #include <stack>
#include <utility> #include <utility>
namespace {
class FindToken {
public:
FindToken(const Token *t) : token(t) {}
bool operator()(const TemplateSimplifier::TokenAndName &t) const {
return t.token == token;
}
private:
const Token * const token;
};
class FindName {
public:
FindName(const std::string &s) : name(s) {}
bool operator()(const TemplateSimplifier::TokenAndName &t) const {
return t.name == name;
}
private:
const std::string name;
};
}
void TemplateSimplifier::cleanupAfterSimplify(Token *tokens) void TemplateSimplifier::cleanupAfterSimplify(Token *tokens)
{ {
bool goback = false; bool goback = false;
@ -547,20 +569,14 @@ std::list<TemplateSimplifier::TokenAndName> TemplateSimplifier::getTemplateInsta
// Add outer template.. // Add outer template..
if (TemplateSimplifier::templateParameters(tok->next())) { if (TemplateSimplifier::templateParameters(tok->next())) {
bool done = false;
const std::string scopeName1(scopeName); const std::string scopeName1(scopeName);
while (!done) { while (true) {
const std::string fullName = scopeName + (scopeName.empty()?"":" :: ") + tok->str(); const std::string fullName = scopeName + (scopeName.empty()?"":" :: ") + tok->str();
const std::list<TokenAndName>::const_iterator it = std::find_if(declarations.begin(), declarations.end(), FindName(fullName));
for (std::list<TokenAndName>::const_iterator it = declarations.begin(); it != declarations.end(); ++it) { if (it != declarations.end()) {
if (it->name == fullName) {
instantiations.push_back(TokenAndName(tok, getScopeName(scopeList), fullName)); instantiations.push_back(TokenAndName(tok, getScopeName(scopeList), fullName));
done = true;
break; break;
} } else {
}
if (!done) {
if (scopeName.empty()) { if (scopeName.empty()) {
instantiations.push_back(TokenAndName(tok, getScopeName(scopeList), scopeName1 + (scopeName1.empty()?"":" :: ") + tok->str())); instantiations.push_back(TokenAndName(tok, getScopeName(scopeList), scopeName1 + (scopeName1.empty()?"":" :: ") + tok->str()));
break; break;
@ -697,11 +713,9 @@ void TemplateSimplifier::useDefaultArgumentValues(const std::list<TokenAndName>
if (Token::Match(tok2, "(|{|[")) if (Token::Match(tok2, "(|{|["))
tok2 = tok2->link(); tok2 = tok2->link();
else if (Token::Match(tok2, "%type% <") && templateParameters(tok2->next())) { else if (Token::Match(tok2, "%type% <") && templateParameters(tok2->next())) {
std::list<TokenAndName>::iterator ti; std::list<TokenAndName>::iterator ti = std::find_if(templateInstantiations->begin(),
for (ti = templateInstantiations->begin(); ti != templateInstantiations->end(); ++ti) { templateInstantiations->end(),
if (ti->token == tok2) FindToken(tok2));
break;
}
if (ti != templateInstantiations->end()) if (ti != templateInstantiations->end())
templateInstantiations->erase(ti); templateInstantiations->erase(ti);
++indentlevel; ++indentlevel;