daiyousei-qz created this revision. daiyousei-qz added reviewers: nridge, klimek. Herald added subscribers: usaxena95, kadircet. Herald added a project: All. daiyousei-qz requested review of this revision. Herald added subscribers: cfe-commits, ilya-biryukov. Herald added a project: clang.
The original discussion starts at this issue: https://github.com/clangd/clangd/issues/1132 where clangd's semantic highlighting is missing for symbols of a template specialization definition. It turns out the visitor didn't traverse the base classes of Class/Var##TemplateSpecializationDecl, i.e. CXXRecordDecl/VarDecl. This patch adds them back as what is done in DEF_TRAVERSE_TMPL_PART_SPEC_DECL. I'm not sure who should be included as reviewers. Please edit as needed. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D126757 Files: clang/include/clang/AST/RecursiveASTVisitor.h Index: clang/include/clang/AST/RecursiveASTVisitor.h =================================================================== --- clang/include/clang/AST/RecursiveASTVisitor.h +++ clang/include/clang/AST/RecursiveASTVisitor.h @@ -2021,7 +2021,7 @@ DEF_TRAVERSE_DECL(CXXRecordDecl, { TRY_TO(TraverseCXXRecordHelper(D)); }) -#define DEF_TRAVERSE_TMPL_SPEC_DECL(TMPLDECLKIND) \ +#define DEF_TRAVERSE_TMPL_SPEC_DECL(TMPLDECLKIND, DECLKIND) \ DEF_TRAVERSE_DECL(TMPLDECLKIND##TemplateSpecializationDecl, { \ /* For implicit instantiations ("set<int> x;"), we don't want to \ recurse at all, since the instatiated template isn't written in \ @@ -2035,17 +2035,21 @@ TRY_TO(TraverseTypeLoc(TSI->getTypeLoc())); \ \ TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc())); \ - if (!getDerived().shouldVisitTemplateInstantiations() && \ - D->getTemplateSpecializationKind() != TSK_ExplicitSpecialization) \ + if (getDerived().shouldVisitTemplateInstantiations() || \ + D->getTemplateSpecializationKind() == TSK_ExplicitSpecialization) { \ + /* Traverse base definition for explicit specializations */ \ + TRY_TO(Traverse##DECLKIND##Helper(D)); \ + } else { \ /* Returning from here skips traversing the \ declaration context of the *TemplateSpecializationDecl \ (embedded in the DEF_TRAVERSE_DECL() macro) \ which contains the instantiated members of the template. */ \ return true; \ + } \ }) -DEF_TRAVERSE_TMPL_SPEC_DECL(Class) -DEF_TRAVERSE_TMPL_SPEC_DECL(Var) +DEF_TRAVERSE_TMPL_SPEC_DECL(Class, CXXRecord) +DEF_TRAVERSE_TMPL_SPEC_DECL(Var, Var) template <typename Derived> bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLocsHelper(
Index: clang/include/clang/AST/RecursiveASTVisitor.h =================================================================== --- clang/include/clang/AST/RecursiveASTVisitor.h +++ clang/include/clang/AST/RecursiveASTVisitor.h @@ -2021,7 +2021,7 @@ DEF_TRAVERSE_DECL(CXXRecordDecl, { TRY_TO(TraverseCXXRecordHelper(D)); }) -#define DEF_TRAVERSE_TMPL_SPEC_DECL(TMPLDECLKIND) \ +#define DEF_TRAVERSE_TMPL_SPEC_DECL(TMPLDECLKIND, DECLKIND) \ DEF_TRAVERSE_DECL(TMPLDECLKIND##TemplateSpecializationDecl, { \ /* For implicit instantiations ("set<int> x;"), we don't want to \ recurse at all, since the instatiated template isn't written in \ @@ -2035,17 +2035,21 @@ TRY_TO(TraverseTypeLoc(TSI->getTypeLoc())); \ \ TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc())); \ - if (!getDerived().shouldVisitTemplateInstantiations() && \ - D->getTemplateSpecializationKind() != TSK_ExplicitSpecialization) \ + if (getDerived().shouldVisitTemplateInstantiations() || \ + D->getTemplateSpecializationKind() == TSK_ExplicitSpecialization) { \ + /* Traverse base definition for explicit specializations */ \ + TRY_TO(Traverse##DECLKIND##Helper(D)); \ + } else { \ /* Returning from here skips traversing the \ declaration context of the *TemplateSpecializationDecl \ (embedded in the DEF_TRAVERSE_DECL() macro) \ which contains the instantiated members of the template. */ \ return true; \ + } \ }) -DEF_TRAVERSE_TMPL_SPEC_DECL(Class) -DEF_TRAVERSE_TMPL_SPEC_DECL(Var) +DEF_TRAVERSE_TMPL_SPEC_DECL(Class, CXXRecord) +DEF_TRAVERSE_TMPL_SPEC_DECL(Var, Var) template <typename Derived> bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLocsHelper(
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits