Browse Source

Merge pull request #182 from ddobrev/master

Added an additional property to type maps indicating if they actually provide marshalling (useful if only copy constructors are replaced)
pull/186/head
João Matos 12 years ago
parent
commit
3057adf1e1
  1. 20
      src/Generator/Generators/CLI/CLIMarshal.cs
  2. 8
      src/Generator/Generators/CSharp/CSharpMarshal.cs
  3. 24
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs
  4. 5
      src/Generator/Types/TypeMap.cs

20
src/Generator/Generators/CLI/CLIMarshal.cs

@ -18,7 +18,7 @@ namespace CppSharp.Generators.CLI
public override bool VisitType(Type type, TypeQualifiers quals) public override bool VisitType(Type type, TypeQualifiers quals)
{ {
TypeMap typeMap; TypeMap typeMap;
if (Context.Driver.TypeDatabase.FindTypeMap(type, out typeMap)) if (Context.Driver.TypeDatabase.FindTypeMap(type, out typeMap) && typeMap.DoesMarshalling)
{ {
typeMap.Type = type; typeMap.Type = type;
typeMap.CLIMarshalToManaged(Context); typeMap.CLIMarshalToManaged(Context);
@ -149,8 +149,8 @@ namespace CppSharp.Generators.CLI
{ {
var decl = typedef.Declaration; var decl = typedef.Declaration;
TypeMap typeMap = null; TypeMap typeMap;
if (Context.Driver.TypeDatabase.FindTypeMap(decl, out typeMap)) if (Context.Driver.TypeDatabase.FindTypeMap(decl, out typeMap) && typeMap.DoesMarshalling)
{ {
typeMap.Type = typedef; typeMap.Type = typedef;
typeMap.CLIMarshalToManaged(Context); typeMap.CLIMarshalToManaged(Context);
@ -175,7 +175,7 @@ namespace CppSharp.Generators.CLI
TypeQualifiers quals) TypeQualifiers quals)
{ {
TypeMap typeMap; TypeMap typeMap;
if (Context.Driver.TypeDatabase.FindTypeMap(template, out typeMap)) if (Context.Driver.TypeDatabase.FindTypeMap(template, out typeMap) && typeMap.DoesMarshalling)
{ {
typeMap.Type = template; typeMap.Type = template;
typeMap.CLIMarshalToManaged(Context); typeMap.CLIMarshalToManaged(Context);
@ -338,7 +338,7 @@ namespace CppSharp.Generators.CLI
public override bool VisitType(Type type, TypeQualifiers quals) public override bool VisitType(Type type, TypeQualifiers quals)
{ {
TypeMap typeMap; TypeMap typeMap;
if (Context.Driver.TypeDatabase.FindTypeMap(type, out typeMap)) if (Context.Driver.TypeDatabase.FindTypeMap(type, out typeMap) && typeMap.DoesMarshalling)
{ {
typeMap.Type = type; typeMap.Type = type;
typeMap.CLIMarshalToNative(Context); typeMap.CLIMarshalToNative(Context);
@ -479,8 +479,8 @@ namespace CppSharp.Generators.CLI
{ {
var decl = typedef.Declaration; var decl = typedef.Declaration;
TypeMap typeMap = null; TypeMap typeMap;
if (Context.Driver.TypeDatabase.FindTypeMap(decl, out typeMap)) if (Context.Driver.TypeDatabase.FindTypeMap(decl, out typeMap) && typeMap.DoesMarshalling)
{ {
typeMap.CLIMarshalToNative(Context); typeMap.CLIMarshalToNative(Context);
return typeMap.IsValueType; return typeMap.IsValueType;
@ -505,8 +505,8 @@ namespace CppSharp.Generators.CLI
public override bool VisitTemplateSpecializationType(TemplateSpecializationType template, public override bool VisitTemplateSpecializationType(TemplateSpecializationType template,
TypeQualifiers quals) TypeQualifiers quals)
{ {
TypeMap typeMap = null; TypeMap typeMap;
if (Context.Driver.TypeDatabase.FindTypeMap(template, out typeMap)) if (Context.Driver.TypeDatabase.FindTypeMap(template, out typeMap) && typeMap.DoesMarshalling)
{ {
typeMap.Type = template; typeMap.Type = template;
typeMap.CLIMarshalToNative(Context); typeMap.CLIMarshalToNative(Context);
@ -552,7 +552,7 @@ namespace CppSharp.Generators.CLI
private void MarshalRefClass(Class @class) private void MarshalRefClass(Class @class)
{ {
TypeMap typeMap = null; TypeMap typeMap = null;
if (Context.Driver.TypeDatabase.FindTypeMap(@class, out typeMap)) if (Context.Driver.TypeDatabase.FindTypeMap(@class, out typeMap) && typeMap.DoesMarshalling)
{ {
typeMap.CLIMarshalToNative(Context); typeMap.CLIMarshalToNative(Context);
return; return;

8
src/Generator/Generators/CSharp/CSharpMarshal.cs

@ -84,7 +84,7 @@ namespace CppSharp.Generators.CSharp
public override bool VisitType(Type type, TypeQualifiers quals) public override bool VisitType(Type type, TypeQualifiers quals)
{ {
TypeMap typeMap; TypeMap typeMap;
if (Context.Driver.TypeDatabase.FindTypeMap(type, out typeMap)) if (Context.Driver.TypeDatabase.FindTypeMap(type, out typeMap) && typeMap.DoesMarshalling)
{ {
typeMap.Type = type; typeMap.Type = type;
typeMap.CSharpMarshalToManaged(Context); typeMap.CSharpMarshalToManaged(Context);
@ -97,7 +97,7 @@ namespace CppSharp.Generators.CSharp
public override bool VisitDeclaration(Declaration decl) public override bool VisitDeclaration(Declaration decl)
{ {
TypeMap typeMap; TypeMap typeMap;
if (Context.Driver.TypeDatabase.FindTypeMap(decl, out typeMap)) if (Context.Driver.TypeDatabase.FindTypeMap(decl, out typeMap) && typeMap.DoesMarshalling)
{ {
typeMap.Declaration = decl; typeMap.Declaration = decl;
typeMap.CSharpMarshalToManaged(Context); typeMap.CSharpMarshalToManaged(Context);
@ -353,7 +353,7 @@ namespace CppSharp.Generators.CSharp
public override bool VisitType(Type type, TypeQualifiers quals) public override bool VisitType(Type type, TypeQualifiers quals)
{ {
TypeMap typeMap; TypeMap typeMap;
if (Context.Driver.TypeDatabase.FindTypeMap(type, out typeMap)) if (Context.Driver.TypeDatabase.FindTypeMap(type, out typeMap) && typeMap.DoesMarshalling)
{ {
typeMap.Type = type; typeMap.Type = type;
typeMap.CSharpMarshalToNative(Context); typeMap.CSharpMarshalToNative(Context);
@ -366,7 +366,7 @@ namespace CppSharp.Generators.CSharp
public override bool VisitDeclaration(Declaration decl) public override bool VisitDeclaration(Declaration decl)
{ {
TypeMap typeMap; TypeMap typeMap;
if (Context.Driver.TypeDatabase.FindTypeMap(decl, out typeMap)) if (Context.Driver.TypeDatabase.FindTypeMap(decl, out typeMap) && typeMap.DoesMarshalling)
{ {
typeMap.Declaration = decl; typeMap.Declaration = decl;
typeMap.CSharpMarshalToNative(Context); typeMap.CSharpMarshalToNative(Context);

24
src/Generator/Generators/CSharp/CSharpTypePrinter.cs

@ -97,12 +97,16 @@ namespace CppSharp.Generators.CSharp
Context.CSharpKind = ContextKind; Context.CSharpKind = ContextKind;
Context.Type = tag; Context.Type = tag;
return new CSharpTypePrinterResult() string type = typeMap.CSharpSignature(Context);
if (!string.IsNullOrEmpty(type))
{
return new CSharpTypePrinterResult
{ {
Type = typeMap.CSharpSignature(Context), Type = type,
TypeMap = typeMap TypeMap = typeMap
}; };
} }
}
return tag.Declaration.Visit(this); return tag.Declaration.Visit(this);
} }
@ -252,12 +256,16 @@ namespace CppSharp.Generators.CSharp
Context.CSharpKind = ContextKind; Context.CSharpKind = ContextKind;
Context.Type = typedef; Context.Type = typedef;
return new CSharpTypePrinterResult() string type = typeMap.CSharpSignature(Context);
if (!string.IsNullOrEmpty(type))
{
return new CSharpTypePrinterResult
{ {
Type = typeMap.CSharpSignature(Context), Type = type,
TypeMap = typeMap TypeMap = typeMap
}; };
} }
}
FunctionType func; FunctionType func;
if (decl.Type.IsPointerTo<FunctionType>(out func)) if (decl.Type.IsPointerTo<FunctionType>(out func))
@ -294,12 +302,16 @@ namespace CppSharp.Generators.CSharp
Context.Type = template; Context.Type = template;
Context.CSharpKind = ContextKind; Context.CSharpKind = ContextKind;
return new CSharpTypePrinterResult() string type = GetCSharpSignature(typeMap);
if (!string.IsNullOrEmpty(type))
{ {
Type = GetCSharpSignature(typeMap), return new CSharpTypePrinterResult
{
Type = type,
TypeMap = typeMap TypeMap = typeMap
}; };
} }
}
return decl.Name; return decl.Name;
} }

5
src/Generator/Types/TypeMap.cs

@ -42,6 +42,11 @@ namespace CppSharp.Types
get { return false; } get { return false; }
} }
/// <summary>
/// Determines if the type map performs marshalling or only replaces copy ctors.
/// </summary>
public virtual bool DoesMarshalling { get { return true; } }
#region C# backend #region C# backend
public virtual string CSharpSignature(CSharpTypePrinterContext ctx) public virtual string CSharpSignature(CSharpTypePrinterContext ctx)

Loading…
Cancel
Save