public RemovableTypesInMember FindRemovableTypesInSingleMember(MemberDecl member) { IdentifyModule(Program.DefaultModuleDef); ClassDecl classDecl = FindClassOfMember(member); FindRemovableTypesInMember(member, classDecl); return _allRemovableTypes.RemovableTypesInMethods[member]; }
public TacticErrorReportingResolver(Tacny.CompoundErrorInformation errorInfo) { Contract.Ensures(_errTok != null); Contract.Ensures(_errMessage != null); Contract.Ensures(_tacticCall != null); Contract.Ensures(_activeTactic != null); Contract.Ensures(_callingMember != null); Contract.Ensures(_tmpFailingMember != null); Contract.Ensures(!string.IsNullOrEmpty(_implTargetName)); var proofState = errorInfo.S; var tmpProgram = ((Tacny.CompoundErrorInformation)errorInfo.E).P; var innerError = ((Tacny.CompoundErrorInformation)errorInfo.E).E; var tmpModule = (DefaultClassDecl)tmpProgram.DefaultModuleDef.TopLevelDecls.FirstOrDefault(); _errTok = (Bpl.Token)innerError.Tok; _errMessage = innerError.FullMsg; _implTargetName = MethodNameFromImpl(innerError.ImplementationName); _tacticCall = proofState.TacticApplication; _activeTactic = proofState.GetTactic(_tacticCall) as Tactic; _callingMember = proofState.TargetMethod; _tmpFailingMember = tmpModule?.Members.FirstOrDefault(x => x.CompileName == _implTargetName); FailingLine = FailingCol = TacticLine = TacticCol = CallingLine = CallingCol = -1; if(!ActiveTacticWasNotUsed()) ResolveCorrectLocations(); }
public StaticContext(MemberDecl md, UpdateStmt tac_call, Program program) : base(md, tac_call) { this.program = program; foreach (DatatypeDecl tld in program.Globals) { datatypes.Add(tld.Name, tld); } }
private Solution Postcond(Statement st) { IVariable lv = null; List <Expression> callArgs; // we don't care about this List <Expression> ensures = new List <Expression>(); InitArgs(st, out lv, out callArgs); Contract.Assert(lv != null, Error.MkErr(st, 8)); Contract.Assert(callArgs.Count <= 1, Error.MkErr(st, 0, 0, callArgs.Count)); MemberDecl memberDecl = null; if (callArgs.Count > 0) { foreach (var member in ResolveExpression(callArgs[0])) { memberDecl = member as MemberDecl; if (memberDecl == null) { Contract.Assert(false, Error.MkErr(st, 1, "Function, [Ghost] Method, Declaration")); } break; } } else { memberDecl = StaticContext.md; } Function fun = memberDecl as Function; if (fun != null) { foreach (var req in fun.Ens) { ensures.Add(Util.Copy.CopyExpression(req)); } } else { Method method = memberDecl as Method; if (method != null) { foreach (var req in method.Ens) { ensures.Add(Util.Copy.CopyExpression(req.E)); } } else { Contract.Assert(false, Error.MkErr(st, 1, "Function, [Ghost] Method, Declaration")); } } return(AddNewLocal(lv, ensures)); }
public ASTMemberNode(MemberDecl Member, ASTNode parent) : base(parent) { if (Member is Field) { Flags = Flags | ASTFlag.FIELD; Var = Member; } this.Member = Member; initHeight(); }
public static Tactic CopyTactic(MemberDecl md) { Tactic oldTac = md as Tactic; if (oldTac == null) { return(null); } return(CopyTactic(oldTac)); }
public static Method CopyMethod(MemberDecl md) { Method oldMd = md as Method; if (oldMd == null) { return(null); } return(CopyMethod(oldMd)); }
public static CoLemma CopyCoLemma(MemberDecl md) { CoLemma oldCl = md as CoLemma; if (oldCl == null) { return(null); } return(CopyCoLemma(oldCl)); }
public DynamicContext(MemberDecl md, ITactic tac, UpdateStmt tac_call) : base(md, tac_call) { tactic = tac; if (tactic is Tactic) { var tmp = tactic as Tactic; tacticBody = new List<Statement>(tmp.Body.Body.ToArray()); } tacCounter = 0; FillTacticInputs(); }
private ClassDecl FindClassOfMember(MemberDecl memberDecl) { foreach (var classDict in _allMethods.Values) { foreach (var classDecl in classDict.Keys) { if(classDict[classDecl].Contains(memberDecl)) return classDecl; } } throw new Exception("Failed to find class!"); }
public static List<Statement> FindSingleTactic(Program program, MemberDecl target, UpdateStmt chosenTacticCall, ErrorReporterDelegate erd, Program unresolvedProgram) { Contract.Requires(program != null); Contract.Requires(target != null); var i = new Interpreter(program, unresolvedProgram); _errorReporterDelegate = erd; var list = i.FindSingleTacticApplication(target, chosenTacticCall); _errorReporterDelegate = null; return list; }
public static Lemma CopyLemma(MemberDecl md) { Lemma oldLm = md as Lemma; if (oldLm == null) { return(null); } return(CopyLemma(oldLm)); }
public bool NextMemberInTld() { var isMore = _tldMembers.MoveNext(); if (!isMore) { return(false); } _member = _tldMembers.Current; _tacticCalls = RefactoringUtil.GetTacticCallsInMember(_member as Method); return(true); }
public DynamicContext(MemberDecl md, ITactic tac, UpdateStmt tac_call) : base(md, tac_call) { tactic = tac; if (tactic is Tactic) { var tmp = tactic as Tactic; tacticBody = new List <Statement>(tmp.Body.Body.ToArray()); } tacCounter = 0; FillTacticInputs(); }
public static List <Statement> FindSingleTactic(Program program, MemberDecl target, UpdateStmt chosenTacticCall, ErrorReporterDelegate erd, Program unresolvedProgram) { Contract.Requires(program != null); Contract.Requires(target != null); var i = new Interpreter(program, unresolvedProgram); _errorReporterDelegate = erd; var list = i.FindSingleTacticApplication(target, chosenTacticCall); _errorReporterDelegate = null; return(list); }
public static void SetVerifyFalseAttr(MemberDecl memb) { var args = new List <Expression>(); var f = new Microsoft.Dafny.LiteralExpr(new Token(TacnyDriver.TacticCodeTokLine, 0) { val = "false" }, false); args.Add(f); Attributes newattr = new Attributes("verify", args, memb.Attributes); memb.Attributes = newattr; }
public void SetCurrent(ITactic tac, MemberDecl md) { Contract.Requires(tac != null); Contract.Requires(md != null); var dd = DebugDataList.LastOrDefault(i => i.Tactic == tac.Name && i.Method == md.Name); if (dd == null) { dd = new DebugData(tac.Name, md.Name); DebugDataList.Add(dd); } CurrentDebug = dd; }
public static void SetVerifyFalseAttr(MemberDecl memb) { var args = new List <Expression>(); var f = new Microsoft.Dafny.LiteralExpr(new Token(Interpreter.TACNY_CODE_TOK_LINE, 0) { val = "false" }, false); args.Add(f); Attributes newattr = new Attributes("verify", args, memb.Attributes); memb.Attributes = newattr; }
private ClassDecl FindClassOfMember(MemberDecl memberDecl) { foreach (var classDict in _allMethods.Values) { foreach (var classDecl in classDict.Keys) { if (classDict[classDecl].Contains(memberDecl)) { return(classDecl); } } } throw new Exception("Failed to find class!"); }
public static MemberDecl FindAndApplyTactic(Program program, MemberDecl target, ErrorReporterDelegate erd, Program unresolvedProgram = null) { Contract.Requires(program != null); Contract.Requires(target != null); // TODO Re-Enable with more permanent solution // Currently, if the interpreter is the same, static across calls, each time the interpreter is // needed, it will just re-use the previous proof states, frames etc. Which will likely cause // problems in the extension, where it is called many times consecutively. //if (_i == null) { _i = new Interpreter(program, unresolvedProgram); //} _errorReporterDelegate = erd; var result = _i.FindTacticApplication(target); _errorReporterDelegate = null; return result; }
/* * public static Program GenerateDafnyProgram(ProofState state, List<MemberDecl> newMembers) { * var prog = state.GetDafnyProgram(); * var tld = prog.DefaultModuleDef.TopLevelDecls.FirstOrDefault(x => x.Name == state.TargetMethod.EnclosingClass.Name) as ClassDecl; * Contract.Assert(tld != null); * var member = tld.Members.FirstOrDefault(x => x.Name == state.TargetMethod.Name); * Contract.Assert(member != null); * // we can safely remove the tactics * tld.Members.RemoveAll(x => x is Tactic); //remove before else index will be wrong * int index = tld.Members.IndexOf(member); * tld.Members.RemoveAt(index); * tld.Members.InsertRange(index, newMembers); * var filePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName()); * var tw = new StreamWriter(filePath); * var printer = new Printer(tw); * printer.PrintTopLevelDecls(prog.DefaultModuleDef.TopLevelDecls, 0, filePath); * tw.Close(); * string err = Parse(files, programName, prog.reporter, out program); * * Parser.ParseOnly(new List<string>() { filePath}, prog.Name, out prog); * return prog; * } */ public static string FreshMemberName(MemberDecl original, List <MemberDecl> context) { Contract.Requires <ArgumentNullException>(original != null, "original"); Contract.Requires <ArgumentNullException>(context != null, "context"); int count = context.Count(m => m.Name == original.Name); string name = $"{original.Name}_{count}"; while (count != 0) { name = $"{original.Name}_{count}"; count = context.Count(m => m.Name == name); } return(name); }
private void FindRemovableTypesInMember(MemberDecl member, ClassDecl classDecl) { if (member is Tactic) { return; } WildCardDecreases wildCardParent = null; // The parent of the current wildCard we are tracking FindDecreasesTypesInMember(member, ref wildCardParent); var method = member as Method; if (method != null) { FindRemovableTypesInMethod(method, wildCardParent, classDecl); } }
public DynamicContext(MemberDecl md, ITactic tac, UpdateStmt tac_call, List<Statement> tac_body, Dictionary<IVariable, object> local_variables, Dictionary<Statement, Statement> updated_statements, int tacCounter, MemberDecl old_target) : base(md, tac_call) { tactic = tac; tacticBody = new List<Statement>(tac_body.ToArray()); List<IVariable> lv_keys = new List<IVariable>(local_variables.Keys); List<object> lv_values = new List<object>(local_variables.Values); localDeclarations = lv_keys.ToDictionary(x => x, x => lv_values[lv_keys.IndexOf(x)]); generatedStatements = updated_statements; this.tacCounter = tacCounter; newTarget = old_target; }
public static MemberDecl FindAndApplyTactic(Program program, MemberDecl target, ErrorReporterDelegate erd, Program unresolvedProgram = null) { Contract.Requires(program != null); Contract.Requires(target != null); // TODO Re-Enable with more permanent solution // Currently, if the interpreter is the same, static across calls, each time the interpreter is // needed, it will just re-use the previous proof states, frames etc. Which will likely cause // problems in the extension, where it is called many times consecutively. //if (_i == null) { _i = new Interpreter(program, unresolvedProgram); //} _errorReporterDelegate = erd; var result = _i.FindTacticApplication(target); _errorReporterDelegate = null; return(result); }
public DynamicContext(MemberDecl md, ITactic tac, UpdateStmt tac_call, List <Statement> tac_body, Dictionary <IVariable, object> local_variables, Dictionary <Statement, Statement> updated_statements, int tacCounter, MemberDecl old_target) : base(md, tac_call) { tactic = tac; tacticBody = new List <Statement>(tac_body.ToArray()); List <IVariable> lv_keys = new List <IVariable>(local_variables.Keys); List <object> lv_values = new List <object>(local_variables.Values); localDeclarations = lv_keys.ToDictionary(x => x, x => lv_values[lv_keys.IndexOf(x)]); generatedStatements = updated_statements; this.tacCounter = tacCounter; newTarget = old_target; }
private List<Statement> FindSingleTacticApplication(MemberDecl target, UpdateStmt chosenTacticCall) { Contract.Requires(tcce.NonNull(target)); _frame = new Stack<Dictionary<IVariable, Type>>(); var method = target as Method; if (method == null) return 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); SearchBlockStmt(method.Body); _frame.Pop(); Contract.Assert(_frame.Count == 0); return (from r in _resultList where r.Key.Tok.pos == chosenTacticCall.Tok.pos select r.Value).FirstOrDefault(); }
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); }
/// <summary> /// Process the declaration's "dllimport" attribute, if any, by emitting the corresponding .NET custom attribute. /// Returns "true" if the declaration has an active "dllimport" attribute; "false", otherwise. /// </summary> public bool ProcessDllImport(MemberDecl decl, TextWriter wr) { Contract.Requires(decl != null); Contract.Requires(wr != null); var dllimportsArgs = Attributes.FindExpressions(decl.Attributes, "dllimport"); if (!DafnyOptions.O.DisallowExterns && dllimportsArgs != null) { StringLiteralExpr libName = null; StringLiteralExpr entryPoint = null; if (dllimportsArgs.Count == 2) { libName = dllimportsArgs[0] as StringLiteralExpr; entryPoint = dllimportsArgs[1] as StringLiteralExpr; } else if (dllimportsArgs.Count == 1) { libName = dllimportsArgs[0] as StringLiteralExpr; // use the given name, not the .CompileName (if user needs something else, the user can supply it as a second argument to :dllimport) entryPoint = new StringLiteralExpr(decl.tok, decl.Name, false); } if (libName == null || entryPoint == null) { Error(decl.tok, "Expected arguments are {{:dllimport dllName}} or {{:dllimport dllName, entryPoint}} where dllName and entryPoint are strings: {0}", wr, decl.FullName); } else if ((decl is Method m && m.Body != null) || (decl is Function f && f.Body != null)) { Error(decl.tok, "A {0} declared with :dllimport is not allowed a body: {1}", wr, decl.WhatKind, decl.FullName); } else if (!decl.IsStatic) { Error(decl.tok, "A {0} declared with :dllimport must be static: {1}", wr, decl.WhatKind, decl.FullName); } else { wr.Write("[System.Runtime.InteropServices.DllImport("); TrStringLiteral(libName, wr); wr.Write(", EntryPoint="); TrStringLiteral(entryPoint, wr); wr.WriteLine(")]"); } return(true); }
/// <summary> /// /// </summary> /// <param name="program"></param> /// <param name="target"></param> /// <param name="erd"></param> /// only used this to report error, local errors which are genereaed during searching should not use this /// <param name="r"></param> /// <returns></returns> public static MemberDecl FindAndApplyTactic(Program program, MemberDecl target, ErrorReporterDelegate erd, Resolver r = null) { Contract.Requires(program != null); Contract.Requires(target != null); Stopwatch watch = new Stopwatch(); watch.Start(); _i = new Interpreter(program); _errorReporterDelegate = erd; var result = _i.EvalTacticApplication(target, r); var p = new Printer(Console.Out); p.PrintMembers(new List<MemberDecl>() { result }, 0, ""); watch.Stop(); Console.WriteLine("Time Used: " + watch.Elapsed.TotalSeconds.ToString()); _errorReporterDelegate = null; return result; }
/// <summary> /// Remove unresolved tactic calls from the program /// </summary> /// <param name="md"></param> /// <param name="program">Dafny Program</param> public void ClearBody(MemberDecl md, Microsoft.Dafny.Program program) { foreach (var item in program.DefaultModuleDef.TopLevelDecls) { var cd = item as ClassDecl; if (cd == null) { continue; } foreach (var member in cd.Members) { var m = member as Method; if (m != null && m.Name != md.Name) { m.Body = null; } } } }
private void FindDecreasesTypesInMember(MemberDecl member, ref WildCardDecreases wildCardParent) { Specification <Expression> decreases = null; if (member is Method) { var method = (Method)member; decreases = method.Decreases; } else if (member is Function) { var function = (Function)member; decreases = function.Decreases; } if (decreases != null) { FindDecreasesTypesInMethodFunction(decreases, ref wildCardParent, member); } }
private MemberDecl EvalTacticApplication(MemberDecl target, Resolver r) { Contract.Requires(tcce.NonNull(target)); // initialize new stack for variables _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 pre_res = _resultList.Keys.Copy(); SearchBlockStmt(method.Body); dict = _frame.Pop(); // sanity check Contract.Assert(_frame.Count == 0); var new_rets = _resultList.Where(kvp => !pre_res.Contains(kvp.Key)).ToDictionary(i => i.Key, i => i.Value); Contract.Assert(new_rets.Count != 0); var body = Util.InsertCode(_state, new_rets); method.Body.Body.Clear(); if (body != null) { method.Body.Body.AddRange(body.Body); } // use the original resolver of the resoved program, as it contains all the necessary type info //TODO: how about pre and post ?? method.CallsTactic = false; // set the tactic call lable to be false, no actual consequence // set the current class in the resolver, so that it can refer to the memberdecl correctly r.SetCurClass(method.EnclosingClass as ClassDecl); r.ResolveMethodBody(method); //Console.WriteLine("Errors: " + _program.reporter.Count(ErrorLevel.Error)); } return(method); }
public virtual void Visit(MemberDecl memberDeclaration) { switch (memberDeclaration) { case Field field: Visit(field); break; case Function function: Visit(function); break; case Method method: Visit(method); break; default: VisitUnknown(memberDeclaration, memberDeclaration.tok); break; } }
// @TODO this could be optimised to hold the resolved data for all programs public List <IVariable> GetResolvedVariables(MemberDecl md) { ParseProgram(); ClearBody(md); RemoveTactics(DafnyProgram); ResolveProgram(); List <IVariable> result = null; foreach (var item in DafnyProgram.DefaultModuleDef.TopLevelDecls) { var cd = item as ClassDecl; if (cd == null) { continue; } foreach (var member in cd.Members) { var m = member as Method; if (m == null) { continue; } if (m.Name != md.Name) { continue; } result = new List <IVariable>(); foreach (var stmt in m.Body.Body) { var vds = stmt as VarDeclStmt; if (vds == null) { continue; } result.AddRange(vds.Locals.Where(local => local.Type != null)); } } } return(result); }
private Symbol?ProcessClassMember(ClassSymbol scope, MemberDecl memberDeclaration) { _cancellationToken.ThrowIfCancellationRequested(); switch (memberDeclaration) { case Function function: return(ProcessFunction(scope, function)); case Method method: // TODO handle the constructors explicitely? The constructor is a sub-class of Method. return(ProcessMethod(scope, method)); case Field field: return(ProcessField(scope, field)); default: // TODO The last missing member is AmbiguousMemberDecl which is created by the resolver. // When is this class exactly used? _logger.LogWarning("encountered unknown class member declaration {}", memberDeclaration.GetType()); return(null); } }
private List <Statement> FindSingleTacticApplication(MemberDecl target, UpdateStmt chosenTacticCall) { Contract.Requires(tcce.NonNull(target)); _frame = new Stack <Dictionary <IVariable, Type> >(); var method = target as Method; if (method == null) { return(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); SearchBlockStmt(method.Body); _frame.Pop(); Contract.Assert(_frame.Count == 0); return((from r in _resultList where r.Key.Tok.pos == chosenTacticCall.Tok.pos select r.Value).FirstOrDefault()); }
private void WriteExternal(MemberDecl lident, List<Tuple<Type, string>> typeList) { if (typeList.Count == 1 && typeList[0].Item1 == null) { // The typeList is just TUnit, so there are no inputs and no outputs. return; } using (WriteArray()) { j.WriteValue(KremlinAst.DExternal); using (WriteArray()) { // of (CallingConvention.t option * lident * typ) WriteDefaultCallingConvention(); WriteLident(lident); // lident if (typeList.Count > 1) { for (int i = 0; i < typeList.Count - 1; ++i) { j.WriteStartArray(); j.WriteValue(KremlinAst.TArrow); j.WriteStartArray(); // of (typ * typ) j.WriteComment(typeList[i].Item2); WriteTypeName(typeList[i].Item1); } } Type finalType = typeList[typeList.Count - 1].Item1; if (finalType == null) { WriteTUnit(); } else { WriteTypeName(finalType); } for (int i = 0; i < typeList.Count - 1; ++i) { j.WriteEndArray(); j.WriteEndArray(); } } } }
public static string SimpleSanitizedName(MemberDecl m) { return SimpleName(SanitizedName(m)); }
public static string SanitizedName(MemberDecl m) { return /* m.EnclosingClass.FullSanitizedName + "." + */ NonglobalVariable.CompilerizeName(m.Name.Replace("#", "&")).Replace("&", "#"); }
public bool NextMemberInTld() { var isMore = _tldMembers.MoveNext(); if (!isMore) return false; _member = _tldMembers.Current; _tacticCalls = RefactoringUtil.GetTacticCallsInMember(_member as Method); return true; }
public static MemberDecl CopyMember(MemberDecl md) { Contract.Requires(md != null); Cloner cl = new Cloner(); return cl.CloneMember(md); }
public static Tactic CopyTactic(MemberDecl md) { Tactic oldTac = md as Tactic; if (oldTac == null) return null; return CopyTactic(oldTac); }
public static Method CopyMethod(MemberDecl md) { Method oldMd = md as Method; if (oldMd == null) return null; return CopyMethod(oldMd); }
public static Lemma CopyLemma(MemberDecl md) { Lemma oldLm = md as Lemma; if (oldLm == null) return null; return CopyLemma(oldLm); }
public MemberDecl CloneMember(MemberDecl member) { if (member is Field) { Contract.Assert(!(member is SpecialField)); // we don't expect a SpecialField to be cloned (or do we?) var f = (Field)member; return new Field(Tok(f.tok), f.Name, f.IsGhost, f.IsMutable, f.IsUserMutable, CloneType(f.Type), CloneAttributes(f.Attributes)); } else if (member is Function) { var f = (Function)member; return CloneFunction(f); } else { var m = (Method)member; return CloneMethod(m); } }
public StaticContext(MemberDecl md, UpdateStmt tac_call, Program program) : base(md, tac_call) { this.program = program; foreach (DatatypeDecl tld in program.Globals) datatypes.Add(tld.Name, tld); }
private void WriteLident(MemberDecl d) { WriteLident(d.FullName); }
private Solution ResolveTactic(List<IVariable> variables, List<IVariable> resolved, UpdateStmt us, MemberDecl md, WhileStmt ws = null) { try { var prog = Util.ObjectExtensions.Copy(_tacnyProgram); var result = Atomic.ResolveTactic(us, md, prog, variables, resolved, ws); prog.PrintDebugData(prog.CurrentDebug); return result; } catch (Exception e) { Printer.Error(e.Message); return null; } }
private void FindDecreasesTypesInMethodFunction(Specification<Expression> decreases, ref WildCardDecreases wildCardParent, MemberDecl member) { foreach (var expression in decreases.Expressions) { if (expression is WildcardExpr) { wildCardParent = new WildCardDecreases(expression, decreases, null); _allRemovableTypes.AddWildCardDecreases(wildCardParent, (Method) member); continue; } _allRemovableTypes.AddDecreases(new Wrap<Expression>(expression, decreases.Expressions), member); } }
public void AddDefaultClassDecl(MemberDecl d) { newDefaultClassDecls.Add(d); }
public Context(MemberDecl md, UpdateStmt tac_call) { Contract.Requires(md != null && tac_call != null); this.md = md; this.tac_call = tac_call; }
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; }
public static CoLemma CopyCoLemma(MemberDecl md) { CoLemma oldCl = md as CoLemma; if (oldCl == null) return null; return CopyCoLemma(oldCl); }
private MemberDecl FindTacticApplication(MemberDecl target) { Contract.Requires(tcce.NonNull(target)); // initialize new stack for variables _frame = new Stack<Dictionary<IVariable, Type>>(); // clean up the result list _resultList.Clear(); 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); SearchBlockStmt(method.Body); dict = _frame.Pop(); // sanity check Contract.Assert(_frame.Count == 0); _state.ResultCache.Add(new ProofState.TacticCache(method?.Name, _resultList.Copy())); var body = Util.InsertCode(_state, _resultList); method.Body.Body.Clear(); if (body != null) method.Body.Body.AddRange(body.Body); } return method; }
public void AddDefaultClassDecl(MemberDecl d, string auxName = null) { LookupFile(auxName).AddDefaultClassDecl(d); }
public static SnapshotSpan GetRangeOfMember(ITextSnapshot snap, MemberDecl m) => new SnapshotSpan(snap, m.tok.pos, m.BodyEndTok.pos - m.tok.pos);
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); }
public static TacticReplaceStatus GetMemberFromPosition(DefaultClassDecl tld, int position, out MemberDecl member) { Contract.Requires(tld != null); member = GetMemberFromPosition(tld, position); return member == null ? TacticReplaceStatus.NoTactic : TacticReplaceStatus.Success; }
private static bool IsLemma(MemberDecl m){ return (m is Lemma || m is FixpointLemma); }
private void FindRemovableTypesInMember(MemberDecl member, ClassDecl classDecl) { if (member is Tactic) return; WildCardDecreases wildCardParent = null; // The parent of the current wildCard we are tracking FindDecreasesTypesInMember(member, ref wildCardParent); var method = member as Method; if (method != null) FindRemovableTypesInMethod(method, wildCardParent, classDecl); }