Skip to content

Commit 8271415

Browse files
committed
TypeMap: refactor C++ backend into common methods
1 parent 6268b1c commit 8271415

File tree

5 files changed

+17
-48
lines changed

5 files changed

+17
-48
lines changed

src/Generator/Generators/C/CppMarshal.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.CppMarshalToManaged(Context);
28+
typeMap.MarshalToManaged(Context);
2929
return false;
3030
}
3131

@@ -173,7 +173,7 @@ public override bool VisitTypedefType(TypedefType typedef, TypeQualifiers quals)
173173
typeMap.DoesMarshalling)
174174
{
175175
typeMap.Type = typedef;
176-
typeMap.CppMarshalToManaged(Context);
176+
typeMap.MarshalToManaged(Context);
177177
return typeMap.IsValueType;
178178
}
179179

@@ -193,7 +193,7 @@ public override bool VisitTemplateSpecializationType(TemplateSpecializationType
193193
if (Context.Context.TypeMaps.FindTypeMap(template, out typeMap) && typeMap.DoesMarshalling)
194194
{
195195
typeMap.Type = template;
196-
typeMap.CppMarshalToManaged(Context);
196+
typeMap.MarshalToManaged(Context);
197197
return true;
198198
}
199199

@@ -341,7 +341,7 @@ public override bool VisitType(Type type, TypeQualifiers quals)
341341
TypeMap typeMap;
342342
if (Context.Context.TypeMaps.FindTypeMap(type, out typeMap) && typeMap.DoesMarshalling)
343343
{
344-
typeMap.CppMarshalToNative(Context);
344+
typeMap.MarshalToNative(Context);
345345
return false;
346346
}
347347

@@ -478,7 +478,7 @@ public override bool VisitTypedefType(TypedefType typedef, TypeQualifiers quals)
478478
if (Context.Context.TypeMaps.FindTypeMap(decl.Type, out typeMap) &&
479479
typeMap.DoesMarshalling)
480480
{
481-
typeMap.CppMarshalToNative(Context);
481+
typeMap.MarshalToNative(Context);
482482
return typeMap.IsValueType;
483483
}
484484

@@ -516,7 +516,7 @@ public override bool VisitTemplateSpecializationType(TemplateSpecializationType
516516
if (Context.Context.TypeMaps.FindTypeMap(template, out typeMap) && typeMap.DoesMarshalling)
517517
{
518518
typeMap.Type = template;
519-
typeMap.CppMarshalToNative(Context);
519+
typeMap.MarshalToNative(Context);
520520
return true;
521521
}
522522

@@ -563,7 +563,7 @@ private void MarshalRefClass(Class @class)
563563
if (Context.Context.TypeMaps.FindTypeMap(type, out typeMap) &&
564564
typeMap.DoesMarshalling)
565565
{
566-
typeMap.CppMarshalToNative(Context);
566+
typeMap.MarshalToNative(Context);
567567
return;
568568
}
569569

src/Generator/Generators/C/CppTypePrinter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public virtual bool FindTypeMap(CppSharp.AST.Type type, out TypePrinterResult re
6868
typePrinter.PushContext(ContextKind);
6969
typePrinter.PushScope(ScopeKind);
7070

71-
var typeName = typeMap.CppSignatureType(typePrinterContext).Visit(typePrinter);
71+
var typeName = typeMap.SignatureType(typePrinterContext).Visit(typePrinter);
7272
result = new TypePrinterResult(typeName) { TypeMap = typeMap };
7373

7474
return true;

src/Generator/Generators/NAPI/NAPIMarshal.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public override bool VisitType(Type type, TypeQualifiers quals)
2626
TypeMap typeMap;
2727
if (Context.Context.TypeMaps.FindTypeMap(type, out typeMap) && typeMap.DoesMarshalling)
2828
{
29-
typeMap.CppMarshalToManaged(Context);
29+
typeMap.MarshalToManaged(Context);
3030
return false;
3131
}
3232

@@ -194,7 +194,7 @@ public override bool VisitTypedefType(TypedefType typedef, TypeQualifiers quals)
194194
typeMap.DoesMarshalling)
195195
{
196196
typeMap.Type = typedef;
197-
typeMap.CppMarshalToManaged(Context);
197+
typeMap.MarshalToManaged(Context);
198198
return typeMap.IsValueType;
199199
}
200200

@@ -214,7 +214,7 @@ public override bool VisitTemplateSpecializationType(TemplateSpecializationType
214214
if (Context.Context.TypeMaps.FindTypeMap(template, out typeMap) && typeMap.DoesMarshalling)
215215
{
216216
typeMap.Type = template;
217-
typeMap.CppMarshalToManaged(Context);
217+
typeMap.MarshalToManaged(Context);
218218
return true;
219219
}
220220

@@ -343,7 +343,7 @@ public override bool VisitType(Type type, TypeQualifiers quals)
343343
TypeMap typeMap;
344344
if (Context.Context.TypeMaps.FindTypeMap(type, out typeMap) && typeMap.DoesMarshalling)
345345
{
346-
typeMap.CppMarshalToNative(Context);
346+
typeMap.MarshalToNative(Context);
347347
return false;
348348
}
349349

@@ -591,7 +591,7 @@ public override bool VisitTypedefType(TypedefType typedef, TypeQualifiers quals)
591591
if (Context.Context.TypeMaps.FindTypeMap(decl.Type, out typeMap) &&
592592
typeMap.DoesMarshalling)
593593
{
594-
typeMap.CppMarshalToNative(Context);
594+
typeMap.MarshalToNative(Context);
595595
return typeMap.IsValueType;
596596
}
597597

@@ -628,7 +628,7 @@ public override bool VisitTemplateSpecializationType(TemplateSpecializationType
628628
if (Context.Context.TypeMaps.FindTypeMap(template, out typeMap) && typeMap.DoesMarshalling)
629629
{
630630
typeMap.Type = template;
631-
typeMap.CppMarshalToNative(Context);
631+
typeMap.MarshalToNative(Context);
632632
return true;
633633
}
634634

src/Generator/Types/TypeMap.cs

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public virtual Type SignatureType(TypePrinterContext ctx, GeneratorKind kind = n
5858
{
5959
case var _ when ReferenceEquals(kind, GeneratorKind.C):
6060
case var _ when ReferenceEquals(kind, GeneratorKind.CPlusPlus):
61-
return CppSignatureType(ctx);
61+
return new CILType(typeof(object));
6262
case var _ when ReferenceEquals(kind, GeneratorKind.CLI):
6363
return CLISignatureType(ctx);
6464
case var _ when ReferenceEquals(kind, GeneratorKind.CSharp):
@@ -75,7 +75,7 @@ public virtual void MarshalToNative(MarshalContext ctx, GeneratorKind kind = nul
7575
{
7676
case var _ when ReferenceEquals(kind, GeneratorKind.C):
7777
case var _ when ReferenceEquals(kind, GeneratorKind.CPlusPlus):
78-
CppMarshalToNative(ctx);
78+
ctx.Return.Write(ctx.Parameter.Name);
7979
return;
8080
case var _ when ReferenceEquals(kind, GeneratorKind.CLI):
8181
CLIMarshalToNative(ctx);
@@ -95,7 +95,7 @@ public virtual void MarshalToManaged(MarshalContext ctx, GeneratorKind kind = nu
9595
{
9696
case var _ when ReferenceEquals(kind, GeneratorKind.C):
9797
case var _ when ReferenceEquals(kind, GeneratorKind.CPlusPlus):
98-
CppMarshalToManaged(ctx);
98+
ctx.Return.Write(ctx.ReturnVarName);
9999
return;
100100
case var _ when ReferenceEquals(kind, GeneratorKind.CLI):
101101
CLIMarshalToManaged(ctx);
@@ -158,30 +158,6 @@ public virtual void CLIMarshalToManaged(MarshalContext ctx)
158158
}
159159

160160
#endregion
161-
162-
#region C++ backend
163-
164-
public virtual Type CppSignatureType(TypePrinterContext ctx)
165-
{
166-
return new CILType(typeof(object));
167-
}
168-
169-
public virtual void CppTypeReference(CLITypeReference collector, ASTRecord<Declaration> record)
170-
{
171-
throw new NotImplementedException();
172-
}
173-
174-
public virtual void CppMarshalToNative(MarshalContext ctx)
175-
{
176-
ctx.Return.Write(ctx.Parameter.Name);
177-
}
178-
179-
public virtual void CppMarshalToManaged(MarshalContext ctx)
180-
{
181-
ctx.Return.Write(ctx.ReturnVarName);
182-
}
183-
184-
#endregion
185161
}
186162

187163
public interface ITypeMapDatabase

tests/dotnet/CLI/CLI.Gen.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,6 @@ public override Type CLISignatureType(TypePrinterContext ctx)
2929
return new CILType(typeof(string));
3030
}
3131

32-
public override Type CppSignatureType(TypePrinterContext ctx)
33-
{
34-
var tagType = ctx.Type as TagType;
35-
var typePrinter = new CppTypePrinter(Context);
36-
return new CustomType(tagType.Declaration.Visit(typePrinter));
37-
}
38-
3932
public override void CLIMarshalToManaged(MarshalContext ctx)
4033
{
4134
ctx.Return.Write("clix::marshalString<clix::E_UTF8>({0}.m_str)", ctx.ReturnVarName);

0 commit comments

Comments
 (0)