public void AddProcedure(DeclWithFormals proc) { Contract.Requires(proc != null); Contract.Requires(proc.Name != null); string name = proc.Name; var previous = (DeclWithFormals)funcdures[name]; if (previous == null) { funcdures.Add(name, proc); } else { var r = (DeclWithFormals)SelectNonExtern(proc, previous); if (r == null) { Error(proc, "more than one declaration of function/procedure name: {0}", name); } else { funcdures[name] = r; } } }
public override Function VisitFunction(Function node) { currentDeclaration = node; if (node.DefinitionAxiom != null) { VisitAxiom(node.DefinitionAxiom); } if (node.OtherDefinitionAxioms != null) { foreach (var a in node.OtherDefinitionAxioms) { if (a != node.DefinitionAxiom) { VisitAxiom(a); } } } var result = base.VisitFunction(node); node.DependenciesCollected = true; currentDeclaration = null; return result; }
public override DeclWithFormals VisitDeclWithFormals(DeclWithFormals node) { //Contract.Requires(node != null); Contract.Ensures(Contract.Result<DeclWithFormals>() != null); return base.VisitDeclWithFormals((DeclWithFormals)node.Clone()); }
public override Procedure VisitProcedure(Procedure node) { currentDeclaration = node; foreach (var param in node.InParams) { if (param.TypedIdent != null && param.TypedIdent.WhereExpr != null) { VisitExpr(param.TypedIdent.WhereExpr); } } var result = base.VisitProcedure(node); node.DependenciesCollected = true; currentDeclaration = null; return result; }
public override Implementation VisitImplementation(Implementation node) { currentDeclaration = node; foreach (var param in node.InParams) { if (param.TypedIdent != null && param.TypedIdent.WhereExpr != null) { VisitExpr(param.TypedIdent.WhereExpr); } } if (node.Proc != null) { node.AddProcedureDependency(node.Proc); } var result = base.VisitImplementation(node); node.DependenciesCollected = true; currentDeclaration = null; return result; }
public override DeclWithFormals VisitDeclWithFormals(DeclWithFormals node) { if (node.TypeParameters.Count > 0) isMonomorphic = false; return base.VisitDeclWithFormals(node); }
public override DeclWithFormals VisitDeclWithFormals(DeclWithFormals node) { Contract.Ensures(Contract.Result<DeclWithFormals>() == node); this.VisitVariableSeq(node.InParams); this.VisitVariableSeq(node.OutParams); return node; }
public virtual DeclWithFormals VisitDeclWithFormals(DeclWithFormals node) { Contract.Requires(node != null); Contract.Ensures(Contract.Result<DeclWithFormals>() != null); node.InParams = this.VisitVariableSeq(node.InParams); node.OutParams = this.VisitVariableSeq(node.OutParams); return node; }
protected DeclWithFormals(DeclWithFormals that) : base(that.tok, cce.NonNull(that.Name)) { Contract.Requires(that != null); this.TypeParameters = that.TypeParameters; this.InParams = that.InParams; this.OutParams = that.OutParams; }
private void CreateYieldCheckerImpl(DeclWithFormals decl, List<List<Cmd>> yields, Dictionary<Variable, Expr> map) { if (yields.Count == 0) return; Program program = linearTypeChecker.program; List<Variable> locals = new List<Variable>(); List<Variable> inputs = new List<Variable>(); foreach (IdentifierExpr ie in map.Values) { locals.Add(ie.Decl); } for (int i = 0; i < decl.InParams.Count - linearTypeChecker.linearDomains.Count; i++) { Variable inParam = decl.InParams[i]; Variable copy = new LocalVariable(Token.NoToken, new TypedIdent(Token.NoToken, inParam.Name, inParam.TypedIdent.Type)); locals.Add(copy); map[decl.InParams[i]] = new IdentifierExpr(Token.NoToken, copy); } { int i = decl.InParams.Count - linearTypeChecker.linearDomains.Count; foreach (string domainName in linearTypeChecker.linearDomains.Keys) { Variable inParam = decl.InParams[i]; Variable copy = new Formal(Token.NoToken, new TypedIdent(Token.NoToken, inParam.Name, inParam.TypedIdent.Type), true); inputs.Add(copy); map[decl.InParams[i]] = new IdentifierExpr(Token.NoToken, copy); i++; } } for (int i = 0; i < decl.OutParams.Count; i++) { Variable outParam = decl.OutParams[i]; var copy = new LocalVariable(Token.NoToken, new TypedIdent(Token.NoToken, outParam.Name, outParam.TypedIdent.Type)); locals.Add(copy); map[decl.OutParams[i]] = new IdentifierExpr(Token.NoToken, copy); } Dictionary<Variable, Expr> ogOldLocalMap = new Dictionary<Variable, Expr>(); Dictionary<Variable, Expr> assumeMap = new Dictionary<Variable, Expr>(map); foreach (IdentifierExpr ie in globalMods) { Variable g = ie.Decl; var copy = new LocalVariable(Token.NoToken, new TypedIdent(Token.NoToken, string.Format("og_local_old_{0}", g.Name), g.TypedIdent.Type)); locals.Add(copy); ogOldLocalMap[g] = Expr.Ident(copy); Formal f = new Formal(Token.NoToken, new TypedIdent(Token.NoToken, string.Format("og_global_old_{0}", g.Name), g.TypedIdent.Type), true); inputs.Add(f); assumeMap[g] = Expr.Ident(f); } Substitution assumeSubst = Substituter.SubstitutionFromHashtable(assumeMap); Substitution oldSubst = Substituter.SubstitutionFromHashtable(ogOldLocalMap); Substitution subst = Substituter.SubstitutionFromHashtable(map); List<Block> yieldCheckerBlocks = new List<Block>(); List<String> labels = new List<String>(); List<Block> labelTargets = new List<Block>(); Block yieldCheckerBlock = new Block(Token.NoToken, "exit", new List<Cmd>(), new ReturnCmd(Token.NoToken)); labels.Add(yieldCheckerBlock.Label); labelTargets.Add(yieldCheckerBlock); yieldCheckerBlocks.Add(yieldCheckerBlock); int yieldCount = 0; foreach (List<Cmd> cs in yields) { var linearDomains = linearTypeChecker.linearDomains; List<Cmd> newCmds = new List<Cmd>(); foreach (Cmd cmd in cs) { PredicateCmd predCmd = (PredicateCmd)cmd; newCmds.Add(new AssumeCmd(Token.NoToken, Substituter.ApplyReplacingOldExprs(assumeSubst, oldSubst, predCmd.Expr))); } foreach (Cmd cmd in cs) { PredicateCmd predCmd = (PredicateCmd)cmd; var newExpr = Substituter.ApplyReplacingOldExprs(subst, oldSubst, predCmd.Expr); if (predCmd is AssertCmd) newCmds.Add(new AssertCmd(predCmd.tok, newExpr, predCmd.Attributes)); else newCmds.Add(new AssumeCmd(Token.NoToken, newExpr)); } newCmds.Add(new AssumeCmd(Token.NoToken, Expr.False)); yieldCheckerBlock = new Block(Token.NoToken, "L" + yieldCount++, newCmds, new ReturnCmd(Token.NoToken)); labels.Add(yieldCheckerBlock.Label); labelTargets.Add(yieldCheckerBlock); yieldCheckerBlocks.Add(yieldCheckerBlock); } yieldCheckerBlocks.Insert(0, new Block(Token.NoToken, "enter", new List<Cmd>(), new GotoCmd(Token.NoToken, labels, labelTargets))); // Create the yield checker procedure var yieldCheckerName = string.Format("{0}_YieldChecker_{1}", decl is Procedure ? "Proc" : "Impl", decl.Name); var yieldCheckerProc = new Procedure(Token.NoToken, yieldCheckerName, decl.TypeParameters, inputs, new List<Variable>(), new List<Requires>(), new List<IdentifierExpr>(), new List<Ensures>()); yieldCheckerProc.AddAttribute("inline", new LiteralExpr(Token.NoToken, Microsoft.Basetypes.BigNum.FromInt(1))); yieldCheckerProcs.Add(yieldCheckerProc); // Create the yield checker implementation var yieldCheckerImpl = new Implementation(Token.NoToken, yieldCheckerName, decl.TypeParameters, inputs, new List<Variable>(), locals, yieldCheckerBlocks); yieldCheckerImpl.Proc = yieldCheckerProc; yieldCheckerImpl.AddAttribute("inline", new LiteralExpr(Token.NoToken, Microsoft.Basetypes.BigNum.FromInt(1))); yieldCheckerImpls.Add(yieldCheckerImpl); }