summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Gräsman <kim.grasman@gmail.com>2022-08-29 08:30:26 +0200
committerKim Gräsman <kim.grasman@gmail.com>2022-08-31 22:16:16 +0200
commit7fd6c9f7982a36cf6c02fd4e460ee6af3d51cde0 (patch)
tree1bd00ce3c51d2171c663de524909798bb6399171
parent77e9128cbad707acf5fdaaa9236eec14a9c29440 (diff)
Replace all uses of RemoveSubstTemplateTypeParm with Desugar
No visible functional change, but we now desugar more aggressively. This patch is the result of: git grep -l "RemoveSubstTemplateTypeParm" | xargs sed -i -e 's/RemoveSubstTemplateTypeParam/Desugar/'
-rw-r--r--iwyu.cc8
-rw-r--r--iwyu_ast_util.cc11
-rw-r--r--iwyu_ast_util.h6
3 files changed, 6 insertions, 19 deletions
diff --git a/iwyu.cc b/iwyu.cc
index 3fdf5ec..1354eec 100644
--- a/iwyu.cc
+++ b/iwyu.cc
@@ -2820,7 +2820,7 @@ class InstantiatedTemplateVisitor
// Among all subst-type params, we only want those in the resugar-map. If
// we're not in the resugar-map at all, we're not a type corresponding to
// the template being instantiated, so we can be ignored.
- type = RemoveSubstTemplateTypeParm(type);
+ type = Desugar(type);
return ContainsKey(resugar_map_, type);
}
@@ -3234,7 +3234,7 @@ class InstantiatedTemplateVisitor
return GetLocOfTemplateThatProvides(decl).isValid();
}
bool IsProvidedByTemplate(const Type* type) const {
- type = RemoveSubstTemplateTypeParm(type);
+ type = Desugar(type);
type = RemovePointersAndReferences(type); // get down to the decl
if (const NamedDecl* decl = TypeToDeclAsWritten(type)) {
decl = GetDefinitionAsWritten(decl);
@@ -3248,7 +3248,7 @@ class InstantiatedTemplateVisitor
// class was instantiated) or not. We store this in resugar_map by
// having the value be nullptr.
bool IsDefaultTemplateParameter(const Type* type) const {
- type = RemoveSubstTemplateTypeParm(type);
+ type = Desugar(type);
return ContainsKeyValue(resugar_map_, type, static_cast<Type*>(nullptr));
}
@@ -3257,7 +3257,7 @@ class InstantiatedTemplateVisitor
// If we're not in the resugar-map, then we weren't canonicalized,
// so we can just use the input type unchanged.
const Type* ResugarType(const Type* type) const {
- type = RemoveSubstTemplateTypeParm(type);
+ type = Desugar(type);
// If we're the resugar-map but with a value of nullptr, it means
// we're a default template arg, which means we don't have anything
// to resugar to. So just return the input type.
diff --git a/iwyu_ast_util.cc b/iwyu_ast_util.cc
index 2b055cc..04a29a6 100644
--- a/iwyu_ast_util.cc
+++ b/iwyu_ast_util.cc
@@ -1160,16 +1160,9 @@ bool IsClassType(const clang::Type* type) {
isa<RecordType>(Desugar(type))));
}
-const Type* RemoveSubstTemplateTypeParm(const Type* type) {
- if (const SubstTemplateTypeParmType* subst_type = DynCastFrom(type))
- return subst_type->getReplacementType().getTypePtr();
- else
- return type;
-}
-
bool InvolvesTypeForWhich(const Type* type,
std::function<bool(const Type*)> pred) {
- type = RemoveSubstTemplateTypeParm(type);
+ type = Desugar(type);
if (pred(type))
return true;
const Decl* decl = TypeToDeclAsWritten(type);
@@ -1231,7 +1224,7 @@ static const NamedDecl* TypeToDeclImpl(const Type* type, bool as_written) {
// Read past SubstTemplateTypeParmType (this can happen if a
// template function returns the tpl-arg type: e.g. for
// 'T MyFn<T>() {...}; MyFn<X>.a', the type of MyFn<X> will be a Subst.
- type = RemoveSubstTemplateTypeParm(type);
+ type = Desugar(type);
CHECK_(!isa<ObjCObjectType>(type) && "IWYU doesn't support Objective-C");
diff --git a/iwyu_ast_util.h b/iwyu_ast_util.h
index c873efd..3762b07 100644
--- a/iwyu_ast_util.h
+++ b/iwyu_ast_util.h
@@ -681,12 +681,6 @@ bool IsTemplatizedType(const clang::Type* type);
// Returns true if the type is a RecordType or a TemplateSpecializationType.
bool IsClassType(const clang::Type* type);
-// Read past SubstTemplateTypeParmType to the underlying type, if type
-// is itself a SubstTemplateTypeParmType. Thus: T is converted to int
-// if we are parsing a template instantiated with T being int.
-// However, vector<T> is *not* converted to vector<int>.
-const clang::Type* RemoveSubstTemplateTypeParm(const clang::Type* type);
-
// Returns true if any type involved (recursively examining template
// arguments) satisfies the given predicate.
bool InvolvesTypeForWhich(const clang::Type* type,