38 #ifndef LLVM_SUPPORT_YAMLPARSER_H
39 #define LLVM_SUPPORT_YAMLPARSER_H
49 class MemoryBufferRef;
56 class document_iterator;
64 bool dumpTokens(StringRef Input, raw_ostream &);
72 std::string
escape(StringRef Input);
96 std::unique_ptr<Scanner> scanner;
97 std::unique_ptr<Document> CurrentDoc;
104 virtual void anchor();
148 size_t Alignment = 16)
throw() {
149 return Alloc.Allocate(Size, Alignment);
153 Alloc.Deallocate(Ptr, Size);
157 std::unique_ptr<Document> &
Doc;
160 void operator delete(
void *)
throw() {}
176 void anchor()
override;
191 void anchor()
override;
234 void anchor()
override;
264 void anchor()
override;
305 template <
class BaseT,
class ValueT>
307 :
public std::iterator<std::forward_iterator_tag, ValueT> {
313 assert(Base && Base->CurrentEntry &&
"Attempted to access end iterator!");
314 return Base->CurrentEntry;
318 assert(Base && Base->CurrentEntry &&
319 "Attempted to dereference end iterator!");
320 return *Base->CurrentEntry;
323 operator ValueT *()
const {
324 assert(Base && Base->CurrentEntry &&
"Attempted to access end iterator!");
325 return Base->CurrentEntry;
329 if (Base != Other.Base)
331 return (Base && Other.Base) &&
332 Base->CurrentEntry != Other.Base->CurrentEntry;
336 assert(Base &&
"Attempted to advance iterator past end!");
339 if (!Base->CurrentEntry)
349 template <
class CollectionType>
350 typename CollectionType::iterator
begin(CollectionType &C) {
351 assert(C.IsAtBeginning &&
"You may only iterate over a collection once!");
352 C.IsAtBeginning =
false;
353 typename CollectionType::iterator ret(&C);
358 template <
class CollectionType>
void skip(CollectionType &C) {
360 assert((C.IsAtBeginning || C.IsAtEnd) &&
"Cannot skip mid parse!");
362 for (
typename CollectionType::iterator i =
begin(C), e = C.end(); i != e;
375 void anchor()
override;
387 IsAtEnd(
false), CurrentEntry(nullptr) {}
391 template <
class T>
friend typename T::iterator
yaml::begin(
T &);
422 void anchor()
override;
442 WasPreviousTokenFlowEntry(
true),
443 CurrentEntry(nullptr) {}
447 template <
class T>
friend typename T::iterator
yaml::begin(
T &);
466 bool WasPreviousTokenFlowEntry;
475 void anchor()
override;
510 const std::map<StringRef, StringRef> &
getTagMap()
const {
return TagMap; }
528 std::map<StringRef, StringRef> TagMap;
532 void setError(
const Twine &Message,
Token &Location)
const;
536 bool parseDirectives();
539 void parseYAMLDirective();
542 void parseTAGDirective();
545 bool expectToken(
int TK);
555 if (isAtEnd() || Other.isAtEnd())
556 return isAtEnd() && Other.isAtEnd();
558 return Doc == Other.Doc;
563 assert(Doc &&
"incrementing iterator past the end.");
564 if (!(*Doc)->skip()) {
567 Stream &S = (*Doc)->stream;
578 bool isAtEnd()
const {
return !Doc || !*Doc; }
580 std::unique_ptr<Document> *Doc;
static bool classof(const Node *N)
document_iterator operator++()
Represents a range in source code.
AliasNode(std::unique_ptr< Document > &D, StringRef Val)
const std::map< StringRef, StringRef > & getTagMap() const
std::unique_ptr< Document > & Doc
std::string getVerbatimTag() const
Get the verbatium tag for a given Node.
SequenceNode(std::unique_ptr< Document > &D, StringRef Anchor, StringRef Tag, SequenceType ST)
Node(unsigned int Type, std::unique_ptr< Document > &, StringRef Anchor, StringRef Tag)
bool scanTokens(StringRef Input)
Scans all tokens in input without outputting anything.
This is an iterator abstraction over YAML collections shared by both sequences and maps...
StringRef getValue(SmallVectorImpl< char > &Storage) const
Gets the value of this node as a StringRef.
StringRef getRawTag() const
Get the tag as it was written in the document.
Represents a YAML sequence created from either a block sequence for a flow sequence.
Node * getKey()
Parse and return the key.
KeyValueNode(std::unique_ptr< Document > &D)
document_iterator begin()
Represents an alias to a Node with an anchor.
void skip(CollectionType &C)
static bool classof(const Node *N)
static bool classof(const Node *N)
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
void setError(const Twine &Message, Token &Location) const
std::unique_ptr< Document > & operator->()
StringRef getRawValue() const
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
StringRef getValue() const
Gets the value of this node as a StringRef.
document_iterator(std::unique_ptr< Document > &D)
static bool classof(const Node *N)
BlockScalarNode(std::unique_ptr< Document > &D, StringRef Anchor, StringRef Tag, StringRef Value, StringRef RawVal)
ScalarNode(std::unique_ptr< Document > &D, StringRef Anchor, StringRef Tag, StringRef Val)
CollectionType::iterator begin(CollectionType &C)
Node * getRoot()
Parse and return the root level node.
basic_collection_iterator< SequenceNode, Node > iterator
static bool classof(const Node *N)
bool dumpTokens(StringRef Input, raw_ostream &)
Dump all the tokens in this stream to OS.
The instances of the Type class are immutable: once they are created, they are never changed...
void printError(Node *N, const Twine &Msg)
Allocate memory in an ever growing pool, as if by bump-pointer.
std::string escape(StringRef Input)
Escape Input for a double quoted scalar.
Document(Stream &ParentStream)
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling...
BumpPtrAllocator & getAllocator()
A scalar node is an opaque datum that can be presented as a series of zero or more Unicode scalar val...
static bool classof(const Node *N)
void setSourceRange(SMRange SR)
ValueT * operator->() const
Node * getValue()
Parse and return the value.
basic_collection_iterator(BaseT *B)
bool skip()
Finish parsing the current document and return true if there are more.
basic_collection_iterator()
This class represents a YAML stream potentially containing multiple documents.
StringRef getAnchor() const
Get the value of the anchor attached to this node.
Stream(StringRef Input, SourceMgr &, bool ShowColors=true)
This keeps a reference to the string referenced by Input.
StringRef getName() const
bool operator!=(const basic_collection_iterator &Other) const
static SMLoc getFromPointer(const char *Ptr)
SMRange getSourceRange() const
static bool classof(const Node *N)
Token - A single YAML token.
A block scalar node is an opaque datum that can be presented as a series of zero or more Unicode scal...
Represents a YAML map created from either a block map for a flow map.
ValueT & operator*() const
Iterator abstraction for Documents over a Stream.
unsigned int getType() const
basic_collection_iterator< MappingNode, KeyValueNode > iterator
LLVM Value Representation.
NullNode(std::unique_ptr< Document > &D)
StringRef - Represent a constant reference to a string, i.e.
bool operator==(const document_iterator &Other)
basic_collection_iterator & operator++()
Represents a location in source code.
bool operator!=(const document_iterator &Other)
An inline mapping node is used for "[key: value]".
Node * parseBlockNode()
Root for parsing a node. Returns a single node.
MappingNode(std::unique_ptr< Document > &D, StringRef Anchor, StringRef Tag, MappingType MT)
A YAML Stream is a sequence of Documents.
Abstract base class for all Nodes.