Skip to content

Commit 6268b1c

Browse files
committed
TypeMap: prepare refactoring into a modular design
1 parent 8c2da6d commit 6268b1c

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/Generator/Generators/QuickJS/QuickJSMarshal.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public override bool VisitType(Type type, TypeQualifiers quals)
2525
TypeMap typeMap;
2626
if (Context.Context.TypeMaps.FindTypeMap(type, out typeMap) && typeMap.DoesMarshalling)
2727
{
28-
typeMap.MarshalToManaged(GeneratorKind.QuickJS, Context);
28+
typeMap.MarshalToManaged(Context);
2929
return false;
3030
}
3131

@@ -210,7 +210,7 @@ public override bool VisitTypedefType(TypedefType typedef, TypeQualifiers quals)
210210
typeMap.DoesMarshalling)
211211
{
212212
typeMap.Type = typedef;
213-
typeMap.MarshalToManaged(GeneratorKind.QuickJS, Context);
213+
typeMap.MarshalToManaged(Context);
214214
return typeMap.IsValueType;
215215
}
216216

@@ -232,7 +232,7 @@ public override bool VisitTemplateSpecializationType(TemplateSpecializationType
232232
if (Context.Context.TypeMaps.FindTypeMap(template, out typeMap) && typeMap.DoesMarshalling)
233233
{
234234
typeMap.Type = template;
235-
typeMap.MarshalToManaged(GeneratorKind.QuickJS, Context);
235+
typeMap.MarshalToManaged(Context);
236236
return true;
237237
}
238238

@@ -385,7 +385,7 @@ public override bool VisitType(Type type, TypeQualifiers quals)
385385
TypeMap typeMap;
386386
if (Context.Context.TypeMaps.FindTypeMap(type, out typeMap) && typeMap.DoesMarshalling)
387387
{
388-
typeMap.MarshalToNative(GeneratorKind.QuickJS, Context);
388+
typeMap.MarshalToNative(Context);
389389
return false;
390390
}
391391

@@ -583,7 +583,7 @@ public override bool VisitTypedefType(TypedefType typedef, TypeQualifiers quals)
583583
if (Context.Context.TypeMaps.FindTypeMap(decl.Type, out typeMap) &&
584584
typeMap.DoesMarshalling)
585585
{
586-
typeMap.MarshalToNative(GeneratorKind.QuickJS, Context);
586+
typeMap.MarshalToNative(Context);
587587
return typeMap.IsValueType;
588588
}
589589

@@ -625,7 +625,7 @@ public override bool VisitTemplateSpecializationType(TemplateSpecializationType
625625
if (Context.Context.TypeMaps.FindTypeMap(template, out typeMap) && typeMap.DoesMarshalling)
626626
{
627627
typeMap.Type = template;
628-
typeMap.MarshalToNative(GeneratorKind.QuickJS, Context);
628+
typeMap.MarshalToNative(Context);
629629
return true;
630630
}
631631

@@ -672,7 +672,7 @@ private void MarshalRefClass(Class @class)
672672
if (Context.Context.TypeMaps.FindTypeMap(type, out typeMap) &&
673673
typeMap.DoesMarshalling)
674674
{
675-
typeMap.MarshalToNative(GeneratorKind.QuickJS, Context);
675+
typeMap.MarshalToNative(Context);
676676
return;
677677
}
678678

src/Generator/Types/TypeMap.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ public class TypeMap
5151
/// </summary>
5252
public virtual bool DoesMarshalling => true;
5353

54-
public virtual Type SignatureType(GeneratorKind kind, TypePrinterContext ctx)
54+
public virtual Type SignatureType(TypePrinterContext ctx, GeneratorKind kind = null)
5555
{
56+
kind ??= Context.Options.GeneratorKind;
5657
switch (kind)
5758
{
5859
case var _ when ReferenceEquals(kind, GeneratorKind.C):
@@ -67,8 +68,9 @@ public virtual Type SignatureType(GeneratorKind kind, TypePrinterContext ctx)
6768
}
6869
}
6970

70-
public virtual void MarshalToNative(GeneratorKind kind, MarshalContext ctx)
71+
public virtual void MarshalToNative(MarshalContext ctx, GeneratorKind kind = null)
7172
{
73+
kind ??= Context.Options.GeneratorKind;
7274
switch (kind)
7375
{
7476
case var _ when ReferenceEquals(kind, GeneratorKind.C):
@@ -86,8 +88,9 @@ public virtual void MarshalToNative(GeneratorKind kind, MarshalContext ctx)
8688
}
8789
}
8890

89-
public virtual void MarshalToManaged(GeneratorKind kind, MarshalContext ctx)
91+
public virtual void MarshalToManaged(MarshalContext ctx, GeneratorKind kind = null)
9092
{
93+
kind ??= Context.Options.GeneratorKind;
9194
switch (kind)
9295
{
9396
case var _ when ReferenceEquals(kind, GeneratorKind.C):

0 commit comments

Comments
 (0)