From 2f0956249d1474c0daf970a3c9fd7b08d8b2736b Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Sat, 5 Aug 2017 16:40:51 +0300 Subject: [PATCH] Deleted redundant code when printing and marshalling in C#. Signed-off-by: Dimitar Dobrev --- .../Generators/CSharp/CSharpMarshal.cs | 41 ------------------- .../Generators/CSharp/CSharpSources.cs | 16 ++++---- .../Generators/CSharp/CSharpTypePrinter.cs | 28 ------------- src/Generator/Generators/TypePrinter.cs | 2 - src/Generator/Passes/DelegatesPass.cs | 4 +- 5 files changed, 10 insertions(+), 81 deletions(-) diff --git a/src/Generator/Generators/CSharp/CSharpMarshal.cs b/src/Generator/Generators/CSharp/CSharpMarshal.cs index 643bc367..ff7ce074 100644 --- a/src/Generator/Generators/CSharp/CSharpMarshal.cs +++ b/src/Generator/Generators/CSharp/CSharpMarshal.cs @@ -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); - } - } } diff --git a/src/Generator/Generators/CSharp/CSharpSources.cs b/src/Generator/Generators/CSharp/CSharpSources.cs index 30d16536..9fc4f7e7 100644 --- a/src/Generator/Generators/CSharp/CSharpSources.cs +++ b/src/Generator/Generators/CSharp/CSharpSources.cs @@ -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 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 }; 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 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 }; 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 }; 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 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)) diff --git a/src/Generator/Generators/CSharp/CSharpTypePrinter.cs b/src/Generator/Generators/CSharp/CSharpTypePrinter.cs index 8b8b7dd8..b23f8237 100644 --- a/src/Generator/Generators/CSharp/CSharpTypePrinter.cs +++ b/src/Generator/Generators/CSharp/CSharpTypePrinter.cs @@ -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); - } - } } diff --git a/src/Generator/Generators/TypePrinter.cs b/src/Generator/Generators/TypePrinter.cs index 8786ec8c..446cde16 100644 --- a/src/Generator/Generators/TypePrinter.cs +++ b/src/Generator/Generators/TypePrinter.cs @@ -57,8 +57,6 @@ namespace CppSharp.Generators public Declaration Declaration; public Parameter Parameter; - public CppSharp.AST.Type Type; - public QualifiedType FullType; #region Dummy implementations diff --git a/src/Generator/Passes/DelegatesPass.cs b/src/Generator/Passes/DelegatesPass.cs index cbf24ef1..1c051f9b 100644 --- a/src/Generator/Passes/DelegatesPass.cs +++ b/src/Generator/Passes/DelegatesPass.cs @@ -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)