[Issue 2836] Navigate from ClassInfo to TypeInfo

2015-06-09 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=2836

Andrei Alexandrescu and...@erdani.com changed:

   What|Removed |Added

Version|2.026   |D2

--


[Issue 2836] Navigate from ClassInfo to TypeInfo

2009-05-12 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=2836


Walter Bright bugzi...@digitalmars.com changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution||FIXED




--- Comment #3 from Walter Bright bugzi...@digitalmars.com  2009-05-12 
10:45:19 PDT ---
Done with dmd 1.045 and 2.030.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


Re: Navigate from ClassInfo to TypeInfo

2009-04-16 Thread Frank Benoit
Fawzi Mohamed schrieb:

 For people interested in runtime introspection tango.core.RuntimeTraits
 might be interesting.
 
 Fawzi
 

After the next tango release :)


Re: Navigate from ClassInfo to TypeInfo

2009-04-15 Thread Daniel Keep


davidl wrote:
 ?? Wed, 15 Apr 2009 10:14:42 +0800??Jarrett Billingsley
 jarrett.billings...@gmail.com :
 
 2009/4/14 davidl dav...@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


Re: Navigate from ClassInfo to TypeInfo

2009-04-15 Thread Frank Benoit
Daniel Keep schrieb:
 
 davidl wrote:
 在 Wed, 15 Apr 2009 10:14:42 +0800,Jarrett Billingsley
 jarrett.billings...@gmail.com 写道:

 2009/4/14 davidl dav...@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 :)


Re: Navigate from ClassInfo to TypeInfo

2009-04-15 Thread Daniel Keep


Frank Benoit wrote:
 Daniel Keep schrieb:
 davidl wrote:
 在 Wed, 15 Apr 2009 10:14:42 +0800,Jarrett Billingsley
 jarrett.billings...@gmail.com 写道:

 2009/4/14 davidl dav...@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


Re: Navigate from ClassInfo to TypeInfo

2009-04-15 Thread Frank Benoit
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.



Re: Navigate from ClassInfo to TypeInfo

2009-04-15 Thread Daniel Keep


Frank Benoit wrote:
 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.
 

I remember having to do something similar once.  I think I solved it by
carrying around these:

 struct ExTypeInfo
 {
 TypeInfo ti;
 ClassInfo ci;
 }

That, or you could store them as Objects, and then use upcasts to work
out which it is.

 if( auto ti = cast(TypeInfo) info )
 // It's a general type info

 else if( auto ci = cast(ClassInfo) info )
 // It's a class

 else
 assert(false);

  -- Daniel


Re: Navigate from ClassInfo to TypeInfo

2009-04-15 Thread Frank Benoit
Daniel Keep schrieb:
 
 Frank Benoit wrote:
 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.

 
 I remember having to do something similar once.  I think I solved it by
 carrying around these:
 
 struct ExTypeInfo
 {
 TypeInfo ti;
 ClassInfo ci;
 }
 
 That, or you could store them as Objects, and then use upcasts to work
 out which it is.
 
 if( auto ti = cast(TypeInfo) info )
 // It's a general type info

 else if( auto ci = cast(ClassInfo) info )
 // It's a class

 else
 assert(false);
 
   -- Daniel

Ick! Right, that is doable.
But still, D lacks this navigation and it should be added.
Working with Object is really the ugly way.





Re: Navigate from ClassInfo to TypeInfo

2009-04-15 Thread Frank Benoit
Frank Benoit schrieb:
 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)?

See also:
http://d.puremagic.com/issues/show_bug.cgi?id=2836


Re: Navigate from ClassInfo to TypeInfo

2009-04-15 Thread grauzone

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)?


I also did hit this issue. Fortunately, I never get a ClassInfo of a 
class whose static type I didn't see at least once before. This means I 
can get both the TypeInfo and ClassInfo from the static type, and put 
them into a global AA like ClassInfo[TypeInfo].


Re: Navigate from ClassInfo to TypeInfo

2009-04-15 Thread Steven Schveighoffer
On Wed, 15 Apr 2009 02:41:50 -0400, Frank Benoit  
keinfarb...@googlemail.com wrote:



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.




Frank, Daniel is right, TypeInfo_Class simply adds a classinfo member.   
Each class type does not use a different TypeInfo derivative, it simply  
uses a different *instance*.  For everything that doesn't use the  
classinfo member in TypeInfo_Class, you can use Object's typeinfo, which  
should be accurate.


For everything else, use the classinfo.

Functions that you can use from Object's typeinfo:

getHash
equals
compare
tsize
flags
swap
next
init


Functions that use classinfo:

offTi
toString
opCmp
opEquals

Which you can simply call classinfo's appropriate functions.

You can also easily build a TypeInfo_Class based on the object:

scope info = new TypeInfo_Class();
info.info = obj.classinfo;

-Steve


Navigate from ClassInfo to TypeInfo

2009-04-14 Thread Frank Benoit
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)?


Re: Navigate from ClassInfo to TypeInfo

2009-04-14 Thread Jarrett Billingsley
2009/4/14 davidl dav...@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.


Re: Navigate from ClassInfo to TypeInfo

2009-04-14 Thread davidl
在 Wed, 15 Apr 2009 10:14:42 +0800,Jarrett Billingsley  
jarrett.billings...@gmail.com 写道:



2009/4/14 davidl dav...@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/