Skip to content

Commit dd82991

Browse files
feat: Emit refs for constructors (#163)
1 parent 0d9ac41 commit dd82991

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

indexer/Indexer.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "clang/AST/DeclCXX.h"
1515
#include "clang/AST/DeclTemplate.h"
1616
#include "clang/AST/Expr.h"
17+
#include "clang/AST/ExprCXX.h"
1718
#include "clang/AST/RawCommentList.h"
1819
#include "clang/AST/TypeLoc.h"
1920
#include "clang/Basic/SourceLocation.h"
@@ -622,6 +623,22 @@ void TuIndexer::saveVarDecl(const clang::VarDecl &varDecl) {
622623
}
623624
}
624625

626+
void TuIndexer::saveCXXConstructExpr(
627+
const clang::CXXConstructExpr &cxxConstructExpr) {
628+
if (auto *cxxConstructorDecl = cxxConstructExpr.getConstructor()) {
629+
if (cxxConstructorDecl->isImplicit()) {
630+
// SCIP doesn't yet have any way to represent implicitly
631+
// synthesized code:
632+
// https://github.com/sourcegraph/scip-clang/issues/126
633+
return;
634+
}
635+
if (auto optSymbol =
636+
this->symbolFormatter.getFunctionSymbol(*cxxConstructorDecl)) {
637+
this->saveReference(*optSymbol, cxxConstructExpr.getBeginLoc());
638+
}
639+
}
640+
}
641+
625642
void TuIndexer::saveDeclRefExpr(const clang::DeclRefExpr &declRefExpr) {
626643
// In the presence of 'using', prefer going to the 'using' instead
627644
// of directly dereferencing.

indexer/Indexer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "indexer/SymbolFormatter.h"
2323

2424
#define FOR_EACH_EXPR_TO_BE_INDEXED(F) \
25+
F(CXXConstruct) \
2526
F(DeclRef) \
2627
F(Member)
2728

test/index/functions/ctors_dtors.snapshot.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,14 @@
6969
D d0;
7070
// ^ reference [..] D#
7171
// ^^ definition local 6
72+
// ^^ reference [..] D#D(ced63f7c635d850d).
7273
C c1{};
7374
// ^ reference [..] C#
7475
// ^^ definition local 7
7576
D d1{};
7677
// ^ reference [..] D#
7778
// ^^ definition local 8
79+
// ^^ reference [..] D#D(ced63f7c635d850d).
7880
C c2{0, 1};
7981
// ^ reference [..] C#
8082
// ^^ definition local 9
@@ -89,6 +91,7 @@
8991
D d3{move(d1)};
9092
// ^ reference [..] D#
9193
// ^^ definition local 11
94+
// ^^ reference [..] D#D(ece7426db7e2c886).
9295
// ^^ reference local 8
9396

9497
C c4 = {};
@@ -97,6 +100,7 @@
97100
D d4 = {};
98101
// ^ reference [..] D#
99102
// ^^ definition local 13
103+
// ^ reference [..] D#D(ced63f7c635d850d).
100104
C c5 = C();
101105
// ^ reference [..] C#
102106
// ^^ definition local 14
@@ -105,6 +109,7 @@
105109
// ^ reference [..] D#
106110
// ^^ definition local 15
107111
// ^ reference [..] D#
112+
// ^ reference [..] D#D(ced63f7c635d850d).
108113
C c6 = {0, 1};
109114
// ^ reference [..] C#
110115
// ^^ definition local 16
@@ -128,5 +133,6 @@
128133
D d10 = move(d1);
129134
// ^ reference [..] D#
130135
// ^^^ definition local 21
136+
// ^^^^ reference [..] D#D(ece7426db7e2c886).
131137
// ^^ reference local 8
132138
}

test/index/vars/members.snapshot.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
S1(): S0() {
3030
// ^^ definition [..] S1#S1(49f6e7a06ebc5aa8).
3131
// ^^ reference [..] S0#
32+
// ^^ reference [..] S0#S0(49f6e7a06ebc5aa8).
3233
x = y;
3334
// ^ reference [..] S0#x.
3435
// ^ reference [..] S0#y.

0 commit comments

Comments
 (0)