37 #ifndef LLVM_SUPPORT_YAMLPARSER_H 38 #define LLVM_SUPPORT_YAMLPARSER_H 49 #include <system_error> 53 class MemoryBufferRef;
61 class document_iterator;
68 bool dumpTokens(StringRef Input, raw_ostream &);
79 std::string
escape(StringRef Input,
bool EscapePrintable =
true);
87 std::error_code *EC =
nullptr);
90 std::error_code *EC =
nullptr);
108 std::unique_ptr<Scanner> scanner;
109 std::unique_ptr<Document> CurrentDoc;
114 virtual void anchor();
133 void operator=(
const Node &) =
delete;
136 size_t Alignment = 16) noexcept {
137 return Alloc.Allocate(Size, Alignment);
141 size_t Size) noexcept {
142 Alloc.Deallocate(Ptr, Size);
145 void operator delete(
void *) noexcept =
delete;
157 std::string getVerbatimTag()
const;
165 Node *parseBlockNode();
167 void setError(
const Twine &Message,
Token &Location)
const;
175 std::unique_ptr<Document> &
Doc;
192 void anchor()
override;
207 void anchor()
override;
212 :
Node(NK_Scalar, D, Anchor, Tag),
Value(Val) {
215 SourceRange =
SMRange(Start, End);
231 return N->
getType() == NK_Scalar;
250 void anchor()
override;
255 :
Node(NK_BlockScalar, D, Anchor, Tag), Value(Value) {
258 SourceRange =
SMRange(Start, End);
265 return N->
getType() == NK_BlockScalar;
280 void anchor()
override;
303 if (
Node *Val = getValue())
309 return N->
getType() == NK_KeyValue;
322 template <
class BaseT,
class ValueT>
324 :
public std::iterator<std::input_iterator_tag, ValueT> {
330 assert(
Base &&
Base->CurrentEntry &&
"Attempted to access end iterator!");
331 return Base->CurrentEntry;
336 "Attempted to dereference end iterator!");
337 return *
Base->CurrentEntry;
341 assert(
Base &&
Base->CurrentEntry &&
"Attempted to access end iterator!");
342 return Base->CurrentEntry;
354 assert((
Base->CurrentEntry == Other.Base->CurrentEntry)
355 &&
"Equal Bases expected to point to equal Entries");
358 return Base == Other.Base;
362 return !(
Base == Other.Base);
366 assert(
Base &&
"Attempted to advance iterator past end!");
369 if (!
Base->CurrentEntry)
375 BaseT *
Base =
nullptr;
379 template <
class CollectionType>
380 typename CollectionType::iterator
begin(CollectionType &
C) {
381 assert(C.IsAtBeginning &&
"You may only iterate over a collection once!");
382 C.IsAtBeginning =
false;
383 typename CollectionType::iterator ret(&C);
388 template <
class CollectionType>
void skip(CollectionType &
C) {
390 assert((C.IsAtBeginning || C.IsAtEnd) &&
"Cannot skip mid parse!");
392 for (
typename CollectionType::iterator i =
begin(C),
e = C.end(); i !=
e;
405 void anchor()
override;
416 :
Node(NK_Mapping, D, Anchor, Tag),
Type(MT) {}
422 template <
class T>
friend typename T::iterator
yaml::begin(
T &);
432 return N->
getType() == NK_Mapping;
437 bool IsAtBeginning =
true;
438 bool IsAtEnd =
false;
453 void anchor()
override;
471 :
Node(NK_Sequence, D, Anchor, Tag), SeqType(ST) {}
477 template <
class T>
friend typename T::iterator
yaml::begin(
T &);
489 return N->
getType() == NK_Sequence;
494 bool IsAtBeginning =
true;
495 bool IsAtEnd =
false;
496 bool WasPreviousTokenFlowEntry =
true;
497 Node *CurrentEntry =
nullptr;
505 void anchor()
override;
527 Node *parseBlockNode();
537 return Root = parseBlockNode();
540 const std::map<StringRef, StringRef> &
getTagMap()
const {
return TagMap; }
558 std::map<StringRef, StringRef> TagMap;
562 void setError(
const Twine &Message,
Token &Location)
const;
566 bool parseDirectives();
569 void parseYAMLDirective();
572 void parseTAGDirective();
575 bool expectToken(
int TK);
585 if (isAtEnd() || Other.isAtEnd())
586 return isAtEnd() && Other.isAtEnd();
588 return Doc == Other.Doc;
591 return !(*
this == Other);
595 assert(Doc &&
"incrementing iterator past the end.");
596 if (!(*Doc)->skip()) {
599 Stream &S = (*Doc)->stream;
610 bool isAtEnd()
const {
return !Doc || !*Doc; }
612 std::unique_ptr<Document> *Doc =
nullptr;
619 #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)
This class represents lattice values for constants.
StringRef getRawTag() const
Get the tag as it was written in the document.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
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...
Determine the kind of a node from its type.
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)
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.