1 //===--- Relation.cpp --------------------------------------------*- C++-*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
16 llvm::raw_ostream
&operator<<(llvm::raw_ostream
&OS
, const RelationKind R
) {
18 case RelationKind::BaseOf
:
19 return OS
<< "BaseOf";
20 case RelationKind::OverriddenBy
:
21 return OS
<< "OverriddenBy";
23 llvm_unreachable("Unhandled RelationKind enum.");
26 llvm::raw_ostream
&operator<<(llvm::raw_ostream
&OS
, const Relation
&R
) {
27 return OS
<< R
.Subject
<< " " << R
.Predicate
<< " " << R
.Object
;
30 llvm::iterator_range
<RelationSlab::iterator
>
31 RelationSlab::lookup(const SymbolID
&Subject
, RelationKind Predicate
) const {
32 auto IterPair
= std::equal_range(Relations
.begin(), Relations
.end(),
33 Relation
{Subject
, Predicate
, SymbolID
{}},
34 [](const Relation
&A
, const Relation
&B
) {
35 return std::tie(A
.Subject
, A
.Predicate
) <
36 std::tie(B
.Subject
, B
.Predicate
);
38 return {IterPair
.first
, IterPair
.second
};
41 RelationSlab
RelationSlab::Builder::build() && {
43 llvm::sort(Relations
);
46 Relations
.erase(std::unique(Relations
.begin(), Relations
.end()),
49 return RelationSlab
{std::move(Relations
)};