Reflection

I've been messing around with something related to this recently.

My requirements comes from games development where game entity details need to be shared across multiple systems (the game editor, scripting language, serialised over the network, load/save, etc). Property systems in game engines are typically implemented using some horrible macro nonsense that register types during setup but that has never been particularly satisfactory. Getting the compiler to do the work would be much better :slight_smile:

However, there are a number of reasons why I don't want the compiler to actually generate any data (such as the Objective-C approach). I still want to maintain tight control over the implementation and determine what does and doesn't get reflected etc. This is why almost all games turn off the built in RTTI and roll their own for example.

I've knocked up a prototype (based on clang naturally) that looks for declaration annotations (either comments or GNU annotate attribute) when walking the AST and spits out the details and metadata to an XML file. The final step of generating some code is pretty trivial formality from that point. The idea would be to use this tool as some kind of pre-build step.

It's only rough but if anyone is interested the code is shared here.

  http://dl.dropbox.com/u/3810428/reflector.rar

Cheers

Gwaredd

Thank you for sharing your code! I will have a look into it.
Can you give some examples of your reasons why you don't want that the
compiler generates such kind of data? I thought that RTTI gets only
turned off by performance-reasons - i am highly interested what else
reasons are out there.