Time for std.reflection

Malte Skarupke malteskarupke at web.de
Mon Nov 19 18:54:47 PST 2012


I like it. First a couple details:

> class ClassInfo {
> @property:
>     string name();
>     string baseName();
>     string parentName(); // if applicable, null otherwise
>     string[] interfaces();
>     bool isShared();
>     Protection protection();
>     DataMemberInfo[] data();
>     MethodInfo[] methods();
>     Object defaultConstructor();
>     ...
> }

Why do you not use recursion here? Why not
ClassInfo base();
ClassInfo parent();
and then you get baseName by calling base.name;

> Then for an e.g. method declaration we'd have:
>
> class MethodInfo {
> @property:
>     string name();
>     bool isStatic(), isFinal(), isOverride();
>     Protection protection();
>     string[] parameterTypes();
>     string[] parameterNames();
> }

Do you think there'll be any way to get the actual types of the 
arguments and the return type back from the struct? I think that 
without compiler magic or an uncomfortable amount of templates it 
probably won't be possible, but I might be wrong.


Now to my big complaint:

I really dislike making the runtime api accessible through a 
mixin. I'd much prefer making it a non-member template. Reasons 
are
a) I don't want to store the runtime information in my type. A 
vtable pointer should be enough to get that information. Maybe 
use it as an index into a global immutable associative array. For 
modules and non-class types the name can act as a unique 
identifier.
b) It'd make it possible to get runtime information on types that 
I get from libraries.
c) It would lead to less coupling.
d) It would discourage writing types that rely on runtime 
reflection, but it would not make it impossible.


More information about the Digitalmars-d mailing list