Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 1 | //===- ArchiveYAML.h - Archive YAMLIO implementation ------------*- 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 | /// \file |
| 10 | /// This file declares classes for handling the YAML representation of archives. |
| 11 | /// |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LLVM_OBJECTYAML_ARCHIVEYAML_H |
| 15 | #define LLVM_OBJECTYAML_ARCHIVEYAML_H |
| 16 | |
| 17 | #include "llvm/Support/YAMLTraits.h" |
| 18 | #include "llvm/ObjectYAML/YAML.h" |
| 19 | #include "llvm/ADT/MapVector.h" |
| 20 | |
| 21 | namespace llvm { |
| 22 | namespace ArchYAML { |
| 23 | |
| 24 | struct Archive { |
| 25 | struct Child { |
| 26 | struct Field { |
| 27 | Field() = default; |
| 28 | Field(StringRef Default, unsigned Length) |
| 29 | : DefaultValue(Default), MaxLength(Length) {} |
| 30 | StringRef Value; |
| 31 | StringRef DefaultValue; |
| 32 | unsigned MaxLength; |
| 33 | }; |
| 34 | |
| 35 | Child() { |
| 36 | Fields["Name"] = {"", 16}; |
| 37 | Fields["LastModified"] = {"0", 12}; |
| 38 | Fields["UID"] = {"0", 6}; |
| 39 | Fields["GID"] = {"0", 6}; |
| 40 | Fields["AccessMode"] = {"0", 8}; |
| 41 | Fields["Size"] = {"0", 10}; |
| 42 | Fields["Terminator"] = {"`\n", 2}; |
| 43 | } |
| 44 | |
| 45 | MapVector<StringRef, Field> Fields; |
| 46 | |
| 47 | Optional<yaml::BinaryRef> Content; |
| 48 | Optional<llvm::yaml::Hex8> PaddingByte; |
| 49 | }; |
| 50 | |
| 51 | StringRef Magic; |
| 52 | Optional<std::vector<Child>> Members; |
| 53 | Optional<yaml::BinaryRef> Content; |
| 54 | }; |
| 55 | |
| 56 | } // end namespace ArchYAML |
| 57 | } // end namespace llvm |
| 58 | |
| 59 | LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ArchYAML::Archive::Child) |
| 60 | |
| 61 | namespace llvm { |
| 62 | namespace yaml { |
| 63 | |
| 64 | template <> struct MappingTraits<ArchYAML::Archive> { |
| 65 | static void mapping(IO &IO, ArchYAML::Archive &A); |
| 66 | static std::string validate(IO &, ArchYAML::Archive &A); |
| 67 | }; |
| 68 | |
| 69 | template <> struct MappingTraits<ArchYAML::Archive::Child> { |
| 70 | static void mapping(IO &IO, ArchYAML::Archive::Child &C); |
| 71 | static std::string validate(IO &, ArchYAML::Archive::Child &C); |
| 72 | }; |
| 73 | |
| 74 | } // end namespace yaml |
| 75 | } // end namespace llvm |
| 76 | |
| 77 | #endif // LLVM_OBJECTYAML_ARCHIVEYAML_H |