Граф коммитов

45 Коммитов

Автор SHA1 Сообщение Дата
Alex Soto f8d7c54a0f [generator] Disallow the use of [Async] when the signature contains ref/out parameters, fixes bug 58792. (#3059)
When a method signature contains any ref/out parameters
it is a hint that this method is not a candidate to be
used with [Async] we now error BI1062 in the generator.

The reason of an error instead of a warning is that we
currently generate not compilable code when ref/out is
used on the method signature or in the signature of the
delegate (completion handler), it is very unlikely we are
breaking someone now that we emit an error instead of broken
code.

* Fix Anchor and Clarify the addition of BI1117 Warning into docs/website/generator-errors.md

BI1117 Warning documentation was missing from docs/website/generator-errors.md
so I added it.
2017-12-18 09:21:23 -05:00
Rolf Bjarne Kvinge dd95d17b5f
[generator] Properly set the IsDirectBinding value. (#3063)
* [generator] Properly set the IsDirectBinding value.

Properly set the IsDirectBinding value to false for models and synthetic types.

This also means we can now stop excluding models when testing if the
IsDirectBinding value is correct.

Also set IsDirectBinding value to true for sealed wrapper types, since those
will always be direct bindings since they can't be subclassed.

https://gist.github.com/rolfbjarne/24028bf944db848fed4083c460d0ec71

* [tests] Add introspection exclusion for XM.

* [introspection] Add back exclusions for Classic, since we can't modify/fix Classic assemblies anymore.

* [generator] Print the correct protocol name with the protocol attribute.

Fixes this test failure:

    [FAIL] Foundation.NSUrlDownloadDelegate : ConformsToProtocol(null) failed

because our binding code claimed that our `NSUrlDownloadDelegate` class
implemented the `NSUrlDownloadDelegate` protocol, but since the
`NSUrlDownloadDelegate` protocol doesn't exist (it's `NSURLDownloadDelegate` -
different case), we'd verify against a null protocol (and return true from
`ConformsToProtocol(null)`, which would fail the test).

* [xtro] Only treat interfaces as protocols.

Unfortunately we add [Protocol] to [Model]s as well as on interfaces, but we
must not process those in xtro, since they don't correspond with the actual protocol.
2017-12-01 15:18:20 +01:00
Rolf Bjarne Kvinge efebe2b73b
[tests] Port the makefile-based generator tests to NUnit. (#3019)
* [tests][generator] Port bindas1048error to NUnit.

* [tests][generator] Port bindas1049error to NUnit.

* [tests][generator] Port bindas1050modelerror to NUnit.

* [tests][generator] Port bindas1050protocolerror to NUnit.

* [tests][generator] Port bug42855 to NUnit.

* [tests][generator] Port bug57070 to NUnit.

* [tests][generator] Port bug52570classinternal to NUnit.

* [tests][generator] Port bug52570methodinternal to NUnit.

* [tests][generator] Port bug52570allowstaticmembers to NUnit.

* [tests][generator] Port protocol-duplicate-abstract-error to NUnit.

* [tests][generator] Port protocol-duplicate-method-diff-length to NUnit.

* [tests][generator] Port protocol-duplicate-method-diff-out to NUnit.

* [tests][generator] Port protocol-duplicate-method-diff-type to NUnit.

* [tests][generator] Port protocol-duplicate-method-diff-return to NUnit.

* [tests][generator] Port warnaserror to NUnit.

* [tests][generator] Port nowarn to NUnit.

* [tests][generator] Add support for inspecting/asserting the generated content.

* [tests][generator] Port some Xamarin.Mac tests to NUnit.

Ported:

* bmac_smoke
* bmac-with-hyphen-in-name
* property-redefination-mac
* NSApplicationPublicEnsureMethods
* protocol-duplicate-abstract

* [tests][generator] Point bgen to our local installation.

* [tests][generator] Port the bug31788 test to a unit test.

* [generator] Make the 'bgen' helper target more complete.

* [tests][generator] Port non-custom iOS tests to unit tests.

* [tests][generator] Add new test.

* [tests][generator] Port the forum54078 test to a unit test.

* [tests][generator] Port the desk63279 test to a unit test.

* [tests][generator] Port the desk79124 test to a unit test.

* [tests][generator] Port the multiple-api-definitions tests to unit tests.

* [generator] Use mono code style.

* [tests][generator] Port the bug29493 test to a unit test.

* [tests][generator] Port the classNameCollision test to a unit test.

* [tests][generator] Port the bi1036 test to a unit test.

* [tests][generator] Port the bug37527 test to a unit test.

Also fix BI1112 and BI1113 to show up as errors in the console output (since
they're exceptions they're already treated as errors and would cause bgen to
fail).

* [tests][generator] Port the bug27986 test to a unit test.

* [tests][generator] Port the bug35176 test to a unit test.

* [tests][generator] Port the bi1046 test to a unit test.

* [tests][generator] Port the virtualwrap test to a unit test.

* [tests][generator] Port the bug42742 test to a unit test.

* [tests][generator] Port the noasyncinternalwrapper test to a unit test.

* [tests][generator] Port the noasyncwarningcs0219 test to a unit test.

* [tests][generator] Port the bug53076 test to a unit test.

* [tests][generator] Port the bug53076withmodel test to a unit test.

* [tests][generator] Port the fieldenumtests test to a unit test.

* [tests][generator] Port the smartenumwithframework test to a unit test.

* [tests][generator] Port the forcedtype test to a unit test.

* [tests][generator] Port the bug46292 test to a unit test.

* [tests][generator] Build tests with MSBuild.

There's no need to use xbuild for these tests.

* [tests][generator] Remove dead code.

* [xharness] Don't run the makefile-based generator tests anymore.

Since there aren't any makefile-based generator tests anymore, they've all
been ported to NUnit tests.

* [tests][generator] Make the bug39614 test do what it was supposed to do: make sure a namespace isn't required (but recommended).
2017-11-20 14:55:16 +01:00
Rolf Bjarne Kvinge e8d16c925b
[mtouch/mmp/bgen] Add support for response files. (#2808)
* [mtouch/mmp/bgen] Add support for response files.

This is the first part of the fix for #56501.

https://bugzilla.xamarin.com/show_bug.cgi?id=56501

* [tests] Make sure no single argument starting with a '@' is passed to mtouch unless it's a response file.

--assembly-build-target takes arguments starting with '@', for instance:

    --assembly-build-target @all=framework

which does not work anymore, because that's interpreted as a response file
(mtouch tries to read the file '@all=framework', which obviously doesn't
exist).

The fix is simple, don't put a space between the two arguments:

    --assembly-build-target=@all=framework

* Add --root-assembly to mtouch/mmp and make the MSBuild tasks use this new option.

This makes it possible to pass root assemblies starting with `@` to mtouch/mmp
without getting mistaken for response files.

* [msbuild] Always use the command-line option that takes an equals or colon.

Always use the command-line option that takes an equals or colon instead of a
space.

Do either of these:

    --foo=something
    --foo:something

instead of this:

    --foo something

so that `something` can start with an at (`@`) sign without being mistaken for
a response file.

* [msbuild] Fix tests according to recent task changes.
2017-11-16 16:02:34 +01:00
Bernhard Urban 20182800a1
[runtime] integrate mono 2017-10 (#2905)
* Update the function name used to initialize libmono-profiler-log, its called mono_profiler_init_log () now.

* [builds] Pass --with-cross-offsets= to crosstv's configure.

* Bump mono to 2017-08.

* Bump mono to 2017-08.

* Force disable 'futimens' and 'utimensat' so that we build with Xcode 9.

This is also needed to build with Xcode 8.3 on High Sierra.

* Remove old AppleTls implementation.

* Bump mono.

* Bump mono to 2017-08.

* Bump mono to 2017-08

* Reenable link-keep-resources-2 test

- This reverts commit 76b759ef22.
- 2017-08 has linker fix

* Bump mono to 2017-10

* Revert "Bump mono to 2017-10"

This reverts commit bb7832724e.

* Bump system mono to 2017-10

* Bump embedded mono to 2017-10

* [runtime] reflect eglib move

9be68f8952

* bump mono

* [btouch] remove Security.Tls usage from test

* [mtouch tests] update the function name used to initialize libmono-profiler-log, its called mono_profiler_init_log () now.

see
ea4e4a9ef6

fixes:

```
1) Failed : Xamarin.MTouch.Profiling(tvOS)
  _mono_profiler_startup_log
  Expected: collection containing "_mono_profiler_startup_log"
  But was:  < "_mono_profiler_init_log" >
at Xamarin.MTouch.Profiling (Xamarin.Profile profile) [0x00106] in <511889694a624cc9a50e0e9b259b05c5>:0

2) Failed : Xamarin.MTouch.Profiling(watchOS)
  _mono_profiler_startup_log
  Expected: collection containing "_mono_profiler_startup_log"
  But was:  < "_xamarin_get_block_descriptor", "_mono_profiler_init_log" >
at Xamarin.MTouch.Profiling (Xamarin.Profile profile) [0x00106] in <511889694a624cc9a50e0e9b259b05c5>:0
```

* [mmptest] update log profiler options.

826558a4af
deprecated the dash prefix for the mlpd path.

`noallocs` or `nocalls` are not needed, neither of them are default anymore.

* [mmptest] fix link-keep-resources-2 test to cope with more corlib resources.

another corlib resource (mscorlib.xml) was added:

https://github.com/mono/mono/commit/11e95169e787#diff-2d1c64decd91d9a6e8842ab0f0e9438d

* Revert "[mmptest] fix link-keep-resources-2 test to cope with more corlib resources."

This reverts commit 350eb3c174.

* [XHarness] Add the Mono.Data.Tds tests.

* Address comments from rolf in the review.

* [mmp regresssion tests] bump mono linker, so mscorlib.xml gets stripped

the test was failing in that way:

> Executing link-keep-resources-2...
> [FAIL]	i18n 4/2 data files present: charinfo.nlp, collation.core.bin, collation.tailoring.bin, mscorlib.xml

also update the output, because it's actually expected at least three
elements.

fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=59277

* bump mono

fixes crash in tvOS: https://github.com/mono/mono/pull/5812

* bump mono for updated BCL tests

see https://github.com/mono/mono/pull/5820

* [mono] set 2017-10 branch in .gitmodules

* [macos] Fix guiunit error on clean builds by depending on correct copy (#2912)

* [macos] Fix guiunit error on clean builds by depending on correct copy

- From a clean build making a BCL test would error due to the non-mobile guiunit not being built
- This was because the Makefile-mac.inc target was incorrect
- This was because xharness assumed that non variation based targets were always Modern
- However, BCL tests are Full, not Modern

* Code review change

* Swap to var to reduce diff

* Revert changes in the paths for GuiUnit.

* [XHarness] Add the System.IO.Compression bcl tests. (#2918)

* [XHarness] Add the System.IO.Compression bcl tests.

*  [XHarness] Add bcl tests for System.IO.Compression.FileSystem. (#2924)

* [XHarness] Add the System.IO.Compression bcl tests.

* Ensure that resources are correctly copied in the bundles.

* [XHarness] Add bcl tests for System.IO.Compression.FileSystem.

* As per review, make the Mac test app name match the tests that are ran.

* [XHarness] Add Mono.CSharp tests on ios. (#2927)

* [XHarness] Add Mono.CSharp tests on ios.

* Bump mono to bring changes in the mono.csharp tests.

* [xtro-sharpie] fix TypeDefinition access due to Cecil change

* Bump mono

* bump mono

fixes
- https://bugzilla.xamarin.com/show_bug.cgi?id=60480
- https://bugzilla.xamarin.com/show_bug.cgi?id=60482

* bump mono

more fixes around conflicting paths when tests are run in parallel.

* Bump for mono/mono@2017-10
2017-11-14 21:30:08 +01:00
Alex Soto 21a56a5f27
[generator] Improve BI1014 - include name of unsupported field and update valid types on docs, fixes bug 57094. (#3001)
* [generator] Improve BI1014 - include name of unsupported field and update valid types on docs, fixes bug 57094.

https://bugzilla.xamarin.com/show_bug.cgi?id=57094

* Implement feedback

* fix error message

* More feedback
2017-11-14 08:46:46 -06:00
Alex Soto b197eab50e
[generator] Fix slightly incorrect error message when trying to use ref/out parameters with BindAs attributes, fixes 57804. (#2997)
https://bugzilla.xamarin.com/show_bug.cgi?id=57804
2017-11-13 14:21:18 -06:00
Alex Soto ee19c79feb
[Generator] BindAs attribute for smart enums of an array of nullable values generates code that doesn't compile, Fixes bug 57797 (#2954)
* [Generator] BindAs attribute for smart enums of an array of nullable values generates code that doesn't compile, Fixes bug 57797

https://bugzilla.xamarin.com/show_bug.cgi?id=57797

We now correctly compiles the array nullabe types

* Disable Nullable array types in BindAs until we add registrar support
2017-11-13 10:54:21 -06:00
Alex Soto 8e92d2a350
[Generator] BindAs attribute for smart enum to multidimensional array generates code that doesn't compile, Fixes Bug 57795 (#2948)
https://bugzilla.xamarin.com/show_bug.cgi?id=57795

We now error out with "BI1048 Unsupported type Foo[,] decorated with [BindAs]"
2017-11-02 08:34:10 -06:00
Rolf Bjarne Kvinge 40d9cb9bf1 Merge remote-tracking branch 'origin/master' into bindas-registrar-support 2017-09-26 10:58:35 +02:00
Rolf Bjarne Kvinge cd542a0845 [generator] Remove non-IKVM code. (#2769) 2017-09-25 14:37:51 -04:00
Rolf Bjarne Kvinge a979a10412 Merge remote-tracking branch 'origin/master' into bindas-registrar-support 2017-09-22 10:50:07 +02:00
Alex Soto dc1b5746eb [generator] Fix smart enum FieldAttribute LibraryName generation (#2376)
This fix is needed by PDFKit because it is a remapped framework[0],
the current code generates incorrect FieldAttribute on smart enums
because it uses `fa.LibraryName` as first option and this causes
remmaped frameworks have incorrect LibraryName generated for example
if a Field uses `+CoreImage` as `LibraryName` the following incorrect
code is generated:

```
	[Field ("First", "+CoreImage")]
	internal unsafe static IntPtr First {
		get {
			fixed (IntPtr *storage = &values [0])
				return Dlfcn.CachePointer (Libraries.+CoreImage.Handle, "First", storage);
		}
	}
```

[0]: f5956d6cc1/src/generator.cs (L5985)
2017-07-26 18:09:42 -05:00
Rolf Bjarne Kvinge 871c055308 [generator] Add unit test project, and port a few tests over from the makefile tests. (#2299) (#2304) 2017-07-11 08:52:24 +02:00
Alex Soto 81e1340865 [generator] Persist BindAs attribute information in generated code.
Persisting BindAs attributes is required for the registrars to be able to
handle methods with BindAs attributes correctly.

Generator diff: https://gist.github.com/rolfbjarne/0fafbce9373ff1f407839a20ea5e72e9
2017-07-04 07:31:13 +02:00
Alex Soto 3c5221b214 [generator] Add enum support for [FieldAttribute], Fixes 57537 and 57535. (#2230)
* [ObjCRuntime] Add GetUInt32/SetUInt32/SetNInt/SetNUInt/SetNFloat to Dlfcn

https://bugzilla.xamarin.com/show_bug.cgi?id=57535
https://bugzilla.xamarin.com/show_bug.cgi?id=57537

This commit is part of the fix for the above bugs, we lacked
GetUInt32/SetUInt32/SetNInt/SetNUInt/SetNFloat in Dlfcn and we
have code inside generator that relies on the methods to be
available 0a316951a3/src/generator.cs (L6090-L6095)

* [generator] Add enum and uint support to FieldAttribute

Fixes:
* https://bugzilla.xamarin.com/show_bug.cgi?id=57535
* https://bugzilla.xamarin.com/show_bug.cgi?id=57537

New Features:
* Added Smart Enum support to [Field]
* Added [Native] enum support to [Field]
* Added enum support to [Field]
* Added uint support to [Field]

Also fixed a bug in Smart Enums support when computing the library name
taking into account third party bindings and some special cases, this is
needed because we ended up generating invalid code when Smart Enum support
was used in third party bindings.

Also added Field Enum generation test.

* Implement PR feedback and added [Get/Set]UInt64 to Dlfcn and [Field] support for it too.
2017-06-20 13:46:00 -05:00
Rolf Bjarne Kvinge bc75388fbc [generator] Improve error reporting for api definition that uses the deprecated availability attributes. Fixes #57070. (#2166)
https://bugzilla.xamarin.com/show_bug.cgi?id=57070
2017-06-02 18:31:10 +02:00
Alex Soto 43e220df7f [generator] Keep [NotImplemented] info so it is usable in 3rd party bindings. Fixes bug 52664 (#2131)
* [generator] Keep [NotImplemented] info so it is usable in 3rd party bindings. Fixes bug 52664

https://bugzilla.xamarin.com/show_bug.cgi?id=52664

Currently we do not keep the [NotImplemented](0) information and the
generator gets a little confused because it will not find an Export
inside the getters/setters of properties and there is no way to tell
if this was intentional or not. We now keep the [NotImplemented]
and also add some null checks in the generator where needed.

Reenabled tests disabled in 9f036b218a

[0]: https://developer.xamarin.com/guides/cross-platform/macios/binding/objective-c-libraries/#Objective-C_Mutable_Pattern_and_Properties

* [generator] Implement feedback

* Added quote method
* Teach linker about NotImplementedAttribute

* [generator] Improve Quote method

* [generator] Fix quote now for realsssss
2017-05-25 14:42:25 -05:00
Alex Soto b75f8eda31 [generator] Create CVPixelBuffer using GetINativeObject so its usable from 3rd party bindings (#2111)
* [generator] Create CVPixelBuffer using GetINativeObject so its usable from 3rd party bindings

Complements https://bugzilla.xamarin.com/show_bug.cgi?id=52665
and PR #2102

CVPixelBuffer was created using the internal handle ctor, this
did not allow 3rd party bindings to bind it correctly since it
generated not compilable code.

We now use Runtime.GetINativeObject<CVPixelBuffer> (ptr, false); just
like the base ctor https://git.io/vHvLj.

* [tests] Add IntPtr.Zero check and fix link in code

* [generator] Make comment easier to find
2017-05-19 11:10:22 -05:00
Alex Soto 9621842016 [generator] Deriving from certain protocol interfaces generates uncompilable code. Fixes bug 52665 (#2102)
Some namespaces are missing on generated files, causing error CS0246
The type or namespace name `Foo` could not be found.

While fixing this another error arose, by enabling the following test

[Protocol] interface C140 : ICIImageProcessorInput {}

some codepaths leads to CVPixelBuffer creation which our code
tries to invoke the handle ctor and fails to find it because it
is internal. This will be fixed in a different commit.
2017-05-18 12:42:57 -04:00
Alex Soto ed505623be [tests] Fix RequiredMethodAsync test (#1931)
When merging https://github.com/xamarin/xamarin-macios/pull/1913 I
forgot to fix RequiredMethodAsync test, we now expect one instance of
a RequiredMethodAsync as an extension method
2017-03-29 11:12:56 +02:00
Alex Soto 28ad23d142 [generator] Remove [Async] members from [Model] classes, fixes bug 53076.
https://bugzilla.xamarin.com/show_bug.cgi?id=53076

When [Async] was used on a member of a [Model][Protocol][Basetype]
interface the ModelClass ended up with additional FooAsync methods that
are not really part of the Model.

This commit removed any instances of FooAsync members from model classes
and also fixes any breaking changes in the currently bound classes.

Added test case using Model.

build diff:
https://gist.github.com/dalexsoto/75cb8424f2462bd6b513049f00bba6a8
2017-03-25 00:35:36 -06:00
Alex Soto 340ade8c68 [generator] Turn [Async] methods inside [Protocol] into extension methods
Partial fix for:
https://bugzilla.xamarin.com/show_bug.cgi?id=53076

We currently generate extension methods for optional members decorated
with [Async] inside a [Protocol] but we ignore the required methods
decorated with [Async]. This commit fixes this issue and we now
generate extension methods for required members.

Lets take the following API definition

```csharp
[Protocol]
interface MyFooProtocol {

	[Abstract]
	[Async]
	[Export ("requiredMethod:completion:")]
	void RequiredMethod (int arg1, Action<NSError> err);

	[Async]
	[Export ("optional:completion:")]
	void OptionalMethod (int arg1, Action<NSError> err);
}
```

This generates:

```csharp
public static partial class MyFooProtocol_Extensions {
	[CompilerGenerated]
	public unsafe static void OptionalMethod (this IMyFooProtocol This, int arg1, [BlockProxy (typeof (ObjCRuntime.Trampolines.NIDActionArity1V0))]global::System.Action<NSError> err)
	{
		if (err == null)
			throw new ArgumentNullException ("err");
		BlockLiteral *block_ptr_err;
		BlockLiteral block_err;
		block_err = new BlockLiteral ();
		block_ptr_err = &block_err;
		block_err.SetupBlock (Trampolines.SDActionArity1V0.Handler, err);

		global::ApiDefinition.Messaging.void_objc_msgSend_int_IntPtr (This.Handle, Selector.GetHandle ("optional:completion:"), arg1, (IntPtr) block_ptr_err);
		block_ptr_err->CleanupBlock ();

	}

	[CompilerGenerated]
	public unsafe static Task OptionalMethodAsync (this IMyFooProtocol This, int arg1)
	{
		var tcs = new TaskCompletionSource<bool> ();
		This.OptionalMethod(arg1, (obj_) => {
			if (obj_ != null)
				tcs.SetException (new NSErrorException(obj_));
			else
				tcs.SetResult (true);
		});
		return tcs.Task;
	}

	[CompilerGenerated]
	public unsafe static Task RequiredMethodAsync (this IMyFooProtocol This, int arg1)
	{
		var tcs = new TaskCompletionSource<bool> ();
		This.RequiredMethod(arg1, (obj_) => {
			if (obj_ != null)
				tcs.SetException (new NSErrorException(obj_));
			else
				tcs.SetResult (true);
		});
		return tcs.Task;
	}

}
```

Adds unit test

Build diff:
https://gist.github.com/dalexsoto/75290d1ffa1fdfb529cc30b9e66de5f2
2017-03-25 00:25:45 -06:00
Alex Soto 155e414e9c [generator] Disable CS0219 when using AsyncAttribute to avoid warning
Currently we get a CS2019 warning whenever we use AsyncAttribute
because we ignore the `result` variable on methods whose return
type is != `void` which is the expected behaviour.

This is specially more annoying on third party bindings,
the generated code did not disable this warning so you get
an "unfixable" warning on the generated code and the user
has no way to fix this on their own.

We now disable and restore CS2019 in the generated code as needed.
Nobody likes warnings that are not their fault.

Added unit test.

Build diff:

https://gist.github.com/dalexsoto/6f57d3f84b039b9fda863e2f8cfcf365
2017-03-24 21:08:40 -06:00
Alex Soto 577d0119df [generator] Remove Async members from internal BaseWrapper derived types
Currently we generate FooAsync members inside internal BaseWrapper
derived types used by protocol support. This generated Async members
are useles so we remove them to avoid extra metadata.

Old generated code

```csharp
internal sealed class MyFooDelegateWrapper : BaseWrapper, IMyFooDelegate {
	[Preserve (Conditional = true)]
	public MyFooDelegateWrapper (IntPtr handle, bool owns)
		: base (handle, owns)
	{
	}

	[Export ("stringMethod:completion:")]
	[CompilerGenerated]
	public unsafe void StringMethod (int arg1, [BlockProxy (typeof (ObjCRuntime.Trampolines.NIDActionArity1V0))]global::System.Action<NSError> err)
	{
		if (err == null)
			throw new ArgumentNullException ("err");
		BlockLiteral *block_ptr_err;
		BlockLiteral block_err;
		block_err = new BlockLiteral ();
		block_ptr_err = &block_err;
		block_err.SetupBlock (Trampolines.SDActionArity1V0.Handler, err);

		global::ApiDefinition.Messaging.void_objc_msgSend_int_IntPtr (this.Handle, Selector.GetHandle ("stringMethod:completion:"), arg1, (IntPtr) block_ptr_err);
		block_ptr_err->CleanupBlock ();

	}

	[CompilerGenerated]
	public unsafe Task StringMethodAsync (int arg1)
	{
		var tcs = new TaskCompletionSource<bool> ();
		StringMethod(arg1, (obj_) => {
			if (obj_ != null)
				tcs.SetException (new NSErrorException(obj_));
			else
				tcs.SetResult (true);
		});
		return tcs.Task;
	}

}
```

new generated code:

```csharp
internal sealed class MyFooDelegateWrapper : BaseWrapper, IMyFooDelegate {
	[Preserve (Conditional = true)]
	public MyFooDelegateWrapper (IntPtr handle, bool owns)
		: base (handle, owns)
	{
	}

	[Export ("stringMethod:completion:")]
	[CompilerGenerated]
	public unsafe void StringMethod (int arg1, [BlockProxy (typeof (ObjCRuntime.Trampolines.NIDActionArity1V0))]global::System.Action<NSError> err)
	{
		if (err == null)
			throw new ArgumentNullException ("err");
		BlockLiteral *block_ptr_err;
		BlockLiteral block_err;
		block_err = new BlockLiteral ();
		block_ptr_err = &block_err;
		block_err.SetupBlock (Trampolines.SDActionArity1V0.Handler, err);

		global::ApiDefinition.Messaging.void_objc_msgSend_int_IntPtr (this.Handle, Selector.GetHandle ("stringMethod:completion:"), arg1, (IntPtr) block_ptr_err);
		block_ptr_err->CleanupBlock ();

	}
}
```

Added unit test.

build diff for this change:

https://gist.github.com/dalexsoto/eeaefc9d86e37b0c5ce5fe6d5d091383
2017-03-24 17:40:55 -06:00
Rolf Bjarne Kvinge d942fcff14 [tests][generator] Simplify mac tests a bit and fix new tests when using IKVM-based bgen.
Simplify mac tests by using different variables for the various flavors of mac
generators, and use these new flavors so that all tests pass when using the
IKVM-based bgen.
2017-03-22 16:22:33 +01:00
Rolf Bjarne Kvinge 8a29f0deae Merge remote-tracking branch 'origin/master' into generator-ikvm 2017-03-22 14:11:00 +01:00
Alex Soto ebcb4ac034 [generator] Fix bug 52573 - Add nowarn and warnaserror to btouch/bmac (#1882)
https://bugzilla.xamarin.com/show_bug.cgi?id=52573

* Added nowarn and warnaserror to btouch/bmac
* Throw a BI0026 if bad args and added error to doc
* Added generator tests
2017-03-22 07:52:24 -05:00
Alex Soto 818c20b19a [generator] The [Advice] attribute doesn't make it to the generated code. Fixes #42742 (#1887)
* [generator] Fix bug 42742 The advice attribute doesn't make it to the generated code

https://bugzilla.xamarin.com/show_bug.cgi?id=42742

The Advice attribute used in our bindings was not making
into the generated code. This fixes it.

Also added unit test for it

* [generator] Merged PrintFooAttributes into one

Merged PrintPlatformAttributes, PrintPreserveAttribute and
PrintAdviceAttribute into a single method PrintAttributes.
This is due to sometimes we call three times in a row the same method:

```csharp
PrintPlatformAttributes (pi.GetGetMethod ());
PrintPreserveAttribute (pi.GetGetMethod ());
PrintAdviceAttribute (pi.GetGetMethod ());
```

We now do

```csharp
PrintAttributes (pi, platform:true, preserve:true, advice:true);
```

Also removed a not used instance (internal field) of AdviceAttribute
2017-03-21 09:20:05 -06:00
Rolf Bjarne Kvinge 001790ff4e Merge remote-tracking branch 'origin/master' into generator-ikvm 2017-03-16 19:09:33 +01:00
Alex Soto 78052430ab [generator] Fixes bug 52570 - [generator] warn when [Static] is used in a [Category] (#1862)
https://bugzilla.xamarin.com/show_bug.cgi?id=52570

In some cases you will find **static** members inside categories like in the following example:

```objc
@interface FooObject (MyFooObjectExtension)
+ (BOOL)boolMethod:(NSRange *)range;
@end
```

This will lead to an **incorrect** Category C# interface definition:

```csharp
[Category]
[BaseType (typeof (FooObject))]
interface FooObject_Extensions {

	// Incorrect Interface definition
	[Static]
	[Export ("boolMethod:")]
	bool BoolMethod (NSRange range);
}
```

This is incorrect because in order to use the `BoolMethod` extension you need an instance of `FooObject` but you are binding an ObjC **static** extension, this is a side effect due to the fact of how C# extension methods are implemented.

The only way to use the above definitions is by the following ugly code:

```csharp
(null as FooObject).BoolMethod (range);
```

The recommendation to avoid this is to inline the `BoolMethod` definition inside the `FooObject` interface definition itself, this will allow you to call this extension like it is intended `FooObject.BoolMethod (range)`.

```csharp
[BaseType (typeof (NSObject))]
interface FooObject {

	[Static]
	[Export ("boolMethod:")]
	bool BoolMethod (NSRange range);
}
```

We will issue a warning (BI1117) whenever we find a `[Static]` member inside a `[Category]` definition. If you really want to have `[Static]` members inside your `[Category]` definitions you can silence the warning by using `[Category (allowStaticMembers: true)]` or by decorating either your member or `[Category]` interface definition with `[Internal]`.
2017-03-14 13:03:13 -06:00
Rolf Bjarne Kvinge a719e1f480 Merge remote-tracking branch 'origin/master' into generator-ikvm 2017-03-14 17:59:45 +01:00
Alex Soto 0ada7dedce [generator] Fixes bug 42855 generator should report an error for [Protocol] without a [Model] that specify a [BaseType] (#1859)
https://bugzilla.xamarin.com/show_bug.cgi?id=42855

We had some logic to catch this but we did not do anything with it.
We now error out with BI1060 whenever we find [Model] but no [BaseType]
added test case.

I am using BI1060 because Rolf reserved today the missing ones in PR
https://github.com/xamarin/xamarin-macios/pull/1849
2017-03-10 09:52:32 -06:00
Rolf Bjarne Kvinge 1d5f432d4f [tests][generator] Add support for running tests with the IKVM-based generator. 2017-03-09 12:47:57 +01:00
Rolf Bjarne Kvinge 88c276e0aa [tests][generator] Port XI/Classic tests to XI/Unified. (#1745)
* [tests][generator] Port XI/Classic tests to XI/Unified.

* [tests][generator] Comment out code triggering previously unknown bugs.

These tests makes the generator fail:

    error BI0000: Unexpected error - Please file a bug report at http://bugzilla.xamarin.com
    System.NullReferenceException: Object reference not set to an instance of an object
      at Generator.GetSetterExportAttribute (System.Reflection.PropertyInfo pinfo) [0x0002e] in /work/maccore/master/xamarin-macios/src/generator.cs:1981
      at Generator.Go () [0x007e3] in /work/maccore/master/xamarin-macios/src/generator.cs:2162
      at BindingTouch.Main2 (System.String[] args) [0x010b2] in /work/maccore/master/xamarin-macios/src/btouch.cs:435
      at BindingTouch.Main (System.String[] args) [0x0001d] in /work/maccore/master/xamarin-macios/src/btouch.cs:77
      at System.Environment.get_StackTrace () [0x00000] in /work/maccore/master/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System/Environment.cs:321
      at ErrorHelper.ShowInternal (System.Exception e) [0x000dc] in /work/maccore/master/xamarin-macios/src/error.cs:200
      at ErrorHelper.Show (System.Exception e) [0x00027] in /work/maccore/master/xamarin-macios/src/error.cs:151
      at BindingTouch.Main (System.String[] args) [0x0002b] in /work/maccore/master/xamarin-macios/src/btouch.cs:79

This has been filed as https://bugzilla.xamarin.com/show_bug.cgi?id=52664.

* [tests][generator] Comment out code triggering previously unknown bugs.

This has been filed as https://bugzilla.xamarin.com/show_bug.cgi?id=52665.
2017-02-22 16:47:11 +01:00
Rolf Bjarne Kvinge 00874dc1e7 [tests][generator] 'virtualwrap' is a custom test, so put it in the corresponding variable. (#1743)
Fixes this warning:

    Makefile:163: warning: overriding commands for target `virtualwrap'
    Makefile:40: warning: ignoring old commands for target `virtualwrap'
2017-02-22 14:23:45 +01:00
Alex Soto a021c0cd3c [generator] Have WrapAttribute generate virtual members (#1707)
* [generator] Have WrapAttribute generate virtual members

WrapAttribute now has a boolean optional parameter named isVirtual,
this instructs the generator to add the virtual keyword to generated
members.

This is useful when fixing breaking changes so we can keep the wrong
signature generated instead of having manual code files.

* [docs] Add docs about virtual to WrapAttribute
2017-02-16 17:24:40 -06:00
Alex Soto 1799c2f489 [generator] Add BindAs support (#1476)
* [generator] Add BindAs support for NSValue and NSNumber
https://trello.com/c/RYCPEnkh

The intent of BindAs attribute is to have a binding definition as

	[return: BindAs (typeof (bool?))]
	[Export ("boolMethod:")]
	NSNumber BoolMethod (int arg1);

and our generator outputs

	[Export ("boolMethod:")]
	public virtual global::System.Nullable<bool> BoolMethod (int arg1) { ...  }

So we internally do the NSNumber <-> bool conversion, this also
applies to properties, parameters and methods.

* [generator] Fix a small formating issue

* [tests] Add BindAsAttribute generator tests

* [generator] Implement @spouliot's feedback

* [tests] Add BI1048 and BI1049 error tests for [BindAs]

* [generator] Implement Rolf's suggestion to avoid almost all string comparisons in [BindAs] for types

* [generator] Add BindAs support for smart enums and arrays with tests

* [generator] Some code clean up and implementation of PR feedback

* [generator] Add Protocol|Model checks and tests also a NRE check in NSArray creator

BindAs attribute cannot be used in Protocol|Model interfaces

* [generator] Add NSNumber <-> Enum support

* [docs] add BindAs documentation

* [docs] Implement documentation feedback for BindAs
2017-01-25 07:14:55 +01:00
Sebastien Pouliot ee046ee034 [generator] Copy [Obsolete] attributes on smart enums. Fixes #46292 (#1104)
Covers attributes on the type itself and on its members.

Reference:
* https://bugzilla.xamarin.com/show_bug.cgi?id=46292
2016-11-02 23:18:59 -04:00
Sebastien Pouliot e55385637f [generator] Allow identical (numeric) values in smart enums. Fixes #46285 (#1102)
Considering the following binding code:

    public enum HMAccessoryCategoryType {
        [Field ("HMAccessoryCategoryTypeGarageDoorOpener")]
        DoorOpener,

        GarageDoorOpener = DoorOpener,
    }

We must

1. Ensure that `HMAccessoryCategoryType.DoorOpener.GetConstant () ==
	HMAccessoryCategoryType.GarageDoorOpener.GetConstant ()`;

This is done by using the numeric value of the enum member (instead of the name)

2. Ensure that `HMAccessoryCategoryTypeExtensions.GetValue ("HMAccessoryCategoryTypeGarageDoorOpener")`
   always return the same enum value, i.e. it can **not** change between
   XI versions (e.g. due to reflection ordering) as it could break
   comparison code;

This is done by only adding a map to the member that has a [Field] and
means that:

2.1. the _favorite_ enum member should be the one with the [Field]; and

2.2. a [Field] value can only be used once per enum (or else we report
     an BI1046 error). This also solve the duplicate code generation for
	 the constant loading code;

Reference:
* https://bugzilla.xamarin.com/show_bug.cgi?id=46285
2016-11-02 21:46:04 -04:00
Alex Soto ff326bdfdb [generator] ForcedType is now only valid on parameters, properties and return value
https://bugzilla.xamarin.com/show_bug.cgi?id=37175
https://bugzilla.xamarin.com/show_bug.cgi?id=44322

* ForcedType is now only valid on parameters, properties and return value
* Added generator test
* Fixed bindings accordingly
* Fixed docs
2016-09-26 03:57:57 -05:00
Alex Soto e397849108 [generator] Fix bug 43579 - Generator emits invalid code when using the same method name (overload) in @delegates using events and C# delegates (#817)
* [generator] Fix bug 43579 - Generator emits invalid code when using the same method name (overload) in @delegates using events and C# delegates
https://bugzilla.xamarin.com/show_bug.cgi?id=43579

Bug Description:
Generator will emit invalid code when using the same name (overload)
in a method inside a @delegate (protocol) that is decorated
either with EventArgs or DelegateName

-----------------------------------------------------------------

This commit introduces a new attribute named DelegateApiNameAttribute
which mimics the EventNameAttribute but for delegate properties in
host classes

It is used to specify the delegate property name that will be created when
the generator creates the delegate property on the host
class that holds events and delegates.

This is really useful when you have two overload methods that makes
sense to keep them named as is but you want to expose them in the host class
with a better given name.

example:
 interface SomeDelegate {
     [Export ("foo"), DelegateApiName ("Confirmation"), DelegateName ("Func<bool>"), DefaultValue (false)]
     bool Confirm (Some source);
 }

 Generates propety in the host class:
	Func<bool> Confirmation { get; set; }

This also introduces two new BIXXXX errors:
- BI1043 Repeated overload {mi.Name} and no [DelegateApiNameAttribute]
provided to generate property name on host class.
- BI1044 Repeated name '{apiName.Name}' provided in [DelegateApiNameAttribute].

Which provides an error instead of generating invalid C# code.

Generator test included :D

* [docs] Added DelegateApiNameAttribute and IgnoredInDelegateAttribute docs

Also added Protocol where Model was used in our docs so we do not
misslead customers about it
2016-09-14 08:20:08 -04:00
Manuel de la Pena 90c7eab95e [Fix] Ensure that strong dictionaries can work with templated dictionaries as property types. 2016-06-13 12:13:48 +02:00
Rolf Bjarne Kvinge 4a714f3c43 Make logic not depend on the checkout directory being named 'xamarin-macios'. (#129) 2016-06-06 12:18:52 +02:00
Rolf Bjarne Kvinge ecfdea9508 [tests] Import 2016-05-26 15:06:52 +02:00