2016-04-21 15:19:32 +03:00
<# // vim: set filetype=cs :
#>
<#@ template language="C#" #>
<#@ import namespace="System" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#
var delegates = new XDelegates {
new XDelegate ("void", "void", "xamarin_register_nsobject",
"MonoObject *", "IntPtr", "managed_obj",
"id", "IntPtr", "native_obj"
2018-02-02 20:20:58 +03:00
) {
WrappedManagedFunction = "RegisterNSObject",
OnlyDynamicUsage = true,
},
2016-04-21 15:19:32 +03:00
new XDelegate ("void", "void", "xamarin_register_assembly",
"MonoReflectionAssembly *", "IntPtr", "assembly"
2018-02-02 20:20:58 +03:00
) {
WrappedManagedFunction = "RegisterAssembly",
OnlyDynamicUsage = true,
},
2016-04-21 15:19:32 +03:00
new XDelegate ("void", "void", "xamarin_throw_ns_exception",
"NSException *", "IntPtr", "exc"
2016-06-02 13:18:45 +03:00
) {
WrappedManagedFunction = "ThrowNSException",
ExceptionHandling = false,
2018-02-02 20:20:58 +03:00
OnlyDynamicUsage = false,
2016-06-02 13:18:45 +03:00
},
2016-04-21 15:19:32 +03:00
2016-10-27 21:03:11 +03:00
new XDelegate ("void", "void", "xamarin_rethrow_managed_exception",
"guint32", "uint", "original_exception_gchandle"
2018-02-02 20:20:58 +03:00
) {
WrappedManagedFunction = "RethrowManagedException",
OnlyDynamicUsage = false,
},
2016-10-27 21:03:11 +03:00
2016-05-11 14:27:51 +03:00
new XDelegate ("int", "int", "xamarin_create_ns_exception",
"NSException *", "IntPtr", "exc"
2018-02-02 20:20:58 +03:00
) {
WrappedManagedFunction = "CreateNSException",
OnlyDynamicUsage = false,
},
2016-05-11 14:27:51 +03:00
new XDelegate ("NSException *", "IntPtr", "xamarin_unwrap_ns_exception",
"int", "int", "exc_handle"
2018-02-02 20:20:58 +03:00
) {
WrappedManagedFunction = "UnwrapNSException",
2018-03-01 00:28:06 +03:00
OnlyDynamicUsage = false,
2018-02-02 20:20:58 +03:00
},
2016-05-11 14:27:51 +03:00
2016-04-21 15:19:32 +03:00
new XDelegate ("MonoObject *", "IntPtr", "xamarin_get_block_wrapper_creator",
"MonoObject *", "IntPtr", "method",
"int", "int", "parameter"
2018-02-02 20:20:58 +03:00
) {
WrappedManagedFunction = "GetBlockWrapperCreator",
OnlyDynamicUsage = true,
},
2016-04-21 15:19:32 +03:00
new XDelegate ("MonoObject *", "IntPtr", "xamarin_create_block_proxy",
"MonoObject *", "IntPtr", "method",
"void *", "IntPtr", "block"
2018-02-02 20:20:58 +03:00
) {
WrappedManagedFunction = "CreateBlockProxy",
2018-03-02 16:30:18 +03:00
OnlyDynamicUsage = false,
2018-02-02 20:20:58 +03:00
},
2016-04-21 15:19:32 +03:00
new XDelegate ("id", "IntPtr", "xamarin_create_delegate_proxy",
"MonoObject *", "IntPtr", "method",
Optimize calls to BlockLiteral.SetupBlock to inject the block signature. (#3391)
* [linker] Optimize calls to BlockLiteral.SetupBlock to inject the block signature.
Optimize calls to BlockLiteral.SetupBlock[Unsafe] to calculate the block
signature at build time, and inject it into the call site.
This makes block invocations 10-15x faster (I've added tests that asserts at
least an 8x increase).
It's also required in order to be able to remove the dynamic registrar code in
the future (since calculating the block signature at runtime requires the
dynamic registrar).
* [mtouch/mmp] Add support for reporting errors/warnings that point to the code line causing the error/warning.
Add support for reporting errors/warnings that point to the code line causing
the error/warning by adding ErrorHelper overloads that take the exact
instruction to report (previously we defaulted to the first line/instruction
in a method).
* [tests] Add support for asserting filename/linenumber in warning messages.
* Make all methods that manually create BlockLiterals optimizable.
* [tests] Create a BaseOptimizeGeneratedCodeTest test that's included in both XI's and XM's link all test.
* [tests] Add link all test (for both XI and XM) to test the BlockLiteral.SetupBlock optimization.
* [tests] Add mtouch/mmp tests for the BlockLiteral.SetupBlock optimization.
* [tests][linker] Make the base test class abstract, so tests in the base class aren't executed twice.
* [tests][linker] Don't execute linkall-only tests in linksdk.
The optimization tests only apply when the test assembly is linked, and that
only happens in linkall, so exclude those tests in linksdk.
* [tests][mmptest] Update test according to mmp changes.
Fixes these test failures:
1) Failed : Xamarin.MMP.Tests.MMPTests.MM0132("inline-runtime-arch")
The warning 'MM0132: Unknown optimization: 'inline-runtime-arch'. Valid optimizations are: remove-uithread-checks, dead-code-elimination, inline-isdirectbinding, inline-intptr-size.' was not found in the output:
Message #1 did not match:
actual: 'Unknown optimization: 'inline-runtime-arch'. Valid optimizations are: remove-uithread-checks, dead-code-elimination, inline-isdirectbinding, inline-intptr-size, blockliteral-setupblock.'
expected: 'Unknown optimization: 'inline-runtime-arch'. Valid optimizations are: remove-uithread-checks, dead-code-elimination, inline-isdirectbinding, inline-intptr-size.'
Message #2 did not match:
actual: 'Unknown optimization: 'inline-runtime-arch'. Valid optimizations are: remove-uithread-checks, dead-code-elimination, inline-isdirectbinding, inline-intptr-size, blockliteral-setupblock.'
expected: 'Unknown optimization: 'inline-runtime-arch'. Valid optimizations are: remove-uithread-checks, dead-code-elimination, inline-isdirectbinding, inline-intptr-size.'
2) Failed : Xamarin.MMP.Tests.MMPTests.MM0132("foo")
The warning 'MM0132: Unknown optimization: 'foo'. Valid optimizations are: remove-uithread-checks, dead-code-elimination, inline-isdirectbinding, inline-intptr-size.' was not found in the output:
Message #1 did not match:
actual: 'Unknown optimization: 'foo'. Valid optimizations are: remove-uithread-checks, dead-code-elimination, inline-isdirectbinding, inline-intptr-size, blockliteral-setupblock.'
expected: 'Unknown optimization: 'foo'. Valid optimizations are: remove-uithread-checks, dead-code-elimination, inline-isdirectbinding, inline-intptr-size.'
Message #2 did not match:
actual: 'Unknown optimization: 'foo'. Valid optimizations are: remove-uithread-checks, dead-code-elimination, inline-isdirectbinding, inline-intptr-size, blockliteral-setupblock.'
expected: 'Unknown optimization: 'foo'. Valid optimizations are: remove-uithread-checks, dead-code-elimination, inline-isdirectbinding, inline-intptr-size.'
* [tests][linker] Fix typo.
Fixes this test failure:
1) SetupBlock_CustomDelegate (Linker.Shared.BaseOptimizeGeneratedCodeTest.SetupBlock_CustomDelegate)
Counter
Expected: 1
But was: 2
* [registrar] Minor adjustment to error message to match previous (and better) behavior.
Fixes this test failure:
1) Failed : Xamarin.Registrar.GenericType_WithInvalidParameterTypes
The error 'MT4136: The registrar cannot marshal the parameter type 'System.Collections.Generic.List`1<U>' of the parameter 'arg' in the method 'Open`1.Bar(System.Collections.Generic.List`1<U>)'' was not found in the output:
Message #1 did not match:
actual: 'The registrar cannot marshal the parameter type 'System.Collections.Generic.List`1<Foundation.NSObject>' of the parameter 'arg' in the method 'Open`1.Bar(System.Collections.Generic.List`1<U>)''
expected: 'The registrar cannot marshal the parameter type 'System.Collections.Generic.List`1<U>' of the parameter 'arg' in the method 'Open`1.Bar(System.Collections.Generic.List`1<U>)''
* [docs] mmp shows MM errors/warnings.
* [docs] Improve according to reviews.
* [tests] Fix merge failure causing test duplication.
2018-02-06 09:08:15 +03:00
"MonoObject *", "IntPtr", "block",
"const char *", "IntPtr", "signature"
2018-02-02 20:20:58 +03:00
) {
WrappedManagedFunction = "CreateDelegateProxy",
OnlyDynamicUsage = false,
},
2016-04-21 15:19:32 +03:00
new XDelegate ("void", "void", "xamarin_register_entry_assembly",
"MonoReflectionAssembly *", "IntPtr", "assembly"
2018-02-02 20:20:58 +03:00
) {
WrappedManagedFunction = "RegisterEntryAssembly",
OnlyDynamicUsage = true,
},
2016-04-21 15:19:32 +03:00
new XDelegate ("MonoObject *", "IntPtr", "xamarin_get_class",
"Class", "IntPtr", "ptr"
2018-02-02 20:20:58 +03:00
) {
WrappedManagedFunction = "GetClass",
OnlyDynamicUsage = false,
},
2016-04-21 15:19:32 +03:00
new XDelegate ("MonoObject *", "IntPtr", "xamarin_get_selector",
"SEL", "IntPtr", "ptr"
2018-02-02 20:20:58 +03:00
) {
WrappedManagedFunction = "GetSelector",
OnlyDynamicUsage = false,
},
2016-04-21 15:19:32 +03:00
2017-07-03 20:18:02 +03:00
new XDelegate ("void", "void", "xamarin_get_method_for_selector",
2016-04-21 15:19:32 +03:00
"Class", "IntPtr", "cls",
2017-07-03 20:18:02 +03:00
"SEL", "IntPtr", "sel",
2017-09-22 11:23:37 +03:00
"bool", "bool", "is_static",
2017-07-03 20:18:02 +03:00
"MethodDescription *", "IntPtr", "desc"
2018-02-02 20:20:58 +03:00
) {
WrappedManagedFunction = "GetMethodForSelector",
OnlyDynamicUsage = true,
},
2016-04-21 15:19:32 +03:00
new XDelegate ("MonoObject *", "IntPtr", "xamarin_get_nsobject",
"id", "IntPtr", "obj"
2018-02-02 20:20:58 +03:00
) {
WrappedManagedFunction = "GetNSObjectWrapped",
OnlyDynamicUsage = true,
},
2016-04-21 15:19:32 +03:00
2016-02-17 14:02:41 +03:00
new XDelegate ("bool", "bool", "xamarin_has_nsobject",
"id", "IntPtr", "obj"
2018-02-02 20:20:58 +03:00
) {
WrappedManagedFunction = "HasNSObject",
OnlyDynamicUsage = false,
},
2016-02-17 14:02:41 +03:00
2016-04-21 15:19:32 +03:00
new XDelegate ("id", "IntPtr", "xamarin_get_handle_for_inativeobject",
"MonoObject *", "IntPtr", "obj"
2018-02-02 20:20:58 +03:00
) {
WrappedManagedFunction = "GetHandleForINativeObject",
OnlyDynamicUsage = false,
},
2016-04-21 15:19:32 +03:00
new XDelegate ("void", "void", "xamarin_unregister_nsobject",
"id", "IntPtr", "native_obj",
"MonoObject *", "IntPtr", "managed_obj"
2018-02-02 20:20:58 +03:00
) {
WrappedManagedFunction = "UnregisterNSObject",
OnlyDynamicUsage = false,
},
2016-04-21 15:19:32 +03:00
new XDelegate ("MonoObject *", "IntPtr", "xamarin_try_get_or_construct_nsobject",
"id", "IntPtr", "obj"
2018-02-02 20:20:58 +03:00
) {
WrappedManagedFunction = "TryGetOrConstructNSObjectWrapped",
OnlyDynamicUsage = false,
},
2016-04-21 15:19:32 +03:00
new XDelegate ("MonoObject *", "IntPtr", "xamarin_get_inative_object_dynamic",
"id", "IntPtr", "obj",
"bool", "bool", "owns",
"void *", "IntPtr", "type"
2018-02-02 20:20:58 +03:00
) {
WrappedManagedFunction = "GetINativeObject_Dynamic",
OnlyDynamicUsage = false,
},
2016-04-21 15:19:32 +03:00
[registrar] Use metadata tokens instead of strings to find types and methods. (#1085)
Use metadata tokens instead of strings to find types and methods.
This makes the code to find methods more compact (a lot less strings in the
executable, and additionally in most cases a compact representation (32-bit
integer) of the corresponding metadata token and additional information can be
used, which results in less executable code (fewer parameters to methods,
etc)), resulting in smaller executables.
Size savings are around 200kb for dont link apps, and 20-60kb for linked apps
(this obviously varies a lot depending on how much has to registered by the
registrar).
| | Before | After | Diff |
|----------------|--------------:|--------------:|------------------:|
| dontlink/32bit | 102.810.144 | 102.609.456 | -200.688 = -0,20% |
| dontlink/64bit | 107.420.576 | 107.221.792 | -198.784 = -0,19% |
| linksdk/32bit | 40.957.296 | 40.936.864 | -20.432 = -0,05% |
| linksdk/64bit | 43.113.136 | 43.093.936 | -19.200 = -0,04% |
| linkall/32bit | 38.410.032 | 38.348.288 | -61.744 = -0,16% |
| linkall/64bit | 40.315.200 | 40.267.344 | -47.856 = -0,12% |
Additionally I've removed the `lazy_map` dictionary, which we populated at
startup and was used to map between Class instances and the corresponding
managed type's FullName, and instead iterate over a native array of Class ->
metadata token mappings whenever we need to look up the managed type for a
certain Class instance.
This is slightly slower for each type we need to look up (for a non-linked app
there might be a 2000-3000 entries in the native array, which would be
iterated instead of using a hashtable lookup), but it's only done once per
type and there's a significant startup memory improvement.
For a non-linked test app I get the following using the Xamarin profiler:
| | Before | After | Diff |
|-------------------|--------:|--------:|----------------:|
| Memory allocated | 2,8 MB | 2,4 MB | -0,4 MB = -14 % |
| Objects allocated | 43678 | 38463 | -5215 = -12 % |
| Private bytes | 26,6 MB | 24,4 MB | -2,2 MB = -8,3% |
| Working set | 26,6 MB | 24,4 MB | -2,2 MB = -8,3% |
2016-11-01 21:34:56 +03:00
new XDelegate ("MonoReflectionMethod *", "IntPtr", "xamarin_get_method_from_token",
"unsigned int", "uint", "token_ref"
2018-02-02 20:20:58 +03:00
) {
WrappedManagedFunction = "GetMethodFromToken",
OnlyDynamicUsage = false,
},
[registrar] Use metadata tokens instead of strings to find types and methods. (#1085)
Use metadata tokens instead of strings to find types and methods.
This makes the code to find methods more compact (a lot less strings in the
executable, and additionally in most cases a compact representation (32-bit
integer) of the corresponding metadata token and additional information can be
used, which results in less executable code (fewer parameters to methods,
etc)), resulting in smaller executables.
Size savings are around 200kb for dont link apps, and 20-60kb for linked apps
(this obviously varies a lot depending on how much has to registered by the
registrar).
| | Before | After | Diff |
|----------------|--------------:|--------------:|------------------:|
| dontlink/32bit | 102.810.144 | 102.609.456 | -200.688 = -0,20% |
| dontlink/64bit | 107.420.576 | 107.221.792 | -198.784 = -0,19% |
| linksdk/32bit | 40.957.296 | 40.936.864 | -20.432 = -0,05% |
| linksdk/64bit | 43.113.136 | 43.093.936 | -19.200 = -0,04% |
| linkall/32bit | 38.410.032 | 38.348.288 | -61.744 = -0,16% |
| linkall/64bit | 40.315.200 | 40.267.344 | -47.856 = -0,12% |
Additionally I've removed the `lazy_map` dictionary, which we populated at
startup and was used to map between Class instances and the corresponding
managed type's FullName, and instead iterate over a native array of Class ->
metadata token mappings whenever we need to look up the managed type for a
certain Class instance.
This is slightly slower for each type we need to look up (for a non-linked app
there might be a 2000-3000 entries in the native array, which would be
iterated instead of using a hashtable lookup), but it's only done once per
type and there's a significant startup memory improvement.
For a non-linked test app I get the following using the Xamarin profiler:
| | Before | After | Diff |
|-------------------|--------:|--------:|----------------:|
| Memory allocated | 2,8 MB | 2,4 MB | -0,4 MB = -14 % |
| Objects allocated | 43678 | 38463 | -5215 = -12 % |
| Private bytes | 26,6 MB | 24,4 MB | -2,2 MB = -8,3% |
| Working set | 26,6 MB | 24,4 MB | -2,2 MB = -8,3% |
2016-11-01 21:34:56 +03:00
new XDelegate ("MonoReflectionMethod *", "IntPtr", "xamarin_get_generic_method_from_token",
"MonoObject *", "IntPtr", "obj",
"unsigned int", "uint", "token_ref"
2018-02-02 20:20:58 +03:00
) {
WrappedManagedFunction = "GetGenericMethodFromToken",
OnlyDynamicUsage = false,
},
[registrar] Use metadata tokens instead of strings to find types and methods. (#1085)
Use metadata tokens instead of strings to find types and methods.
This makes the code to find methods more compact (a lot less strings in the
executable, and additionally in most cases a compact representation (32-bit
integer) of the corresponding metadata token and additional information can be
used, which results in less executable code (fewer parameters to methods,
etc)), resulting in smaller executables.
Size savings are around 200kb for dont link apps, and 20-60kb for linked apps
(this obviously varies a lot depending on how much has to registered by the
registrar).
| | Before | After | Diff |
|----------------|--------------:|--------------:|------------------:|
| dontlink/32bit | 102.810.144 | 102.609.456 | -200.688 = -0,20% |
| dontlink/64bit | 107.420.576 | 107.221.792 | -198.784 = -0,19% |
| linksdk/32bit | 40.957.296 | 40.936.864 | -20.432 = -0,05% |
| linksdk/64bit | 43.113.136 | 43.093.936 | -19.200 = -0,04% |
| linkall/32bit | 38.410.032 | 38.348.288 | -61.744 = -0,16% |
| linkall/64bit | 40.315.200 | 40.267.344 | -47.856 = -0,12% |
Additionally I've removed the `lazy_map` dictionary, which we populated at
startup and was used to map between Class instances and the corresponding
managed type's FullName, and instead iterate over a native array of Class ->
metadata token mappings whenever we need to look up the managed type for a
certain Class instance.
This is slightly slower for each type we need to look up (for a non-linked app
there might be a 2000-3000 entries in the native array, which would be
iterated instead of using a hashtable lookup), but it's only done once per
type and there's a significant startup memory improvement.
For a non-linked test app I get the following using the Xamarin profiler:
| | Before | After | Diff |
|-------------------|--------:|--------:|----------------:|
| Memory allocated | 2,8 MB | 2,4 MB | -0,4 MB = -14 % |
| Objects allocated | 43678 | 38463 | -5215 = -12 % |
| Private bytes | 26,6 MB | 24,4 MB | -2,2 MB = -8,3% |
| Working set | 26,6 MB | 24,4 MB | -2,2 MB = -8,3% |
2016-11-01 21:34:56 +03:00
2016-04-21 15:19:32 +03:00
new XDelegate ("MonoObject *", "IntPtr", "xamarin_get_inative_object_static",
"id", "IntPtr", "obj",
"bool", "bool", "owns",
"const char *", "string", "type_name",
"const char *", "string", "iface_name"
2018-02-02 20:20:58 +03:00
) {
WrappedManagedFunction = "GetINativeObject_Static",
OnlyDynamicUsage = false,
},
2016-04-21 15:19:32 +03:00
new XDelegate ("MonoObject *", "IntPtr", "xamarin_get_nsobject_with_type",
"id", "IntPtr", "obj",
"void *", "IntPtr", "type",
2018-06-29 15:38:28 +03:00
"int32_t *", "out bool", "created",
"SEL", "IntPtr", "selector",
"MonoReflectionMethod *", "IntPtr", "method"
2018-02-02 20:20:58 +03:00
) {
WrappedManagedFunction = "GetNSObjectWithType",
OnlyDynamicUsage = false,
},
2016-04-21 15:19:32 +03:00
new XDelegate ("void", "void", "xamarin_dispose",
"MonoObject *", "IntPtr", "mobj"
2018-02-02 20:20:58 +03:00
) {
WrappedManagedFunction = "Dispose",
OnlyDynamicUsage = false,
},
2016-04-21 15:19:32 +03:00
new XDelegate ("bool", "bool", "xamarin_is_parameter_transient",
"MonoReflectionMethod *", "IntPtr", "method",
"int", "int", "parameter"
2018-02-02 20:20:58 +03:00
) {
WrappedManagedFunction = "IsParameterTransient",
OnlyDynamicUsage = true,
},
2016-04-21 15:19:32 +03:00
new XDelegate ("bool", "bool", "xamarin_is_parameter_out",
"MonoReflectionMethod *", "IntPtr", "method",
"int", "int", "parameter"
2018-02-02 20:20:58 +03:00
) {
WrappedManagedFunction = "IsParameterOut",
OnlyDynamicUsage = true,
},
2016-04-21 15:19:32 +03:00
2017-07-03 20:18:02 +03:00
new XDelegate ("void", "void", "xamarin_get_method_and_object_for_selector",
2016-04-21 15:19:32 +03:00
"Class", "IntPtr", "cls",
"SEL", "IntPtr", "sel",
2017-09-07 14:05:44 +03:00
"bool", "bool", "is_static",
2016-04-21 15:19:32 +03:00
"id", "IntPtr", "obj",
2017-07-03 20:18:02 +03:00
"MonoObject **", "ref IntPtr", "mthis",
"MethodDescription *", "IntPtr", "desc"
2018-02-02 20:20:58 +03:00
) {
WrappedManagedFunction = "GetMethodAndObjectForSelector",
OnlyDynamicUsage = true,
},
2016-04-21 15:19:32 +03:00
2016-06-02 13:18:45 +03:00
new XDelegate ("guint32", "int", "xamarin_create_product_exception_for_error",
2016-04-21 15:19:32 +03:00
"int", "int", "code",
"const char *", "string", "message"
2018-02-02 20:20:58 +03:00
) {
WrappedManagedFunction = "CreateProductException",
OnlyDynamicUsage = false,
},
2016-04-21 15:19:32 +03:00
new XDelegate ("char *", "IntPtr", "xamarin_reflection_type_get_full_name",
"MonoReflectionType *", "IntPtr", "type"
2018-02-02 20:20:58 +03:00
) {
WrappedManagedFunction = "TypeGetFullName",
2018-03-01 00:28:06 +03:00
OnlyDynamicUsage = false,
2018-02-02 20:20:58 +03:00
},
2016-04-21 15:19:32 +03:00
new XDelegate ("char *", "IntPtr", "xamarin_lookup_managed_type_name",
"Class", "IntPtr", "klass"
2018-02-02 20:20:58 +03:00
) {
WrappedManagedFunction = "LookupManagedTypeName",
OnlyDynamicUsage = false,
},
2016-05-11 14:27:51 +03:00
2018-03-01 20:04:01 +03:00
new XDelegate ("enum MarshalManagedExceptionMode", "MarshalManagedExceptionMode", "xamarin_on_marshal_managed_exception",
2016-05-11 14:27:51 +03:00
"int", "int", "exception"
2018-02-02 20:20:58 +03:00
) {
WrappedManagedFunction = "OnMarshalManagedException",
OnlyDynamicUsage = false,
},
2016-05-11 14:27:51 +03:00
2018-03-01 20:04:01 +03:00
new XDelegate ("enum MarshalObjectiveCExceptionMode", "MarshalObjectiveCExceptionMode", "xamarin_on_marshal_objectivec_exception",
2016-06-06 15:33:37 +03:00
"id", "IntPtr", "exception",
"bool", "bool", "throwManagedAsDefault"
2018-02-02 20:20:58 +03:00
) {
WrappedManagedFunction = "OnMarshalObjectiveCException",
OnlyDynamicUsage = false,
},
2017-07-03 20:18:02 +03:00
new XDelegate ("NSString *", "IntPtr", "xamarin_convert_smart_enum_to_nsstring",
"void *", "IntPtr", "value"
2018-02-02 20:20:58 +03:00
) {
WrappedManagedFunction = "ConvertSmartEnumToNSString",
OnlyDynamicUsage = true,
},
2017-07-03 20:18:02 +03:00
new XDelegate ("void *", "IntPtr", "xamarin_convert_nsstring_to_smart_enum",
"NSString *", "IntPtr", "value",
"MonoReflectionType *", "IntPtr", "type"
2018-02-02 20:20:58 +03:00
) {
WrappedManagedFunction = "ConvertNSStringToSmartEnum",
OnlyDynamicUsage = true,
},
2018-06-29 15:38:28 +03:00
new XDelegate ("int32_t", "int", "xamarin_create_runtime_exception",
"int32_t", "int", "code",
"const char *", "IntPtr", "message"
) {
WrappedManagedFunction = "CreateRuntimeException",
OnlyDynamicUsage = false,
},
2016-04-21 15:19:32 +03:00
};
delegates.CalculateLengths ();
#><#+
class Arg
{
public string CType;
public string MType;
public string Name;
}
class XDelegates : List<XDelegate>
{
public void CalculateLengths ()
{
foreach (var x in this) {
MaxEntryPointLength = Math.Max (MaxEntryPointLength, x.EntryPoint.Length);
MaxCReturnTypeLength = Math.Max (MaxCReturnTypeLength, x.CReturnType.Length);
x.Delegates = this;
}
}
public int MaxEntryPointLength;
public int MaxCReturnTypeLength;
}
class XDelegate
{
public string CReturnType;
public string MReturnType;
public string EntryPoint;
public List<Arg> Arguments;
public string WrappedManagedFunction;
2016-06-02 13:18:45 +03:00
public bool ExceptionHandling = true;
2018-02-02 20:20:58 +03:00
// Detemines whether the function is only used by the dynamic registrar (in which case we might be able to link the function away if the static registrar is being used)
public bool OnlyDynamicUsage;
2016-04-21 15:19:32 +03:00
public XDelegates Delegates;
public XDelegate (string cReturnType, string mReturnType, string entryPoint, params string [] arguments)
{
CReturnType = cReturnType;
MReturnType = mReturnType;
EntryPoint = entryPoint;
if (arguments == null || arguments.Length == 0)
return;
if (arguments.Length % 3 != 0)
throw new Exception (string.Format ("Export arguments params must be a multiple of 3 to form a set of (c type, managed name, name) triples for {0}", entryPoint));
if (!entryPoint.StartsWith ("xamarin_"))
throw new Exception ("All entry points must start with 'xamarin_'");
Arguments = new List<Arg> ();
for (var i = 0; i < arguments.Length; i += 3)
Arguments.Add (new Arg {
CType = arguments [i],
MType = arguments [i + 1],
Name = arguments [i + 2]
});
}
public string SimpleEntryPoint {
get {
return EntryPoint.Substring ("xamarin_".Length);
}
}
public string AlignEntryPoint {
get {
return new string (' ', Delegates.MaxEntryPointLength - EntryPoint.Length);
}
}
public string AlignCReturnType {
get {
return new string (' ', Delegates.MaxCReturnTypeLength - CReturnType.Length);
}
}
string CFormatArgs (string empty, bool nameOnly)
{
if (Arguments == null || Arguments.Count == 0)
return empty;
var builder = new StringBuilder ();
foreach (var arg in Arguments) {
if (!nameOnly) {
builder.Append (arg.CType);
builder.Append (' ');
}
builder.Append (arg.Name);
builder.Append (", ");
}
builder.Length -= 2;
2016-06-02 13:18:45 +03:00
if (ExceptionHandling) {
if (nameOnly) {
builder.Append (", exception_gchandle");
} else {
builder.Append (", guint32 *exception_gchandle");
}
}
2016-04-21 15:19:32 +03:00
return builder.ToString ();
}
string MFormatArgs (string empty, bool nameOnly)
{
if (Arguments == null || Arguments.Count == 0)
return empty;
var builder = new StringBuilder ();
foreach (var arg in Arguments) {
if (!nameOnly) {
builder.Append (arg.MType);
builder.Append (' ');
} else if (arg.MType.StartsWith ("out ")) {
builder.Append ("out ");
} else if (arg.MType.StartsWith ("ref ")) {
builder.Append ("ref ");
}
builder.Append (arg.Name);
builder.Append (", ");
}
builder.Length -= 2;
2016-06-02 13:18:45 +03:00
if (ExceptionHandling) {
if (nameOnly) {
// nothing to do
} else {
builder.Append (", out int exception_gchandle");
}
}
2016-04-21 15:19:32 +03:00
return builder.ToString ();
}
public string CArgumentSignature {
get { return CFormatArgs ("void", nameOnly: false); }
}
public string CArgumentNames {
get { return CFormatArgs (String.Empty, nameOnly: true); }
}
public string MArgumentSignature {
get { return MFormatArgs ("", nameOnly: false); }
}
public string MArgumentNames {
get { return MFormatArgs (String.Empty, nameOnly: true); }
}
}
#>