Bug Summary

File:include/llvm/Support/YAMLTraits.h
Warning:line 797, 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 CodeViewYAMLTypes.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 -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -ffunction-sections -fdata-sections -resource-dir /usr/lib/llvm-8/lib/clang/8.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-8~svn350071/build-llvm/lib/ObjectYAML -I /build/llvm-toolchain-snapshot-8~svn350071/lib/ObjectYAML -I /build/llvm-toolchain-snapshot-8~svn350071/build-llvm/include -I /build/llvm-toolchain-snapshot-8~svn350071/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/include/clang/8.0.0/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-8/lib/clang/8.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++11 -fdeprecated-macro -fdebug-compilation-dir /build/llvm-toolchain-snapshot-8~svn350071/build-llvm/lib/ObjectYAML -fdebug-prefix-map=/build/llvm-toolchain-snapshot-8~svn350071=. -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -stack-protector 2 -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -o /tmp/scan-build-2018-12-27-042839-1215-1 -x c++ /build/llvm-toolchain-snapshot-8~svn350071/lib/ObjectYAML/CodeViewYAMLTypes.cpp -faddrsig

/build/llvm-toolchain-snapshot-8~svn350071/lib/ObjectYAML/CodeViewYAMLTypes.cpp

1//===- CodeViewYAMLTypes.cpp - CodeView YAMLIO types implementation -------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines classes for handling the YAML representation of CodeView
11// Debug Info.
12//
13//===----------------------------------------------------------------------===//
14
15#include "llvm/ObjectYAML/CodeViewYAMLTypes.h"
16#include "llvm/ADT/APSInt.h"
17#include "llvm/ADT/ArrayRef.h"
18#include "llvm/ADT/StringRef.h"
19#include "llvm/BinaryFormat/COFF.h"
20#include "llvm/DebugInfo/CodeView/AppendingTypeTableBuilder.h"
21#include "llvm/DebugInfo/CodeView/CVTypeVisitor.h"
22#include "llvm/DebugInfo/CodeView/CodeView.h"
23#include "llvm/DebugInfo/CodeView/CodeViewError.h"
24#include "llvm/DebugInfo/CodeView/ContinuationRecordBuilder.h"
25#include "llvm/DebugInfo/CodeView/TypeDeserializer.h"
26#include "llvm/DebugInfo/CodeView/TypeIndex.h"
27#include "llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h"
28#include "llvm/Support/Allocator.h"
29#include "llvm/Support/BinaryStreamReader.h"
30#include "llvm/Support/BinaryStreamWriter.h"
31#include "llvm/Support/Endian.h"
32#include "llvm/Support/Error.h"
33#include "llvm/Support/ErrorHandling.h"
34#include "llvm/Support/YAMLTraits.h"
35#include "llvm/Support/raw_ostream.h"
36#include <algorithm>
37#include <cassert>
38#include <cstdint>
39#include <vector>
40
41using namespace llvm;
42using namespace llvm::codeview;
43using namespace llvm::CodeViewYAML;
44using namespace llvm::CodeViewYAML::detail;
45using namespace llvm::yaml;
46
47LLVM_YAML_IS_SEQUENCE_VECTOR(OneMethodRecord)namespace llvm { namespace yaml { static_assert( !std::is_fundamental
<OneMethodRecord>::value && !std::is_same<OneMethodRecord
, std::string>::value && !std::is_same<OneMethodRecord
, llvm::StringRef>::value, "only use LLVM_YAML_IS_SEQUENCE_VECTOR for types you control"
); template <> struct SequenceElementTraits<OneMethodRecord
> { static const bool flow = false; }; } }
48LLVM_YAML_IS_SEQUENCE_VECTOR(VFTableSlotKind)namespace llvm { namespace yaml { static_assert( !std::is_fundamental
<VFTableSlotKind>::value && !std::is_same<VFTableSlotKind
, std::string>::value && !std::is_same<VFTableSlotKind
, llvm::StringRef>::value, "only use LLVM_YAML_IS_SEQUENCE_VECTOR for types you control"
); template <> struct SequenceElementTraits<VFTableSlotKind
> { static const bool flow = false; }; } }
49LLVM_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; }; } }
50
51LLVM_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; } }; } }
52LLVM_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; } }; } }
53
54LLVM_YAML_DECLARE_ENUM_TRAITS(TypeLeafKind)namespace llvm { namespace yaml { template <> struct ScalarEnumerationTraits
<TypeLeafKind> { static void enumeration(IO &io, TypeLeafKind
&Value); }; } }
55LLVM_YAML_DECLARE_ENUM_TRAITS(PointerToMemberRepresentation)namespace llvm { namespace yaml { template <> struct ScalarEnumerationTraits
<PointerToMemberRepresentation> { static void enumeration
(IO &io, PointerToMemberRepresentation &Value); }; } }
56LLVM_YAML_DECLARE_ENUM_TRAITS(VFTableSlotKind)namespace llvm { namespace yaml { template <> struct ScalarEnumerationTraits
<VFTableSlotKind> { static void enumeration(IO &io,
VFTableSlotKind &Value); }; } }
57LLVM_YAML_DECLARE_ENUM_TRAITS(CallingConvention)namespace llvm { namespace yaml { template <> struct ScalarEnumerationTraits
<CallingConvention> { static void enumeration(IO &io
, CallingConvention &Value); }; } }
58LLVM_YAML_DECLARE_ENUM_TRAITS(PointerKind)namespace llvm { namespace yaml { template <> struct ScalarEnumerationTraits
<PointerKind> { static void enumeration(IO &io, PointerKind
&Value); }; } }
59LLVM_YAML_DECLARE_ENUM_TRAITS(PointerMode)namespace llvm { namespace yaml { template <> struct ScalarEnumerationTraits
<PointerMode> { static void enumeration(IO &io, PointerMode
&Value); }; } }
60LLVM_YAML_DECLARE_ENUM_TRAITS(HfaKind)namespace llvm { namespace yaml { template <> struct ScalarEnumerationTraits
<HfaKind> { static void enumeration(IO &io, HfaKind
&Value); }; } }
61LLVM_YAML_DECLARE_ENUM_TRAITS(MemberAccess)namespace llvm { namespace yaml { template <> struct ScalarEnumerationTraits
<MemberAccess> { static void enumeration(IO &io, MemberAccess
&Value); }; } }
62LLVM_YAML_DECLARE_ENUM_TRAITS(MethodKind)namespace llvm { namespace yaml { template <> struct ScalarEnumerationTraits
<MethodKind> { static void enumeration(IO &io, MethodKind
&Value); }; } }
63LLVM_YAML_DECLARE_ENUM_TRAITS(WindowsRTClassKind)namespace llvm { namespace yaml { template <> struct ScalarEnumerationTraits
<WindowsRTClassKind> { static void enumeration(IO &
io, WindowsRTClassKind &Value); }; } }
64LLVM_YAML_DECLARE_ENUM_TRAITS(LabelType)namespace llvm { namespace yaml { template <> struct ScalarEnumerationTraits
<LabelType> { static void enumeration(IO &io, LabelType
&Value); }; } }
65
66LLVM_YAML_DECLARE_BITSET_TRAITS(PointerOptions)namespace llvm { namespace yaml { template <> struct ScalarBitSetTraits
<PointerOptions> { static void bitset(IO &IO, PointerOptions
&Options); }; } }
67LLVM_YAML_DECLARE_BITSET_TRAITS(ModifierOptions)namespace llvm { namespace yaml { template <> struct ScalarBitSetTraits
<ModifierOptions> { static void bitset(IO &IO, ModifierOptions
&Options); }; } }
68LLVM_YAML_DECLARE_BITSET_TRAITS(FunctionOptions)namespace llvm { namespace yaml { template <> struct ScalarBitSetTraits
<FunctionOptions> { static void bitset(IO &IO, FunctionOptions
&Options); }; } }
69LLVM_YAML_DECLARE_BITSET_TRAITS(ClassOptions)namespace llvm { namespace yaml { template <> struct ScalarBitSetTraits
<ClassOptions> { static void bitset(IO &IO, ClassOptions
&Options); }; } }
70LLVM_YAML_DECLARE_BITSET_TRAITS(MethodOptions)namespace llvm { namespace yaml { template <> struct ScalarBitSetTraits
<MethodOptions> { static void bitset(IO &IO, MethodOptions
&Options); }; } }
71
72LLVM_YAML_DECLARE_MAPPING_TRAITS(OneMethodRecord)namespace llvm { namespace yaml { template <> struct MappingTraits
<OneMethodRecord> { static void mapping(IO &IO, OneMethodRecord
&Obj); }; } }
73LLVM_YAML_DECLARE_MAPPING_TRAITS(MemberPointerInfo)namespace llvm { namespace yaml { template <> struct MappingTraits
<MemberPointerInfo> { static void mapping(IO &IO, MemberPointerInfo
&Obj); }; } }
74
75namespace llvm {
76namespace CodeViewYAML {
77namespace detail {
78
79struct LeafRecordBase {
80 TypeLeafKind Kind;
81
82 explicit LeafRecordBase(TypeLeafKind K) : Kind(K) {}
83 virtual ~LeafRecordBase() = default;
84
85 virtual void map(yaml::IO &io) = 0;
86 virtual CVType toCodeViewRecord(AppendingTypeTableBuilder &TS) const = 0;
87 virtual Error fromCodeViewRecord(CVType Type) = 0;
88};
89
90template <typename T> struct LeafRecordImpl : public LeafRecordBase {
91 explicit LeafRecordImpl(TypeLeafKind K)
92 : LeafRecordBase(K), Record(static_cast<TypeRecordKind>(K)) {}
93
94 void map(yaml::IO &io) override;
95
96 Error fromCodeViewRecord(CVType Type) override {
97 return TypeDeserializer::deserializeAs<T>(Type, Record);
98 }
99
100 CVType toCodeViewRecord(AppendingTypeTableBuilder &TS) const override {
101 TS.writeLeafType(Record);
102 return CVType(Kind, TS.records().back());
103 }
104
105 mutable T Record;
106};
107
108template <> struct LeafRecordImpl<FieldListRecord> : public LeafRecordBase {
109 explicit LeafRecordImpl(TypeLeafKind K) : LeafRecordBase(K) {}
110
111 void map(yaml::IO &io) override;
112 CVType toCodeViewRecord(AppendingTypeTableBuilder &TS) const override;
113 Error fromCodeViewRecord(CVType Type) override;
114
115 std::vector<MemberRecord> Members;
116};
117
118struct MemberRecordBase {
119 TypeLeafKind Kind;
120
121 explicit MemberRecordBase(TypeLeafKind K) : Kind(K) {}
122 virtual ~MemberRecordBase() = default;
123
124 virtual void map(yaml::IO &io) = 0;
125 virtual void writeTo(ContinuationRecordBuilder &CRB) = 0;
126};
127
128template <typename T> struct MemberRecordImpl : public MemberRecordBase {
129 explicit MemberRecordImpl(TypeLeafKind K)
130 : MemberRecordBase(K), Record(static_cast<TypeRecordKind>(K)) {}
131
132 void map(yaml::IO &io) override;
133
134 void writeTo(ContinuationRecordBuilder &CRB) override {
135 CRB.writeMemberType(Record);
136 }
137
138 mutable T Record;
139};
140
141} // end namespace detail
142} // end namespace CodeViewYAML
143} // end namespace llvm
144
145void ScalarTraits<GUID>::output(const GUID &G, void *, llvm::raw_ostream &OS) {
146 OS << G;
147}
148
149StringRef ScalarTraits<GUID>::input(StringRef Scalar, void *Ctx, GUID &S) {
150 if (Scalar.size() != 38)
151 return "GUID strings are 38 characters long";
152 if (Scalar[0] != '{' || Scalar[37] != '}')
153 return "GUID is not enclosed in {}";
154 if (Scalar[9] != '-' || Scalar[14] != '-' || Scalar[19] != '-' ||
155 Scalar[24] != '-')
156 return "GUID sections are not properly delineated with dashes";
157
158 uint8_t *OutBuffer = S.Guid;
159 for (auto Iter = Scalar.begin(); Iter != Scalar.end();) {
160 if (*Iter == '-' || *Iter == '{' || *Iter == '}') {
161 ++Iter;
162 continue;
163 }
164 uint8_t Value = (llvm::hexDigitValue(*Iter++) << 4);
165 Value |= llvm::hexDigitValue(*Iter++);
166 *OutBuffer++ = Value;
167 }
168
169 return "";
170}
171
172void ScalarTraits<TypeIndex>::output(const TypeIndex &S, void *,
173 raw_ostream &OS) {
174 OS << S.getIndex();
175}
176
177StringRef ScalarTraits<TypeIndex>::input(StringRef Scalar, void *Ctx,
178 TypeIndex &S) {
179 uint32_t I;
180 StringRef Result = ScalarTraits<uint32_t>::input(Scalar, Ctx, I);
181 S.setIndex(I);
182 return Result;
183}
184
185void ScalarTraits<APSInt>::output(const APSInt &S, void *, raw_ostream &OS) {
186 S.print(OS, S.isSigned());
187}
188
189StringRef ScalarTraits<APSInt>::input(StringRef Scalar, void *Ctx, APSInt &S) {
190 S = APSInt(Scalar);
191 return "";
192}
193
194void ScalarEnumerationTraits<TypeLeafKind>::enumeration(IO &io,
195 TypeLeafKind &Value) {
196#define CV_TYPE(name, val) io.enumCase(Value, #name, name);
197#include "llvm/DebugInfo/CodeView/CodeViewTypes.def"
198#undef CV_TYPE
199}
200
201void ScalarEnumerationTraits<PointerToMemberRepresentation>::enumeration(
202 IO &IO, PointerToMemberRepresentation &Value) {
203 IO.enumCase(Value, "Unknown", PointerToMemberRepresentation::Unknown);
204 IO.enumCase(Value, "SingleInheritanceData",
205 PointerToMemberRepresentation::SingleInheritanceData);
206 IO.enumCase(Value, "MultipleInheritanceData",
207 PointerToMemberRepresentation::MultipleInheritanceData);
208 IO.enumCase(Value, "VirtualInheritanceData",
209 PointerToMemberRepresentation::VirtualInheritanceData);
210 IO.enumCase(Value, "GeneralData", PointerToMemberRepresentation::GeneralData);
211 IO.enumCase(Value, "SingleInheritanceFunction",
212 PointerToMemberRepresentation::SingleInheritanceFunction);
213 IO.enumCase(Value, "MultipleInheritanceFunction",
214 PointerToMemberRepresentation::MultipleInheritanceFunction);
215 IO.enumCase(Value, "VirtualInheritanceFunction",
216 PointerToMemberRepresentation::VirtualInheritanceFunction);
217 IO.enumCase(Value, "GeneralFunction",
218 PointerToMemberRepresentation::GeneralFunction);
219}
220
221void ScalarEnumerationTraits<VFTableSlotKind>::enumeration(
222 IO &IO, VFTableSlotKind &Kind) {
223 IO.enumCase(Kind, "Near16", VFTableSlotKind::Near16);
224 IO.enumCase(Kind, "Far16", VFTableSlotKind::Far16);
225 IO.enumCase(Kind, "This", VFTableSlotKind::This);
226 IO.enumCase(Kind, "Outer", VFTableSlotKind::Outer);
227 IO.enumCase(Kind, "Meta", VFTableSlotKind::Meta);
228 IO.enumCase(Kind, "Near", VFTableSlotKind::Near);
229 IO.enumCase(Kind, "Far", VFTableSlotKind::Far);
230}
231
232void ScalarEnumerationTraits<CallingConvention>::enumeration(
233 IO &IO, CallingConvention &Value) {
234 IO.enumCase(Value, "NearC", CallingConvention::NearC);
235 IO.enumCase(Value, "FarC", CallingConvention::FarC);
236 IO.enumCase(Value, "NearPascal", CallingConvention::NearPascal);
237 IO.enumCase(Value, "FarPascal", CallingConvention::FarPascal);
238 IO.enumCase(Value, "NearFast", CallingConvention::NearFast);
239 IO.enumCase(Value, "FarFast", CallingConvention::FarFast);
240 IO.enumCase(Value, "NearStdCall", CallingConvention::NearStdCall);
241 IO.enumCase(Value, "FarStdCall", CallingConvention::FarStdCall);
242 IO.enumCase(Value, "NearSysCall", CallingConvention::NearSysCall);
243 IO.enumCase(Value, "FarSysCall", CallingConvention::FarSysCall);
244 IO.enumCase(Value, "ThisCall", CallingConvention::ThisCall);
245 IO.enumCase(Value, "MipsCall", CallingConvention::MipsCall);
246 IO.enumCase(Value, "Generic", CallingConvention::Generic);
247 IO.enumCase(Value, "AlphaCall", CallingConvention::AlphaCall);
248 IO.enumCase(Value, "PpcCall", CallingConvention::PpcCall);
249 IO.enumCase(Value, "SHCall", CallingConvention::SHCall);
250 IO.enumCase(Value, "ArmCall", CallingConvention::ArmCall);
251 IO.enumCase(Value, "AM33Call", CallingConvention::AM33Call);
252 IO.enumCase(Value, "TriCall", CallingConvention::TriCall);
253 IO.enumCase(Value, "SH5Call", CallingConvention::SH5Call);
254 IO.enumCase(Value, "M32RCall", CallingConvention::M32RCall);
255 IO.enumCase(Value, "ClrCall", CallingConvention::ClrCall);
256 IO.enumCase(Value, "Inline", CallingConvention::Inline);
257 IO.enumCase(Value, "NearVector", CallingConvention::NearVector);
258}
259
260void ScalarEnumerationTraits<PointerKind>::enumeration(IO &IO,
261 PointerKind &Kind) {
262 IO.enumCase(Kind, "Near16", PointerKind::Near16);
263 IO.enumCase(Kind, "Far16", PointerKind::Far16);
264 IO.enumCase(Kind, "Huge16", PointerKind::Huge16);
265 IO.enumCase(Kind, "BasedOnSegment", PointerKind::BasedOnSegment);
266 IO.enumCase(Kind, "BasedOnValue", PointerKind::BasedOnValue);
267 IO.enumCase(Kind, "BasedOnSegmentValue", PointerKind::BasedOnSegmentValue);
268 IO.enumCase(Kind, "BasedOnAddress", PointerKind::BasedOnAddress);
269 IO.enumCase(Kind, "BasedOnSegmentAddress",
270 PointerKind::BasedOnSegmentAddress);
271 IO.enumCase(Kind, "BasedOnType", PointerKind::BasedOnType);
272 IO.enumCase(Kind, "BasedOnSelf", PointerKind::BasedOnSelf);
273 IO.enumCase(Kind, "Near32", PointerKind::Near32);
274 IO.enumCase(Kind, "Far32", PointerKind::Far32);
275 IO.enumCase(Kind, "Near64", PointerKind::Near64);
276}
277
278void ScalarEnumerationTraits<PointerMode>::enumeration(IO &IO,
279 PointerMode &Mode) {
280 IO.enumCase(Mode, "Pointer", PointerMode::Pointer);
281 IO.enumCase(Mode, "LValueReference", PointerMode::LValueReference);
282 IO.enumCase(Mode, "PointerToDataMember", PointerMode::PointerToDataMember);
283 IO.enumCase(Mode, "PointerToMemberFunction",
284 PointerMode::PointerToMemberFunction);
285 IO.enumCase(Mode, "RValueReference", PointerMode::RValueReference);
286}
287
288void ScalarEnumerationTraits<HfaKind>::enumeration(IO &IO, HfaKind &Value) {
289 IO.enumCase(Value, "None", HfaKind::None);
290 IO.enumCase(Value, "Float", HfaKind::Float);
291 IO.enumCase(Value, "Double", HfaKind::Double);
292 IO.enumCase(Value, "Other", HfaKind::Other);
293}
294
295void ScalarEnumerationTraits<MemberAccess>::enumeration(IO &IO,
296 MemberAccess &Access) {
297 IO.enumCase(Access, "None", MemberAccess::None);
298 IO.enumCase(Access, "Private", MemberAccess::Private);
299 IO.enumCase(Access, "Protected", MemberAccess::Protected);
300 IO.enumCase(Access, "Public", MemberAccess::Public);
301}
302
303void ScalarEnumerationTraits<MethodKind>::enumeration(IO &IO,
304 MethodKind &Kind) {
305 IO.enumCase(Kind, "Vanilla", MethodKind::Vanilla);
306 IO.enumCase(Kind, "Virtual", MethodKind::Virtual);
307 IO.enumCase(Kind, "Static", MethodKind::Static);
308 IO.enumCase(Kind, "Friend", MethodKind::Friend);
309 IO.enumCase(Kind, "IntroducingVirtual", MethodKind::IntroducingVirtual);
310 IO.enumCase(Kind, "PureVirtual", MethodKind::PureVirtual);
311 IO.enumCase(Kind, "PureIntroducingVirtual",
312 MethodKind::PureIntroducingVirtual);
313}
314
315void ScalarEnumerationTraits<WindowsRTClassKind>::enumeration(
316 IO &IO, WindowsRTClassKind &Value) {
317 IO.enumCase(Value, "None", WindowsRTClassKind::None);
318 IO.enumCase(Value, "Ref", WindowsRTClassKind::RefClass);
319 IO.enumCase(Value, "Value", WindowsRTClassKind::ValueClass);
320 IO.enumCase(Value, "Interface", WindowsRTClassKind::Interface);
321}
322
323void ScalarEnumerationTraits<LabelType>::enumeration(IO &IO, LabelType &Value) {
324 IO.enumCase(Value, "Near", LabelType::Near);
325 IO.enumCase(Value, "Far", LabelType::Far);
326}
327
328void ScalarBitSetTraits<PointerOptions>::bitset(IO &IO,
329 PointerOptions &Options) {
330 IO.bitSetCase(Options, "None", PointerOptions::None);
331 IO.bitSetCase(Options, "Flat32", PointerOptions::Flat32);
332 IO.bitSetCase(Options, "Volatile", PointerOptions::Volatile);
333 IO.bitSetCase(Options, "Const", PointerOptions::Const);
334 IO.bitSetCase(Options, "Unaligned", PointerOptions::Unaligned);
335 IO.bitSetCase(Options, "Restrict", PointerOptions::Restrict);
336 IO.bitSetCase(Options, "WinRTSmartPointer",
337 PointerOptions::WinRTSmartPointer);
338}
339
340void ScalarBitSetTraits<ModifierOptions>::bitset(IO &IO,
341 ModifierOptions &Options) {
342 IO.bitSetCase(Options, "None", ModifierOptions::None);
343 IO.bitSetCase(Options, "Const", ModifierOptions::Const);
344 IO.bitSetCase(Options, "Volatile", ModifierOptions::Volatile);
345 IO.bitSetCase(Options, "Unaligned", ModifierOptions::Unaligned);
346}
347
348void ScalarBitSetTraits<FunctionOptions>::bitset(IO &IO,
349 FunctionOptions &Options) {
350 IO.bitSetCase(Options, "None", FunctionOptions::None);
351 IO.bitSetCase(Options, "CxxReturnUdt", FunctionOptions::CxxReturnUdt);
352 IO.bitSetCase(Options, "Constructor", FunctionOptions::Constructor);
353 IO.bitSetCase(Options, "ConstructorWithVirtualBases",
354 FunctionOptions::ConstructorWithVirtualBases);
355}
356
357void ScalarBitSetTraits<ClassOptions>::bitset(IO &IO, ClassOptions &Options) {
358 IO.bitSetCase(Options, "None", ClassOptions::None);
359 IO.bitSetCase(Options, "HasConstructorOrDestructor",
360 ClassOptions::HasConstructorOrDestructor);
361 IO.bitSetCase(Options, "HasOverloadedOperator",
362 ClassOptions::HasOverloadedOperator);
363 IO.bitSetCase(Options, "Nested", ClassOptions::Nested);
364 IO.bitSetCase(Options, "ContainsNestedClass",
365 ClassOptions::ContainsNestedClass);
366 IO.bitSetCase(Options, "HasOverloadedAssignmentOperator",
367 ClassOptions::HasOverloadedAssignmentOperator);
368 IO.bitSetCase(Options, "HasConversionOperator",
369 ClassOptions::HasConversionOperator);
370 IO.bitSetCase(Options, "ForwardReference", ClassOptions::ForwardReference);
371 IO.bitSetCase(Options, "Scoped", ClassOptions::Scoped);
372 IO.bitSetCase(Options, "HasUniqueName", ClassOptions::HasUniqueName);
373 IO.bitSetCase(Options, "Sealed", ClassOptions::Sealed);
374 IO.bitSetCase(Options, "Intrinsic", ClassOptions::Intrinsic);
375}
376
377void ScalarBitSetTraits<MethodOptions>::bitset(IO &IO, MethodOptions &Options) {
378 IO.bitSetCase(Options, "None", MethodOptions::None);
379 IO.bitSetCase(Options, "Pseudo", MethodOptions::Pseudo);
380 IO.bitSetCase(Options, "NoInherit", MethodOptions::NoInherit);
381 IO.bitSetCase(Options, "NoConstruct", MethodOptions::NoConstruct);
382 IO.bitSetCase(Options, "CompilerGenerated", MethodOptions::CompilerGenerated);
383 IO.bitSetCase(Options, "Sealed", MethodOptions::Sealed);
384}
385
386void MappingTraits<MemberPointerInfo>::mapping(IO &IO, MemberPointerInfo &MPI) {
387 IO.mapRequired("ContainingType", MPI.ContainingType);
388 IO.mapRequired("Representation", MPI.Representation);
389}
390
391namespace llvm {
392namespace CodeViewYAML {
393namespace detail {
394
395template <> void LeafRecordImpl<ModifierRecord>::map(IO &IO) {
396 IO.mapRequired("ModifiedType", Record.ModifiedType);
397 IO.mapRequired("Modifiers", Record.Modifiers);
398}
399
400template <> void LeafRecordImpl<ProcedureRecord>::map(IO &IO) {
401 IO.mapRequired("ReturnType", Record.ReturnType);
402 IO.mapRequired("CallConv", Record.CallConv);
403 IO.mapRequired("Options", Record.Options);
404 IO.mapRequired("ParameterCount", Record.ParameterCount);
405 IO.mapRequired("ArgumentList", Record.ArgumentList);
406}
407
408template <> void LeafRecordImpl<MemberFunctionRecord>::map(IO &IO) {
409 IO.mapRequired("ReturnType", Record.ReturnType);
410 IO.mapRequired("ClassType", Record.ClassType);
411 IO.mapRequired("ThisType", Record.ThisType);
412 IO.mapRequired("CallConv", Record.CallConv);
413 IO.mapRequired("Options", Record.Options);
414 IO.mapRequired("ParameterCount", Record.ParameterCount);
415 IO.mapRequired("ArgumentList", Record.ArgumentList);
416 IO.mapRequired("ThisPointerAdjustment", Record.ThisPointerAdjustment);
417}
418
419template <> void LeafRecordImpl<LabelRecord>::map(IO &IO) {
420 IO.mapRequired("Mode", Record.Mode);
421}
422
423template <> void LeafRecordImpl<MemberFuncIdRecord>::map(IO &IO) {
424 IO.mapRequired("ClassType", Record.ClassType);
425 IO.mapRequired("FunctionType", Record.FunctionType);
426 IO.mapRequired("Name", Record.Name);
427}
428
429template <> void LeafRecordImpl<ArgListRecord>::map(IO &IO) {
430 IO.mapRequired("ArgIndices", Record.ArgIndices);
431}
432
433template <> void LeafRecordImpl<StringListRecord>::map(IO &IO) {
434 IO.mapRequired("StringIndices", Record.StringIndices);
435}
436
437template <> void LeafRecordImpl<PointerRecord>::map(IO &IO) {
438 IO.mapRequired("ReferentType", Record.ReferentType);
439 IO.mapRequired("Attrs", Record.Attrs);
440 IO.mapOptional("MemberInfo", Record.MemberInfo);
441}
442
443template <> void LeafRecordImpl<ArrayRecord>::map(IO &IO) {
444 IO.mapRequired("ElementType", Record.ElementType);
445 IO.mapRequired("IndexType", Record.IndexType);
446 IO.mapRequired("Size", Record.Size);
447 IO.mapRequired("Name", Record.Name);
448}
449
450void LeafRecordImpl<FieldListRecord>::map(IO &IO) {
451 IO.mapRequired("FieldList", Members);
452}
453
454} // end namespace detail
455} // end namespace CodeViewYAML
456} // end namespace llvm
457
458namespace {
459
460class MemberRecordConversionVisitor : public TypeVisitorCallbacks {
461public:
462 explicit MemberRecordConversionVisitor(std::vector<MemberRecord> &Records)
463 : Records(Records) {}
464
465#define TYPE_RECORD(EnumName, EnumVal, Name)
466#define MEMBER_RECORD(EnumName, EnumVal, Name) \
467 Error visitKnownMember(CVMemberRecord &CVR, Name##Record &Record) override { \
468 return visitKnownMemberImpl(Record); \
469 }
470#define TYPE_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
471#define MEMBER_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
472#include "llvm/DebugInfo/CodeView/CodeViewTypes.def"
473private:
474 template <typename T> Error visitKnownMemberImpl(T &Record) {
475 TypeLeafKind K = static_cast<TypeLeafKind>(Record.getKind());
476 auto Impl = std::make_shared<MemberRecordImpl<T>>(K);
477 Impl->Record = Record;
478 Records.push_back(MemberRecord{Impl});
479 return Error::success();
480 }
481
482 std::vector<MemberRecord> &Records;
483};
484
485} // end anonymous namespace
486
487Error LeafRecordImpl<FieldListRecord>::fromCodeViewRecord(CVType Type) {
488 MemberRecordConversionVisitor V(Members);
489 return visitMemberRecordStream(Type.content(), V);
490}
491
492CVType LeafRecordImpl<FieldListRecord>::toCodeViewRecord(
493 AppendingTypeTableBuilder &TS) const {
494 ContinuationRecordBuilder CRB;
495 CRB.begin(ContinuationRecordKind::FieldList);
496 for (const auto &Member : Members) {
497 Member.Member->writeTo(CRB);
498 }
499 TS.insertRecord(CRB);
500 return CVType(Kind, TS.records().back());
501}
502
503void MappingTraits<OneMethodRecord>::mapping(IO &io, OneMethodRecord &Record) {
504 io.mapRequired("Type", Record.Type);
505 io.mapRequired("Attrs", Record.Attrs.Attrs);
506 io.mapRequired("VFTableOffset", Record.VFTableOffset);
507 io.mapRequired("Name", Record.Name);
508}
509
510namespace llvm {
511namespace CodeViewYAML {
512namespace detail {
513
514template <> void LeafRecordImpl<ClassRecord>::map(IO &IO) {
515 IO.mapRequired("MemberCount", Record.MemberCount);
516 IO.mapRequired("Options", Record.Options);
517 IO.mapRequired("FieldList", Record.FieldList);
518 IO.mapRequired("Name", Record.Name);
519 IO.mapRequired("UniqueName", Record.UniqueName);
520 IO.mapRequired("DerivationList", Record.DerivationList);
521 IO.mapRequired("VTableShape", Record.VTableShape);
522 IO.mapRequired("Size", Record.Size);
523}
524
525template <> void LeafRecordImpl<UnionRecord>::map(IO &IO) {
526 IO.mapRequired("MemberCount", Record.MemberCount);
527 IO.mapRequired("Options", Record.Options);
528 IO.mapRequired("FieldList", Record.FieldList);
529 IO.mapRequired("Name", Record.Name);
530 IO.mapRequired("UniqueName", Record.UniqueName);
531 IO.mapRequired("Size", Record.Size);
532}
533
534template <> void LeafRecordImpl<EnumRecord>::map(IO &IO) {
535 IO.mapRequired("NumEnumerators", Record.MemberCount);
536 IO.mapRequired("Options", Record.Options);
537 IO.mapRequired("FieldList", Record.FieldList);
538 IO.mapRequired("Name", Record.Name);
539 IO.mapRequired("UniqueName", Record.UniqueName);
540 IO.mapRequired("UnderlyingType", Record.UnderlyingType);
541}
542
543template <> void LeafRecordImpl<BitFieldRecord>::map(IO &IO) {
544 IO.mapRequired("Type", Record.Type);
545 IO.mapRequired("BitSize", Record.BitSize);
546 IO.mapRequired("BitOffset", Record.BitOffset);
547}
548
549template <> void LeafRecordImpl<VFTableShapeRecord>::map(IO &IO) {
550 IO.mapRequired("Slots", Record.Slots);
551}
552
553template <> void LeafRecordImpl<TypeServer2Record>::map(IO &IO) {
554 IO.mapRequired("Guid", Record.Guid);
555 IO.mapRequired("Age", Record.Age);
556 IO.mapRequired("Name", Record.Name);
557}
558
559template <> void LeafRecordImpl<StringIdRecord>::map(IO &IO) {
560 IO.mapRequired("Id", Record.Id);
561 IO.mapRequired("String", Record.String);
562}
563
564template <> void LeafRecordImpl<FuncIdRecord>::map(IO &IO) {
565 IO.mapRequired("ParentScope", Record.ParentScope);
566 IO.mapRequired("FunctionType", Record.FunctionType);
567 IO.mapRequired("Name", Record.Name);
568}
569
570template <> void LeafRecordImpl<UdtSourceLineRecord>::map(IO &IO) {
571 IO.mapRequired("UDT", Record.UDT);
572 IO.mapRequired("SourceFile", Record.SourceFile);
573 IO.mapRequired("LineNumber", Record.LineNumber);
574}
575
576template <> void LeafRecordImpl<UdtModSourceLineRecord>::map(IO &IO) {
577 IO.mapRequired("UDT", Record.UDT);
578 IO.mapRequired("SourceFile", Record.SourceFile);
579 IO.mapRequired("LineNumber", Record.LineNumber);
580 IO.mapRequired("Module", Record.Module);
581}
582
583template <> void LeafRecordImpl<BuildInfoRecord>::map(IO &IO) {
584 IO.mapRequired("ArgIndices", Record.ArgIndices);
585}
586
587template <> void LeafRecordImpl<VFTableRecord>::map(IO &IO) {
588 IO.mapRequired("CompleteClass", Record.CompleteClass);
589 IO.mapRequired("OverriddenVFTable", Record.OverriddenVFTable);
590 IO.mapRequired("VFPtrOffset", Record.VFPtrOffset);
591 IO.mapRequired("MethodNames", Record.MethodNames);
592}
593
594template <> void LeafRecordImpl<MethodOverloadListRecord>::map(IO &IO) {
595 IO.mapRequired("Methods", Record.Methods);
596}
597
598template <> void LeafRecordImpl<PrecompRecord>::map(IO &IO) {
599 IO.mapRequired("StartTypeIndex", Record.StartTypeIndex);
600 IO.mapRequired("TypesCount", Record.TypesCount);
601 IO.mapRequired("Signature", Record.Signature);
602 IO.mapRequired("PrecompFilePath", Record.PrecompFilePath);
603}
604
605template <> void LeafRecordImpl<EndPrecompRecord>::map(IO &IO) {
606 IO.mapRequired("Signature", Record.Signature);
607}
608
609template <> void MemberRecordImpl<OneMethodRecord>::map(IO &IO) {
610 MappingTraits<OneMethodRecord>::mapping(IO, Record);
611}
612
613template <> void MemberRecordImpl<OverloadedMethodRecord>::map(IO &IO) {
614 IO.mapRequired("NumOverloads", Record.NumOverloads);
615 IO.mapRequired("MethodList", Record.MethodList);
616 IO.mapRequired("Name", Record.Name);
617}
618
619template <> void MemberRecordImpl<NestedTypeRecord>::map(IO &IO) {
620 IO.mapRequired("Type", Record.Type);
621 IO.mapRequired("Name", Record.Name);
622}
623
624template <> void MemberRecordImpl<DataMemberRecord>::map(IO &IO) {
625 IO.mapRequired("Attrs", Record.Attrs.Attrs);
626 IO.mapRequired("Type", Record.Type);
627 IO.mapRequired("FieldOffset", Record.FieldOffset);
628 IO.mapRequired("Name", Record.Name);
629}
630
631template <> void MemberRecordImpl<StaticDataMemberRecord>::map(IO &IO) {
632 IO.mapRequired("Attrs", Record.Attrs.Attrs);
633 IO.mapRequired("Type", Record.Type);
634 IO.mapRequired("Name", Record.Name);
635}
636
637template <> void MemberRecordImpl<EnumeratorRecord>::map(IO &IO) {
638 IO.mapRequired("Attrs", Record.Attrs.Attrs);
639 IO.mapRequired("Value", Record.Value);
640 IO.mapRequired("Name", Record.Name);
641}
642
643template <> void MemberRecordImpl<VFPtrRecord>::map(IO &IO) {
644 IO.mapRequired("Type", Record.Type);
645}
646
647template <> void MemberRecordImpl<BaseClassRecord>::map(IO &IO) {
648 IO.mapRequired("Attrs", Record.Attrs.Attrs);
649 IO.mapRequired("Type", Record.Type);
650 IO.mapRequired("Offset", Record.Offset);
651}
652
653template <> void MemberRecordImpl<VirtualBaseClassRecord>::map(IO &IO) {
654 IO.mapRequired("Attrs", Record.Attrs.Attrs);
655 IO.mapRequired("BaseType", Record.BaseType);
656 IO.mapRequired("VBPtrType", Record.VBPtrType);
657 IO.mapRequired("VBPtrOffset", Record.VBPtrOffset);
658 IO.mapRequired("VTableIndex", Record.VTableIndex);
659}
660
661template <> void MemberRecordImpl<ListContinuationRecord>::map(IO &IO) {
662 IO.mapRequired("ContinuationIndex", Record.ContinuationIndex);
663}
664
665} // end namespace detail
666} // end namespace CodeViewYAML
667} // end namespace llvm
668
669template <typename T>
670static inline Expected<LeafRecord> fromCodeViewRecordImpl(CVType Type) {
671 LeafRecord Result;
672
673 auto Impl = std::make_shared<LeafRecordImpl<T>>(Type.kind());
674 if (auto EC = Impl->fromCodeViewRecord(Type))
675 return std::move(EC);
676 Result.Leaf = Impl;
677 return Result;
678}
679
680Expected<LeafRecord> LeafRecord::fromCodeViewRecord(CVType Type) {
681#define TYPE_RECORD(EnumName, EnumVal, ClassName) \
682 case EnumName: \
683 return fromCodeViewRecordImpl<ClassName##Record>(Type);
684#define TYPE_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName) \
685 TYPE_RECORD(EnumName, EnumVal, ClassName)
686#define MEMBER_RECORD(EnumName, EnumVal, ClassName)
687#define MEMBER_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName)
688 switch (Type.kind()) {
689#include "llvm/DebugInfo/CodeView/CodeViewTypes.def"
690 default:
691 llvm_unreachable("Unknown leaf kind!")::llvm::llvm_unreachable_internal("Unknown leaf kind!", "/build/llvm-toolchain-snapshot-8~svn350071/lib/ObjectYAML/CodeViewYAMLTypes.cpp"
, 691)
;
692 }
693 return make_error<CodeViewError>(cv_error_code::corrupt_record);
694}
695
696CVType
697LeafRecord::toCodeViewRecord(AppendingTypeTableBuilder &Serializer) const {
698 return Leaf->toCodeViewRecord(Serializer);
699}
700
701namespace llvm {
702namespace yaml {
703
704template <> struct MappingTraits<LeafRecordBase> {
705 static void mapping(IO &io, LeafRecordBase &Record) { Record.map(io); }
706};
707
708template <> struct MappingTraits<MemberRecordBase> {
709 static void mapping(IO &io, MemberRecordBase &Record) { Record.map(io); }
710};
711
712} // end namespace yaml
713} // end namespace llvm
714
715template <typename ConcreteType>
716static void mapLeafRecordImpl(IO &IO, const char *Class, TypeLeafKind Kind,
717 LeafRecord &Obj) {
718 if (!IO.outputting())
719 Obj.Leaf = std::make_shared<LeafRecordImpl<ConcreteType>>(Kind);
720
721 if (Kind == LF_FIELDLIST)
722 Obj.Leaf->map(IO);
723 else
724 IO.mapRequired(Class, *Obj.Leaf);
725}
726
727void MappingTraits<LeafRecord>::mapping(IO &IO, LeafRecord &Obj) {
728 TypeLeafKind Kind;
1
'Kind' declared without an initial value
729 if (IO.outputting())
2
Assuming the condition is false
3
Taking false branch
730 Kind = Obj.Leaf->Kind;
731 IO.mapRequired("Kind", Kind);
4
Calling 'IO::mapRequired'
732
733#define TYPE_RECORD(EnumName, EnumVal, ClassName) \
734 case EnumName: \
735 mapLeafRecordImpl<ClassName##Record>(IO, #ClassName, Kind, Obj); \
736 break;
737#define TYPE_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName) \
738 TYPE_RECORD(EnumName, EnumVal, ClassName)
739#define MEMBER_RECORD(EnumName, EnumVal, ClassName)
740#define MEMBER_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName)
741 switch (Kind) {
742#include "llvm/DebugInfo/CodeView/CodeViewTypes.def"
743 default: { llvm_unreachable("Unknown leaf kind!")::llvm::llvm_unreachable_internal("Unknown leaf kind!", "/build/llvm-toolchain-snapshot-8~svn350071/lib/ObjectYAML/CodeViewYAMLTypes.cpp"
, 743)
; }
744 }
745}
746
747template <typename ConcreteType>
748static void mapMemberRecordImpl(IO &IO, const char *Class, TypeLeafKind Kind,
749 MemberRecord &Obj) {
750 if (!IO.outputting())
751 Obj.Member = std::make_shared<MemberRecordImpl<ConcreteType>>(Kind);
752
753 IO.mapRequired(Class, *Obj.Member);
754}
755
756void MappingTraits<MemberRecord>::mapping(IO &IO, MemberRecord &Obj) {
757 TypeLeafKind Kind;
758 if (IO.outputting())
759 Kind = Obj.Member->Kind;
760 IO.mapRequired("Kind", Kind);
761
762#define MEMBER_RECORD(EnumName, EnumVal, ClassName) \
763 case EnumName: \
764 mapMemberRecordImpl<ClassName##Record>(IO, #ClassName, Kind, Obj); \
765 break;
766#define MEMBER_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName) \
767 MEMBER_RECORD(EnumName, EnumVal, ClassName)
768#define TYPE_RECORD(EnumName, EnumVal, ClassName)
769#define TYPE_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName)
770 switch (Kind) {
771#include "llvm/DebugInfo/CodeView/CodeViewTypes.def"
772 default: { llvm_unreachable("Unknown member kind!")::llvm::llvm_unreachable_internal("Unknown member kind!", "/build/llvm-toolchain-snapshot-8~svn350071/lib/ObjectYAML/CodeViewYAMLTypes.cpp"
, 772)
; }
773 }
774}
775
776std::vector<LeafRecord>
777llvm::CodeViewYAML::fromDebugT(ArrayRef<uint8_t> DebugTorP,
778 StringRef SectionName) {
779 ExitOnError Err("Invalid " + std::string(SectionName) + " section!");
780 BinaryStreamReader Reader(DebugTorP, support::little);
781 CVTypeArray Types;
782 uint32_t Magic;
783
784 Err(Reader.readInteger(Magic));
785 assert(Magic == COFF::DEBUG_SECTION_MAGIC &&((Magic == COFF::DEBUG_SECTION_MAGIC && "Invalid .debug$T or .debug$P section!"
) ? static_cast<void> (0) : __assert_fail ("Magic == COFF::DEBUG_SECTION_MAGIC && \"Invalid .debug$T or .debug$P section!\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/ObjectYAML/CodeViewYAMLTypes.cpp"
, 786, __PRETTY_FUNCTION__))
786 "Invalid .debug$T or .debug$P section!")((Magic == COFF::DEBUG_SECTION_MAGIC && "Invalid .debug$T or .debug$P section!"
) ? static_cast<void> (0) : __assert_fail ("Magic == COFF::DEBUG_SECTION_MAGIC && \"Invalid .debug$T or .debug$P section!\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/ObjectYAML/CodeViewYAMLTypes.cpp"
, 786, __PRETTY_FUNCTION__))
;
787
788 std::vector<LeafRecord> Result;
789 Err(Reader.readArray(Types, Reader.bytesRemaining()));
790 for (const auto &T : Types) {
791 auto CVT = Err(LeafRecord::fromCodeViewRecord(T));
792 Result.push_back(CVT);
793 }
794 return Result;
795}
796
797ArrayRef<uint8_t> llvm::CodeViewYAML::toDebugT(ArrayRef<LeafRecord> Leafs,
798 BumpPtrAllocator &Alloc,
799 StringRef SectionName) {
800 AppendingTypeTableBuilder TS(Alloc);
801 uint32_t Size = sizeof(uint32_t);
802 for (const auto &Leaf : Leafs) {
803 CVType T = Leaf.Leaf->toCodeViewRecord(TS);
804 Size += T.length();
805 assert(T.length() % 4 == 0 && "Improper type record alignment!")((T.length() % 4 == 0 && "Improper type record alignment!"
) ? static_cast<void> (0) : __assert_fail ("T.length() % 4 == 0 && \"Improper type record alignment!\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/ObjectYAML/CodeViewYAMLTypes.cpp"
, 805, __PRETTY_FUNCTION__))
;
806 }
807 uint8_t *ResultBuffer = Alloc.Allocate<uint8_t>(Size);
808 MutableArrayRef<uint8_t> Output(ResultBuffer, Size);
809 BinaryStreamWriter Writer(Output, support::little);
810 ExitOnError Err("Error writing type record to " + std::string(SectionName) +
811 " section");
812 Err(Writer.writeInteger<uint32_t>(COFF::DEBUG_SECTION_MAGIC));
813 for (const auto &R : TS.records()) {
814 Err(Writer.writeBytes(R));
815 }
816 assert(Writer.bytesRemaining() == 0 && "Didn't write all type record bytes!")((Writer.bytesRemaining() == 0 && "Didn't write all type record bytes!"
) ? static_cast<void> (0) : __assert_fail ("Writer.bytesRemaining() == 0 && \"Didn't write all type record bytes!\""
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/ObjectYAML/CodeViewYAMLTypes.cpp"
, 816, __PRETTY_FUNCTION__))
;
817 return Output;
818}

/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/Support/YAMLTraits.h

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

/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/DebugInfo/CodeView/CodeViewTypes.def

1//===-- CodeViewTypes.def - All CodeView leaf types -------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// See LEAF_ENUM_e in cvinfo.h. This should match the constants there.
11//
12//===----------------------------------------------------------------------===//
13
14// If the type is known, then we have a record describing it in TypeRecord.h.
15
16#ifndef CV_TYPE
17#define CV_TYPE(lf_ename, value)
18#endif
19
20// If the type is known, then we have a record describing it in TypeRecord.h.
21#ifndef TYPE_RECORD
22#define TYPE_RECORD(lf_ename, value, name) CV_TYPE(lf_ename, value)
23#endif
24
25#ifndef TYPE_RECORD_ALIAS
26#define TYPE_RECORD_ALIAS(lf_ename, value, name, alias_name) \
27 TYPE_RECORD(lf_ename, value, name)
28#endif
29
30#ifndef MEMBER_RECORD
31#define MEMBER_RECORD(lf_ename, value, name) TYPE_RECORD(lf_ename, value, name)
32#endif
33
34#ifndef MEMBER_RECORD_ALIAS
35#define MEMBER_RECORD_ALIAS(lf_ename, value, name, alias_name) \
36 MEMBER_RECORD(lf_ename, value, name)
37#endif
38
39TYPE_RECORD(LF_POINTER, 0x1002, Pointer)
10
Passing value via 1st parameter 'Val'
11
Calling 'IO::enumCase'
40TYPE_RECORD(LF_MODIFIER, 0x1001, Modifier)
41TYPE_RECORD(LF_PROCEDURE, 0x1008, Procedure)
42TYPE_RECORD(LF_MFUNCTION, 0x1009, MemberFunction)
43TYPE_RECORD(LF_LABEL, 0x000e, Label)
44TYPE_RECORD(LF_ARGLIST, 0x1201, ArgList)
45
46TYPE_RECORD(LF_FIELDLIST, 0x1203, FieldList)
47
48TYPE_RECORD(LF_ARRAY, 0x1503, Array)
49TYPE_RECORD(LF_CLASS, 0x1504, Class)
50TYPE_RECORD_ALIAS(LF_STRUCTURE, 0x1505, Struct, Class)
51TYPE_RECORD_ALIAS(LF_INTERFACE, 0x1519, Interface, Class)
52TYPE_RECORD(LF_UNION, 0x1506, Union)
53TYPE_RECORD(LF_ENUM, 0x1507, Enum)
54TYPE_RECORD(LF_TYPESERVER2, 0x1515, TypeServer2)
55TYPE_RECORD(LF_VFTABLE, 0x151d, VFTable)
56TYPE_RECORD(LF_VTSHAPE, 0x000a, VFTableShape)
57
58TYPE_RECORD(LF_BITFIELD, 0x1205, BitField)
59
60// Member type records. These are generally not length prefixed, and appear
61// inside of a field list record.
62MEMBER_RECORD(LF_BCLASS, 0x1400, BaseClass)
63MEMBER_RECORD_ALIAS(LF_BINTERFACE, 0x151a, BaseInterface, BaseClass)
64
65MEMBER_RECORD(LF_VBCLASS, 0x1401, VirtualBaseClass)
66MEMBER_RECORD_ALIAS(LF_IVBCLASS, 0x1402, IndirectVirtualBaseClass,
67 VirtualBaseClass)
68
69MEMBER_RECORD(LF_VFUNCTAB, 0x1409, VFPtr)
70MEMBER_RECORD(LF_STMEMBER, 0x150e, StaticDataMember)
71MEMBER_RECORD(LF_METHOD, 0x150f, OverloadedMethod)
72MEMBER_RECORD(LF_MEMBER, 0x150d, DataMember)
73MEMBER_RECORD(LF_NESTTYPE, 0x1510, NestedType)
74MEMBER_RECORD(LF_ONEMETHOD, 0x1511, OneMethod)
75MEMBER_RECORD(LF_ENUMERATE, 0x1502, Enumerator)
76MEMBER_RECORD(LF_INDEX, 0x1404, ListContinuation)
77
78// ID leaf records. Subsequent leaf types may be referenced from .debug$S.
79TYPE_RECORD(LF_FUNC_ID, 0x1601, FuncId)
80TYPE_RECORD(LF_MFUNC_ID, 0x1602, MemberFuncId)
81TYPE_RECORD(LF_BUILDINFO, 0x1603, BuildInfo)
82TYPE_RECORD(LF_SUBSTR_LIST, 0x1604, StringList)
83TYPE_RECORD(LF_STRING_ID, 0x1605, StringId)
84TYPE_RECORD(LF_UDT_SRC_LINE, 0x1606, UdtSourceLine)
85TYPE_RECORD(LF_UDT_MOD_SRC_LINE, 0x1607, UdtModSourceLine)
86
87
88TYPE_RECORD(LF_METHODLIST, 0x1206, MethodOverloadList)
89
90TYPE_RECORD(LF_PRECOMP, 0x1509, Precomp)
91TYPE_RECORD(LF_ENDPRECOMP, 0x0014, EndPrecomp)
92
93// 16 bit type records.
94CV_TYPE(LF_MODIFIER_16t, 0x0001)
95CV_TYPE(LF_POINTER_16t, 0x0002)
96CV_TYPE(LF_ARRAY_16t, 0x0003)
97CV_TYPE(LF_CLASS_16t, 0x0004)
98CV_TYPE(LF_STRUCTURE_16t, 0x0005)
99CV_TYPE(LF_UNION_16t, 0x0006)
100CV_TYPE(LF_ENUM_16t, 0x0007)
101CV_TYPE(LF_PROCEDURE_16t, 0x0008)
102CV_TYPE(LF_MFUNCTION_16t, 0x0009)
103CV_TYPE(LF_COBOL0_16t, 0x000b)
104CV_TYPE(LF_COBOL1, 0x000c)
105CV_TYPE(LF_BARRAY_16t, 0x000d)
106CV_TYPE(LF_NULLLEAF, 0x000f) // LF_NULL
107CV_TYPE(LF_NOTTRAN, 0x0010)
108CV_TYPE(LF_DIMARRAY_16t, 0x0011)
109CV_TYPE(LF_VFTPATH_16t, 0x0012)
110CV_TYPE(LF_PRECOMP_16t, 0x0013)
111CV_TYPE(LF_OEM_16t, 0x0015)
112CV_TYPE(LF_TYPESERVER_ST, 0x0016)
113
114CV_TYPE(LF_SKIP_16t, 0x0200)
115CV_TYPE(LF_ARGLIST_16t, 0x0201)
116CV_TYPE(LF_DEFARG_16t, 0x0202)
117CV_TYPE(LF_LIST, 0x0203)
118CV_TYPE(LF_FIELDLIST_16t, 0x0204)
119CV_TYPE(LF_DERIVED_16t, 0x0205)
120CV_TYPE(LF_BITFIELD_16t, 0x0206)
121CV_TYPE(LF_METHODLIST_16t, 0x0207)
122CV_TYPE(LF_DIMCONU_16t, 0x0208)
123CV_TYPE(LF_DIMCONLU_16t, 0x0209)
124CV_TYPE(LF_DIMVARU_16t, 0x020a)
125CV_TYPE(LF_DIMVARLU_16t, 0x020b)
126CV_TYPE(LF_REFSYM, 0x020c)
127
128// 16 bit member types. Generally not length prefixed.
129CV_TYPE(LF_BCLASS_16t, 0x0400)
130CV_TYPE(LF_VBCLASS_16t, 0x0401)
131CV_TYPE(LF_IVBCLASS_16t, 0x0402)
132CV_TYPE(LF_ENUMERATE_ST, 0x0403)
133CV_TYPE(LF_FRIENDFCN_16t, 0x0404)
134CV_TYPE(LF_INDEX_16t, 0x0405)
135CV_TYPE(LF_MEMBER_16t, 0x0406)
136CV_TYPE(LF_STMEMBER_16t, 0x0407)
137CV_TYPE(LF_METHOD_16t, 0x0408)
138CV_TYPE(LF_NESTTYPE_16t, 0x0409)
139CV_TYPE(LF_VFUNCTAB_16t, 0x040a)
140CV_TYPE(LF_FRIENDCLS_16t, 0x040b)
141CV_TYPE(LF_ONEMETHOD_16t, 0x040c)
142CV_TYPE(LF_VFUNCOFF_16t, 0x040d)
143
144CV_TYPE(LF_TI16_MAX, 0x1000)
145
146CV_TYPE(LF_ARRAY_ST, 0x1003)
147CV_TYPE(LF_CLASS_ST, 0x1004)
148CV_TYPE(LF_STRUCTURE_ST, 0x1005)
149CV_TYPE(LF_UNION_ST, 0x1006)
150CV_TYPE(LF_ENUM_ST, 0x1007)
151CV_TYPE(LF_COBOL0, 0x100a)
152CV_TYPE(LF_BARRAY, 0x100b)
153CV_TYPE(LF_DIMARRAY_ST, 0x100c)
154CV_TYPE(LF_VFTPATH, 0x100d)
155CV_TYPE(LF_PRECOMP_ST, 0x100e)
156CV_TYPE(LF_OEM, 0x100f)
157CV_TYPE(LF_ALIAS_ST, 0x1010)
158CV_TYPE(LF_OEM2, 0x1011)
159
160CV_TYPE(LF_SKIP, 0x1200)
161CV_TYPE(LF_DEFARG_ST, 0x1202)
162CV_TYPE(LF_DERIVED, 0x1204)
163CV_TYPE(LF_DIMCONU, 0x1207)
164CV_TYPE(LF_DIMCONLU, 0x1208)
165CV_TYPE(LF_DIMVARU, 0x1209)
166CV_TYPE(LF_DIMVARLU, 0x120a)
167
168// Member type records. These are generally not length prefixed, and appear
169// inside of a field list record.
170CV_TYPE(LF_FRIENDFCN_ST, 0x1403)
171CV_TYPE(LF_MEMBER_ST, 0x1405)
172CV_TYPE(LF_STMEMBER_ST, 0x1406)
173CV_TYPE(LF_METHOD_ST, 0x1407)
174CV_TYPE(LF_NESTTYPE_ST, 0x1408)
175CV_TYPE(LF_FRIENDCLS, 0x140a)
176CV_TYPE(LF_ONEMETHOD_ST, 0x140b)
177CV_TYPE(LF_VFUNCOFF, 0x140c)
178CV_TYPE(LF_NESTTYPEEX_ST, 0x140d)
179CV_TYPE(LF_MEMBERMODIFY_ST, 0x140e)
180CV_TYPE(LF_MANAGED_ST, 0x140f)
181
182CV_TYPE(LF_ST_MAX, 0x1500)
183CV_TYPE(LF_TYPESERVER, 0x1501)
184CV_TYPE(LF_DIMARRAY, 0x1508)
185CV_TYPE(LF_ALIAS, 0x150a)
186CV_TYPE(LF_DEFARG, 0x150b)
187CV_TYPE(LF_FRIENDFCN, 0x150c)
188CV_TYPE(LF_NESTTYPEEX, 0x1512)
189CV_TYPE(LF_MEMBERMODIFY, 0x1513)
190CV_TYPE(LF_MANAGED, 0x1514)
191CV_TYPE(LF_STRIDED_ARRAY, 0x1516)
192CV_TYPE(LF_HLSL, 0x1517)
193CV_TYPE(LF_MODIFIER_EX, 0x1518)
194CV_TYPE(LF_VECTOR, 0x151b)
195CV_TYPE(LF_MATRIX, 0x151c)
196
197// ID leaf records. Subsequent leaf types may be referenced from .debug$S.
198
199// Numeric leaf types. These are generally contained in other records, and not
200// encountered in the main type stream.
201
202CV_TYPE(LF_NUMERIC, 0x8000)
203CV_TYPE(LF_CHAR, 0x8000)
204CV_TYPE(LF_SHORT, 0x8001)
205CV_TYPE(LF_USHORT, 0x8002)
206CV_TYPE(LF_LONG, 0x8003)
207CV_TYPE(LF_ULONG, 0x8004)
208CV_TYPE(LF_REAL32, 0x8005)
209CV_TYPE(LF_REAL64, 0x8006)
210CV_TYPE(LF_REAL80, 0x8007)
211CV_TYPE(LF_REAL128, 0x8008)
212CV_TYPE(LF_QUADWORD, 0x8009)
213CV_TYPE(LF_UQUADWORD, 0x800a)
214CV_TYPE(LF_REAL48, 0x800b)
215CV_TYPE(LF_COMPLEX32, 0x800c)
216CV_TYPE(LF_COMPLEX64, 0x800d)
217CV_TYPE(LF_COMPLEX80, 0x800e)
218CV_TYPE(LF_COMPLEX128, 0x800f)
219CV_TYPE(LF_VARSTRING, 0x8010)
220CV_TYPE(LF_OCTWORD, 0x8017)
221CV_TYPE(LF_UOCTWORD, 0x8018)
222CV_TYPE(LF_DECIMAL, 0x8019)
223CV_TYPE(LF_DATE, 0x801a)
224CV_TYPE(LF_UTF8STRING, 0x801b)
225CV_TYPE(LF_REAL16, 0x801c)
226
227// Padding bytes. These are emitted into alignment bytes in the type stream.
228
229CV_TYPE(LF_PAD0, 0xf0)
230CV_TYPE(LF_PAD1, 0xf1)
231CV_TYPE(LF_PAD2, 0xf2)
232CV_TYPE(LF_PAD3, 0xf3)
233CV_TYPE(LF_PAD4, 0xf4)
234CV_TYPE(LF_PAD5, 0xf5)
235CV_TYPE(LF_PAD6, 0xf6)
236CV_TYPE(LF_PAD7, 0xf7)
237CV_TYPE(LF_PAD8, 0xf8)
238CV_TYPE(LF_PAD9, 0xf9)
239CV_TYPE(LF_PAD10, 0xfa)
240CV_TYPE(LF_PAD11, 0xfb)
241CV_TYPE(LF_PAD12, 0xfc)
242CV_TYPE(LF_PAD13, 0xfd)
243CV_TYPE(LF_PAD14, 0xfe)
244CV_TYPE(LF_PAD15, 0xff)
245
246#undef CV_TYPE
247#undef TYPE_RECORD
248#undef TYPE_RECORD_ALIAS
249#undef MEMBER_RECORD
250#undef MEMBER_RECORD_ALIAS