14 #include "llvm/ADT/DenseMap.h" 15 #include "llvm/ADT/DenseSet.h" 16 #include "llvm/ADT/SmallString.h" 17 #include "llvm/ADT/StringMap.h" 18 #include "llvm/Support/Path.h" 27 llvm::Optional<Path> uriToAbsolutePath(llvm::StringRef URI,
PathRef HintPath) {
39 class BackgroundIndexLoader {
42 : IndexStorageFactory(IndexStorageFactory) {}
47 std::vector<LoadedShard> takeResult() &&;
53 std::pair<const LoadedShard &, std::vector<Path>>
57 llvm::StringMap<LoadedShard> LoadedShards;
62 std::pair<const LoadedShard &, std::vector<Path>>
63 BackgroundIndexLoader::loadShard(
PathRef StartSourceFile,
PathRef DependentTU) {
64 auto It = LoadedShards.try_emplace(StartSourceFile);
65 LoadedShard &LS = It.first->getValue();
66 std::vector<Path> Edges = {};
71 LS.AbsolutePath = StartSourceFile.str();
72 LS.DependentTU = DependentTU;
73 BackgroundIndexStorage *Storage = IndexStorageFactory(LS.AbsolutePath);
74 auto Shard = Storage->loadShard(StartSourceFile);
75 if (!Shard || !Shard->Sources) {
76 vlog(
"Failed to load shard: {0}", StartSourceFile);
80 LS.Shard = std::move(Shard);
81 for (
const auto &It : *LS.Shard->Sources) {
82 auto AbsPath = uriToAbsolutePath(It.getKey(), StartSourceFile);
86 if (*AbsPath != StartSourceFile) {
87 Edges.push_back(*AbsPath);
92 const IncludeGraphNode &IGN = It.getValue();
93 LS.Digest = IGN.Digest;
97 assert(LS.Digest !=
FileDigest{{0}} &&
"Digest is empty?");
102 llvm::StringSet<> InQueue;
104 std::queue<PathRef> ToVisit;
105 InQueue.insert(MainFile);
106 ToVisit.push(MainFile);
108 while (!ToVisit.empty()) {
109 PathRef SourceFile = ToVisit.front();
112 auto ShardAndEdges = loadShard(SourceFile, MainFile);
113 for (
PathRef Edge : ShardAndEdges.second) {
114 auto It = InQueue.insert(Edge);
116 ToVisit.push(It.first->getKey());
121 std::vector<LoadedShard> BackgroundIndexLoader::takeResult() && {
122 std::vector<LoadedShard>
Result;
123 Result.reserve(LoadedShards.size());
124 for (
auto &It : LoadedShards)
125 Result.push_back(std::move(It.getValue()));
130 std::vector<LoadedShard>
134 BackgroundIndexLoader Loader(IndexStorageFactory);
135 for (llvm::StringRef MainFile : MainFiles) {
136 assert(llvm::sys::path::is_absolute(MainFile));
137 Loader.load(MainFile);
139 return std::move(Loader).takeResult();
llvm::unique_function< BackgroundIndexStorage *(PathRef)> Factory
std::array< uint8_t, 8 > FileDigest
llvm::StringRef PathRef
A typedef to represent a ref to file path.
Documents should not be synced at all.
void vlog(const char *Fmt, Ts &&... Vals)
Provides compilation arguments used for parsing C and C++ files.
std::vector< LoadedShard > loadIndexShards(llvm::ArrayRef< Path > MainFiles, BackgroundIndexStorage::Factory &IndexStorageFactory, const GlobalCompilationDatabase &CDB)
Loads all shards for the TU MainFile from Storage.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
static llvm::Expected< std::string > resolve(const URI &U, llvm::StringRef HintPath="")
Resolves the absolute path of U.
static llvm::Expected< URI > parse(llvm::StringRef Uri)
Parse a URI string "<scheme>:[//<authority>/]<path>".