37#ifndef LLVM_SUPPORT_YAMLPARSER_H
38#define LLVM_SUPPORT_YAMLPARSER_H
52#include <system_error>
92 std::error_code *EC =
nullptr);
95 bool ShowColors =
true, std::error_code *EC =
nullptr);
116 std::unique_ptr<Scanner> scanner;
117 std::unique_ptr<Document> CurrentDoc;
122 virtual void anchor();
144 size_t Alignment = 16)
noexcept {
149 size_t Size)
noexcept {
153 void operator delete(
void *)
noexcept =
delete;
165 std::string getVerbatimTag()
const;
173 Node *parseBlockNode();
175 void setError(
const Twine &Message,
Token &Location)
const;
180 unsigned int getType()
const {
return TypeID; }
183 std::unique_ptr<Document> &
Doc;
200 void anchor()
override;
215 void anchor()
override;
263 void anchor()
override;
293 void anchor()
override;
347 assert(Base && Base->CurrentEntry &&
"Attempted to access end iterator!");
348 return Base->CurrentEntry;
352 assert(Base && Base->CurrentEntry &&
353 "Attempted to dereference end iterator!");
354 return *Base->CurrentEntry;
358 assert(Base && Base->CurrentEntry &&
"Attempted to access end iterator!");
359 return Base->CurrentEntry;
370 if (Base && (Base ==
Other.Base)) {
371 assert((Base->CurrentEntry ==
Other.Base->CurrentEntry)
372 &&
"Equal Bases expected to point to equal Entries");
375 return Base ==
Other.Base;
379 return !(Base ==
Other.Base);
383 assert(Base &&
"Attempted to advance iterator past end!");
386 if (!Base->CurrentEntry)
392 BaseT *
Base =
nullptr;
396template <
class CollectionType>
397typename CollectionType::iterator
begin(CollectionType &
C) {
398 assert(
C.IsAtBeginning &&
"You may only iterate over a collection once!");
399 C.IsAtBeginning =
false;
400 typename CollectionType::iterator ret(&
C);
405template <
class CollectionType>
void skip(CollectionType &
C) {
407 assert((
C.IsAtBeginning ||
C.IsAtEnd) &&
"Cannot skip mid parse!");
409 for (
typename CollectionType::iterator i =
begin(
C), e =
C.end(); i != e;
422 void anchor()
override;
454 bool IsAtBeginning =
true;
455 bool IsAtEnd =
false;
470 void anchor()
override;
510 SequenceType SeqType;
511 bool IsAtBeginning =
true;
512 bool IsAtEnd =
false;
513 bool WasPreviousTokenFlowEntry =
true;
514 Node *CurrentEntry =
nullptr;
522 void anchor()
override;
556 const std::map<StringRef, StringRef> &
getTagMap()
const {
return TagMap; }
574 std::map<StringRef, StringRef> TagMap;
578 void setError(
const Twine &Message,
Token &Location)
const;
582 bool parseDirectives();
585 void parseYAMLDirective();
588 void parseTAGDirective();
591 bool expectToken(
int TK);
601 if (isAtEnd() ||
Other.isAtEnd())
602 return isAtEnd() &&
Other.isAtEnd();
604 return Doc ==
Other.Doc;
607 return !(*
this ==
Other);
611 assert(Doc &&
"incrementing iterator past the end.");
612 if (!(*Doc)->skip()) {
615 Stream &S = (*Doc)->stream;
626 bool isAtEnd()
const {
return !Doc || !*Doc; }
628 std::unique_ptr<Document> *Doc =
nullptr;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the BumpPtrAllocator interface.
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
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.
This class implements an extremely fast bulk output stream that can only output to a stream.
AliasNode(std::unique_ptr< Document > &D, StringRef Val)
static bool classof(const Node *N)
StringRef getName() const
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.
LLVM_ABI Node * parseBlockNode()
Root for parsing a node. Returns a single node.
const std::map< StringRef, StringRef > & getTagMap() const
LLVM_ABI bool skip()
Finish parsing the current document and return true if there are more.
Node * getRoot()
Parse and return the root level node.
friend class document_iterator
LLVM_ABI Document(Stream &ParentStream)
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
MappingNode(std::unique_ptr< Document > &D, StringRef Anchor, StringRef Tag, MappingType MT)
Abstract base class for all Nodes.
StringRef getRawTag() const
Get the tag as it was written in the document.
unsigned int getType() const
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)
SMRange getSourceRange() const
void operator=(const Node &)=delete
NullNode(std::unique_ptr< Document > &D)
static bool classof(const Node *N)
static bool classof(const Node *N)
ScalarNode(std::unique_ptr< Document > &D, StringRef Anchor, StringRef Tag, StringRef Val)
StringRef getRawValue() const
Scans YAML tokens from a MemoryBuffer.
Represents a YAML sequence created from either a block sequence for a flow sequence.
static bool classof(const Node *N)
SequenceNode(std::unique_ptr< Document > &D, StringRef Anchor, StringRef Tag, SequenceType ST)
basic_collection_iterator< SequenceNode, Node > iterator
This class represents a YAML stream potentially containing multiple documents.
LLVM_ABI document_iterator end()
LLVM_ABI document_iterator begin()
LLVM_ABI Stream(StringRef Input, SourceMgr &, bool ShowColors=true, std::error_code *EC=nullptr)
This keeps a reference to the string referenced by Input.
LLVM_ABI 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.
LLVM_ABI bool dumpTokens(StringRef Input, raw_ostream &)
Dump all the tokens in this stream to OS.
LLVM_ABI std::optional< bool > parseBool(StringRef S)
Parse S as a bool according to https://yaml.org/type/bool.html.
LLVM_ABI bool scanTokens(StringRef Input)
Scans all tokens in input without outputting anything.
void skip(CollectionType &C)
CollectionType::iterator begin(CollectionType &C)
LLVM_ABI 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.
bool failed(LogicalResult Result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value.
BumpPtrAllocatorImpl BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
Token - A single YAML token.