I am using libclang (Python bindings) to parse some C++ code.
I need to distinguish includes that resolve to system headers, e.g., #include <algorithm>, from includes that resolve to project-local headers, e.g., #include "my_header.h".
The problem is that I cannot find a way to retrive this information from the libclang AST.
Some thoughts/considerations:
- the information has to be there somewhere, since running clang with
-E(only run preprocessor), system includes are marked by appending the flag3when they are included. Example:
# 1 "/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/exception" 1 3 - of course, I could invoke the preprocessor myself and match the results, but this adds overhead and more potential sources for bugs
- simply look for
<>vs""in the tokens of the include statement does not work, as they just determine lookup order. - checking the beginning of the expanded include file path for sth like
/usr/lib/...does not work, since it is not platform independent and the user can add custom "system" directories via-isystem.
I hope you can help me out on this :)