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;
83 LS.CountReferences = IGN.Flags & IncludeGraphNode::SourceFlag::IsTU;
84 LS.HadErrors = IGN.Flags & IncludeGraphNode::SourceFlag::HadErrors;
86 assert(LS.Digest != FileDigest{{0}} &&
"Digest is empty?");
90void BackgroundIndexLoader::load(
PathRef MainFile) {
91 llvm::StringSet<> InQueue;
93 std::queue<PathRef> ToVisit;
94 InQueue.insert(MainFile);
95 ToVisit.push(MainFile);
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));
126 Loader.load(MainFile);
128 return std::move(Loader).takeResult();
void elog(const char *Fmt, Ts &&... Vals)
llvm::unique_function< BackgroundIndexStorage *(PathRef)> Factory
Provides compilation arguments used for parsing C and C++ files.
FIXME: Skip testing on windows temporarily due to the different escaping code mode.
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)
llvm::StringRef PathRef
A typedef to represent a ref to file path.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//