38 #ifndef LLVM_SUPPORT_YAMLPARSER_H
39 #define LLVM_SUPPORT_YAMLPARSER_H
50 #include <system_error>
54 class MemoryBufferRef;
62 class document_iterator;
69 bool dumpTokens(StringRef Input, raw_ostream &);
77 std::string
escape(StringRef Input);
85 std::error_code *EC =
nullptr);
88 std::error_code *EC =
nullptr);
106 std::unique_ptr<Scanner> scanner;
107 std::unique_ptr<Document> CurrentDoc;
112 virtual void anchor();
129 size_t Alignment = 16) noexcept {
134 size_t Size) noexcept {
138 void operator delete(
void *) noexcept =
delete;
168 std::unique_ptr<Document> &
Doc;
185 void anchor()
override;
200 void anchor()
override;
243 void anchor()
override;
273 void anchor()
override;
313 template <
class BaseT,
class ValueT>
315 :
public std::iterator<std::input_iterator_tag, ValueT> {
321 assert(
Base &&
Base->CurrentEntry &&
"Attempted to access end iterator!");
322 return Base->CurrentEntry;
327 "Attempted to dereference end iterator!");
328 return *
Base->CurrentEntry;
332 assert(
Base &&
Base->CurrentEntry &&
"Attempted to access end iterator!");
333 return Base->CurrentEntry;
345 assert((
Base->CurrentEntry == Other.Base->CurrentEntry)
346 &&
"Equal Bases expected to point to equal Entries");
349 return Base == Other.Base;
353 return !(
Base == Other.Base);
357 assert(
Base &&
"Attempted to advance iterator past end!");
360 if (!
Base->CurrentEntry)
366 BaseT *
Base =
nullptr;
370 template <
class CollectionType>
371 typename CollectionType::iterator
begin(CollectionType &
C) {
372 assert(C.IsAtBeginning &&
"You may only iterate over a collection once!");
373 C.IsAtBeginning =
false;
374 typename CollectionType::iterator ret(&C);
379 template <
class CollectionType>
void skip(CollectionType &
C) {
381 assert((C.IsAtBeginning || C.IsAtEnd) &&
"Cannot skip mid parse!");
383 for (
typename CollectionType::iterator i =
begin(C), e = C.end(); i != e;
396 void anchor()
override;
413 template <
class T>
friend typename T::iterator
yaml::begin(
T &);
428 bool IsAtBeginning =
true;
429 bool IsAtEnd =
false;
444 void anchor()
override;
468 template <
class T>
friend typename T::iterator
yaml::begin(
T &);
485 bool IsAtBeginning =
true;
486 bool IsAtEnd =
false;
487 bool WasPreviousTokenFlowEntry =
true;
488 Node *CurrentEntry =
nullptr;
496 void anchor()
override;
531 const std::map<StringRef, StringRef> &
getTagMap()
const {
return TagMap; }
549 std::map<StringRef, StringRef> TagMap;
553 void setError(
const Twine &Message,
Token &Location)
const;
557 bool parseDirectives();
560 void parseYAMLDirective();
563 void parseTAGDirective();
566 bool expectToken(
int TK);
576 if (isAtEnd() || Other.isAtEnd())
577 return isAtEnd() && Other.isAtEnd();
579 return Doc == Other.Doc;
584 assert(Doc &&
"incrementing iterator past the end.");
585 if (!(*Doc)->skip()) {
588 Stream &S = (*Doc)->stream;
599 bool isAtEnd()
const {
return !Doc || !*Doc; }
601 std::unique_ptr<Document> *Doc =
nullptr;
608 #endif // LLVM_SUPPORT_YAMLPARSER_H
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)
basic_collection_iterator< MappingNode, KeyValueNode > iterator
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.
static bool classof(const Node *N)
bool dumpTokens(StringRef Input, raw_ostream &)
Dump all the tokens in this stream to OS.
document_iterator()=default
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)
static const unsigned End
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.
This class represents a YAML stream potentially containing multiple documents.
StringRef getAnchor() const
Get the value of the anchor attached to this node.
bool operator==(const basic_collection_iterator &Other) const
Note on EqualityComparable:
StringRef getName() const
bool operator!=(const basic_collection_iterator &Other) const
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
static SMLoc getFromPointer(const char *Ptr)
SMRange getSourceRange() const
Stream(StringRef Input, SourceMgr &, bool ShowColors=true, std::error_code *EC=nullptr)
This keeps a reference to the string referenced by Input.
basic_collection_iterator< SequenceNode, Node > iterator
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.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned int getType() const
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.
basic_collection_iterator()=default
Abstract base class for all Nodes.