[Kde-bindings] playground/bindings/kimono

Arno Rehn kde at arnorehn.de
Tue Mar 20 20:19:30 UTC 2007


SVN commit 644738 by arnorehn:

* Made instance operators work

CCMAIL: kde-bindings at kde.org



 M  +1 -0      ChangeLog  
 M  +21 -2     Qyoto.cs  
 M  +46 -32    SmokeInvocation.cs  


--- trunk/playground/bindings/kimono/ChangeLog #644737:644738
@@ -9,6 +9,7 @@
 
 	* Allow 'zero' return types for methods and for args of methods being called
 	  from C++
+	* Made instance operators work
 
 2007-03-18  Richard Dale  <rdale at foton.es>
 
--- trunk/playground/bindings/kimono/Qyoto.cs #644737:644738
@@ -483,10 +483,29 @@
 
 			return res;
 		}	
+		
+		public static bool IsInstanceOperator(MethodInfo mi) {
+			object[] attrs = mi.GetCustomAttributes(typeof(SmokeMethod), false);
+			if (attrs.Length > 0) {
+				SmokeMethod sm = (SmokeMethod) attrs[0];
+				return IsInstanceOperator(sm);
+			}
+			return false;
+		}
+		
+		public static bool IsInstanceOperator(SmokeMethod sm) {
+			if (!sm.Name.StartsWith("operator")) // no operator
+				return false;
+			
+			string[] args = sm.ArgsSignature.Split(',');
+			if (args.Length == 1) // the operator takes only one argument, so it has to be a instance operator
+				return true;
+			return false; // else return false
+		}
 	}
 	
 	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface)]
-	class SmokeClass : Attribute
+	public class SmokeClass : Attribute
 	{
 		public string signature;	
 	
@@ -504,7 +523,7 @@
 	[AttributeUsage(	AttributeTargets.Constructor 
 						| AttributeTargets.Method
 						| AttributeTargets.Interface )]
-	class SmokeMethod : Attribute
+	public class SmokeMethod : Attribute
 	{
 		public string name;
 		public string argsSignature;
--- trunk/playground/bindings/kimono/SmokeInvocation.cs #644737:644738
@@ -399,43 +399,57 @@
 			StackItem[] stack = new StackItem[callMessage.ArgCount+1];
 
 			if (callMessage.MethodSignature != null) {
-				Type[] types = (Type[]) callMessage.MethodSignature;
-				for (int i = 0; i < callMessage.ArgCount; i++) {
-					if (callMessage.Args[i] == null) {
-						unsafe {
-							stack[i+1].s_class = (IntPtr) 0;
+				if (Qyoto.IsInstanceOperator((MethodInfo) callMessage.MethodBase)) {
+					// for instance operators only length of 2 => 1. return type, 2. value to compare
+					stack = new StackItem[2];
+					// TODO: is it sometimes a primitive value to compare?
+					// then change this to check for all possible types as it is done a few lines below
+					stack[1].s_class = (IntPtr) GCHandle.Alloc(callMessage.Args[1]);
+				} else {
+					Type[] types = (Type[]) callMessage.MethodSignature;
+					for (int i = 0; i < callMessage.ArgCount; i++) {
+						if (callMessage.Args[i] == null) {
+							unsafe {
+								stack[i+1].s_class = (IntPtr) 0;
+							}
+						} else if (types[i] == typeof(bool)) {
+							stack[i+1].s_bool = (bool) callMessage.Args[i];
+						} else if (types[i] == typeof(sbyte)) {
+							stack[i+1].s_char = (sbyte) callMessage.Args[i];
+						} else if (types[i] == typeof(byte)) {
+							stack[i+1].s_uchar = (byte) callMessage.Args[i];
+						} else if (types[i] == typeof(short)) {
+							stack[i+1].s_short = (short) callMessage.Args[i];
+						} else if (types[i] == typeof(ushort)) {
+							stack[i+1].s_ushort = (ushort) callMessage.Args[i];
+						} else if (types[i] == typeof(int) || types[i].IsEnum) {
+							stack[i+1].s_int = (int) callMessage.Args[i];
+						} else if (types[i] == typeof(uint)) {
+							stack[i+1].s_uint = (uint) callMessage.Args[i];
+						} else if (types[i] == typeof(long)) {
+							stack[i+1].s_long = (long) callMessage.Args[i];
+						} else if (types[i] == typeof(ulong)) {
+							stack[i+1].s_ulong = (ulong) callMessage.Args[i];
+						} else if (types[i] == typeof(float)) {
+							stack[i+1].s_float = (float) callMessage.Args[i];
+						} else if (types[i] == typeof(double)) {
+							stack[i+1].s_double = (double) callMessage.Args[i];
+						} else if (types[i] == typeof(string)) {
+							stack[i+1].s_class = (IntPtr) GCHandle.Alloc(callMessage.Args[i]);
+						} else {
+							stack[i+1].s_class = (IntPtr) GCHandle.Alloc(callMessage.Args[i]);
 						}
-					} else if (types[i] == typeof(bool)) {
-						stack[i+1].s_bool = (bool) callMessage.Args[i];
-					} else if (types[i] == typeof(sbyte)) {
-						stack[i+1].s_char = (sbyte) callMessage.Args[i];
-					} else if (types[i] == typeof(byte)) {
-						stack[i+1].s_uchar = (byte) callMessage.Args[i];
-					} else if (types[i] == typeof(short)) {
-						stack[i+1].s_short = (short) callMessage.Args[i];
-					} else if (types[i] == typeof(ushort)) {
-						stack[i+1].s_ushort = (ushort) callMessage.Args[i];
-					} else if (types[i] == typeof(int) || types[i].IsEnum) {
-						stack[i+1].s_int = (int) callMessage.Args[i];
-					} else if (types[i] == typeof(uint)) {
-						stack[i+1].s_uint = (uint) callMessage.Args[i];
-					} else if (types[i] == typeof(long)) {
-						stack[i+1].s_long = (long) callMessage.Args[i];
-					} else if (types[i] == typeof(ulong)) {
-						stack[i+1].s_ulong = (ulong) callMessage.Args[i];
-					} else if (types[i] == typeof(float)) {
-						stack[i+1].s_float = (float) callMessage.Args[i];
-					} else if (types[i] == typeof(double)) {
-						stack[i+1].s_double = (double) callMessage.Args[i];
-					} else if (types[i] == typeof(string)) {
-						stack[i+1].s_class = (IntPtr) GCHandle.Alloc(callMessage.Args[i]);
-					} else {
-						stack[i+1].s_class = (IntPtr) GCHandle.Alloc(callMessage.Args[i]);
 					}
 				}
 			}
 
-			GCHandle instanceHandle = GCHandle.Alloc(_instance);
+			GCHandle instanceHandle;
+			if (Qyoto.IsInstanceOperator((MethodInfo) callMessage.MethodBase)) {
+				// if it's an instance operator, the instance is the first argument
+				instanceHandle = GCHandle.Alloc(callMessage.Args[0]);
+			} else {
+				instanceHandle = GCHandle.Alloc(_instance);
+			}
 			MethodReturnMessageWrapper returnValue = new MethodReturnMessageWrapper((IMethodReturnMessage) returnMessage); 
 			
 			unsafe {



More information about the Kde-bindings mailing list