summaryrefslogtreecommitdiff
path: root/modules/mono/editor
diff options
context:
space:
mode:
authorIgnacio Roldán Etcheverry <ignalfonsore@gmail.com>2022-07-28 17:41:50 +0200
committerIgnacio Roldán Etcheverry <ignalfonsore@gmail.com>2022-08-22 03:36:52 +0200
commit3123be2384c14f7dd156b1cc2d53d822002b837a (patch)
tree34358a0c1b1e2555b8df0a5c346e20e4d9ff6645 /modules/mono/editor
parent344f5028d48d4a5caf321abdf023c34f52aae0a4 (diff)
C#: Array, Dictionary and marshaling refactoring
- Array and Dictionary now store `Variant` instead of `System.Object`. - Removed generic Array and Dictionary. They cause too much issues, heavily relying on reflection and very limited by the lack of a generic specialization. - Removed support for non-Godot collections. Support for them also relied heavily on reflection for marshaling. Support for them will likely be re-introduced in the future, but it will have to rely on source generators instead of reflection. - Reduced our use of reflection. The remaining usages will be moved to source generators soon. The only usage that I'm not sure yet how to replace is dynamic invocation of delegates.
Diffstat (limited to 'modules/mono/editor')
-rw-r--r--modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Sample/ExportedFields.cs35
-rw-r--r--modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Sample/ExportedProperties.cs35
-rw-r--r--modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MarshalType.cs16
-rw-r--r--modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MarshalUtils.cs277
-rw-r--r--modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptMethodsGenerator.cs4
-rw-r--r--modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertiesGenerator.cs4
-rw-r--r--modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSerializationGenerator.cs28
-rw-r--r--modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs2
-rw-r--r--modules/mono/editor/GodotTools/GodotTools/Build/BuildInfo.cs2
-rw-r--r--modules/mono/editor/GodotTools/GodotTools/Build/BuildOutputView.cs9
-rw-r--r--modules/mono/editor/GodotTools/GodotTools/Build/BuildSystem.cs9
-rw-r--r--modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs4
-rw-r--r--modules/mono/editor/GodotTools/GodotTools/Ides/Rider/RiderPathManager.cs4
-rw-r--r--modules/mono/editor/bindings_generator.cpp18
14 files changed, 210 insertions, 237 deletions
diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Sample/ExportedFields.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Sample/ExportedFields.cs
index 86c639f7b6..a5b4cb81f6 100644
--- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Sample/ExportedFields.cs
+++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Sample/ExportedFields.cs
@@ -80,28 +80,9 @@ namespace Godot.SourceGenerators.Sample
[Export] private Vector3[] field_Vector3Array = { Vector3.Up, Vector3.Down, Vector3.Left, Vector3.Right };
[Export] private Color[] field_ColorArray = { Colors.Aqua, Colors.Aquamarine, Colors.Azure, Colors.Beige };
[Export] private Godot.Object[] field_GodotObjectOrDerivedArray = { null };
-
- // Generics
- [Export] private Godot.Collections.Dictionary<string, string> field_GodotGenericDictionary =
- new Godot.Collections.Dictionary<string, string> { { "key1", "value1" }, { "key2", "value2" } };
-
- [Export] private Godot.Collections.Array<string> field_GodotGenericArray =
- new Godot.Collections.Array<string> { "elem1", "elem2", "elem3" };
-
- [Export] private System.Collections.Generic.Dictionary<string, string> field_SystemGenericDictionary =
- new System.Collections.Generic.Dictionary<string, string> { { "key1", "value1" }, { "key2", "value2" } };
-
- [Export] private System.Collections.Generic.List<string> field_SystemGenericList =
- new System.Collections.Generic.List<string> { "elem1", "elem2", "elem3" };
-
- [Export] private System.Collections.Generic.IDictionary<string, string> field_GenericIDictionary =
- new System.Collections.Generic.Dictionary<string, string> { { "key1", "value1" }, { "key2", "value2" } };
-
- [Export] private System.Collections.Generic.ICollection<string> field_GenericICollection =
- new System.Collections.Generic.List<string> { "elem1", "elem2", "elem3" };
-
- [Export] private System.Collections.Generic.IEnumerable<string> field_GenericIEnumerable =
- new System.Collections.Generic.List<string> { "elem1", "elem2", "elem3" };
+ [Export] private StringName[] field_StringNameArray = { "foo", "bar" };
+ [Export] private NodePath[] field_NodePathArray = { "foo", "bar" };
+ [Export] private RID[] field_RIDArray = { default, default, default };
// Variant
[Export] private Variant field_Variant = "foo";
@@ -118,15 +99,5 @@ namespace Godot.SourceGenerators.Sample
[Export] private Godot.Collections.Array field_GodotArray =
new() { "foo", 10, Vector2.Up, Colors.Chocolate };
-
- [Export] private System.Collections.IDictionary field_IDictionary =
- new System.Collections.Generic.Dictionary<object, object>
- { { "foo", 10 }, { Vector2.Up, Colors.Chocolate } };
-
- [Export] private System.Collections.ICollection field_ICollection =
- new System.Collections.Generic.List<object> { "foo", 10, Vector2.Up, Colors.Chocolate };
-
- [Export] private System.Collections.IEnumerable field_IEnumerable =
- new System.Collections.Generic.List<object> { "foo", 10, Vector2.Up, Colors.Chocolate };
}
}
diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Sample/ExportedProperties.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Sample/ExportedProperties.cs
index 665eb7f2a8..eb35c88260 100644
--- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Sample/ExportedProperties.cs
+++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Sample/ExportedProperties.cs
@@ -80,28 +80,9 @@ namespace Godot.SourceGenerators.Sample
[Export] private Vector3[] property_Vector3Array { get; set; } = { Vector3.Up, Vector3.Down, Vector3.Left, Vector3.Right };
[Export] private Color[] property_ColorArray { get; set; } = { Colors.Aqua, Colors.Aquamarine, Colors.Azure, Colors.Beige };
[Export] private Godot.Object[] property_GodotObjectOrDerivedArray { get; set; } = { null };
-
- // Generics
- [Export] private Godot.Collections.Dictionary<string, string> property_GodotGenericDictionary { get; set; } =
- new Godot.Collections.Dictionary<string, string> { { "key1", "value1" }, { "key2", "value2" } };
-
- [Export] private Godot.Collections.Array<string> property_GodotGenericArray { get; set; } =
- new Godot.Collections.Array<string> { "elem1", "elem2", "elem3" };
-
- [Export] private System.Collections.Generic.Dictionary<string, string> property_SystemGenericDictionary { get; set; } =
- new System.Collections.Generic.Dictionary<string, string> { { "key1", "value1" }, { "key2", "value2" } };
-
- [Export] private System.Collections.Generic.List<string> property_SystemGenericList { get; set; } =
- new System.Collections.Generic.List<string> { "elem1", "elem2", "elem3" };
-
- [Export] private System.Collections.Generic.IDictionary<string, string> property_GenericIDictionary { get; set; } =
- new System.Collections.Generic.Dictionary<string, string> { { "key1", "value1" }, { "key2", "value2" } };
-
- [Export] private System.Collections.Generic.ICollection<string> property_GenericICollection { get; set; } =
- new System.Collections.Generic.List<string> { "elem1", "elem2", "elem3" };
-
- [Export] private System.Collections.Generic.IEnumerable<string> property_GenericIEnumerable { get; set; } =
- new System.Collections.Generic.List<string> { "elem1", "elem2", "elem3" };
+ [Export] private StringName[] field_StringNameArray { get; set; } = { "foo", "bar" };
+ [Export] private NodePath[] field_NodePathArray { get; set; } = { "foo", "bar" };
+ [Export] private RID[] field_RIDArray { get; set; } = { default, default, default };
// Variant
[Export] private Variant property_Variant { get; set; } = "foo";
@@ -118,15 +99,5 @@ namespace Godot.SourceGenerators.Sample
[Export] private Godot.Collections.Array property_GodotArray { get; set; } =
new() { "foo", 10, Vector2.Up, Colors.Chocolate };
-
- [Export] private System.Collections.IDictionary property_IDictionary { get; set; } =
- new System.Collections.Generic.Dictionary<object, object>
- { { "foo", 10 }, { Vector2.Up, Colors.Chocolate } };
-
- [Export] private System.Collections.ICollection property_ICollection { get; set; } =
- new System.Collections.Generic.List<object> { "foo", 10, Vector2.Up, Colors.Chocolate };
-
- [Export] private System.Collections.IEnumerable property_IEnumerable { get; set; } =
- new System.Collections.Generic.List<object> { "foo", 10, Vector2.Up, Colors.Chocolate };
}
}
diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MarshalType.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MarshalType.cs
index e967cbe662..3f767c8a5f 100644
--- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MarshalType.cs
+++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MarshalType.cs
@@ -53,16 +53,9 @@ namespace Godot.SourceGenerators
Vector3Array,
ColorArray,
GodotObjectOrDerivedArray,
- SystemArrayOfSupportedType,
-
- // Generics
- GodotGenericDictionary,
- GodotGenericArray,
- SystemGenericDictionary,
- SystemGenericList,
- GenericIDictionary,
- GenericICollection,
- GenericIEnumerable,
+ SystemArrayOfStringName,
+ SystemArrayOfNodePath,
+ SystemArrayOfRID,
// Variant
Variant,
@@ -74,8 +67,5 @@ namespace Godot.SourceGenerators
RID,
GodotDictionary,
GodotArray,
- IDictionary,
- ICollection,
- IEnumerable,
}
}
diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MarshalUtils.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MarshalUtils.cs
index d132b6304f..4300037796 100644
--- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MarshalUtils.cs
+++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MarshalUtils.cs
@@ -10,17 +10,6 @@ namespace Godot.SourceGenerators
public class TypeCache
{
public INamedTypeSymbol GodotObjectType { get; }
- public INamedTypeSymbol GodotGenericDictionary { get; }
- public INamedTypeSymbol GodotGenericArray { get; }
-
- // ReSharper disable once InconsistentNaming
- public INamedTypeSymbol IDictionary { get; }
-
- // ReSharper disable once InconsistentNaming
- public INamedTypeSymbol ICollection { get; }
- public INamedTypeSymbol GenericIDictionary { get; }
- public INamedTypeSymbol SystemGenericDictionary { get; }
- public INamedTypeSymbol SystemGenericList { get; }
public TypeCache(GeneratorExecutionContext context)
{
@@ -31,13 +20,6 @@ namespace Godot.SourceGenerators
}
GodotObjectType = GetTypeByMetadataNameOrThrow("Godot.Object");
- GodotGenericDictionary = GetTypeByMetadataNameOrThrow("Godot.Collections.Dictionary`2");
- GodotGenericArray = GetTypeByMetadataNameOrThrow("Godot.Collections.Array`1");
- IDictionary = GetTypeByMetadataNameOrThrow("System.Collections.IDictionary");
- ICollection = GetTypeByMetadataNameOrThrow("System.Collections.ICollection");
- GenericIDictionary = GetTypeByMetadataNameOrThrow("System.Collections.Generic.IDictionary`2");
- SystemGenericDictionary = GetTypeByMetadataNameOrThrow("System.Collections.Generic.Dictionary`2");
- SystemGenericList = GetTypeByMetadataNameOrThrow("System.Collections.Generic.List`1");
}
}
@@ -86,14 +68,9 @@ namespace Godot.SourceGenerators
MarshalType.Vector3Array => VariantType.PackedVector3Array,
MarshalType.ColorArray => VariantType.PackedColorArray,
MarshalType.GodotObjectOrDerivedArray => VariantType.Array,
- MarshalType.SystemArrayOfSupportedType => VariantType.Array,
- MarshalType.GodotGenericDictionary => VariantType.Dictionary,
- MarshalType.GodotGenericArray => VariantType.Array,
- MarshalType.SystemGenericDictionary => VariantType.Dictionary,
- MarshalType.SystemGenericList => VariantType.Array,
- MarshalType.GenericIDictionary => VariantType.Dictionary,
- MarshalType.GenericICollection => VariantType.Array,
- MarshalType.GenericIEnumerable => VariantType.Array,
+ MarshalType.SystemArrayOfStringName => VariantType.Array,
+ MarshalType.SystemArrayOfNodePath => VariantType.Array,
+ MarshalType.SystemArrayOfRID => VariantType.Array,
MarshalType.Variant => VariantType.Nil,
MarshalType.GodotObjectOrDerived => VariantType.Object,
MarshalType.StringName => VariantType.StringName,
@@ -101,9 +78,6 @@ namespace Godot.SourceGenerators
MarshalType.RID => VariantType.Rid,
MarshalType.GodotDictionary => VariantType.Dictionary,
MarshalType.GodotArray => VariantType.Array,
- MarshalType.IDictionary => VariantType.Dictionary,
- MarshalType.ICollection => VariantType.Array,
- MarshalType.IEnumerable => VariantType.Array,
_ => null
};
@@ -212,54 +186,22 @@ namespace Godot.SourceGenerators
return MarshalType.Vector3Array;
case { Name: "Color" }:
return MarshalType.ColorArray;
+ case { Name: "StringName" }:
+ return MarshalType.SystemArrayOfStringName;
+ case { Name: "NodePath" }:
+ return MarshalType.SystemArrayOfNodePath;
+ case { Name: "RID" }:
+ return MarshalType.SystemArrayOfRID;
}
}
- if (ConvertManagedTypeToMarshalType(elementType, typeCache) != null)
- return MarshalType.SystemArrayOfSupportedType;
-
return null;
}
- else if (type is INamedTypeSymbol { IsGenericType: true } genericType)
- {
- var genericTypeDef = genericType.ConstructedFrom;
-
- if (SymbolEqualityComparer.Default.Equals(genericTypeDef, typeCache.GodotGenericDictionary))
- return MarshalType.GodotGenericDictionary;
-
- if (SymbolEqualityComparer.Default.Equals(genericTypeDef, typeCache.GodotGenericArray))
- return MarshalType.GodotGenericArray;
-
- if (SymbolEqualityComparer.Default.Equals(genericTypeDef, typeCache.SystemGenericDictionary))
- return MarshalType.SystemGenericDictionary;
-
- if (SymbolEqualityComparer.Default.Equals(genericTypeDef, typeCache.SystemGenericList))
- return MarshalType.SystemGenericList;
-
- if (SymbolEqualityComparer.Default.Equals(genericTypeDef, typeCache.GenericIDictionary))
- return MarshalType.GenericIDictionary;
-
- return genericTypeDef.SpecialType switch
- {
- SpecialType.System_Collections_Generic_ICollection_T => MarshalType.GenericICollection,
- SpecialType.System_Collections_Generic_IEnumerable_T => MarshalType.GenericIEnumerable,
- _ => null
- };
- }
else
{
if (type.SimpleDerivesFrom(typeCache.GodotObjectType))
return MarshalType.GodotObjectOrDerived;
- if (SymbolEqualityComparer.Default.Equals(type, typeCache.IDictionary))
- return MarshalType.IDictionary;
-
- if (SymbolEqualityComparer.Default.Equals(type, typeCache.ICollection))
- return MarshalType.ICollection;
-
- if (specialType == SpecialType.System_Collections_IEnumerable)
- return MarshalType.IEnumerable;
-
if (type.ContainingAssembly.Name == "GodotSharp")
{
switch (type.ContainingNamespace.Name)
@@ -341,13 +283,9 @@ namespace Godot.SourceGenerators
string c, string d, string e, string f, string g)
=> source.Append(a).Append(b).Append(c).Append(d).Append(e).Append(f).Append(g);
- private static StringBuilder Append(this StringBuilder source, string a, string b,
- string c, string d, string e, string f, string g, string h)
- => source.Append(a).Append(b).Append(c).Append(d).Append(e).Append(f).Append(g).Append(h);
-
private const string VariantUtils = "global::Godot.NativeInterop.VariantUtils";
- public static StringBuilder AppendVariantToManagedExpr(this StringBuilder source,
+ public static StringBuilder AppendNativeVariantToManagedExpr(this StringBuilder source,
string inputExpr, ITypeSymbol typeSymbol, MarshalType marshalType)
{
return marshalType switch
@@ -438,30 +376,12 @@ namespace Godot.SourceGenerators
MarshalType.GodotObjectOrDerivedArray =>
source.Append(VariantUtils, ".ConvertToSystemArrayOfGodotObject<",
((IArrayTypeSymbol)typeSymbol).ElementType.FullQualifiedName(), ">(", inputExpr, ")"),
- MarshalType.SystemArrayOfSupportedType =>
- source.Append(VariantUtils, ".ConvertToSystemArrayOfSupportedType<",
- ((IArrayTypeSymbol)typeSymbol).ElementType.FullQualifiedName(), ">(", inputExpr, ")"),
- MarshalType.GodotGenericDictionary =>
- source.Append(VariantUtils, ".ConvertToGenericDictionaryObject<",
- ((INamedTypeSymbol)typeSymbol).TypeArguments[0].FullQualifiedName(), ", ",
- ((INamedTypeSymbol)typeSymbol).TypeArguments[1].FullQualifiedName(), ">(", inputExpr, ")"),
- MarshalType.GodotGenericArray =>
- source.Append(VariantUtils, ".ConvertToGenericArrayObject<",
- ((INamedTypeSymbol)typeSymbol).TypeArguments[0].FullQualifiedName(), ">(", inputExpr, ")"),
- MarshalType.SystemGenericDictionary =>
- source.Append(VariantUtils, ".ConvertToSystemGenericDictionary<",
- ((INamedTypeSymbol)typeSymbol).TypeArguments[0].FullQualifiedName(), ", ",
- ((INamedTypeSymbol)typeSymbol).TypeArguments[1].FullQualifiedName(), ">(", inputExpr, ")"),
- MarshalType.SystemGenericList =>
- source.Append(VariantUtils, ".ConvertToSystemGenericList<",
- ((INamedTypeSymbol)typeSymbol).TypeArguments[0].FullQualifiedName(), ">(", inputExpr, ")"),
- MarshalType.GenericIDictionary =>
- source.Append(VariantUtils, ".ConvertToGenericDictionaryObject<",
- ((INamedTypeSymbol)typeSymbol).TypeArguments[0].FullQualifiedName(), ", ",
- ((INamedTypeSymbol)typeSymbol).TypeArguments[1].FullQualifiedName(), ">(", inputExpr, ")"),
- MarshalType.GenericICollection or MarshalType.GenericIEnumerable =>
- source.Append(VariantUtils, ".ConvertToGenericArrayObject<",
- ((INamedTypeSymbol)typeSymbol).TypeArguments[0].FullQualifiedName(), ">(", inputExpr, ")"),
+ MarshalType.SystemArrayOfStringName =>
+ source.Append(VariantUtils, ".ConvertToSystemArrayOfStringName(", inputExpr, ")"),
+ MarshalType.SystemArrayOfNodePath =>
+ source.Append(VariantUtils, ".ConvertToSystemArrayOfNodePath(", inputExpr, ")"),
+ MarshalType.SystemArrayOfRID =>
+ source.Append(VariantUtils, ".ConvertToSystemArrayOfRID(", inputExpr, ")"),
MarshalType.Variant =>
source.Append("global::Godot.Variant.CreateCopyingBorrowed(", inputExpr, ")"),
MarshalType.GodotObjectOrDerived =>
@@ -477,16 +397,12 @@ namespace Godot.SourceGenerators
source.Append(VariantUtils, ".ConvertToDictionaryObject(", inputExpr, ")"),
MarshalType.GodotArray =>
source.Append(VariantUtils, ".ConvertToArrayObject(", inputExpr, ")"),
- MarshalType.IDictionary =>
- source.Append(VariantUtils, ".ConvertToDictionaryObject(", inputExpr, ")"),
- MarshalType.ICollection or MarshalType.IEnumerable =>
- source.Append(VariantUtils, ".ConvertToArrayObject(", inputExpr, ")"),
_ => throw new ArgumentOutOfRangeException(nameof(marshalType), marshalType,
"Received unexpected marshal type")
};
}
- public static StringBuilder AppendManagedToVariantExpr(
+ public static StringBuilder AppendManagedToNativeVariantExpr(
this StringBuilder source, string inputExpr, MarshalType marshalType)
{
return marshalType switch
@@ -575,22 +491,12 @@ namespace Godot.SourceGenerators
source.Append(VariantUtils, ".CreateFromPackedColorArray(", inputExpr, ")"),
MarshalType.GodotObjectOrDerivedArray =>
source.Append(VariantUtils, ".CreateFromSystemArrayOfGodotObject(", inputExpr, ")"),
- MarshalType.SystemArrayOfSupportedType =>
- source.Append(VariantUtils, ".CreateFromSystemArrayOfSupportedType(", inputExpr, ")"),
- MarshalType.GodotGenericDictionary =>
- source.Append(VariantUtils, ".CreateFromDictionary(", inputExpr, ")"),
- MarshalType.GodotGenericArray =>
- source.Append(VariantUtils, ".CreateFromArray(", inputExpr, ")"),
- MarshalType.SystemGenericDictionary =>
- source.Append(VariantUtils, ".CreateFromSystemDictionary(", inputExpr, ")"),
- MarshalType.SystemGenericList =>
- source.Append(VariantUtils, ".CreateFromSystemICollection(", inputExpr, ")"),
- MarshalType.GenericIDictionary =>
- source.Append(VariantUtils, ".CreateFromSystemGenericIDictionary(", inputExpr, ")"),
- MarshalType.GenericICollection =>
- source.Append(VariantUtils, ".CreateFromSystemGenericICollection(", inputExpr, ")"),
- MarshalType.GenericIEnumerable =>
- source.Append(VariantUtils, ".CreateFromSystemGenericIEnumerable(", inputExpr, ")"),
+ MarshalType.SystemArrayOfStringName =>
+ source.Append(VariantUtils, ".CreateFromSystemArrayOfStringName(", inputExpr, ")"),
+ MarshalType.SystemArrayOfNodePath =>
+ source.Append(VariantUtils, ".CreateFromSystemArrayOfNodePath(", inputExpr, ")"),
+ MarshalType.SystemArrayOfRID =>
+ source.Append(VariantUtils, ".CreateFromSystemArrayOfRID(", inputExpr, ")"),
MarshalType.Variant =>
source.Append(inputExpr, ".CopyNativeVariant()"),
MarshalType.GodotObjectOrDerived =>
@@ -605,15 +511,140 @@ namespace Godot.SourceGenerators
source.Append(VariantUtils, ".CreateFromDictionary(", inputExpr, ")"),
MarshalType.GodotArray =>
source.Append(VariantUtils, ".CreateFromArray(", inputExpr, ")"),
- MarshalType.IDictionary =>
- source.Append(VariantUtils, ".CreateFromSystemIDictionary(", inputExpr, ")"),
- MarshalType.ICollection =>
- source.Append(VariantUtils, ".CreateFromSystemICollection(", inputExpr, ")"),
- MarshalType.IEnumerable =>
- source.Append(VariantUtils, ".CreateFromSystemIEnumerable(", inputExpr, ")"),
_ => throw new ArgumentOutOfRangeException(nameof(marshalType), marshalType,
"Received unexpected marshal type")
};
}
+
+ public static StringBuilder AppendVariantToManagedExpr(this StringBuilder source,
+ string inputExpr, ITypeSymbol typeSymbol, MarshalType marshalType)
+ {
+ return marshalType switch
+ {
+ MarshalType.Boolean => source.Append(inputExpr, ".AsBool()"),
+ MarshalType.Char => source.Append(inputExpr, ".AsChar()"),
+ MarshalType.SByte => source.Append(inputExpr, ".AsSByte()"),
+ MarshalType.Int16 => source.Append(inputExpr, ".AsInt16()"),
+ MarshalType.Int32 => source.Append(inputExpr, ".AsInt32()"),
+ MarshalType.Int64 => source.Append(inputExpr, ".AsInt64()"),
+ MarshalType.Byte => source.Append(inputExpr, ".AsByte()"),
+ MarshalType.UInt16 => source.Append(inputExpr, ".AsUInt16()"),
+ MarshalType.UInt32 => source.Append(inputExpr, ".AsUInt32()"),
+ MarshalType.UInt64 => source.Append(inputExpr, ".AsUInt64()"),
+ MarshalType.Single => source.Append(inputExpr, ".AsSingle()"),
+ MarshalType.Double => source.Append(inputExpr, ".AsDouble()"),
+ MarshalType.String => source.Append(inputExpr, ".AsString()"),
+ MarshalType.Vector2 => source.Append(inputExpr, ".AsVector2()"),
+ MarshalType.Vector2i => source.Append(inputExpr, ".AsVector2i()"),
+ MarshalType.Rect2 => source.Append(inputExpr, ".AsRect2()"),
+ MarshalType.Rect2i => source.Append(inputExpr, ".AsRect2i()"),
+ MarshalType.Transform2D => source.Append(inputExpr, ".AsTransform2D()"),
+ MarshalType.Vector3 => source.Append(inputExpr, ".AsVector3()"),
+ MarshalType.Vector3i => source.Append(inputExpr, ".AsVector3i()"),
+ MarshalType.Basis => source.Append(inputExpr, ".AsBasis()"),
+ MarshalType.Quaternion => source.Append(inputExpr, ".AsQuaternion()"),
+ MarshalType.Transform3D => source.Append(inputExpr, ".AsTransform3D()"),
+ MarshalType.Vector4 => source.Append(inputExpr, ".AsVector4()"),
+ MarshalType.Vector4i => source.Append(inputExpr, ".AsVector4i()"),
+ MarshalType.Projection => source.Append(inputExpr, ".AsProjection()"),
+ MarshalType.AABB => source.Append(inputExpr, ".AsAABB()"),
+ MarshalType.Color => source.Append(inputExpr, ".AsColor()"),
+ MarshalType.Plane => source.Append(inputExpr, ".AsPlane()"),
+ MarshalType.Callable => source.Append(inputExpr, ".AsCallable()"),
+ MarshalType.SignalInfo => source.Append(inputExpr, ".AsSignalInfo()"),
+ MarshalType.Enum =>
+ source.Append("(", typeSymbol.FullQualifiedName(), ")", inputExpr, ".AsInt64()"),
+ MarshalType.ByteArray => source.Append(inputExpr, ".AsByteArray()"),
+ MarshalType.Int32Array => source.Append(inputExpr, ".AsInt32Array()"),
+ MarshalType.Int64Array => source.Append(inputExpr, ".AsInt64Array()"),
+ MarshalType.Float32Array => source.Append(inputExpr, ".AsFloat32Array()"),
+ MarshalType.Float64Array => source.Append(inputExpr, ".AsFloat64Array()"),
+ MarshalType.StringArray => source.Append(inputExpr, ".AsStringArray()"),
+ MarshalType.Vector2Array => source.Append(inputExpr, ".AsVector2Array()"),
+ MarshalType.Vector3Array => source.Append(inputExpr, ".AsVector3Array()"),
+ MarshalType.ColorArray => source.Append(inputExpr, ".AsColorArray()"),
+ MarshalType.GodotObjectOrDerivedArray => source.Append(inputExpr, ".AsGodotObjectArray<",
+ ((IArrayTypeSymbol)typeSymbol).ElementType.FullQualifiedName(), ">()"),
+ MarshalType.SystemArrayOfStringName => source.Append(inputExpr, ".AsSystemArrayOfStringName()"),
+ MarshalType.SystemArrayOfNodePath => source.Append(inputExpr, ".AsSystemArrayOfNodePath()"),
+ MarshalType.SystemArrayOfRID => source.Append(inputExpr, ".AsSystemArrayOfRID()"),
+ MarshalType.Variant => source.Append(inputExpr),
+ MarshalType.GodotObjectOrDerived => source.Append("(",
+ typeSymbol.FullQualifiedName(), ")", inputExpr, ".AsGodotObject()"),
+ MarshalType.StringName => source.Append(inputExpr, ".AsStringName()"),
+ MarshalType.NodePath => source.Append(inputExpr, ".AsNodePath()"),
+ MarshalType.RID => source.Append(inputExpr, ".AsRID()"),
+ MarshalType.GodotDictionary => source.Append(inputExpr, ".AsGodotDictionary()"),
+ MarshalType.GodotArray => source.Append(inputExpr, ".AsGodotArray()"),
+ _ => throw new ArgumentOutOfRangeException(nameof(marshalType), marshalType,
+ "Received unexpected marshal type")
+ };
+ }
+
+ public static StringBuilder AppendManagedToVariantExpr(this StringBuilder source,
+ string inputExpr, MarshalType marshalType)
+ {
+ switch (marshalType)
+ {
+ case MarshalType.Boolean:
+ case MarshalType.Char:
+ case MarshalType.SByte:
+ case MarshalType.Int16:
+ case MarshalType.Int32:
+ case MarshalType.Int64:
+ case MarshalType.Byte:
+ case MarshalType.UInt16:
+ case MarshalType.UInt32:
+ case MarshalType.UInt64:
+ case MarshalType.Single:
+ case MarshalType.Double:
+ case MarshalType.String:
+ case MarshalType.Vector2:
+ case MarshalType.Vector2i:
+ case MarshalType.Rect2:
+ case MarshalType.Rect2i:
+ case MarshalType.Transform2D:
+ case MarshalType.Vector3:
+ case MarshalType.Vector3i:
+ case MarshalType.Basis:
+ case MarshalType.Quaternion:
+ case MarshalType.Transform3D:
+ case MarshalType.Vector4:
+ case MarshalType.Vector4i:
+ case MarshalType.Projection:
+ case MarshalType.AABB:
+ case MarshalType.Color:
+ case MarshalType.Plane:
+ case MarshalType.Callable:
+ case MarshalType.SignalInfo:
+ case MarshalType.ByteArray:
+ case MarshalType.Int32Array:
+ case MarshalType.Int64Array:
+ case MarshalType.Float32Array:
+ case MarshalType.Float64Array:
+ case MarshalType.StringArray:
+ case MarshalType.Vector2Array:
+ case MarshalType.Vector3Array:
+ case MarshalType.ColorArray:
+ case MarshalType.GodotObjectOrDerivedArray:
+ case MarshalType.SystemArrayOfStringName:
+ case MarshalType.SystemArrayOfNodePath:
+ case MarshalType.SystemArrayOfRID:
+ case MarshalType.GodotObjectOrDerived:
+ case MarshalType.StringName:
+ case MarshalType.NodePath:
+ case MarshalType.RID:
+ case MarshalType.GodotDictionary:
+ case MarshalType.GodotArray:
+ return source.Append("Variant.CreateFrom(", inputExpr, ")");
+ case MarshalType.Enum:
+ return source.Append("Variant.CreateFrom((long)", inputExpr, ")");
+ case MarshalType.Variant:
+ return source.Append(inputExpr);
+ default:
+ throw new ArgumentOutOfRangeException(nameof(marshalType), marshalType,
+ "Received unexpected marshal type");
+ }
+ }
}
}
diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptMethodsGenerator.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptMethodsGenerator.cs
index 8ee9489fe2..1fdc04a262 100644
--- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptMethodsGenerator.cs
+++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptMethodsGenerator.cs
@@ -381,7 +381,7 @@ namespace Godot.SourceGenerators
if (i != 0)
source.Append(", ");
- source.AppendVariantToManagedExpr(string.Concat("args[", i.ToString(), "]"),
+ source.AppendNativeVariantToManagedExpr(string.Concat("args[", i.ToString(), "]"),
method.ParamTypeSymbols[i], method.ParamTypes[i]);
}
@@ -391,7 +391,7 @@ namespace Godot.SourceGenerators
{
source.Append(" ret = ");
- source.AppendManagedToVariantExpr("callRet", method.RetType.Value);
+ source.AppendManagedToNativeVariantExpr("callRet", method.RetType.Value);
source.Append(";\n");
source.Append(" return true;\n");
diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertiesGenerator.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertiesGenerator.cs
index 29a15e2d16..12a369fd72 100644
--- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertiesGenerator.cs
+++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertiesGenerator.cs
@@ -293,7 +293,7 @@ namespace Godot.SourceGenerators
.Append(" ")
.Append(propertyMemberName)
.Append(" = ")
- .AppendVariantToManagedExpr("value", propertyTypeSymbol, propertyMarshalType)
+ .AppendNativeVariantToManagedExpr("value", propertyTypeSymbol, propertyMarshalType)
.Append(";\n")
.Append(" return true;\n")
.Append(" }\n");
@@ -315,7 +315,7 @@ namespace Godot.SourceGenerators
.Append(propertyMemberName)
.Append(") {\n")
.Append(" value = ")
- .AppendManagedToVariantExpr(propertyMemberName, propertyMarshalType)
+ .AppendManagedToNativeVariantExpr(propertyMemberName, propertyMarshalType)
.Append(";\n")
.Append(" return true;\n")
.Append(" }\n");
diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSerializationGenerator.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSerializationGenerator.cs
index 224a2d0a50..1b87c6e760 100644
--- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSerializationGenerator.cs
+++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSerializationGenerator.cs
@@ -160,8 +160,8 @@ namespace Godot.SourceGenerators
source.Append(" info.AddProperty(GodotInternal.PropName_")
.Append(propertyName)
- .Append(", this.")
- .Append(propertyName)
+ .Append(", ")
+ .AppendManagedToVariantExpr(string.Concat("this.", propertyName), property.Type)
.Append(");\n");
}
@@ -173,8 +173,8 @@ namespace Godot.SourceGenerators
source.Append(" info.AddProperty(GodotInternal.PropName_")
.Append(fieldName)
- .Append(", this.")
- .Append(fieldName)
+ .Append(", ")
+ .AppendManagedToVariantExpr(string.Concat("this.", fieldName), field.Type)
.Append(");\n");
}
@@ -202,19 +202,17 @@ namespace Godot.SourceGenerators
foreach (var property in godotClassProperties)
{
string propertyName = property.PropertySymbol.Name;
- string propertyTypeQualifiedName = property.PropertySymbol.Type.FullQualifiedName();
- source.Append(" if (info.TryGetProperty<")
- .Append(propertyTypeQualifiedName)
- .Append(">(GodotInternal.PropName_")
+ source.Append(" if (info.TryGetProperty(GodotInternal.PropName_")
.Append(propertyName)
.Append(", out var _value_")
.Append(propertyName)
.Append("))\n")
.Append(" this.")
.Append(propertyName)
- .Append(" = _value_")
- .Append(propertyName)
+ .Append(" = ")
+ .AppendVariantToManagedExpr(string.Concat("_value_", propertyName),
+ property.PropertySymbol.Type, property.Type)
.Append(";\n");
}
@@ -223,19 +221,17 @@ namespace Godot.SourceGenerators
foreach (var field in godotClassFields)
{
string fieldName = field.FieldSymbol.Name;
- string fieldTypeQualifiedName = field.FieldSymbol.Type.FullQualifiedName();
- source.Append(" if (info.TryGetProperty<")
- .Append(fieldTypeQualifiedName)
- .Append(">(GodotInternal.PropName_")
+ source.Append(" if (info.TryGetProperty(GodotInternal.PropName_")
.Append(fieldName)
.Append(", out var _value_")
.Append(fieldName)
.Append("))\n")
.Append(" this.")
.Append(fieldName)
- .Append(" = _value_")
- .Append(fieldName)
+ .Append(" = ")
+ .AppendVariantToManagedExpr(string.Concat("_value_", fieldName),
+ field.FieldSymbol.Type, field.Type)
.Append(";\n");
}
diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs
index 10f4ddd149..536ddb02f8 100644
--- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs
+++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs
@@ -397,7 +397,7 @@ namespace Godot.SourceGenerators
if (i != 0)
source.Append(", ");
- source.AppendVariantToManagedExpr(string.Concat("args[", i.ToString(), "]"),
+ source.AppendNativeVariantToManagedExpr(string.Concat("args[", i.ToString(), "]"),
invokeMethodData.ParamTypeSymbols[i], invokeMethodData.ParamTypes[i]);
}
diff --git a/modules/mono/editor/GodotTools/GodotTools/Build/BuildInfo.cs b/modules/mono/editor/GodotTools/GodotTools/Build/BuildInfo.cs
index f8a810fd44..3c5b897719 100644
--- a/modules/mono/editor/GodotTools/GodotTools/Build/BuildInfo.cs
+++ b/modules/mono/editor/GodotTools/GodotTools/Build/BuildInfo.cs
@@ -20,7 +20,7 @@ namespace GodotTools.Build
public bool OnlyClean { get; private set; }
// TODO Use List once we have proper serialization
- public Array<string> CustomProperties { get; private set; } = new Array<string>();
+ public Godot.Collections.Array CustomProperties { get; private set; } = new();
public string LogsDirPath =>
Path.Combine(GodotSharpDirs.BuildLogsDirs, $"{Solution.MD5Text()}_{Configuration}");
diff --git a/modules/mono/editor/GodotTools/GodotTools/Build/BuildOutputView.cs b/modules/mono/editor/GodotTools/GodotTools/Build/BuildOutputView.cs
index 38d2eefd02..a8128be909 100644
--- a/modules/mono/editor/GodotTools/GodotTools/Build/BuildOutputView.cs
+++ b/modules/mono/editor/GodotTools/GodotTools/Build/BuildOutputView.cs
@@ -1,7 +1,6 @@
using Godot;
using System;
using System.Diagnostics.CodeAnalysis;
-using Godot.Collections;
using GodotTools.Internals;
using File = GodotTools.Utils.File;
using Path = System.IO.Path;
@@ -59,7 +58,7 @@ namespace GodotTools.Build
}
// TODO Use List once we have proper serialization.
- private Array<BuildIssue> _issues = new Array<BuildIssue>();
+ private Godot.Collections.Array _issues = new();
private ItemList _issuesList;
private PopupMenu _issuesListContextMenu;
private TextEdit _buildLog;
@@ -129,12 +128,12 @@ namespace GodotTools.Build
if (issueIndex < 0 || issueIndex >= _issues.Count)
throw new IndexOutOfRangeException("Issue index out of range");
- BuildIssue issue = _issues[issueIndex];
+ var issue = (BuildIssue)_issues[issueIndex];
if (string.IsNullOrEmpty(issue.ProjectFile) && string.IsNullOrEmpty(issue.File))
return;
- string projectDir = issue.ProjectFile.Length > 0 ?
+ string projectDir = !string.IsNullOrEmpty(issue.ProjectFile) ?
issue.ProjectFile.GetBaseDir() :
_buildInfo.Solution.GetBaseDir();
@@ -163,7 +162,7 @@ namespace GodotTools.Build
{
for (int i = 0; i < _issues.Count; i++)
{
- BuildIssue issue = _issues[i];
+ var issue = (BuildIssue)_issues[i];
if (!(issue.Warning ? WarningsVisible : ErrorsVisible))
continue;
diff --git a/modules/mono/editor/GodotTools/GodotTools/Build/BuildSystem.cs b/modules/mono/editor/GodotTools/GodotTools/Build/BuildSystem.cs
index 506c0ec067..655be0ab5e 100644
--- a/modules/mono/editor/GodotTools/GodotTools/Build/BuildSystem.cs
+++ b/modules/mono/editor/GodotTools/GodotTools/Build/BuildSystem.cs
@@ -4,6 +4,7 @@ using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Diagnostics;
using System.IO;
+using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GodotTools.BuildLogger;
@@ -156,9 +157,9 @@ namespace GodotTools.Build
AddLoggerArgument(buildInfo, arguments);
// Custom properties
- foreach (string customProperty in buildInfo.CustomProperties)
+ foreach (var customProperty in buildInfo.CustomProperties)
{
- arguments.Add("-p:" + customProperty);
+ arguments.Add("-p:" + (string)customProperty);
}
}
@@ -198,9 +199,9 @@ namespace GodotTools.Build
AddLoggerArgument(buildInfo, arguments);
// Custom properties
- foreach (string customProperty in buildInfo.CustomProperties)
+ foreach (var customProperty in buildInfo.CustomProperties)
{
- arguments.Add("-p:" + customProperty);
+ arguments.Add("-p:" + (string)customProperty);
}
// Publish output directory
diff --git a/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs b/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs
index 362bb18b36..dcc3f3db76 100644
--- a/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs
+++ b/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs
@@ -481,9 +481,9 @@ namespace GodotTools
_editorSettings.AddPropertyInfo(new Godot.Collections.Dictionary
{
- ["type"] = Variant.Type.Int,
+ ["type"] = (int)Variant.Type.Int,
["name"] = "mono/editor/external_editor",
- ["hint"] = PropertyHint.Enum,
+ ["hint"] = (int)PropertyHint.Enum,
["hint_string"] = settingsHintStr
});
diff --git a/modules/mono/editor/GodotTools/GodotTools/Ides/Rider/RiderPathManager.cs b/modules/mono/editor/GodotTools/GodotTools/Ides/Rider/RiderPathManager.cs
index a62fe29e7e..60602a5847 100644
--- a/modules/mono/editor/GodotTools/GodotTools/Ides/Rider/RiderPathManager.cs
+++ b/modules/mono/editor/GodotTools/GodotTools/Ides/Rider/RiderPathManager.cs
@@ -30,9 +30,9 @@ namespace GodotTools.Ides.Rider
Globals.EditorDef(EditorPathSettingName, "Optional");
editorSettings.AddPropertyInfo(new Godot.Collections.Dictionary
{
- ["type"] = Variant.Type.String,
+ ["type"] = (int)Variant.Type.String,
["name"] = EditorPathSettingName,
- ["hint"] = PropertyHint.File,
+ ["hint"] = (int)PropertyHint.File,
["hint_string"] = ""
});
}
diff --git a/modules/mono/editor/bindings_generator.cpp b/modules/mono/editor/bindings_generator.cpp
index 50820c6384..b879c95fa1 100644
--- a/modules/mono/editor/bindings_generator.cpp
+++ b/modules/mono/editor/bindings_generator.cpp
@@ -1664,8 +1664,7 @@ Error BindingsGenerator::_generate_cs_type(const TypeInterface &itype, const Str
if (arg_type->cname == name_cache.type_Array_generic || arg_type->cname == name_cache.type_Dictionary_generic) {
String arg_cs_type = arg_type->cs_type + _get_generic_type_parameters(*arg_type, iarg.type.generic_type_parameters);
- output << "new " << arg_cs_type << "(" << sformat(arg_type->cs_variant_to_managed,
- "args[" + itos(i) + "]", arg_type->cs_type, arg_type->name) << ")";
+ output << "new " << arg_cs_type << "(" << sformat(arg_type->cs_variant_to_managed, "args[" + itos(i) + "]", arg_type->cs_type, arg_type->name) << ")";
} else {
output << sformat(arg_type->cs_variant_to_managed,
"args[" + itos(i) + "]", arg_type->cs_type, arg_type->name);
@@ -2892,8 +2891,13 @@ bool BindingsGenerator::_populate_object_type_interfaces() {
String() + "Return type is reference but hint is not '" _STR(PROPERTY_HINT_RESOURCE_TYPE) "'." +
" Are you returning a reference type by pointer? Method: '" + itype.name + "." + imethod.name + "'.");
} else if (return_info.type == Variant::ARRAY && return_info.hint == PROPERTY_HINT_ARRAY_TYPE) {
+// TODO: Enable once generic Array is re-implemented
+#if 0
imethod.return_type.cname = Variant::get_type_name(return_info.type) + "_@generic";
imethod.return_type.generic_type_parameters.push_back(TypeReference(return_info.hint_string));
+#else
+ imethod.return_type.cname = Variant::get_type_name(return_info.type);
+#endif
} else if (return_info.hint == PROPERTY_HINT_RESOURCE_TYPE) {
imethod.return_type.cname = return_info.hint_string;
} else if (return_info.type == Variant::NIL && return_info.usage & PROPERTY_USAGE_NIL_IS_VARIANT) {
@@ -2924,8 +2928,13 @@ bool BindingsGenerator::_populate_object_type_interfaces() {
} else if (arginfo.class_name != StringName()) {
iarg.type.cname = arginfo.class_name;
} else if (arginfo.type == Variant::ARRAY && arginfo.hint == PROPERTY_HINT_ARRAY_TYPE) {
+// TODO: Enable once generic Array is re-implemented
+#if 0
iarg.type.cname = Variant::get_type_name(arginfo.type) + "_@generic";
iarg.type.generic_type_parameters.push_back(TypeReference(arginfo.hint_string));
+#else
+ iarg.type.cname = Variant::get_type_name(arginfo.type);
+#endif
} else if (arginfo.hint == PROPERTY_HINT_RESOURCE_TYPE) {
iarg.type.cname = arginfo.hint_string;
} else if (arginfo.type == Variant::NIL) {
@@ -3032,8 +3041,13 @@ bool BindingsGenerator::_populate_object_type_interfaces() {
} else if (arginfo.class_name != StringName()) {
iarg.type.cname = arginfo.class_name;
} else if (arginfo.type == Variant::ARRAY && arginfo.hint == PROPERTY_HINT_ARRAY_TYPE) {
+// TODO: Enable once generic Array is re-implemented
+#if 0
iarg.type.cname = Variant::get_type_name(arginfo.type) + "_@generic";
iarg.type.generic_type_parameters.push_back(TypeReference(arginfo.hint_string));
+#else
+ iarg.type.cname = Variant::get_type_name(arginfo.type);
+#endif
} else if (arginfo.hint == PROPERTY_HINT_RESOURCE_TYPE) {
iarg.type.cname = arginfo.hint_string;
} else if (arginfo.type == Variant::NIL) {