Skip to content

Commit 9a0598c

Browse files
committed
TBDGen: Use LinkerPlatformId enum type instead of casting to uint8_t.
Increase type safety by consistently using the `LinkerPlatformId` enum type, instead of casting to/from `uint8_t` unnecessarily. NFC.
1 parent 3aea3a0 commit 9a0598c

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

lib/IRGen/TBDGen.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,24 +100,23 @@ getAllMovedPlatformVersions(Decl *D) {
100100
return Results;
101101
}
102102

103-
static StringRef getLinkerPlatformName(uint8_t Id) {
103+
static StringRef getLinkerPlatformName(LinkerPlatformId Id) {
104104
switch (Id) {
105-
#define LD_PLATFORM(Name, Id) case Id: return #Name;
105+
#define LD_PLATFORM(Name, Id) case LinkerPlatformId::Name: return #Name;
106106
#include "ldPlatformKinds.def"
107-
default:
108-
llvm_unreachable("unrecognized platform id");
109107
}
108+
llvm_unreachable("unrecognized platform id");
110109
}
111110

112-
static std::optional<uint8_t> getLinkerPlatformId(StringRef Platform) {
113-
return llvm::StringSwitch<std::optional<uint8_t>>(Platform)
114-
#define LD_PLATFORM(Name, Id) .Case(#Name, Id)
111+
static std::optional<LinkerPlatformId> getLinkerPlatformId(StringRef Platform) {
112+
return llvm::StringSwitch<std::optional<LinkerPlatformId>>(Platform)
113+
#define LD_PLATFORM(Name, Id) .Case(#Name, LinkerPlatformId::Name)
115114
#include "ldPlatformKinds.def"
116115
.Default(std::nullopt);
117116
}
118117

119118
StringRef InstallNameStore::getInstallName(LinkerPlatformId Id) const {
120-
auto It = PlatformInstallName.find((uint8_t)Id);
119+
auto It = PlatformInstallName.find(Id);
121120
if (It == PlatformInstallName.end())
122121
return InstallName;
123122
else
@@ -129,8 +128,9 @@ static std::string getScalaNodeText(Node *N) {
129128
return cast<ScalarNode>(N)->getValue(Buffer).str();
130129
}
131130

132-
static std::set<int8_t> getSequenceNodePlatformList(ASTContext &Ctx, Node *N) {
133-
std::set<int8_t> Results;
131+
static std::set<LinkerPlatformId> getSequenceNodePlatformList(ASTContext &Ctx,
132+
Node *N) {
133+
std::set<LinkerPlatformId> Results;
134134
for (auto &E: *cast<SequenceNode>(N)) {
135135
auto Platform = getScalaNodeText(&E);
136136
auto Id = getLinkerPlatformId(Platform);
@@ -158,7 +158,7 @@ parseEntry(ASTContext &Ctx,
158158
auto *MN = cast<MappingNode>(&*It);
159159
std::string ModuleName;
160160
std::string InstallName;
161-
std::optional<std::set<int8_t>> Platforms;
161+
std::optional<std::set<LinkerPlatformId>> Platforms;
162162
for (auto &Pair: *MN) {
163163
auto Key = getScalaNodeText(Pair.getKey());
164164
auto* Value = Pair.getValue();
@@ -333,7 +333,7 @@ void TBDGenVisitor::addLinkerDirectiveSymbolsLdPrevious(
333333
OS << "$ld$previous$";
334334
OS << InstallName << "$";
335335
OS << ComptibleVersion << "$";
336-
OS << std::to_string((uint8_t)PlatformNumber) << "$";
336+
OS << std::to_string(static_cast<uint8_t>(PlatformNumber)) << "$";
337337
static auto getMinor = [](std::optional<unsigned> Minor) {
338338
return Minor.has_value() ? *Minor : 0;
339339
};

lib/IRGen/TBDGenVisitor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ struct InstallNameStore {
5252
std::string InstallName;
5353
// The install name specific to the platform id. This takes precedence over
5454
// the default install name.
55-
std::map<uint8_t, std::string> PlatformInstallName;
55+
std::map<LinkerPlatformId, std::string> PlatformInstallName;
5656
StringRef getInstallName(LinkerPlatformId Id) const;
5757
};
5858

0 commit comments

Comments
 (0)