diff options
Diffstat (limited to 'contrib/llvm/lib/Support/YAMLParser.cpp')
-rw-r--r-- | contrib/llvm/lib/Support/YAMLParser.cpp | 60 |
1 files changed, 28 insertions, 32 deletions
diff --git a/contrib/llvm/lib/Support/YAMLParser.cpp b/contrib/llvm/lib/Support/YAMLParser.cpp index 3be02ee..4688ff1 100644 --- a/contrib/llvm/lib/Support/YAMLParser.cpp +++ b/contrib/llvm/lib/Support/YAMLParser.cpp @@ -259,8 +259,8 @@ namespace yaml { /// @brief Scans YAML tokens from a MemoryBuffer. class Scanner { public: - Scanner(const StringRef Input, SourceMgr &SM); - Scanner(MemoryBuffer *Buffer, SourceMgr &SM_); + Scanner(StringRef Input, SourceMgr &SM); + Scanner(MemoryBufferRef Buffer, SourceMgr &SM_); /// @brief Parse the next token and return it without popping it. Token &peekNext(); @@ -294,6 +294,8 @@ public: } private: + void init(MemoryBufferRef Buffer); + StringRef currentInput() { return StringRef(Current, End - Current); } @@ -469,7 +471,7 @@ private: SourceMgr &SM; /// @brief The original input. - MemoryBuffer *InputBuffer; + MemoryBufferRef InputBuffer; /// @brief The current position of the scanner. StringRef::iterator Current; @@ -699,34 +701,28 @@ std::string yaml::escape(StringRef Input) { return EscapedInput; } -Scanner::Scanner(StringRef Input, SourceMgr &sm) - : SM(sm) - , Indent(-1) - , Column(0) - , Line(0) - , FlowLevel(0) - , IsStartOfStream(true) - , IsSimpleKeyAllowed(true) - , Failed(false) { - InputBuffer = MemoryBuffer::getMemBuffer(Input, "YAML"); - SM.AddNewSourceBuffer(InputBuffer, SMLoc()); - Current = InputBuffer->getBufferStart(); - 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(StringRef Input, SourceMgr &sm) : SM(sm) { + init(MemoryBufferRef(Input, "YAML")); +} + +Scanner::Scanner(MemoryBufferRef Buffer, SourceMgr &SM_) : SM(SM_) { + init(Buffer); +} + +void Scanner::init(MemoryBufferRef Buffer) { + InputBuffer = Buffer; + Current = InputBuffer.getBufferStart(); + End = InputBuffer.getBufferEnd(); + Indent = -1; + Column = 0; + Line = 0; + FlowLevel = 0; + IsStartOfStream = true; + IsSimpleKeyAllowed = true; + Failed = false; + std::unique_ptr<MemoryBuffer> InputBufferOwner = + MemoryBuffer::getMemBuffer(Buffer); + SM.AddNewSourceBuffer(std::move(InputBufferOwner), SMLoc()); } Token &Scanner::peekNext() { @@ -1524,7 +1520,7 @@ bool Scanner::fetchMoreTokens() { Stream::Stream(StringRef Input, SourceMgr &SM) : scanner(new Scanner(Input, SM)), CurrentDoc() {} -Stream::Stream(MemoryBuffer *InputBuffer, SourceMgr &SM) +Stream::Stream(MemoryBufferRef InputBuffer, SourceMgr &SM) : scanner(new Scanner(InputBuffer, SM)), CurrentDoc() {} Stream::~Stream() {} |