public override void CSharpMarshalToNative(CSharpMarshalContext ctx) { var type = ctx.Parameter.Type.Desugar(); ClassTemplateSpecialization basicString = GetBasicString(type); var typePrinter = new CSharpTypePrinter(ctx.Driver); typePrinter.PushContext(CSharpTypePrinterContextKind.Native); if (!ctx.Parameter.Type.Desugar().IsAddress()) ctx.Return.Write("*({0}*) ", basicString.Visit(typePrinter)); typePrinter.PopContext(); var allocator = ctx.Driver.ASTContext.FindClass("allocator", false, true).First( a => a.IsSupportedStdType()); if (type.IsPointer() || (type.IsReference() && ctx.Declaration is Field)) { ctx.Return.Write("new {0}({1}, new {2}()).{3}", basicString.Visit(typePrinter), ctx.Parameter.Name, allocator.Visit(typePrinter), Helpers.InstanceIdentifier); } else { string varBasicString = "__basicString" + ctx.ParameterIndex; ctx.SupportBefore.WriteLine("using (var {0} = new {1}({2}, new {3}()))", varBasicString, basicString.Visit(typePrinter), ctx.Parameter.Name, allocator.Visit(typePrinter)); ctx.SupportBefore.WriteStartBraceIndent(); ctx.Return.Write("{0}.{1}", varBasicString, Helpers.InstanceIdentifier); ctx.HasCodeBlock = true; } }
public override void CSharpMarshalToNative(CSharpMarshalContext ctx) { var type = ctx.Parameter.Type.Desugar(); ClassTemplateSpecialization basicString = GetBasicString(type); var typePrinter = new CSharpTypePrinter(ctx.Context); typePrinter.PushContext(CSharpTypePrinterContextKind.Native); if (!ctx.Parameter.Type.Desugar().IsAddress()) ctx.Return.Write("*({0}*) ", basicString.Visit(typePrinter)); typePrinter.PopContext(); var allocator = ctx.Context.ASTContext.FindClass("allocator", false, true).First( a => a.IsDependent); if (type.IsPointer() || (type.IsReference() && ctx.Declaration is Field)) { ctx.Return.Write("new {0}({1}, new {2}()).{3}", basicString.Visit(typePrinter), ctx.Parameter.Name, allocator.Visit(typePrinter), Helpers.InstanceIdentifier); } else { string varAllocator = "__allocator" + ctx.ParameterIndex; string varBasicString = "__basicString" + ctx.ParameterIndex; ctx.SupportBefore.WriteLine("var {0} = new {1}();", varAllocator, allocator.Visit(typePrinter)); ctx.SupportBefore.WriteLine("var {0} = new {1}({2}, {3});", varBasicString, basicString.Visit(typePrinter), ctx.Parameter.Name, varAllocator); ctx.Return.Write("{0}.{1}", varBasicString, Helpers.InstanceIdentifier); ctx.Cleanup.WriteLine("{0}.Dispose({1});", varBasicString, type.IsPointer() ? "true" : "false"); ctx.Cleanup.WriteLine("{0}.Dispose();", varAllocator); } }
public override void CSharpMarshalToNative(CSharpMarshalContext ctx) { if (ctx.Parameter.Type.Desugar().IsAddress()) ctx.Return.Write("new global::System.IntPtr(&{0})", ctx.Parameter.Name); else ctx.Return.Write(ctx.Parameter.Name); }
public override void CSharpMarshalToManaged(CSharpMarshalContext ctx) { if (ctx.ReturnType.Type.Desugar().IsAddress()) { var finalType = ctx.ReturnType.Type.GetFinalPointee() ?? ctx.ReturnType.Type; var enumType = GetEnumType(finalType); ctx.Return.Write("*({0}*) {1}", enumType, ctx.ReturnVarName); } else { ctx.Return.Write(ctx.ReturnVarName); } }
public override void CSharpMarshalToNative(CSharpMarshalContext ctx) { ctx.SupportBefore.WriteLine("var __stringPtr{0} = ReferenceEquals({1}, null) ? null : (ushort*) Marshal.StringToHGlobalUni({1}).ToPointer();", ctx.ParameterIndex, ctx.Parameter.Name); ctx.SupportBefore.WriteLine("var __qstring{0} = __stringPtr{0} == null ? null : QtCore.QString.FromUtf16(ref *__stringPtr{0}, {1}.Length);", ctx.ParameterIndex, ctx.Parameter.Name); var type = ctx.Parameter.Type.Desugar(); if (type.IsAddress()) { ctx.Return.Write("ReferenceEquals(__qstring{0}, null) ? global::System.IntPtr.Zero : __qstring{0}.{1}", ctx.ParameterIndex, Helpers.InstanceIdentifier); return; } Class @class; type.TryGetClass(out @class); if (@class == null) { this.Type.TryGetClass(out @class); } this.typePrinter = this.typePrinter ?? (this.typePrinter = new CSharpTypePrinter(ctx.Context)); var qualifiedIdentifier = (@class.OriginalClass ?? @class).Visit(this.typePrinter); ctx.Return.Write("ReferenceEquals(__qstring{0}, null) ? new {1}.{2}() : *({1}.{2}*) (__qstring{0}.{3})", ctx.ParameterIndex, qualifiedIdentifier, Helpers.InternalStruct, Helpers.InstanceIdentifier); }
public override void CSharpMarshalToManaged(CSharpMarshalContext ctx) { ctx.Return.Write("Marshal.PtrToStringUni(new IntPtr(QtCore.QString.{0}({1}).Utf16))", Helpers.CreateInstanceIdentifier, ctx.ReturnVarName); }
public override bool VisitParameterDecl(Parameter parameter) { if (parameter.Usage == ParameterUsage.Unknown || parameter.IsIn) return base.VisitParameterDecl(parameter); var ctx = new CSharpMarshalContext(Context.Driver) { ReturnType = Context.ReturnType, ReturnVarName = Context.ReturnVarName }; var marshal = new CSharpMarshalNativeToManagedPrinter(ctx); parameter.Type.Visit(marshal); if (!string.IsNullOrWhiteSpace(ctx.SupportBefore)) Context.SupportBefore.WriteLine(ctx.SupportBefore); if (!string.IsNullOrWhiteSpace(ctx.Return) && !parameter.Type.IsPrimitiveTypeConvertibleToRef()) { Context.SupportBefore.WriteLine("var _{0} = {1};", parameter.Name, ctx.Return); } Context.Return.Write("{0}{1}", parameter.Type.IsPrimitiveTypeConvertibleToRef() ? "ref *" : "_", parameter.Name); return true; }
protected CSharpMarshalPrinter(CSharpMarshalContext context) : base(context) { Options.VisitFunctionParameters = false; Options.VisitTemplateArguments = false; }
public CSharpMarshalNativeToManagedPrinter(CSharpMarshalContext context) : base(context) { Context.MarshalToManaged = this; }
public override void CSharpMarshalToNative(CSharpMarshalContext ctx) { ctx.Return.Write(ctx.Parameter.Name); }
public override void CSharpMarshalToNative(CSharpMarshalContext ctx) { ctx.Return.Write("new Std.WString()"); }
public CSharpMarshalNativeToManagedPrinter(CSharpMarshalContext context) : base(context) { typePrinter = new CSharpTypePrinter(context.Driver); }
public override void CSharpMarshalToNative(CSharpMarshalContext ctx) { ctx.Return.Write("IntPtr.Zero"); }
public virtual void CSharpMarshalToManaged(CSharpMarshalContext ctx) { throw new NotImplementedException(); }
public CSharpMarshalManagedToNativePrinter(CSharpMarshalContext context) : base(context) { typePrinter = new CSharpTypePrinter(context.Context); }
public override void CSharpMarshalToManaged(CSharpMarshalContext ctx) { var templateType = Type as TemplateSpecializationType; var type = templateType.Arguments[0].Type; ctx.Return.Write("new Std.Vector<{0}>({1})", type, ctx.ReturnVarName); }
public override void CSharpMarshalToNative(CSharpMarshalContext ctx) { // pointless, put just so that the generated code compiles ctx.Return.Write("new QList.Internal()"); }
public override void CSharpMarshalToManaged(CSharpMarshalContext ctx) { ctx.Return.Write(ctx.ReturnVarName); }
public CSharpMarshalManagedToNativePrinter(CSharpMarshalContext context) : base(context) { Context.MarshalToNative = this; }
public override void CSharpMarshalToManaged(CSharpMarshalContext ctx) { var type = ctx.ReturnType.Type; ClassTemplateSpecialization basicString = GetBasicString(type); Declaration c_str = basicString.Methods.FirstOrDefault(m => m.OriginalName == "c_str"); if (!c_str.IsGenerated) c_str = basicString.Properties.First(p => p.OriginalName == "c_str"); var typePrinter = new CSharpTypePrinter(ctx.Context); if (type.IsPointer() || ctx.Declaration is Field) { ctx.Return.Write("{0}.{1}({2}).{3}{4}", basicString.Visit(typePrinter), Helpers.CreateInstanceIdentifier, ctx.ReturnVarName, c_str.Name, c_str is Method ? "()" : string.Empty); } else { const string varBasicString = "__basicStringRet"; ctx.SupportBefore.WriteLine("using (var {0} = {1}.{2}({3}))", varBasicString, basicString.Visit(typePrinter), Helpers.CreateInstanceIdentifier, ctx.ReturnVarName); ctx.SupportBefore.WriteStartBraceIndent(); ctx.Return.Write("{0}.{1}{2}", varBasicString, c_str.Name, c_str is Method ? "()" : string.Empty); ctx.HasCodeBlock = true; } }