mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-09 11:25:55 +00:00
yaml::Stream doesn't need to take ownership of the buffer.
In fact, most users were already using the StringRef version. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216575 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -41,13 +41,13 @@
|
|||||||
#include "llvm/ADT/SmallString.h"
|
#include "llvm/ADT/SmallString.h"
|
||||||
#include "llvm/ADT/StringRef.h"
|
#include "llvm/ADT/StringRef.h"
|
||||||
#include "llvm/Support/Allocator.h"
|
#include "llvm/Support/Allocator.h"
|
||||||
|
#include "llvm/Support/MemoryBuffer.h"
|
||||||
#include "llvm/Support/SMLoc.h"
|
#include "llvm/Support/SMLoc.h"
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
class MemoryBuffer;
|
|
||||||
class SourceMgr;
|
class SourceMgr;
|
||||||
class raw_ostream;
|
class raw_ostream;
|
||||||
class Twine;
|
class Twine;
|
||||||
@@ -79,7 +79,7 @@ public:
|
|||||||
/// \brief This keeps a reference to the string referenced by \p Input.
|
/// \brief This keeps a reference to the string referenced by \p Input.
|
||||||
Stream(StringRef Input, SourceMgr &);
|
Stream(StringRef Input, SourceMgr &);
|
||||||
|
|
||||||
Stream(std::unique_ptr<MemoryBuffer> InputBuffer, SourceMgr &);
|
Stream(MemoryBufferRef InputBuffer, SourceMgr &);
|
||||||
~Stream();
|
~Stream();
|
||||||
|
|
||||||
document_iterator begin();
|
document_iterator begin();
|
||||||
|
@@ -260,7 +260,7 @@ namespace yaml {
|
|||||||
class Scanner {
|
class Scanner {
|
||||||
public:
|
public:
|
||||||
Scanner(const StringRef Input, SourceMgr &SM);
|
Scanner(const StringRef Input, SourceMgr &SM);
|
||||||
Scanner(std::unique_ptr<MemoryBuffer> Buffer, SourceMgr &SM_);
|
Scanner(MemoryBufferRef Buffer, SourceMgr &SM_);
|
||||||
|
|
||||||
/// @brief Parse the next token and return it without popping it.
|
/// @brief Parse the next token and return it without popping it.
|
||||||
Token &peekNext();
|
Token &peekNext();
|
||||||
@@ -294,6 +294,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void init(MemoryBufferRef Buffer);
|
||||||
|
|
||||||
StringRef currentInput() {
|
StringRef currentInput() {
|
||||||
return StringRef(Current, End - Current);
|
return StringRef(Current, End - Current);
|
||||||
}
|
}
|
||||||
@@ -469,7 +471,7 @@ private:
|
|||||||
SourceMgr &SM;
|
SourceMgr &SM;
|
||||||
|
|
||||||
/// @brief The original input.
|
/// @brief The original input.
|
||||||
MemoryBuffer *InputBuffer;
|
MemoryBufferRef InputBuffer;
|
||||||
|
|
||||||
/// @brief The current position of the scanner.
|
/// @brief The current position of the scanner.
|
||||||
StringRef::iterator Current;
|
StringRef::iterator Current;
|
||||||
@@ -699,29 +701,28 @@ std::string yaml::escape(StringRef Input) {
|
|||||||
return EscapedInput;
|
return EscapedInput;
|
||||||
}
|
}
|
||||||
|
|
||||||
Scanner::Scanner(StringRef Input, SourceMgr &sm)
|
Scanner::Scanner(StringRef Input, SourceMgr &sm) : SM(sm) {
|
||||||
: SM(sm)
|
init(MemoryBufferRef(Input, "YAML"));
|
||||||
, Indent(-1)
|
|
||||||
, Column(0)
|
|
||||||
, Line(0)
|
|
||||||
, FlowLevel(0)
|
|
||||||
, IsStartOfStream(true)
|
|
||||||
, IsSimpleKeyAllowed(true)
|
|
||||||
, Failed(false) {
|
|
||||||
std::unique_ptr<MemoryBuffer> InputBufferOwner(
|
|
||||||
MemoryBuffer::getMemBuffer(Input, "YAML"));
|
|
||||||
InputBuffer = InputBufferOwner.get();
|
|
||||||
SM.AddNewSourceBuffer(std::move(InputBufferOwner), SMLoc());
|
|
||||||
Current = InputBuffer->getBufferStart();
|
|
||||||
End = InputBuffer->getBufferEnd();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Scanner::Scanner(std::unique_ptr<MemoryBuffer> Buffer, SourceMgr &SM_)
|
Scanner::Scanner(MemoryBufferRef Buffer, SourceMgr &SM_) : SM(SM_) {
|
||||||
: SM(SM_), InputBuffer(Buffer.get()),
|
init(Buffer);
|
||||||
Current(InputBuffer->getBufferStart()), End(InputBuffer->getBufferEnd()),
|
}
|
||||||
Indent(-1), Column(0), Line(0), FlowLevel(0), IsStartOfStream(true),
|
|
||||||
IsSimpleKeyAllowed(true), Failed(false) {
|
void Scanner::init(MemoryBufferRef Buffer) {
|
||||||
SM.AddNewSourceBuffer(std::move(Buffer), SMLoc());
|
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() {
|
Token &Scanner::peekNext() {
|
||||||
@@ -1519,8 +1520,8 @@ bool Scanner::fetchMoreTokens() {
|
|||||||
Stream::Stream(StringRef Input, SourceMgr &SM)
|
Stream::Stream(StringRef Input, SourceMgr &SM)
|
||||||
: scanner(new Scanner(Input, SM)), CurrentDoc() {}
|
: scanner(new Scanner(Input, SM)), CurrentDoc() {}
|
||||||
|
|
||||||
Stream::Stream(std::unique_ptr<MemoryBuffer> InputBuffer, SourceMgr &SM)
|
Stream::Stream(MemoryBufferRef InputBuffer, SourceMgr &SM)
|
||||||
: scanner(new Scanner(std::move(InputBuffer), SM)), CurrentDoc() {}
|
: scanner(new Scanner(InputBuffer, SM)), CurrentDoc() {}
|
||||||
|
|
||||||
Stream::~Stream() {}
|
Stream::~Stream() {}
|
||||||
|
|
||||||
|
@@ -212,7 +212,7 @@ TEST(YAMLParser, DiagnosticFilenameFromBufferID) {
|
|||||||
// we get its ID as filename in diagnostics.
|
// we get its ID as filename in diagnostics.
|
||||||
std::unique_ptr<MemoryBuffer> Buffer(
|
std::unique_ptr<MemoryBuffer> Buffer(
|
||||||
MemoryBuffer::getMemBuffer("[]", "buffername.yaml"));
|
MemoryBuffer::getMemBuffer("[]", "buffername.yaml"));
|
||||||
yaml::Stream Stream(std::move(Buffer), SM);
|
yaml::Stream Stream(Buffer->getMemBufferRef(), SM);
|
||||||
Stream.printError(Stream.begin()->getRoot(), "Hello, World!");
|
Stream.printError(Stream.begin()->getRoot(), "Hello, World!");
|
||||||
EXPECT_EQ("buffername.yaml", GeneratedDiag.getFilename());
|
EXPECT_EQ("buffername.yaml", GeneratedDiag.getFilename());
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user