Exemple #1
0
        public void Compile(CompilationContext context)
        {
            Label elseLabel  = context.ilGenerator.DefineLabel();
            Label endIfLabel = context.ilGenerator.DefineLabel();

            condition.Compile(context);
            context.Emit(OpCodes.Brfalse, elseLabel);

            if (trueBranch != null)
            {
                trueBranch.Compile(context);
            }
            if (falseBranch != null)
            {
                context.Emit(OpCodes.Br, endIfLabel);
            }

            context.ilGenerator.MarkLabel(elseLabel);
            if (falseBranch != null)
            {
                falseBranch.Compile(context);
            }
            context.ilGenerator.MarkLabel(endIfLabel);
        }
Exemple #2
0
		public void BuildCopyImplMethod()
		{
			if (ReflectionUtils.IsNullable(from))
			{
				from = Nullable.GetUnderlyingType(from);
			}
			if (ReflectionUtils.IsNullable(to))
			{
				to = Nullable.GetUnderlyingType(to);
			}

			MethodBuilder methodBuilder = typeBuilder.DefineMethod(
				"MapImpl",
				MethodAttributes.Public | MethodAttributes.Virtual,
				typeof(object),
				new Type[] { typeof(object), typeof(object), typeof(object) }
				);

			ILGenerator ilGen = methodBuilder.GetILGenerator();
			CompilationContext compilationContext = new CompilationContext(ilGen);

			AstComplexNode mapperAst = new AstComplexNode();
			var locFrom = ilGen.DeclareLocal(from);
			var locTo = ilGen.DeclareLocal(to);
			var locState = ilGen.DeclareLocal(typeof(object));
			LocalBuilder locException = null;

			mapperAst.nodes.Add(BuilderUtils.InitializeLocal(locFrom, 1));
			mapperAst.nodes.Add(BuilderUtils.InitializeLocal(locTo, 2));
			mapperAst.nodes.Add(BuilderUtils.InitializeLocal(locState, 3));

#if DEBUG
			locException = compilationContext.ilGenerator.DeclareLocal(typeof(Exception));
#endif
			var mappingOperations = mappingConfigurator.GetMappingOperations(from, to);
			StaticConvertersManager staticConverter = mappingConfigurator.GetStaticConvertersManager();
            mapperAst.nodes.Add(
				new MappingOperationsProcessor()
				{
					locException = locException,
					locFrom = locFrom,
					locState = locState,
					locTo = locTo,
					objectsMapperManager = objectsMapperManager,
					compilationContext = compilationContext,
					storedObjects = storedObjects,
					operations = mappingOperations,
					mappingConfigurator = mappingConfigurator,
					rootOperation = mappingConfigurator.GetRootMappingOperation(from, to),
					staticConvertersManager = staticConverter ?? StaticConvertersManager.DefaultInstance
				}.ProcessOperations()
			);
			mapperAst.nodes.Add(
				new AstReturn()
				{
					returnType = typeof(object),
					returnValue = AstBuildHelper.ReadLocalRV(locTo)
				}
			);

			mapperAst.Compile(compilationContext);
		}