xamarin-macios/runtime/Delegates.cs.t4

157 строки
3.9 KiB
Plaintext
Исходник Постоянная ссылка Обычный вид История

2016-04-21 15:19:32 +03:00
// vim: set filetype=c :
//
// Delegates.generated.cs:
//
// Authors:
// Rolf Bjarne Kvinge <rolf@xamarin.com>
//
// Copyright 2013-2014 Xamarin Inc.
//
/*
* This file was generated from Delegates.cs.t4, any modifications will be lost once this file is re-generated.
*/
<#@ include file="delegates.t4" #>
#if !COREBUILD
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.InteropServices;
using Foundation;
using Registrar;
2016-04-21 15:19:32 +03:00
namespace ObjCRuntime {
2016-04-21 15:19:32 +03:00
public unsafe partial class Runtime {
#if !NET
2016-04-21 15:19:32 +03:00
<# foreach (var d in delegates) { #>
<#
if (d.OnlyCoreCLR)
continue;
#>
internal delegate <#= d.ReturnType.MType #> <#= d.SimpleEntryPoint #>_delegate (<#= d.MArgumentSignature #>);
2016-04-21 15:19:32 +03:00
<# } #>
#endif // !NET
2016-04-21 15:19:32 +03:00
internal struct Delegates {
<# foreach (var d in delegates) { #>
<#
if (d.OnlyCoreCLR)
Write ("#if NET\n");
#>
2016-04-21 15:19:32 +03:00
public IntPtr <#= d.SimpleEntryPoint #>;
<#
if (d.OnlyCoreCLR)
Write ("#endif // NET\n");
#>
2016-04-21 15:19:32 +03:00
<# } #>
}
<# foreach (var d in delegates) { #>
<#
if (d.OnlyCoreCLR)
Write ("#if NET\n");
#>
#if NET
[UnmanagedCallersOnly]
#else
2016-04-21 15:19:32 +03:00
[MonoPInvokeCallback (typeof (<#= d.SimpleEntryPoint #>_delegate))]
#endif
static unsafe <#= d.ReturnType.MType #> <#= d.SimpleEntryPoint #> (<#= d.MArgumentSignature #>)
<# if (d.ExceptionHandling) { #>
{
*exception_gchandle = IntPtr.Zero;
try {
<# if (string.IsNullOrEmpty (d.WrappedManagedFunction)) { #>
throw new NotImplementedException ();
<# } else { #>
<# if (d.ReturnType.MType != "void") { #>return <# } #><#=d.WrappedManagedFunction#> (<#=d.MArgumentNames#>);
<# } #>
} catch (Exception ex) {
var handle = GCHandle.Alloc (ex, GCHandleType.Normal);
*exception_gchandle = GCHandle.ToIntPtr (handle);
<# if (d.SimpleEntryPoint == "get_nsobject_with_type") { #> *created = 0;
<# } #>
<# if (d.ReturnType.MType != "void") { #> return default (<#= d.ReturnType.MType #>);
<# } #>
}
}
<# } else { #>
2016-04-21 15:19:32 +03:00
{
<# if (string.IsNullOrEmpty (d.WrappedManagedFunction)) { #>
throw new NotImplementedException ();
<# } else { #>
<# if (d.ReturnType.MType != "void") { #>return <# } #><#=d.WrappedManagedFunction#> (<#=d.MArgumentNames#>);
2016-04-21 15:19:32 +03:00
<# } #>
}
<# } #>
<#
if (d.OnlyCoreCLR)
Write ("#endif // NET\n");
#>
2016-04-21 15:19:32 +03:00
<# } #>
[BindingImpl (BindingImplOptions.Optimizable)] // To inline the Runtime.DynamicRegistrationSupported code if possible.
unsafe static void RegisterDelegates (InitializationOptions* options)
2016-04-21 15:19:32 +03:00
{
#if NET
<# foreach (var d in delegates.NotOnlyDynamic) { #>
<#
if (d.OnlyCoreCLR) {
Write ("\t\t\tif (IsCoreCLR) {\n\t");
}
if (d.SkipManagedStaticRegistrar) {
Write ("\t\t\tif (!Runtime.IsManagedStaticRegistrar) {\n\t");
}
#>
options->Delegates-><#= d.SimpleEntryPoint #> = (IntPtr) (void *) <#= d.UnmanagedDelegateCast #> &<#= d.SimpleEntryPoint #>;
<#
if (d.OnlyCoreCLR) {
WriteLine ("\t\t\t}");
}
if (d.SkipManagedStaticRegistrar) {
WriteLine ("\t\t\t}");
}
#>
<# } #>
#else
<# foreach (var d in delegates.NotOnlyDynamic) {
if (d.OnlyCoreCLR)
continue;
#>
options->Delegates-><#= d.SimpleEntryPoint #> = GetFunctionPointer (new <#= d.SimpleEntryPoint #>_delegate (<#= d.SimpleEntryPoint #>));
<# } #>
#endif
// The linker will remove this condition (and the subsequent method call) if possible
if (DynamicRegistrationSupported)
RegisterDelegatesDynamic (options);
}
static void RegisterDelegatesDynamic (InitializationOptions* options)
{
<# foreach (var d in delegates.OnlyDynamic) { #>
<#
if (d.OnlyCoreCLR) {
Write ("#if NET\n");
Write ("\t\t\tif (IsCoreCLR)\n\t");
}
#>
#if NET
options->Delegates-><#= d.SimpleEntryPoint #> = (IntPtr) (void *) <#= d.UnmanagedDelegateCast #> &<#= d.SimpleEntryPoint #>;
#else
options->Delegates-><#= d.SimpleEntryPoint #> = GetFunctionPointer (new <#= d.SimpleEntryPoint #>_delegate (<#= d.SimpleEntryPoint #>));
#endif
<#
if (d.OnlyCoreCLR)
Write ("#endif // NET\n");
#>
2016-04-21 15:19:32 +03:00
<# } #>
}
}
}
#endif