protected void GenerateParameterExtraction(RgacMethod method) { for (int i = 0; i < method.ParameterNames.Length; i++) { GenerateParameterExtraction(method.ParameterNames[i], method.ParameterTypes[i]); } }
protected string GenerateMethodAccess(RgacMethod method, bool isStatic) { return(isStatic ? (method.OwnerUDT.AssociatedGacType.ToString() + "::" + method.Name) : string.Format("__GacUIInternal<{0}>::GetInternalObject(*this)->{1}", method.OwnerUDT.ToString(), method.Name) ); }
protected void GenerateMethod(RgacMethod method, bool isStatic) { WriteLine("{0}{1} {2}({3});", (isStatic ? "static " : ""), GetType(method.ReturnType), method.Name, method.ParameterTypes .Zip(method.ParameterNames, Tuple.Create) .Select(t => string.Format("{0} {1}", GetType(t.Item1), t.Item2)) .Aggregate("", (a, b) => a == "" ? b : a + ", " + b) ); }
protected void GenerateMethod(RgacMethod method, bool isStatic) { WriteLine("{0} {1}{2}({3})", GetType(method.ReturnType), method.OwnerUDT.Name.Aggregate("", (a, b) => a + b + "::"), method.Name, method.ParameterTypes .Zip(method.ParameterNames, Tuple.Create) .Select(t => string.Format("{0} {1}", GetType(t.Item1), t.Item2)) .Aggregate("", (a, b) => a == "" ? b : a + ", " + b) ); Begin("{"); if (method.OwnerUDT.ToString() == "GuiPolygonElement" && method.Name == "SetPoints") { WriteLine("vl::collections::Array<vl::presentation::Point> _unwrapped_points(count);"); WriteLine("for(int i=0;i<count;i++)"); Begin("{"); WriteLine("_unwrapped_points[i] = *__GacUIInternal<Point>::GetInternalObject(p[i]);"); End("}"); WriteLine("throw 0;"); } else { GenerateParameterExtraction(method); if (method.ReturnType.Kind == RgacTypeKind.Primitive && method.ReturnType.PrimitiveKind == RgacPrimitiveKind.Void) { WriteLine("{0}{1};", GenerateMethodAccess(method, isStatic), GenerateParametersPassing(method) ); } else { WriteLine("{0} _unwrapped_result = {1}{2};", method.ReturnType.ToString(), GenerateMethodAccess(method, isStatic), GenerateParametersPassing(method) ); GenerateResultExtraction("_unwrapped_result", method.ReturnType); } } End("}"); WriteLine(""); }
protected void GenerateConstructor(RgacMethod method) { WriteLine("rptr<{0}> {1}CreateRptr({2})", GacUdtTypeName(method.OwnerUDT), method.OwnerUDT.Name.Aggregate("", (a, b) => a + b + "::"), method.ParameterTypes .Zip(method.ParameterNames, Tuple.Create) .Select(t => string.Format("{0} {1}", GetType(t.Item1), t.Item2)) .Aggregate("", (a, b) => a == "" ? b : a + ", " + b) ); Begin("{"); GenerateParameterExtraction(method); WriteLine("{0}* _unwrapped_result = new {1}{2};", method.OwnerUDT.AssociatedGacType.ToString(), method.OwnerUDT.AssociatedGacType.ToString(), GenerateParametersPassing(method) ); WriteLine("return __GacUIInternal<{0}>::BuildRptr(_unwrapped_result);", method.OwnerUDT.ToString()); End("}"); WriteLine(""); if (method.OwnerUDT.Kind == RgacUDTKind.Struct) { WriteLine("{0} {1}Create({2})", GacUdtTypeName(method.OwnerUDT), method.OwnerUDT.Name.Aggregate("", (a, b) => a + b + "::"), method.ParameterTypes .Zip(method.ParameterNames, Tuple.Create) .Select(t => string.Format("{0} {1}", GetType(t.Item1), t.Item2)) .Aggregate("", (a, b) => a == "" ? b : a + ", " + b) ); Begin("{"); GenerateParameterExtraction(method); WriteLine("{0} _unwrapped_result = {1}{2};", method.OwnerUDT.AssociatedGacType.ToString(), method.OwnerUDT.AssociatedGacType.ToString(), GenerateParametersPassing(method) ); WriteLine("return __GacUIInternal<{0}>::BuildCopy(&_unwrapped_result);", method.OwnerUDT.ToString()); End("}"); WriteLine(""); } }
protected void GenerateMethod(RgacUDT owner, RgacMethod method, bool isStatic, List <Action> methodInvokers) { WriteLine("(new MethodDescriptor(L\"{0}\", IMemberDescriptor::{1}))", method.Name, (isStatic ? "Static" : method.Kind.ToString())); WriteLine("->ReturnType(" + GetType(method.ReturnType) + ")"); for (int i = 0; i < method.ParameterTypes.Length; i++) { WriteLine("->Parameter(L\"{0}\", {1})", method.ParameterNames[i], GetType(method.ParameterTypes[i])); } string methodName = method.Name; if (methodName.StartsWith("operator")) { switch (methodName) { case "operator[]": methodName = "operator_index"; break; case "operator=": methodName = "operator_assign"; break; case "operator<": methodName = "operator_lt"; break; case "operator<=": methodName = "operator_le"; break; case "operator>": methodName = "operator_gt"; break; case "operator>=": methodName = "operator_ge"; break; case "operator==": methodName = "operator_eq"; break; case "operator!=": methodName = "operator_ne"; break; default: throw new ArgumentException(); } } string methodInvokerName = "method_handler_" + methodName + "_" + methodInvokers.Count.ToString(); GenerateMethodHandler(owner, methodInvokerName); GenerateMethodInvoker(owner, methodInvokerName, methodInvokers, () => { WriteLine("throw 0;"); }); }
protected void GenerateConstructor(RgacMethod method) { WriteLine("static rptr<{0}> CreateRptr({1});", GacUdtTypeName(method.OwnerUDT), method.ParameterTypes .Zip(method.ParameterNames, Tuple.Create) .Select(t => string.Format("{0} {1}", GetType(t.Item1), t.Item2)) .Aggregate("", (a, b) => a == "" ? b : a + ", " + b) ); if (method.OwnerUDT.Kind == RgacUDTKind.Struct) { WriteLine("static {0} Create({1});", method.OwnerUDT.Name.Last(), method.ParameterTypes .Zip(method.ParameterNames, Tuple.Create) .Select(t => string.Format("{0} {1}", GetType(t.Item1), t.Item2)) .Aggregate("", (a, b) => a == "" ? b : a + ", " + b) ); } }
protected IEnumerable <RgacUDT> GetRelatedUdts(RgacMethod method) { return(GetRelatedUdts(method.ReturnType) .Concat(method.ParameterTypes.SelectMany(GetRelatedUdts))); }
protected string GenerateParametersPassing(RgacMethod method) { return("(" + (method.ParameterNames.Select(GetUnwrappedParameterName).Aggregate("", (a, b) => a == "" ? b : a + ", " + b)) + ")"); }