Exemplo n.º 1
0
 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;
     }
 }
Exemplo n.º 2
0
 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);
     }
 }
Exemplo n.º 3
0
 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);
 }
Exemplo n.º 4
0
 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);
     }
 }
Exemplo n.º 5
0
 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);
 }
Exemplo n.º 6
0
 public override void CSharpMarshalToManaged(CSharpMarshalContext ctx)
 {
     ctx.Return.Write("Marshal.PtrToStringUni(new IntPtr(QtCore.QString.{0}({1}).Utf16))",
         Helpers.CreateInstanceIdentifier, ctx.ReturnVarName);
 }
Exemplo n.º 7
0
        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;
        }
Exemplo n.º 8
0
 protected CSharpMarshalPrinter(CSharpMarshalContext context)
     : base(context)
 {
     Options.VisitFunctionParameters = false;
     Options.VisitTemplateArguments = false;
 }
Exemplo n.º 9
0
 protected CSharpMarshalPrinter(CSharpMarshalContext context)
     : base(context)
 {
     Options.VisitFunctionParameters = false;
     Options.VisitTemplateArguments  = false;
 }
Exemplo n.º 10
0
 public CSharpMarshalNativeToManagedPrinter(CSharpMarshalContext context)
     : base(context)
 {
     Context.MarshalToManaged = this;
 }
Exemplo n.º 11
0
 public override void CSharpMarshalToNative(CSharpMarshalContext ctx)
 {
     ctx.Return.Write(ctx.Parameter.Name);
 }
Exemplo n.º 12
0
 public CSharpMarshalNativeToManagedPrinter(CSharpMarshalContext context)
     : base(context)
 {
     Context.MarshalToManaged = this;
 }
Exemplo n.º 13
0
 public override void CSharpMarshalToNative(CSharpMarshalContext ctx)
 {
     ctx.Return.Write("new Std.WString()");
 }
Exemplo n.º 14
0
 public CSharpMarshalNativeToManagedPrinter(CSharpMarshalContext context)
     : base(context)
 {
     typePrinter = new CSharpTypePrinter(context.Driver);
 }
Exemplo n.º 15
0
 public override void CSharpMarshalToNative(CSharpMarshalContext ctx)
 {
     ctx.Return.Write("IntPtr.Zero");
 }
Exemplo n.º 16
0
 public virtual void CSharpMarshalToManaged(CSharpMarshalContext ctx)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 17
0
 public CSharpMarshalManagedToNativePrinter(CSharpMarshalContext context)
     : base(context)
 {
     typePrinter = new CSharpTypePrinter(context.Context);
 }
Exemplo n.º 18
0
        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);
        }
Exemplo n.º 19
0
 public override void CSharpMarshalToNative(CSharpMarshalContext ctx)
 {
     // pointless, put just so that the generated code compiles
     ctx.Return.Write("new QList.Internal()");
 }
Exemplo n.º 20
0
 public override void CSharpMarshalToManaged(CSharpMarshalContext ctx)
 {
     ctx.Return.Write(ctx.ReturnVarName);
 }
Exemplo n.º 21
0
 public CSharpMarshalManagedToNativePrinter(CSharpMarshalContext context)
     : base(context)
 {
     Context.MarshalToNative = this;
 }
Exemplo n.º 22
0
 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;
     }
 }
Exemplo n.º 23
0
 public CSharpMarshalManagedToNativePrinter(CSharpMarshalContext context)
     : base(context)
 {
     Context.MarshalToNative = this;
 }