determining header inclusion path

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

determining header inclusion path

Naoya Maruyama
Hi,

I'm trying to find how each C declaration is included from the
originating source file. Specifically, say, I have a Decl object, and
I want to know where this Decl is declared. And if it's in a header
file, I want to know the inclusion path from the originating source
file. For example, if main.c includes foo.h, and foo.h includes bar.h,
I want to know the inclusion path of each declaration in bar.h to be
something like "main.c->foo.h->bar.h". Would anybody please tell me
how to find this information from Decl objects in clang?

Regards,

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

Re: determining header inclusion path

Douglas Gregor

On Jul 1, 2010, at 1:18 AM, Naoya Maruyama wrote:

> Hi,
>
> I'm trying to find how each C declaration is included from the
> originating source file. Specifically, say, I have a Decl object, and
> I want to know where this Decl is declared. And if it's in a header
> file, I want to know the inclusion path from the originating source
> file. For example, if main.c includes foo.h, and foo.h includes bar.h,
> I want to know the inclusion path of each declaration in bar.h to be
> something like "main.c->foo.h->bar.h". Would anybody please tell me
> how to find this information from Decl objects in clang?

Get the location of the decl (with Decl::getLocation()), then use the SourceManager to retrieve information about that source location: whether it comes from a macro instantiation, what file it was instantiated in, and (then) the include path.

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