/// <summary> /// Return the string signature of an UpdateStmt /// </summary> /// <param name="us"></param> /// <returns></returns> public static string GetSignature(UpdateStmt us) { Contract.Requires <ArgumentNullException>(Tcce.NonNull(us)); Contract.Ensures(Contract.Result <string>() != null); var er = us.Rhss[0] as ExprRhs; Contract.Assert(er != null); return(GetSignature(er.Expr as ApplySuffix)); }
private bool IsTacticCall(string name) { Contract.Requires(Tcce.NonNull(name)); if (name == null) { return(false); } return(Tactics.ContainsKey(name)); }
/// <summary> /// Return Dafny key /// </summary> /// <param name="key">Variable name</param> /// <returns>bool</returns> /// <exception cref="KeyNotFoundException">Variable does not exist in the current context</exception> public IVariable GetDafnyVar(string key) { Contract.Requires <ArgumentNullException>(Tcce.NonNull(key)); Contract.Ensures(Contract.Result <IVariable>() != null); if (ContainDafnyVar(key)) { return(_scope.Peek().GetDafnyVariableData(key).Variable); } throw new KeyNotFoundException($"Dafny variable {key} does not exist in the current context"); }
/// <summary> /// Return the type of the key /// </summary> /// <param name="key">name of the key</param> /// <returns>null if type is not known</returns> /// <exception cref="KeyNotFoundException">Variable does not exist in the current context</exception> public Dfy.Type GetDafnyVarType(string key) { Contract.Requires <ArgumentNullException>(Tcce.NonNull(key)); Contract.Ensures(Contract.Result <Dfy.Type>() != null); if (ContainDafnyVar(key)) { return(GetDafnyVar(key).Type); } throw new KeyNotFoundException($"Dafny variable {key} does not exist in the current context"); }
private TacnyDriver(Program program, ErrorReporterDelegate erd) { Contract.Requires(Tcce.NonNull(program)); // initialize state GetTimer().Restart(); _state = new ProofState(program); _errorReporterDelegate = erd; _branches = new List <IEnumerable <ProofState> >(); _tacticCalls = 0; }
private MemberDecl InterpretAndUnfoldTactic(MemberDecl target, Resolver r) { Contract.Requires(Tcce.NonNull(target)); // initialize new stack for variables var frame = new Stack <Dictionary <IVariable, Type> >(); var method = target as Method; if (method != null) { _state.SetTopLevelClass(method.EnclosingClass?.Name); _state.TargetMethod = target; var dict = method.Ins.Concat(method.Outs) .ToDictionary <IVariable, IVariable, Type>(item => item, item => item.Type); frame.Push(dict); var preRes = GetResultList().Keys.Copy(); InterpertBlockStmt(method.Body, frame); GenerateResultCode(); // sanity check Contract.Assert(frame.Count == 0); var newRets = GetResultList().Where(kvp => !preRes.Contains(kvp.Key)).ToDictionary(i => i.Key, i => i.Value); Contract.Assert(newRets.Count != 0); var body = Util.InsertCode(_state, newRets); method.Body.Body.Clear(); if (newRets.Count != 0 && body != null) { method.Body.Body.AddRange(body.Body); } // use the original resolver of the resoved program, as it contains all the necessary type info method.CallsTactic = 0; // set the current class in the resolver, so that it can refer to the memberdecl correctly r.SetCurClass(method.EnclosingClass as ClassDecl); //asssume the defualt module is the current module, this needs to be improved. r.ResolveMethodBody(method, _state.GetDafnyProgram().DefaultModuleDef.Name); //Console.WriteLine("Errors: " + _program.reporter.Count(ErrorLevel.Error)); } return(method); }
private void InterpretIfStmt(IfStmt ifStmt, Stack <Dictionary <IVariable, Type> > frame) { Contract.Requires(Tcce.NonNull(ifStmt)); //throw new NotImplementedException(); InterpertBlockStmt(ifStmt.Thn, frame); if (ifStmt.Els == null) { return; } var els = ifStmt.Els as BlockStmt; if (els != null) { InterpertBlockStmt(els, frame); } else if (ifStmt.Els is IfStmt) { InterpretIfStmt((IfStmt)ifStmt.Els, frame); } }
public static string GetSignature(ApplySuffix aps) { Contract.Requires <ArgumentNullException>(Tcce.NonNull(aps)); Contract.Ensures(Contract.Result <string>() != null); return(aps?.Lhs.tok.val); }
/// <summary> /// Add new dafny stmt to the top frame /// </summary> /// <param name="stmtList"></param> public void AddStatements(List <Statement> stmtList) { Contract.Requires <ArgumentNullException>(Tcce.NonNullElements(stmtList)); _scope.Peek().FrameCtrl.AddGeneratedCode(stmtList); }
/// <summary> /// Return the type of the key /// </summary> /// <param name="variable">key</param> /// <returns>null if type is not known</returns> /// <exception cref="KeyNotFoundException">Variable does not exist in the current context</exception> public Dfy.Type GetDafnyVarType(IVariable variable) { Contract.Requires <ArgumentNullException>(Tcce.NonNull(variable)); Contract.Ensures(Contract.Result <Dfy.Type>() != null); return(GetDafnyVarType(variable.Name)); }
/// <summary> /// Return Dafny key /// </summary> /// <param name="key">Variable name</param> /// <returns>bool</returns> /// <exception cref="KeyNotFoundException">Variable does not exist in the current context</exception> public IVariable GetDafnyVar(NameSegment key) { Contract.Requires <ArgumentNullException>(Tcce.NonNull(key)); Contract.Ensures(Contract.Result <IVariable>() != null); return(GetDafnyVar(key.Name)); }
/// <summary> /// Check if Dafny key exists in the current context /// </summary> /// <param name="key">Variable</param> /// <returns>bool</returns> public bool ContainDafnyVar(NameSegment key) { Contract.Requires <ArgumentNullException>(Tcce.NonNull(key)); return(ContainDafnyVar(key.Name)); }
/// <summary> /// Check if Dafny key exists in the current context /// </summary> /// <param name="key">Variable name</param> /// <returns>bool</returns> public bool ContainDafnyVar(string key) { Contract.Requires <ArgumentNullException>(Tcce.NonNull(key)); return(_scope.Peek().ContainDafnyVar(key)); }
// Find tactic application and resolve it private void InterpertBlockStmt(BlockStmt body, Stack <Dictionary <IVariable, Type> > frame) { Contract.Requires(Tcce.NonNull(body)); InterpertBlockStmt(body.Body, frame); }
public static IEnumerable <ProofState> EvalTopLevelTactic(ProofState state, Dictionary <IVariable, Type> variables, Statement tacticApplication, ApplySuffix aps, ErrorReporterDelegate errorDelegate, bool ifPartial) { Contract.Requires <ArgumentNullException>(Tcce.NonNull(variables)); Contract.Requires <ArgumentNullException>(Tcce.NonNull(tacticApplication)); Contract.Requires <ArgumentNullException>(state != null, "state"); Contract.Requires(tacticApplication == null || tacticApplication is UpdateStmt || tacticApplication is InlineTacticBlockStmt); IEnumerable <ProofState> branches; if (state.InitState(tacticApplication, aps, variables, ifPartial) == false) { return(null); } #if !TACNY_DEBUG try { #endif if (state.GetErrHandler().Reporter.Count(ErrorLevel.Error) != 0) { var errs = CompoundErrorInformation.GenerateErrorInfoList(state); if (errorDelegate != null) { foreach (var err in errs) { errorDelegate(err); } } return(null); } branches = GenerateSolution(state, errorDelegate); #if !TACNY_DEBUG } catch (Exception e) { String msg; List <CompoundErrorInformation> errs; try { msg = "Tactic unknown exception: " + e.Message; errs = CompoundErrorInformation.GenerateErrorInfoList(state, msg); } catch (Exception) { msg = "Tactic exception"; errs = new List <CompoundErrorInformation>(); } if (errorDelegate != null) { foreach (var err in errs) { errorDelegate(err); } } return(null); } #endif return(branches); }