[PATCH] D70849: [AST] Traverse the class type loc inside the member type loc.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 29 04:17:37 PST 2019
hokein created this revision.
hokein added a reviewer: ilya-biryukov.
Herald added subscribers: usaxena95, kadircet, mgorny.
Herald added a project: clang.
We are missing this currently.
This would fix https://github.com/clangd/clangd/issues/216.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D70849
Files:
clang/include/clang/AST/RecursiveASTVisitor.h
clang/unittests/Tooling/CMakeLists.txt
clang/unittests/Tooling/RecursiveASTVisitorTests/MemberPointerTypeLoc.cpp
Index: clang/unittests/Tooling/RecursiveASTVisitorTests/MemberPointerTypeLoc.cpp
===================================================================
--- /dev/null
+++ clang/unittests/Tooling/RecursiveASTVisitorTests/MemberPointerTypeLoc.cpp
@@ -0,0 +1,37 @@
+//===- unittest/Tooling/RecursiveASTVisitorTests/MemberPointerTypeLoc.cpp -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "TestVisitor.h"
+
+using namespace clang;
+
+namespace {
+
+class MemberPointerTypeLocVisitor
+ : public ExpectedLocationVisitor<MemberPointerTypeLocVisitor> {
+public:
+ bool VisitRecordTypeLoc(RecordTypeLoc RTL) {
+ if (!RTL)
+ return true;
+ Match(RTL.getDecl()->getName(), RTL.getNameLoc());
+ return true;
+ }
+};
+
+TEST(RecursiveASTVisitor, VisitTypeLocInMemberPointerTypeLoc) {
+ MemberPointerTypeLocVisitor Visitor;
+ Visitor.ExpectMatch("Bar", 4, 36);
+ EXPECT_TRUE(Visitor.runOver(R"cpp(
+ class Bar { void func(int); };
+ class Foo {
+ void bind(const char*, void(Bar::*Foo)(int)) {}
+ };
+ )cpp"));
+}
+
+} // end anonymous namespace
Index: clang/unittests/Tooling/CMakeLists.txt
===================================================================
--- clang/unittests/Tooling/CMakeLists.txt
+++ clang/unittests/Tooling/CMakeLists.txt
@@ -42,6 +42,7 @@
RecursiveASTVisitorTests/LambdaDefaultCapture.cpp
RecursiveASTVisitorTests/LambdaExpr.cpp
RecursiveASTVisitorTests/LambdaTemplateParams.cpp
+ RecursiveASTVisitorTests/MemberPointerTypeLoc.cpp
RecursiveASTVisitorTests/NestedNameSpecifiers.cpp
RecursiveASTVisitorTests/ParenExpr.cpp
RecursiveASTVisitorTests/TemplateArgumentLocTraverser.cpp
Index: clang/include/clang/AST/RecursiveASTVisitor.h
===================================================================
--- clang/include/clang/AST/RecursiveASTVisitor.h
+++ clang/include/clang/AST/RecursiveASTVisitor.h
@@ -1166,7 +1166,10 @@
// We traverse this in the type case as well, but how is it not reached through
// the pointee type?
DEF_TRAVERSE_TYPELOC(MemberPointerType, {
- TRY_TO(TraverseType(QualType(TL.getTypePtr()->getClass(), 0)));
+ if (auto *TSI = TL.getClassTInfo())
+ TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));
+ else
+ TRY_TO(TraverseType(QualType(TL.getTypePtr()->getClass(), 0)));
TRY_TO(TraverseTypeLoc(TL.getPointeeLoc()));
})
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70849.231518.patch
Type: text/x-patch
Size: 2586 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191129/5104a839/attachment.bin>
More information about the cfe-commits
mailing list