]> granicus.if.org Git - clang/commitdiff
Overload SourceManager::overrideFileContents so that unconditionally passing ownershi...
authorDavid Blaikie <dblaikie@gmail.com>
Wed, 27 Aug 2014 20:54:45 +0000 (20:54 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Wed, 27 Aug 2014 20:54:45 +0000 (20:54 +0000)
Only those callers who are dynamically passing ownership should need the
3 argument form. Those accepting the default ("do pass ownership")
should do so explicitly with a unique_ptr now.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@216614 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/SourceManager.h
lib/Format/Format.cpp
lib/Frontend/CompilerInstance.cpp
lib/Index/SimpleFormatContext.h
lib/Lex/Preprocessor.cpp
lib/Serialization/ASTReader.cpp
lib/Tooling/Refactoring.cpp
unittests/Basic/SourceManagerTest.cpp
unittests/Tooling/RewriterTestContext.h

index fb65c4b28d0f8b875b371fbc9aeff49c52a994a8..8addde9d1559103c2db7b2491a5c9d0345c2c27a 100644 (file)
@@ -832,7 +832,11 @@ public:
   /// \param DoNotFree If true, then the buffer will not be freed when the
   /// source manager is destroyed.
   void overrideFileContents(const FileEntry *SourceFile,
-                            llvm::MemoryBuffer *Buffer, bool DoNotFree = false);
+                            llvm::MemoryBuffer *Buffer, bool DoNotFree);
+  void overrideFileContents(const FileEntry *SourceFile,
+                            std::unique_ptr<llvm::MemoryBuffer> Buffer) {
+    overrideFileContents(SourceFile, Buffer.release(), /*DoNotFree*/ false);
+  }
 
   /// \brief Override the given source file with another one.
   ///
index 32808b519af5ab3d9dbf408272154cc25338a726..432da61d85a0dfe3ddd3386141edaddbc165642f 100644 (file)
@@ -1996,7 +1996,7 @@ tooling::Replacements reformat(const FormatStyle &Style, StringRef Code,
       llvm::MemoryBuffer::getMemBuffer(Code, FileName);
   const clang::FileEntry *Entry =
       Files.getVirtualFile(FileName, Buf->getBufferSize(), 0);
-  SourceMgr.overrideFileContents(Entry, Buf.release());
+  SourceMgr.overrideFileContents(Entry, std::move(Buf));
   FileID ID =
       SourceMgr.createFileID(Entry, SourceLocation(), clang::SrcMgr::C_User);
   Lexer Lex(ID, SourceMgr.getBuffer(ID), SourceMgr,
index a535afdc056546b688b889de51331b287321c375..4cba26cc63293249feac6da3cea283d21459d7de 100644 (file)
@@ -727,7 +727,7 @@ bool CompilerInstance::InitializeSourceManager(const FrontendInputFile &Input,
               FileMgr.getBufferForFile(File, &ErrorStr, /*isVolatile=*/true)) {
         // Create a new virtual file that will have the correct size.
         File = FileMgr.getVirtualFile(InputFile, MB->getBufferSize(), 0);
-        SourceMgr.overrideFileContents(File, MB.release());
+        SourceMgr.overrideFileContents(File, std::move(MB));
       } else {
         Diags.Report(diag::err_cannot_open_file) << InputFile << ErrorStr;
         return false;
@@ -749,7 +749,7 @@ bool CompilerInstance::InitializeSourceManager(const FrontendInputFile &Input,
                                                    SB->getBufferSize(), 0);
     SourceMgr.setMainFileID(
         SourceMgr.createFileID(File, SourceLocation(), Kind));
-    SourceMgr.overrideFileContents(File, SB.release());
+    SourceMgr.overrideFileContents(File, std::move(SB));
   }
 
   assert(!SourceMgr.getMainFileID().isInvalid() &&
@@ -951,7 +951,7 @@ static bool compileModuleImpl(CompilerInstance &ImportingInstance,
         llvm::MemoryBuffer::getMemBuffer(InferredModuleMapContent);
     ModuleMapFile = Instance.getFileManager().getVirtualFile(
         "__inferred_module.map", InferredModuleMapContent.size(), 0);
-    SourceMgr.overrideFileContents(ModuleMapFile, ModuleMapBuffer.release());
+    SourceMgr.overrideFileContents(ModuleMapFile, std::move(ModuleMapBuffer));
   }
 
   // Construct a module-generating action. Passing through the module map is
index faf865786a522ce2da74005131d97eb29fcf8c21..080a4ad04ddf8ac3facc243562dc93fff186c4bc 100644 (file)
@@ -51,7 +51,7 @@ public:
         llvm::MemoryBuffer::getMemBuffer(Content);
     const FileEntry *Entry =
         Files.getVirtualFile(Name, Source->getBufferSize(), 0);
-    Sources.overrideFileContents(Entry, Source.release());
+    Sources.overrideFileContents(Entry, std::move(Source));
     assert(Entry != nullptr);
     return Sources.createFileID(Entry, SourceLocation(), SrcMgr::C_User);
   }
index 29956c9f584574372a16bb4d0cf552f443d290d9..1dd46b0de9b40730d8fa2b9223687533c13d9b56 100644 (file)
@@ -406,7 +406,7 @@ bool Preprocessor::SetCodeCompletionPoint(const FileEntry *File,
     char *NewPos = std::copy(Buffer->getBufferStart(), Position, NewBuf);
     *NewPos = '\0';
     std::copy(Position, Buffer->getBufferEnd(), NewPos+1);
-    SourceMgr.overrideFileContents(File, NewBuffer.release());
+    SourceMgr.overrideFileContents(File, std::move(NewBuffer));
   }
 
   return false;
index 1bee2a026b842a1ba115250f8c183e939065bc42..68faeed6a2007566b46af1d5eeb6fa069e9ac8ce 100644 (file)
@@ -1226,7 +1226,7 @@ bool ASTReader::ReadSLocEntry(int ID) {
       
       std::unique_ptr<llvm::MemoryBuffer> Buffer
         = llvm::MemoryBuffer::getMemBuffer(Blob.drop_back(1), File->getName());
-      SourceMgr.overrideFileContents(File, Buffer.release());
+      SourceMgr.overrideFileContents(File, std::move(Buffer));
     }
 
     break;
index ab16dfd35f85bac4a1d4d470ac704ef1503046e1..b2a02cb0964cb5f8f3f2fc8a0f789f0926d6c7ae 100644 (file)
@@ -186,7 +186,7 @@ std::string applyAllReplacements(StringRef Code, const Replacements &Replaces) {
       llvm::MemoryBuffer::getMemBuffer(Code, "<stdin>");
   const clang::FileEntry *Entry =
       Files.getVirtualFile("<stdin>", Buf->getBufferSize(), 0);
-  SourceMgr.overrideFileContents(Entry, Buf.release());
+  SourceMgr.overrideFileContents(Entry, std::move(Buf));
   FileID ID =
       SourceMgr.createFileID(Entry, SourceLocation(), clang::SrcMgr::C_User);
   for (Replacements::const_iterator I = Replaces.begin(), E = Replaces.end();
index dc27560b3a81dd626eb32b7088273b1af967980a..540a8051e6011a01250a6f5a5f0323cbd3808993 100644 (file)
@@ -193,7 +193,7 @@ TEST_F(SourceManagerTest, getMacroArgExpandedLocation) {
 
   const FileEntry *headerFile = FileMgr.getVirtualFile("/test-header.h",
                                                  HeaderBuf->getBufferSize(), 0);
-  SourceMgr.overrideFileContents(headerFile, HeaderBuf.release());
+  SourceMgr.overrideFileContents(headerFile, std::move(HeaderBuf));
 
   VoidModuleLoader ModLoader;
   HeaderSearch HeaderInfo(new HeaderSearchOptions, SourceMgr, Diags, LangOpts, 
@@ -291,7 +291,7 @@ TEST_F(SourceManagerTest, isBeforeInTranslationUnitWithMacroInInclude) {
 
   const FileEntry *headerFile = FileMgr.getVirtualFile("/test-header.h",
                                                  HeaderBuf->getBufferSize(), 0);
-  SourceMgr.overrideFileContents(headerFile, HeaderBuf.release());
+  SourceMgr.overrideFileContents(headerFile, std::move(HeaderBuf));
 
   VoidModuleLoader ModLoader;
   HeaderSearch HeaderInfo(new HeaderSearchOptions, SourceMgr, Diags, LangOpts, 
index bf25f8c9989b94472e8fbb50fc839c9b85a6044a..82c00582f1fac7d28c8f5556791f9dd505a66c98 100644 (file)
@@ -52,7 +52,7 @@ class RewriterTestContext {
         llvm::MemoryBuffer::getMemBuffer(Content);
     const FileEntry *Entry =
       Files.getVirtualFile(Name, Source->getBufferSize(), 0);
-    Sources.overrideFileContents(Entry, Source.release());
+    Sources.overrideFileContents(Entry, std::move(Source));
     assert(Entry != nullptr);
     return Sources.createFileID(Entry, SourceLocation(), SrcMgr::C_User);
   }