mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-11-04 12:51:48 +00:00
A bit of cleanup in the ScriptGlue generator
This commit is contained in:
@@ -9,8 +9,11 @@ using System.Text.Json;
|
|||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
|
using Microsoft.CodeAnalysis.CSharp;
|
||||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||||
|
|
||||||
|
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
|
||||||
|
|
||||||
namespace ScriptCoreGenerator;
|
namespace ScriptCoreGenerator;
|
||||||
|
|
||||||
internal class GlueMethod
|
internal class GlueMethod
|
||||||
@@ -386,13 +389,8 @@ public class ScriptGlueGenerator : IIncrementalGenerator
|
|||||||
|
|
||||||
call.Append($"&{tmpArgName}");
|
call.Append($"&{tmpArgName}");
|
||||||
|
|
||||||
parameterConversions.Add($"\t\t{parameterType.CSharpTypeName} {tmpArgName} = default;\n");
|
parameterConversions.Add($"{parameterType.CSharpTypeName} {tmpArgName} = default;");
|
||||||
|
cleanups.Add(string.Format(parameterType.WrapperOutConversion, tmpArgName, param.Name));
|
||||||
StringBuilder cleanup = new();
|
|
||||||
cleanup.Append("\t\t");
|
|
||||||
cleanup.AppendFormat(parameterType.WrapperOutConversion, tmpArgName, param.Name);
|
|
||||||
cleanup.AppendLine();
|
|
||||||
cleanups.Add(cleanup.ToString());
|
|
||||||
}
|
}
|
||||||
else if (parameterType.WrapperConvertInput is not null)
|
else if (parameterType.WrapperConvertInput is not null)
|
||||||
{
|
{
|
||||||
@@ -434,9 +432,9 @@ public class ScriptGlueGenerator : IIncrementalGenerator
|
|||||||
case TypeModifier.In:
|
case TypeModifier.In:
|
||||||
case TypeModifier.Out:
|
case TypeModifier.Out:
|
||||||
case TypeModifier.Ref:
|
case TypeModifier.Ref:
|
||||||
paramName = "__fixed" + param.Name;
|
paramName = "__" + param.Name + "FixedPtr";
|
||||||
parameterConversions.Add($"\t\tfixed ({parameterType.CSharpTypeName}* {paramName} = &{param.Name}) {{");
|
parameterConversions.Add($"fixed ({parameterType.CSharpTypeName}* {paramName} = &{param.Name}) {{");
|
||||||
afterReturnCleanups.Add("\t\t}");
|
afterReturnCleanups.Add("}");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -446,18 +444,16 @@ public class ScriptGlueGenerator : IIncrementalGenerator
|
|||||||
|
|
||||||
call.Append(");");
|
call.Append(");");
|
||||||
|
|
||||||
cleanups.Reverse();
|
output.AppendLine(
|
||||||
|
$$"""
|
||||||
output.AppendLine($$"""
|
|
||||||
public static {{returnType.CSharpWrapperType}} {{method.Name}}({{parameterText}})
|
public static {{returnType.CSharpWrapperType}} {{method.Name}}({{parameterText}})
|
||||||
{
|
{
|
||||||
{{string.Join("\n", parameterConversions)}}
|
{{string.Join("\n", parameterConversions)}}
|
||||||
{{call}}
|
{{call}}
|
||||||
{{string.Join("\n", cleanups)}}
|
{{string.Join("\n", Enumerable.Reverse(cleanups))}}
|
||||||
{{returnType.ReturnValueConversion}}
|
{{returnType.ReturnValueConversion}}
|
||||||
{{string.Join("\n", afterReturnCleanups)}}
|
{{string.Join("\n", afterReturnCleanups)}}
|
||||||
}
|
}
|
||||||
|
|
||||||
""");
|
""");
|
||||||
|
|
||||||
|
|
||||||
@@ -502,6 +498,7 @@ public class ScriptGlueGenerator : IIncrementalGenerator
|
|||||||
|
|
||||||
unsafe internal partial struct EngineFunctions
|
unsafe internal partial struct EngineFunctions
|
||||||
{
|
{
|
||||||
|
|
||||||
""");
|
""");
|
||||||
|
|
||||||
wrappers.Append("""
|
wrappers.Append("""
|
||||||
@@ -515,6 +512,7 @@ public class ScriptGlueGenerator : IIncrementalGenerator
|
|||||||
|
|
||||||
internal static unsafe partial class ScriptGlue
|
internal static unsafe partial class ScriptGlue
|
||||||
{
|
{
|
||||||
|
|
||||||
""");
|
""");
|
||||||
|
|
||||||
List<GlueMethod> methods = new List<GlueMethod>();
|
List<GlueMethod> methods = new List<GlueMethod>();
|
||||||
@@ -537,11 +535,13 @@ public class ScriptGlueGenerator : IIncrementalGenerator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
engineFunctions.Append("\n}");
|
engineFunctions.Append("}");
|
||||||
wrappers.Append("\n}");
|
wrappers.Append("\n}");
|
||||||
|
|
||||||
|
var parsedWrappers = ParseCompilationUnit(wrappers.ToString());
|
||||||
|
|
||||||
context.AddSource("EngineFunctions.g.cs", engineFunctions.ToString());
|
context.AddSource("EngineFunctions.g.cs", engineFunctions.ToString());
|
||||||
context.AddSource("ScriptGlue.g.cs", wrappers.ToString());
|
context.AddSource("ScriptGlue.g.cs", parsedWrappers.NormalizeWhitespace().ToFullString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool IsScriptGlueClass(
|
private static bool IsScriptGlueClass(
|
||||||
|
|||||||
Reference in New Issue
Block a user