arphaman created this revision.

Global binding declarations should be recorded as `variable` symbols.


Repository:
  rL LLVM

https://reviews.llvm.org/D33920

Files:
  lib/Index/IndexDecl.cpp
  lib/Index/IndexSymbol.cpp
  test/Index/Core/index-source.cpp


Index: test/Index/Core/index-source.cpp
===================================================================
--- test/Index/Core/index-source.cpp
+++ test/Index/Core/index-source.cpp
@@ -1,4 +1,4 @@
-// RUN: c-index-test core -print-source-symbols -- %s -std=c++14 -target 
x86_64-apple-macosx10.7 | FileCheck %s
+// RUN: c-index-test core -print-source-symbols -- %s -std=c++1z -target 
x86_64-apple-macosx10.7 | FileCheck %s
 
 // CHECK: [[@LINE+1]]:7 | class/C++ | Cls | [[Cls_USR:.*]] | <no-cgname> | Def 
| rel: 0
 class Cls { public:
@@ -433,3 +433,29 @@
 T varDecl = T();
 
 } // end namespace ensureDefaultTemplateParamsAreRecordedOnce
+
+namespace cpp17structuredBinding {
+
+struct Cpp17StructuredBinding {
+  int x, y;
+
+  Cpp17StructuredBinding(int x, int y): x(x), y(y) { }
+};
+
+auto [structuredBinding1, structuredBinding2] = 
Cpp17StructuredBinding(Record::C, 0);
+// CHECK: [[@LINE-1]]:7 | variable/C++ | structuredBinding1 | 
c:@N@cpp17structuredBinding@structuredBinding1 | <no-cgname> | Decl,RelChild | 
rel: 1
+// CHECK-NEXT: RelChild | cpp17structuredBinding | c:@N@cpp17structuredBinding
+// CHECK: [[@LINE-3]]:27 | variable/C++ | structuredBinding2 | 
c:@N@cpp17structuredBinding@structuredBinding2 | <no-cgname> | Decl,RelChild | 
rel: 1
+// CHECK-NEXT: RelChild | cpp17structuredBinding | c:@N@cpp17structuredBinding
+
+void localStructuredBindingAndRef() {
+  int ref = structuredBinding1;
+// CHECK: [[@LINE-1]]:13 | variable/C++ | structuredBinding1 | 
c:@N@cpp17structuredBinding@structuredBinding1 | <no-cgname> | Ref,Read,RelCont 
| rel: 1
+// CHECK-NEXT: RelCont | localStructuredBindingAndRef | 
c:@N@cpp17structuredBinding@F@localStructuredBindingAndRef#
+  auto [localBinding1, localBinding2] = Cpp17StructuredBinding(ref, 
structuredBinding2);
+// CHECK: [[@LINE-1]]:69 | variable/C++ | structuredBinding2 | 
c:@N@cpp17structuredBinding@structuredBinding2 | <no-cgname> | Ref,Read,RelCont 
| rel: 1
+// CHECK-NEXT: RelCont | localStructuredBindingAndRef | 
c:@N@cpp17structuredBinding@F@localStructuredBindingAndRef#
+// CHECK-NOT: localBinding
+}
+
+}
Index: lib/Index/IndexSymbol.cpp
===================================================================
--- lib/Index/IndexSymbol.cpp
+++ lib/Index/IndexSymbol.cpp
@@ -301,6 +301,10 @@
       Info.Kind = SymbolKind::TypeAlias;
       Info.Lang = SymbolLanguage::CXX;
       break;
+    case Decl::Binding:
+      Info.Kind = SymbolKind::Variable;
+      Info.Lang = SymbolLanguage::CXX;
+      break;
     default:
       break;
     }
Index: lib/Index/IndexDecl.cpp
===================================================================
--- lib/Index/IndexDecl.cpp
+++ lib/Index/IndexDecl.cpp
@@ -293,6 +293,12 @@
     return true;
   }
 
+  bool VisitDecompositionDecl(const DecompositionDecl *D) {
+    for (const auto *Binding : D->bindings())
+      TRY_DECL(Binding, IndexCtx.handleDecl(Binding));
+    return Base::VisitDecompositionDecl(D);
+  }
+
   bool VisitFieldDecl(const FieldDecl *D) {
     SmallVector<SymbolRelation, 4> Relations;
     gatherTemplatePseudoOverrides(D, Relations);


Index: test/Index/Core/index-source.cpp
===================================================================
--- test/Index/Core/index-source.cpp
+++ test/Index/Core/index-source.cpp
@@ -1,4 +1,4 @@
-// RUN: c-index-test core -print-source-symbols -- %s -std=c++14 -target x86_64-apple-macosx10.7 | FileCheck %s
+// RUN: c-index-test core -print-source-symbols -- %s -std=c++1z -target x86_64-apple-macosx10.7 | FileCheck %s
 
 // CHECK: [[@LINE+1]]:7 | class/C++ | Cls | [[Cls_USR:.*]] | <no-cgname> | Def | rel: 0
 class Cls { public:
@@ -433,3 +433,29 @@
 T varDecl = T();
 
 } // end namespace ensureDefaultTemplateParamsAreRecordedOnce
+
+namespace cpp17structuredBinding {
+
+struct Cpp17StructuredBinding {
+  int x, y;
+
+  Cpp17StructuredBinding(int x, int y): x(x), y(y) { }
+};
+
+auto [structuredBinding1, structuredBinding2] = Cpp17StructuredBinding(Record::C, 0);
+// CHECK: [[@LINE-1]]:7 | variable/C++ | structuredBinding1 | c:@N@cpp17structuredBinding@structuredBinding1 | <no-cgname> | Decl,RelChild | rel: 1
+// CHECK-NEXT: RelChild | cpp17structuredBinding | c:@N@cpp17structuredBinding
+// CHECK: [[@LINE-3]]:27 | variable/C++ | structuredBinding2 | c:@N@cpp17structuredBinding@structuredBinding2 | <no-cgname> | Decl,RelChild | rel: 1
+// CHECK-NEXT: RelChild | cpp17structuredBinding | c:@N@cpp17structuredBinding
+
+void localStructuredBindingAndRef() {
+  int ref = structuredBinding1;
+// CHECK: [[@LINE-1]]:13 | variable/C++ | structuredBinding1 | c:@N@cpp17structuredBinding@structuredBinding1 | <no-cgname> | Ref,Read,RelCont | rel: 1
+// CHECK-NEXT: RelCont | localStructuredBindingAndRef | c:@N@cpp17structuredBinding@F@localStructuredBindingAndRef#
+  auto [localBinding1, localBinding2] = Cpp17StructuredBinding(ref, structuredBinding2);
+// CHECK: [[@LINE-1]]:69 | variable/C++ | structuredBinding2 | c:@N@cpp17structuredBinding@structuredBinding2 | <no-cgname> | Ref,Read,RelCont | rel: 1
+// CHECK-NEXT: RelCont | localStructuredBindingAndRef | c:@N@cpp17structuredBinding@F@localStructuredBindingAndRef#
+// CHECK-NOT: localBinding
+}
+
+}
Index: lib/Index/IndexSymbol.cpp
===================================================================
--- lib/Index/IndexSymbol.cpp
+++ lib/Index/IndexSymbol.cpp
@@ -301,6 +301,10 @@
       Info.Kind = SymbolKind::TypeAlias;
       Info.Lang = SymbolLanguage::CXX;
       break;
+    case Decl::Binding:
+      Info.Kind = SymbolKind::Variable;
+      Info.Lang = SymbolLanguage::CXX;
+      break;
     default:
       break;
     }
Index: lib/Index/IndexDecl.cpp
===================================================================
--- lib/Index/IndexDecl.cpp
+++ lib/Index/IndexDecl.cpp
@@ -293,6 +293,12 @@
     return true;
   }
 
+  bool VisitDecompositionDecl(const DecompositionDecl *D) {
+    for (const auto *Binding : D->bindings())
+      TRY_DECL(Binding, IndexCtx.handleDecl(Binding));
+    return Base::VisitDecompositionDecl(D);
+  }
+
   bool VisitFieldDecl(const FieldDecl *D) {
     SmallVector<SymbolRelation, 4> Relations;
     gatherTemplatePseudoOverrides(D, Relations);
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D33920: [index] Record... Alex Lorenz via Phabricator via cfe-commits

Reply via email to