2424#include " swift/Basic/LLVM.h"
2525#include " swift/AST/Type.h"
2626#include " swift/AST/Types.h"
27- #include " swift/AST/TypeLoc.h"
2827#include " swift/AST/TypeAlignments.h"
2928#include " swift/Basic/InlineBitfield.h"
3029#include " swift/Basic/OptionSet.h"
@@ -35,6 +34,7 @@ namespace swift {
3534 class Expr ;
3635 enum class CheckedCastKind : unsigned ;
3736 class TypeExpr ;
37+ class TypeLoc ;
3838
3939// / PatternKind - The classification of different kinds of
4040// / value-matching pattern.
@@ -470,19 +470,14 @@ class IsPattern : public Pattern {
470470 CheckedCastKind CastKind;
471471
472472 // / The type being checked for.
473- TypeLoc CastType;
473+ TypeExpr * CastType;
474474
475475public:
476- IsPattern (SourceLoc IsLoc, TypeLoc CastTy,
477- Pattern *SubPattern,
478- CheckedCastKind Kind)
479- : Pattern(PatternKind::Is),
480- IsLoc (IsLoc),
481- SubPattern(SubPattern),
482- CastKind(Kind),
483- CastType(CastTy) {
484- assert (IsLoc.isValid () == CastTy.hasLocation ());
485- }
476+ IsPattern (SourceLoc IsLoc, TypeExpr *CastTy, Pattern *SubPattern,
477+ CheckedCastKind Kind);
478+
479+ static IsPattern *createImplicit (ASTContext &Ctx, Type castTy,
480+ Pattern *SubPattern, CheckedCastKind Kind);
486481
487482 CheckedCastKind getCastKind () const { return CastKind; }
488483 void setCastKind (CheckedCastKind kind) { CastKind = kind; }
@@ -493,16 +488,11 @@ class IsPattern : public Pattern {
493488 void setSubPattern (Pattern *p) { SubPattern = p; }
494489
495490 SourceLoc getLoc () const { return IsLoc; }
496- SourceRange getSourceRange () const {
497- SourceLoc beginLoc =
498- SubPattern ? SubPattern->getSourceRange ().Start : IsLoc;
499- SourceLoc endLoc =
500- (isImplicit () ? beginLoc : CastType.getSourceRange ().End );
501- return { beginLoc, endLoc };
502- }
491+ SourceRange getSourceRange () const ;
503492
504- TypeLoc &getCastTypeLoc () { return CastType; }
505- TypeLoc getCastTypeLoc () const { return CastType; }
493+ void setCastType (Type castTy);
494+ Type getCastType () const ;
495+ TypeRepr *getCastTypeRepr () const ;
506496
507497 static bool classof (const Pattern *P) {
508498 return P->getKind () == PatternKind::Is;
@@ -513,35 +503,31 @@ class IsPattern : public Pattern {
513503// / case, then the value is extracted. If there is a subpattern, it is then
514504// / matched against the associated value for the case.
515505class EnumElementPattern : public Pattern {
516- TypeLoc ParentType;
506+ TypeExpr * ParentType;
517507 SourceLoc DotLoc;
518508 DeclNameLoc NameLoc;
519509 DeclNameRef Name;
520510 PointerUnion<EnumElementDecl *, Expr*> ElementDeclOrUnresolvedOriginalExpr;
521511 Pattern /* nullable*/ *SubPattern;
522512
523513public:
524- EnumElementPattern (TypeLoc ParentType, SourceLoc DotLoc, DeclNameLoc NameLoc,
525- DeclNameRef Name, EnumElementDecl *Element,
526- Pattern *SubPattern)
527- : Pattern(PatternKind::EnumElement),
528- ParentType (ParentType), DotLoc(DotLoc), NameLoc(NameLoc), Name(Name),
529- ElementDeclOrUnresolvedOriginalExpr(Element),
530- SubPattern(SubPattern) { }
514+ EnumElementPattern (TypeExpr *ParentType, SourceLoc DotLoc,
515+ DeclNameLoc NameLoc, DeclNameRef Name,
516+ EnumElementDecl *Element, Pattern *SubPattern)
517+ : Pattern(PatternKind::EnumElement), ParentType(ParentType),
518+ DotLoc (DotLoc), NameLoc(NameLoc), Name(Name),
519+ ElementDeclOrUnresolvedOriginalExpr(Element), SubPattern(SubPattern) {
520+ assert (ParentType && " Missing parent type?" );
521+ }
531522
532523 // / Create an unresolved EnumElementPattern for a `.foo` pattern relying on
533524 // / contextual type.
534- EnumElementPattern (SourceLoc DotLoc,
535- DeclNameLoc NameLoc,
536- DeclNameRef Name,
537- Pattern *SubPattern,
538- Expr *UnresolvedOriginalExpr)
539- : Pattern(PatternKind::EnumElement),
540- ParentType(), DotLoc(DotLoc), NameLoc(NameLoc), Name(Name),
541- ElementDeclOrUnresolvedOriginalExpr(UnresolvedOriginalExpr),
542- SubPattern(SubPattern) {
543-
544- }
525+ EnumElementPattern (SourceLoc DotLoc, DeclNameLoc NameLoc, DeclNameRef Name,
526+ Pattern *SubPattern, Expr *UnresolvedOriginalExpr)
527+ : Pattern(PatternKind::EnumElement), ParentType(nullptr ), DotLoc(DotLoc),
528+ NameLoc(NameLoc), Name(Name),
529+ ElementDeclOrUnresolvedOriginalExpr(UnresolvedOriginalExpr),
530+ SubPattern(SubPattern) {}
545531
546532 bool hasSubPattern () const { return SubPattern; }
547533
@@ -553,10 +539,6 @@ class EnumElementPattern : public Pattern {
553539 return SubPattern;
554540 }
555541
556- bool isParentTypeImplicit () {
557- return !ParentType.hasLocation ();
558- }
559-
560542 void setSubPattern (Pattern *p) { SubPattern = p; }
561543
562544 DeclNameRef getName () const { return Name; }
@@ -577,21 +559,14 @@ class EnumElementPattern : public Pattern {
577559
578560 DeclNameLoc getNameLoc () const { return NameLoc; }
579561 SourceLoc getLoc () const { return NameLoc.getBaseNameLoc (); }
580- SourceLoc getStartLoc () const {
581- return ParentType.hasLocation () ? ParentType.getSourceRange ().Start :
582- DotLoc.isValid () ? DotLoc
583- : NameLoc.getBaseNameLoc ();
584- }
585- SourceLoc getEndLoc () const {
586- if (SubPattern && SubPattern->getSourceRange ().isValid ()) {
587- return SubPattern->getSourceRange ().End ;
588- }
589- return NameLoc.getEndLoc ();
590- }
562+ SourceLoc getStartLoc () const ;
563+ SourceLoc getEndLoc () const ;
591564 SourceRange getSourceRange () const { return {getStartLoc (), getEndLoc ()}; }
592565
593- TypeLoc &getParentType () { return ParentType; }
594- TypeLoc getParentType () const { return ParentType; }
566+ TypeRepr *getParentTypeRepr () const ;
567+
568+ void setParentType (Type ty);
569+ Type getParentType () const ;
595570
596571 static bool classof (const Pattern *P) {
597572 return P->getKind () == PatternKind::EnumElement;
0 commit comments