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.
@@ -503,35 +503,31 @@ class IsPattern : public Pattern {
503503// / case, then the value is extracted. If there is a subpattern, it is then
504504// / matched against the associated value for the case.
505505class EnumElementPattern : public Pattern {
506- TypeLoc ParentType;
506+ TypeExpr * ParentType;
507507 SourceLoc DotLoc;
508508 DeclNameLoc NameLoc;
509509 DeclNameRef Name;
510510 PointerUnion<EnumElementDecl *, Expr*> ElementDeclOrUnresolvedOriginalExpr;
511511 Pattern /* nullable*/ *SubPattern;
512512
513513public:
514- EnumElementPattern (TypeLoc ParentType, SourceLoc DotLoc, DeclNameLoc NameLoc,
515- DeclNameRef Name, EnumElementDecl *Element,
516- Pattern *SubPattern)
517- : Pattern(PatternKind::EnumElement),
518- ParentType (ParentType), DotLoc(DotLoc), NameLoc(NameLoc), Name(Name),
519- ElementDeclOrUnresolvedOriginalExpr(Element),
520- 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+ }
521522
522523 // / Create an unresolved EnumElementPattern for a `.foo` pattern relying on
523524 // / contextual type.
524- EnumElementPattern (SourceLoc DotLoc,
525- DeclNameLoc NameLoc,
526- DeclNameRef Name,
527- Pattern *SubPattern,
528- Expr *UnresolvedOriginalExpr)
529- : Pattern(PatternKind::EnumElement),
530- ParentType(), DotLoc(DotLoc), NameLoc(NameLoc), Name(Name),
531- ElementDeclOrUnresolvedOriginalExpr(UnresolvedOriginalExpr),
532- SubPattern(SubPattern) {
533-
534- }
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) {}
535531
536532 bool hasSubPattern () const { return SubPattern; }
537533
@@ -543,10 +539,6 @@ class EnumElementPattern : public Pattern {
543539 return SubPattern;
544540 }
545541
546- bool isParentTypeImplicit () {
547- return !ParentType.hasLocation ();
548- }
549-
550542 void setSubPattern (Pattern *p) { SubPattern = p; }
551543
552544 DeclNameRef getName () const { return Name; }
@@ -567,21 +559,14 @@ class EnumElementPattern : public Pattern {
567559
568560 DeclNameLoc getNameLoc () const { return NameLoc; }
569561 SourceLoc getLoc () const { return NameLoc.getBaseNameLoc (); }
570- SourceLoc getStartLoc () const {
571- return ParentType.hasLocation () ? ParentType.getSourceRange ().Start :
572- DotLoc.isValid () ? DotLoc
573- : NameLoc.getBaseNameLoc ();
574- }
575- SourceLoc getEndLoc () const {
576- if (SubPattern && SubPattern->getSourceRange ().isValid ()) {
577- return SubPattern->getSourceRange ().End ;
578- }
579- return NameLoc.getEndLoc ();
580- }
562+ SourceLoc getStartLoc () const ;
563+ SourceLoc getEndLoc () const ;
581564 SourceRange getSourceRange () const { return {getStartLoc (), getEndLoc ()}; }
582565
583- TypeLoc &getParentType () { return ParentType; }
584- TypeLoc getParentType () const { return ParentType; }
566+ TypeRepr *getParentTypeRepr () const ;
567+
568+ void setParentType (Type ty);
569+ Type getParentType () const ;
585570
586571 static bool classof (const Pattern *P) {
587572 return P->getKind () == PatternKind::EnumElement;
0 commit comments