private IEnumerable <Variable> AvailableLinearLocalVars(Absy absy) { if (absy is Implementation impl) { return(FilterInParams(absyMap.OriginalOrInput(impl).InParams)); } if (absy is Procedure proc) { return(FilterInParams(absyMap.OriginalOrInput(proc).InParams)); } return(civlTypeChecker.linearTypeChecker.AvailableLinearVars(absyMap[absy]).Where(v => !(v is GlobalVariable) && civlTypeChecker.LocalVariableLayerRange(v).Contains(layerNum))); }
private void DesugarParCallCmdInBlock(Block block, bool isBlockInYieldingLoop) { var parCallCmd = (ParCallCmd)block.Cmds[0]; List <Cmd> newCmds = new List <Cmd>(); if (!isBlockInYieldingLoop) { newCmds.AddRange(refinementInstrumentation.CreateUpdatesToRefinementVars(IsParCallMarked(parCallCmd))); } List <Expr> ins = new List <Expr>(); List <IdentifierExpr> outs = new List <IdentifierExpr>(); string procName = "ParallelCall"; foreach (CallCmd callCmd in parCallCmd.CallCmds) { // Use original procedure names to make aggregated name more readable procName = procName + "_" + absyMap.OriginalOrInput(callCmd.Proc).Name; ins.AddRange(callCmd.Ins); outs.AddRange(callCmd.Outs); } procName = civlTypeChecker.AddNamePrefix(procName) + "_" + layerNum; if (!parallelCallAggregators.ContainsKey(procName)) { List <Variable> inParams = new List <Variable>(); List <Variable> outParams = new List <Variable>(); List <Requires> requiresSeq = new List <Requires>(); List <Ensures> ensuresSeq = new List <Ensures>(); int count = 0; foreach (CallCmd callCmd in parCallCmd.CallCmds) { Dictionary <Variable, Expr> map = new Dictionary <Variable, Expr>(); foreach (Variable x in callCmd.Proc.InParams) { Variable y = ParCallDesugarFormal(x, count, true); inParams.Add(y); map[x] = Expr.Ident(y); } foreach (Variable x in callCmd.Proc.OutParams) { Variable y = ParCallDesugarFormal(x, count, false); outParams.Add(y); map[x] = Expr.Ident(y); } Contract.Assume(callCmd.Proc.TypeParameters.Count == 0); Substitution subst = Substituter.SubstitutionFromHashtable(map); foreach (Requires req in callCmd.Proc.Requires) { requiresSeq.Add(new Requires(req.tok, req.Free, Substituter.Apply(subst, req.Condition), null, req.Attributes)); } foreach (Ensures ens in callCmd.Proc.Ensures) { ensuresSeq.Add(new Ensures(ens.tok, ens.Free, Substituter.Apply(subst, ens.Condition), null, ens.Attributes)); } count++; } parallelCallAggregators[procName] = new Procedure(Token.NoToken, procName, new List <TypeVariable>(), inParams, outParams, requiresSeq, civlTypeChecker.GlobalVariables.Select(v => Expr.Ident(v)).ToList(), ensuresSeq); } Procedure proc = parallelCallAggregators[procName]; CallCmd checkerCallCmd = new CallCmd(parCallCmd.tok, proc.Name, ins, outs, parCallCmd.Attributes); checkerCallCmd.Proc = proc; newCmds.Add(checkerCallCmd); newCmds.AddRange(refinementInstrumentation.CreateAssumeCmds()); newCmds.AddRange(globalSnapshotInstrumentation.CreateUpdatesToOldGlobalVars()); newCmds.AddRange(refinementInstrumentation.CreateUpdatesToOldOutputVars()); newCmds.AddRange(noninterferenceInstrumentation.CreateUpdatesToPermissionCollector(parCallCmd)); newCmds.AddRange(block.cmds.GetRange(1, block.cmds.Count - 1)); block.cmds = newCmds; }