mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Use llvm::MemoryBuffer::getBufferIdentifier(). Thanks, Jordan!
Swift SVN r6745
This commit is contained in:
@@ -36,8 +36,7 @@ SerializedModuleLoader::~SerializedModuleLoader() = default;
|
|||||||
// FIXME: Copied from SourceLoader. Not bothering to fix until we decide that
|
// FIXME: Copied from SourceLoader. Not bothering to fix until we decide that
|
||||||
// the source loader search path should be the same as the module loader search
|
// the source loader search path should be the same as the module loader search
|
||||||
// path.
|
// path.
|
||||||
static std::pair<llvm::error_code, std::string>
|
static llvm::error_code findModule(ASTContext &ctx, AccessPathElem moduleID,
|
||||||
findModule(ASTContext &ctx, AccessPathElem moduleID,
|
|
||||||
llvm::OwningPtr<llvm::MemoryBuffer> &buffer){
|
llvm::OwningPtr<llvm::MemoryBuffer> &buffer){
|
||||||
llvm::SmallString<64> moduleFilename(moduleID.first.str());
|
llvm::SmallString<64> moduleFilename(moduleID.first.str());
|
||||||
moduleFilename += '.';
|
moduleFilename += '.';
|
||||||
@@ -59,14 +58,14 @@ findModule(ASTContext &ctx, AccessPathElem moduleID,
|
|||||||
llvm::sys::path::append(inputFilename, moduleFilename.str());
|
llvm::sys::path::append(inputFilename, moduleFilename.str());
|
||||||
llvm::error_code err = llvm::MemoryBuffer::getFile(inputFilename, buffer);
|
llvm::error_code err = llvm::MemoryBuffer::getFile(inputFilename, buffer);
|
||||||
if (!err)
|
if (!err)
|
||||||
return std::make_pair(err, inputFilename.str());
|
return err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Second, search in the current directory.
|
// Second, search in the current directory.
|
||||||
llvm::error_code err = llvm::MemoryBuffer::getFile(moduleFilename, buffer);
|
llvm::error_code err = llvm::MemoryBuffer::getFile(moduleFilename, buffer);
|
||||||
if (!err)
|
if (!err)
|
||||||
return std::make_pair(err, moduleFilename.str());
|
return err;
|
||||||
|
|
||||||
// If we fail, search each import search path.
|
// If we fail, search each import search path.
|
||||||
for (auto Path : ctx.ImportSearchPaths) {
|
for (auto Path : ctx.ImportSearchPaths) {
|
||||||
@@ -74,10 +73,10 @@ findModule(ASTContext &ctx, AccessPathElem moduleID,
|
|||||||
llvm::sys::path::append(inputFilename, moduleFilename.str());
|
llvm::sys::path::append(inputFilename, moduleFilename.str());
|
||||||
err = llvm::MemoryBuffer::getFile(inputFilename, buffer);
|
err = llvm::MemoryBuffer::getFile(inputFilename, buffer);
|
||||||
if (!err)
|
if (!err)
|
||||||
return std::make_pair(err, inputFilename.str());
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::make_pair(err, std::string());
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Module *makeTU(ASTContext &ctx, AccessPathElem moduleID,
|
static Module *makeTU(ASTContext &ctx, AccessPathElem moduleID,
|
||||||
@@ -130,16 +129,16 @@ Module *SerializedModuleLoader::loadModule(SourceLoc importLoc,
|
|||||||
auto moduleID = path[0];
|
auto moduleID = path[0];
|
||||||
|
|
||||||
llvm::OwningPtr<llvm::MemoryBuffer> inputFile;
|
llvm::OwningPtr<llvm::MemoryBuffer> inputFile;
|
||||||
auto ErrPath = findModule(Ctx, moduleID, inputFile);
|
if (llvm::error_code err = findModule(Ctx, moduleID, inputFile)) {
|
||||||
if (ErrPath.first) {
|
if (err.value() != llvm::errc::no_such_file_or_directory) {
|
||||||
if (ErrPath.first.value() != llvm::errc::no_such_file_or_directory) {
|
|
||||||
Ctx.Diags.diagnose(moduleID.second, diag::sema_opening_import,
|
Ctx.Diags.diagnose(moduleID.second, diag::sema_opening_import,
|
||||||
moduleID.first.str(), ErrPath.first.message());
|
moduleID.first.str(), err.message());
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
assert(inputFile);
|
assert(inputFile);
|
||||||
|
std::string DebugModuleName = inputFile->getBufferIdentifier();
|
||||||
|
|
||||||
llvm::OwningPtr<ModuleFile> loadedModuleFile;
|
llvm::OwningPtr<ModuleFile> loadedModuleFile;
|
||||||
ModuleStatus err = ModuleFile::load(std::move(inputFile), loadedModuleFile);
|
ModuleStatus err = ModuleFile::load(std::move(inputFile), loadedModuleFile);
|
||||||
@@ -163,8 +162,8 @@ Module *SerializedModuleLoader::loadModule(SourceLoc importLoc,
|
|||||||
|
|
||||||
auto comp = new (Ctx.Allocate<Component>(1)) Component();
|
auto comp = new (Ctx.Allocate<Component>(1)) Component();
|
||||||
auto module = new (Ctx) SerializedModule(Ctx, *this, moduleID.first,
|
auto module = new (Ctx) SerializedModule(Ctx, *this, moduleID.first,
|
||||||
ErrPath.second, comp,
|
DebugModuleName,
|
||||||
loadedModuleFile.get());
|
comp, loadedModuleFile.get());
|
||||||
|
|
||||||
// Whether we succeed or fail, don't try to load this module again.
|
// Whether we succeed or fail, don't try to load this module again.
|
||||||
Ctx.LoadedModules[moduleID.first.str()] = module;
|
Ctx.LoadedModules[moduleID.first.str()] = module;
|
||||||
|
|||||||
Reference in New Issue
Block a user