clang-tools 10.0.0

Relation.cpp
Go to the documentation of this file.
1 //===--- Relation.cpp --------------------------------------------*- C++-*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "Relation.h"
10
11 #include <algorithm>
12
13 namespace clang {
14 namespace clangd {
15
16 llvm::iterator_range<RelationSlab::iterator>
17 RelationSlab::lookup(const SymbolID &Subject, RelationKind Predicate) const {
18 auto IterPair = std::equal_range(Relations.begin(), Relations.end(),
19 Relation{Subject, Predicate, SymbolID{}},
20 [](const Relation &A, const Relation &B) {
21 return std::tie(A.Subject, A.Predicate) <
22 std::tie(B.Subject, B.Predicate);
23 });
24 return {IterPair.first, IterPair.second};
25 }
26
27 RelationSlab RelationSlab::Builder::build() && {
28 // Sort in SPO order.
29 std::sort(Relations.begin(), Relations.end());
30
31 // Remove duplicates.
32 Relations.erase(std::unique(Relations.begin(), Relations.end()),
33 Relations.end());
34
35 return RelationSlab{std::move(Relations)};
36 }
37
38 } // namespace clangd
39 } // namespace clang
clang::clangd::Relation
Represents a relation between two symbols.
Definition: Relation.h:29
clang::clangd::RelationKind
RelationKind
Definition: Relation.h:22
clang::clangd::RelationSlab
Definition: Relation.h:45
clang::clangd::RelationSlab::lookup
llvm::iterator_range< iterator > lookup(const SymbolID &Subject, RelationKind Predicate) const
Lookup all relations matching the given subject and predicate.
Definition: Relation.cpp:17
clang::clangd::Relation::Predicate
RelationKind Predicate
Definition: Relation.h:31
clang::clangd::RelationSlab::Builder::build
RelationSlab build() &&
Consumes the builder to finalize the slab.
Definition: Relation.cpp:27
Relation.h
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::clangd::Relation::Subject
SymbolID Subject
Definition: Relation.h:30
clang::clangd::SymbolID
Definition: SymbolID.h:31