Beispiel #1
0
        public void EmitLoadLocala()
        {
            //EmitHelper.LoadVara(IL, LocalVarSymbol.VarBuilder);
            if (this.ClassContext is ContextNestedClass)
            {
                FieldBuilder fieldBuilder = this.ProcContext.ClassContext.GetZCompilingType()
                                            .SearchDeclaredZField(VarName).FieldBuilder;

                EmitHelper.EmitThis(IL, false);
                EmitHelper.LoadFielda(IL, fieldBuilder);
            }
            else if (LocalVarSymbol.IsReplaceToNestedFiled)
            {
                FieldBuilder fieldBuilder = this.ProcContext.GetNestedClassContext().GetZCompilingType()
                                            .SearchDeclaredZField(VarName).FieldBuilder;
                ZCLocalVar instanceVar = this.ProcContext.NestedInstance;

                EmitSymbolHelper.EmitLoad(IL, LocalVarSymbol);
                EmitHelper.LoadFielda(IL, fieldBuilder);
            }
            else
            {
                //EmitGetLocal();
                EmitHelper.LoadVara(IL, LocalVarSymbol.VarBuilder);
            }
        }
Beispiel #2
0
 public static bool EmitLoada(ILGenerator il, IIdent iident)
 {
     if (iident is ZAParamInfo)
     {
         ZAParamInfo zlp = (ZAParamInfo)iident;
         EmitHelper.LoadArga(il, zlp.GetEmitIndex());
         return(true);
     }
     else if (iident is ZCLocalVar)
     {
         ZCLocalVar zlp = (ZCLocalVar)iident;
         EmitHelper.LoadVara(il, zlp.VarBuilder);
         return(true);
     }
     else if (iident is ZCFieldInfo)
     {
         ZCFieldInfo zlp = (ZCFieldInfo)iident;
         EmitHelper.LoadFielda(il, zlp.FieldBuilder);
         return(true);
     }
     else if (iident is ZLFieldInfo)
     {
         ZLFieldInfo zlp = (ZLFieldInfo)iident;
         EmitHelper.LoadFielda(il, zlp.SharpField);
         return(true);
     }
     else
     {
         return(false);
     }
     //EmitHelper.LoadArg(il, zcparam.EmitIndex);
 }
Beispiel #3
0
        //private void EmitGetNested()
        //{
        //    if (this.NestedFieldSymbol != null)
        //    {
        //        EmitHelper.EmitThis(IL, false);
        //        EmitSymbolHelper.EmitLoad(IL, this.NestedFieldSymbol);
        //        base.EmitConv();
        //    }
        //    else
        //    {
        //        throw new CCException();
        //    }
        //}

        public override void EmitSet(Exp valueExp)
        {
            if (this.ClassContext is ContextNestedClass)
            {
                FieldBuilder fieldBuilder = this.ProcContext.ClassContext.GetZCompilingType()
                                            .SearchDeclaredZField(VarName).FieldBuilder;

                EmitHelper.EmitThis(IL, false);
                EmitValueExp(valueExp);
                EmitHelper.StormField(IL, fieldBuilder);
            }
            else if (LocalVarSymbol.IsReplaceToNestedFiled)
            {
                ZCClassInfo  classType    = this.ProcContext.GetNestedClassContext().GetZCompilingType();
                FieldBuilder fieldBuilder = classType.SearchDeclaredZField(VarName).FieldBuilder;
                ZCLocalVar   instanceVar  = this.ProcContext.NestedInstance;

                EmitSymbolHelper.EmitLoad(IL, instanceVar);
                EmitValueExp(valueExp);
                EmitHelper.StormField(IL, fieldBuilder);
                base.EmitConv();
            }
            else
            {
                EmitValueExp(valueExp);
                EmitSymbolHelper.EmitStorm(IL, LocalVarSymbol);
            }
        }
Beispiel #4
0
        protected void CreateEachSymbols()
        {
            var procContext    = this.ExpContext.ProcContext;
            int foreachIndex   = this.ExpContext.ProcContext.CreateEachIndex();
            var listSymbolName = "@each" + foreachIndex + "_list";
            var indexName      = "@each" + foreachIndex + "_index";
            var elementName    = "@each" + foreachIndex + "_item";
            var countName      = "@each" + foreachIndex + "_count";

            ListSymbol = new ZCLocalVar(listSymbolName, SubjectExp.RetType, true);
            //ListSymbol.LoacalVarIndex = procContext.CreateLocalVarIndex(ListSymbol.ZName);
            this.ProcContext.AddLocalVar(ListSymbol);

            Type[] genericTypes = GenericUtil.GetInstanceGenriceType(ZTypeUtil.GetTypeOrBuilder(SubjectExp.RetType), typeof(列表 <>));
            //Type[] genericTypes = GenericUtil.GetInstanceGenriceType(SubjectExp.RetType.SharpType, typeof(列表<>));
            Type ElementType = genericTypes[0];

            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);
        }
Beispiel #5
0
 public ExpEachItem(ContextExp expContext, ZCLocalVar listSymbol, ZCLocalVar indexSymbol)
     : base(expContext)
 {
     //ExpContext = expContext;
     ListSymbol  = listSymbol;
     IndexSymbol = indexSymbol;
 }
Beispiel #6
0
 public static void EmitLocalVar(ContextProc procContext, bool isStatic, ILGenerator IL, List <ZCLocalVar> localList)
 {
     localList.Reverse();
     for (int i = 0; i < localList.Count; i++)
     {
         ZCLocalVar varSymbol = localList[i];
         varSymbol.VarBuilder = IL.DeclareLocal(ZTypeUtil.GetTypeOrBuilder(varSymbol.GetZType()));
         varSymbol.VarBuilder.SetLocalSymInfo(varSymbol.ZName);
     }
     for (int i = 0; i < localList.Count; i++)
     {
         ZCLocalVar varSymbol = localList[i];
         if (varSymbol.IsNestedClassInstance)
         {
             LocalBuilder       lanmbdaLocalBuilder = procContext.NestedInstance.VarBuilder;
             ConstructorBuilder newBuilder          = procContext.GetNestedClassContext().DefaultConstructorBuilder;
             IL.Emit(OpCodes.Newobj, newBuilder);
             EmitHelper.StormVar(IL, lanmbdaLocalBuilder);
             if (!isStatic)
             {
                 ZCFieldInfo masterClassField = procContext.GetNestedClassContext().MasterClassField;
                 if (masterClassField != null)
                 {
                     ILGeneratorUtil.LoadLocal(IL, lanmbdaLocalBuilder);
                 }
                 IL.Emit(OpCodes.Ldarg_0);
                 EmitSymbolHelper.EmitStorm(IL, masterClassField);
             }
         }
     }
 }
Beispiel #7
0
        private void AnalyPropertyTempLocal()
        {
            int tempIndex = this.ExpContext.ProcContext.CreateTempIndex();
            var tempName  = "@property_temp" + tempIndex;

            tempLocal = new ZCLocalVar(tempName, SubjectExp.RetType, true);
            this.ProcContext.AddLocalVar(tempLocal);
        }
Beispiel #8
0
        private void AnalyResultLocal()
        {
            var VarName = "@binary_temp_storm_" + TempStormIndex;

            TempStormLocalVarSymbol = new ZCLocalVar(VarName, this.RetType);
            this.ProcContext.AddLocalVar(TempStormLocalVarSymbol);
            TempStormIndex++;
        }
Beispiel #9
0
        public int Add(ZCLocalVar localVar)
        {
            LocalVarList.Add(localVar);
            int index = LocalVarList.Count;

            localVar.LoacalVarIndex = index;
            return(index);
        }
Beispiel #10
0
        public ContextNestedClass CreateNestedClassContext()
        {
            if (_NestedClassContext == null)
            {
                _NestedClassContext = new ContextNestedClass(this);
                _NestedClassContext.SetClassName(this.CreateNestedClassName());
                var nestedClassInstanceName = _NestedClassContext.ClassName + "_0";

                var            packageName        = this.ClassContext.FileContext.ProjectContext.ProjectModel.ProjectPackageName;
                string         fullName           = packageName + "." + _NestedClassContext.ClassName;
                TypeAttributes typeAttrs          = TypeAttributes.NestedPrivate | TypeAttributes.Sealed;
                TypeBuilder    NestedClassBuilder = this.ClassContext.SelfCompilingType.ClassBuilder.DefineNestedType(fullName, typeAttrs);
                _NestedClassContext.SetTypeBuilder(NestedClassBuilder);

                ZCClassInfo ztype = _NestedClassContext.SelfCompilingType;
                if (NestedInstance == null)
                {
                    NestedInstance = new ZCLocalVar(nestedClassInstanceName, ztype, true)
                    {
                        IsNestedClassInstance = true
                    };
                    this.LocalManager.Add(NestedInstance);
                }

                if (!this.IsStatic())
                {
                    ZCFieldInfo zf2 = _NestedClassContext.SelfCompilingType.DefineFieldPublic
                                          (ContextNestedClass.MasterClassFieldName, this.ClassContext.SelfCompilingType);
                    _NestedClassContext.MasterClassField = zf2;
                }

                if (this.ArgList.Count > 0)
                {
                    foreach (var arg in this.ArgList)
                    {
                        ZCParamInfo zp  = this.GetParameter(arg);
                        ZCFieldInfo zf3 = _NestedClassContext.SelfCompilingType.DefineFieldPublic
                                              (arg, zp.GetZClass());
                        _NestedClassContext.MasterArgDict.Add(arg, zf3);
                    }
                }
                /* 生成内部类默认构造函数 */
                {
                    ConstructorBuilder NewBuilder = NestedClassBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, new Type[] { });
                    var il = NewBuilder.GetILGenerator();
                    il.Emit(OpCodes.Ret);
                    ZCConstructorInfo zcc = new ZCConstructorInfo(this._NestedClassContext.SelfCompilingType)
                    {
                        ConstructorBuilder = NewBuilder
                    };
                    this._NestedClassContext.SelfCompilingType.AddConstructord(zcc);
                    this._NestedClassContext.DefaultConstructorBuilder = NewBuilder;
                }
            }
            return(_NestedClassContext);
        }
Beispiel #11
0
        public int AddLocalVar(ZCLocalVar localSymbol)
        {
            int index = LocalManager.Add(localSymbol);

            if (!localSymbol.IsAutoGenerated)
            {
                this.ProcSegmenter.AddWord(localSymbol.ZName);
                //localDefDict.Add(localSymbol.ZName, localSymbol);
            }
            return(index);
        }
Beispiel #12
0
        public bool ReplaceLocalToField(string varName)
        {
            if (this.ContainsPropertyName(varName))
            {
                return(false);
            }
            ZCLocalVar  localVar           = this.MasterProcContext.LocalManager.GetDefLocal(varName);
            ZType       ztype              = localVar.GetZType();
            Type        varSharpType       = ZTypeUtil.GetTypeOrBuilder(ztype);
            var         NestedClassBuilder = this.SelfCompilingType.ClassBuilder;
            ZCFieldInfo zf = this.SelfCompilingType.DefineFieldPublic(varName, (ZAClassInfo)ztype);

            localVar.IsReplaceToNestedFiled = true;
            this.MasterProcContext.LocalManager.DecLocalIndex(varName);
            return(true);
        }
Beispiel #13
0
        public Exp AnalyDim(ZType retType)
        {
            RetType = retType;

            ZCLocalVar localVarSymbol = new ZCLocalVar(VarName, RetType);

            this.LocalVarSymbol = localVarSymbol;
            this.ProcContext.AddLocalVar(localVarSymbol);
            IsAnalyed = true;
            return(this);
            //Exp varExp2 = varExp.Analy();
            //return varExp2;

            //if (!this.ProcContext.ContainsVarName(VarName))
            //{
            //    varExp.SetAssigned(ValueExp.RetType);
            //    //varExp.SetContextExp(this.ExpContext);
            //    ToExp = AnalyDim(varExp);
            //    AnalyCorrect = AnalyCorrect && ValueExp.AnalyCorrect;
            //}
        }
Beispiel #14
0
        protected void CreateEachSymbols()
        {
            var procContext = this.ProcContext;

            int foreachIndex = procContext.CreateRepeatIndex();
            var indexName    = "@loop" + foreachIndex + "_index";
            var countName    = "@loop" + foreachIndex + "_count";
            var condiName    = "@loop" + foreachIndex + "_bool";

            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);

            CondiSymbol = new ZCLocalVar(condiName, ZLangBasicTypes.ZBOOL, true);
            //CondiSymbol.LoacalVarIndex = procContext.CreateLocalVarIndex(condiName);
            this.ProcContext.AddLocalVar(CondiSymbol);
        }
Beispiel #15
0
        public override Stmt Analy()
        {
            TypeArgParser parser = new TypeArgParser(this.ProcContext.ClassContext);

            TypeArgParser.ParseResult result = parser.Parse(Raw.ExceptionTypeVarToken);
            if (result.ResultCount == 1)
            {
                exTypeName = result.ArgZTypes[0].ZTypeName;
                exType     = (ZLType)result.ArgZTypes[0];
                exName     = result.ArgName;
            }
            if (this.ProcContext.ContainsVarName(exName) == false)
            {
                exSymbol = new ZCLocalVar(exName, exType, true);
                //exSymbol.LoacalVarIndex =this.ProcContext.CreateLocalVarIndex(exName);
                this.ProcContext.AddLocalVar(exSymbol);
            }
            else
            {
                if (this.ProcContext.LocalManager.IsDefLocal(exName))
                {
                    exSymbol = this.ProcContext.LocalManager.GetDefLocal(exName);
                    if (exSymbol.GetZType() != exType)
                    {
                        Errorf(Raw.ExceptionTypeVarToken.Position, "变量'{0}'的类型与异常的类型不一致", exName);
                    }
                }
                else
                {
                    Errorf(Raw.ExceptionTypeVarToken.Position, "变量名称'{0}'已经使用过", exName);
                }
            }
            //CatchBody.ProcContext = this.ProcContext;
            StmtBody.Analy();
            return(this);
        }
Beispiel #16
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);
        }
Beispiel #17
0
 public static void EmitStorm(ILGenerator il, ZCLocalVar symbolVar)
 {
     EmitHelper.StormVar(il, symbolVar.VarBuilder);
 }
Beispiel #18
0
 public static void EmitLoad(ILGenerator il, ZCLocalVar symbolVar)
 {
     EmitHelper.LoadVar(il, symbolVar.VarBuilder);
 }