xref: /llvm-project/llvm/lib/TextAPI/TextStubCommon.h (revision 913f21ae5c460d6fdd73ac7663534e73f8e19044)
1 //===- TextStubCommon.h ---------------------------------------------------===//
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 // Defines common Text Stub YAML mappings.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_TEXTAPI_TEXT_STUB_COMMON_H
14 #define LLVM_TEXTAPI_TEXT_STUB_COMMON_H
15 
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/Support/YAMLTraits.h"
18 #include "llvm/TextAPI/Architecture.h"
19 #include "llvm/TextAPI/InterfaceFile.h"
20 #include "llvm/TextAPI/Platform.h"
21 #include "llvm/TextAPI/Target.h"
22 
23 using UUID = std::pair<llvm::MachO::Target, std::string>;
24 
25 // clang-format off
26 enum TBDFlags : unsigned {
27   None                         = 0U,
28   FlatNamespace                = 1U << 0,
29   NotApplicationExtensionSafe  = 1U << 1,
30   InstallAPI                   = 1U << 2,
31   SimulatorSupport             = 1U << 3,
32   LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/SimulatorSupport),
33 };
34 // clang-format on
35 
36 LLVM_YAML_STRONG_TYPEDEF(llvm::StringRef, FlowStringRef)
37 LLVM_YAML_STRONG_TYPEDEF(uint8_t, SwiftVersion)
38 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(UUID)
39 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(FlowStringRef)
40 
41 namespace llvm {
42 
43 namespace MachO {
44 class ArchitectureSet;
45 class PackedVersion;
46 
47 Expected<std::unique_ptr<InterfaceFile>>
48 getInterfaceFileFromJSON(StringRef JSON);
49 
50 Error serializeInterfaceFileToJSON(raw_ostream &OS, const InterfaceFile &File,
51                                    bool Compact);
52 } // namespace MachO
53 
54 namespace yaml {
55 
56 template <> struct ScalarTraits<FlowStringRef> {
57   static void output(const FlowStringRef &, void *, raw_ostream &);
58   static StringRef input(StringRef, void *, FlowStringRef &);
59   static QuotingType mustQuote(StringRef);
60 };
61 
62 template <> struct ScalarEnumerationTraits<MachO::ObjCConstraintType> {
63   static void enumeration(IO &, MachO::ObjCConstraintType &);
64 };
65 
66 template <> struct ScalarTraits<MachO::PlatformSet> {
67   static void output(const MachO::PlatformSet &, void *, raw_ostream &);
68   static StringRef input(StringRef, void *, MachO::PlatformSet &);
69   static QuotingType mustQuote(StringRef);
70 };
71 
72 template <> struct ScalarBitSetTraits<MachO::ArchitectureSet> {
73   static void bitset(IO &, MachO::ArchitectureSet &);
74 };
75 
76 template <> struct ScalarTraits<MachO::Architecture> {
77   static void output(const MachO::Architecture &, void *, raw_ostream &);
78   static StringRef input(StringRef, void *, MachO::Architecture &);
79   static QuotingType mustQuote(StringRef);
80 };
81 
82 template <> struct ScalarTraits<MachO::PackedVersion> {
83   static void output(const MachO::PackedVersion &, void *, raw_ostream &);
84   static StringRef input(StringRef, void *, MachO::PackedVersion &);
85   static QuotingType mustQuote(StringRef);
86 };
87 
88 template <> struct ScalarTraits<SwiftVersion> {
89   static void output(const SwiftVersion &, void *, raw_ostream &);
90   static StringRef input(StringRef, void *, SwiftVersion &);
91   static QuotingType mustQuote(StringRef);
92 };
93 
94 // UUIDs are no longer respected but kept in the YAML parser
95 // to keep reading in older TBDs.
96 template <> struct ScalarTraits<UUID> {
97   static void output(const UUID &, void *, raw_ostream &);
98   static StringRef input(StringRef, void *, UUID &);
99   static QuotingType mustQuote(StringRef);
100 };
101 
102 } // end namespace yaml.
103 } // end namespace llvm.
104 
105 #endif // LLVM_TEXTAPI_TEXT_STUB_COMMON_H
106