[IDE] Fix SyntaxModel to corretly walk sequence expression correctly

* Handle sequence expression at call argument position
* Set the sequence expression as the parent when walking into its sub
  expressions.
* Correctly call walkToExprPost() to the sequence expression.

rdar://problem/47603866 / https://bugs.swift.org/browse/SR-9776
This commit is contained in:
Rintaro Ishizaki
2019-01-28 11:25:07 -08:00
parent ac557c53b2
commit e7700dc67f
2 changed files with 17 additions and 12 deletions

View File

@@ -425,18 +425,6 @@ std::pair<bool, Expr *> ModelASTWalker::walkToExprPre(Expr *E) {
if (isVisitedBeforeInIfConfig(E))
return {false, E};
// In SequenceExpr, explicit cast expressions (e.g. 'as', 'is') appear twice.
// Skip pointers we've already seen.
if (auto SE = dyn_cast<SequenceExpr>(E)) {
SmallPtrSet<Expr *, 5> seenExpr;
for (auto subExpr : SE->getElements()) {
if (!seenExpr.insert(subExpr).second)
continue;
subExpr->walk(*this);
}
return { false, SE };
}
auto addCallArgExpr = [&](Expr *Elem, TupleExpr *ParentTupleExpr) {
if (isCurrentCallArgExpr(ParentTupleExpr)) {
CharSourceRange NR = parameterNameRangeOfCallArg(ParentTupleExpr, Elem);
@@ -558,6 +546,18 @@ std::pair<bool, Expr *> ModelASTWalker::walkToExprPre(Expr *E) {
Closure->getExplicitResultTypeLoc().getSourceRange());
pushStructureNode(SN, Closure);
} else if (auto SE = dyn_cast<SequenceExpr>(E)) {
// In SequenceExpr, explicit cast expressions (e.g. 'as', 'is') appear
// twice. Skip pointers we've already seen.
SmallPtrSet<Expr *, 5> seenExpr;
for (auto subExpr : SE->getElements()) {
if (!seenExpr.insert(subExpr).second) {
continue;
}
llvm::SaveAndRestore<ASTWalker::ParentTy> SetParent(Parent, E);
subExpr->walk(*this);
}
return { false, walkToExprPost(SE) };
}
return { true, E };