зеркало из https://github.com/microsoft/clang-1.git
Use error_code instead of std::string* for MemoryBuffer.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@121378 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
8f1509446f
Коммит
3a321e23f6
|
@ -24,6 +24,7 @@
|
|||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
#include "llvm/Support/system_error.h"
|
||||
#include "llvm/Config/config.h"
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
@ -400,13 +401,16 @@ void FileManager::FixupRelativePath(llvm::sys::Path &path,
|
|||
|
||||
llvm::MemoryBuffer *FileManager::
|
||||
getBufferForFile(const FileEntry *Entry, std::string *ErrorStr) {
|
||||
llvm::error_code ec;
|
||||
if (FileSystemOpts.WorkingDir.empty()) {
|
||||
const char *Filename = Entry->getName();
|
||||
// If the file is already open, use the open file descriptor.
|
||||
if (Entry->FD != -1) {
|
||||
llvm::MemoryBuffer *Buf =
|
||||
llvm::MemoryBuffer::getOpenFile(Entry->FD, Filename, ErrorStr,
|
||||
llvm::MemoryBuffer::getOpenFile(Entry->FD, Filename, ec,
|
||||
Entry->getSize());
|
||||
if (Buf == 0 && ErrorStr)
|
||||
*ErrorStr = ec.message();
|
||||
// getOpenFile will have closed the file descriptor, don't reuse or
|
||||
// reclose it.
|
||||
Entry->FD = -1;
|
||||
|
@ -414,23 +418,38 @@ getBufferForFile(const FileEntry *Entry, std::string *ErrorStr) {
|
|||
}
|
||||
|
||||
// Otherwise, open the file.
|
||||
return llvm::MemoryBuffer::getFile(Filename, ErrorStr, Entry->getSize());
|
||||
llvm::MemoryBuffer *res =
|
||||
llvm::MemoryBuffer::getFile(Filename, ec, Entry->getSize());
|
||||
if (res == 0 && ErrorStr)
|
||||
*ErrorStr = ec.message();
|
||||
return res;
|
||||
}
|
||||
|
||||
llvm::sys::Path FilePath(Entry->getName());
|
||||
FixupRelativePath(FilePath, FileSystemOpts);
|
||||
return llvm::MemoryBuffer::getFile(FilePath.c_str(), ErrorStr,
|
||||
Entry->getSize());
|
||||
llvm::MemoryBuffer *res =
|
||||
llvm::MemoryBuffer::getFile(FilePath.c_str(), ec, Entry->getSize());
|
||||
if (res == 0 && ErrorStr)
|
||||
*ErrorStr = ec.message();
|
||||
return res;
|
||||
}
|
||||
|
||||
llvm::MemoryBuffer *FileManager::
|
||||
getBufferForFile(llvm::StringRef Filename, std::string *ErrorStr) {
|
||||
if (FileSystemOpts.WorkingDir.empty())
|
||||
return llvm::MemoryBuffer::getFile(Filename, ErrorStr);
|
||||
|
||||
llvm::error_code ec;
|
||||
if (FileSystemOpts.WorkingDir.empty()) {
|
||||
llvm::MemoryBuffer *res = llvm::MemoryBuffer::getFile(Filename, ec);
|
||||
if (res == 0 && ErrorStr)
|
||||
*ErrorStr = ec.message();
|
||||
return res;
|
||||
}
|
||||
|
||||
llvm::sys::Path FilePath(Filename);
|
||||
FixupRelativePath(FilePath, FileSystemOpts);
|
||||
return llvm::MemoryBuffer::getFile(FilePath.c_str(), ErrorStr);
|
||||
llvm::MemoryBuffer *res = llvm::MemoryBuffer::getFile(FilePath.c_str(), ec);
|
||||
if (res == 0 && ErrorStr)
|
||||
*ErrorStr = ec.message();
|
||||
return res;
|
||||
}
|
||||
|
||||
/// getStatValue - Get the 'stat' information for the specified path, using the
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
#include "llvm/Support/system_error.h"
|
||||
|
||||
#include <cstdlib> // ::getenv
|
||||
|
||||
|
@ -1243,8 +1244,9 @@ static bool HasMultilib(llvm::Triple::ArchType Arch, enum LinuxDistro Distro) {
|
|||
}
|
||||
|
||||
static LinuxDistro DetectLinuxDistro(llvm::Triple::ArchType Arch) {
|
||||
llvm::error_code ec;
|
||||
llvm::OwningPtr<const llvm::MemoryBuffer>
|
||||
LsbRelease(llvm::MemoryBuffer::getFile("/etc/lsb-release"));
|
||||
LsbRelease(llvm::MemoryBuffer::getFile("/etc/lsb-release", ec));
|
||||
if (LsbRelease) {
|
||||
llvm::StringRef Data = LsbRelease.get()->getBuffer();
|
||||
llvm::SmallVector<llvm::StringRef, 8> Lines;
|
||||
|
@ -1263,7 +1265,7 @@ static LinuxDistro DetectLinuxDistro(llvm::Triple::ArchType Arch) {
|
|||
}
|
||||
|
||||
llvm::OwningPtr<const llvm::MemoryBuffer>
|
||||
RHRelease(llvm::MemoryBuffer::getFile("/etc/redhat-release"));
|
||||
RHRelease(llvm::MemoryBuffer::getFile("/etc/redhat-release", ec));
|
||||
if (RHRelease) {
|
||||
llvm::StringRef Data = RHRelease.get()->getBuffer();
|
||||
if (Data.startswith("Fedora release 14 (Laughlin)"))
|
||||
|
@ -1274,7 +1276,7 @@ static LinuxDistro DetectLinuxDistro(llvm::Triple::ArchType Arch) {
|
|||
}
|
||||
|
||||
llvm::OwningPtr<const llvm::MemoryBuffer>
|
||||
DebianVersion(llvm::MemoryBuffer::getFile("/etc/debian_version"));
|
||||
DebianVersion(llvm::MemoryBuffer::getFile("/etc/debian_version", ec));
|
||||
if (DebianVersion) {
|
||||
llvm::StringRef Data = DebianVersion.get()->getBuffer();
|
||||
if (Data[0] == '5')
|
||||
|
@ -1285,7 +1287,7 @@ static LinuxDistro DetectLinuxDistro(llvm::Triple::ArchType Arch) {
|
|||
}
|
||||
|
||||
llvm::OwningPtr<const llvm::MemoryBuffer>
|
||||
SuseRelease(llvm::MemoryBuffer::getFile("/etc/SuSE-release"));
|
||||
SuseRelease(llvm::MemoryBuffer::getFile("/etc/SuSE-release", ec));
|
||||
if (SuseRelease) {
|
||||
llvm::StringRef Data = SuseRelease.get()->getBuffer();
|
||||
if (Data.startswith("openSUSE 11.3"))
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include "llvm/Support/Path.h"
|
||||
#include "llvm/Support/Program.h"
|
||||
#include "llvm/Support/Signals.h"
|
||||
#include "llvm/Support/system_error.h"
|
||||
using namespace clang;
|
||||
|
||||
CompilerInstance::CompilerInstance()
|
||||
|
@ -486,8 +487,10 @@ bool CompilerInstance::InitializeSourceManager(llvm::StringRef InputFile,
|
|||
}
|
||||
SourceMgr.createMainFileID(File);
|
||||
} else {
|
||||
llvm::MemoryBuffer *SB = llvm::MemoryBuffer::getSTDIN();
|
||||
llvm::error_code ec;
|
||||
llvm::MemoryBuffer *SB = llvm::MemoryBuffer::getSTDIN(ec);
|
||||
if (!SB) {
|
||||
// FIXME: Give ec.message() in this diag.
|
||||
Diags.Report(diag::err_fe_error_reading_stdin);
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "llvm/ADT/StringExtras.h"
|
||||
#include "llvm/ADT/StringMap.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include "llvm/Support/system_error.h"
|
||||
using namespace clang;
|
||||
using namespace clang::io;
|
||||
|
||||
|
@ -436,9 +437,12 @@ static void InvalidPTH(Diagnostic &Diags, const char *Msg) {
|
|||
|
||||
PTHManager *PTHManager::Create(const std::string &file, Diagnostic &Diags) {
|
||||
// Memory map the PTH file.
|
||||
llvm::OwningPtr<llvm::MemoryBuffer> File(llvm::MemoryBuffer::getFile(file));
|
||||
llvm::error_code ec;
|
||||
llvm::OwningPtr<llvm::MemoryBuffer> File(
|
||||
llvm::MemoryBuffer::getFile(file, ec));
|
||||
|
||||
if (!File) {
|
||||
// FIXME: Add ec.message() to this diag.
|
||||
Diags.Report(diag::err_invalid_pth_file) << file;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
#include "llvm/Support/system_error.h"
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <cstdio>
|
||||
|
@ -2275,9 +2276,12 @@ ASTReader::ASTReadResult ASTReader::ReadASTCore(llvm::StringRef FileName,
|
|||
//
|
||||
// FIXME: This shouldn't be here, we should just take a raw_ostream.
|
||||
std::string ErrStr;
|
||||
if (FileName == "-")
|
||||
F.Buffer.reset(llvm::MemoryBuffer::getSTDIN(&ErrStr));
|
||||
else
|
||||
llvm::error_code ec;
|
||||
if (FileName == "-") {
|
||||
F.Buffer.reset(llvm::MemoryBuffer::getSTDIN(ec));
|
||||
if (ec)
|
||||
ErrStr = ec.message();
|
||||
} else
|
||||
F.Buffer.reset(FileMgr.getBufferForFile(FileName, &ErrStr));
|
||||
if (!F.Buffer) {
|
||||
Error(ErrStr.c_str());
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include "llvm/Support/Host.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
#include "llvm/Support/Signals.h"
|
||||
#include "llvm/Support/system_error.h"
|
||||
#include "llvm/Target/TargetAsmBackend.h"
|
||||
#include "llvm/Target/TargetAsmParser.h"
|
||||
#include "llvm/Target/TargetData.h"
|
||||
|
@ -224,8 +225,10 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts, Diagnostic &Diags) {
|
|||
return false;
|
||||
}
|
||||
|
||||
MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(Opts.InputFile, &Error);
|
||||
error_code ec;
|
||||
MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(Opts.InputFile, ec);
|
||||
if (Buffer == 0) {
|
||||
Error = ec.message();
|
||||
Diags.Report(diag::err_fe_error_reading) << Opts.InputFile;
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include "llvm/Support/Path.h"
|
||||
#include "llvm/Support/Program.h"
|
||||
#include "llvm/Support/Signals.h"
|
||||
#include "llvm/Support/system_error.h"
|
||||
using namespace clang;
|
||||
using namespace clang::driver;
|
||||
|
||||
|
@ -181,7 +182,8 @@ static void ExpandArgsFromBuf(const char *Arg,
|
|||
llvm::SmallVectorImpl<const char*> &ArgVector,
|
||||
std::set<std::string> &SavedStrings) {
|
||||
const char *FName = Arg + 1;
|
||||
llvm::MemoryBuffer *MemBuf = llvm::MemoryBuffer::getFile(FName);
|
||||
llvm::error_code ec;
|
||||
llvm::MemoryBuffer *MemBuf = llvm::MemoryBuffer::getFile(FName, ec);
|
||||
if (!MemBuf) {
|
||||
ArgVector.push_back(SaveStringInSet(SavedStrings, Arg));
|
||||
return;
|
||||
|
|
Загрузка…
Ссылка в новой задаче