1#import <Foundation/Foundation.h>
2
3int side_effect = 0;
4
5NSString *str = @"some string";
6
7const char *directCallConflictingName() {
8 return "wrong function";
9}
10
11@interface Foo : NSObject {
12 int instance_var;
13}
14-(int) entryPoint;
15@end
16
17@implementation Foo
18-(int) entryPoint
19{
20 // Try calling directly with self. Same as in the main method otherwise.
21 return 0; //%self.expect_expr("[self directCallNoArgs]", result_summary='"called directCallNoArgs"')
22 //%self.expect_expr("[self directCallArgs: 1111]", result_value="2345")
23 //%self.expect_expr("side_effect = 0; [self directCallVoidReturn]; side_effect", result_value="4321")
24 //%self.expect_expr("[self directCallNSStringArg: str]", result_summary='@"some string"')
25 //%self.expect_expr("[self directCallIdArg: (id)str]", result_summary='@"some string appendix"')
26 //%self.expect_expr("[self directCallConflictingName]", result_summary='"correct function"')
27 //%self.expect_expr("[self directCallWithCategory]", result_summary='"called function with category"')
28}
29
30// Declare several objc_direct functions we can test.
31-(const char *) directCallNoArgs __attribute__((objc_direct))
32{
33 return "called directCallNoArgs";
34}
35
36-(void) directCallVoidReturn __attribute__((objc_direct))
37{
38 side_effect = 4321;
39}
40
41-(int) directCallArgs:(int)i __attribute__((objc_direct))
42{
43 // Use the arg in some way to make sure that gets passed correctly.
44 return i + 1234;
45}
46
47-(NSString *) directCallNSStringArg:(NSString *)str __attribute__((objc_direct))
48{
49 return str;
50}
51
52-(NSString *) directCallIdArg:(id)param __attribute__((objc_direct))
53{
54 return [param stringByAppendingString:@" appendix"];
55}
56
57// We have another function with the same name above. Make sure this doesn't influence
58// what we call.
59-(const char *) directCallConflictingName __attribute__((objc_direct))
60{
61 return "correct function";
62}
63@end
64
65
66@interface Foo (Cat)
67@end
68
69@implementation Foo (Cat)
70-(const char *) directCallWithCategory __attribute__((objc_direct))
71{
72 return "called function with category";
73}
74@end
75
76int main()
77{
78 Foo *foo = [[Foo alloc] init];
79 [foo directCallNoArgs];
80 [foo directCallArgs: 1];
81 [foo directCallVoidReturn];
82 [foo directCallNSStringArg: str];
83 [foo directCallIdArg: (id)str];
84 [foo entryPoint]; //%self.expect_expr("[foo directCallNoArgs]", result_summary='"called directCallNoArgs"')
85 //%self.expect_expr("[foo directCallArgs: 1111]", result_value="2345")
86 //%self.expect_expr("side_effect = 0; [foo directCallVoidReturn]; side_effect", result_value="4321")
87 //%self.expect_expr("[foo directCallNSStringArg: str]", result_summary='@"some string"')
88 //%self.expect_expr("[foo directCallIdArg: (id)str]", result_summary='@"some string appendix"')
89 //%self.expect_expr("[foo directCallConflictingName]", result_summary='"correct function"')
90 //%self.expect_expr("[foo directCallWithCategory]", result_summary='"called function with category"')
91 return 0;
92}
93

source code of lldb/test/API/lang/objc/objc_direct-methods/main.m