@@ -1537,27 +1537,39 @@ class PlaceholderExpansionScanner {
1537
1537
// / For example, if the CallExpr is enclosed in another expression or statement
1538
1538
// / such as "outer(inner(<#closure#>))", or "if inner(<#closure#>)", then trailing
1539
1539
// / closure should not be applied to the inner call.
1540
- std::pair<CallExpr *, bool > enclosingCallExpr (SourceFile &SF, SourceLoc SL) {
1540
+ std::pair<Expr *, bool > enclosingCallExprArg (SourceFile &SF, SourceLoc SL) {
1541
1541
1542
1542
class CallExprFinder : public SourceEntityWalker {
1543
1543
public:
1544
1544
const SourceManager &SM;
1545
1545
SourceLoc TargetLoc;
1546
- CallExpr *EnclosingCall ;
1546
+ std::pair<Expr *, Expr*> EnclosingCallAndArg ;
1547
1547
Expr *OuterExpr;
1548
1548
Stmt *OuterStmt;
1549
1549
explicit CallExprFinder (const SourceManager &SM)
1550
1550
:SM(SM) { }
1551
1551
1552
+ bool checkCallExpr (Expr *E) {
1553
+ Expr* Arg = nullptr ;
1554
+ if (auto *CE = dyn_cast<CallExpr>(E)) {
1555
+ // Call expression can have argument.
1556
+ Arg = CE->getArg ();
1557
+ } else if (auto UME = dyn_cast<UnresolvedMemberExpr>(E)) {
1558
+ // Unresolved member can have argument too.
1559
+ Arg = UME->getArgument ();
1560
+ }
1561
+ if (!Arg)
1562
+ return false ;
1563
+ if (EnclosingCallAndArg.first )
1564
+ OuterExpr = EnclosingCallAndArg.first ;
1565
+ EnclosingCallAndArg = {E, Arg};
1566
+ return true ;
1567
+ }
1568
+
1552
1569
bool walkToExprPre (Expr *E) override {
1553
1570
auto SR = E->getSourceRange ();
1554
1571
if (SR.isValid () && SM.rangeContainsTokenLoc (SR, TargetLoc)) {
1555
- if (auto *CE = dyn_cast<CallExpr>(E)) {
1556
- if (EnclosingCall)
1557
- OuterExpr = EnclosingCall;
1558
- EnclosingCall = CE;
1559
- }
1560
- else if (!EnclosingCall)
1572
+ if (!checkCallExpr (E) && !EnclosingCallAndArg.first )
1561
1573
OuterExpr = E;
1562
1574
}
1563
1575
return true ;
@@ -1572,7 +1584,7 @@ class PlaceholderExpansionScanner {
1572
1584
bool walkToStmtPre (Stmt *S) override {
1573
1585
auto SR = S->getSourceRange ();
1574
1586
if (SR.isValid () && SM.rangeContainsTokenLoc (SR, TargetLoc)) {
1575
- if (!EnclosingCall ) {
1587
+ if (!EnclosingCallAndArg. first ) {
1576
1588
if (isa<BraceStmt>(S))
1577
1589
// In case OuterStmt is already set, we should clear it to nullptr.
1578
1590
OuterStmt = nullptr ;
@@ -1583,18 +1595,18 @@ class PlaceholderExpansionScanner {
1583
1595
return true ;
1584
1596
}
1585
1597
1586
- CallExpr * findEnclosingCall (SourceFile &SF, SourceLoc SL) {
1587
- EnclosingCall = nullptr ;
1598
+ Expr * findEnclosingCallArg (SourceFile &SF, SourceLoc SL) {
1599
+ EnclosingCallAndArg = { nullptr , nullptr } ;
1588
1600
OuterExpr = nullptr ;
1589
1601
OuterStmt = nullptr ;
1590
1602
TargetLoc = SL;
1591
1603
walk (SF);
1592
- return EnclosingCall ;
1604
+ return EnclosingCallAndArg. second ;
1593
1605
}
1594
1606
};
1595
1607
1596
1608
CallExprFinder CEFinder (SM);
1597
- auto *CE = CEFinder.findEnclosingCall (SF, SL);
1609
+ auto *CE = CEFinder.findEnclosingCallArg (SF, SL);
1598
1610
1599
1611
if (!CE)
1600
1612
return std::make_pair (CE, false );
@@ -1647,8 +1659,8 @@ class PlaceholderExpansionScanner {
1647
1659
// and if the call parens can be removed in that case.
1648
1660
// We'll first find the enclosing CallExpr, and then do further analysis.
1649
1661
bool UseTrailingClosure = false ;
1650
- std::pair<CallExpr*, bool > ECE = enclosingCallExpr (SF, PlaceholderStartLoc);
1651
- Expr *Args = ECE.first ? ECE. first -> getArg () : nullptr ;
1662
+ auto ECE = enclosingCallExprArg (SF, PlaceholderStartLoc);
1663
+ Expr *Args = ECE.first ;
1652
1664
if (Args && ECE.second ) {
1653
1665
if (isa<ParenExpr>(Args)) {
1654
1666
UseTrailingClosure = true ;
0 commit comments