To give an example:
Say I have a very simple library that allows C code to be called from another language L.
In order to use your C code from L you need to change certain constructs in your C code such as changing function types to void, replacing function parameters with a single library type etc. So your C code might change from something like this:
double foo(double bar, double baz) {
return bar + baz;
}
to something like this:
void foo(LibraryArgs args) {
double bar = args.get(1);
double baz = args.get(2);
setReturn(baz + bar);
}
and now your function can be called from L.
I'm trying to write a program that does this transformation automatically when it sees a function marked with some sort of annotation, perhaps something like:
@MakeCallableFromL
double foo(double bar, double baz) {
return bar + baz;
}
But I can't seem to find a solution short of writing a near complete parser for C. Would there be a simpler approach to solving this sort of problem?