private bool IsRelevant(Bpl.Cmd cmd) { Bpl.AssertCmd assertCmd = cmd as Bpl.AssertCmd; if (assertCmd == null) { return(false); } string sourceFile = Bpl.QKeyValue.FindStringAttribute(assertCmd.Attributes, "sourceFile"); if (sourceFile == null) { return(false); } string[] ds = sourceFile.Split('\\'); if (sourceFile != fileName && ds[ds.Length - 1] != fileName) { return(false); } int sourceLine = Bpl.QKeyValue.FindIntAttribute(assertCmd.Attributes, "sourceLine", -1); Debug.Assert(sourceLine != -1); if (sourceLine != lineNumber) { return(false); } return(true); }
public virtual Cmd VisitAssertCmd(AssertCmd node) { Contract.Requires(node != null); Contract.Ensures(Contract.Result<Cmd>() != null); node.Expr = this.VisitExpr(node.Expr); return node; }
/// <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())); }
public override Cmd VisitAssertCmd(AssertCmd node) { AssertCmd assertCmd = (AssertCmd) base.VisitAssertCmd(node); if (QKeyValue.FindIntAttribute(assertCmd.Attributes, "phase", int.MaxValue) != phaseNum) assertCmd.Expr = Expr.True; return assertCmd; }
public override Cmd VisitAssertCmd(AssertCmd node) { AssertCmd assertCmd = (AssertCmd) base.VisitAssertCmd(node); if (!moverTypeChecker.absyToLayerNums[node].Contains(layerNum)) assertCmd.Expr = Expr.True; return assertCmd; }
private void AddHoudiniConstant(AssertCmd assertCmd) { Variable houdiniConstant; if (houdini.MatchCandidate(assertCmd.Expr, out houdiniConstant)) houdiniAssertConstants.Add(houdiniConstant); if (houdiniConstant != null && CommandLineOptions.Clo.ExplainHoudini && !constToControl.ContainsKey(houdiniConstant.Name)) { // For each houdini constant c, create two more constants c_pos and c_neg. // Then change the asserted condition (c ==> \phi) to // (c ==> (c_pos && (\phi || \not c_neg)) var control = createNewExplainConstants(houdiniConstant); assertCmd.Expr = houdini.InsertCandidateControl(assertCmd.Expr, control.Item1, control.Item2); explainPositive.Add(control.Item1); explainNegative.Add(control.Item2); constToControl.Add(houdiniConstant.Name, control); } }
public override void Visit(IDivision division) { this.Visit(division.LeftOperand); this.Visit(division.RightOperand); Bpl.Expr rexp = TranslatedExpressions.Pop(); Bpl.Expr lexp = TranslatedExpressions.Pop(); var tok = division.Token(); var loc = this.sink.CreateFreshLocal(division.RightOperand.Type); var locExpr = Bpl.Expr.Ident(loc); var storeLocal = Bpl.Cmd.SimpleAssign(tok, locExpr, rexp); this.StmtTraverser.StmtBuilder.Add(storeLocal); var a = new Bpl.AssertCmd(tok, Bpl.Expr.Binary(Bpl.BinaryOperator.Opcode.Neq, locExpr, Bpl.Expr.Literal(0))); this.StmtTraverser.StmtBuilder.Add(a); TranslatedExpressions.Push(Bpl.Expr.Binary(Bpl.BinaryOperator.Opcode.Div, lexp, locExpr)); }
private void RaiseExceptionHelper(Bpl.StmtListBuilder builder) { int count = this.sink.nestedTryCatchFinallyStatements.Count; if (count == 0) { // FEEDBACK TODO unfortunately return statements are created here too // 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); builder.Add(falseAssertion); } } builder.Add(new Bpl.ReturnCmd(Bpl.Token.NoToken)); } else { Tuple <ITryCatchFinallyStatement, Sink.TryCatchFinallyContext> topOfStack = this.sink.nestedTryCatchFinallyStatements[count - 1]; string exceptionTarget; if (topOfStack.Item2 == Sink.TryCatchFinallyContext.InTry) { exceptionTarget = this.sink.FindOrCreateCatchLabel(topOfStack.Item1); } else if (topOfStack.Item2 == Sink.TryCatchFinallyContext.InCatch) { builder.Add(TranslationHelper.BuildAssignCmd(Bpl.Expr.Ident(this.sink.LabelVariable), Bpl.Expr.Literal(-1))); exceptionTarget = this.sink.FindOrCreateFinallyLabel(topOfStack.Item1); } else { exceptionTarget = this.sink.FindOrCreateContinuationLabel(topOfStack.Item1); } builder.Add(new Bpl.GotoCmd(Bpl.Token.NoToken, new List <string>(new string[] { exceptionTarget }))); } }
private void AssertOrAssumeNonNull(Bpl.IToken token, Bpl.Expr instance) { if (this.sink.Options.dereference != Options.Dereference.None) { Bpl.Cmd c; var n = Bpl.Expr.Ident(this.sink.Heap.NullRef); var neq = Bpl.Expr.Binary(Bpl.BinaryOperator.Opcode.Neq, instance, n); if (this.sink.Options.dereference == Options.Dereference.Assume) { c = new Bpl.AssumeCmd(token, neq); } else { c = new Bpl.AssertCmd(token, neq); } this.StmtTraverser.StmtBuilder.Add(c); } }
private void AnnotateBlock(Implementation impl, ProverContext ctxt, Block header) { Contract.Assert(header != null); string name = impl.Name + "_" + header.Label + "_invar"; if (annotationInfo.ContainsKey(name)) return; // collect the variables needed in the invariant List<Expr> exprs = new List<Expr>(); List<Variable> vars = new List<Variable>(); List<string> names = new List<string>(); if (style == AnnotationStyle.Flat) { // in flat mode, all live globals should be in live set #if false foreach (Variable v in program.GlobalVariables()) { vars.Add(v); names.Add(v.ToString()); exprs.Add(new IdentifierExpr(Token.NoToken, v)); } #endif foreach (Variable v in /* impl.LocVars */ header.liveVarsBefore) { if (!(v is BoundVariable)) { vars.Add(v); names.Add(v.ToString()); exprs.Add(new IdentifierExpr(Token.NoToken, v)); } } } else { foreach (Variable v in program.GlobalVariables()) { vars.Add(v); names.Add("@old_" + v.ToString()); exprs.Add(new OldExpr(Token.NoToken, new IdentifierExpr(Token.NoToken, v))); } foreach (IdentifierExpr ie in impl.Proc.Modifies) { if (ie.Decl == null) continue; vars.Add(ie.Decl); names.Add(ie.Decl.ToString()); exprs.Add(ie); } foreach (Variable v in impl.Proc.InParams) { Contract.Assert(v != null); vars.Add(v); names.Add("@old_" + v.ToString()); exprs.Add(new OldExpr(Token.NoToken, new IdentifierExpr(Token.NoToken, v))); } foreach (Variable v in impl.LocVars) { vars.Add(v); names.Add(v.ToString()); exprs.Add(new IdentifierExpr(Token.NoToken, v)); } } TypedIdent ti = new TypedIdent(Token.NoToken, "", Microsoft.Boogie.Type.Bool); Contract.Assert(ti != null); Formal returnVar = new Formal(Token.NoToken, ti, false); Contract.Assert(returnVar != null); var function = new Function(Token.NoToken, name, vars, returnVar); ctxt.DeclareFunction(function, ""); Expr invarExpr = new NAryExpr(Token.NoToken, new FunctionCall(function), exprs); var invarAssertion = new AssertCmd(Token.NoToken, invarExpr); List<Cmd> newCmds = new List<Cmd>(); newCmds.Add(invarAssertion); // make a record in annotationInfo; var info = new AnnotationInfo(); info.filename = header.tok.filename; info.lineno = header.Line; info.argnames = names.ToArray(); info.type = AnnotationInfo.AnnotationType.LoopInvariant; annotationInfo.Add(name, info); // get file and line info from havoc, if there is... if (header.Cmds.Count > 0) { PredicateCmd bif = header.Cmds[0] as PredicateCmd; if (bif != null) { string foo = QKeyValue.FindStringAttribute(bif.Attributes, "sourcefile"); if (foo != null) info.filename = foo; int bar = QKeyValue.FindIntAttribute(bif.Attributes, "sourceline", -1); if (bar != -1) info.lineno = bar; } } var thing = header; foreach (Cmd c in header.Cmds) { newCmds.Add(c); } header.Cmds = newCmds; }
public static CommandLineOptions.SubsumptionOption Subsumption(AssertCmd ac) { Contract.Requires(ac != null); int n = QKeyValue.FindIntAttribute(ac.Attributes, "subsumption", -1); switch (n) { case 0: return CommandLineOptions.SubsumptionOption.Never; case 1: return CommandLineOptions.SubsumptionOption.NotForQuantifiers; case 2: return CommandLineOptions.SubsumptionOption.Always; default: return CommandLineOptions.Clo.UseSubsumption; } }
public Bpl.Procedure addHandlerStubCaller(Sink sink, IMethodDefinition def) { MethodBody callerBody = new MethodBody(); MethodDefinition callerDef = new MethodDefinition() { InternFactory = (def as MethodDefinition).InternFactory, ContainingTypeDefinition = def.ContainingTypeDefinition, IsStatic = true, Name = sink.host.NameTable.GetNameFor("BOOGIE_STUB_CALLER_" + def.Name.Value), Type = sink.host.PlatformType.SystemVoid, Body = callerBody, }; callerBody.MethodDefinition = callerDef; Sink.ProcedureInfo procInfo = sink.FindOrCreateProcedure(def); Sink.ProcedureInfo callerInfo = sink.FindOrCreateProcedure(callerDef); Bpl.LocalVariable[] localVars = new Bpl.LocalVariable[procInfo.Decl.InParams.Count]; Bpl.IdentifierExpr[] varExpr = new Bpl.IdentifierExpr[procInfo.Decl.InParams.Count]; for (int i = 0; i < procInfo.Decl.InParams.Count; i++) { Bpl.LocalVariable loc = new Bpl.LocalVariable(Bpl.Token.NoToken, new Bpl.TypedIdent(Bpl.Token.NoToken, TranslationHelper.GenerateTempVarName(), procInfo.Decl.InParams[i].TypedIdent.Type)); localVars[i] = loc; varExpr[i] = new Bpl.IdentifierExpr(Bpl.Token.NoToken, loc); } Bpl.StmtListBuilder builder = new Bpl.StmtListBuilder(); builder.Add(getResetNavigationCheck(sink)); string pageXaml= PhoneCodeHelper.instance().PhonePlugin.getXAMLForPage(def.ContainingTypeDefinition.ToString()); Bpl.Variable boogieCurrentURI = sink.FindOrCreateFieldVariable(PhoneCodeHelper.CurrentURIFieldDefinition); Bpl.Constant boogieXamlConstant; if (pageXaml != null) boogieXamlConstant = sink.FindOrCreateConstant(pageXaml); else boogieXamlConstant = null; // NAVIGATION TODO: For now just assume we are in this page to be able to call the handler, this is NOT true for any handler // NAVIGATION TODO: ie, a network event handler if (boogieXamlConstant != null) { Bpl.AssumeCmd assumeCurrentPage = new Bpl.AssumeCmd(Bpl.Token.NoToken, Bpl.Expr.Binary(Bpl.BinaryOperator.Opcode.Eq, new Bpl.IdentifierExpr(Bpl.Token.NoToken, boogieCurrentURI), new Bpl.IdentifierExpr(Bpl.Token.NoToken, boogieXamlConstant))); builder.Add(assumeCurrentPage); } // NAVIGATION TODO: have to do the pair generation all in one go instead of having different files that need to be sed'ed boogieXamlConstant = sink.FindOrCreateConstant(BOOGIE_STARTING_URI_PLACEHOLDER); Bpl.AssumeCmd assumeStartPage = new Bpl.AssumeCmd(Bpl.Token.NoToken, Bpl.Expr.Binary(Bpl.BinaryOperator.Opcode.Eq, new Bpl.IdentifierExpr(Bpl.Token.NoToken, boogieCurrentURI), new Bpl.IdentifierExpr(Bpl.Token.NoToken, boogieXamlConstant))); builder.Add(assumeStartPage); builder.Add(new Bpl.CallCmd(Bpl.Token.NoToken, procInfo.Decl.Name, new List<Bpl.Expr>(varExpr), new List<Bpl.IdentifierExpr>())); boogieXamlConstant = sink.FindOrCreateConstant(BOOGIE_ENDING_URI_PLACEHOLDER); Bpl.AssertCmd assertEndPage = new Bpl.AssertCmd(Bpl.Token.NoToken, Bpl.Expr.Binary(Bpl.BinaryOperator.Opcode.Neq, new Bpl.IdentifierExpr(Bpl.Token.NoToken, boogieCurrentURI), new Bpl.IdentifierExpr(Bpl.Token.NoToken, boogieXamlConstant))); Bpl.Expr guard= new Bpl.IdentifierExpr(Bpl.Token.NoToken, sink.FindOrCreateGlobalVariable(PhoneCodeHelper.BOOGIE_NAVIGATION_CHECK_VARIABLE, Bpl.Type.Bool)); Bpl.StmtListBuilder thenBuilder = new Bpl.StmtListBuilder(); thenBuilder.Add(assertEndPage); Bpl.IfCmd ifNavigated = new Bpl.IfCmd(Bpl.Token.NoToken, guard, thenBuilder.Collect(Bpl.Token.NoToken), null, new Bpl.StmtListBuilder().Collect(Bpl.Token.NoToken)); builder.Add(ifNavigated); Bpl.Implementation impl = new Bpl.Implementation(Bpl.Token.NoToken, callerInfo.Decl.Name, new List<Bpl.TypeVariable>(), new List<Bpl.Variable>(), new List<Bpl.Variable>(), new List<Bpl.Variable>(localVars), builder.Collect(Bpl.Token.NoToken), null, new Bpl.Errors()); sink.TranslatedProgram.AddTopLevelDeclaration(impl); return impl.Proc; }
public override Cmd VisitAssertCmd(AssertCmd node) { AddHoudiniConstant(node); return base.VisitAssertCmd(node); }
private List<List<Cmd>> CollectAndDesugarYields(Implementation impl, Dictionary<string, Variable> domainNameToInputVar, Dictionary<string, Variable> domainNameToLocalVar, Dictionary<Variable, Variable> ogOldGlobalMap) { // Collect the yield predicates and desugar yields List<List<Cmd>> yields = new List<List<Cmd>>(); List<Cmd> cmds = new List<Cmd>(); foreach (Block b in impl.Blocks) { YieldCmd yieldCmd = null; List<Cmd> newCmds = new List<Cmd>(); for (int i = 0; i < b.Cmds.Count; i++) { Cmd cmd = b.Cmds[i]; if (cmd is YieldCmd) { yieldCmd = (YieldCmd)cmd; continue; } if (yieldCmd != null) { PredicateCmd pcmd = cmd as PredicateCmd; if (pcmd == null) { DesugarYield(yieldCmd, cmds, newCmds, ogOldGlobalMap, domainNameToInputVar, domainNameToLocalVar); if (cmds.Count > 0) { yields.Add(cmds); cmds = new List<Cmd>(); } yieldCmd = null; } else { cmds.Add(pcmd); } } if (cmd is CallCmd) { CallCmd callCmd = cmd as CallCmd; if (yieldingProcs.Contains(callCmd.Proc)) { AddCallToYieldProc(callCmd.tok, newCmds, ogOldGlobalMap, domainNameToLocalVar); } if (callCmd.IsAsync) { if (!asyncAndParallelCallDesugarings.ContainsKey(callCmd.Proc.Name)) { asyncAndParallelCallDesugarings[callCmd.Proc.Name] = new Procedure(Token.NoToken, string.Format("DummyAsyncTarget_{0}", callCmd.Proc.Name), callCmd.Proc.TypeParameters, callCmd.Proc.InParams, callCmd.Proc.OutParams, callCmd.Proc.Requires, new List<IdentifierExpr>(), new List<Ensures>()); } var dummyAsyncTargetProc = asyncAndParallelCallDesugarings[callCmd.Proc.Name]; CallCmd dummyCallCmd = new CallCmd(callCmd.tok, dummyAsyncTargetProc.Name, callCmd.Ins, callCmd.Outs, callCmd.Attributes); dummyCallCmd.Proc = dummyAsyncTargetProc; newCmds.Add(dummyCallCmd); } else { newCmds.Add(callCmd); } if (yieldingProcs.Contains(callCmd.Proc)) { HashSet<Variable> availableLinearVars = new HashSet<Variable>(AvailableLinearVars(callCmd)); linearTypeChecker.AddAvailableVars(callCmd, availableLinearVars); if (!callCmd.IsAsync && globalMods.Count > 0 && pc != null) { // assume pc || alpha(i, g); Expr assumeExpr = Expr.Or(Expr.Ident(pc), alpha); assumeExpr.Type = Type.Bool; newCmds.Add(new AssumeCmd(Token.NoToken, assumeExpr)); } Dictionary<string, Expr> domainNameToExpr = ComputeAvailableExprs(availableLinearVars, domainNameToInputVar); AddUpdatesToOldGlobalVars(newCmds, ogOldGlobalMap, domainNameToLocalVar, domainNameToExpr); } } else if (cmd is ParCallCmd) { ParCallCmd parCallCmd = cmd as ParCallCmd; AddCallToYieldProc(parCallCmd.tok, newCmds, ogOldGlobalMap, domainNameToLocalVar); DesugarParallelCallCmd(newCmds, parCallCmd); HashSet<Variable> availableLinearVars = new HashSet<Variable>(AvailableLinearVars(parCallCmd)); linearTypeChecker.AddAvailableVars(parCallCmd, availableLinearVars); if (globalMods.Count > 0 && pc != null) { // assume pc || alpha(i, g); Expr assumeExpr = Expr.Or(Expr.Ident(pc), alpha); assumeExpr.Type = Type.Bool; newCmds.Add(new AssumeCmd(Token.NoToken, assumeExpr)); } Dictionary<string, Expr> domainNameToExpr = ComputeAvailableExprs(availableLinearVars, domainNameToInputVar); AddUpdatesToOldGlobalVars(newCmds, ogOldGlobalMap, domainNameToLocalVar, domainNameToExpr); } else { newCmds.Add(cmd); } } if (yieldCmd != null) { DesugarYield(yieldCmd, cmds, newCmds, ogOldGlobalMap, domainNameToInputVar, domainNameToLocalVar); if (cmds.Count > 0) { yields.Add(cmds); cmds = new List<Cmd>(); } } if (b.TransferCmd is ReturnCmd) { AddCallToYieldProc(b.TransferCmd.tok, newCmds, ogOldGlobalMap, domainNameToLocalVar); if (pc != null) { AssertCmd assertCmd = new AssertCmd(b.TransferCmd.tok, Expr.Ident(ok)); assertCmd.ErrorData = "Failed to execute atomic action before procedure return"; newCmds.Add(assertCmd); } } b.Cmds = newCmds; } return yields; }
private void RaiseExceptionHelper(Bpl.StmtListBuilder builder) { int count = this.sink.nestedTryCatchFinallyStatements.Count; if (count == 0) { // FEEDBACK TODO unfortunately return statements are created here too // 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); builder.Add(falseAssertion); } } builder.Add(new Bpl.ReturnCmd(Bpl.Token.NoToken)); } else { Tuple<ITryCatchFinallyStatement, Sink.TryCatchFinallyContext> topOfStack = this.sink.nestedTryCatchFinallyStatements[count - 1]; string exceptionTarget; if (topOfStack.Item2 == Sink.TryCatchFinallyContext.InTry) { exceptionTarget = this.sink.FindOrCreateCatchLabel(topOfStack.Item1); } else if (topOfStack.Item2 == Sink.TryCatchFinallyContext.InCatch) { builder.Add(TranslationHelper.BuildAssignCmd(Bpl.Expr.Ident(this.sink.LabelVariable), Bpl.Expr.Literal(-1))); exceptionTarget = this.sink.FindOrCreateFinallyLabel(topOfStack.Item1); } else { exceptionTarget = this.sink.FindOrCreateContinuationLabel(topOfStack.Item1); } builder.Add(new Bpl.GotoCmd(Bpl.Token.NoToken, new List<string>(new string[] {exceptionTarget}))); } }
public override Cmd VisitAssertCmd(AssertCmd node) { if (enclosingImpl == null) { // in this case, we are visiting an assert inside a CodeExpr return base.VisitAssertCmd(node); } sharedVarsAccessed = new HashSet<Variable>(); Debug.Assert(introducedLocalVarsUpperBound == int.MinValue); base.VisitAssertCmd(node); CheckAndAddLayers(node, node.Attributes, procToActionInfo[enclosingImpl.Proc].createdAtLayerNum); if (introducedLocalVarsUpperBound > Least(FindLayers(node.Attributes))) { Error(node, "An introduced local variable is accessed but not available"); } introducedLocalVarsUpperBound = int.MinValue; sharedVarsAccessed = null; return node; }
public override Cmd VisitAssertCmd(AssertCmd node) { Contract.Ensures(Contract.Result<Cmd>() == node); this.VisitExpr(node.Expr); return node; }
protected override Cmd ComputeDesugaring() { Contract.Ensures(Contract.Result<Cmd>() != null); List<Cmd> newBlockBody = new List<Cmd>(); Dictionary<Variable, Expr> substMap = new Dictionary<Variable, Expr>(); Dictionary<Variable, Expr> substMapOld = new Dictionary<Variable, Expr>(); Dictionary<Variable, Expr> substMapBound = new Dictionary<Variable, Expr>(); List<Variable>/*!*/ tempVars = new List<Variable>(); // proc P(ins) returns (outs) // requires Pre // //modifies frame // ensures Post // // call aouts := P(ains) // ins : formal in parameters of procedure // frame : a list of global variables from the modifies clause // outs : formal out parameters of procedure // ains : actual in arguments passed to call // aouts : actual variables assigned to from call // cins : new variables created just for this call, one per ains // cframe : new variables created just for this call, to keep track of OLD values // couts : new variables created just for this call, one per aouts // WildcardVars : new variables created just for this call, one per null in ains #region Create cins; each one is an incarnation of the corresponding in parameter List<Variable>/*!*/ cins = new List<Variable>(); List<Variable> wildcardVars = new List<Variable>(); Contract.Assume(this.Proc != null); for (int i = 0; i < this.Proc.InParams.Count; ++i) { Variable/*!*/ param = cce.NonNull(this.Proc.InParams[i]); bool isWildcard = this.Ins[i] == null; Type/*!*/ actualType; if (isWildcard) actualType = param.TypedIdent.Type.Substitute(TypeParamSubstitution()); else // during type checking, we have ensured that the type of the actual // parameter Ins[i] is correct, so we can use it here actualType = cce.NonNull(cce.NonNull(Ins[i]).Type); Variable cin = CreateTemporaryVariable(tempVars, param, actualType, TempVarKind.Formal); cins.Add(cin); IdentifierExpr ie = new IdentifierExpr(cin.tok, cin); substMap.Add(param, ie); if (isWildcard) { cin = CreateTemporaryVariable(tempVars, param, actualType, TempVarKind.Bound); wildcardVars.Add(cin); ie = new IdentifierExpr(cin.tok, cin); } substMapBound.Add(param, ie); } #endregion #region call aouts := P(ains) becomes: (open outlining one level to see) #region cins := ains (or havoc cin when ain is null) for (int i = 0, n = this.Ins.Count; i < n; i++) { IdentifierExpr/*!*/ cin_exp = new IdentifierExpr(cce.NonNull(cins[i]).tok, cce.NonNull(cins[i])); Contract.Assert(cin_exp != null); if (this.Ins[i] != null) { AssignCmd assign = Cmd.SimpleAssign(Token.NoToken, cin_exp, cce.NonNull(this.Ins[i])); newBlockBody.Add(assign); } else { List<IdentifierExpr>/*!*/ ies = new List<IdentifierExpr>(); ies.Add(cin_exp); HavocCmd havoc = new HavocCmd(Token.NoToken, ies); newBlockBody.Add(havoc); } } #endregion #region assert (exists wildcardVars :: Pre[ins := cins]) Substitution s = Substituter.SubstitutionFromHashtable(substMapBound); bool hasWildcard = (wildcardVars.Count != 0); Expr preConjunction = null; for (int i = 0; i < this.Proc.Requires.Count; i++) { Requires/*!*/ req = cce.NonNull(this.Proc.Requires[i]); if (!req.Free && !IsFree) { if (hasWildcard) { Expr pre = Substituter.Apply(s, req.Condition); if (preConjunction == null) { preConjunction = pre; } else { preConjunction = Expr.And(preConjunction, pre); } } else { Requires/*!*/ reqCopy = (Requires/*!*/)cce.NonNull(req.Clone()); reqCopy.Condition = Substituter.Apply(s, req.Condition); AssertCmd/*!*/ a = new AssertRequiresCmd(this, reqCopy); Contract.Assert(a != null); a.ErrorDataEnhanced = reqCopy.ErrorDataEnhanced; newBlockBody.Add(a); } } else if (CommandLineOptions.Clo.StratifiedInlining > 0) { // inject free requires as assume statements at the call site AssumeCmd/*!*/ a = new AssumeCmd(req.tok, Substituter.Apply(s, req.Condition)); Contract.Assert(a != null); newBlockBody.Add(a); } } if (hasWildcard) { if (preConjunction == null) { preConjunction = Expr.True; } Expr/*!*/ expr = new ExistsExpr(tok, wildcardVars, preConjunction); Contract.Assert(expr != null); AssertCmd/*!*/ a = new AssertCmd(tok, expr); Contract.Assert(a != null); a.ErrorDataEnhanced = AssertCmd.GenerateBoundVarMiningStrategy(expr); newBlockBody.Add(a); } #endregion #region assume Pre[ins := cins] with formal paramters if (hasWildcard) { s = Substituter.SubstitutionFromHashtable(substMap); for (int i = 0; i < this.Proc.Requires.Count; i++) { Requires/*!*/ req = cce.NonNull(this.Proc.Requires[i]); if (!req.Free) { Requires/*!*/ reqCopy = (Requires/*!*/)cce.NonNull(req.Clone()); reqCopy.Condition = Substituter.Apply(s, req.Condition); AssumeCmd/*!*/ a = new AssumeCmd(tok, reqCopy.Condition); Contract.Assert(a != null); newBlockBody.Add(a); } } } #endregion #region cframe := frame (to hold onto frame values in case they are referred to in the postcondition) List<IdentifierExpr> havocVarExprs = new List<IdentifierExpr>(); foreach (IdentifierExpr/*!*/ f in this.Proc.Modifies) { Contract.Assert(f != null); Contract.Assume(f.Decl != null); Contract.Assert(f.Type != null); Variable v = CreateTemporaryVariable(tempVars, f.Decl, f.Type, TempVarKind.Old); IdentifierExpr v_exp = new IdentifierExpr(v.tok, v); substMapOld.Add(f.Decl, v_exp); // this assumes no duplicates in this.Proc.Modifies AssignCmd assign = Cmd.SimpleAssign(f.tok, v_exp, f); newBlockBody.Add(assign); // fra if (!havocVarExprs.Contains(f)) havocVarExprs.Add(f); } #endregion #region Create couts List<Variable>/*!*/ couts = new List<Variable>(); for (int i = 0; i < this.Proc.OutParams.Count; ++i) { Variable/*!*/ param = cce.NonNull(this.Proc.OutParams[i]); bool isWildcard = this.Outs[i] == null; Type/*!*/ actualType; if (isWildcard) actualType = param.TypedIdent.Type.Substitute(TypeParamSubstitution()); else // during type checking, we have ensured that the type of the actual // out parameter Outs[i] is correct, so we can use it here actualType = cce.NonNull(cce.NonNull(Outs[i]).Type); Variable cout = CreateTemporaryVariable(tempVars, param, actualType, TempVarKind.Formal); couts.Add(cout); IdentifierExpr ie = new IdentifierExpr(cout.tok, cout); substMap.Add(param, ie); if (!havocVarExprs.Contains(ie)) havocVarExprs.Add(ie); } // add the where clauses, now that we have the entire substitution map foreach (Variable/*!*/ param in this.Proc.OutParams) { Contract.Assert(param != null); Expr w = param.TypedIdent.WhereExpr; if (w != null) { IdentifierExpr ie = (IdentifierExpr/*!*/)cce.NonNull(substMap[param]); Contract.Assert(ie.Decl != null); ie.Decl.TypedIdent.WhereExpr = Substituter.Apply(Substituter.SubstitutionFromHashtable(substMap), w); } } #endregion #region havoc frame, couts // pass on this's token HavocCmd hc = new HavocCmd(this.tok, havocVarExprs); newBlockBody.Add(hc); #endregion #region assume Post[ins, outs, old(frame) := cins, couts, cframe] Substitution s2 = Substituter.SubstitutionFromHashtable(substMap); Substitution s2old = Substituter.SubstitutionFromHashtable(substMapOld); foreach (Ensures/*!*/ e in this.Proc.Ensures) { Contract.Assert(e != null); Expr copy = Substituter.ApplyReplacingOldExprs(s2, s2old, e.Condition); AssumeCmd assume = new AssumeCmd(this.tok, copy); #region stratified inlining support if (QKeyValue.FindBoolAttribute(e.Attributes, "si_fcall")) { assume.Attributes = Attributes; } if (QKeyValue.FindBoolAttribute(e.Attributes, "candidate")) { assume.Attributes = new QKeyValue(Token.NoToken, "candidate", new List<object>(), assume.Attributes); assume.Attributes.Params.Add(this.callee); } #endregion newBlockBody.Add(assume); } #endregion #region aouts := couts for (int i = 0, n = this.Outs.Count; i < n; i++) { if (this.Outs[i] != null) { Variable/*!*/ param_i = cce.NonNull(this.Proc.OutParams[i]); Expr/*!*/ cout_exp = new IdentifierExpr(cce.NonNull(couts[i]).tok, cce.NonNull(couts[i])); Contract.Assert(cout_exp != null); AssignCmd assign = Cmd.SimpleAssign(param_i.tok, cce.NonNull(this.Outs[i]), cout_exp); newBlockBody.Add(assign); } } #endregion #endregion return new StateCmd(this.tok, tempVars, newBlockBody); }
public override Cmd VisitAssertCmd(AssertCmd node) { int phaseNum = QKeyValue.FindIntAttribute(node.Attributes, "phase", int.MaxValue); assertionPhaseNums.Add(phaseNum); if (phaseNum > enclosingProcPhaseNum) { Error(node, "The phase of assert cannot be greater than the phase of enclosing procedure"); } return node; }
static void Instrument(Implementation impl, NativeLattice.Element[] pre, NativeLattice.Element[] post) { Contract.Requires(impl != null); Contract.Requires(pre != null); foreach (var b in impl.Blocks) { var element = pre[b.aiId]; if (element != null && (b.widenBlock || CommandLineOptions.Clo.InstrumentInfer == CommandLineOptions.InstrumentationPlaces.Everywhere)) { List<Cmd> newCommands = new List<Cmd>(); Expr inv = element.ToExpr(); PredicateCmd cmd; var kv = new QKeyValue(Token.NoToken, "inferred", new List<object>(), null); if (CommandLineOptions.Clo.InstrumentWithAsserts) { cmd = new AssertCmd(Token.NoToken, inv, kv); } else { cmd = new AssumeCmd(Token.NoToken, inv, kv); } newCommands.Add(cmd); newCommands.AddRange(b.Cmds); if (post != null && post[b.aiId] != null) { inv = post[b.aiId].ToExpr(); kv = new QKeyValue(Token.NoToken, "inferred", new List<object>(), null); if (CommandLineOptions.Clo.InstrumentWithAsserts) { cmd = new AssertCmd(Token.NoToken, inv, kv); } else { cmd = new AssumeCmd(Token.NoToken, inv, kv); } newCommands.Add(cmd); } b.Cmds = newCommands; // destructively replace the commands of the block } } }
private void ProcessLoopHeaders(Implementation impl, Graph<Block> graph, HashSet<Block> yieldingHeaders, Dictionary<string, Variable> domainNameToInputVar, Dictionary<string, Variable> domainNameToLocalVar, Dictionary<Variable, Variable> ogOldGlobalMap, out List<Variable> oldPcs, out List<Variable> oldOks) { oldPcs = new List<Variable>(); oldOks = new List<Variable>(); foreach (Block header in yieldingHeaders) { LocalVariable oldPc = null; LocalVariable oldOk = null; if (pc != null) { oldPc = new LocalVariable(Token.NoToken, new TypedIdent(Token.NoToken, string.Format("{0}_{1}", pc.Name, header.Label), Type.Bool)); oldPcs.Add(oldPc); oldOk = new LocalVariable(Token.NoToken, new TypedIdent(Token.NoToken, string.Format("{0}_{1}", ok.Name, header.Label), Type.Bool)); oldOks.Add(oldOk); } Dictionary<string, Expr> domainNameToExpr = ComputeAvailableExprs(AvailableLinearVars(header), domainNameToInputVar); foreach (Block pred in header.Predecessors) { AddCallToYieldProc(header.tok, pred.Cmds, ogOldGlobalMap, domainNameToLocalVar); if (pc != null && !graph.BackEdgeNodes(header).Contains(pred)) { pred.Cmds.Add(new AssignCmd(Token.NoToken, new List<AssignLhs>( new AssignLhs[] { new SimpleAssignLhs(Token.NoToken, Expr.Ident(oldPc)), new SimpleAssignLhs(Token.NoToken, Expr.Ident(oldOk)) }), new List<Expr>(new Expr[] { Expr.Ident(pc), Expr.Ident(ok) }))); } AddUpdatesToOldGlobalVars(pred.Cmds, ogOldGlobalMap, domainNameToLocalVar, domainNameToExpr); } List<Cmd> newCmds = new List<Cmd>(); if (pc != null) { AssertCmd assertCmd; assertCmd = new AssertCmd(header.tok, Expr.Eq(Expr.Ident(oldPc), Expr.Ident(pc))); assertCmd.ErrorData = "Specification state must not change for transitions ending in loop headers"; newCmds.Add(assertCmd); assertCmd = new AssertCmd(header.tok, Expr.Imp(Expr.Ident(oldOk), Expr.Ident(ok))); assertCmd.ErrorData = "Specification state must not change for transitions ending in loop headers"; newCmds.Add(assertCmd); } foreach (string domainName in linearTypeChecker.linearDomains.Keys) { newCmds.Add(new AssumeCmd(Token.NoToken, Expr.Eq(Expr.Ident(domainNameToLocalVar[domainName]), domainNameToExpr[domainName]))); } foreach (Variable v in ogOldGlobalMap.Keys) { newCmds.Add(new AssumeCmd(Token.NoToken, Expr.Eq(Expr.Ident(v), Expr.Ident(ogOldGlobalMap[v])))); } newCmds.AddRange(header.Cmds); header.Cmds = newCmds; } }
void LabelOrCmd(out Cmd c, out IToken label) { IToken/*!*/ x; Expr/*!*/ e; List<IToken>/*!*/ xs; List<IdentifierExpr> ids; c = dummyCmd; label = null; Cmd/*!*/ cn; QKeyValue kv = null; switch (la.kind) { case 1: { LabelOrAssign(out c, out label); break; } case 47: { Get(); x = t; while (la.kind == 28) { Attribute(ref kv); } Proposition(out e); c = new AssertCmd(x, e, kv); Expect(9); break; } case 48: { Get(); x = t; while (la.kind == 28) { Attribute(ref kv); } Proposition(out e); c = new AssumeCmd(x, e, kv); Expect(9); break; } case 49: { Get(); x = t; Idents(out xs); Expect(9); ids = new List<IdentifierExpr>(); foreach(IToken/*!*/ y in xs){ Contract.Assert(y != null); ids.Add(new IdentifierExpr(y, y.val)); } c = new HavocCmd(x,ids); break; } case 36: case 52: case 53: { CallCmd(out cn); Expect(9); c = cn; break; } case 54: { ParCallCmd(out cn); c = cn; break; } case 50: { Get(); x = t; Expect(9); c = new YieldCmd(x); break; } default: SynErr(106); break; } }
public PredicateCmd CreateCandidateInvariant(Expr e, string tag = null, int StageId = 0) { Constant ExistentialBooleanConstant = MakeExistentialBoolean(StageId); IdentifierExpr ExistentialBoolean = new IdentifierExpr(Token.NoToken, ExistentialBooleanConstant); PredicateCmd invariant = new AssertCmd(Token.NoToken, Expr.Imp(ExistentialBoolean, e)); if (tag != null) invariant.Attributes = new QKeyValue(Token.NoToken, "tag", new List<object>(new object[] { tag }), null); return invariant; }
public override Cmd VisitAssertCmd(AssertCmd node) { CivlAttributes.RemoveLayerAttribute(node); return base.VisitAssertCmd(node); }
public override Cmd VisitAssertCmd(AssertCmd node) { node.Attributes = RemoveLayerAttribute(node.Attributes); return base.VisitAssertCmd(node); }
private void AddCallToYieldProc(IToken tok, List<Cmd> newCmds, Dictionary<Variable, Variable> ogOldGlobalMap, Dictionary<string, Variable> domainNameToLocalVar) { if (!CommandLineOptions.Clo.TrustNonInterference) { CallCmd yieldCallCmd = CallToYieldProc(tok, ogOldGlobalMap, domainNameToLocalVar); newCmds.Add(yieldCallCmd); } if (pc != null) { Expr aa = OldEqualityExprForGlobals(ogOldGlobalMap); Expr bb = OldEqualityExpr(ogOldGlobalMap); // assert pc || g_old == g || beta(i, g_old, o, g); Expr assertExpr = Expr.Or(Expr.Ident(pc), Expr.Or(aa, beta)); assertExpr.Typecheck(new TypecheckingContext(null)); AssertCmd skipOrBetaAssertCmd = new AssertCmd(tok, assertExpr); skipOrBetaAssertCmd.ErrorData = "Transition invariant in initial state violated"; newCmds.Add(skipOrBetaAssertCmd); // assert pc ==> o_old == o && g_old == g; assertExpr = Expr.Imp(Expr.Ident(pc), bb); assertExpr.Typecheck(new TypecheckingContext(null)); AssertCmd skipAssertCmd = new AssertCmd(tok, assertExpr); skipAssertCmd.ErrorData = "Transition invariant in final state violated"; ; newCmds.Add(skipAssertCmd); // pc, ok := g_old == g ==> pc, ok || beta(i, g_old, o, g); List<AssignLhs> pcUpdateLHS = new List<AssignLhs>( new AssignLhs[] { new SimpleAssignLhs(Token.NoToken, Expr.Ident(pc)), new SimpleAssignLhs(Token.NoToken, Expr.Ident(ok)) }); List<Expr> pcUpdateRHS = new List<Expr>( new Expr[] { Expr.Imp(aa, Expr.Ident(pc)), Expr.Or(Expr.Ident(ok), beta) }); foreach (Expr e in pcUpdateRHS) { e.Typecheck(new TypecheckingContext(null)); } newCmds.Add(new AssignCmd(Token.NoToken, pcUpdateLHS, pcUpdateRHS)); } }
public override Cmd VisitAssertCmd(AssertCmd node) { if (enclosingImpl == null) return base.VisitAssertCmd(node); minLayerNum = int.MaxValue; maxLayerNum = -1; canAccessSharedVars = true; canAccessGhostVars = true; Cmd ret = base.VisitAssertCmd(node); canAccessGhostVars = false; canAccessSharedVars = false; CheckAndAddLayers(node, node.Attributes, procToActionInfo[enclosingImpl.Proc].createdAtLayerNum); return ret; }
private void CreateYieldCheckerImpl(Implementation impl, List<List<Cmd>> yields) { if (yields.Count == 0) return; Dictionary<Variable, Expr> map = new Dictionary<Variable, Expr>(); foreach (Variable local in impl.LocVars) { var copy = new LocalVariable(Token.NoToken, new TypedIdent(Token.NoToken, local.Name, local.TypedIdent.Type)); map[local] = Expr.Ident(copy); } Program program = linearTypeChecker.program; List<Variable> locals = new List<Variable>(); List<Variable> inputs = new List<Variable>(); foreach (IdentifierExpr ie in map.Values) { locals.Add(ie.Decl); } for (int i = 0; i < impl.InParams.Count - linearTypeChecker.linearDomains.Count; i++) { Variable inParam = impl.InParams[i]; Variable copy = new LocalVariable(Token.NoToken, new TypedIdent(Token.NoToken, inParam.Name, inParam.TypedIdent.Type)); locals.Add(copy); map[impl.InParams[i]] = Expr.Ident(copy); } { int i = impl.InParams.Count - linearTypeChecker.linearDomains.Count; foreach (string domainName in linearTypeChecker.linearDomains.Keys) { Variable inParam = impl.InParams[i]; Variable copy = new Formal(Token.NoToken, new TypedIdent(Token.NoToken, inParam.Name, inParam.TypedIdent.Type), true); inputs.Add(copy); map[impl.InParams[i]] = Expr.Ident(copy); i++; } } for (int i = 0; i < impl.OutParams.Count; i++) { Variable outParam = impl.OutParams[i]; var copy = new LocalVariable(Token.NoToken, new TypedIdent(Token.NoToken, outParam.Name, outParam.TypedIdent.Type)); locals.Add(copy); map[impl.OutParams[i]] = Expr.Ident(copy); } Dictionary<Variable, Expr> ogOldLocalMap = new Dictionary<Variable, Expr>(); Dictionary<Variable, Expr> assumeMap = new Dictionary<Variable, Expr>(map); foreach (IdentifierExpr ie in globalMods) { Variable g = ie.Decl; var copy = new LocalVariable(Token.NoToken, new TypedIdent(Token.NoToken, string.Format("og_local_old_{0}", g.Name), g.TypedIdent.Type)); locals.Add(copy); ogOldLocalMap[g] = Expr.Ident(copy); Formal f = new Formal(Token.NoToken, new TypedIdent(Token.NoToken, string.Format("og_global_old_{0}", g.Name), g.TypedIdent.Type), true); inputs.Add(f); assumeMap[g] = Expr.Ident(f); } Substitution assumeSubst = Substituter.SubstitutionFromHashtable(assumeMap); Substitution oldSubst = Substituter.SubstitutionFromHashtable(ogOldLocalMap); Substitution subst = Substituter.SubstitutionFromHashtable(map); List<Block> yieldCheckerBlocks = new List<Block>(); List<String> labels = new List<String>(); List<Block> labelTargets = new List<Block>(); Block yieldCheckerBlock = new Block(Token.NoToken, "exit", new List<Cmd>(), new ReturnCmd(Token.NoToken)); labels.Add(yieldCheckerBlock.Label); labelTargets.Add(yieldCheckerBlock); yieldCheckerBlocks.Add(yieldCheckerBlock); int yieldCount = 0; foreach (List<Cmd> cs in yields) { List<Cmd> newCmds = new List<Cmd>(); foreach (Cmd cmd in cs) { PredicateCmd predCmd = (PredicateCmd)cmd; newCmds.Add(new AssumeCmd(Token.NoToken, Substituter.ApplyReplacingOldExprs(assumeSubst, oldSubst, predCmd.Expr))); } foreach (Cmd cmd in cs) { PredicateCmd predCmd = (PredicateCmd)cmd; var newExpr = Substituter.ApplyReplacingOldExprs(subst, oldSubst, predCmd.Expr); if (predCmd is AssertCmd) { AssertCmd assertCmd = new AssertCmd(predCmd.tok, newExpr, predCmd.Attributes); assertCmd.ErrorData = "Non-interference check failed"; newCmds.Add(assertCmd); } else { newCmds.Add(new AssumeCmd(Token.NoToken, newExpr)); } } newCmds.Add(new AssumeCmd(Token.NoToken, Expr.False)); yieldCheckerBlock = new Block(Token.NoToken, "L" + yieldCount++, newCmds, new ReturnCmd(Token.NoToken)); labels.Add(yieldCheckerBlock.Label); labelTargets.Add(yieldCheckerBlock); yieldCheckerBlocks.Add(yieldCheckerBlock); } yieldCheckerBlocks.Insert(0, new Block(Token.NoToken, "enter", new List<Cmd>(), new GotoCmd(Token.NoToken, labels, labelTargets))); // Create the yield checker procedure var yieldCheckerName = string.Format("{0}_YieldChecker_{1}", "Impl", impl.Name); var yieldCheckerProc = new Procedure(Token.NoToken, yieldCheckerName, impl.TypeParameters, inputs, new List<Variable>(), new List<Requires>(), new List<IdentifierExpr>(), new List<Ensures>()); yieldCheckerProc.AddAttribute("inline", new LiteralExpr(Token.NoToken, Microsoft.Basetypes.BigNum.FromInt(1))); yieldCheckerProcs.Add(yieldCheckerProc); // Create the yield checker implementation var yieldCheckerImpl = new Implementation(Token.NoToken, yieldCheckerName, impl.TypeParameters, inputs, new List<Variable>(), locals, yieldCheckerBlocks); yieldCheckerImpl.Proc = yieldCheckerProc; yieldCheckerImpl.AddAttribute("inline", new LiteralExpr(Token.NoToken, Microsoft.Basetypes.BigNum.FromInt(1))); yieldCheckerImpls.Add(yieldCheckerImpl); }
public Bpl.Procedure addHandlerStubCaller(Sink sink, IMethodDefinition def) { MethodBody callerBody = new MethodBody(); MethodDefinition callerDef = new MethodDefinition() { InternFactory = (def as MethodDefinition).InternFactory, ContainingTypeDefinition = def.ContainingTypeDefinition, IsStatic = true, Name = sink.host.NameTable.GetNameFor("BOOGIE_STUB_CALLER_" + def.Name.Value), Type = sink.host.PlatformType.SystemVoid, Body = callerBody, }; callerBody.MethodDefinition = callerDef; Sink.ProcedureInfo procInfo = sink.FindOrCreateProcedure(def); Sink.ProcedureInfo callerInfo = sink.FindOrCreateProcedure(callerDef); Bpl.LocalVariable[] localVars = new Bpl.LocalVariable[procInfo.Decl.InParams.Count]; Bpl.IdentifierExpr[] varExpr = new Bpl.IdentifierExpr[procInfo.Decl.InParams.Count]; for (int i = 0; i < procInfo.Decl.InParams.Count; i++) { Bpl.LocalVariable loc = new Bpl.LocalVariable(Bpl.Token.NoToken, new Bpl.TypedIdent(Bpl.Token.NoToken, TranslationHelper.GenerateTempVarName(), procInfo.Decl.InParams[i].TypedIdent.Type)); localVars[i] = loc; varExpr[i] = new Bpl.IdentifierExpr(Bpl.Token.NoToken, loc); } Bpl.StmtListBuilder builder = new Bpl.StmtListBuilder(); builder.Add(getResetNavigationCheck(sink)); string pageXaml = PhoneCodeHelper.instance().PhonePlugin.getXAMLForPage(def.ContainingTypeDefinition.ToString()); Bpl.Variable boogieCurrentURI = sink.FindOrCreateFieldVariable(PhoneCodeHelper.CurrentURIFieldDefinition); Bpl.Constant boogieXamlConstant; if (pageXaml != null) { boogieXamlConstant = sink.FindOrCreateConstant(pageXaml); } else { boogieXamlConstant = null; } // NAVIGATION TODO: For now just assume we are in this page to be able to call the handler, this is NOT true for any handler // NAVIGATION TODO: ie, a network event handler if (boogieXamlConstant != null) { Bpl.AssumeCmd assumeCurrentPage = new Bpl.AssumeCmd(Bpl.Token.NoToken, Bpl.Expr.Binary(Bpl.BinaryOperator.Opcode.Eq, new Bpl.IdentifierExpr(Bpl.Token.NoToken, boogieCurrentURI), new Bpl.IdentifierExpr(Bpl.Token.NoToken, boogieXamlConstant))); builder.Add(assumeCurrentPage); } // NAVIGATION TODO: have to do the pair generation all in one go instead of having different files that need to be sed'ed boogieXamlConstant = sink.FindOrCreateConstant(BOOGIE_STARTING_URI_PLACEHOLDER); Bpl.AssumeCmd assumeStartPage = new Bpl.AssumeCmd(Bpl.Token.NoToken, Bpl.Expr.Binary(Bpl.BinaryOperator.Opcode.Eq, new Bpl.IdentifierExpr(Bpl.Token.NoToken, boogieCurrentURI), new Bpl.IdentifierExpr(Bpl.Token.NoToken, boogieXamlConstant))); builder.Add(assumeStartPage); builder.Add(new Bpl.CallCmd(Bpl.Token.NoToken, procInfo.Decl.Name, new List <Bpl.Expr>(varExpr), new List <Bpl.IdentifierExpr>())); boogieXamlConstant = sink.FindOrCreateConstant(BOOGIE_ENDING_URI_PLACEHOLDER); Bpl.AssertCmd assertEndPage = new Bpl.AssertCmd(Bpl.Token.NoToken, Bpl.Expr.Binary(Bpl.BinaryOperator.Opcode.Neq, new Bpl.IdentifierExpr(Bpl.Token.NoToken, boogieCurrentURI), new Bpl.IdentifierExpr(Bpl.Token.NoToken, boogieXamlConstant))); Bpl.Expr guard = new Bpl.IdentifierExpr(Bpl.Token.NoToken, sink.FindOrCreateGlobalVariable(PhoneCodeHelper.BOOGIE_NAVIGATION_CHECK_VARIABLE, Bpl.Type.Bool)); Bpl.StmtListBuilder thenBuilder = new Bpl.StmtListBuilder(); thenBuilder.Add(assertEndPage); Bpl.IfCmd ifNavigated = new Bpl.IfCmd(Bpl.Token.NoToken, guard, thenBuilder.Collect(Bpl.Token.NoToken), null, new Bpl.StmtListBuilder().Collect(Bpl.Token.NoToken)); builder.Add(ifNavigated); Bpl.Implementation impl = new Bpl.Implementation(Bpl.Token.NoToken, callerInfo.Decl.Name, new List <Bpl.TypeVariable>(), new List <Bpl.Variable>(), new List <Bpl.Variable>(), new List <Bpl.Variable>(localVars), builder.Collect(Bpl.Token.NoToken), null, new Bpl.Errors()); sink.TranslatedProgram.AddTopLevelDeclaration(impl); return(impl.Proc); }
public override Cmd VisitAssertCmd(AssertCmd node) { //Contract.Requires(node != null); Contract.Ensures(Contract.Result<Cmd>() != null); return base.VisitAssertCmd((AssertCmd)node.Clone()); }
public override Cmd VisitAssertCmd(AssertCmd node) { if (enclosingImpl == null) { // in this case, we are visiting an assert inside a CodeExpr return base.VisitAssertCmd(node); } sharedVarsAccessed = new HashSet<Variable>(); Debug.Assert(introducedLocalVarsUpperBound == int.MinValue); var layerNums = FindLayers(node.Attributes); introducedLocalVarsUpperBound = Least(layerNums); if (layerNums.Count == 1) { ghostVarIntroLayerAllowed = layerNums[0]; } base.VisitAssertCmd(node); CheckAndAddLayers(node, node.Attributes, procToActionInfo[enclosingImpl.Proc].createdAtLayerNum); introducedLocalVarsUpperBound = int.MinValue; ghostVarIntroLayerAllowed = int.MinValue; sharedVarsAccessed = null; return node; }