summaryrefslogtreecommitdiff
path: root/include/llvm/Support/YAMLParser.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/llvm/Support/YAMLParser.h')
-rw-r--r--include/llvm/Support/YAMLParser.h80
1 files changed, 44 insertions, 36 deletions
diff --git a/include/llvm/Support/YAMLParser.h b/include/llvm/Support/YAMLParser.h
index c907a99ddb59..5b031a9a4270 100644
--- a/include/llvm/Support/YAMLParser.h
+++ b/include/llvm/Support/YAMLParser.h
@@ -64,23 +64,26 @@ class Node;
class Scanner;
struct Token;
-/// \brief Dump all the tokens in this stream to OS.
+/// Dump all the tokens in this stream to OS.
/// \returns true if there was an error, false otherwise.
bool dumpTokens(StringRef Input, raw_ostream &);
-/// \brief Scans all tokens in input without outputting anything. This is used
+/// Scans all tokens in input without outputting anything. This is used
/// for benchmarking the tokenizer.
/// \returns true if there was an error, false otherwise.
bool scanTokens(StringRef Input);
-/// \brief Escape \a Input for a double quoted scalar.
-std::string escape(StringRef Input);
+/// Escape \a Input for a double quoted scalar; if \p EscapePrintable
+/// is true, all UTF8 sequences will be escaped, if \p EscapePrintable is
+/// false, those UTF8 sequences encoding printable unicode scalars will not be
+/// escaped, but emitted verbatim.
+std::string escape(StringRef Input, bool EscapePrintable = true);
-/// \brief This class represents a YAML stream potentially containing multiple
+/// This class represents a YAML stream potentially containing multiple
/// documents.
class Stream {
public:
- /// \brief This keeps a reference to the string referenced by \p Input.
+ /// This keeps a reference to the string referenced by \p Input.
Stream(StringRef Input, SourceMgr &, bool ShowColors = true,
std::error_code *EC = nullptr);
@@ -107,7 +110,7 @@ private:
std::unique_ptr<Document> CurrentDoc;
};
-/// \brief Abstract base class for all Nodes.
+/// Abstract base class for all Nodes.
class Node {
virtual void anchor();
@@ -125,6 +128,11 @@ public:
Node(unsigned int Type, std::unique_ptr<Document> &, StringRef Anchor,
StringRef Tag);
+ // It's not safe to copy YAML nodes; the document is streamed and the position
+ // is part of the state.
+ Node(const Node &) = delete;
+ void operator=(const Node &) = delete;
+
void *operator new(size_t Size, BumpPtrAllocator &Alloc,
size_t Alignment = 16) noexcept {
return Alloc.Allocate(Size, Alignment);
@@ -137,15 +145,15 @@ public:
void operator delete(void *) noexcept = delete;
- /// \brief Get the value of the anchor attached to this node. If it does not
+ /// Get the value of the anchor attached to this node. If it does not
/// have one, getAnchor().size() will be 0.
StringRef getAnchor() const { return Anchor; }
- /// \brief Get the tag as it was written in the document. This does not
+ /// Get the tag as it was written in the document. This does not
/// perform tag resolution.
StringRef getRawTag() const { return Tag; }
- /// \brief Get the verbatium tag for a given Node. This performs tag resoluton
+ /// Get the verbatium tag for a given Node. This performs tag resoluton
/// and substitution.
std::string getVerbatimTag() const;
@@ -173,11 +181,11 @@ protected:
private:
unsigned int TypeID;
StringRef Anchor;
- /// \brief The tag as typed in the document.
+ /// The tag as typed in the document.
StringRef Tag;
};
-/// \brief A null value.
+/// A null value.
///
/// Example:
/// !!null null
@@ -191,7 +199,7 @@ public:
static bool classof(const Node *N) { return N->getType() == NK_Null; }
};
-/// \brief A scalar node is an opaque datum that can be presented as a
+/// A scalar node is an opaque datum that can be presented as a
/// series of zero or more Unicode scalar values.
///
/// Example:
@@ -213,7 +221,7 @@ public:
// utf8).
StringRef getRawValue() const { return Value; }
- /// \brief Gets the value of this node as a StringRef.
+ /// Gets the value of this node as a StringRef.
///
/// \param Storage is used to store the content of the returned StringRef iff
/// it requires any modification from how it appeared in the source.
@@ -232,7 +240,7 @@ private:
SmallVectorImpl<char> &Storage) const;
};
-/// \brief A block scalar node is an opaque datum that can be presented as a
+/// A block scalar node is an opaque datum that can be presented as a
/// series of zero or more Unicode scalar values.
///
/// Example:
@@ -251,7 +259,7 @@ public:
SourceRange = SMRange(Start, End);
}
- /// \brief Gets the value of this node as a StringRef.
+ /// Gets the value of this node as a StringRef.
StringRef getValue() const { return Value; }
static bool classof(const Node *N) {
@@ -262,7 +270,7 @@ private:
StringRef Value;
};
-/// \brief A key and value pair. While not technically a Node under the YAML
+/// A key and value pair. While not technically a Node under the YAML
/// representation graph, it is easier to treat them this way.
///
/// TODO: Consider making this not a child of Node.
@@ -276,14 +284,14 @@ public:
KeyValueNode(std::unique_ptr<Document> &D)
: Node(NK_KeyValue, D, StringRef(), StringRef()) {}
- /// \brief Parse and return the key.
+ /// Parse and return the key.
///
/// This may be called multiple times.
///
/// \returns The key, or nullptr if failed() == true.
Node *getKey();
- /// \brief Parse and return the value.
+ /// Parse and return the value.
///
/// This may be called multiple times.
///
@@ -307,7 +315,7 @@ private:
Node *Value = nullptr;
};
-/// \brief This is an iterator abstraction over YAML collections shared by both
+/// This is an iterator abstraction over YAML collections shared by both
/// sequences and maps.
///
/// BaseT must have a ValueT* member named CurrentEntry and a member function
@@ -387,7 +395,7 @@ template <class CollectionType> void skip(CollectionType &C) {
i->skip();
}
-/// \brief Represents a YAML map created from either a block map for a flow map.
+/// Represents a YAML map created from either a block map for a flow map.
///
/// This parses the YAML stream as increment() is called.
///
@@ -434,7 +442,7 @@ private:
void increment();
};
-/// \brief Represents a YAML sequence created from either a block sequence for a
+/// Represents a YAML sequence created from either a block sequence for a
/// flow sequence.
///
/// This parses the YAML stream as increment() is called.
@@ -490,7 +498,7 @@ private:
Node *CurrentEntry = nullptr;
};
-/// \brief Represents an alias to a Node with an anchor.
+/// Represents an alias to a Node with an anchor.
///
/// Example:
/// *AnchorName
@@ -510,20 +518,20 @@ private:
StringRef Name;
};
-/// \brief A YAML Stream is a sequence of Documents. A document contains a root
+/// A YAML Stream is a sequence of Documents. A document contains a root
/// node.
class Document {
public:
Document(Stream &ParentStream);
- /// \brief Root for parsing a node. Returns a single node.
+ /// Root for parsing a node. Returns a single node.
Node *parseBlockNode();
- /// \brief Finish parsing the current document and return true if there are
+ /// Finish parsing the current document and return true if there are
/// more. Return false otherwise.
bool skip();
- /// \brief Parse and return the root level node.
+ /// Parse and return the root level node.
Node *getRoot() {
if (Root)
return Root;
@@ -536,18 +544,18 @@ private:
friend class Node;
friend class document_iterator;
- /// \brief Stream to read tokens from.
+ /// Stream to read tokens from.
Stream &stream;
- /// \brief Used to allocate nodes to. All are destroyed without calling their
+ /// Used to allocate nodes to. All are destroyed without calling their
/// destructor when the document is destroyed.
BumpPtrAllocator NodeAllocator;
- /// \brief The root node. Used to support skipping a partially parsed
+ /// The root node. Used to support skipping a partially parsed
/// document.
Node *Root;
- /// \brief Maps tag prefixes to their expansion.
+ /// Maps tag prefixes to their expansion.
std::map<StringRef, StringRef> TagMap;
Token &peekNext();
@@ -555,20 +563,20 @@ private:
void setError(const Twine &Message, Token &Location) const;
bool failed() const;
- /// \brief Parse %BLAH directives and return true if any were encountered.
+ /// Parse %BLAH directives and return true if any were encountered.
bool parseDirectives();
- /// \brief Parse %YAML
+ /// Parse %YAML
void parseYAMLDirective();
- /// \brief Parse %TAG
+ /// Parse %TAG
void parseTAGDirective();
- /// \brief Consume the next token and error if it is not \a TK.
+ /// Consume the next token and error if it is not \a TK.
bool expectToken(int TK);
};
-/// \brief Iterator abstraction for Documents over a Stream.
+/// Iterator abstraction for Documents over a Stream.
class document_iterator {
public:
document_iterator() = default;