Skip to content

Commit 5381628

Browse files
committed
Fixed type map support for typedef types.
Fixes #1205.
1 parent 33ce83c commit 5381628

File tree

7 files changed

+40
-3
lines changed

7 files changed

+40
-3
lines changed

src/AST/Type.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,11 @@ public override object Clone()
438438
public override bool Equals(object obj)
439439
{
440440
var typedef = obj as TypedefType;
441-
return Declaration.Type.Equals(typedef == null ? obj : typedef.Declaration.Type);
441+
if (typedef == null)
442+
return false;
443+
444+
return Declaration.OriginalName == typedef.Declaration.OriginalName &&
445+
Declaration.Type.Equals(typedef.Declaration.Type);
442446
}
443447

444448
public override int GetHashCode() =>

src/Generator/Generators/CSharp/CSharpTypePrinter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ public override TypePrinterResult VisitTypedefType(TypedefType typedef,
253253
var decl = typedef.Declaration;
254254

255255
TypeMap typeMap;
256-
if (TypeMapDatabase.FindTypeMap(decl.Type, out typeMap))
256+
if (TypeMapDatabase.FindTypeMap(typedef, out typeMap))
257257
{
258258
typeMap.Type = typedef;
259259

src/Generator/Types/TypeMapDatabase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public bool FindTypeMap(Type type, out TypeMap typeMap)
9393
PrintLogicalNames = true
9494
};
9595

96-
foreach (var resolveTypeDefs in new[] { true, false })
96+
foreach (var resolveTypeDefs in new[] { false, true })
9797
{
9898
foreach (var typePrintScopeKind in
9999
new[] { TypePrintScopeKind.Local, TypePrintScopeKind.Qualified })

tests/CSharp/CSharp.Tests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,4 +1285,10 @@ private class OverrideVirtualTemplate : VirtualTemplate<int>
12851285
{
12861286
public override int Function() => 10;
12871287
}
1288+
1289+
[Test]
1290+
public void TestTypemapTypedefParam()
1291+
{
1292+
Assert.That(CSharp.CSharp.TakeTypemapTypedefParam(false), Is.False);
1293+
}
12881294
}

tests/CSharp/CSharp.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,3 +1564,8 @@ const char*& takeConstCharStarRef(const char*& c)
15641564
{
15651565
return c;
15661566
}
1567+
1568+
boolean_t takeTypemapTypedefParam(boolean_t b)
1569+
{
1570+
return b;
1571+
}

tests/CSharp/CSharp.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,24 @@ public override bool VisitFunctionDecl(Function function)
9595
}
9696

9797
#region Type Maps
98+
[TypeMap("boolean_t")]
99+
public class BooleanTypeMap : TypeMap
100+
{
101+
public override Type CSharpSignatureType(TypePrinterContext ctx)
102+
{
103+
return new BuiltinType(PrimitiveType.Bool);
104+
}
105+
106+
public override void CSharpMarshalToNative(CSharpMarshalContext ctx)
107+
{
108+
ctx.Return.Write(ctx.Parameter.Name);
109+
}
110+
111+
public override void CSharpMarshalToManaged(CSharpMarshalContext ctx)
112+
{
113+
ctx.Return.Write(ctx.ReturnVarName);
114+
}
115+
}
98116

99117
[TypeMap("QFlags")]
100118
public class QFlags : TypeMap

tests/CSharp/CSharp.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,3 +1321,7 @@ struct {
13211321
} example;
13221322
} root;
13231323
} kotlin;
1324+
1325+
typedef int boolean_t;
1326+
DLL_API boolean_t takeTypemapTypedefParam(boolean_t b);
1327+

0 commit comments

Comments
 (0)