traversing the AST

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

traversing the AST

Stefan Seefeld
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 ?

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 ? 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() ?

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 ?

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

Thanks for your help !

         Stefan

--

       ...ich hab' noch einen Koffer in Berlin...

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: traversing the AST

Douglas Gregor

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:


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

- Doug

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev