Home | History | Annotate | Download | only in Rewriter
      1 // RUN: %clang_cc1 -x objective-c -Wno-objc-root-class -fms-extensions -rewrite-objc %s -o %t-rw.cpp
      2 // RUN: FileCheck  --input-file=%t-rw.cpp %s
      3 // rdar://9846759
      4 // rdar://15517895
      5 
      6 typedef struct MyWidget {
      7   int a;
      8 } MyWidget;
      9 
     10 MyWidget gWidget = { 17 };
     11 
     12 @protocol MyProto
     13 - (MyWidget *)widget;
     14 @end
     15 
     16 @interface Foo 
     17 @end
     18 
     19 @interface Bar: Foo <MyProto>
     20 @end
     21 
     22 @interface Container 
     23 + (MyWidget *)elementForView:(Foo *)view;
     24 @end
     25 
     26 @implementation Foo
     27 @end
     28 
     29 @implementation Bar
     30 - (MyWidget *)widget {
     31   return &gWidget;
     32 }
     33 @end
     34 
     35 @implementation Container
     36 + (MyWidget *)elementForView:(Foo *)view
     37 {
     38   MyWidget *widget = (void*)0;
     39   if (@protocol(MyProto)) {
     40     widget = [(id <MyProto>)view widget];
     41   }
     42   return widget;
     43 }
     44 @end
     45 
     46 int main(void) {
     47   id view;
     48   MyWidget *w = [Container elementForView: view];
     49 
     50   return 0;
     51 }
     52 
     53 // rdar://15517895
     54 @class NSObject;
     55 
     56 @interface NSProtocolChecker
     57 + (id)protocolCheckerWithTarget:(NSObject *)anObject protocol:(Protocol *)aProtocol;
     58 @end
     59 
     60 @protocol NSConnectionVersionedProtocol
     61 @end
     62 
     63 
     64 @interface NSConnection @end
     65 
     66 @implementation NSConnection
     67 - (void) Meth {
     68   [NSProtocolChecker protocolCheckerWithTarget:0 protocol:@protocol(NSConnectionVersionedProtocol)];
     69 }
     70 @end
     71 
     72 // CHECK: static struct _protocol_t *_OBJC_PROTOCOL_REFERENCE_$_NSConnectionVersionedProtocol = &_OBJC_PROTOCOL_NSConnectionVersionedProtocol
     73 // CHECK: sel_registerName("protocolCheckerWithTarget:protocol:"), (NSObject *)0, (Protocol *)_OBJC_PROTOCOL_REFERENCE_$_NSConnectionVersionedProtocol
     74