24
24
#include " swift/Basic/LLVM.h"
25
25
#include " swift/AST/Type.h"
26
26
#include " swift/AST/Types.h"
27
- #include " swift/AST/TypeLoc.h"
28
27
#include " swift/AST/TypeAlignments.h"
29
28
#include " swift/Basic/InlineBitfield.h"
30
29
#include " swift/Basic/OptionSet.h"
@@ -35,6 +34,7 @@ namespace swift {
35
34
class Expr ;
36
35
enum class CheckedCastKind : unsigned ;
37
36
class TypeExpr ;
37
+ class TypeLoc ;
38
38
39
39
// / PatternKind - The classification of different kinds of
40
40
// / value-matching pattern.
@@ -503,35 +503,31 @@ class IsPattern : public Pattern {
503
503
// / case, then the value is extracted. If there is a subpattern, it is then
504
504
// / matched against the associated value for the case.
505
505
class EnumElementPattern : public Pattern {
506
- TypeLoc ParentType;
506
+ TypeExpr * ParentType;
507
507
SourceLoc DotLoc;
508
508
DeclNameLoc NameLoc;
509
509
DeclNameRef Name;
510
510
PointerUnion<EnumElementDecl *, Expr*> ElementDeclOrUnresolvedOriginalExpr;
511
511
Pattern /* nullable*/ *SubPattern;
512
512
513
513
public:
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
+ }
521
522
522
523
// / Create an unresolved EnumElementPattern for a `.foo` pattern relying on
523
524
// / 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) {}
535
531
536
532
bool hasSubPattern () const { return SubPattern; }
537
533
@@ -543,10 +539,6 @@ class EnumElementPattern : public Pattern {
543
539
return SubPattern;
544
540
}
545
541
546
- bool isParentTypeImplicit () {
547
- return !ParentType.hasLocation ();
548
- }
549
-
550
542
void setSubPattern (Pattern *p) { SubPattern = p; }
551
543
552
544
DeclNameRef getName () const { return Name; }
@@ -567,21 +559,14 @@ class EnumElementPattern : public Pattern {
567
559
568
560
DeclNameLoc getNameLoc () const { return NameLoc; }
569
561
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 ;
581
564
SourceRange getSourceRange () const { return {getStartLoc (), getEndLoc ()}; }
582
565
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 ;
585
570
586
571
static bool classof (const Pattern *P) {
587
572
return P->getKind () == PatternKind::EnumElement;
0 commit comments