Skip to content

Commit 008047f

Browse files
committed
[Serialization] Intro ModuleFile::getSourceLoc()
Generate a fake empty buffer to return a SourceLoc pointing to the beginning of a swiftmodule file.
1 parent 478c653 commit 008047f

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/Serialization/Deserialization.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,15 @@ void ModuleFile::fatal(llvm::Error error) const {
179179
Core->fatal(diagnoseFatal(std::move(error)));
180180
}
181181

182+
SourceLoc ModuleFile::getSourceLoc() const {
183+
auto &SourceMgr = getContext().Diags.SourceMgr;
184+
auto filename = getModuleFilename();
185+
auto bufferID = SourceMgr.getIDForBufferIdentifier(filename);
186+
if (!bufferID)
187+
bufferID = SourceMgr.addMemBufferCopy(StringRef(), filename);
188+
return SourceMgr.getLocForBufferStart(*bufferID);
189+
}
190+
182191
llvm::Error ModuleFile::diagnoseFatal(llvm::Error error) const {
183192
if (FileContext)
184193
getContext().Diags.diagnose(SourceLoc(), diag::serialization_fatal,

lib/Serialization/ModuleFile.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,9 @@ class ModuleFile
667667
getTransitiveLoadingBehavior(const Dependency &dependency,
668668
bool forTestable) const;
669669

670+
/// Generate a \c SourceLoc pointing at the loaded swiftmodule file.
671+
SourceLoc getSourceLoc() const;
672+
670673
/// Returns `true` if there is a buffer that might contain source code where
671674
/// other parts of the compiler could have emitted diagnostics, to indicate
672675
/// that the object must be kept alive as long as the diagnostics exist.

0 commit comments

Comments
 (0)