www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to see result of a mixin? (equivalent of running C preprocessor)

reply asd <x x.com> writes:
I'm trying to get D-ObjC bridge working and I'm getting weird errors triggered
somewhere deeply in a mix of templates and mixins that's too hard for me to
understand.

How can I analyze such problem in D? Is it possible to tell dmd to run only
compile-time functions/templates and output that as a D source?
Jul 24 2009
next sibling parent reply Ary Borenszweig <ary esperanto.org.ar> writes:
asd wrote:
 I'm trying to get D-ObjC bridge working and I'm getting weird errors triggered
somewhere deeply in a mix of templates and mixins that's too hard for me to
understand.
 
 How can I analyze such problem in D? Is it possible to tell dmd to run only
compile-time functions/templates and output that as a D source?
You can debug templates and mixins using Descent: http://dsource.org/project/descent
Jul 24 2009
parent Ary Borenszweig <ary esperanto.org.ar> writes:
Ary Borenszweig wrote:
 asd wrote:
 I'm trying to get D-ObjC bridge working and I'm getting weird errors 
 triggered somewhere deeply in a mix of templates and mixins that's too 
 hard for me to understand.

 How can I analyze such problem in D? Is it possible to tell dmd to run 
 only compile-time functions/templates and output that as a D source?
You can debug templates and mixins using Descent: http://dsource.org/project/descent
I mean... http://dsource.org/projects/descent
Jul 24 2009
prev sibling parent reply Lutger <lutger.blijdestijn gmail.com> writes:
asd wrote:

 I'm trying to get D-ObjC bridge working and I'm getting weird errors
 triggered somewhere deeply in a mix of templates and mixins that's too
 hard for me to understand.
 
 How can I analyze such problem in D? Is it possible to tell dmd to run
 only compile-time functions/templates and output that as a D source?
Not directly except with descent. It's worth it to try descent compile time debugger (and compile time view!), really awesome stuff. Other than that, you can use pragma(msg, ...) where you have several options for ... depending on what you want to debug and whether it's D1 or D2. .stringof property and typeof() are useful for this. Take a look at std.traits and for D2 at __traits. Generally the error messages with such code is not so friendly. String mixins can also just be printed with writeln / Stdout.
Jul 24 2009
parent reply asd <asd none.invalid> writes:
thanks for quick response!

Lutger Wrote:

 Not directly except with descent. It's worth it to try descent compile time 
 debugger (and compile time view!), really awesome stuff. 
It's indeed pretty nice, but unfortunately it doesn't seem to show mixins:
	public void STARTS_HERE() {}
	
	mixin ObjcMethodInfo!(objcForward_isEqual_, BOOL, "isEqual:", id);
	
	public void  ENDS_HERE(int h) {}
is displayed in Descent's Compile-Time view as:
	void STARTS_HERE() {
	}

	void ENDS_HERE(int h) {
	}
Error I'm trying to fix is: cocoa/foundation/object.d(74): Error: function cocoa.foundation.object.NSObject.ObjcMethodInfo!(objcForward_isEqual_,byte,"isEqual:",objc_ob ject*).ObjcSubclassIfNeeded!().ObjcSubclass!().ObjcSubclass!("NSObj ct"c).objcHardWired multiple overrides of same function My guess is that I need to make this mixin to insert override keyword when neccessary, but haven't figured out yet how.
Jul 24 2009
next sibling parent asd <a sd.invalid> writes:
 Error I'm trying to fix is:
 cocoa/foundation/object.d(74): Error: function
cocoa.foundation.object.NSObject.ObjcMethodInfo!(objcForward_isEqual_,byte,"isEqual:",objc_ob
 ject*).ObjcSubclassIfNeeded!().ObjcSubclass!().ObjcSubclass!("NSObj
ct"c).objcHardWired multiple overrides of same function
Solved! I've sprinkled the code with pragma(msg,"I'm not dead yet") and it led me to the actual source of problem. Thanks for the tip!
Jul 24 2009
prev sibling parent reply Ary Borenszweig <ary esperanto.org.ar> writes:
asd escribió:
 thanks for quick response!
 
 Lutger Wrote:
 
 Not directly except with descent. It's worth it to try descent compile time 
 debugger (and compile time view!), really awesome stuff. 
It's indeed pretty nice, but unfortunately it doesn't seem to show mixins:
 	public void STARTS_HERE() {}
 	
 	mixin ObjcMethodInfo!(objcForward_isEqual_, BOOL, "isEqual:", id);
 	
 	public void  ENDS_HERE(int h) {}
is displayed in Descent's Compile-Time view as:
 	void STARTS_HERE() {
 	}

 	void ENDS_HERE(int h) {
 	}
Maybe because it can't instantiante the template. :-) The idea in these cases is to debug the instantiation. Right click on it -> Source -> Debug at Compile Time. The debug view opens, you can step into, and when an error happens it'll be printed in the console at the line where it happens.
Jul 25 2009
parent reply Ary Borenszweig <ary esperanto.org.ar> writes:
Ary Borenszweig escribió:
 asd escribió:
 thanks for quick response!

 Lutger Wrote:

 Not directly except with descent. It's worth it to try descent 
 compile time debugger (and compile time view!), really awesome stuff. 
It's indeed pretty nice, but unfortunately it doesn't seem to show mixins:
     public void STARTS_HERE() {}
     
     mixin ObjcMethodInfo!(objcForward_isEqual_, BOOL, "isEqual:", id);
     
     public void  ENDS_HERE(int h) {}
is displayed in Descent's Compile-Time view as:
     void STARTS_HERE() {
     }

     void ENDS_HERE(int h) {
     }
Maybe because it can't instantiante the template. :-) The idea in these cases is to debug the instantiation. Right click on it -> Source -> Debug at Compile Time. The debug view opens, you can step into, and when an error happens it'll be printed in the console at the line where it happens.
But now I see "D2". Still not supported by Descent, awww...
Jul 25 2009
parent Trass3r <mrmocool gmx.de> writes:
Ary Borenszweig schrieb:
 But now I see "D2". Still not supported by Descent, awww...
Unfortunately, yes :(
Jul 26 2009