@@ -4721,6 +4721,14 @@ class CallExpr final : public ApplyExpr,
4721
4721
/* trailingClosures=*/ {}, /* implicit=*/ true , getType);
4722
4722
}
4723
4723
4724
+ // / Create a new implicit call expression with no arguments and no
4725
+ // / source-location information.
4726
+ // /
4727
+ // / \param fn The nullary function being called.
4728
+ static CallExpr *createImplicitEmpty (ASTContext &ctx, Expr *fn) {
4729
+ return createImplicit (ctx, fn, {}, {});
4730
+ }
4731
+
4724
4732
// / Create a new call expression.
4725
4733
// /
4726
4734
// / \param fn The function being called
@@ -4779,9 +4787,12 @@ class CallExpr final : public ApplyExpr,
4779
4787
4780
4788
// / PrefixUnaryExpr - Prefix unary expressions like '!y'.
4781
4789
class PrefixUnaryExpr : public ApplyExpr {
4790
+ PrefixUnaryExpr (Expr *fn, Expr *operand, Type ty = Type())
4791
+ : ApplyExpr(ExprKind::PrefixUnary, fn, operand, /* implicit*/ false , ty) {}
4792
+
4782
4793
public:
4783
- PrefixUnaryExpr (Expr *Fn , Expr *Arg, Type Ty = Type())
4784
- : ApplyExpr(ExprKind::PrefixUnary, Fn, Arg, /* Implicit= */ false , Ty) {}
4794
+ static PrefixUnaryExpr * create (ASTContext &ctx , Expr *fn, Expr *operand,
4795
+ Type ty = Type());
4785
4796
4786
4797
SourceLoc getLoc () const { return getFn ()->getStartLoc (); }
4787
4798
@@ -4799,9 +4810,13 @@ class PrefixUnaryExpr : public ApplyExpr {
4799
4810
4800
4811
// / PostfixUnaryExpr - Postfix unary expressions like 'y!'.
4801
4812
class PostfixUnaryExpr : public ApplyExpr {
4813
+ PostfixUnaryExpr (Expr *fn, Expr *operand, Type ty = Type())
4814
+ : ApplyExpr(ExprKind::PostfixUnary, fn, operand, /* implicit*/ false , ty) {
4815
+ }
4816
+
4802
4817
public:
4803
- PostfixUnaryExpr (Expr *Fn , Expr *Arg, Type Ty = Type())
4804
- : ApplyExpr(ExprKind::PostfixUnary, Fn, Arg, /* Implicit= */ false , Ty) {}
4818
+ static PostfixUnaryExpr * create (ASTContext &ctx , Expr *fn, Expr *operand,
4819
+ Type ty = Type());
4805
4820
4806
4821
SourceLoc getLoc () const { return getFn ()->getStartLoc (); }
4807
4822
@@ -4869,15 +4884,19 @@ class SelfApplyExpr : public ApplyExpr {
4869
4884
// / is modeled as a DeclRefExpr or OverloadSetRefExpr on the method.
4870
4885
class DotSyntaxCallExpr : public SelfApplyExpr {
4871
4886
SourceLoc DotLoc;
4872
-
4873
- public:
4874
- DotSyntaxCallExpr (Expr *FnExpr, SourceLoc DotLoc, Expr *BaseExpr,
4875
- Type Ty = Type())
4876
- : SelfApplyExpr(ExprKind::DotSyntaxCall, FnExpr, BaseExpr, Ty),
4877
- DotLoc (DotLoc) {
4887
+
4888
+ DotSyntaxCallExpr (Expr *fnExpr, SourceLoc dotLoc, Expr *baseExpr,
4889
+ Type ty = Type())
4890
+ : SelfApplyExpr(ExprKind::DotSyntaxCall, fnExpr, baseExpr, ty),
4891
+ DotLoc (dotLoc) {
4878
4892
setImplicit (DotLoc.isInvalid ());
4879
4893
}
4880
4894
4895
+ public:
4896
+ static DotSyntaxCallExpr *create (ASTContext &ctx, Expr *fnExpr,
4897
+ SourceLoc dotLoc, Expr *baseExpr,
4898
+ Type ty = Type());
4899
+
4881
4900
SourceLoc getDotLoc () const { return DotLoc; }
4882
4901
4883
4902
SourceLoc getLoc () const ;
@@ -4893,9 +4912,12 @@ class DotSyntaxCallExpr : public SelfApplyExpr {
4893
4912
// / actual reference to function which returns the constructor is modeled
4894
4913
// / as a DeclRefExpr.
4895
4914
class ConstructorRefCallExpr : public SelfApplyExpr {
4915
+ ConstructorRefCallExpr (Expr *fnExpr, Expr *baseExpr, Type ty = Type())
4916
+ : SelfApplyExpr(ExprKind::ConstructorRefCall, fnExpr, baseExpr, ty) {}
4917
+
4896
4918
public:
4897
- ConstructorRefCallExpr (Expr *FnExpr , Expr *BaseExpr, Type Ty = Type())
4898
- : SelfApplyExpr(ExprKind::ConstructorRefCall, FnExpr, BaseExpr, Ty) {}
4919
+ static ConstructorRefCallExpr * create (ASTContext &ctx , Expr *fnExpr,
4920
+ Expr *baseExpr, Type ty = Type());
4899
4921
4900
4922
SourceLoc getLoc () const { return getFn ()->getLoc (); }
4901
4923
SourceLoc getStartLoc () const { return getBase ()->getStartLoc (); }
@@ -5587,7 +5609,8 @@ class KeyPathExpr : public Expr {
5587
5609
Kind KindValue;
5588
5610
Type ComponentType;
5589
5611
SourceLoc Loc;
5590
-
5612
+
5613
+ // Private constructor for subscript component.
5591
5614
explicit Component (ASTContext *ctxForCopyingLabels,
5592
5615
DeclNameOrRef decl,
5593
5616
Expr *indexExpr,
@@ -5597,27 +5620,31 @@ class KeyPathExpr : public Expr {
5597
5620
Type type,
5598
5621
SourceLoc loc);
5599
5622
5600
- // Private constructor for tuple element kind
5601
- Component (unsigned tupleIndex, Type elementType, SourceLoc loc)
5602
- : Component(nullptr , {}, nullptr , {}, {}, Kind::TupleElement,
5603
- 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) {
5604
5634
TupleIndex = tupleIndex;
5605
5635
}
5606
-
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
+
5607
5641
public:
5608
- Component ()
5609
- : Component(nullptr , {}, nullptr , {}, {}, Kind::Invalid,
5610
- Type (), SourceLoc())
5611
- {}
5612
-
5642
+ Component () : Component(Kind::Invalid, Type(), SourceLoc()) {}
5643
+
5613
5644
// / Create an unresolved component for a property.
5614
5645
static Component forUnresolvedProperty (DeclNameRef UnresolvedName,
5615
5646
SourceLoc Loc) {
5616
- return Component (nullptr ,
5617
- UnresolvedName, nullptr , {}, {},
5618
- Kind::UnresolvedProperty,
5619
- Type (),
5620
- Loc);
5647
+ return Component (UnresolvedName, Kind::UnresolvedProperty, Type (), Loc);
5621
5648
}
5622
5649
5623
5650
// / Create an unresolved component for a subscript.
@@ -5647,38 +5674,26 @@ class KeyPathExpr : public Expr {
5647
5674
5648
5675
// / Create an unresolved optional force `!` component.
5649
5676
static Component forUnresolvedOptionalForce (SourceLoc BangLoc) {
5650
- return Component (nullptr , {}, nullptr , {}, {},
5651
- Kind::OptionalForce,
5652
- Type (),
5653
- BangLoc);
5677
+ return Component (Kind::OptionalForce, Type (), BangLoc);
5654
5678
}
5655
5679
5656
5680
// / Create an unresolved optional chain `?` component.
5657
5681
static Component forUnresolvedOptionalChain (SourceLoc QuestionLoc) {
5658
- return Component (nullptr , {}, nullptr , {}, {},
5659
- Kind::OptionalChain,
5660
- Type (),
5661
- QuestionLoc);
5682
+ return Component (Kind::OptionalChain, Type (), QuestionLoc);
5662
5683
}
5663
5684
5664
5685
// / Create a component for a property.
5665
5686
static Component forProperty (ConcreteDeclRef property,
5666
5687
Type propertyType,
5667
5688
SourceLoc loc) {
5668
- return Component (nullptr , property, nullptr , {}, {},
5669
- Kind::Property,
5670
- propertyType,
5671
- loc);
5689
+ return Component (property, Kind::Property, propertyType, loc);
5672
5690
}
5673
5691
5674
5692
// / Create a component for a dictionary key (#keyPath only).
5675
5693
static Component forDictionaryKey (DeclNameRef UnresolvedName,
5676
5694
Type valueType,
5677
5695
SourceLoc loc) {
5678
- return Component (nullptr , UnresolvedName, nullptr , {}, {},
5679
- Kind::DictionaryKey,
5680
- valueType,
5681
- loc);
5696
+ return Component (UnresolvedName, Kind::DictionaryKey, valueType, loc);
5682
5697
}
5683
5698
5684
5699
// / Create a component for a subscript.
@@ -5704,32 +5719,24 @@ class KeyPathExpr : public Expr {
5704
5719
5705
5720
// / Create an optional-forcing `!` component.
5706
5721
static Component forOptionalForce (Type forcedType, SourceLoc bangLoc) {
5707
- return Component (nullptr , {}, nullptr , {}, {},
5708
- Kind::OptionalForce, forcedType,
5709
- bangLoc);
5722
+ return Component (Kind::OptionalForce, forcedType, bangLoc);
5710
5723
}
5711
5724
5712
5725
// / Create an optional-chaining `?` component.
5713
5726
static Component forOptionalChain (Type unwrappedType,
5714
5727
SourceLoc questionLoc) {
5715
- return Component (nullptr , {}, nullptr , {}, {},
5716
- Kind::OptionalChain, unwrappedType,
5717
- questionLoc);
5728
+ return Component (Kind::OptionalChain, unwrappedType, questionLoc);
5718
5729
}
5719
5730
5720
5731
// / Create an optional-wrapping component. This doesn't have a surface
5721
5732
// / syntax but may appear when the non-optional result of an optional chain
5722
5733
// / is implicitly wrapped.
5723
5734
static Component forOptionalWrap (Type wrappedType) {
5724
- return Component (nullptr , {}, nullptr , {}, {},
5725
- Kind::OptionalWrap, wrappedType,
5726
- SourceLoc ());
5735
+ return Component (Kind::OptionalWrap, wrappedType, SourceLoc ());
5727
5736
}
5728
5737
5729
5738
static Component forIdentity (SourceLoc selfLoc) {
5730
- return Component (nullptr , {}, nullptr , {}, {},
5731
- Kind::Identity, Type (),
5732
- selfLoc);
5739
+ return Component (Kind::Identity, Type (), selfLoc);
5733
5740
}
5734
5741
5735
5742
static Component forTupleElement (unsigned fieldNumber,
@@ -5739,8 +5746,7 @@ class KeyPathExpr : public Expr {
5739
5746
}
5740
5747
5741
5748
static Component forCodeCompletion (SourceLoc Loc) {
5742
- return Component (nullptr , {}, nullptr , {}, {}, Kind::CodeCompletion,
5743
- Type (), Loc);
5749
+ return Component (Kind::CodeCompletion, Type (), Loc);
5744
5750
}
5745
5751
5746
5752
SourceLoc getLoc () const {
0 commit comments