[cfe-dev] determining header inclusion path

Douglas Gregor dgregor at apple.com
Thu Jul 1 07:07:42 PDT 2010

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

More information about the cfe-dev mailing list