mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-04-04 10:30:01 +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:
parent
7132e325d5
commit
34806d20dd
@ -41,13 +41,13 @@
|
||||
#include "llvm/ADT/SmallString.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/Support/Allocator.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include "llvm/Support/SMLoc.h"
|
||||
#include <limits>
|
||||
#include <map>
|
||||
#include <utility>
|
||||
|
||||
namespace llvm {
|
||||
class MemoryBuffer;
|
||||
class SourceMgr;
|
||||
class raw_ostream;
|
||||
class Twine;
|
||||
@ -79,7 +79,7 @@ public:
|
||||
/// \brief This keeps a reference to the string referenced by \p Input.
|
||||
Stream(StringRef Input, SourceMgr &);
|
||||
|
||||
Stream(std::unique_ptr<MemoryBuffer> InputBuffer, SourceMgr &);
|
||||
Stream(MemoryBufferRef InputBuffer, SourceMgr &);
|
||||
~Stream();
|
||||
|
||||
document_iterator begin();
|
||||
|
@ -260,7 +260,7 @@ namespace yaml {
|
||||
class Scanner {
|
||||
public:
|
||||
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.
|
||||
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,29 +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) {
|
||||
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(StringRef Input, SourceMgr &sm) : SM(sm) {
|
||||
init(MemoryBufferRef(Input, "YAML"));
|
||||
}
|
||||
|
||||
Scanner::Scanner(std::unique_ptr<MemoryBuffer> 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(std::move(Buffer), SMLoc());
|
||||
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() {
|
||||
@ -1519,8 +1520,8 @@ bool Scanner::fetchMoreTokens() {
|
||||
Stream::Stream(StringRef Input, SourceMgr &SM)
|
||||
: scanner(new Scanner(Input, SM)), CurrentDoc() {}
|
||||
|
||||
Stream::Stream(std::unique_ptr<MemoryBuffer> InputBuffer, SourceMgr &SM)
|
||||
: scanner(new Scanner(std::move(InputBuffer), SM)), CurrentDoc() {}
|
||||
Stream::Stream(MemoryBufferRef InputBuffer, SourceMgr &SM)
|
||||
: scanner(new Scanner(InputBuffer, SM)), CurrentDoc() {}
|
||||
|
||||
Stream::~Stream() {}
|
||||
|
||||
|
@ -212,7 +212,7 @@ TEST(YAMLParser, DiagnosticFilenameFromBufferID) {
|
||||
// we get its ID as filename in diagnostics.
|
||||
std::unique_ptr<MemoryBuffer> Buffer(
|
||||
MemoryBuffer::getMemBuffer("[]", "buffername.yaml"));
|
||||
yaml::Stream Stream(std::move(Buffer), SM);
|
||||
yaml::Stream Stream(Buffer->getMemBufferRef(), SM);
|
||||
Stream.printError(Stream.begin()->getRoot(), "Hello, World!");
|
||||
EXPECT_EQ("buffername.yaml", GeneratedDiag.getFilename());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user