File: main.m

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (92 lines) | stat: -rw-r--r-- 3,101 bytes parent folder | download | duplicates (19)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#import <Foundation/Foundation.h>

int side_effect = 0;

NSString *str = @"some string";

const char *directCallConflictingName() {
  return "wrong function";
}

@interface Foo : NSObject {
  int instance_var;
}
-(int) entryPoint;
@end

@implementation Foo
-(int) entryPoint
{
  // Try calling directly with self. Same as in the main method otherwise.
  return 0; //%self.expect_expr("[self directCallNoArgs]", result_summary='"called directCallNoArgs"')
            //%self.expect_expr("[self directCallArgs: 1111]", result_value="2345")
            //%self.expect_expr("side_effect = 0; [self directCallVoidReturn]; side_effect", result_value="4321")
            //%self.expect_expr("[self directCallNSStringArg: str]", result_summary='@"some string"')
            //%self.expect_expr("[self directCallIdArg: (id)str]", result_summary='@"some string appendix"')
            //%self.expect_expr("[self directCallConflictingName]", result_summary='"correct function"')
            //%self.expect_expr("[self directCallWithCategory]", result_summary='"called function with category"')
}

// Declare several objc_direct functions we can test.
-(const char *) directCallNoArgs __attribute__((objc_direct))
{
  return "called directCallNoArgs";
}

-(void) directCallVoidReturn __attribute__((objc_direct))
{
  side_effect = 4321;
}

-(int) directCallArgs:(int)i __attribute__((objc_direct))
{
  // Use the arg in some way to make sure that gets passed correctly.
  return i + 1234;
}

-(NSString *) directCallNSStringArg:(NSString *)str __attribute__((objc_direct))
{
  return str;
}

-(NSString *) directCallIdArg:(id)param __attribute__((objc_direct))
{
  return [param stringByAppendingString:@" appendix"];
}

// We have another function with the same name above. Make sure this doesn't influence
// what we call.
-(const char *) directCallConflictingName  __attribute__((objc_direct))
{
  return "correct function";
}
@end


@interface Foo (Cat)
@end

@implementation Foo (Cat)
-(const char *) directCallWithCategory  __attribute__((objc_direct))
{
  return "called function with category";
}
@end

int main()
{
  Foo *foo = [[Foo alloc] init];
  [foo directCallNoArgs];
  [foo directCallArgs: 1];
  [foo directCallVoidReturn];
  [foo directCallNSStringArg: str];
  [foo directCallIdArg: (id)str];
  [foo entryPoint];  //%self.expect_expr("[foo directCallNoArgs]", result_summary='"called directCallNoArgs"')
                     //%self.expect_expr("[foo directCallArgs: 1111]", result_value="2345")
                     //%self.expect_expr("side_effect = 0; [foo directCallVoidReturn]; side_effect", result_value="4321")
                     //%self.expect_expr("[foo directCallNSStringArg: str]", result_summary='@"some string"')
                     //%self.expect_expr("[foo directCallIdArg: (id)str]", result_summary='@"some string appendix"')
                     //%self.expect_expr("[foo directCallConflictingName]", result_summary='"correct function"')
                     //%self.expect_expr("[foo directCallWithCategory]", result_summary='"called function with category"')
  return 0;
}