• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# CodeGenContext类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中CodeGenContext的典型用法代码示例。如果您正苦于以下问题:C# CodeGenContext类的具体用法?C# CodeGenContext怎么用?C# CodeGenContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



CodeGenContext类属于命名空间,在下文中一共展示了CodeGenContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: GenerateWriterMethod

		public void GenerateWriterMethod(Type type, CodeGenContext ctx, ILGenerator il)
		{
			// arg0: Serializer, arg1: Stream, arg2: value

			var fields = Helpers.GetFieldInfos(type);

			foreach (var field in fields)
			{
				// Note: the user defined value type is not passed as reference. could cause perf problems with big structs

				var fieldType = field.FieldType;

				var data = ctx.GetTypeDataForCall(fieldType);

				if (data.NeedsInstanceParameter)
					il.Emit(OpCodes.Ldarg_0);

				il.Emit(OpCodes.Ldarg_1);
				if (type.IsValueType)
					il.Emit(OpCodes.Ldarga_S, 2);
				else
					il.Emit(OpCodes.Ldarg_2);
				il.Emit(OpCodes.Ldfld, field);

				il.Emit(OpCodes.Call, data.WriterMethodInfo);
			}

			il.Emit(OpCodes.Ret);
		}
开发者ID:yashodhank,项目名称:QuasarRAT,代码行数:29,代码来源:GenericSerializer.cs


示例2: ReturnArray

 protected void ReturnArray(CodeGenContext context)
 {
     // Ruby.Eval.Return(array, caller);
     array.GenCode(context);
     context.ldloc(0);
     context.call(Runtime.Eval.Return);
 }
开发者ID:chunlea,项目名称:rubydotnetcompiler,代码行数:7,代码来源:ControlFlow.cs


示例3: GenCall

        internal void GenCall(CodeGenContext context)
        {
            int result = context.CreateLocal("result", PrimitiveType.Object);

            PERWAPI.CILLabel endLabel = context.NewLabel();
            PERWAPI.CILLabel retryLabel = context.NewLabel();

            context.CodeLabel(retryLabel);

            context.StartBlock(Clause.Try);
            {
                // object result = Call(...)
                GenCall0(context);
                context.stloc(result);

                context.Goto(endLabel);
            }
            PERWAPI.TryBlock tryBlock = context.EndTryBlock();
            context.StartBlock(Clause.Catch);
            {
                CatchBreakException(context, result, endLabel);
            }
            context.EndCatchBlock(Runtime.BreakExceptionRef, tryBlock);
            context.StartBlock(Clause.Catch);
            {
                CatchRetryException(context, retryLabel);
            }
            context.EndCatchBlock(Runtime.RetryExceptionRef, tryBlock);

            context.CodeLabel(endLabel);
            context.ldloc(result);

            context.ReleaseLocal(result, true);
        }
开发者ID:chunlea,项目名称:rubydotnetcompiler,代码行数:34,代码来源:Calls.cs


示例4: GenCode0

        internal override void GenCode0(CodeGenContext context)
        {
            // String.Concat(String.Concat(arg1, arg2), args, ...);

            head.GenCode0(context);

            if (head.nd_next != null)
            {
                int first = context.StoreInTemp("head", Runtime.StringRef, head.location);

                for (Node n = head.nd_next; n != null; n = n.nd_next)
                {
                    n.GenCode0(context);
                    int second = context.StoreInTemp("tail", Runtime.StringRef, n.location);

                    context.ldloc(first);
                    context.ldloc(second);
                    context.callvirt(Runtime.String.Concat);
                    context.stloc(first);

                    context.ReleaseLocal(second, true);
                }

                context.ldloc(first);

                context.ReleaseLocal(first, true);
            }
        }
开发者ID:chunlea,项目名称:rubydotnetcompiler,代码行数:28,代码来源:Strings.cs


示例5: Defined

 internal override void Defined(CodeGenContext context)
 {
     if (args != null)
         new AND(new ProxyNode(MethodDefined, location), new ProxyNode(((Node)args).Defined, location), location).GenCode(context);
     else
         MethodDefined(context);
 }
开发者ID:chunlea,项目名称:rubydotnetcompiler,代码行数:7,代码来源:Calls.cs


示例6: GenCode0

        internal override void GenCode0(CodeGenContext context)
        {
            // hash = new Hash();
            context.newobj(Runtime.Hash.ctor);
            int hash = context.StoreInTemp("hash", Runtime.HashRef, location);

            Node entry = elements;
            while (entry != null)
            {
                bool key_created, value_created;

                ISimple key = context.PreCompute0(entry, "key", out key_created);
                entry = entry.nd_next;
                ISimple value = context.PreCompute0(entry, "value", out value_created);
                entry = entry.nd_next;

                // hash.Add(key, value);
                context.ldloc(hash);
                key.GenSimple(context);
                value.GenSimple(context);
                context.callvirt(Runtime.Hash.Add);

                context.ReleaseLocal(key, key_created);
                context.ReleaseLocal(value, value_created);
            }

            context.ldloc(hash);

            context.ReleaseLocal(hash, true);
        }
开发者ID:chunlea,项目名称:rubydotnetcompiler,代码行数:30,代码来源:Values.cs


示例7: Assign

        internal override void Assign(CodeGenContext context, Node rhs)
        {
            // Gen right hand sides
            ListGen mrhs;
            if (rhs is ListGen && !(rhs is MultipleRHS))
                mrhs = (ListGen)rhs;
            else
                mrhs = new ARGS(null, null, rhs, null, location, true);

            bool created;
            ISimple list = mrhs.GenArgList(context, out created);
            list.GenSimple(context);
            context.callvirt(Runtime.ArgList.CheckSingleRHS);
            int array = context.StoreInTemp("mrhs", Runtime.ArgListRef, location);

            context.ReleaseLocal(list, created);

            // Gen assignments to left hand sides
            for (LVALUE l = elements; l != null; l = (LVALUE)l.nd_next)
            {
                l.Assign(context, new MultipleRHS(array, l.location));
                context.pop();
            }

            context.ldloc(array);
            context.callvirt(Runtime.ArgList.ToRubyArray);

            context.ReleaseLocal(array, true);
        }
开发者ID:chunlea,项目名称:rubydotnetcompiler,代码行数:29,代码来源:Assignments.cs


示例8: GenerateClassForMethod

        protected new PERWAPI.MethodDef GenerateClassForMethod(CodeGenContext context)
        {
            // public class Eval: IEval {
            evalClass = context.CreateGlobalClass("_Internal", "Eval", Runtime.SystemObjectRef);
            evalClass.AddImplementedInterface(Runtime.IEvalRef);

            if (context.CurrentRubyClass == null)
            {
                context.CurrentRubyClass = CodeGenContext.AddField(evalClass, PERWAPI.FieldAttr.PublicStatic, "myRubyClass", Runtime.ClassRef);

                CodeGenContext cctor = context.CreateStaticConstructor(evalClass);

                cctor.ldsfld(Runtime.Init.rb_cObject);
                cctor.stsfld(context.CurrentRubyClass);
                cctor.ret();
                cctor.Close();
            }

            MethodDef constructor = GenConstructor(evalClass, context);

            GenInvokeMethod(evalClass, context);

            return constructor;
            // }
        }
开发者ID:chunlea,项目名称:rubydotnetcompiler,代码行数:25,代码来源:Eval.cs


示例9: GenCode0

 internal virtual void GenCode0(CodeGenContext context)
 {
     if (this is ISimple)
         ((ISimple)this).GenSimple(context);
     else
         throw new NotImplementedException(GetType().ToString());
 }
开发者ID:chunlea,项目名称:rubydotnetcompiler,代码行数:7,代码来源:Node.cs


示例10: GenerateWriterMethod

		public void GenerateWriterMethod(Type obtype, CodeGenContext ctx, ILGenerator il)
		{
			var getTypeIDMethodInfo = typeof(Serializer).GetMethod("GetTypeID", BindingFlags.NonPublic | BindingFlags.Instance, null,
				new Type[] { typeof(object) }, null);

			var map = ctx.TypeMap;

			// arg0: Serializer, arg1: Stream, arg2: object

			var idLocal = il.DeclareLocal(typeof(ushort));

			// get TypeID from object's Type
			il.Emit(OpCodes.Ldarg_0);
			il.Emit(OpCodes.Ldarg_2);
			il.Emit(OpCodes.Call, getTypeIDMethodInfo);
			il.Emit(OpCodes.Stloc_S, idLocal);

			// write typeID
			il.Emit(OpCodes.Ldarg_1);
			il.Emit(OpCodes.Ldloc_S, idLocal);
			il.Emit(OpCodes.Call, ctx.GetWriterMethodInfo(typeof(ushort)));

			// +1 for 0 (null)
			var jumpTable = new Label[map.Count + 1];
			jumpTable[0] = il.DefineLabel();
			foreach (var kvp in map)
				jumpTable[kvp.Value.TypeID] = il.DefineLabel();

			il.Emit(OpCodes.Ldloc_S, idLocal);
			il.Emit(OpCodes.Switch, jumpTable);

			il.Emit(OpCodes.Newobj, Helpers.ExceptionCtorInfo);
			il.Emit(OpCodes.Throw);

			/* null case */
			il.MarkLabel(jumpTable[0]);
			il.Emit(OpCodes.Ret);

			/* cases for types */
			foreach (var kvp in map)
			{
				var type = kvp.Key;
				var data = kvp.Value;

				il.MarkLabel(jumpTable[data.TypeID]);

				if (data.NeedsInstanceParameter)
					il.Emit(OpCodes.Ldarg_0);

				il.Emit(OpCodes.Ldarg_1);
				il.Emit(OpCodes.Ldarg_2);
				il.Emit(type.IsValueType ? OpCodes.Unbox_Any : OpCodes.Castclass, type);

				il.Emit(OpCodes.Tailcall);
				il.Emit(OpCodes.Call, data.WriterMethodInfo);

				il.Emit(OpCodes.Ret);
			}
		}
开发者ID:yashodhank,项目名称:QuasarRAT,代码行数:59,代码来源:ObjectSerializer.cs


示例11: GenCode0

        internal override void GenCode0(CodeGenContext context)
        {
            bool created;
            ISimple left = context.PreCompute(lhs, "lhs", out created);

            new COND((Node)left, (Node)left, rhs, location).GenCode(context);

            context.ReleaseLocal(left, created);
        }
开发者ID:chunlea,项目名称:rubydotnetcompiler,代码行数:9,代码来源:Operators.cs


示例12: GenCode0

        internal override void GenCode0(CodeGenContext context)
        {
            bool created;
            ISimple list = GenArgList(context, out created);
            list.GenSimple(context);
            context.callvirt(Runtime.ArgList.ToRubyObject);

            context.ReleaseLocal(list, created);
        }
开发者ID:chunlea,项目名称:rubydotnetcompiler,代码行数:9,代码来源:Args.cs


示例13: GenCode

 internal void GenCode(CodeGenContext context)
 {
     for (Node stmt = this; stmt != null; stmt = stmt.nd_next)
     {
         stmt.GenCode0(context);
         if (stmt.nd_next != null && context.Reachable())
             context.pop();
     }
 }
开发者ID:chunlea,项目名称:rubydotnetcompiler,代码行数:9,代码来源:Node.cs


示例14: GenerateReaderMethod

		public void GenerateReaderMethod(Type type, CodeGenContext ctx, ILGenerator il)
		{
			// arg0: Serializer, arg1: stream, arg2: out value

			if (type.IsClass)
			{
				// instantiate empty class
				il.Emit(OpCodes.Ldarg_2);

				var gtfh = typeof(Type).GetMethod("GetTypeFromHandle", BindingFlags.Public | BindingFlags.Static);
				var guo = typeof(System.Runtime.Serialization.FormatterServices).GetMethod("GetUninitializedObject", BindingFlags.Public | BindingFlags.Static);
				il.Emit(OpCodes.Ldtoken, type);
				il.Emit(OpCodes.Call, gtfh);
				il.Emit(OpCodes.Call, guo);
				il.Emit(OpCodes.Castclass, type);

				il.Emit(OpCodes.Stind_Ref);
			}

			var fields = Helpers.GetFieldInfos(type);

			foreach (var field in fields)
			{
				var fieldType = field.FieldType;

				var data = ctx.GetTypeDataForCall(fieldType);

				if (data.NeedsInstanceParameter)
					il.Emit(OpCodes.Ldarg_0);

				il.Emit(OpCodes.Ldarg_1);
				il.Emit(OpCodes.Ldarg_2);
				if (type.IsClass)
					il.Emit(OpCodes.Ldind_Ref);
				il.Emit(OpCodes.Ldflda, field);

				il.Emit(OpCodes.Call, data.ReaderMethodInfo);
			}

			if (typeof(System.Runtime.Serialization.IDeserializationCallback).IsAssignableFrom(type))
			{
				var miOnDeserialization = typeof(System.Runtime.Serialization.IDeserializationCallback).GetMethod("OnDeserialization",
										BindingFlags.Instance | BindingFlags.Public,
										null, new[] { typeof(Object) }, null);

				il.Emit(OpCodes.Ldarg_2);
				il.Emit(OpCodes.Ldnull);
				il.Emit(OpCodes.Constrained, type);
				il.Emit(OpCodes.Callvirt, miOnDeserialization);
			}

			il.Emit(OpCodes.Ret);
		}
开发者ID:yashodhank,项目名称:QuasarRAT,代码行数:53,代码来源:GenericSerializer.cs


示例15: GenerateCode

        internal PERWAPI.PEFile GenerateCode(Field CurrentRubyClass)
        {
            CodeGenContext context = new CodeGenContext();
            context.CurrentRubyClass = CurrentRubyClass;

            string name = "Eval_" + System.Guid.NewGuid().ToString("N");

            context.CreateAssembly("./", name + ".dll", name, false);

            GenerateClassForMethod(context);
                      
            return context.Assembly;
        }
开发者ID:chunlea,项目名称:rubydotnetcompiler,代码行数:13,代码来源:Eval.cs


示例16: PushScope

 private ISimple PushScope(CodeGenContext context, out bool created)
 {
     if (name != null && name.scope != null)
         return context.PreCompute(name.scope, "scope", out created);
     else
     {
         created = false;
         if (context.CurrentRubyClass != null)
             return new StaticField(context.CurrentRubyClass, name.location);
         else
             return new StaticField(Runtime.Init.rb_cObject, name.location);
     }
 }
开发者ID:chunlea,项目名称:rubydotnetcompiler,代码行数:13,代码来源:ClassesAndModules.cs


示例17: GenCode0

        internal override void GenCode0(CodeGenContext context)
        {
            PERWAPI.CILLabel elseLabel = context.NewLabel();
            PERWAPI.CILLabel endLabel = context.NewLabel();

            // if (Eval.Test(cond))
            cond.GenCode(context);
            context.call(Runtime.Eval.Test);
            context.brfalse(elseLabel);
            body.GenCode(context);
            context.br(endLabel);
            context.CodeLabel(elseLabel);
            _else.GenCode(context);
            context.CodeLabel(endLabel);
        }
开发者ID:chunlea,项目名称:rubydotnetcompiler,代码行数:15,代码来源:Stmts.cs


示例18: GenCode0

        internal override void GenCode0(CodeGenContext context)
        {
            PERWAPI.CILLabel finalLabel = context.NewLabel();

            int RescueTemp = context.CreateLocal("rescueTemp", PERWAPI.PrimitiveType.Object);
            context.ldnull();
            context.stloc(RescueTemp);

            if (ensure != null)
            {
                context.StartBlock(Clause.Try); // outer try block with finally

                context.StartBlock(Clause.Try); // inner try block with catch
            }

            GenInnerBlock(context, RescueTemp);

            if (ensure != null)
            {
                context.Goto(finalLabel);

                PERWAPI.TryBlock innerTry = context.EndTryBlock();

                context.StartBlock(Clause.Catch);
                GenRescue(context, null, 0, null);
                context.EndCatchBlock(Runtime.SystemExceptionRef, innerTry);

                PERWAPI.TryBlock outerTry = context.EndTryBlock();
                
                // Fixme: reset labels to prevent branches out of finally block.    
                context.StartBlock(Clause.Finally);
                ensure.GenCode(context);
                if (context.Reachable())
                    context.pop();
                context.endfinally();
                context.EndFinallyBlock(outerTry);

                context.CodeLabel(finalLabel);
                context.newEndPoint(location);
            }

            context.ldloc(RescueTemp);

            context.ReleaseLocal(RescueTemp, true);
        }
开发者ID:chunlea,项目名称:rubydotnetcompiler,代码行数:45,代码来源:Exceptions.cs


示例19: CopySimple

        internal void CopySimple(CodeGenContext context, Scope scope)
        {
            if (block != null)
            {
                // locals.block = block;
                string bname = ID.ToDotNetName(block.vid);
                context.ldloc(0);
                LoadBlock(context);
                context.stfld(scope.GetFrameField(bname));
            }

            for (Node f = normal; f != null; f = f.nd_next)
            {
                string fname = ID.ToDotNetName(((VAR)f).vid);

                // local.f = f;
                context.ldloc(0);
                context.ldarg(fname);
                context.stfld(scope.GetFrameField(fname));
            }
        }
开发者ID:chunlea,项目名称:rubydotnetcompiler,代码行数:21,代码来源:Formals.cs


示例20: GenerateWriterMethod

        public void GenerateWriterMethod(Type type, CodeGenContext ctx, ILGenerator il)
        {
            // arg0: buffer, arg1: value

            var fields = Helpers.GetFieldInfos(type);

            foreach (var field in fields)
            {
                // Note: the user defined value type is not passed as reference. could cause perf problems with big structs

                il.Emit(OpCodes.Ldarg_0);
                if (type.IsValueType)
                    il.Emit(OpCodes.Ldarga_S, 1);
                else
                    il.Emit(OpCodes.Ldarg_1);
                il.Emit(OpCodes.Ldfld, field);

                Helpers.GenSerializerCall(ctx, il, field.FieldType);
            }

            il.Emit(OpCodes.Ret);
        }
开发者ID:Egipto87,项目名称:DOOP.ec,代码行数:22,代码来源:PacketSerializer.cs



注:本文中的CodeGenContext类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# CodeGenerationContext类代码示例发布时间:2022-05-24
下一篇:
C# CodeGen类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap