daiyousei-qz updated this revision to Diff 434196.
daiyousei-qz marked an inline comment as done.
daiyousei-qz added a comment.
squashed commits.
updated comments.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D126757/new/
https://reviews.llvm.org/D126757
Files:
clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
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
\
@@ -2034,18 +2034,23 @@
if (TypeSourceInfo *TSI = D->getTypeAsWritten())
\
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 {
\
+ TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
\
+
\
/* 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-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -807,6 +807,19 @@
$Function_deprecated[[Foo]]($Parameter[[x]]);
$Function_deprecated[[Foo]]($Parameter[[x]]);
}
+ )cpp",
+ // Explicit template specialization
+ R"cpp(
+ struct $Class_decl[[Base]]{};
+ template <typename $TemplateParameter_decl[[T]]>
+ struct $Class_decl[[S]] : public $Class[[Base]] {};
+ template <>
+ struct $Class_decl[[S]]<void> : public $Class[[Base]] {};
+
+ template <typename $TemplateParameter_decl[[T]]>
+ $TemplateParameter[[T]] $Variable_decl[[x]] = {};
+ template <>
+ int $Variable_decl[[x]]<int> = (int)sizeof($Class[[Base]]);
)cpp"};
for (const auto &TestCase : TestCases)
// Mask off scope modifiers to keep the tests manageable.
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 \
@@ -2034,18 +2034,23 @@
if (TypeSourceInfo *TSI = D->getTypeAsWritten()) \
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 { \
+ TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc())); \
+ \
/* 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-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -807,6 +807,19 @@
$Function_deprecated[[Foo]]($Parameter[[x]]);
$Function_deprecated[[Foo]]($Parameter[[x]]);
}
+ )cpp",
+ // Explicit template specialization
+ R"cpp(
+ struct $Class_decl[[Base]]{};
+ template <typename $TemplateParameter_decl[[T]]>
+ struct $Class_decl[[S]] : public $Class[[Base]] {};
+ template <>
+ struct $Class_decl[[S]]<void> : public $Class[[Base]] {};
+
+ template <typename $TemplateParameter_decl[[T]]>
+ $TemplateParameter[[T]] $Variable_decl[[x]] = {};
+ template <>
+ int $Variable_decl[[x]]<int> = (int)sizeof($Class[[Base]]);
)cpp"};
for (const auto &TestCase : TestCases)
// Mask off scope modifiers to keep the tests manageable.
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits