From 29099ded0c1546dac891cf5510fd611a1d1992a5 Mon Sep 17 00:00:00 2001 From: Erik Pilkington Date: Sat, 16 Jul 2016 00:35:23 +0000 Subject: [ObjC] Implement @available in the Parser and AST This patch adds a new AST node: ObjCAvailabilityCheckExpr, and teaches the Parser and Sema to generate it. This node represents an availability check of the form: @available(macos 10.10, *); Which will eventually compile to a runtime check of the host's OS version. This is the first patch of the feature I proposed here: http://lists.llvm.org/pipermail/cfe-dev/2016-July/049851.html Differential Revision: https://reviews.llvm.org/D22171 llvm-svn: 275654 --- clang/lib/Sema/SemaExpr.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'clang/lib/Sema/SemaExpr.cpp') diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 0c8a9136948..57159fb5971 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -15083,3 +15083,27 @@ Sema::ActOnObjCBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind) { return new (Context) ObjCBoolLiteralExpr(Kind == tok::kw___objc_yes, BoolT, OpLoc); } + +ExprResult Sema::ActOnObjCAvailabilityCheckExpr( + llvm::ArrayRef AvailSpecs, SourceLocation AtLoc, + SourceLocation RParen) { + + StringRef Platform = getASTContext().getTargetInfo().getPlatformName(); + + auto Spec = std::find_if(AvailSpecs.begin(), AvailSpecs.end(), + [&](const AvailabilitySpec &Spec) { + return Spec.getPlatform() == Platform; + }); + + VersionTuple Version; + if (Spec != AvailSpecs.end()) + Version = Spec->getVersion(); + else + // This is the '*' case in @available. We should diagnose this; the + // programmer should explicitly account for this case if they target this + // platform. + Diag(AtLoc, diag::warn_available_using_star_case) << RParen << Platform; + + return new (Context) + ObjCAvailabilityCheckExpr(Version, AtLoc, RParen, Context.BoolTy); +} -- cgit v1.2.3