Bug Summary

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

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -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 -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -mframe-pointer=none -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -ffunction-sections -fdata-sections -fcoverage-compilation-dir=/build/llvm-toolchain-snapshot-14~++20210903100615+fd66b44ec19e/build-llvm/lib/ObjectYAML -resource-dir /usr/lib/llvm-14/lib/clang/14.0.0 -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-14~++20210903100615+fd66b44ec19e/build-llvm/lib/ObjectYAML -I /build/llvm-toolchain-snapshot-14~++20210903100615+fd66b44ec19e/llvm/lib/ObjectYAML -I /build/llvm-toolchain-snapshot-14~++20210903100615+fd66b44ec19e/build-llvm/include -I /build/llvm-toolchain-snapshot-14~++20210903100615+fd66b44ec19e/llvm/include -D NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/x86_64-linux-gnu/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/backward -internal-isystem /usr/lib/llvm-14/lib/clang/14.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/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-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wno-comment -std=c++14 -fdeprecated-macro -fdebug-compilation-dir=/build/llvm-toolchain-snapshot-14~++20210903100615+fd66b44ec19e/build-llvm/lib/ObjectYAML -fdebug-prefix-map=/build/llvm-toolchain-snapshot-14~++20210903100615+fd66b44ec19e=. -ferror-limit 19 -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2021-09-04-040900-46481-1 -x c++ /build/llvm-toolchain-snapshot-14~++20210903100615+fd66b44ec19e/llvm/lib/ObjectYAML/CodeViewYAMLTypes.cpp

/build/llvm-toolchain-snapshot-14~++20210903100615+fd66b44ec19e/llvm/lib/ObjectYAML/CodeViewYAMLTypes.cpp

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

/build/llvm-toolchain-snapshot-14~++20210903100615+fd66b44ec19e/llvm/include/llvm/Support/YAMLTraits.h

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

/build/llvm-toolchain-snapshot-14~++20210903100615+fd66b44ec19e/llvm/include/llvm/DebugInfo/CodeView/CodeViewTypes.def

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