Bug Summary

File:llvm/include/llvm/Support/YAMLTraits.h
Warning:line 794, column 51
The left operand of '==' is a garbage value

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name CodeViewYAMLSymbols.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=none -fmath-errno -fno-rounding-math -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -fno-split-dwarf-inlining -debugger-tuning=gdb -ffunction-sections -fdata-sections -resource-dir /usr/lib/llvm-11/lib/clang/11.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/build-llvm/lib/ObjectYAML -I /build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/ObjectYAML -I /build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/build-llvm/include -I /build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/include -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-11/lib/clang/11.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-comment -std=c++14 -fdeprecated-macro -fdebug-compilation-dir /build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/build-llvm/lib/ObjectYAML -fdebug-prefix-map=/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347=. -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -o /tmp/scan-build-2020-03-09-184146-41876-1 -x c++ /build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/ObjectYAML/CodeViewYAMLSymbols.cpp

/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/ObjectYAML/CodeViewYAMLSymbols.cpp

1//===- CodeViewYAMLSymbols.cpp - CodeView YAMLIO Symbol implementation ----===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines classes for handling the YAML representation of CodeView
10// Debug Info.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/ObjectYAML/CodeViewYAMLSymbols.h"
15#include "llvm/ADT/ArrayRef.h"
16#include "llvm/ADT/StringRef.h"
17#include "llvm/DebugInfo/CodeView/CodeView.h"
18#include "llvm/DebugInfo/CodeView/CodeViewError.h"
19#include "llvm/DebugInfo/CodeView/EnumTables.h"
20#include "llvm/DebugInfo/CodeView/RecordSerialization.h"
21#include "llvm/DebugInfo/CodeView/SymbolDeserializer.h"
22#include "llvm/DebugInfo/CodeView/SymbolRecord.h"
23#include "llvm/DebugInfo/CodeView/SymbolSerializer.h"
24#include "llvm/DebugInfo/CodeView/TypeIndex.h"
25#include "llvm/ObjectYAML/YAML.h"
26#include "llvm/Support/Allocator.h"
27#include "llvm/Support/Error.h"
28#include "llvm/Support/YAMLTraits.h"
29#include <algorithm>
30#include <cstdint>
31#include <cstring>
32#include <string>
33#include <vector>
34
35using namespace llvm;
36using namespace llvm::codeview;
37using namespace llvm::CodeViewYAML;
38using namespace llvm::CodeViewYAML::detail;
39using namespace llvm::yaml;
40
41LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(TypeIndex)namespace llvm { namespace yaml { static_assert( !std::is_fundamental
<TypeIndex>::value && !std::is_same<TypeIndex
, std::string>::value && !std::is_same<TypeIndex
, llvm::StringRef>::value, "only use LLVM_YAML_IS_SEQUENCE_VECTOR for types you control"
); template <> struct SequenceElementTraits<TypeIndex
> { static const bool flow = true; }; } }
42LLVM_YAML_IS_SEQUENCE_VECTOR(LocalVariableAddrGap)namespace llvm { namespace yaml { static_assert( !std::is_fundamental
<LocalVariableAddrGap>::value && !std::is_same<
LocalVariableAddrGap, std::string>::value && !std::
is_same<LocalVariableAddrGap, llvm::StringRef>::value, "only use LLVM_YAML_IS_SEQUENCE_VECTOR for types you control"
); template <> struct SequenceElementTraits<LocalVariableAddrGap
> { static const bool flow = false; }; } }
43
44// We only need to declare these, the definitions are in CodeViewYAMLTypes.cpp
45LLVM_YAML_DECLARE_SCALAR_TRAITS(APSInt, QuotingType::None)namespace llvm { namespace yaml { template <> struct ScalarTraits
<APSInt> { static void output(const APSInt &Value, void
*ctx, raw_ostream &Out); static StringRef input(StringRef
Scalar, void *ctxt, APSInt &Value); static QuotingType mustQuote
(StringRef) { return QuotingType::None; } }; } }
46LLVM_YAML_DECLARE_SCALAR_TRAITS(TypeIndex, QuotingType::None)namespace llvm { namespace yaml { template <> struct ScalarTraits
<TypeIndex> { static void output(const TypeIndex &Value
, void *ctx, raw_ostream &Out); static StringRef input(StringRef
Scalar, void *ctxt, TypeIndex &Value); static QuotingType
mustQuote(StringRef) { return QuotingType::None; } }; } }
47
48LLVM_YAML_DECLARE_ENUM_TRAITS(SymbolKind)namespace llvm { namespace yaml { template <> struct ScalarEnumerationTraits
<SymbolKind> { static void enumeration(IO &io, SymbolKind
&Value); }; } }
49LLVM_YAML_DECLARE_ENUM_TRAITS(FrameCookieKind)namespace llvm { namespace yaml { template <> struct ScalarEnumerationTraits
<FrameCookieKind> { static void enumeration(IO &io,
FrameCookieKind &Value); }; } }
50
51LLVM_YAML_DECLARE_BITSET_TRAITS(CompileSym2Flags)namespace llvm { namespace yaml { template <> struct ScalarBitSetTraits
<CompileSym2Flags> { static void bitset(IO &IO, CompileSym2Flags
&Options); }; } }
52LLVM_YAML_DECLARE_BITSET_TRAITS(CompileSym3Flags)namespace llvm { namespace yaml { template <> struct ScalarBitSetTraits
<CompileSym3Flags> { static void bitset(IO &IO, CompileSym3Flags
&Options); }; } }
53LLVM_YAML_DECLARE_BITSET_TRAITS(ExportFlags)namespace llvm { namespace yaml { template <> struct ScalarBitSetTraits
<ExportFlags> { static void bitset(IO &IO, ExportFlags
&Options); }; } }
54LLVM_YAML_DECLARE_BITSET_TRAITS(PublicSymFlags)namespace llvm { namespace yaml { template <> struct ScalarBitSetTraits
<PublicSymFlags> { static void bitset(IO &IO, PublicSymFlags
&Options); }; } }
55LLVM_YAML_DECLARE_BITSET_TRAITS(LocalSymFlags)namespace llvm { namespace yaml { template <> struct ScalarBitSetTraits
<LocalSymFlags> { static void bitset(IO &IO, LocalSymFlags
&Options); }; } }
56LLVM_YAML_DECLARE_BITSET_TRAITS(ProcSymFlags)namespace llvm { namespace yaml { template <> struct ScalarBitSetTraits
<ProcSymFlags> { static void bitset(IO &IO, ProcSymFlags
&Options); }; } }
57LLVM_YAML_DECLARE_BITSET_TRAITS(FrameProcedureOptions)namespace llvm { namespace yaml { template <> struct ScalarBitSetTraits
<FrameProcedureOptions> { static void bitset(IO &IO
, FrameProcedureOptions &Options); }; } }
58LLVM_YAML_DECLARE_ENUM_TRAITS(CPUType)namespace llvm { namespace yaml { template <> struct ScalarEnumerationTraits
<CPUType> { static void enumeration(IO &io, CPUType
&Value); }; } }
59LLVM_YAML_DECLARE_ENUM_TRAITS(RegisterId)namespace llvm { namespace yaml { template <> struct ScalarEnumerationTraits
<RegisterId> { static void enumeration(IO &io, RegisterId
&Value); }; } }
60LLVM_YAML_DECLARE_ENUM_TRAITS(TrampolineType)namespace llvm { namespace yaml { template <> struct ScalarEnumerationTraits
<TrampolineType> { static void enumeration(IO &io, TrampolineType
&Value); }; } }
61LLVM_YAML_DECLARE_ENUM_TRAITS(ThunkOrdinal)namespace llvm { namespace yaml { template <> struct ScalarEnumerationTraits
<ThunkOrdinal> { static void enumeration(IO &io, ThunkOrdinal
&Value); }; } }
62
63LLVM_YAML_STRONG_TYPEDEF(StringRef, TypeName)struct TypeName { TypeName() = default; TypeName(const StringRef
v) : value(v) {} TypeName(const TypeName &v) = default; TypeName
&operator=(const TypeName &rhs) = default; TypeName &
operator=(const StringRef &rhs) { value = rhs; return *this
; } operator const StringRef & () const { return value; }
bool operator==(const TypeName &rhs) const { return value
== rhs.value; } bool operator==(const StringRef &rhs) const
{ return value == rhs; } bool operator<(const TypeName &
rhs) const { return value < rhs.value; } StringRef value; using
BaseType = StringRef; };
64
65LLVM_YAML_DECLARE_SCALAR_TRAITS(TypeName, QuotingType::Single)namespace llvm { namespace yaml { template <> struct ScalarTraits
<TypeName> { static void output(const TypeName &Value
, void *ctx, raw_ostream &Out); static StringRef input(StringRef
Scalar, void *ctxt, TypeName &Value); static QuotingType
mustQuote(StringRef) { return QuotingType::Single; } }; } }
66
67StringRef ScalarTraits<TypeName>::input(StringRef S, void *V, TypeName &T) {
68 return ScalarTraits<StringRef>::input(S, V, T.value);
69}
70
71void ScalarTraits<TypeName>::output(const TypeName &T, void *V,
72 raw_ostream &R) {
73 ScalarTraits<StringRef>::output(T.value, V, R);
74}
75
76void ScalarEnumerationTraits<SymbolKind>::enumeration(IO &io,
77 SymbolKind &Value) {
78 auto SymbolNames = getSymbolTypeNames();
79 for (const auto &E : SymbolNames)
14
Assuming '__begin1' is not equal to '__end1'
80 io.enumCase(Value, E.Name.str().c_str(), E.Value);
15
Passing value via 1st parameter 'Val'
16
Calling 'IO::enumCase'
81}
82
83void ScalarBitSetTraits<CompileSym2Flags>::bitset(IO &io,
84 CompileSym2Flags &Flags) {
85 auto FlagNames = getCompileSym2FlagNames();
86 for (const auto &E : FlagNames) {
87 io.bitSetCase(Flags, E.Name.str().c_str(),
88 static_cast<CompileSym2Flags>(E.Value));
89 }
90}
91
92void ScalarBitSetTraits<CompileSym3Flags>::bitset(IO &io,
93 CompileSym3Flags &Flags) {
94 auto FlagNames = getCompileSym3FlagNames();
95 for (const auto &E : FlagNames) {
96 io.bitSetCase(Flags, E.Name.str().c_str(),
97 static_cast<CompileSym3Flags>(E.Value));
98 }
99}
100
101void ScalarBitSetTraits<ExportFlags>::bitset(IO &io, ExportFlags &Flags) {
102 auto FlagNames = getExportSymFlagNames();
103 for (const auto &E : FlagNames) {
104 io.bitSetCase(Flags, E.Name.str().c_str(),
105 static_cast<ExportFlags>(E.Value));
106 }
107}
108
109void ScalarBitSetTraits<PublicSymFlags>::bitset(IO &io, PublicSymFlags &Flags) {
110 auto FlagNames = getPublicSymFlagNames();
111 for (const auto &E : FlagNames) {
112 io.bitSetCase(Flags, E.Name.str().c_str(),
113 static_cast<PublicSymFlags>(E.Value));
114 }
115}
116
117void ScalarBitSetTraits<LocalSymFlags>::bitset(IO &io, LocalSymFlags &Flags) {
118 auto FlagNames = getLocalFlagNames();
119 for (const auto &E : FlagNames) {
120 io.bitSetCase(Flags, E.Name.str().c_str(),
121 static_cast<LocalSymFlags>(E.Value));
122 }
123}
124
125void ScalarBitSetTraits<ProcSymFlags>::bitset(IO &io, ProcSymFlags &Flags) {
126 auto FlagNames = getProcSymFlagNames();
127 for (const auto &E : FlagNames) {
128 io.bitSetCase(Flags, E.Name.str().c_str(),
129 static_cast<ProcSymFlags>(E.Value));
130 }
131}
132
133void ScalarBitSetTraits<FrameProcedureOptions>::bitset(
134 IO &io, FrameProcedureOptions &Flags) {
135 auto FlagNames = getFrameProcSymFlagNames();
136 for (const auto &E : FlagNames) {
137 io.bitSetCase(Flags, E.Name.str().c_str(),
138 static_cast<FrameProcedureOptions>(E.Value));
139 }
140}
141
142void ScalarEnumerationTraits<CPUType>::enumeration(IO &io, CPUType &Cpu) {
143 auto CpuNames = getCPUTypeNames();
144 for (const auto &E : CpuNames) {
145 io.enumCase(Cpu, E.Name.str().c_str(), static_cast<CPUType>(E.Value));
146 }
147}
148
149void ScalarEnumerationTraits<RegisterId>::enumeration(IO &io, RegisterId &Reg) {
150 auto RegNames = getRegisterNames(CPUType::X64);
151 for (const auto &E : RegNames) {
152 io.enumCase(Reg, E.Name.str().c_str(), static_cast<RegisterId>(E.Value));
153 }
154 io.enumFallback<Hex16>(Reg);
155}
156
157void ScalarEnumerationTraits<TrampolineType>::enumeration(
158 IO &io, TrampolineType &Tramp) {
159 auto TrampNames = getTrampolineNames();
160 for (const auto &E : TrampNames) {
161 io.enumCase(Tramp, E.Name.str().c_str(),
162 static_cast<TrampolineType>(E.Value));
163 }
164}
165
166void ScalarEnumerationTraits<ThunkOrdinal>::enumeration(IO &io,
167 ThunkOrdinal &Ord) {
168 auto ThunkNames = getThunkOrdinalNames();
169 for (const auto &E : ThunkNames) {
170 io.enumCase(Ord, E.Name.str().c_str(), static_cast<ThunkOrdinal>(E.Value));
171 }
172}
173
174void ScalarEnumerationTraits<FrameCookieKind>::enumeration(
175 IO &io, FrameCookieKind &FC) {
176 auto ThunkNames = getFrameCookieKindNames();
177 for (const auto &E : ThunkNames) {
178 io.enumCase(FC, E.Name.str().c_str(),
179 static_cast<FrameCookieKind>(E.Value));
180 }
181}
182
183namespace llvm {
184namespace yaml {
185template <> struct MappingTraits<LocalVariableAddrRange> {
186 static void mapping(IO &io, LocalVariableAddrRange &Range) {
187 io.mapRequired("OffsetStart", Range.OffsetStart);
188 io.mapRequired("ISectStart", Range.ISectStart);
189 io.mapRequired("Range", Range.Range);
190 }
191};
192template <> struct MappingTraits<LocalVariableAddrGap> {
193 static void mapping(IO &io, LocalVariableAddrGap &Gap) {
194 io.mapRequired("GapStartOffset", Gap.GapStartOffset);
195 io.mapRequired("Range", Gap.Range);
196 }
197};
198} // namespace yaml
199} // namespace llvm
200
201namespace llvm {
202namespace CodeViewYAML {
203namespace detail {
204
205struct SymbolRecordBase {
206 codeview::SymbolKind Kind;
207
208 explicit SymbolRecordBase(codeview::SymbolKind K) : Kind(K) {}
209 virtual ~SymbolRecordBase() = default;
210
211 virtual void map(yaml::IO &io) = 0;
212 virtual codeview::CVSymbol
213 toCodeViewSymbol(BumpPtrAllocator &Allocator,
214 CodeViewContainer Container) const = 0;
215 virtual Error fromCodeViewSymbol(codeview::CVSymbol Type) = 0;
216};
217
218template <typename T> struct SymbolRecordImpl : public SymbolRecordBase {
219 explicit SymbolRecordImpl(codeview::SymbolKind K)
220 : SymbolRecordBase(K), Symbol(static_cast<SymbolRecordKind>(K)) {}
221
222 void map(yaml::IO &io) override;
223
224 codeview::CVSymbol
225 toCodeViewSymbol(BumpPtrAllocator &Allocator,
226 CodeViewContainer Container) const override {
227 return SymbolSerializer::writeOneSymbol(Symbol, Allocator, Container);
228 }
229
230 Error fromCodeViewSymbol(codeview::CVSymbol CVS) override {
231 return SymbolDeserializer::deserializeAs<T>(CVS, Symbol);
232 }
233
234 mutable T Symbol;
235};
236
237struct UnknownSymbolRecord : public SymbolRecordBase {
238 explicit UnknownSymbolRecord(codeview::SymbolKind K) : SymbolRecordBase(K) {}
239
240 void map(yaml::IO &io) override;
241
242 CVSymbol toCodeViewSymbol(BumpPtrAllocator &Allocator,
243 CodeViewContainer Container) const override {
244 RecordPrefix Prefix;
245 uint32_t TotalLen = sizeof(RecordPrefix) + Data.size();
246 Prefix.RecordKind = Kind;
247 Prefix.RecordLen = TotalLen - 2;
248 uint8_t *Buffer = Allocator.Allocate<uint8_t>(TotalLen);
249 ::memcpy(Buffer, &Prefix, sizeof(RecordPrefix));
250 ::memcpy(Buffer + sizeof(RecordPrefix), Data.data(), Data.size());
251 return CVSymbol(ArrayRef<uint8_t>(Buffer, TotalLen));
252 }
253
254 Error fromCodeViewSymbol(CVSymbol CVS) override {
255 this->Kind = CVS.kind();
256 Data = CVS.RecordData.drop_front(sizeof(RecordPrefix));
257 return Error::success();
258 }
259
260 std::vector<uint8_t> Data;
261};
262
263template <> void SymbolRecordImpl<ScopeEndSym>::map(IO &IO) {}
264
265void UnknownSymbolRecord::map(yaml::IO &io) {
266 yaml::BinaryRef Binary;
267 if (io.outputting())
268 Binary = yaml::BinaryRef(Data);
269 io.mapRequired("Data", Binary);
270 if (!io.outputting()) {
271 std::string Str;
272 raw_string_ostream OS(Str);
273 Binary.writeAsBinary(OS);
274 OS.flush();
275 Data.assign(Str.begin(), Str.end());
276 }
277}
278
279template <> void SymbolRecordImpl<Thunk32Sym>::map(IO &IO) {
280 IO.mapRequired("Parent", Symbol.Parent);
281 IO.mapRequired("End", Symbol.End);
282 IO.mapRequired("Next", Symbol.Next);
283 IO.mapRequired("Off", Symbol.Offset);
284 IO.mapRequired("Seg", Symbol.Segment);
285 IO.mapRequired("Len", Symbol.Length);
286 IO.mapRequired("Ordinal", Symbol.Thunk);
287}
288
289template <> void SymbolRecordImpl<TrampolineSym>::map(IO &IO) {
290 IO.mapRequired("Type", Symbol.Type);
291 IO.mapRequired("Size", Symbol.Size);
292 IO.mapRequired("ThunkOff", Symbol.ThunkOffset);
293 IO.mapRequired("TargetOff", Symbol.TargetOffset);
294 IO.mapRequired("ThunkSection", Symbol.ThunkSection);
295 IO.mapRequired("TargetSection", Symbol.TargetSection);
296}
297
298template <> void SymbolRecordImpl<SectionSym>::map(IO &IO) {
299 IO.mapRequired("SectionNumber", Symbol.SectionNumber);
300 IO.mapRequired("Alignment", Symbol.Alignment);
301 IO.mapRequired("Rva", Symbol.Rva);
302 IO.mapRequired("Length", Symbol.Length);
303 IO.mapRequired("Characteristics", Symbol.Characteristics);
304 IO.mapRequired("Name", Symbol.Name);
305}
306
307template <> void SymbolRecordImpl<CoffGroupSym>::map(IO &IO) {
308 IO.mapRequired("Size", Symbol.Size);
309 IO.mapRequired("Characteristics", Symbol.Characteristics);
310 IO.mapRequired("Offset", Symbol.Offset);
311 IO.mapRequired("Segment", Symbol.Segment);
312 IO.mapRequired("Name", Symbol.Name);
313}
314
315template <> void SymbolRecordImpl<ExportSym>::map(IO &IO) {
316 IO.mapRequired("Ordinal", Symbol.Ordinal);
317 IO.mapRequired("Flags", Symbol.Flags);
318 IO.mapRequired("Name", Symbol.Name);
319}
320
321template <> void SymbolRecordImpl<ProcSym>::map(IO &IO) {
322 IO.mapOptional("PtrParent", Symbol.Parent, 0U);
323 IO.mapOptional("PtrEnd", Symbol.End, 0U);
324 IO.mapOptional("PtrNext", Symbol.Next, 0U);
325 IO.mapRequired("CodeSize", Symbol.CodeSize);
326 IO.mapRequired("DbgStart", Symbol.DbgStart);
327 IO.mapRequired("DbgEnd", Symbol.DbgEnd);
328 IO.mapRequired("FunctionType", Symbol.FunctionType);
329 IO.mapOptional("Offset", Symbol.CodeOffset, 0U);
330 IO.mapOptional("Segment", Symbol.Segment, uint16_t(0));
331 IO.mapRequired("Flags", Symbol.Flags);
332 IO.mapRequired("DisplayName", Symbol.Name);
333}
334
335template <> void SymbolRecordImpl<RegisterSym>::map(IO &IO) {
336 IO.mapRequired("Type", Symbol.Index);
337 IO.mapRequired("Seg", Symbol.Register);
338 IO.mapRequired("Name", Symbol.Name);
339}
340
341template <> void SymbolRecordImpl<PublicSym32>::map(IO &IO) {
342 IO.mapRequired("Flags", Symbol.Flags);
343 IO.mapOptional("Offset", Symbol.Offset, 0U);
344 IO.mapOptional("Segment", Symbol.Segment, uint16_t(0));
345 IO.mapRequired("Name", Symbol.Name);
346}
347
348template <> void SymbolRecordImpl<ProcRefSym>::map(IO &IO) {
349 IO.mapRequired("SumName", Symbol.SumName);
350 IO.mapRequired("SymOffset", Symbol.SymOffset);
351 IO.mapRequired("Mod", Symbol.Module);
352 IO.mapRequired("Name", Symbol.Name);
353}
354
355template <> void SymbolRecordImpl<EnvBlockSym>::map(IO &IO) {
356 IO.mapRequired("Entries", Symbol.Fields);
357}
358
359template <> void SymbolRecordImpl<InlineSiteSym>::map(IO &IO) {
360 IO.mapOptional("PtrParent", Symbol.Parent, 0U);
361 IO.mapOptional("PtrEnd", Symbol.End, 0U);
362 IO.mapRequired("Inlinee", Symbol.Inlinee);
363 // TODO: The binary annotations
364}
365
366template <> void SymbolRecordImpl<LocalSym>::map(IO &IO) {
367 IO.mapRequired("Type", Symbol.Type);
368 IO.mapRequired("Flags", Symbol.Flags);
369
370 IO.mapRequired("VarName", Symbol.Name);
371}
372
373template <> void SymbolRecordImpl<DefRangeSym>::map(IO &IO) {
374 IO.mapRequired("Program", Symbol.Program);
375 IO.mapRequired("Range", Symbol.Range);
376 IO.mapRequired("Gaps", Symbol.Gaps);
377}
378
379template <> void SymbolRecordImpl<DefRangeSubfieldSym>::map(IO &IO) {
380 IO.mapRequired("Program", Symbol.Program);
381 IO.mapRequired("OffsetInParent", Symbol.OffsetInParent);
382 IO.mapRequired("Range", Symbol.Range);
383 IO.mapRequired("Gaps", Symbol.Gaps);
384}
385
386template <> void SymbolRecordImpl<DefRangeRegisterSym>::map(IO &IO) {
387 IO.mapRequired("Register", Symbol.Hdr.Register);
388 IO.mapRequired("MayHaveNoName", Symbol.Hdr.MayHaveNoName);
389 IO.mapRequired("Range", Symbol.Range);
390 IO.mapRequired("Gaps", Symbol.Gaps);
391}
392
393template <> void SymbolRecordImpl<DefRangeFramePointerRelSym>::map(IO &IO) {
394 IO.mapRequired("Offset", Symbol.Hdr.Offset);
395 IO.mapRequired("Range", Symbol.Range);
396 IO.mapRequired("Gaps", Symbol.Gaps);
397}
398
399template <> void SymbolRecordImpl<DefRangeSubfieldRegisterSym>::map(IO &IO) {
400 IO.mapRequired("Register", Symbol.Hdr.Register);
401 IO.mapRequired("MayHaveNoName", Symbol.Hdr.MayHaveNoName);
402 IO.mapRequired("OffsetInParent", Symbol.Hdr.OffsetInParent);
403 IO.mapRequired("Range", Symbol.Range);
404 IO.mapRequired("Gaps", Symbol.Gaps);
405}
406
407template <>
408void SymbolRecordImpl<DefRangeFramePointerRelFullScopeSym>::map(IO &IO) {
409 IO.mapRequired("Register", Symbol.Offset);
410}
411
412template <> void SymbolRecordImpl<DefRangeRegisterRelSym>::map(IO &IO) {
413 IO.mapRequired("Register", Symbol.Hdr.Register);
414 IO.mapRequired("Flags", Symbol.Hdr.Flags);
415 IO.mapRequired("BasePointerOffset", Symbol.Hdr.BasePointerOffset);
416 IO.mapRequired("Range", Symbol.Range);
417 IO.mapRequired("Gaps", Symbol.Gaps);
418}
419
420template <> void SymbolRecordImpl<BlockSym>::map(IO &IO) {
421 IO.mapOptional("PtrParent", Symbol.Parent, 0U);
422 IO.mapOptional("PtrEnd", Symbol.End, 0U);
423 IO.mapRequired("CodeSize", Symbol.CodeSize);
424 IO.mapOptional("Offset", Symbol.CodeOffset, 0U);
425 IO.mapOptional("Segment", Symbol.Segment, uint16_t(0));
426 IO.mapRequired("BlockName", Symbol.Name);
427}
428
429template <> void SymbolRecordImpl<LabelSym>::map(IO &IO) {
430 IO.mapOptional("Offset", Symbol.CodeOffset, 0U);
431 IO.mapOptional("Segment", Symbol.Segment, uint16_t(0));
432 IO.mapRequired("Flags", Symbol.Flags);
433 IO.mapRequired("Flags", Symbol.Flags);
434 IO.mapRequired("DisplayName", Symbol.Name);
435}
436
437template <> void SymbolRecordImpl<ObjNameSym>::map(IO &IO) {
438 IO.mapRequired("Signature", Symbol.Signature);
439 IO.mapRequired("ObjectName", Symbol.Name);
440}
441
442template <> void SymbolRecordImpl<Compile2Sym>::map(IO &IO) {
443 IO.mapRequired("Flags", Symbol.Flags);
444 IO.mapRequired("Machine", Symbol.Machine);
445 IO.mapRequired("FrontendMajor", Symbol.VersionFrontendMajor);
446 IO.mapRequired("FrontendMinor", Symbol.VersionFrontendMinor);
447 IO.mapRequired("FrontendBuild", Symbol.VersionFrontendBuild);
448 IO.mapRequired("BackendMajor", Symbol.VersionBackendMajor);
449 IO.mapRequired("BackendMinor", Symbol.VersionBackendMinor);
450 IO.mapRequired("BackendBuild", Symbol.VersionBackendBuild);
451 IO.mapRequired("Version", Symbol.Version);
452}
453
454template <> void SymbolRecordImpl<Compile3Sym>::map(IO &IO) {
455 IO.mapRequired("Flags", Symbol.Flags);
456 IO.mapRequired("Machine", Symbol.Machine);
457 IO.mapRequired("FrontendMajor", Symbol.VersionFrontendMajor);
458 IO.mapRequired("FrontendMinor", Symbol.VersionFrontendMinor);
459 IO.mapRequired("FrontendBuild", Symbol.VersionFrontendBuild);
460 IO.mapRequired("FrontendQFE", Symbol.VersionFrontendQFE);
461 IO.mapRequired("BackendMajor", Symbol.VersionBackendMajor);
462 IO.mapRequired("BackendMinor", Symbol.VersionBackendMinor);
463 IO.mapRequired("BackendBuild", Symbol.VersionBackendBuild);
464 IO.mapRequired("BackendQFE", Symbol.VersionBackendQFE);
465 IO.mapRequired("Version", Symbol.Version);
466}
467
468template <> void SymbolRecordImpl<FrameProcSym>::map(IO &IO) {
469 IO.mapRequired("TotalFrameBytes", Symbol.TotalFrameBytes);
470 IO.mapRequired("PaddingFrameBytes", Symbol.PaddingFrameBytes);
471 IO.mapRequired("OffsetToPadding", Symbol.OffsetToPadding);
472 IO.mapRequired("BytesOfCalleeSavedRegisters",
473 Symbol.BytesOfCalleeSavedRegisters);
474 IO.mapRequired("OffsetOfExceptionHandler", Symbol.OffsetOfExceptionHandler);
475 IO.mapRequired("SectionIdOfExceptionHandler",
476 Symbol.SectionIdOfExceptionHandler);
477 IO.mapRequired("Flags", Symbol.Flags);
478}
479
480template <> void SymbolRecordImpl<CallSiteInfoSym>::map(IO &IO) {
481 IO.mapOptional("Offset", Symbol.CodeOffset, 0U);
482 IO.mapOptional("Segment", Symbol.Segment, uint16_t(0));
483 IO.mapRequired("Type", Symbol.Type);
484}
485
486template <> void SymbolRecordImpl<FileStaticSym>::map(IO &IO) {
487 IO.mapRequired("Index", Symbol.Index);
488 IO.mapRequired("ModFilenameOffset", Symbol.ModFilenameOffset);
489 IO.mapRequired("Flags", Symbol.Flags);
490 IO.mapRequired("Name", Symbol.Name);
491}
492
493template <> void SymbolRecordImpl<HeapAllocationSiteSym>::map(IO &IO) {
494 IO.mapOptional("Offset", Symbol.CodeOffset, 0U);
495 IO.mapOptional("Segment", Symbol.Segment, uint16_t(0));
496 IO.mapRequired("CallInstructionSize", Symbol.CallInstructionSize);
497 IO.mapRequired("Type", Symbol.Type);
498}
499
500template <> void SymbolRecordImpl<FrameCookieSym>::map(IO &IO) {
501 IO.mapRequired("Register", Symbol.Register);
502 IO.mapRequired("CookieKind", Symbol.CookieKind);
503 IO.mapRequired("Flags", Symbol.Flags);
504}
505
506template <> void SymbolRecordImpl<CallerSym>::map(IO &IO) {
507 IO.mapRequired("FuncID", Symbol.Indices);
508}
509
510template <> void SymbolRecordImpl<UDTSym>::map(IO &IO) {
511 IO.mapRequired("Type", Symbol.Type);
512 IO.mapRequired("UDTName", Symbol.Name);
513}
514
515template <> void SymbolRecordImpl<BuildInfoSym>::map(IO &IO) {
516 IO.mapRequired("BuildId", Symbol.BuildId);
517}
518
519template <> void SymbolRecordImpl<BPRelativeSym>::map(IO &IO) {
520 IO.mapRequired("Offset", Symbol.Offset);
521 IO.mapRequired("Type", Symbol.Type);
522 IO.mapRequired("VarName", Symbol.Name);
523}
524
525template <> void SymbolRecordImpl<RegRelativeSym>::map(IO &IO) {
526 IO.mapRequired("Offset", Symbol.Offset);
527 IO.mapRequired("Type", Symbol.Type);
528 IO.mapRequired("Register", Symbol.Register);
529 IO.mapRequired("VarName", Symbol.Name);
530}
531
532template <> void SymbolRecordImpl<ConstantSym>::map(IO &IO) {
533 IO.mapRequired("Type", Symbol.Type);
534 IO.mapRequired("Value", Symbol.Value);
535 IO.mapRequired("Name", Symbol.Name);
536}
537
538template <> void SymbolRecordImpl<DataSym>::map(IO &IO) {
539 IO.mapRequired("Type", Symbol.Type);
540 IO.mapOptional("Offset", Symbol.DataOffset, 0U);
541 IO.mapOptional("Segment", Symbol.Segment, uint16_t(0));
542 IO.mapRequired("DisplayName", Symbol.Name);
543}
544
545template <> void SymbolRecordImpl<ThreadLocalDataSym>::map(IO &IO) {
546 IO.mapRequired("Type", Symbol.Type);
547 IO.mapOptional("Offset", Symbol.DataOffset, 0U);
548 IO.mapOptional("Segment", Symbol.Segment, uint16_t(0));
549 IO.mapRequired("DisplayName", Symbol.Name);
550}
551
552template <> void SymbolRecordImpl<UsingNamespaceSym>::map(IO &IO) {
553 IO.mapRequired("Namespace", Symbol.Name);
554}
555
556template <> void SymbolRecordImpl<AnnotationSym>::map(IO &IO) {
557 IO.mapOptional("Offset", Symbol.CodeOffset, 0U);
558 IO.mapOptional("Segment", Symbol.Segment, uint16_t(0));
559 IO.mapRequired("Strings", Symbol.Strings);
560}
561
562} // end namespace detail
563} // end namespace CodeViewYAML
564} // end namespace llvm
565
566CVSymbol CodeViewYAML::SymbolRecord::toCodeViewSymbol(
567 BumpPtrAllocator &Allocator, CodeViewContainer Container) const {
568 return Symbol->toCodeViewSymbol(Allocator, Container);
569}
570
571namespace llvm {
572namespace yaml {
573
574template <> struct MappingTraits<SymbolRecordBase> {
575 static void mapping(IO &io, SymbolRecordBase &Record) { Record.map(io); }
576};
577
578} // end namespace yaml
579} // end namespace llvm
580
581template <typename SymbolType>
582static inline Expected<CodeViewYAML::SymbolRecord>
583fromCodeViewSymbolImpl(CVSymbol Symbol) {
584 CodeViewYAML::SymbolRecord Result;
585
586 auto Impl = std::make_shared<SymbolType>(Symbol.kind());
587 if (auto EC = Impl->fromCodeViewSymbol(Symbol))
588 return std::move(EC);
589 Result.Symbol = Impl;
590 return Result;
591}
592
593Expected<CodeViewYAML::SymbolRecord>
594CodeViewYAML::SymbolRecord::fromCodeViewSymbol(CVSymbol Symbol) {
595#define SYMBOL_RECORD(EnumName, EnumVal, ClassName) \
596 case EnumName: \
597 return fromCodeViewSymbolImpl<SymbolRecordImpl<ClassName>>(Symbol);
598#define SYMBOL_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName) \
599 SYMBOL_RECORD(EnumName, EnumVal, ClassName)
600 switch (Symbol.kind()) {
601#include "llvm/DebugInfo/CodeView/CodeViewSymbols.def"
602 default:
603 return fromCodeViewSymbolImpl<UnknownSymbolRecord>(Symbol);
604 }
605 return make_error<CodeViewError>(cv_error_code::corrupt_record);
606}
607
608template <typename ConcreteType>
609static void mapSymbolRecordImpl(IO &IO, const char *Class, SymbolKind Kind,
610 CodeViewYAML::SymbolRecord &Obj) {
611 if (!IO.outputting())
612 Obj.Symbol = std::make_shared<ConcreteType>(Kind);
613
614 IO.mapRequired(Class, *Obj.Symbol);
615}
616
617void MappingTraits<CodeViewYAML::SymbolRecord>::mapping(
618 IO &IO, CodeViewYAML::SymbolRecord &Obj) {
619 SymbolKind Kind;
1
'Kind' declared without an initial value
620 if (IO.outputting())
2
Assuming the condition is false
3
Taking false branch
621 Kind = Obj.Symbol->Kind;
622 IO.mapRequired("Kind", Kind);
4
Passing value via 2nd parameter 'Val'
5
Calling 'IO::mapRequired'
623
624#define SYMBOL_RECORD(EnumName, EnumVal, ClassName) \
625 case EnumName: \
626 mapSymbolRecordImpl<SymbolRecordImpl<ClassName>>(IO, #ClassName, Kind, \
627 Obj); \
628 break;
629#define SYMBOL_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName) \
630 SYMBOL_RECORD(EnumName, EnumVal, ClassName)
631 switch (Kind) {
632#include "llvm/DebugInfo/CodeView/CodeViewSymbols.def"
633 default:
634 mapSymbolRecordImpl<UnknownSymbolRecord>(IO, "UnknownSym", Kind, Obj);
635 }
636}

/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/include/llvm/Support/YAMLTraits.h

1//===- llvm/Support/YAMLTraits.h --------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_SUPPORT_YAMLTRAITS_H
10#define LLVM_SUPPORT_YAMLTRAITS_H
11
12#include "llvm/ADT/Optional.h"
13#include "llvm/ADT/SmallVector.h"
14#include "llvm/ADT/StringExtras.h"
15#include "llvm/ADT/StringMap.h"
16#include "llvm/ADT/StringRef.h"
17#include "llvm/ADT/Twine.h"
18#include "llvm/Support/AlignOf.h"
19#include "llvm/Support/Allocator.h"
20#include "llvm/Support/Endian.h"
21#include "llvm/Support/Regex.h"
22#include "llvm/Support/SourceMgr.h"
23#include "llvm/Support/YAMLParser.h"
24#include "llvm/Support/raw_ostream.h"
25#include <cassert>
26#include <cctype>
27#include <cstddef>
28#include <cstdint>
29#include <iterator>
30#include <map>
31#include <memory>
32#include <new>
33#include <string>
34#include <system_error>
35#include <type_traits>
36#include <vector>
37
38namespace llvm {
39namespace yaml {
40
41enum class NodeKind : uint8_t {
42 Scalar,
43 Map,
44 Sequence,
45};
46
47struct EmptyContext {};
48
49/// This class should be specialized by any type that needs to be converted
50/// to/from a YAML mapping. For example:
51///
52/// struct MappingTraits<MyStruct> {
53/// static void mapping(IO &io, MyStruct &s) {
54/// io.mapRequired("name", s.name);
55/// io.mapRequired("size", s.size);
56/// io.mapOptional("age", s.age);
57/// }
58/// };
59template<class T>
60struct MappingTraits {
61 // Must provide:
62 // static void mapping(IO &io, T &fields);
63 // Optionally may provide:
64 // static StringRef validate(IO &io, T &fields);
65 //
66 // The optional flow flag will cause generated YAML to use a flow mapping
67 // (e.g. { a: 0, b: 1 }):
68 // static const bool flow = true;
69};
70
71/// This class is similar to MappingTraits<T> but allows you to pass in
72/// additional context for each map operation. For example:
73///
74/// struct MappingContextTraits<MyStruct, MyContext> {
75/// static void mapping(IO &io, MyStruct &s, MyContext &c) {
76/// io.mapRequired("name", s.name);
77/// io.mapRequired("size", s.size);
78/// io.mapOptional("age", s.age);
79/// ++c.TimesMapped;
80/// }
81/// };
82template <class T, class Context> struct MappingContextTraits {
83 // Must provide:
84 // static void mapping(IO &io, T &fields, Context &Ctx);
85 // Optionally may provide:
86 // static StringRef validate(IO &io, T &fields, Context &Ctx);
87 //
88 // The optional flow flag will cause generated YAML to use a flow mapping
89 // (e.g. { a: 0, b: 1 }):
90 // static const bool flow = true;
91};
92
93/// This class should be specialized by any integral type that converts
94/// to/from a YAML scalar where there is a one-to-one mapping between
95/// in-memory values and a string in YAML. For example:
96///
97/// struct ScalarEnumerationTraits<Colors> {
98/// static void enumeration(IO &io, Colors &value) {
99/// io.enumCase(value, "red", cRed);
100/// io.enumCase(value, "blue", cBlue);
101/// io.enumCase(value, "green", cGreen);
102/// }
103/// };
104template <typename T, typename Enable = void> struct ScalarEnumerationTraits {
105 // Must provide:
106 // static void enumeration(IO &io, T &value);
107};
108
109/// This class should be specialized by any integer type that is a union
110/// of bit values and the YAML representation is a flow sequence of
111/// strings. For example:
112///
113/// struct ScalarBitSetTraits<MyFlags> {
114/// static void bitset(IO &io, MyFlags &value) {
115/// io.bitSetCase(value, "big", flagBig);
116/// io.bitSetCase(value, "flat", flagFlat);
117/// io.bitSetCase(value, "round", flagRound);
118/// }
119/// };
120template <typename T, typename Enable = void> struct ScalarBitSetTraits {
121 // Must provide:
122 // static void bitset(IO &io, T &value);
123};
124
125/// Describe which type of quotes should be used when quoting is necessary.
126/// Some non-printable characters need to be double-quoted, while some others
127/// are fine with simple-quoting, and some don't need any quoting.
128enum class QuotingType { None, Single, Double };
129
130/// This class should be specialized by type that requires custom conversion
131/// to/from a yaml scalar. For example:
132///
133/// template<>
134/// struct ScalarTraits<MyType> {
135/// static void output(const MyType &val, void*, llvm::raw_ostream &out) {
136/// // stream out custom formatting
137/// out << llvm::format("%x", val);
138/// }
139/// static StringRef input(StringRef scalar, void*, MyType &value) {
140/// // parse scalar and set `value`
141/// // return empty string on success, or error string
142/// return StringRef();
143/// }
144/// static QuotingType mustQuote(StringRef) { return QuotingType::Single; }
145/// };
146template <typename T, typename Enable = void> struct ScalarTraits {
147 // Must provide:
148 //
149 // Function to write the value as a string:
150 // static void output(const T &value, void *ctxt, llvm::raw_ostream &out);
151 //
152 // Function to convert a string to a value. Returns the empty
153 // StringRef on success or an error string if string is malformed:
154 // static StringRef input(StringRef scalar, void *ctxt, T &value);
155 //
156 // Function to determine if the value should be quoted.
157 // static QuotingType mustQuote(StringRef);
158};
159
160/// This class should be specialized by type that requires custom conversion
161/// to/from a YAML literal block scalar. For example:
162///
163/// template <>
164/// struct BlockScalarTraits<MyType> {
165/// static void output(const MyType &Value, void*, llvm::raw_ostream &Out)
166/// {
167/// // stream out custom formatting
168/// Out << Value;
169/// }
170/// static StringRef input(StringRef Scalar, void*, MyType &Value) {
171/// // parse scalar and set `value`
172/// // return empty string on success, or error string
173/// return StringRef();
174/// }
175/// };
176template <typename T>
177struct BlockScalarTraits {
178 // Must provide:
179 //
180 // Function to write the value as a string:
181 // static void output(const T &Value, void *ctx, llvm::raw_ostream &Out);
182 //
183 // Function to convert a string to a value. Returns the empty
184 // StringRef on success or an error string if string is malformed:
185 // static StringRef input(StringRef Scalar, void *ctxt, T &Value);
186 //
187 // Optional:
188 // static StringRef inputTag(T &Val, std::string Tag)
189 // static void outputTag(const T &Val, raw_ostream &Out)
190};
191
192/// This class should be specialized by type that requires custom conversion
193/// to/from a YAML scalar with optional tags. For example:
194///
195/// template <>
196/// struct TaggedScalarTraits<MyType> {
197/// static void output(const MyType &Value, void*, llvm::raw_ostream
198/// &ScalarOut, llvm::raw_ostream &TagOut)
199/// {
200/// // stream out custom formatting including optional Tag
201/// Out << Value;
202/// }
203/// static StringRef input(StringRef Scalar, StringRef Tag, void*, MyType
204/// &Value) {
205/// // parse scalar and set `value`
206/// // return empty string on success, or error string
207/// return StringRef();
208/// }
209/// static QuotingType mustQuote(const MyType &Value, StringRef) {
210/// return QuotingType::Single;
211/// }
212/// };
213template <typename T> struct TaggedScalarTraits {
214 // Must provide:
215 //
216 // Function to write the value and tag as strings:
217 // static void output(const T &Value, void *ctx, llvm::raw_ostream &ScalarOut,
218 // llvm::raw_ostream &TagOut);
219 //
220 // Function to convert a string to a value. Returns the empty
221 // StringRef on success or an error string if string is malformed:
222 // static StringRef input(StringRef Scalar, StringRef Tag, void *ctxt, T
223 // &Value);
224 //
225 // Function to determine if the value should be quoted.
226 // static QuotingType mustQuote(const T &Value, StringRef Scalar);
227};
228
229/// This class should be specialized by any type that needs to be converted
230/// to/from a YAML sequence. For example:
231///
232/// template<>
233/// struct SequenceTraits<MyContainer> {
234/// static size_t size(IO &io, MyContainer &seq) {
235/// return seq.size();
236/// }
237/// static MyType& element(IO &, MyContainer &seq, size_t index) {
238/// if ( index >= seq.size() )
239/// seq.resize(index+1);
240/// return seq[index];
241/// }
242/// };
243template<typename T, typename EnableIf = void>
244struct SequenceTraits {
245 // Must provide:
246 // static size_t size(IO &io, T &seq);
247 // static T::value_type& element(IO &io, T &seq, size_t index);
248 //
249 // The following is option and will cause generated YAML to use
250 // a flow sequence (e.g. [a,b,c]).
251 // static const bool flow = true;
252};
253
254/// This class should be specialized by any type for which vectors of that
255/// type need to be converted to/from a YAML sequence.
256template<typename T, typename EnableIf = void>
257struct SequenceElementTraits {
258 // Must provide:
259 // static const bool flow;
260};
261
262/// This class should be specialized by any type that needs to be converted
263/// to/from a list of YAML documents.
264template<typename T>
265struct DocumentListTraits {
266 // Must provide:
267 // static size_t size(IO &io, T &seq);
268 // static T::value_type& element(IO &io, T &seq, size_t index);
269};
270
271/// This class should be specialized by any type that needs to be converted
272/// to/from a YAML mapping in the case where the names of the keys are not known
273/// in advance, e.g. a string map.
274template <typename T>
275struct CustomMappingTraits {
276 // static void inputOne(IO &io, StringRef key, T &elem);
277 // static void output(IO &io, T &elem);
278};
279
280/// This class should be specialized by any type that can be represented as
281/// a scalar, map, or sequence, decided dynamically. For example:
282///
283/// typedef std::unique_ptr<MyBase> MyPoly;
284///
285/// template<>
286/// struct PolymorphicTraits<MyPoly> {
287/// static NodeKind getKind(const MyPoly &poly) {
288/// return poly->getKind();
289/// }
290/// static MyScalar& getAsScalar(MyPoly &poly) {
291/// if (!poly || !isa<MyScalar>(poly))
292/// poly.reset(new MyScalar());
293/// return *cast<MyScalar>(poly.get());
294/// }
295/// // ...
296/// };
297template <typename T> struct PolymorphicTraits {
298 // Must provide:
299 // static NodeKind getKind(const T &poly);
300 // static scalar_type &getAsScalar(T &poly);
301 // static map_type &getAsMap(T &poly);
302 // static sequence_type &getAsSequence(T &poly);
303};
304
305// Only used for better diagnostics of missing traits
306template <typename T>
307struct MissingTrait;
308
309// Test if ScalarEnumerationTraits<T> is defined on type T.
310template <class T>
311struct has_ScalarEnumerationTraits
312{
313 using Signature_enumeration = void (*)(class IO&, T&);
314
315 template <typename U>
316 static char test(SameType<Signature_enumeration, &U::enumeration>*);
317
318 template <typename U>
319 static double test(...);
320
321 static bool const value =
322 (sizeof(test<ScalarEnumerationTraits<T>>(nullptr)) == 1);
323};
324
325// Test if ScalarBitSetTraits<T> is defined on type T.
326template <class T>
327struct has_ScalarBitSetTraits
328{
329 using Signature_bitset = void (*)(class IO&, T&);
330
331 template <typename U>
332 static char test(SameType<Signature_bitset, &U::bitset>*);
333
334 template <typename U>
335 static double test(...);
336
337 static bool const value = (sizeof(test<ScalarBitSetTraits<T>>(nullptr)) == 1);
338};
339
340// Test if ScalarTraits<T> is defined on type T.
341template <class T>
342struct has_ScalarTraits
343{
344 using Signature_input = StringRef (*)(StringRef, void*, T&);
345 using Signature_output = void (*)(const T&, void*, raw_ostream&);
346 using Signature_mustQuote = QuotingType (*)(StringRef);
347
348 template <typename U>
349 static char test(SameType<Signature_input, &U::input> *,
350 SameType<Signature_output, &U::output> *,
351 SameType<Signature_mustQuote, &U::mustQuote> *);
352
353 template <typename U>
354 static double test(...);
355
356 static bool const value =
357 (sizeof(test<ScalarTraits<T>>(nullptr, nullptr, nullptr)) == 1);
358};
359
360// Test if BlockScalarTraits<T> is defined on type T.
361template <class T>
362struct has_BlockScalarTraits
363{
364 using Signature_input = StringRef (*)(StringRef, void *, T &);
365 using Signature_output = void (*)(const T &, void *, raw_ostream &);
366
367 template <typename U>
368 static char test(SameType<Signature_input, &U::input> *,
369 SameType<Signature_output, &U::output> *);
370
371 template <typename U>
372 static double test(...);
373
374 static bool const value =
375 (sizeof(test<BlockScalarTraits<T>>(nullptr, nullptr)) == 1);
376};
377
378// Test if TaggedScalarTraits<T> is defined on type T.
379template <class T> struct has_TaggedScalarTraits {
380 using Signature_input = StringRef (*)(StringRef, StringRef, void *, T &);
381 using Signature_output = void (*)(const T &, void *, raw_ostream &,
382 raw_ostream &);
383 using Signature_mustQuote = QuotingType (*)(const T &, StringRef);
384
385 template <typename U>
386 static char test(SameType<Signature_input, &U::input> *,
387 SameType<Signature_output, &U::output> *,
388 SameType<Signature_mustQuote, &U::mustQuote> *);
389
390 template <typename U> static double test(...);
391
392 static bool const value =
393 (sizeof(test<TaggedScalarTraits<T>>(nullptr, nullptr, nullptr)) == 1);
394};
395
396// Test if MappingContextTraits<T> is defined on type T.
397template <class T, class Context> struct has_MappingTraits {
398 using Signature_mapping = void (*)(class IO &, T &, Context &);
399
400 template <typename U>
401 static char test(SameType<Signature_mapping, &U::mapping>*);
402
403 template <typename U>
404 static double test(...);
405
406 static bool const value =
407 (sizeof(test<MappingContextTraits<T, Context>>(nullptr)) == 1);
408};
409
410// Test if MappingTraits<T> is defined on type T.
411template <class T> struct has_MappingTraits<T, EmptyContext> {
412 using Signature_mapping = void (*)(class IO &, T &);
413
414 template <typename U>
415 static char test(SameType<Signature_mapping, &U::mapping> *);
416
417 template <typename U> static double test(...);
418
419 static bool const value = (sizeof(test<MappingTraits<T>>(nullptr)) == 1);
420};
421
422// Test if MappingContextTraits<T>::validate() is defined on type T.
423template <class T, class Context> struct has_MappingValidateTraits {
424 using Signature_validate = StringRef (*)(class IO &, T &, Context &);
425
426 template <typename U>
427 static char test(SameType<Signature_validate, &U::validate>*);
428
429 template <typename U>
430 static double test(...);
431
432 static bool const value =
433 (sizeof(test<MappingContextTraits<T, Context>>(nullptr)) == 1);
434};
435
436// Test if MappingTraits<T>::validate() is defined on type T.
437template <class T> struct has_MappingValidateTraits<T, EmptyContext> {
438 using Signature_validate = StringRef (*)(class IO &, T &);
439
440 template <typename U>
441 static char test(SameType<Signature_validate, &U::validate> *);
442
443 template <typename U> static double test(...);
444
445 static bool const value = (sizeof(test<MappingTraits<T>>(nullptr)) == 1);
446};
447
448// Test if SequenceTraits<T> is defined on type T.
449template <class T>
450struct has_SequenceMethodTraits
451{
452 using Signature_size = size_t (*)(class IO&, T&);
453
454 template <typename U>
455 static char test(SameType<Signature_size, &U::size>*);
456
457 template <typename U>
458 static double test(...);
459
460 static bool const value = (sizeof(test<SequenceTraits<T>>(nullptr)) == 1);
461};
462
463// Test if CustomMappingTraits<T> is defined on type T.
464template <class T>
465struct has_CustomMappingTraits
466{
467 using Signature_input = void (*)(IO &io, StringRef key, T &v);
468
469 template <typename U>
470 static char test(SameType<Signature_input, &U::inputOne>*);
471
472 template <typename U>
473 static double test(...);
474
475 static bool const value =
476 (sizeof(test<CustomMappingTraits<T>>(nullptr)) == 1);
477};
478
479// has_FlowTraits<int> will cause an error with some compilers because
480// it subclasses int. Using this wrapper only instantiates the
481// real has_FlowTraits only if the template type is a class.
482template <typename T, bool Enabled = std::is_class<T>::value>
483class has_FlowTraits
484{
485public:
486 static const bool value = false;
487};
488
489// Some older gcc compilers don't support straight forward tests
490// for members, so test for ambiguity cause by the base and derived
491// classes both defining the member.
492template <class T>
493struct has_FlowTraits<T, true>
494{
495 struct Fallback { bool flow; };
496 struct Derived : T, Fallback { };
497
498 template<typename C>
499 static char (&f(SameType<bool Fallback::*, &C::flow>*))[1];
500
501 template<typename C>
502 static char (&f(...))[2];
503
504 static bool const value = sizeof(f<Derived>(nullptr)) == 2;
505};
506
507// Test if SequenceTraits<T> is defined on type T
508template<typename T>
509struct has_SequenceTraits : public std::integral_constant<bool,
510 has_SequenceMethodTraits<T>::value > { };
511
512// Test if DocumentListTraits<T> is defined on type T
513template <class T>
514struct has_DocumentListTraits
515{
516 using Signature_size = size_t (*)(class IO &, T &);
517
518 template <typename U>
519 static char test(SameType<Signature_size, &U::size>*);
520
521 template <typename U>
522 static double test(...);
523
524 static bool const value = (sizeof(test<DocumentListTraits<T>>(nullptr))==1);
525};
526
527template <class T> struct has_PolymorphicTraits {
528 using Signature_getKind = NodeKind (*)(const T &);
529
530 template <typename U>
531 static char test(SameType<Signature_getKind, &U::getKind> *);
532
533 template <typename U> static double test(...);
534
535 static bool const value = (sizeof(test<PolymorphicTraits<T>>(nullptr)) == 1);
536};
537
538inline bool isNumeric(StringRef S) {
539 const static auto skipDigits = [](StringRef Input) {
540 return Input.drop_front(
541 std::min(Input.find_first_not_of("0123456789"), Input.size()));
542 };
543
544 // Make S.front() and S.drop_front().front() (if S.front() is [+-]) calls
545 // safe.
546 if (S.empty() || S.equals("+") || S.equals("-"))
547 return false;
548
549 if (S.equals(".nan") || S.equals(".NaN") || S.equals(".NAN"))
550 return true;
551
552 // Infinity and decimal numbers can be prefixed with sign.
553 StringRef Tail = (S.front() == '-' || S.front() == '+') ? S.drop_front() : S;
554
555 // Check for infinity first, because checking for hex and oct numbers is more
556 // expensive.
557 if (Tail.equals(".inf") || Tail.equals(".Inf") || Tail.equals(".INF"))
558 return true;
559
560 // Section 10.3.2 Tag Resolution
561 // YAML 1.2 Specification prohibits Base 8 and Base 16 numbers prefixed with
562 // [-+], so S should be used instead of Tail.
563 if (S.startswith("0o"))
564 return S.size() > 2 &&
565 S.drop_front(2).find_first_not_of("01234567") == StringRef::npos;
566
567 if (S.startswith("0x"))
568 return S.size() > 2 && S.drop_front(2).find_first_not_of(
569 "0123456789abcdefABCDEF") == StringRef::npos;
570
571 // Parse float: [-+]? (\. [0-9]+ | [0-9]+ (\. [0-9]* )?) ([eE] [-+]? [0-9]+)?
572 S = Tail;
573
574 // Handle cases when the number starts with '.' and hence needs at least one
575 // digit after dot (as opposed by number which has digits before the dot), but
576 // doesn't have one.
577 if (S.startswith(".") &&
578 (S.equals(".") ||
579 (S.size() > 1 && std::strchr("0123456789", S[1]) == nullptr)))
580 return false;
581
582 if (S.startswith("E") || S.startswith("e"))
583 return false;
584
585 enum ParseState {
586 Default,
587 FoundDot,
588 FoundExponent,
589 };
590 ParseState State = Default;
591
592 S = skipDigits(S);
593
594 // Accept decimal integer.
595 if (S.empty())
596 return true;
597
598 if (S.front() == '.') {
599 State = FoundDot;
600 S = S.drop_front();
601 } else if (S.front() == 'e' || S.front() == 'E') {
602 State = FoundExponent;
603 S = S.drop_front();
604 } else {
605 return false;
606 }
607
608 if (State == FoundDot) {
609 S = skipDigits(S);
610 if (S.empty())
611 return true;
612
613 if (S.front() == 'e' || S.front() == 'E') {
614 State = FoundExponent;
615 S = S.drop_front();
616 } else {
617 return false;
618 }
619 }
620
621 assert(State == FoundExponent && "Should have found exponent at this point.")((State == FoundExponent && "Should have found exponent at this point."
) ? static_cast<void> (0) : __assert_fail ("State == FoundExponent && \"Should have found exponent at this point.\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/include/llvm/Support/YAMLTraits.h"
, 621, __PRETTY_FUNCTION__))
;
622 if (S.empty())
623 return false;
624
625 if (S.front() == '+' || S.front() == '-') {
626 S = S.drop_front();
627 if (S.empty())
628 return false;
629 }
630
631 return skipDigits(S).empty();
632}
633
634inline bool isNull(StringRef S) {
635 return S.equals("null") || S.equals("Null") || S.equals("NULL") ||
636 S.equals("~");
637}
638
639inline bool isBool(StringRef S) {
640 return S.equals("true") || S.equals("True") || S.equals("TRUE") ||
641 S.equals("false") || S.equals("False") || S.equals("FALSE");
642}
643
644// 5.1. Character Set
645// The allowed character range explicitly excludes the C0 control block #x0-#x1F
646// (except for TAB #x9, LF #xA, and CR #xD which are allowed), DEL #x7F, the C1
647// control block #x80-#x9F (except for NEL #x85 which is allowed), the surrogate
648// block #xD800-#xDFFF, #xFFFE, and #xFFFF.
649inline QuotingType needsQuotes(StringRef S) {
650 if (S.empty())
651 return QuotingType::Single;
652 if (isspace(static_cast<unsigned char>(S.front())) ||
653 isspace(static_cast<unsigned char>(S.back())))
654 return QuotingType::Single;
655 if (isNull(S))
656 return QuotingType::Single;
657 if (isBool(S))
658 return QuotingType::Single;
659 if (isNumeric(S))
660 return QuotingType::Single;
661
662 // 7.3.3 Plain Style
663 // Plain scalars must not begin with most indicators, as this would cause
664 // ambiguity with other YAML constructs.
665 static constexpr char Indicators[] = R"(-?:\,[]{}#&*!|>'"%@`)";
666 if (S.find_first_of(Indicators) == 0)
667 return QuotingType::Single;
668
669 QuotingType MaxQuotingNeeded = QuotingType::None;
670 for (unsigned char C : S) {
671 // Alphanum is safe.
672 if (isAlnum(C))
673 continue;
674
675 switch (C) {
676 // Safe scalar characters.
677 case '_':
678 case '-':
679 case '^':
680 case '.':
681 case ',':
682 case ' ':
683 // TAB (0x9) is allowed in unquoted strings.
684 case 0x9:
685 continue;
686 // LF(0xA) and CR(0xD) may delimit values and so require at least single
687 // quotes.
688 case 0xA:
689 case 0xD:
690 MaxQuotingNeeded = QuotingType::Single;
691 continue;
692 // DEL (0x7F) are excluded from the allowed character range.
693 case 0x7F:
694 return QuotingType::Double;
695 // Forward slash is allowed to be unquoted, but we quote it anyway. We have
696 // many tests that use FileCheck against YAML output, and this output often
697 // contains paths. If we quote backslashes but not forward slashes then
698 // paths will come out either quoted or unquoted depending on which platform
699 // the test is run on, making FileCheck comparisons difficult.
700 case '/':
701 default: {
702 // C0 control block (0x0 - 0x1F) is excluded from the allowed character
703 // range.
704 if (C <= 0x1F)
705 return QuotingType::Double;
706
707 // Always double quote UTF-8.
708 if ((C & 0x80) != 0)
709 return QuotingType::Double;
710
711 // The character is not safe, at least simple quoting needed.
712 MaxQuotingNeeded = QuotingType::Single;
713 }
714 }
715 }
716
717 return MaxQuotingNeeded;
718}
719
720template <typename T, typename Context>
721struct missingTraits
722 : public std::integral_constant<bool,
723 !has_ScalarEnumerationTraits<T>::value &&
724 !has_ScalarBitSetTraits<T>::value &&
725 !has_ScalarTraits<T>::value &&
726 !has_BlockScalarTraits<T>::value &&
727 !has_TaggedScalarTraits<T>::value &&
728 !has_MappingTraits<T, Context>::value &&
729 !has_SequenceTraits<T>::value &&
730 !has_CustomMappingTraits<T>::value &&
731 !has_DocumentListTraits<T>::value &&
732 !has_PolymorphicTraits<T>::value> {};
733
734template <typename T, typename Context>
735struct validatedMappingTraits
736 : public std::integral_constant<
737 bool, has_MappingTraits<T, Context>::value &&
738 has_MappingValidateTraits<T, Context>::value> {};
739
740template <typename T, typename Context>
741struct unvalidatedMappingTraits
742 : public std::integral_constant<
743 bool, has_MappingTraits<T, Context>::value &&
744 !has_MappingValidateTraits<T, Context>::value> {};
745
746// Base class for Input and Output.
747class IO {
748public:
749 IO(void *Ctxt = nullptr);
750 virtual ~IO();
751
752 virtual bool outputting() const = 0;
753
754 virtual unsigned beginSequence() = 0;
755 virtual bool preflightElement(unsigned, void *&) = 0;
756 virtual void postflightElement(void*) = 0;
757 virtual void endSequence() = 0;
758 virtual bool canElideEmptySequence() = 0;
759
760 virtual unsigned beginFlowSequence() = 0;
761 virtual bool preflightFlowElement(unsigned, void *&) = 0;
762 virtual void postflightFlowElement(void*) = 0;
763 virtual void endFlowSequence() = 0;
764
765 virtual bool mapTag(StringRef Tag, bool Default=false) = 0;
766 virtual void beginMapping() = 0;
767 virtual void endMapping() = 0;
768 virtual bool preflightKey(const char*, bool, bool, bool &, void *&) = 0;
769 virtual void postflightKey(void*) = 0;
770 virtual std::vector<StringRef> keys() = 0;
771
772 virtual void beginFlowMapping() = 0;
773 virtual void endFlowMapping() = 0;
774
775 virtual void beginEnumScalar() = 0;
776 virtual bool matchEnumScalar(const char*, bool) = 0;
777 virtual bool matchEnumFallback() = 0;
778 virtual void endEnumScalar() = 0;
779
780 virtual bool beginBitSetScalar(bool &) = 0;
781 virtual bool bitSetMatch(const char*, bool) = 0;
782 virtual void endBitSetScalar() = 0;
783
784 virtual void scalarString(StringRef &, QuotingType) = 0;
785 virtual void blockScalarString(StringRef &) = 0;
786 virtual void scalarTag(std::string &) = 0;
787
788 virtual NodeKind getNodeKind() = 0;
789
790 virtual void setError(const Twine &) = 0;
791
792 template <typename T>
793 void enumCase(T &Val, const char* Str, const T ConstVal) {
794 if ( matchEnumScalar(Str, outputting() && Val == ConstVal) ) {
17
Assuming the condition is true
18
The left operand of '==' is a garbage value
795 Val = ConstVal;
796 }
797 }
798
799 // allow anonymous enum values to be used with LLVM_YAML_STRONG_TYPEDEF
800 template <typename T>
801 void enumCase(T &Val, const char* Str, const uint32_t ConstVal) {
802 if ( matchEnumScalar(Str, outputting() && Val == static_cast<T>(ConstVal)) ) {
803 Val = ConstVal;
804 }
805 }
806
807 template <typename FBT, typename T>
808 void enumFallback(T &Val) {
809 if (matchEnumFallback()) {
810 EmptyContext Context;
811 // FIXME: Force integral conversion to allow strong typedefs to convert.
812 FBT Res = static_cast<typename FBT::BaseType>(Val);
813 yamlize(*this, Res, true, Context);
814 Val = static_cast<T>(static_cast<typename FBT::BaseType>(Res));
815 }
816 }
817
818 template <typename T>
819 void bitSetCase(T &Val, const char* Str, const T ConstVal) {
820 if ( bitSetMatch(Str, outputting() && (Val & ConstVal) == ConstVal) ) {
821 Val = static_cast<T>(Val | ConstVal);
822 }
823 }
824
825 // allow anonymous enum values to be used with LLVM_YAML_STRONG_TYPEDEF
826 template <typename T>
827 void bitSetCase(T &Val, const char* Str, const uint32_t ConstVal) {
828 if ( bitSetMatch(Str, outputting() && (Val & ConstVal) == ConstVal) ) {
829 Val = static_cast<T>(Val | ConstVal);
830 }
831 }
832
833 template <typename T>
834 void maskedBitSetCase(T &Val, const char *Str, T ConstVal, T Mask) {
835 if (bitSetMatch(Str, outputting() && (Val & Mask) == ConstVal))
836 Val = Val | ConstVal;
837 }
838
839 template <typename T>
840 void maskedBitSetCase(T &Val, const char *Str, uint32_t ConstVal,
841 uint32_t Mask) {
842 if (bitSetMatch(Str, outputting() && (Val & Mask) == ConstVal))
843 Val = Val | ConstVal;
844 }
845
846 void *getContext() const;
847 void setContext(void *);
848
849 template <typename T> void mapRequired(const char *Key, T &Val) {
850 EmptyContext Ctx;
851 this->processKey(Key, Val, true, Ctx);
6
Passing value via 2nd parameter 'Val'
7
Calling 'IO::processKey'
852 }
853
854 template <typename T, typename Context>
855 void mapRequired(const char *Key, T &Val, Context &Ctx) {
856 this->processKey(Key, Val, true, Ctx);
857 }
858
859 template <typename T> void mapOptional(const char *Key, T &Val) {
860 EmptyContext Ctx;
861 mapOptionalWithContext(Key, Val, Ctx);
862 }
863
864 template <typename T, typename DefaultT>
865 void mapOptional(const char *Key, T &Val, const DefaultT &Default) {
866 EmptyContext Ctx;
867 mapOptionalWithContext(Key, Val, Default, Ctx);
868 }
869
870 template <typename T, typename Context>
871 std::enable_if_t<has_SequenceTraits<T>::value, void>
872 mapOptionalWithContext(const char *Key, T &Val, Context &Ctx) {
873 // omit key/value instead of outputting empty sequence
874 if (this->canElideEmptySequence() && !(Val.begin() != Val.end()))
875 return;
876 this->processKey(Key, Val, false, Ctx);
877 }
878
879 template <typename T, typename Context>
880 void mapOptionalWithContext(const char *Key, Optional<T> &Val, Context &Ctx) {
881 this->processKeyWithDefault(Key, Val, Optional<T>(), /*Required=*/false,
882 Ctx);
883 }
884
885 template <typename T, typename Context>
886 std::enable_if_t<!has_SequenceTraits<T>::value, void>
887 mapOptionalWithContext(const char *Key, T &Val, Context &Ctx) {
888 this->processKey(Key, Val, false, Ctx);
889 }
890
891 template <typename T, typename Context, typename DefaultT>
892 void mapOptionalWithContext(const char *Key, T &Val, const DefaultT &Default,
893 Context &Ctx) {
894 static_assert(std::is_convertible<DefaultT, T>::value,
895 "Default type must be implicitly convertible to value type!");
896 this->processKeyWithDefault(Key, Val, static_cast<const T &>(Default),
897 false, Ctx);
898 }
899
900private:
901 template <typename T, typename Context>
902 void processKeyWithDefault(const char *Key, Optional<T> &Val,
903 const Optional<T> &DefaultValue, bool Required,
904 Context &Ctx) {
905 assert(DefaultValue.hasValue() == false &&((DefaultValue.hasValue() == false && "Optional<T> shouldn't have a value!"
) ? static_cast<void> (0) : __assert_fail ("DefaultValue.hasValue() == false && \"Optional<T> shouldn't have a value!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/include/llvm/Support/YAMLTraits.h"
, 906, __PRETTY_FUNCTION__))
906 "Optional<T> shouldn't have a value!")((DefaultValue.hasValue() == false && "Optional<T> shouldn't have a value!"
) ? static_cast<void> (0) : __assert_fail ("DefaultValue.hasValue() == false && \"Optional<T> shouldn't have a value!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/include/llvm/Support/YAMLTraits.h"
, 906, __PRETTY_FUNCTION__))
;
907 void *SaveInfo;
908 bool UseDefault = true;
909 const bool sameAsDefault = outputting() && !Val.hasValue();
910 if (!outputting() && !Val.hasValue())
911 Val = T();
912 if (Val.hasValue() &&
913 this->preflightKey(Key, Required, sameAsDefault, UseDefault,
914 SaveInfo)) {
915 yamlize(*this, Val.getValue(), Required, Ctx);
916 this->postflightKey(SaveInfo);
917 } else {
918 if (UseDefault)
919 Val = DefaultValue;
920 }
921 }
922
923 template <typename T, typename Context>
924 void processKeyWithDefault(const char *Key, T &Val, const T &DefaultValue,
925 bool Required, Context &Ctx) {
926 void *SaveInfo;
927 bool UseDefault;
928 const bool sameAsDefault = outputting() && Val == DefaultValue;
929 if ( this->preflightKey(Key, Required, sameAsDefault, UseDefault,
930 SaveInfo) ) {
931 yamlize(*this, Val, Required, Ctx);
932 this->postflightKey(SaveInfo);
933 }
934 else {
935 if ( UseDefault )
936 Val = DefaultValue;
937 }
938 }
939
940 template <typename T, typename Context>
941 void processKey(const char *Key, T &Val, bool Required, Context &Ctx) {
942 void *SaveInfo;
943 bool UseDefault;
944 if ( this->preflightKey(Key, Required, false, UseDefault, SaveInfo) ) {
8
Assuming the condition is true
9
Taking true branch
945 yamlize(*this, Val, Required, Ctx);
10
Passing value via 2nd parameter 'Val'
11
Calling 'yamlize<llvm::codeview::SymbolKind>'
946 this->postflightKey(SaveInfo);
947 }
948 }
949
950private:
951 void *Ctxt;
952};
953
954namespace detail {
955
956template <typename T, typename Context>
957void doMapping(IO &io, T &Val, Context &Ctx) {
958 MappingContextTraits<T, Context>::mapping(io, Val, Ctx);
959}
960
961template <typename T> void doMapping(IO &io, T &Val, EmptyContext &Ctx) {
962 MappingTraits<T>::mapping(io, Val);
963}
964
965} // end namespace detail
966
967template <typename T>
968std::enable_if_t<has_ScalarEnumerationTraits<T>::value, void>
969yamlize(IO &io, T &Val, bool, EmptyContext &Ctx) {
970 io.beginEnumScalar();
971 ScalarEnumerationTraits<T>::enumeration(io, Val);
12
Passing value via 2nd parameter 'Value'
13
Calling 'ScalarEnumerationTraits::enumeration'
972 io.endEnumScalar();
973}
974
975template <typename T>
976std::enable_if_t<has_ScalarBitSetTraits<T>::value, void>
977yamlize(IO &io, T &Val, bool, EmptyContext &Ctx) {
978 bool DoClear;
979 if ( io.beginBitSetScalar(DoClear) ) {
980 if ( DoClear )
981 Val = T();
982 ScalarBitSetTraits<T>::bitset(io, Val);
983 io.endBitSetScalar();
984 }
985}
986
987template <typename T>
988std::enable_if_t<has_ScalarTraits<T>::value, void> yamlize(IO &io, T &Val, bool,
989 EmptyContext &Ctx) {
990 if ( io.outputting() ) {
991 std::string Storage;
992 raw_string_ostream Buffer(Storage);
993 ScalarTraits<T>::output(Val, io.getContext(), Buffer);
994 StringRef Str = Buffer.str();
995 io.scalarString(Str, ScalarTraits<T>::mustQuote(Str));
996 }
997 else {
998 StringRef Str;
999 io.scalarString(Str, ScalarTraits<T>::mustQuote(Str));
1000 StringRef Result = ScalarTraits<T>::input(Str, io.getContext(), Val);
1001 if ( !Result.empty() ) {
1002 io.setError(Twine(Result));
1003 }
1004 }
1005}
1006
1007template <typename T>
1008std::enable_if_t<has_BlockScalarTraits<T>::value, void>
1009yamlize(IO &YamlIO, T &Val, bool, EmptyContext &Ctx) {
1010 if (YamlIO.outputting()) {
1011 std::string Storage;
1012 raw_string_ostream Buffer(Storage);
1013 BlockScalarTraits<T>::output(Val, YamlIO.getContext(), Buffer);
1014 StringRef Str = Buffer.str();
1015 YamlIO.blockScalarString(Str);
1016 } else {
1017 StringRef Str;
1018 YamlIO.blockScalarString(Str);
1019 StringRef Result =
1020 BlockScalarTraits<T>::input(Str, YamlIO.getContext(), Val);
1021 if (!Result.empty())
1022 YamlIO.setError(Twine(Result));
1023 }
1024}
1025
1026template <typename T>
1027std::enable_if_t<has_TaggedScalarTraits<T>::value, void>
1028yamlize(IO &io, T &Val, bool, EmptyContext &Ctx) {
1029 if (io.outputting()) {
1030 std::string ScalarStorage, TagStorage;
1031 raw_string_ostream ScalarBuffer(ScalarStorage), TagBuffer(TagStorage);
1032 TaggedScalarTraits<T>::output(Val, io.getContext(), ScalarBuffer,
1033 TagBuffer);
1034 io.scalarTag(TagBuffer.str());
1035 StringRef ScalarStr = ScalarBuffer.str();
1036 io.scalarString(ScalarStr,
1037 TaggedScalarTraits<T>::mustQuote(Val, ScalarStr));
1038 } else {
1039 std::string Tag;
1040 io.scalarTag(Tag);
1041 StringRef Str;
1042 io.scalarString(Str, QuotingType::None);
1043 StringRef Result =
1044 TaggedScalarTraits<T>::input(Str, Tag, io.getContext(), Val);
1045 if (!Result.empty()) {
1046 io.setError(Twine(Result));
1047 }
1048 }
1049}
1050
1051template <typename T, typename Context>
1052std::enable_if_t<validatedMappingTraits<T, Context>::value, void>
1053yamlize(IO &io, T &Val, bool, Context &Ctx) {
1054 if (has_FlowTraits<MappingTraits<T>>::value)
1055 io.beginFlowMapping();
1056 else
1057 io.beginMapping();
1058 if (io.outputting()) {
1059 StringRef Err = MappingTraits<T>::validate(io, Val);
1060 if (!Err.empty()) {
1061 errs() << Err << "\n";
1062 assert(Err.empty() && "invalid struct trying to be written as yaml")((Err.empty() && "invalid struct trying to be written as yaml"
) ? static_cast<void> (0) : __assert_fail ("Err.empty() && \"invalid struct trying to be written as yaml\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/include/llvm/Support/YAMLTraits.h"
, 1062, __PRETTY_FUNCTION__))
;
1063 }
1064 }
1065 detail::doMapping(io, Val, Ctx);
1066 if (!io.outputting()) {
1067 StringRef Err = MappingTraits<T>::validate(io, Val);
1068 if (!Err.empty())
1069 io.setError(Err);
1070 }
1071 if (has_FlowTraits<MappingTraits<T>>::value)
1072 io.endFlowMapping();
1073 else
1074 io.endMapping();
1075}
1076
1077template <typename T, typename Context>
1078std::enable_if_t<unvalidatedMappingTraits<T, Context>::value, void>
1079yamlize(IO &io, T &Val, bool, Context &Ctx) {
1080 if (has_FlowTraits<MappingTraits<T>>::value) {
1081 io.beginFlowMapping();
1082 detail::doMapping(io, Val, Ctx);
1083 io.endFlowMapping();
1084 } else {
1085 io.beginMapping();
1086 detail::doMapping(io, Val, Ctx);
1087 io.endMapping();
1088 }
1089}
1090
1091template <typename T>
1092std::enable_if_t<has_CustomMappingTraits<T>::value, void>
1093yamlize(IO &io, T &Val, bool, EmptyContext &Ctx) {
1094 if ( io.outputting() ) {
1095 io.beginMapping();
1096 CustomMappingTraits<T>::output(io, Val);
1097 io.endMapping();
1098 } else {
1099 io.beginMapping();
1100 for (StringRef key : io.keys())
1101 CustomMappingTraits<T>::inputOne(io, key, Val);
1102 io.endMapping();
1103 }
1104}
1105
1106template <typename T>
1107std::enable_if_t<has_PolymorphicTraits<T>::value, void>
1108yamlize(IO &io, T &Val, bool, EmptyContext &Ctx) {
1109 switch (io.outputting() ? PolymorphicTraits<T>::getKind(Val)
1110 : io.getNodeKind()) {
1111 case NodeKind::Scalar:
1112 return yamlize(io, PolymorphicTraits<T>::getAsScalar(Val), true, Ctx);
1113 case NodeKind::Map:
1114 return yamlize(io, PolymorphicTraits<T>::getAsMap(Val), true, Ctx);
1115 case NodeKind::Sequence:
1116 return yamlize(io, PolymorphicTraits<T>::getAsSequence(Val), true, Ctx);
1117 }
1118}
1119
1120template <typename T>
1121std::enable_if_t<missingTraits<T, EmptyContext>::value, void>
1122yamlize(IO &io, T &Val, bool, EmptyContext &Ctx) {
1123 char missing_yaml_trait_for_type[sizeof(MissingTrait<T>)];
1124}
1125
1126template <typename T, typename Context>
1127std::enable_if_t<has_SequenceTraits<T>::value, void>
1128yamlize(IO &io, T &Seq, bool, Context &Ctx) {
1129 if ( has_FlowTraits< SequenceTraits<T>>::value ) {
1130 unsigned incnt = io.beginFlowSequence();
1131 unsigned count = io.outputting() ? SequenceTraits<T>::size(io, Seq) : incnt;
1132 for(unsigned i=0; i < count; ++i) {
1133 void *SaveInfo;
1134 if ( io.preflightFlowElement(i, SaveInfo) ) {
1135 yamlize(io, SequenceTraits<T>::element(io, Seq, i), true, Ctx);
1136 io.postflightFlowElement(SaveInfo);
1137 }
1138 }
1139 io.endFlowSequence();
1140 }
1141 else {
1142 unsigned incnt = io.beginSequence();
1143 unsigned count = io.outputting() ? SequenceTraits<T>::size(io, Seq) : incnt;
1144 for(unsigned i=0; i < count; ++i) {
1145 void *SaveInfo;
1146 if ( io.preflightElement(i, SaveInfo) ) {
1147 yamlize(io, SequenceTraits<T>::element(io, Seq, i), true, Ctx);
1148 io.postflightElement(SaveInfo);
1149 }
1150 }
1151 io.endSequence();
1152 }
1153}
1154
1155template<>
1156struct ScalarTraits<bool> {
1157 static void output(const bool &, void* , raw_ostream &);
1158 static StringRef input(StringRef, void *, bool &);
1159 static QuotingType mustQuote(StringRef) { return QuotingType::None; }
1160};
1161
1162template<>
1163struct ScalarTraits<StringRef> {
1164 static void output(const StringRef &, void *, raw_ostream &);
1165 static StringRef input(StringRef, void *, StringRef &);
1166 static QuotingType mustQuote(StringRef S) { return needsQuotes(S); }
1167};
1168
1169template<>
1170struct ScalarTraits<std::string> {
1171 static void output(const std::string &, void *, raw_ostream &);
1172 static StringRef input(StringRef, void *, std::string &);
1173 static QuotingType mustQuote(StringRef S) { return needsQuotes(S); }
1174};
1175
1176template<>
1177struct ScalarTraits<uint8_t> {
1178 static void output(const uint8_t &, void *, raw_ostream &);
1179 static StringRef input(StringRef, void *, uint8_t &);
1180 static QuotingType mustQuote(StringRef) { return QuotingType::None; }
1181};
1182
1183template<>
1184struct ScalarTraits<uint16_t> {
1185 static void output(const uint16_t &, void *, raw_ostream &);
1186 static StringRef input(StringRef, void *, uint16_t &);
1187 static QuotingType mustQuote(StringRef) { return QuotingType::None; }
1188};
1189
1190template<>
1191struct ScalarTraits<uint32_t> {
1192 static void output(const uint32_t &, void *, raw_ostream &);
1193 static StringRef input(StringRef, void *, uint32_t &);
1194 static QuotingType mustQuote(StringRef) { return QuotingType::None; }
1195};
1196
1197template<>
1198struct ScalarTraits<uint64_t> {
1199 static void output(const uint64_t &, void *, raw_ostream &);
1200 static StringRef input(StringRef, void *, uint64_t &);
1201 static QuotingType mustQuote(StringRef) { return QuotingType::None; }
1202};
1203
1204template<>
1205struct ScalarTraits<int8_t> {
1206 static void output(const int8_t &, void *, raw_ostream &);
1207 static StringRef input(StringRef, void *, int8_t &);
1208 static QuotingType mustQuote(StringRef) { return QuotingType::None; }
1209};
1210
1211template<>
1212struct ScalarTraits<int16_t> {
1213 static void output(const int16_t &, void *, raw_ostream &);
1214 static StringRef input(StringRef, void *, int16_t &);
1215 static QuotingType mustQuote(StringRef) { return QuotingType::None; }
1216};
1217
1218template<>
1219struct ScalarTraits<int32_t> {
1220 static void output(const int32_t &, void *, raw_ostream &);
1221 static StringRef input(StringRef, void *, int32_t &);
1222 static QuotingType mustQuote(StringRef) { return QuotingType::None; }
1223};
1224
1225template<>
1226struct ScalarTraits<int64_t> {
1227 static void output(const int64_t &, void *, raw_ostream &);
1228 static StringRef input(StringRef, void *, int64_t &);
1229 static QuotingType mustQuote(StringRef) { return QuotingType::None; }
1230};
1231
1232template<>
1233struct ScalarTraits<float> {
1234 static void output(const float &, void *, raw_ostream &);
1235 static StringRef input(StringRef, void *, float &);
1236 static QuotingType mustQuote(StringRef) { return QuotingType::None; }
1237};
1238
1239template<>
1240struct ScalarTraits<double> {
1241 static void output(const double &, void *, raw_ostream &);
1242 static StringRef input(StringRef, void *, double &);
1243 static QuotingType mustQuote(StringRef) { return QuotingType::None; }
1244};
1245
1246// For endian types, we use existing scalar Traits class for the underlying
1247// type. This way endian aware types are supported whenever the traits are
1248// defined for the underlying type.
1249template <typename value_type, support::endianness endian, size_t alignment>
1250struct ScalarTraits<support::detail::packed_endian_specific_integral<
1251 value_type, endian, alignment>,
1252 std::enable_if_t<has_ScalarTraits<value_type>::value>> {
1253 using endian_type =
1254 support::detail::packed_endian_specific_integral<value_type, endian,
1255 alignment>;
1256
1257 static void output(const endian_type &E, void *Ctx, raw_ostream &Stream) {
1258 ScalarTraits<value_type>::output(static_cast<value_type>(E), Ctx, Stream);
1259 }
1260
1261 static StringRef input(StringRef Str, void *Ctx, endian_type &E) {
1262 value_type V;
1263 auto R = ScalarTraits<value_type>::input(Str, Ctx, V);
1264 E = static_cast<endian_type>(V);
1265 return R;
1266 }
1267
1268 static QuotingType mustQuote(StringRef Str) {
1269 return ScalarTraits<value_type>::mustQuote(Str);
1270 }
1271};
1272
1273template <typename value_type, support::endianness endian, size_t alignment>
1274struct ScalarEnumerationTraits<
1275 support::detail::packed_endian_specific_integral<value_type, endian,
1276 alignment>,
1277 std::enable_if_t<has_ScalarEnumerationTraits<value_type>::value>> {
1278 using endian_type =
1279 support::detail::packed_endian_specific_integral<value_type, endian,
1280 alignment>;
1281
1282 static void enumeration(IO &io, endian_type &E) {
1283 value_type V = E;
1284 ScalarEnumerationTraits<value_type>::enumeration(io, V);
1285 E = V;
1286 }
1287};
1288
1289template <typename value_type, support::endianness endian, size_t alignment>
1290struct ScalarBitSetTraits<
1291 support::detail::packed_endian_specific_integral<value_type, endian,
1292 alignment>,
1293 std::enable_if_t<has_ScalarBitSetTraits<value_type>::value>> {
1294 using endian_type =
1295 support::detail::packed_endian_specific_integral<value_type, endian,
1296 alignment>;
1297 static void bitset(IO &io, endian_type &E) {
1298 value_type V = E;
1299 ScalarBitSetTraits<value_type>::bitset(io, V);
1300 E = V;
1301 }
1302};
1303
1304// Utility for use within MappingTraits<>::mapping() method
1305// to [de]normalize an object for use with YAML conversion.
1306template <typename TNorm, typename TFinal>
1307struct MappingNormalization {
1308 MappingNormalization(IO &i_o, TFinal &Obj)
1309 : io(i_o), BufPtr(nullptr), Result(Obj) {
1310 if ( io.outputting() ) {
1311 BufPtr = new (&Buffer) TNorm(io, Obj);
1312 }
1313 else {
1314 BufPtr = new (&Buffer) TNorm(io);
1315 }
1316 }
1317
1318 ~MappingNormalization() {
1319 if ( ! io.outputting() ) {
1320 Result = BufPtr->denormalize(io);
1321 }
1322 BufPtr->~TNorm();
1323 }
1324
1325 TNorm* operator->() { return BufPtr; }
1326
1327private:
1328 using Storage = AlignedCharArrayUnion<TNorm>;
1329
1330 Storage Buffer;
1331 IO &io;
1332 TNorm *BufPtr;
1333 TFinal &Result;
1334};
1335
1336// Utility for use within MappingTraits<>::mapping() method
1337// to [de]normalize an object for use with YAML conversion.
1338template <typename TNorm, typename TFinal>
1339struct MappingNormalizationHeap {
1340 MappingNormalizationHeap(IO &i_o, TFinal &Obj, BumpPtrAllocator *allocator)
1341 : io(i_o), Result(Obj) {
1342 if ( io.outputting() ) {
1343 BufPtr = new (&Buffer) TNorm(io, Obj);
1344 }
1345 else if (allocator) {
1346 BufPtr = allocator->Allocate<TNorm>();
1347 new (BufPtr) TNorm(io);
1348 } else {
1349 BufPtr = new TNorm(io);
1350 }
1351 }
1352
1353 ~MappingNormalizationHeap() {
1354 if ( io.outputting() ) {
1355 BufPtr->~TNorm();
1356 }
1357 else {
1358 Result = BufPtr->denormalize(io);
1359 }
1360 }
1361
1362 TNorm* operator->() { return BufPtr; }
1363
1364private:
1365 using Storage = AlignedCharArrayUnion<TNorm>;
1366
1367 Storage Buffer;
1368 IO &io;
1369 TNorm *BufPtr = nullptr;
1370 TFinal &Result;
1371};
1372
1373///
1374/// The Input class is used to parse a yaml document into in-memory structs
1375/// and vectors.
1376///
1377/// It works by using YAMLParser to do a syntax parse of the entire yaml
1378/// document, then the Input class builds a graph of HNodes which wraps
1379/// each yaml Node. The extra layer is buffering. The low level yaml
1380/// parser only lets you look at each node once. The buffering layer lets
1381/// you search and interate multiple times. This is necessary because
1382/// the mapRequired() method calls may not be in the same order
1383/// as the keys in the document.
1384///
1385class Input : public IO {
1386public:
1387 // Construct a yaml Input object from a StringRef and optional
1388 // user-data. The DiagHandler can be specified to provide
1389 // alternative error reporting.
1390 Input(StringRef InputContent,
1391 void *Ctxt = nullptr,
1392 SourceMgr::DiagHandlerTy DiagHandler = nullptr,
1393 void *DiagHandlerCtxt = nullptr);
1394 Input(MemoryBufferRef Input,
1395 void *Ctxt = nullptr,
1396 SourceMgr::DiagHandlerTy DiagHandler = nullptr,
1397 void *DiagHandlerCtxt = nullptr);
1398 ~Input() override;
1399
1400 // Check if there was an syntax or semantic error during parsing.
1401 std::error_code error();
1402
1403private:
1404 bool outputting() const override;
1405 bool mapTag(StringRef, bool) override;
1406 void beginMapping() override;
1407 void endMapping() override;
1408 bool preflightKey(const char *, bool, bool, bool &, void *&) override;
1409 void postflightKey(void *) override;
1410 std::vector<StringRef> keys() override;
1411 void beginFlowMapping() override;
1412 void endFlowMapping() override;
1413 unsigned beginSequence() override;
1414 void endSequence() override;
1415 bool preflightElement(unsigned index, void *&) override;
1416 void postflightElement(void *) override;
1417 unsigned beginFlowSequence() override;
1418 bool preflightFlowElement(unsigned , void *&) override;
1419 void postflightFlowElement(void *) override;
1420 void endFlowSequence() override;
1421 void beginEnumScalar() override;
1422 bool matchEnumScalar(const char*, bool) override;
1423 bool matchEnumFallback() override;
1424 void endEnumScalar() override;
1425 bool beginBitSetScalar(bool &) override;
1426 bool bitSetMatch(const char *, bool ) override;
1427 void endBitSetScalar() override;
1428 void scalarString(StringRef &, QuotingType) override;
1429 void blockScalarString(StringRef &) override;
1430 void scalarTag(std::string &) override;
1431 NodeKind getNodeKind() override;
1432 void setError(const Twine &message) override;
1433 bool canElideEmptySequence() override;
1434
1435 class HNode {
1436 virtual void anchor();
1437
1438 public:
1439 HNode(Node *n) : _node(n) { }
1440 virtual ~HNode() = default;
1441
1442 static bool classof(const HNode *) { return true; }
1443
1444 Node *_node;
1445 };
1446
1447 class EmptyHNode : public HNode {
1448 void anchor() override;
1449
1450 public:
1451 EmptyHNode(Node *n) : HNode(n) { }
1452
1453 static bool classof(const HNode *n) { return NullNode::classof(n->_node); }
1454
1455 static bool classof(const EmptyHNode *) { return true; }
1456 };
1457
1458 class ScalarHNode : public HNode {
1459 void anchor() override;
1460
1461 public:
1462 ScalarHNode(Node *n, StringRef s) : HNode(n), _value(s) { }
1463
1464 StringRef value() const { return _value; }
1465
1466 static bool classof(const HNode *n) {
1467 return ScalarNode::classof(n->_node) ||
1468 BlockScalarNode::classof(n->_node);
1469 }
1470
1471 static bool classof(const ScalarHNode *) { return true; }
1472
1473 protected:
1474 StringRef _value;
1475 };
1476
1477 class MapHNode : public HNode {
1478 void anchor() override;
1479
1480 public:
1481 MapHNode(Node *n) : HNode(n) { }
1482
1483 static bool classof(const HNode *n) {
1484 return MappingNode::classof(n->_node);
1485 }
1486
1487 static bool classof(const MapHNode *) { return true; }
1488
1489 using NameToNode = StringMap<std::unique_ptr<HNode>>;
1490
1491 NameToNode Mapping;
1492 SmallVector<std::string, 6> ValidKeys;
1493 };
1494
1495 class SequenceHNode : public HNode {
1496 void anchor() override;
1497
1498 public:
1499 SequenceHNode(Node *n) : HNode(n) { }
1500
1501 static bool classof(const HNode *n) {
1502 return SequenceNode::classof(n->_node);
1503 }
1504
1505 static bool classof(const SequenceHNode *) { return true; }
1506
1507 std::vector<std::unique_ptr<HNode>> Entries;
1508 };
1509
1510 std::unique_ptr<Input::HNode> createHNodes(Node *node);
1511 void setError(HNode *hnode, const Twine &message);
1512 void setError(Node *node, const Twine &message);
1513
1514public:
1515 // These are only used by operator>>. They could be private
1516 // if those templated things could be made friends.
1517 bool setCurrentDocument();
1518 bool nextDocument();
1519
1520 /// Returns the current node that's being parsed by the YAML Parser.
1521 const Node *getCurrentNode() const;
1522
1523private:
1524 SourceMgr SrcMgr; // must be before Strm
1525 std::unique_ptr<llvm::yaml::Stream> Strm;
1526 std::unique_ptr<HNode> TopNode;
1527 std::error_code EC;
1528 BumpPtrAllocator StringAllocator;
1529 document_iterator DocIterator;
1530 std::vector<bool> BitValuesUsed;
1531 HNode *CurrentNode = nullptr;
1532 bool ScalarMatchFound = false;
1533};
1534
1535///
1536/// The Output class is used to generate a yaml document from in-memory structs
1537/// and vectors.
1538///
1539class Output : public IO {
1540public:
1541 Output(raw_ostream &, void *Ctxt = nullptr, int WrapColumn = 70);
1542 ~Output() override;
1543
1544 /// Set whether or not to output optional values which are equal
1545 /// to the default value. By default, when outputting if you attempt
1546 /// to write a value that is equal to the default, the value gets ignored.
1547 /// Sometimes, it is useful to be able to see these in the resulting YAML
1548 /// anyway.
1549 void setWriteDefaultValues(bool Write) { WriteDefaultValues = Write; }
1550
1551 bool outputting() const override;
1552 bool mapTag(StringRef, bool) override;
1553 void beginMapping() override;
1554 void endMapping() override;
1555 bool preflightKey(const char *key, bool, bool, bool &, void *&) override;
1556 void postflightKey(void *) override;
1557 std::vector<StringRef> keys() override;
1558 void beginFlowMapping() override;
1559 void endFlowMapping() override;
1560 unsigned beginSequence() override;
1561 void endSequence() override;
1562 bool preflightElement(unsigned, void *&) override;
1563 void postflightElement(void *) override;
1564 unsigned beginFlowSequence() override;
1565 bool preflightFlowElement(unsigned, void *&) override;
1566 void postflightFlowElement(void *) override;
1567 void endFlowSequence() override;
1568 void beginEnumScalar() override;
1569 bool matchEnumScalar(const char*, bool) override;
1570 bool matchEnumFallback() override;
1571 void endEnumScalar() override;
1572 bool beginBitSetScalar(bool &) override;
1573 bool bitSetMatch(const char *, bool ) override;
1574 void endBitSetScalar() override;
1575 void scalarString(StringRef &, QuotingType) override;
1576 void blockScalarString(StringRef &) override;
1577 void scalarTag(std::string &) override;
1578 NodeKind getNodeKind() override;
1579 void setError(const Twine &message) override;
1580 bool canElideEmptySequence() override;
1581
1582 // These are only used by operator<<. They could be private
1583 // if that templated operator could be made a friend.
1584 void beginDocuments();
1585 bool preflightDocument(unsigned);
1586 void postflightDocument();
1587 void endDocuments();
1588
1589private:
1590 void output(StringRef s);
1591 void outputUpToEndOfLine(StringRef s);
1592 void newLineCheck();
1593 void outputNewLine();
1594 void paddedKey(StringRef key);
1595 void flowKey(StringRef Key);
1596
1597 enum InState {
1598 inSeqFirstElement,
1599 inSeqOtherElement,
1600 inFlowSeqFirstElement,
1601 inFlowSeqOtherElement,
1602 inMapFirstKey,
1603 inMapOtherKey,
1604 inFlowMapFirstKey,
1605 inFlowMapOtherKey
1606 };
1607
1608 static bool inSeqAnyElement(InState State);
1609 static bool inFlowSeqAnyElement(InState State);
1610 static bool inMapAnyKey(InState State);
1611 static bool inFlowMapAnyKey(InState State);
1612
1613 raw_ostream &Out;
1614 int WrapColumn;
1615 SmallVector<InState, 8> StateStack;
1616 int Column = 0;
1617 int ColumnAtFlowStart = 0;
1618 int ColumnAtMapFlowStart = 0;
1619 bool NeedBitValueComma = false;
1620 bool NeedFlowSequenceComma = false;
1621 bool EnumerationMatchFound = false;
1622 bool WriteDefaultValues = false;
1623 StringRef Padding;
1624 StringRef PaddingBeforeContainer;
1625};
1626
1627/// YAML I/O does conversion based on types. But often native data types
1628/// are just a typedef of built in intergral types (e.g. int). But the C++
1629/// type matching system sees through the typedef and all the typedefed types
1630/// look like a built in type. This will cause the generic YAML I/O conversion
1631/// to be used. To provide better control over the YAML conversion, you can
1632/// use this macro instead of typedef. It will create a class with one field
1633/// and automatic conversion operators to and from the base type.
1634/// Based on BOOST_STRONG_TYPEDEF
1635#define LLVM_YAML_STRONG_TYPEDEF(_base, _type)struct _type { _type() = default; _type(const _base v) : value
(v) {} _type(const _type &v) = default; _type &operator
=(const _type &rhs) = default; _type &operator=(const
_base &rhs) { value = rhs; return *this; } operator const
_base & () const { return value; } bool operator==(const
_type &rhs) const { return value == rhs.value; } bool operator
==(const _base &rhs) const { return value == rhs; } bool operator
<(const _type &rhs) const { return value < rhs.value
; } _base value; using BaseType = _base; };
\
1636 struct _type { \
1637 _type() = default; \
1638 _type(const _base v) : value(v) {} \
1639 _type(const _type &v) = default; \
1640 _type &operator=(const _type &rhs) = default; \
1641 _type &operator=(const _base &rhs) { value = rhs; return *this; } \
1642 operator const _base & () const { return value; } \
1643 bool operator==(const _type &rhs) const { return value == rhs.value; } \
1644 bool operator==(const _base &rhs) const { return value == rhs; } \
1645 bool operator<(const _type &rhs) const { return value < rhs.value; } \
1646 _base value; \
1647 using BaseType = _base; \
1648 };
1649
1650///
1651/// Use these types instead of uintXX_t in any mapping to have
1652/// its yaml output formatted as hexadecimal.
1653///
1654LLVM_YAML_STRONG_TYPEDEF(uint8_t, Hex8)struct Hex8 { Hex8() = default; Hex8(const uint8_t v) : value
(v) {} Hex8(const Hex8 &v) = default; Hex8 &operator=
(const Hex8 &rhs) = default; Hex8 &operator=(const uint8_t
&rhs) { value = rhs; return *this; } operator const uint8_t
& () const { return value; } bool operator==(const Hex8 &
rhs) const { return value == rhs.value; } bool operator==(const
uint8_t &rhs) const { return value == rhs; } bool operator
<(const Hex8 &rhs) const { return value < rhs.value
; } uint8_t value; using BaseType = uint8_t; };
1655LLVM_YAML_STRONG_TYPEDEF(uint16_t, Hex16)struct Hex16 { Hex16() = default; Hex16(const uint16_t v) : value
(v) {} Hex16(const Hex16 &v) = default; Hex16 &operator
=(const Hex16 &rhs) = default; Hex16 &operator=(const
uint16_t &rhs) { value = rhs; return *this; } operator const
uint16_t & () const { return value; } bool operator==(const
Hex16 &rhs) const { return value == rhs.value; } bool operator
==(const uint16_t &rhs) const { return value == rhs; } bool
operator<(const Hex16 &rhs) const { return value <
rhs.value; } uint16_t value; using BaseType = uint16_t; };
1656LLVM_YAML_STRONG_TYPEDEF(uint32_t, Hex32)struct Hex32 { Hex32() = default; Hex32(const uint32_t v) : value
(v) {} Hex32(const Hex32 &v) = default; Hex32 &operator
=(const Hex32 &rhs) = default; Hex32 &operator=(const
uint32_t &rhs) { value = rhs; return *this; } operator const
uint32_t & () const { return value; } bool operator==(const
Hex32 &rhs) const { return value == rhs.value; } bool operator
==(const uint32_t &rhs) const { return value == rhs; } bool
operator<(const Hex32 &rhs) const { return value <
rhs.value; } uint32_t value; using BaseType = uint32_t; };
1657LLVM_YAML_STRONG_TYPEDEF(uint64_t, Hex64)struct Hex64 { Hex64() = default; Hex64(const uint64_t v) : value
(v) {} Hex64(const Hex64 &v) = default; Hex64 &operator
=(const Hex64 &rhs) = default; Hex64 &operator=(const
uint64_t &rhs) { value = rhs; return *this; } operator const
uint64_t & () const { return value; } bool operator==(const
Hex64 &rhs) const { return value == rhs.value; } bool operator
==(const uint64_t &rhs) const { return value == rhs; } bool
operator<(const Hex64 &rhs) const { return value <
rhs.value; } uint64_t value; using BaseType = uint64_t; };
1658
1659template<>
1660struct ScalarTraits<Hex8> {
1661 static void output(const Hex8 &, void *, raw_ostream &);
1662 static StringRef input(StringRef, void *, Hex8 &);
1663 static QuotingType mustQuote(StringRef) { return QuotingType::None; }
1664};
1665
1666template<>
1667struct ScalarTraits<Hex16> {
1668 static void output(const Hex16 &, void *, raw_ostream &);
1669 static StringRef input(StringRef, void *, Hex16 &);
1670 static QuotingType mustQuote(StringRef) { return QuotingType::None; }
1671};
1672
1673template<>
1674struct ScalarTraits<Hex32> {
1675 static void output(const Hex32 &, void *, raw_ostream &);
1676 static StringRef input(StringRef, void *, Hex32 &);
1677 static QuotingType mustQuote(StringRef) { return QuotingType::None; }
1678};
1679
1680template<>
1681struct ScalarTraits<Hex64> {
1682 static void output(const Hex64 &, void *, raw_ostream &);
1683 static StringRef input(StringRef, void *, Hex64 &);
1684 static QuotingType mustQuote(StringRef) { return QuotingType::None; }
1685};
1686
1687// Define non-member operator>> so that Input can stream in a document list.
1688template <typename T>
1689inline std::enable_if_t<has_DocumentListTraits<T>::value, Input &>
1690operator>>(Input &yin, T &docList) {
1691 int i = 0;
1692 EmptyContext Ctx;
1693 while ( yin.setCurrentDocument() ) {
1694 yamlize(yin, DocumentListTraits<T>::element(yin, docList, i), true, Ctx);
1695 if ( yin.error() )
1696 return yin;
1697 yin.nextDocument();
1698 ++i;
1699 }
1700 return yin;
1701}
1702
1703// Define non-member operator>> so that Input can stream in a map as a document.
1704template <typename T>
1705inline std::enable_if_t<has_MappingTraits<T, EmptyContext>::value, Input &>
1706operator>>(Input &yin, T &docMap) {
1707 EmptyContext Ctx;
1708 yin.setCurrentDocument();
1709 yamlize(yin, docMap, true, Ctx);
1710 return yin;
1711}
1712
1713// Define non-member operator>> so that Input can stream in a sequence as
1714// a document.
1715template <typename T>
1716inline std::enable_if_t<has_SequenceTraits<T>::value, Input &>
1717operator>>(Input &yin, T &docSeq) {
1718 EmptyContext Ctx;
1719 if (yin.setCurrentDocument())
1720 yamlize(yin, docSeq, true, Ctx);
1721 return yin;
1722}
1723
1724// Define non-member operator>> so that Input can stream in a block scalar.
1725template <typename T>
1726inline std::enable_if_t<has_BlockScalarTraits<T>::value, Input &>
1727operator>>(Input &In, T &Val) {
1728 EmptyContext Ctx;
1729 if (In.setCurrentDocument())
1730 yamlize(In, Val, true, Ctx);
1731 return In;
1732}
1733
1734// Define non-member operator>> so that Input can stream in a string map.
1735template <typename T>
1736inline std::enable_if_t<has_CustomMappingTraits<T>::value, Input &>
1737operator>>(Input &In, T &Val) {
1738 EmptyContext Ctx;
1739 if (In.setCurrentDocument())
1740 yamlize(In, Val, true, Ctx);
1741 return In;
1742}
1743
1744// Define non-member operator>> so that Input can stream in a polymorphic type.
1745template <typename T>
1746inline std::enable_if_t<has_PolymorphicTraits<T>::value, Input &>
1747operator>>(Input &In, T &Val) {
1748 EmptyContext Ctx;
1749 if (In.setCurrentDocument())
1750 yamlize(In, Val, true, Ctx);
1751 return In;
1752}
1753
1754// Provide better error message about types missing a trait specialization
1755template <typename T>
1756inline std::enable_if_t<missingTraits<T, EmptyContext>::value, Input &>
1757operator>>(Input &yin, T &docSeq) {
1758 char missing_yaml_trait_for_type[sizeof(MissingTrait<T>)];
1759 return yin;
1760}
1761
1762// Define non-member operator<< so that Output can stream out document list.
1763template <typename T>
1764inline std::enable_if_t<has_DocumentListTraits<T>::value, Output &>
1765operator<<(Output &yout, T &docList) {
1766 EmptyContext Ctx;
1767 yout.beginDocuments();
1768 const size_t count = DocumentListTraits<T>::size(yout, docList);
1769 for(size_t i=0; i < count; ++i) {
1770 if ( yout.preflightDocument(i) ) {
1771 yamlize(yout, DocumentListTraits<T>::element(yout, docList, i), true,
1772 Ctx);
1773 yout.postflightDocument();
1774 }
1775 }
1776 yout.endDocuments();
1777 return yout;
1778}
1779
1780// Define non-member operator<< so that Output can stream out a map.
1781template <typename T>
1782inline std::enable_if_t<has_MappingTraits<T, EmptyContext>::value, Output &>
1783operator<<(Output &yout, T &map) {
1784 EmptyContext Ctx;
1785 yout.beginDocuments();
1786 if ( yout.preflightDocument(0) ) {
1787 yamlize(yout, map, true, Ctx);
1788 yout.postflightDocument();
1789 }
1790 yout.endDocuments();
1791 return yout;
1792}
1793
1794// Define non-member operator<< so that Output can stream out a sequence.
1795template <typename T>
1796inline std::enable_if_t<has_SequenceTraits<T>::value, Output &>
1797operator<<(Output &yout, T &seq) {
1798 EmptyContext Ctx;
1799 yout.beginDocuments();
1800 if ( yout.preflightDocument(0) ) {
1801 yamlize(yout, seq, true, Ctx);
1802 yout.postflightDocument();
1803 }
1804 yout.endDocuments();
1805 return yout;
1806}
1807
1808// Define non-member operator<< so that Output can stream out a block scalar.
1809template <typename T>
1810inline std::enable_if_t<has_BlockScalarTraits<T>::value, Output &>
1811operator<<(Output &Out, T &Val) {
1812 EmptyContext Ctx;
1813 Out.beginDocuments();
1814 if (Out.preflightDocument(0)) {
1815 yamlize(Out, Val, true, Ctx);
1816 Out.postflightDocument();
1817 }
1818 Out.endDocuments();
1819 return Out;
1820}
1821
1822// Define non-member operator<< so that Output can stream out a string map.
1823template <typename T>
1824inline std::enable_if_t<has_CustomMappingTraits<T>::value, Output &>
1825operator<<(Output &Out, T &Val) {
1826 EmptyContext Ctx;
1827 Out.beginDocuments();
1828 if (Out.preflightDocument(0)) {
1829 yamlize(Out, Val, true, Ctx);
1830 Out.postflightDocument();
1831 }
1832 Out.endDocuments();
1833 return Out;
1834}
1835
1836// Define non-member operator<< so that Output can stream out a polymorphic
1837// type.
1838template <typename T>
1839inline std::enable_if_t<has_PolymorphicTraits<T>::value, Output &>
1840operator<<(Output &Out, T &Val) {
1841 EmptyContext Ctx;
1842 Out.beginDocuments();
1843 if (Out.preflightDocument(0)) {
1844 // FIXME: The parser does not support explicit documents terminated with a
1845 // plain scalar; the end-marker is included as part of the scalar token.
1846 assert(PolymorphicTraits<T>::getKind(Val) != NodeKind::Scalar && "plain scalar documents are not supported")((PolymorphicTraits<T>::getKind(Val) != NodeKind::Scalar
&& "plain scalar documents are not supported") ? static_cast
<void> (0) : __assert_fail ("PolymorphicTraits<T>::getKind(Val) != NodeKind::Scalar && \"plain scalar documents are not supported\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/include/llvm/Support/YAMLTraits.h"
, 1846, __PRETTY_FUNCTION__))
;
1847 yamlize(Out, Val, true, Ctx);
1848 Out.postflightDocument();
1849 }
1850 Out.endDocuments();
1851 return Out;
1852}
1853
1854// Provide better error message about types missing a trait specialization
1855template <typename T>
1856inline std::enable_if_t<missingTraits<T, EmptyContext>::value, Output &>
1857operator<<(Output &yout, T &seq) {
1858 char missing_yaml_trait_for_type[sizeof(MissingTrait<T>)];
1859 return yout;
1860}
1861
1862template <bool B> struct IsFlowSequenceBase {};
1863template <> struct IsFlowSequenceBase<true> { static const bool flow = true; };
1864
1865template <typename T, bool Flow>
1866struct SequenceTraitsImpl : IsFlowSequenceBase<Flow> {
1867private:
1868 using type = typename T::value_type;
1869
1870public:
1871 static size_t size(IO &io, T &seq) { return seq.size(); }
1872
1873 static type &element(IO &io, T &seq, size_t index) {
1874 if (index >= seq.size())
1875 seq.resize(index + 1);
1876 return seq[index];
1877 }
1878};
1879
1880// Simple helper to check an expression can be used as a bool-valued template
1881// argument.
1882template <bool> struct CheckIsBool { static const bool value = true; };
1883
1884// If T has SequenceElementTraits, then vector<T> and SmallVector<T, N> have
1885// SequenceTraits that do the obvious thing.
1886template <typename T>
1887struct SequenceTraits<
1888 std::vector<T>,
1889 std::enable_if_t<CheckIsBool<SequenceElementTraits<T>::flow>::value>>
1890 : SequenceTraitsImpl<std::vector<T>, SequenceElementTraits<T>::flow> {};
1891template <typename T, unsigned N>
1892struct SequenceTraits<
1893 SmallVector<T, N>,
1894 std::enable_if_t<CheckIsBool<SequenceElementTraits<T>::flow>::value>>
1895 : SequenceTraitsImpl<SmallVector<T, N>, SequenceElementTraits<T>::flow> {};
1896template <typename T>
1897struct SequenceTraits<
1898 SmallVectorImpl<T>,
1899 std::enable_if_t<CheckIsBool<SequenceElementTraits<T>::flow>::value>>
1900 : SequenceTraitsImpl<SmallVectorImpl<T>, SequenceElementTraits<T>::flow> {};
1901
1902// Sequences of fundamental types use flow formatting.
1903template <typename T>
1904struct SequenceElementTraits<T,
1905 std::enable_if_t<std::is_fundamental<T>::value>> {
1906 static const bool flow = true;
1907};
1908
1909// Sequences of strings use block formatting.
1910template<> struct SequenceElementTraits<std::string> {
1911 static const bool flow = false;
1912};
1913template<> struct SequenceElementTraits<StringRef> {
1914 static const bool flow = false;
1915};
1916template<> struct SequenceElementTraits<std::pair<std::string, std::string>> {
1917 static const bool flow = false;
1918};
1919
1920/// Implementation of CustomMappingTraits for std::map<std::string, T>.
1921template <typename T> struct StdMapStringCustomMappingTraitsImpl {
1922 using map_type = std::map<std::string, T>;
1923
1924 static void inputOne(IO &io, StringRef key, map_type &v) {
1925 io.mapRequired(key.str().c_str(), v[std::string(key)]);
1926 }
1927
1928 static void output(IO &io, map_type &v) {
1929 for (auto &p : v)
1930 io.mapRequired(p.first.c_str(), p.second);
1931 }
1932};
1933
1934} // end namespace yaml
1935} // end namespace llvm
1936
1937#define LLVM_YAML_IS_SEQUENCE_VECTOR_IMPL(TYPE, FLOW)namespace llvm { namespace yaml { static_assert( !std::is_fundamental
<TYPE>::value && !std::is_same<TYPE, std::string
>::value && !std::is_same<TYPE, llvm::StringRef
>::value, "only use LLVM_YAML_IS_SEQUENCE_VECTOR for types you control"
); template <> struct SequenceElementTraits<TYPE>
{ static const bool flow = FLOW; }; } }
\
1938 namespace llvm { \
1939 namespace yaml { \
1940 static_assert( \
1941 !std::is_fundamental<TYPE>::value && \
1942 !std::is_same<TYPE, std::string>::value && \
1943 !std::is_same<TYPE, llvm::StringRef>::value, \
1944 "only use LLVM_YAML_IS_SEQUENCE_VECTOR for types you control"); \
1945 template <> struct SequenceElementTraits<TYPE> { \
1946 static const bool flow = FLOW; \
1947 }; \
1948 } \
1949 }
1950
1951/// Utility for declaring that a std::vector of a particular type
1952/// should be considered a YAML sequence.
1953#define LLVM_YAML_IS_SEQUENCE_VECTOR(type)namespace llvm { namespace yaml { static_assert( !std::is_fundamental
<type>::value && !std::is_same<type, std::string
>::value && !std::is_same<type, llvm::StringRef
>::value, "only use LLVM_YAML_IS_SEQUENCE_VECTOR for types you control"
); template <> struct SequenceElementTraits<type>
{ static const bool flow = false; }; } }
\
1954 LLVM_YAML_IS_SEQUENCE_VECTOR_IMPL(type, false)namespace llvm { namespace yaml { static_assert( !std::is_fundamental
<type>::value && !std::is_same<type, std::string
>::value && !std::is_same<type, llvm::StringRef
>::value, "only use LLVM_YAML_IS_SEQUENCE_VECTOR for types you control"
); template <> struct SequenceElementTraits<type>
{ static const bool flow = false; }; } }
1955
1956/// Utility for declaring that a std::vector of a particular type
1957/// should be considered a YAML flow sequence.
1958#define LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(type)namespace llvm { namespace yaml { static_assert( !std::is_fundamental
<type>::value && !std::is_same<type, std::string
>::value && !std::is_same<type, llvm::StringRef
>::value, "only use LLVM_YAML_IS_SEQUENCE_VECTOR for types you control"
); template <> struct SequenceElementTraits<type>
{ static const bool flow = true; }; } }
\
1959 LLVM_YAML_IS_SEQUENCE_VECTOR_IMPL(type, true)namespace llvm { namespace yaml { static_assert( !std::is_fundamental
<type>::value && !std::is_same<type, std::string
>::value && !std::is_same<type, llvm::StringRef
>::value, "only use LLVM_YAML_IS_SEQUENCE_VECTOR for types you control"
); template <> struct SequenceElementTraits<type>
{ static const bool flow = true; }; } }
1960
1961#define LLVM_YAML_DECLARE_MAPPING_TRAITS(Type)namespace llvm { namespace yaml { template <> struct MappingTraits
<Type> { static void mapping(IO &IO, Type &Obj)
; }; } }
\
1962 namespace llvm { \
1963 namespace yaml { \
1964 template <> struct MappingTraits<Type> { \
1965 static void mapping(IO &IO, Type &Obj); \
1966 }; \
1967 } \
1968 }
1969
1970#define LLVM_YAML_DECLARE_ENUM_TRAITS(Type)namespace llvm { namespace yaml { template <> struct ScalarEnumerationTraits
<Type> { static void enumeration(IO &io, Type &
Value); }; } }
\
1971 namespace llvm { \
1972 namespace yaml { \
1973 template <> struct ScalarEnumerationTraits<Type> { \
1974 static void enumeration(IO &io, Type &Value); \
1975 }; \
1976 } \
1977 }
1978
1979#define LLVM_YAML_DECLARE_BITSET_TRAITS(Type)namespace llvm { namespace yaml { template <> struct ScalarBitSetTraits
<Type> { static void bitset(IO &IO, Type &Options
); }; } }
\
1980 namespace llvm { \
1981 namespace yaml { \
1982 template <> struct ScalarBitSetTraits<Type> { \
1983 static void bitset(IO &IO, Type &Options); \
1984 }; \
1985 } \
1986 }
1987
1988#define LLVM_YAML_DECLARE_SCALAR_TRAITS(Type, MustQuote)namespace llvm { namespace yaml { template <> struct ScalarTraits
<Type> { static void output(const Type &Value, void
*ctx, raw_ostream &Out); static StringRef input(StringRef
Scalar, void *ctxt, Type &Value); static QuotingType mustQuote
(StringRef) { return MustQuote; } }; } }
\
1989 namespace llvm { \
1990 namespace yaml { \
1991 template <> struct ScalarTraits<Type> { \
1992 static void output(const Type &Value, void *ctx, raw_ostream &Out); \
1993 static StringRef input(StringRef Scalar, void *ctxt, Type &Value); \
1994 static QuotingType mustQuote(StringRef) { return MustQuote; } \
1995 }; \
1996 } \
1997 }
1998
1999/// Utility for declaring that a std::vector of a particular type
2000/// should be considered a YAML document list.
2001#define LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(_type)namespace llvm { namespace yaml { template <unsigned N>
struct DocumentListTraits<SmallVector<_type, N>>
: public SequenceTraitsImpl<SmallVector<_type, N>, false
> {}; template <> struct DocumentListTraits<std::
vector<_type>> : public SequenceTraitsImpl<std::vector
<_type>, false> {}; } }
\
2002 namespace llvm { \
2003 namespace yaml { \
2004 template <unsigned N> \
2005 struct DocumentListTraits<SmallVector<_type, N>> \
2006 : public SequenceTraitsImpl<SmallVector<_type, N>, false> {}; \
2007 template <> \
2008 struct DocumentListTraits<std::vector<_type>> \
2009 : public SequenceTraitsImpl<std::vector<_type>, false> {}; \
2010 } \
2011 }
2012
2013/// Utility for declaring that std::map<std::string, _type> should be considered
2014/// a YAML map.
2015#define LLVM_YAML_IS_STRING_MAP(_type)namespace llvm { namespace yaml { template <> struct CustomMappingTraits
<std::map<std::string, _type>> : public StdMapStringCustomMappingTraitsImpl
<_type> {}; } }
\
2016 namespace llvm { \
2017 namespace yaml { \
2018 template <> \
2019 struct CustomMappingTraits<std::map<std::string, _type>> \
2020 : public StdMapStringCustomMappingTraitsImpl<_type> {}; \
2021 } \
2022 }
2023
2024LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(llvm::yaml::Hex64)namespace llvm { namespace yaml { static_assert( !std::is_fundamental
<llvm::yaml::Hex64>::value && !std::is_same<
llvm::yaml::Hex64, std::string>::value && !std::is_same
<llvm::yaml::Hex64, llvm::StringRef>::value, "only use LLVM_YAML_IS_SEQUENCE_VECTOR for types you control"
); template <> struct SequenceElementTraits<llvm::yaml
::Hex64> { static const bool flow = true; }; } }
2025LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(llvm::yaml::Hex32)namespace llvm { namespace yaml { static_assert( !std::is_fundamental
<llvm::yaml::Hex32>::value && !std::is_same<
llvm::yaml::Hex32, std::string>::value && !std::is_same
<llvm::yaml::Hex32, llvm::StringRef>::value, "only use LLVM_YAML_IS_SEQUENCE_VECTOR for types you control"
); template <> struct SequenceElementTraits<llvm::yaml
::Hex32> { static const bool flow = true; }; } }
2026LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(llvm::yaml::Hex16)namespace llvm { namespace yaml { static_assert( !std::is_fundamental
<llvm::yaml::Hex16>::value && !std::is_same<
llvm::yaml::Hex16, std::string>::value && !std::is_same
<llvm::yaml::Hex16, llvm::StringRef>::value, "only use LLVM_YAML_IS_SEQUENCE_VECTOR for types you control"
); template <> struct SequenceElementTraits<llvm::yaml
::Hex16> { static const bool flow = true; }; } }
2027LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(llvm::yaml::Hex8)namespace llvm { namespace yaml { static_assert( !std::is_fundamental
<llvm::yaml::Hex8>::value && !std::is_same<llvm
::yaml::Hex8, std::string>::value && !std::is_same
<llvm::yaml::Hex8, llvm::StringRef>::value, "only use LLVM_YAML_IS_SEQUENCE_VECTOR for types you control"
); template <> struct SequenceElementTraits<llvm::yaml
::Hex8> { static const bool flow = true; }; } }
2028
2029#endif // LLVM_SUPPORT_YAMLTRAITS_H