Skip to content

Commit 8a656c9

Browse files
committedJun 15, 2017
[index] Record C++17 global binding declarations
The global C++17 binding declarations should be indexed as variable symbols. Differential Revision: https://reviews.llvm.org/D33920 llvm-svn: 305508
1 parent 45fbb59 commit 8a656c9

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed
 

‎clang/lib/Index/IndexDecl.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,12 @@ class IndexingDeclVisitor : public ConstDeclVisitor<IndexingDeclVisitor, bool> {
293293
return true;
294294
}
295295

296+
bool VisitDecompositionDecl(const DecompositionDecl *D) {
297+
for (const auto *Binding : D->bindings())
298+
TRY_DECL(Binding, IndexCtx.handleDecl(Binding));
299+
return Base::VisitDecompositionDecl(D);
300+
}
301+
296302
bool VisitFieldDecl(const FieldDecl *D) {
297303
SmallVector<SymbolRelation, 4> Relations;
298304
gatherTemplatePseudoOverrides(D, Relations);

‎clang/lib/Index/IndexSymbol.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,10 @@ SymbolInfo index::getSymbolInfo(const Decl *D) {
301301
Info.Kind = SymbolKind::TypeAlias;
302302
Info.Lang = SymbolLanguage::CXX;
303303
break;
304+
case Decl::Binding:
305+
Info.Kind = SymbolKind::Variable;
306+
Info.Lang = SymbolLanguage::CXX;
307+
break;
304308
default:
305309
break;
306310
}

‎clang/test/Index/Core/index-source.cpp

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: c-index-test core -print-source-symbols -- %s -std=c++14 -target x86_64-apple-macosx10.7 | FileCheck %s
1+
// RUN: c-index-test core -print-source-symbols -- %s -std=c++1z -target x86_64-apple-macosx10.7 | FileCheck %s
22

33
// CHECK: [[@LINE+1]]:7 | class/C++ | Cls | [[Cls_USR:.*]] | <no-cgname> | Def | rel: 0
44
class Cls { public:
@@ -449,3 +449,29 @@ void staticAssertInFn() {
449449
// CHECK: [[@LINE-3]]:17 | struct/C++ | StaticAssertRef | c:@S@StaticAssertRef | <no-cgname> | Ref,RelCont | rel: 1
450450
// CHECK-NEXT: RelCont | staticAssertInFn | c:@F@staticAssertInFn#
451451
}
452+
453+
namespace cpp17structuredBinding {
454+
455+
struct Cpp17StructuredBinding {
456+
int x, y;
457+
458+
Cpp17StructuredBinding(int x, int y): x(x), y(y) { }
459+
};
460+
461+
auto [structuredBinding1, structuredBinding2] = Cpp17StructuredBinding(Record::C, 0);
462+
// CHECK: [[@LINE-1]]:7 | variable/C++ | structuredBinding1 | c:@N@cpp17structuredBinding@structuredBinding1 | <no-cgname> | Decl,RelChild | rel: 1
463+
// CHECK-NEXT: RelChild | cpp17structuredBinding | c:@N@cpp17structuredBinding
464+
// CHECK: [[@LINE-3]]:27 | variable/C++ | structuredBinding2 | c:@N@cpp17structuredBinding@structuredBinding2 | <no-cgname> | Decl,RelChild | rel: 1
465+
// CHECK-NEXT: RelChild | cpp17structuredBinding | c:@N@cpp17structuredBinding
466+
467+
void localStructuredBindingAndRef() {
468+
int ref = structuredBinding1;
469+
// CHECK: [[@LINE-1]]:13 | variable/C++ | structuredBinding1 | c:@N@cpp17structuredBinding@structuredBinding1 | <no-cgname> | Ref,Read,RelCont | rel: 1
470+
// CHECK-NEXT: RelCont | localStructuredBindingAndRef | c:@N@cpp17structuredBinding@F@localStructuredBindingAndRef#
471+
auto [localBinding1, localBinding2] = Cpp17StructuredBinding(ref, structuredBinding2);
472+
// CHECK: [[@LINE-1]]:69 | variable/C++ | structuredBinding2 | c:@N@cpp17structuredBinding@structuredBinding2 | <no-cgname> | Ref,Read,RelCont | rel: 1
473+
// CHECK-NEXT: RelCont | localStructuredBindingAndRef | c:@N@cpp17structuredBinding@F@localStructuredBindingAndRef#
474+
// CHECK-NOT: localBinding
475+
}
476+
477+
}

0 commit comments

Comments
 (0)
Please sign in to comment.