mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Replace llvm::OwningPtr with std::unique_ptr
It looks like llvm::OwningPtr is going to be removed soon. Swift SVN r14729
This commit is contained in:
@@ -98,8 +98,13 @@ public:
|
||||
return unsigned(BufferID);
|
||||
}
|
||||
|
||||
// FIXME: remove this overload.
|
||||
size_t addNewSourceBuffer(llvm::MemoryBuffer *Buffer);
|
||||
|
||||
size_t addNewSourceBuffer(std::unique_ptr<llvm::MemoryBuffer> Buffer) {
|
||||
return addNewSourceBuffer(Buffer.release());
|
||||
}
|
||||
|
||||
/// Returns a buffer ID for a previously added buffer with the given
|
||||
/// buffer identifier, or Nothing if there is no such buffer.
|
||||
Optional<unsigned> getIDForBufferIdentifier(StringRef BufIdentifier);
|
||||
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
/// Loads an OutputFileMap from the given \p Buffer, taking ownership
|
||||
/// of the buffer in the process.
|
||||
static std::unique_ptr<OutputFileMap>
|
||||
loadFromBuffer(llvm::MemoryBuffer *Buffer);
|
||||
loadFromBuffer(std::unique_ptr<llvm::MemoryBuffer> Buffer);
|
||||
|
||||
/// Get the map of outputs for the given \p Input, if present in the
|
||||
/// OutputFileMap. (If not present, returns nullptr.)
|
||||
@@ -62,7 +62,7 @@ private:
|
||||
/// of \p Buffer in the process.
|
||||
///
|
||||
/// \returns true on error, false on success
|
||||
bool parse(llvm::MemoryBuffer *Buffer);
|
||||
bool parse(std::unique_ptr<llvm::MemoryBuffer> Buffer);
|
||||
};
|
||||
|
||||
} // end namespace driver
|
||||
|
||||
@@ -213,8 +213,8 @@ public:
|
||||
FrontendOpts.InputFilenames.push_back(Filename);
|
||||
}
|
||||
|
||||
void addInputBuffer(llvm::MemoryBuffer *Buf) {
|
||||
FrontendOpts.InputBuffers.push_back(Buf);
|
||||
void addInputBuffer(std::unique_ptr<llvm::MemoryBuffer> Buffer) {
|
||||
FrontendOpts.InputBuffers.push_back(Buffer.release());
|
||||
}
|
||||
|
||||
void clearInputs() {
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
#ifndef SWIFT_SERIALIZEDDIAGNOSTICCONSUMER_H
|
||||
#define SWIFT_SERIALIZEDDIAGNOSTICCONSUMER_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace llvm {
|
||||
class raw_ostream;
|
||||
}
|
||||
@@ -34,7 +36,7 @@ namespace swift {
|
||||
/// ownership of the stream.
|
||||
///
|
||||
/// \returns A new diagnostic consumer that serializes diagnostics.
|
||||
DiagnosticConsumer *createConsumer(llvm::raw_ostream *OS);
|
||||
DiagnosticConsumer *createConsumer(std::unique_ptr<llvm::raw_ostream> OS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#include "swift/Basic/LLVM.h"
|
||||
#include "llvm/ADT/ArrayRef.h"
|
||||
#include "llvm/ADT/DenseMap.h"
|
||||
#include "llvm/ADT/OwningPtr.h"
|
||||
#include "llvm/ADT/TinyPtrVector.h"
|
||||
#include "llvm/Bitcode/BitstreamReader.h"
|
||||
|
||||
|
||||
@@ -11,8 +11,6 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "swift/Driver/OutputFileMap.h"
|
||||
|
||||
#include "llvm/ADT/OwningPtr.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "llvm/Support/system_error.h"
|
||||
@@ -21,25 +19,25 @@ using namespace swift;
|
||||
using namespace swift::driver;
|
||||
|
||||
std::unique_ptr<OutputFileMap> OutputFileMap::loadFromPath(StringRef Path) {
|
||||
llvm::OwningPtr<llvm::MemoryBuffer> Buffer;
|
||||
std::unique_ptr<llvm::MemoryBuffer> Buffer;
|
||||
llvm::error_code Result = llvm::MemoryBuffer::getFile(Path, Buffer);
|
||||
if (Result != 0)
|
||||
return nullptr;
|
||||
return loadFromBuffer(Buffer.take());
|
||||
return loadFromBuffer(std::move(Buffer));
|
||||
}
|
||||
|
||||
std::unique_ptr<OutputFileMap> OutputFileMap::loadFromBuffer(StringRef Data) {
|
||||
llvm::OwningPtr<llvm::MemoryBuffer> Buffer{
|
||||
std::unique_ptr<llvm::MemoryBuffer> Buffer{
|
||||
llvm::MemoryBuffer::getMemBuffer(Data)
|
||||
};
|
||||
return loadFromBuffer(Buffer.take());
|
||||
return loadFromBuffer(std::move(Buffer));
|
||||
}
|
||||
|
||||
std::unique_ptr<OutputFileMap>
|
||||
OutputFileMap::loadFromBuffer(llvm::MemoryBuffer *Buffer) {
|
||||
OutputFileMap::loadFromBuffer(std::unique_ptr<llvm::MemoryBuffer> Buffer) {
|
||||
std::unique_ptr<OutputFileMap> OFM(new OutputFileMap());
|
||||
|
||||
if (OFM->parse(Buffer))
|
||||
if (OFM->parse(std::move(Buffer)))
|
||||
return nullptr;
|
||||
|
||||
return OFM;
|
||||
@@ -91,9 +89,9 @@ void OutputFileMap::dump(llvm::raw_ostream &os, bool Sort) const {
|
||||
}
|
||||
}
|
||||
|
||||
bool OutputFileMap::parse(llvm::MemoryBuffer *Buffer) {
|
||||
bool OutputFileMap::parse(std::unique_ptr<llvm::MemoryBuffer> Buffer) {
|
||||
llvm::SourceMgr SM;
|
||||
llvm::yaml::Stream YAMLStream(Buffer, SM);
|
||||
llvm::yaml::Stream YAMLStream(Buffer.release(), SM);
|
||||
auto I = YAMLStream.begin();
|
||||
if (I == YAMLStream.end())
|
||||
return true;
|
||||
|
||||
@@ -184,7 +184,7 @@ bool swift::CompilerInstance::setup(const CompilerInvocation &Invok) {
|
||||
}
|
||||
|
||||
// Open the input file.
|
||||
llvm::OwningPtr<llvm::MemoryBuffer> InputFile;
|
||||
std::unique_ptr<llvm::MemoryBuffer> InputFile;
|
||||
if (llvm::error_code Err =
|
||||
llvm::MemoryBuffer::getFileOrSTDIN(File, InputFile)) {
|
||||
Diagnostics.diagnose(SourceLoc(), diag::error_open_input_file,
|
||||
@@ -192,7 +192,7 @@ bool swift::CompilerInstance::setup(const CompilerInvocation &Invok) {
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned BufferID = SourceMgr.addNewSourceBuffer(InputFile.take());
|
||||
unsigned BufferID = SourceMgr.addNewSourceBuffer(std::move(InputFile));
|
||||
|
||||
// Transfer ownership of the MemoryBuffer to the SourceMgr.
|
||||
BufferIDs.push_back(BufferID);
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#include "swift/Parse/Lexer.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/ADT/Twine.h"
|
||||
#include "llvm/ADT/OwningPtr.h"
|
||||
#include "llvm/ADT/DenseMap.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "llvm/ADT/IntrusiveRefCntPtr.h"
|
||||
@@ -85,8 +84,8 @@ typedef SmallVector<uint64_t, 64> RecordData;
|
||||
typedef SmallVectorImpl<uint64_t> RecordDataImpl;
|
||||
|
||||
struct SharedState : llvm::RefCountedBase<SharedState> {
|
||||
SharedState(raw_ostream *os)
|
||||
: Stream(Buffer), OS(os), EmittedAnyDiagBlocks(false) { }
|
||||
SharedState(std::unique_ptr<raw_ostream> OS)
|
||||
: Stream(Buffer), OS(std::move(OS)), EmittedAnyDiagBlocks(false) { }
|
||||
|
||||
/// \brief The byte buffer for the serialized content.
|
||||
llvm::SmallString<1024> Buffer;
|
||||
@@ -95,7 +94,7 @@ struct SharedState : llvm::RefCountedBase<SharedState> {
|
||||
llvm::BitstreamWriter Stream;
|
||||
|
||||
/// \brief The name of the diagnostics file.
|
||||
llvm::OwningPtr<raw_ostream> OS;
|
||||
std::unique_ptr<raw_ostream> OS;
|
||||
|
||||
/// \brief The set of constructed record abbreviations.
|
||||
AbbreviationMap Abbrevs;
|
||||
@@ -126,7 +125,8 @@ class SerializedDiagnosticConsumer : public DiagnosticConsumer {
|
||||
/// \brief State shared among the various clones of this diagnostic consumer.
|
||||
llvm::IntrusiveRefCntPtr<SharedState> State;
|
||||
public:
|
||||
SerializedDiagnosticConsumer(raw_ostream *OS) : State(new SharedState(OS)) {
|
||||
SerializedDiagnosticConsumer(std::unique_ptr<raw_ostream> OS)
|
||||
: State(new SharedState(std::move(OS))) {
|
||||
emitPreamble();
|
||||
}
|
||||
|
||||
@@ -195,8 +195,8 @@ private:
|
||||
}
|
||||
|
||||
namespace swift { namespace serialized_diagnostics {
|
||||
DiagnosticConsumer *createConsumer(llvm::raw_ostream *OS) {
|
||||
return new SerializedDiagnosticConsumer(OS);
|
||||
DiagnosticConsumer *createConsumer(std::unique_ptr<llvm::raw_ostream> OS) {
|
||||
return new SerializedDiagnosticConsumer(std::move(OS));
|
||||
}
|
||||
}}
|
||||
|
||||
|
||||
@@ -199,7 +199,7 @@ static std::unique_ptr<llvm::Module> performIRGeneration(IRGenOptions &Opts,
|
||||
// Bail out if there are any errors.
|
||||
if (M->Ctx.hadError()) return nullptr;
|
||||
|
||||
llvm::OwningPtr<raw_fd_ostream> RawOS;
|
||||
std::unique_ptr<raw_fd_ostream> RawOS;
|
||||
formatted_raw_ostream FormattedOS;
|
||||
if (!Opts.OutputFilename.empty()) {
|
||||
// Try to open the output file. Clobbering an existing file is fine.
|
||||
|
||||
@@ -37,29 +37,29 @@
|
||||
#include "swift/SIL/SILModule.h"
|
||||
#include "swift/SILPasses/Passes.h"
|
||||
#include "llvm/ADT/SmallPtrSet.h"
|
||||
#include "llvm/ADT/StringSwitch.h"
|
||||
#include "llvm/ADT/SmallString.h"
|
||||
#include "llvm/ADT/StringSwitch.h"
|
||||
#include "llvm/ExecutionEngine/JIT.h"
|
||||
#include "llvm/IR/DataLayout.h"
|
||||
#include "llvm/IR/LLVMContext.h"
|
||||
#include "llvm/IR/Module.h"
|
||||
#include "llvm/Linker/Linker.h"
|
||||
#include "llvm/PassManager.h"
|
||||
#include "llvm/Support/ConvertUTF.h"
|
||||
#include "llvm/Support/Debug.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
#include "llvm/Support/Host.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
#include "llvm/Support/PrettyStackTrace.h"
|
||||
#include "llvm/Support/Process.h"
|
||||
#include "llvm/Support/SaveAndRestore.h"
|
||||
#include "llvm/Support/Signals.h"
|
||||
#include "llvm/Support/system_error.h"
|
||||
#include "llvm/Support/TargetSelect.h"
|
||||
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "llvm/Support/system_error.h"
|
||||
#include "llvm/Transforms/IPO.h"
|
||||
#include "llvm/IR/DataLayout.h"
|
||||
#include "llvm/IR/LLVMContext.h"
|
||||
#include "llvm/IR/Module.h"
|
||||
#include "llvm/Linker.h"
|
||||
#include "llvm/PassManager.h"
|
||||
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
|
||||
|
||||
// FIXME: We need a more library-neutral way for frameworks to take ownership of
|
||||
// the main loop.
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#include "swift/Parse/DelayedParsingCallbacks.h"
|
||||
#include "swift/Parse/PersistentParserState.h"
|
||||
#include "swift/Basic/SourceManager.h"
|
||||
#include "llvm/ADT/OwningPtr.h"
|
||||
#include "llvm/ADT/SmallString.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
@@ -34,7 +33,7 @@ using namespace swift;
|
||||
// FIXME: Basically the same as SerializedModuleLoader.
|
||||
static llvm::error_code findModule(ASTContext &ctx, StringRef moduleID,
|
||||
SourceLoc importLoc,
|
||||
llvm::OwningPtr<llvm::MemoryBuffer> &buffer){
|
||||
std::unique_ptr<llvm::MemoryBuffer> &buffer){
|
||||
llvm::SmallString<128> inputFilename;
|
||||
|
||||
for (auto Path : ctx.SearchPathOpts.ImportSearchPaths) {
|
||||
@@ -71,7 +70,7 @@ Module *SourceLoader::loadModule(SourceLoc importLoc,
|
||||
|
||||
auto moduleID = path[0];
|
||||
|
||||
llvm::OwningPtr<llvm::MemoryBuffer> inputFile;
|
||||
std::unique_ptr<llvm::MemoryBuffer> inputFile;
|
||||
if (llvm::error_code err = findModule(Ctx, moduleID.first.str(),
|
||||
moduleID.second, inputFile)) {
|
||||
if (err.value() != llvm::errc::no_such_file_or_directory) {
|
||||
@@ -91,7 +90,7 @@ Module *SourceLoader::loadModule(SourceLoc importLoc,
|
||||
Ctx.SourceMgr.getIDForBufferIdentifier(inputFile->getBufferIdentifier()))
|
||||
bufferID = BufID.getValue();
|
||||
else
|
||||
bufferID = Ctx.SourceMgr.addNewSourceBuffer(inputFile.take());
|
||||
bufferID = Ctx.SourceMgr.addNewSourceBuffer(std::move(inputFile));
|
||||
|
||||
auto *importMod = Module::create(moduleID.first, Ctx);
|
||||
Ctx.LoadedModules[moduleID.first.str()] = importMod;
|
||||
|
||||
@@ -27,35 +27,7 @@ using namespace swift;
|
||||
|
||||
namespace {
|
||||
typedef std::pair<Identifier, SourceLoc> AccessPathElem;
|
||||
|
||||
/// An adapter class that allows a std::unique_ptr to be used as an
|
||||
/// llvm::OwningPtr.
|
||||
template <typename T>
|
||||
class OwningPtrAdapter {
|
||||
llvm::OwningPtr<T> Owner;
|
||||
std::unique_ptr<T> &Result;
|
||||
public:
|
||||
OwningPtrAdapter(std::unique_ptr<T> &result) : Result(result) {
|
||||
Owner.reset(Result.release());
|
||||
}
|
||||
|
||||
OwningPtrAdapter(const OwningPtrAdapter &other) = delete;
|
||||
OwningPtrAdapter &operator=(const OwningPtrAdapter &other) = delete;
|
||||
OwningPtrAdapter(OwningPtrAdapter &&other) = default;
|
||||
OwningPtrAdapter &operator=(OwningPtrAdapter &&other) = default;
|
||||
|
||||
~OwningPtrAdapter() {
|
||||
Result.reset(Owner.take());
|
||||
}
|
||||
operator llvm::OwningPtr<T> &() { return Owner; }
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
OwningPtrAdapter<T> makeOwningPtrAdapter(std::unique_ptr<T> &result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
} // end unnamed namespace
|
||||
|
||||
// Defined out-of-line so that we can see ~ModuleFile.
|
||||
SerializedModuleLoader::SerializedModuleLoader(ASTContext &ctx) : Ctx(ctx) {}
|
||||
@@ -74,8 +46,7 @@ static llvm::error_code findModule(ASTContext &ctx, AccessPathElem moduleID,
|
||||
for (auto path : ctx.SearchPathOpts.ImportSearchPaths) {
|
||||
inputFilename = path;
|
||||
llvm::sys::path::append(inputFilename, moduleFilename.str());
|
||||
auto err = llvm::MemoryBuffer::getFile(inputFilename.str(),
|
||||
makeOwningPtrAdapter(buffer));
|
||||
auto err = llvm::MemoryBuffer::getFile(inputFilename.str(), buffer);
|
||||
if (!err || err.value() != llvm::errc::no_such_file_or_directory)
|
||||
return err;
|
||||
}
|
||||
@@ -96,8 +67,7 @@ static llvm::error_code findModule(ASTContext &ctx, AccessPathElem moduleID,
|
||||
inputFilename = path;
|
||||
llvm::sys::path::append(inputFilename, moduleFramework.str(),
|
||||
moduleFilename.str(), archFilename.str());
|
||||
auto err = llvm::MemoryBuffer::getFile(inputFilename.str(),
|
||||
makeOwningPtrAdapter(buffer));
|
||||
auto err = llvm::MemoryBuffer::getFile(inputFilename.str(), buffer);
|
||||
if (!err || err.value() != llvm::errc::no_such_file_or_directory)
|
||||
return err;
|
||||
}
|
||||
@@ -106,8 +76,7 @@ static llvm::error_code findModule(ASTContext &ctx, AccessPathElem moduleID,
|
||||
isFramework = false;
|
||||
inputFilename = ctx.SearchPathOpts.RuntimeLibraryImportPath;
|
||||
llvm::sys::path::append(inputFilename, moduleFilename.str());
|
||||
return llvm::MemoryBuffer::getFile(inputFilename.str(),
|
||||
makeOwningPtrAdapter(buffer));
|
||||
return llvm::MemoryBuffer::getFile(inputFilename.str(), buffer);
|
||||
}
|
||||
|
||||
FileUnit *
|
||||
|
||||
@@ -298,7 +298,7 @@ int frontend_main(ArrayRef<const char *>Args,
|
||||
}
|
||||
|
||||
SerializedConsumer.reset(
|
||||
serialized_diagnostics::createConsumer(OS.release()));
|
||||
serialized_diagnostics::createConsumer(std::move(OS)));
|
||||
Instance.addDiagnosticConsumer(SerializedConsumer.get());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
#include "swift/Basic/Dwarf.h"
|
||||
#include "swift/Frontend/Frontend.h"
|
||||
#include "swift/ASTSectionImporter/ASTSectionImporter.h"
|
||||
#include "llvm/ADT/OwningPtr.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/PrettyStackTrace.h"
|
||||
#include "llvm/Support/Signals.h"
|
||||
|
||||
@@ -81,7 +81,7 @@ int main(int argc, char **argv) {
|
||||
Invocation.setImportSearchPaths(ImportPaths);
|
||||
|
||||
// Load the input file.
|
||||
llvm::OwningPtr<llvm::MemoryBuffer> InputFile;
|
||||
std::unique_ptr<llvm::MemoryBuffer> InputFile;
|
||||
if (llvm::MemoryBuffer::getFileOrSTDIN(InputFilename, InputFile)) {
|
||||
fprintf(stderr, "Error! Failed to open file: %s\n", InputFilename.c_str());
|
||||
exit(-1);
|
||||
@@ -89,9 +89,8 @@ int main(int argc, char **argv) {
|
||||
|
||||
// If it looks like we have an AST, set the source file kind to SIL and the
|
||||
// name of the module to the file's name.
|
||||
Invocation.addInputBuffer(InputFile.get());
|
||||
bool IsModule = false;
|
||||
if (SerializedModuleLoader::isSerializedAST(InputFile.get()->getBuffer())) {
|
||||
if (SerializedModuleLoader::isSerializedAST(InputFile->getBuffer())) {
|
||||
IsModule = true;
|
||||
const StringRef Stem = ModuleName.size() ?
|
||||
StringRef(ModuleName) :
|
||||
@@ -102,6 +101,7 @@ int main(int argc, char **argv) {
|
||||
Invocation.setModuleName("main");
|
||||
Invocation.setInputKind(SourceFileKind::SIL);
|
||||
}
|
||||
Invocation.addInputBuffer(std::move(InputFile));
|
||||
|
||||
CompilerInstance CI;
|
||||
PrintingDiagnosticConsumer PrintDiags;
|
||||
|
||||
@@ -237,7 +237,7 @@ int main(int argc, char **argv) {
|
||||
Invocation.setImportSearchPaths(ImportPaths);
|
||||
|
||||
// Load the input file.
|
||||
llvm::OwningPtr<llvm::MemoryBuffer> InputFile;
|
||||
std::unique_ptr<llvm::MemoryBuffer> InputFile;
|
||||
if (llvm::MemoryBuffer::getFileOrSTDIN(InputFilename, InputFile)) {
|
||||
fprintf(stderr, "Error! Failed to open file: %s\n", InputFilename.c_str());
|
||||
exit(-1);
|
||||
@@ -245,7 +245,6 @@ int main(int argc, char **argv) {
|
||||
|
||||
// If it looks like we have an AST, set the source file kind to SIL and the
|
||||
// name of the module to the file's name.
|
||||
Invocation.addInputBuffer(InputFile.get());
|
||||
bool IsModule = false;
|
||||
if (SerializedModuleLoader::isSerializedAST(InputFile.get()->getBuffer())) {
|
||||
IsModule = true;
|
||||
@@ -258,6 +257,7 @@ int main(int argc, char **argv) {
|
||||
Invocation.setModuleName("main");
|
||||
Invocation.setInputKind(SourceFileKind::SIL);
|
||||
}
|
||||
Invocation.addInputBuffer(std::move(InputFile));
|
||||
|
||||
CompilerInstance CI;
|
||||
PrintingDiagnosticConsumer PrintDiags;
|
||||
|
||||
Reference in New Issue
Block a user