private void addFunctionInstantiation(FAE e) { if (ExpressionSymbolCounter.isInterpreted(e.function.name)) { return; } var f = e.function as BasicFunctionTemplateInstance; if (f == null /*|| f.template.mapTypeArguments.Count()==0*/) { return; } FunctioneTemplateEntry fti; if (!functionTemplateInstantiations.TryGetValue(e.function.name, out fti)) { functionTemplateInstantiations[e.function.name] = fti = new FunctioneTemplateEntry(f.template); } string s = argumentString(f.typeArguments); if (!fti.instances.ContainsKey(s)) { fti.instances[s] = new Dictionary <string, FAE>(); } fti.instances[s][e.ToString()] = e; if (f.isGroundInstance()) { fti.groundInstances.Add(s); } }
private void slice() { CFG <BasicBlock, BasicEdge> cfg = p.cfg; HashSet <string> relevantAssumptions = calculateRelevantAssumptions(); BasicBlock nn = cfg.addNode("start0"); // foreach (var k in assumptions.Keys) // relevantAssumptions.Add(k); var sl = new SortedList <string, string>(); foreach (var a in relevantAssumptions) { sl.Add(a, a); } foreach (var a in sl) { if (assumptions.ContainsKey(a.Value)) { nn.appendStatement(new Assume((assumptions[a.Value].statement as Assume).expression)); } } /* foreach (var m in assumptions) * if (relevantAssumptions.Contains(m.Key)) * nn.appendStatement(new Assume((m.Value.statement as Assume).fae)); */ foreach (var a in assumptions) { if (!relevantAssumptions.Contains(a.Key)) { string es = (a.Value.statement as Assume).expression.ToString(); bool slice = false; foreach (var s in symbolsPerExpression[es]) { if (!ExpressionSymbolCounter.isInterpreted(s)) { slice = true; } } if (!slice) { nn.appendStatement(new Assume((assumptions[es].statement as Assume).expression)); } } } nn.appendStatement(new Assert(assertion.expression, assertion.message)); nn.setControlStatement(new Block(nn)); cfg.setStartNode(nn.label); cfg.setEndNode(nn.label); cfg.removeNode(bb.label); }
public void collectFunctionTypes() { foreach (var f in procedure.parentScope.functionTemplates) { if (ExpressionSymbolCounter.isInterpreted(f.name) /*|| f.mapTypeArguments.Count() == 0*/) { continue; } functionTemplateInstantiations[f.name] = new FunctioneTemplateEntry(f); string s = ""; if (f.typeParameters.Count() > 0) { s += "<"; foreach (var tp in f.typeParameters) { s += ((s.Last() == '<') ? "" : ",") + tp.name; } s += "> "; } s += "("; foreach (var at in f.signature.argumentTypes) { s += ((s.Count() == 0 || s.Last() == '(') ? "" : ",") + at.ToStringN(); } s += ") --> "; s += f.signature.resultType.ToStringN(); List <FunctionTemplate> ft = null; if (!functionTemplates.TryGetValue(s, out ft)) { functionTemplates[s] = ft = new List <FunctionTemplate>(); } ft.Add(f); } /* * Console.WriteLine("Function signatures:"); * foreach (var ft in functionTemplates) * { * Console.Write("\t{0} :", ft.Key); * foreach (var f in ft.Value) * Console.Write(" {0}", f.name); * Console.WriteLine(); * }*/ }
public static void Remove(Procedure p) { var uvr = new UnusedSymbolRemover(p); foreach (var bb in p.cfg.nodes) { foreach (var si in bb.statements) { uvr.visit(si.statementId); } } foreach (var ft in p.parentScope.functionTemplates) { ft.signature.resultType.visit(uvr); foreach (var at in ft.signature.argumentTypes) { at.visit(uvr); } } foreach (var v in p.parentScope.locals) { v.type.visit(uvr); } foreach (var v in p.locals) { v.type.visit(uvr); } foreach (var v in p.inputs) { v.type.visit(uvr); } foreach (var v in p.outputs) { v.type.visit(uvr); } // foreach (var e in ( from ft in p.parentScope.functionTemplates where ft.fae!=null select ft.fae)) // e.visitI(uvr); var deleted = new HashSet <StatementId>(); foreach (var f in uvr.functionOccurences) { if (f.Value.Count == 1 && !ExpressionSymbolCounter.isInterpreted(f.Key) && !deleted.Contains(f.Value.First().Value)) { Expression e = f.Value.First().Key.expression; // Console.WriteLine("Function {0} has one occurence: {1}", f.Key, e.ToString()); Expression qe = e; while (qe is QuantifiedTypeExpression) { qe = (qe as QuantifiedTypeExpression).expression; } while (qe is QuantifiedExpression) { qe = (qe as QuantifiedExpression).expression; } var fae = qe as FAE; if (fae != null) { if (BFunction.isEquality(fae.function) || BFunction.isEquivalence(fae.function) || BFunction.isImplication(fae.function)) { var a0fae = fae.arguments[0] as FAE; while (a0fae != null && (BFunction.isMapRead(a0fae.function) || BFunction.isCoerce(a0fae.function) || (a0fae.arguments.count == 1 && a0fae.function.name != f.Key))) { a0fae = a0fae.arguments[0] as FAE; } var a1fae = fae.arguments[1] as FAE; while (a1fae != null && (BFunction.isMapRead(a1fae.function) || BFunction.isCoerce(a1fae.function) || (a1fae.arguments.count == 1 && a1fae.function.name != f.Key))) { a1fae = a1fae.arguments[0] as FAE; } if ((a0fae != null && a0fae.function.name == f.Key) ^ (a1fae != null && a1fae.function.name == f.Key)) { // Console.WriteLine("\tDefinition - can be removed safely"); uvr.unusedFunctions.Add(f.Key); deleted.Add(f.Value.First().Value); f.Value.First().Value.delete(); } } } } } /////////////////////////////////////////////////////////// foreach (var v in uvr.unusedVariables) { if (p.tryFindVariable(v) != null) { p.removeVariable(v); } else { p.parentScope.removeVariable(v); } } foreach (var f in uvr.unusedFunctions) { p.removeFunctionTemplate(f); } foreach (var tc in uvr.unusedTypeConstructors) { p.removeTypeConstructor(tc); } foreach (var ts in uvr.unusedTypeSynonyms) { p.removeTypeSynonym(ts); } // return uvr; }