brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · 3b3e0dd Raw
53 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9#include "Relation.h"10 11#include <algorithm>12 13namespace clang {14namespace clangd {15 16llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const RelationKind R) {17  switch (R) {18  case RelationKind::BaseOf:19    return OS << "BaseOf";20  case RelationKind::OverriddenBy:21    return OS << "OverriddenBy";22  }23  llvm_unreachable("Unhandled RelationKind enum.");24}25 26llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Relation &R) {27  return OS << R.Subject << " " << R.Predicate << " " << R.Object;28}29 30llvm::iterator_range<RelationSlab::iterator>31RelationSlab::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);37                                   });38  return {IterPair.first, IterPair.second};39}40 41RelationSlab RelationSlab::Builder::build() && {42  // Sort in SPO order.43  llvm::sort(Relations);44 45  // Remove duplicates.46  Relations.erase(llvm::unique(Relations), Relations.end());47 48  return RelationSlab{std::move(Relations)};49}50 51} // namespace clangd52} // namespace clang53