@@ -14,6 +14,7 @@ use std::{
14
14
use webidl;
15
15
16
16
use super :: Result ;
17
+ use util:: camel_case_ident;
17
18
18
19
/// Collection of constructs that may use partial.
19
20
#[ derive( Default ) ]
@@ -33,6 +34,7 @@ pub(crate) struct InterfaceData {
33
34
pub ( crate ) partial : bool ,
34
35
pub ( crate ) operations : BTreeMap < OperationId , OperationData > ,
35
36
pub ( crate ) global : bool ,
37
+ pub ( crate ) superclass : Option < String > ,
36
38
}
37
39
38
40
#[ derive( PartialEq , Eq , PartialOrd , Ord ) ]
@@ -178,6 +180,7 @@ impl FirstPass<()> for webidl::ast::NonPartialInterface {
178
180
. and_modify ( |interface_data| {
179
181
if interface_data. partial {
180
182
interface_data. partial = false ;
183
+ interface_data. superclass = self . inherits . clone ( ) ;
181
184
} else {
182
185
warn ! ( "Encountered multiple declarations of {}" , self . name) ;
183
186
}
@@ -187,6 +190,7 @@ impl FirstPass<()> for webidl::ast::NonPartialInterface {
187
190
partial : false ,
188
191
operations : Default :: default ( ) ,
189
192
global : false ,
193
+ superclass : self . inherits . clone ( ) ,
190
194
} ,
191
195
) ;
192
196
@@ -216,6 +220,7 @@ impl FirstPass<()> for webidl::ast::PartialInterface {
216
220
partial : true ,
217
221
operations : Default :: default ( ) ,
218
222
global : false ,
223
+ superclass : None ,
219
224
} ,
220
225
) ;
221
226
@@ -386,3 +391,27 @@ impl FirstPass<()> for webidl::ast::Typedef {
386
391
Ok ( ( ) )
387
392
}
388
393
}
394
+
395
+ impl < ' a > FirstPassRecord < ' a > {
396
+ pub fn all_superclasses < ' me > ( & ' me self , interface : & str )
397
+ -> impl Iterator < Item = String > + ' me
398
+ {
399
+ let mut set = BTreeSet :: new ( ) ;
400
+ self . fill_superclasses ( interface, & mut set) ;
401
+ set. into_iter ( )
402
+ }
403
+
404
+ fn fill_superclasses ( & self , interface : & str , set : & mut BTreeSet < String > ) {
405
+ let data = match self . interfaces . get ( interface) {
406
+ Some ( data) => data,
407
+ None => return ,
408
+ } ;
409
+ let superclass = match & data. superclass {
410
+ Some ( class) => class,
411
+ None => return ,
412
+ } ;
413
+ if set. insert ( camel_case_ident ( superclass) ) {
414
+ self . fill_superclasses ( superclass, set) ;
415
+ }
416
+ }
417
+ }
0 commit comments