Replace _compiler_version with a new directive

This commit is contained in:
David Hart
2018-04-17 15:17:40 +02:00
committed by David Hart
parent cd5acad1b5
commit ff0156c1fa
2 changed files with 59 additions and 2 deletions

View File

@@ -278,7 +278,8 @@ public:
}
// 'swift' '(' '>=' float-literal ( '.' integer-literal )* ')'
if (*KindName == "swift") {
// 'compiler' '(' '>=' float-literal ( '.' integer-literal )* ')'
if (*KindName == "swift" || *KindName == "compiler") {
auto PUE = dyn_cast<PrefixUnaryExpr>(Arg);
llvm::Optional<StringRef> PrefixName = PUE ?
getDeclRefStr(PUE->getFn(), DeclRefKind::PrefixOperator) : None;
@@ -452,6 +453,13 @@ public:
Str, SourceLoc(), nullptr).getValue();
auto thisVersion = Ctx.LangOpts.EffectiveLanguageVersion;
return thisVersion >= Val;
} else if (KindName == "compiler") {
auto PUE = cast<PrefixUnaryExpr>(Arg);
auto Str = extractExprSource(Ctx.SourceMgr, PUE->getArg());
auto Val = version::Version::parseVersionString(
Str, SourceLoc(), nullptr).getValue();
auto thisVersion = version::Version::getCurrentLanguageVersion();
return thisVersion >= Val;
} else if (KindName == "canImport") {
auto Str = extractExprSource(Ctx.SourceMgr, Arg);
return Ctx.canImportModule({ Ctx.getIdentifier(Str) , E->getLoc() });
@@ -539,7 +547,8 @@ public:
bool visitCallExpr(CallExpr *E) {
auto KindName = getDeclRefStr(E->getFn());
return KindName == "_compiler_version" || KindName == "swift";
return KindName == "_compiler_version" || KindName == "swift" ||
KindName == "compiler";
}
bool visitPrefixUnaryExpr(PrefixUnaryExpr *E) { return visit(E->getArg()); }