[cfe-dev] Reflection

Stuart Carnie stuart.carnie at gmail.com
Mon Dec 13 12:58:30 PST 2010


Cédric,

Your suggestion is quite reasonable, however in your scenario you must load
the shared object / library into memory and execute code in order to
enumerate the metadata.  You will incur all the performance penalties for
loading shared libraries for executable purposes, such as rebasing, etc.  A
particularly useful scenario for reflection is to scan a directory of
libraries and determine available features or plugins, that would be quite
costly if they all had to be dynamically loaded.  It would be fairly easy to
abstract the reading of the metadata from a specific data section.

My scenario still does not require changes to LLVM or the C++ language, only
changes to Clang to generate the metadata.

Good discussion, either way, as it would make it easy to generate scriptable
C++ libraries in a non-invasive way.

Cheers,

Stu

*Stuart Carnie, CTO*
*manomio <http://manomio.com/> | in retro we trust!*


On Mon, Dec 13, 2010 at 12:12 PM, Cédric Venet <cedric.venet at laposte.net>wrote:

>
>
> 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
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20101213/074c55a8/attachment.html>


More information about the cfe-dev mailing list