RecursiveASTVisitor for const Stmt?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

RecursiveASTVisitor for const Stmt?

Oleg Smolsky via cfe-dev

The RecursiveASTVisitor does not appear to support visiting const-qualified statements since its VisitStmt member function accepts a pointer to an unqualified Stmt:

 

https://clang.llvm.org/doxygen/classclang_1_1RecursiveASTVisitor.html

 

By contrast, the ast_matcher’s getNodeAs function returns a pointer to a const-qualified node type:

 

https://clang.llvm.org/doxygen/classclang_1_1ast__matchers_1_1BoundNodes.html

 

I was using the ast_matcher but reached a point where I needed to apply a RecursiveASTVisitor to the result of a getNodeAs call to check for something deeply nested (without writing more matchers to get me through any possible thing I might encounter on the way down).  Unfortunately, it looks like I can’t do that without resorting to an ugly const_cast and assuming that the visitor does not actually modify any Stmts.

 

Am I missing something?  Is there a const-alternative to RecursiveASTVisitor?

 

Thanks,

Troy


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: RecursiveASTVisitor for const Stmt?

Oleg Smolsky via cfe-dev

I got one reply to this question off-list that suggested ConstStmtVisitor.  That has a slightly different interface than RecursiveASTVisitor which required me to implement a general Visit function and then initiate recursion myself (since it does not have Traverse functions), but it worked.  Just passing that along for anyone who stumbles on this thread later with a similar question.

 

-Troy

 

From: cfe-dev <[hidden email]> On Behalf Of Troy Johnson via cfe-dev
Sent: Tuesday, November 13, 2018 9:35 AM
To: Clang Dev <[hidden email]>
Subject: [cfe-dev] RecursiveASTVisitor for const Stmt?

 

The RecursiveASTVisitor does not appear to support visiting const-qualified statements since its VisitStmt member function accepts a pointer to an unqualified Stmt:

 

https://clang.llvm.org/doxygen/classclang_1_1RecursiveASTVisitor.html

 

By contrast, the ast_matcher’s getNodeAs function returns a pointer to a const-qualified node type:

 

https://clang.llvm.org/doxygen/classclang_1_1ast__matchers_1_1BoundNodes.html

 

I was using the ast_matcher but reached a point where I needed to apply a RecursiveASTVisitor to the result of a getNodeAs call to check for something deeply nested (without writing more matchers to get me through any possible thing I might encounter on the way down).  Unfortunately, it looks like I can’t do that without resorting to an ugly const_cast and assuming that the visitor does not actually modify any Stmts.

 

Am I missing something?  Is there a const-alternative to RecursiveASTVisitor?

 

Thanks,

Troy


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev