@@ -361,11 +361,12 @@ class ModelASTWalker : public ASTWalker {
361361 friend class InactiveClauseRAII ;
362362 bool inInactiveClause = false ;
363363
364+ struct ParentArgsTy {
365+ Expr *Parent = nullptr ;
366+ llvm::DenseMap<Expr *, Argument> Args;
367+ };
364368 // / 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;
369370
370371public:
371372 SyntaxModelWalker &Walker;
@@ -528,21 +529,27 @@ static bool shouldTreatAsSingleToken(const SyntaxStructureNode &Node,
528529
529530std::pair<bool , ArgumentList *>
530531ModelASTWalker::walkToArgumentListPre (ArgumentList *ArgList) {
532+ Expr *ParentExpr = Parent.getAsExpr ();
533+ if (!ParentExpr)
534+ return {true , ArgList};
535+
536+ ParentArgsTy Mapping;
537+ Mapping.Parent = ParentExpr;
531538 for (auto Arg : *ArgList) {
532- auto res = ArgumentInfo. insert ({ Arg.getExpr (), Arg} );
539+ auto res = Mapping. Args . try_emplace ( Arg.getExpr (), Arg);
533540 assert (res.second && " Duplicate arguments?" );
534541 (void )res;
535542 }
536- ArgumentListDepth += 1 ;
543+ ParentArgs. push_back ( std::move (Mapping)) ;
537544 return {true , ArgList};
538545}
539546
540547ArgumentList *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+ }
546553 return ArgList;
547554}
548555
@@ -573,9 +580,14 @@ std::pair<bool, Expr *> ModelASTWalker::walkToExprPre(Expr *E) {
573580 pushStructureNode (SN, Elem);
574581 };
575582
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+ }
579591
580592 if (E->isImplicit ())
581593 return { true , E };
0 commit comments