Esempio n. 1
0
 private BinaryOperation ParseBinaryOperation(BinaryOperation binaryOperation)
 {
     binaryOperation.RightOperand = this.PopOperandStack();
       binaryOperation.LeftOperand = this.PopOperandStack();
       return binaryOperation;
 }
    private BinaryOperation HarmonizeOperands(BinaryOperation binaryOperation) {
      Contract.Requires(binaryOperation != null);
      Contract.Ensures(Contract.Result<BinaryOperation>() != null);

      var leftType = binaryOperation.LeftOperand.Type;
      var rightType = binaryOperation.RightOperand.Type;
      if (TypeHelper.TypesAreEquivalent(leftType, rightType)) return binaryOperation;
      switch (leftType.TypeCode) {
        case PrimitiveTypeCode.Boolean:
        case PrimitiveTypeCode.Char:
          binaryOperation.RightOperand = TypeInferencer.Convert(binaryOperation.RightOperand, leftType);
          return binaryOperation;
        case PrimitiveTypeCode.NotPrimitive:
          if (leftType.IsEnum || leftType.ResolvedType.IsEnum) {
            binaryOperation.RightOperand = new Conversion() { ValueToConvert = binaryOperation.RightOperand, TypeAfterConversion = leftType };
            return binaryOperation;
          }
          break;
      }
      switch (rightType.TypeCode) {
        case PrimitiveTypeCode.Boolean:
        case PrimitiveTypeCode.Char:
          binaryOperation.LeftOperand = TypeInferencer.Convert(binaryOperation.LeftOperand, rightType);
          return binaryOperation;
        case PrimitiveTypeCode.NotPrimitive:
          if (rightType.IsEnum || rightType.ResolvedType.IsEnum) {
            binaryOperation.LeftOperand = new Conversion() { ValueToConvert = binaryOperation.LeftOperand, TypeAfterConversion = rightType };
            return binaryOperation;
          }
          break;
      }
      return binaryOperation;
    }
 private BinaryOperation ParseUnsignedBinaryOperation(BinaryOperation binaryOperation) {
   Contract.Requires(binaryOperation != null);
   binaryOperation.RightOperand = this.PopOperandStackAsUnsigned();
   binaryOperation.LeftOperand = this.PopOperandStackAsUnsigned();
   return binaryOperation;
 }
Esempio n. 4
0
 public override void RewriteChildren(BinaryOperation binaryOperation)
 {
     var leftPop = binaryOperation.LeftOperand is IPopValue && binaryOperation.LeftOperand.Type.TypeCode != PrimitiveTypeCode.Boolean;
     var rightPop = binaryOperation.RightOperand is IPopValue && binaryOperation.RightOperand.Type.TypeCode != PrimitiveTypeCode.Boolean;
     base.RewriteChildren(binaryOperation);
     if (leftPop && !rightPop && binaryOperation.LeftOperand.Type.TypeCode == PrimitiveTypeCode.Boolean)
     {
         // then left went from int to bool
         binaryOperation.RightOperand = TypeInferencer.Convert(binaryOperation.RightOperand, this.systemBool);
     }
     else if (rightPop && !leftPop && binaryOperation.RightOperand.Type.TypeCode == PrimitiveTypeCode.Boolean)
     {
         // then right went from int to bool
         binaryOperation.LeftOperand = TypeInferencer.Convert(binaryOperation.LeftOperand, this.systemBool);
     }
 }
Esempio n. 5
0
 private void CopyChildren(BinaryOperation binaryOperation)
 {
     this.CopyChildren((Expression)binaryOperation);
       binaryOperation.LeftOperand = this.Copy(binaryOperation.LeftOperand);
       binaryOperation.RightOperand = this.Copy(binaryOperation.RightOperand);
 }
Esempio n. 6
0
 /// <summary>
 /// Visits the specified binary operation.
 /// </summary>
 /// <param name="binaryOperation">The binary operation.</param>
 /// <returns></returns>
 protected virtual IExpression DeepCopy(BinaryOperation binaryOperation)
 {
     binaryOperation.LeftOperand = this.Substitute(binaryOperation.LeftOperand);
       binaryOperation.RightOperand = this.Substitute(binaryOperation.RightOperand);
       binaryOperation.Type = this.Substitute(binaryOperation.Type);
       return binaryOperation;
 }
Esempio n. 7
0
 /// <summary>
 /// Called from the type specific rewrite method to rewrite the common part of all binary operation expressions.
 /// </summary>
 public virtual void RewriteChildren(BinaryOperation binaryOperation)
 {
     this.RewriteChildren((Expression)binaryOperation);
       binaryOperation.LeftOperand = this.Rewrite(binaryOperation.LeftOperand);
       binaryOperation.RightOperand = this.Rewrite(binaryOperation.RightOperand);
 }
Esempio n. 8
0
 /// <summary>
 /// Visits the specified binary operation.
 /// </summary>
 /// <param name="binaryOperation">The binary operation.</param>
 /// <returns></returns>
 public virtual IExpression Visit(BinaryOperation binaryOperation)
 {
     binaryOperation.LeftOperand = this.Visit(binaryOperation.LeftOperand);
       binaryOperation.RightOperand = this.Visit(binaryOperation.RightOperand);
       binaryOperation.Type = this.Visit(binaryOperation.Type);
       return binaryOperation;
 }