Browse Source

Deleted redundant code when printing and marshalling in C#.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/890/head
Dimitar Dobrev 8 years ago
parent
commit
2f0956249d
  1. 41
      src/Generator/Generators/CSharp/CSharpMarshal.cs
  2. 16
      src/Generator/Generators/CSharp/CSharpSources.cs
  3. 28
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs
  4. 2
      src/Generator/Generators/TypePrinter.cs
  5. 4
      src/Generator/Passes/DelegatesPass.cs

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

@ -843,45 +843,4 @@ namespace CppSharp.Generators.CSharp @@ -843,45 +843,4 @@ namespace CppSharp.Generators.CSharp
private readonly CSharpTypePrinter typePrinter;
}
public static class CSharpMarshalExtensions
{
public static void CSharpMarshalToNative(this QualifiedType type,
CSharpMarshalManagedToNativePrinter printer)
{
printer.Context.FullType = type;
type.Visit(printer);
}
public static void CSharpMarshalToNative(this Type type,
CSharpMarshalManagedToNativePrinter printer)
{
CSharpMarshalToNative(new QualifiedType(type), printer);
}
public static void CSharpMarshalToNative(this ITypedDecl decl,
CSharpMarshalManagedToNativePrinter printer)
{
CSharpMarshalToNative(decl.QualifiedType, printer);
}
public static void CSharpMarshalToManaged(this QualifiedType type,
CSharpMarshalNativeToManagedPrinter printer)
{
printer.Context.FullType = type;
type.Visit(printer);
}
public static void CSharpMarshalToManaged(this Type type,
CSharpMarshalNativeToManagedPrinter printer)
{
CSharpMarshalToManaged(new QualifiedType(type), printer);
}
public static void CSharpMarshalToManaged(this ITypedDecl decl,
CSharpMarshalNativeToManagedPrinter printer)
{
CSharpMarshalToManaged(decl.QualifiedType, printer);
}
}
}

16
src/Generator/Generators/CSharp/CSharpSources.cs

@ -583,10 +583,10 @@ namespace CppSharp.Generators.CSharp @@ -583,10 +583,10 @@ namespace CppSharp.Generators.CSharp
{
TypePrinter.PushContext(TypePrinterContextKind.Native);
retType = function.ReturnType.CSharpType(TypePrinter);
retType = function.ReturnType.Visit(TypePrinter);
var @params = function.GatherInternalParams(Context.ParserOptions.IsItaniumLikeAbi).Select(p =>
string.Format("{0} {1}", p.CSharpType(TypePrinter), p.Name)).ToList();
$"{p.Visit(TypePrinter)} {p.Name}").ToList();
TypePrinter.PopContext();
@ -775,7 +775,7 @@ namespace CppSharp.Generators.CSharp @@ -775,7 +775,7 @@ namespace CppSharp.Generators.CSharp
ctx.PushMarshalKind(MarshalKind.Variable);
var marshal = new CSharpMarshalManagedToNativePrinter(ctx);
decl.CSharpMarshalToNative(marshal);
decl.QualifiedType.Visit(marshal);
if (!string.IsNullOrWhiteSpace(marshal.Context.Before))
Write(marshal.Context.Before);
@ -1046,7 +1046,7 @@ namespace CppSharp.Generators.CSharp @@ -1046,7 +1046,7 @@ namespace CppSharp.Generators.CSharp
};
var marshal = new CSharpMarshalNativeToManagedPrinter(ctx);
decl.CSharpMarshalToManaged(marshal);
decl.QualifiedType.Visit(marshal);
if (!string.IsNullOrWhiteSpace(marshal.Context.Before))
Write(marshal.Context.Before);
@ -1105,7 +1105,7 @@ namespace CppSharp.Generators.CSharp @@ -1105,7 +1105,7 @@ namespace CppSharp.Generators.CSharp
ctx.ReturnVarName = HandleValueArray(arrayType, field);
var marshal = new CSharpMarshalNativeToManagedPrinter(ctx);
field.CSharpMarshalToManaged(marshal);
field.QualifiedType.Visit(marshal);
if (!string.IsNullOrWhiteSpace(marshal.Context.Before))
Write(marshal.Context.Before);
@ -2759,7 +2759,7 @@ namespace CppSharp.Generators.CSharp @@ -2759,7 +2759,7 @@ namespace CppSharp.Generators.CSharp
};
var marshal = new CSharpMarshalNativeToManagedPrinter(ctx);
retType.CSharpMarshalToManaged(marshal);
retType.Visit(marshal);
if (!string.IsNullOrWhiteSpace(marshal.Context.Before))
Write(marshal.Context.Before);
@ -2849,7 +2849,7 @@ namespace CppSharp.Generators.CSharp @@ -2849,7 +2849,7 @@ namespace CppSharp.Generators.CSharp
};
var marshal = new CSharpMarshalNativeToManagedPrinter(ctx);
param.CSharpMarshalToManaged(marshal);
param.QualifiedType.Visit(marshal);
if (!string.IsNullOrWhiteSpace(marshal.Context.Before))
Write(marshal.Context.Before);
@ -2919,7 +2919,7 @@ namespace CppSharp.Generators.CSharp @@ -2919,7 +2919,7 @@ namespace CppSharp.Generators.CSharp
paramMarshal.Context = ctx;
var marshal = new CSharpMarshalManagedToNativePrinter(ctx);
param.CSharpMarshalToNative(marshal);
param.QualifiedType.Visit(marshal);
paramMarshal.HasUsingBlock = ctx.HasCodeBlock;
if (string.IsNullOrEmpty(marshal.Context.Return))

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

@ -756,32 +756,4 @@ namespace CppSharp.Generators.CSharp @@ -756,32 +756,4 @@ namespace CppSharp.Generators.CSharp
return returnTypePrinter;
}
}
public static class CSharpTypePrinterExtensions
{
public static TypePrinterResult CSharpType(this QualifiedType type,
CSharpTypePrinter printer)
{
printer.FullType = type;
return type.Visit(printer);
}
public static TypePrinterResult CSharpType(this Type type,
CSharpTypePrinter printer)
{
return CSharpType(new QualifiedType(type), printer);
}
public static TypePrinterResult CSharpType(this Declaration decl,
CSharpTypePrinter printer)
{
if (decl is ITypedDecl)
{
var type = (decl as ITypedDecl).QualifiedType;
printer.FullType = type;
}
return decl.Visit(printer);
}
}
}

2
src/Generator/Generators/TypePrinter.cs

@ -57,8 +57,6 @@ namespace CppSharp.Generators @@ -57,8 +57,6 @@ namespace CppSharp.Generators
public Declaration Declaration;
public Parameter Parameter;
public CppSharp.AST.Type Type;
public QualifiedType FullType;
#region Dummy implementations

4
src/Generator/Passes/DelegatesPass.cs

@ -197,12 +197,12 @@ namespace CppSharp.Passes @@ -197,12 +197,12 @@ namespace CppSharp.Passes
var typesBuilder = new StringBuilder();
if (!returnType.Type.IsPrimitiveType(PrimitiveType.Void))
{
typesBuilder.Insert(0, returnType.Type.CSharpType(TypePrinter));
typesBuilder.Insert(0, returnType.Visit(TypePrinter));
typesBuilder.Append('_');
}
foreach (var parameter in @params)
{
typesBuilder.Append(parameter.CSharpType(TypePrinter));
typesBuilder.Append(parameter.Visit(TypePrinter));
typesBuilder.Append('_');
}
if (typesBuilder.Length > 0)

Loading…
Cancel
Save