mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Merge remote-tracking branch 'origin/main' into rebranch
This commit is contained in:
@@ -959,6 +959,41 @@ Optional<CommentInfo> ModuleFile::getCommentForDecl(const Decl *D) const {
|
||||
return getCommentForDeclByUSR(USRBuffer.str());
|
||||
}
|
||||
|
||||
void ModuleFile::collectBasicSourceFileInfo(
|
||||
llvm::function_ref<void(const BasicSourceFileInfo &)> callback) const {
|
||||
if (Core->SourceFileListData.empty())
|
||||
return;
|
||||
assert(!Core->SourceLocsTextData.empty());
|
||||
|
||||
auto *Cursor = Core->SourceFileListData.bytes_begin();
|
||||
auto *End = Core->SourceFileListData.bytes_end();
|
||||
while (Cursor < End) {
|
||||
// FilePath (byte offset in 'SourceLocsTextData').
|
||||
auto fileID = endian::readNext<uint32_t, little, unaligned>(Cursor);
|
||||
// InterfaceHash (fixed length string).
|
||||
auto fpStr = StringRef{reinterpret_cast<const char *>(Cursor),
|
||||
Fingerprint::DIGEST_LENGTH};
|
||||
Cursor += Fingerprint::DIGEST_LENGTH;
|
||||
// LastModified (nanoseconds since epoch).
|
||||
auto timestamp = endian::readNext<uint64_t, little, unaligned>(Cursor);
|
||||
// FileSize (num of bytes).
|
||||
auto fileSize = endian::readNext<uint64_t, little, unaligned>(Cursor);
|
||||
|
||||
assert(fileID < Core->SourceLocsTextData.size());
|
||||
auto filePath = Core->SourceLocsTextData.substr(fileID);
|
||||
size_t terminatorOffset = filePath.find('\0');
|
||||
filePath = filePath.slice(0, terminatorOffset);
|
||||
|
||||
BasicSourceFileInfo info;
|
||||
info.FilePath = filePath;
|
||||
info.InterfaceHash = Fingerprint::fromString(fpStr);
|
||||
info.LastModified =
|
||||
llvm::sys::TimePoint<>(std::chrono::nanoseconds(timestamp));
|
||||
info.FileSize = fileSize;
|
||||
callback(info);
|
||||
}
|
||||
}
|
||||
|
||||
Optional<BasicDeclLocs>
|
||||
ModuleFile::getBasicDeclLocsForDecl(const Decl *D) const {
|
||||
assert(D);
|
||||
|
||||
Reference in New Issue
Block a user