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

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [gcc/] [testsuite/] [obj-c++.dg/] [template-4.mm] - Blame information for rev 20

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

Line No. Rev Author Line
1 12 jlechner
/* Author:  Ziemowit Laski .  */
2
 
3
/* { dg-do run } */
4
 
5
#include 
6
#include 
7
#include 
8
 
9
#ifdef __NEXT_RUNTIME__
10
/* The following ain't pretty, but does allow us to have just one copy
11
   of next_mapping.h.  */
12
#include "../objc/execute/next_mapping.h"
13
#else
14
#include 
15
#endif
16
 
17
#define CHECK_IF(expr) if(!(expr)) abort()
18
 
19
template  class TestT
20
{
21
public:
22
  TYPE k;
23
  int abc(ARR *array) {
24
    return [array count] * k;
25
  }
26
  TestT(TYPE _k): k(_k) { }
27
};
28
 
29
template 
30
const char *getDesc(void) {
31
  return [TYPE name];
32
}
33
 
34
@class Array;
35
 
36
template 
37
int abc(TYPE *xyz, Array *array) {
38
  return [xyz count] + [array count];
39
}
40
 
41
@interface Array: Object {
42
  id *arr;
43
  int count;
44
}
45
+ (id)arrayWithObjects:(id)first, ... ;
46
- (int)count;
47
@end
48
 
49
@implementation Array
50
+ (id)arrayWithObjects:(id)first, ... {
51
  Array *a = [Array new];
52
  a->count = 0;
53
  a->arr = (id *) calloc(8, sizeof(id));
54
 
55
  va_list args;
56
  va_start (args, first);
57
 
58
  a->arr[a->count++] = first;
59
 
60
  for (id el; el = va_arg(args, id); a->count++)
61
    a->arr[a->count] = el;
62
 
63
  return a;
64
}
65
- (int)count {
66
  return count;
67
}
68
@end
69
 
70
int main(void) {
71
  CHECK_IF(!strcmp ([@"Object" cString], getDesc()));
72
  CHECK_IF(!strcmp ([@"Array" cString], getDesc()));
73
 
74
  Array* a1 = [Array arrayWithObjects:@"One", @"Two", @"Three", nil];
75
  Array* a2 = [Array arrayWithObjects:@"Four", @"Five", nil];
76
 
77
  TestT t(7);
78
  CHECK_IF(t.abc(a1) + t.abc(a2) == 35);
79
  CHECK_IF(abc(a1, a2) * t.k == 35);
80
  return 0;
81
}

powered by: WebSVN 2.1.0

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