38 #ifndef LLVM_SUPPORT_YAMLPARSER_H
39 #define LLVM_SUPPORT_YAMLPARSER_H
45 #include <system_error>
49 class MemoryBufferRef;
56 class document_iterator;
64 bool dumpTokens(StringRef Input, raw_ostream &);
72 std::string
escape(StringRef Input);
80 std::error_code *EC =
nullptr);
83 std::error_code *EC =
nullptr);
98 std::unique_ptr<Scanner> scanner;
99 std::unique_ptr<Document> CurrentDoc;
106 virtual void anchor();
150 size_t Alignment = 16) noexcept {
151 return Alloc.Allocate(Size, Alignment);
155 size_t Size) noexcept {
156 Alloc.Deallocate(
Ptr, Size);
160 std::unique_ptr<Document> &
Doc;
163 void operator delete(
void *) noexcept =
delete;
179 void anchor()
override;
194 void anchor()
override;
237 void anchor()
override;
267 void anchor()
override;
308 template <
class BaseT,
class ValueT>
310 :
public std::iterator<std::input_iterator_tag, ValueT> {
316 assert(Base && Base->CurrentEntry &&
"Attempted to access end iterator!");
317 return Base->CurrentEntry;
321 assert(Base && Base->CurrentEntry &&
322 "Attempted to dereference end iterator!");
323 return *Base->CurrentEntry;
327 assert(Base && Base->CurrentEntry &&
"Attempted to access end iterator!");
328 return Base->CurrentEntry;
339 if (Base && (Base == Other.Base)) {
340 assert((Base->CurrentEntry == Other.Base->CurrentEntry)
341 &&
"Equal Bases expected to point to equal Entries");
344 return Base == Other.Base;
348 return !(Base == Other.Base);
352 assert(Base &&
"Attempted to advance iterator past end!");
355 if (!Base->CurrentEntry)
365 template <
class CollectionType>
366 typename CollectionType::iterator
begin(CollectionType &
C) {
367 assert(C.IsAtBeginning &&
"You may only iterate over a collection once!");
368 C.IsAtBeginning =
false;
369 typename CollectionType::iterator ret(&C);
374 template <
class CollectionType>
void skip(CollectionType &
C) {
376 assert((C.IsAtBeginning || C.IsAtEnd) &&
"Cannot skip mid parse!");
378 for (
typename CollectionType::iterator
i =
begin(C), e = C.end();
i != e;
391 void anchor()
override;
403 IsAtEnd(
false), CurrentEntry(nullptr) {}
407 template <
class T>
friend typename T::iterator
yaml::begin(
T &);
438 void anchor()
override;
458 WasPreviousTokenFlowEntry(
true),
459 CurrentEntry(nullptr) {}
463 template <
class T>
friend typename T::iterator
yaml::begin(
T &);
482 bool WasPreviousTokenFlowEntry;
491 void anchor()
override;
526 const std::map<StringRef, StringRef> &
getTagMap()
const {
return TagMap; }
544 std::map<StringRef, StringRef> TagMap;
548 void setError(
const Twine &Message,
Token &Location)
const;
552 bool parseDirectives();
555 void parseYAMLDirective();
558 void parseTAGDirective();
561 bool expectToken(
int TK);
571 if (isAtEnd() || Other.isAtEnd())
572 return isAtEnd() && Other.isAtEnd();
574 return Doc == Other.Doc;
579 assert(Doc &&
"incrementing iterator past the end.");
580 if (!(*Doc)->skip()) {
583 Stream &S = (*Doc)->stream;
594 bool isAtEnd()
const {
return !Doc || !*Doc; }
596 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 GCRegistry::Add< StatepointGC > D("statepoint-example","an example strategy for statepoint")
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.
Function Alias Analysis false
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
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)
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.
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.
bool operator==(const basic_collection_iterator &Other) const
Note on EqualityComparable:
StringRef getName() const
bool operator!=(const basic_collection_iterator &Other) const
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
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.
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
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.