2525#include " swift/AST/ProtocolConformanceRef.h"
2626#include " swift/AST/TrailingCallArguments.h"
2727#include " swift/AST/TypeAlignments.h"
28- #include " swift/AST/TypeLoc.h"
2928#include " swift/AST/Availability.h"
3029#include " swift/Basic/Debug.h"
3130#include " swift/Basic/InlineBitfield.h"
@@ -555,7 +554,7 @@ class alignas(8) Expr {
555554 SWIFT_DEBUG_DUMP;
556555 void dump (raw_ostream &OS, unsigned Indent = 0 ) const ;
557556 void dump (raw_ostream &OS, llvm::function_ref<Type (Expr *)> getType,
558- llvm::function_ref<Type (TypeLoc & )> getTypeOfTypeLoc ,
557+ llvm::function_ref<Type (TypeRepr * )> getTypeOfTypeRepr ,
559558 llvm::function_ref<Type (KeyPathExpr *E, unsigned index)>
560559 getTypeOfKeyPathComponent,
561560 unsigned Indent = 0 ) const ;
@@ -4587,23 +4586,22 @@ class DotSyntaxBaseIgnoredExpr : public Expr {
45874586class ExplicitCastExpr : public Expr {
45884587 Expr *SubExpr;
45894588 SourceLoc AsLoc;
4590- TypeLoc CastTy;
4589+ TypeExpr * const CastTy;
45914590
45924591protected:
4593- ExplicitCastExpr (ExprKind kind, Expr *sub, SourceLoc AsLoc, TypeLoc castTy)
4594- : Expr(kind, /* Implicit=*/ false ), SubExpr(sub), AsLoc(AsLoc), CastTy(castTy)
4595- {}
4592+ ExplicitCastExpr (ExprKind kind, Expr *sub, SourceLoc AsLoc, TypeExpr * castTy)
4593+ : Expr(kind, /* Implicit=*/ false ), SubExpr(sub), AsLoc(AsLoc),
4594+ CastTy (castTy) {}
45964595
45974596public:
45984597 Expr *getSubExpr () const { return SubExpr; }
4599-
4600- // / Get the type syntactically spelled in the cast. For some forms of checked
4601- // / cast this is different from the result type of the expression.
4602- TypeLoc &getCastTypeLoc () { return CastTy; }
46034598
46044599 // / Get the type syntactically spelled in the cast. For some forms of checked
46054600 // / cast this is different from the result type of the expression.
4606- TypeLoc getCastTypeLoc () const { return CastTy; }
4601+ Type getCastType () const { return CastTy->getInstanceType (); }
4602+ void setCastType (Type type);
4603+
4604+ TypeRepr *getCastTypeRepr () const { return CastTy->getTypeRepr (); }
46074605
46084606 void setSubExpr (Expr *E) { SubExpr = E; }
46094607
@@ -4619,7 +4617,7 @@ class ExplicitCastExpr : public Expr {
46194617 }
46204618
46214619 SourceRange getSourceRange () const {
4622- SourceRange castTyRange = CastTy. getSourceRange ();
4620+ const SourceRange castTyRange = CastTy-> getSourceRange ();
46234621 if (castTyRange.isInvalid ())
46244622 return SubExpr->getSourceRange ();
46254623
@@ -4644,14 +4642,13 @@ StringRef getCheckedCastKindName(CheckedCastKind kind);
46444642// / Abstract base class for checked casts 'as' and 'is'. These represent
46454643// / casts that can dynamically fail.
46464644class CheckedCastExpr : public ExplicitCastExpr {
4647- public:
4648- CheckedCastExpr (ExprKind kind,
4649- Expr *sub, SourceLoc asLoc, TypeLoc castTy)
4650- : ExplicitCastExpr(kind, sub, asLoc, castTy)
4651- {
4645+ protected:
4646+ CheckedCastExpr (ExprKind kind, Expr *sub, SourceLoc asLoc, TypeExpr *castTy)
4647+ : ExplicitCastExpr(kind, sub, asLoc, castTy) {
46524648 Bits.CheckedCastExpr .CastKind = unsigned (CheckedCastKind::Unresolved);
46534649 }
4654-
4650+
4651+ public:
46554652 // / Return the semantic kind of cast performed.
46564653 CheckedCastKind getCastKind () const {
46574654 return CheckedCastKind (Bits.CheckedCastExpr .CastKind );
@@ -4675,22 +4672,20 @@ class CheckedCastExpr : public ExplicitCastExpr {
46754672// / from a value of some type to some specified subtype and fails dynamically
46764673// / if the value does not have that type.
46774674// / Spelled 'a as! T' and produces a value of type 'T'.
4678- class ForcedCheckedCastExpr : public CheckedCastExpr {
4675+ class ForcedCheckedCastExpr final : public CheckedCastExpr {
46794676 SourceLoc ExclaimLoc;
46804677
4681- public:
46824678 ForcedCheckedCastExpr (Expr *sub, SourceLoc asLoc, SourceLoc exclaimLoc,
4683- TypeLoc type)
4684- : CheckedCastExpr(ExprKind::ForcedCheckedCast,
4685- sub, asLoc, type),
4686- ExclaimLoc (exclaimLoc)
4687- {
4688- }
4679+ TypeExpr *type)
4680+ : CheckedCastExpr(ExprKind::ForcedCheckedCast, sub, asLoc, type),
4681+ ExclaimLoc (exclaimLoc) {}
46894682
4690- ForcedCheckedCastExpr (SourceLoc asLoc, SourceLoc exclaimLoc, TypeLoc type)
4691- : ForcedCheckedCastExpr(nullptr , asLoc, exclaimLoc, type)
4692- {
4693- }
4683+ public:
4684+ static ForcedCheckedCastExpr *create (ASTContext &ctx, SourceLoc asLoc,
4685+ SourceLoc exclaimLoc, TypeRepr *tyRepr);
4686+
4687+ static ForcedCheckedCastExpr *createImplicit (ASTContext &ctx, Expr *sub,
4688+ Type castTy);
46944689
46954690 // / Retrieve the location of the '!' that follows 'as'.
46964691 SourceLoc getExclaimLoc () const { return ExclaimLoc; }
@@ -4704,21 +4699,24 @@ class ForcedCheckedCastExpr : public CheckedCastExpr {
47044699// / from a type to some subtype and produces an Optional value, which will be
47054700// / .Some(x) if the cast succeeds, or .None if the cast fails.
47064701// / Spelled 'a as? T' and produces a value of type 'T?'.
4707- class ConditionalCheckedCastExpr : public CheckedCastExpr {
4702+ class ConditionalCheckedCastExpr final : public CheckedCastExpr {
47084703 SourceLoc QuestionLoc;
47094704
4710- public:
47114705 ConditionalCheckedCastExpr (Expr *sub, SourceLoc asLoc, SourceLoc questionLoc,
4712- TypeLoc type)
4713- : CheckedCastExpr(ExprKind::ConditionalCheckedCast,
4714- sub, asLoc, type),
4715- QuestionLoc (questionLoc)
4716- { }
4717-
4718- ConditionalCheckedCastExpr (SourceLoc asLoc, SourceLoc questionLoc,
4719- TypeLoc type)
4720- : ConditionalCheckedCastExpr(nullptr , asLoc, questionLoc, type)
4721- {}
4706+ TypeExpr *type)
4707+ : CheckedCastExpr(ExprKind::ConditionalCheckedCast, sub, asLoc, type),
4708+ QuestionLoc (questionLoc) {}
4709+
4710+ public:
4711+ static ConditionalCheckedCastExpr *create (ASTContext &ctx, SourceLoc asLoc,
4712+ SourceLoc questionLoc,
4713+ TypeRepr *tyRepr);
4714+
4715+ static ConditionalCheckedCastExpr *createImplicit (ASTContext &ctx, Expr *sub,
4716+ Type castTy);
4717+
4718+ static ConditionalCheckedCastExpr *
4719+ createImplicit (ASTContext &ctx, Expr *sub, TypeRepr *tyRepr, Type castTy);
47224720
47234721 // / Retrieve the location of the '?' that follows 'as'.
47244722 SourceLoc getQuestionLoc () const { return QuestionLoc; }
@@ -4733,16 +4731,13 @@ class ConditionalCheckedCastExpr : public CheckedCastExpr {
47334731// / of the type and 'a as T' would succeed, false otherwise.
47344732// /
47354733// / FIXME: We should support type queries with a runtime metatype value too.
4736- class IsExpr : public CheckedCastExpr {
4734+ class IsExpr final : public CheckedCastExpr {
4735+ IsExpr (Expr *sub, SourceLoc isLoc, TypeExpr *type)
4736+ : CheckedCastExpr(ExprKind::Is, sub, isLoc, type) {}
4737+
47374738public:
4738- IsExpr (Expr *sub, SourceLoc isLoc, TypeLoc type)
4739- : CheckedCastExpr(ExprKind::Is, sub, isLoc, type)
4740- {}
4741-
4742- IsExpr (SourceLoc isLoc, TypeLoc type)
4743- : IsExpr(nullptr , isLoc, type)
4744- {}
4745-
4739+ static IsExpr *create (ASTContext &ctx, SourceLoc isLoc, TypeRepr *tyRepr);
4740+
47464741 static bool classof (const Expr *E) {
47474742 return E->getKind () == ExprKind::Is;
47484743 }
@@ -4751,35 +4746,29 @@ class IsExpr : public CheckedCastExpr {
47514746// / Represents an explicit coercion from a value to a specific type.
47524747// /
47534748// / Spelled 'a as T' and produces a value of type 'T'.
4754- class CoerceExpr : public ExplicitCastExpr {
4749+ class CoerceExpr final : public ExplicitCastExpr {
47554750 // / Since there is already `asLoc` location,
47564751 // / we use it to store `start` of the initializer
47574752 // / call source range to save some storage.
47584753 SourceLoc InitRangeEnd;
47594754
4760- public:
4761- CoerceExpr (Expr *sub, SourceLoc asLoc, TypeLoc type)
4762- : ExplicitCastExpr(ExprKind::Coerce, sub, asLoc, type)
4763- { }
4755+ CoerceExpr (Expr *sub, SourceLoc asLoc, TypeExpr *type)
4756+ : ExplicitCastExpr(ExprKind::Coerce, sub, asLoc, type) {}
47644757
4765- CoerceExpr (SourceLoc asLoc, TypeLoc type)
4766- : CoerceExpr(nullptr , asLoc, type)
4767- { }
4768-
4769- private:
4770- CoerceExpr (SourceRange initRange, Expr *literal, TypeLoc type)
4771- : ExplicitCastExpr(ExprKind::Coerce, literal, initRange.Start,
4772- type), InitRangeEnd(initRange.End)
4773- { setImplicit (); }
4758+ CoerceExpr (SourceRange initRange, Expr *literal, TypeExpr *type)
4759+ : ExplicitCastExpr(ExprKind::Coerce, literal, initRange.Start, type),
4760+ InitRangeEnd (initRange.End) {}
47744761
47754762public:
4763+ static CoerceExpr *create (ASTContext &ctx, SourceLoc asLoc, TypeRepr *tyRepr);
4764+
4765+ static CoerceExpr *createImplicit (ASTContext &ctx, Expr *sub, Type castTy);
4766+
47764767 // / Create an implicit coercion expression for literal initialization
47774768 // / preserving original source information, this way original call
47784769 // / could be recreated if needed.
47794770 static CoerceExpr *forLiteralInit (ASTContext &ctx, Expr *literal,
4780- SourceRange range, TypeLoc literalType) {
4781- return new (ctx) CoerceExpr (range, literal, literalType);
4782- }
4771+ SourceRange range, TypeRepr *literalTyRepr);
47834772
47844773 bool isLiteralInit () const { return InitRangeEnd.isValid (); }
47854774
0 commit comments