[cfe-dev] Clang beginner - how to parse multiple files?

Manuel Klimek klimek at google.com
Thu Apr 5 13:21:54 PDT 2012

On Thu, Apr 5, 2012 at 9:50 PM, Yaakov Davis <yaakov.davis at gmail.com> wrote:
> OK, thanks for the detailed info, I'll look into the linking process.

I might be able to give some tips if you can tell me more about what
you're actually trying to do.

If you want to run over the ASTs of multiple TUs in one file, you can
do that with the tooling infrastructure that's in. See
for an example of how to set it up.

The unit tests for the tooling:
give you ideas of how to implement ASTConsumers and ASTFrontendActions
to get you started.

The ASTContext for each run will be provided if you implement
HandleTranslationUnit in the ASTConsumer.


> On Apr 5, 2012 10:39 PM, "Douglas Gregor" <dgregor at apple.com> wrote:
>> On Apr 5, 2012, at 12:15 PM, Yaakov Davis <yaakov.davis at gmail.com> wrote:
>> > Can the different compilers use the same ASTContext?
>> No, they must have different ASTContexts.
>> > E.g. say a.cpp contains Foo::bar() and b.cpp contains Foo::bar2(); will
>> > the Foo type in the semantic DeclContext contain both foo and foo2 after
>> > parsing both files?
>> No, it won't. Separate translation units are separate until something
>> comes in to link them together.
>> > Could you please provide an example how to setup the parsers?
>> Sorry, I don't have time to write up a complete example now, but this kind
>> of thing will get a lot easier soon with the current work on Tooling
>> infrastructure.
>>        - Doug
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

More information about the cfe-dev mailing list