OSDN Git Service

Backported from mainline
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / obj-c++.dg / encode-4.mm
index 25c0b50..4f34644 100644 (file)
 
 /* Contributed by Ziemowit Laski <zlaski@apple.com>.  */
 /* { dg-do run } */
+/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
+#include "../objc-obj-c++-shared/TestsuiteObject.m"
+#include "../objc-obj-c++-shared/runtime.h"
 
+#include <stdio.h>
+#include <stdlib.h>
 
-#include <objc/objc.h>
-#include <objc/Object.h>
-
-#ifdef __NEXT_RUNTIME__
-#define METHOD Method
-#define OBJC_GETCLASS objc_getClass
-#define CLASS_GETINSTANCEMETHOD class_getInstanceMethod
-#else
-#include <objc/objc-api.h>
-#define METHOD Method_t
-#define OBJC_GETCLASS objc_get_class
-#define CLASS_GETINSTANCEMETHOD class_get_instance_method
-#endif
-
-extern "C" {
-  extern int sscanf(const char *str, const char *format, ...);
-  extern void abort(void);
-}
 #define CHECK_IF(expr) if(!(expr)) abort()
 
-@interface Foo: Object
+@interface Foo: TestsuiteObject
 typedef struct { float x, y; } XXPoint;
 typedef struct { float width, height; } XXSize;
 typedef struct _XXRect { XXPoint origin; XXSize size; } XXRect;
@@ -79,27 +66,28 @@ unsigned offs1, offs2, offs3, offs4, offs5, offs6, offs7;
 
 int main(void) {
   Foo *foo = [[Foo alloc] init];
-  Class fooClass = OBJC_GETCLASS("Foo");
-  METHOD meth;
+  Class fooClass = objc_getClass("Foo");
+  Method meth;
   const char *string;
 
-  meth = CLASS_GETINSTANCEMETHOD(fooClass, @selector(setRect:withInt:));
+  meth = class_getInstanceMethod(fooClass, @selector(setRect:withInt:));
   offs2 = 9999;
-  sscanf(meth->method_types, "@%u@%u:%u{_XXRect={?=ff}{?=ff}}%ui%u", &offs1, &offs2, &offs3,
+  sscanf(method_getTypeEncoding(meth), "@%u@%u:%u{_XXRect={?=ff}{?=ff}}%ui%u", &offs1, &offs2, &offs3,
       &offs4, &offs5);
   CHECK_IF(!offs2);
   [foo setRect:my_rect withInt:123];
 
-  meth = CLASS_GETINSTANCEMETHOD(fooClass, @selector(char:float:double:long:));
+  meth = class_getInstanceMethod(fooClass, @selector(char:float:double:long:));
   offs2 = 9999;
   if (sizeof (long) == 8)
     string = "v%u@%u:%uc%uf%ud%uq%u";
   else
     string = "v%u@%u:%uc%uf%ud%ul%u";
-  sscanf(meth->method_types, string, &offs1, &offs2, &offs3,  
+  sscanf(method_getTypeEncoding(meth), string, &offs1, &offs2, &offs3,  
         &offs4, &offs5, &offs6, &offs7);
   CHECK_IF(!offs2);
   [foo char:'c' float:2.3 double:3.5 long:2345L];
 
   return 0;
 }  
+