diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 1f77f1a65..abf414ec5 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2646,37 +2646,10 @@ std::list Tokenizer::simplifyTemplatesGetTemplateDeclarations() return templates; } -void Tokenizer::simplifyTemplates() +std::list Tokenizer::simplifyTemplatesGetTemplateInstantiations() { - std::set expandedtemplates(simplifyTemplatesExpandSpecialized()); - - // Locate templates.. - std::list 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 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 expandedtemplates(simplifyTemplatesExpandSpecialized()); + + // Locate templates.. + std::list 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 used(simplifyTemplatesGetTemplateInstantiations()); + // No template instantiations? Then remove all templates. if (used.empty()) { diff --git a/lib/tokenize.h b/lib/tokenize.h index 2691b967a..9470d7089 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -409,6 +409,12 @@ public: */ std::list simplifyTemplatesGetTemplateDeclarations(); + /** + * Get template instantiations + * @return list of template instantiations + */ + std::list simplifyTemplatesGetTemplateInstantiations(); + /** * Used after simplifyTemplates to perform a little cleanup. * Sometimes the simplifyTemplates isn't fully successful and then