public static MemberDecl ApplyTacticInMethod(Program program, MemberDecl target, ErrorReporterDelegate erd, Resolver r = null, Program raw = null) { Contract.Requires(program != null); Contract.Requires(target != null); Stopwatch watch = new Stopwatch(); watch.Start(); _driver = new TacnyDriver(program, erd); // backup datatype info, as this will be reset by the internal resolving process in tacny. // this contains datatype obj instance for comparing types Type.BackupScopes(); var result = _driver.InterpretAndUnfoldTactic(target, r); Type.RestoreScopes(); var p = new Printer(Console.Out); p.PrintMembers(new List <MemberDecl>() { result }, 0, ""); watch.Stop(); Console.WriteLine("Time Used: " + watch.Elapsed.TotalSeconds); _errorReporterDelegate = null; return(result); }
public bool IsTimeOut() { var top = _scope.Peek(); if (top.FrameCtrl.TimeStamp != 0 && top.FrameCtrl.TimeStamp <= TacnyDriver.GetTimer().Elapsed.Seconds) { return(true); } return(false); }
public static Program GenerateResolvedProg(ProofState state) { var prog = state.GetDafnyProgram(); var result = TacnyDriver.GetResultList().Where( kvp => kvp.Key.Tok.pos != state.TopLevelTacApp.Tok.pos).ToDictionary(c => c.Key, c => c.Value); result.Add(state.TopLevelTacApp, state.GetGeneratedCode().Copy()); var body = InsertCode(state, result); Method destMd = null; DefaultClassDecl defaultClassDecl = null; foreach (var m in prog.DefaultModuleDef.TopLevelDecls) { if (m.WhatKind == "class") { var classDecl = m as DefaultClassDecl; if (classDecl != null) { foreach (var method in classDecl.Members) { if (method.Name == state.TargetMethod.Name) { destMd = (method as Method); defaultClassDecl = classDecl; } else if (!(method is Tactic)) { method.CallsTactic = 0; var o = method as Method; if (o != null && o.Body != null) { o?.Body.Body.Clear(); } SetVerifyFalseAttr(method); } } } } } destMd.CallsTactic = 0; destMd.Body.Body.Clear(); destMd.Body.Body.AddRange(body.Body); var r = new Resolver(prog); r.ResolveProgram(prog); if (prog.reporter.Count(ErrorLevel.Error) != 0) { state.GetErrHandler().Reporter = prog.reporter; #if _TACTIC_DEBUG_L1 Console.Write("Fail to resolve prog, skip verifier ! \n"); #endif return(null); } else { return(prog); } }
/// <summary> /// an optimised version for verifying prog /// </summary> /// <param name="states"></param> /// <returns></returns> public static Program GenerateResolvedProg(List <ProofState> states) { var state = states[0]; var prog = states[0].GetDafnyProgram(); List <BlockStmt> bodies = new List <BlockStmt>(); for (var i = 0; i < states.Count; i++) { var state0 = states[i]; var result = TacnyDriver.GetResultList().Where( kvp => kvp.Key.Tok.pos != state0.TopLevelTacApp.Tok.pos).ToDictionary(c => c.Key, c => c.Value); result.Add(state0.TopLevelTacApp, state0.GetGeneratedCode().Copy()); var body0 = InsertCode(state0, result); SetStatementTokLine(TacnyDriver.TacticCodeTokLine - i - 1, body0); SetStatementName(body0, state0.TargetMethod.Name, state0.TargetMethod.Name + "_tacny_code_" + i); bodies.Add(body0); } Method destMd = null; DefaultClassDecl defaultClassDecl = null; var body = bodies[0]; foreach (var m in prog.DefaultModuleDef.TopLevelDecls) { if (m.WhatKind == "class") { var classDecl = m as DefaultClassDecl; if (classDecl != null) { foreach (var method in classDecl.Members) { if (method.Name == state.TargetMethod.Name) { destMd = (method as Method); defaultClassDecl = classDecl; } else if (!(method is Tactic)) { method.CallsTactic = 0; var o = method as Method; if (o != null && o.Body != null) { o?.Body.Body.Clear(); } SetVerifyFalseAttr(method); } } } } } for (var i = 0; i < bodies.Count - 1; i++) { var dest = destMd.Copy(); dest.CallsTactic = 0; dest.Body.Body.Clear(); dest.Body.Body.AddRange(bodies[i].Body); dest.Name = dest.Name + "_tacny_code_" + i; defaultClassDecl.Members.Add(dest); dest.Body.Tok.line = TacnyDriver.TacticCodeTokLine - i - 1; } destMd.CallsTactic = 0; destMd.Body.Body.Clear(); destMd.Body.Body.AddRange(bodies[bodies.Count - 1].Body); destMd.Name = destMd.Name + "_tacny_code_" + (bodies.Count - 1); destMd.Body.Tok.line = TacnyDriver.TacticCodeTokLine - bodies.Count; var r = new Resolver(prog); r.ResolveProgram(prog); return(prog); }