@@ -13,7 +13,7 @@ public class MultipleInheritancePass : TranslationUnitPass
13
13
/// We also need it to check if a class already has a complementary interface
14
14
/// because different classes may have the same secondary bases.
15
15
/// </summary>
16
- private readonly Dictionary < Class , Class > interfaces = new Dictionary < Class , Class > ( ) ;
16
+ private readonly HashSet < Class > interfaces = new HashSet < Class > ( ) ;
17
17
18
18
public MultipleInheritancePass ( )
19
19
{
@@ -30,8 +30,11 @@ public MultipleInheritancePass()
30
30
public override bool VisitTranslationUnit ( TranslationUnit unit )
31
31
{
32
32
bool result = base . VisitTranslationUnit ( unit ) ;
33
- foreach ( var @interface in interfaces . Where ( i => ! ( i . Key is ClassTemplateSpecialization ) ) )
34
- @interface . Key . Namespace . Classes . Add ( @interface . Value ) ;
33
+ foreach ( var @interface in interfaces . Where ( i => ! ( i is ClassTemplateSpecialization ) ) )
34
+ {
35
+ int index = @interface . Namespace . Declarations . IndexOf ( @interface . OriginalClass ) ;
36
+ @interface . Namespace . Declarations . Insert ( index , @interface ) ;
37
+ }
35
38
interfaces . Clear ( ) ;
36
39
return result ;
37
40
}
@@ -60,12 +63,9 @@ private Class GetInterface(Class @base)
60
63
{
61
64
if ( @base . CompleteDeclaration != null )
62
65
@base = ( Class ) @base . CompleteDeclaration ;
63
- var name = "I" + @base . Name ;
64
- if ( interfaces . ContainsKey ( @base ) )
65
- return interfaces [ @base ] ;
66
66
67
- return @base . Namespace . Classes . FirstOrDefault ( c => c . Name == name ) ??
68
- GetNewInterface ( name , @base ) ;
67
+ return interfaces . FirstOrDefault ( i => i . OriginalClass == @base ) ??
68
+ GetNewInterface ( "I" + @base . Name , @base ) ;
69
69
}
70
70
71
71
private Class GetNewInterface ( string name , Class @base )
@@ -80,8 +80,9 @@ private Class GetNewInterface(string name, Class @base)
80
80
{
81
81
Class template = specialization . TemplatedDecl . TemplatedClass ;
82
82
Class templatedInterface = GetInterface ( template ) ;
83
- if ( interfaces . ContainsKey ( specialization ) )
84
- return interfaces [ specialization ] ;
83
+ @interface = interfaces . FirstOrDefault ( i => i . OriginalClass == @base ) ;
84
+ if ( @interface != null )
85
+ return @interface ;
85
86
var specializedInterface = new ClassTemplateSpecialization ( ) ;
86
87
specializedInterface . Arguments . AddRange ( specialization . Arguments ) ;
87
88
specializedInterface . TemplatedDecl = new ClassTemplate { TemplatedDecl = templatedInterface } ;
@@ -163,7 +164,7 @@ where property.IsDeclared
163
164
164
165
@base . Bases . Add ( new BaseClassSpecifier { Type = new TagType ( @interface ) } ) ;
165
166
166
- interfaces . Add ( @base , @ interface) ;
167
+ interfaces . Add ( @interface ) ;
167
168
if ( @base . IsTemplate )
168
169
{
169
170
@interface . IsDependent = true ;
0 commit comments