C#: Static marshaling for bindings and source generators

Previously, we added source generators for invoking/accessing methods,
properties and fields in scripts. This freed us from the overhead of
reflection. However, the generated code still used our dynamic
marshaling functions, which do runtime type checking and box value
types.

This commit changes the bindings and source generators to include
'static' marshaling. Based on the types known at compile time, now
we generate the appropriate marshaling call for each type.
This commit is contained in:
Ignacio Roldán Etcheverry 2022-02-27 21:57:46 +01:00
parent 778007a358
commit e22dd3bc6a
14 changed files with 1009 additions and 356 deletions

View file

@ -190,6 +190,7 @@ namespace Godot.SourceGenerators
if (method.IsGenericMethod)
continue;
var retSymbol = method.ReturnType;
var retType = method.ReturnsVoid ?
null :
MarshalUtils.ConvertManagedTypeToMarshalType(method.ReturnType, typeCache);
@ -212,7 +213,7 @@ namespace Godot.SourceGenerators
continue;
yield return new GodotMethodData(method, paramTypes, parameters
.Select(p => p.Type).ToImmutableArray(), retType);
.Select(p => p.Type).ToImmutableArray(), retType, retSymbol);
}
}