<font face="tahoma,sans-serif">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.  Objective C already has this, so you should be able to to leverage the same concepts for a C++ version.  You already have a great example in Clang; Objective-C provides all it's reflection through the runtime APIs, and therefore a C++ extension could do the same thing.  No built-in's, alterations to LLVM or changes to the C++ language.</font><div>
<font face="tahoma,sans-serif"><br></font></div><div><font face="tahoma,sans-serif">The reflection information is merely metadata generated at compile time to describe the symbols in a specific module.  A lot of the work is around the runtime.</font></div>
<div><font class="Apple-style-span" face="tahoma, sans-serif"><br></font></div><div><font face="tahoma,sans-serif"></font><font class="Apple-style-span" face="tahoma, sans-serif">I imagine some of the things you would need are:</font></div>
<div><ul><li><font class="Apple-style-span" face="tahoma, sans-serif">A runtime, similar to Objective-C's, which needs some of the following capabilities</font></li><ul><li><font class="Apple-style-span" face="tahoma, sans-serif">collection of metadata classes which describe methods, types, etc</font></li>
<li><font class="Apple-style-span" face="tahoma, sans-serif">APIs to read over data sections to extract metadata and generate aforementioned classes</font></li><li><font class="Apple-style-span" face="tahoma, sans-serif">Public APIs to query for this metadata, create instances of classes via name, etc</font></li>
</ul><li><font class="Apple-style-span" face="tahoma, sans-serif">Changes to compiler</font></li><ul><li><font class="Apple-style-span" face="tahoma, sans-serif">Generation of metadata into special data section</font></li>
<li><font class="Apple-style-span" face="tahoma, sans-serif">Generation of entry points / APIs to compiled libraries, executables </font><span class="Apple-style-span" style="font-family: tahoma, sans-serif; ">to allow you to do things like create instances of classes / types by name, etc</span></li>
</ul></ul><div><font class="Apple-style-span" face="tahoma, sans-serif">Cheers,</font></div><div><font class="Apple-style-span" face="tahoma, sans-serif"><br></font></div><div><font class="Apple-style-span" face="tahoma, sans-serif">Stu</font></div>
<div><div><font face="tahoma,sans-serif"></font><font class="Apple-style-span" face="tahoma, sans-serif"><br></font><div><div><span style="font-family:arial, sans-serif;font-size:13px;border-collapse:collapse;color:rgb(80, 0, 80)"><strong><span style="color:rgb(153, 204, 255)">Stuart Carnie, CTO</span></strong><br>
<span style="color:rgb(255, 102, 0)"><strong><a href="http://manomio.com/" style="color:rgb(255, 102, 0)" target="_blank">manomio</a> | in retro we trust!</strong></span></span><br>
<br><br><div class="gmail_quote">2010/12/13 Aurélien Vallée <span dir="ltr"><<a href="mailto:vallee.aurelien@gmail.com">vallee.aurelien@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
This is actually very interesting, and I was also looking to achieve something similar. However, I chose to do the things differently.<div><br><div>As C++ is statically typed, why bother with dynamic reflection, while you can achieve a more efficient, cleaner static reflection?</div>


<div>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.</div>


<div><br></div><div>struct Foo</div><div>{</div><div>  void f();</div><div>  int a;</div><div>};<br><br></div><div>The generated traits may look like (very roughly):</div><div><br></div><div>reflect_trait<Foo>::attribute::count</div>


<div>reflect_trait<Foo>::attribute<1>::type</div><div>reflect_trait<Foo>::attribute<1>::name</div><div>reflect_trait<Foo>::method<1>::type</div><div>reflect_trait<Foo>::method<1>::signature</div>


<div>reflect_trait<Foo>::method<1>::name</div><div>reflect_trait<Foo>::method<1>::param::count</div><div>etc..</div><div><br></div><div>Just my 2 cents</div><div><div><div></div><div class="h5"><br>
<div class="gmail_quote">On Mon, Dec 13, 2010 at 2:49 PM, Russell Harmon <span dir="ltr"><<a href="mailto:russ@eatnumber1.com" target="_blank">russ@eatnumber1.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I'm looking to possibly add support for reflection to clang & llvm.<br>
I'm thinking it would work something like the following:<br>
<br>
- clang inserts reflection information into the compiled bitcode<br>
  - does debugging symbols provide enough information already?<br>
  - should this be a new symbol table, or an extension of the debugging symbols?<br>
- I write a c library which using the symbols from the compiled<br>
binary, allows you to do reflection<br>
  - A typeof() or similar builtin will be necessary<br>
- I'll need to eventually modify llvm's optimizer somehow so that it<br>
doesn't break the reflection information<br>
<br>
Thoughts?<br>
This is going to be my introduction to the llvm & clang code base, so<br>
any advice on where to start?<br>
<font color="#888888"><br>
-Russell Harmon<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
</font></blockquote></div><br><br clear="all"><br></div></div>-- <br>Aurélien Vallée<br>+33 6 47 41 70 37<br>
</div></div>
<br>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div></div></div></div></div>