ArchiveYAML.cpp 2.0 KB

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