Exemplo n.º 1
0
        public ICLS_Type GetType(CLType type)
        {
            if (type == null)
            {
                return(typess["null"]);
            }

            ICLS_Type ret = null;

            if (types.TryGetValue(type, out ret) == false)
            {
                logger.Log_Warn("(CLScript)类型未注册,将自动注册一份匿名:" + type.ToString());
                ret = RegHelper_Type.MakeType(type, "");
                RegType(ret);
            }
            return(ret);
        }
Exemplo n.º 2
0
        public CLS_Environment(ICLS_Logger logger)
        {
            //if(useNamespace==true)
            //{
            //    throw new Exception("使用命名空间还不能完全兼容,建议关闭");
            //}
            this.logger = logger;
            //this.useNamespace = useNamespace;
            tokenParser = new CLS_TokenParser();
            compiler    = new CLS_Expression_Compiler(logger);
            RegType(new CLS_Type_Int());
            RegType(new CLS_Type_UInt());
            RegType(new CLS_Type_Float());
            RegType(new CLS_Type_Double());
            RegType(new CLS_Type_String());
            RegType(new CLS_Type_Var());
            RegType(new CLS_Type_Bool());
            RegType(new CLS_Type_Lambda());
            RegType(new CLS_Type_Delegate());
            RegType(new CLS_Type_Byte());
            RegType(new CLS_Type_Char());
            RegType(new CLS_Type_UShort());
            RegType(new CLS_Type_Sbyte());
            RegType(new CLS_Type_Short());
            RegType(new CLS_Type_Long());
            RegType(new CLS_Type_ULong());

            RegType(RegHelper_Type.MakeType(typeof(object), "object"));
            RegType(RegHelper_Type.MakeType(typeof(List <>), "List"));
            RegType(RegHelper_Type.MakeType(typeof(Dictionary <,>), "Dictionary"));

            typess["null"] = new CLS_Type_NULL();
            //contentGloabl = CreateContent();
            //if (!useNamespace)//命名空间模式不能直接用函数
            {
                RegFunction(new FunctionTrace());
            }
        }
Exemplo n.º 3
0
        public ICLS_Type GetTypeByKeyword(string keyword)
        {
            ICLS_Type iType;

            if (dictTypeKeywords.TryGetValue(keyword, out iType))
            {
                return(iType);
            }

            int len = keyword.Length;

            if (keyword[len - 1] == '>')
            {
                int           iis      = keyword.IndexOf('<');
                string        typeName = keyword.Substring(0, iis);
                List <string> _types   = new List <string>();
                int           istart   = iis + 1;
                int           inow     = istart;
                int           dep      = 0;
                while (inow < len)
                {
                    if (keyword[inow] == '<')
                    {
                        dep++;
                    }
                    if (keyword[inow] == '>')
                    {
                        dep--;
                        if (dep < 0)
                        {
                            _types.Add(keyword.Substring(istart, inow - istart));
                            break;
                        }
                    }

                    if (keyword[inow] == ',' && dep == 0)
                    {
                        _types.Add(keyword.Substring(istart, inow - istart));
                        istart = inow + 1;
                        inow   = istart;
                        continue;
                    }

                    inow++;
                }

                iType = GetTypeByKeyword(typeName);
                if (iType != null)
                {
                    Type genericType = iType.type;
                    if (genericType != null && genericType.IsGenericTypeDefinition)
                    {
                        Type[] types = new Type[_types.Count];
                        for (int i = 0; i < types.Length; i++)
                        {
                            iType = GetTypeByKeyword(_types[i]);

                            Type rt = iType.type;
                            if (rt != null)
                            {
                                types[i] = rt;
                            }
                            else
                            {
                                types[i] = typeof(SInstance);
                            }
                        }

                        if (typeName == "List" && types[0] == typeof(SInstance))
                        {
                            iType = new CLS_Type_List <SInstance>(keyword);
                        }
                        else
                        {
                            iType = new RegHelper_Type(genericType.MakeGenericType(types), keyword);
                        }

                        RegType(iType);
                        return(iType);
                    }
                }
            }
            else if (keyword[len - 1] == ']')
            {
                string typeName = keyword.Substring(0, keyword.IndexOf('['));
                iType = GetTypeByKeyword(typeName);
                if (iType != null)
                {
                    Type rt = iType.type;
                    if (rt == null)
                    {
                        rt    = typeof(SInstance);
                        iType = new CLS_Type_Array <SInstance>(keyword);
                    }
                    else
                    {
                        iType = new RegHelper_Type(rt.MakeArrayType(), keyword);
                    }

                    RegType(iType);
                    return(iType);
                }
            }

            logger.Log_Error("类型未注册: " + keyword);
            return(null);
        }
Exemplo n.º 4
0
        public ICLS_Type GetTypeByKeyword(string keyword)
        {
            ICLS_Type iType;
            if (dictTypeKeywords.TryGetValue(keyword, out iType))
                return iType;

            int len = keyword.Length;
            if (keyword[len - 1] == '>')
            {
                int iis = keyword.IndexOf('<');
                string typeName = keyword.Substring(0, iis);
                List<string> _types = new List<string>();
                int istart = iis + 1;
                int inow = istart;
                int dep = 0;
                while (inow < len)
                {
                    if (keyword[inow] == '<')
                    {
                        dep++;
                    }
                    if (keyword[inow] == '>')
                    {
                        dep--;
                        if (dep < 0)
                        {
                            _types.Add(keyword.Substring(istart, inow - istart));
                            break;
                        }
                    }

                    if (keyword[inow] == ',' && dep == 0)
                    {
                        _types.Add(keyword.Substring(istart, inow - istart));
                        istart = inow + 1;
                        inow = istart;
                        continue;
                    }

                    inow++;
                }

                iType = GetTypeByKeyword(typeName);
                if (iType != null)
                {
                    Type genericType = iType.type;
                    if (genericType != null && genericType.IsGenericTypeDefinition)
                    {
                        Type[] types = new Type[_types.Count];
                        for (int i = 0; i < types.Length; i++)
                        {
                            iType = GetTypeByKeyword(_types[i]);

                            Type rt = iType.type;
                            if (rt != null)
                                types[i] = rt;
                            else
                                types[i] = typeof(SInstance);
                        }

                        if (typeName == "List" && types[0] == typeof(SInstance))
                        {
                            iType = new CLS_Type_List<SInstance>(keyword);
                        }
                        else
                        {
                            iType = new RegHelper_Type(genericType.MakeGenericType(types), keyword);
                        }

                        RegType(iType);
                        return iType;
                    }
                }
            }
            else if (keyword[len - 1] == ']')
            {
                string typeName = keyword.Substring(0, keyword.IndexOf('['));
                iType = GetTypeByKeyword(typeName);
                if (iType != null)
                {
                    Type rt = iType.type;
                    if (rt == null)
                    {
                        rt = typeof(SInstance);
                        iType = new CLS_Type_Array<SInstance>(keyword);
                    }
                    else
                    {
                        iType = new RegHelper_Type(rt.MakeArrayType(), keyword);
                    }

                    RegType(iType);
                    return iType;
                }
            }

            logger.Log_Error("类型未注册: " + keyword);
            return null;
        }