Skip to content

Commit

Permalink
fix(cxx_indexer): use function names, not exps, for semantics (#5213)
Browse files Browse the repository at this point in the history
Protip: MemberExprs aren't DeclRefExprs
  • Loading branch information
zrlk committed Feb 14, 2022
1 parent effb97a commit a11bf38
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
24 changes: 18 additions & 6 deletions kythe/cxx/indexer/cxx/IndexerASTHooks.cc
Expand Up @@ -1347,6 +1347,15 @@ bool IndexerASTVisitor::VisitMemberExpr(const clang::MemberExpr* E) {
if (options_.DataflowEdges && !Job->InfluenceSets.empty()) {
Job->InfluenceSets.back().insert(FieldDecl);
}
if (isa<clang::CXXMethodDecl>(FieldDecl)) {
if (const auto* semantic = AlternateSemanticForDecl(FieldDecl);
semantic != nullptr && semantic->node) {
Observer.recordSemanticDeclUseLocation(
RCC.value(), *(semantic->node), semantic->use_kind,
GraphObserver::Claimability::Unclaimable,
this->IsImplicit(RCC.value()));
}
}
}
}
return true;
Expand Down Expand Up @@ -1642,12 +1651,6 @@ bool IndexerASTVisitor::VisitCallExpr(const clang::CallExpr* E) {
for (const auto& S : Supports) {
S->InspectCallExpr(*this, E, RCC.value(), CalleeId);
}
if (const auto* semantic = AlternateSemanticForDecl(Callee);
semantic != nullptr && semantic->node) {
Observer.recordSemanticDeclUseLocation(
RCC.value(), *(semantic->node), semantic->use_kind,
GraphObserver::Claimability::Unclaimable, IsImplicit(RCC.value()));
}
} else if (const auto* CE = E->getCallee()) {
if (auto CalleeId = BuildNodeIdForExpr(CE, EmitRanges::Yes)) {
RecordCallEdges(RCC.value(), CalleeId.value());
Expand Down Expand Up @@ -2405,6 +2408,15 @@ bool IndexerASTVisitor::VisitDeclRefOrIvarRefExpr(
Job->InfluenceSets.back().insert(FoundDecl);
}
}
if (isa<clang::FunctionDecl>(FoundDecl)) {
if (const auto* semantic = AlternateSemanticForDecl(FoundDecl);
semantic != nullptr && semantic->node) {
Observer.recordSemanticDeclUseLocation(
RCC.value(), *(semantic->node), semantic->use_kind,
GraphObserver::Claimability::Unclaimable,
this->IsImplicit(RCC.value()));
}
}
Observer.recordSemanticDeclUseLocation(
*RCC, DeclId, UseKindFor(Expr),
GraphObserver::Claimability::Unclaimable, this->IsImplicit(*RCC));
Expand Down
Expand Up @@ -4,7 +4,7 @@
void foo();

void bar() {
//- @"foo()" ref/writes vname(gsig, gcorp, groot, gpath, glang)
//- @foo ref/writes vname(gsig, gcorp, groot, gpath, glang)
//- @foo ref FnFoo
//- @"foo()" ref/call FnFoo
foo();
Expand Down
20 changes: 10 additions & 10 deletions kythe/cxx/indexer/cxx/testdata/proto/proto_semantic.cc
Expand Up @@ -6,43 +6,43 @@ void fn() {

//- @Message ref CxxMessage
Message msg;
//- @"msg.set_string_field(\"value\")" ref/writes StringField
//- @set_string_field ref/writes StringField
msg.set_string_field("value");
//- @string_field ref CxxGetStringField
msg.string_field();
//- @"msg.release_string_field()" ref/writes StringField
//- @release_string_field ref/writes StringField
msg.release_string_field();
//- @"msg.set_allocated_string_field(nullptr)" ref/writes StringField
//- @set_allocated_string_field ref/writes StringField
msg.set_allocated_string_field(nullptr);
//- @"msg.set_int32_field(43)" ref/writes Int32Field
//- @set_int32_field ref/writes Int32Field
msg.set_int32_field(43);
//- @int32_field ref CxxGetInt32Field
msg.int32_field();

//- @NestedMessage ref CxxNestedMessage
Message::NestedMessage nested;
//- @"nested.set_nested_string(\"value\")" ref/writes NestedString
//- @set_nested_string ref/writes NestedString
nested.set_nested_string("value");
//- @nested_string ref CxxGetNestedStringField
nested.nested_string();
//- @"nested.set_nested_bool(true)" ref/writes NestedBool
//- @set_nested_bool ref/writes NestedBool
nested.set_nested_bool(true);
//- @nested_bool ref CxxGetNestedBoolField
nested.nested_bool();


//- @"msg.mutable_nested_message()" ref/writes NestedMessageField
//- @mutable_nested_message ref/writes NestedMessageField
*msg.mutable_nested_message() = nested;
//- @nested_message ref CxxGetNestedMessageField
msg.nested_message();

//- @"msg.clear_oneof_field()" ref/writes OneofField
//- @clear_oneof_field ref/writes OneofField
msg.clear_oneof_field();
//- @oneof_field_case ref CxxOneofFieldCase
msg.oneof_field_case();
//- @"msg.set_oneof_string(\"hello\")" ref/writes OneofString
//- @set_oneof_string ref/writes OneofString
msg.set_oneof_string("hello");

//- @"msg.add_repeated_int32_field(4)" ref/writes RepeatedInt32Field
//- @add_repeated_int32_field ref/writes RepeatedInt32Field
msg.add_repeated_int32_field(4);
}

0 comments on commit a11bf38

Please sign in to comment.