[cfe-dev] Running CLang as a preprocessor
dgregor at apple.com
Wed Jan 19 16:34:49 PST 2011
On Jan 19, 2011, at 3:40 PM, Stefan Seefeld wrote:
> Is it possible to use libclang to preprocess source code, i.e. skip the
> actual parsing ?
> I have tried clang_parseTranslationUnit(), passing "-E" in the flags
> argument, but that didn't have the desired effect. (It gave me a
> "warning: argument unused during compilation: '-fsyntax-only'" warning
> and then did the parse anyhow.)
> Is there another libclang function I should use instead ? (I'm
> interested in all the normal preprocessor information, such as header
> inclusions, macro definitions, and macro expansions.
There is no way to invoke (only) the preprocessor through the libclang interface, although you can get at the artifacts of preprocessing (inclusions, macro definitions, macro instantiations, etc.) through the cursor interface.
You can use clang_tokenize() to re-lex parts of the buffer.
More information about the cfe-dev