@@ -137,6 +137,14 @@ pub struct BindgenContext<'ctx> {
137
137
/// Current module being traversed.
138
138
current_module : ItemId ,
139
139
140
+ /// A HashMap keyed on a type definition, and whose value is the parent id
141
+ /// of the declaration.
142
+ ///
143
+ /// This is used to handle the cases where the semantic and the lexical
144
+ /// parents of the cursor differ, like when a nested class is defined
145
+ /// outside of the parent class.
146
+ semantic_parents : HashMap < clang:: Cursor , ItemId > ,
147
+
140
148
/// A stack with the current type declarations and types we're parsing. This
141
149
/// is needed to avoid infinite recursion when parsing a type like:
142
150
///
@@ -375,6 +383,7 @@ impl<'ctx> BindgenContext<'ctx> {
375
383
next_item_id : ItemId ( 1 ) ,
376
384
root_module : root_module. id ( ) ,
377
385
current_module : root_module. id ( ) ,
386
+ semantic_parents : Default :: default ( ) ,
378
387
currently_parsed_types : vec ! [ ] ,
379
388
parsed_macros : Default :: default ( ) ,
380
389
replacements : Default :: default ( ) ,
@@ -1187,6 +1196,31 @@ impl<'ctx> BindgenContext<'ctx> {
1187
1196
self . current_module
1188
1197
}
1189
1198
1199
+ /// Add a semantic parent for a given type definition.
1200
+ ///
1201
+ /// We do this from the type declaration, in order to be able to find the
1202
+ /// correct type definition afterwards.
1203
+ ///
1204
+ /// TODO(emilio): We could consider doing this only when
1205
+ /// declaration.lexical_parent() != definition.lexical_parent(), but it's
1206
+ /// not sure it's worth it.
1207
+ pub fn add_semantic_parent (
1208
+ & mut self ,
1209
+ definition : clang:: Cursor ,
1210
+ parent_id : ItemId ,
1211
+ ) {
1212
+ self . semantic_parents . insert ( definition, parent_id) ;
1213
+ }
1214
+
1215
+ /// Returns a known semantic parent for a given definition.
1216
+ pub fn known_semantic_parent (
1217
+ & self ,
1218
+ definition : clang:: Cursor
1219
+ ) -> Option < ItemId > {
1220
+ self . semantic_parents . get ( & definition) . cloned ( )
1221
+ }
1222
+
1223
+
1190
1224
/// Given a cursor pointing to the location of a template instantiation,
1191
1225
/// return a tuple of the form `(declaration_cursor, declaration_id,
1192
1226
/// num_expected_template_args)`.
0 commit comments