Permalink
Browse files

Add more information to bindings for the static registrar.

The static registrar needs more information in order to correctly
generate the static glue code - in particular it needs to know if
a type is a wrapper type, if a type is a protocol and if a method
is a variadic method.
  • Loading branch information...
1 parent 0f82002 commit 71afc294df5bb253f35cfab9ec7e41e78132702b @rolfbjarne rolfbjarne committed Mar 8, 2013
@@ -61,6 +61,11 @@ public class ExportAttribute : Attribute {
set { this.semantic = value; }
}
+ public bool IsVariadic {
+ get;
+ set;
+ }
+
//#if MONOMAC
public ExportAttribute ToGetter (PropertyInfo prop) {
if (string.IsNullOrEmpty (Selector))
@@ -29,4 +29,10 @@ public sealed class ModelAttribute : Attribute {
public ModelAttribute () {}
}
+
+ [AttributeUsage (AttributeTargets.Class | AttributeTargets.Interface)]
+ public sealed class ProtocolAttribute : Attribute {
+
+ public ProtocolAttribute () {}
+ }
}
View
@@ -369,6 +369,7 @@ interface AVAudioPlayer {
[BaseType (typeof (NSObject))]
[Model]
+ [Protocol]
interface AVAudioPlayerDelegate {
[Export ("audioPlayerDidFinishPlaying:successfully:"), CheckDisposed]
void FinishedPlaying (AVAudioPlayer player, bool flag);
@@ -472,6 +473,7 @@ interface AVAudioRecorder {
[BaseType (typeof (NSObject))]
[Model]
+ [Protocol]
interface AVAudioRecorderDelegate {
[Export ("audioRecorderDidFinishRecording:successfully:"), CheckDisposed]
void FinishedRecording (AVAudioRecorder recorder, bool flag);
@@ -797,6 +799,7 @@ interface AVAudioSessionRouteChangeEventArgs {
[BaseType (typeof (NSObject))]
[Model]
+ [Protocol]
interface AVAudioSessionDelegate {
[Export ("beginInterruption")]
void BeginInterruption ();
@@ -1190,6 +1193,7 @@ interface AVAssetResourceLoader {
[Since (6,0)]
[BaseType (typeof (NSObject))]
[Model]
+ [Protocol]
interface AVAssetResourceLoaderDelegate {
[Abstract]
[Export ("resourceLoader:shouldWaitForLoadingOfRequestedResource:")]
@@ -2845,7 +2849,7 @@ interface AVVideoComposition {
[Since (5,0)]
[BaseType (typeof (NSObject))]
[Model]
- // Protocol
+ [Protocol]
[DisableDefaultCtor]
interface AVVideoCompositionValidationHandling {
[Export ("videoComposition:shouldContinueValidatingAfterFindingInvalidValueForKey:")]
@@ -3323,6 +3327,7 @@ interface AVCaptureVideoDataOutput {
[BaseType (typeof (NSObject))]
[Since (4,0)]
[Model]
+ [Protocol]
interface AVCaptureVideoDataOutputSampleBufferDelegate {
[Export ("captureOutput:didOutputSampleBuffer:fromConnection:")]
// CMSampleBufferRef
@@ -3345,6 +3350,7 @@ interface AVCaptureAudioDataOutput {
[Since (4,0)]
[BaseType (typeof (NSObject))]
[Model]
+ [Protocol]
interface AVCaptureAudioDataOutputSampleBufferDelegate {
[Export ("captureOutput:didOutputSampleBuffer:fromConnection:")]
void DidOutputSampleBuffer (AVCaptureOutput captureOutput, CMSampleBuffer sampleBuffer, AVCaptureConnection connection);
@@ -3389,6 +3395,7 @@ interface AVCaptureFileOutput {
[BaseType (typeof (NSObject))]
[Model]
[Since (4,0)]
+ [Protocol]
interface AVCaptureFileOutputRecordingDelegate {
[Export ("captureOutput:didStartRecordingToOutputFileAtURL:fromConnections:")]
void DidStartRecording (AVCaptureFileOutput captureOutput, NSUrl outputFileUrl, NSObject [] connections);
@@ -3420,6 +3427,7 @@ interface AVCaptureMetadataOutput {
[Since (6,0)]
[BaseType (typeof (NSObject))]
[Model]
+ [Protocol]
interface AVCaptureMetadataOutputObjectsDelegate {
[Export ("captureOutput:didOutputMetadataObjects:fromConnection:")]
void DidOutputMetadataObjects (AVCaptureMetadataOutput captureOutput, AVMetadataObject [] metadataObjects, AVCaptureConnection connection);
@@ -4089,6 +4097,7 @@ interface AVPlayerItemVideoOutput {
[Since (6,0)]
[BaseType (typeof (NSObject))]
[Model]
+ [Protocol]
interface AVPlayerItemOutputPullDelegate {
[Export ("outputMediaDataWillChange:")]
void OutputMediaDataWillChange (AVPlayerItemOutput sender);
@@ -4242,6 +4251,7 @@ interface AVPlayerItemTrack {
[BaseType (typeof (NSObject))]
[Model]
[Since (4,0)]
+ [Protocol]
interface AVAsynchronousKeyValueLoading {
[Abstract]
[Export ("statusOfValueForKey:error:")]
View
@@ -730,6 +730,7 @@ public interface CATextLayer {
[BaseType (typeof (NSObject))]
[Model]
+ [Protocol]
public interface CALayerDelegate {
[Export ("displayLayer:")]
void DisplayLayer (CALayer layer);
@@ -758,7 +759,7 @@ public interface CAEAGLLayer {
[BaseType (typeof (NSObject))]
[Model]
- // protocol
+ [Protocol]
[DisableDefaultCtor]
public interface CAAction {
[Export ("runActionForKey:object:arguments:")]
@@ -873,6 +874,7 @@ public interface CAAnimation {
[BaseType (typeof (NSObject))]
[Model]
+ [Synthetic]
public interface CAAnimationDelegate {
[Export ("animationDidStart:")]
void AnimationStarted (CAAnimation anim);
View
@@ -347,6 +347,7 @@ interface NSFetchedResultsController {
[BaseType (typeof (NSObject))]
[Model]
+ [Protocol]
interface NSFetchedResultsControllerDelegate {
[Export ("controllerWillChangeContent:")]
void WillChangeContent (NSFetchedResultsController controller);
@@ -366,6 +367,7 @@ interface NSFetchedResultsControllerDelegate {
[BaseType (typeof (NSObject))]
[Model]
+ [Protocol]
interface NSFetchedResultsSectionInfo {
[Export ("numberOfObjects")]
int Count { get; }
View
@@ -238,6 +238,7 @@ partial interface CLLocationManager {
[BaseType (typeof (NSObject))]
[Model]
+ [Synthetic]
partial interface CLLocationManagerDelegate
{
[Obsolete ("Deprecated in iOS 6.0")]
View
@@ -288,6 +288,7 @@ public interface NSCache {
[BaseType (typeof (NSObject))]
[Model]
+ [Protocol]
public interface NSCacheDelegate {
[Export ("cache:willEvictObject:"), EventArgs ("NSObject")]
void WillEvictObject (NSCache cache, NSObject obj);
@@ -1041,6 +1042,7 @@ public interface NSFormatter {
[BaseType (typeof (NSObject))]
[Model]
+ [Protocol]
public interface NSKeyedArchiverDelegate {
[Export ("archiver:didEncodeObject:"), EventArgs ("NSObject")]
void EncodedObject (NSKeyedArchiver archiver, NSObject obj);
@@ -1060,6 +1062,7 @@ public interface NSKeyedArchiverDelegate {
[BaseType (typeof (NSObject))]
[Model]
+ [Protocol]
public interface NSKeyedUnarchiverDelegate {
[Export ("unarchiver:didDecodeObject:"), DelegateName ("NSDecoderCallback"), DefaultValue (null)]
NSObject DecodedObject (NSKeyedUnarchiver unarchiver, NSObject obj);
@@ -1303,6 +1306,7 @@ public interface NSMetadataQuery {
[BaseType (typeof (NSObject))]
[Model]
+ [Protocol]
public interface NSMetadataQueryDelegate {
[Export ("metadataQuery:replacementObjectForResultObject:"), DelegateName ("NSMetadataQueryObject"), DefaultValue(null)]
NSObject ReplacementObjectForResultObject (NSMetadataQuery query, NSMetadataItem result);
@@ -3068,6 +3072,7 @@ public interface NSUrlConnection {
[BaseType (typeof (NSObject), Name="NSURLConnectionDelegate")]
[Model]
+ [Protocol]
public interface NSUrlConnectionDelegate {
[Export ("connection:willSendRequest:redirectResponse:")]
NSUrlRequest WillSendRequest (NSUrlConnection connection, NSUrlRequest request, NSUrlResponse response);
@@ -3108,6 +3113,7 @@ public interface NSUrlConnectionDelegate {
[BaseType (typeof (NSUrlConnectionDelegate), Name="NSUrlConnectionDownloadDelegate")]
[Model]
+ [Protocol]
public interface NSUrlConnectionDownloadDelegate {
[Export ("connection:didWriteData:totalBytesWritten:expectedTotalBytes:")]
void WroteData (NSUrlConnection connection, long bytesWritten, long totalBytesWritten, long expectedTotalBytes);
@@ -3710,6 +3716,7 @@ public interface NSStream {
[BaseType (typeof (NSObject))]
[Model]
+ [Protocol]
public interface NSStreamDelegate {
[Export ("stream:handleEvent:"), EventArgs ("NSStream"), EventName ("OnEvent")]
void HandleEvent (NSStream theStream, NSStreamEvent streamEvent);
@@ -4725,6 +4732,7 @@ public interface NSNetService {
}
[Model, BaseType (typeof (NSObject))]
+ [Protocol]
public interface NSNetServiceDelegate {
[Export ("netServiceWillPublish:")]
void WillPublish (NSNetService sender);
@@ -4782,6 +4790,7 @@ public interface NSNetServiceBrowser {
}
[Model, BaseType (typeof (NSObject))]
+ [Protocol]
public interface NSNetServiceBrowserDelegate {
[Export ("netServiceBrowserWillSearch:")]
void SearchStarted (NSNetServiceBrowser sender);
@@ -5983,6 +5992,7 @@ public partial interface NSFileManager {
[BaseType(typeof(NSObject))]
[Model]
+ [Protocol]
public interface NSFileManagerDelegate {
[Export("fileManager:shouldCopyItemAtPath:toPath:")]
bool ShouldCopyItemAtPath(NSFileManager fm, NSString srcPath, NSString dstPath);
@@ -6047,6 +6057,7 @@ public interface NSFileManagerDelegate {
[BaseType (typeof (NSObject))]
[Model]
+ [Protocol]
partial interface NSFilePresenter {
[Abstract]
[Export ("presentedItemURL")]
View
@@ -8,7 +8,7 @@
// Marek Safar (marek.safar@gmail.com)
//
// Copyright 2009-2010, Novell, Inc.
-// Copyright 2011-2012 Xamarin, Inc.
+// Copyright 2011-2013 Xamarin, Inc.
//
//
// This generator produces various */*.g.cs files based on the
@@ -196,6 +196,11 @@ public static Type GetBaseType (Type type)
}
}
+// Used to mark if a type is not a wrapper type.
+public class SyntheticAttribute : Attribute {
+ public SyntheticAttribute () { }
+}
+
public class NeedsAuditAttribute : Attribute {
public NeedsAuditAttribute (string reason)
{
@@ -2809,6 +2814,7 @@ void GenerateProperty (Type type, PropertyInfo pi, List<string> instance_fields_
bool is_override = HasAttribute (pi, typeof (OverrideAttribute)) || !MemberBelongsToType (pi.DeclaringType, type);
bool is_new = HasAttribute (pi, typeof (NewAttribute));
bool is_sealed = HasAttribute (pi, typeof (SealedAttribute));
+ bool is_wrapper = !HasAttribute (pi.DeclaringType, typeof(SyntheticAttribute));
bool is_unsafe = false;
if (pi.PropertyType.IsSubclassOf (typeof (Delegate)))
@@ -2920,10 +2926,12 @@ void GenerateProperty (Type type, PropertyInfo pi, List<string> instance_fields_
PrintPlatformAttributes (pi);
- if (export.ArgumentSemantic != ArgumentSemantic.None)
- print ("[Export (\"{0}\", ArgumentSemantic.{1})]", sel, export.ArgumentSemantic);
- else
- print ("[Export (\"{0}\")]", sel);
+ if (!is_sealed || !is_wrapper) {
+ if (export.ArgumentSemantic != ArgumentSemantic.None)
+ print ("[Export (\"{0}\", ArgumentSemantic.{1})]", sel, export.ArgumentSemantic);
+ else
+ print ("[Export (\"{0}\")]", sel);
+ }
if (is_abstract){
print ("get; ");
} else {
@@ -2963,7 +2971,7 @@ void GenerateProperty (Type type, PropertyInfo pi, List<string> instance_fields_
PrintPlatformAttributes (pi);
- if (!not_implemented){
+ if (!not_implemented && (!is_sealed || !is_wrapper)){
if (export.ArgumentSemantic != ArgumentSemantic.None)
print ("[Export (\"{0}\", ArgumentSemantic.{1})]", sel, export.ArgumentSemantic);
else
@@ -3011,6 +3019,8 @@ void GenerateMethod (Type type, MethodInfo mi, bool is_model, Type category_exte
print ("#pragma warning restore 168");
}
+ bool is_sealed = HasAttribute (mi, typeof (SealedAttribute));
+ bool is_wrapper = !HasAttribute (type, typeof(SyntheticAttribute));
string selector = null;
bool virtual_method = false;
string wrap_method = null;
@@ -3032,8 +3042,11 @@ void GenerateMethod (Type type, MethodInfo mi, bool is_model, Type category_exte
ExportAttribute ea = (ExportAttribute) attr [0];
selector = ea.Selector;
- print ("[Export (\"{0}\")]", ea.Selector);
- virtual_method = mi.Name != "Constructor";
+ if (!is_sealed || !is_wrapper) {
+ var is_variadic = ea.IsVariadic ? ", IsVariadic = true" : string.Empty;
+ print ("[Export (\"{0}\"{1})]", ea.Selector, is_variadic);
+ virtual_method = mi.Name != "Constructor";
+ }
}
foreach (ObsoleteAttribute oa in mi.GetCustomAttributes (typeof (ObsoleteAttribute), false)) {
@@ -3064,7 +3077,6 @@ void GenerateMethod (Type type, MethodInfo mi, bool is_model, Type category_exte
bool is_internal = HasAttribute (mi, typeof (InternalAttribute));
bool is_override = HasAttribute (mi, typeof (OverrideAttribute)) || !MemberBelongsToType (mi.DeclaringType, type);
bool is_new = HasAttribute (mi, typeof (NewAttribute));
- bool is_sealed = HasAttribute (mi, typeof (SealedAttribute));
bool is_unsafe = false;
bool is_autorelease = HasAttribute (mi, typeof (AutoreleaseAttribute));
@@ -3184,6 +3196,7 @@ public void Generate (Type type)
bool is_category_class = category_attribute.Length > 0;
bool is_static_class = type.GetCustomAttributes (typeof (StaticAttribute), true).Length > 0 || is_category_class;
bool is_model = type.GetCustomAttributes (typeof (ModelAttribute), true).Length > 0;
+ bool is_protocol = HasAttribute (type, typeof (ProtocolAttribute));
var default_ctor_visibility = GetAttribute<DefaultCtorVisibilityAttribute> (type);
object [] btype = type.GetCustomAttributes (typeof (BaseTypeAttribute), true);
BaseTypeAttribute bta = btype.Length > 0 ? ((BaseTypeAttribute) btype [0]) : null;
@@ -3199,7 +3212,9 @@ public void Generate (Type type)
base_type = typeof (object);
class_mod = "static ";
} else {
- print ("[Register(\"{0}\", true)]", objc_type_name);
+ if (is_protocol)
+ print ("[Protocol]");
+ print ("[Register(\"{0}\", {1})]", objc_type_name, HasAttribute (type, typeof (SyntheticAttribute)) ? "false" : "true");
if (need_abstract.ContainsKey (type))
class_mod = "abstract ";
}
View
@@ -76,6 +76,7 @@ interface QLPreviewController {
[Since (4,0)]
[BaseType (typeof (NSObject))]
[Model]
+ [Protocol]
interface QLPreviewControllerDataSource {
[Abstract]
[Export ("numberOfPreviewItemsInPreviewController:")]
@@ -89,6 +90,7 @@ interface QLPreviewControllerDataSource {
[Since (4,0)]
[BaseType (typeof (NSObject))]
[Model]
+ [Protocol]
interface QLPreviewControllerDelegate {
[Export ("previewControllerWillDismiss:")]
void WillDismiss (QLPreviewController controller);
@@ -115,6 +117,7 @@ interface QLPreviewControllerDelegate {
[Since (4,0)]
[BaseType (typeof (NSObject))]
[Model]
+ [Protocol]
interface QLPreviewItem {
[Abstract]
[Export ("previewItemURL")]

0 comments on commit 71afc29

Please sign in to comment.