mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Frontend] When setting up the buffers for a CompilerInstance, allow a memory buffer to
provide the contents of a filename, based on its buffer identifier. Swift SVN r10042
This commit is contained in:
@@ -94,7 +94,24 @@ bool swift::CompilerInstance::setup(const CompilerInvocation &Invok) {
|
||||
bool MainMode = (Invocation.getInputKind() == SourceFile::Main);
|
||||
bool SILMode = (Invocation.getInputKind() == SourceFile::SIL);
|
||||
|
||||
// Add the memory buffers first, these will be associated with a filename
|
||||
// and they can replace the contents of an input filename.
|
||||
for (auto Buf : Invocation.getInputBuffers()) {
|
||||
if (SILMode)
|
||||
MainBufferIndex = BufferIDs.size();
|
||||
|
||||
// CompilerInvocation doesn't own the buffers, copy to a new buffer.
|
||||
BufferIDs.push_back(SourceMgr.addNewSourceBuffer(
|
||||
llvm::MemoryBuffer::getMemBufferCopy(Buf->getBuffer(),
|
||||
Buf->getBufferIdentifier())));
|
||||
}
|
||||
|
||||
for (auto &File : Invocation.getInputFilenames()) {
|
||||
// FIXME: Working with filenames is fragile, maybe use the real path
|
||||
// or have some kind of FileManager.
|
||||
if (SourceMgr.getIDForBufferIdentifier(File).hasValue())
|
||||
continue; // replaced by a memory buffer.
|
||||
|
||||
// Open the input file.
|
||||
llvm::OwningPtr<llvm::MemoryBuffer> InputFile;
|
||||
if (llvm::error_code Err =
|
||||
@@ -112,16 +129,6 @@ bool swift::CompilerInstance::setup(const CompilerInvocation &Invok) {
|
||||
BufferIDs.push_back(SourceMgr.addNewSourceBuffer(InputFile.take()));
|
||||
}
|
||||
|
||||
for (auto Buf : Invocation.getInputBuffers()) {
|
||||
if (SILMode)
|
||||
MainBufferIndex = BufferIDs.size();
|
||||
|
||||
// CompilerInvocation doesn't own the buffers, copy to a new buffer.
|
||||
BufferIDs.push_back(SourceMgr.addNewSourceBuffer(
|
||||
llvm::MemoryBuffer::getMemBufferCopy(Buf->getBuffer(),
|
||||
Buf->getBufferIdentifier())));
|
||||
}
|
||||
|
||||
if (MainMode && MainBufferIndex == NO_SUCH_BUFFER && BufferIDs.size() == 1)
|
||||
MainBufferIndex = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user