[cfe-dev] Handling multiple files with libclang

Douglas Gregor dgregor at apple.com
Fri May 18 08:25:04 PDT 2012


On May 18, 2012, at 5:38 AM, Jacob Carlborg <doob at me.com> wrote:

> What I've understood, libclang can only parse one file/translation unit 
> at the time. I'm working on a tool where I would like to be able to pass 
> multiple files on the command line and process them with libclang. 
> Should I be calling "clang_parseTranslationUnit", or similar, once for 
> each file to accomplish this?

Yes, exactly.

> If I'm supposed to call "clang_parseTranslationUnit" multiple times then 
> my next question is: how do I handle the command line arguments? I know 
> that "clang_parseTranslationUnit" handles the command line arguments but 
> how do I get the rest of the files, the ones that weren't handle by 
> libclang.

Unfortunately, libclang just skips over all files beyond the first one, and doesn't even tell you that it's doing it. We would need to introduce some new API into libclang to parse a command line into its respective pieces to get this information back to the user.

Since you're building the tool yourself, you might consider just tweaking your command-line syntax to make this obvious for your tool where the source files are. For example, do something like:

	your-tool source1.c source2.cpp source3.cpp -- -Wall <command-line arguments>

	- Doug




More information about the cfe-dev mailing list