1
- // ===--- PreCheckExpr .cpp - Expression pre -checking pass ------------------===//
1
+ // ===--- PreCheckTarget .cpp - Pre -checking pass --------- ------------------===//
2
2
//
3
3
// This source file is part of the Swift.org open source project
4
4
//
@@ -1036,7 +1036,7 @@ void markDirectCallee(Expr *callee) {
1036
1036
}
1037
1037
}
1038
1038
1039
- class PreCheckExpression : public ASTWalker {
1039
+ class PreCheckTarget final : public ASTWalker {
1040
1040
ASTContext &Ctx;
1041
1041
DeclContext *DC;
1042
1042
@@ -1101,7 +1101,7 @@ class PreCheckExpression : public ASTWalker {
1101
1101
void markAcceptableDiscardExprs (Expr *E);
1102
1102
1103
1103
public:
1104
- PreCheckExpression (DeclContext *dc) : Ctx(dc->getASTContext ()), DC(dc) {}
1104
+ PreCheckTarget (DeclContext *dc) : Ctx(dc->getASTContext ()), DC(dc) {}
1105
1105
1106
1106
ASTContext &getASTContext () const { return Ctx; }
1107
1107
@@ -1475,7 +1475,7 @@ class PreCheckExpression : public ASTWalker {
1475
1475
1476
1476
// / Perform prechecking of a ClosureExpr before we dive into it. This returns
1477
1477
// / true when we want the body to be considered part of this larger expression.
1478
- bool PreCheckExpression ::walkToClosureExprPre (ClosureExpr *closure) {
1478
+ bool PreCheckTarget ::walkToClosureExprPre (ClosureExpr *closure) {
1479
1479
// Pre-check the closure body.
1480
1480
(void )evaluateOrDefault (Ctx.evaluator , PreCheckClosureBodyRequest{closure},
1481
1481
nullptr );
@@ -1489,7 +1489,7 @@ bool PreCheckExpression::walkToClosureExprPre(ClosureExpr *closure) {
1489
1489
return true ;
1490
1490
}
1491
1491
1492
- TypeExpr *PreCheckExpression ::simplifyNestedTypeExpr (UnresolvedDotExpr *UDE) {
1492
+ TypeExpr *PreCheckTarget ::simplifyNestedTypeExpr (UnresolvedDotExpr *UDE) {
1493
1493
if (!UDE->getName ().isSimpleName () ||
1494
1494
UDE->getName ().isSpecial ())
1495
1495
return nullptr ;
@@ -1612,7 +1612,7 @@ TypeExpr *PreCheckExpression::simplifyNestedTypeExpr(UnresolvedDotExpr *UDE) {
1612
1612
return nullptr ;
1613
1613
}
1614
1614
1615
- TypeExpr *PreCheckExpression ::simplifyUnresolvedSpecializeExpr (
1615
+ TypeExpr *PreCheckTarget ::simplifyUnresolvedSpecializeExpr (
1616
1616
UnresolvedSpecializeExpr *us) {
1617
1617
// If this is a reference type a specialized type, form a TypeExpr.
1618
1618
// The base should be a TypeExpr that we already resolved.
@@ -1630,7 +1630,7 @@ TypeExpr *PreCheckExpression::simplifyUnresolvedSpecializeExpr(
1630
1630
1631
1631
// / Whether the given expression "looks like" a (possibly sugared) type. For
1632
1632
// / example, `(foo, bar)` "looks like" a type, but `foo + bar` does not.
1633
- bool PreCheckExpression ::exprLooksLikeAType (Expr *expr) {
1633
+ bool PreCheckTarget ::exprLooksLikeAType (Expr *expr) {
1634
1634
return isa<OptionalEvaluationExpr>(expr) ||
1635
1635
isa<BindOptionalExpr>(expr) ||
1636
1636
isa<ForceValueExpr>(expr) ||
@@ -1646,7 +1646,7 @@ bool PreCheckExpression::exprLooksLikeAType(Expr *expr) {
1646
1646
getCompositionExpr (expr);
1647
1647
}
1648
1648
1649
- bool PreCheckExpression ::possiblyInTypeContext (Expr *E) {
1649
+ bool PreCheckTarget ::possiblyInTypeContext (Expr *E) {
1650
1650
// Walk back up the stack of parents looking for a valid type context.
1651
1651
for (auto *ParentExpr : llvm::reverse (ExprStack)) {
1652
1652
// We're considered to be in a type context if either:
@@ -1666,7 +1666,7 @@ bool PreCheckExpression::possiblyInTypeContext(Expr *E) {
1666
1666
1667
1667
// / Only allow simplification of a DiscardAssignmentExpr if it hasn't already
1668
1668
// / been explicitly marked as correct, and the current AST state allows it.
1669
- bool PreCheckExpression ::canSimplifyDiscardAssignmentExpr (
1669
+ bool PreCheckTarget ::canSimplifyDiscardAssignmentExpr (
1670
1670
DiscardAssignmentExpr *DAE) {
1671
1671
return !CorrectDiscardAssignmentExprs.count (DAE) &&
1672
1672
possiblyInTypeContext (DAE);
@@ -1676,7 +1676,7 @@ bool PreCheckExpression::canSimplifyDiscardAssignmentExpr(
1676
1676
// / In Swift < 5, diagnose and correct invalid multi-argument or
1677
1677
// / argument-labeled interpolations. Returns \c true if the AST walk should
1678
1678
// / continue, or \c false if it should be aborted.
1679
- bool PreCheckExpression ::correctInterpolationIfStrange (
1679
+ bool PreCheckTarget ::correctInterpolationIfStrange (
1680
1680
InterpolatedStringLiteralExpr *ISLE) {
1681
1681
// These expressions are valid in Swift 5+.
1682
1682
if (getASTContext ().isSwiftVersionAtLeast (5 ))
@@ -1799,7 +1799,7 @@ bool PreCheckExpression::correctInterpolationIfStrange(
1799
1799
// / Scout out the specified destination of an AssignExpr to recursively
1800
1800
// / identify DiscardAssignmentExpr in legal places. We can only allow them
1801
1801
// / in simple pattern-like expressions, so we reject anything complex here.
1802
- void PreCheckExpression ::markAcceptableDiscardExprs (Expr *E) {
1802
+ void PreCheckTarget ::markAcceptableDiscardExprs (Expr *E) {
1803
1803
if (!E) return ;
1804
1804
1805
1805
if (auto *PE = dyn_cast<ParenExpr>(E))
@@ -1817,7 +1817,7 @@ void PreCheckExpression::markAcceptableDiscardExprs(Expr *E) {
1817
1817
// Otherwise, we can't support this.
1818
1818
}
1819
1819
1820
- VarDecl *PreCheckExpression ::getImplicitSelfDeclForSuperContext (SourceLoc Loc) {
1820
+ VarDecl *PreCheckTarget ::getImplicitSelfDeclForSuperContext (SourceLoc Loc) {
1821
1821
auto *methodContext = DC->getInnermostMethodContext ();
1822
1822
1823
1823
if (auto *typeContext = DC->getInnermostTypeContext ()) {
@@ -1884,7 +1884,7 @@ static bool isTildeOperator(Expr *expr) {
1884
1884
// / Simplify expressions which are type sugar productions that got parsed
1885
1885
// / as expressions due to the parser not knowing which identifiers are
1886
1886
// / type names.
1887
- TypeExpr *PreCheckExpression ::simplifyTypeExpr (Expr *E) {
1887
+ TypeExpr *PreCheckTarget ::simplifyTypeExpr (Expr *E) {
1888
1888
// If it's already a type expression, return it.
1889
1889
if (auto typeExpr = dyn_cast<TypeExpr>(E))
1890
1890
return typeExpr;
@@ -2207,7 +2207,7 @@ TypeExpr *PreCheckExpression::simplifyTypeExpr(Expr *E) {
2207
2207
return nullptr ;
2208
2208
}
2209
2209
2210
- void PreCheckExpression ::resolveKeyPathExpr (KeyPathExpr *KPE) {
2210
+ void PreCheckTarget ::resolveKeyPathExpr (KeyPathExpr *KPE) {
2211
2211
if (KPE->isObjC ())
2212
2212
return ;
2213
2213
@@ -2353,7 +2353,7 @@ void PreCheckExpression::resolveKeyPathExpr(KeyPathExpr *KPE) {
2353
2353
KPE->setComponents (getASTContext (), components);
2354
2354
}
2355
2355
2356
- Expr *PreCheckExpression ::simplifyTypeConstructionWithLiteralArg (Expr *E) {
2356
+ Expr *PreCheckTarget ::simplifyTypeConstructionWithLiteralArg (Expr *E) {
2357
2357
// If constructor call is expected to produce an optional let's not attempt
2358
2358
// this optimization because literal initializers aren't failable.
2359
2359
if (!getASTContext ().LangOpts .isSwiftVersionAtLeast (5 )) {
@@ -2429,7 +2429,7 @@ bool ConstraintSystem::preCheckTarget(SyntacticElementTarget &target) {
2429
2429
auto &ctx = DC->getASTContext ();
2430
2430
2431
2431
FrontendStatsTracer StatsTracer (ctx.Stats , " precheck-target" );
2432
- PreCheckExpression preCheck (DC);
2432
+ PreCheckTarget preCheck (DC);
2433
2433
2434
2434
auto newTarget = target.walk (preCheck);
2435
2435
if (!newTarget)
0 commit comments