@@ -361,11 +361,12 @@ class ModelASTWalker : public ASTWalker {
361
361
friend class InactiveClauseRAII ;
362
362
bool inInactiveClause = false ;
363
363
364
+ struct ParentArgsTy {
365
+ Expr *Parent = nullptr ;
366
+ llvm::DenseMap<Expr *, Argument> Args;
367
+ };
364
368
// / A mapping of argument expressions to their full argument info.
365
- llvm::DenseMap<Expr *, Argument> ArgumentInfo;
366
-
367
- // / The number of ArgumentList parents in the walk.
368
- unsigned ArgumentListDepth = 0 ;
369
+ SmallVector<ParentArgsTy, 4 > ParentArgs;
369
370
370
371
public:
371
372
SyntaxModelWalker &Walker;
@@ -528,21 +529,27 @@ static bool shouldTreatAsSingleToken(const SyntaxStructureNode &Node,
528
529
529
530
std::pair<bool , ArgumentList *>
530
531
ModelASTWalker::walkToArgumentListPre (ArgumentList *ArgList) {
532
+ Expr *ParentExpr = Parent.getAsExpr ();
533
+ if (!ParentExpr)
534
+ return {true , ArgList};
535
+
536
+ ParentArgsTy Mapping;
537
+ Mapping.Parent = ParentExpr;
531
538
for (auto Arg : *ArgList) {
532
- auto res = ArgumentInfo. insert ({ Arg.getExpr (), Arg} );
539
+ auto res = Mapping. Args . try_emplace ( Arg.getExpr (), Arg);
533
540
assert (res.second && " Duplicate arguments?" );
534
541
(void )res;
535
542
}
536
- ArgumentListDepth += 1 ;
543
+ ParentArgs. push_back ( std::move (Mapping)) ;
537
544
return {true , ArgList};
538
545
}
539
546
540
547
ArgumentList *ModelASTWalker::walkToArgumentListPost (ArgumentList *ArgList) {
541
- // If there are no more argument lists above us, we can clear out the argument
542
- // mapping to save memory.
543
- ArgumentListDepth -= 1 ;
544
- if (ArgumentListDepth == 0 )
545
- ArgumentInfo. clear ();
548
+ if (Expr *ParentExpr = Parent. getAsExpr ()) {
549
+ assert (ParentExpr == ParentArgs. back (). Parent &&
550
+ " Unmatched walkToArgumentList(Pre|Post) " ) ;
551
+ ParentArgs. pop_back ();
552
+ }
546
553
return ArgList;
547
554
}
548
555
@@ -573,9 +580,14 @@ std::pair<bool, Expr *> ModelASTWalker::walkToExprPre(Expr *E) {
573
580
pushStructureNode (SN, Elem);
574
581
};
575
582
576
- auto Arg = ArgumentInfo.find (E);
577
- if (Arg != ArgumentInfo.end ())
578
- addCallArgExpr (Arg->second );
583
+ if (auto *ParentExpr = Parent.getAsExpr ()) {
584
+ if (!ParentArgs.empty () && ParentArgs.back ().Parent == ParentExpr) {
585
+ auto &ArgumentInfo = ParentArgs.back ().Args ;
586
+ auto Arg = ArgumentInfo.find (E);
587
+ if (Arg != ArgumentInfo.end ())
588
+ addCallArgExpr (Arg->second );
589
+ }
590
+ }
579
591
580
592
if (E->isImplicit ())
581
593
return { true , E };
0 commit comments