You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-06 12:20:30 +00:00
C#: Add initial implementation of source generator for script members
This replaces the way we invoke methods and set/get properties. This first iteration rids us of runtime type checking in those cases, as it's now done at compile time. Later it will also stop needing the use of reflection. After that, we will only depend on reflection for generic Godot Array and Dictionary. We're stuck with reflection in generic collections for now as C# doesn't support generic/template specialization. This is only the initial implementation. Further iterations are coming, specially once we switch to the native extension system which completely changes the way members are accessed/invoked. For example, with the native extension system we will likely need to create `UnmanagedCallersOnly` invoke wrapper methods and return function pointers to the engine. Other kind of members, like event signals will be receiving the same treatment in the future.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.CodeAnalysis;
|
||||
@@ -13,6 +14,11 @@ namespace Godot.SourceGenerators
|
||||
) => context.AnalyzerConfigOptions.GlobalOptions
|
||||
.TryGetValue("build_property." + property, out value);
|
||||
|
||||
public static bool AreGodotSourceGeneratorsDisabled(this GeneratorExecutionContext context)
|
||||
=> context.TryGetGlobalAnalyzerProperty("GodotSourceGenerators", out string? toggle) &&
|
||||
toggle != null &&
|
||||
toggle.Equals("disabled", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
private static bool InheritsFrom(this INamedTypeSymbol? symbol, string baseName)
|
||||
{
|
||||
if (symbol == null)
|
||||
@@ -72,15 +78,11 @@ namespace Godot.SourceGenerators
|
||||
public static bool IsPartial(this ClassDeclarationSyntax cds)
|
||||
=> cds.Modifiers.Any(SyntaxKind.PartialKeyword);
|
||||
|
||||
public static bool HasDisableGeneratorsAttribute(this INamedTypeSymbol symbol)
|
||||
=> symbol.GetAttributes().Any(attr =>
|
||||
attr.AttributeClass?.ToString() == GodotClasses.DisableGodotGeneratorsAttr);
|
||||
|
||||
private static SymbolDisplayFormat FullyQualifiedFormatOmitGlobal { get; } =
|
||||
SymbolDisplayFormat.FullyQualifiedFormat
|
||||
.WithGlobalNamespaceStyle(SymbolDisplayGlobalNamespaceStyle.Omitted);
|
||||
|
||||
public static string FullQualifiedName(this INamedTypeSymbol symbol)
|
||||
public static string FullQualifiedName(this ITypeSymbol symbol)
|
||||
=> symbol.ToDisplayString(NullableFlowState.NotNull, FullyQualifiedFormatOmitGlobal);
|
||||
|
||||
public static string FullQualifiedName(this INamespaceSymbol namespaceSymbol)
|
||||
|
||||
Reference in New Issue
Block a user