[PATCH] D102614: [index] Add support for type of pointers to class members

Ella Ma via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 17 04:50:03 PDT 2021


OikawaKirie created this revision.
OikawaKirie added a reviewer: akyrtzi.
OikawaKirie added a project: clang.
Herald added a subscriber: arphaman.
OikawaKirie requested review of this revision.
Herald added a subscriber: cfe-commits.

Required in D102159 <https://reviews.llvm.org/D102159> that we should add support for the unhandled items instead of workaround them.
In this patch, support is added for indexing the type of pointers to class members. Such usages are found in MySQL.
The format is `<class index>::*<member index>`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102614

Files:
  clang/lib/Index/USRGeneration.cpp
  clang/test/Index/USR/MemberFunctionPtr.cpp


Index: clang/test/Index/USR/MemberFunctionPtr.cpp
===================================================================
--- /dev/null
+++ clang/test/Index/USR/MemberFunctionPtr.cpp
@@ -0,0 +1,33 @@
+// RUN: c-index-test core -print-source-symbols -- %s | FileCheck %s
+
+struct C {
+  int X;
+  void f(char);
+};
+
+void f(int C::*) {}
+// CHECK: function/C | f | c:@F at f#$@S at C::*I#
+void f(void (C::*)(char)) {}
+// CHECK: function/C | f | c:@F at f#$@S at C::*Fv(#C)#
+
+typedef int C::*Xtd;
+void ftd(Xtd) {}
+// CHECK: function/C | ftd | c:@F at ftd#$@S at C::*I#
+typedef void (C::*Ftd)(char);
+void ftd(Ftd) {}
+// CHECK: function/C | ftd | c:@F at ftd#$@S at C::*Fv(#C)#
+
+using Xus = int C::*;
+void fus(Xus) {}
+// CHECK: function/C | fus | c:@F at fus#$@S at C::*I#
+using Fus = void (C::*)(char);
+void fus(Fus) {}
+// CHECK: function/C | fus | c:@F at fus#$@S at C::*Fv(#C)#
+
+template <typename T> struct S;
+template <typename T, typename U> struct S<T U::*> {
+  static const bool V = true;
+  // CHECK: static-property/C++ | V | c:@SP>2#T#T at S>#t0.1::*t0.0 at V
+  void f() {}
+  // CHECK: instance-method/C++ | f | c:@SP>2#T#T at S>#t0.1::*t0.0 at F@f#
+};
Index: clang/lib/Index/USRGeneration.cpp
===================================================================
--- clang/lib/Index/USRGeneration.cpp
+++ clang/lib/Index/USRGeneration.cpp
@@ -893,6 +893,12 @@
       T = AT->getElementType();
       continue;
     }
+    if (const MemberPointerType *MPT = T->getAs<MemberPointerType>()) {
+      VisitType(QualType(MPT->getClass(), 0));
+      Out << "::*";
+      T = MPT->getPointeeType();
+      continue;
+    }
 
     // Unhandled type.
     Out << ' ';


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102614.345814.patch
Type: text/x-patch
Size: 1639 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210517/042d723b/attachment.bin>


More information about the cfe-commits mailing list