static public void check(TypeSystem t, Method m){ ModifiesChecker mChecker=new ModifiesChecker(t); ControlFlowGraph cfg=ControlFlowGraph.For(m); mChecker.Run(cfg, null // TBD ); }
private void Init(){ ErrorNodeList tempErrors = new ErrorNodeList(); ErrorHandler tempErrorHandler = new ErrorHandler(tempErrors); tempTypeSystem = new TypeSystem(tempErrorHandler); // Here we ignore the errors generated by this temporary checker on purpose! tempChecker = new Checker(tempErrorHandler, tempTypeSystem, null, null, null); if (errorHandler == null) { errors = new ErrorNodeList(); errorHandler = new ErrorHandler(errors); } }
/// <summary> /// Constructor /// </summary> /// <param name="t"></param> /// <param name="method"></param> protected ExposureChecker(TypeSystem t,Method method) { typeSystem=t; currentMethod=method; iVisitor=new ExposureInstructionVisitor(this); }
/// <summary> /// Entry point to check a method. /// </summary> /// <param name="t"></param> /// <param name="method"></param> public static void Check(TypeSystem t, Method method, Analyzer analyzer) { if(method==null) return; if (method.HasCompilerGeneratedSignature) return; // REVIEW: this means we don't check default ctors, among other things. ExposureChecker checker= new ExposureChecker(t,method); Analyzer.WriteLine(""); ControlFlowGraph cfg=analyzer.GetCFG(method); if(cfg!=null) { checker.Run( cfg, new ExposureState(t)); } }
private ExposureState(IEGraph egraph, TypeNode currentException, TypeSystem t) { this.typeSystem = t; this.egraph = egraph; this.currentException = currentException; }
public ExposureState(TypeSystem t) { this.typeSystem = t; this.egraph = new EGraph(Lattice.It); this.currentException = null; }
public ExposureState(ExposureState old){ this.typeSystem = old.typeSystem; this.egraph = (IEGraph)old.egraph.Clone(); this.currentException = old.currentException; }
static int Main(string[] args) { ErrorNodeList enl = new ErrorNodeList(); ErrorHandler eh = new ErrorHandler(enl); TypeSystem ts = new TypeSystem(eh); //args = new string[] // { // //@"C:\Users\Jonathan Tapicer\Documents\Visual Studio 2010\Projects\escape_test\escape_test\bin\Debug\escape_test.dll", // //@"C:\Users\Jonathan Tapicer\Desktop\tesis\cci_rewriter\example_with_contracts\Example\obj\Debug\Decl\Example.dll", // @"C:\Users\Jonathan Tapicer\Desktop\tesis\cci_rewriter\experiments\experiments\obj\Debug\Decl\experiments.dll", // }; if (args.Length == 0) { Console.WriteLine("Provide assembly full path as an argument."); return 1; } AssemblyNode assembly = AssemblyNode.GetAssembly( args[0], true, true, true); PointsToAnalysis pta = new PointsToAnalysis(ts, assembly, true, true, 3); pta.Visit(assembly); XmlTextWriter xml = new XmlTextWriter(Console.Out); xml.Formatting = Formatting.Indented; xml.WriteStartElement("ptg"); foreach (var method in pta.AnalyzedMethods()) { xml.WriteStartElement("method"); xml.WriteAttributeString("type", method.DeclaringType.ToString()); xml.WriteAttributeString("name", method.Name.ToString()); var summ = pta.GetSummaryForMethod(method); var ptg = summ.PointsToGraph; //if (method.Name.ToString() == "M1") ptg.GenerateDotGraph("c:\\tmp\\ptg.dot"); //nodes escape xml.WriteStartElement("escape"); var added = new List<string>(); foreach (var n in ptg.ReachableFromParametersReturnAndGlobals()) { if (!added.Contains(n.Name)) { xml.WriteStartElement("node"); xml.WriteAttributeString("name", n.Name); if (n.Label != null && n.Label.Method != null) { xml.WriteAttributeString("method", n.Label.Method.DeclaringType.ToString() + "::" + n.Label.Method.Name); } xml.WriteEndElement(); //</node> added.Add(n.Name); } } xml.WriteEndElement(); //</escape> //locals, params, ret, globals, fields inside nodes xml.WriteStartElement("expressions"); Edges edges = new Edges(); edges.AddEdges(ptg.I); edges.AddEdges(ptg.O); foreach (var v in ptg.LV) { xml.WriteStartElement("expr"); if (ptg.RetValue == v.Key.Variable) { xml.WriteAttributeString("isReturn", "true"); } xml.WriteAttributeString("val", v.Key.Name.Name); Nodes nodesReacheable = Nodes.Empty; var reacheableNodesExpressions = new Dictionary<string, Set<string>>(); //key are exprs, values are reacheable nodes by the expr foreach (var addr in v.Value) { var nodesReacheableFromAddr = ptg.NodesForwardReachableFrom(addr); nodesReacheable.AddRange(nodesReacheableFromAddr); foreach (var nodeReacheableFromAddr in nodesReacheableFromAddr) { Set<IEnumerable<Edge>> pathsFromAddrToReacheableNode = (Set<IEnumerable<Edge>>)ptg.DFSPathFromTo(addr, nodeReacheableFromAddr, edges); foreach (var path in pathsFromAddrToReacheableNode) { var pathFields = new List<string>(); foreach (var edge in path) { if (edge.Field.Name.Name != "*" && edge.Field.Name.Name != "?" && edge.Field.Name.Name != "$") { pathFields.Add(edge.Field.Name.Name); } } if (!reacheableNodesExpressions.ContainsKey(nodeReacheableFromAddr.Name)) { reacheableNodesExpressions.Add(nodeReacheableFromAddr.Name, new Set<string>()); } var expr = "." + string.Join(".", pathFields); if (!reacheableNodesExpressions[nodeReacheableFromAddr.Name].Contains(expr)) { reacheableNodesExpressions[nodeReacheableFromAddr.Name].Add(expr); } } } } xml.WriteStartElement("reaches"); foreach (var r in nodesReacheable) { if (r.Name != v.Key.Name.Name) { xml.WriteStartElement("node"); xml.WriteAttributeString("name", r.Name); if (r.Label != null && r.Label.Method != null) { xml.WriteAttributeString("method", r.Label.Method.DeclaringType.ToString() + "::" + r.Label.Method.Name); } if (reacheableNodesExpressions.ContainsKey(r.Name)) { foreach (var expr in reacheableNodesExpressions[r.Name]) { xml.WriteStartElement("expr"); xml.WriteAttributeString("val", expr); xml.WriteEndElement(); //</expr> } } xml.WriteEndElement(); //</node> } } xml.WriteEndElement(); //</reaches> xml.WriteEndElement(); //</expr> } xml.WriteEndElement(); //</expressions> xml.WriteEndElement(); //</method> } xml.WriteEndElement(); //</ptg> return 0; }
public Lattice.AVal FieldNullness(NonNullChecker checker, Field field, TypeSystem ts){ if (IsNonNullType(field.Type)) { return Lattice.AVal.NonNull; } else if (field.Type != null && field.Type.IsValueType) { return Lattice.AVal.MayBeNull; } else { if (ts.FieldReadAsNonNull(checker.analyzer.CompilerOptions, field)) { // HACK HACK for now we assume fields of reference type are always non-null when read return Lattice.AVal.NonNull; } else { return Lattice.AVal.MayBeNull; } } }
public NonNullState(TypeSystem t, IDelayInfo ieinfo) { this.typeSystem = t; this.egraph = new EGraph(Lattice.It); this.currentException = null; existDelayInfo = ieinfo; // materialize the null symbol early on so // all derived states share it. ISymValue nullsym = this.Null; }
public NonNullState(NonNullState old){ this.typeSystem = old.typeSystem; this.egraph = (IEGraph)old.egraph.Clone(); this.currentException = old.currentException; // this.existDelayInfo = old.ExistDelayInfo; }
/// <summary> /// Constructor. /// </summary> /// <param name="c"></param> public NonNullInstructionVisitor(NonNullChecker c) { NNChecker=c; ts=c.typeSystem; }
/// <summary> /// Constructor /// </summary> /// <param name="t"></param> /// <param name="method"></param> protected NonNullChecker(TypeSystem t, Method method, Analyzer analyzer) { this.typeSystem = t; this.analyzer = analyzer; this.currentMethod=method; this.iVisitor=new NonNullInstructionVisitor(this); }
/// <summary> /// Entry point to check a method. /// </summary> /// <param name="t"></param> /// <param name="method"></param> public static INonNullInformation Check(TypeSystem t, Method method, Analyzer analyzer) { if(method==null) return null; NonNullChecker checker = new NonNullChecker(t, method, analyzer); ControlFlowGraph cfg = analyzer.GetCFG(method); if (cfg != null) { checker.nonNullEdgeInfo = new IFunctionalMap[cfg.BlockCount]; checker.Run(cfg, new NonNullState(t, analyzer.DelayInfo)); checker.OptimizeMethodBody(method); return checker; } return null; }
private ModifiesChecker(TypeSystem t){ typeSystem=t; iVisitor=new ModifiesInstructionVisitor(); }
public ExposureInstructionVisitor(ExposureChecker c) { ExposureChecker=c; ts=c.typeSystem; reportedErrors=new Hashtable(); }
public Lattice.AVal PropertyNullness(Property property, TypeSystem ts){ if (IsNonNullType(property.Type)) { return Lattice.AVal.NonNull; } else if (property.Type != null && property.Type.IsValueType) { return Lattice.AVal.MayBeNull; } else { return Lattice.AVal.MayBeNull; } }
public ModifiesAnalyzer(TypeSystem t) { typeSystem=t; }