Exemplo n.º 1
0
        void ParseMethodSignature(XElement top, VkCommandInfo result)
        {
            var signature = new VkMethodSignature();

            signature.Name       = (result.Name.StartsWith("vk", StringComparison.InvariantCulture)) ? result.Name.Substring(2) : result.Name;
            signature.ReturnType = result.CsReturnType;

            var arguments = new Dictionary <string, VkFunctionArgument> ();

            foreach (var arg in result.NativeFunction.Arguments)
            {
                arguments.Add(arg.Name, arg);
            }

            // FILTER OUT VALUES FOR SIGNATURE
            foreach (var arg in result.NativeFunction.Arguments)
            {
                // object reference
                if (Handles.ContainsKey(arg.BaseCsType) && !arg.IsPointer)
                {
                    if (arg.Index == 0)
                    {
                        result.FirstInstance = arg;
                    }

                    arguments.Remove(arg.Name);
                }

                VkFunctionArgument localLength;
                if (arg.LengthVariable != null && arguments.TryGetValue(arg.LengthVariable, out localLength))
                {
                    result.LocalVariables.Add(localLength);
                    arguments.Remove(arg.LengthVariable);
                }
            }

            signature.Parameters = (from arg in arguments.Values
                                    orderby arg.Index ascending
                                    select new VkMethodParameter {
                Name = arg.Name, Source = arg
            }).ToList();

            foreach (var param in signature.Parameters)
            {
                param.CsType           = param.Source.BaseCsType;
                param.UseOut           = param.Source.UseOut;
                param.IsFixedArray     = param.Source.IsFixedArray;
                param.IsArrayParameter = !param.Source.IsConst && param.Source.LengthVariable != null;
                param.IsNullableType   = param.Source.IsPointer && param.Source.IsOptional;
                param.UseRef           = param.Source.UseOut && blittableTypes.Contains(param.CsType);
            }

            result.MethodSignature = signature;
        }
Exemplo n.º 2
0
        static List <VkContainerClass> RefactorMgInterfaces()
        {
            var interfaces = new Type[] {
                typeof(IMgEntrypoint),
                typeof(IMgInstance),
                typeof(IMgPhysicalDevice),
                typeof(IMgDevice),
                typeof(IMgQueue),
                typeof(IMgCommandBuffer),

                typeof(IMgDeviceMemory),
                typeof(IMgCommandPool),
                typeof(IMgBuffer),
                typeof(IMgBufferView),
                typeof(IMgImage),

                typeof(IMgImageView),
                typeof(IMgShaderModule),
                typeof(IMgPipeline),
                typeof(IMgPipelineLayout),
                typeof(IMgSampler),

                typeof(IMgDescriptorSet),
                typeof(IMgDescriptorSetLayout),
                typeof(IMgDescriptorPool),
                typeof(IMgFence),
                typeof(IMgSemaphore),

                typeof(IMgEvent),
                typeof(IMgQueryPool),
                typeof(IMgFramebuffer),
                typeof(IMgRenderPass),
                typeof(IMgPipelineCache),

                typeof(IMgSurfaceKHR),
                typeof(IMgSwapchainKHR),
                typeof(IMgDebugReportCallbackEXT),
                typeof(IMgAllocationCallbacks),
            };

            var uniques = new StringCollection();


            foreach (var handle in interfaces)
            {
                if (uniques.Contains(handle.Name))
                {
                    throw new InvalidOperationException();
                }
                else
                {
                    uniques.Add(handle.Name);
                }
            }

            var reservedNames = new StringCollection()
            {
                "event", "object"
            };

            var implementation = new List <VkContainerClass>();

            foreach (var i in interfaces)
            {
                var container = new VkContainerClass {
                    Name = i.Name.Replace("IMg", "Vk")
                };
                container.InterfaceName = i.Name;
                foreach (var info in i.GetMethods())
                {
                    var method = new VkMethodSignature
                    {
                        Name       = info.Name,
                        IsStatic   = false,
                        ReturnType = info.ReturnType.Name,
                    };

                    if (method.ReturnType == "Void")
                    {
                        method.ReturnType = "void";
                    }

                    foreach (var param in info.GetParameters())
                    {
                        var p = new VkMethodParameter
                        {
                            Name       = param.Name,
                            BaseCsType = param.ParameterType.Name,
                            UseOut     = param.IsOut,
                        };

                        // Name
                        if (reservedNames.Contains(p.Name))
                        {
                            p.Name = "@" + p.Name;
                        }


                        // BaseCsType
                        if (p.UseOut)
                        {
                            p.BaseCsType = p.BaseCsType.Replace("&", "");
                        }
                        else if (p.BaseCsType == "Void")
                        {
                            p.BaseCsType = "void";
                        }
                        else if (p.BaseCsType == "String")
                        {
                            p.BaseCsType = "string";
                        }

                        method.Parameters.Add(p);
                    }

                    container.Methods.Add(method);
                }
                implementation.Add(container);
            }
            return(implementation);
        }