OSDN Git Service

Backported from mainline
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / objc.dg / encode-7-next-64bit.m
1 /* Additional testing for the NeXT runtime. Encoding in -m64 mode  */
2
3 /* { dg-do run { target *-*-darwin* } } */
4 /* { dg-require-effective-target lp64 } */
5 /* { dg-skip-if "" { *-*-* } { "-fgnu-runtime" } { "" } } */
6 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
7 /* { dg-additional-options "-framework Foundation" } */
8
9 #include <stdbool.h>
10 #include <string.h>
11 #include <stdlib.h>
12 #include <Foundation/NSObject.h>
13 #include "../objc-obj-c++-shared/runtime.h"
14
15 extern int printf(char *,...);
16 void CHECK_IF(const char *s1, const char *s2)
17 {
18  if (strcmp(s1,s2) != 0) {
19  printf ("'%s'\n'%s'\n",s1,s2);
20  abort ();
21  }
22 }
23
24 @class NSDictionary, NSFont, NSError, _NSATSTypesetterGuts, NSString, NSMenu, NSArray;
25
26 struct FSRef {
27   UInt8 hidden[80];
28 };
29 typedef struct FSRef FSRef;
30
31 typedef struct _NSPoint {
32     float x;
33     float y;
34 } NSPoint;
35
36 typedef struct _NSSize {
37     float width;
38     float height;
39 } NSSize;
40
41 typedef struct _NSRect {
42     NSPoint origin;
43     NSSize size;
44 } NSRect;
45
46 typedef struct _NSRange {
47     unsigned int location;
48     unsigned int length;
49 } NSRange;
50
51 typedef const char *NXAtom;
52
53 typedef struct {
54   NSDictionary *_attributes;
55   NSFont *_font;
56   CFIndex _characterLength;
57   CFIndex _nominalGlyphLocation;
58   const CFIndex *p;
59   float _defaultLineHeight;
60   float _defaultBaselineOffset;
61   float _horizExpansion;
62   float _baselineDelta;
63   NSRect _attachmentBBox;
64   long ll, *llp;
65   unsigned long ull, *ullp;
66   id a;
67   const id a1;
68   const struct objc_object *a2;
69   SEL b;
70   const SEL b1;
71   const struct objc_selector *b2;
72   const char *str1;
73   char *str2;
74   char *const str3;
75   const char *const str4;
76   struct {
77     unsigned int _isAttachmentRun:1;
78     unsigned int _hasPositionalStake:1;
79     unsigned int _isDefaultFace:1;
80     unsigned int _hasCombiningMarks:1;
81     unsigned int _isScreenFont:1;
82     unsigned int _reserved:27;
83   } _rFlags;
84 } NSATSGlyphStorageRun;
85
86 typedef struct __CFSet *CFMutableSetRef;
87 typedef const struct __CTLine * CTLineRef;
88 typedef const struct __NSAppleEventManagerSuspension* NSAppleEventManagerSuspensionID;
89
90 struct ComponentInstanceRecord {
91   long data[1];
92 };
93 typedef struct ComponentInstanceRecord  ComponentInstanceRecord;
94 typedef ComponentInstanceRecord *ComponentInstance;
95
96 typedef NSString *(*NSErrorUserInfoFormatterFunc)(id objToBeDisplayed, NSError *err, char modifier);
97 typedef struct {
98   NSErrorUserInfoFormatterFunc formatterFunc;
99   NSString *userInfoKey;
100   unsigned int parameterMask;
101 } NSErrorUserInfoFormatter;
102
103 typedef NSObject MyObj;
104 typedef NSObject *MyPtr;
105
106 @interface Foo: NSObject {
107   NSATSGlyphStorageRun r;
108 }
109 - (NSError *)_errorWithOSStatus:(OSStatus)inOSStatus ref1:(const FSRef *)inRef1 ref2:(const struct FSRef *)inRef2
110   reading:(BOOL)inReadingNotWriting;
111 - (const NSATSGlyphStorageRun *)_attributeRunForCharacterAtIndex:(const CFIndex)charIndex;
112 - (const _NSATSTypesetterGuts *)_getATSTypesetterGuts:(const struct objc_selector *)sel;
113 - (void)resumeWithSuspensionID:(NSAppleEventManagerSuspensionID)suspensionID and:(const CFIndex *)status;
114 - (const id)anotherMeth:(const SEL)sel and:(const Foo *)foo and:(const struct objc_object *)obj;
115 - (id)str1:(const char *)str1 str2:(char *)str2 str3:(char *const)str3 str4:(const char *const)str4;
116 - (oneway void)foo1:(Foo *)foo1 foo2:(const Foo *)foo2 foo3:(Foo *const)foo3 foo4:(const Foo *const)foo4;
117 - (in const char *)sel1:(const SEL)sel1 id1:(const id)id1;
118 - (inout id)obj1:(const MyPtr)obj1 obj2:(NSObject *const)obj2 obj3:(MyObj *const)obj3;
119 + (ComponentInstance)_defaultScriptingComponent;
120 - (NSString *)_formatCocoaErrorString:(NSString *)formatString parameters:(const char *)parameters 
121   applicableFormatters:(NSErrorUserInfoFormatter **)formatters count:(int)numFormatters;
122 - (NSErrorUserInfoFormatter *)formatter_func:(id)obj run:(const NSATSGlyphStorageRun **)run;
123 - (BOOL)_forgetWord:(bycopy in NSString *)word inDictionary:(bycopy in NSString *)language;
124 - (void)_registerServicesMenu:(NSMenu *)servicesMenu withSendTypes:(const NXAtom *)sendTypes 
125   andReturnTypes:(const NXAtom *)returnTypes addToList:(BOOL)addToList;
126 + (CFMutableSetRef *)_proxySharePointer;
127 - (NSRange)_checkGrammarInString:(in NSString *)stringToCheck language:(bycopy in NSString *)language details:(bycopy out NSArray **)details;
128 - (bool)_resolvePositionalStakeGlyphsForLineFragment:(CTLineRef)line lineFragmentRect:(NSRect)lineFragmentRect
129   minPosition:(float)minPosition maxPosition:(float)maxPosition maxLineFragmentWidth:(float)maxLineFragmentWidth
130   breakHint:(CFIndex *)charIndex;
131 + (BOOL)findVoiceByIdentifier:(NSString *)identifier returningCreator:(OSType *)returnedCreator returningID:(OSType *)returnedID;
132 @end
133
134 NSRange globalRange;
135
136 @implementation Foo
137 - (NSError *)_errorWithOSStatus:(OSStatus)inOSStatus ref1:(const FSRef *)inRef1 ref2:(const struct FSRef *)inRef2
138   reading:(BOOL)inReadingNotWriting {
139   return (NSError *)self;
140 }
141 - (const NSATSGlyphStorageRun *)_attributeRunForCharacterAtIndex:(CFIndex)charIndex {
142   return (const NSATSGlyphStorageRun *)self;
143 }
144 - (const _NSATSTypesetterGuts *)_getATSTypesetterGuts:(const struct objc_selector *)sel {
145   return (const _NSATSTypesetterGuts *)self;
146 }
147 - (void)resumeWithSuspensionID:(NSAppleEventManagerSuspensionID)suspensionID and:(const CFIndex *)status {
148 }
149 - (const id)anotherMeth:(const SEL)sel and:(const Foo *)foo and:(const struct objc_object *)obj {
150   return (const id)self;
151 }
152 - (id)str1:(const char *)str1 str2:(char *)str2 str3:(char *const)str3 str4:(const char *const)str4 {
153   return self;
154 }
155 - (oneway void)foo1:(Foo *)foo1 foo2:(const Foo *)foo2 foo3:(Foo *const)foo3 foo4:(const Foo *const)foo4 {
156 }
157 - (in const char *)sel1:(const SEL)sel1 id1:(const id)id1 {
158   return "Hello";
159 }  
160 - (inout id)obj1:(const MyPtr)obj1 obj2:(NSObject *const)obj2 obj3:(MyObj *const)obj3 {
161   return self;
162 }
163 + (ComponentInstance)_defaultScriptingComponent {
164   return (ComponentInstance)0;
165 }
166 - (NSString *)_formatCocoaErrorString:(NSString *)formatString parameters:(const char *)parameters 
167   applicableFormatters:(NSErrorUserInfoFormatter **)formatters count:(int)numFormatters {
168   return (NSString *)self;
169 }
170 - (NSErrorUserInfoFormatter *)formatter_func:(id)obj run:(const NSATSGlyphStorageRun **)run {
171   return (NSErrorUserInfoFormatter *)0;
172 }
173 - (BOOL)_forgetWord:(bycopy in NSString *)word inDictionary:(bycopy in NSString *)language {
174   return YES;
175 }
176 - (void)_registerServicesMenu:(NSMenu *)servicesMenu withSendTypes:(const NXAtom *)sendTypes 
177   andReturnTypes:(const NXAtom *)returnTypes addToList:(BOOL)addToList {
178 }
179 + (CFMutableSetRef *)_proxySharePointer {
180   return (CFMutableSetRef *)0;
181 }
182 - (NSRange)_checkGrammarInString:(in NSString *)stringToCheck language:(bycopy in NSString *)language details:(bycopy out NSArray **)details {
183   return globalRange;
184 }
185 - (bool)_resolvePositionalStakeGlyphsForLineFragment:(CTLineRef)line lineFragmentRect:(NSRect)lineFragmentRect 
186   minPosition:(float)minPosition maxPosition:(float)maxPosition maxLineFragmentWidth:(float)maxLineFragmentWidth 
187   breakHint:(CFIndex *)charIndex {
188   return false;
189 }
190 + (BOOL)findVoiceByIdentifier:(NSString *)identifier returningCreator:(OSType *)returnedCreator returningID:(OSType *)returnedID {
191   return NO;
192 }
193 @end
194
195 /* FIXME: we produce different output c.f. the system compiler on OSX10.6+ */
196
197 int main(void) {
198   Class fooClass = objc_getClass ("Foo");
199   Method meth;
200   Ivar *ivars;
201   unsigned int ivar_count;
202   Ivar ivar;
203
204   meth = class_getInstanceMethod (fooClass, @selector(_errorWithOSStatus:ref1:ref2:reading:));
205   CHECK_IF (method_getTypeEncoding(meth), "@40@0:8i16r^{FSRef=[80C]}20r^{FSRef=[80C]}28c36");
206
207   meth = class_getInstanceMethod (fooClass, @selector(_attributeRunForCharacterAtIndex:));
208   CHECK_IF (method_getTypeEncoding (meth), "r^{?=@@qq^qffff{_NSRect={_NSPoint=ff}{_NSSize=ff}}q^qQ^Q@@@:::****{?=b1b1b1b1b1b27}}24@0:8q16");
209 /* clang produces: r^{?=@@qq^qffff{_NSRect={_NSPoint=ff}{_NSSize=ff}}q^qQ^Q@@@::^{objc_selector}****{?=b1b1b1b1b1b27}}24@0:8q16 */
210
211   meth = class_getInstanceMethod (fooClass, @selector(_getATSTypesetterGuts:));
212   CHECK_IF (method_getTypeEncoding (meth), "r@24@0:8r:16");
213 /* "@24@0:8r^{objc_selector=}16" */
214
215   meth = class_getInstanceMethod (fooClass, @selector(resumeWithSuspensionID:and:));
216   CHECK_IF (method_getTypeEncoding (meth), "v32@0:8^{__NSAppleEventManagerSuspension=}16r^q24");
217
218   meth = class_getInstanceMethod (fooClass, @selector(anotherMeth:and:and:));
219   CHECK_IF (method_getTypeEncoding (meth), "r@40@0:8r:16r@24r@32");
220
221   meth = class_getInstanceMethod (fooClass, @selector(str1:str2:str3:str4:));
222   CHECK_IF (method_getTypeEncoding (meth), "@48@0:8r*16*24*32r*40");
223
224   meth = class_getInstanceMethod (fooClass, @selector(foo1:foo2:foo3:foo4:));
225   CHECK_IF (method_getTypeEncoding (meth), "Vv48@0:8@16r@24@32r@40");
226
227   meth = class_getInstanceMethod (fooClass, @selector(sel1:id1:));
228   CHECK_IF (method_getTypeEncoding (meth), "rn*32@0:8r:16r@24");
229
230   meth = class_getInstanceMethod (fooClass, @selector(obj1:obj2:obj3:));
231   CHECK_IF (method_getTypeEncoding (meth), "N@40@0:8r@16@24^{NSObject=#}32");
232
233   meth = class_getClassMethod (fooClass, @selector(_defaultScriptingComponent));
234   CHECK_IF (method_getTypeEncoding (meth), "^{ComponentInstanceRecord=[1q]}16@0:8");
235
236   meth = class_getInstanceMethod (fooClass, @selector(_formatCocoaErrorString:parameters:applicableFormatters:count:));
237   CHECK_IF (method_getTypeEncoding (meth), "@44@0:8@16r*24^^{?}32i40");
238
239   meth = class_getInstanceMethod (fooClass, @selector(formatter_func:run:));
240   CHECK_IF (method_getTypeEncoding (meth), "^{?=^?@I}32@0:8@16r^^{?}24");
241
242   meth = class_getInstanceMethod (fooClass, @selector(_forgetWord:inDictionary:));
243   CHECK_IF (method_getTypeEncoding (meth), "c32@0:8nO@16nO@24");
244
245   meth = class_getInstanceMethod (fooClass, @selector(_registerServicesMenu:withSendTypes:andReturnTypes:addToList:));
246   CHECK_IF (method_getTypeEncoding (meth), "v44@0:8@16r^*24r^*32c40");
247
248   meth = class_getClassMethod (fooClass, @selector(_proxySharePointer));
249   CHECK_IF (method_getTypeEncoding (meth), "^^{__CFSet}16@0:8");
250
251   meth = class_getInstanceMethod (fooClass, @selector(_checkGrammarInString:language:details:));
252   CHECK_IF (method_getTypeEncoding (meth), "{_NSRange=II}40@0:8n@16nO@24oO^@32");
253
254   meth = class_getInstanceMethod (fooClass, @selector(_resolvePositionalStakeGlyphsForLineFragment:lineFragmentRect:minPosition:maxPosition:maxLineFragmentWidth:breakHint:));
255   CHECK_IF (method_getTypeEncoding (meth), "B60@0:8^{__CTLine=}16{_NSRect={_NSPoint=ff}{_NSSize=ff}}24f40f44f48^q52");
256
257   meth = class_getClassMethod (fooClass, @selector(findVoiceByIdentifier:returningCreator:returningID:));
258   CHECK_IF (method_getTypeEncoding (meth), "c40@0:8@16^I24^I32");
259
260   ivars = class_copyIvarList (fooClass, &ivar_count);
261   if (ivar_count != 1) {
262     abort ();
263   }
264
265   ivar = ivars[0];
266   CHECK_IF (ivar_getName(ivar), "r");
267   CHECK_IF (ivar_getTypeEncoding(ivar),
268    "{?=\"_attributes\"@\"NSDictionary\"\"_font\"@\"NSFont\"\"_characterLength\""
269     "q\"_nominalGlyphLocation\"q\"p\"^q\"_defaultLineHeight\"f\"_defaultBaselineOffset\""
270     "f\"_horizExpansion\"f\"_baselineDelta\"f\"_attachmentBBox\"{_NSRect=\"origin\""
271     "{_NSPoint=\"x\"f\"y\"f}\"size\"{_NSSize=\"width\"f\"height\"f}}\"ll\"q\"llp\"^q\"ull\""
272     "Q\"ullp\"^Q\"a\"@\"a1\"@\"a2\"@\"b\":\"b1\":\"b2\":\"str1\"*\"str2\"*\"str3\"*\"str4\""
273     "*\"_rFlags\"{?=\"_isAttachmentRun\"b1\"_hasPositionalStake\"b1\"_isDefaultFace\""
274     "b1\"_hasCombiningMarks\"b1\"_isScreenFont\"b1\"_reserved\"b27}}");
275 /*"{?=\"_attributes\"@\"NSDictionary\"\"_font\"@\"NSFont\"\"_characterLength\"q\"_nominalGlyphLocation\"q\"p\"^q\"_defaultLineHeight\"f\"_defaultBaselineOffset\"f\"_horizExpansion\"f\"_baselineDelta\"f\"_attachmentBBox\"{_NSRect=\"origin\"{_NSPoint=\"x\"f\"y\"f}\"size\"{_NSSize=\"width\"f\"height\"f}}\"ll\"q\"llp\"^q\"ull\"Q\"ullp\"^Q\"a\"@\"a1\"@\"a2\"@\"b\":\"b1\":\"b2\"^{objc_selector}\"str1\"*\"str2\"*\"str3\"*\"str4\"*\"_rFlags\"{?=\"_isAttachmentRun\"b1\"_hasPositionalStake\"b1\"_isDefaultFace\"b1\"_hasCombiningMarks\"b1\"_isScreenFont\"b1\"_reserved\"b27}}"*/
276   return 0;
277 }