Пример #1
0
        public static void EmitConvert(XamlEmitContextWithLocals <IXamlILEmitter, XamlILNodeEmitResult> context, IXamlILEmitter ilgen, IXamlLineInfo node,
                                       IXamlType what,
                                       IXamlType to)
        {
            XamlLocalsPool.PooledLocal local = null;

            EmitConvert(context, node, what, to, lda =>
            {
                if (!lda)
                {
                    return(ilgen);
                }
                local = ilgen.LocalsPool.GetLocal(what);
                ilgen
                .Stloc(local.Local)
                .Ldloca(local.Local);
                return(ilgen);
            });
            local?.Dispose();
        }
Пример #2
0
        protected override void EmitConvert(IXamlAstNode value, IXamlILEmitter codeGen, IXamlType expectedType, IXamlType returnedType)
        {
            XamlLocalsPool.PooledLocal local = null;
            // ReSharper disable once ExpressionIsAlwaysNull
            // Value is assigned inside the closure in certain conditions

            ILEmitHelpers.EmitConvert(this, value, returnedType, expectedType, ldaddr =>
            {
                if (ldaddr && returnedType.IsValueType)
                {
                    // We need to store the value to a temporary variable, since *address*
                    // is required (probably for  method call on the value type)
                    local = GetLocalOfType(returnedType);
                    codeGen
                    .Stloc(local.Local)
                    .Ldloca(local.Local);
                }
                // Otherwise do nothing, value is already at the top of the stack
                return(codeGen);
            });
            local?.Dispose();
        }