D1/D2: How to check if a method has been overridden

Mafi mafi at example.org
Tue Sep 7 14:07:44 PDT 2010


Am 07.09.2010 23:00, schrieb klickverbot:
> Hello all,
>
> as some of you might know, I have started working on a D module for SWIG
> quite some time ago. In the meantime, the project is almost ready for
> inclusion in SWIG trunk as a full-fledged language module supporting
> D1/Tango and D2/Phobos.
>
> However, there is one major blocker left: I need to check if a method
> has been overridden for this in a potential subclass (obviously at
> runtime), as illustrated below.
>
> ---
> class A {
> void foo( float a ) {}
> void foo( int a ) {}
>
> final void bar() {
> // Determine whether this.foo( 1 ) and this.foo( 1f ) really refer
> // to A.foo( float ) and A.foo( int ) or if they point to a subclass
> // implementation – how?
> }
> }
>
> class B : A {
> override void foo( float a ) {}
> }
>
> class C : A {
> override void foo( int a ) {}
> }
>
> class D : B {
> override void foo( int a ) {}
> }
> ---
>
> Until DMD 1.047, I have used a piece of code shown in
> http://d.puremagic.com/issues/show_bug.cgi?id=4835, but the casts in
> there are no longer enough for DMD to determine which overload is being
> referred to.
>
> Now, please tell me that there _is_ a way to do this (D1 and D2, but I
> don't mind if have to generate different code for the both)…

Hi,
couldn't you just check if a delegate's funcptr is the same as the real 
funcptr:
  &this.foo == &foo
I'm not sure if the right isn't an shortcut for the left and it could 
get weird with strange linking but if D really want's to be a system's 
language then this should work.

Mafi


More information about the Digitalmars-d mailing list