Permalink
Browse files

Deleted redundant code when printing and marshalling in C#.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
  • Loading branch information...
ddobrev committed Aug 5, 2017
1 parent 47633db commit 2f0956249d1474c0daf970a3c9fd7b08d8b2736b
@@ -843,45 +843,4 @@ public override bool VisitFunctionTemplateDecl(FunctionTemplate template)
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);
}
}
}
@@ -583,10 +583,10 @@ private IEnumerable<string> GatherInternalParams(Function function, out TypePrin
{
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 @@ private void GenerateClassField(Field field, bool @public = false)
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 @@ private void GenerateIndexerSetter(Function function)
};
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 @@ private void GenerateFieldGetter(Field field, Class @class)
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 @@ into context
};
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 @@ private int GetInstanceParamIndex(Function method)
};
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 @@ public struct ParamMarshal
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))
@@ -756,32 +756,4 @@ public override TypePrinterResult VisitFieldDecl(Field field)
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);
}
}
}
@@ -57,8 +57,6 @@ public void PushMarshalKind(MarshalKind marshalKind)
public Declaration Declaration;
public Parameter Parameter;
public CppSharp.AST.Type Type;
public QualifiedType FullType;
#region Dummy implementations
@@ -197,12 +197,12 @@ private string GenerateDelegateSignature(IEnumerable<Parameter> @params, Qualifi
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)

0 comments on commit 2f09562

Please sign in to comment.