[Sema] Define availability via compiler flag

Introduce availability macros defined by a frontend flag.
This feature makes it possible to set the availability
versions at the moment of compilation instead of having
it hard coded in the sources. It can be used by projects
with a need to change the availability depending on the
compilation context while using the same sources.

The availability macro is defined with the `-define-availability` flag:

swift MyLib.swift -define-availability "_iOS8Aligned:macOS 10.10, iOS 8.0" ..

The macro can be used in code instead of a platform name and version:
@available(_iOS8Aligned, *)
public func foo() {}

rdar://problem/65612624
This commit is contained in:
Alexis Laferrière
2020-07-28 10:58:12 -07:00
parent 327f4f8806
commit c6fc53e844
10 changed files with 379 additions and 16 deletions

View File

@@ -504,6 +504,10 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
}
}
for (const Arg *A : Args.filtered(OPT_define_availability)) {
Opts.AvailabilityMacros.push_back(A->getValue());
}
if (const Arg *A = Args.getLastArg(OPT_value_recursion_threshold)) {
unsigned threshold;
if (StringRef(A->getValue()).getAsInteger(10, threshold)) {