diff --git a/include/llvm/Support/YAMLParser.h b/include/llvm/Support/YAMLParser.h index c39874cbd2c..d1167e5f35d 100644 --- a/include/llvm/Support/YAMLParser.h +++ b/include/llvm/Support/YAMLParser.h @@ -79,8 +79,7 @@ public: /// \brief This keeps a reference to the string referenced by \p Input. Stream(StringRef Input, SourceMgr &); - /// \brief This takes ownership of \p InputBuffer. - Stream(MemoryBuffer *InputBuffer, SourceMgr &); + Stream(std::unique_ptr InputBuffer, SourceMgr &); ~Stream(); document_iterator begin(); diff --git a/lib/Support/YAMLParser.cpp b/lib/Support/YAMLParser.cpp index 3be02ee9fb9..01cd926297a 100644 --- a/lib/Support/YAMLParser.cpp +++ b/lib/Support/YAMLParser.cpp @@ -260,7 +260,7 @@ namespace yaml { class Scanner { public: Scanner(const StringRef Input, SourceMgr &SM); - Scanner(MemoryBuffer *Buffer, SourceMgr &SM_); + Scanner(std::unique_ptr Buffer, SourceMgr &SM_); /// @brief Parse the next token and return it without popping it. Token &peekNext(); @@ -714,19 +714,12 @@ Scanner::Scanner(StringRef Input, SourceMgr &sm) End = InputBuffer->getBufferEnd(); } -Scanner::Scanner(MemoryBuffer *Buffer, SourceMgr &SM_) - : SM(SM_) - , InputBuffer(Buffer) - , Current(InputBuffer->getBufferStart()) - , End(InputBuffer->getBufferEnd()) - , Indent(-1) - , Column(0) - , Line(0) - , FlowLevel(0) - , IsStartOfStream(true) - , IsSimpleKeyAllowed(true) - , Failed(false) { - SM.AddNewSourceBuffer(InputBuffer, SMLoc()); +Scanner::Scanner(std::unique_ptr Buffer, SourceMgr &SM_) + : SM(SM_), InputBuffer(Buffer.get()), + Current(InputBuffer->getBufferStart()), End(InputBuffer->getBufferEnd()), + Indent(-1), Column(0), Line(0), FlowLevel(0), IsStartOfStream(true), + IsSimpleKeyAllowed(true), Failed(false) { + SM.AddNewSourceBuffer(Buffer.release(), SMLoc()); } Token &Scanner::peekNext() { @@ -1524,8 +1517,8 @@ bool Scanner::fetchMoreTokens() { Stream::Stream(StringRef Input, SourceMgr &SM) : scanner(new Scanner(Input, SM)), CurrentDoc() {} -Stream::Stream(MemoryBuffer *InputBuffer, SourceMgr &SM) - : scanner(new Scanner(InputBuffer, SM)), CurrentDoc() {} +Stream::Stream(std::unique_ptr InputBuffer, SourceMgr &SM) + : scanner(new Scanner(std::move(InputBuffer), SM)), CurrentDoc() {} Stream::~Stream() {} diff --git a/unittests/Support/YAMLParserTest.cpp b/unittests/Support/YAMLParserTest.cpp index cd8b9f735d7..1a5188a3018 100644 --- a/unittests/Support/YAMLParserTest.cpp +++ b/unittests/Support/YAMLParserTest.cpp @@ -210,8 +210,9 @@ TEST(YAMLParser, DiagnosticFilenameFromBufferID) { // When we construct a YAML stream over a named buffer, // we get its ID as filename in diagnostics. - MemoryBuffer* Buffer = MemoryBuffer::getMemBuffer("[]", "buffername.yaml"); - yaml::Stream Stream(Buffer, SM); + std::unique_ptr Buffer( + MemoryBuffer::getMemBuffer("[]", "buffername.yaml")); + yaml::Stream Stream(std::move(Buffer), SM); Stream.printError(Stream.begin()->getRoot(), "Hello, World!"); EXPECT_EQ("buffername.yaml", GeneratedDiag.getFilename()); }