www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - __traits proposal: derive hierachy and current-scope-type or something

reply dennis luehring <dl.soluz gmx.net> writes:
1. derive-hierachy

class A
class B:A
class C:A
class D:C

* derivedClasses - returns the derived classes
(what about abstract/interface classes?)

__traits( derivedClasses, "A" ) ==> [ B, C ]
__traits( derivedClasses, "C" ) ==> [ D ]

* baseClass (the upward version of derivedClasses)

__traits( baseClass, "D" ) ==> [ C ]
__traits( baseClass, "B" ) ==> [ A ]

should maybe work only in module-scope

2. current-scope-type

class bla
{
   scope-type = in class bla
   void test()
   {
     scope-type = in class bla.test()
   }
}

maybe with line/module information

only at compile-time

ciao dennis
Sep 21 2007
parent reply Christopher Wright <dhasenan gmail.com> writes:
dennis luehring wrote:
 1. derive-hierachy
 
 class A
 class B:A
 class C:A
 class D:C
 
 * derivedClasses - returns the derived classes
 (what about abstract/interface classes?)
 
 __traits( derivedClasses, "A" ) ==> [ B, C ]
 __traits( derivedClasses, "C" ) ==> [ D ]

// in file a.d module a; class A { } class B : A { } // set to ["B"] const string[] a_derived = __traits(derivedClasses, "A"); // in file c.d module c; import a; class C : A { } // set to ["B"] const string[] my_a_derived = a.a_derived; It's a difficult relationship to get meaningfully and consistent.
 * baseClass (the upward version of derivedClasses)
 
 __traits( baseClass, "D" ) ==> [ C ]
 __traits( baseClass, "B" ) ==> [ A ]

This works reliably.
 should maybe work only in module-scope

For derivedClasses, it'd have to.
 2. current-scope-type
 
 class bla
 {
   scope-type = in class bla
   void test()
   {
     scope-type = in class bla.test()
   }
 }
 
 maybe with line/module information

I don't get the purpose of this.
 only at compile-time
 
 ciao dennis

Sep 21 2007
parent reply dennis luehring <dl.soluz gmx.net> writes:
Christopher Wright schrieb:
 dennis luehring wrote:
 1. derive-hierachy

 class A
 class B:A
 class C:A
 class D:C

 * derivedClasses - returns the derived classes
 (what about abstract/interface classes?)

 __traits( derivedClasses, "A" ) ==> [ B, C ]
 __traits( derivedClasses, "C" ) ==> [ D ]

// in file a.d module a; class A { } class B : A { } // set to ["B"] const string[] a_derived = __traits(derivedClasses, "A"); // in file c.d module c; import a; class C : A { } // set to ["B"] const string[] my_a_derived = a.a_derived;

 It's a difficult relationship to get meaningfully and consistent.

module a; class A{} __traits( derivedClass, "A" ) => [ "a.B" ] ----- module b; class B:A{} -- module c; module b; module a; class C:A{} __traits( derivedClass, "A" ) => [ "a.C", "b.B" ] and without using import b; __traits( derivedClass, "A" ) => [ "a.C" ] so you need to create an "hierachy.d" with classes you want to analyse or somethig if you want to "see" the hierachy of them... but thats pure speculation: i don't know what relationship information the d compiler got (maybe he knows all the derivations)
 class bla
 {
   scope-type = in class bla
   void test()
   {
     scope-type = in class bla.test()
   }
 }

 maybe with line/module information

I don't get the purpose of this.

a compiletime "where am i" type (in class scope, methode scope, ... line,import) and some helper _traits to "analyse" the scope --- import x; [scope = main/import | scope.info = modulename, imports, classes, globals...] class a { [scope = class a | scope.info = classname, derivations, ...] __traits( inClass, scope ) ==> true public { [scope = class a/public | attribute ] void test() { [scope = class a/public/test (method) | parameters, returntypes] __traits( inMethod, scope ) ==> true debug_msg!("blablu"); } } } // an then you can write (for example) position(type) at related // information , debug-help or what else templates / ctfs template debug_msg( char[] text ) { static if( __traits( isMethode, scope ) ) { //scope is now an alias for the method at compile-time: ...get method name ...analayse parameter ...line/filename } else { pragma( msg, "no working outer method-scope ); } } ---
Sep 21 2007
parent dennis luehring <dl.soluz gmx.net> writes:
i've made an mistake

 module a;
 
 class A{}
 

 
 -----

 module b;
 
 class B:A{}

__traits( derivedClass, "A" ) => [ "b.B" ]
Sep 21 2007