[cfe-commits] r121956 - in /cfe/trunk: lib/Basic/FileManager.cpp lib/Driver/ToolChains.cpp lib/Frontend/CompilerInstance.cpp lib/Lex/PTHLexer.cpp lib/Serialization/ASTReader.cpp tools/driver/cc1as_main.cpp tools/driver/driver.cpp

Michael J. Spencer bigcheesegs at gmail.com
Wed Dec 15 19:28:14 PST 2010


Author: mspencer
Date: Wed Dec 15 21:28:14 2010
New Revision: 121956

URL: http://llvm.org/viewvc/llvm-project?rev=121956&view=rev
Log:
MemoryBuffer API update.

Modified:
    cfe/trunk/lib/Basic/FileManager.cpp
    cfe/trunk/lib/Driver/ToolChains.cpp
    cfe/trunk/lib/Frontend/CompilerInstance.cpp
    cfe/trunk/lib/Lex/PTHLexer.cpp
    cfe/trunk/lib/Serialization/ASTReader.cpp
    cfe/trunk/tools/driver/cc1as_main.cpp
    cfe/trunk/tools/driver/driver.cpp

Modified: cfe/trunk/lib/Basic/FileManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=121956&r1=121955&r2=121956&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/FileManager.cpp (original)
+++ cfe/trunk/lib/Basic/FileManager.cpp Wed Dec 15 21:28:14 2010
@@ -401,55 +401,54 @@
 
 llvm::MemoryBuffer *FileManager::
 getBufferForFile(const FileEntry *Entry, std::string *ErrorStr) {
+  llvm::OwningPtr<llvm::MemoryBuffer> Result;
   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, ec,
-                                        Entry->getSize());
-      if (Buf == 0 && ErrorStr)
+      ec = llvm::MemoryBuffer::getOpenFile(Entry->FD, Filename, Result,
+                                           Entry->getSize());
+      if (ErrorStr)
         *ErrorStr = ec.message();
       // getOpenFile will have closed the file descriptor, don't reuse or
       // reclose it.
       Entry->FD = -1;
-      return Buf;
+      return Result.take();
     }
 
     // Otherwise, open the file.
-    llvm::MemoryBuffer *res =
-      llvm::MemoryBuffer::getFile(Filename, ec, Entry->getSize());
-    if (res == 0 && ErrorStr)
+    ec = llvm::MemoryBuffer::getFile(Filename, Result, Entry->getSize());
+    if (ec && ErrorStr)
       *ErrorStr = ec.message();
-    return res;
+    return Result.take();
   }
   
   llvm::sys::Path FilePath(Entry->getName());
   FixupRelativePath(FilePath, FileSystemOpts);
-  llvm::MemoryBuffer *res =
-    llvm::MemoryBuffer::getFile(FilePath.c_str(), ec, Entry->getSize());
-  if (res == 0 && ErrorStr)
+  ec = llvm::MemoryBuffer::getFile(FilePath.c_str(), Result, Entry->getSize());
+  if (ec && ErrorStr)
     *ErrorStr = ec.message();
-  return res;
+  return Result.take();
 }
 
 llvm::MemoryBuffer *FileManager::
 getBufferForFile(llvm::StringRef Filename, std::string *ErrorStr) {
+  llvm::OwningPtr<llvm::MemoryBuffer> Result;
   llvm::error_code ec;
   if (FileSystemOpts.WorkingDir.empty()) {
-    llvm::MemoryBuffer *res = llvm::MemoryBuffer::getFile(Filename, ec);
-    if (res == 0 && ErrorStr)
+    ec = llvm::MemoryBuffer::getFile(Filename, Result);
+    if (ec && ErrorStr)
       *ErrorStr = ec.message();
-    return res;
+    return Result.take();
   }
 
   llvm::sys::Path FilePath(Filename);
   FixupRelativePath(FilePath, FileSystemOpts);
-  llvm::MemoryBuffer *res = llvm::MemoryBuffer::getFile(FilePath.c_str(), ec);
-  if (res == 0 && ErrorStr)
+  ec = llvm::MemoryBuffer::getFile(FilePath.c_str(), Result);
+  if (ec && ErrorStr)
     *ErrorStr = ec.message();
-  return res;
+  return Result.take();
 }
 
 /// getStatValue - Get the 'stat' information for the specified path, using the

Modified: cfe/trunk/lib/Driver/ToolChains.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=121956&r1=121955&r2=121956&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains.cpp Wed Dec 15 21:28:14 2010
@@ -1244,11 +1244,9 @@
 }
 
 static LinuxDistro DetectLinuxDistro(llvm::Triple::ArchType Arch) {
-  llvm::error_code ec;
-  llvm::OwningPtr<const llvm::MemoryBuffer>
-    LsbRelease(llvm::MemoryBuffer::getFile("/etc/lsb-release", ec));
-  if (LsbRelease) {
-    llvm::StringRef Data = LsbRelease.get()->getBuffer();
+  llvm::OwningPtr<llvm::MemoryBuffer> File;
+  if (!llvm::MemoryBuffer::getFile("/etc/lsb-release", File)) {
+    llvm::StringRef Data = File.get()->getBuffer();
     llvm::SmallVector<llvm::StringRef, 8> Lines;
     Data.split(Lines, "\n");
     for (unsigned int i = 0, s = Lines.size(); i < s; ++ i) {
@@ -1257,17 +1255,15 @@
       else if (Lines[i] == "DISTRIB_CODENAME=lucid")
         return UbuntuLucid;
       else if (Lines[i] == "DISTRIB_CODENAME=jaunty")
-	return UbuntuJaunty;
+        return UbuntuJaunty;
       else if (Lines[i] == "DISTRIB_CODENAME=karmic")
         return UbuntuKarmic;
     }
     return UnknownDistro;
   }
 
-  llvm::OwningPtr<const llvm::MemoryBuffer>
-    RHRelease(llvm::MemoryBuffer::getFile("/etc/redhat-release", ec));
-  if (RHRelease) {
-    llvm::StringRef Data = RHRelease.get()->getBuffer();
+  if (!llvm::MemoryBuffer::getFile("/etc/redhat-release", File)) {
+    llvm::StringRef Data = File.get()->getBuffer();
     if (Data.startswith("Fedora release 14 (Laughlin)"))
       return Fedora14;
     else if (Data.startswith("Fedora release 13 (Goddard)"))
@@ -1275,10 +1271,8 @@
     return UnknownDistro;
   }
 
-  llvm::OwningPtr<const llvm::MemoryBuffer>
-    DebianVersion(llvm::MemoryBuffer::getFile("/etc/debian_version", ec));
-  if (DebianVersion) {
-    llvm::StringRef Data = DebianVersion.get()->getBuffer();
+  if (!llvm::MemoryBuffer::getFile("/etc/debian_version", File)) {
+    llvm::StringRef Data = File.get()->getBuffer();
     if (Data[0] == '5')
       return DebianLenny;
     else if (Data.startswith("squeeze/sid"))
@@ -1286,10 +1280,8 @@
     return UnknownDistro;
   }
 
-  llvm::OwningPtr<const llvm::MemoryBuffer>
-    SuseRelease(llvm::MemoryBuffer::getFile("/etc/SuSE-release", ec));
-  if (SuseRelease) {
-    llvm::StringRef Data = SuseRelease.get()->getBuffer();
+  if (!llvm::MemoryBuffer::getFile("/etc/SuSE-release", File)) {
+    llvm::StringRef Data = File.get()->getBuffer();
     if (Data.startswith("openSUSE 11.3"))
       return OpenSuse11_3;
     return UnknownDistro;

Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=121956&r1=121955&r2=121956&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Wed Dec 15 21:28:14 2010
@@ -487,9 +487,8 @@
     }
     SourceMgr.createMainFileID(File);
   } else {
-    llvm::error_code ec;
-    llvm::MemoryBuffer *SB = llvm::MemoryBuffer::getSTDIN(ec);
-    if (!SB) {
+    llvm::OwningPtr<llvm::MemoryBuffer> SB;
+    if (llvm::MemoryBuffer::getSTDIN(SB)) {
       // FIXME: Give ec.message() in this diag.
       Diags.Report(diag::err_fe_error_reading_stdin);
       return false;
@@ -497,7 +496,7 @@
     const FileEntry *File = FileMgr.getVirtualFile(SB->getBufferIdentifier(),
                                                    SB->getBufferSize(), 0);
     SourceMgr.createMainFileID(File);
-    SourceMgr.overrideFileContents(File, SB);
+    SourceMgr.overrideFileContents(File, SB.take());
   }
 
   assert(!SourceMgr.getMainFileID().isInvalid() &&

Modified: cfe/trunk/lib/Lex/PTHLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PTHLexer.cpp?rev=121956&r1=121955&r2=121956&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PTHLexer.cpp (original)
+++ cfe/trunk/lib/Lex/PTHLexer.cpp Wed Dec 15 21:28:14 2010
@@ -437,11 +437,9 @@
 
 PTHManager *PTHManager::Create(const std::string &file, Diagnostic &Diags) {
   // Memory map the PTH file.
-  llvm::error_code ec;
-  llvm::OwningPtr<llvm::MemoryBuffer> File(
-    llvm::MemoryBuffer::getFile(file, ec));
+  llvm::OwningPtr<llvm::MemoryBuffer> File;
 
-  if (!File) {
+  if (llvm::MemoryBuffer::getFile(file, File)) {
     // FIXME: Add ec.message() to this diag.
     Diags.Report(diag::err_invalid_pth_file) << file;
     return 0;

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=121956&r1=121955&r2=121956&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Wed Dec 15 21:28:14 2010
@@ -2278,7 +2278,7 @@
   std::string ErrStr;
   llvm::error_code ec;
   if (FileName == "-") {
-    F.Buffer.reset(llvm::MemoryBuffer::getSTDIN(ec));
+    ec = llvm::MemoryBuffer::getSTDIN(F.Buffer);
     if (ec)
       ErrStr = ec.message();
   } else

Modified: cfe/trunk/tools/driver/cc1as_main.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/cc1as_main.cpp?rev=121956&r1=121955&r2=121956&view=diff
==============================================================================
--- cfe/trunk/tools/driver/cc1as_main.cpp (original)
+++ cfe/trunk/tools/driver/cc1as_main.cpp Wed Dec 15 21:28:14 2010
@@ -228,13 +228,13 @@
     return false;
   }
 
-  error_code ec;
-  MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(Opts.InputFile, ec);
-  if (Buffer == 0) {
+  OwningPtr<MemoryBuffer> BufferPtr;
+  if (error_code ec = MemoryBuffer::getFileOrSTDIN(Opts.InputFile, BufferPtr)) {
     Error = ec.message();
     Diags.Report(diag::err_fe_error_reading) << Opts.InputFile;
     return false;
   }
+  MemoryBuffer *Buffer = BufferPtr.take();
 
   SourceMgr SrcMgr;
 

Modified: cfe/trunk/tools/driver/driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/driver.cpp?rev=121956&r1=121955&r2=121956&view=diff
==============================================================================
--- cfe/trunk/tools/driver/driver.cpp (original)
+++ cfe/trunk/tools/driver/driver.cpp Wed Dec 15 21:28:14 2010
@@ -182,9 +182,8 @@
                               llvm::SmallVectorImpl<const char*> &ArgVector,
                               std::set<std::string> &SavedStrings) {
   const char *FName = Arg + 1;
-  llvm::error_code ec;
-  llvm::MemoryBuffer *MemBuf = llvm::MemoryBuffer::getFile(FName, ec);
-  if (!MemBuf) {
+  llvm::OwningPtr<llvm::MemoryBuffer> MemBuf;
+  if (llvm::MemoryBuffer::getFile(FName, MemBuf)) {
     ArgVector.push_back(SaveStringInSet(SavedStrings, Arg));
     return;
   }
@@ -235,7 +234,6 @@
     }
     CurArg.push_back(*P);
   }
-  delete MemBuf;
 }
 
 static void ExpandArgv(int argc, const char **argv,





More information about the cfe-commits mailing list