1
1
//! Objective C types
2
2
3
- use super :: context:: BindgenContext ;
3
+ use super :: context:: { BindgenContext , ItemId } ;
4
4
use super :: function:: FunctionSig ;
5
5
use super :: traversal:: { Trace , Tracer } ;
6
+ use super :: ty:: TypeKind ;
6
7
use clang;
7
8
use clang_sys:: CXChildVisit_Continue ;
8
9
use clang_sys:: CXCursor_ObjCCategoryDecl ;
9
10
use clang_sys:: CXCursor_ObjCClassRef ;
10
11
use clang_sys:: CXCursor_ObjCInstanceMethodDecl ;
11
12
use clang_sys:: CXCursor_ObjCProtocolDecl ;
13
+ use clang_sys:: CXCursor_ObjCProtocolRef ;
12
14
13
15
/// Objective C interface as used in TypeKind
14
16
///
@@ -23,6 +25,8 @@ pub struct ObjCInterface {
23
25
24
26
is_protocol : bool ,
25
27
28
+ conforms_to : Vec < ItemId > ,
29
+
26
30
/// List of the methods defined in this interfae
27
31
methods : Vec < ObjCInstanceMethod > ,
28
32
}
@@ -47,6 +51,7 @@ impl ObjCInterface {
47
51
name : name. to_owned ( ) ,
48
52
category : None ,
49
53
is_protocol : false ,
54
+ conforms_to : Vec :: new ( ) ,
50
55
methods : Vec :: new ( ) ,
51
56
}
52
57
}
@@ -98,6 +103,34 @@ impl ObjCInterface {
98
103
interface. category = Some ( cursor. spelling ( ) ) ;
99
104
}
100
105
}
106
+ CXCursor_ObjCProtocolRef => {
107
+ // Gather protocols this interface conforms to
108
+ let needle = format ! ( "protocol_{}" , c. spelling( ) ) ;
109
+ let items_map = ctx. items ( ) ;
110
+ debug ! ( "Interface {} conforms to {}, find the item" , interface. name, needle) ;
111
+
112
+ for ( id, item) in items_map
113
+ {
114
+ if let Some ( ty) = item. as_type ( ) {
115
+ match * ty. kind ( ) {
116
+ TypeKind :: ObjCInterface ( ref protocol) => {
117
+ if protocol. is_protocol
118
+ {
119
+ debug ! ( "Checking protocol {}, ty.name {:?}" , protocol. name, ty. name( ) ) ;
120
+ if Some ( needle. as_ref ( ) ) == ty. name ( )
121
+ {
122
+ debug ! ( "Found conforming protocol {:?}" , item) ;
123
+ interface. conforms_to . push ( * id) ;
124
+ break ;
125
+ }
126
+ }
127
+ }
128
+ _ => { }
129
+ }
130
+ }
131
+ }
132
+
133
+ }
101
134
CXCursor_ObjCInstanceMethodDecl => {
102
135
let name = c. spelling ( ) ;
103
136
let signature =
@@ -176,9 +209,12 @@ impl Trace for ObjCInterface {
176
209
fn trace < T > ( & self , context : & BindgenContext , tracer : & mut T , _: & ( ) )
177
210
where T : Tracer ,
178
211
{
179
- for method in & self . methods
180
- {
212
+ for method in & self . methods {
181
213
method. signature . trace ( context, tracer, & ( ) ) ;
182
214
}
215
+
216
+ for protocol in & self . conforms_to {
217
+ tracer. visit ( * protocol) ;
218
+ }
183
219
}
184
220
}
0 commit comments