71 строка
1.8 KiB
C#
71 строка
1.8 KiB
C#
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<string,string> signatures = new Dictionary<string, string> ();
|
|
public List<Exception> exceptions = new List<Exception> ();
|
|
public StringBuilder signature = new StringBuilder ();
|
|
public HashSet<string> names = new HashSet<string> ();
|
|
|
|
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 <stdarg.h>");
|
|
hdr.WriteLine ("#include <xamarin/xamarin.h>");
|
|
hdr.WriteLine ("#include <objc/objc.h>");
|
|
hdr.WriteLine ("#include <objc/runtime.h>");
|
|
hdr.WriteLine ("#include <objc/message.h>");
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
|