[cfe-dev] Reflection

Aurélien Vallée vallee.aurelien at gmail.com
Mon Dec 13 07:18:25 PST 2010


This is actually very interesting, and I was also looking to achieve
something similar. However, I chose to do the things differently.

As C++ is statically typed, why bother with dynamic reflection, while you
can achieve a more efficient, cleaner static reflection?
I rather thought of kind of preprocess phase that would add traits on
classes containing their members, methods, etc... The reflection would be
implemented by using these generated traits. We then could add a post
reflection processed target that would simply prints the traits, thus
allowing to have a standard C++ code buildable with any compiler.

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

The generated traits may look like (very roughly):

reflect_trait<Foo>::attribute::count
reflect_trait<Foo>::attribute<1>::type
reflect_trait<Foo>::attribute<1>::name
reflect_trait<Foo>::method<1>::type
reflect_trait<Foo>::method<1>::signature
reflect_trait<Foo>::method<1>::name
reflect_trait<Foo>::method<1>::param::count
etc..

Just my 2 cents

On Mon, Dec 13, 2010 at 2:49 PM, Russell Harmon <russ at eatnumber1.com> wrote:

> I'm looking to possibly add support for reflection to clang & llvm.
> I'm thinking it would work something like the following:
>
> - clang inserts reflection information into the compiled bitcode
>  - does debugging symbols provide enough information already?
>  - should this be a new symbol table, or an extension of the debugging
> symbols?
> - I write a c library which using the symbols from the compiled
> binary, allows you to do reflection
>  - A typeof() or similar builtin will be necessary
> - I'll need to eventually modify llvm's optimizer somehow so that it
> doesn't break the reflection information
>
> Thoughts?
> This is going to be my introduction to the llvm & clang code base, so
> any advice on where to start?
>
> -Russell Harmon
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>



-- 
Aurélien Vallée
+33 6 47 41 70 37
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20101213/23a997d4/attachment.html>


More information about the cfe-dev mailing list