Reset branch to trunk.
[official-gcc.git] / trunk / gcc / testsuite / objc.dg / call-super-1.m
blob19e0d4900dde66cda06388059106dce0654a0705
1 /* Check if objc_super stack variables are created correctly (and
2    not clobbered by other values).  */
3 /* Contributed by Ziemowit Laski <zlaski@apple.com>.  */
4 /* { dg-options "-std=c99 -lobjc" } */
5 /* { dg-do run } */
7 #include <objc/objc.h>
8 #include <objc/Object.h>
10 extern void abort(void);
12 #define CHECK_IF(expr) if(!(expr)) abort();
14 typedef struct _Point { 
15   float x; 
16   float y; 
17 } Point; 
19 Point MakePoint ( float x , float y ) { 
20   Point p; 
21   p.x = x; 
22   p.y = y; 
23   return p; 
24
26 @interface Base: Object 
27 - ( void ) translateOriginToPoint : ( Point ) translation ; 
28 @end
30 @interface Derived : Base 
31 - ( void ) scrollToPoint : ( Point ) newOrigin ; 
32 - ( void ) translateOriginToPoint : ( Point ) translation ;
33 @end 
35 int blort;
36 float result;
38 @implementation Base
39 - ( void ) translateOriginToPoint : ( Point ) translation  {
40   result = translation.x + translation.y;
42 @end
44 @implementation Derived
45 - ( void ) scrollToPoint : ( Point ) newOrigin { 
46   float transDeltaX =newOrigin.x, transDeltaY =newOrigin.y ; 
47   Point w;
48   if ( ! blort ) {
49     w.x = transDeltaX ; w.y = transDeltaY ;
50     [ super translateOriginToPoint : w ] ; 
51     return;
52   } 
53   [ super translateOriginToPoint : MakePoint ( transDeltaX , transDeltaY ) ] ; 
54   return; 
55
56 - (void) translateOriginToPoint : ( Point ) translation  {
57   /* This should never be called.  */
58   CHECK_IF(0);
60 @end 
62 int main(void) {
63   Derived *v = [Derived new];
64   float r0 = 1.5 + 1.5;
65   blort = 1;
66   [v scrollToPoint: MakePoint(1.5, 1.5)];
67   CHECK_IF(result == r0);
68   blort = 0;
69   [v scrollToPoint: MakePoint(1.5, 1.5)];
70   CHECK_IF(result == r0);
71   blort = 1;
72   [v scrollToPoint: MakePoint(1.5, 1.5)];
73   CHECK_IF(result == r0);
74   [v free];
75   return 0;