[clang] 4597e3b - [libclang]: visit BindingDecl in DecompositionDecl

Benjamin Kramer via cfe-commits cfe-commits at lists.llvm.org
Sat May 2 13:20:00 PDT 2020


Author: Milian Wolff
Date: 2020-05-02T22:18:31+02:00
New Revision: 4597e3bd475badff9f81e5d738913cd841bc3c1d

URL: https://github.com/llvm/llvm-project/commit/4597e3bd475badff9f81e5d738913cd841bc3c1d
DIFF: https://github.com/llvm/llvm-project/commit/4597e3bd475badff9f81e5d738913cd841bc3c1d.diff

LOG: [libclang]: visit BindingDecl in DecompositionDecl

This makes the BindingDecl accessible to consumers of libclang
as CXCursor_UnexposedDecl where previously these AST nodes were
not visited at all from the libclang API.

Differential Revision: https://reviews.llvm.org/D78213

Added: 
    clang/test/Index/cxx17-structured-binding.cpp

Modified: 
    clang/tools/libclang/CIndex.cpp
    clang/tools/libclang/CursorVisitor.h

Removed: 
    


################################################################################
diff  --git a/clang/test/Index/cxx17-structured-binding.cpp b/clang/test/Index/cxx17-structured-binding.cpp
new file mode 100644
index 000000000000..3fbd262eadae
--- /dev/null
+++ b/clang/test/Index/cxx17-structured-binding.cpp
@@ -0,0 +1,25 @@
+// Test is line- and column-sensitive; see below.
+int main() {
+  int a[2] = {1, 2};
+  auto [x, y] = a;
+}
+
+// RUN: c-index-test -test-load-source all -std=c++17 %s | FileCheck -check-prefix=CHECK-LOAD %s
+// CHECK-LOAD: cxx17-structured-binding.cpp:2:5: FunctionDecl=main:2:5 (Definition) Extent=[2:1 - 5:2]
+// CHECK-LOAD: cxx17-structured-binding.cpp:2:12: CompoundStmt= Extent=[2:12 - 5:2]
+// CHECK-LOAD: cxx17-structured-binding.cpp:3:3: DeclStmt= Extent=[3:3 - 3:21]
+// CHECK-LOAD: cxx17-structured-binding.cpp:3:7: VarDecl=a:3:7 (Definition) Extent=[3:3 - 3:20]
+// CHECK-LOAD: cxx17-structured-binding.cpp:3:9: IntegerLiteral= Extent=[3:9 - 3:10]
+// CHECK-LOAD: cxx17-structured-binding.cpp:3:14: InitListExpr= Extent=[3:14 - 3:20]
+// CHECK-LOAD: cxx17-structured-binding.cpp:3:15: IntegerLiteral= Extent=[3:15 - 3:16]
+// CHECK-LOAD: cxx17-structured-binding.cpp:3:18: IntegerLiteral= Extent=[3:18 - 3:19]
+// CHECK-LOAD: cxx17-structured-binding.cpp:4:3: DeclStmt= Extent=[4:3 - 4:19]
+// CHECK-LOAD: cxx17-structured-binding.cpp:4:8: UnexposedDecl=[x, y]:4:8 (Definition) Extent=[4:3 - 4:18]
+// CHECK-LOAD: cxx17-structured-binding.cpp:4:9: UnexposedDecl=x:4:9 (Definition) Extent=[4:9 - 4:10]
+// CHECK-LOAD: cxx17-structured-binding.cpp:4:12: UnexposedDecl=y:4:12 (Definition) Extent=[4:12 - 4:13]
+// CHECK-LOAD: cxx17-structured-binding.cpp:4:17: UnexposedExpr= Extent=[4:17 - 4:18]
+// CHECK-LOAD: cxx17-structured-binding.cpp:4:17: DeclRefExpr=a:3:7 Extent=[4:17 - 4:18]
+// CHECK-LOAD: cxx17-structured-binding.cpp:4:17: UnexposedExpr= Extent=[4:17 - 4:9]
+// CHECK-LOAD: cxx17-structured-binding.cpp:4:17: ArraySubscriptExpr= Extent=[4:17 - 4:9]
+// CHECK-LOAD: cxx17-structured-binding.cpp:4:17: UnexposedExpr=a:3:7 Extent=[4:17 - 4:18]
+// CHECK-LOAD: cxx17-structured-binding.cpp:4:17: DeclRefExpr=a:3:7 Extent=[4:17 - 4:18]

diff  --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
index f09d40115a74..f99cc5a8a6fd 100644
--- a/clang/tools/libclang/CIndex.cpp
+++ b/clang/tools/libclang/CIndex.cpp
@@ -1295,6 +1295,14 @@ bool CursorVisitor::VisitFriendDecl(FriendDecl *D) {
   return false;
 }
 
+bool CursorVisitor::VisitDecompositionDecl(DecompositionDecl *D) {
+  for (auto *B : D->bindings()) {
+    if (Visit(MakeCXCursor(B, TU, RegionOfInterest)))
+      return true;
+  }
+  return VisitVarDecl(D);
+}
+
 bool CursorVisitor::VisitDeclarationNameInfo(DeclarationNameInfo Name) {
   switch (Name.getName().getNameKind()) {
   case clang::DeclarationName::Identifier:

diff  --git a/clang/tools/libclang/CursorVisitor.h b/clang/tools/libclang/CursorVisitor.h
index 3337fecd0db3..364d9fdebdbc 100644
--- a/clang/tools/libclang/CursorVisitor.h
+++ b/clang/tools/libclang/CursorVisitor.h
@@ -241,6 +241,7 @@ class CursorVisitor : public DeclVisitor<CursorVisitor, bool>,
   bool VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
   bool VisitStaticAssertDecl(StaticAssertDecl *D);
   bool VisitFriendDecl(FriendDecl *D);
+  bool VisitDecompositionDecl(DecompositionDecl *D);
 
   // Name visitor
   bool VisitDeclarationNameInfo(DeclarationNameInfo Name);


        


More information about the cfe-commits mailing list