@@ -364,6 +364,9 @@ class ModelASTWalker : public ASTWalker {
364364 // / A mapping of argument expressions to their full argument info.
365365 llvm::DenseMap<Expr *, Argument> ArgumentInfo;
366366
367+ // / The number of ArgumentList parents in the walk.
368+ unsigned ArgumentListDepth = 0 ;
369+
367370public:
368371 SyntaxModelWalker &Walker;
369372 ArrayRef<SyntaxNode> TokenNodes;
@@ -383,6 +386,7 @@ class ModelASTWalker : public ASTWalker {
383386
384387 std::pair<bool , ArgumentList *>
385388 walkToArgumentListPre (ArgumentList *ArgList) override ;
389+ ArgumentList *walkToArgumentListPost (ArgumentList *ArgList) override ;
386390
387391 std::pair<bool , Expr *> walkToExprPre (Expr *E) override ;
388392 Expr *walkToExprPost (Expr *E) override ;
@@ -529,9 +533,19 @@ ModelASTWalker::walkToArgumentListPre(ArgumentList *ArgList) {
529533 assert (res.second && " Duplicate arguments?" );
530534 (void )res;
531535 }
536+ ArgumentListDepth += 1 ;
532537 return {true , ArgList};
533538}
534539
540+ 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 ();
546+ return ArgList;
547+ }
548+
535549std::pair<bool , Expr *> ModelASTWalker::walkToExprPre (Expr *E) {
536550 if (isVisitedBefore (E))
537551 return {false , E};
0 commit comments