Skip to content

Commit 1cd4f4a

Browse files
committed
[Serialization] Intro ModularizationError::getSourceLoc
This service provides a path to the loaded swiftmodule file and synthesizes pseudo-Swift code representing the reference.
1 parent 2f03c95 commit 1cd4f4a

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/Serialization/Deserialization.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,21 @@ SourceLoc ModuleFile::getSourceLoc() const {
189189
return SourceMgr.getLocForBufferStart(*bufferID);
190190
}
191191

192+
SourceLoc ModularizationError::getSourceLoc() const {
193+
auto &SourceMgr = referenceModule->getContext().Diags.SourceMgr;
194+
auto filename = referenceModule->getModuleFilename();
195+
196+
// Synthesize some context. We don't have an actual decl here
197+
// so try to print a simple representation of the reference.
198+
std::string S;
199+
llvm::raw_string_ostream OS(S);
200+
OS << expectedModule->getName() << "." << name;
201+
202+
// If we enable these remarks by default we may want to reuse these buffers.
203+
auto bufferID = SourceMgr.addMemBufferCopy(S, filename);
204+
return SourceMgr.getLocForBufferStart(bufferID);
205+
}
206+
192207
void
193208
ModularizationError::diagnose(const ModuleFile *MF,
194209
DiagnosticBehavior limit) const {

lib/Serialization/DeserializationErrors.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,8 @@ class ModularizationError : public llvm::ErrorInfo<ModularizationError> {
402402
path.print(OS);
403403
}
404404

405+
SourceLoc getSourceLoc() const;
406+
405407
std::error_code convertToErrorCode() const override {
406408
return llvm::inconvertibleErrorCode();
407409
}

0 commit comments

Comments
 (0)