Yet another "compile-time reflection revisited" proposal

RivenTheMage riven-mage at id.ru
Tue Nov 29 12:11:34 PST 2011


*1) Replace all symbol-related traits with ".metainfo" property*

__traits(isAbstractClass, A) ==> A.metainfo.isAbstractClass

__traits(A.func, isVirtualFunction) ==> 
by name: A.metainfo.members["func"].isVirtualFunction
by index: A.metainfo.members[N].isVirtualFunction

__traits(hasMember, A, "func") ==> A.metainfo.members.find("func")

Aliasing should be posssible:
---
alias A.metainfo.members mymeta;
mymeta.find("func");
---


*2) Replace rest of traits with "meta" keyword*

__traits(compiles, ...) ==> meta.compiles(...)


*4) Add special extendable namespace, accesible through "meta" keyword*

The namespace can be extented by special file "meta.d" which should be a part
of D runtime. Actually, it's the same thing as std.traits, the intention is
to put all reflection stuff under one roof.

instead of:
---
import std.traits; 
int foo(); 
ReturnType!(foo) x;
---

it would be:
---
int foo();
meta.ReturnType!(foo) x;
---


*6) Replace identificator-related "is" expressions with ".metainfo" property*

is(Identifier ...) ==> Identifier.metainfo.isXXX(...)


*7) Replace rest of "is" expressions with "meta.is"*

is(...) ==> meta.isXXX(...)


*5) Replace "typeid" keyword with ".typeinfo" property*

typeid(int) ==> int.typeinfo
typeid(typeof(x)) ==> typeof(x).typeinfo
typeid(i++) ==> (i++).typeinfo


Thoughts?


More information about the Digitalmars-d mailing list