@@ -647,43 +647,59 @@ class OptionalSomePattern : public Pattern {
647647class ExprPattern : public Pattern {
648648 llvm::PointerIntPair<Expr *, 1 , bool > SubExprAndIsResolved;
649649
650- // / An expression constructed during type-checking that produces a call to the
651- // / '~=' operator comparing the match expression on the left to the matched
652- // / value on the right.
653- Expr *MatchExpr = nullptr ;
650+ DeclContext *DC;
654651
655- // / An implicit variable used to represent the RHS value of the match.
656- VarDecl *MatchVar = nullptr ;
652+ // / A synthesized call to the '~=' operator comparing the match expression
653+ // / on the left to the matched value on the right.
654+ mutable Expr *MatchExpr = nullptr ;
657655
658- ExprPattern (Expr *E, bool isResolved)
659- : Pattern(PatternKind::Expr), SubExprAndIsResolved(E, isResolved) {}
656+ // / An implicit variable used to represent the RHS value of the synthesized
657+ // / match expression.
658+ mutable VarDecl *MatchVar = nullptr ;
659+
660+ ExprPattern (Expr *E, DeclContext *DC, bool isResolved)
661+ : Pattern(PatternKind::Expr), SubExprAndIsResolved(E, isResolved),
662+ DC (DC) {}
663+
664+ friend class ExprPatternMatchRequest ;
660665
661666public:
662667 // / Create a new parsed unresolved ExprPattern.
663- static ExprPattern *createParsed (ASTContext &ctx, Expr *E);
668+ static ExprPattern *createParsed (ASTContext &ctx, Expr *E, DeclContext *DC );
664669
665670 // / Create a new resolved ExprPattern. This should be used in cases
666671 // / where a user-written expression should be treated as an ExprPattern.
667- static ExprPattern *createResolved (ASTContext &ctx, Expr *E);
672+ static ExprPattern *createResolved (ASTContext &ctx, Expr *E, DeclContext *DC );
668673
669674 // / Create a new implicit resolved ExprPattern.
670- static ExprPattern *createImplicit (ASTContext &ctx, Expr *E);
675+ static ExprPattern *createImplicit (ASTContext &ctx, Expr *E, DeclContext *DC );
671676
672677 Expr *getSubExpr () const { return SubExprAndIsResolved.getPointer (); }
673678 void setSubExpr (Expr *e) { SubExprAndIsResolved.setPointer (e); }
674679
675- Expr *getMatchExpr () const { return MatchExpr; }
680+ DeclContext *getDeclContext () const { return DC; }
681+
682+ // / The match expression if it has been computed, \c nullptr otherwise.
683+ // / Should only be used by the ASTDumper and ASTWalker.
684+ Expr *getCachedMatchExpr () const { return MatchExpr; }
685+
686+ // / The match variable if it has been computed, \c nullptr otherwise.
687+ // / Should only be used by the ASTDumper and ASTWalker.
688+ VarDecl *getCachedMatchVar () const { return MatchVar; }
689+
690+ // / A synthesized call to the '~=' operator comparing the match expression
691+ // / on the left to the matched value on the right.
692+ Expr *getMatchExpr () const ;
693+
694+ // / An implicit variable used to represent the RHS value of the synthesized
695+ // / match expression.
696+ VarDecl *getMatchVar () const ;
697+
676698 void setMatchExpr (Expr *e) {
677- assert (isResolved () && " cannot set match fn for unresolved expr patter " );
699+ assert (MatchExpr && " Should only update an existing MatchExpr " );
678700 MatchExpr = e;
679701 }
680702
681- VarDecl *getMatchVar () const { return MatchVar; }
682- void setMatchVar (VarDecl *v) {
683- assert (isResolved () && " cannot set match var for unresolved expr patter" );
684- MatchVar = v;
685- }
686-
687703 SourceLoc getLoc () const ;
688704 SourceRange getSourceRange () const ;
689705
@@ -851,6 +867,9 @@ class ContextualPattern {
851867};
852868
853869void simple_display (llvm::raw_ostream &out, const ContextualPattern &pattern);
870+ void simple_display (llvm::raw_ostream &out, const Pattern *pattern);
871+
872+ SourceLoc extractNearestSourceLoc (const Pattern *pattern);
854873
855874} // end namespace swift
856875
0 commit comments