Clang libTooling: How to find which title the AST element came from

Examples found on the Internet for clang tools always run on toy examples, which are usually really trivial C programs.

I am creating a tool that converts source code to C ++ code, which is obviously a very, very difficult task, but clang is appropriate for this task.

The problem I am facing right now is that the AST that clang generates for any C ++ code that uses STL is huge. For example, I have C ++ code for which clang++ -ast-dump ... | wc -l- 67018 lines of horrific AST gobbledygook!

99% of this is standard library material, which I try to ignore in my task of metaprogramming from source to source. So, for this, I just want to filter the files. Suppose that I want to look only at the class definitions in the project headers that I am analyzing (and ignore all the standard library header files), I just need to find out what title my came from CXXRecordDecl!

Can this be done?

Edit: Hope this is a way to do this. Try it now ... The important point is that he should tell me the heading from which the ad came out, and not the cpp file corresponding to the translation unit.

+4
2

, "" AST node Locations. , node , , .

, , , .

+1

, , - , hasName() ( . :

recordDecl(hasName("MyBaseClass")) // etc.

-ast-dump - , , CLang. , . , clang-check CPP . , .

0

All Articles