public void FindAndResolveTacticApplication(Program tacnyProgram, Function fun) { if (IsLeaf()) { var aps = Data as ApplySuffix; if (aps == null) { return; } UpdateStmt us = new UpdateStmt(aps.tok, aps.tok, new List <Expression>(), new List <AssignmentRhs> { new ExprRhs(aps) }); if (tacnyProgram.IsTacticCall(us)) { List <IVariable> variables = new List <IVariable>(); ITactic tac = tacnyProgram.GetTactic(us); tacnyProgram.SetCurrent(tac, fun); variables.AddRange(fun.Formals); // get the resolved variables List <IVariable> resolved = new List <IVariable>(); Console.Out.WriteLine($"Resolving {tac.Name} in {fun.Name}"); resolved.AddRange(fun.Formals); // add input arguments as resolved variables var result = LazyTacny.Atomic.ResolveTactic(us, fun, tacnyProgram, variables, resolved); Data = result.State.DynamicContext.generatedExpressions[0]; tacnyProgram.CurrentDebug.Fin(); Modified = true; } } else { LChild.FindAndResolveTacticApplication(tacnyProgram, fun); RChild?.FindAndResolveTacticApplication(tacnyProgram, fun); } }
private string ScanMemberBody(MemberDecl md) { Contract.Requires(md != null); solution_list.plist.Clear(); Method m = md as Method; if (m == null) { return(null); } if (m.Body == null) { return(null); } List <IVariable> variables = new List <IVariable>(); variables.AddRange(m.Ins); variables.AddRange(m.Outs); SolutionList sol_list = new SolutionList(); sol_list.AddRange(solution_list.plist); if (TacnyOptions.O.ParallelExecution) { Parallel.ForEach(m.Body.Body, st => { // register local variables VarDeclStmt vds = st as VarDeclStmt; if (vds != null) { variables.AddRange(vds.Locals); } UpdateStmt us = st as UpdateStmt; if (us != null) { if (tacnyProgram.IsTacticCall(us)) { try { tacnyProgram.SetCurrent(tacnyProgram.GetTactic(us), md); // get the resolved variables List <IVariable> resolved = tacnyProgram.GetResolvedVariables(md); resolved.AddRange(m.Ins); // add input arguments as resolved variables Atomic.ResolveTactic(tacnyProgram.GetTactic(us), us, md, tacnyProgram, variables, resolved, ref sol_list); tacnyProgram.CurrentDebug.Fin(); } catch (AggregateException e) { foreach (var err in e.Data) { Printer.Error(err.ToString()); } } } } }); } else { foreach (var st in m.Body.Body) { // register local variables VarDeclStmt vds = st as VarDeclStmt; if (vds != null) { variables.AddRange(vds.Locals); } UpdateStmt us = st as UpdateStmt; if (us != null) { if (tacnyProgram.IsTacticCall(us)) { try { tacnyProgram.SetCurrent(tacnyProgram.GetTactic(us), md); // get the resolved variables List <IVariable> resolved = tacnyProgram.GetResolvedVariables(md); resolved.AddRange(m.Ins); // add input arguments as resolved variables Atomic.ResolveTactic(tacnyProgram.GetTactic(us), us, md, tacnyProgram, variables, resolved, ref sol_list); tacnyProgram.CurrentDebug.Fin(); } catch (Exception e) { return(e.Message); } } } } } solution_list.AddRange(sol_list.plist); return(null); }
private Solution LazyScanMemberBody(MemberDecl md) { Contract.Requires(md != null); Console.WriteLine($"Starting thread: {System.Threading.Thread.CurrentThread.Name}"); Debug.WriteLine($"Scanning member {md.Name} body"); var function = md as Function; if (function != null) { var fun = function; if (fun.Body == null) { return(null); } var expt = ExpressionTree.ExpressionToTree(fun.Body); expt.FindAndResolveTacticApplication(_tacnyProgram, fun); /* No reason ot generate new solution * if nothing has been changed */ if (!expt.Modified) { return(null); } var res = expt.TreeToExpression(); var newFun = new Function(fun.tok, fun.Name, fun.HasStaticKeyword, fun.IsProtected, fun.IsGhost, fun.TypeArgs, fun.Formals, fun.ResultType, fun.Req, fun.Reads, fun.Ens, fun.Decreases, res, fun.Attributes, fun.SignatureEllipsis); var ac = new Atomic { IsFunction = true, DynamicContext = { newTarget = newFun } }; return(new Solution(ac)); } var m = md as Method; if (m?.Body == null) { return(null); } List <IVariable> variables = new List <IVariable>(); List <IVariable> resolved; lock (_tacnyProgram) { resolved = _tacnyProgram.GetResolvedVariables(md); } variables.AddRange(m.Ins); variables.AddRange(m.Outs); resolved.AddRange(m.Ins); // add input arguments as resolved variables resolved.AddRange(m.Outs); // does not work for multiple tactic applications foreach (var st in m.Body.Body) { UpdateStmt us = null; WhileStmt ws = null; // register local variables if (st is VarDeclStmt) { VarDeclStmt vds = st as VarDeclStmt; variables.AddRange(vds.Locals); } else if (st is UpdateStmt) { us = st as UpdateStmt; } else if (st is WhileStmt) { ws = st as WhileStmt; us = ws.TacAps as UpdateStmt; foreach (var wst in ws.Body.Body) { if (!(wst is VarDeclStmt)) { continue; } var vds = wst as VarDeclStmt; variables.AddRange(vds.Locals); } } if (us == null || !_tacnyProgram.IsTacticCall(us)) { continue; } Debug.WriteLine("Tactic call found"); return(ResolveTactic(variables, resolved, us, md, ws)); } return(null); }