Ejemplo n.º 1
0
        private static void TranslateReturnValue(CodeTypeDelegate d)
        {
            CodeTypeReference s;

            if (d.ReturnType.BaseType == "void")
            {
                d.ReturnType.BaseType = "System.Void";
            }

            if (GLTypes.TryGetValue(d.ReturnType.BaseType, out s))
            {
                d.ReturnType = s;
            }

            if (d.ReturnType.BaseType == "GLstring")
            {
                d.ReturnType = new CodeTypeReference("IntPtr");
                d.ReturnType.UserData.Add("Wrapper", WrapperTypes.StringReturnValue);
            }

            if (d.ReturnType.BaseType.ToLower().Contains("object"))
            {
                d.ReturnType.BaseType = "IntPtr";
                d.ReturnType.UserData.Add("Wrapper", WrapperTypes.GenericReturnValue);
                d.ReturnType.ArrayRank = 0;
            }

            if (d.ReturnType.UserData.Contains("Wrapper"))
            {
                d.UserData.Add("Wrapper", null);
            }
        }
Ejemplo n.º 2
0
        private static void TranslateParameters(CodeTypeDelegate d)
        {
            CodeTypeReference s;

            if (d.Name == "GetBufferPointerv")
            {
            }

            // Translate each parameter of the function while checking for needed wrappers:
            foreach (CodeParameterDeclarationExpression p in d.Parameters)
            {
                // Translate parameter type
                if (GLTypes.TryGetValue(p.Type.BaseType, out s))
                {
                    p.Type.BaseType = s.BaseType;
                }

                // Check for needed wrappers:
                if (p.Type.BaseType.Contains("ushort") && d.Name.Contains("LineStipple"))
                {
                    // glLineStipple needs wrapper to allow large unsigned mask values.
                    p.UserData.Add("Wrapper", WrapperTypes.UncheckedParameter);
                }
                else if (p.Type.ArrayRank > 0 && p.Type.BaseType.Contains("String"))
                {
                    // string parameters do not need special wrappers. We add this here
                    // to simplify the next if-statements.
                    // p.Type.ArrayRank = 0;
                }
                else if (p.Type.ArrayRank > 0 && p.Type.BaseType.Contains("char") ||
                         p.Type.ArrayRank == 0 && p.Type.BaseType.Contains("String"))

                {
                    // GLchar[] parameters should become (in) string or (out) StringBuilder
                    if (p.Direction == FieldDirection.Out || p.Direction == FieldDirection.Ref)
                    {
                        p.Type = new CodeTypeReference("System.Text.StringBuilder");
                    }
                    else
                    {
                        p.Type = new CodeTypeReference("System.String");
                    }
                }
                else if (p.Type.ArrayRank > 0)
                {
                    // All other array parameters need wrappers (around IntPtr).
                    if (p.Type.BaseType.Contains("void") || p.Type.BaseType.Contains("Void"))
                    {
                        p.UserData.Add("Wrapper", WrapperTypes.GenericParameter);
                    }
                    else if (p.Type.BaseType.Contains("IntPtr"))
                    {
                        //p.UserData.Add("Wrapper", WrapperTypes.PointerParameter);
                    }
                    else
                    {
                        p.UserData.Add("Wrapper", WrapperTypes.ArrayParameter);
                        p.UserData.Add("OriginalType", new string(p.Type.BaseType.ToCharArray()));
                    }

                    // We do not want an array of IntPtrs (IntPtr[]) - it is the IntPtr that points to the array.
                    p.Type           = new CodeTypeReference();
                    p.Type.BaseType  = "System.IntPtr";
                    p.Type.ArrayRank = 0;
                    p.UserData.Add("Flow", p.Direction);
                    // The same wrapper works for either in or out parameters.
                    //p.CustomAttributes.Add(new CodeAttributeDeclaration("In, Out"));
                }

                if (p.UserData.Contains("Wrapper") && !d.UserData.Contains("Wrapper"))
                {
                    // If there is at least 1 parameter that needs wrappers, mark the function for wrapping.
                    d.UserData.Add("Wrapper", null);
                }

                //p.Direction = FieldDirection.In;
            }
        }