Skip to content

Commit

Permalink
feat(cxx_indexer): support decayed types (#5852)
Browse files Browse the repository at this point in the history
Use the new type when we encounter a decayed/adjusted type
(unless it's null, then try the old one).

NB: according to clang's documentation, an adjusted type
is "a type which was implicitly adjusted by the semantic engine
for arbitrary reasons"
  • Loading branch information
zrlk authored Sep 18, 2023
1 parent 73f3832 commit 77ff9e4
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
20 changes: 18 additions & 2 deletions kythe/cxx/indexer/cxx/IndexerASTHooks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4666,6 +4666,16 @@ NodeSet IndexerASTVisitor::BuildNodeSetForDependentAddressSpace(
return BuildNodeSetForType(T.getPointeeType());
}

NodeSet IndexerASTVisitor::BuildNodeSetForAdjusted(
const clang::AdjustedType& T) {
if (auto S = T.getAdjustedType(); !S.isNull()) {
return BuildNodeSetForType(S);
} else if (auto U = T.getOriginalType(); !U.isNull()) {
return BuildNodeSetForType(U);
}
return NodeSet::Empty();
}

GraphObserver::NodeId IndexerASTVisitor::BuildNominalNodeIdForDecl(
const clang::NamedDecl* Decl) {
// TODO(shahms): Separate building the node id from emitting it.
Expand Down Expand Up @@ -4802,6 +4812,11 @@ NodeSet IndexerASTVisitor::BuildNodeSetForTypeInternal(const clang::Type& T) {
#define DELEGATE_TYPE(t) \
case clang::Type::t: \
return BuildNodeSetFor##t(clang::cast<clang::t##Type>(T));

#define DELEGATE_TYPE_TO_BASE(t, b) \
case clang::Type::t: \
return BuildNodeSetFor##b(clang::cast<clang::b##Type>(T));

// We only care about leaves in the type hierarchy (eg, we shouldn't match
// on Reference, but instead on LValueReference or RValueReference).
switch (T.getTypeClass()) {
Expand Down Expand Up @@ -4843,15 +4858,15 @@ NodeSet IndexerASTVisitor::BuildNodeSetForTypeInternal(const clang::Type& T) {
DELEGATE_TYPE(DependentAddressSpace);
DELEGATE_TYPE(BitInt);
DELEGATE_TYPE(DependentBitInt);
DELEGATE_TYPE(Adjusted);
DELEGATE_TYPE_TO_BASE(Decayed, Adjusted);
UNSUPPORTED_CLANG_TYPE(BTFTagAttributed);
UNSUPPORTED_CLANG_TYPE(DependentTemplateSpecialization);
UNSUPPORTED_CLANG_TYPE(Complex);
UNSUPPORTED_CLANG_TYPE(VariableArray);
UNSUPPORTED_CLANG_TYPE(DependentSizedExtVector);
UNSUPPORTED_CLANG_TYPE(Vector);
UNSUPPORTED_CLANG_TYPE(ExtVector);
UNSUPPORTED_CLANG_TYPE(Adjusted);
UNSUPPORTED_CLANG_TYPE(Decayed);
UNSUPPORTED_CLANG_TYPE(TypeOfExpr);
UNSUPPORTED_CLANG_TYPE(TypeOf);
UNSUPPORTED_CLANG_TYPE(UnresolvedUsing);
Expand All @@ -4876,6 +4891,7 @@ NodeSet IndexerASTVisitor::BuildNodeSetForTypeInternal(const clang::Type& T) {
}
#undef UNSUPPORTED_CLANG_TYPE
#undef DELEGATE_TYPE
#undef DELEGATE_TYPE_TO_BASE
}

std::optional<GraphObserver::NodeId>
Expand Down
1 change: 1 addition & 0 deletions kythe/cxx/indexer/cxx/IndexerASTHooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ class IndexerASTVisitor : public RecursiveTypeVisitor<IndexerASTVisitor> {
NodeSet BuildNodeSetForAttributed(const clang::AttributedType& T);
NodeSet BuildNodeSetForDependentAddressSpace(
const clang::DependentAddressSpaceType& T);
NodeSet BuildNodeSetForAdjusted(const clang::AdjustedType& T);

// Helper function which constructs marked source and records
// a tnominal node for the given `Decl`.
Expand Down
7 changes: 7 additions & 0 deletions kythe/cxx/indexer/cxx/testdata/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,13 @@ cc_indexer_test(
tags = ["basic"],
)

cc_indexer_test(
name = "decayed_type",
srcs = ["basic/decayed_type.cc"],
check_for_singletons = True,
tags = ["basic"],
)

cc_indexer_test(
name = "decltype_auto",
srcs = ["basic/decltype_auto.cc"],
Expand Down
26 changes: 26 additions & 0 deletions kythe/cxx/indexer/cxx/testdata/basic/decayed_type.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// We support decayed types.
void i() {
//- @i ref FnI
//- FnI typed TyI
//- @j defines/binding VarJ
//- VarJ typed TyJ
auto j = i;
//- @k defines/binding VarK
//- VarK typed TyK
int k[1] = {1};
//- @l defines/binding VarL
//- VarL typed TyL
auto* l = k;
}
//- @TFnVoidVoid defines/binding AliasFVV
//- AliasFVV aliases TyI
using TFnVoidVoid = decltype(i);
//- @TPtrFnVoidVoid defines/binding AliasPFVV
//- AliasPFVV aliases TyJ
using TPtrFnVoidVoid = decltype(i)*;
//- @TCArrInt defines/binding AliasCAI
//- AliasCAI aliases TyK
using TCArrInt = int[1];
//- @TPtrInt defines/binding AliasPI
//- AliasPI aliases TyL
using TPtrInt = int*;

0 comments on commit 77ff9e4

Please sign in to comment.