示例#1
0
 /// <summary>
 /// Gets the code for declaring the specified model as a parameter to a managed method.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <returns>The code.</returns>
 public string GetFormalParameterCode(ParameterModel model)
 {
     if (model.Flags.HasFlag(ParameterModelFlags.IsOutput))
         return string.Format("out {0} {1}", model.Type.Name, model.Name);
     else
         return string.Format("{0} {1}", model.Type.Name, model.Name);
 }
示例#2
0
 /// <summary>
 /// Gets the code for passing the specified model as parameter to a trampoline method.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <returns>The code.</returns>
 public string GetTrampolineParameterCode(ParameterModel model)
 {
     if (model.Flags.HasFlag(ParameterModelFlags.IsOutput))
         return string.Format("ref {0}", model.Name);
     else
         return string.Format("{0}", model.Name);
 }
示例#3
0
        /// <summary>
        /// Gets the code for setup of local variables related to the specified parameter.
        /// </summary>
        /// <param name="marshaller">The marshalling service interface.</param>
        /// <param name="model">The model.</param>
        /// <returns>The code.</returns>
        public string GetLocalVariableSetupCode(MarshallingService marshaller, ParameterModel model)
        {
            if (model.Flags.HasFlag(ParameterModelFlags.IsOutput))
                return string.Empty;

            var builder = new StringBuilder();
            switch (marshaller.ResolveBehavior(model.Type))
            {
                case MarshalBehavior.Structure:
                    builder.AppendLine(string.Format("{0}Marshaller* _{1} = stackalloc {0}Marshaller[{1}.Length];", model.Type.Name, model.Name));
                    builder.AppendLine(string.Format("for(int i = 0; i < {0}.Length; ++i)", model.Name));
                    builder.AppendLine(string.Format("\t_{0}[i] = {1}.ToMarshaller({0}[i]);", model.Name, model.Type.Name));
                    break;
                case MarshalBehavior.Interface:
                    builder.AppendLine(string.Format("System.IntPtr* _{1} = stackalloc System.IntPtr[{1}.Length];", model.Type.Name, model.Name));
                    builder.AppendLine(string.Format("for(int i = 0; i < {0}.Length; ++i)", model.Name));
                    builder.AppendLine(string.Format("\t_{0}[i] = {0}[i].NativePointer;", model.Name, model.Type.Name));
                    break;
                default:
                    builder.AppendLine(string.Format("{0}* _{1} = stackalloc {0}[{1}.Length];", model.Type.Name, model.Name));
                    builder.AppendLine(string.Format("for(int i = 0; i < {0}.Length; ++i)", model.Name));
                    builder.AppendLine(string.Format("\t_{0}[i] = {0}[i];", model.Name, model.Type.Name));
                    break;
            }

            return builder.ToString();
        }
示例#4
0
 /// <summary>
 /// Gets the code for declaring the specified model as a parameter to a managed method.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <returns>The code.</returns>
 public string GetFormalParameterCode(ParameterModel model)
 {
     if (model.Flags.HasFlag(ParameterModelFlags.IsOutput))
         return string.Format("out System.IntPtr {0}", model.Name);
     else
         return string.Format("System.IntPtr {0}", model.Name);
 }
 /// <summary>
 /// Gets the code for cleanup of local variables related to the specified parameter.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <returns>The code.</returns>
 public string GetLocalVariableCleanupCode(ParameterModel model)
 {
     if (model.Flags.HasFlag(ParameterModelFlags.IsOutput))
     {
         return(string.Format("{0} = {1}.FromMarshaller(_{0});", model.Name, model.Type.Name));
     }
     return(string.Format("_{0}.Release();", model.Name));
 }
 /// <summary>
 /// Gets the code for setup of local variables related to the specified parameter.
 /// </summary>
 /// <param name="marshaller">The marshalling service interface.</param>
 /// <param name="model">The model.</param>
 /// <returns>The code.</returns>
 public string GetLocalVariableSetupCode(MarshallingService marshaller, ParameterModel model)
 {
     if (model.Flags.HasFlag(ParameterModelFlags.IsOutput))
     {
         return(string.Format("{0}Marshaller _{1} = default({0}Marshaller);", model.Type.Name, model.Name));
     }
     return(string.Format("{0}Marshaller _{1} = {0}.ToMarshaller({1});", model.Type.Name, model.Name));
 }
示例#7
0
 /// <summary>
 /// Gets the code for passing the specified model as parameter to a trampoline method.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <returns>The code.</returns>
 public string GetTrampolineParameterCode(ParameterModel model)
 {
     if (model.Flags.HasFlag(ParameterModelFlags.IsOutput))
     {
         return(string.Format("ref _{0}", model.Name));
     }
     return(string.Format("{0} != null ? {0}.NativePointer : System.IntPtr.Zero", model.Name));
 }
 /// <summary>
 /// Gets the code for declaring the specified model as a parameter to a managed method.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <returns>The code.</returns>
 public string GetFormalParameterCode(ParameterModel model)
 {
     if (model.Flags.HasFlag(ParameterModelFlags.IsOutput))
     {
         return(string.Format("out {0} {1}", model.Type.Name, model.Name));
     }
     return(string.Format("{0} {1}", model.Type.Name, model.Name));
 }
示例#9
0
 /// <summary>
 /// Gets the code for passing the specified model as parameter to a trampoline method.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <returns>The code.</returns>
 public string GetTrampolineParameterCode(ParameterModel model)
 {
     if (model.Flags.HasFlag(ParameterModelFlags.IsOutput))
     {
         return("System.IntPtr.Zero");
     }
     return(string.Format("new System.IntPtr(_{0})", model.Name));
 }
示例#10
0
 /// <summary>
 /// Gets the code for setup of local variables related to the specified parameter.
 /// </summary>
 /// <param name="marshaller">The marshalling service interface.</param>
 /// <param name="model">The model.</param>
 /// <returns>The code.</returns>
 public string GetLocalVariableSetupCode(MarshallingService marshaller, ParameterModel model)
 {
     if (model.Flags.HasFlag(ParameterModelFlags.IsOutput))
     {
         return(string.Format("System.IntPtr _{0} = default(System.IntPtr);", model.Name));
     }
     return(string.Empty);
 }
示例#11
0
 /// <summary>
 /// Gets the code for cleanup of local variables related to the specified parameter.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <returns>The code.</returns>
 public string GetLocalVariableCleanupCode(ParameterModel model)
 {
     if (model.Flags.HasFlag(ParameterModelFlags.IsOutput))
     {
         return(string.Format("{0} = _{0};", model.Name));
     }
     return(string.Empty);
 }
 /// <summary>
 /// Gets the code for declaring the specified model as a parameter to a managed method.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <returns>The code.</returns>
 public string GetFormalParameterCode(ParameterModel model)
 {
     if (model.Flags.HasFlag(ParameterModelFlags.IsOutput))
     {
         return(string.Format("out System.IntPtr {0}", model.Name));
     }
     else
     {
         return(string.Format("System.IntPtr {0}", model.Name));
     }
 }
 /// <summary>
 /// Gets the code for passing the specified model as parameter to a trampoline method.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <returns>The code.</returns>
 public string GetTrampolineParameterCode(ParameterModel model)
 {
     if (model.Flags.HasFlag(ParameterModelFlags.IsOutput))
     {
         return(string.Format("ref {0}", model.Name));
     }
     else
     {
         return(string.Format("{0}", model.Name));
     }
 }
示例#14
0
        public Type ResolveType(ParameterModel model)
        {
            if (model == null)
            {
                return(null);
            }

            var behavior = new MarshallingService().ResolveBehavior(model);

            if (behavior == MarshalBehavior.Array || behavior == MarshalBehavior.Indirect)
            {
                return(typeof(IntPtr));
            }
            return(ResolveType(model.Type));
        }
示例#15
0
        /// <summary>
        /// Gets the code for passing the specified model as parameter to a trampoline method.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns>The code.</returns>
        public string GetTrampolineParameterCode(ParameterModel model)
        {
            if (model.Flags.HasFlag(ParameterModelFlags.IsOutput))
                return string.Format("ref _{0}", model.Name);

            TranslationModel translationModel = model.Type as TranslationModel;
            if (translationModel != null)
            {
                var type = Type.GetType(translationModel.TargetType);
                if (Marshal.SizeOf(type) > sizeof(long))
                    return string.Format("new System.IntPtr(&{0})", model.Name);
            }

            return model.Name;
        }
示例#16
0
        public MarshalBehavior ResolveBehavior(ParameterModel model)
        {
            if (model.SizeParameter != null)
            {
                if (model.Flags.HasFlag(ParameterModelFlags.HasElementCount))
                    return MarshalBehavior.Array;
                else
                    return MarshalBehavior.Indirect;
            }

            var fallback = ResolveBehavior(model.Type);
            if (fallback == MarshalBehavior.Direct && model.IndirectionLevel > 0)
                return MarshalBehavior.Indirect;
            return fallback;
        }
示例#17
0
        /// <summary>
        /// Gets the code for cleanup of local variables related to the specified parameter.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns>The code.</returns>
        public string GetLocalVariableCleanupCode(ParameterModel model)
        {
            if (model.Flags.HasFlag(ParameterModelFlags.IsOutput))
            {
                //TODO: This check against IUnknown is a hack for DXGISwapChain::GetBuffer. To remove the
                //      hack, it must be made possible to mark a function for removal -- GetBuffer must be
                //      hand-written in terms of the trampoline that would be generated for it, because it
                //      does not make sense for the model layer to understand the relationship between the
                //      output parameter in question, the IID parameter ("riid"), and the object factory.
                if (model.Type.Key == "IUnknown")
                    return string.Format("{0} = SlimDX.ObjectFactory.Create(_{0}, riid);", model.Name);
                return string.Format("{0} = _{0} != System.IntPtr.Zero ? new {1}(_{0}) : null;", model.Name, model.Type.Name);
            }

            return string.Empty;
        }
示例#18
0
        /// <summary>
        /// Gets the code for cleanup of local variables related to the specified parameter.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns>The code.</returns>
        public string GetLocalVariableCleanupCode(ParameterModel model)
        {
            if (model.Flags.HasFlag(ParameterModelFlags.IsOutput))
            {
                //TODO: This check against IUnknown is a hack for DXGISwapChain::GetBuffer. To remove the
                //      hack, it must be made possible to mark a function for removal -- GetBuffer must be
                //      hand-written in terms of the trampoline that would be generated for it, because it
                //      does not make sense for the model layer to understand the relationship between the
                //      output parameter in question, the IID parameter ("riid"), and the object factory.
                if (model.Type.Key == "IUnknown")
                {
                    return(string.Format("{0} = SlimDX.ObjectFactory.Create(_{0}, riid);", model.Name));
                }
                return(string.Format("{0} = _{0} != System.IntPtr.Zero ? new {1}(_{0}) : null;", model.Name, model.Type.Name));
            }

            return(string.Empty);
        }
示例#19
0
        /// <summary>
        /// Gets the code for passing the specified model as parameter to a trampoline method.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns>The code.</returns>
        public string GetTrampolineParameterCode(ParameterModel model)
        {
            if (model.Flags.HasFlag(ParameterModelFlags.IsOutput))
            {
                return(string.Format("ref _{0}", model.Name));
            }

            TranslationModel translationModel = model.Type as TranslationModel;

            if (translationModel != null)
            {
                var type = Type.GetType(translationModel.TargetType);
                if (Marshal.SizeOf(type) > sizeof(long))
                {
                    return(string.Format("new System.IntPtr(&{0})", model.Name));
                }
            }

            return(model.Name);
        }
示例#20
0
        public MarshalBehavior ResolveBehavior(ParameterModel model)
        {
            if (model.SizeParameter != null)
            {
                if (model.Flags.HasFlag(ParameterModelFlags.HasElementCount))
                {
                    return(MarshalBehavior.Array);
                }
                else
                {
                    return(MarshalBehavior.Indirect);
                }
            }

            var fallback = ResolveBehavior(model.Type);

            if (fallback == MarshalBehavior.Direct && model.IndirectionLevel > 0)
            {
                return(MarshalBehavior.Indirect);
            }
            return(fallback);
        }
示例#21
0
 /// <summary>
 /// Gets the code for setup of local variables related to the specified parameter.
 /// </summary>
 /// <param name="marshaller">The marshalling service interface.</param>
 /// <param name="model">The model.</param>
 /// <returns>The code.</returns>
 public string GetLocalVariableSetupCode(MarshallingService marshaller, ParameterModel model)
 {
     if (model.Flags.HasFlag(ParameterModelFlags.IsOutput))
         return string.Format("int _{0} = default(int);", model.Name);
     return string.Empty;
 }
示例#22
0
 public void AddParameter(ParameterModel parameter)
 {
     parameters.Add(parameter);
 }
示例#23
0
 /// <summary>
 /// Gets the code for passing the specified model as parameter to a trampoline method.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <returns>The code.</returns>
 public string GetTrampolineParameterCode(ParameterModel model)
 {
     if (model.Flags.HasFlag(ParameterModelFlags.IsOutput))
         return string.Format("ref _{0}", model.Name);
     return string.Format("{0} != null ? {0}.NativePointer : System.IntPtr.Zero", model.Name);
 }
示例#24
0
 public void AddParameter(ParameterModel parameter)
 {
     parameters.Add(parameter);
 }
示例#25
0
 /// <summary>
 /// Gets the code for cleanup of local variables related to the specified parameter.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <returns>The code.</returns>
 public string GetLocalVariableCleanupCode(ParameterModel model)
 {
     return(string.Format("System.Runtime.InteropServices.Marshal.FreeHGlobal(_{0});", model.Name));
 }
示例#26
0
 /// <summary>
 /// Gets the code for setup of local variables related to the specified parameter.
 /// </summary>
 /// <param name="marshaller">The marshalling service interface.</param>
 /// <param name="model">The model.</param>
 /// <returns>The code.</returns>
 public string GetLocalVariableSetupCode(MarshallingService marshaller, ParameterModel model)
 {
     return(string.Format("System.IntPtr _{0} = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi({0});", model.Name));
 }
示例#27
0
 /// <summary>
 /// Gets the code for declaring the specified model as a parameter to a managed method.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <returns>The code.</returns>
 public string GetFormalParameterCode(ParameterModel model)
 {
     return string.Format("System.String {0}", model.Name);
 }
示例#28
0
 /// <summary>
 /// Gets the code for setup of local variables related to the specified parameter.
 /// </summary>
 /// <param name="marshaller">The marshalling service interface.</param>
 /// <param name="model">The model.</param>
 /// <returns>The code.</returns>
 public string GetLocalVariableSetupCode(MarshallingService marshaller, ParameterModel model)
 {
     return string.Format("{0} = default(System.IntPtr);", model.Name);
 }
 /// <summary>
 /// Gets the code for setup of local variables related to the specified parameter.
 /// </summary>
 /// <param name="marshaller">The marshalling service interface.</param>
 /// <param name="model">The model.</param>
 /// <returns>The code.</returns>
 public string GetLocalVariableSetupCode(MarshallingService marshaller, ParameterModel model)
 {
     return(string.Format("{0} = default(System.IntPtr);", model.Name));
 }
示例#30
0
 /// <summary>
 /// Gets the code for passing the specified model as parameter to a trampoline method.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <returns>The code.</returns>
 public string GetTrampolineParameterCode(ParameterModel model)
 {
     if (model.Flags.HasFlag(ParameterModelFlags.IsOutput))
         return "System.IntPtr.Zero";
     return string.Format("new System.IntPtr(_{0})", model.Name);
 }
示例#31
0
 /// <summary>
 /// Gets the code for cleanup of local variables related to the specified parameter.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <returns>The code.</returns>
 public string GetLocalVariableCleanupCode(ParameterModel model)
 {
     if (model.Flags.HasFlag(ParameterModelFlags.IsOutput))
         return string.Format("{0} = null;", model.Name);
     return string.Empty;
 }
示例#32
0
 /// <summary>
 /// Gets the code for passing the specified model as parameter to a trampoline method.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <returns>The code.</returns>
 public string GetTrampolineParameterCode(ParameterModel model)
 {
     return string.Format("_{0}", model.Name);
 }
示例#33
0
 /// <summary>
 /// Gets the code for setup of local variables related to the specified parameter.
 /// </summary>
 /// <param name="marshaller">The marshalling service interface.</param>
 /// <param name="model">The model.</param>
 /// <returns>The code.</returns>
 public string GetLocalVariableSetupCode(MarshallingService marshaller, ParameterModel model)
 {
     return string.Format("System.IntPtr _{0} = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi({0});", model.Name);
 }
 /// <summary>
 /// Gets the code for passing the specified model as parameter to a trampoline method.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <returns>The code.</returns>
 public string GetTrampolineParameterCode(ParameterModel model)
 {
     return(string.Format("new System.IntPtr(&_{0})", model.Name));
 }
示例#35
0
 /// <summary>
 /// Gets the code for passing the specified model as parameter to a trampoline method.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <returns>The code.</returns>
 public string GetTrampolineParameterCode(ParameterModel model)
 {
     return(string.Format("_{0}", model.Name));
 }
示例#36
0
 /// <summary>
 /// Gets the code for cleanup of local variables related to the specified parameter.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <returns>The code.</returns>
 public string GetLocalVariableCleanupCode(ParameterModel model)
 {
     if (model.Flags.HasFlag(ParameterModelFlags.IsOutput))
         return string.Format("{0} = {1}.FromMarshaller(_{0});", model.Name, model.Type.Name);
     return string.Format("_{0}.Release();", model.Name);
 }
示例#37
0
        public Type ResolveType(ParameterModel model)
        {
            if (model == null)
                return null;

            var behavior = new MarshallingService().ResolveBehavior(model);
            if (behavior == MarshalBehavior.Array || behavior == MarshalBehavior.Indirect)
                return typeof(IntPtr);
            return ResolveType(model.Type);
        }
 /// <summary>
 /// Gets the code for cleanup of local variables related to the specified parameter.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <returns>The code.</returns>
 public string GetLocalVariableCleanupCode(ParameterModel model)
 {
     return(string.Empty);
 }
示例#39
0
 /// <summary>
 /// Gets the code for setup of local variables related to the specified parameter.
 /// </summary>
 /// <param name="marshaller">The marshalling service interface.</param>
 /// <param name="model">The model.</param>
 /// <returns>The code.</returns>
 public string GetLocalVariableSetupCode(MarshallingService marshaller, ParameterModel model)
 {
     if (model.Flags.HasFlag(ParameterModelFlags.IsOutput))
         return string.Format("{0}Marshaller _{1} = default({0}Marshaller);", model.Type.Name, model.Name);
     return string.Format("{0}Marshaller _{1} = {0}.ToMarshaller({1});", model.Type.Name, model.Name);
 }
示例#40
0
 /// <summary>
 /// Gets the code for passing the specified model as parameter to a trampoline method.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <returns>The code.</returns>
 public string GetTrampolineParameterCode(ParameterModel model)
 {
     return string.Format("new System.IntPtr(&_{0})", model.Name);
 }
示例#41
0
 /// <summary>
 /// Gets the code for declaring the specified model as a parameter to a managed method.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <returns>The code.</returns>
 public string GetFormalParameterCode(ParameterModel model)
 {
     return(string.Format("System.String {0}", model.Name));
 }
示例#42
0
 /// <summary>
 /// Gets the code for cleanup of local variables related to the specified parameter.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <returns>The code.</returns>
 public string GetLocalVariableCleanupCode(ParameterModel model)
 {
     return string.Format("System.Runtime.InteropServices.Marshal.FreeHGlobal(_{0});", model.Name);
 }
示例#43
0
 /// <summary>
 /// Gets the code for cleanup of local variables related to the specified parameter.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <returns>The code.</returns>
 public string GetLocalVariableCleanupCode(ParameterModel model)
 {
     return string.Empty;
 }