Templating preprocessor for C
One of the (many) things I truly hate about the C preprocessor and C++ templates instantiation is although they create input to the compiler....
Their output (the compilers input) is neither visible (by default or to gdb) or readable (if you intercept it). In principle, there is no reason why a C / C++ file cannot be run through some sort of templating pre-processor and output perfectly human readable C/C++ as an intermediate file. It would be trivial to knock up ruby pre-processor that does something like this... but a couple of things are awkward to manage... (limiting scope, variable instantiation, token-pasting, stringification, handling expansion tokens in comments and strings...) Not impossible, I could do something.... but hey, I'd hate to reinvent the wheel. Does anyone know of an open source templating / macro engine that inputs beautiful human readable template definitions and outputs beautiful human readable C. I don't think m4 qualifies as beautiful human readable input. If all else fails cpp -P -C | indent might work. All suggestions welcome - thanks. |
Quote:
|
FYI, the latest gcc (4.8) can show macro context of errors:
Quote:
Quote:
|
Quote:
I don't think template instantiation output is available in the source language or in any readable form. Quote:
The C preprocessor was intentionally designed with nasty (from a C programmer's viewpoint) limitations to make it easy to separate a C preprocessor from a C compiler. Templating has no similar restrictions. The whole front end of a C++ compiler is needed to understand C++ code well enough to do template expansion. Quote:
Quote:
Quote:
|
Quote:
Apart from the complexity of understanding the scope of a template parameters.... I thought it was a pretty much mechanical replace all template parameters with whatever it is instantiated with. Thereafter much of the dark magic is about function overloading. Which parts of template instantiation step (prior to handling overloading) do you feel requires a full compiler? Quote:
The hard problem now seems to be generating separate header and .c files in a DRY fashion. Which sort of implies I need to create a facility to #include .template files and track the dependencies. Hmm. |
Quote:
Hmm. Sort of aiming for something simpler.... closer to cpp -E -P | indent. but I will keep that in mind. |
All times are GMT -5. The time now is 01:21 PM. |