コード例 #1
0
ファイル: Copier.cs プロジェクト: riverar/devtools
 /// <summary>
 /// Visits the specified less than or equal.
 /// </summary>
 /// <param name="lessThanOrEqual">The less than or equal.</param>
 public override void Visit(ILessThanOrEqual lessThanOrEqual)
 {
     LessThanOrEqual mutableLessThanOrEqual = new LessThanOrEqual(lessThanOrEqual);
     this.resultExpression = this.myCodeCopier.DeepCopy(mutableLessThanOrEqual);
 }
コード例 #2
0
ファイル: Copier.cs プロジェクト: riverar/devtools
 /// <summary>
 /// Visits the specified less than or equal.
 /// </summary>
 /// <param name="lessThanOrEqual">The less than or equal.</param>
 /// <returns></returns>
 protected virtual IExpression DeepCopy(LessThanOrEqual lessThanOrEqual)
 {
     return this.DeepCopy((BinaryOperation)lessThanOrEqual);
 }
コード例 #3
0
ファイル: IfThenElseReplacer.cs プロジェクト: xornand/cci
    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;
    }
コード例 #4
0
        /// <summary>
        /// Adds the rsd contract to the method, it is added as a postcondition where the rsd field of the type is less than or equal to limit
        /// </summary>
        protected FieldDefinition AddRsdContractToMethod(IMethodDefinition method, ITypeReference type, string rsdName, IExpression limit, IExpression cond)
        {
            var rsdField = GetRsdField(method, rsdName, type);

            var newContract = new Microsoft.Cci.MutableContracts.MethodContract();
            var postconditions = new List<IPostcondition>();

            var limitCondition = new LessThanOrEqual()
            {
                LeftOperand = new BoundExpression()
                {
                    Definition = rsdField,
                    Type = rsdField.Type
                },
                RightOperand = limit,
                Type = _host.PlatformType.SystemBoolean,
            };

            var int32Type = new PlatformType(_host).SystemInt32;

            if (cond != null)
            {
                //cond ==> tmp <= limit =~=
                //!cond || tmp <= limit =~=
                //!cond ? tmp <= limit : true
                postconditions.Add(
                    new Microsoft.Cci.MutableContracts.PostCondition()
                    {
                        Condition = new Conditional()
                        {
                            Condition = new LogicalNot() { Operand = cond },
                            Type = int32Type,
                            ResultIfTrue = new CompileTimeConstant() { Type = int32Type, Value = 1 },
                            ResultIfFalse = limitCondition
                        },
                        OriginalSource = "!cond ? rsd <= limit : true",
                    }
                );
            }
            else
            {
                postconditions.Add(
                    new Microsoft.Cci.MutableContracts.PostCondition()
                    {
                        Condition = limitCondition,
                        OriginalSource = "rsd <= limit",
                    }
                );
            }

            newContract.Postconditions = postconditions;

            var contract = _contractProvider.GetMethodContractFor(method);
            if (contract != null)
            {
                Microsoft.Cci.MutableContracts.ContractHelper.AddMethodContract(newContract, contract);
            }
            _contractProvider.AssociateMethodWithContract(method, newContract);

            return rsdField;
        }
コード例 #5
0
ファイル: Mutator.cs プロジェクト: riverar/devtools
 /// <summary>
 /// Visits the specified less than or equal.
 /// </summary>
 /// <param name="lessThanOrEqual">The less than or equal.</param>
 /// <returns></returns>
 public virtual IExpression Visit(LessThanOrEqual lessThanOrEqual)
 {
     return this.Visit((BinaryOperation)lessThanOrEqual);
 }
コード例 #6
0
ファイル: Mutator.cs プロジェクト: riverar/devtools
 /// <summary>
 /// Rewrites the children of the given less-than-or-equal expression.
 /// </summary>
 public virtual void RewriteChildren(LessThanOrEqual lessThanOrEqual)
 {
     this.RewriteChildren((BinaryOperation)lessThanOrEqual);
 }
コード例 #7
0
ファイル: Mutator.cs プロジェクト: riverar/devtools
 /// <summary>
 /// Visits the specified less than or equal.
 /// </summary>
 /// <param name="lessThanOrEqual">The less than or equal.</param>
 public override void Visit(ILessThanOrEqual lessThanOrEqual)
 {
     LessThanOrEqual mutableLessThanOrEqual = lessThanOrEqual as LessThanOrEqual;
     if (alwaysMakeACopy || mutableLessThanOrEqual == null) mutableLessThanOrEqual = new LessThanOrEqual(lessThanOrEqual);
     this.resultExpression = this.myCodeMutator.Visit(mutableLessThanOrEqual);
 }