Beispiel #1
0
        private HLLocation ProcessLogicalNotExpression(ILogicalNot pExpression)
        {
            HLLocation locationOperand   = ProcessExpression(pExpression.Operand);
            HLLocation locationTemporary = HLTemporaryLocation.Create(CreateTemporary(HLDomain.GetOrCreateType(pExpression.Type)));

            mCurrentBlock.EmitBitwiseXor(locationTemporary, locationOperand, HLBooleanLiteralLocation.Create(true));
            return(locationTemporary);
        }
 public override void Visit(ILogicalNot logicalNot)
 {
     if (Process(logicalNot))
     {
         visitor.Visit(logicalNot);
     }
     base.Visit(logicalNot);
 }
Beispiel #3
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));
            }
        }
Beispiel #4
0
        internal static IExpression InvertCondition(IExpression expression)
        {
            IBinaryOperation /*?*/ binOp = expression as IBinaryOperation;

            if (binOp != null)
            {
                return(InvertBinaryOperation(binOp));
            }
            ILogicalNot /*?*/ logNot = expression as ILogicalNot;

            if (logNot != null)
            {
                return(logNot.Operand);
            }
            LogicalNot logicalNot = new LogicalNot();

            logicalNot.Operand = expression;
            logicalNot.Type    = expression.Type;
            logicalNot.Locations.AddRange(expression.Locations);
            return(logicalNot);
        }
 public virtual void onASTElement(ILogicalNot logicalNot) { }
    public override void Visit(ILogicalNot logicalNot) {
      base.Visit(logicalNot);
      Bpl.Expr exp = TranslatedExpressions.Pop();
      TranslatedExpressions.Push(Bpl.Expr.Unary(
          logicalNot.Token(),
          Bpl.UnaryOperator.Opcode.Not, exp));

    }
 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);
   }
 }
 public override void Visit(ILogicalNot logicalNot)
 {
     if(Process(logicalNot)){visitor.Visit(logicalNot);}
     base.Visit(logicalNot);
 }
Beispiel #9
0
 public void Visit(ILogicalNot logicalNot)
 {
     Contract.Requires(logicalNot != null);
       throw new NotImplementedException();
 }
 public override void TraverseChildren(ILogicalNot logicalNot)
 {
   base.Traverse(logicalNot.Operand);
   Bpl.Expr exp = TranslatedExpressions.Pop();
   Bpl.Type operandType = this.sink.CciTypeToBoogie(logicalNot.Operand.Type);
   if (operandType == this.sink.Heap.RefType) {
     exp = Bpl.Expr.Binary(Bpl.BinaryOperator.Opcode.Neq, exp, Bpl.Expr.Ident(this.sink.Heap.NullRef));
   }
   else if (operandType == Bpl.Type.Int) {
     exp = Bpl.Expr.Binary(Bpl.BinaryOperator.Opcode.Neq, exp, Bpl.Expr.Literal(0));
   }
   else {
     //System.Diagnostics.Debug.Assert(operandType == Bpl.Type.Bool);
   }
   TranslatedExpressions.Push(Bpl.Expr.Unary(
       logicalNot.Token(),
       Bpl.UnaryOperator.Opcode.Not, exp));
 }
        public override void TraverseChildren(ILogicalNot logicalNot)
{ MethodEnter(logicalNot);
            base.TraverseChildren(logicalNot);
     MethodExit();   }
 /// <summary>
 /// Rewrites the given logical not expression.
 /// </summary>
 /// <param name="logicalNot"></param>
 public virtual IExpression Rewrite(ILogicalNot logicalNot)
 {
     return logicalNot;
 }
Beispiel #13
0
 public void Visit(ILogicalNot logicalNot)
 {
     this.result = this.rewriter.Rewrite(logicalNot);
 }
Beispiel #14
0
        public override IExpression Rewrite(ILogicalNot logicalNot)
        {
            var result = base.Rewrite(logicalNot);

            return(BooleanExpressionHelper.Normalize(result));
        }
Beispiel #15
0
 public override void Visit(ILogicalNot logicalNot)
 {
     allElements.Add(new InvokInfo(Traverser, "ILogicalNot", logicalNot));
 }
Beispiel #16
0
 public override void TraverseChildren(ILogicalNot logicalNot)
 {
     base.TraverseChildren(logicalNot);
     ((LogicalNot)logicalNot).Type = this.platformType.SystemBoolean;
 }
Beispiel #17
0
 /// <summary>
 /// Generates IL for the specified logical not.
 /// </summary>
 /// <param name="logicalNot">The logical not.</param>
 public override void TraverseChildren(ILogicalNot logicalNot)
 {
     if (logicalNot.Operand.Type.IsValueType) {
     //The type should be a primitive integer, a boolean or an enum.
     this.Traverse(logicalNot.Operand);
     var opsize = TypeHelper.SizeOfType(logicalNot.Operand.Type);
     if (opsize == 1 || opsize == 2 || opsize == 4) {
       this.generator.Emit(OperationCode.Ldc_I4_0);
       this.StackSize++;
       this.generator.Emit(OperationCode.Ceq);
       this.StackSize--;
     } else if (opsize == 8) {
       this.generator.Emit(OperationCode.Ldc_I4_0);
       this.StackSize++;
       this.generator.Emit(OperationCode.Conv_I8);
       this.generator.Emit(OperationCode.Ceq);
       this.StackSize--;
     } else {
       Contract.Assert(opsize == 0); //If not, the CodeModel is invalid.
       //the type is an unresolved reference, typically an enum, so we just don't know what size it is (at compile time, that is).
       var trueCase = new ILGeneratorLabel();
       var done = new ILGeneratorLabel();
       this.generator.Emit(OperationCode.Brtrue_S, trueCase);
       this.generator.Emit(OperationCode.Ldc_I4_0);
       this.generator.Emit(OperationCode.Br_S, done);
       this.generator.MarkLabel(trueCase);
       this.generator.Emit(OperationCode.Ldc_I4_1);
       this.generator.MarkLabel(done);
     }
       } else {
     //pointer non null test
     this.Traverse(logicalNot.Operand);
     this.generator.Emit(OperationCode.Ldnull);
     this.StackSize++;
     this.generator.Emit(OperationCode.Ceq);
     this.StackSize--;
       }
 }
Beispiel #18
0
 public override void TraverseChildren(ILogicalNot logicalNot) {
   this.sourceEmitterOutput.Write("Not ");
   this.Traverse(logicalNot.Operand);
 }
Beispiel #19
0
 /// <summary>
 /// Rewrites the given logical not expression.
 /// </summary>
 /// <param name="logicalNot"></param>
 public virtual IExpression Rewrite(ILogicalNot logicalNot)
 {
     var mutableLogicalNot = logicalNot as LogicalNot;
       if (mutableLogicalNot == null) return logicalNot;
       this.RewriteChildren(mutableLogicalNot);
       return mutableLogicalNot;
 }
Beispiel #20
0
 //^ ensures this.path.Count == old(this.path.Count);
 /// <summary>
 /// Traverses the given logical not expression.
 /// </summary>
 /// <param name="logicalNot"></param>
 public virtual void Visit(ILogicalNot logicalNot)
 {
     if (this.stopTraversal) return;
       //^ int oldCount = this.path.Count;
       this.path.Push(logicalNot);
       this.Visit(logicalNot.Operand);
       //^ assume this.path.Count == oldCount+1; //True because all of the virtual methods of this class promise not to decrease this.path.Count.hod or operation is not implemented.");
       this.path.Pop();
 }
Beispiel #21
0
 public void Visit(ILogicalNot logicalNot)
 {
     this.result = this.copier.Copy(logicalNot);
 }
Beispiel #22
0
 /// <summary>
 /// Traverses the logical not expression.
 /// </summary>
 public void Traverse(ILogicalNot logicalNot)
 {
     Contract.Requires(logicalNot != null);
       if (this.preorderVisitor != null) this.preorderVisitor.Visit(logicalNot);
       if (this.StopTraversal) return;
       this.TraverseChildren(logicalNot);
       if (this.StopTraversal) return;
       if (this.postorderVisitor != null) this.postorderVisitor.Visit(logicalNot);
 }
Beispiel #23
0
 public virtual void onASTElement(ILogicalNot logicalNot)
 {
 }
Beispiel #24
0
 public void Visit(ILogicalNot logicalNot)
 {
     this.traverser.Traverse(logicalNot);
 }
 public override void TraverseChildren(ILogicalNot logicalNot) {
   base.TraverseChildren(logicalNot);
   ((LogicalNot)logicalNot).Type = this.platformType.SystemBoolean;
 }
Beispiel #26
0
 private HLLocation ProcessLogicalNotExpression(ILogicalNot pExpression)
 {
     HLLocation locationOperand = ProcessExpression(pExpression.Operand);
     HLLocation locationTemporary = HLTemporaryLocation.Create(CreateTemporary(HLDomain.GetOrCreateType(pExpression.Type)));
     mCurrentBlock.EmitBitwiseXor(locationTemporary, locationOperand, HLBooleanLiteralLocation.Create(true));
     return locationTemporary;
 }
Beispiel #27
0
 /// <summary>
 /// Performs some computation with the given logical not expression.
 /// </summary>
 /// <param name="logicalNot"></param>
 public virtual void Visit(ILogicalNot logicalNot)
 {
 }
Beispiel #28
0
    /// <summary>
    /// Returns a shallow copy of the given logical not expression.
    /// </summary>
    /// <param name="logicalNot"></param>
    public LogicalNot Copy(ILogicalNot logicalNot) {
      Contract.Requires(logicalNot != null);
      Contract.Ensures(Contract.Result<LogicalNot>() != null);

      return new LogicalNot(logicalNot);
    }
Beispiel #29
0
 /// <summary>
 /// Traverses the children of the logical not expression.
 /// </summary>
 public virtual void TraverseChildren(ILogicalNot logicalNot)
 {
     Contract.Requires(logicalNot != null);
       this.TraverseChildren((IUnaryOperation)logicalNot);
 }
Beispiel #30
0
    /// <summary>
    /// Returns a deep copy of the given logical not expression.
    /// </summary>
    /// <param name="logicalNot"></param>
    public LogicalNot Copy(ILogicalNot logicalNot) {
      Contract.Requires(logicalNot != null);
      Contract.Ensures(Contract.Result<LogicalNot>() != null);

      var mutableCopy = this.shallowCopier.Copy(logicalNot);
      this.CopyChildren((UnaryOperation)mutableCopy);
      return mutableCopy;
    }
Beispiel #31
0
 /// <summary>
 /// Performs some computation with the given logical not expression.
 /// </summary>
 /// <param name="logicalNot"></param>
 public virtual void Visit(ILogicalNot logicalNot)
 {
     this.Visit((IUnaryOperation)logicalNot);
 }
 /// <summary>
 /// Performs some computation with the given logical not expression.
 /// </summary>
 /// <param name="logicalNot"></param>
 public virtual void Visit(ILogicalNot logicalNot)
 {
 }
Beispiel #33
0
 public void Visit(ILogicalNot logicalNot)
 {
     throw new NotImplementedException();
 }
Beispiel #34
0
 /// <summary>
 /// Visits the specified logical not.
 /// </summary>
 /// <param name="logicalNot">The logical not.</param>
 public override void Visit(ILogicalNot logicalNot)
 {
     LogicalNot mutableLogicalNot = new LogicalNot(logicalNot);
     this.resultExpression = this.myCodeCopier.DeepCopy(mutableLogicalNot);
 }
Beispiel #35
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="logicalNot"></param>
 public LogicalNot(ILogicalNot logicalNot)
     : base(logicalNot)
 {
 }
Beispiel #36
0
 /// <summary>
 /// Returns a deep copy of the given logical not expression.
 /// </summary>
 /// <param name="logicalNot"></param>
 public LogicalNot Copy(ILogicalNot logicalNot)
 {
     var mutableCopy = this.shallowCopier.Copy(logicalNot);
       this.CopyChildren((UnaryOperation)mutableCopy);
       return mutableCopy;
 }
    public override void TraverseChildren(ILogicalNot logicalNot) {
      var needsParen = LowerPrecedenceThanParentExpression(logicalNot);
      var savedCurrentPrecedence = this.currentPrecedence;
      this.currentPrecedence = this.Precedence(logicalNot);

      if (needsParen) this.sourceEmitterOutput.Write("(");
      this.sourceEmitterOutput.Write("!");
      this.Traverse(logicalNot.Operand);
      if (needsParen) this.sourceEmitterOutput.Write(")");

      this.currentPrecedence = savedCurrentPrecedence;
    }
Beispiel #38
0
 /// <summary>
 /// Returns a shallow copy of the given logical not expression.
 /// </summary>
 /// <param name="logicalNot"></param>
 public LogicalNot Copy(ILogicalNot logicalNot)
 {
     return new LogicalNot(logicalNot);
 }
Beispiel #39
0
 public override void TraverseChildren(ILogicalNot logicalNot)
 {
     MethodEnter(logicalNot);
     base.TraverseChildren(logicalNot);
     MethodExit();
 }
Beispiel #40
0
 /// <summary>
 /// Visits the specified logical not.
 /// </summary>
 /// <param name="logicalNot">The logical not.</param>
 public override void Visit(ILogicalNot logicalNot)
 {
     LogicalNot mutableLogicalNot = logicalNot as LogicalNot;
     if (alwaysMakeACopy || mutableLogicalNot == null) mutableLogicalNot = new LogicalNot(logicalNot);
     this.resultExpression = this.myCodeMutator.Visit(mutableLogicalNot);
 }