Will Leeson
Will Leeson

Reputation: 49

How do I get the pointer associated with a node in the ClangAST using the c++ API?

When you dump the AST of a C program using clang, each node in the tree has a unique hexcode.

https://stephenwzl.github.io/images/ast-dump.png

For example, x in the above image has 0x7efcf7017538.

I am trying to do some calculations based on the AST of C programs. I need to be able to connect variable references with their previous use and assignments. I think the best way to do this is to use the unique hexcode clang assigns to a VarDecl. I've tried looking through the clang API and reverse engineering the dump function, but i can't seem to find how this value is stored. I'm using the recursive visitor to walk the tree. Is there a variable I have to reference for a node or a function I have to call on a node?

Upvotes: 2

Views: 152

Answers (1)

Will Leeson
Will Leeson

Reputation: 49

So, it looks like it's literally just the actual pointer to the stmt, decl, etc.

So, if you have a stmt* s and you want to get the pointer, simply cout s

Upvotes: 2

Related Questions