[cfe-dev] traversing the AST

Douglas Gregor dgregor at apple.com
Thu Mar 18 10:03:36 PDT 2010


On Mar 18, 2010, at 9:54 AM, Stefan Seefeld wrote:

> Doug,
> 
> thanks for the clarification on invalid source locations. May I assume 
> that whenever the filename is 0, the location corresponds to "builtin", 
> i.e. injected code, preceding the actual source code ?

When the filename is 0, it means that the entity you're looking at was implicitly declared by the compiler.

> I'v got a little further now. Using clang_visitChildren() on a file 
> containing "int i;" will report a cursor with kind CXCursor_VarDecl, 
> where the location corresponds to the position after the declarator "i" 
> (and the spelling yields the declarator itself).
> Is that intended ?

The location should point at the first character of "i".

> I wonder what "VarDecl" stands for, Declarator, or 
> Declaration. If this really reports the declarator, how can I access the 
> (full) declaration. Why is this not directly visited via 
> clang_visitChildren() ?

We're pointing at the declaration of the variable "i". 

> More generally, what entities does clang_visitChildren() report, and, 
> assuming this is just a subset of the full AST, how may I access the rest ?

Everything listed in the CXCursorKind is reported by this API. Not everything in C++ is reported exposed, but it's relatively simple to expose new declaration kinds.

> I'm sorry to come up with all those entry-level questions. Perhaps there 
> is some documentation available, which I haven't found yet.

The Doxygen documentation is here:

	http://clang.llvm.org/doxygen/group__CINDEX.html

In c-index-test shows how to poke the API.

	- Doug
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20100318/9cda9db6/attachment.html>


More information about the cfe-dev mailing list