示例#1
0
        public override void Generate(EmitStmtContext context)
        {
            IL = context.ILout;
            MarkSequencePoint(context);

            EmitExpContext expContext = new EmitExpContext(context);

            var True_Label  = IL.DefineLabel();
            var False_Label = IL.DefineLabel();

            generateList(expContext);
            generateCount(context);
            genInitIndex(context);

            generateCondition(context);
            IL.Emit(OpCodes.Brfalse, False_Label);

            //定义一个标签,表示从下面开始进入循环体
            IL.MarkLabel(True_Label);
            generateSet(expContext, ValueExp);
            EmitHelper.Inc(IL, indexSymbol.VarBuilder);
            generateCondition(context);
            IL.Emit(OpCodes.Brtrue, True_Label);
            IL.MarkLabel(False_Label);
        }
示例#2
0
        public override void Generate(EmitExpContext context)
        {
            var             il          = NestedMethodContext.EmitContext.CurrentMethodBuilder.GetILGenerator();
            EmitStmtContext stmtContext = new EmitStmtContext(NestedMethodContext.EmitContext);
            EmitExpContext  expContext  = new EmitExpContext(stmtContext);

            if (retSymbol != null)
            {
                retSymbol.VarBuilder = il.DeclareLocal(retSymbol.DimType);
            }
            //GenerateBodyExpHead(context);

            BodyExp.Generate(expContext);
            if (retSymbol == null)
            {
                if (BodyExp.RetType != typeof(void))
                {
                    il.Emit(OpCodes.Pop);
                }
            }
            else
            {
                EmitHelper.StormVar(il, retSymbol.VarBuilder);
            }

            if (RetType != typeof(void))
            {
                il.Emit(OpCodes.Ldloc, retSymbol.VarBuilder);
            }
            il.Emit(OpCodes.Ret);
            generateConstructor(context);
            NestedType = NestedClassContext.EmitContext.CurrentTypeBuilder.CreateType();
            base.GenerateConv(context);
        }
示例#3
0
        void genInitIndex(EmitStmtContext context)
        {
            ILGenerator il = context.ILout;

            EmitHelper.LoadInt(il, startIndex);
            EmitHelper.StormVar(il, indexSymbol.VarBuilder);
        }
示例#4
0
        public override void Generate(EmitStmtContext context)
        {
            ILGenerator il = context.ILout;

            Label        EndLabel  = il.DefineLabel();
            Label        ElseLabel = il.DefineLabel();
            List <Label> labels    = new List <Label>();

            for (int i = 0; i < Parts.Count; i++)
            {
                labels.Add(il.DefineLabel());
            }
            labels.Add(ElseLabel);

            for (int i = 0; i < Parts.Count; i++)
            {
                var item = Parts[i];
                item.EndLabel     = EndLabel;
                item.CurrentLabel = labels[i];
                item.NextLabel    = labels[i + 1];
                item.Generate(context);
            }
            il.MarkLabel(ElseLabel);
            if (ElsePart != null)
            {
                ElsePart.Generate(context);
            }
            il.MarkLabel(EndLabel);
        }
示例#5
0
 public override void Generate(EmitStmtContext context)
 {
     foreach (var stmt in Body)
     {
         stmt.Generate(context);
     }
 }
示例#6
0
        public void Generate(TypeBuilder classBuilder, bool isStatic)
        {
            var             symbols     = MethodContext.Symbols;
            EmitStmtContext stmtContext = new EmitStmtContext(MethodContext.EmitContext);
            var             il          = MethodContext.EmitContext.ILout;

            for (int i = 0; i < MethodContext.LoacalVarList.Count; i++)
            {
                string    ident     = MethodContext.LoacalVarList[i];
                SymbolVar varSymbol = symbols.Get(ident) as SymbolVar;
                varSymbol.VarBuilder = il.DeclareLocal(varSymbol.DimType);
                varSymbol.VarBuilder.SetLocalSymInfo(varSymbol.SymbolName);
            }
            if (MethodContext.RetType != typeof(void))
            {
                if (MethodContext.RetType.IsValueType)
                {
                    EmitHelper.LoadInt(il, 0);
                }
                else
                {
                    il.Emit(OpCodes.Ldnull);
                }
                EmitHelper.StormVar(il, (symbols.Get(MethodContext.LoacalVarList[0]) as SymbolVar).VarBuilder);
            }

            if (FnName.IsConstructor(this.ClassName) != -1)
            {
                if (!isStatic)
                {
                    callBaseDefault();
                    if (ClassContext.InitMemberValueMethod != null)
                    {
                        il.Emit(OpCodes.Ldarg_0);
                        EmitHelper.CallDynamic(il, ClassContext.InitMemberValueMethod, true);//EmitHelper.CallDynamic(il, ClassContext.InitMemberValueMethod);
                    }
                }
                else
                {
                    if (ClassContext.InitMemberValueMethod != null)
                    {
                        EmitHelper.CallDynamic(il, ClassContext.InitMemberValueMethod, true);//EmitHelper.CallDynamic(il, ClassContext.InitMemberValueMethod);
                    }
                }
            }
            //var MethodName = getMethodName(isStatic);
            //if(MethodName=="启动")
            //{
            //    //EmitHelper.CallDynamic(il, typeof(DebugHelper).GetMethod("PrintBaseDirectory"));
            //}
            FnBody.Generate(stmtContext);

            if (MethodContext.RetType != typeof(void))
            {
                il.Emit(OpCodes.Ldloc, retResult.VarBuilder);
                EmitHelper.EmitConv(il, MethodContext.RetType, retResult.DimType);
            }
            il.Emit(OpCodes.Ret);
        }
示例#7
0
        void generateList(EmitStmtContext context)
        {
            ILGenerator    il         = context.ILout;
            EmitExpContext expContext = new EmitExpContext(context);

            ListExp.Generate(expContext);
            EmitHelper.StormVar(il, listSymbol.VarBuilder);
        }
示例#8
0
        void generateNormal(EmitStmtContext context)
        {
            ILGenerator il = context.ILout;

            EmitExpContext expContext = new EmitExpContext(context);

            (LeftToExp as IGenerateSet).GenerateSet(expContext, RightValueExp);
        }
示例#9
0
 void generateCondition(EmitStmtContext context)
 {
     EmitHelper.LoadVar(IL, indexSymbol.VarBuilder);
     EmitHelper.LoadVar(IL, countSymbol.VarBuilder);
     EmitHelper.CallDynamic(IL, compareMethod, true);
     EmitHelper.LoadInt(IL, 1);
     IL.Emit(OpCodes.Ceq);
 }
示例#10
0
        void generateCount(EmitStmtContext context)
        {
            ILGenerator il = context.ILout;

            EmitHelper.LoadVar(il, listSymbol.VarBuilder);
            EmitHelper.CallDynamic(il, getCountMethod);
            EmitHelper.StormVar(il, countSymbol.VarBuilder);
        }
示例#11
0
        void generateEveryOne(EmitStmtContext context)
        {
            ILGenerator il = context.ILout;

            EveryOneExp    everyoneExp = LeftToExp as EveryOneExp;
            EmitExpContext expContext  = new EmitExpContext(context);

            (LeftToExp as IGenerateSet).GenerateSet(expContext, RightValueExp);
        }
示例#12
0
        void generateElement(EmitStmtContext context)
        {
            ILGenerator il = context.ILout;

            EmitHelper.LoadVar(il, listSymbol.VarBuilder);
            EmitHelper.LoadVar(il, indexSymbol.VarBuilder);
            EmitHelper.CallDynamic(il, diMethod);
            EmitHelper.StormVar(il, elementSymbol.VarBuilder);
        }
示例#13
0
        protected void MarkSequencePoint(EmitStmtContext context)
        {
            ILGenerator il = context.ILout;

            if (context.MethodEmitContext.ClassContext.IDoc != null)
            {
                il.MarkSequencePoint(context.MethodEmitContext.ClassContext.IDoc, this.Postion.Line, this.Postion.Col, this.Postion.Line, this.Postion.Col + this.ToCode().Length);
            }
        }
示例#14
0
        void generateCondition(EmitStmtContext context)
        {
            ILGenerator il = context.ILout;

            EmitHelper.LoadVar(il, indexSymbol.VarBuilder);
            EmitHelper.LoadVar(il, countSymbol.VarBuilder);
            EmitHelper.CallDynamic(il, compareMethod, true);
            EmitHelper.LoadInt(il, 1);
            il.Emit(OpCodes.Ceq);
        }
示例#15
0
        public override void Generate(EmitStmtContext context)
        {
            ILGenerator il = context.ILout;

            MarkSequencePoint(context);
            il.BeginCatchBlock(exType);
            EmitHelper.StormVar(il, exSymbol.VarBuilder);
            CatchBody.Generate(context);
            il.EndExceptionBlock();
        }
示例#16
0
 public override void Generate(EmitStmtContext context)
 {
     MarkSequencePoint(context);
     if (isEveryOneAssign)
     {
         everyOneAssignStmt.Generate(context);
     }
     else
     {
         generateNormal(context);
     }
 }
示例#17
0
        public override void Generate(EmitStmtContext context)
        {
            ILGenerator il = context.ILout;

            MarkSequencePoint(context);
            EmitExpContext expContext = new EmitExpContext(context);

            resultExp.Generate(expContext);
            if (resultExp.RetType != typeof(void))
            {
                il.Emit(OpCodes.Pop);
            }
        }
示例#18
0
            public override void Generate(EmitStmtContext context)
            {
                ILGenerator    il         = context.ILout;
                EmitExpContext expContext = new EmitExpContext(context);

                il.MarkLabel(CurrentLabel);
                Condition.Generate(expContext);
                EmitHelper.LoadInt(il, 1);
                il.Emit(OpCodes.Ceq);
                il.Emit(OpCodes.Brfalse, NextLabel);
                Body.Generate(context);
                il.Emit(OpCodes.Br, EndLabel);
            }
示例#19
0
        public override void Generate(EmitStmtContext context)
        {
            ILGenerator    il          = context.ILout;
            EmitExpContext expContext  = new EmitExpContext(context);
            var            True_Label  = il.DefineLabel();
            var            False_Label = il.DefineLabel();

            il.MarkLabel(True_Label);
            Condition.Generate(expContext);
            EmitHelper.LoadInt(il, 1);
            il.Emit(OpCodes.Ceq);
            il.Emit(OpCodes.Brfalse, False_Label);
            Body.Generate(context);
            il.Emit(OpCodes.Br, True_Label);
            il.MarkLabel(False_Label);
        }
示例#20
0
        public override void Generate(EmitStmtContext context)
        {
            ILGenerator il          = context.ILout;
            var         True_Label  = il.DefineLabel();
            var         False_Label = il.DefineLabel();

            generateList(context);
            generateCount(context);
            genInitIndex(context);

            generateCondition(context);
            il.Emit(OpCodes.Brfalse, False_Label);

            //定义一个标签,表示从下面开始进入循环体
            il.MarkLabel(True_Label);
            generateElement(context);
            Body.Generate(context);
            EmitHelper.Inc(il, indexSymbol.VarBuilder);
            generateCondition(context);
            il.Emit(OpCodes.Brtrue, True_Label);
            il.MarkLabel(False_Label);
        }
示例#21
0
        public bool CompileBody(bool isStatic)
        {
            if (Count == 0)
            {
                return(true);
            }
            TypeBuilder classBuilder = ClassContext.ClassSymbol.ClassBuilder;

            if (ClassContext.InitMemberValueMethod == null)
            {
                string initMemberValueMethodName = "__InitMemberValueMethod";
                if (isStatic)
                {
                    ClassContext.InitMemberValueMethod = classBuilder.DefineMethod(initMemberValueMethodName, MethodAttributes.Private | MethodAttributes.Static, typeof(void), new Type[] { });
                }
                else
                {
                    ClassContext.InitMemberValueMethod = classBuilder.DefineMethod(initMemberValueMethodName, MethodAttributes.Private, typeof(void), new Type[] { });
                }
            }
            EmitMethodContext context = new EmitMethodContext();

            context.ClassContext = ClassContext.EmitContext;;
            context.SetBuilder(ClassContext.InitMemberValueMethod);
            EmitStmtContext stmtContext = new EmitStmtContext(context);
            EmitExpContext  expContext  = new EmitExpContext(stmtContext);

            var il = ClassContext.InitMemberValueMethod.GetILGenerator();

            foreach (var ppt in PropertyList)
            {
                ppt.GenerateBody(expContext);
            }
            il.Emit(OpCodes.Ret);
            return(true);
        }
示例#22
0
 void generateCount(EmitStmtContext context)
 {
     EmitHelper.LoadVar(IL, listSymbol.VarBuilder);
     EmitHelper.CallDynamic(IL, getCountMethod, ExProperty.IsSelf);
     EmitHelper.StormVar(IL, countSymbol.VarBuilder);
 }
示例#23
0
 void genInitIndex(EmitStmtContext context)
 {
     EmitHelper.LoadInt(IL, startIndex);
     EmitHelper.StormVar(IL, indexSymbol.VarBuilder);
 }
示例#24
0
 public abstract void Generate(EmitStmtContext context);
示例#25
0
 public override void Generate(EmitStmtContext context)
 {
     ILGenerator il       = context.ILout;
     Label       tryLabel = il.BeginExceptionBlock();
 }