[cfe-dev] Reflection

variadic.template variadic.template at googlemail.com
Wed Dec 15 16:54:15 PST 2010


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.

> 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 :)
>
> 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
>
> -----Original Message-----
> From: David Chisnall <theraven at sucs.org>
> Subject: Re: [cfe-dev] Reflection
> To: "variadic.template" <variadic.template at googlemail.com>
> Cc: "cfe-dev at cs.uiuc.edu" <cfe-dev at cs.uiuc.edu>
> Message-ID: <FE1936C9-D71A-4AB9-B8A4-06269429949C at sucs.org>
> Content-Type: text/plain; charset=us-ascii
>
> On 14 Dec 2010, at 22:04, variadic.template wrote:
>
>> Introspecting C++/Objective-C-classes is what i am currently trying to
>> do with clang. The idea of adding reflections to C/C++/ObjC is in mind
>> for quite a long time. My main purpose is the
>> serialization/deserialization of more-or-less complex objects into
>> different formats, without having the need of using
>> boost.serialization or something similar. For this purpose, traits
>> would be sufficient and i think they should be included in an approach
>> of realizing introspection. Of course, there should also be a dynamic
>> runtime for the use of doing some scripting or other use-cases, which  
>> already have been mentioned.
>> Also, the use of reflection-specific attributes should bear in mind.
>
> Objective-C classes already contain introspection information.  In the  
> EtoileSerialise framework, we use the information about instance  
> variable layout to automatically serialise most Objective-C classes  
> (anything that doesn't contain pointers to C types - those need some  
> manual assistance, since we can't tell if they're arrays, and if they  
> are what their size is).  LanguageKit, similarly, uses this information  
> when compiling classes from Smalltalk or EScript to access instance  
> variables in the superclass and to determine the correct types when  
> calling Objective-C methods.
>
> If you want to add metadata to Objective-C classes, be careful that  
> you're not duplicating something that's already there...
>
> David
>
> -- Sent from my brain
>
>
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list