[cfe-dev] Extracting the include tree from a source file
Bertjan Broeksema
broeksema at kde.org
Mon Nov 15 08:17:08 PST 2010
Hi all,
For a small program [1] I'm working on to analyze physical properties of a
C++ project, I'm interested in integrating clang. The first (and I think
relative simple) step I'd like to take is using clang to extract the
included headers.
My program already has an internal project graph containing source files,
object files, executables and (external) libraries. This graph I want to
complete with the headers.
So my question is, what is the easiest way, using clang (programmatically)
to extract the include tree given a path to a source file, a list of include
directories (i.e. the one past to the compiler, not internal paths) and a
list of defines (again, only the defines past to the compiler).
I attached some initial code I'm playing with (not integrated with the rest
of my program, just to get a feeling on how to use clang). Currently it
somewhat works, but it doesn't find system includes (i.e. the headers that
the compiler normally internally resolves) and if something goes wrong, e.g.
a header is not found, it just plain crashes. Also, its not clear to me how
to set defines and finally most important, how to actually get the include
tree after (or during?) preprocessing.
Any help is appreciated.
Cheers,
Bertjan
[1] http://gitorious.org/cpp-dependency-analyzer
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.ml.cpp
Type: text/x-c++src
Size: 2192 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20101115/1799b4f7/attachment.cpp>
More information about the cfe-dev
mailing list