Coverage Report

Created: 2024-01-17 10:31

/src/llvm-project/llvm/lib/ObjectYAML/ArchiveYAML.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- ArchiveYAML.cpp - ELF YAMLIO 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 archives.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "llvm/ObjectYAML/ArchiveYAML.h"
14
15
namespace llvm {
16
17
namespace yaml {
18
19
0
void MappingTraits<ArchYAML::Archive>::mapping(IO &IO, ArchYAML::Archive &A) {
20
0
  assert(!IO.getContext() && "The IO context is initialized already");
21
0
  IO.setContext(&A);
22
0
  IO.mapTag("!Arch", true);
23
0
  IO.mapOptional("Magic", A.Magic, "!<arch>\n");
24
0
  IO.mapOptional("Members", A.Members);
25
0
  IO.mapOptional("Content", A.Content);
26
0
  IO.setContext(nullptr);
27
0
}
28
29
std::string MappingTraits<ArchYAML::Archive>::validate(IO &,
30
0
                                                       ArchYAML::Archive &A) {
31
0
  if (A.Members && A.Content)
32
0
    return "\"Content\" and \"Members\" cannot be used together";
33
0
  return "";
34
0
}
35
36
void MappingTraits<ArchYAML::Archive::Child>::mapping(
37
0
    IO &IO, ArchYAML::Archive::Child &E) {
38
0
  assert(IO.getContext() && "The IO context is not initialized");
39
0
  for (auto &P : E.Fields)
40
0
    IO.mapOptional(P.first.data(), P.second.Value, P.second.DefaultValue);
41
0
  IO.mapOptional("Content", E.Content);
42
0
  IO.mapOptional("PaddingByte", E.PaddingByte);
43
0
}
44
45
std::string
46
MappingTraits<ArchYAML::Archive::Child>::validate(IO &,
47
0
                                                  ArchYAML::Archive::Child &C) {
48
0
  for (auto &P : C.Fields)
49
0
    if (P.second.Value.size() > P.second.MaxLength)
50
0
      return ("the maximum length of \"" + P.first + "\" field is " +
51
0
              Twine(P.second.MaxLength))
52
0
          .str();
53
0
  return "";
54
0
}
55
56
} // end namespace yaml
57
58
} // end namespace llvm