示例#1
0
        public override IExpression Rewrite(IEquality equality)
        {
            base.Rewrite(equality);
            var cc2 = equality.RightOperand as CompileTimeConstant;

            if (cc2 != null && ExpressionHelper.IsNumericZero(cc2) && equality.LeftOperand.Type.TypeCode == PrimitiveTypeCode.Boolean)
            {
                return(IfThenElseReplacer.InvertCondition(equality.LeftOperand));
            }
            return(equality);
        }
示例#2
0
        public override IExpression Rewrite(ILogicalNot logicalNot)
        {
            if (logicalNot.Type is Dummy)
            {
                return(IfThenElseReplacer.InvertCondition(this.Rewrite(logicalNot.Operand)));
            }
            else if (logicalNot.Operand.Type.TypeCode == PrimitiveTypeCode.Int32)
            {
                return new Equality()
                       {
                           LeftOperand  = this.Rewrite(logicalNot.Operand),
                           RightOperand = new CompileTimeConstant()
                           {
                               Value = 0, Type = this.host.PlatformType.SystemInt32
                           },
                           Type = this.host.PlatformType.SystemBoolean,
                       }
            }
            ;
            else
            {
                var castIfPossible = logicalNot.Operand as CastIfPossible;

                if (castIfPossible != null)
                {
                    var mutableLogicalNot = logicalNot as LogicalNot;
                    if (mutableLogicalNot != null)
                    {
                        var operand = new CheckIfInstance()
                        {
                            Locations   = castIfPossible.Locations,
                            Operand     = castIfPossible.ValueToCast,
                            Type        = this.host.PlatformType.SystemBoolean,
                            TypeToCheck = castIfPossible.TargetType,
                        };
                        mutableLogicalNot.Operand = operand;
                        return(mutableLogicalNot);
                    }
                }
                return(base.Rewrite(logicalNot));
            }
        }