Interact with clang's preprocessor

dear cfe-list,

I would like to interface with the clang preprocessor in order to check
programming-style rules. For instance:

`Arguments to a function-like macro shall not contain tokens that look
like preprocessing directives.'

An example of violation.
------->
#define AB define
#define C A ## B
#define macro(X) X
int define;
int f() {
   return macro(C);
}
-------<

My own code (which checks the arguments' text) should be called:
   - *before* function-macro expansion, but
   - *after* the expansion of the arguments.

Is there a way to do this using the clang preprocessor (e.g., by
suitably registering my own code as a callback function)?

What is the simplest way to achieve this?

Thanks
pb

Paolo Bolzoni wrote:-

dear cfe-list,

I would like to interface with the clang preprocessor in order to check
programming-style rules. For instance:

`Arguments to a function-like macro shall not contain tokens that look
like preprocessing directives.'

An example of violation.
------->
#define AB define
#define C A ## B
#define macro(X) X
int define;
int f() {
   return macro(C);
}
-------<

That doesn't look like a pp directive; there is no '#', and it is
certainly not at the start of a logical line.

  return macro(
#ifdef foo
#endif
  );

would be such an example.

Neil.

clang already warns about this iirc.

-Chris