mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +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()); }
|
||||
|
||||
@@ -69,6 +69,13 @@ foo bar
|
||||
let _: Int = 1
|
||||
#endif
|
||||
|
||||
#if !compiler(>=4.1)
|
||||
// There should be no error here.
|
||||
foo bar
|
||||
#else
|
||||
let _: Int = 1
|
||||
#endif
|
||||
|
||||
#if (swift(>=2.2))
|
||||
let _: Int = 1
|
||||
#else
|
||||
@@ -76,6 +83,13 @@ let _: Int = 1
|
||||
foo bar
|
||||
#endif
|
||||
|
||||
#if (compiler(>=4.1))
|
||||
let _: Int = 1
|
||||
#else
|
||||
// There should be no error here.
|
||||
foo bar
|
||||
#endif
|
||||
|
||||
#if swift(>=99.0) || swift(>=88.1.1)
|
||||
// There should be no error here.
|
||||
foo bar baz // expected-error 2 {{consecutive statements}}
|
||||
@@ -83,12 +97,25 @@ foo bar baz // expected-error 2 {{consecutive statements}}
|
||||
undefinedElse() // expected-error {{use of unresolved identifier 'undefinedElse'}}
|
||||
#endif
|
||||
|
||||
#if compiler(>=99.0) || compiler(>=88.1.1)
|
||||
// There should be no error here.
|
||||
foo bar baz // expected-error 2 {{consecutive statements}}
|
||||
#else
|
||||
undefinedElse() // expected-error {{use of unresolved identifier 'undefinedElse'}}
|
||||
#endif
|
||||
|
||||
#if swift(>=99.0) || FOO
|
||||
undefinedIf() // expected-error {{use of unresolved identifier 'undefinedIf'}}
|
||||
#else
|
||||
undefinedElse()
|
||||
#endif
|
||||
|
||||
#if compiler(>=99.0) || FOO
|
||||
undefinedIf() // expected-error {{use of unresolved identifier 'undefinedIf'}}
|
||||
#else
|
||||
undefinedElse()
|
||||
#endif
|
||||
|
||||
#if swift(>=99.0) && FOO
|
||||
// There should be no error here.
|
||||
foo bar baz // expected-error 2 {{consecutive statements}}
|
||||
@@ -96,6 +123,13 @@ foo bar baz // expected-error 2 {{consecutive statements}}
|
||||
undefinedElse() // expected-error {{use of unresolved identifier 'undefinedElse'}}
|
||||
#endif
|
||||
|
||||
#if compiler(>=99.0) && FOO
|
||||
// There should be no error here.
|
||||
foo bar baz // expected-error 2 {{consecutive statements}}
|
||||
#else
|
||||
undefinedElse() // expected-error {{use of unresolved identifier 'undefinedElse'}}
|
||||
#endif
|
||||
|
||||
#if FOO && swift(>=2.2)
|
||||
undefinedIf() // expected-error {{use of unresolved identifier 'undefinedIf'}}
|
||||
#else
|
||||
@@ -103,6 +137,13 @@ undefinedIf() // expected-error {{use of unresolved identifier 'undefinedIf'}}
|
||||
foo bar baz // expected-error 2 {{consecutive statements}}
|
||||
#endif
|
||||
|
||||
#if FOO && compiler(>=4.0)
|
||||
undefinedIf() // expected-error {{use of unresolved identifier 'undefinedIf'}}
|
||||
#else
|
||||
// There should be no error here.
|
||||
foo bar baz // expected-error 2 {{consecutive statements}}
|
||||
#endif
|
||||
|
||||
#if swift(>=2.2) && swift(>=1)
|
||||
undefinedIf() // expected-error {{use of unresolved identifier 'undefinedIf'}}
|
||||
#else
|
||||
@@ -110,6 +151,13 @@ undefinedIf() // expected-error {{use of unresolved identifier 'undefinedIf'}}
|
||||
foo bar baz // expected-error 2 {{consecutive statements}}
|
||||
#endif
|
||||
|
||||
#if compiler(>=4.1) && compiler(>=4)
|
||||
undefinedIf() // expected-error {{use of unresolved identifier 'undefinedIf'}}
|
||||
#else
|
||||
// There should be no error here.
|
||||
foo bar baz // expected-error 2 {{consecutive statements}}
|
||||
#endif
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// SR-4031: Compound name in compilation condition
|
||||
// See test/Parse/ConditionalCompilation/compoundName_swift4.swift for Swfit 4 behavior
|
||||
Reference in New Issue
Block a user