[cfe-dev] Reflection

Cédric Venet cedric.venet at laposte.net
Mon Dec 13 11:12:08 PST 2010



Le 13/12/2010 19:37, Stuart Carnie a écrit :
> Static reflection seems to be very limited.  Reflection is a powerful
> mechanism for being able to analyse a 3rd party executable or dynamic
> library and interact with it at runtime, dynamically invoking APIs.

Static reflection is useful, but I agree it is a (completly) different 
problem. However, your proposal still seems quite complex and invasive. 
Why not juste store the reflection data in C++ structures and expose 
them by the mean of global const static object?

something like:

**** input
struct Foo
{
   void f();
   int a;
};

**** generated by clang
// Contain functions for decoding the reflexion information
struct reflection::class_data_base  {
   void EnumMembers(Fct callback);
   int GetValue(const char* name);
   void Call(const char* name);
   //...
};
// for name mangling
struct reflection::class_data<Foo>:reflection::class_data_base {
   static const int num_members=2;
   // obviously pseudo code :)
   static const datatable=[ "f", &f, "a", &a ... ];
};


This would allow to not modify llvm and C++ code could be generated by 
clang for other compiler. Clang does not need to generate the reflexion 
code, it could create an ast or codegen it directly.

This would also make it portable, no need to access metadata in an 
executable...

Hope this makes sense.
Anyways just my two cents. Good luck on your project, it is really 
interesting and useful (especially with the rise of fast scripting 
language).

regards,
Cédric



More information about the cfe-dev mailing list