Skip to content

Commit 02b745c

Browse files
Revert "Typemap cleanup (mono#1802)"
This reverts commit e068f2a.
1 parent 519e97f commit 02b745c

21 files changed

+355
-289
lines changed

src/Generator/AST/Utils.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public static bool IsMappedToPrimitive(ITypeMapDatabase typeMaps, Type type)
207207
return false;
208208

209209
var typePrinterContext = new TypePrinterContext { Type = type };
210-
var mappedTo = typeMap.SignatureType(typePrinterContext);
210+
var mappedTo = typeMap.CSharpSignatureType(typePrinterContext);
211211
mappedTo = mappedTo.Desugar();
212212
mappedTo = (mappedTo.GetFinalPointee() ?? mappedTo).Desugar();
213213
return (mappedTo.IsPrimitiveType() ||

src/Generator/GeneratorKind.cs

-5
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@ public GeneratorKind(string id, string name, System.Type generatorType, System.T
3838
Registered.Add(this);
3939
}
4040

41-
public static GeneratorKind FindGeneratorKindByID(string id)
42-
{
43-
return Registered.Where(kind => kind.ID == id).First();
44-
}
45-
4641
public Generator CreateGenerator(BindingContext context)
4742
{
4843
return (Generator)Activator.CreateInstance(GeneratorType, context);

src/Generator/Generators/C/CppMarshal.cs

+7-7
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(Context);
28+
typeMap.CppMarshalToManaged(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.MarshalToManaged(Context);
176+
typeMap.CppMarshalToManaged(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.MarshalToManaged(Context);
196+
typeMap.CppMarshalToManaged(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.MarshalToNative(Context);
344+
typeMap.CppMarshalToNative(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.MarshalToNative(Context);
481+
typeMap.CppMarshalToNative(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.MarshalToNative(Context);
519+
typeMap.CppMarshalToNative(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.MarshalToNative(Context);
566+
typeMap.CppMarshalToNative(Context);
567567
return;
568568
}
569569

src/Generator/Generators/C/CppTypePrinter.cs

+1-1
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.SignatureType(typePrinterContext).Visit(typePrinter);
71+
var typeName = typeMap.CppSignatureType(typePrinterContext).Visit(typePrinter);
7272
result = new TypePrinterResult(typeName) { TypeMap = typeMap };
7373

7474
return true;

src/Generator/Generators/CLI/CLIMarshal.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public override bool VisitType(Type type, TypeQualifiers quals)
2222
TypeMap typeMap;
2323
if (Context.Context.TypeMaps.FindTypeMap(type, out typeMap) && typeMap.DoesMarshalling)
2424
{
25-
typeMap.MarshalToManaged(Context);
25+
typeMap.CLIMarshalToManaged(Context);
2626
return false;
2727
}
2828

@@ -215,7 +215,7 @@ public override bool VisitTypedefType(TypedefType typedef, TypeQualifiers quals)
215215
typeMap.DoesMarshalling)
216216
{
217217
typeMap.Type = typedef;
218-
typeMap.MarshalToManaged(Context);
218+
typeMap.CLIMarshalToManaged(Context);
219219
return typeMap.IsValueType;
220220
}
221221

@@ -240,7 +240,7 @@ public override bool VisitTemplateSpecializationType(TemplateSpecializationType
240240
if (Context.Context.TypeMaps.FindTypeMap(template, out typeMap) && typeMap.DoesMarshalling)
241241
{
242242
typeMap.Type = template;
243-
typeMap.MarshalToManaged(Context);
243+
typeMap.CLIMarshalToManaged(Context);
244244
return true;
245245
}
246246

@@ -406,7 +406,7 @@ public override bool VisitType(Type type, TypeQualifiers quals)
406406
TypeMap typeMap;
407407
if (Context.Context.TypeMaps.FindTypeMap(type, out typeMap) && typeMap.DoesMarshalling)
408408
{
409-
typeMap.MarshalToNative(Context);
409+
typeMap.CLIMarshalToNative(Context);
410410
return false;
411411
}
412412

@@ -605,7 +605,7 @@ public override bool VisitTypedefType(TypedefType typedef, TypeQualifiers quals)
605605
if (Context.Context.TypeMaps.FindTypeMap(decl.Type, out typeMap) &&
606606
typeMap.DoesMarshalling)
607607
{
608-
typeMap.MarshalToNative(Context);
608+
typeMap.CLIMarshalToNative(Context);
609609
return typeMap.IsValueType;
610610
}
611611

@@ -641,7 +641,7 @@ public override bool VisitTemplateSpecializationType(TemplateSpecializationType
641641
if (Context.Context.TypeMaps.FindTypeMap(template, out typeMap) && typeMap.DoesMarshalling)
642642
{
643643
typeMap.Type = template;
644-
typeMap.MarshalToNative(Context);
644+
typeMap.CLIMarshalToNative(Context);
645645
return true;
646646
}
647647

@@ -688,7 +688,7 @@ private void MarshalRefClass(Class @class)
688688
if (Context.Context.TypeMaps.FindTypeMap(type, out typeMap) &&
689689
typeMap.DoesMarshalling)
690690
{
691-
typeMap.MarshalToNative(Context);
691+
typeMap.CLIMarshalToNative(Context);
692692
return;
693693
}
694694

src/Generator/Generators/CLI/CLITypePrinter.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public override TypePrinterResult VisitTagType(TagType tag, TypeQualifiers quals
2121
if (TypeMapDatabase.FindTypeMap(tag, out typeMap))
2222
{
2323
var typePrinterContext = new TypePrinterContext { Type = tag };
24-
return typeMap.SignatureType(typePrinterContext).ToString();
24+
return typeMap.CLISignatureType(typePrinterContext).ToString();
2525
}
2626

2727
Declaration decl = tag.Declaration;
@@ -112,7 +112,7 @@ public override TypePrinterResult VisitPointerType(PointerType pointer,
112112
Type = pointer
113113
};
114114

115-
return typeMap.SignatureType(typePrinterContext).Visit(this);
115+
return typeMap.CLISignatureType(typePrinterContext).Visit(this);
116116
}
117117

118118
var pointee = pointer.Pointee.Desugar();
@@ -217,7 +217,7 @@ public override TypePrinterResult VisitTypedefType(TypedefType typedef,
217217
{
218218
typeMap.Type = typedef;
219219
var typePrinterContext = new TypePrinterContext { Type = typedef };
220-
return typeMap.SignatureType(typePrinterContext).ToString();
220+
return typeMap.CLISignatureType(typePrinterContext).ToString();
221221
}
222222

223223
FunctionType func;
@@ -241,7 +241,7 @@ public override TypePrinterResult VisitTemplateSpecializationType(
241241
if (TypeMapDatabase.FindTypeMap(template, out typeMap) && !typeMap.IsIgnored)
242242
{
243243
var typePrinterContext = new TypePrinterContext { Type = template };
244-
return typeMap.SignatureType(typePrinterContext).ToString();
244+
return typeMap.CLISignatureType(typePrinterContext).ToString();
245245
}
246246

247247
return decl.Name;

src/Generator/Generators/CSharp/CSharpMarshal.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public override bool VisitType(Type type, TypeQualifiers quals)
4545
TypeMap typeMap;
4646
if (Context.Context.TypeMaps.FindTypeMap(type, out typeMap) && typeMap.DoesMarshalling)
4747
{
48-
typeMap.MarshalToManaged(Context);
48+
typeMap.CSharpMarshalToManaged(Context);
4949
return false;
5050
}
5151

@@ -471,7 +471,7 @@ public override bool VisitType(Type type, TypeQualifiers quals)
471471
TypeMap typeMap;
472472
if (Context.Context.TypeMaps.FindTypeMap(type, out typeMap) && typeMap.DoesMarshalling)
473473
{
474-
typeMap.MarshalToNative(Context);
474+
typeMap.CSharpMarshalToNative(Context);
475475
return false;
476476
}
477477

src/Generator/Generators/CSharp/CSharpSources.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3158,7 +3158,7 @@ public void GenerateFunctionCall(string functionName, Function function,
31583158
Type = indirectRetType.Type.Desugar()
31593159
};
31603160

3161-
WriteLine("{0} {1};", typeMap.SignatureType(typePrinterContext),
3161+
WriteLine("{0} {1};", typeMap.CSharpSignatureType(typePrinterContext),
31623162
Helpers.ReturnIdentifier);
31633163
}
31643164
else

src/Generator/Generators/CSharp/CSharpTypePrinter.cs

+10-10
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public override TypePrinterResult VisitTagType(TagType tag, TypeQualifiers quals
3636
return string.Empty;
3737

3838
TypeMap typeMap;
39-
if (TypeMapDatabase.FindTypeMap(tag, GeneratorKind.CSharp, out typeMap))
39+
if (TypeMapDatabase.FindTypeMap(tag, out typeMap))
4040
{
4141
typeMap.Type = tag;
4242

@@ -47,7 +47,7 @@ public override TypePrinterResult VisitTagType(TagType tag, TypeQualifiers quals
4747
Type = tag
4848
};
4949

50-
return typeMap.SignatureType(typePrinterContext).ToString();
50+
return typeMap.CSharpSignatureType(typePrinterContext).ToString();
5151
}
5252

5353
return base.VisitTagType(tag, quals);
@@ -150,7 +150,7 @@ public override TypePrinterResult VisitArrayType(ArrayType array,
150150
public override TypePrinterResult VisitBuiltinType(BuiltinType builtin, TypeQualifiers quals)
151151
{
152152
TypeMap typeMap;
153-
if (TypeMapDatabase.FindTypeMap(builtin, GeneratorKind.CSharp, out typeMap))
153+
if (TypeMapDatabase.FindTypeMap(builtin, out typeMap))
154154
{
155155
var typePrinterContext = new TypePrinterContext()
156156
{
@@ -159,7 +159,7 @@ public override TypePrinterResult VisitBuiltinType(BuiltinType builtin, TypeQual
159159
Type = builtin,
160160
Parameter = Parameter
161161
};
162-
return typeMap.SignatureType(typePrinterContext).Visit(this);
162+
return typeMap.CSharpSignatureType(typePrinterContext).Visit(this);
163163
}
164164
return base.VisitBuiltinType(builtin, quals);
165165
}
@@ -183,15 +183,15 @@ public override TypePrinterResult VisitPointerType(PointerType pointer,
183183
if (allowStrings && pointer.IsConstCharString())
184184
{
185185
TypeMap typeMap;
186-
TypeMapDatabase.FindTypeMap(pointer, GeneratorKind.CSharp, out typeMap);
186+
TypeMapDatabase.FindTypeMap(pointer, out typeMap);
187187
var typePrinterContext = new TypePrinterContext()
188188
{
189189
Kind = ContextKind,
190190
MarshalKind = MarshalKind,
191191
Type = pointer.Pointee,
192192
Parameter = Parameter
193193
};
194-
return typeMap.SignatureType(typePrinterContext).Visit(this);
194+
return typeMap.CSharpSignatureType(typePrinterContext).Visit(this);
195195
}
196196

197197
var pointee = pointer.Pointee.Desugar();
@@ -258,7 +258,7 @@ public override TypePrinterResult VisitTypedefType(TypedefType typedef,
258258
var decl = typedef.Declaration;
259259

260260
TypeMap typeMap;
261-
if (TypeMapDatabase.FindTypeMap(typedef, GeneratorKind.CSharp, out typeMap))
261+
if (TypeMapDatabase.FindTypeMap(typedef, out typeMap))
262262
{
263263
typeMap.Type = typedef;
264264

@@ -270,7 +270,7 @@ public override TypePrinterResult VisitTypedefType(TypedefType typedef,
270270
Parameter = Parameter
271271
};
272272

273-
return typeMap.SignatureType(typePrinterContext).ToString();
273+
return typeMap.CSharpSignatureType(typePrinterContext).ToString();
274274
}
275275

276276
FunctionType func;
@@ -299,7 +299,7 @@ public override TypePrinterResult VisitTemplateSpecializationType(
299299
template.Template.TemplatedDecl;
300300

301301
TypeMap typeMap;
302-
if (!TypeMapDatabase.FindTypeMap(template, GeneratorKind.CSharp, out typeMap))
302+
if (!TypeMapDatabase.FindTypeMap(template, out typeMap))
303303
{
304304
if (ContextKind == TypePrinterContextKind.Managed &&
305305
decl == template.Template.TemplatedDecl &&
@@ -330,7 +330,7 @@ public override TypePrinterResult VisitTemplateSpecializationType(
330330
MarshalKind = MarshalKind
331331
};
332332

333-
return typeMap.SignatureType(typePrinterContext).ToString();
333+
return typeMap.CSharpSignatureType(typePrinterContext).ToString();
334334
}
335335

336336
public override TypePrinterResult VisitDependentTemplateSpecializationType(

src/Generator/Generators/ExtensionMethods.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,12 @@ public static Type GetMappedType(this Type type, TypeMapDatabase typeMaps,
6363
Type = typeMap.Type
6464
};
6565

66-
if (generatorKind == GeneratorKind.CLI || generatorKind == GeneratorKind.CSharp)
66+
switch (generatorKind)
6767
{
68-
return typeMap.SignatureType(typePrinterContext).Desugar();
68+
case var _ when ReferenceEquals(generatorKind, GeneratorKind.CLI):
69+
return typeMap.CLISignatureType(typePrinterContext).Desugar();
70+
case var _ when ReferenceEquals(generatorKind, GeneratorKind.CSharp):
71+
return typeMap.CSharpSignatureType(typePrinterContext).Desugar();
6972
}
7073
}
7174

src/Generator/Generators/NAPI/NAPIMarshal.cs

+6-6
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.MarshalToManaged(Context);
29+
typeMap.CppMarshalToManaged(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.MarshalToManaged(Context);
197+
typeMap.CppMarshalToManaged(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.MarshalToManaged(Context);
217+
typeMap.CppMarshalToManaged(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.MarshalToNative(Context);
346+
typeMap.CppMarshalToNative(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.MarshalToNative(Context);
594+
typeMap.CppMarshalToNative(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.MarshalToNative(Context);
631+
typeMap.CppMarshalToNative(Context);
632632
return true;
633633
}
634634

0 commit comments

Comments
 (0)