__traits proposal: derive hierachy and current-scope-type or something
dennis luehring
dl.soluz at gmx.net
Fri Sep 21 23:50:01 PDT 2007
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 );
}
}
---
More information about the Digitalmars-d
mailing list