Browse Source

Simplify `IsTemplateParameterType`

pull/1778/head
Salvage 2 years ago committed by João Matos
parent
commit
b4f261ea38
  1. 11
      src/AST/TypeExtensions.cs
  2. 4
      src/Generator/Generators/CSharp/CSharpMarshal.cs
  3. 4
      src/Generator/Types/Std/Stdlib.CSharp.cs

11
src/AST/TypeExtensions.cs

@ -439,18 +439,13 @@
return false; return false;
} }
public static bool IsTemplate(this Type type) public static bool IsTemplateParameterType(this Type type)
{ {
if (type is TemplateParameterType or TemplateParameterSubstitutionType) if (type is TemplateParameterType or TemplateParameterSubstitutionType)
return true; return true;
var ptr = type; if (type is PointerType pt)
while (ptr is PointerType pType) return pt.GetFinalPointee() is TemplateParameterType or TemplateParameterSubstitutionType;
{
ptr = pType.Pointee;
if (ptr is TemplateParameterType or TemplateParameterSubstitutionType)
return true;
}
return false; return false;
} }

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

@ -644,7 +644,7 @@ namespace CppSharp.Generators.CSharp
else else
{ {
Context.Before.Write($"var {arg} = "); Context.Before.Write($"var {arg} = ");
if (pointer.Pointee.IsTemplate()) if (pointer.Pointee.IsTemplateParameterType())
Context.Before.Write($"(({Context.Parameter.Type}) (object) {Context.Parameter.Name})"); Context.Before.Write($"(({Context.Parameter.Type}) (object) {Context.Parameter.Name})");
else else
Context.Before.WriteLine(Context.Parameter.Name); Context.Before.WriteLine(Context.Parameter.Name);
@ -810,7 +810,7 @@ namespace CppSharp.Generators.CSharp
private void MarshalValueClass() private void MarshalValueClass()
{ {
if (Context.Parameter.Type.IsTemplate()) if (Context.Parameter.Type.IsTemplateParameterType())
Context.Return.Write($"(({Context.Parameter.Type}) (object) {Context.Parameter.Name})"); Context.Return.Write($"(({Context.Parameter.Type}) (object) {Context.Parameter.Name})");
else else
Context.Return.Write(Context.Parameter.Name); Context.Return.Write(Context.Parameter.Name);

4
src/Generator/Types/Std/Stdlib.CSharp.cs

@ -330,7 +330,7 @@ namespace CppSharp.Types.Std
Helpers.InternalStruct}.{assign.Name}(new { Helpers.InternalStruct}.{assign.Name}(new {
typePrinter.IntPtrType}(&{ typePrinter.IntPtrType}(&{
ctx.ReturnVarName}), "); ctx.ReturnVarName}), ");
if (ctx.Parameter.Type.IsTemplate()) if (ctx.Parameter.Type.IsTemplateParameterType())
ctx.Return.Write("(string) (object) "); ctx.Return.Write("(string) (object) ");
ctx.Return.Write($"{ctx.Parameter.Name})"); ctx.Return.Write($"{ctx.Parameter.Name})");
ctx.ReturnVarName = string.Empty; ctx.ReturnVarName = string.Empty;
@ -343,7 +343,7 @@ namespace CppSharp.Types.Std
ctx.Before.Write($@"{qualifiedBasicString}Extensions.{ ctx.Before.Write($@"{qualifiedBasicString}Extensions.{
assign.Name}({varBasicString}, "); assign.Name}({varBasicString}, ");
if (ctx.Parameter.Type.IsTemplate()) if (ctx.Parameter.Type.IsTemplateParameterType())
ctx.Before.Write("(string) (object) "); ctx.Before.Write("(string) (object) ");
ctx.Before.WriteLine($"{ctx.Parameter.Name});"); ctx.Before.WriteLine($"{ctx.Parameter.Name});");

Loading…
Cancel
Save