/// <summary> /// /// </summary> public override void TraverseChildren(IReturnStatement returnStatement) { Bpl.IToken tok = returnStatement.Token(); if (returnStatement.Expression != null) { ExpressionTraverser etrav = this.factory.MakeExpressionTraverser(this.sink, this, this.contractContext); etrav.Traverse(returnStatement.Expression); if (this.sink.ReturnVariable == null || etrav.TranslatedExpressions.Count < 1) { throw new TranslationException(String.Format("{0} returns a value that is not supported by the function", returnStatement.ToString())); } StmtBuilder.Add(Bpl.Cmd.SimpleAssign(tok, new Bpl.IdentifierExpr(tok, this.sink.ReturnVariable), etrav.TranslatedExpressions.Pop())); } // FEEDBACK TODO extract into a method if (PhoneCodeHelper.instance().PhoneFeedbackToggled) { IMethodDefinition methodTranslated = sink.getMethodBeingTranslated(); if (methodTranslated != null && PhoneCodeHelper.instance().isMethodInputHandlerOrFeedbackOverride(methodTranslated) && !PhoneCodeHelper.instance().isMethodIgnoredForFeedback(methodTranslated)) { Bpl.AssertCmd falseAssertion = new Bpl.AssertCmd(Bpl.Token.NoToken, Bpl.LiteralExpr.False); StmtBuilder.Add(falseAssertion); } } StmtBuilder.Add(new Bpl.ReturnCmd(returnStatement.Token())); }
Bpl.Expr ExpressionFor(IExpression expression) { ExpressionTraverser etrav = this.factory.MakeExpressionTraverser(this.sink, this, this.contractContext); etrav.Traverse(expression); Contract.Assert(etrav.TranslatedExpressions.Count == 1); return(etrav.TranslatedExpressions.Pop()); }
/// <inheritdoc /> public override IExpression OnVisit(ExpressionTraverser traverser, IExpression expression) { if (_predicate(expression)) { FoundExpressions.Add(expression); } return(expression); }
/// <inheritdoc /> public override IExpression OnVisit(ExpressionTraverser traverser, IExpression expression) { if (_predicate(expression)) { Found = expression; traverser.Stop(); } return(expression); }
public override void TraverseChildren(IThrowStatement throwStatement) { if (this.sink.Options.modelExceptions == 0) { StmtBuilder.Add(new Bpl.AssumeCmd(throwStatement.Token(), Bpl.Expr.False)); return; } ExpressionTraverser exceptionTraverser = this.factory.MakeExpressionTraverser(this.sink, this, this.contractContext); exceptionTraverser.Traverse(throwStatement.Exception); StmtBuilder.Add(TranslationHelper.BuildAssignCmd(Bpl.Expr.Ident(this.sink.Heap.ExceptionVariable), exceptionTraverser.TranslatedExpressions.Pop())); RaiseException(); }
/// <summary> /// /// </summary> /// <param name="expressionStatement"></param> /// <remarks> TODO: might be wrong for the general case</remarks> public override void TraverseChildren(IExpressionStatement expressionStatement) { var expressionIsOpAssignStatement = false; var binOp = expressionStatement.Expression as IBinaryOperation; if (binOp != null && binOp.LeftOperand is ITargetExpression) { expressionIsOpAssignStatement = true; } ExpressionTraverser etrav = this.factory.MakeExpressionTraverser(this.sink, this, this.contractContext, expressionIsOpAssignStatement); etrav.Traverse(expressionStatement.Expression); }
/// <summary> /// /// </summary> /// <remarks>(mschaef) Works, but still a stub</remarks> /// <param name="conditionalStatement"></param> public override void TraverseChildren(IConditionalStatement conditionalStatement) { StatementTraverser thenTraverser = this.factory.MakeStatementTraverser(this.sink, this.PdbReader, this.contractContext); StatementTraverser elseTraverser = this.factory.MakeStatementTraverser(this.sink, this.PdbReader, this.contractContext); ExpressionTraverser condTraverser = this.factory.MakeExpressionTraverser(this.sink, this, this.contractContext); if (this.sink.Options.instrumentBranches) { var tok = conditionalStatement.Token(); thenTraverser.StmtBuilder.Add( new Bpl.AssumeCmd(tok, Bpl.Expr.True, new Bpl.QKeyValue(Bpl.Token.NoToken, "breadcrumb", new List <object> { Bpl.Expr.Literal(this.sink.UniqueNumberAcrossAllAssemblies) }, null)) ); elseTraverser.StmtBuilder.Add( new Bpl.AssumeCmd(tok, Bpl.Expr.True, new Bpl.QKeyValue(Bpl.Token.NoToken, "breadcrumb", new List <object> { Bpl.Expr.Literal(this.sink.UniqueNumberAcrossAllAssemblies) }, null)) ); } condTraverser.Traverse(conditionalStatement.Condition); thenTraverser.Traverse(conditionalStatement.TrueBranch); elseTraverser.Traverse(conditionalStatement.FalseBranch); Bpl.Expr conditionExpr = condTraverser.TranslatedExpressions.Pop(); Bpl.Type conditionType = this.sink.CciTypeToBoogie(conditionalStatement.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); } Bpl.IfCmd ifcmd = new Bpl.IfCmd(conditionalStatement.Token(), conditionExpr, thenTraverser.StmtBuilder.Collect(conditionalStatement.TrueBranch.Token()), null, elseTraverser.StmtBuilder.Collect(conditionalStatement.FalseBranch.Token()) ); StmtBuilder.Add(ifcmd); }
/// <inheritdoc /> public override IExpression OnVisit(ExpressionTraverser traverser, IExpression expression) { var previous = _last; expression.Meta.Previous = previous; if (previous != null && previous != expression.Meta.Parent) { previous.Meta.Next = expression; } //Stack.AddLast(expression); return(expression); }
public IEnumerable <Bpl.Ensures> getPostconditionTranslation(IMethodContract contract) { ICollection <Bpl.Ensures> translatedPosts = new List <Bpl.Ensures>(); foreach (IPostcondition post in contract.Postconditions) { var stmtTraverser = this.Factory.MakeStatementTraverser(sink, null, true); ExpressionTraverser exptravers = this.Factory.MakeExpressionTraverser(sink, stmtTraverser, true); exptravers.Traverse(post.Condition); // Todo: Deal with Descriptions var ens = new Bpl.Ensures(post.Token(), false, exptravers.TranslatedExpressions.Pop(), ""); translatedPosts.Add(ens); } return(translatedPosts); }
public IEnumerable <Bpl.Requires> getPreconditionTranslation(IMethodContract contract) { ICollection <Bpl.Requires> translatedPres = new List <Bpl.Requires>(); foreach (IPrecondition pre in contract.Preconditions) { var stmtTraverser = this.Factory.MakeStatementTraverser(sink, null, true); ExpressionTraverser exptravers = this.Factory.MakeExpressionTraverser(sink, stmtTraverser, true); exptravers.Traverse(pre.Condition); // TODO // Todo: Deal with Descriptions var req = new Bpl.Requires(pre.Token(), false, exptravers.TranslatedExpressions.Pop(), ""); translatedPres.Add(req); } return(translatedPres); }
public IEnumerable <Bpl.IdentifierExpr> getModifiedIdentifiers(IMethodContract contract) { ICollection <Bpl.IdentifierExpr> modifiedExpr = new List <Bpl.IdentifierExpr>(); foreach (IAddressableExpression mod in contract.ModifiedVariables) { ExpressionTraverser exptravers = this.Factory.MakeExpressionTraverser(sink, null, true); exptravers.Traverse(mod); Bpl.IdentifierExpr idexp = exptravers.TranslatedExpressions.Pop() as Bpl.IdentifierExpr; if (idexp == null) { throw new TranslationException(String.Format("Cannot create IdentifierExpr for Modifyed Variable {0}", mod.ToString())); } modifiedExpr.Add(idexp); } return(modifiedExpr); }
/// <summary> /// /// </summary> public override void TraverseChildren(IReturnStatement returnStatement) { Bpl.IToken tok = returnStatement.Token(); if (returnStatement.Expression != null) { ExpressionTraverser etrav = this.factory.MakeExpressionTraverser(this.sink, this, this.contractContext); etrav.Traverse(returnStatement.Expression); if (this.sink.ReturnVariable == null || etrav.TranslatedExpressions.Count < 1) { throw new TranslationException(String.Format("{0} returns a value that is not supported by the function", returnStatement.ToString())); } var returnExprBpl = etrav.TranslatedExpressions.Pop(); AddRecordCall("<return value>", returnStatement.Expression, returnExprBpl); StmtBuilder.Add(Bpl.Cmd.SimpleAssign(tok, new Bpl.IdentifierExpr(tok, this.sink.ReturnVariable), returnExprBpl)); } StmtBuilder.Add(new Bpl.ReturnCmd(returnStatement.Token())); }
/// <inheritdoc /> public abstract IExpression OnVisit(ExpressionTraverser traverser, IExpression expression);
public override IExpression OnVisit(ExpressionTraverser traverser, IExpression expression) { return(Visit(expression)); }