Browse Source

Simplified the printing of templates.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/890/head
Dimitar Dobrev 8 years ago
parent
commit
225cd5c49b
  1. 24
      src/Generator/Generators/CSharp/CSharpSources.cs
  2. 5
      src/Generator/Generators/CSharp/CSharpSourcesExtensions.cs
  3. 14
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs

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

@ -394,7 +394,7 @@ namespace CppSharp.Generators.CSharp @@ -394,7 +394,7 @@ namespace CppSharp.Generators.CSharp
c => c.IsInterface && c.OriginalClass == @class);
var printedClass = (@interface ?? @class).Visit(TypePrinter);
var dict = $@"global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, {
printedClass}{printedClass.NameSuffix}>";
printedClass}>";
WriteLine("internal static readonly {0} NativeToManagedMap = new {0}();", dict);
WriteLine("protected void*[] __OriginalVTables;");
}
@ -1247,11 +1247,11 @@ namespace CppSharp.Generators.CSharp @@ -1247,11 +1247,11 @@ namespace CppSharp.Generators.CSharp
if (prop.IsVirtual && !isOverride && !prop.IsPure)
Write("virtual ");
WriteLine($"{printedType}{printedType.NameSuffix} {GetPropertyName(prop)}");
WriteLine($"{printedType} {GetPropertyName(prop)}");
}
else
{
WriteLine($@"{printedType}{printedType.NameSuffix} {
WriteLine($@"{printedType} {
prop.ExplicitInterfaceImpl.Name}.{GetPropertyName(prop)}");
}
WriteStartBraceIndent();
@ -1682,8 +1682,7 @@ namespace CppSharp.Generators.CSharp @@ -1682,8 +1682,7 @@ namespace CppSharp.Generators.CSharp
NewLine();
var printedClass = @class.Visit(TypePrinter);
WriteLine($@"var {Helpers.TargetIdentifier} = ({printedClass}{
printedClass.NameSuffix}) NativeToManagedMap[instance];");
WriteLine($"var {Helpers.TargetIdentifier} = ({printedClass}) NativeToManagedMap[instance];");
WriteLine("if ({0}.{1})", Helpers.TargetIdentifier, Helpers.OwnsNativeInstanceIdentifier);
WriteLineIndent("{0}.SetupVTables();", Helpers.TargetIdentifier);
GenerateVTableManagedCall(method);
@ -1907,7 +1906,7 @@ namespace CppSharp.Generators.CSharp @@ -1907,7 +1906,7 @@ namespace CppSharp.Generators.CSharp
// The local var must be of the exact type in the object map because of TryRemove
var printedClass = (@interface ?? (
@base.IsAbstractImpl ? @base.BaseClass : @base)).Visit(TypePrinter);
WriteLine($"{printedClass}{printedClass.NameSuffix} {Helpers.DummyIdentifier};");
WriteLine($"{printedClass} {Helpers.DummyIdentifier};");
WriteLine("NativeToManagedMap.TryRemove({0}, out {1});",
Helpers.InstanceIdentifier, Helpers.DummyIdentifier);
var classInternal = TypePrinter.PrintNative(@class);
@ -1987,12 +1986,12 @@ namespace CppSharp.Generators.CSharp @@ -1987,12 +1986,12 @@ namespace CppSharp.Generators.CSharp
{
PushBlock(BlockKind.Method);
var printedClass = @class.Visit(TypePrinter);
WriteLine("internal static {0}{1}{2} {3}(global::System.IntPtr native, bool skipVTables = false)",
WriteLine("internal static {0}{1} {2}(global::System.IntPtr native, bool skipVTables = false)",
@class.NeedsBase && !@class.BaseClass.IsInterface ? "new " : string.Empty,
printedClass, printedClass.NameSuffix, Helpers.CreateInstanceIdentifier);
printedClass, Helpers.CreateInstanceIdentifier);
WriteStartBraceIndent();
var suffix = @class.IsAbstract ? "Internal" : string.Empty;
var ctorCall = $"{printedClass}{printedClass.NameSuffix}{suffix}";
var ctorCall = $"{printedClass}{suffix}";
WriteLine("return new {0}(native.ToPointer(), skipVTables);", ctorCall);
WriteCloseBraceIndent();
PopBlock(NewLineKind.BeforeNextBlock);
@ -2189,7 +2188,7 @@ namespace CppSharp.Generators.CSharp @@ -2189,7 +2188,7 @@ namespace CppSharp.Generators.CSharp
method.OperatorKind == CXXOperatorKind.ExplicitConversion)
{
var printedType = method.OriginalReturnType.Visit(TypePrinter);
Write($"{functionName} {printedType}{printedType.NameSuffix}(");
Write($"{functionName} {printedType}(");
}
else
Write("{0} {1}(", method.OriginalReturnType, functionName);
@ -2484,11 +2483,10 @@ namespace CppSharp.Generators.CSharp @@ -2484,11 +2483,10 @@ namespace CppSharp.Generators.CSharp
if (@interface != null)
{
var printedInterface = @interface.Visit(TypePrinter);
WriteLine($@"return new {printedType}{printedType.NameSuffix}(({
printedInterface}{printedInterface.NameSuffix}) {paramName});");
WriteLine($@"return new {printedType}(({printedInterface}) {paramName});");
}
else
WriteLine($"return new {printedType}{printedType.NameSuffix}({paramName});");
WriteLine($"return new {printedType}({paramName});");
}
else
{

5
src/Generator/Generators/CSharp/CSharpSourcesExtensions.cs

@ -22,12 +22,11 @@ namespace CppSharp.Generators.CSharp @@ -22,12 +22,11 @@ namespace CppSharp.Generators.CSharp
this CSharpSources gen, Class @class)
{
var printedClass = @class.Visit(gen.TypePrinter);
var returnType = $"{printedClass}{printedClass.NameSuffix}";
if (@class.IsDependent)
foreach (var specialization in @class.GetSpecializationsToGenerate().Where(s => !s.Ignore))
gen.GenerateNativeConstructorByValue(specialization, returnType);
gen.GenerateNativeConstructorByValue(specialization, printedClass.Type);
else
gen.GenerateNativeConstructorByValue(@class, returnType);
gen.GenerateNativeConstructorByValue(@class, printedClass.Type);
}
public static void GenerateField(this CSharpSources gen, Class @class,

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

@ -343,7 +343,7 @@ namespace CppSharp.Generators.CSharp @@ -343,7 +343,7 @@ namespace CppSharp.Generators.CSharp
{
if (ContextKind == TypePrinterContextKind.Managed &&
decl == template.Template.TemplatedDecl)
return $@"{decl.Visit(this)}<{string.Join(", ",
return $@"{VisitDeclaration(decl)}<{string.Join(", ",
template.Arguments.Select(VisitTemplateArgument))}>";
return decl.Visit(this);
}
@ -549,12 +549,11 @@ namespace CppSharp.Generators.CSharp @@ -549,12 +549,11 @@ namespace CppSharp.Generators.CSharp
if (ContextKind == TypePrinterContextKind.Native)
return $"{VisitDeclaration(@class.OriginalClass ?? @class)}.{Helpers.InternalStruct}";
var typePrinterResult = new TypePrinterResult();
typePrinterResult.Type = VisitDeclaration(@class).Type;
if (@class.IsDependent)
typePrinterResult.NameSuffix = $@"<{
string.Join(", ", @class.TemplateParameters.Select(p => p.Name))}>";
return typePrinterResult;
var printed = VisitDeclaration(@class).Type;
if (!@class.IsDependent)
return printed;
return $@"{printed}<{string.Join(", ",
@class.TemplateParameters.Select(p => p.Name))}>";
}
public override TypePrinterResult VisitClassTemplateSpecializationDecl(
@ -652,7 +651,6 @@ namespace CppSharp.Generators.CSharp @@ -652,7 +651,6 @@ namespace CppSharp.Generators.CSharp
typeBuilder.Append("[MarshalAs(UnmanagedType.I1)] ");
var printedType = param.Type.Visit(this, param.QualifiedType.Qualifiers);
typeBuilder.Append(printedType);
typeBuilder.Append(printedType.NameSuffix);
var type = typeBuilder.ToString();
if (Context.Delegates.ContainsKey(param))

Loading…
Cancel
Save