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/] [proto-qual-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
/* Check that protocol qualifiers are compiled and encoded properly.  */
2
/* Author: Ziemowit Laski <zlaski@apple.com>  */
3
/* { dg-options "-lobjc" } */
4
/* { dg-do run } */
5
 
6
#include <objc/Protocol.h>
7
#ifndef __NEXT_RUNTIME__
8
#include <objc/objc-api.h>
9
#endif
10
 
11
/* The encoded parameter sizes will be rounded up to match pointer alignment.  */
12
#define ROUND(s,a) (a * ((s + a - 1) / a))
13
#define aligned_sizeof(T) ROUND(sizeof(T),__alignof(void *))
14
 
15
extern int sscanf(const char *str, const char *format, ...);
16
extern void abort(void);
17
#define CHECK_IF(expr) if(!(expr)) abort()
18
 
19
@protocol Retain
20
+ (oneway void)retainArgument:(out bycopy id)arg1 with:(in signed char **)arg2;
21
- (bycopy) address:(byref inout id)location with:(out short unsigned **)arg2;
22
@end
23
 
24
@interface Foo <Retain>
25
+ (oneway void)retainArgument:(out bycopy id)arg with:(in signed char **)arg2;
26
@end
27
 
28
@implementation Foo
29
+ (oneway void)retainArgument:(out bycopy id)arg1 with:(in signed char **)arg2 { }
30
- (bycopy) address:(byref inout id)location with:(out short unsigned **)arg2 { return nil; }
31
@end
32
 
33
Protocol *proto = @protocol(Retain);
34
struct objc_method_description *meth;
35
unsigned totsize, offs0, offs1, offs2, offs3, offs4, offs5, offs6, offs7;
36
 
37
static void scan_initial(const char *pattern) {
38
  totsize = offs0 = offs1 = offs2 = offs3 = offs4 = offs5 = offs6 = offs7 = (unsigned)-1;
39
  sscanf(meth->types, pattern, &totsize, &offs0, &offs1, &offs2, &offs3,
40
      &offs4, &offs5, &offs6, &offs7);
41
  CHECK_IF(!offs0 && offs1 == aligned_sizeof(id) && offs2 == offs1 + aligned_sizeof(SEL) && totsize >= offs2);
42
}
43
 
44
int main(void) {
45
  meth = [proto descriptionForInstanceMethod: @selector(address:with:)];
46
  scan_initial("O@%u@%u:%uRN@%uo^^S%u");
47
  CHECK_IF(offs3 == offs2 + aligned_sizeof(id) && totsize == offs3 + aligned_sizeof(unsigned));
48
  meth = [proto descriptionForClassMethod: @selector(retainArgument:with:)];
49
  scan_initial("Vv%u@%u:%uoO@%un^*%u");
50
  CHECK_IF(offs3 == offs2 + aligned_sizeof(id) && totsize == offs3 + aligned_sizeof(char **));
51
  return 0;
52
}

powered by: WebSVN 2.1.0

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