[cfe-dev] Getting started with source code analysis using CLang
Douglas Gregor
dgregor at apple.com
Tue Mar 16 15:07:23 PDT 2010
On Mar 14, 2010, at 2:48 PM, Stefan Seefeld wrote:
> Hello,
>
> I'm looking at various bits of CLang code, trying to figure out the very
> first steps needed to:
>
> 1) parse a source file into an internal representation suitable for
> static code analysis.
> 2) navigate that representation (via CIndex, as Doug suggested).
CIndex can do both of these. clang_createTranslationUnitFromSourceFile(), part of the CIndex library, makes it easy to parse a source file into an AST.
> Can anyone give me some hints as to what specific API to use for this ?
clang_createTranslationUnitFromSourceFile() is the main entry point; clang_visitChildren() will let you walk the AST. That's most of it!
> Is there some documentation for this that I have overlooked ?
CIndex is documented here:
http://clang.llvm.org/doxygen/group__CINDEX.html
there's a little c-index-test program in Clang's source tree that shows how to load a source file and walk the AST, printing some information about the entities reached.
- Doug
More information about the cfe-dev
mailing list