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); } }
public Type GetSerializer(XmlSerializer caller, Type t, ref string rootName, ref string rootNamespace) { // start again with clean error list - do NOT return errors from the temporary checker. errors = new ErrorNodeList(); errorHandler = new ErrorHandler(errors); TypeNode type = TypeNode.GetTypeNode(t); string nspace = GetSerializerNamespace(type); string serializerClassName = GetSerializerName(type); string fullName = nspace + ((nspace != "" && nspace != null) ? "." : "") + serializerClassName; // Structural types have no container element name. if (!IsStructuralType(type) && !(type is EnumNode)) { if (rootName == null) { Identifier name = Checker.GetDefaultElementName(type); rootName = name.Name; if (rootNamespace == null && name.Prefix != null) { rootNamespace = name.Prefix.Name; } } } if (caller.GetType().FullName == fullName) return caller.GetType(); AssemblyNode assembly = AssemblyNode.GetAssembly(t.Assembly, cache, false, true); // see if we can find a serializer in the same assembly as the given type. TypeNode serializerType = assembly.GetType(Identifier.For(nspace), Identifier.For(serializerClassName)); if (serializerType != null) { Type result = serializerType.GetRuntimeType(); Debug.Assert(result != null, "GetRuntimeType() failed on " + serializerType.FullName); return result; } System.Reflection.Assembly sasm = (System.Reflection.Assembly)genCache[t]; if (sasm == null) { ComegaCompilerOptions options = new ComegaCompilerOptions(); options.OutputAssembly = type.Name + "Serializer.dll"; options.GenerateExecutable = false; options.ModuleKind = ModuleKindFlags.DynamicallyLinkedLibrary; if (DumpOption == null) { DumpOption = System.Environment.GetEnvironmentVariable("DEBUG_SERIALIZER"); if (DumpOption == null) DumpOption = ""; } options.GenerateInMemory = (DumpOption == ""); options.DumpTree = (DumpOption != ""); options.IncludeDebugInformation = (DumpOption != ""); options.TempFiles = new TempFileCollection(Directory.GetCurrentDirectory(), true); string writerAssembly = typeof(XmlSerializationWriter).Assembly.Location; options.ReferencedAssemblies.Add(writerAssembly); string xmlAssembly = typeof(XmlTextReader).Assembly.Location; options.ReferencedAssemblies.Add(xmlAssembly); Compiler compiler = new Compiler(); Module module = compiler.CreateModule(options, errors); CompilationUnit cu = CreateCompilationUnit(module, type); // so we can find all the structural types already defined in the assembly // associated with the type we are building the serializer for. cu.TargetModule.AssemblyReferences.Add(new AssemblyReference(assembly)); CompilerResults results = compiler.CompileAssemblyFromIR(options, cu, errors); if (errors.Length > 0) { throw new XmlSerializerException(errors[0].GetMessage()); } else if (results.Errors.Count>0) { throw new XmlSerializerException(results.Errors[0].ErrorText); } else { sasm = results.CompiledAssembly; if (sasm == null) throw new XmlSerializerException(RuntimeError.SerializationAssembly); genCache[t] = sasm; } } Type instanceType = sasm.GetType(fullName, false, false); if (instanceType == null) throw new XmlSerializerException(RuntimeError.SerializationClass, fullName); return instanceType; }
internal Class CreateSerializerFor(TypeNode type, ErrorHandler errorHandler) { this.errorHandler = errorHandler; this.errors = errorHandler.Errors; return CreateSerializerFor(type); }
public ReadEffectAdmissibilityChecker(Method method, System.Compiler.ErrorHandler handler) { this.Method = method; this.ErrorHandler = handler; }
public AdmissibilityChecker(System.Compiler.Checker callingChecker) : base(callingChecker) { this.ErrorHandler = (ErrorHandler)callingChecker.ErrorHandler; this.checker = callingChecker; }
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; }