summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/YAMLParser.cpp
diff options
context:
space:
mode:
authorSean Silva <silvas@purdue.edu>2012-11-19 23:21:47 +0000
committerSean Silva <silvas@purdue.edu>2012-11-19 23:21:47 +0000
commitaba8270dbad556b667db943f5abff63be89e2602 (patch)
tree74040216e1ea4722c01ed4ed7f98093d913c0248 /llvm/lib/Support/YAMLParser.cpp
parent3c0c536300df007927879eaed4835b0b4cc3f3e8 (diff)
downloadbcm5719-llvm-aba8270dbad556b667db943f5abff63be89e2602.tar.gz
bcm5719-llvm-aba8270dbad556b667db943f5abff63be89e2602.zip
Allow using MemoryBuffers with yaml::Stream directly.
The rationale is to get YAML filenames in diagnostics from yaml::Stream::printError -- currently the filename is hard-coded as "YAML" because there's no buffer information available. Patch by Kim Gräsman! llvm-svn: 168341
Diffstat (limited to 'llvm/lib/Support/YAMLParser.cpp')
-rw-r--r--llvm/lib/Support/YAMLParser.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/llvm/lib/Support/YAMLParser.cpp b/llvm/lib/Support/YAMLParser.cpp
index 34df636a72a..2ae33f5b996 100644
--- a/llvm/lib/Support/YAMLParser.cpp
+++ b/llvm/lib/Support/YAMLParser.cpp
@@ -252,6 +252,7 @@ namespace yaml {
class Scanner {
public:
Scanner(const StringRef Input, SourceMgr &SM);
+ Scanner(MemoryBuffer *Buffer, SourceMgr &SM_);
/// @brief Parse the next token and return it without popping it.
Token &peekNext();
@@ -708,6 +709,21 @@ 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());
+}
+
Token &Scanner::peekNext() {
// If the current token is a possible simple key, keep parsing until we
// can confirm.
@@ -1532,6 +1548,10 @@ Stream::Stream(StringRef Input, SourceMgr &SM)
: scanner(new Scanner(Input, SM))
, CurrentDoc(0) {}
+Stream::Stream(MemoryBuffer *InputBuffer, SourceMgr &SM)
+ : scanner(new Scanner(InputBuffer, SM))
+ , CurrentDoc(0) {}
+
Stream::~Stream() {}
bool Stream::failed() { return scanner->failed(); }
OpenPOWER on IntegriCloud