www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Reflection would be really nice

reply "Frank Benoit (keinfarbton)" <benoit tionex.removethispart.de> writes:
A little hello world in SWT is actually bigger then 7 MB.
This is due to the generated reflection code, and the need to pull in
the whole SWT in the initialization phase.

With rudimentary reflection, this would be much better.

I also think, there would be many application possible with this kind of
stuff.

class ClassInfo{
	Field[] fields;
	Method[] methods;
	Constructors[] constructors;
	static ClassInfo[] allClasses; // probably the most important
}

class Field{
	uint offset;
	TypeInfo type;
	Attribute[] attribs;
	char[] name;
	void* getPtr( Object* obj );
}
class Parameter{
	char[] name;
	TypeInfo type;
	Attribute[] attribs;
}
class Method{
	uint offset;
	TypeInfo ret_type;
	Attribute[] attribs;
	char[] name;
	Parameter[] params;
	void* getPtr( Object* obj = null );
}
class Constructor{
	Attribute[] attribs;
	char[] name;
	void* getPtr();
	Parameter[] params;
}
Apr 19 2007
next sibling parent reply Walter Bright <newshound1 digitalmars.com> writes:
Frank Benoit (keinfarbton) wrote:
 class ClassInfo{
 	Field[] fields;
 	Method[] methods;
 	Constructors[] constructors;
 	static ClassInfo[] allClasses; // probably the most important
 }

allClasses is already there, see Classinfo.find().
Apr 19 2007
next sibling parent reply "Frank Benoit (keinfarbton)" <benoit tionex.removethispart.de> writes:
 
 allClasses is already there, see Classinfo.find().

Didn't know about it :) Now i can test if "org.eclipse.swt.SWT.SWT" exists. If so, is there a way to call the static method "static_this()"?
Apr 19 2007
next sibling parent Sean Kelly <sean f4.ca> writes:
Frank Benoit (keinfarbton) wrote:
 allClasses is already there, see Classinfo.find().

Didn't know about it :)

It was added in 1.011 (IIRC), so that's not surprising :-) Sean
Apr 19 2007
prev sibling parent reply Walter Bright <newshound1 digitalmars.com> writes:
Frank Benoit (keinfarbton) wrote:
 allClasses is already there, see Classinfo.find().

Didn't know about it :) Now i can test if "org.eclipse.swt.SWT.SWT" exists. If so, is there a way to call the static method "static_this()"?

In the module info, there should be an array of the static constructors.
Apr 19 2007
parent reply "Frank Benoit (keinfarbton)" <benoit tionex.removethispart.de> writes:
Walter Bright schrieb:
 Frank Benoit (keinfarbton) wrote:
 allClasses is already there, see Classinfo.find().

Didn't know about it :) Now i can test if "org.eclipse.swt.SWT.SWT" exists. If so, is there a way to call the static method "static_this()"?

In the module info, there should be an array of the static constructors.

I cannot use them, because of circular dependencies. This is, why i "manually" call "static_this()" methods (note the underscore) in a defined order.
Apr 19 2007
next sibling parent Walter Bright <newshound1 digitalmars.com> writes:
Frank Benoit (keinfarbton) wrote:
 Walter Bright schrieb:
 Frank Benoit (keinfarbton) wrote:
 allClasses is already there, see Classinfo.find().

Now i can test if "org.eclipse.swt.SWT.SWT" exists. If so, is there a way to call the static method "static_this()"?


I cannot use them, because of circular dependencies. This is, why i "manually" call "static_this()" methods (note the underscore) in a defined order.

There isn't a way to do that with reflection at the moment.
Apr 19 2007
prev sibling parent "Vladimir Panteleev" <thecybershadow gmail.com> writes:
On Fri, 20 Apr 2007 01:39:12 +0300, Frank Benoit (keinfarbton)
<benoit tionex.removethispart.de> wrote:

 Walter Bright schrieb:
 Frank Benoit (keinfarbton) wrote:
 allClasses is already there, see Classinfo.find().

Didn't know about it :) Now i can test if "org.eclipse.swt.SWT.SWT" exists. If so, is there a way to call the static method "static_this()"?

In the module info, there should be an array of the static constructors.

I cannot use them, because of circular dependencies. This is, why i "manually" call "static_this()" methods (note the underscore) in a defined order.

Speaking of circular dependencies, those are quite annoying. Would it be possible to add a module/static constructor modifier keyword like "standalone" (doesn't depend on the static constructors of imported modules) or "depends" (which allows to enumerate the modules this [module's] static constructor[s] depend on)? -- Best regards, Vladimir mailto:thecybershadow gmail.com
Apr 20 2007
prev sibling parent reply "Frank Benoit (keinfarbton)" <benoit tionex.removethispart.de> writes:
Walter Bright schrieb:
 Frank Benoit (keinfarbton) wrote:
 class ClassInfo{
     Field[] fields;
     Method[] methods;
     Constructors[] constructors;
     static ClassInfo[] allClasses; // probably the most important
 }

allClasses is already there, see Classinfo.find().

Where can i find the ClassInfo DDoc? It seems, it disappeared from http://www.digitalmars.com/d/phobos/object.html
Apr 19 2007
parent torhu <fake address.dude> writes:
Frank Benoit (keinfarbton) wrote:
 Walter Bright schrieb:
 Frank Benoit (keinfarbton) wrote:
 class ClassInfo{
     Field[] fields;
     Method[] methods;
     Constructors[] constructors;
     static ClassInfo[] allClasses; // probably the most important
 }

allClasses is already there, see Classinfo.find().

Where can i find the ClassInfo DDoc? It seems, it disappeared from http://www.digitalmars.com/d/phobos/object.html

It's missing from the 1.010 docs (which are one the web currently), but reappeared in 1.011. So it's probably in your dmd/html folder. ;)
Apr 19 2007
prev sibling parent Dan <murpsoft hotmail.com> writes:
Frank Benoit (keinfarbton) Wrote (MODIFIED BY ME)
 struct ClassInfo{
 	Field[] fields;
 	Method[] methods;
 	Constructors[] constructors;
 	static ClassInfo[] allClasses; // probably the most important
 }
 
 struct Field{
 	uint offset;
 	TypeInfo type;
 	Attribute[] attribs;
 	char[] name;
 	void* getPtr( Object* obj );
 }
 struct Parameter{
 	char[] name;
 	TypeInfo type;
 	Attribute[] attribs;
 }
 struct Method{
 	uint offset;
 	TypeInfo ret_type;
 	Attribute[] attribs;
 	char[] name;
 	Parameter[] params;
 	void* getPtr( Object* obj = null );
 }
 struct Constructor{
 	Attribute[] attribs;
 	char[] name;
 	void* getPtr();
 	Parameter[] params;
 }

That's simpler (inside) : )
Apr 19 2007