Skip to content

Commit b4f261e

Browse files
Saalvagetritao
authored andcommitted
Simplify IsTemplateParameterType
1 parent 28000a1 commit b4f261e

File tree

3 files changed

+7
-12
lines changed

3 files changed

+7
-12
lines changed

src/AST/TypeExtensions.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -439,18 +439,13 @@ public static bool IsDependentPointer(this Type type)
439439
return false;
440440
}
441441

442-
public static bool IsTemplate(this Type type)
442+
public static bool IsTemplateParameterType(this Type type)
443443
{
444444
if (type is TemplateParameterType or TemplateParameterSubstitutionType)
445445
return true;
446446

447-
var ptr = type;
448-
while (ptr is PointerType pType)
449-
{
450-
ptr = pType.Pointee;
451-
if (ptr is TemplateParameterType or TemplateParameterSubstitutionType)
452-
return true;
453-
}
447+
if (type is PointerType pt)
448+
return pt.GetFinalPointee() is TemplateParameterType or TemplateParameterSubstitutionType;
454449

455450
return false;
456451
}

src/Generator/Generators/CSharp/CSharpMarshal.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
644644
else
645645
{
646646
Context.Before.Write($"var {arg} = ");
647-
if (pointer.Pointee.IsTemplate())
647+
if (pointer.Pointee.IsTemplateParameterType())
648648
Context.Before.Write($"(({Context.Parameter.Type}) (object) {Context.Parameter.Name})");
649649
else
650650
Context.Before.WriteLine(Context.Parameter.Name);
@@ -810,7 +810,7 @@ private void MarshalRefClass(Class @class)
810810

811811
private void MarshalValueClass()
812812
{
813-
if (Context.Parameter.Type.IsTemplate())
813+
if (Context.Parameter.Type.IsTemplateParameterType())
814814
Context.Return.Write($"(({Context.Parameter.Type}) (object) {Context.Parameter.Name})");
815815
else
816816
Context.Return.Write(Context.Parameter.Name);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ public override void CSharpMarshalToNative(CSharpMarshalContext ctx)
330330
Helpers.InternalStruct}.{assign.Name}(new {
331331
typePrinter.IntPtrType}(&{
332332
ctx.ReturnVarName}), ");
333-
if (ctx.Parameter.Type.IsTemplate())
333+
if (ctx.Parameter.Type.IsTemplateParameterType())
334334
ctx.Return.Write("(string) (object) ");
335335
ctx.Return.Write($"{ctx.Parameter.Name})");
336336
ctx.ReturnVarName = string.Empty;
@@ -343,7 +343,7 @@ public override void CSharpMarshalToNative(CSharpMarshalContext ctx)
343343

344344
ctx.Before.Write($@"{qualifiedBasicString}Extensions.{
345345
assign.Name}({varBasicString}, ");
346-
if (ctx.Parameter.Type.IsTemplate())
346+
if (ctx.Parameter.Type.IsTemplateParameterType())
347347
ctx.Before.Write("(string) (object) ");
348348
ctx.Before.WriteLine($"{ctx.Parameter.Name});");
349349

0 commit comments

Comments
 (0)