Browse Source

TypeMap: prepare refactoring into a modular design

pull/1802/head
Deadlocklogic 3 years ago
parent
commit
6268b1c3c8
  1. 14
      src/Generator/Generators/QuickJS/QuickJSMarshal.cs
  2. 9
      src/Generator/Types/TypeMap.cs

14
src/Generator/Generators/QuickJS/QuickJSMarshal.cs

@ -25,7 +25,7 @@ namespace CppSharp.Generators.Cpp
TypeMap typeMap; TypeMap typeMap;
if (Context.Context.TypeMaps.FindTypeMap(type, out typeMap) && typeMap.DoesMarshalling) if (Context.Context.TypeMaps.FindTypeMap(type, out typeMap) && typeMap.DoesMarshalling)
{ {
typeMap.MarshalToManaged(GeneratorKind.QuickJS, Context); typeMap.MarshalToManaged(Context);
return false; return false;
} }
@ -210,7 +210,7 @@ namespace CppSharp.Generators.Cpp
typeMap.DoesMarshalling) typeMap.DoesMarshalling)
{ {
typeMap.Type = typedef; typeMap.Type = typedef;
typeMap.MarshalToManaged(GeneratorKind.QuickJS, Context); typeMap.MarshalToManaged(Context);
return typeMap.IsValueType; return typeMap.IsValueType;
} }
@ -232,7 +232,7 @@ namespace CppSharp.Generators.Cpp
if (Context.Context.TypeMaps.FindTypeMap(template, out typeMap) && typeMap.DoesMarshalling) if (Context.Context.TypeMaps.FindTypeMap(template, out typeMap) && typeMap.DoesMarshalling)
{ {
typeMap.Type = template; typeMap.Type = template;
typeMap.MarshalToManaged(GeneratorKind.QuickJS, Context); typeMap.MarshalToManaged(Context);
return true; return true;
} }
@ -385,7 +385,7 @@ namespace CppSharp.Generators.Cpp
TypeMap typeMap; TypeMap typeMap;
if (Context.Context.TypeMaps.FindTypeMap(type, out typeMap) && typeMap.DoesMarshalling) if (Context.Context.TypeMaps.FindTypeMap(type, out typeMap) && typeMap.DoesMarshalling)
{ {
typeMap.MarshalToNative(GeneratorKind.QuickJS, Context); typeMap.MarshalToNative(Context);
return false; return false;
} }
@ -583,7 +583,7 @@ namespace CppSharp.Generators.Cpp
if (Context.Context.TypeMaps.FindTypeMap(decl.Type, out typeMap) && if (Context.Context.TypeMaps.FindTypeMap(decl.Type, out typeMap) &&
typeMap.DoesMarshalling) typeMap.DoesMarshalling)
{ {
typeMap.MarshalToNative(GeneratorKind.QuickJS, Context); typeMap.MarshalToNative(Context);
return typeMap.IsValueType; return typeMap.IsValueType;
} }
@ -625,7 +625,7 @@ namespace CppSharp.Generators.Cpp
if (Context.Context.TypeMaps.FindTypeMap(template, out typeMap) && typeMap.DoesMarshalling) if (Context.Context.TypeMaps.FindTypeMap(template, out typeMap) && typeMap.DoesMarshalling)
{ {
typeMap.Type = template; typeMap.Type = template;
typeMap.MarshalToNative(GeneratorKind.QuickJS, Context); typeMap.MarshalToNative(Context);
return true; return true;
} }
@ -672,7 +672,7 @@ namespace CppSharp.Generators.Cpp
if (Context.Context.TypeMaps.FindTypeMap(type, out typeMap) && if (Context.Context.TypeMaps.FindTypeMap(type, out typeMap) &&
typeMap.DoesMarshalling) typeMap.DoesMarshalling)
{ {
typeMap.MarshalToNative(GeneratorKind.QuickJS, Context); typeMap.MarshalToNative(Context);
return; return;
} }

9
src/Generator/Types/TypeMap.cs

@ -51,8 +51,9 @@ namespace CppSharp.Types
/// </summary> /// </summary>
public virtual bool DoesMarshalling => true; 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) switch (kind)
{ {
case var _ when ReferenceEquals(kind, GeneratorKind.C): 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) switch (kind)
{ {
case var _ when ReferenceEquals(kind, GeneratorKind.C): 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) switch (kind)
{ {
case var _ when ReferenceEquals(kind, GeneratorKind.C): case var _ when ReferenceEquals(kind, GeneratorKind.C):

Loading…
Cancel
Save