[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Translation of C structs [a rant]

[rant snipped]

Simplicity of transmuting the syntax has probably never been central design
element driving pretty much any language design.

Common Lisp (or perhaps even moreso, Scheme) comes close, but it's
constantly being flamed at its "horrible syntax". Syntaxes with easy machine
parsing tend to be poo-poo'd by programmers. Nobody LIKEs XML, we just deal
with it.

And frankly, the syntax isn't really the problem. The problem is the fact
that the meta-information generated by the compiler is rarely kept around
for use by other tools in some form besides the original syntax.

Java has a nice reflection api that would let you do what you want (I
think), without access to the source code. So, that leads me to another
thought that may work for you.

Have you considered deciphering the information stored in the .o files of
C/C++ programs when they are created with the debugging information? Clearly
things like gdb are able to learn quite a bit about a program from this
information. With C++ you have the problem with name mangling to potentially
deal with, but I'll bet that you can get at quite a bit of what you're
looking for if you can take all of the structures you are interested in,
compile them into a simple stub dummy.c file (that perhaps needs to
reference everything just once), and then look through the meta data
generated for the debugger. Mind you this isn't the obvious path, but
clearly the information is there. Even better, once done, you should have to
do it once, with little regard to future syntax changes and such to C or

The raw syntax is always difficult to handle, some kind of reflection system
is far easier I think, minimally because you know you're interpret
everything properly and there isn't any misunderstand between what you think
the compiler is doing and what the compiler DID do.


Will Hartung