[PATCH] D139409: [include-cleaner] Handle dependent type members in AST
Viktoriia Bakalova via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 6 06:30:58 PST 2022
VitaNuo updated this revision to Diff 480466.
VitaNuo added a comment.
Implement dependent type handling for template specialization types.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D139409/new/
https://reviews.llvm.org/D139409
Files:
clang-tools-extra/include-cleaner/lib/WalkAST.cpp
clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===================================================================
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -178,6 +178,11 @@
"void foo() { X{}.^foo(); }");
}
+TEST(WalkAST, CXXDependentScopeMemberExprs) {
+ testWalk("template<typename T> struct $explicit^Base { void method(); };",
+ "template<typename T> void k(Base<T> t) { t.^method(); }");
+}
+
TEST(WalkAST, ConstructExprs) {
testWalk("struct $implicit^S {};", "S ^t;");
testWalk("struct S { $implicit^S(); };", "S ^t;");
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===================================================================
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -19,6 +19,7 @@
#include "clang/Basic/SourceManager.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/Casting.h"
+#include <iostream>
namespace clang::include_cleaner {
namespace {
@@ -63,6 +64,17 @@
return true;
}
+ bool VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E) {
+ QualType Type = E->getBaseType().getCanonicalType();
+ if (isa<TemplateSpecializationType>(Type)) {
+ const TemplateSpecializationType *TST =
+ cast<TemplateSpecializationType>(Type);
+ TemplateDecl *TD = TST->getTemplateName().getAsTemplateDecl();
+ report(E->getMemberLoc(), TD);
+ }
+ return true;
+ }
+
bool VisitCXXConstructExpr(CXXConstructExpr *E) {
report(E->getLocation(), E->getConstructor(),
E->getParenOrBraceRange().isValid() ? RefType::Explicit
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139409.480466.patch
Type: text/x-patch
Size: 1732 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221206/53ada0f7/attachment.bin>
More information about the cfe-commits
mailing list