Пример #1
0
        protected internal override void EmitBranch(CodeGen g, OptionalLabel labelTrue, OptionalLabel labelFalse)
        {
            this.SetNotLeaked();

            // try handle And/Or
            bool handled = false;
            var  lit     = _ifTrue as IntLiteral;

            if (!ReferenceEquals(lit, null) && lit.Value == 1 && lit.GetReturnType(g.TypeMapper) == g.TypeMapper.MapType(typeof(bool)))
            {
                EmitOr(g, labelTrue, labelFalse, _cond, _ifFalse);
                handled = true;
            }
            else if (ReferenceEquals(lit, null))
            {
                lit = _ifFalse as IntLiteral;
                if (!ReferenceEquals(lit, null) && lit.Value == 0 && lit.GetReturnType(g.TypeMapper) == g.TypeMapper.MapType(typeof(bool)))
                {
                    EmitAnd(g, labelTrue, labelFalse, _cond, _ifTrue);
                    handled = true;
                }
            }

            if (!handled)
            {
                base.EmitBranch(g, labelTrue, labelFalse);
            }
        }
Пример #2
0
 public AddUserForm()
 {
     InitializeComponent();
     //UserNameBox.Enabled = false;
     //UserSurnameBox.Enabled = false;
     //UserMailBox.Enabled = false;
     OptionalLabel.Hide();
 }
Пример #3
0
        protected internal override void EmitBranch(CodeGen g, OptionalLabel labelTrue, OptionalLabel labelFalse)
        {
            OperandExtensions.SetLeakedState(this, false);
            if (ReferenceEquals(_local, null))
            {
                _local = g.Local(_internal);
            }

            _local.EmitBranch(g, labelTrue, labelFalse);
        }
Пример #4
0
        void EmitAnd(CodeGen g, OptionalLabel labelTrue, OptionalLabel labelFalse, Operand first, Operand second)
        {
            var trueOptional = new OptionalLabel(g.IL);

            labelFalse.EnsureExists();
            first.EmitBranch(g, trueOptional, labelFalse);
            if (trueOptional.IsLabelExist) // it can jump out of internal Or on first true but we still need to check second
            {
                g.IL.MarkLabel(trueOptional.Value);
            }
            second.EmitBranch(g, labelTrue, labelFalse);
        }
Пример #5
0
        void EmitOr(CodeGen g, OptionalLabel labelTrue, OptionalLabel labelFalse, Operand first, Operand second)
        {
            var falseOptional = new OptionalLabel(g.IL);

            labelTrue.EnsureExists();
            first.EmitBranch(g, labelTrue, falseOptional);
            if (falseOptional.IsLabelExist) // it can jump out of internal And on first false but we still may hope on second
            {
                g.IL.MarkLabel(falseOptional.Value);
            }
            second.EmitBranch(g, labelTrue, labelFalse);
        }
Пример #6
0
        protected internal override void EmitGet(CodeGen g)
        {
            OperandExtensions.SetLeakedState(this, false);
            Initialize(g.TypeMapper);
            Label lbTrue = g.IL.DefineLabel();
            Label lbEnd  = g.IL.DefineLabel();

            var lbFalse = new OptionalLabel(g.IL);

            _cond.EmitBranch(g, lbTrue, lbFalse);
            if (lbFalse.IsLabelExist)
            {
                g.IL.MarkLabel(lbFalse.Value);
            }
            _ifFalse.EmitGet(g);
            g.IL.Emit(OpCodes.Br, lbEnd);
            g.IL.MarkLabel(lbTrue);
            _ifTrue.EmitGet(g);
            g.IL.MarkLabel(lbEnd);
        }
Пример #7
0
        protected internal override void EmitGet(CodeGen g)  
        {
		    OperandExtensions.SetLeakedState(this, false); 
            Initialize(g.TypeMapper);
            Label lbTrue = g.IL.DefineLabel();
            Label lbEnd = g.IL.DefineLabel();

            var lbFalse = new OptionalLabel(g.IL);

            _cond.EmitBranch(g, lbTrue, lbFalse);
            if (lbFalse.IsLabelExist)
                g.IL.MarkLabel(lbFalse.Value);
            _ifFalse.EmitGet(g);
            g.IL.Emit(OpCodes.Br, lbEnd);
            g.IL.MarkLabel(lbTrue);
            _ifTrue.EmitGet(g);
            g.IL.MarkLabel(lbEnd);
        }
Пример #8
0
 void EmitAnd(CodeGen g, OptionalLabel labelTrue,OptionalLabel labelFalse, Operand first, Operand second)
 {
     var trueOptional = new OptionalLabel(g.IL);
     labelFalse.EnsureExists();
     first.EmitBranch(g, trueOptional, labelFalse);
     if (trueOptional.IsLabelExist) // it can jump out of internal Or on first true but we still need to check second
         g.IL.MarkLabel(trueOptional.Value);
     second.EmitBranch(g, labelTrue, labelFalse);
 }
Пример #9
0
 void EmitOr(CodeGen g, OptionalLabel labelTrue, OptionalLabel labelFalse, Operand first, Operand second)
 {
     var falseOptional = new OptionalLabel(g.IL);
     labelTrue.EnsureExists();
     first.EmitBranch(g, labelTrue, falseOptional);
     if (falseOptional.IsLabelExist) // it can jump out of internal And on first false but we still may hope on second
         g.IL.MarkLabel(falseOptional.Value);
     second.EmitBranch(g, labelTrue, labelFalse);
 }
Пример #10
0
        protected internal override void EmitBranch(CodeGen g, OptionalLabel labelTrue, OptionalLabel labelFalse)
        {
            this.SetNotLeaked();
            
            // try handle And/Or
            bool handled = false;
            var lit = _ifTrue as IntLiteral;
            if (!ReferenceEquals(lit, null) && lit.Value == 1 && lit.GetReturnType(g.TypeMapper) == g.TypeMapper.MapType(typeof(bool)))
            {
                EmitOr(g, labelTrue, labelFalse, _cond, _ifFalse);
                handled = true;
            }
            else if (ReferenceEquals(lit, null))
            {
                lit = _ifFalse as IntLiteral;
                if (!ReferenceEquals(lit, null) && lit.Value == 0 && lit.GetReturnType(g.TypeMapper) == g.TypeMapper.MapType(typeof(bool)))
                {
                    EmitAnd(g, labelTrue, labelFalse, _cond, _ifTrue);
                    handled = true;
                }
            }

            if (!handled) base.EmitBranch(g, labelTrue, labelFalse);
        }
Пример #11
0
 protected internal override void EmitBranch(CodeGen g, OptionalLabel labelTrue, OptionalLabel labelFalse)
 {
     OperandExtensions.SetLeakedState(this, false);
     if (ReferenceEquals(_local, null))
         _local = g.Local(_internal);
     
     _local.EmitBranch(g, labelTrue,labelFalse);
 }
Пример #12
0
        protected internal override void EmitBranch(CodeGen g, OptionalLabel labelTrue, OptionalLabel labelFalse)
        {
            OperandExtensions.SetLeakedState(this, false);

            foreach (LocalCache lc in _caches)
            {
                lc.Clear();
            }

            bool argsEmitted = false;

            var branchSet = BranchSet.Normal;

            // value type handling
            if (_operands.Length == 2)
            {
                var  valueOperand = _operands[0] ?? _operands[1];
                Type returnType   = valueOperand?.GetReturnType(g.TypeMapper);
                if (returnType?.IsValueType ?? false)
                {
                    if (ReferenceEquals(_operands[0], null) || ReferenceEquals(_operands[1], null))
                    {
                        bool isNullable = Helpers.GetNullableUnderlyingType(returnType) != null;

                        var op = branchSet.Get(_op.BranchOp, true);
                        if (op == OpCodes.Bne_Un || op == OpCodes.Bne_Un_S)
                        {
                            if (isNullable)
                            {
                                valueOperand.Property("HasValue", g.TypeMapper).EmitBranch(g, labelTrue, labelFalse);
                            }
                            else
                            {
                                // ValueType != null, should return true
                                if (labelTrue != null && labelTrue.IsLabelExist) // otherwise default path
                                {
                                    g.IL.Emit(OpCodes.Br, labelTrue.Value);
                                }
                            }
                            return;
                        }
                        else if (op == OpCodes.Beq || op == OpCodes.Beq_S)
                        {
                            if (isNullable)
                            {
                                valueOperand.Property("HasValue", g.TypeMapper).EmitBranch(g, labelFalse, labelTrue);
                            }
                            else
                            {
                                // ValueType == null, should return false
                                if (labelFalse != null && labelFalse.IsLabelExist) // otherwise default path
                                {
                                    g.IL.Emit(OpCodes.Br, labelFalse.Value);
                                }
                            }
                            return;
                        }
                        else if (_op.IsLogical)                                // 5? > null, 5 <= null, ...
                        {
                            if (labelFalse != null && labelFalse.IsLabelExist) // otherwise default path
                            {
                                g.IL.Emit(OpCodes.Br, labelFalse.Value);
                            }
                        }
                    }
                }
            }

            PrepareAf(g.TypeMapper);

            if (!ReferenceEquals(_afInterceptor, null))
            {
                _afInterceptor.EmitBranch(g, labelTrue, labelFalse);
                return;
            }

            IStandardOperation stdOp = _af.Method as IStandardOperation;

            if (_op.BranchOp == 0 || stdOp == null)
            {
                base.EmitBranch(g, labelTrue, labelFalse);
                return;
            }

            if (!argsEmitted)
            {
                _af.EmitArgs(g, _operands);
            }

            bool inverted = false;

            if (labelTrue == null || !labelTrue.IsLabelExist)
            {
                if (labelFalse == null)
                {
                    throw new InvalidOperationException("No labels passed");
                }
                if (!labelFalse.IsLabelExist)
                {
                    throw new InvalidOperationException("No existing labels were passed");
                }
                labelTrue = labelFalse;
                branchSet = branchSet.GetInverted();
                inverted  = true;
            }
            g.IL.Emit(branchSet.Get(_op.BranchOp, stdOp.IsUnsigned), labelTrue.Value);
            if (!inverted && labelFalse != null && labelFalse.IsLabelExist)
            {
                g.IL.Emit(OpCodes.Br, labelFalse.Value);
            }
        }