I need to do some manipulation of the source source in the Linux kernel. I tried using clang for this purpose, but there is a problem. Clang preprocesses the source code, that is, the macro, and enables the extension. This causes clang to sometimes create broken C code from the perspective of the Linux kernel. I cannot support all changes manually, as I expect to have thousands of changes per file.
I tried ANTLR, but public grammars are incomplete and not suitable for projects such as the Linux kernel.
So my question is the following. Are there any ways to do source manipulation with source for C code without preprocessing?
Assume the following code.
#define AAA 1 void f1(int a){ if(a == AAA) printf("hello"); }
After applying source manipulation with the source, I want to get this
#define AAA 1 void f1(int a){ if(functionCall(a == AAA)) printf("hello"); }
But Clang, for example, produces the following code that does not meet my requirements, that is, it extends the AAA macro
#define AAA 1 void f1(int a){ if(functionCall(a == 1)) printf("hello"); }
I hope I was clear enough.
Edit
The above code is just an example. The source-source processing that I want to do is not limited to replacing the if() operator, but also inserting a unary operator before the expression, replacing the arithmetic expression with its positive or negative value, etc.
Decision
There is one solution that I have found for myself. I use gcc to create preprocessed source code, and then use Clang. Then I have no problems with the extension of macros and include, since this work is done by gcc. Thanks for answers!