[PATCH] D70849: [AST] Traverse the class type loc inside the member pointer type loc.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 2 02:05:15 PST 2019


hokein updated this revision to Diff 231649.
hokein marked 3 inline comments as done.
hokein added a comment.
Herald added subscribers: arphaman, jkorous.

address review comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70849/new/

https://reviews.llvm.org/D70849

Files:
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
  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
@@ -1162,11 +1162,11 @@
 DEF_TRAVERSE_TYPELOC(RValueReferenceType,
                      { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
 
-// FIXME: location of base class?
 // 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()));
   TRY_TO(TraverseTypeLoc(TL.getPointeeLoc()));
 })
 
Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -407,8 +407,8 @@
       }
     )cpp",
       R"cpp(
-      template<typename $TemplateParameter[[T]], 
-        void (T::*$TemplateParameter[[method]])(int)>
+      template<typename $TemplateParameter[[T]],
+        void ($TemplateParameter[[T]]::*$TemplateParameter[[method]])(int)>
       struct $Class[[G]] {
         void $Method[[foo]](
             $TemplateParameter[[T]] *$Parameter[[O]]) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70849.231649.patch
Type: text/x-patch
Size: 3343 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191202/dd63b8ed/attachment-0001.bin>


More information about the cfe-commits mailing list