Esempio n. 1
0
        public ZLDimInfo CreateZType()
        {
            Type type        = DimBuilder.CreateType();
            var  EmitedZType = ZTypeManager.CreateZLDimImp(type);

            return(EmitedZType);
        }
Esempio n. 2
0
        public ZLEnumInfo CreateZType()
        {
            var        EmitedType = EnumTypeBuilder.CreateType();
            ZLEnumInfo ztype      = ZTypeManager.GetByMarkType(EmitedType) as ZLEnumInfo;

            return(ztype);
        }
Esempio n. 3
0
        public override Exp Analy( )
        {
            //SubjectExp.SetContext(this.ExpContext);
            //ArgExp.SetContext(this.ExpContext);

            SubjectExp = AnalySubExp(SubjectExp); // SubjectExp.Analy();
            ArgExp     = AnalySubExp(ArgExp);     //ArgExp = ArgExp.Analy();
            if (!this.AnalyCorrect)
            {
                return(this);
            }

            var propertyName = CompileConstant.ZListItemPropertyName;// "Item";
            var subjType     = SubjectExp.RetType;

            if (subjType is ZClassType)
            {
                ZClassType zclass = subjType as ZClassType;
                Property = zclass.SharpType.GetProperty(propertyName);
            }

            if (Property == null)
            {
                ErrorE(SubjectExp.Postion, "不存在索引");
            }
            else
            {
                RetType = ZTypeManager.GetBySharpType(Property.PropertyType) as ZType;
            }
            return(this);
        }
Esempio n. 4
0
        private ZType GetZTypeByTypeName(string typeName)
        {
            //if (typeName == "Func<bool>")
            //{
            //    arg = new ZMethodArg(typeName, ZTypeCache.GetByZType(typeof(Func<bool>)));
            //}
            //else if (argtypename == "Action")
            //{
            //    arg = new ZMethodArg(realArgName, ZTypeCache.GetByZType(typeof(Action)));
            //}
            //else
            //{

            var ztypes = ZTypeManager.GetByMarkName(typeName);

            if (ztypes.Length == 0)
            {
                ztypes = ZTypeManager.GetBySharpName(typeName);
            }
            if (ztypes.Length > 0)
            {
                ZType ztype = ztypes[0] as ZType;
                //arg = new ZMethodArg(typeName, ztype);
                return(ztype);
            }
            else
            {
            }
            return(null);
        }
Esempio n. 5
0
        public override Exp Analy( )
        {
            if (this.IsAnalyed)
            {
                return(this);
            }
            SubjectExp = AnalySubExp(SubjectExp);
            ArgExp     = AnalySubExp(ArgExp);
            if (!this.AnalyCorrect)
            {
                return(this);
            }

            var propertyName = ZLangUtil.ZListItemPropertyName;
            var subjType     = SubjectExp.RetType;

            if (subjType is ZLClassInfo)
            {
                ZLClassInfo zclass  = subjType as ZLClassInfo;
                Type        argType = ZTypeUtil.GetTypeOrBuilder(ArgExp.RetType);
                Property = zclass.SharpType.GetProperty(propertyName, new Type[] { argType });
            }

            if (Property == null)
            {
                Errorf(SubjectExp.Position, "不存在索引");
            }
            else
            {
                RetType = ZTypeManager.GetBySharpType(Property.PropertyType) as ZType;
            }
            IsAnalyed = true;
            return(this);
        }
Esempio n. 6
0
        public override Exp Analy( )
        {
            if (this.IsAnalyed)
            {
                return(this);
            }
            AnalyCorrect = true;
            if (LeftExp == null && RightExp != null)
            {
                ExpUnary unexp = new ExpUnary(this.ExpContext, OpToken, RightExp);
                var      exp   = unexp.Analy();
                return(exp);
            }
            else if (LeftExp == null && RightExp == null)
            {
                Errorf(this.OpToken.Position, "运算符'{0}'两边缺少表达式", OpToken.Text);
            }
            OpKind   = OpToken.Kind;
            LeftExp  = AnalySubExp(LeftExp);
            RightExp = AnalySubExp(RightExp);

            if (RightExp == null)
            {
                Errorf(OpToken.Position, "运算符'{0}'右边缺少运算元素", OpToken.Text);
            }
            else
            {
                this.AnalyCorrect = this.LeftExp.AnalyCorrect && RightExp.AnalyCorrect && this.AnalyCorrect;
                if (LeftExp.AnalyCorrect && RightExp.AnalyCorrect)
                {
                    ZType ltype = LeftExp.RetType;
                    ZType rtype = RightExp.RetType;
                    if (ZTypeUtil.IsVoid(ltype) || ZTypeUtil.IsVoid(rtype))
                    {
                        Errorf(OpToken.Position, "没有结果的表达式无法进行'{0}'运算", OpToken.ToCode());
                    }
                    else
                    {
                        OpMethod = ExpBinaryUtil.GetCalcMethod(OpKind, ltype, rtype);
                        if (OpMethod != null)
                        {
                            RetType = ZTypeManager.GetBySharpType(OpMethod.ReturnType) as ZType;
                        }
                        else
                        {
                            Errorf(OpToken.Position, "两种类型无法进行'{0}'运算", OpToken.ToCode());
                        }
                    }
                }
                else
                {
                    this.RetType = ZLangBasicTypes.ZOBJECT;
                }
            }
            //AnalyResultLocal();
            IsAnalyed = true;
            return(this);
        }
Esempio n. 7
0
        public void EmitGet( )
        {
            MethodInfo getMethod = Property.GetGetMethod();

            SubjectExp.Emit();
            ArgExp.RequireType = ZTypeManager.GetBySharpType(getMethod.ReturnType) as ZType;
            ArgExp.Emit();
            EmitHelper.CallDynamic(IL, getMethod);
        }
Esempio n. 8
0
 public ZDimType GetCreatedZType()
 {
     if (EmitedZType == null)
     {
         Type type = this.Builder.CreateType();
         EmitedZType = ZTypeManager.GetByMarkType(type) as ZDimType;
     }
     return(EmitedZType);
 }
Esempio n. 9
0
        public void Analy()
        {
            string      fileName  = this.ASTClass.FileContext.FileModel.GeneratedClassName;
            bool        IsStatic  = false;
            ZLClassInfo BaseZType = null;

            if (Raw == null)
            {
                IsStatic  = false;
                BaseZType = ZLangBasicTypes.ZOBJECT;
            }
            else if (Raw.BaseTypeToken == null)
            {
                ExtendsTypeName = null;
                IsStatic        = false;
                BaseZType       = ZLangBasicTypes.ZOBJECT;
            }
            else
            {
                ExtendsTypeName = Raw.BaseTypeToken.Text;
                if (ExtendsTypeName == "唯一类型")
                {
                    IsStatic = true;
                }
                else if (ExtendsTypeName == "普通类型" || ExtendsTypeName == "一般类型")
                {
                    IsStatic  = false;
                    BaseZType = ZLangBasicTypes.ZOBJECT;
                }
                else
                {
                    IsStatic = false;
                    var ztypes = ZTypeManager.GetByMarkName(ExtendsTypeName);
                    if (ztypes.Length == 0)
                    {
                        this.ASTClass.FileContext.Errorf(Raw.BaseTypeToken.Position, "类型'{0}'不存在", ExtendsTypeName);
                    }
                    else if (ztypes.Length == 1)
                    {
                        BaseZType = ztypes[0] as ZLClassInfo;
                    }
                    else if (ztypes.Length == 0)
                    {
                        this.ASTClass.FileContext.Errorf(Raw.BaseTypeToken.Position, "'{0}'存在{1}个同名类型", ExtendsTypeName, ztypes.Length.ToString());
                    }
                }
                //if (ClassName != fileName)
                //{
                //    this.FileContext.Errorf(BaseTypeToken.Position, "类名称 '" + ClassName + "'和文件名称'" + fileName + "'不一致");
                //}
            }
            this.ASTClass.ClassContext.SetIsStatic(IsStatic);
            this.ASTClass.ClassContext.SetSuperClass(BaseZType);
        }
Esempio n. 10
0
        public override Exp Analy( )
        {
            //var propertyName = "Item";
            var subjType = ListSymbol.SymbolZType;

            ZClassType zclass = subjType as ZClassType;

            Property = zclass.SharpType.GetProperty(CompileConstant.ZListItemPropertyName);//propertyName);
            RetType  = ZTypeManager.GetBySharpType(Property.PropertyType) as ZType;
            return(this);
        }
Esempio n. 11
0
        public ZType Compile(ModuleBuilder moduleBuilder, string packageName)
        {
            AnalyName();
            EmitName(moduleBuilder, packageName);
            AnalyBody();
            EmitBody();
            var   EmitedType = Builder.CreateType();
            ZType ztype      = ZTypeManager.GetByMarkType(EmitedType) as ZType;

            return(ztype);
        }
Esempio n. 12
0
        protected void EmitArgsExp(ParameterInfo[] paramInfos, Exp[] args)
        {
            var size = paramInfos.Length;

            for (int i = 0; i < size; i++)
            {
                Exp           argExp    = args[i];
                ParameterInfo parameter = paramInfos[i];
                argExp.RequireType = ZTypeManager.GetBySharpType(parameter.ParameterType) as ZType;
                argExp.Emit();
            }
        }
Esempio n. 13
0
        public void CreateZType()
        {
            ProjectCompileResult compileResult = this.ProjectContext.CompileResult;

            if (!HasError())
            {
                Type       type  = this.ClassSection.Builder.CreateType();
                IZDescType ztype = ZTypeManager.GetByMarkType(type);
                this.FileContext.EmitedZClass = ztype as ZType;
                this.ProjectContext.CompileResult.CompiledTypes.Add(ztype);
            }
        }
Esempio n. 14
0
        private void AnalyGeneric_1()
        {
            Token genericArgTypeToken = TypeTokens[0];
            ZType genericArgZType     = SearchZType(genericArgTypeToken);

            if (genericArgZType != null)
            {
                Type  newType  = mainZType.SharpType.MakeGenericType(genericArgZType.SharpType);
                ZType newZtype = ZTypeManager.RegNewGenericType(newType);
                RetType = newZtype;
            }
        }
Esempio n. 15
0
        //public void EmitBody()
        //{
        //    if (Properties != null)
        //    {
        //        Properties.EmitBodys();
        //    }
        //    foreach (ProcConstructorBase item in Constructors)
        //    {
        //        item.EmitBody();
        //    }
        //    foreach (ProcMethod item in Methods)
        //    {
        //        item.EmitBody();
        //    }
        //}

        public ZLClassInfo CreateZType()
        {
            if (!HasError())
            {
                Type        type       = this.ClassContext.GetTypeBuilder().CreateType();
                var         ztype      = ZTypeManager.GetByMarkType(type);
                ZLClassInfo zclasstype = (ZLClassInfo)ztype;
                this.FileContext.EmitedIZDescType = zclasstype;
                return(zclasstype);
            }
            return(null);
        }
Esempio n. 16
0
        public void EmitSet(Exp valueExp)
        {
            MethodInfo setMethod = Property.GetSetMethod();

            SubjectExp.Emit();
            ArgExp.RequireType = ZTypeManager.GetBySharpType(setMethod.GetParameters()[0].ParameterType) as ZType;
            ArgExp.Emit();
            //EmitHelper.Box(il, ArgExp.RetType, setMethod.GetParameters()[0].ParameterType);
            valueExp.RequireType = ZTypeManager.GetBySharpType(setMethod.GetParameters()[1].ParameterType) as ZType;
            valueExp.Emit();
            EmitHelper.CallDynamic(IL, setMethod);
        }
Esempio n. 17
0
        private void AnalyGeneric_2()
        {
            Token genericArgTypeToken1 = TypeTokens[0];
            Token genericArgTypeToken2 = TypeTokens[1];
            ZType genericArgZType1     = SearchZType(genericArgTypeToken1);
            ZType genericArgZType2     = SearchZType(genericArgTypeToken2);

            if (genericArgZType1 != null && genericArgZType2 != null)
            {
                Type  newType  = mainZType.SharpType.MakeGenericType(genericArgZType1.SharpType, genericArgZType2.SharpType);
                ZType newZtype = ZTypeManager.RegNewGenericType(newType);
                RetType = newZtype;
            }
        }
Esempio n. 18
0
        private Exp AnalyGeneric_1()
        {
            LexToken genericArgTypeToken = TypeTokens[0];
            ZType    genericArgZType     = SearchZType(genericArgTypeToken);

            if (genericArgZType != null)
            {
                //Type newType = MakeGenericType(mainZType, genericArgZType);
                //ZType newZtype = ZTypeManager.RegNewGenericType(newType);
                ZLClassInfo newZClass = ZTypeManager.MakeGenericType((ZLClassInfo)mainZType, genericArgZType);
                ExpTypeTwo  twoExp    = new ExpTypeTwo(this.ExpContext, TypeTokens[0], TypeTokens[1], genericArgZType, mainZType, newZClass);
                return(twoExp.Analy());
            }
            return(noneType);
        }
Esempio n. 19
0
        public override Exp Analy( )
        {
            if (this.IsAnalyed)
            {
                return(this);
            }
            var subjType = ListSymbol.GetZType();

            ZLClassInfo zclass = subjType as ZLClassInfo;

            Property  = zclass.SharpType.GetProperty(ZLangUtil.ZListItemPropertyName);
            RetType   = ZTypeManager.GetBySharpType(Property.PropertyType) as ZType;
            IsAnalyed = true;
            return(this);
        }
Esempio n. 20
0
        private void AddDimWord(ZDimType zdim, WordDictionary wordDictionary)
        {
            Dictionary <string, string> dims = zdim.Dims;

            foreach (string dimName in dims.Keys)
            {
                string       dimTypeName = dims[dimName];
                IZDescType[] ztypes      = ZTypeManager.GetByMarkName(dimTypeName);
                if (ztypes.Length > 0)
                {
                    ZType    ztype = ztypes[0] as ZType;
                    WordInfo word  = new WordInfo(dimName, WordKind.DimName, ztype);
                    wordDictionary.Add(word);
                }
            }
        }
Esempio n. 21
0
 private void AnalyBase(ContextClass context)
 {
     SuperTable = null;
     if (BaseTypeToken == null)
     {
         IsStatic   = false;
         BaseZType  = ZTypeManager.ZOBJECT;
         SuperTable = new SuperSymbolTable("SUPER-唯一", ZTypeManager.ZOBJECT);
     }
     else
     {
         BaseTypeName = BaseTypeToken.GetText();
         if (BaseTypeName == "唯一")
         {
             IsStatic   = true;
             SuperTable = new SuperSymbolTable("SUPER-唯一", null);
         }
         else
         {
             IsStatic = false;
             var ztypes = ZTypeManager.GetByMarkName(BaseTypeName);
             if (ztypes.Length == 0)
             {
                 errorf(BaseTypeToken.Position, "类型'{0}'不存在", BaseTypeName);
             }
             else if (ztypes.Length == 1)
             {
                 BaseZType  = ztypes[0] as ZClassType;
                 SuperTable = new SuperSymbolTable("SUPER-" + BaseZType.ZName, BaseZType);
             }
             else if (ztypes.Length == 0)
             {
                 errorf(BaseTypeToken.Position, "'{0}'存在{1}个同名类型", BaseTypeName, ztypes.Length);
                 SuperTable = new SuperSymbolTable("SUPER", null);
             }
         }
     }
     if (SuperTable == null)
     {
         SuperTable = new SuperSymbolTable("SUPER-STATIC", null);
     }
     SuperTable.ParentTable = FileContext.UseContext.SymbolTable;
     context.SetSuperTable(SuperTable);
     context.BaseZType = BaseZType;
 }
Esempio n. 22
0
        private Exp AnalyGeneric_2()
        {
            LexToken genericArgTypeToken1 = TypeTokens[0];
            LexToken genericArgTypeToken2 = TypeTokens[1];
            ZType    genericArgZType1     = SearchZType(genericArgTypeToken1);
            ZType    genericArgZType2     = SearchZType(genericArgTypeToken2);

            if (genericArgZType1 != null && genericArgZType2 != null)
            {
                //Type newType = MakeGenericType(mainZType, genericArgZType1, genericArgZType2);
                //ZType newZtype = ZTypeManager.RegNewGenericType(newType);
                //RetType = newZtype;
                ZLClassInfo  newZClass = ZTypeManager.MakeGenericType((ZLClassInfo)mainZType, genericArgZType1, genericArgZType2);
                ExpTypeThree twoExp    = new ExpTypeThree(this.ExpContext, TypeTokens[0], TypeTokens[1], TypeTokens[2], genericArgZType1, genericArgZType2, mainZType, newZClass);
                return(twoExp.Analy());
            }
            return(noneType);
        }
Esempio n. 23
0
        public override Exp Analy( )
        {
            if (LeftExp == null && RightExp != null)
            {
                ExpUnary unexp = new ExpUnary(OpToken, RightExp, this.ExpContext);
                //unexp.SetContext(this.ExpContext);
                var exp = unexp.Analy();
                return(exp);
            }
            else if (LeftExp == null && RightExp == null)
            {
                ErrorE(this.OpToken.Position, "运算符'{0}'两边缺少表达式", OpToken.GetText());
                //AnalyResult = false;
            }

            OpKind   = OpToken.Kind;
            LeftExp  = AnalySubExp(LeftExp);
            RightExp = AnalySubExp(RightExp);

            if (RightExp == null)
            {
                ErrorE(OpToken.Position, "运算符'{0}'右边缺少运算元素", OpToken.GetText());
                //AnalyResult = false;
            }
            else
            {
                if (LeftExp.AnalyCorrect && RightExp.AnalyCorrect)
                {
                    ZType ltype = LeftExp.RetType;
                    ZType rtype = RightExp.RetType;

                    OpMethod = ExpBinaryUtil.GetCalcMethod(OpKind, ltype.SharpType, rtype.SharpType);
                    if (OpMethod != null)
                    {
                        RetType = ZTypeManager.GetBySharpType(OpMethod.ReturnType) as ZType;
                    }
                    else
                    {
                        ErrorE(OpToken.Position, "两种类型无法进行'{0}'运算", OpToken.ToCode());
                    }
                }
            }
            return(this);
        }
Esempio n. 24
0
        private ParseResult ParseNameBySegmenter(Token token, IWordDictionary collection)
        {
            //WordCollection nameManager = this.procContext.ClassContext.FileContext.GetNameDimWordManger();
            WordSegmenter segmenter = new WordSegmenter(collection);

            Token[] newTokens = segmenter.Split(token);
            if (newTokens.Length == 2)
            {
                string argTypeName = newTokens[0].GetText();
                var    ArgType     = ZTypeManager.GetByMarkName(argTypeName)[0] as ZType;
                var    result      = new ParseResult()
                {
                    TypeName = argTypeName, ZType = ArgType, VarName = newTokens[1].GetText()
                };
                return(result);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 25
0
 public override Exp Analy()
 {
     if (this.IsAnalyed)
     {
         return(this);
     }
     SubjectExp = SubjectExp.Analy();
     if (SubjectExp.RetType == null)
     {
         //Type newType =typeof(列表<>).MakeGenericType(typeof(object));
         //ZType newZtype = ZTypeManager.RegNewGenericType(newType);
         ZLClassInfo newZClass = ZTypeManager.MakeGenericType(ZLangBasicTypes.ZLIST, ZLangBasicTypes.ZOBJECT);
         SubjectExp.RetType = newZClass;
     }
     CreateEachSymbols();
     AnalyCountMethod();
     ItemExp      = new ExpEachItem(this.ExpContext, this.ListSymbol, this.IndexSymbol);
     this.RetType = ZLangBasicTypes.ZVOID;
     IsAnalyed    = true;
     return(this);
 }
Esempio n. 26
0
        //private void AnalyListExp()
        //{
        //    ListExp = AnalyExpRaw();
        //    if (ListExp == null)
        //    {
        //        Errorf(ForeachToken.Position, "循环每一个语句没有表达式");
        //    }
        //    else
        //    {
        //        ListExp = ListExp.Analy();
        //    }
        //}

        //private Exp AnalyExpRaw()
        //{
        //    ExpRaw rawExp = Raw.ListExp;// (Exp)ListExp;
        //    ContextExp context = new ContextExp(this.ProcContext, this);
        //    //rawExp.SetContext(context);
        //    List<LexToken> tokens = rawExp.Seg();
        //    ExpParser parser = new ExpParser();
        //    Exp exp = parser.Parse(tokens, this.ProcContext.ClassContext.FileContext);
        //    //exp.SetContext(rawExp.ExpContext);
        //    return exp;
        //}

        protected void CreateEachSymbols()
        {
            var procContext = this.ProcContext;

            int foreachIndex = procContext.CreateRepeatIndex();
            var indexName    = "@foreach" + foreachIndex + "_index";
            var countName    = "@foreach" + foreachIndex + "_count";
            var listName     = "@foreach" + foreachIndex + "_list";
            var itemName     = this.Raw.ItemToken.Text;

            indexSymbol = new ZCLocalVar(indexName, ZLangBasicTypes.ZINT, true);
            //indexSymbol.LoacalVarIndex = procContext.CreateLocalVarIndex(indexName);
            this.ProcContext.AddLocalVar(indexSymbol);

            countSymbol = new ZCLocalVar(countName, ZLangBasicTypes.ZINT, true);
            //countSymbol.LoacalVarIndex = procContext.CreateLocalVarIndex(countName);
            this.ProcContext.AddLocalVar(countSymbol);

            listSymbol = new ZCLocalVar(listName, this.ForeachListExp.RetType, true);
            //listSymbol.LoacalVarIndex = procContext.CreateLocalVarIndex(listName);
            this.ProcContext.AddLocalVar(listSymbol);

            var listType = ZTypeUtil.GetTypeOrBuilder(this.ForeachListExp.RetType);

            Type[] genericTypes = GenericUtil.GetInstanceGenriceType(listType, typeof(列表 <>));
            if (genericTypes.Length == 0)
            {
                genericTypes = GenericUtil.GetInstanceGenriceType(listType, typeof(IList <>));
            }

            Type ElementType = genericTypes[0];

            itemSymbol = new ZCLocalVar(itemName, (ZType)(ZTypeManager.GetBySharpType(ElementType)), true);
            //itemSymbol.LoacalVarIndex = procContext.CreateLocalVarIndex(itemName);
            this.ProcContext.AddLocalVar(itemSymbol);
        }
Esempio n. 27
0
        protected void EmitArgsExp(IEnumerable <Exp> args, IEnumerable <ParameterInfo> paras)
        {
            var ztypes = paras.Select(p => (ZTypeManager.GetBySharpType(p.ParameterType) as ZType)).ToArray();

            EmitArgsExp(args, ztypes);
        }