66using CppSharp . Generators ;
77using CppSharp . Generators . CLI ;
88using CppSharp . Generators . CSharp ;
9+ using CppSharp . Types ;
910
1011namespace CppSharp . Passes
1112{
@@ -95,7 +96,11 @@ public static string FixSignatureForConversions(Function function, string signat
9596
9697 public class ParameterTypeComparer : IEqualityComparer < Parameter >
9798 {
98- public static readonly ParameterTypeComparer Instance = new ParameterTypeComparer ( ) ;
99+ public static readonly ParameterTypeComparer Instance =
100+ new ParameterTypeComparer ( ) ;
101+
102+ public static TypeMapDatabase TypeMaps { get ; set ; }
103+ public static GeneratorKind GeneratorKind { get ; set ; }
99104
100105 public bool Equals ( Parameter x , Parameter y )
101106 {
@@ -107,17 +112,60 @@ public bool Equals(Parameter x, Parameter y)
107112 // TODO: some target languages might make a difference between values and pointers
108113 Type leftPointee = left . GetPointee ( ) ;
109114 Type rightPointee = right . GetPointee ( ) ;
115+
116+ if ( CheckForSpecializations ( leftPointee , rightPointee ) )
117+ return true ;
118+
119+ if ( leftPointee != null && rightPointee != null &&
120+ leftPointee . GetMappedType ( TypeMaps , GeneratorKind ) . Equals (
121+ rightPointee . GetMappedType ( TypeMaps , GeneratorKind ) ) )
122+ return true ;
123+
110124 return ( leftPointee != null && leftPointee . Desugar ( false ) . Equals ( right ) ) ||
111125 ( rightPointee != null && rightPointee . Desugar ( false ) . Equals ( left ) ) ;
112126 }
113127
128+ private static bool CheckForSpecializations ( Type leftPointee , Type rightPointee )
129+ {
130+ ClassTemplateSpecialization leftSpecialization ;
131+ ClassTemplateSpecialization rightSpecialization ;
132+ return leftPointee . TryGetDeclaration ( out leftSpecialization ) &&
133+ rightPointee . TryGetDeclaration ( out rightSpecialization ) &&
134+ leftSpecialization . TemplatedDecl . TemplatedDecl . Equals (
135+ rightSpecialization . TemplatedDecl . TemplatedDecl ) &&
136+ leftSpecialization . Arguments . SequenceEqual (
137+ rightSpecialization . Arguments , TemplateArgumentComparer . Instance ) ;
138+ }
139+
114140 public int GetHashCode ( Parameter obj )
115141 {
116142 return obj . Type . GetHashCode ( ) ;
117143 }
118144
119145 public static TypePrinter TypePrinter { get ; set ; }
120146 }
147+
148+ public class TemplateArgumentComparer : IEqualityComparer < TemplateArgument >
149+ {
150+ public static readonly TemplateArgumentComparer Instance =
151+ new TemplateArgumentComparer ( ) ;
152+
153+ public bool Equals ( TemplateArgument x , TemplateArgument y )
154+ {
155+ if ( x . Kind != TemplateArgument . ArgumentKind . Type ||
156+ y . Kind != TemplateArgument . ArgumentKind . Type )
157+ return x . Equals ( y ) ;
158+ return x . Type . Type . GetMappedType ( ParameterTypeComparer . TypeMaps ,
159+ ParameterTypeComparer . GeneratorKind ) . Equals (
160+ y . Type . Type . GetMappedType ( ParameterTypeComparer . TypeMaps ,
161+ ParameterTypeComparer . GeneratorKind ) ) ;
162+ }
163+
164+ public int GetHashCode ( TemplateArgument obj )
165+ {
166+ return obj . GetHashCode ( ) ;
167+ }
168+ }
121169 }
122170
123171 public class CheckDuplicatedNamesPass : TranslationUnitPass
@@ -143,6 +191,8 @@ public override bool VisitASTContext(ASTContext context)
143191 break ;
144192 }
145193 DeclarationName . ParameterTypeComparer . TypePrinter = typePrinter ;
194+ DeclarationName . ParameterTypeComparer . TypeMaps = Context . TypeMaps ;
195+ DeclarationName . ParameterTypeComparer . GeneratorKind = Options . GeneratorKind ;
146196 return base . VisitASTContext ( context ) ;
147197 }
148198
0 commit comments