public PathInfo(Dictionary <Variable, Expr> varToExpr, List <Expr> pathExprs) { this.varToExpr = new Dictionary <Variable, Expr>(); foreach (var v in varToExpr.Keys) { this.varToExpr[v] = MyDuplicator.Duplicate(varToExpr[v]); } this.pathExprs = new List <Expr>(); foreach (var e in pathExprs) { this.pathExprs.Add(MyDuplicator.Duplicate(e)); } }
private Expr CalculatePathCondition(PathInfo path) { HashSet <Variable> allExistsVars = new HashSet <Variable>(firstExistsVars.Union(secondExistsVars)); HashSet <Variable> usedExistsVars = new HashSet <Variable>(); Dictionary <Variable, Expr> existsSubstitutionMap = new Dictionary <Variable, Expr>(); List <Expr> inferredSelectEqualities = new List <Expr>(); foreach (Variable v in path.varToExpr.Keys.Except(postExistVars)) { var expr = path.varToExpr[v]; usedExistsVars.UnionWith(VariableCollector.Collect(expr).Intersect(allExistsVars)); IdentifierExpr ie = expr as IdentifierExpr; if (ie != null && IsExistsVar(ie.Decl) && !existsSubstitutionMap.ContainsKey(ie.Decl)) { existsSubstitutionMap[ie.Decl] = Expr.Ident(v); } else if (IsMapStoreExpr(expr)) { inferredSelectEqualities.Add(GenerateEqualityWithSelect(expr as NAryExpr, Expr.Ident(v))); } } foreach (Expr expr in path.pathExprs) { usedExistsVars.UnionWith(VariableCollector.Collect(expr).Intersect(allExistsVars)); } InferSubstitution(allExistsVars, existsSubstitutionMap, path.pathExprs, inferredSelectEqualities); List <Expr> triggerExprs = new List <Expr>(); List <Variable> quantifiedVars = new List <Variable>(); foreach (var v in usedExistsVars.Except(existsSubstitutionMap.Keys)) { var triggerFun = TriggerFunction(v); // this call populates existsVars[v] var quantifiedVar = existsVars[v]; triggerExprs.Add( new NAryExpr(Token.NoToken, new FunctionCall(triggerFun), new Expr[] { Expr.Ident(quantifiedVar) })); quantifiedVars.Add(quantifiedVar); existsSubstitutionMap[v] = Expr.Ident(quantifiedVar); } Substitution subst = Substituter.SubstitutionFromHashtable(existsSubstitutionMap); List <Expr> returnExprs = new List <Expr>(); foreach (Variable v in path.varToExpr.Keys.Except(postExistVars)) { Expr withOldExpr = MyDuplicator.Duplicate(path.varToExpr[v]); var substExpr = Expr.Eq(Expr.Ident(v), Substituter.Apply(subst, withOldExpr)); substExpr.Type = Type.Bool; returnExprs.Add(substExpr); } foreach (Expr x in path.pathExprs) { var withOldExpr = MyDuplicator.Duplicate(x); returnExprs.Add(Substituter.Apply(subst, withOldExpr)); } var returnExpr = Expr.And(returnExprs); if (quantifiedVars.Count > 0) { if (first == null) { returnExpr = new ExistsExpr(Token.NoToken, quantifiedVars, returnExpr); } else { returnExpr = new ExistsExpr(Token.NoToken, quantifiedVars, new Trigger(Token.NoToken, true, triggerExprs), returnExpr); } } return(returnExpr); }