www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - CT info about class' children

reply "Yuriy" <yuriy.glukhov gmail.com> writes:
Hello, is there a way of getting CT info of a class' children?

If no, what do you think of a new feature for DMD: template this 
static ctors/dtors:

class A
{
     static this(this T)()
     {
         writeln("static this(", T.stringof, ")");
     }
}

class B : A
{

}

would output:
static this(A)
static this(B)

how it works:
when instantiating (shared) static ctors/dtors of class C, DMD 
will look for template_this_static_ctors/dtors in C, and all of 
it's superclasses, instantiating each with C as this, and adding 
such instances to C as regular static ctors/dtors.
Apr 22 2014
parent reply Jacob Carlborg <doob me.com> writes:
On 2014-04-22 11:20, Yuriy wrote:
 Hello, is there a way of getting CT info of a class' children?
Not in a pretty way but I think this should work: * Implement a custom RTInfo in object.d in druntime. This template will be instantiated with all user defined types * For each type that is a class, check all it's parents via __traits * If a parent is matching what you're looking for then you found a child -- /Jacob Carlborg
Apr 22 2014
parent reply "Yuriy" <yuriy.glukhov gmail.com> writes:
Any way to do it without patching druntime?
Apr 22 2014
next sibling parent Jacob Carlborg <doob me.com> writes:
On 22/04/14 22:50, Yuriy wrote:
 Any way to do it without patching druntime?
Not that I know of. -- /Jacob Carlborg
Apr 22 2014
prev sibling parent reply "Daniel Murphy" <yebbliesnospam gmail.com> writes:
"Yuriy"  wrote in message news:duumbptvbqwknucxgaxi forum.dlang.org... 

 Any way to do it without patching druntime?
Patch the compiler.
Apr 22 2014
parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Wed, 23 Apr 2014 02:34:52 -0400, Daniel Murphy  
<yebbliesnospam gmail.com> wrote:

 "Yuriy"  wrote in message news:duumbptvbqwknucxgaxi forum.dlang.org...
 Any way to do it without patching druntime?
Patch the compiler.
Did you type that with a straight face? -Steve
Apr 23 2014
parent reply "Daniel Murphy" <yebbliesnospam gmail.com> writes:
"Steven Schveighoffer"  wrote in message 
news:op.xerz7jcceav7ka stevens-macbook-pro-2.local...

 Did you type that with a straight face?
:)
Apr 23 2014
parent reply "Yuriy" <yuriy.glukhov gmail.com> writes:
Ok, i've added a pull request to be discussed. It expands RTInfo 
capability as Jacob suggested. What do you think?

https://github.com/D-Programming-Language/druntime/pull/775
Apr 23 2014
parent reply "Martin Nowak" <code dawg.eu> writes:
On Wednesday, 23 April 2014 at 16:06:58 UTC, Yuriy wrote:
 Ok, i've added a pull request to be discussed. It expands 
 RTInfo capability as Jacob suggested. What do you think?

 https://github.com/D-Programming-Language/druntime/pull/775
Looks fairly interesting, because it partly solves the issue to allow custom rtinfo.
Apr 23 2014
parent reply Jacob Carlborg <doob me.com> writes:
On 24/04/14 00:29, Martin Nowak wrote:

 Looks fairly interesting, because it partly solves the issue to allow
 custom rtinfo.
I don't like this solution for custom RTInfo. It requires you to change your type. I would rather modify the compiler to do something like this: * Add a UDA to druntime: "core.attributes.rtInfo" * If any template has the core.attributes.rtInfo UDA attached to itself, instantiate that as is done with core.RTInfo -- /Jacob Carlborg
Apr 23 2014
next sibling parent reply "Yuriy" <yuriy.glukhov gmail.com> writes:
On Thursday, 24 April 2014 at 06:08:11 UTC, Jacob Carlborg wrote:
 On 24/04/14 00:29, Martin Nowak wrote:

 Looks fairly interesting, because it partly solves the issue 
 to allow
 custom rtinfo.
I don't like this solution for custom RTInfo. It requires you to change your type. I would rather modify the compiler to do something like this: * Add a UDA to druntime: "core.attributes.rtInfo" * If any template has the core.attributes.rtInfo UDA attached to itself, instantiate that as is done with core.RTInfo
I guess this could be done without modifying the compiler, just extend RTInfo(T) to support this UDA, but there's a problem with attributes. They don't propagate to class' children, thus they can't solve the main question of this topic.
Apr 23 2014
parent reply "Yuriy" <yuriy.glukhov gmail.com> writes:
 I guess this could be done without modifying the compiler, just 
 extend RTInfo(T) to support this UDA, but there's a problem 
 with attributes. They don't propagate to class' children, thus 
 they can't solve the main question of this topic.
But as an additional feature such UDA might be useful.
Apr 23 2014
parent "Yuriy" <yuriy.glukhov gmail.com> writes:
Also, this whole thing is not only about RT registration, it may 
be used differently. The next usage that comes to mind after RT 
is validating proper inheritance. E.g. Some root class wants it's 
subclasses to always have a default ctor available, which again 
can be verified in CT.
Apr 23 2014
prev sibling parent reply "Martin Nowak" <code dawg.eu> writes:
On Thursday, 24 April 2014 at 06:08:11 UTC, Jacob Carlborg wrote:
 On 24/04/14 00:29, Martin Nowak wrote:

 Looks fairly interesting, because it partly solves the issue 
 to allow
 custom rtinfo.
I don't like this solution for custom RTInfo. It requires you to change your type. I would rather modify the compiler to do something like this: * Add a UDA to druntime: "core.attributes.rtInfo" * If any template has the core.attributes.rtInfo UDA attached to itself, instantiate that as is done with core.RTInfo
This is technically almost identical to having a special _RTInfo template within the type, but it's a cleaner solution.
Apr 24 2014
parent "Yuriy" <yuriy.glukhov gmail.com> writes:
rtInfo through attributes implemented. Jacob, have i done it the 
way you wanted?

https://github.com/D-Programming-Language/druntime/pull/775#issuecomment-41278520
Apr 24 2014