mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Replace _compiler_version with a new directive
This commit is contained in:
@@ -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()); }
|
||||
|
||||
Reference in New Issue
Block a user