[cfe-dev] Interact with the preprocessor

Sebastian Redl sebastian.redl at getdesigned.at
Tue Feb 10 06:04:20 PST 2009


On Tue, 10 Feb 2009 13:38:16 +0100, Paolo Bolzoni <bolzoni at cs.unipr.it>
wrote:
> On Mon, 09 Feb 2009 18:32:33 +0100
> Sebastian Redl <sebastian.redl at getdesigned.at> wrote:
>> Paolo Bolzoni wrote:
>> > dear cfe-list,
>> > Is the clang preprocessor easy to interact/interface with?  As far we
>> > could understand, the answer should be negative because clang's
>> > preprocessor seems to be tightly integrated with the subsequent
parsing
>> > phases, but we could be wrong (actually, we _hope_ to be wrong), so I
>> > asked here. 
>> The preprocessor and the main lexer are pretty tightly integrated, but
>> the parser is completely separate. You can run some of your validation
>> steps as a run separate from actual compilation and replace the parser.
>> I'm pretty sure you have enough control over the PP to do what you want.
> 
> I am missing what is the best way you are suggesting me.
> 
> What does that replace the parser mean? I saw the clang::Preprocessor but
I
> missed the way to interact with its actions (no virtual functions for
> example)
> 
> Or you mean I should make a completely new parser using clang (as lib)
that
> makes the checks?

Yes, that's what I mean. The things you listed in your mail don't require
any parsing at all; they're only about macros. So you don't really need to
reimplement anything. Just write a program that uses the Clang preprocessor
as a library.

Sebastian



More information about the cfe-dev mailing list