23 void ScalarNode::anchor() {}
24 void ArrayNode::anchor() {}
25 void MapNode::anchor() {}
30 auto A = std::make_shared<ArrayNode>();
31 for (
size_t I = 0;
I < Length; ++
I) {
33 if (
auto Err = OptNodeOrErr.takeError())
34 return std::move(Err);
36 return make_error<StringError>(
37 "Insufficient array elements",
39 A->push_back(std::move(**OptNodeOrErr));
45 auto M = std::make_shared<MapNode>();
46 for (
size_t I = 0;
I < Length; ++
I) {
48 if (
auto Err = OptKeyOrErr.takeError())
49 return std::move(Err);
51 return make_error<StringError>(
52 "Insufficient map elements",
55 if (
auto Err = OptValOrErr.takeError())
56 return std::move(Err);
58 return make_error<StringError>(
59 "Insufficient map elements",
61 auto *
Key =
dyn_cast<ScalarNode>((*OptKeyOrErr)->get());
63 return make_error<StringError>(
64 "Only string map keys are supported",
67 return make_error<StringError>(
68 "Only string map keys are supported",
70 M->try_emplace(Key->getString(), std::move(**OptValOrErr));
78 auto ContinueOrErr = MPReader.
read(Obj);
79 if (
auto Err = ContinueOrErr.takeError())
80 return std::move(Err);
90 return OptNodePtr(std::make_shared<ScalarNode>());
100 return Node::readArray(MPReader, Obj.
Length);
102 return Node::readMap(MPReader, Obj.
Length);
104 return make_error<StringError>(
105 "Extension types are not supported",
111 void ScalarNode::destroy() {
115 StringValue.~basic_string();
124 :
Node(NK_Scalar), SKind(SK_Int), IntValue(IntValue) {}
127 :
ScalarNode(static_cast<int64_t>(IntValue)) {}
133 :
ScalarNode(static_cast<uint64_t>(IntValue)) {}
165 switch (SKind = RHS.SKind) {
167 IntValue = RHS.IntValue;
180 new (&
StringValue) std::string(std::move(RHS.StringValue));
192 return yaml::ScalarTraits<int64_t>::input(ScalarStr,
nullptr, IntValue);
194 return yaml::ScalarTraits<uint64_t>::input(ScalarStr,
nullptr,
UIntValue);
198 return yaml::ScalarTraits<bool>::input(ScalarStr,
nullptr,
BoolValue);
200 return yaml::ScalarTraits<double>::input(ScalarStr,
nullptr,
FloatValue);
203 return yaml::ScalarTraits<std::string>::input(ScalarStr,
nullptr,
212 yaml::ScalarTraits<int64_t>::output(IntValue,
nullptr, OS);
215 yaml::ScalarTraits<uint64_t>::output(
UIntValue,
nullptr, OS);
218 yaml::ScalarTraits<StringRef>::output(
"",
nullptr, OS);
221 yaml::ScalarTraits<bool>::output(
BoolValue,
nullptr, OS);
224 yaml::ScalarTraits<double>::output(
FloatValue,
nullptr, OS);
228 yaml::ScalarTraits<std::string>::output(
StringValue,
nullptr, OS);
236 return yaml::ScalarTraits<int64_t>::mustQuote(ScalarStr);
238 return yaml::ScalarTraits<uint64_t>::mustQuote(ScalarStr);
240 return yaml::ScalarTraits<StringRef>::mustQuote(ScalarStr);
242 return yaml::ScalarTraits<bool>::mustQuote(ScalarStr);
244 return yaml::ScalarTraits<double>::mustQuote(ScalarStr);
247 return yaml::ScalarTraits<std::string>::mustQuote(ScalarStr);
282 MPWriter.
write(IntValue);
static const char * FloatTag
Expected< bool > read(Object &Obj)
Read one object from the input buffer, advancing past it.
This class represents lattice values for constants.
StringRef getYAMLTag() const
Get the YAML tag for the current ScalarKind.
yaml::QuotingType mustQuoteYAML(StringRef ScalarStr) const
Determine which YAML quoting type the current value would need when output.
StringRef getBuffer() const
Writes MessagePack objects to an output stream, one at a time.
std::error_code make_error_code(BitcodeError E)
Tagged union holding either a T or a Error.
ScalarNode()
Construct a Nil ScalarNode.
static const char * BinaryTag
void outputYAML(raw_ostream &OS) const
Output a YAML scalar of the current ScalarKind into OS.
static const char * IntTag
static Expected< OptNodePtr > read(Reader &MPReader)
Read from a MessagePack reader MPReader, returning an error if one is encountered, or None if MPReader is at the end of stream, or some Node pointer if some type is read.
MessagePack object, represented as a tagged union of C++ types.
This is a data structure for representing MessagePack "documents", with methods to go to and from Mes...
static const char * BooleanTag
void writeNil()
Write a Nil to the output stream.
Reads MessagePack objects from memory, one at a time.
Abstract base-class which can be any MessagePack type.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
double Float
Value for Type::Float.
void write(Writer &MPWriter) override
Write to a MessagePack writer MPWriter.
static const char * NilTag
void write(bool b)
Write a Boolean to the output stream.
StringRef Raw
Value for Type::String and Type::Binary.
ScalarNode & operator=(const ScalarNode &RHS)=delete
int64_t Int
Value for Type::Int.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
bool Bool
Value for Type::Boolean.
This class implements an extremely fast bulk output stream that can only output to a stream...
StringRef - Represent a constant reference to a string, i.e.
uint64_t UInt
Value for Type::Uint.
Optional< NodePtr > OptNodePtr
Short-hand for an Optional Node pointer.
size_t Length
Value for Type::Array and Type::Map.
static const char * StringTag
StringRef inputYAML(StringRef ScalarStr)
Parse a YAML scalar of the current ScalarKind from ScalarStr.