Exemplo n.º 1
0
 /// <summary>
 /// Visits the specified not equality.
 /// </summary>
 /// <param name="notEquality">The not equality.</param>
 /// <returns></returns>
 protected virtual IExpression DeepCopy(NotEquality notEquality)
 {
     return this.DeepCopy((BinaryOperation)notEquality);
 }
Exemplo n.º 2
0
 private Statement ParseUnaryConditionalBranch(IOperation currentOperation)
 {
     Expression condition = this.PopOperandStack();
       var castIfPossible = condition as CastIfPossible;
       if (castIfPossible != null) {
     condition = new CheckIfInstance() {
       Locations = castIfPossible.Locations,
       Operand = castIfPossible.ValueToCast,
       TypeToCheck = castIfPossible.TargetType,
     };
       } else if (condition.Type != Dummy.TypeReference && condition.Type.TypeCode != PrimitiveTypeCode.Boolean) {
     var defaultValue = new DefaultValue() { DefaultValueType = condition.Type, Type = condition.Type };
     condition = new NotEquality() { LeftOperand = condition, RightOperand = defaultValue };
       }
       condition.Type = this.platformType.SystemBoolean;
       GotoStatement gotoStatement = MakeGoto(currentOperation);
       ConditionalStatement ifStatement = new ConditionalStatement();
       ifStatement.Condition = condition;
       switch (currentOperation.OperationCode) {
     case OperationCode.Brfalse:
     case OperationCode.Brfalse_S:
       ifStatement.TrueBranch = new EmptyStatement();
       ifStatement.FalseBranch = gotoStatement;
       break;
     case OperationCode.Brtrue:
     case OperationCode.Brtrue_S:
     default:
       ifStatement.TrueBranch = gotoStatement;
       ifStatement.FalseBranch = new EmptyStatement();
       break;
       }
       return ifStatement;
 }
Exemplo n.º 3
0
    private static IExpression InvertBinaryOperation(IBinaryOperation binOp) {
      Contract.Requires(binOp != null);
      Contract.Ensures(Contract.Result<IExpression>() != null);

      BinaryOperation/*?*/ result = null;
      if (binOp is IEquality && binOp.LeftOperand.Type.TypeCode != PrimitiveTypeCode.Float32 && binOp.LeftOperand.Type.TypeCode != PrimitiveTypeCode.Float64)
        result = new NotEquality();
      else if (binOp is INotEquality && binOp.LeftOperand.Type.TypeCode != PrimitiveTypeCode.Float32 && binOp.LeftOperand.Type.TypeCode != PrimitiveTypeCode.Float64)
        result = new Equality();
      else if (binOp is ILessThan)
        result = new GreaterThanOrEqual() { IsUnsignedOrUnordered = KeepUnsignedButInvertUnordered(((ILessThan)binOp).IsUnsignedOrUnordered, binOp) };
      else if (binOp is ILessThanOrEqual)
        result = new GreaterThan() { IsUnsignedOrUnordered = KeepUnsignedButInvertUnordered(((ILessThanOrEqual)binOp).IsUnsignedOrUnordered, binOp) };
      else if (binOp is IGreaterThan)
        result = new LessThanOrEqual() { IsUnsignedOrUnordered = KeepUnsignedButInvertUnordered(((IGreaterThan)binOp).IsUnsignedOrUnordered, binOp) };
      else if (binOp is IGreaterThanOrEqual)
        result = new LessThan() { IsUnsignedOrUnordered = KeepUnsignedButInvertUnordered(((IGreaterThanOrEqual)binOp).IsUnsignedOrUnordered, binOp) };
      if (result != null) {
        result.LeftOperand = binOp.LeftOperand;
        result.RightOperand = binOp.RightOperand;
        result.Type = binOp.Type;
        result.Locations.AddRange(binOp.Locations);
        return result;
      }
      LogicalNot logicalNot = new LogicalNot();
      logicalNot.Operand = binOp;
      logicalNot.Type = binOp.Type;
      logicalNot.Locations.AddRange(binOp.Locations);
      return logicalNot;
    }
Exemplo n.º 4
0
 /// <summary>
 /// Visits the specified not equality.
 /// </summary>
 /// <param name="notEquality">The not equality.</param>
 public override void Visit(INotEquality notEquality)
 {
     NotEquality mutableNotEquality = new NotEquality(notEquality);
     this.resultExpression = this.myCodeCopier.DeepCopy(mutableNotEquality);
 }
Exemplo n.º 5
0
    private static IExpression ConvertToBoolean(IExpression expression) {
      Contract.Requires(expression != null);
      Contract.Ensures(Contract.Result<IExpression>() != null);

      IPlatformType platformType = expression.Type.PlatformType;
      var cc = expression as CompileTimeConstant;
      if (cc != null && TypeHelper.IsPrimitiveInteger(cc.Type)) {
        cc.Value = !ExpressionHelper.IsIntegralZero(cc);
        cc.Type = platformType.SystemBoolean;
        return cc;
      }
      var conditional = expression as Conditional;
      if (conditional != null) {
        conditional.ResultIfTrue = ConvertToBoolean(conditional.ResultIfTrue);
        conditional.ResultIfFalse = ConvertToBoolean(conditional.ResultIfFalse);
        conditional.Type = platformType.SystemBoolean;
        return conditional;
      }
      object/*?*/ val = null;
      ITypeReference type = platformType.SystemObject;
      ITypeReference expressionType = expression.Type;
      IExpression rightOperand = null; // zero or null, but has to be type-specific
      switch (expressionType.TypeCode) {
        case PrimitiveTypeCode.Boolean: {
            var addrDeref = expression as AddressDereference;
            Conversion conversion;
            IManagedPointerTypeReference mgdPtr;
            if (addrDeref != null && (conversion = addrDeref.Address as Conversion) != null && 
              (mgdPtr = conversion.ValueToConvert.Type as IManagedPointerTypeReference) != null) {
              expressionType = mgdPtr.TargetType;
              addrDeref.Address = conversion.ValueToConvert;
              addrDeref.Type = expressionType;
              expression = addrDeref;
              goto default;
            }
            return expression;
          }
        case PrimitiveTypeCode.Char: val = (char)0; type = platformType.SystemChar; break;
        case PrimitiveTypeCode.Float32: val = (float)0; type = platformType.SystemFloat32; break;
        case PrimitiveTypeCode.Float64: val = (double)0; type = platformType.SystemFloat64; break;
        case PrimitiveTypeCode.Int16: val = (short)0; type = platformType.SystemInt16; break;
        case PrimitiveTypeCode.Int32: val = (int)0; type = platformType.SystemInt32; break;
        case PrimitiveTypeCode.Int64: val = (long)0; type = platformType.SystemInt64; break;
        case PrimitiveTypeCode.Int8: val = (sbyte)0; type = platformType.SystemInt8; break;
        case PrimitiveTypeCode.IntPtr: val = IntPtr.Zero; type = platformType.SystemIntPtr; break;
        case PrimitiveTypeCode.UInt16: val = (ushort)0; type = platformType.SystemUInt16; break;
        case PrimitiveTypeCode.UInt32: val = (uint)0; type = platformType.SystemUInt32; break;
        case PrimitiveTypeCode.UInt64: val = (ulong)0; type = platformType.SystemUInt64; break;
        case PrimitiveTypeCode.UInt8: val = (byte)0; type = platformType.SystemUInt8; break;
        case PrimitiveTypeCode.UIntPtr: val = UIntPtr.Zero; type = platformType.SystemUIntPtr; break;
        default:
          rightOperand = new DefaultValue() {
            DefaultValueType = expressionType,
            Type = expressionType,
          };
          break;
      }
      if (rightOperand == null) {
        rightOperand = new CompileTimeConstant() {
          Value = val,
          Type = type,
        };
      }
      NotEquality result = new NotEquality() {
        LeftOperand = expression,
        RightOperand = rightOperand,
        Type = platformType.SystemBoolean,
      };
      return result;
    }
 public override IExpression Visit(NotEquality notEquality)
 {
     base.Visit(notEquality);
       var cc1 = notEquality.LeftOperand as CompileTimeConstant;
       var cc2 = notEquality.RightOperand as CompileTimeConstant;
       if (cc1 != null && cc2 != null) {
     if (cc1.Type.TypeCode == PrimitiveTypeCode.Int32 && cc2.Type.TypeCode == PrimitiveTypeCode.Int32)
       return new CompileTimeConstant() { Value = ((int)cc1.Value) != ((int)cc2.Value), Type = notEquality.Type };
       }
       return notEquality;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Visits the specified not equality.
 /// </summary>
 /// <param name="notEquality">The not equality.</param>
 /// <returns></returns>
 public virtual IExpression Visit(NotEquality notEquality)
 {
     return this.Visit((BinaryOperation)notEquality);
 }
Exemplo n.º 8
0
 /// <summary>
 /// Rewrites the children of the given not equality expression.
 /// </summary>
 public virtual void RewriteChildren(NotEquality notEquality)
 {
     this.RewriteChildren((BinaryOperation)notEquality);
 }
Exemplo n.º 9
0
 /// <summary>
 /// Visits the specified not equality.
 /// </summary>
 /// <param name="notEquality">The not equality.</param>
 public override void Visit(INotEquality notEquality)
 {
     NotEquality mutableNotEquality = notEquality as NotEquality;
     if (alwaysMakeACopy || mutableNotEquality == null) mutableNotEquality = new NotEquality(notEquality);
     this.resultExpression = this.myCodeMutator.Visit(mutableNotEquality);
 }