File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 24
24
#include " llvm/ADT/Optional.h"
25
25
#include " llvm/ADT/SmallVector.h"
26
26
#include " llvm/ADT/StringRef.h"
27
+ #include " clang/Basic/VersionTuple.h"
27
28
#include < string>
28
29
29
30
namespace swift {
@@ -89,6 +90,10 @@ class Version {
89
90
return Components.empty ();
90
91
}
91
92
93
+ // / Convert to a (maximum-4-element) clang::VersionTuple, truncating
94
+ // / away any 5th component that might be in this version.
95
+ operator clang::VersionTuple () const ;
96
+
92
97
// / Return whether this version is a valid Swift language version number
93
98
// / to set the compiler to using -swift-version; this is not the same as
94
99
// / the set of Swift versions that have ever existed, just those that we
Original file line number Diff line number Diff line change @@ -285,6 +285,31 @@ Version::preprocessorDefinition(StringRef macroName,
285
285
return define;
286
286
}
287
287
288
+ Version::operator clang::VersionTuple () const
289
+ {
290
+ switch (Components.size ()) {
291
+ case 0 :
292
+ return clang::VersionTuple ();
293
+ case 1 :
294
+ return clang::VersionTuple ((unsigned )Components[0 ]);
295
+ case 2 :
296
+ return clang::VersionTuple ((unsigned )Components[0 ],
297
+ (unsigned )Components[1 ]);
298
+ case 3 :
299
+ return clang::VersionTuple ((unsigned )Components[0 ],
300
+ (unsigned )Components[1 ],
301
+ (unsigned )Components[2 ]);
302
+ case 4 :
303
+ case 5 :
304
+ return clang::VersionTuple ((unsigned )Components[0 ],
305
+ (unsigned )Components[1 ],
306
+ (unsigned )Components[2 ],
307
+ (unsigned )Components[3 ]);
308
+ default :
309
+ llvm_unreachable (" swift::version::Version with 6 or more components" );
310
+ }
311
+ }
312
+
288
313
bool
289
314
Version::isValidEffectiveLanguageVersion () const
290
315
{
You can’t perform that action at this time.
0 commit comments