1 //===- TextStubCommon.cpp -------------------------------------------------===//
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 // Implememts common Text Stub YAML mappings.
11 //===----------------------------------------------------------------------===//
13 #include "TextStubCommon.h"
14 #include "TextAPIContext.h"
16 using namespace llvm::MachO
;
21 void ScalarTraits
<FlowStringRef
>::output(const FlowStringRef
&Value
, void *Ctx
,
23 ScalarTraits
<StringRef
>::output(Value
, Ctx
, OS
);
25 StringRef ScalarTraits
<FlowStringRef
>::input(StringRef Value
, void *Ctx
,
27 return ScalarTraits
<StringRef
>::input(Value
, Ctx
, Out
.value
);
29 QuotingType ScalarTraits
<FlowStringRef
>::mustQuote(StringRef Name
) {
30 return ScalarTraits
<StringRef
>::mustQuote(Name
);
33 void ScalarEnumerationTraits
<ObjCConstraintType
>::enumeration(
34 IO
&IO
, ObjCConstraintType
&Constraint
) {
35 IO
.enumCase(Constraint
, "none", ObjCConstraintType::None
);
36 IO
.enumCase(Constraint
, "retain_release", ObjCConstraintType::Retain_Release
);
37 IO
.enumCase(Constraint
, "retain_release_for_simulator",
38 ObjCConstraintType::Retain_Release_For_Simulator
);
39 IO
.enumCase(Constraint
, "retain_release_or_gc",
40 ObjCConstraintType::Retain_Release_Or_GC
);
41 IO
.enumCase(Constraint
, "gc", ObjCConstraintType::GC
);
44 void ScalarTraits
<PlatformSet
>::output(const PlatformSet
&Values
, void *IO
,
47 const auto *Ctx
= reinterpret_cast<TextAPIContext
*>(IO
);
48 assert((!Ctx
|| Ctx
->FileKind
!= FileType::Invalid
) &&
49 "File type is not set in context");
51 if (Ctx
&& Ctx
->FileKind
== TBD_V3
&& Values
.count(PlatformKind::macOS
) &&
52 Values
.count(PlatformKind::macCatalyst
)) {
57 assert(Values
.size() == 1U);
58 switch (*Values
.begin()) {
60 llvm_unreachable("unexpected platform");
62 case PlatformKind::macOS
:
65 case PlatformKind::iOS
:
68 case PlatformKind::watchOS
:
71 case PlatformKind::tvOS
:
74 case PlatformKind::bridgeOS
:
80 StringRef ScalarTraits
<PlatformSet
>::input(StringRef Scalar
, void *IO
,
81 PlatformSet
&Values
) {
82 const auto *Ctx
= reinterpret_cast<TextAPIContext
*>(IO
);
83 assert((!Ctx
|| Ctx
->FileKind
!= FileType::Invalid
) &&
84 "File type is not set in context");
86 if (Scalar
== "zippered") {
87 if (Ctx
&& Ctx
->FileKind
== FileType::TBD_V3
) {
88 Values
.insert(PlatformKind::macOS
);
89 Values
.insert(PlatformKind::macCatalyst
);
92 return "invalid platform";
95 auto Platform
= StringSwitch
<PlatformKind
>(Scalar
)
96 .Case("unknown", PlatformKind::unknown
)
97 .Case("macosx", PlatformKind::macOS
)
98 .Case("ios", PlatformKind::iOS
)
99 .Case("watchos", PlatformKind::watchOS
)
100 .Case("tvos", PlatformKind::tvOS
)
101 .Case("bridgeos", PlatformKind::bridgeOS
)
102 .Case("iosmac", PlatformKind::macCatalyst
)
103 .Default(PlatformKind::unknown
);
105 if (Platform
== PlatformKind::macCatalyst
)
106 if (Ctx
&& Ctx
->FileKind
!= FileType::TBD_V3
)
107 return "invalid platform";
109 if (Platform
== PlatformKind::unknown
)
110 return "unknown platform";
112 Values
.insert(Platform
);
116 QuotingType ScalarTraits
<PlatformSet
>::mustQuote(StringRef
) {
117 return QuotingType::None
;
120 void ScalarBitSetTraits
<ArchitectureSet
>::bitset(IO
&IO
,
121 ArchitectureSet
&Archs
) {
122 #define ARCHINFO(arch, type, subtype) \
123 IO.bitSetCase(Archs, #arch, 1U << static_cast<int>(AK_##arch));
124 #include "llvm/TextAPI/MachO/Architecture.def"
128 void ScalarTraits
<Architecture
>::output(const Architecture
&Value
, void *,
132 StringRef ScalarTraits
<Architecture
>::input(StringRef Scalar
, void *,
133 Architecture
&Value
) {
134 Value
= getArchitectureFromName(Scalar
);
137 QuotingType ScalarTraits
<Architecture
>::mustQuote(StringRef
) {
138 return QuotingType::None
;
141 void ScalarTraits
<PackedVersion
>::output(const PackedVersion
&Value
, void *,
145 StringRef ScalarTraits
<PackedVersion
>::input(StringRef Scalar
, void *,
146 PackedVersion
&Value
) {
147 if (!Value
.parse32(Scalar
))
148 return "invalid packed version string.";
151 QuotingType ScalarTraits
<PackedVersion
>::mustQuote(StringRef
) {
152 return QuotingType::None
;
155 void ScalarTraits
<SwiftVersion
>::output(const SwiftVersion
&Value
, void *,
171 OS
<< (unsigned)Value
;
175 StringRef ScalarTraits
<SwiftVersion
>::input(StringRef Scalar
, void *IO
,
176 SwiftVersion
&Value
) {
177 const auto *Ctx
= reinterpret_cast<TextAPIContext
*>(IO
);
178 assert((!Ctx
|| Ctx
->FileKind
!= FileType::Invalid
) &&
179 "File type is not set in context");
181 if (Ctx
->FileKind
== FileType::TBD_V4
) {
182 if (Scalar
.getAsInteger(10, Value
))
183 return "invalid Swift ABI version.";
186 Value
= StringSwitch
<SwiftVersion
>(Scalar
)
194 if (Value
!= SwiftVersion(0))
197 if (Scalar
.getAsInteger(10, Value
))
198 return "invalid Swift ABI version.";
202 QuotingType ScalarTraits
<SwiftVersion
>::mustQuote(StringRef
) {
203 return QuotingType::None
;
206 void ScalarTraits
<UUID
>::output(const UUID
&Value
, void *, raw_ostream
&OS
) {
207 OS
<< Value
.first
<< ": " << Value
.second
;
209 StringRef ScalarTraits
<UUID
>::input(StringRef Scalar
, void *, UUID
&Value
) {
210 auto Split
= Scalar
.split(':');
211 auto Arch
= Split
.first
.trim();
212 auto UUID
= Split
.second
.trim();
214 return "invalid uuid string pair";
216 Value
.first
= Target
{getArchitectureFromName(Arch
), PlatformKind::unknown
};
220 QuotingType ScalarTraits
<UUID
>::mustQuote(StringRef
) {
221 return QuotingType::Single
;
224 } // end namespace yaml.
225 } // end namespace llvm.