Skip to content

Commit b091a03

Browse files
committed
Extract and rework type map finding code from VisitTagType in C++ type printer.
1 parent c7db119 commit b091a03

File tree

1 file changed

+37
-8
lines changed

1 file changed

+37
-8
lines changed

src/Generator/Generators/C/CppTypePrinter.cs

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,46 @@ public CppTypePrinter(BindingContext context) : base(TypePrinterContextKind.Mana
3838
public bool ResolveTypeMaps { get; set; } = true;
3939
public bool ResolveTypedefs { get; set; }
4040

41-
public override TypePrinterResult VisitTagType(TagType tag,
42-
TypeQualifiers quals)
41+
public bool FindTypeMap(CppSharp.AST.Type type, out TypePrinterResult result)
4342
{
43+
result = null;
44+
45+
if (!ResolveTypeMaps)
46+
return false;
47+
4448
TypeMap typeMap;
45-
if (ResolveTypeMaps && TypeMapDatabase.FindTypeMap(tag, out typeMap) &&
46-
!typeMap.IsIgnored)
49+
if (!TypeMapDatabase.FindTypeMap(type, out typeMap) || typeMap.IsIgnored)
50+
return false;
51+
52+
var typePrinterContext = new TypePrinterContext
4753
{
48-
var typePrinterContext = new TypePrinterContext { Type = tag };
49-
var type = typeMap.CppSignatureType(typePrinterContext).ToString();
50-
return new TypePrinterResult(type) { TypeMap = typeMap };
51-
}
54+
Type = type,
55+
Kind = Kind,
56+
MarshalKind = MarshalKind
57+
};
58+
59+
var typePrinter = new CppTypePrinter(Context)
60+
{
61+
PrintFlavorKind = PrintFlavorKind,
62+
ScopeKind = ScopeKind,
63+
PrintTypeQualifiers = PrintTypeQualifiers,
64+
PrintTypeModifiers = PrintTypeModifiers,
65+
ResolveTypeMaps = false
66+
};
67+
typePrinter.PushContext(ContextKind);
68+
69+
var typeName = typeMap.CppSignatureType(typePrinterContext).Visit(typePrinter);
70+
result = new TypePrinterResult(typeName) { TypeMap = typeMap };
71+
72+
return true;
73+
}
74+
75+
public override TypePrinterResult VisitTagType(TagType tag,
76+
TypeQualifiers quals)
77+
{
78+
TypePrinterResult result;
79+
if (FindTypeMap(tag, out result))
80+
return result;
5281

5382
var qual = GetStringQuals(quals);
5483
return $"{qual}{tag.Declaration.Visit(this)}";

0 commit comments

Comments
 (0)