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
<PlatformKind
>::output(const PlatformKind
&Value
, void *,
48 llvm_unreachable("unexpected platform");
50 case PlatformKind::macOS
:
53 case PlatformKind::iOS
:
56 case PlatformKind::watchOS
:
59 case PlatformKind::tvOS
:
62 case PlatformKind::bridgeOS
:
67 StringRef ScalarTraits
<PlatformKind
>::input(StringRef Scalar
, void *,
68 PlatformKind
&Value
) {
69 Value
= StringSwitch
<PlatformKind
>(Scalar
)
70 .Case("macosx", PlatformKind::macOS
)
71 .Case("ios", PlatformKind::iOS
)
72 .Case("watchos", PlatformKind::watchOS
)
73 .Case("tvos", PlatformKind::tvOS
)
74 .Case("bridgeos", PlatformKind::bridgeOS
)
75 .Default(PlatformKind::unknown
);
77 if (Value
== PlatformKind::unknown
)
78 return "unknown platform";
81 QuotingType ScalarTraits
<PlatformKind
>::mustQuote(StringRef
) {
82 return QuotingType::None
;
85 void ScalarBitSetTraits
<ArchitectureSet
>::bitset(IO
&IO
,
86 ArchitectureSet
&Archs
) {
87 #define ARCHINFO(arch, type, subtype) \
88 IO.bitSetCase(Archs, #arch, 1U << static_cast<int>(Architecture::arch));
89 #include "llvm/TextAPI/MachO/Architecture.def"
93 void ScalarTraits
<Architecture
>::output(const Architecture
&Value
, void *,
97 StringRef ScalarTraits
<Architecture
>::input(StringRef Scalar
, void *,
98 Architecture
&Value
) {
99 Value
= getArchitectureFromName(Scalar
);
102 QuotingType ScalarTraits
<Architecture
>::mustQuote(StringRef
) {
103 return QuotingType::None
;
106 void ScalarTraits
<PackedVersion
>::output(const PackedVersion
&Value
, void *,
110 StringRef ScalarTraits
<PackedVersion
>::input(StringRef Scalar
, void *,
111 PackedVersion
&Value
) {
112 if (!Value
.parse32(Scalar
))
113 return "invalid packed version string.";
116 QuotingType ScalarTraits
<PackedVersion
>::mustQuote(StringRef
) {
117 return QuotingType::None
;
120 void ScalarTraits
<SwiftVersion
>::output(const SwiftVersion
&Value
, void *,
136 OS
<< (unsigned)Value
;
140 StringRef ScalarTraits
<SwiftVersion
>::input(StringRef Scalar
, void *,
141 SwiftVersion
&Value
) {
142 Value
= StringSwitch
<SwiftVersion
>(Scalar
)
148 if (Value
!= SwiftVersion(0))
151 if (Scalar
.getAsInteger(10, Value
))
152 return "invalid Swift ABI version.";
156 QuotingType ScalarTraits
<SwiftVersion
>::mustQuote(StringRef
) {
157 return QuotingType::None
;
160 void ScalarTraits
<UUID
>::output(const UUID
&Value
, void *, raw_ostream
&OS
) {
161 OS
<< Value
.first
<< ": " << Value
.second
;
163 StringRef ScalarTraits
<UUID
>::input(StringRef Scalar
, void *, UUID
&Value
) {
164 auto Split
= Scalar
.split(':');
165 auto Arch
= Split
.first
.trim();
166 auto UUID
= Split
.second
.trim();
168 return "invalid uuid string pair";
169 Value
.first
= getArchitectureFromName(Arch
);
173 QuotingType ScalarTraits
<UUID
>::mustQuote(StringRef
) {
174 return QuotingType::Single
;
177 } // end namespace yaml.
178 } // end namespace llvm.