1 //===- ArchiveYAML.cpp - ELF YAMLIO implementation -------------------- ----===//
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
7 //===----------------------------------------------------------------------===//
9 // This file defines classes for handling the YAML representation of archives.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/ObjectYAML/ArchiveYAML.h"
19 void MappingTraits
<ArchYAML::Archive
>::mapping(IO
&IO
, ArchYAML::Archive
&A
) {
20 assert(!IO
.getContext() && "The IO context is initialized already");
22 IO
.mapTag("!Arch", true);
23 IO
.mapOptional("Magic", A
.Magic
, "!<arch>\n");
24 IO
.mapOptional("Members", A
.Members
);
25 IO
.mapOptional("Content", A
.Content
);
26 IO
.setContext(nullptr);
29 std::string MappingTraits
<ArchYAML::Archive
>::validate(IO
&,
30 ArchYAML::Archive
&A
) {
31 if (A
.Members
&& A
.Content
)
32 return "\"Content\" and \"Members\" cannot be used together";
36 void MappingTraits
<ArchYAML::Archive::Child
>::mapping(
37 IO
&IO
, ArchYAML::Archive::Child
&E
) {
38 assert(IO
.getContext() && "The IO context is not initialized");
39 for (auto &P
: E
.Fields
)
40 IO
.mapOptional(P
.first
.data(), P
.second
.Value
, P
.second
.DefaultValue
);
41 IO
.mapOptional("Content", E
.Content
);
42 IO
.mapOptional("PaddingByte", E
.PaddingByte
);
46 MappingTraits
<ArchYAML::Archive::Child
>::validate(IO
&,
47 ArchYAML::Archive::Child
&C
) {
48 for (auto &P
: C
.Fields
)
49 if (P
.second
.Value
.size() > P
.second
.MaxLength
)
50 return ("the maximum length of \"" + P
.first
+ "\" field is " +
51 Twine(P
.second
.MaxLength
))
56 } // end namespace yaml
58 } // end namespace llvm