File: main.m

package info (click to toggle)
llvm-toolchain-11 1%3A11.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 995,808 kB
  • sloc: cpp: 4,767,656; ansic: 760,916; asm: 477,436; python: 170,940; objc: 69,804; lisp: 29,914; sh: 23,855; f90: 18,173; pascal: 7,551; perl: 7,471; ml: 5,603; awk: 3,489; makefile: 2,573; xml: 915; cs: 573; fortran: 503; javascript: 452
file content (92 lines) | stat: -rw-r--r-- 3,035 bytes parent folder | download | duplicates (2)
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]", substrs=["called directCallNoArgs"])
            //%self.expect("expr [self directCallArgs: 1111]", substrs=["= 2345"])
            //%self.expect("expr side_effect = 0; [self directCallVoidReturn]; side_effect", substrs=["= 4321"])
            //%self.expect("expr [self directCallNSStringArg: str]", substrs=['@"some string"'])
            //%self.expect("expr [self directCallIdArg: (id)str]", substrs=['@"some string appendix"'])
            //%self.expect("expr [self directCallConflictingName]", substrs=["correct function"])
            //%self.expect("expr [self directCallWithCategory]", substrs=["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]", substrs=["called directCallNoArgs"])
                     //%self.expect("expr [foo directCallArgs: 1111]", substrs=["= 2345"])
                     //%self.expect("expr side_effect = 0; [foo directCallVoidReturn]; side_effect", substrs=["= 4321"])
                     //%self.expect("expr [foo directCallNSStringArg: str]", substrs=['@"some string"'])
                     //%self.expect("expr [foo directCallIdArg: (id)str]", substrs=['@"some string appendix"'])
                     //%self.expect("expr [foo directCallConflictingName]", substrs=["correct function"])
                     //%self.expect("expr [foo directCallWithCategory]", substrs=["called function with category"])
  return 0;
}