VitaNuo updated this revision to Diff 480469. VitaNuo added a comment. Adjust implementation to handle pointer 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 @@ -88,12 +88,10 @@ auto RTStr = llvm::to_string(RT); for (auto Expected : Target.points(RTStr)) if (!llvm::is_contained(ReferencedOffsets[RT], Expected)) - DiagnosePoint("location not marked used with type " + RTStr, - Expected); + DiagnosePoint("location not marked used with type " + RTStr, Expected); for (auto Actual : ReferencedOffsets[RT]) if (!llvm::is_contained(Target.points(RTStr), Actual)) - DiagnosePoint("location unexpectedly used with type " + RTStr, - Actual); + DiagnosePoint("location unexpectedly used with type " + RTStr, Actual); } // If there were any differences, we print the entire referencing code once. @@ -178,6 +176,15 @@ "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(); }"); + testWalk("template<typename T> struct $explicit^Base { void method(); };", + "template<typename T> void k(Base<T>& t) { t.^method(); }"); + 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 @@ -63,6 +63,21 @@ return true; } + bool VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E) { + QualType Type = E->getBaseType().getCanonicalType(); + if (Type->isPointerType()) { + Type = Type->getPointeeType(); + } + + 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
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 @@ -88,12 +88,10 @@ auto RTStr = llvm::to_string(RT); for (auto Expected : Target.points(RTStr)) if (!llvm::is_contained(ReferencedOffsets[RT], Expected)) - DiagnosePoint("location not marked used with type " + RTStr, - Expected); + DiagnosePoint("location not marked used with type " + RTStr, Expected); for (auto Actual : ReferencedOffsets[RT]) if (!llvm::is_contained(Target.points(RTStr), Actual)) - DiagnosePoint("location unexpectedly used with type " + RTStr, - Actual); + DiagnosePoint("location unexpectedly used with type " + RTStr, Actual); } // If there were any differences, we print the entire referencing code once. @@ -178,6 +176,15 @@ "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(); }"); + testWalk("template<typename T> struct $explicit^Base { void method(); };", + "template<typename T> void k(Base<T>& t) { t.^method(); }"); + 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 @@ -63,6 +63,21 @@ return true; } + bool VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E) { + QualType Type = E->getBaseType().getCanonicalType(); + if (Type->isPointerType()) { + Type = Type->getPointeeType(); + } + + 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
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits