llvm.org GIT mirror llvm / b5a6adc
Convert an ownership comment with std::uinque_ptr. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@215855 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 6 years ago
3 changed file(s) with 13 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
7878 /// \brief This keeps a reference to the string referenced by \p Input.
7979 Stream(StringRef Input, SourceMgr &);
8080
81 /// \brief This takes ownership of \p InputBuffer.
82 Stream(MemoryBuffer *InputBuffer, SourceMgr &);
81 Stream(std::unique_ptr InputBuffer, SourceMgr &);
8382 ~Stream();
8483
8584 document_iterator begin();
259259 class Scanner {
260260 public:
261261 Scanner(const StringRef Input, SourceMgr &SM);
262 Scanner(MemoryBuffer *Buffer, SourceMgr &SM_);
262 Scanner(std::unique_ptr Buffer, SourceMgr &SM_);
263263
264264 /// @brief Parse the next token and return it without popping it.
265265 Token &peekNext();
713713 End = InputBuffer->getBufferEnd();
714714 }
715715
716 Scanner::Scanner(MemoryBuffer *Buffer, SourceMgr &SM_)
717 : SM(SM_)
718 , InputBuffer(Buffer)
719 , Current(InputBuffer->getBufferStart())
720 , End(InputBuffer->getBufferEnd())
721 , Indent(-1)
722 , Column(0)
723 , Line(0)
724 , FlowLevel(0)
725 , IsStartOfStream(true)
726 , IsSimpleKeyAllowed(true)
727 , Failed(false) {
728 SM.AddNewSourceBuffer(InputBuffer, SMLoc());
716 Scanner::Scanner(std::unique_ptr Buffer, SourceMgr &SM_)
717 : SM(SM_), InputBuffer(Buffer.get()),
718 Current(InputBuffer->getBufferStart()), End(InputBuffer->getBufferEnd()),
719 Indent(-1), Column(0), Line(0), FlowLevel(0), IsStartOfStream(true),
720 IsSimpleKeyAllowed(true), Failed(false) {
721 SM.AddNewSourceBuffer(Buffer.release(), SMLoc());
729722 }
730723
731724 Token &Scanner::peekNext() {
15231516 Stream::Stream(StringRef Input, SourceMgr &SM)
15241517 : scanner(new Scanner(Input, SM)), CurrentDoc() {}
15251518
1526 Stream::Stream(MemoryBuffer *InputBuffer, SourceMgr &SM)
1527 : scanner(new Scanner(InputBuffer, SM)), CurrentDoc() {}
1519 Stream::Stream(std::unique_ptr InputBuffer, SourceMgr &SM)
1520 : scanner(new Scanner(std::move(InputBuffer), SM)), CurrentDoc() {}
15281521
15291522 Stream::~Stream() {}
15301523
209209
210210 // When we construct a YAML stream over a named buffer,
211211 // we get its ID as filename in diagnostics.
212 MemoryBuffer* Buffer = MemoryBuffer::getMemBuffer("[]", "buffername.yaml");
213 yaml::Stream Stream(Buffer, SM);
212 std::unique_ptr Buffer(
213 MemoryBuffer::getMemBuffer("[]", "buffername.yaml"));
214 yaml::Stream Stream(std::move(Buffer), SM);
214215 Stream.printError(Stream.begin()->getRoot(), "Hello, World!");
215216 EXPECT_EQ("buffername.yaml", GeneratedDiag.getFilename());
216217 }