public BoogieExpr GetSumExpr(VariableDeclaration decl, BoogieExpr varExpr) { BoogieIdentifierExpr sumIdent = new BoogieIdentifierExpr(GetSumName(decl)); BoogieMapSelect sumSelect = new BoogieMapSelect(sumIdent, varExpr); return(sumSelect); }
public BoogieMapUpdate(BoogieExpr baseExpr, List <BoogieExpr> arguments, BoogieExpr value) { Debug.Assert(arguments != null && arguments.Count > 0); this.BaseExpr = baseExpr; this.Arguments = arguments; this.Value = value; }
public BoogieExpr GetLength(VariableDeclaration varDecl, BoogieExpr receiver) { if (context.TranslateFlags.UseMultiDim && context.Analysis.Alias.getResults().Contains(varDecl)) { BoogieExpr curExpr = receiver; int lvl = -1; List <BoogieExpr> keys = new List <BoogieExpr>(); while (curExpr is BoogieMapSelect sel) { curExpr = sel.BaseExpr; keys.Insert(0, sel.Arguments[0]); lvl++; } string lenName = GetMultiDimLengthName(varDecl, lvl); BoogieExpr lenExpr = new BoogieIdentifierExpr(lenName); foreach (BoogieExpr key in keys) { lenExpr = new BoogieMapSelect(lenExpr, key); } return(lenExpr); } return(new BoogieMapSelect(new BoogieIdentifierExpr("Length"), receiver)); }
public BoogieMapUpdate(BoogieExpr baseExpr, BoogieExpr indexExpr, BoogieExpr value) { this.BaseExpr = baseExpr;; this.Arguments = new List <BoogieExpr>(); this.Arguments.Add(indexExpr); this.Value = value; }
private BoogieWhileCmd GenerateWhileLoop(ContractDefinition contract, Dictionary <int, BoogieExpr> houdiniVarMap, List <BoogieVariable> localVars) { // havoc all local variables except `this' BoogieStmtList body = GenerateHavocBlock(contract, localVars); // generate the choice block body.AddStatement(GenerateChoiceBlock(contract)); // generate candidate invariants for Houdini List <BoogiePredicateCmd> candidateInvs = new List <BoogiePredicateCmd>(); foreach (int id in houdiniVarMap.Keys) { BoogieIdentifierExpr houdiniVar = new BoogieIdentifierExpr(GetHoudiniVarName(id, contract)); BoogieExpr candidateInv = houdiniVarMap[id]; BoogieExpr invExpr = new BoogieBinaryOperation(BoogieBinaryOperation.Opcode.IMP, houdiniVar, candidateInv); BoogieLoopInvCmd invCmd = new BoogieLoopInvCmd(invExpr); candidateInvs.Add(invCmd); } // add the contract invariant if present if (contractInvariants.ContainsKey(contract.Name)) { contractInvariants[contract.Name].ForEach(x => candidateInvs.Add(new BoogieLoopInvCmd(x))); } return(new BoogieWhileCmd(new BoogieLiteralExpr(true), body, candidateInvs)); }
public BoogieWhileCmd(BoogieExpr guard, BoogieStmtList body, List <BoogieExpr> invariants = null) { this.Guard = guard; this.Body = body; this.Invariants = invariants == null ? new List <BoogiePredicateCmd>() : invariants.Select(x => new BoogieLoopInvCmd(x)).ToList <BoogiePredicateCmd>(); }
public BoogieExpr GetLength(Expression solExpr, BoogieExpr receiver) { VariableDeclaration decl = getDecl(solExpr); //this can happen in the case of newExpression if (decl == null) { return(new BoogieMapSelect(new BoogieIdentifierExpr("Length"), receiver)); } return(GetLength(decl, receiver)); }
// returns a map from integer id to an atomic Boogie predicate public static Dictionary <int, BoogieExpr> GenerateHoudiniVarMapping(ContractDefinition contract, TranslatorContext context) { Dictionary <int, BoogieExpr> ret = new Dictionary <int, BoogieExpr>(); HashSet <VariableDeclaration> stateVars = context.GetVisibleStateVarsByContract(contract); // collect all state variables of type address List <VariableDeclaration> addressVariables = new List <VariableDeclaration>(); foreach (VariableDeclaration stateVar in stateVars) { if (stateVar.TypeName is ElementaryTypeName elementaryType) { if (elementaryType.TypeDescriptions.TypeString.Equals("address") || elementaryType.TypeDescriptions.TypeString.Equals("address payable")) { addressVariables.Add(stateVar); } } } int id = 0; // equaility and disequality to null foreach (VariableDeclaration addressVar in addressVariables) { BoogieExpr lhs = GetBoogieExprOfStateVar(addressVar, context); BoogieExpr rhs = new BoogieIdentifierExpr("null"); BoogieExpr equality = new BoogieBinaryOperation(BoogieBinaryOperation.Opcode.EQ, lhs, rhs); ret[++id] = equality; BoogieExpr disequality = new BoogieBinaryOperation(BoogieBinaryOperation.Opcode.NEQ, lhs, rhs); ret[++id] = disequality; } // pair-wise equality and disequality for (int i = 0; i < addressVariables.Count; ++i) { BoogieExpr lhs = GetBoogieExprOfStateVar(addressVariables[i], context); for (int j = i + 1; j < addressVariables.Count; ++j) { BoogieExpr rhs = GetBoogieExprOfStateVar(addressVariables[j], context); BoogieExpr equality = new BoogieBinaryOperation(BoogieBinaryOperation.Opcode.EQ, lhs, rhs); ret[++id] = equality; BoogieExpr disequality = new BoogieBinaryOperation(BoogieBinaryOperation.Opcode.NEQ, lhs, rhs); ret[++id] = disequality; } } // PrintHoudiniCandidateMap(ret); return(ret); }
public static BoogieFunction GenerateMultiDimZeroFunction(VariableDeclaration decl) { TypeName curType = decl.TypeName; List <BoogieType> boogieType = new List <BoogieType>(); while (curType is Mapping || curType is ArrayTypeName) { if (curType is Mapping map) { boogieType.Insert(0, TransUtils.GetBoogieTypeFromSolidityTypeName(map.KeyType)); curType = map.ValueType; } else if (curType is ArrayTypeName arr) { boogieType.Insert(0, BoogieType.Int); curType = arr.BaseType; } } BoogieType valType = TransUtils.GetBoogieTypeFromSolidityTypeName(curType); BoogieExpr boogieInit = TransUtils.GetDefaultVal(valType); string smtType = GetSmtType(valType); string smtInit = boogieInit.ToString().Equals("null") ? "0" : boogieInit.ToString(); BoogieType mapType = valType; string fnName = $"{valType.ToString()}Arr"; foreach (BoogieType type in boogieType) { smtType = $"(Array {GetSmtType(type)} {smtType})"; mapType = new BoogieMapType(type, mapType); smtInit = $"((as const {smtType}) {smtInit})"; fnName = $"{type.ToString()}{fnName}"; } var outVar = new BoogieFormalParam(new BoogieTypedIdent("ret", mapType)); var smtDefinedAttr = new BoogieAttribute("smtdefined", $"\"{smtInit}\""); return(new BoogieFunction($"zero{fnName}", new List <BoogieVariable>(), new List <BoogieVariable>() { outVar }, new List <BoogieAttribute>() { smtDefinedAttr })); }
public static BoogieExpr GetCallExprForInit(BoogieType curType, BoogieExpr initExpr) { if (!(curType is BoogieMapType)) { return(initExpr); } string fnName = "init"; while (curType is BoogieMapType map) { fnName = $"{fnName}{String.Join("", map.Arguments)}"; curType = map.Result; } fnName = $"{fnName}{curType}Arr"; return(new BoogieFuncCallExpr(fnName, new List <BoogieExpr>() { initExpr })); }
public static BoogieFunction GenerateMultiDimZeroFunction(BoogieType keyType, BoogieType valType) { BoogieExpr boogieInit = TransUtils.GetDefaultVal(valType); string smtType = GetSmtType(valType); BoogieType mapType = new BoogieMapType(keyType, valType); string fnName = $"zero{keyType.ToString()}{valType.ToString()}Arr"; string smtInit = boogieInit.ToString().Equals("null") ? "0" : boogieInit.ToString(); smtInit = $"((as const (Array {GetSmtType(keyType)} {smtType})) {smtInit})"; var outVar = new BoogieFormalParam(new BoogieTypedIdent("ret", mapType)); var smtDefinedAttr = new BoogieAttribute("smtdefined", $"\"{smtInit}\""); return(new BoogieFunction(fnName, new List <BoogieVariable>(), new List <BoogieVariable>() { outVar }, new List <BoogieAttribute>() { smtDefinedAttr })); }
public BoogieITE(BoogieExpr guard, BoogieExpr thenExpr, BoogieExpr elseExpr) { this.Guard = guard; this.ThenExpr = thenExpr; this.ElseExpr = elseExpr; }
public BoogieBinaryOperation(Opcode op, BoogieExpr lhs, BoogieExpr rhs) { this.Op = op; this.Lhs = lhs; this.Rhs = rhs; }
public BoogieUnaryOperation(Opcode op, BoogieExpr expr) { this.Op = op; this.Expr = expr; }
public BoogieMapSelect(BoogieExpr baseExpr, BoogieExpr indexExpr) { this.BaseExpr = baseExpr;; this.Arguments = new List <BoogieExpr>(); this.Arguments.Add(indexExpr); }
private BoogieImplementation CreateSendFail() { // send__fail(from: Ref, to: Ref, amt: uint) returns (success: boolean) // { // var __exception: bool; // havoc __exception; // // if(__exception) // { // //save current temps // if ((__tmp__Balance[from]) >= (amt)) { // call FallbackDispatch__fail(from, to, amt); // } // // success := false; // assume(__revert); // // // restore old temps // revert := false; // } // else { // if ((__tmp__Balance[from]) >= (amt)) { // call FallbackDispatch__fail(from, to, amt); // success := true; // } else { // success := false; // } // // assume(!(__revert)); // } // } List <BoogieVariable> inParams = new List <BoogieVariable>() { new BoogieFormalParam(new BoogieTypedIdent("from", BoogieType.Ref)), new BoogieFormalParam(new BoogieTypedIdent("to", BoogieType.Ref)), new BoogieFormalParam(new BoogieTypedIdent("amount", BoogieType.Int)) }; List <BoogieVariable> outParms = new List <BoogieVariable>() { new BoogieFormalParam(new BoogieTypedIdent("success", BoogieType.Bool)) }; List <BoogieVariable> locals = new List <BoogieVariable>() { new BoogieLocalVariable(new BoogieTypedIdent("__exception", BoogieType.Bool)) }; var fromId = new BoogieIdentifierExpr("from"); var toId = new BoogieIdentifierExpr("to"); var amtId = new BoogieIdentifierExpr("amount"); var successId = new BoogieIdentifierExpr("success"); var revertId = new BoogieIdentifierExpr("revert"); var exceptionId = new BoogieIdentifierExpr("__exception"); var body = new BoogieStmtList(); body.AddStatement(new BoogieHavocCmd(exceptionId)); var checkTmpBalGuard = new BoogieBinaryOperation(BoogieBinaryOperation.Opcode.GE, new BoogieMapSelect(new BoogieIdentifierExpr(shadowGlobals["Balance"].Name), fromId), amtId); var callFailDispatch = new BoogieCallCmd("FallbackDispatch__fail", new List <BoogieExpr>() { fromId, toId, amtId }, null); var exceptionCase = new BoogieStmtList(); foreach (var shadowGlobalPair in shadowGlobals) { var shadowName = shadowGlobalPair.Value.Name; var tmpLocalName = "__snap_" + shadowName; locals.Add(new BoogieLocalVariable(new BoogieTypedIdent(tmpLocalName, shadowGlobalPair.Value.TypedIdent.Type))); exceptionCase.AddStatement(new BoogieAssignCmd(new BoogieIdentifierExpr(tmpLocalName), new BoogieIdentifierExpr(shadowName))); } BoogieStmtList exStmtList = new BoogieStmtList(); exStmtList.AddStatement(new BoogieCommentCmd("---- Logic for payable function START ")); var exBalFrom = new BoogieMapSelect(new BoogieIdentifierExpr(shadowGlobals["Balance"].Name), new BoogieIdentifierExpr(inParams[0].Name)); var exBalTo = new BoogieMapSelect(new BoogieIdentifierExpr(shadowGlobals["Balance"].Name), new BoogieIdentifierExpr(inParams[1].Name)); var exMsgVal = new BoogieIdentifierExpr(inParams[2].Name); //balance[msg.sender] = balance[msg.sender] - msg.value exStmtList.AddStatement(new BoogieAssignCmd(exBalFrom, new BoogieBinaryOperation(BoogieBinaryOperation.Opcode.SUB, exBalFrom, exMsgVal))); //balance[this] = balance[this] + msg.value exStmtList.AddStatement(new BoogieAssignCmd(exBalTo, new BoogieBinaryOperation(BoogieBinaryOperation.Opcode.ADD, exBalTo, exMsgVal))); exStmtList.AddStatement(new BoogieCommentCmd("---- Logic for payable function END ")); exStmtList.AddStatement(callFailDispatch); exceptionCase.AddStatement(new BoogieIfCmd(checkTmpBalGuard, exStmtList, null)); exceptionCase.AddStatement(new BoogieAssignCmd(successId, new BoogieLiteralExpr(false))); BoogieExpr failAssumePred = revertId; if (context.TranslateFlags.InstrumentGas) { failAssumePred = new BoogieBinaryOperation(BoogieBinaryOperation.Opcode.OR, failAssumePred, new BoogieBinaryOperation(BoogieBinaryOperation.Opcode.LT, new BoogieIdentifierExpr("gas"), new BoogieLiteralExpr(0))); } exceptionCase.AddStatement(new BoogieAssumeCmd(failAssumePred)); foreach (var shadowGlobalPair in shadowGlobals) { var shadowName = shadowGlobalPair.Value.Name; var tmpLocalName = "__snap_" + shadowName; exceptionCase.AddStatement(new BoogieAssignCmd(new BoogieIdentifierExpr(shadowName), new BoogieIdentifierExpr(tmpLocalName))); } exceptionCase.AddStatement(new BoogieAssignCmd(revertId, new BoogieLiteralExpr(false))); var successCase = new BoogieStmtList(); var successDispatchCall = new BoogieStmtList(); successDispatchCall.AddStatement(new BoogieCommentCmd("---- Logic for payable function START ")); //balance[msg.sender] = balance[msg.sender] - msg.value successDispatchCall.AddStatement(new BoogieAssignCmd(exBalFrom, new BoogieBinaryOperation(BoogieBinaryOperation.Opcode.SUB, exBalFrom, exMsgVal))); //balance[this] = balance[this] + msg.value successDispatchCall.AddStatement(new BoogieAssignCmd(exBalTo, new BoogieBinaryOperation(BoogieBinaryOperation.Opcode.ADD, exBalTo, exMsgVal))); successDispatchCall.AddStatement(new BoogieCommentCmd("---- Logic for payable function END ")); successDispatchCall.AddStatement(callFailDispatch); successDispatchCall.AddStatement(new BoogieAssignCmd(successId, new BoogieLiteralExpr(true))); successCase.AddStatement(new BoogieIfCmd(checkTmpBalGuard, successDispatchCall, BoogieStmtList.MakeSingletonStmtList(new BoogieAssignCmd(successId, new BoogieLiteralExpr(false))))); BoogieExpr successAssumePred = new BoogieUnaryOperation(BoogieUnaryOperation.Opcode.NOT, revertId); if (context.TranslateFlags.InstrumentGas) { successAssumePred = new BoogieBinaryOperation(BoogieBinaryOperation.Opcode.AND, successAssumePred, new BoogieBinaryOperation(BoogieBinaryOperation.Opcode.GE, new BoogieIdentifierExpr("gas"), new BoogieLiteralExpr(0))); } successCase.AddStatement(new BoogieAssumeCmd(successAssumePred)); body.AddStatement(new BoogieIfCmd(exceptionId, exceptionCase, successCase)); return(new BoogieImplementation("send__fail", inParams, outParms, locals, body)); }
public BoogieReturnExprCmd(BoogieExpr expr) { this.Expr = expr; throw new NotSupportedException("return " + expr.ToString()); }
public BoogieAssumeCmd(BoogieExpr expr) { this.Expr = expr; }
public BoogieAssignCmd(BoogieExpr lhs, BoogieExpr rhs) { this.Lhs = lhs; this.Rhs = rhs; }
public BoogieQuantifiedExpr(bool isForall, List <BoogieIdentifierExpr> qvars, List <BoogieType> qvarTypes, BoogieExpr bodyExpr, List <BoogieExpr> trigger = null) { this.IsForall = isForall; this.QVars = qvars; this.QVarTypes = qvarTypes; Debug.Assert(QVars.Count != 0, "Need at least one bound variable"); Debug.Assert(QVarTypes.Count == QVars.Count, "Need at least one bound variable"); this.BodyExpr = bodyExpr; this.Trigger = trigger; }
private BoogieImplementation CreateSendSucess() { // send__success(from: Ref, to: Ref, amt: uint) returns (success: boolean) // { // var __exception: bool; // havoc __exception; // // if(__exception) // { // //set tmps // if ((__tmp__Balance[from]) >= (amt)) { // call FallbackDispatch__fail(from, to, amt); // } // // success := false; // assume(__revert); // // revert := false; // } // else { // if ((Balance[from]) >= (amt)) { // call FallbackDispatch__success(from, to, amt); // success := true; // } else { // success := false; // } // // assume(!(__revert)); // } // } List <BoogieVariable> inParams = new List <BoogieVariable>() { new BoogieFormalParam(new BoogieTypedIdent("from", BoogieType.Ref)), new BoogieFormalParam(new BoogieTypedIdent("to", BoogieType.Ref)), new BoogieFormalParam(new BoogieTypedIdent("amount", BoogieType.Int)) }; List <BoogieVariable> outParms = new List <BoogieVariable>() { new BoogieFormalParam(new BoogieTypedIdent("success", BoogieType.Bool)) }; List <BoogieVariable> locals = new List <BoogieVariable>() { new BoogieLocalVariable(new BoogieTypedIdent("__exception", BoogieType.Bool)) }; var fromId = new BoogieIdentifierExpr("from"); var toId = new BoogieIdentifierExpr("to"); var amtId = new BoogieIdentifierExpr("amount"); var successId = new BoogieIdentifierExpr("success"); var revertId = new BoogieIdentifierExpr("revert"); var exceptionId = new BoogieIdentifierExpr("__exception"); BoogieStmtList body = new BoogieStmtList(); body.AddStatement(new BoogieHavocCmd(exceptionId)); BoogieStmtList exceptionCase = new BoogieStmtList(); foreach (var shadowGlobalPair in shadowGlobals) { string origVarName = shadowGlobalPair.Key; string shadowName = shadowGlobalPair.Value.Name; exceptionCase.AddStatement(new BoogieAssignCmd(new BoogieIdentifierExpr(shadowName), new BoogieIdentifierExpr(origVarName))); } var checkTmpBalGuard = new BoogieBinaryOperation(BoogieBinaryOperation.Opcode.GE, new BoogieMapSelect(new BoogieIdentifierExpr(shadowGlobals["Balance"].Name), fromId), amtId); var callFailDispatch = new BoogieCallCmd("FallbackDispatch__fail", new List <BoogieExpr>() { fromId, toId, amtId }, null); exceptionCase.AddStatement(new BoogieIfCmd(checkTmpBalGuard, BoogieStmtList.MakeSingletonStmtList(callFailDispatch), null)); exceptionCase.AddStatement(new BoogieAssignCmd(successId, new BoogieLiteralExpr(false))); BoogieExpr failAssumePred = revertId; if (context.TranslateFlags.InstrumentGas) { failAssumePred = new BoogieBinaryOperation(BoogieBinaryOperation.Opcode.OR, failAssumePred, new BoogieBinaryOperation(BoogieBinaryOperation.Opcode.LT, new BoogieIdentifierExpr("gas"), new BoogieLiteralExpr(0))); } exceptionCase.AddStatement(new BoogieAssumeCmd(failAssumePred)); exceptionCase.AddStatement(new BoogieAssignCmd(revertId, new BoogieLiteralExpr(false))); var successCase = new BoogieStmtList(); var checkBalGuard = new BoogieBinaryOperation(BoogieBinaryOperation.Opcode.GE, new BoogieMapSelect(new BoogieIdentifierExpr("Balance"), fromId), amtId); var successCaseStmts = new BoogieStmtList(); var callSuccessDispatch = new BoogieCallCmd("FallbackDispatch__success", new List <BoogieExpr>() { fromId, toId, amtId }, null); successCaseStmts.AddStatement(callSuccessDispatch); successCaseStmts.AddStatement(new BoogieAssignCmd(successId, new BoogieLiteralExpr(true))); successCase.AddStatement(new BoogieIfCmd(checkBalGuard, successCaseStmts, BoogieStmtList.MakeSingletonStmtList(new BoogieAssignCmd(successId, new BoogieLiteralExpr(false))))); BoogieExpr successAssumePred = new BoogieUnaryOperation(BoogieUnaryOperation.Opcode.NOT, revertId); if (context.TranslateFlags.InstrumentGas) { successAssumePred = new BoogieBinaryOperation(BoogieBinaryOperation.Opcode.AND, successAssumePred, new BoogieBinaryOperation(BoogieBinaryOperation.Opcode.GE, new BoogieIdentifierExpr("gas"), new BoogieLiteralExpr(0))); } successCase.AddStatement(new BoogieAssumeCmd(successAssumePred)); body.AddStatement(new BoogieIfCmd(exceptionId, exceptionCase, successCase)); return(new BoogieImplementation("send__success", inParams, outParms, locals, body)); }
public BoogieExpr GetMemoryMapSelectExpr(VariableDeclaration decl, BoogieType mapKeyType, BoogieType mapValType, BoogieExpr baseExpr, BoogieExpr indexExpr) { string mapName = GetMemoryMapName(decl, mapKeyType, mapValType); BoogieIdentifierExpr mapIdent = new BoogieIdentifierExpr(mapName); BoogieMapSelect mapSelectExpr = new BoogieMapSelect(mapIdent, baseExpr); mapSelectExpr = new BoogieMapSelect(mapSelectExpr, indexExpr); return(mapSelectExpr); }
public BoogieAxiom(BoogieExpr bExpr) { BExpr = bExpr; }
public BoogieIfCmd(BoogieExpr guard, BoogieStmtList thenBody, BoogieStmtList elseBody) { this.Guard = guard; this.ThenBody = thenBody; this.ElseBody = elseBody; }
public BoogieAssertCmd(BoogieExpr expr, List <BoogieAttribute> attributes = null) { this.Expr = expr; this.Attributes = attributes; }
public BoogieWhileCmd(BoogieExpr guard, BoogieStmtList body, List <BoogiePredicateCmd> invariants) { this.Guard = guard; this.Body = body; this.Invariants = invariants; }
public BoogieLoopInvCmd(BoogieExpr expr) { this.Expr = expr; }
public BoogieMapSelect(BoogieExpr baseExpr, List <BoogieExpr> arguments) { Debug.Assert(arguments != null && arguments.Count > 0); this.BaseExpr = baseExpr; this.Arguments = arguments; }
private BoogieExpr dupAndReplaceExpr(BoogieExpr expr, bool isFail, bool inHarness) { List <BoogieExpr> dupAndReplaceExprList(List <BoogieExpr> exprs) { return(exprs.Select(e => dupAndReplaceExpr(e, isFail, inHarness)).ToList()); } if (expr is BoogieIdentifierExpr) { string idName = ((BoogieIdentifierExpr)expr).Name; if (isFail && shadowGlobals.ContainsKey(idName)) { return(new BoogieIdentifierExpr(shadowGlobals[idName].Name)); } return(expr); } if (expr is BoogieMapSelect) { BoogieMapSelect selectExpr = (BoogieMapSelect)expr; return(new BoogieMapSelect(dupAndReplaceExpr(selectExpr.BaseExpr, isFail, inHarness), dupAndReplaceExprList(selectExpr.Arguments))); } if (expr is BoogieMapUpdate) { BoogieMapUpdate updateExpr = (BoogieMapUpdate)expr; return(new BoogieMapUpdate(dupAndReplaceExpr(updateExpr.BaseExpr, isFail, inHarness), dupAndReplaceExprList(updateExpr.Arguments), dupAndReplaceExpr(updateExpr.Value, isFail, inHarness))); } if (expr is BoogieUnaryOperation) { BoogieUnaryOperation unaryOperation = (BoogieUnaryOperation)expr; return(new BoogieUnaryOperation(unaryOperation.Op, dupAndReplaceExpr(unaryOperation.Expr, isFail, inHarness))); } if (expr is BoogieBinaryOperation) { BoogieBinaryOperation binOperation = (BoogieBinaryOperation)expr; return(new BoogieBinaryOperation(binOperation.Op, dupAndReplaceExpr(binOperation.Lhs, isFail, inHarness), dupAndReplaceExpr(binOperation.Rhs, isFail, inHarness))); } if (expr is BoogieITE) { BoogieITE iteExpr = (BoogieITE)expr; return(new BoogieITE(dupAndReplaceExpr(iteExpr.Guard, isFail, inHarness), dupAndReplaceExpr(iteExpr.ThenExpr, isFail, inHarness), dupAndReplaceExpr(iteExpr.ElseExpr, isFail, inHarness))); } if (expr is BoogieQuantifiedExpr) { BoogieQuantifiedExpr quantifiedExpr = (BoogieQuantifiedExpr)expr; return(new BoogieQuantifiedExpr(quantifiedExpr.IsForall, quantifiedExpr.QVars, quantifiedExpr.QVarTypes, dupAndReplaceExpr(quantifiedExpr.BodyExpr, isFail, inHarness), quantifiedExpr.Trigger)); } if (expr is BoogieFuncCallExpr) { BoogieFuncCallExpr callExpr = (BoogieFuncCallExpr)expr; string calledFun = callExpr.Function; // TODO: handle this properly. // if (!isHarnessProcudure(calledFun) && procsWiltImplNames.Contains(calledFun)) // { // if (!inHarness || (!isConstructor(calledFun) && !isPublic(proceduresInProgram[calledFun]))) // calledFun = calledFun + (isFail ? "__fail" : "__success"); // } return(new BoogieFuncCallExpr(calledFun, dupAndReplaceExprList(callExpr.Arguments))); } if (expr is BoogieTupleExpr) { BoogieTupleExpr tupleExpr = (BoogieTupleExpr)expr; return(new BoogieTupleExpr(dupAndReplaceExprList(tupleExpr.Arguments))); } return(expr); }
//return a BoogieExpression public static BoogieExpr GetMemoryMapSelectExpr(BoogieType mapKeyType, BoogieType mapValType, BoogieExpr baseExpr, BoogieExpr indexExpr) { string generateMapName = generateMemoryMapName(mapKeyType, mapValType); BoogieIdentifierExpr mapIdentifier = new BoogieIdentifierExpr(generateMapName); BoogieMapSelect mapSelectExpr = new BoogieMapSelect(mapIdentifier, baseExpr); mapSelectExpr = new BoogieMapSelect(mapSelectExpr, indexExpr); return(mapSelectExpr); }