@@ -36,12 +36,13 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
3636 var structNamespace = context . TargetSymbol . ContainingType . ContainingNamespace . ToString ( ) ;
3737 var structName = context . TargetSymbol . ContainingType . Name ;
3838 var methodSymbol = ( IMethodSymbol ) context . TargetSymbol ;
39+ var isReturnTypeVoid = methodSymbol . ReturnsVoid ;
3940 var functionName = methodSymbol . Name ;
4041 var returnTypeName = methodSymbol . ReturnType . ToDisplayString ( SymbolDisplayFormat . FullyQualifiedFormat ) ;
4142 var parameters = methodSymbol . Parameters . Select ( x => new ParameterTypeNamePair ( x . Type . ToDisplayString ( SymbolDisplayFormat . FullyQualifiedFormat ) , x . Name ) ) ;
4243 var index = ( int ) context . Attributes [ 0 ] . NamedArguments . FirstOrDefault ( x => x . Key . Equals ( "Index" ) ) . Value . Value ! ;
4344
44- return new VTableFunctionInfo ( fullyQualifiedParentTypeName , structNamespace , structName , functionName , returnTypeName , index , new ( parameters . ToImmutableArray ( ) ) ) ;
45+ return new VTableFunctionInfo ( fullyQualifiedParentTypeName , structNamespace , structName , isReturnTypeVoid , functionName , returnTypeName , index , new ( parameters . ToImmutableArray ( ) ) ) ;
4546 } )
4647 . Where ( static item => item is not null )
4748 . Collect ( )
@@ -88,12 +89,14 @@ private string GenerateVtableFunctionsForStruct(ImmutableArray<VTableFunctionInf
8889
8990 foreach ( var source in sources )
9091 {
92+ var returnTypeName = source . IsReturnTypeVoid ? "void" : "int" ;
93+
9194 builder . AppendLine ( $ " [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]") ;
9295
9396 builder . AppendLine ( $ " public partial { source . ReturnTypeName } { source . Name } ({ string . Join ( ", " , source . Parameters . Select ( x => $ "{ x . FullyQualifiedTypeName } { x . ValueName } ") ) } )") ;
9497 builder . AppendLine ( $ " {{") ;
95- builder . AppendLine ( $ " return ({ source . ReturnTypeName } )((delegate* unmanaged[MemberFunction]<{ sources . ElementAt ( 0 ) . ParentTypeName } *, { string . Join ( ", " , source . Parameters . Select ( x => $ "{ x . FullyQualifiedTypeName } ") ) } , int >)(lpVtbl[{ source . Index } ]))") ;
96- builder . AppendLine ( $ " (({ sources . ElementAt ( 0 ) . ParentTypeName } *)global::System.Runtime.CompilerServices.Unsafe.AsPointer(ref this), { string . Join ( ", " , source . Parameters . Select ( x => $ "{ x . ValueName } ") ) } );") ;
98+ builder . AppendLine ( $ " return ({ source . ReturnTypeName } )((delegate* unmanaged[MemberFunction]<{ sources . ElementAt ( 0 ) . FullyQualifiedParentTypeName } *, { string . Join ( ", " , source . Parameters . Select ( x => $ "{ x . FullyQualifiedTypeName } ") ) } , { returnTypeName } >)(lpVtbl[{ source . Index } ]))") ;
99+ builder . AppendLine ( $ " (({ sources . ElementAt ( 0 ) . FullyQualifiedParentTypeName } *)global::System.Runtime.CompilerServices.Unsafe.AsPointer(ref this), { string . Join ( ", " , source . Parameters . Select ( x => $ "{ x . ValueName } ") ) } );") ;
97100 builder . AppendLine ( $ " }}") ;
98101
99102 if ( sourceIndex < sourceCount - 1 )
0 commit comments