@@ -242,6 +242,7 @@ class ModelASTWalker : public ASTWalker {
242
242
const LangOptions &LangOpts;
243
243
const SourceManager &SM;
244
244
unsigned BufferID;
245
+ ASTContext &Ctx;
245
246
std::vector<StructureElement> SubStructureStack;
246
247
SourceLoc LastLoc;
247
248
static const std::regex &getURLRegex (StringRef Protocol);
@@ -262,6 +263,7 @@ class ModelASTWalker : public ASTWalker {
262
263
LangOpts (File.getASTContext().LangOpts),
263
264
SM(File.getASTContext().SourceMgr),
264
265
BufferID(File.getBufferID().getValue()),
266
+ Ctx(File.getASTContext()),
265
267
Walker(Walker) { }
266
268
267
269
// FIXME: Remove this
@@ -521,13 +523,14 @@ std::pair<bool, Expr *> ModelASTWalker::walkToExprPre(Expr *E) {
521
523
SN.BodyRange = innerCharSourceRangeFromSourceRange (SM, E->getSourceRange ());
522
524
pushStructureNode (SN, E);
523
525
} else if (auto *Tup = dyn_cast<TupleExpr>(E)) {
526
+ auto *ParentE = Parent.getAsExpr ();
524
527
if (isCurrentCallArgExpr (Tup)) {
525
528
for (unsigned I = 0 ; I < Tup->getNumElements (); ++ I) {
526
529
SourceLoc NameLoc = Tup->getElementNameLoc (I);
527
530
if (NameLoc.isValid ())
528
531
passTokenNodesUntil (NameLoc, PassNodesBehavior::ExcludeNodeAtLocation);
529
532
}
530
- } else {
533
+ } else if (!ParentE || !isa<InterpolatedStringLiteralExpr>(ParentE)) {
531
534
SyntaxStructureNode SN;
532
535
SN.Kind = SyntaxStructureKind::TupleExpression;
533
536
SN.Range = charSourceRangeFromSourceRange (SM, Tup->getSourceRange ());
@@ -562,6 +565,18 @@ std::pair<bool, Expr *> ModelASTWalker::walkToExprPre(Expr *E) {
562
565
subExpr->walk (*this );
563
566
}
564
567
return { false , walkToExprPost (SE) };
568
+ } else if (auto *ISL = dyn_cast<InterpolatedStringLiteralExpr>(E)) {
569
+ // Don't visit the child expressions directly. Instead visit the arguments
570
+ // of each appendStringLiteral/appendInterpolation CallExpr so we don't
571
+ // try to output structure nodes for those calls.
572
+ llvm::SaveAndRestore<ASTWalker::ParentTy> SetParent (Parent, E);
573
+ ISL->forEachSegment (Ctx, [&](bool isInterpolation, CallExpr *CE) {
574
+ if (isInterpolation) {
575
+ if (auto *Arg = CE->getArg ())
576
+ Arg->walk (*this );
577
+ }
578
+ });
579
+ return { false , walkToExprPost (E) };
565
580
}
566
581
567
582
return { true , E };
@@ -1166,7 +1181,8 @@ bool ModelASTWalker::shouldPassBraceStructureNode(BraceStmt *S) {
1166
1181
return (!dyn_cast_or_null<AbstractFunctionDecl>(Parent.getAsDecl ()) &&
1167
1182
!dyn_cast_or_null<TopLevelCodeDecl>(Parent.getAsDecl ()) &&
1168
1183
!dyn_cast_or_null<CaseStmt>(Parent.getAsStmt ()) &&
1169
- S->getSourceRange ().isValid ());
1184
+ S->getSourceRange ().isValid () &&
1185
+ !S->isImplicit ());
1170
1186
}
1171
1187
1172
1188
ModelASTWalker::PassUntilResult
0 commit comments