14#include "llvm/ADT/StringMap.h"
15#include "llvm/Support/Path.h"
26class BackgroundIndexLoader {
29 : IndexStorageFactory(IndexStorageFactory) {}
34 std::vector<LoadedShard> takeResult() &&;
40 std::pair<const LoadedShard &, std::vector<Path>>
44 llvm::StringMap<LoadedShard> LoadedShards;
49std::pair<const LoadedShard &, std::vector<Path>>
50BackgroundIndexLoader::loadShard(
PathRef StartSourceFile,
PathRef DependentTU) {
51 auto It = LoadedShards.try_emplace(StartSourceFile);
52 LoadedShard &LS = It.first->getValue();
53 std::vector<Path> Edges = {};
58 LS.AbsolutePath = StartSourceFile.str();
59 LS.DependentTU = std::string(DependentTU);
60 BackgroundIndexStorage *Storage = IndexStorageFactory(LS.AbsolutePath);
61 auto Shard = Storage->loadShard(StartSourceFile);
62 if (!Shard || !Shard->Sources) {
63 vlog(
"Failed to load shard: {0}", StartSourceFile);
67 LS.Shard = std::move(Shard);
68 for (
const auto &It : *LS.Shard->Sources) {
69 auto AbsPath =
URI::resolve(It.getKey(), StartSourceFile);
71 elog(
"Failed to resolve URI: {0}", AbsPath.takeError());
75 if (*AbsPath != StartSourceFile) {
76 Edges.push_back(*AbsPath);
81 const IncludeGraphNode &IGN = It.getValue();
82 LS.Digest = IGN.Digest;
86 assert(LS.Digest !=
FileDigest{{0}} &&
"Digest is empty?");
91 llvm::StringSet<> InQueue;
93 std::queue<PathRef> ToVisit;
97 while (!ToVisit.empty()) {
98 PathRef SourceFile = ToVisit.front();
101 auto ShardAndEdges = loadShard(SourceFile,
MainFile);
102 for (
PathRef Edge : ShardAndEdges.second) {
103 auto It = InQueue.insert(Edge);
105 ToVisit.push(It.first->getKey());
110std::vector<LoadedShard> BackgroundIndexLoader::takeResult() && {
111 std::vector<LoadedShard> Result;
112 Result.reserve(LoadedShards.size());
113 for (
auto &It : LoadedShards)
114 Result.push_back(std::move(It.getValue()));
119std::vector<LoadedShard>
123 BackgroundIndexLoader Loader(IndexStorageFactory);
124 for (llvm::StringRef
MainFile : MainFiles) {
125 assert(llvm::sys::path::is_absolute(
MainFile));
128 return std::move(Loader).takeResult();
llvm::unique_function< BackgroundIndexStorage *(PathRef)> Factory
Provides compilation arguments used for parsing C and C++ files.
static llvm::Expected< std::string > resolve(const URI &U, llvm::StringRef HintPath="")
Resolves the absolute path of U.
std::vector< LoadedShard > loadIndexShards(llvm::ArrayRef< Path > MainFiles, BackgroundIndexStorage::Factory &IndexStorageFactory, const GlobalCompilationDatabase &CDB)
Loads all shards for the TU MainFile from Storage.
void vlog(const char *Fmt, Ts &&... Vals)
std::array< uint8_t, 8 > FileDigest
llvm::StringRef PathRef
A typedef to represent a ref to file path.
void elog(const char *Fmt, Ts &&... Vals)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//