How to move clang AST manually?

I can traverse specific clangs of AST clang using the recursive lookup class, but I want to skip clang AST node to node.

I would be very grateful if anyone could help me with this.

Thanks in advance.

+6
source share
1 answer

RecursiveASTVisitor can do what you need.

Implementing the member methods TraverseDecl(Decl *x) , TraverseStmt(Stmt *x) and TraverseType(QualType x) for your derived class RecursiveASTVisitor (e.g. MyClass) will do the trick. Combined, these three methods will lead you to each node in your AST.

Example:

 class MyClass : public RecursiveASTVisitor<MyClass> { public: bool TraverseDecl(Decl *D) { // your logic here RecursiveASTVisitor<MyClass>::TraverseDecl(D); // Forward to base class return true; // Return false to stop the AST analyzing } bool TraverseStmt(Stmt *x) { // your logic here RecursiveASTVisitor<MyClass>::TraverseStmt(x); return true; } bool TraverseType(QualType x) { // your logic here RecursiveASTVisitor<MyClass>::TraverseType(x); return true; } }; 
+12
source

Source: https://habr.com/ru/post/989017/


All Articles