Skip to content

Commit 2abb931

Browse files
committed
Reuse code between swift and compiler directives
1 parent ff0156c commit 2abb931

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

lib/Parse/ParseIfConfig.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -446,20 +446,18 @@ class EvaluateIfConfigCondition :
446446
Str, SourceLoc(), nullptr).getValue();
447447
auto thisVersion = version::Version::getCurrentCompilerVersion();
448448
return thisVersion >= Val;
449-
} else if (KindName == "swift") {
449+
} else if ((KindName == "swift") || (KindName == "compiler")) {
450450
auto PUE = cast<PrefixUnaryExpr>(Arg);
451451
auto Str = extractExprSource(Ctx.SourceMgr, PUE->getArg());
452452
auto Val = version::Version::parseVersionString(
453453
Str, SourceLoc(), nullptr).getValue();
454-
auto thisVersion = Ctx.LangOpts.EffectiveLanguageVersion;
455-
return thisVersion >= Val;
456-
} else if (KindName == "compiler") {
457-
auto PUE = cast<PrefixUnaryExpr>(Arg);
458-
auto Str = extractExprSource(Ctx.SourceMgr, PUE->getArg());
459-
auto Val = version::Version::parseVersionString(
460-
Str, SourceLoc(), nullptr).getValue();
461-
auto thisVersion = version::Version::getCurrentLanguageVersion();
462-
return thisVersion >= Val;
454+
if (KindName == "swift") {
455+
return Ctx.LangOpts.EffectiveLanguageVersion >= Val;
456+
} else if (KindName == "compiler") {
457+
return version::Version::getCurrentLanguageVersion() >= Val;
458+
} else {
459+
llvm_unreachable("unsupported version conditional");
460+
}
463461
} else if (KindName == "canImport") {
464462
auto Str = extractExprSource(Ctx.SourceMgr, Arg);
465463
return Ctx.canImportModule({ Ctx.getIdentifier(Str) , E->getLoc() });

0 commit comments

Comments
 (0)