36#ifndef LLVM_SUPPORT_YAMLPARSER_H
37#define LLVM_SUPPORT_YAMLPARSER_H
50#include <system_error>
61class document_iterator;
68bool dumpTokens(StringRef Input, raw_ostream &);
79std::string
escape(StringRef Input,
bool EscapePrintable =
true);
82std::optional<bool>
parseBool(StringRef S);
90 std::error_code *EC =
nullptr);
93 std::error_code *EC =
nullptr);
114 std::unique_ptr<Scanner> scanner;
115 std::unique_ptr<Document> CurrentDoc;
120 virtual void anchor();
142 size_t Alignment = 16)
noexcept {
147 size_t Size)
noexcept {
151 void operator delete(
void *)
noexcept =
delete;
181 std::unique_ptr<Document> &
Doc;
198 void anchor()
override;
213 void anchor()
override;
261 void anchor()
override;
291 void anchor()
override;
345 assert(Base && Base->CurrentEntry &&
"Attempted to access end iterator!");
346 return Base->CurrentEntry;
350 assert(Base && Base->CurrentEntry &&
351 "Attempted to dereference end iterator!");
352 return *Base->CurrentEntry;
356 assert(Base && Base->CurrentEntry &&
"Attempted to access end iterator!");
357 return Base->CurrentEntry;
368 if (Base && (Base ==
Other.Base)) {
369 assert((Base->CurrentEntry ==
Other.Base->CurrentEntry)
370 &&
"Equal Bases expected to point to equal Entries");
373 return Base ==
Other.Base;
377 return !(Base ==
Other.Base);
381 assert(Base &&
"Attempted to advance iterator past end!");
384 if (!Base->CurrentEntry)
390 BaseT *Base =
nullptr;
394template <
class CollectionType>
395typename CollectionType::iterator begin(CollectionType &
C) {
396 assert(
C.IsAtBeginning &&
"You may only iterate over a collection once!");
397 C.IsAtBeginning =
false;
398 typename CollectionType::iterator ret(&
C);
403template <
class CollectionType>
void skip(CollectionType &
C) {
405 assert((
C.IsAtBeginning ||
C.IsAtEnd) &&
"Cannot skip mid parse!");
407 for (
typename CollectionType::iterator i = begin(
C), e =
C.end(); i != e;
420 void anchor()
override;
452 bool IsAtBeginning =
true;
453 bool IsAtEnd =
false;
468 void anchor()
override;
509 bool IsAtBeginning =
true;
510 bool IsAtEnd =
false;
511 bool WasPreviousTokenFlowEntry =
true;
512 Node *CurrentEntry =
nullptr;
520 void anchor()
override;
554 const std::map<StringRef, StringRef> &
getTagMap()
const {
return TagMap; }
572 std::map<StringRef, StringRef> TagMap;
576 void setError(
const Twine &Message,
Token &Location)
const;
580 bool parseDirectives();
583 void parseYAMLDirective();
586 void parseTAGDirective();
589 bool expectToken(
int TK);
599 if (isAtEnd() ||
Other.isAtEnd())
600 return isAtEnd() &&
Other.isAtEnd();
602 return Doc ==
Other.Doc;
605 return !(*
this ==
Other);
609 assert(Doc &&
"incrementing iterator past the end.");
610 if (!(*Doc)->skip()) {
613 Stream &S = (*Doc)->stream;
624 bool isAtEnd()
const {
return !Doc || !*Doc; }
626 std::unique_ptr<Document> *Doc =
nullptr;
This file defines the BumpPtrAllocator interface.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Allocate memory in an ever growing pool, as if by bump-pointer.
Represents a location in source code.
static SMLoc getFromPointer(const char *Ptr)
Represents a range in source code.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
StringRef - Represent a constant reference to a string, i.e.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM Value Representation.
Represents an alias to a Node with an anchor.
AliasNode(std::unique_ptr< Document > &D, StringRef Val)
static bool classof(const Node *N)
StringRef getName() const
A block scalar node is an opaque datum that can be presented as a series of zero or more Unicode scal...
static bool classof(const Node *N)
BlockScalarNode(std::unique_ptr< Document > &D, StringRef Anchor, StringRef Tag, StringRef Value, StringRef RawVal)
StringRef getValue() const
Gets the value of this node as a StringRef.
A YAML Stream is a sequence of Documents.
Node * parseBlockNode()
Root for parsing a node. Returns a single node.
const std::map< StringRef, StringRef > & getTagMap() const
bool skip()
Finish parsing the current document and return true if there are more.
Node * getRoot()
Parse and return the root level node.
Node * getValue()
Parse and return the value.
static bool classof(const Node *N)
Node * getKey()
Parse and return the key.
KeyValueNode(std::unique_ptr< Document > &D)
Represents a YAML map created from either a block map for a flow map.
@ MT_Inline
An inline mapping node is used for "[key: value]".
static bool classof(const Node *N)
basic_collection_iterator< MappingNode, KeyValueNode > iterator
Abstract base class for all Nodes.
StringRef getRawTag() const
Get the tag as it was written in the document.
unsigned int getType() const
std::string getVerbatimTag() const
Get the verbatium tag for a given Node.
std::unique_ptr< Document > & Doc
Node(const Node &)=delete
StringRef getAnchor() const
Get the value of the anchor attached to this node.
void setSourceRange(SMRange SR)
Node(unsigned int Type, std::unique_ptr< Document > &, StringRef Anchor, StringRef Tag)
BumpPtrAllocator & getAllocator()
SMRange getSourceRange() const
void operator=(const Node &)=delete
void setError(const Twine &Message, Token &Location) const
NullNode(std::unique_ptr< Document > &D)
static bool classof(const Node *N)
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)
ScalarNode(std::unique_ptr< Document > &D, StringRef Anchor, StringRef Tag, StringRef Val)
StringRef getRawValue() const
StringRef getValue(SmallVectorImpl< char > &Storage) const
Gets the value of this node as a StringRef.
Represents a YAML sequence created from either a block sequence for a flow sequence.
static bool classof(const Node *N)
basic_collection_iterator< SequenceNode, Node > iterator
This class represents a YAML stream potentially containing multiple documents.
document_iterator begin()
void printError(Node *N, const Twine &Msg, SourceMgr::DiagKind Kind=SourceMgr::DK_Error)
This is an iterator abstraction over YAML collections shared by both sequences and maps.
bool operator==(const basic_collection_iterator &Other) const
Note on EqualityComparable:
basic_collection_iterator & operator++()
ValueT & operator*() const
bool operator!=(const basic_collection_iterator &Other) const
std::input_iterator_tag iterator_category
std::ptrdiff_t difference_type
basic_collection_iterator(BaseT *B)
ValueT * operator->() const
basic_collection_iterator()=default
Iterator abstraction for Documents over a Stream.
document_iterator operator++()
document_iterator(std::unique_ptr< Document > &D)
bool operator==(const document_iterator &Other) const
bool operator!=(const document_iterator &Other) const
document_iterator()=default
std::unique_ptr< Document > & operator->()
@ C
The default llvm calling convention, compatible with C.
bool dumpTokens(StringRef Input, raw_ostream &)
Dump all the tokens in this stream to OS.
std::optional< bool > parseBool(StringRef S)
Parse S as a bool according to https://yaml.org/type/bool.html.
bool scanTokens(StringRef Input)
Scans all tokens in input without outputting anything.
void skip(CollectionType &C)
CollectionType::iterator begin(CollectionType &C)
std::string escape(StringRef Input, bool EscapePrintable=true)
Escape Input for a double quoted scalar; if EscapePrintable is true, all UTF8 sequences will be escap...
This is an optimization pass for GlobalISel generic memory operations.
Determine the kind of a node from its type.
Token - A single YAML token.