Skip to content

Commit a6fc9fa

Browse files
committed
Fix CppTypePrinter to check for typemaps for tag types and keep track of them.
1 parent 21ec932 commit a6fc9fa

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/Generator/Generators/C/CppTypePrinter.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,21 @@ public CppTypePrinter(BindingContext context) : base(TypePrinterContextKind.Mana
3535
public TypeMapDatabase TypeMapDatabase => Context.TypeMaps;
3636
public DriverOptions Options => Context.Options;
3737

38+
public bool ResolveTypeMaps { get; set; } = true;
3839
public bool ResolveTypedefs { get; set; }
3940

40-
public override TypePrinterResult VisitTagType(TagType tag, TypeQualifiers quals)
41+
public override TypePrinterResult VisitTagType(TagType tag,
42+
TypeQualifiers quals)
4143
{
44+
TypeMap typeMap;
45+
if (ResolveTypeMaps && TypeMapDatabase.FindTypeMap(tag, out typeMap) &&
46+
!typeMap.IsIgnored)
47+
{
48+
var typePrinterContext = new TypePrinterContext { Type = tag };
49+
var type = typeMap.CppSignatureType(typePrinterContext).ToString();
50+
return new TypePrinterResult(type) { TypeMap = typeMap };
51+
}
52+
4253
var qual = GetStringQuals(quals);
4354
return $"{qual}{tag.Declaration.Visit(this)}";
4455
}
@@ -88,6 +99,9 @@ public override TypePrinterResult VisitPointerType(PointerType pointer,
8899
TypeQualifiers quals)
89100
{
90101
var pointeeType = pointer.Pointee.Visit(this, pointer.QualifiedPointee.Qualifiers);
102+
if (pointeeType.TypeMap != null)
103+
return pointeeType;
104+
91105
var mod = PrintTypeModifiers ? ConvertModifierToString(pointer.Modifier) : string.Empty;
92106
pointeeType.NamePrefix.Append(mod);
93107

src/Generator/Generators/TypePrinter.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using CppSharp.AST;
2+
using CppSharp.Types;
23
using System;
34
using System.Collections.Generic;
45
using System.Text;
@@ -11,6 +12,7 @@ public class TypePrinterResult
1112
public string Name { get; set; } = string.Empty;
1213
public StringBuilder NamePrefix { get; set; } = new StringBuilder();
1314
public StringBuilder NameSuffix { get; set; } = new StringBuilder();
15+
public TypeMap TypeMap { get; set; }
1416

1517
public TypePrinterResult(string type = "", string nameSuffix = "")
1618
{

src/Generator/Types/TypeMapDatabase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public bool FindTypeMap(Type type, out TypeMap typeMap)
9191

9292
var typePrinter = new CppTypePrinter(Context)
9393
{
94+
ResolveTypeMaps = false,
9495
PrintTypeQualifiers = printExtra,
9596
PrintTypeModifiers = printExtra,
9697
PrintLogicalNames = true

0 commit comments

Comments
 (0)