Jump to page: 1 2
Thread overview
Navigate from ClassInfo to TypeInfo
Apr 14, 2009
Frank Benoit
Apr 14, 2009
Christopher Wright
Apr 15, 2009
davidl
Apr 15, 2009
davidl
Apr 15, 2009
Daniel Keep
Apr 15, 2009
Frank Benoit
Apr 15, 2009
Daniel Keep
Apr 15, 2009
Frank Benoit
Apr 15, 2009
Daniel Keep
Apr 15, 2009
Frank Benoit
Apr 16, 2009
davidl
Apr 16, 2009
Fawzi Mohamed
Apr 16, 2009
Frank Benoit
Apr 15, 2009
Frank Benoit
Apr 15, 2009
grauzone
April 14, 2009
I need to retrieve an instance of TypeInfo from an object instance at runtime.

TypeInfo info = typeid(obj) // does not work, only compile time

TypeInfo info = obj.classinfo.????; // how to navigate to TypeInfo?

Is that possible?
If not, why? And can it be added (D1)?
April 14, 2009
Frank Benoit wrote:
> I need to retrieve an instance of TypeInfo from an object instance at
> runtime.
> 
> TypeInfo info = typeid(obj) // does not work, only compile time
> 
> TypeInfo info = obj.classinfo.????; // how to navigate to TypeInfo?
> 
> Is that possible?
> If not, why? And can it be added (D1)?

There is no way that I know of to do so, and I've looked into the issue previously. -- I don't know how TypeInfo is instantiated; I imagine it's in the data segment of the executable; so it should be possible to examine all symbols in an executable to find TypeInfo instances and determine what they refer to. However, the language and runtime lack support for this.
April 14, 2009
On Wed, Apr 15, 2009 at 1:35 AM, Christopher Wright <dhasenan@gmail.com> wrote:
> Frank Benoit wrote:
>>
>> I need to retrieve an instance of TypeInfo from an object instance at runtime.
>>
>> TypeInfo info = typeid(obj) // does not work, only compile time
>>
>> TypeInfo info = obj.classinfo.????; // how to navigate to TypeInfo?
>>
>> Is that possible?
>> If not, why? And can it be added (D1)?
>
> There is no way that I know of to do so, and I've looked into the issue previously. -- I don't know how TypeInfo is instantiated; I imagine it's in the data segment of the executable; so it should be possible to examine all symbols in an executable to find TypeInfo instances and determine what they refer to. However, the language and runtime lack support for this.
>

Seems reasonable to me to add a TypeInfo field to ClassInfo.
April 15, 2009
在 Wed, 15 Apr 2009 02:16:44 +0800,Frank Benoit <keinfarbton@googlemail.com> 写道:

> I need to retrieve an instance of TypeInfo from an object instance at
> runtime.
>
> TypeInfo info = typeid(obj) // does not work, only compile time
>
> TypeInfo info = obj.classinfo.????; // how to navigate to TypeInfo?
>
> Is that possible?
> If not, why? And can it be added (D1)?

Send this object to vararg func, and retrieve the TypeInfo there and return?

-- 
使用 Opera 革命性的电子邮件客户程序: http://www.opera.com/mail/
April 15, 2009
2009/4/14 davidl <davidl@nospam.org>:
>
> Send this object to vararg func, and retrieve the TypeInfo there and return?

No.  The typeinfo passed to vararg functions is also determined at compile-time.
April 15, 2009
在 Wed, 15 Apr 2009 10:14:42 +0800,Jarrett Billingsley <jarrett.billingsley@gmail.com> 写道:

> 2009/4/14 davidl <davidl@nospam.org>:
>>
>> Send this object to vararg func, and retrieve the TypeInfo there and return?
>
> No.  The typeinfo passed to vararg functions is also determined at compile-time.

so it's a bug?

I think vararg funcs always want the real typeinfo of the object

-- 
使用 Opera 革命性的电子邮件客户程序: http://www.opera.com/mail/
April 15, 2009

davidl wrote:
> ÔÚ Wed, 15 Apr 2009 10:14:42 +0800£¬Jarrett Billingsley <jarrett.billingsley@gmail.com> дµÀ:
> 
>> 2009/4/14 davidl <davidl@nospam.org>:
>>>
>>> Send this object to vararg func, and retrieve the TypeInfo there and return?
>>
>> No.  The typeinfo passed to vararg functions is also determined at compile-time.
> 
> so it's a bug?
> 
> I think vararg funcs always want the real typeinfo of the object

No, they get the typeinfo of what they're passed.

> class A {}
> class B : A {}
>
> void foo(...) {}
>
> void bar(A a) { foo(a); }
>
> void main()
> {
>     scope b = new B;
>     bar(b);
> }

bar cannot possibly know what the "real" TypeInfo of a is.  But that doesn't matter because it's passing an A with A's TypeInfo.  And if foo is maybe interested in Bs, then it can just try to up-cast.

  -- Daniel
April 15, 2009
Daniel Keep schrieb:
> 
> davidl wrote:
>> 在 Wed, 15 Apr 2009 10:14:42 +0800,Jarrett Billingsley <jarrett.billingsley@gmail.com> 写道:
>>
>>> 2009/4/14 davidl <davidl@nospam.org>:
>>>> Send this object to vararg func, and retrieve the TypeInfo there and return?
>>> No.  The typeinfo passed to vararg functions is also determined at compile-time.
>> so it's a bug?
>>
>> I think vararg funcs always want the real typeinfo of the object
> 
> No, they get the typeinfo of what they're passed.
> 
>> class A {}
>> class B : A {}
>>
>> void foo(...) {}
>>
>> void bar(A a) { foo(a); }
>>
>> void main()
>> {
>>     scope b = new B;
>>     bar(b);
>> }
> 
> bar cannot possibly know what the "real" TypeInfo of a is.  But that doesn't matter because it's passing an A with A's TypeInfo.  And if foo is maybe interested in Bs, then it can just try to up-cast.
> 
>   -- Daniel

Or it can request the classinfo of the passed object. Hey, and now the typeinfo please :)
April 15, 2009

Frank Benoit wrote:
> Daniel Keep schrieb:
>> davidl wrote:
>>> 在 Wed, 15 Apr 2009 10:14:42 +0800,Jarrett Billingsley <jarrett.billingsley@gmail.com> 写道:
>>>
>>>> 2009/4/14 davidl <davidl@nospam.org>:
>>>>> Send this object to vararg func, and retrieve the TypeInfo there and return?
>>>> No.  The typeinfo passed to vararg functions is also determined at compile-time.
>>> so it's a bug?
>>>
>>> I think vararg funcs always want the real typeinfo of the object
>> No, they get the typeinfo of what they're passed.
>>
>>> class A {}
>>> class B : A {}
>>>
>>> void foo(...) {}
>>>
>>> void bar(A a) { foo(a); }
>>>
>>> void main()
>>> {
>>>     scope b = new B;
>>>     bar(b);
>>> }
>> bar cannot possibly know what the "real" TypeInfo of a is.  But that doesn't matter because it's passing an A with A's TypeInfo.  And if foo is maybe interested in Bs, then it can just try to up-cast.
>>
>>   -- Daniel
> 
> Or it can request the classinfo of the passed object. Hey, and now the typeinfo please :)

Ok.  What do you propose to do with this TypeInfo?

The ONLY thing a given TypeInfo_Class gives you is the ClassInfo, which you already have.  The TypeInfo object itself gives you getHash, equals and compare, all of which are in Object and thus redundant, tsize which is the size of a pointer, swap which I can't see a use for, next which is useless, init which is also redundant and flags which is already in ClassInfo.

Again, why do you even want that specific TypeInfo when it is less useful than the ClassInfo?

  -- Daniel
April 15, 2009
Daniel Keep schrieb:
> Ok.  What do you propose to do with this TypeInfo?
> 
> The ONLY thing a given TypeInfo_Class gives you is the ClassInfo, which you already have.  The TypeInfo object itself gives you getHash, equals and compare, all of which are in Object and thus redundant, tsize which is the size of a pointer, swap which I can't see a use for, next which is useless, init which is also redundant and flags which is already in ClassInfo.
> 
> Again, why do you even want that specific TypeInfo when it is less useful than the ClassInfo?
> 
>   -- Daniel

I need to have a "something" to retrieve and pass around to hold all
available information about a type. Including classes, interfaces and
primitives.
Because of ClassInfo cannot have information about primitives, I need to
work with TypeInfo.
Because of I have that need to retrieve that "something" from any object
reference also, i need a way from classinfo to typeinfo.

« First   ‹ Prev
1 2