@@ -5609,7 +5609,8 @@ class KeyPathExpr : public Expr {
5609
5609
Kind KindValue;
5610
5610
Type ComponentType;
5611
5611
SourceLoc Loc;
5612
-
5612
+
5613
+ // Private constructor for subscript component.
5613
5614
explicit Component (ASTContext *ctxForCopyingLabels,
5614
5615
DeclNameOrRef decl,
5615
5616
Expr *indexExpr,
@@ -5619,27 +5620,31 @@ class KeyPathExpr : public Expr {
5619
5620
Type type,
5620
5621
SourceLoc loc);
5621
5622
5622
- // Private constructor for tuple element kind
5623
- Component (unsigned tupleIndex, Type elementType, SourceLoc loc)
5624
- : Component(nullptr , {}, nullptr , {}, {}, Kind::TupleElement,
5625
- elementType, loc) {
5623
+ // Private constructor for property or #keyPath dictionary key.
5624
+ explicit Component (DeclNameOrRef decl, Kind kind, Type type, SourceLoc loc)
5625
+ : Component(kind, type, loc) {
5626
+ assert (kind == Kind::Property || kind == Kind::UnresolvedProperty ||
5627
+ kind == Kind::DictionaryKey);
5628
+ Decl = decl;
5629
+ }
5630
+
5631
+ // Private constructor for tuple element kind.
5632
+ explicit Component (unsigned tupleIndex, Type elementType, SourceLoc loc)
5633
+ : Component(Kind::TupleElement, elementType, loc) {
5626
5634
TupleIndex = tupleIndex;
5627
5635
}
5628
-
5636
+
5637
+ // Private constructor for basic components with no additional information.
5638
+ explicit Component (Kind kind, Type type, SourceLoc loc)
5639
+ : Decl(), KindValue(kind), ComponentType(type), Loc(loc) {}
5640
+
5629
5641
public:
5630
- Component ()
5631
- : Component(nullptr , {}, nullptr , {}, {}, Kind::Invalid,
5632
- Type (), SourceLoc())
5633
- {}
5634
-
5642
+ Component () : Component(Kind::Invalid, Type(), SourceLoc()) {}
5643
+
5635
5644
// / Create an unresolved component for a property.
5636
5645
static Component forUnresolvedProperty (DeclNameRef UnresolvedName,
5637
5646
SourceLoc Loc) {
5638
- return Component (nullptr ,
5639
- UnresolvedName, nullptr , {}, {},
5640
- Kind::UnresolvedProperty,
5641
- Type (),
5642
- Loc);
5647
+ return Component (UnresolvedName, Kind::UnresolvedProperty, Type (), Loc);
5643
5648
}
5644
5649
5645
5650
// / Create an unresolved component for a subscript.
@@ -5669,38 +5674,26 @@ class KeyPathExpr : public Expr {
5669
5674
5670
5675
// / Create an unresolved optional force `!` component.
5671
5676
static Component forUnresolvedOptionalForce (SourceLoc BangLoc) {
5672
- return Component (nullptr , {}, nullptr , {}, {},
5673
- Kind::OptionalForce,
5674
- Type (),
5675
- BangLoc);
5677
+ return Component (Kind::OptionalForce, Type (), BangLoc);
5676
5678
}
5677
5679
5678
5680
// / Create an unresolved optional chain `?` component.
5679
5681
static Component forUnresolvedOptionalChain (SourceLoc QuestionLoc) {
5680
- return Component (nullptr , {}, nullptr , {}, {},
5681
- Kind::OptionalChain,
5682
- Type (),
5683
- QuestionLoc);
5682
+ return Component (Kind::OptionalChain, Type (), QuestionLoc);
5684
5683
}
5685
5684
5686
5685
// / Create a component for a property.
5687
5686
static Component forProperty (ConcreteDeclRef property,
5688
5687
Type propertyType,
5689
5688
SourceLoc loc) {
5690
- return Component (nullptr , property, nullptr , {}, {},
5691
- Kind::Property,
5692
- propertyType,
5693
- loc);
5689
+ return Component (property, Kind::Property, propertyType, loc);
5694
5690
}
5695
5691
5696
5692
// / Create a component for a dictionary key (#keyPath only).
5697
5693
static Component forDictionaryKey (DeclNameRef UnresolvedName,
5698
5694
Type valueType,
5699
5695
SourceLoc loc) {
5700
- return Component (nullptr , UnresolvedName, nullptr , {}, {},
5701
- Kind::DictionaryKey,
5702
- valueType,
5703
- loc);
5696
+ return Component (UnresolvedName, Kind::DictionaryKey, valueType, loc);
5704
5697
}
5705
5698
5706
5699
// / Create a component for a subscript.
@@ -5726,32 +5719,24 @@ class KeyPathExpr : public Expr {
5726
5719
5727
5720
// / Create an optional-forcing `!` component.
5728
5721
static Component forOptionalForce (Type forcedType, SourceLoc bangLoc) {
5729
- return Component (nullptr , {}, nullptr , {}, {},
5730
- Kind::OptionalForce, forcedType,
5731
- bangLoc);
5722
+ return Component (Kind::OptionalForce, forcedType, bangLoc);
5732
5723
}
5733
5724
5734
5725
// / Create an optional-chaining `?` component.
5735
5726
static Component forOptionalChain (Type unwrappedType,
5736
5727
SourceLoc questionLoc) {
5737
- return Component (nullptr , {}, nullptr , {}, {},
5738
- Kind::OptionalChain, unwrappedType,
5739
- questionLoc);
5728
+ return Component (Kind::OptionalChain, unwrappedType, questionLoc);
5740
5729
}
5741
5730
5742
5731
// / Create an optional-wrapping component. This doesn't have a surface
5743
5732
// / syntax but may appear when the non-optional result of an optional chain
5744
5733
// / is implicitly wrapped.
5745
5734
static Component forOptionalWrap (Type wrappedType) {
5746
- return Component (nullptr , {}, nullptr , {}, {},
5747
- Kind::OptionalWrap, wrappedType,
5748
- SourceLoc ());
5735
+ return Component (Kind::OptionalWrap, wrappedType, SourceLoc ());
5749
5736
}
5750
5737
5751
5738
static Component forIdentity (SourceLoc selfLoc) {
5752
- return Component (nullptr , {}, nullptr , {}, {},
5753
- Kind::Identity, Type (),
5754
- selfLoc);
5739
+ return Component (Kind::Identity, Type (), selfLoc);
5755
5740
}
5756
5741
5757
5742
static Component forTupleElement (unsigned fieldNumber,
@@ -5761,8 +5746,7 @@ class KeyPathExpr : public Expr {
5761
5746
}
5762
5747
5763
5748
static Component forCodeCompletion (SourceLoc Loc) {
5764
- return Component (nullptr , {}, nullptr , {}, {}, Kind::CodeCompletion,
5765
- Type (), Loc);
5749
+ return Component (Kind::CodeCompletion, Type (), Loc);
5766
5750
}
5767
5751
5768
5752
SourceLoc getLoc () const {
0 commit comments