Пример #1
0
        void loadPackage(string packageName, ClassContext classContext)
        {
            var refTypes       = classContext.ProjectContext.TKTTypes;
            var libWords       = classContext.ProjectContext.LibWords;
            var genericTypes   = classContext.ImportContext.GenericTypes;
            var importPackages = classContext.ImportContext.importPackages;

            List <IGcl> list = new List <IGcl>();

            foreach (var type in refTypes)
            {
                if (type.IsPublic && type.Namespace == packageName)
                {
                    IGcl gcl = GclUtil.Load(type, getWordDict(libWords, type));
                    if (gcl != null)
                    {
                        list.Add(gcl);
                        addGeneric(genericTypes, gcl);
                    }
                }
            }
            if (list.Count == 0)
            {
                errorf("开发包'{0}'内没有类型", packageName);
            }
            else
            {
                importPackages.Add(packageName, list);
            }
        }
Пример #2
0
 static void addGeneric(List <IGcl> genericTypes, IGcl gcl)
 {
     if (gcl.ForType.IsGenericType)
     {
         genericTypes.Add(gcl);
     }
 }
Пример #3
0
        public IGcl SearchGCL(Type type)
        {
            foreach (var igcl in GenericCreatedTypes)
            {
                if (igcl.ForType == type)
                {
                    return(igcl);
                }
            }
            /* 实现和包装在同一个项目里导致找不到正确的GCL */
            List <IGcl> gcls = new List <IGcl>();

            foreach (var igcls in importPackages.Values.ToList())
            {
                foreach (var igcl in igcls)
                {
                    if (igcl.ForType == type)
                    {
                        //return igcl;
                        gcls.Add(igcl);
                    }
                }
                if (gcls.Count > 0)
                {
                    break;
                }
            }

            if (gcls.Count > 0)
            {
                foreach (var gcl in gcls)
                {
                    if (!(gcl is ExternalGcl))
                    {
                        return(gcl);
                    }
                }

                foreach (var gcl in gcls)
                {
                    return(gcl);
                }
            }

            if (type.IsGenericType)
            {
                Type baseGenericType = type.GetGenericTypeDefinition();
                IGcl baseGCL         = SearchGCL(baseGenericType);
                if (baseGCL == null)
                {
                    return(null);
                }
                IGcl newGCL = baseGCL.CreateNewFor(type);
                this.GenericCreatedTypes.Add(newGCL);
                return(newGCL);
            }

            return(null);
        }
Пример #4
0
        Exp analyType(AnalyExpContext context)
        {
            IGcl gcl = context.StmtContext.MethodContext.ClassContext.SearchType(IdentName);

            if (gcl != null)
            {
                Type    type = gcl.ForType;
                TypeExp exp  = new TypeExp(this, IdentToken, type);
                return(exp);
            }
            return(null);
        }
Пример #5
0
        List <IGcl> FindImportEndwith(string name)
        {
            List <IGcl> list    = new List <IGcl>();
            IGcl        typeGcl = searchEndwithFromImportTypes(name);

            if (typeGcl != null)
            {
                list.Add(typeGcl);
            }
            list.AddRange(searchFromPackage(name));
            return(list);
        }
Пример #6
0
        public bool AnalyRet( )
        {
            var methodContext = this.MethodAST.MethodContext;
            var symbols       = MethodAST.MethodContext.Symbols;

            if (RetToken == null)
            {
                methodContext.RetType = typeof(void);
            }
            else
            {
                string     retName = RetToken.GetText();
                SymbolInfo symbol  = symbols.Get(retName);
                if (symbol is SymbolArg)
                {
                    SymbolArg argSymbol = symbol as SymbolArg;
                    if (argSymbol.IsGeneric)
                    {
                        IsGenericRet               = true;
                        GenericRetIndex            = argSymbol.ArgIndex;
                        methodContext.RetType      = typeof(object);
                        methodContext.RetIsGeneric = true;
                    }
                    else
                    {
                        error("非‘类型’的参数不能用作返回类型");
                        return(false);
                    }
                }
                else if (symbol is SymbolDefClass)
                {
                    methodContext.RetType = (symbol as SymbolDefClass).GetRealType();
                }
                else
                {
                    IGcl gcl = this.MethodAST.ClassContext.SearchType(retName);
                    if (gcl != null)
                    {
                        methodContext.RetType = gcl.ForType;
                    }
                    else
                    {
                        errorf("返回结果'{0}'不是类型", retName);
                        return(false);
                    }
                }
            }
            return(true);
        }
Пример #7
0
        public IGcl[] SearchGCLFromImport(string name)
        {
            IGcl gcl = searchFromImportTypes(name);

            if (gcl != null)
            {
                return(new IGcl[] { gcl });
            }

            var packageIgcls = searchFromPackage(name);

            if (packageIgcls.Length > 0)
            {
                return(packageIgcls);
            }
            return(new IGcl[] { });
        }
Пример #8
0
        public IGcl SearchType(string name)
        {
            if (typeNameAnalyer == null)
            {
                typeNameAnalyer = new TypeNameAnalyer(this.ImportContext);
            }
            IGcl gcl = typeNameAnalyer.Analy(name);

            if (gcl != null && gcl.ForType.IsGenericType)
            {
                if (this.ImportContext.GenericCreatedTypes.IndexOf(gcl) == -1)
                {
                    this.ImportContext.GenericCreatedTypes.Add(gcl);
                }
            }
            return(gcl);
        }
Пример #9
0
        public void CompileName(ClassContext classContext, bool isStatic)
        {
            if (TypeToken == null || NameToken == null)
            {
                TrueAnalyed = false;
                return;
            }
            IsStatic          = isStatic;
            this.ClassContext = classContext;
            var symbols = ClassContext.Symbols;

            TypeName     = TypeToken.GetText();
            PropertyName = NameToken.GetText();
            PropertyGcl  = classContext.SearchType(TypeName);

            if (PropertyGcl != null)
            {
                PropertyType = PropertyGcl.ForType;
            }
            else
            {
                errorf("没有找到类型'{0}'", TypeName);
            }

            if (ClassContext.ClassSymbol.PropertyDict.ContainsKey(PropertyName))
            {
                error("属性'" + PropertyName + "'已经存在");
                return;
            }

            if (PropertyType == null)
            {
                error("属性类型'" + TypeName + "'不存在");
                return;
            }
            PropertySymbol = new SymbolDefProperty(PropertyName, PropertyType, isStatic);
            symbols.AddSafe(PropertySymbol);
            ClassContext.ClassSymbol.PropertyDict.Add(PropertyName, PropertySymbol);

            var classBuilder = ClassContext.EmitContext.CurrentTypeBuilder;

            GenerateName(classBuilder, IsStatic);

            AnalyBody(classContext);
        }
Пример #10
0
        NewExp analyNewExp(AnalyExpContext context)
        {
            var symbols = this.AnalyExpContext.Symbols;

            if (!isNewFormat())
            {
                return(null);
            }
            Exp    first = Elements[0];
            string name  = (first as FTextExp).IdentToken.GetText();
            IGcl   gcl   = context.StmtContext.MethodContext.ClassContext.SearchType(name);

            if (gcl == null)
            {
                return(null);
            }
            NewExp newExp = new NewExp(this);

            newExp.SubjectGCL      = gcl;
            newExp.IsAssignedValue = this.IsAssignedValue;
            newExp.BrackestArgs    = (Elements[1] as BracketExp);
            return(newExp);
        }
Пример #11
0
        public IGcl Analy(string name)
        {
            var array = context.SearchGCL(name);

            if (array.Length == 1)
            {
                IGcl gcl0            = array[0];
                int  genericArgCount = GenericUtil.GetGenericTypeArgCount(gcl0.ForType);
                if (genericArgCount == 0)
                {
                    return(gcl0);
                }
                else if (genericArgCount == 1)
                {
                    Type newType = gcl0.ForType.MakeGenericType(new Type[] { typeof(object) });
                    IGcl result  = gcl0.CreateNewFor(newType);
                    return(result);
                }
                else if (genericArgCount == 2)
                {
                    Type newType = gcl0.ForType.MakeGenericType(new Type[] { typeof(object), typeof(object) });
                    IGcl result  = gcl0.CreateNewFor(newType);
                    return(result);
                }
                else
                {
                    return(null);
                }
            }
            else if (array.Length > 1)
            {
                return(null);
            }

            List <IGcl> glist = FindGenericEndwith(name);

            if (glist.Count == 0)
            {
                return(null);
            }
            foreach (IGcl mpClass in glist)
            {
                int    genericArgCount = GenericUtil.GetGenericTypeArgCount(mpClass.ForType);
                string typeName        = mpClass.ShowName;
                string gtypeName       = name.Substring(0, name.Length - typeName.Length);
                if (genericArgCount == 1)
                {
                    var gcls = context.SearchGCLFromImport(gtypeName);//searchTypeSymbol(gtypeName);
                    if (gcls.Length == 1)
                    {
                        Type newType = mpClass.ForType.MakeGenericType(new Type[] { gcls[0].ForType });
                        IGcl result  = mpClass.CreateNewFor(newType);
                        return(result);
                    }
                }
                else if (genericArgCount == 2)
                {
                    List <IGcl> nlist = FindImportEndwith(gtypeName);
                    if (nlist.Count == 0)
                    {
                        return(null);
                    }
                    foreach (var nClass in nlist)
                    {
                        string ntypeName  = nClass.ShowName;
                        string ngtypeName = gtypeName.Substring(0, gtypeName.Length - ntypeName.Length); //string ngtypeName = gtypeName.Substring(0, name.Length - ntypeName.Length);
                        //ITypeSymbol ntypeSymbol = searchTypeSymbol(ngtypeName);
                        var gcls = context.SearchGCLFromImport(ngtypeName);                              //var gcls = context.SearchGCLFromImport(gtypeName);
                        if (gcls.Length == 1)
                        {
                            var  gcl0    = gcls[0];
                            Type newType = mpClass.ForType.MakeGenericType(new Type[] { gcl0.ForType, nClass.ForType });
                            IGcl result  = mpClass.CreateNewFor(newType); //gcl0.CreateNewFor(newType);
                            return(result);
                        }
                    }
                }
            }
            return(null);
        }
Пример #12
0
        public override Exp Analy(AnalyExpContext context)
        {
            base.Analy(context);
            if (MemberToken == null)
            {
                error("'的'字前面没有对象");
                return(null);
            }
            if (MemberToken == null)
            {
                error("'的'字后面没有属性名称");
                return(null);
            }
            var symbols = this.AnalyExpContext.Symbols;

            SubjectExp.IsAssignedBy    = this.IsAssignedBy;
            SubjectExp.IsAssignedValue = this.IsAssignedValue;
            SubjectExp   = SubjectExp.Analy(context);
            propertyName = MemberToken.GetText();
            var subjType = SubjectExp.RetType;

            if (subjType == null)
            {
                return(null);
            }
            if (propertyName == "每一个" && subjType.IsGenericType && subjType.GetGenericTypeDefinition() == typeof(Z语言系统.列表 <>))
            {
                EveryOneExp eoexp = new EveryOneExp();
                eoexp.ListExp     = this.SubjectExp;
                eoexp.MemberToken = this.MemberToken;
                Exp eoExp = eoexp.Analy(context);
                return(eoExp);
            }
            else
            {
                if (!(subjType is TypeBuilder))
                {
                    IGcl obj = context.StmtContext.MethodContext.ClassContext.ImportContext.SearchGCL(subjType);
                    if (obj == null)
                    {
                        //ExProperty = subjType.GetExProperty(propertyName);
                        ExProperty = GclUtil.SearchExProperty(propertyName, subjType);
                    }
                    else
                    {
                        ExProperty = obj.SearchExProperty(propertyName);
                    }
                }
                else
                {
                    string     name   = subjType.Name;
                    SymbolInfo symbol = symbols.Get(name);
                    if (symbol is SymbolDefClass)
                    {
                        ExProperty = (symbol as SymbolDefClass).GetExProperty(propertyName);
                        //ExProperty = GclUtil.SearchExProperty(propertyName, symbol as SymbolDefClass);
                    }
                }
            }
            if (ExProperty == null)
            {
                error(SubjectExp.Postion, "不存在" + propertyName + "属性");
                return(null);
            }
            else
            {
                RetType = ExProperty.Property.PropertyType;
            }
            return(this);
        }