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 &);
80 std::string
escape(StringRef Input,
bool EscapePrintable =
true);
88 std::error_code *EC =
nullptr);
91 std::error_code *EC =
nullptr);
109 std::unique_ptr<Scanner> scanner;
110 std::unique_ptr<Document> CurrentDoc;
115 virtual void anchor();
134 void operator=(
const Node &) =
delete;
137 size_t Alignment = 16) noexcept {
138 return Alloc.Allocate(Size, Alignment);
142 size_t Size) noexcept {
143 Alloc.Deallocate(Ptr, Size);
146 void operator delete(
void *) noexcept =
delete;
158 std::string getVerbatimTag()
const;
166 Node *parseBlockNode();
168 void setError(
const Twine &Message,
Token &Location)
const;
176 std::unique_ptr<Document> &
Doc;
193 void anchor()
override;
208 void anchor()
override;
213 :
Node(NK_Scalar, D, Anchor, Tag),
Value(Val) {
216 SourceRange =
SMRange(Start, End);
232 return N->
getType() == NK_Scalar;
251 void anchor()
override;
256 :
Node(NK_BlockScalar, D, Anchor, Tag), Value(Value) {
259 SourceRange =
SMRange(Start, End);
266 return N->
getType() == NK_BlockScalar;
281 void anchor()
override;
304 if (
Node *Val = getValue())
310 return N->
getType() == NK_KeyValue;
323 template <
class BaseT,
class ValueT>
325 :
public std::iterator<std::input_iterator_tag, ValueT> {
331 assert(
Base &&
Base->CurrentEntry &&
"Attempted to access end iterator!");
332 return Base->CurrentEntry;
337 "Attempted to dereference end iterator!");
338 return *
Base->CurrentEntry;
342 assert(
Base &&
Base->CurrentEntry &&
"Attempted to access end iterator!");
343 return Base->CurrentEntry;
355 assert((
Base->CurrentEntry == Other.Base->CurrentEntry)
356 &&
"Equal Bases expected to point to equal Entries");
359 return Base == Other.Base;
363 return !(
Base == Other.Base);
367 assert(
Base &&
"Attempted to advance iterator past end!");
370 if (!
Base->CurrentEntry)
376 BaseT *
Base =
nullptr;
380 template <
class CollectionType>
381 typename CollectionType::iterator
begin(CollectionType &
C) {
382 assert(C.IsAtBeginning &&
"You may only iterate over a collection once!");
383 C.IsAtBeginning =
false;
384 typename CollectionType::iterator ret(&C);
389 template <
class CollectionType>
void skip(CollectionType &
C) {
391 assert((C.IsAtBeginning || C.IsAtEnd) &&
"Cannot skip mid parse!");
393 for (
typename CollectionType::iterator i =
begin(C), e = C.end(); i != e;
406 void anchor()
override;
417 :
Node(NK_Mapping, D, Anchor, Tag),
Type(MT) {}
423 template <
class T>
friend typename T::iterator
yaml::begin(
T &);
433 return N->
getType() == NK_Mapping;
438 bool IsAtBeginning =
true;
439 bool IsAtEnd =
false;
454 void anchor()
override;
472 :
Node(NK_Sequence, D, Anchor, Tag), SeqType(ST) {}
478 template <
class T>
friend typename T::iterator
yaml::begin(
T &);
490 return N->
getType() == NK_Sequence;
495 bool IsAtBeginning =
true;
496 bool IsAtEnd =
false;
497 bool WasPreviousTokenFlowEntry =
true;
498 Node *CurrentEntry =
nullptr;
506 void anchor()
override;
528 Node *parseBlockNode();
538 return Root = parseBlockNode();
541 const std::map<StringRef, StringRef> &
getTagMap()
const {
return TagMap; }
559 std::map<StringRef, StringRef> TagMap;
563 void setError(
const Twine &Message,
Token &Location)
const;
567 bool parseDirectives();
570 void parseYAMLDirective();
573 void parseTAGDirective();
576 bool expectToken(
int TK);
586 if (isAtEnd() || Other.isAtEnd())
587 return isAtEnd() && Other.isAtEnd();
589 return Doc == Other.Doc;
592 return !(*
this == Other);
596 assert(Doc &&
"incrementing iterator past the end.");
597 if (!(*Doc)->skip()) {
600 Stream &S = (*Doc)->stream;
611 bool isAtEnd()
const {
return !Doc || !*Doc; }
613 std::unique_ptr<Document> *Doc =
nullptr;
620 #endif // LLVM_SUPPORT_YAMLPARSER_H StringRef getRawValue() const
static bool classof(const Node *N)
document_iterator operator++()
Represents a range in source code.
AliasNode(std::unique_ptr< Document > &D, StringRef Val)
std::unique_ptr< Document > & Doc
SequenceNode(std::unique_ptr< Document > &D, StringRef Anchor, StringRef Tag, SequenceType ST)
Compute iterated dominance frontiers using a linear time algorithm.
StringRef getRawTag() const
Get the tag as it was written in the document.
bool scanTokens(StringRef Input)
Scans all tokens in input without outputting anything.
bool operator==(const document_iterator &Other) const
This is an iterator abstraction over YAML collections shared by both sequences and maps...
Represents a YAML sequence created from either a block sequence for a flow sequence.
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...
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.
bool operator==(const basic_collection_iterator &Other) const
Note on EqualityComparable:
std::unique_ptr< Document > & operator->()
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
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.
static bool classof(const Node *N)
ValueT * operator->() const
bool dumpTokens(StringRef Input, raw_ostream &)
Dump all the tokens in this stream to OS.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
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.
StringRef getValue() const
Gets the value of this node as a StringRef.
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling...
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)
basic_collection_iterator(BaseT *B)
This class represents a YAML stream potentially containing multiple documents.
StringRef getAnchor() const
Get the value of the anchor attached to this node.
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
ValueT & operator*() const
static SMLoc getFromPointer(const char *Ptr)
Stream(StringRef Input, SourceMgr &, bool ShowColors=true, std::error_code *EC=nullptr)
This keeps a reference to the string referenced by Input.
unsigned int getType() const
const std::map< StringRef, StringRef > & getTagMap() 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.
StringRef getName() const
Iterator abstraction for Documents over a Stream.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
NullNode(std::unique_ptr< Document > &D)
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
bool operator!=(const document_iterator &Other) const
StringRef - Represent a constant reference to a string, i.e.
basic_collection_iterator & operator++()
Represents a location in source code.
bool operator!=(const basic_collection_iterator &Other) const
MappingNode(std::unique_ptr< Document > &D, StringRef Anchor, StringRef Tag, MappingType MT)
A YAML Stream is a sequence of Documents.
SMRange getSourceRange() const
Abstract base class for all Nodes.