@@ -217,32 +217,37 @@ public override bool VisitPrimitiveType(PrimitiveType primitive, TypeQualifiers
217
217
218
218
public override bool VisitTypedefType ( TypedefType typedef , TypeQualifiers quals )
219
219
{
220
- if ( ! VisitType ( typedef , quals ) )
220
+ if ( ! ( typedef . Declaration . Type . Desugar ( false ) is TemplateParameterSubstitutionType ) &&
221
+ ! VisitType ( typedef , quals ) )
221
222
return false ;
222
223
223
224
var decl = typedef . Declaration ;
224
225
225
- var functionType = decl . Type as FunctionType ;
226
- if ( functionType != null || decl . Type . IsPointerTo ( out functionType ) )
227
- {
228
- var ptrName = $ "{ Generator . GeneratedIdentifier ( "ptr" ) } { Context . ParameterIndex } ";
229
-
230
- Context . Before . WriteLine ( $ "var { ptrName } = { Context . ReturnVarName } ;") ;
231
-
232
- var specialization = decl . Namespace as ClassTemplateSpecialization ;
233
- Type returnType = Context . ReturnType . Type . Desugar ( ) ;
234
- var finalType = ( returnType . GetFinalPointee ( ) ?? returnType ) . Desugar ( ) ;
235
- var res = string . Format (
236
- "{0} == IntPtr.Zero? null : {1}({2}) Marshal.GetDelegateForFunctionPointer({0}, typeof({2}))" ,
237
- ptrName ,
238
- finalType . IsDependent ? $@ "({ specialization . TemplatedDecl . TemplatedClass . Typedefs . First (
239
- t => t . Name == decl . Name ) . Visit ( this . typePrinter ) } ) (object) " : string . Empty ,
240
- typedef ) ;
241
- Context . Return . Write ( res ) ;
242
- return true ;
243
- }
226
+ Type type = decl . Type . Desugar ( ) ;
227
+ var functionType = type as FunctionType ;
228
+ if ( functionType == null && ! type . IsPointerTo ( out functionType ) )
229
+ return decl . Type . Visit ( this ) ;
230
+
231
+ var ptrName = $@ "{ Generator . GeneratedIdentifier ( "ptr" ) } {
232
+ Context . ParameterIndex } " ;
244
233
245
- return decl . Type . Visit ( this ) ;
234
+ Context . Before . WriteLine ( $ "var { ptrName } = { Context . ReturnVarName } ;") ;
235
+
236
+ var substitution = decl . Type . Desugar ( false )
237
+ as TemplateParameterSubstitutionType ;
238
+
239
+ if ( substitution != null )
240
+ Context . Return . Write ( $@ "({
241
+ substitution . ReplacedParameter . Parameter . Name } ) (object) (" ) ;
242
+
243
+ Context . Return . Write ( $@ "{ ptrName } == IntPtr.Zero? null : {
244
+ ( substitution == null ? $ "({ Context . ReturnType } ) " :
245
+ string . Empty ) } Marshal.GetDelegateForFunctionPointer({
246
+ ptrName } , typeof({ typedef } ))" ) ;
247
+
248
+ if ( substitution != null )
249
+ Context . Return . Write ( ")" ) ;
250
+ return true ;
246
251
}
247
252
248
253
public override bool VisitFunctionType ( FunctionType function , TypeQualifiers quals )
0 commit comments