@@ -147,13 +147,14 @@ impl Type {
147
147
type_resolver. resolve_type ( t) . can_derive_debug ( type_resolver)
148
148
}
149
149
TypeKind :: ResolvedTypeRef ( t) |
150
+ TypeKind :: TemplateAlias ( t, _) |
150
151
TypeKind :: Alias ( _, t) => {
151
152
type_resolver. resolve_type ( t) . can_derive_debug ( type_resolver)
152
153
}
153
154
TypeKind :: Comp ( ref info) => {
154
155
info. can_derive_debug ( type_resolver, self . layout ( type_resolver) )
155
156
}
156
- _ => true ,
157
+ _ => true ,
157
158
}
158
159
}
159
160
@@ -178,6 +179,7 @@ impl Type {
178
179
pub fn can_derive_copy_in_array ( & self , type_resolver : & TypeResolver , item : & Item ) -> bool {
179
180
match self . kind {
180
181
TypeKind :: ResolvedTypeRef ( t) |
182
+ TypeKind :: TemplateAlias ( t, _) |
181
183
TypeKind :: Alias ( _, t) |
182
184
TypeKind :: Array ( t, _) => {
183
185
type_resolver. resolve_item ( t)
@@ -195,6 +197,7 @@ impl Type {
195
197
type_resolver. resolve_item ( t) . can_derive_copy_in_array ( type_resolver)
196
198
}
197
199
TypeKind :: ResolvedTypeRef ( t) |
200
+ TypeKind :: TemplateAlias ( t, _) |
198
201
TypeKind :: TemplateRef ( t, _) |
199
202
TypeKind :: Alias ( _, t) => {
200
203
type_resolver. resolve_item ( t) . can_derive_copy ( type_resolver)
@@ -210,6 +213,7 @@ impl Type {
210
213
// FIXME: Can we do something about template parameters? Huh...
211
214
match self . kind {
212
215
TypeKind :: TemplateRef ( t, _) |
216
+ TypeKind :: TemplateAlias ( t, _) |
213
217
TypeKind :: Alias ( _, t) |
214
218
TypeKind :: ResolvedTypeRef ( t) |
215
219
TypeKind :: Array ( t, _) => {
@@ -226,6 +230,7 @@ impl Type {
226
230
pub fn has_destructor ( & self , type_resolver : & TypeResolver ) -> bool {
227
231
self . is_opaque ( type_resolver) || match self . kind {
228
232
TypeKind :: TemplateRef ( t, _) |
233
+ TypeKind :: TemplateAlias ( t, _) |
229
234
TypeKind :: Alias ( _, t) |
230
235
TypeKind :: ResolvedTypeRef ( t) |
231
236
TypeKind :: Array ( t, _) => {
@@ -264,7 +269,8 @@ impl Type {
264
269
type_resolver. resolve_type ( sig. return_type ( ) )
265
270
. signature_contains_named_type ( type_resolver, ty)
266
271
} ,
267
- TypeKind :: TemplateRef ( _inner, ref template_args) => {
272
+ TypeKind :: TemplateAlias ( _, ref template_args) |
273
+ TypeKind :: TemplateRef ( _, ref template_args) => {
268
274
template_args. iter ( ) . any ( |arg| {
269
275
type_resolver. resolve_type ( * arg)
270
276
. signature_contains_named_type ( type_resolver, ty)
@@ -293,6 +299,7 @@ impl Type {
293
299
294
300
TypeKind :: ResolvedTypeRef ( inner) |
295
301
TypeKind :: Alias ( _, inner) |
302
+ TypeKind :: TemplateAlias ( inner, _) |
296
303
TypeKind :: TemplateRef ( inner, _)
297
304
=> type_resolver. resolve_type ( inner) . canonical_type ( type_resolver) ,
298
305
@@ -328,6 +335,9 @@ pub enum TypeKind {
328
335
Float ( FloatKind ) ,
329
336
/// A type alias, with a name, that points to another type.
330
337
Alias ( String , ItemId ) ,
338
+ /// A templated alias, pointing to an inner Alias type, with template
339
+ /// parameters.
340
+ TemplateAlias ( ItemId , Vec < ItemId > ) ,
331
341
/// An array of a type and a lenght.
332
342
Array ( ItemId , usize ) ,
333
343
/// A function type, with a given signature.
@@ -372,6 +382,7 @@ impl Type {
372
382
}
373
383
TypeKind :: ResolvedTypeRef ( inner) |
374
384
TypeKind :: Alias ( _, inner) |
385
+ TypeKind :: TemplateAlias ( inner, _) |
375
386
TypeKind :: TemplateRef ( inner, _)
376
387
=> type_resolver. resolve_type ( inner) . is_unsized ( type_resolver) ,
377
388
TypeKind :: Named ( ..) |
@@ -445,6 +456,51 @@ impl Type {
445
456
. expect ( "C'mon" ) ;
446
457
TypeKind :: Comp ( complex)
447
458
}
459
+ CXCursor_TypeAliasTemplateDecl => {
460
+ debug ! ( "TypeAliasTemplateDecl" ) ;
461
+
462
+ // We need to manually unwind this one.
463
+ let mut inner = Err ( ParseError :: Continue ) ;
464
+ let mut args = vec ! [ ] ;
465
+
466
+ location. visit ( |cur, _| {
467
+ match cur. kind ( ) {
468
+ CXCursor_TypeAliasDecl => {
469
+ debug_assert ! ( cur. cur_type( ) . kind( ) == CXType_Typedef ) ;
470
+ inner = Item :: from_ty ( & cur. cur_type ( ) ,
471
+ Some ( * cur) ,
472
+ Some ( potential_id) ,
473
+ ctx) ;
474
+ }
475
+ CXCursor_TemplateTypeParameter => {
476
+ let default_type =
477
+ Item :: from_ty ( & cur. cur_type ( ) ,
478
+ Some ( * cur) ,
479
+ Some ( potential_id) ,
480
+ ctx) . ok ( ) ;
481
+ let param =
482
+ Item :: named_type ( cur. spelling ( ) ,
483
+ default_type,
484
+ potential_id, ctx) ;
485
+ args. push ( param) ;
486
+ }
487
+ _ => { }
488
+ }
489
+ CXChildVisit_Continue
490
+ } ) ;
491
+
492
+ if inner. is_err ( ) {
493
+ error ! ( "Failed to parse templated type alias {:?}" , location) ;
494
+ return Err ( ParseError :: Continue ) ;
495
+ }
496
+
497
+ if args. is_empty ( ) {
498
+ error ! ( "Failed to get any template parameter, maybe a specialization? {:?}" , location) ;
499
+ return Err ( ParseError :: Continue ) ;
500
+ }
501
+
502
+ TypeKind :: TemplateAlias ( inner. unwrap ( ) , args)
503
+ }
448
504
CXCursor_TemplateRef => {
449
505
let referenced = location. referenced ( ) ;
450
506
return Self :: from_clang_ty ( potential_id,
@@ -522,7 +578,7 @@ impl Type {
522
578
let signature = try!( FunctionSig :: from_ty ( ty, & location. unwrap_or ( cursor) , ctx) ) ;
523
579
TypeKind :: Function ( signature)
524
580
}
525
- CXType_Typedef => {
581
+ CXType_Typedef => {
526
582
let inner = cursor. typedef_type ( ) ;
527
583
let inner =
528
584
Item :: from_ty_or_ref ( inner, location, parent_id, ctx) ;
0 commit comments