Files
swift-mirror/include/swift/AST/ExprNodes.def
Devin Coughlin b727b6d932 Treat potentially unavailable global variable references as optional.
This patch adds the ability (-enable-experimental-unavailable-as-optional) to
treat potentially unavailable declarations as if they had optional types. For
the moment, this is only implemented for global variables.

The high-level approach is to (1) record the potential unavailability of a
declaration reference in the overload choice during constraint generation; (2)
treat the declaration as if it had an optional type during overload resolution
(this is similar to how optional protocol members are treated); and (3) add an
implicit conversion (UnavailableToOptionalExpr) during constraint application
to represent the run-time availability check and optional injection.

This patch does not implement SILGen for UnavailableToOptionalExpr.


Swift SVN r22245
2014-09-24 00:07:46 +00:00

162 lines
5.9 KiB
C++

//===--- ExprNodes.def - Swift Expression AST Metaprogramming ---*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This file defines macros used for macro-metaprogramming with expressions.
//
//===----------------------------------------------------------------------===//
/// EXPR(Id, Parent)
/// If the expression node is not abstract, its enumerator value is
/// ExprKind::Id. The node's class name is Id##Expr, and the name of
/// its base class (in the Expr hierarchy) is Parent.
#ifndef EXPR
#define EXPR(Id, Parent)
#endif
/// An abstract expression node is an abstract base class in the hierarchy;
/// it is never a most-derived type, and it does not have an enumerator in
/// ExprKind.
///
/// Most metaprograms do not care about abstract expressions, so the default
/// is to ignore them.
#ifndef ABSTRACT_EXPR
#define ABSTRACT_EXPR(Id, Parent)
#endif
/// An "unchecked" expression node is removed from valid code by the end
/// of the type-checking phase.
///
/// By default, these are treated like any other expression.
#ifndef UNCHECKED_EXPR
#define UNCHECKED_EXPR(Id, Parent) EXPR(Id, Parent)
#endif
/// A convenience for determining the range of expressions. These will always
/// appear immediately after the last member.
#ifndef EXPR_RANGE
#define EXPR_RANGE(Id, First, Last)
#endif
EXPR(Error, Expr)
ABSTRACT_EXPR(Literal, Expr)
EXPR(NilLiteral, LiteralExpr)
EXPR(IntegerLiteral, LiteralExpr)
EXPR(FloatLiteral, LiteralExpr)
EXPR(BooleanLiteral, LiteralExpr)
EXPR(CharacterLiteral, LiteralExpr)
EXPR(StringLiteral, LiteralExpr)
EXPR(InterpolatedStringLiteral, LiteralExpr)
EXPR(MagicIdentifierLiteral, LiteralExpr)
EXPR_RANGE(Literal, NilLiteral, MagicIdentifierLiteral)
EXPR(DiscardAssignment, Expr)
EXPR(DeclRef, Expr)
EXPR(SuperRef, Expr)
EXPR(Type, Expr)
EXPR(OtherConstructorDeclRef, Expr)
UNCHECKED_EXPR(UnresolvedConstructor, Expr)
EXPR(DotSyntaxBaseIgnored, Expr)
ABSTRACT_EXPR(OverloadSetRef, Expr)
UNCHECKED_EXPR(OverloadedDeclRef, OverloadSetRefExpr)
UNCHECKED_EXPR(OverloadedMemberRef, OverloadSetRefExpr)
EXPR_RANGE(OverloadSetRef, OverloadedDeclRef, OverloadedMemberRef)
UNCHECKED_EXPR(UnresolvedDeclRef, Expr)
EXPR(MemberRef, Expr)
ABSTRACT_EXPR(DynamicLookup, Expr)
EXPR(DynamicMemberRef, DynamicLookupExpr)
EXPR(DynamicSubscript, DynamicLookupExpr)
EXPR_RANGE(DynamicLookup, DynamicMemberRef, DynamicSubscript)
UNCHECKED_EXPR(UnresolvedSpecialize, Expr)
UNCHECKED_EXPR(UnresolvedMember, Expr)
UNCHECKED_EXPR(UnresolvedDot, Expr)
UNCHECKED_EXPR(UnresolvedSelector, Expr)
UNCHECKED_EXPR(Sequence, Expr)
ABSTRACT_EXPR(Identity, Expr)
EXPR(Paren, IdentityExpr)
EXPR(DotSelf, IdentityExpr)
EXPR_RANGE(Identity, Paren, DotSelf)
EXPR(Tuple, Expr)
ABSTRACT_EXPR(Collection, Expr)
EXPR(Array, CollectionExpr)
EXPR(Dictionary, CollectionExpr)
EXPR_RANGE(Collection, Array, Dictionary)
EXPR(Subscript, Expr)
EXPR(TupleElement, Expr)
ABSTRACT_EXPR(AbstractClosure, Expr)
EXPR(Closure, AbstractClosureExpr)
EXPR(AutoClosure, AbstractClosureExpr)
EXPR_RANGE(AbstractClosure, Closure, AutoClosure)
EXPR(Module, Expr)
EXPR(InOut, Expr)
EXPR(DynamicType, Expr)
EXPR(RebindSelfInConstructor, Expr)
EXPR(OpaqueValue, Expr)
EXPR(BindOptional, Expr)
EXPR(OptionalEvaluation, Expr)
EXPR(ForceValue, Expr)
EXPR(OpenExistential, Expr)
ABSTRACT_EXPR(Apply, Expr)
EXPR(Call, ApplyExpr)
EXPR(PrefixUnary, ApplyExpr)
EXPR(PostfixUnary, ApplyExpr)
EXPR(Binary, ApplyExpr)
ABSTRACT_EXPR(SelfApply, ApplyExpr)
EXPR(DotSyntaxCall, SelfApplyExpr)
EXPR(ConstructorRefCall, SelfApplyExpr)
EXPR_RANGE(SelfApply, DotSyntaxCall, ConstructorRefCall)
EXPR_RANGE(Apply, Call, ConstructorRefCall)
ABSTRACT_EXPR(ImplicitConversion, Expr)
EXPR(Load, ImplicitConversionExpr)
EXPR(TupleShuffle, ImplicitConversionExpr)
EXPR(FunctionConversion, ImplicitConversionExpr)
EXPR(CovariantFunctionConversion, ImplicitConversionExpr)
EXPR(CovariantReturnConversion, ImplicitConversionExpr)
EXPR(MetatypeConversion, ImplicitConversionExpr)
EXPR(CollectionUpcastConversion, ImplicitConversionExpr)
ABSTRACT_EXPR(AnyErasure, ImplicitConversionExpr)
EXPR(Erasure, AnyErasureExpr)
EXPR(MetatypeErasure, AnyErasureExpr)
EXPR_RANGE(AnyErasure, Erasure, MetatypeErasure)
EXPR(DerivedToBase, ImplicitConversionExpr)
EXPR(ArchetypeToSuper, ImplicitConversionExpr)
EXPR(ScalarToTuple, ImplicitConversionExpr)
EXPR(InjectIntoOptional, ImplicitConversionExpr)
EXPR(UnavailableToOptional, ImplicitConversionExpr)
EXPR(ClassMetatypeToObject, ImplicitConversionExpr)
EXPR(ExistentialMetatypeToObject, ImplicitConversionExpr)
EXPR(ProtocolMetatypeToObject, ImplicitConversionExpr)
EXPR(InOutToPointer, ImplicitConversionExpr)
EXPR(ArrayToPointer, ImplicitConversionExpr)
EXPR(StringToPointer, ImplicitConversionExpr)
EXPR(PointerToPointer, ImplicitConversionExpr)
EXPR(LValueToPointer, ImplicitConversionExpr)
EXPR(ForeignObjectConversion, ImplicitConversionExpr)
EXPR_RANGE(ImplicitConversion, Load, ForeignObjectConversion)
ABSTRACT_EXPR(ExplicitCast, Expr)
ABSTRACT_EXPR(CheckedCast, ExplicitCastExpr)
UNCHECKED_EXPR(UnresolvedCheckedCast, CheckedCastExpr)
EXPR(ForcedCheckedCast, CheckedCastExpr)
EXPR(ConditionalCheckedCast, CheckedCastExpr)
EXPR(Isa, CheckedCastExpr)
EXPR_RANGE(CheckedCast, UnresolvedCheckedCast, Isa)
EXPR(Coerce, ExplicitCastExpr)
EXPR_RANGE(ExplicitCast, UnresolvedCheckedCast, Coerce)
EXPR(If, Expr)
EXPR(Assign, Expr)
EXPR(DefaultValue, Expr)
UNCHECKED_EXPR(UnresolvedPattern, Expr)
EXPR(AvailabilityQuery, Expr)
#undef EXPR_RANGE
#undef UNCHECKED_EXPR
#undef ABSTRACT_EXPR
#undef EXPR