コード例 #1
0
            //

            public MethodParameterPropertyImpl(object owner, string name, bool isStatic, Metadata.TypeInfo type, Metadata.TypeInfo typeUnreferenced, Metadata.Parameter[] indexers, bool readOnly, string category, string displayName, bool referenceSupport, CompiledShaderScript.Parameter parameter, bool invoke)
                : base(owner, name, isStatic, type, typeUnreferenced, indexers, readOnly)
            {
                this.category         = category;
                this.displayName      = displayName;
                this.referenceSupport = referenceSupport;
                this.parameter        = parameter;
                this.invoke           = invoke;
            }
コード例 #2
0
        MethodParameterPropertyImpl OneMethod_AddPropertyOfParameter(CompiledShaderScript.Parameter parameter)
        {
            ////!!!!имя еще как-то фиксить?
            string name = null;

            if (parameter.ReturnValue)
            {
                name = "ReturnValue";
            }
            else
            {
                name = parameter.Name.Substring(0, 1).ToUpper() + parameter.Name.Substring(1);
            }

            bool readOnly = parameter.Output || parameter.ReturnValue;

            //!!!!
            //var parameterType = GetOverrideParameterType( parameter, out bool error );
            //if( error )
            //{
            //	unableToInit = true;
            //	goto unableToInitLabel;
            //}
            //var parameterType = parameter.Type;

            Metadata.TypeInfo type;
            bool referenceSupport = !readOnly;

            if (referenceSupport)
            {
                Type unrefNetType = parameter.Type.GetNetType();
                var  refNetType   = typeof(Reference <>).MakeGenericType(unrefNetType);
                type = MetadataManager.GetTypeOfNetType(refNetType);
            }
            else
            {
                type = parameter.Type;
            }

            bool invoke = parameter.ReturnValue || parameter.ByReference || parameter.Output;

            string namePrefix  = "__parameter_";
            string displayName = TypeUtility.DisplayNameAddSpaces(name);

            var prop = new MethodParameterPropertyImpl(this, namePrefix + name, false, type, parameter.Type, new Metadata.Parameter[0], readOnly, "Method's Parameters", displayName, referenceSupport, parameter, invoke);

            prop.Description = "";
            if (!readOnly)
            {
                prop.Serializable = SerializeType.Enable;
            }

            return(prop);
        }
コード例 #3
0
        static CompiledShaderScript GetOrCompileScript(string code, out string error)
        {
            error = "";

            lock ( compiledScriptCache )
            {
                if (compiledScriptCache.TryGetValue(code, out var script))
                {
                    return(script);
                }
            }

            var lines = code.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);

            var line = "";

            foreach (var line2 in lines)
            {
                if (line2.Contains(@"/*!public*/"))
                {
                    line = line2;
                    break;
                }
            }

            if (string.IsNullOrEmpty(line))
            {
                error = "No method is marked public.";
                return(null);
            }

            var result = new CompiledShaderScript();

            result.Body = code;

            try
            {
                // /*!public*/ vec3 Method(vec3 parameter1, vec3 parameter2)

                var str1 = line.Substring(line.IndexOf(@"/*!public*/") + @"/*!public*/".Length);

                int braceOpen  = str1.IndexOf('(');
                int braceClose = str1.IndexOf(')');

                var str2      = str1.Substring(0, braceOpen).Trim();
                var str2Split = str2.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (str2Split.Length != 2)
                {
                    throw new Exception("");
                }

                var parameters = new List <CompiledShaderScript.Parameter>();

                //get return type
                var returnTypeStr = str2Split[0];
                var returnType    = GetTypeByString(returnTypeStr, true);
                if (returnType == null)
                {
                    throw new Exception($"Unknown type \"{returnTypeStr}\".");
                }

                //get method name
                result.MethodName = str2Split[1];

                //parameters
                str2      = str1.Substring(braceOpen + 1, braceClose - braceOpen - 1).Trim();
                str2Split = str2.Split(new char[] { ',' });
                foreach (var str3 in str2Split)
                {
                    var str4 = str3.Trim();

                    var str4Split = str4.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    if (str4Split.Length < 2 || str4Split.Length > 3)
                    {
                        throw new Exception("");
                    }

                    //out, ref
                    bool isOut = false;
                    if (str4Split.Length == 3)
                    {
                        switch (str4Split[0])
                        {
                        case "out": throw new Exception("Output parameters are not supported.");

                        //case "out": isOut = true; break;
                        case "ref": throw new Exception("Parameters passed by reference are not supported.");

                        default: throw new Exception("");
                        }
                    }

                    //get type
                    var typeStr = str4Split.Length == 3 ? str4Split[1] : str4Split[0];
                    var type    = GetTypeByString(typeStr, false);
                    if (type == null)
                    {
                        throw new Exception($"Unknown type \"{typeStr}\".");
                    }

                    //get name
                    var name = str4Split.Length == 3 ? str4Split[2] : str4Split[1];

                    //add parameter
                    var p = new CompiledShaderScript.Parameter();
                    p.Name   = name;
                    p.Type   = MetadataManager.GetTypeOfNetType(type);
                    p.Output = isOut;
                    parameters.Add(p);
                }

                //add return parameter
                if (returnType != typeof(void))
                {
                    var p = new CompiledShaderScript.Parameter();
                    p.Name        = "ReturnValue";
                    p.Type        = MetadataManager.GetTypeOfNetType(returnType);
                    p.ReturnValue = true;
                    parameters.Add(p);
                }

                result.MethodParameters = parameters.ToArray();
            }
            catch (Exception e)
            {
                error = "Can't parse method signature.\r\n" + "\"" + line + "\"" + "\r\n\r\n" + e.Message;
                return(null);
            }

            //add to cache
            lock ( compiledScriptCache )
            {
                if (compiledScriptCache.Count > 300)
                {
                    compiledScriptCache.Clear();
                }
                compiledScriptCache[code] = result;
            }

            return(result);
        }