internal SyntaxTree Generate(NativeSymbolBag bag, ErrorProvider ep) { // Make sure than all of the referenced NativeDefinedType instances are in the correct // portion of the bag ChaseReferencedDefinedTypes(bag); // First step is to resolve the symbols bag.TryResolveSymbolsAndValues(ep); // Create the codedom transform var transform = new CodeTransform(_langaugeType, bag); var marshalUtil = new MarshalTransform(_langaugeType, bag, TransformKindFlags.All); var col = new CodeTypeDeclarationCollection(); // Only output the constants if there are actually any var constList = bag.FindResolvedConstants().ToList(); if (constList.Count > 0) { var constCtd = transform.GenerateConstants(constList); if (constCtd.Members.Count > 0) { col.Add(constCtd); } } foreach (var definedNt in bag.FindResolvedDefinedTypes()) { var ctd = transform.GenerateDeclaration(definedNt); marshalUtil.Process(ctd); col.Add(ctd); } var procList = bag.FindResolvedProcedures().ToList(); if (procList.Count > 0) { var procType = transform.GenerateProcedures(procList); marshalUtil.Process(procType); col.Add(procType); } // Add the helper types that we need AddHelperTypes(col); // Next step is to run the pretty lister on it var prettyLister = new CodeDomPrettyList(bag); prettyLister.PerformRename(col); var code = BasicConverter.ConvertCodeDomToPInvokeCodeImpl(_langaugeType, col, ep); return(CSharpSyntaxTree.ParseText(code)); }