From 6268b1c3c8be7dc5a28290ea52f3c5e5ebec73ab Mon Sep 17 00:00:00 2001 From: Deadlocklogic Date: Sun, 3 Dec 2023 03:51:05 +0200 Subject: [PATCH] TypeMap: prepare refactoring into a modular design --- src/Generator/Generators/QuickJS/QuickJSMarshal.cs | 14 +++++++------- src/Generator/Types/TypeMap.cs | 9 ++++++--- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/Generator/Generators/QuickJS/QuickJSMarshal.cs b/src/Generator/Generators/QuickJS/QuickJSMarshal.cs index 5de2ad04..4937192b 100644 --- a/src/Generator/Generators/QuickJS/QuickJSMarshal.cs +++ b/src/Generator/Generators/QuickJS/QuickJSMarshal.cs @@ -25,7 +25,7 @@ namespace CppSharp.Generators.Cpp TypeMap typeMap; if (Context.Context.TypeMaps.FindTypeMap(type, out typeMap) && typeMap.DoesMarshalling) { - typeMap.MarshalToManaged(GeneratorKind.QuickJS, Context); + typeMap.MarshalToManaged(Context); return false; } @@ -210,7 +210,7 @@ namespace CppSharp.Generators.Cpp typeMap.DoesMarshalling) { typeMap.Type = typedef; - typeMap.MarshalToManaged(GeneratorKind.QuickJS, Context); + typeMap.MarshalToManaged(Context); return typeMap.IsValueType; } @@ -232,7 +232,7 @@ namespace CppSharp.Generators.Cpp if (Context.Context.TypeMaps.FindTypeMap(template, out typeMap) && typeMap.DoesMarshalling) { typeMap.Type = template; - typeMap.MarshalToManaged(GeneratorKind.QuickJS, Context); + typeMap.MarshalToManaged(Context); return true; } @@ -385,7 +385,7 @@ namespace CppSharp.Generators.Cpp TypeMap typeMap; if (Context.Context.TypeMaps.FindTypeMap(type, out typeMap) && typeMap.DoesMarshalling) { - typeMap.MarshalToNative(GeneratorKind.QuickJS, Context); + typeMap.MarshalToNative(Context); return false; } @@ -583,7 +583,7 @@ namespace CppSharp.Generators.Cpp if (Context.Context.TypeMaps.FindTypeMap(decl.Type, out typeMap) && typeMap.DoesMarshalling) { - typeMap.MarshalToNative(GeneratorKind.QuickJS, Context); + typeMap.MarshalToNative(Context); return typeMap.IsValueType; } @@ -625,7 +625,7 @@ namespace CppSharp.Generators.Cpp if (Context.Context.TypeMaps.FindTypeMap(template, out typeMap) && typeMap.DoesMarshalling) { typeMap.Type = template; - typeMap.MarshalToNative(GeneratorKind.QuickJS, Context); + typeMap.MarshalToNative(Context); return true; } @@ -672,7 +672,7 @@ namespace CppSharp.Generators.Cpp if (Context.Context.TypeMaps.FindTypeMap(type, out typeMap) && typeMap.DoesMarshalling) { - typeMap.MarshalToNative(GeneratorKind.QuickJS, Context); + typeMap.MarshalToNative(Context); return; } diff --git a/src/Generator/Types/TypeMap.cs b/src/Generator/Types/TypeMap.cs index e7060192..7834552c 100644 --- a/src/Generator/Types/TypeMap.cs +++ b/src/Generator/Types/TypeMap.cs @@ -51,8 +51,9 @@ namespace CppSharp.Types /// public virtual bool DoesMarshalling => true; - public virtual Type SignatureType(GeneratorKind kind, TypePrinterContext ctx) + public virtual Type SignatureType(TypePrinterContext ctx, GeneratorKind kind = null) { + kind ??= Context.Options.GeneratorKind; switch (kind) { case var _ when ReferenceEquals(kind, GeneratorKind.C): @@ -67,8 +68,9 @@ namespace CppSharp.Types } } - public virtual void MarshalToNative(GeneratorKind kind, MarshalContext ctx) + public virtual void MarshalToNative(MarshalContext ctx, GeneratorKind kind = null) { + kind ??= Context.Options.GeneratorKind; switch (kind) { case var _ when ReferenceEquals(kind, GeneratorKind.C): @@ -86,8 +88,9 @@ namespace CppSharp.Types } } - public virtual void MarshalToManaged(GeneratorKind kind, MarshalContext ctx) + public virtual void MarshalToManaged(MarshalContext ctx, GeneratorKind kind = null) { + kind ??= Context.Options.GeneratorKind; switch (kind) { case var _ when ReferenceEquals(kind, GeneratorKind.C):