using System; using System.Collections.Generic; using System.IO; using System.Text; using Mono.Cecil; using Xamarin.Bundler; using XamCore.Registrar; namespace Xamarin.Bundler { class PInvokeWrapperGenerator { public Dictionary signatures = new Dictionary (); public List exceptions = new List (); public StringBuilder signature = new StringBuilder (); public HashSet names = new HashSet (); public AutoIndentStringBuilder sb = new AutoIndentStringBuilder (); AutoIndentStringBuilder hdr = new AutoIndentStringBuilder (); AutoIndentStringBuilder decls = new AutoIndentStringBuilder (); AutoIndentStringBuilder mthds = new AutoIndentStringBuilder (); public StaticRegistrar Registrar; public string HeaderPath; public string SourcePath; bool first; public void Start () { if (Driver.EnableDebug) hdr.WriteLine ("#define DEBUG 1"); hdr.WriteLine ("#include "); hdr.WriteLine ("#include "); hdr.WriteLine ("#include "); hdr.WriteLine ("#include "); hdr.WriteLine ("#include "); Registrar.GeneratePInvokeWrappersStart (hdr, decls, mthds); mthds.WriteLine ($"#include \"{Path.GetFileName (HeaderPath)}\""); sb.WriteLine ("extern \"C\" {"); } public void End () { sb.WriteLine ("}"); Registrar.GeneratePInvokeWrappersEnd (); Driver.WriteIfDifferent (HeaderPath, hdr.ToString () + "\n" + decls.ToString () + "\n"); Driver.WriteIfDifferent (SourcePath, mthds.ToString () + "\n" + sb.ToString () + "\n"); } public void ProcessMethod (MethodDefinition method) { if (!first) { Start (); first = true; } Registrar.GeneratePInvokeWrapper (this, method); } } }