Skip to content

Commit

Permalink
feat(cxx_indexer): add alias-taking semantic (#5540)
Browse files Browse the repository at this point in the history
* feat(cxx_indexer): add alias-taking semantic
  • Loading branch information
zrlk authored Mar 15, 2023
1 parent 4fdd2c9 commit 0155c52
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 6 deletions.
3 changes: 3 additions & 0 deletions kythe/cxx/common/kythe_metadata_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ absl::optional<MetadataFile::Rule> MetadataFile::LoadMetaElement(
case MappingRule::SEMA_READ_WRITE:
sema = Semantic::kReadWrite;
break;
case MappingRule::SEMA_TAKE_ALIAS:
sema = Semantic::kTakeAlias;
break;
default:
sema = Semantic::kNone;
}
Expand Down
1 change: 1 addition & 0 deletions kythe/cxx/common/kythe_metadata_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class MetadataFile {
kNone, ///< No special semantics.
kWrite, ///< Write semantics.
kReadWrite, ///< Read+write semantics.
kTakeAlias, ///< Alias-taking semantics.
};

/// \brief A single metadata rule.
Expand Down
1 change: 1 addition & 0 deletions kythe/cxx/common/protobuf_metadata_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ std::unique_ptr<kythe::MetadataFile> ProtobufMetadataSupport::ParseFile(
absl::StartsWith(token, "release_")) {
rule.semantic = kythe::MetadataFile::Semantic::kWrite;
} else if (absl::StartsWith(token, "mutable_")) {
// TODO(zarko): kTakeAlias in a PR after #5538
rule.semantic = kythe::MetadataFile::Semantic::kReadWrite;
}
}
Expand Down
2 changes: 2 additions & 0 deletions kythe/cxx/indexer/cxx/GraphObserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ class GraphObserver {
kWrite,
/// This use site is both a read and a write.
kReadWrite,
/// This use site takes an alias.
kTakeAlias,
};

GraphObserver() {}
Expand Down
3 changes: 3 additions & 0 deletions kythe/cxx/indexer/cxx/IndexerASTHooks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5905,6 +5905,9 @@ void IndexerASTVisitor::PrepareAlternateSemanticCache() {
case MetadataFile::Semantic::kReadWrite:
kind = GraphObserver::UseKind::kReadWrite;
break;
case MetadataFile::Semantic::kTakeAlias:
kind = GraphObserver::UseKind::kTakeAlias;
break;
default:
break;
}
Expand Down
9 changes: 9 additions & 0 deletions kythe/cxx/indexer/cxx/IndexerASTHooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,15 @@ class IndexerASTVisitor : public RecursiveTypeVisitor<IndexerASTVisitor> {
return stmt;
}

/// \brief Marks that `expr` was used as an alias target.
/// \return `expr` as passed.
const clang::Expr* UsedAsAlias(const clang::Expr* expr) {
if (expr != nullptr)
use_kinds_[SkipTrivialAliasing(expr)] =
GraphObserver::UseKind::kTakeAlias;
return expr;
}

/// \brief Maps known Decls to their NodeIds.
llvm::DenseMap<const clang::Decl*, GraphObserver::NodeId> DeclToNodeId;

Expand Down
1 change: 1 addition & 0 deletions kythe/proto/metadata.proto
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ message MappingRule {
SEMA_NONE = 0;
SEMA_WRITE = 1;
SEMA_READ_WRITE = 2;
SEMA_TAKE_ALIAS = 3;
};

Semantic semantic = 11;
Expand Down
17 changes: 11 additions & 6 deletions kythe/proto/metadata_go_proto/metadata.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0155c52

Please sign in to comment.