@@ -52,6 +52,11 @@ static const StringRef SupportedConditionalCompilationEndianness[] = {
52
52
" big"
53
53
};
54
54
55
+ static const StringRef SupportedConditionalCompilationRuntimes[] = {
56
+ " _ObjC" ,
57
+ " _Native" ,
58
+ };
59
+
55
60
template <size_t N>
56
61
bool contains (const StringRef (&Array)[N], const StringRef &V,
57
62
std::vector<StringRef> &suggestions) {
@@ -75,36 +80,31 @@ bool contains(const StringRef (&Array)[N], const StringRef &V,
75
80
return false ;
76
81
}
77
82
78
- bool LangOptions::checkPlatformConditionOS (
79
- StringRef &OSName, std::vector<StringRef> &suggestions) {
80
- if (OSName == " macOS" )
81
- OSName = " OSX" ;
82
- return contains (SupportedConditionalCompilationOSs,
83
- OSName,
84
- suggestions);
85
- }
86
-
87
- bool
88
- LangOptions::isPlatformConditionArchSupported (
89
- StringRef ArchName, std::vector<StringRef> &suggestions) {
90
- return contains (SupportedConditionalCompilationArches,
91
- ArchName,
92
- suggestions);
93
- }
94
-
95
- bool
96
- LangOptions::isPlatformConditionEndiannessSupported (
97
- StringRef Endianness, std::vector<StringRef> &suggestions) {
98
- return contains (SupportedConditionalCompilationEndianness,
99
- Endianness,
100
- suggestions);
83
+ bool LangOptions::
84
+ checkPlatformConditionSupported (PlatformConditionKind Kind, StringRef Value,
85
+ std::vector<StringRef> &suggestions) {
86
+ switch (Kind) {
87
+ case PlatformConditionKind::OS:
88
+ return contains (SupportedConditionalCompilationOSs, Value,
89
+ suggestions);
90
+ case PlatformConditionKind::Arch:
91
+ return contains (SupportedConditionalCompilationArches, Value,
92
+ suggestions);
93
+ case PlatformConditionKind::Endianness:
94
+ return contains (SupportedConditionalCompilationEndianness, Value,
95
+ suggestions);
96
+ case PlatformConditionKind::Runtime:
97
+ return contains (SupportedConditionalCompilationRuntimes, Value,
98
+ suggestions);
99
+ }
100
+ llvm_unreachable (" Unhandled enum value" );
101
101
}
102
102
103
103
StringRef
104
- LangOptions::getPlatformConditionValue (StringRef Name ) const {
104
+ LangOptions::getPlatformConditionValue (PlatformConditionKind Kind ) const {
105
105
// Last one wins.
106
106
for (auto &Opt : reversed (PlatformConditionValues)) {
107
- if (Opt.first == Name )
107
+ if (Opt.first == Kind )
108
108
return Opt.second ;
109
109
}
110
110
return StringRef ();
@@ -141,23 +141,23 @@ std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) {
141
141
142
142
// Set the "os" platform condition.
143
143
if (Target.isMacOSX ())
144
- addPlatformConditionValue (" os " , " OSX" );
144
+ addPlatformConditionValue (PlatformConditionKind::OS , " OSX" );
145
145
else if (triple.isTvOS ())
146
- addPlatformConditionValue (" os " , " tvOS" );
146
+ addPlatformConditionValue (PlatformConditionKind::OS , " tvOS" );
147
147
else if (triple.isWatchOS ())
148
- addPlatformConditionValue (" os " , " watchOS" );
148
+ addPlatformConditionValue (PlatformConditionKind::OS , " watchOS" );
149
149
else if (triple.isiOS ())
150
- addPlatformConditionValue (" os " , " iOS" );
150
+ addPlatformConditionValue (PlatformConditionKind::OS , " iOS" );
151
151
else if (triple.isAndroid ())
152
- addPlatformConditionValue (" os " , " Android" );
152
+ addPlatformConditionValue (PlatformConditionKind::OS , " Android" );
153
153
else if (triple.isOSLinux ())
154
- addPlatformConditionValue (" os " , " Linux" );
154
+ addPlatformConditionValue (PlatformConditionKind::OS , " Linux" );
155
155
else if (triple.isOSFreeBSD ())
156
- addPlatformConditionValue (" os " , " FreeBSD" );
156
+ addPlatformConditionValue (PlatformConditionKind::OS , " FreeBSD" );
157
157
else if (triple.isOSWindows ())
158
- addPlatformConditionValue (" os " , " Windows" );
158
+ addPlatformConditionValue (PlatformConditionKind::OS , " Windows" );
159
159
else if (triple.isPS4 ())
160
- addPlatformConditionValue (" os " , " PS4" );
160
+ addPlatformConditionValue (PlatformConditionKind::OS , " PS4" );
161
161
else
162
162
UnsupportedOS = true ;
163
163
@@ -167,25 +167,25 @@ std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) {
167
167
switch (Target.getArch ()) {
168
168
case llvm::Triple::ArchType::arm:
169
169
case llvm::Triple::ArchType::thumb:
170
- addPlatformConditionValue (" arch " , " arm" );
170
+ addPlatformConditionValue (PlatformConditionKind::Arch , " arm" );
171
171
break ;
172
172
case llvm::Triple::ArchType::aarch64:
173
- addPlatformConditionValue (" arch " , " arm64" );
173
+ addPlatformConditionValue (PlatformConditionKind::Arch , " arm64" );
174
174
break ;
175
175
case llvm::Triple::ArchType::ppc64:
176
- addPlatformConditionValue (" arch " , " powerpc64" );
176
+ addPlatformConditionValue (PlatformConditionKind::Arch , " powerpc64" );
177
177
break ;
178
178
case llvm::Triple::ArchType::ppc64le:
179
- addPlatformConditionValue (" arch " , " powerpc64le" );
179
+ addPlatformConditionValue (PlatformConditionKind::Arch , " powerpc64le" );
180
180
break ;
181
181
case llvm::Triple::ArchType::x86:
182
- addPlatformConditionValue (" arch " , " i386" );
182
+ addPlatformConditionValue (PlatformConditionKind::Arch , " i386" );
183
183
break ;
184
184
case llvm::Triple::ArchType::x86_64:
185
- addPlatformConditionValue (" arch " , " x86_64" );
185
+ addPlatformConditionValue (PlatformConditionKind::Arch , " x86_64" );
186
186
break ;
187
187
case llvm::Triple::ArchType::systemz:
188
- addPlatformConditionValue (" arch " , " s390x" );
188
+ addPlatformConditionValue (PlatformConditionKind::Arch , " s390x" );
189
189
break ;
190
190
default :
191
191
UnsupportedArch = true ;
@@ -198,35 +198,35 @@ std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) {
198
198
switch (Target.getArch ()) {
199
199
case llvm::Triple::ArchType::arm:
200
200
case llvm::Triple::ArchType::thumb:
201
- addPlatformConditionValue (" _endian " , " little" );
201
+ addPlatformConditionValue (PlatformConditionKind::Endianness , " little" );
202
202
break ;
203
203
case llvm::Triple::ArchType::aarch64:
204
- addPlatformConditionValue (" _endian " , " little" );
204
+ addPlatformConditionValue (PlatformConditionKind::Endianness , " little" );
205
205
break ;
206
206
case llvm::Triple::ArchType::ppc64:
207
- addPlatformConditionValue (" _endian " , " big" );
207
+ addPlatformConditionValue (PlatformConditionKind::Endianness , " big" );
208
208
break ;
209
209
case llvm::Triple::ArchType::ppc64le:
210
- addPlatformConditionValue (" _endian " , " little" );
210
+ addPlatformConditionValue (PlatformConditionKind::Endianness , " little" );
211
211
break ;
212
212
case llvm::Triple::ArchType::x86:
213
- addPlatformConditionValue (" _endian " , " little" );
213
+ addPlatformConditionValue (PlatformConditionKind::Endianness , " little" );
214
214
break ;
215
215
case llvm::Triple::ArchType::x86_64:
216
- addPlatformConditionValue (" _endian " , " little" );
216
+ addPlatformConditionValue (PlatformConditionKind::Endianness , " little" );
217
217
break ;
218
218
case llvm::Triple::ArchType::systemz:
219
- addPlatformConditionValue (" _endian " , " big" );
219
+ addPlatformConditionValue (PlatformConditionKind::Endianness , " big" );
220
220
break ;
221
221
default :
222
222
llvm_unreachable (" undefined architecture endianness" );
223
223
}
224
224
225
225
// Set the "runtime" platform condition.
226
226
if (EnableObjCInterop)
227
- addPlatformConditionValue (" _runtime " , " _ObjC" );
227
+ addPlatformConditionValue (PlatformConditionKind::Runtime , " _ObjC" );
228
228
else
229
- addPlatformConditionValue (" _runtime " , " _Native" );
229
+ addPlatformConditionValue (PlatformConditionKind::Runtime , " _Native" );
230
230
231
231
// If you add anything to this list, change the default size of
232
232
// PlatformConditionValues to not require an extra allocation
0 commit comments