public override void TraverseChildren(IAssertStatement assertStatement)
 {
     Bpl.Expr conditionExpr = ExpressionFor(assertStatement.Condition);
     Bpl.Type conditionType = this.sink.CciTypeToBoogie(assertStatement.Condition.Type);
     if (conditionType == this.sink.Heap.RefType)
     {
         conditionExpr = Bpl.Expr.Binary(Bpl.BinaryOperator.Opcode.Neq, conditionExpr, Bpl.Expr.Ident(this.sink.Heap.NullRef));
     }
     else if (conditionType == Bpl.Type.Int)
     {
         conditionExpr = Bpl.Expr.Binary(Bpl.BinaryOperator.Opcode.Neq, conditionExpr, Bpl.Expr.Literal(0));
     }
     else
     {
         System.Diagnostics.Debug.Assert(conditionType == Bpl.Type.Bool);
     }
     if (this.sink.Options.getMeHere)
     {
         StmtBuilder.Add(new Bpl.AssumeCmd(assertStatement.Token(), conditionExpr));
     }
     else
     {
         StmtBuilder.Add(new Bpl.AssertCmd(assertStatement.Token(), conditionExpr));
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Allocates a copy of a statement that asserts that a condition must always be true when execution reaches it. For example the assert statement of Spec#.
 /// </summary>
 /// <param name="assertStatement"></param>
 public AssertStatement(IAssertStatement assertStatement)
   : base(assertStatement) {
   this.condition = assertStatement.Condition;
   this.description = assertStatement.Description;
   this.conditionAsText = assertStatement.OriginalSource;
   this.hasBeenVerified = assertStatement.HasBeenVerified;
 }
 public override void Visit(IAssertStatement assertStatement)
 {
     if (Process(assertStatement))
     {
         visitor.Visit(assertStatement);
     }
     base.Visit(assertStatement);
 }
Esempio n. 4
0
 public override void TraverseChildren(IAssertStatement assertStatement) {
   this.PrintToken(CSharpToken.Indent);
   sourceEmitterOutput.Write("CodeContract.Assert(");
   this.Traverse(assertStatement.Condition);
   if (assertStatement.Description != null) {
     sourceEmitterOutput.Write(",");
     this.Traverse(assertStatement.Description);
   }
   sourceEmitterOutput.WriteLine(");");
 }
Esempio n. 5
0
 public override void TraverseChildren(IAssertStatement assertStatement)
 {
     this.PrintToken(VBToken.Indent);
     sourceEmitterOutput.Write("CodeContract.Assert(");
     this.Traverse(assertStatement.Condition);
     if (assertStatement.Description != null)
     {
         sourceEmitterOutput.Write(",");
         this.Traverse(assertStatement.Description);
     }
     sourceEmitterOutput.WriteLine(");");
 }
Esempio n. 6
0
        /// <summary>
        ///     Converts the assert statement into a call to Contract.Assert
        /// </summary>
        public override IStatement Rewrite(IAssertStatement assertStatement)
        {
            var methodCall = new MethodCall
            {
                Arguments =
                    new List <IExpression>
                {
                    Rewrite(assertStatement.Condition),
                    assertStatement.Description ?? new CompileTimeConstant {
                        Type = host.PlatformType.SystemString, Value = "Assert"
                    }
                },
                IsStaticCall = true,
                MethodToCall = AssertReference,
                Type         = systemVoid,
                Locations    = new List <ILocation>(assertStatement.Locations)
            };
            var es = new ExpressionStatement
            {
                Expression = methodCall
            };

            return(es);
        }
 public override void TraverseChildren(IAssertStatement assertStatement) {
   Bpl.Expr conditionExpr = ExpressionFor(assertStatement.Condition);
   Bpl.Type conditionType = this.sink.CciTypeToBoogie(assertStatement.Condition.Type);
   if (conditionType == this.sink.Heap.RefType) {
     conditionExpr = Bpl.Expr.Binary(Bpl.BinaryOperator.Opcode.Neq, conditionExpr, Bpl.Expr.Ident(this.sink.Heap.NullRef));
   }
   else if (conditionType == Bpl.Type.Int) {
     conditionExpr = Bpl.Expr.Binary(Bpl.BinaryOperator.Opcode.Neq, conditionExpr, Bpl.Expr.Literal(0));
   }
   else {
     System.Diagnostics.Debug.Assert(conditionType == Bpl.Type.Bool);
   }
   if (this.sink.Options.getMeHere) {
     StmtBuilder.Add(new Bpl.AssumeCmd(assertStatement.Token(), conditionExpr));
   } else {
     StmtBuilder.Add(new Bpl.AssertCmd(assertStatement.Token(), conditionExpr));
   }
 }
Esempio n. 8
0
 public void Visit(IAssertStatement assertStatement)
 {
     Contract.Requires(assertStatement != null);
       throw new NotImplementedException();
 }
Esempio n. 9
0
 /// <summary>
 /// Performs some computation with the given assert statement.
 /// </summary>
 /// <param name="assertStatement"></param>
 public virtual void Visit(IAssertStatement assertStatement)
 {
     this.Visit((IStatement)assertStatement);
 }
Esempio n. 10
0
 /// <summary>
 /// Traverses the children of the assert statement.
 /// </summary>
 public virtual void TraverseChildren(IAssertStatement assertStatement)
 {
     Contract.Requires(assertStatement != null);
       this.TraverseChildren((IStatement)assertStatement);
       if (this.StopTraversal) return;
       this.Traverse(assertStatement.Condition);
       if (this.StopTraversal) return;
       if (assertStatement.Description != null)
     this.Traverse(assertStatement.Description);
 }
Esempio n. 11
0
 /// <summary>
 /// Performs some computation with the given assert statement.
 /// </summary>
 /// <param name="assertStatement"></param>
 public virtual void Visit(IAssertStatement assertStatement)
 {
 }
Esempio n. 12
0
 public virtual void onASTElement(IAssertStatement assertStatement)
 {
 }
Esempio n. 13
0
    /// <summary>
    /// Returns a deep copy of the given assert statement.
    /// </summary>
    /// <param name="assertStatement"></param>
    public AssertStatement Copy(IAssertStatement assertStatement) {
      Contract.Requires(assertStatement != null);
      Contract.Ensures(Contract.Result<AssertStatement>() != null);

      var mutableCopy = this.shallowCopier.Copy(assertStatement);
      mutableCopy.Condition = this.Copy(mutableCopy.Condition);
      if (mutableCopy.Description != null)
        mutableCopy.Description = this.Copy(mutableCopy.Description);
      return mutableCopy;
    }
Esempio n. 14
0
 public void Visit(IAssertStatement assertStatement)
 {
     this.result = this.rewriter.Rewrite(assertStatement);
 }
 /// <summary>
 /// Rewrites the given assert statement.
 /// </summary>
 /// <param name="assertStatement"></param>
 public virtual IStatement Rewrite(IAssertStatement assertStatement)
 {
     return assertStatement;
 }
Esempio n. 16
0
 public override void Visit(IAssertStatement assertStatement)
 {
     allElements.Add(new InvokInfo(Traverser, "IAssertStatement", assertStatement));
 }
Esempio n. 17
0
 /// <summary>
 /// Throws an exception when executed: IAssertStatement nodes
 /// must be replaced before converting the Code Model to IL.
 /// </summary>
 public override void TraverseChildren(IAssertStatement assertStatement)
 {
     Contract.Assume(false, "IAssertStatement nodes must be replaced before trying to convert the Code Model to IL.");
 }
 public override void Visit(IAssertStatement assertStatement)
 {
     if(Process(assertStatement)){visitor.Visit(assertStatement);}
     base.Visit(assertStatement);
 }
Esempio n. 19
0
 /// <summary>
 /// Returns a shallow copy of the given assert statement.
 /// </summary>
 /// <param name="assertStatement"></param>
 public AssertStatement Copy(IAssertStatement assertStatement)
 {
     return new AssertStatement(assertStatement);
 }
Esempio n. 20
0
 public void Visit(IAssertStatement assertStatement)
 {
     this.result = this.copier.Copy(assertStatement);
 }
Esempio n. 21
0
    /// <summary>
    /// Returns a shallow copy of the given assert statement.
    /// </summary>
    /// <param name="assertStatement"></param>
    public AssertStatement Copy(IAssertStatement assertStatement) {
      Contract.Requires(assertStatement != null);
      Contract.Ensures(Contract.Result<AssertStatement>() != null);

      return new AssertStatement(assertStatement);
    }
        public override void TraverseChildren(IAssertStatement assertStatement)
{ MethodEnter(assertStatement);
            base.TraverseChildren(assertStatement);
     MethodExit();   }
 /// <summary>
 /// Performs some computation with the given assert statement.
 /// </summary>
 /// <param name="assertStatement"></param>
 public virtual void Visit(IAssertStatement assertStatement)
 {
 }
Esempio n. 24
0
 /// <summary>
 /// Traverses the assert statement.
 /// </summary>
 public void Traverse(IAssertStatement assertStatement)
 {
     Contract.Requires(assertStatement != null);
       if (this.preorderVisitor != null) this.preorderVisitor.Visit(assertStatement);
       if (this.StopTraversal) return;
       this.TraverseChildren(assertStatement);
       if (this.StopTraversal) return;
       if (this.postorderVisitor != null) this.postorderVisitor.Visit(assertStatement);
 }
Esempio n. 25
0
 /// <summary>
 /// Rewrites the given assert statement.
 /// </summary>
 /// <param name="assertStatement"></param>
 public virtual IStatement Rewrite(IAssertStatement assertStatement)
 {
     var mutableAssertStatement = assertStatement as AssertStatement;
       if (mutableAssertStatement == null) return assertStatement;
       this.RewriteChildren(mutableAssertStatement);
       return mutableAssertStatement;
 }
Esempio n. 26
0
 public void Visit(IAssertStatement assertStatement)
 {
     this.traverser.Traverse(assertStatement);
 }
Esempio n. 27
0
 public virtual void onASTElement(IAssertStatement assertStatement) { }
Esempio n. 28
0
 //^ ensures this.path.Count == old(this.path.Count);
 /// <summary>
 /// Traverses the given assert statement.
 /// </summary>
 /// <param name="assertStatement"></param>
 public virtual void Visit(IAssertStatement assertStatement)
 {
     if (this.stopTraversal) return;
       //^ int oldCount = this.path.Count;
       this.path.Push(assertStatement);
       this.Visit(assertStatement.Condition);
       if (assertStatement.Description != null)
     this.Visit(assertStatement.Description);
       //^ assume this.path.Count == oldCount+1; //True because all of the virtual methods of this class promise not to decrease this.path.Count.
       this.path.Pop();
 }
Esempio n. 29
0
 /// <summary>
 /// Visits the specified assert statement.
 /// </summary>
 /// <param name="assertStatement">The assert statement.</param>
 public override void Visit(IAssertStatement assertStatement)
 {
     AssertStatement mutableAssertStatement = assertStatement as AssertStatement;
     if (alwaysMakeACopy || mutableAssertStatement == null) mutableAssertStatement = new AssertStatement(assertStatement);
     this.resultStatement = this.myCodeMutator.Visit(mutableAssertStatement);
 }
Esempio n. 30
0
 public void Visit(IAssertStatement assertStatement)
 {
     throw new NotImplementedException();
 }
Esempio n. 31
0
 /// <summary>
 /// Returns a deep copy of the given assert statement.
 /// </summary>
 /// <param name="assertStatement"></param>
 public AssertStatement Copy(IAssertStatement assertStatement)
 {
     var mutableCopy = this.shallowCopier.Copy(assertStatement);
       mutableCopy.Condition = this.Copy(mutableCopy.Condition);
       if (mutableCopy.Description != null)
     mutableCopy.Description = this.Copy(mutableCopy.Description);
       return mutableCopy;
 }
Esempio n. 32
0
 /// <summary>
 /// Visits the specified assert statement.
 /// </summary>
 /// <param name="assertStatement">The assert statement.</param>
 public override void Visit(IAssertStatement assertStatement)
 {
     AssertStatement mutableAssertStatement = new AssertStatement(assertStatement);
     this.resultStatement = this.myCodeCopier.DeepCopy(mutableAssertStatement);
 }
Esempio n. 33
0
 /// <summary>
 /// Converts the assert statement into a call to Contract.Assert
 /// </summary>
 public override IStatement Rewrite(IAssertStatement assertStatement) {
   var methodCall = new MethodCall() {
     Arguments = new List<IExpression> { assertStatement.Condition, },
     IsStaticCall = true,
     MethodToCall = this.contractProvider.ContractMethods.Assert,
     Type = systemVoid,
     Locations = new List<ILocation>(assertStatement.Locations),
   };
   ExpressionStatement es = new ExpressionStatement() {
     Expression = methodCall
   };
   return es;
 }
Esempio n. 34
0
 public override void TraverseChildren(IAssertStatement assertStatement)
 {
     MethodEnter(assertStatement);
     base.TraverseChildren(assertStatement);
     MethodExit();
 }
Esempio n. 35
0
 /// <summary>
 /// Visits the specified assert statement.
 /// </summary>
 /// <param name="assertStatement">The assert statement.</param>
 public override void Visit(IAssertStatement assertStatement)
 {
     AssertStatement mutableAssertStatement = assertStatement as AssertStatement;
     if (mutableAssertStatement == null) {
       this.resultStatement = assertStatement;
       return;
     }
     this.resultStatement = this.myCodeMutator.Visit(mutableAssertStatement);
 }