[cfe-dev] Interact with the preprocessor

Paolo Bolzoni bolzoni at cs.unipr.it
Wed Feb 11 08:27:38 PST 2009


On Tue, 10 Feb 2009 15:04:20 +0100
Sebastian Redl <sebastian.redl at getdesigned.at> wrote:
> > Sebastian Redl <sebastian.redl at getdesigned.at> wrote:

> 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

So I should make a clang::preprocessor, set the predefines, the headers
directories and so go on. I know how to.

And I should check the rules using the member functions of the preprocessor.
I saw the clang::PPCallbacks class, using it I can make my own functions that
are called when:
- a source file is entered (via #include) or exited (because an eof is found
  in a included file.)
- when an #indent or #sccs directive is found.
- when a #pragma comment is found.

This is useful, but using PPCallbacks I can't detect when a macro is expanded
to what.

The clang::preprocessor class itself has many member functions. 
A part of the usual get/set functions for the various parts,
there are various Enter* and Handle* functions that seem needed for
implementation more than for user.

The function void Lex(Token&) returns the next token after all the phases,
LexNonComment() is similar but skips comments.

There are few methods clean representation of Tokens.

About he previous rule example, detect if the user is redefining a
keyword.
The solution is use both Lex() and LexUnexpandedToken() and check if there is
a keyword in the latter and not in the former?
Is there not a easy way to interact with the operation just like the other
PPCallbacks functions?
Am I just missing the obvious?

Thanks for all the trouble,
pb



More information about the cfe-dev mailing list