@@ -76,6 +76,9 @@ class FileIndexImpl {
7676 bool foreachFileIncludedByFile (CanonicalFilePathRef sourcePath,
7777 function_ref<bool (CanonicalFilePathRef targetPath, unsigned line)> Receiver);
7878
79+ bool foreachIncludeOfUnit (StringRef unitName,
80+ function_ref<bool (CanonicalFilePathRef sourcePath, CanonicalFilePathRef targetPath, unsigned line)> receiver);
81+
7982 bool foreachIncludeOfStoreUnitContainingFile (CanonicalFilePathRef filePath,
8083 function_ref<bool (CanonicalFilePathRef sourcePath, CanonicalFilePathRef targetPath, unsigned line)> receiver);
8184};
@@ -223,6 +226,23 @@ bool FileIndexImpl::foreachFileIncludedByFile(CanonicalFilePathRef inputSourcePa
223226 });
224227}
225228
229+ bool FileIndexImpl::foreachIncludeOfUnit (StringRef unitName,
230+ function_ref<bool (CanonicalFilePathRef sourcePath, CanonicalFilePathRef targetPath, unsigned line)> receiver) {
231+ std::string error;
232+ IndexUnitReader storeUnit (*IdxStore, unitName, error);
233+ if (!storeUnit.isValid ())
234+ return true ;
235+ StringRef workDir = storeUnit.getWorkingDirectory ();
236+ return storeUnit.foreachInclude ([&](IndexUnitInclude inc) -> bool {
237+ StringRef sourcePath = inc.getSourcePath ();
238+ StringRef targetPath = inc.getTargetPath ();
239+ unsigned line = inc.getSourceLine ();
240+ CanonicalFilePath fullSourcePath = getCanonicalPath (sourcePath, workDir);
241+ CanonicalFilePath fullTargetPath = getCanonicalPath (targetPath, workDir);
242+ return receiver (fullSourcePath, fullTargetPath, line);
243+ });
244+ }
245+
226246bool FileIndexImpl::foreachIncludeOfStoreUnitContainingFile (CanonicalFilePathRef filePath,
227247 function_ref<bool (CanonicalFilePathRef sourcePath, CanonicalFilePathRef targetPath, unsigned line)> receiver) {
228248 SmallVector<std::string, 32 > allUnitNames;
@@ -241,19 +261,7 @@ bool FileIndexImpl::foreachIncludeOfStoreUnitContainingFile(CanonicalFilePathRef
241261 }
242262
243263 for (auto &unitName: allUnitNames) {
244- std::string error;
245- IndexUnitReader storeUnit (*IdxStore, unitName, error);
246- if (!storeUnit.isValid ())
247- continue ;
248- StringRef workDir = storeUnit.getWorkingDirectory ();
249- bool cont = storeUnit.foreachInclude ([&](IndexUnitInclude inc) -> bool {
250- StringRef sourcePath = inc.getSourcePath ();
251- StringRef targetPath = inc.getTargetPath ();
252- unsigned line = inc.getSourceLine ();
253- CanonicalFilePath fullSourcePath = getCanonicalPath (sourcePath, workDir);
254- CanonicalFilePath fullTargetPath = getCanonicalPath (targetPath, workDir);
255- return receiver (fullSourcePath, fullTargetPath, line);
256- });
264+ bool cont = foreachIncludeOfUnit (unitName, receiver);
257265 if (!cont)
258266 return false ;
259267 }
@@ -314,3 +322,7 @@ bool FilePathIndex::foreachFileIncludingFile(CanonicalFilePathRef TargetPath, fu
314322bool FilePathIndex::foreachFileIncludedByFile (CanonicalFilePathRef SourcePath, function_ref<bool (CanonicalFilePathRef, unsigned int )> Receiver) {
315323 return IMPL->foreachFileIncludedByFile (SourcePath, Receiver);
316324}
325+
326+ bool FilePathIndex::foreachIncludeOfUnit (StringRef unitName, function_ref<bool (CanonicalFilePathRef sourcePath, CanonicalFilePathRef targetPath, unsigned line)> receiver) {
327+ return IMPL->foreachIncludeOfUnit (unitName, receiver);
328+ }
0 commit comments