banach-space / clang-tutor

A collection of out-of-tree Clang plugins for teaching and learning
The Unlicense
659 stars 62 forks source link

What's the difference between TraverseForStmt and VisitForStmt? #19

Open zhou-shulin opened 2 years ago

zhou-shulin commented 2 years ago

Hi,

I am learning the excellent tutorial, and I have some confusion in UnusedForLoopVar Tool. In UnusedForLoopVar especially in the implementation of RecursiveASTVisitor, the TraverseForStmt() is used to visit the ForStmt in AST, rather than VisitForStmt(). What's the difference between these two methods on visiting the AST nodes? Why would UnusedForLoopVar use TraverseForStmt() rather than VisitForStmt()?

Thank you very much!!!

banach-space commented 2 years ago

Hello @zhou-shulin , thank you for stopping by :) Apologies for the delay, I was away for a couple of weeks.

The difference between these methods is documented here. It's a bit dense, so let me know if it's still unclear and I will try to clarify.

Best, -Andrzej