OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [gcc/] [testsuite/] [objc.dg/] [lookup-1.m] - Blame information for rev 20

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 12 jlechner
/* { dg-do run { target *-*-darwin* } } */
2
 
3
#include <objc/Object.h>
4
#include <stdlib.h>
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: Object
17
@end
18
 
19
@interface Bar: Foo <MyProto>
20
@end
21
 
22
@interface Container: Object
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 = nil;
39
  if ([view conformsTo:@protocol(MyProto)]) {
40
    widget = [(Foo <MyProto> *)view widget];
41
  }
42
  return widget;
43
}
44
@end
45
 
46
int main(void) {
47
  id view = [Bar new];
48
  MyWidget *w = [Container elementForView: view];
49
 
50
  if (!w || w->a != 17)
51
    abort ();
52
 
53
  return 0;
54
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.