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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [gcc/] [testsuite/] [objc.dg/] [encode-3.m] - Blame information for rev 378

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

Line No. Rev Author Line
1 309 jeremybenn
/* Method encoding tests for stand-alone @protocol declarations.  */
2
/* Contributed by Ziemowit Laski <zlaski@apple.com>.  */
3
/* { dg-do run } */
4
 
5
#include <stdlib.h>
6
#include "../objc-obj-c++-shared/Protocol1.h"
7
/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
8
 
9
#ifdef __cplusplus
10
#define ProtoBool bool
11
#else
12
#define ProtoBool _Bool
13
#endif
14
 
15
#ifndef __NEXT_RUNTIME__
16
#include <objc/objc-api.h>
17
#endif
18
 
19
extern int sscanf(const char *str, const char *format, ...);
20
extern void abort(void);
21
#define CHECK_IF(expr) if(!(expr)) abort()
22
 
23
enum Enum {
24
  zero, one, two, three
25
};
26
typedef enum Enum Enum;
27
typedef signed char ObjCBool; /* as used by the NeXT runtime */
28
 
29
@protocol Proto
30
union __XXAngle { unsigned int alpha, beta; };
31
typedef struct { float x, y; union __XXAngle a; } XXPoint;
32
typedef struct { double width, height; } XXSize;
33
typedef struct _XXRect { XXPoint origin; XXSize size; struct _XXRect *next; } XXRect;
34
- (void) char:(signed char)c float:(float)f double:(double)d unsigned:(unsigned)u short:(short)s long:(long)l;
35
- (void *)setRect:(XXRect)r withBool:(ProtoBool)b withInt:(int)i;
36
+ (Enum *)getEnum:(XXPoint *)pt enum:(enum Enum)e bool:(ObjCBool)b;
37
+ (ProtoBool **)getBool:(ObjCBool **)b;
38
@end
39
 
40
Protocol *proto = @protocol(Proto);
41
struct objc_method_description *meth;
42
unsigned totsize, offs0, offs1, offs2, offs3, offs4, offs5, offs6, offs7;
43
 
44
static void scan_initial(const char *pattern) {
45
  totsize = offs0 = offs1 = offs2 = offs3 = offs4 = offs5 = offs6 = offs7 = (unsigned)-1;
46
  sscanf(meth->types, pattern, &totsize, &offs0, &offs1, &offs2, &offs3,
47
      &offs4, &offs5, &offs6, &offs7);
48
  CHECK_IF(!offs0 && offs1 == sizeof(id) && offs2 == offs1 + sizeof(SEL) && totsize >= offs2);
49
}
50
 
51
int main(void) {
52
  const char *string;
53
 
54
  meth = [proto descriptionForInstanceMethod: @selector(char:float:double:unsigned:short:long:)];
55
  if (sizeof (long) == 8)
56
    string = "v%u@%u:%uc%uf%ud%uI%us%uq%u";
57
  else
58
    string = "v%u@%u:%uc%uf%ud%uI%us%ul%u";
59
  scan_initial(string);
60
  CHECK_IF(offs3 == offs2 + sizeof(int) && offs4 == offs3 + sizeof(float));
61
  CHECK_IF(offs5 == offs4 + sizeof(double) && offs6 == offs5 + sizeof(unsigned));
62
  CHECK_IF(offs7 == offs6 + sizeof(int) && totsize == offs7 + sizeof(long));
63
  meth = [proto descriptionForInstanceMethod: @selector(setRect:withBool:withInt:)];
64
  scan_initial("^v%u@%u:%u{_XXRect={?=ff(__XXAngle=II)}{?=dd}^{_XXRect}}%uB%ui%u");
65
  CHECK_IF(offs3 == offs2 + sizeof(XXRect) && offs4 == offs3 + sizeof(int));
66
  CHECK_IF(totsize == offs4 + sizeof(int));
67
  meth = [proto descriptionForClassMethod: @selector(getEnum:enum:bool:)];
68
  scan_initial("^i%u@%u:%u^{?=ff(__XXAngle=II)}%ui%uc%u");
69
  CHECK_IF(offs3 == offs2 + sizeof(XXPoint *) && offs4 == offs3 + sizeof(enum Enum));
70
  CHECK_IF(totsize == offs4 + sizeof(int));  /* 'ObjCBool' is really 'char' */
71
  meth = [proto descriptionForClassMethod: @selector(getBool:)];
72
  scan_initial("^^B%u@%u:%u^*%u");
73
  CHECK_IF(totsize == offs2 + sizeof(ObjCBool **));
74
  return 0;
75
}

powered by: WebSVN 2.1.0

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