Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Typemap cleanup" #1810

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Generator/AST/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public static bool IsMappedToPrimitive(ITypeMapDatabase typeMaps, Type type)
return false;

var typePrinterContext = new TypePrinterContext { Type = type };
var mappedTo = typeMap.SignatureType(typePrinterContext);
var mappedTo = typeMap.CSharpSignatureType(typePrinterContext);
mappedTo = mappedTo.Desugar();
mappedTo = (mappedTo.GetFinalPointee() ?? mappedTo).Desugar();
return (mappedTo.IsPrimitiveType() ||
Expand Down
5 changes: 0 additions & 5 deletions src/Generator/GeneratorKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ public GeneratorKind(string id, string name, System.Type generatorType, System.T
Registered.Add(this);
}

public static GeneratorKind FindGeneratorKindByID(string id)
{
return Registered.Where(kind => kind.ID == id).First();
}

public Generator CreateGenerator(BindingContext context)
{
return (Generator)Activator.CreateInstance(GeneratorType, context);
Expand Down
14 changes: 7 additions & 7 deletions src/Generator/Generators/C/CppMarshal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public override bool VisitType(Type type, TypeQualifiers quals)
TypeMap typeMap;
if (Context.Context.TypeMaps.FindTypeMap(type, out typeMap) && typeMap.DoesMarshalling)
{
typeMap.MarshalToManaged(Context);
typeMap.CppMarshalToManaged(Context);
return false;
}

Expand Down Expand Up @@ -173,7 +173,7 @@ public override bool VisitTypedefType(TypedefType typedef, TypeQualifiers quals)
typeMap.DoesMarshalling)
{
typeMap.Type = typedef;
typeMap.MarshalToManaged(Context);
typeMap.CppMarshalToManaged(Context);
return typeMap.IsValueType;
}

Expand All @@ -193,7 +193,7 @@ public override bool VisitTemplateSpecializationType(TemplateSpecializationType
if (Context.Context.TypeMaps.FindTypeMap(template, out typeMap) && typeMap.DoesMarshalling)
{
typeMap.Type = template;
typeMap.MarshalToManaged(Context);
typeMap.CppMarshalToManaged(Context);
return true;
}

Expand Down Expand Up @@ -341,7 +341,7 @@ public override bool VisitType(Type type, TypeQualifiers quals)
TypeMap typeMap;
if (Context.Context.TypeMaps.FindTypeMap(type, out typeMap) && typeMap.DoesMarshalling)
{
typeMap.MarshalToNative(Context);
typeMap.CppMarshalToNative(Context);
return false;
}

Expand Down Expand Up @@ -478,7 +478,7 @@ public override bool VisitTypedefType(TypedefType typedef, TypeQualifiers quals)
if (Context.Context.TypeMaps.FindTypeMap(decl.Type, out typeMap) &&
typeMap.DoesMarshalling)
{
typeMap.MarshalToNative(Context);
typeMap.CppMarshalToNative(Context);
return typeMap.IsValueType;
}

Expand Down Expand Up @@ -516,7 +516,7 @@ public override bool VisitTemplateSpecializationType(TemplateSpecializationType
if (Context.Context.TypeMaps.FindTypeMap(template, out typeMap) && typeMap.DoesMarshalling)
{
typeMap.Type = template;
typeMap.MarshalToNative(Context);
typeMap.CppMarshalToNative(Context);
return true;
}

Expand Down Expand Up @@ -563,7 +563,7 @@ private void MarshalRefClass(Class @class)
if (Context.Context.TypeMaps.FindTypeMap(type, out typeMap) &&
typeMap.DoesMarshalling)
{
typeMap.MarshalToNative(Context);
typeMap.CppMarshalToNative(Context);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Generator/Generators/C/CppTypePrinter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public virtual bool FindTypeMap(CppSharp.AST.Type type, out TypePrinterResult re
typePrinter.PushContext(ContextKind);
typePrinter.PushScope(ScopeKind);

var typeName = typeMap.SignatureType(typePrinterContext).Visit(typePrinter);
var typeName = typeMap.CppSignatureType(typePrinterContext).Visit(typePrinter);
result = new TypePrinterResult(typeName) { TypeMap = typeMap };

return true;
Expand Down
14 changes: 7 additions & 7 deletions src/Generator/Generators/CLI/CLIMarshal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public override bool VisitType(Type type, TypeQualifiers quals)
TypeMap typeMap;
if (Context.Context.TypeMaps.FindTypeMap(type, out typeMap) && typeMap.DoesMarshalling)
{
typeMap.MarshalToManaged(Context);
typeMap.CLIMarshalToManaged(Context);
return false;
}

Expand Down Expand Up @@ -215,7 +215,7 @@ public override bool VisitTypedefType(TypedefType typedef, TypeQualifiers quals)
typeMap.DoesMarshalling)
{
typeMap.Type = typedef;
typeMap.MarshalToManaged(Context);
typeMap.CLIMarshalToManaged(Context);
return typeMap.IsValueType;
}

Expand All @@ -240,7 +240,7 @@ public override bool VisitTemplateSpecializationType(TemplateSpecializationType
if (Context.Context.TypeMaps.FindTypeMap(template, out typeMap) && typeMap.DoesMarshalling)
{
typeMap.Type = template;
typeMap.MarshalToManaged(Context);
typeMap.CLIMarshalToManaged(Context);
return true;
}

Expand Down Expand Up @@ -406,7 +406,7 @@ public override bool VisitType(Type type, TypeQualifiers quals)
TypeMap typeMap;
if (Context.Context.TypeMaps.FindTypeMap(type, out typeMap) && typeMap.DoesMarshalling)
{
typeMap.MarshalToNative(Context);
typeMap.CLIMarshalToNative(Context);
return false;
}

Expand Down Expand Up @@ -605,7 +605,7 @@ public override bool VisitTypedefType(TypedefType typedef, TypeQualifiers quals)
if (Context.Context.TypeMaps.FindTypeMap(decl.Type, out typeMap) &&
typeMap.DoesMarshalling)
{
typeMap.MarshalToNative(Context);
typeMap.CLIMarshalToNative(Context);
return typeMap.IsValueType;
}

Expand Down Expand Up @@ -641,7 +641,7 @@ public override bool VisitTemplateSpecializationType(TemplateSpecializationType
if (Context.Context.TypeMaps.FindTypeMap(template, out typeMap) && typeMap.DoesMarshalling)
{
typeMap.Type = template;
typeMap.MarshalToNative(Context);
typeMap.CLIMarshalToNative(Context);
return true;
}

Expand Down Expand Up @@ -688,7 +688,7 @@ private void MarshalRefClass(Class @class)
if (Context.Context.TypeMaps.FindTypeMap(type, out typeMap) &&
typeMap.DoesMarshalling)
{
typeMap.MarshalToNative(Context);
typeMap.CLIMarshalToNative(Context);
return;
}

Expand Down
8 changes: 4 additions & 4 deletions src/Generator/Generators/CLI/CLITypePrinter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public override TypePrinterResult VisitTagType(TagType tag, TypeQualifiers quals
if (TypeMapDatabase.FindTypeMap(tag, out typeMap))
{
var typePrinterContext = new TypePrinterContext { Type = tag };
return typeMap.SignatureType(typePrinterContext).ToString();
return typeMap.CLISignatureType(typePrinterContext).ToString();
}

Declaration decl = tag.Declaration;
Expand Down Expand Up @@ -112,7 +112,7 @@ public override TypePrinterResult VisitPointerType(PointerType pointer,
Type = pointer
};

return typeMap.SignatureType(typePrinterContext).Visit(this);
return typeMap.CLISignatureType(typePrinterContext).Visit(this);
}

var pointee = pointer.Pointee.Desugar();
Expand Down Expand Up @@ -217,7 +217,7 @@ public override TypePrinterResult VisitTypedefType(TypedefType typedef,
{
typeMap.Type = typedef;
var typePrinterContext = new TypePrinterContext { Type = typedef };
return typeMap.SignatureType(typePrinterContext).ToString();
return typeMap.CLISignatureType(typePrinterContext).ToString();
}

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

return decl.Name;
Expand Down
4 changes: 2 additions & 2 deletions src/Generator/Generators/CSharp/CSharpMarshal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public override bool VisitType(Type type, TypeQualifiers quals)
TypeMap typeMap;
if (Context.Context.TypeMaps.FindTypeMap(type, out typeMap) && typeMap.DoesMarshalling)
{
typeMap.MarshalToManaged(Context);
typeMap.CSharpMarshalToManaged(Context);
return false;
}

Expand Down Expand Up @@ -471,7 +471,7 @@ public override bool VisitType(Type type, TypeQualifiers quals)
TypeMap typeMap;
if (Context.Context.TypeMaps.FindTypeMap(type, out typeMap) && typeMap.DoesMarshalling)
{
typeMap.MarshalToNative(Context);
typeMap.CSharpMarshalToNative(Context);
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Generator/Generators/CSharp/CSharpSources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3158,7 +3158,7 @@ public void GenerateFunctionCall(string functionName, Function function,
Type = indirectRetType.Type.Desugar()
};

WriteLine("{0} {1};", typeMap.SignatureType(typePrinterContext),
WriteLine("{0} {1};", typeMap.CSharpSignatureType(typePrinterContext),
Helpers.ReturnIdentifier);
}
else
Expand Down
20 changes: 10 additions & 10 deletions src/Generator/Generators/CSharp/CSharpTypePrinter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public override TypePrinterResult VisitTagType(TagType tag, TypeQualifiers quals
return string.Empty;

TypeMap typeMap;
if (TypeMapDatabase.FindTypeMap(tag, GeneratorKind.CSharp, out typeMap))
if (TypeMapDatabase.FindTypeMap(tag, out typeMap))
{
typeMap.Type = tag;

Expand All @@ -47,7 +47,7 @@ public override TypePrinterResult VisitTagType(TagType tag, TypeQualifiers quals
Type = tag
};

return typeMap.SignatureType(typePrinterContext).ToString();
return typeMap.CSharpSignatureType(typePrinterContext).ToString();
}

return base.VisitTagType(tag, quals);
Expand Down Expand Up @@ -150,7 +150,7 @@ public override TypePrinterResult VisitArrayType(ArrayType array,
public override TypePrinterResult VisitBuiltinType(BuiltinType builtin, TypeQualifiers quals)
{
TypeMap typeMap;
if (TypeMapDatabase.FindTypeMap(builtin, GeneratorKind.CSharp, out typeMap))
if (TypeMapDatabase.FindTypeMap(builtin, out typeMap))
{
var typePrinterContext = new TypePrinterContext()
{
Expand All @@ -159,7 +159,7 @@ public override TypePrinterResult VisitBuiltinType(BuiltinType builtin, TypeQual
Type = builtin,
Parameter = Parameter
};
return typeMap.SignatureType(typePrinterContext).Visit(this);
return typeMap.CSharpSignatureType(typePrinterContext).Visit(this);
}
return base.VisitBuiltinType(builtin, quals);
}
Expand All @@ -183,15 +183,15 @@ public override TypePrinterResult VisitPointerType(PointerType pointer,
if (allowStrings && pointer.IsConstCharString())
{
TypeMap typeMap;
TypeMapDatabase.FindTypeMap(pointer, GeneratorKind.CSharp, out typeMap);
TypeMapDatabase.FindTypeMap(pointer, out typeMap);
var typePrinterContext = new TypePrinterContext()
{
Kind = ContextKind,
MarshalKind = MarshalKind,
Type = pointer.Pointee,
Parameter = Parameter
};
return typeMap.SignatureType(typePrinterContext).Visit(this);
return typeMap.CSharpSignatureType(typePrinterContext).Visit(this);
}

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

TypeMap typeMap;
if (TypeMapDatabase.FindTypeMap(typedef, GeneratorKind.CSharp, out typeMap))
if (TypeMapDatabase.FindTypeMap(typedef, out typeMap))
{
typeMap.Type = typedef;

Expand All @@ -270,7 +270,7 @@ public override TypePrinterResult VisitTypedefType(TypedefType typedef,
Parameter = Parameter
};

return typeMap.SignatureType(typePrinterContext).ToString();
return typeMap.CSharpSignatureType(typePrinterContext).ToString();
}

FunctionType func;
Expand Down Expand Up @@ -299,7 +299,7 @@ public override TypePrinterResult VisitTemplateSpecializationType(
template.Template.TemplatedDecl;

TypeMap typeMap;
if (!TypeMapDatabase.FindTypeMap(template, GeneratorKind.CSharp, out typeMap))
if (!TypeMapDatabase.FindTypeMap(template, out typeMap))
{
if (ContextKind == TypePrinterContextKind.Managed &&
decl == template.Template.TemplatedDecl &&
Expand Down Expand Up @@ -330,7 +330,7 @@ public override TypePrinterResult VisitTemplateSpecializationType(
MarshalKind = MarshalKind
};

return typeMap.SignatureType(typePrinterContext).ToString();
return typeMap.CSharpSignatureType(typePrinterContext).ToString();
}

public override TypePrinterResult VisitDependentTemplateSpecializationType(
Expand Down
7 changes: 5 additions & 2 deletions src/Generator/Generators/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,12 @@ public static Type GetMappedType(this Type type, TypeMapDatabase typeMaps,
Type = typeMap.Type
};

if (generatorKind == GeneratorKind.CLI || generatorKind == GeneratorKind.CSharp)
switch (generatorKind)
{
return typeMap.SignatureType(typePrinterContext).Desugar();
case var _ when ReferenceEquals(generatorKind, GeneratorKind.CLI):
return typeMap.CLISignatureType(typePrinterContext).Desugar();
case var _ when ReferenceEquals(generatorKind, GeneratorKind.CSharp):
return typeMap.CSharpSignatureType(typePrinterContext).Desugar();
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/Generator/Generators/NAPI/NAPIMarshal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public override bool VisitType(Type type, TypeQualifiers quals)
TypeMap typeMap;
if (Context.Context.TypeMaps.FindTypeMap(type, out typeMap) && typeMap.DoesMarshalling)
{
typeMap.MarshalToManaged(Context);
typeMap.CppMarshalToManaged(Context);
return false;
}

Expand Down Expand Up @@ -194,7 +194,7 @@ public override bool VisitTypedefType(TypedefType typedef, TypeQualifiers quals)
typeMap.DoesMarshalling)
{
typeMap.Type = typedef;
typeMap.MarshalToManaged(Context);
typeMap.CppMarshalToManaged(Context);
return typeMap.IsValueType;
}

Expand All @@ -214,7 +214,7 @@ public override bool VisitTemplateSpecializationType(TemplateSpecializationType
if (Context.Context.TypeMaps.FindTypeMap(template, out typeMap) && typeMap.DoesMarshalling)
{
typeMap.Type = template;
typeMap.MarshalToManaged(Context);
typeMap.CppMarshalToManaged(Context);
return true;
}

Expand Down Expand Up @@ -343,7 +343,7 @@ public override bool VisitType(Type type, TypeQualifiers quals)
TypeMap typeMap;
if (Context.Context.TypeMaps.FindTypeMap(type, out typeMap) && typeMap.DoesMarshalling)
{
typeMap.MarshalToNative(Context);
typeMap.CppMarshalToNative(Context);
return false;
}

Expand Down Expand Up @@ -591,7 +591,7 @@ public override bool VisitTypedefType(TypedefType typedef, TypeQualifiers quals)
if (Context.Context.TypeMaps.FindTypeMap(decl.Type, out typeMap) &&
typeMap.DoesMarshalling)
{
typeMap.MarshalToNative(Context);
typeMap.CppMarshalToNative(Context);
return typeMap.IsValueType;
}

Expand Down Expand Up @@ -628,7 +628,7 @@ public override bool VisitTemplateSpecializationType(TemplateSpecializationType
if (Context.Context.TypeMaps.FindTypeMap(template, out typeMap) && typeMap.DoesMarshalling)
{
typeMap.Type = template;
typeMap.MarshalToNative(Context);
typeMap.CppMarshalToNative(Context);
return true;
}

Expand Down
Loading