@@ -281,34 +281,32 @@ const clang::NamedDecl* decl_of_impl(const void* T) {
281281}
282282
283283auto decl_of (clang::QualType type) -> const clang::NamedDecl* {
284+ if (auto TST = type->getAs <clang::TemplateSpecializationType>()) {
285+ auto decl = TST->getTemplateName ().getAsTemplateDecl ();
286+ if (type->isDependentType ()) {
287+ return decl;
288+ }
289+
290+ // / For a template specialization type, the template name is possibly a `ClassTemplateDecl`
291+ // / `TypeAliasTemplateDecl` or `TemplateTemplateParmDecl` and `BuiltinTemplateDecl`.
292+ if (llvm::isa<clang::TypeAliasTemplateDecl>(decl)) {
293+ return decl->getTemplatedDecl ();
294+ }
295+
296+ if (llvm::isa<clang::TemplateTemplateParmDecl, clang::BuiltinTemplateDecl>(decl)) {
297+ return decl;
298+ }
299+
300+ return instantiated_from (TST->getAsCXXRecordDecl ());
301+ }
302+
284303 switch (type->getTypeClass ()) {
285304#define ABSTRACT_TYPE (TY, BASE )
286305#define TYPE (TY, BASE ) \
287306 case clang::Type::TY: return decl_of_impl (llvm::cast<clang::TY##Type>(type));
288307#include " clang/AST/TypeNodes.inc"
289308 }
290309
291- // / FIXME: Handle Template Specialization type in the future
292- // / if(auto TST = type->getAs<clang::TemplateSpecializationType>()) {
293- // / auto decl = TST->getTemplateName().getAsTemplateDecl();
294- // / if(type->isDependentType()) {
295- // / return decl;
296- // / }
297- // /
298- // / /// For a template specialization type, the template name is possibly a
299- // / `ClassTemplateDecl`
300- // / /// `TypeAliasTemplateDecl` or `TemplateTemplateParmDecl` and `BuiltinTemplateDecl`.
301- // / if(llvm::isa<clang::TypeAliasTemplateDecl>(decl)) {
302- // / return decl->getTemplatedDecl();
303- // / }
304- // /
305- // / if(llvm::isa<clang::TemplateTemplateParmDecl, clang::BuiltinTemplateDecl>(decl)) {
306- // / return decl;
307- // / }
308- // /
309- // / return instantiated_from(TST->getAsCXXRecordDecl());
310- // /}
311-
312310 return nullptr ;
313311}
314312
0 commit comments