From 81e41f129aa02b83431770847df4cb50918b5f46 Mon Sep 17 00:00:00 2001 From: IOBYTE Date: Fri, 7 Jun 2019 02:22:34 -0400 Subject: [PATCH] template simplifier: improve populating template specialization maps (#1873) Declaration to specialization mapping is still not perfect. --- lib/templatesimplifier.cpp | 21 +++++++++++++++++++-- lib/templatesimplifier.h | 12 ++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 373109da3..231978e82 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -2922,6 +2922,17 @@ void TemplateSimplifier::replaceTemplateUsage( } } +static bool specMatch( + const TemplateSimplifier::TokenAndName &spec, + const TemplateSimplifier::TokenAndName &decl) +{ + // make sure decl is really a declaration + if (decl.isPartialSpecialization() || decl.isSpecialization() || decl.isAlias()) + return false; + + return spec.isSameFamily(decl); +} + void TemplateSimplifier::getSpecializations() { // try to locate a matching declaration for each user defined specialization @@ -2929,7 +2940,7 @@ void TemplateSimplifier::getSpecializations() if (spec.isSpecialization()) { bool found = false; for (auto & decl : mTemplateDeclarations) { - if (decl.isSpecialization()) + if (!specMatch(spec, decl)) continue; // make sure the scopes and names match @@ -2942,6 +2953,9 @@ void TemplateSimplifier::getSpecializations() if (!found) { for (auto & decl : mTemplateForwardDeclarations) { + if (!specMatch(spec, decl)) + continue; + // make sure the scopes and names match if (spec.fullName == decl.fullName) { // @todo make sure function parameters also match @@ -2960,7 +2974,7 @@ void TemplateSimplifier::getPartialSpecializations() if (spec.isPartialSpecialization()) { bool found = false; for (auto & decl : mTemplateDeclarations) { - if (decl.isPartialSpecialization()) + if (!specMatch(spec, decl)) continue; // make sure the scopes and names match @@ -2973,6 +2987,9 @@ void TemplateSimplifier::getPartialSpecializations() if (!found) { for (auto & decl : mTemplateForwardDeclarations) { + if (!specMatch(spec, decl)) + continue; + // make sure the scopes and names match if (spec.fullName == decl.fullName) { // @todo make sure function parameters also match diff --git a/lib/templatesimplifier.h b/lib/templatesimplifier.h index 29a123711..f7a36ca0b 100644 --- a/lib/templatesimplifier.h +++ b/lib/templatesimplifier.h @@ -208,6 +208,18 @@ public: * @return true if alias token, false if not */ bool isAliasToken(const Token *tok) const; + + /** + * Is declaration the same family (class, function or variable). + * + * @param decl declaration to compare to + * @return true if same family, false if different family + */ + bool isSameFamily(const TemplateSimplifier::TokenAndName &decl) const { + // maks sure a family flag is set and matches + return (flags & (fIsClass | fIsFunction | fIsVariable)) & + (decl.flags & (fIsClass | fIsFunction | fIsVariable)); + } }; /**