[cfe-dev] Extra parameters to Traverse* functions in ASTVisitor

Saswat Padhi padhi at cs.ucla.edu
Mon Apr 27 15:01:03 PDT 2015


Hi Mats, 

Thanks for the reply. 

That's something I had thought about. I was thinking of adding a stack to my Visitor class, and the Traverse* functions would push and pop on to the stack to store and fetch the argument. I was hoping there would be a cleaner way to do this. 
If not, I think it would definitely be a good improvement to Clang. The functions within the Visitor classes should accept one more parameter that could point to any extra data the programmer wants to send. 


From: "mats petersson" <mats at planetcatfish.com> 
To: "Saswat Padhi" <padhi at cs.ucla.edu> 
Cc: "cfe-dev" <cfe-dev at cs.uiuc.edu> 
Sent: Monday, 27 April, 2015 02:03:13 
Subject: Re: [cfe-dev] Extra parameters to Traverse* functions in ASTVisitor 

I've not worked directly with RecurisiveASTVisitor, but in my own compiler, I have my own ASTVisitor class, and the way I pass "extra information" is to add it to the class that is doing the visiting. In the RecursiveASTVisitor, that would mean adding it to the `Derived` class that is the template parameter. You then call `getDerived()` to get the derived class and dig out your extra argument that way. Would that work for your case? 

-- 
Mats 

On 27 April 2015 at 07:04, Saswat Padhi < padhi at cs.ucla.edu > wrote: 


Hello everyone, 

I am new to Clang and am trying to build a Static Checker for one of my projects. I am currently using a RecursiveASTVisitor to walk through the AST. But I also need to pass some state to the Traverse* functions, while walking through the AST. For example, when I call TraverseStmt recursively, I need to pass some extra arguments, but the Traverse* functions only accept single arguments. Is there any way I could achieve this? 

I can keep a local stack within the ASTVisitor, but I was wondering if there would be a cleaner way to do it. 

Thanks, 
Saswat 
_______________________________________________ 
cfe-dev mailing list 
cfe-dev at cs.uiuc.edu 
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev 




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150427/c2b3417c/attachment.html>


More information about the cfe-dev mailing list