diff options
Diffstat (limited to 'contrib/llvm/lib/Support/YAMLParser.cpp')
-rw-r--r-- | contrib/llvm/lib/Support/YAMLParser.cpp | 90 |
1 files changed, 31 insertions, 59 deletions
diff --git a/contrib/llvm/lib/Support/YAMLParser.cpp b/contrib/llvm/lib/Support/YAMLParser.cpp index 620841c..c17a6f6 100644 --- a/contrib/llvm/lib/Support/YAMLParser.cpp +++ b/contrib/llvm/lib/Support/YAMLParser.cpp @@ -12,12 +12,12 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/YAMLParser.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/Twine.h" -#include "llvm/ADT/ilist.h" -#include "llvm/ADT/ilist_node.h" +#include "llvm/ADT/AllocatorList.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/SourceMgr.h" @@ -108,7 +108,7 @@ void SequenceNode::anchor() {} void AliasNode::anchor() {} /// Token - A single YAML token. -struct Token : ilist_node<Token> { +struct Token { enum TokenKind { TK_Error, // Uninitialized token. TK_StreamStart, @@ -147,40 +147,7 @@ struct Token : ilist_node<Token> { } } -namespace llvm { -template<> -struct ilist_sentinel_traits<Token> { - Token *createSentinel() const { - return &Sentinel; - } - static void destroySentinel(Token*) {} - - Token *provideInitialHead() const { return createSentinel(); } - Token *ensureHead(Token*) const { return createSentinel(); } - static void noteHead(Token*, Token*) {} - -private: - mutable Token Sentinel; -}; - -template<> -struct ilist_node_traits<Token> { - Token *createNode(const Token &V) { - return new (Alloc.Allocate<Token>()) Token(V); - } - static void deleteNode(Token *V) { V->~Token(); } - - void addNodeToList(Token *) {} - void removeNodeFromList(Token *) {} - void transferNodesFromList(ilist_node_traits & /*SrcTraits*/, - ilist_iterator<Token> /*first*/, - ilist_iterator<Token> /*last*/) {} - - BumpPtrAllocator Alloc; -}; -} - -typedef ilist<Token> TokenQueueT; +typedef llvm::BumpPtrList<Token> TokenQueueT; namespace { /// @brief This struct is used to track simple keys. @@ -265,8 +232,10 @@ namespace yaml { /// @brief Scans YAML tokens from a MemoryBuffer. class Scanner { public: - Scanner(StringRef Input, SourceMgr &SM, bool ShowColors = true); - Scanner(MemoryBufferRef Buffer, SourceMgr &SM_, bool ShowColors = true); + Scanner(StringRef Input, SourceMgr &SM, bool ShowColors = true, + std::error_code *EC = nullptr); + Scanner(MemoryBufferRef Buffer, SourceMgr &SM_, bool ShowColors = true, + std::error_code *EC = nullptr); /// @brief Parse the next token and return it without popping it. Token &peekNext(); @@ -283,6 +252,10 @@ public: if (Current >= End) Current = End - 1; + // propagate the error if possible + if (EC) + *EC = make_error_code(std::errc::invalid_argument); + // Don't print out more errors after the first one we encounter. The rest // are just the result of the first, and have no meaning. if (!Failed) @@ -393,10 +366,7 @@ private: /// @brief Scan ns-uri-char[39]s starting at Cur. /// /// This updates Cur and Column while scanning. - /// - /// @returns A StringRef starting at Cur which covers the longest contiguous - /// sequence of ns-uri-char. - StringRef scan_ns_uri_char(); + void scan_ns_uri_char(); /// @brief Consume a minimal well-formed code unit subsequence starting at /// \a Cur. Return false if it is not the same Unicode scalar value as @@ -564,6 +534,8 @@ private: /// @brief Potential simple keys. SmallVector<SimpleKey, 4> SimpleKeys; + + std::error_code *EC; }; } // end namespace yaml @@ -758,13 +730,15 @@ std::string yaml::escape(StringRef Input) { return EscapedInput; } -Scanner::Scanner(StringRef Input, SourceMgr &sm, bool ShowColors) - : SM(sm), ShowColors(ShowColors) { +Scanner::Scanner(StringRef Input, SourceMgr &sm, bool ShowColors, + std::error_code *EC) + : SM(sm), ShowColors(ShowColors), EC(EC) { init(MemoryBufferRef(Input, "YAML")); } -Scanner::Scanner(MemoryBufferRef Buffer, SourceMgr &SM_, bool ShowColors) - : SM(SM_), ShowColors(ShowColors) { +Scanner::Scanner(MemoryBufferRef Buffer, SourceMgr &SM_, bool ShowColors, + std::error_code *EC) + : SM(SM_), ShowColors(ShowColors), EC(EC) { init(Buffer); } @@ -802,8 +776,7 @@ Token &Scanner::peekNext() { removeStaleSimpleKeyCandidates(); SimpleKey SK; SK.Tok = TokenQueue.begin(); - if (std::find(SimpleKeys.begin(), SimpleKeys.end(), SK) - == SimpleKeys.end()) + if (!is_contained(SimpleKeys, SK)) break; else NeedMore = true; @@ -819,9 +792,8 @@ Token Scanner::getNext() { // There cannot be any referenced Token's if the TokenQueue is empty. So do a // quick deallocation of them all. - if (TokenQueue.empty()) { - TokenQueue.Alloc.Reset(); - } + if (TokenQueue.empty()) + TokenQueue.resetAlloc(); return Ret; } @@ -918,8 +890,7 @@ static bool is_ns_word_char(const char C) { || (C >= 'A' && C <= 'Z'); } -StringRef Scanner::scan_ns_uri_char() { - StringRef::iterator Start = Current; +void Scanner::scan_ns_uri_char() { while (true) { if (Current == End) break; @@ -935,7 +906,6 @@ StringRef Scanner::scan_ns_uri_char() { } else break; } - return StringRef(Start, Current - Start); } bool Scanner::consume(uint32_t Expected) { @@ -1766,11 +1736,13 @@ bool Scanner::fetchMoreTokens() { return false; } -Stream::Stream(StringRef Input, SourceMgr &SM, bool ShowColors) - : scanner(new Scanner(Input, SM, ShowColors)), CurrentDoc() {} +Stream::Stream(StringRef Input, SourceMgr &SM, bool ShowColors, + std::error_code *EC) + : scanner(new Scanner(Input, SM, ShowColors, EC)), CurrentDoc() {} -Stream::Stream(MemoryBufferRef InputBuffer, SourceMgr &SM, bool ShowColors) - : scanner(new Scanner(InputBuffer, SM, ShowColors)), CurrentDoc() {} +Stream::Stream(MemoryBufferRef InputBuffer, SourceMgr &SM, bool ShowColors, + std::error_code *EC) + : scanner(new Scanner(InputBuffer, SM, ShowColors, EC)), CurrentDoc() {} Stream::~Stream() {} |